#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(); }
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!)
The source is the same except this line "if (CommonValue > 0L)": ^^here This is the result by using "0L"
; if (CommonValue > 0L) // Surely, Common Value is 100, ; SOURCE LINE # 19 MOV DPTR,#CommonValue MOVX A,@DPTR MOV R4,A INC DPTR MOVX A,@DPTR MOV R5,A INC DPTR MOVX A,@DPTR MOV R6,A INC DPTR MOVX A,@DPTR MOV R7,A MOV A,R4 RLC A JZ ?C0004 JC ?C0004
; if (CommonValue > 2L) // Surely, Common Value is 100, ; SOURCE LINE # 19 MOV DPTR,#CommonValue MOVX A,@DPTR MOV R4,A INC DPTR MOVX A,@DPTR MOV R5,A INC DPTR MOVX A,@DPTR MOV R6,A INC DPTR MOVX A,@DPTR MOV R7,A CLR A MOV R3,#02H MOV R2,A MOV R1,A MOV R0,A CLR C LCALL ?C?SLCMP JNC ?C0004