We are running a survey to help us improve the experience for all of our members. If you see the survey appear, please take the time to tell us about your experience if you can.
#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(); }
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.