Hello everyone. I decided to try out working in C for a change, but this compiler is really getting on my nerves with it's incessant optimization :/ Can anyone please tell me what i'm doing wrong here: (i'm using optimization level 0) 9: void main() 10: { 11: byte volatile blah; 12: 13: XBYTE[0x7E00] = 0x38; C:0x8030 907E00 MOV DPTR,#0x7E00 C:0x8033 7438 MOV A,#0x38 C:0x8035 F0 MOVX @DPTR,A 14: while(XBYTE[0x7E01] && 0x80) C:0x8036 907E01 MOV DPTR,#0x7E01 C:0x8039 E0 MOVX A,@DPTR C:0x803A FF MOV R7,A C:0x803B EF MOV A,R7 C:0x803C 6004 JZ C:8042 15: { 16: blah = blah+1; C:0x803E 0508 INC 0x08 17: } 18: C:0x8040 80F4 SJMP C:8036 as you can see, the "&& 0x80" bit is optimized out, and thusly this little test program fails.. Cheers, B.A
You're using a LOGICAL and with a non-zero value. That's like saying while (somevar and TRUE) which can in all cases be optimized to while (somevar); and this in turn means that that loop will execute until XBYTE[0x7E01] becomes zero. If what you're trying to do is see if the MSBit of XBYTE[0x7E01] is set, then you want to use the BITWISE and operator as in:
while (XBYTE[0X7E01] & 0x80)