![Epson S1C17 Series Скачать руководство пользователя страница 13](http://html.mh-extra.com/html/epson/s1c17-series/s1c17-series_manual_107781013.webp)
2-4
Seiko Epson Corporation
S1C17 CORE MANUAL
(REV. 1.2)
2.4 Stack Pointer (SP)
Symbol
SP
Size
24 bits
Initial value
0x000000
Register name
Stack Pointer
R/W
R/W
The Stack Pointer (hereinafter referred to as the “SP”) is a 24-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 32-bit boundaries.
32-bit boundary address
0 0
0
1
2
23
Fixed
(read only)
Figure 2.4.1 Stack Pointer (SP)
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 0x000000 when it is initialized upon reset, “last stack a 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 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 at Subroutine Call/Return
A subroutine call instruction,
call
or
calla
, uses four bytes of the stack. The
call
/
calla
instruction saves the
contents of the PC (return address) onto the stack before branching to a subroutine. The saved address is restored
into the PC by the
ret
instruction, and the program is returned to the address next to that of the
call
/
calla
in-
struction.
SP operation by the
call
/
calla
instruction
(1) SP = SP - 4
(2) PC + 2
→
[SP]
SP
7
0
0xffffff
0x000000
SP = SP - 4
7
0
0xffffff
0x00
PC[23:16]
PC[15:8]
PC[7:0]
0x000000
Figure 2.4.2.1 SP and Stack (1)