Hi,
I am using GNU compiler in uVision 3.51. A portion of code is simliar to below:
X = 100; Y = 100; If(x!=y){ Xxxx; }else{ Yyyy; }
By using break point, i found that both Xxxx and Yyyy are entered. It happened in both subroutine, and main. Both X and Y are declared as unsigned integer as global variables. The entire code is less than 16K (about 70% of 16K). Do you have any idea on this? The IC used is LPC2129. Thanks for your advice.
Regards,
Most likely what happens is this: in the ARM instruction set, almost all instructions can be conditional, i.e. when they are executed their effect depends on the condition code flags in the current program status register. The compiler takes advantage of this when generating code for simple if statements: both branches are executed by the CPU, but only one of them has effect. As Christoph mentioned, you should not see this at lower optimization levels.
Regards, - mike
Yes, the problem was solved by choosing "No Optimization" in Compiler option.
As mentioned by Mike, when some optimization level was chosen, both branches are entered by "break point", but only the one fulfilling the true condition is excuted. I've verified that too. So it looked like the debugger is causing such trouble.
Thanks for Christoph and Mike.
Regards, Tey
"both branches are entered by 'break point', but only the one fulfilling the true condition is excuted"
In other words, the code is actually operating correctly?
"So it looked like the debugger is causing such trouble."
No: it sounds like it's your interpretation of what the debugger is doing (especially with conditional instructions) that's faulty, not the actual debugger?