
S3C8639/C863A/P863A/C8647/F8647
ADDRESS SPACES
2-21
SYSTEM AND USER STACKS
S3-series microcontrollers can be programmed to use the system stack for subroutine calls, returns and
interrupts and to store data. The PUSH and POP instructions are used to control system stack operations. The
S3C8639/C863A architecture supports stack operations in the internal register file.
Stack Operations
Return addresses for procedure calls and interrupts and data are stored on the stack. The contents of the PC are
saved to stack by a CALL instruction and restored by the RET instruction. When an interrupt occurs, the contents
of the PC and the FLAGS register are pushed to the stack. The IRET instruction then pops these values back to
their original locations. The stack address is always decremented before a push operation and incremented after
a pop operation. The stack pointer (SP) always points to the stack frame stored on the top of the stack, as shown
in Figure 2-15.
Stack contents
after a call
instruction
Stack contents
after an
interrupt
Top of
stack
Flags
PCH
PCL
PCH
Top of
stack
Low Address
High Address
Figure 2-18. Stack Operations
User-Defined Stacks
You can freely define stacks in the internal register file as data storage locations. The instructions PUSHUI,
PUSHUD, POPUI, and POPUD support user-defined stack operations.
Stack Pointers (SPL, SPH)
Register locations D8H and D9H contain the 16-bit stack pointer (SP) that is used for system stack operations.
The most significant byte of the SP address, SP15–SP8, is stored in the SPH register (D8H) and the least
significant byte, SP7–SP0, is stored in the SPL register (D9H). After a reset, the SP value is undetermined.
Because only internal memory space is implemented in S3C8639/C863A, the SPL must be initialized to an 8-bit
value in the range 00H–FFH. The SPH register is not needed here and can be used as a general-purpose
register, if necessary.
When the SPL register contains the only stack pointer value (that is, when it points to a system stack in the
register file), you can use the SPH register as a general-purpose data register. However, if an overflow or
underflow condition occurs as the result of incrementing or decrementing the stack address in the SPL register
during normal stack operations, the value in the SPL register will overflow (or underflow) to the SPH register,
overwriting any data that is currently stored there. To avoid overwriting data in the SPH register, you can
initialize the SPL value to "FFH" rather than "00H".