
CENTRAL PROCESSING UNIT (CPU)
2.1 Central processing unit (CPU)
7700 FAMILY SOFTWARE MANUAL
2–4
2.1.4 Stack pointer (S)
Stack pointer S is a 16-bit register. It is used for a subroutine call or an interrupt. It is also used for
addressing modes using the stack. The contents of the stack pointer S indicate the address (stack area)
for storing registers during subroutine calls and interrupts.
When an interrupt request is accepted, the contents of the program bank register PG is stored at the
address indicated by the contents of the stack pointer S, and the contents of the stack pointer S are
decremented by 1. Then the contents of the program counter PC and the processor status register PS
(PC
H
, PC
L
, PS
H
, PS
L
) are stored. The contents of the stack pointer S after accepting an interrupt request
are equal to the contents of the stack pointer S before the accepting of the interrupt request decremented
by 5.
Figure 2.1.2 shows the stored registers before an interrupt routine.
When returning to the original routine after processing the interrupt routine by executing the
RTI
instruction,
the registers stored in the stack area are restored to the original registers in the reverse sequence and the
contents of the stack pointer are returned to the numerical value before the accepting of interrupt request.
The same operation is performed during a subroutine call, but the contents of the processor status register
PS are not automatically stored. (The contents of the program bank register PG may not be stored. It
depends on the addressing mode.)
The user is responsible for storing registers other than those described above with a program during
interrupts or subroutine calls.
Additionally, the stack pointer S must be initialized at the beginning of the program because its contents
are undefined at reset. The stack area changes when subroutines are nested or when multiple interrupt
requests are accepted. Therefore, make sure necessary data in the internal RAM are not destroyed when
nesting subroutines.
Fig. 2.1.2 Stored registers before an interrupt routine
C
“S” is the initial address that the stack pointer (S)
indicates at accepting an interrupt request.
The S’s contents become “S–5” after storing the
above registers.
Address
S–4
S–3
S–2
S–1
S
Stack area
S–5
Processor status register’s low-order byte (PS
L
)
Processor status register’s high-order byte (PS
H
)
Program counter’s low-order byte (PC
L
)
Program counter’s high-order byte (PC
H
)
Program bank register (PG)