
2.1 CPU
26
Chapter 2: Hardware
s User Stack Pointer (USP) and System Stack Pointer (SSP)
The USP and SSP are 16-bit registers, indicating addresses in memory where data is saved or restored
during execution of PUSH/POP instructions and subroutines. The USP and SSP registers are treated in
the same way by stack instructions, but the USP register is enabled when the S flag in the processor
status register (PS) is set to ‘0’ and the SSP register is enabled when the S flag is set to ‘1’ (see Figure
2.1.11).
Because the S flag is set to '1' when an interrupt is received, register saving due to interrupts must be
handled in memory areas indicated by the SSP register. Normally stack processing for interrupt routines
uses the SSP, and stack processing other than for interrupt routines uses the USP register. When there is
no need to divide stack space, the SSP register alone should be used.
If values set in the stack pointers designate odd-numbered addresses, word access will be broken into
two parts, reducing efficiency. Therefore even-numbered addresses should be used.
The upper 8 bits of addresses used in stack pointers are stored in the SSB register for the SSP pointer,
and in the USB register for the USP pointer.
Neither the SUP nor the SSP is initialized at reset, so that both have undefined values.
Example 1.
PUSHW A, with S flag set to ‘0’
Example 2.
PUSHW A, with S flag set to ‘1’
Fig. 2.1.11 Stack Operation Instructions and Stack Pointers
USP
F328H
XX
MSB
LSB
C6F326H
USB C6H
AL
A624H
SSP
1234H
SSB 56H
S flag
0
Before execution
USP
F326H
A6H
24H
C6F326H
USB C6H
AL
A624H
SSP
1234H
SSB 56H
After execution
S flag
0
User stack is used because S flag is ‘0’
USP
F328H
XX
561232H
USB C6H
AL
A624H
SSP
1234H
SSB 56H
S flag
1
Before execution
USP
F328H
A6H
24H
561232H
USB C6H
AL
A624H
SSP
1232H
SSB 56H
After execution
S flag
1
User stack is used because S flag is ‘1’