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.
I've asked is same question in stack overflow, but didn't get the response. Here goes,
Why is Stack-pointer register not reading correct value from another register? When I move a value from register (r0) to stack pointer (r13), the SP reads incorrect value. This is what is mean:
MOV R0, 10 MOV R13, R0
In this case, "A" should move to R13 but instead it gets 8. Similarly,
MOV R0, 9 MOV R13, R0
In this case R13 stores 8 instead of 9.
Here's a simple program program that demonstrates the problem,
void Init() { __asm( "LDR R0, =0x3FFFFDA7\n" "MOV R13, R0\n" ); } int main(void) { Init(); return (1); } void SystemInit(void) { }
Nothing much is going on here. Just a simple function call. Inside the function I moved the address to r0. Then I moved the address to R13(SP), but instead of actual address i.e. 0x3FFFFDA7, SP received 0x3FFFFDA4.
So what is going on here? Why is Stack pointer Register reading incorrect values?
I am using ARM inline Assembly with C. The IDE is KEIL.
Thanks in advance.
It is actually 4 byte align. You can also write 4, 12 etc.
Sorry 8 byte alignment is an ABI requirement for sp and all the code complies to that. Btw ARM depreciates using sp for any other purpose but stack.