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

Compiler generates bad code ?

I have spent a lot of time on this. Here is my observation:

I am porting a piece of GNU code to the MCB2130 card using the Keil toolset (including the limited compiler that comes with the board). I have a function call:

handle = function1(a, b, c, d);

handle is unsigned char. function1 has a number of different return codes. When I look at the generated code for one specific return code, I see the following:

923: return (-20);
00000024 4800 LDR R0,=0xFFFFFFEC
00000026 E0EC B L_204 ; T=0x00000202
924: }

So far so good.... but when I get to label L_204, I see the following:

0000022A L_204:
0000022A 4886 LDR R0,=0x218
0000022C 4485 ADD R13,R13,R0
0000022E B001 ADD R13,#0x4
00000230 BC08 POP {R3}
00000232 4718 BX R3
00000234 ENDP ;

Obviously, the first thing that this code does is to overwitre the return code. My handle is assigned a wrong value. I found out that if I remove some code inside function1, especially a call to another function, the L_204 code does not overwrite the return code (obvisouly function1 is now broken).

I am going to try the GNU compiler.

Any idea ?

0