Hi, I would like to calculate the free remaining stack space during run time.
I tried to access the r13 register with:
LPSTR pcSP; { register volatile int mySP __asm("sp"); pcSP= (LPSTR)mySP; }
This compiles, but this does NOT load the contents of r13 into my pcSP pointer variable.
I also tried many other things (e. g. "r13" instead of "sp"), but the compiler will refuse to access "r13".
Anyone how knows, how I can read the contents of the stack pointer register r13?
Create a module for ARM assembly and write a very simple function to do what you ask.
{ unsigned int foo; // local variable on stack unsigned int *bar = &foo; }
unsigned int stack_remaining(void) { unsigned int foo; // local variable on stack foo = (unsigned int)&foo - stack_base; // +/- fudge factor return(foo); }
Thank you, incredibly smart :).
I meanwhile also got it running with __asm("msp"). This works also.