dsPIC30F Family Reference Manual
DS70049C-page 2-8 © 2004 Microchip Technology Inc.
2.3 Software Stack Pointer
W15 serves as a dedicated software stack pointer 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 (e.g., creating stack frames).
W15 is initialized to 0x0800 during all Resets. This address ensures that the stack pointer (SP)
will point to valid RAM in all dsPIC30F devices and permits stack availability for non-maskable
trap exceptions, which may occur before the SP is initialized by the user software. The user may
reprogram the SP during initialization to any location within data space.
The stack pointer always points to the first available free word and fills the software stack working
from lower towards higher addresses. It pre-decrements for a stack pop (read) and
post-increments for a stack push (writes), as shown in Figure 2-3.
When the PC is pushed onto the stack, PC<15:0> is pushed onto the first available stack word,
then PC<22:16> is pushed into the second available stack location. For a PC push during any
CALL instruction, the MSByte of the PC is zero-extended before the push as shown in Figure 2-3.
During exception processing, the MSByte of the PC is concatenated with the lower 8 bits of the
CPU status register, SR. This allows the contents of SRL to be preserved automatically during
interrupt processing.
Figure 2-3: Stack Operation for a CALL Instruction
Note: In order to protect against misaligned stack accesses, W15<0> is fixed to ‘0’ by the
hardware.
<Free Word>
PC<15:0>
PC<22:16>
015
W15 (before CALL)
W15 (after CALL)
Stack Grows Towards
Higher Address
B‘000000000’
CALL SUBR