ST7LITEUSxCPU REGISTERS (Cont’d) Stack Pointer (SP) The least significant byte of the Stack Pointer Read/Write (called S) can be directly accessed by a LD in- struction. Reset Value: 00 FFh Note: When the lower limit is exceeded, the Stack 15 8 Pointer wraps around to the stack upper limit, with- out indicating the stack overflow. The previously stored information is then overwritten and there- 0 0 0 0 0 0 0 0 fore lost. The stack also wraps in case of an under- flow. 7 0 The stack is used to save the return address dur- ing a subroutine call and the CPU context during 1 1 SP5 SP4 SP3 SP2 SP1 SP0 an interrupt. The user may also directly manipulate the stack by means of the PUSH and POP instruc- tions. In the case of an interrupt, the PCL is stored The Stack Pointer is a 16-bit register which is al- at the first location pointed to by the SP. Then the ways pointing to the next free location in the stack. other registers are stored in the next locations as It is then decremented after data has been pushed shown in Figure 8. onto the stack and incremented before data is – When an interrupt is received, the SP is decre- popped from the stack (see Figure 8). mented and the context is pushed on the stack. Since the stack is 64 bytes deep, the 10 most sig- – On return from interrupt, the SP is incremented nificant bits are forced by hardware. Following an and the context is popped from the stack. MCU Reset, or after a Reset Stack Pointer instruc- A subroutine call occupies two locations and an in- tion (RSP), the Stack Pointer contains its reset val- terrupt five locations in the stack area. ue (the SP5 to SP0 bits are set) which is the stack higher address. Figure 8. Stack Manipulation Example CALL Interrupt PUSH Y POP Y IRET RET Subroutine event or RSP @ 00C0h SP SP SP Y CC CC CC A A A X X X PCH PCH PCH SP SP PCL PCL PCL PCH PCH PCH PCH PCH SP @ 00FFh PCL PCL PCL PCL PCL Stack Higher Address = 00FFh Stack Lower Address = 00C0h 16/108 1