4.4.1.2 Software Stack
The W15 register serves as a dedicated Software Stack Pointer (SSP), and is automatically modified by exception processing, subroutine calls and returns; however, W15 can be referenced by any instruction in the same manner as all other W registers. This simplifies reading, writing and manipulating the Stack Pointer (for example, creating stack frames).
0
’
by the hardware.W15 is initialized to 0x1000 during all Resets. This address ensures that the SSP points to valid RAM in all dsPIC33CK512MPT608 devices and permits stack availability for non-maskable trap exceptions. These can occur before the SSP is initialized by the user software. You can reprogram the SSP during initialization to any location within Data Space.
The Software Stack Pointer always points to the first available free word and fills the software stack, working from lower toward higher addresses. Figure 4-9 illustrates how it pre-decrements for a stack pop (read) and post-increments for a stack push (writes).
When the PC is pushed onto the stack, PC[15:0] are pushed onto the first
available stack word, then PC[22:16] are pushed into the second available stack
location. For a PC push during any CALL
instruction, the MSB of the PC
is zero-extended before the push, as shown in Figure 4-9.
During exception processing, the MSB of the PC is concatenated with the lower eight bits
of the CPU STATUS Register, SR. This allows the contents of SRL to be preserved
automatically during interrupt processing.
- To maintain system Stack Pointer (W15) coherency, W15 is never subject to (EDS)
paging, and is therefore, restricted to an address range of 0x0000 to 0xFFFF.
The same applies to the W14 when used as a Stack Frame Pointer (SFA =
1
). - As the stack can be placed in, and can access X and Y spaces, care must be taken regarding its use, particularly with regard to local automatic variables in a C development environment.
CALL
Stack
Frame