Stack Operations - Samsung KS57C2308 Manual

Single-chip cmos microcontroller
Table of Contents

Advertisement

ADDRESS SPACES

STACK OPERATIONS

STACK POINTER (SP)
The stack pointer (SP) is an 8-bit register that stores the address used to access the stack, an area of data
memory set aside for temporary storage of data and addresses. The SP can be read or written by 8-bit control
instructions. When addressing the SP, bit 0 must always remain cleared to logic zero.
F80H
SP3
F81H
SP7
There are two basic stack operations: writing to the top of the stack (push), and reading from the top of the stack
(pop). A push decrements the SP and a pop increments it so that the SP always points to the top address of the
last data to be written to the stack.
The program counter contents and program status word are stored in the stack area prior to the execution of a
CALL or a PUSH instruction, or during interrupt service routines. Stack operation is a LIFO (Last In-First Out)
type. The stack area is located in general-purpose data memory bank 0.
During an interrupt or a subroutine, the PC value and the PSW are saved to the stack area. When the routine has
completed, the stack pointer is referenced to restore the PC and PSW, and the next instruction is executed.
The SP can address stack registers in bank 0 (addresses 000H-0FFH) regardless of the current value of the
enable memory bank (EMB) flag and the select memory bank (SMB) flag. Although general-purpose register
areas can be used for stack operations, be careful to avoid data loss due to simultaneous use of the same
register(s).
Since the
value of the stack pointer is not defined in firmware, we recommend that you initialize the stack
RESET
pointer by program code to location 00H. This sets the first register of the stack area to 0FFH.
A subroutine call occupies six nibbles in the stack; an interrupt requires six. When subroutine nesting or
interrupt routines are used continuously, the stack area should be set in accordance with the maximum
number of subroutine levels. To do this, estimate the number of nibbles that will be used for the
subroutines or interrupts and set the stack area correspondingly.
+ +
PROGRAMMING TIP — Initializing the Stack Pointer
To initialize the stack pointer (SP):
1. When EMB = "1":
SMB
15
LD
EA,#00H
LD
SP,EA
2. When EMB = "0":
LD
EA,#00H
LD
SP,EA
2-12
SP2
SP1
SP6
SP5
"0"
SP4
NOTE
; Select memory bank 15
; Bit 0 of SP is always cleared to "0"
; Stack area initial address (0FFH)
; Memory addressing area (00H–7FH, F80H–FFFH)
KS57C2308/P2308/C2316/P2316
(SP) – 1

Hide quick links:

Advertisement

Table of Contents
loading

This manual is also suitable for:

P2308C2316P2316Ks57p2308Ks57c2316Ks57p2316

Table of Contents