6.73 __set_SP Intrinsic Function

Assigns a new address to the stack pointer register (R13).

Note: __set_MSP can be equivalent to __set_SP.

The function sets the Main Stack Pointer (MSP) value using the instruction MSR. 

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

__set_MSP

Caveats

None.

Examples

Consider migrating IAR code such as:
void __set_SP(unsigned int); 
to MPLAB XC codes similar to:
__set_MSP(); 

Further Information

None.