Samsung C8249 Microscope & Magnifier User Manual


 
ADDRESS SPACES S3C8245/P8245/C8249/P8249
2-18
SYSTEM AND USER STACK
The S3C8-series microcontrollers use the system stack for data storage, subroutine calls and returns. The PUSH
and POP instructions are used to control system stack operations. The S3C8245/C8249 architecture supports stack
operations in the internal register file.
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 the FLAGS register 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 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
PCL
PCH
Top of
stack
Low Address
High Address
Figure 2-15. 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 the S3C8245/C8249, 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".