Chances are, that the optimizer has replaced the 'variable' by a register. There's no reason to reserve space on the stack, increase it there and then clean up the stack if the return value needs to be in R15 for return anyway. Also, since the scope of the variable is limited to the function and the address(!) of the variable is never forwarded anywhere, declaring it volatile has no effect at all. I _think_ there is a compiler flag to disable register variables. But normally, the compiler uses them, in any optimisation stage.
My guess is that GDB gets the symbol, but cannot handle it properly and just assumes it somewhere at the start of .text. Or the linker has put it at start of .txt since it isn't used anywhere. A look into the .lst file should make things clear. This is always my reference if something goes wrong. My bet is that this address is never accessed anywhere and all is done directly in a register. JMGross ----- Ursprüngliche Nachricht ----- Von: Carl An: GCC for MSP430 - http://mspgcc.sf.net Gesendet am: 20 Feb 2010 22:16:22 Betreff: Re: [Mspgcc-users] stack variable in flash? If I declare it as a global it is where I expect at the beginning of RAM (0x1100). But if it is on the stack in the main function, even if I declare it volatile, use asm(""); // __asm__ __volatile__ (""); or pass it to a function, the variable address is in flash at 0x3102. It doesn't make sense. Now if I use the program: #include <io.h> int f1() { volatile int i = 5; i += 2; return i; } int main() { while(1) { f1(); } } The variable i address is on the stack in RAM at 0x30f8 which makes sense. But if I change the compile option to use -02. Then the function stack variable, i, goes back to being located in flash at 0x3102. And it's value is not initialed to 5 nor is 2 added to it. The value of i is constant = 12544 (0x3100.)
