The STKPTR register contains the Stack Pointer value. The STKOVF (Stack Overflow) Status bit and the STKUNF (Stack Underflow) Status bit can be accessed using the PCON0 register. The value of the Stack Pointer can be zero through 127. On Reset, the Stack Pointer value will be zero. The user may read and write the Stack Pointer value. After the PC is pushed onto the stack 128 times (without popping any values off the stack), the STKOVF bit is set. The STKOVF bit is cleared by software or by a POR. The action that takes place when the stack becomes full depends on the state of the STVREN (Stack Overflow Reset Enable) Configuration bit.
If STVREN is set (default), a Reset will be generated and a Stack
Overflow will be indicated by the STKOVF bit. This includes CALL and CALLW instructions, as well
as stacking the return address during an interrupt response. The STKOVF bit will remain set
and the Stack Pointer will be set to zero.
If STVREN is cleared, the STKOVF bit will be set on the 128th push and the Stack Pointer will remain at 127 but no Reset will occur. Any additional pushes will overwrite the 127st push but the STKPTR will remain unchanged.
Setting STKOVF = 1 in
software will change the bit, but will not generate a Reset.
The STKUNF bit is set when a stack pop returns a value of zero. The STKUNF bit is cleared by software or by POR. The action that takes place when the stack becomes full depends on the state of the STVREN (Stack Overflow Reset Enable) Configuration bit.
If STVREN is set (default) and the stack has been popped enough
times to unload the stack, the next pop will return a value of zero to the PC, it will set
the STKUNF bit and a Reset will be generated. This condition can be generated by the
RETURN, RETLW and RETFIE instructions.
If STVREN is cleared, the STKUNF bit will be set, but no Reset will occur.