We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
Hi, all I found there is likely a bug in keil c51's compiler(V6.02, Optimization Level = 8) When compile and link the following program lines:
#include <absacc.h> #include <reg52.h> #define ADDR201 XBYTE[0x8000] bdata unsigned char D201; sbit green = D201^2; void main(void) { while(1) { green = 1; ADDR201 = D201; green = 0; green = 1; ADDR201 = D201; } }
RSEG ?PR?main?TMAIN main: ; SOURCE LINE # 8 ; { ; SOURCE LINE # 9 ?C0001: ; while(1) ; SOURCE LINE # 10 ; { ; SOURCE LINE # 11 ; green = 1; ; SOURCE LINE # 12 SETB green ; ADDR201 = D201; ; SOURCE LINE # 13 MOV DPTR,#08000H MOV A,D201 MOVX @DPTR,A ; green = 0; ; SOURCE LINE # 14 CLR green ; green = 1; ; SOURCE LINE # 15 SETB green ; ADDR201 = D201; ; SOURCE LINE # 16 MOVX @DPTR,A ; } ; SOURCE LINE # 17 SJMP ?C0001 ; END OF main END
MOV A,D201
MOVX @DPTR,A
Hmmm, dunno if that would be considered a "bug". To me, D201's declaration deserves "volatile" qualifier. --Dan Henry
But Source Line #13 has already loaded D201 into A:
; SOURCE LINE # 13 MOV DPTR,#08000H MOV A,D201 MOVX @DPTR,A ; green = 0; ; SOURCE LINE # 14 CLR green ; green = 1; ; SOURCE LINE # 15 SETB green ; ADDR201 = D201; ; SOURCE LINE # 16 MOVX @DPTR,A ;A has not changed - it is still D201!
Thx very much.