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
  • The assembly language for line 18 does not look right to me. The code reads the four bytes of CommonValue into R4, R5, R6 and R7. Fine. The code then does an RLC on the byte in R4 before checking its value - very odd...

    One thing you should try is to lower the level of optimisation to 0 and see if you get sensible looking assembly code and a working program. If you do, increment the optimisation level one step at a time to find out where things start to go wrong. I'm sure Keil support will be interested to hear your results.

Reply
  • The assembly language for line 18 does not look right to me. The code reads the four bytes of CommonValue into R4, R5, R6 and R7. Fine. The code then does an RLC on the byte in R4 before checking its value - very odd...

    One thing you should try is to lower the level of optimisation to 0 and see if you get sensible looking assembly code and a working program. If you do, increment the optimisation level one step at a time to find out where things start to go wrong. I'm sure Keil support will be interested to hear your results.

Children
No data