PSoC5LP: right way to save value of Stack Pointer (r13) register

Tip / Sign in to post questions, reply, level up, and achieve exciting badges. Know more

cross mob
EnSi_1099366
Level 1
Level 1

Hello,

I am learning to use ARM MCUs and I want to make a stack monitor. I managed with filling it, monitor it ecc, but I want to start to fill it from a proper unused location without knowing the r13 value in debug. So I just need to implement a way to store the r13 somewhere in the code and using it later. So far I was visually checking the content of r13 in debug and adjusting the code accordingly.

What is the right way of storing locally the content of SP (r13) register in a ARM Cortex M3?

Thank you,

0 Likes
1 Solution
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi user_381194313​,

You can try the following snippet to track the stack pointer in your code:

register uint32 sp_track asm("sp");

int main()

{

// your code

}

The variable sp_track will now hold the value of the stack pointer and will change when the stack pointer changes, like pointer.

Regards,

Bragadeesh

Regards,
Bragadeesh

View solution in original post

0 Likes
2 Replies
BragadeeshV
Moderator
Moderator
Moderator
First question asked 1000 replies posted 750 replies posted

Hi user_381194313​,

You can try the following snippet to track the stack pointer in your code:

register uint32 sp_track asm("sp");

int main()

{

// your code

}

The variable sp_track will now hold the value of the stack pointer and will change when the stack pointer changes, like pointer.

Regards,

Bragadeesh

Regards,
Bragadeesh
0 Likes

Hello,

thanks for the hint! But I wonder, what does return the asm instruction "sp", a pointer? In this case what is doing the "register" attribute? Can I avoid that?

0 Likes