ARM Assembly - stack pointer

I am trying to control the stack pointer in C on the embedded ARM MCU. As the project grows, I would like to know how much space is left and display more if necessary.

I already know the start and top address of the stack from the map file generated during compilation.

I would like to get the address pointed to by sp, so I can do the basic math and control the stack based on the percentage, but I'm new to ARM and don't understand why my build is not working.

This is what I do:

int stackptr;
asm
{                
    LDR r0, =stackptr  // put address of C variable stackptr in r0
    MOV r1, sp         // move value of sp to r1
    STR r1, [r0]       // put value of r1 in address contained in r0 (stackptr)
}

// math using stackptr...

If I look at the address stored in stackptr, its right at the beginning of the stack and its not changing (I call it every 100 ms). I expected this to bounce somewhere in the middle of my stack.

, ( , sb sl), 0. , , .

+4
1

stackptr volatile, , .

- . , GCC - fstack-use -Wstack-usage. -fstack-usage .su , . -Wstack-usage=X , , , . , , ( ). , ​​, GCC.

+3

All Articles