6.38 __get_SP Intrinsic Function
Returns the value of the stack pointer register (R13
).
Note: How
__get_MSP
can be quivalent to __get_SP
. The function reads the Main Stack Pointer (MSP) value using the instruction MRS.
Physically two different stack pointers (SP) exist:
- The Main Stack Pointer (MSP) is the default stack pointer after reset. It is also used when running exception handlers (handler mode).
- The Process Stack Pointer (PSP), which can be used only in thread mode.
Register R13
banks the SP
. The SP
selection is determined by the bit[1] of the CONTROL
register:
- =0 MSP is the current stack pointer. This is also the default SP. The initial value is loaded from the first 32-bit word of the vector table from the program memory.
- =1 PSP is the current stack pointer. The initial value is undefined.
Suggested Replacement
__get_MSP
Caveats
None.
Examples
Consider migrating IAR code such
as:
unsigned int __get_SP(void);
to MPLAB XC codes similar
to:__get_MSP();
Further Information
None.