I am trying to monitor the stack pointer in C on an embedded ARM MCU. As the project grows, I'd like to know how much space is left and map more if necessary.
I already know the start and top address of the stack from the map file generated when compiled.
I would like to get the address the sp is pointing to so I can do some basic math and monitor the stack on a percentage used basis, but I am new to ARM and don't understand why my assembly is not working.
This is what I am doing:
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 start of the stack and its not changing (I am calling this every 100ms). I expected this to be bouncing around somewhere in the middle of my stack.
Also, if I try to get the address of the stack base and limit (using the same method but with sb and sl), I just get 0's. I am not as concerned about this since from my research it seems they are not always used.
Thanks for the help