This discussion has been locked.
You can no longer post new replies to this discussion. If you have a question you can start a new discussion

A compiler bug of Keil C V6.21

#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();
}


Parents Reply Children
  • Can you post the .scr?
    (not foretting the the &ltpre&gt and &lt/pre&gt 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
    

    and this is the result by using "2L"
    ;     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