#include <reg52.h> // Due to these two options, the // program always goes wrong. #pragma NOINTPROMOTE #pragma OPTIMIZE(7, SPEED) unsigned long xdata CommonValue; unsigned char xdata Result; void UseResult(void) { P3=Result; } void Func() { for (;;) { // Surely, Common Value is 100, if (CommonValue > 0L) { // Should come here Result = 0xff; } else { // But it always comes here. Result = 0; } UseResult(); } } void main(void) { CommonValue=100; Func(); }
please could you re-post your code samples using the <pre> and </pre> tags, so that the layout is preserved and we can read them! See the link 'Tips for Posting Messages' in the lefthand sidebar http://www.keil.com/forum/tips.asp
#include <reg52.h> #pragma NOINTPROMOTE #pragma OPTIMIZE(7, SPEED) unsigned long xdata CommonValue; unsigned char xdata Result; void UseResult(void) { P3=Result; } void Func() { for (;;) { if (CommonValue > 0L) // Surely, Common Value is 100, { Result = 0xff; // Should be here } else { Result = 0; // But it always comes here. } UseResult(); } } void main(void) { CommonValue=100; Func(); }
Thanks for the more readable code. To return to your original question:
// Due to these two options, the // program always goes wrong. #pragma NOINTPROMOTE #pragma OPTIMIZE(7, SPEED)
I read the .src file generated by uv2, the very different code will be get by using "0L" and "1L", so I think this is a bug. I just simulate this sample code using uv2, when use "0L" it will reach the wrong way.
Can you post the .scr? (not foretting the the <pre> and </pre> tags, of course!)
<PRE> stmt level source 1 #include <reg52.h> 2 3 #pragma NOINTPROMOTE 4 #pragma OPTIMIZE(7, SPEED) 5 6 unsigned long xdata CommonValue; 7 unsigned char xdata Result; 8 9 void UseResult(void) 10 { 11 1 P3=Result; 12 1 } 13 14 void Func() 15 { 16 1 for (;;) 17 1 { 18 2 if (CommonValue > 0L) // Surely, Common Value is 100, 19 2 { 20 3 Result = 0xff; // Should be here 21 3 } 22 2 else 23 2 { 24 3 Result = 0; // But it always comes here. 25 3 } 26 2 27 2 UseResult(); 28 2 } 29 1 } 30 31 void main(void) 32 { 33 1 CommonValue=100; 34 1 Func(); 35 1 } 36 C51 COMPILER V6.21 MAIN 12/06/2001 22:51:35 PAGE 2 ASSEMBLY LISTING OF GENERATED OBJECT CODE ; FUNCTION UseResult (BEGIN) ; SOURCE LINE # 9 ; SOURCE LINE # 10 ; SOURCE LINE # 11 0000 900000 R MOV DPTR,#Result 0003 E0 MOVX A,@DPTR 0004 F5B0 MOV P3,A ; SOURCE LINE # 12 0006 22 RET ; FUNCTION UseResult (END) ; FUNCTION Func (BEGIN) ; SOURCE LINE # 14 ; SOURCE LINE # 15 ; SOURCE LINE # 16 0000 ?C0002: ; SOURCE LINE # 17 ; SOURCE LINE # 18 0000 900000 R MOV DPTR,#CommonValue 0003 E0 MOVX A,@DPTR 0004 FC MOV R4,A 0005 A3 INC DPTR 0006 E0 MOVX A,@DPTR 0007 FD MOV R5,A 0008 A3 INC DPTR 0009 E0 MOVX A,@DPTR 000A FE MOV R6,A 000B A3 INC DPTR 000C E0 MOVX A,@DPTR 000D FF MOV R7,A 000E EC MOV A,R4 000F 33 RLC A 0010 600A JZ ?C0004 0012 4008 JC ?C0004 ; SOURCE LINE # 19 ; SOURCE LINE # 20 0014 900000 R MOV DPTR,#Result 0017 74FF MOV A,#0FFH 0019 F0 MOVX @DPTR,A ; SOURCE LINE # 21 001A 8005 SJMP ?C0005 001C ?C0004: ; SOURCE LINE # 23 ; SOURCE LINE # 24 001C E4 CLR A 001D 900000 R MOV DPTR,#Result 0020 F0 MOVX @DPTR,A ; SOURCE LINE # 25 0021 ?C0005: ; SOURCE LINE # 27 0021 120000 R LCALL UseResult ; SOURCE LINE # 28 0024 80DA SJMP ?C0002 0026 22 RET ; FUNCTION Func (END) ; FUNCTION main (BEGIN) ; SOURCE LINE # 31 ; SOURCE LINE # 32 C51 COMPILER V6.21 MAIN 12/06/2001 22:51:35 PAGE 3 ; SOURCE LINE # 33 0000 900000 R MOV DPTR,#CommonValue 0003 120000 E LCALL ?C?LSTKXDATA 0006 00 DB 00H 0007 00 DB 00H 0008 00 DB 00H 0009 64 DB 064H ; SOURCE LINE # 34 000A 120000 R LCALL Func ; SOURCE LINE # 35 000D 22 RET ; FUNCTION main (END) C51 COMPILER V6.21 MAIN . . . </PRE>
I just use:
{ bit SavedIe = IE; IE = 0; //the synchronize code IE = SavedIe; }
Ignore the above message. It was posted to the wrong thread.
View all questions in Keil forum