System And User Stack - Samsung S3F84B8 User Manual

8-bit cmos
Hide thumbs Also See for S3F84B8:
Table of Contents

Advertisement

S3F84B8_UM_REV 1.00

2.4.4 SYSTEM AND USER STACK

The S3C8 series microcontrollers use the system stack for data storage, subroutine calls, and returns. Both PUSH
and POP instructions control the system stack operations. The S3F84B8 architecture supports stack operations in
internal register file.
2.4.4.1 Stack Operations
Return addresses for procedure calls, 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 FLAGS registers are pushed to the stack. The IRET instruction then pops these values back to their
original locations. The stack address value is always decreased by one before a push operation and increased by
one after a pop operation. The stack pointer (SP) always points to the stack frame stored on the top of stack, as
shown in
Figure
2-16.
Top of
stack
2.4.4.2 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.
2.4.4.3 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.
Since only internal memory space is implemented in S3F84B8, the SPL must be initialized to an 8-bit value in the
range 00H–FFH. The SPH register is not needed 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 a result of increasing or decreasing the stack address value in the SPL register
during normal stack operations, the value in the SPL register will overflow (or underflow) to the SPH register,
overwriting any other data that is currently stored there. To avoid overwriting data in the SPH register, you can
initialize the SPL value to "FFH" instead of "00H".
High Address
PCL
PCH
Stack contents
after a call
instruction
Figure 2-16
Top of
stack
Stack contents
Low Address
Stack Operations
2-19
2 ADDRESS SPACES
PCL
PCH
Flags
after an
interrupt

Hide quick links:

Advertisement

Table of Contents
loading

Table of Contents