2024-01-16 10:01 AM
I have following code snippet, when I compile it with -O0 optimization level it gives below assembly code and I can observe value address on Expression window. But when I compile it with -O3 optimization level I couldn't observe address of value.
Where is the storing location of value when compiled it with -O3 ?
#define SRAM_ADDR 0x20000004U
int main(void) {
uint32_t value = 41;
uint32_t *ptr = (uint32_t *)SRAM_ADDR;
while(1) {
value = *ptr;
if(value) break;
}
while(1);
return 0;
}
Disassembly :
-O0 optimization :
-O3 optimization :
Solved! Go to Solution.
2024-01-16 10:16 AM
Make value volatile, otherwise optimizer optimizes it away entirely.
JW
2024-01-16 10:16 AM
Make value volatile, otherwise optimizer optimizes it away entirely.
JW
2024-01-16 10:45 AM
value is simply held in register r3, and stored within the local stack frame [r7+4] or [sp+4]