2.4 Stack Pointer (SP)
Symbol
SP
Stack Pointer
The Stack Pointer (hereinafter referred to as the "SP") is a 32-bit register for holding the start address of the stack.
The stack is an area locatable at any place in the system RAM, the start address of which is set in the SP during the
initialization process. The 2 low-order bits of the SP are fixed to 0 and cannot be accessed for writing. Therefore,
the addresses specifiable by the SP are those that lie on word boundaries.
31
2.4.1 About the Stack Area
The size of an area usable as the stack is limited according to the RAM size available for the system and the size of
the area occupied by ordinary RAM data. Care must be taken to prevent the stack and data area from overlapping.
Furthermore, as the SP becomes indeterminate when it is initialized upon reset, "last stack address + 4, with 2 low-
order bits = 0" must be written to the SP in the beginning part of the initialization routine. A load instruction may
be used to write this address. If an interrupt or exception occurs before the stack is set up, it is possible that the PC
or PSR will be saved to an indeterminate location, and normal operation of a program cannot be guaranteed. To
prevent such a problem, NMIs (nonmaskable interrupts) that cannot be controlled in software are masked out in
hardware until the SP is initialized.
2.4.2 SP Operation during Execution of Push-Related Instructions
In a push-related instruction, first the stack pointer indicated by the SP is decremented by 4 to move the SP to a
lower address location.
SP = SP - 4
Next, the content of the register specified in the push instruction is stored at the address pointed to by the SP.
rs → [SP]
Example: pushn
%r2
SP
S1C33 FAMILY C33 PE CORE MANUAL
Register name
Word boundary address
Figure 2.4.1 Stack Pointer (SP)
0xFFFFFFFF
31
0
0x00000000
Figure 2.4.2.1 SP and Stack (1)
EPSON
Size
R/W
32 bits
R/W
0xFFFFFFFF
31
r2
r1
SP = SP - 12
r0
0x00000000
2 REGISTERS
Initial value
Indeterminate
2
1
0
0 0
Fixed
(read only)
0
7