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

Stack Pointer reading incorrect value from register

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.