Stack Pointer (Sp); About The Stack Area; Sp Operation At Subroutine Call/Return - Epson S1C17 Series Manual

Cmos 16-bit single chip microcontroller
Hide thumbs Also See for S1C17 Series:
Table of Contents

Advertisement

2 REGISTERS

2.4 Stack Pointer (SP)

Symbol
SP
Stack Pointer
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.
23

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 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 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
2-4
Register name
32-bit boundary address
Figure 2.4.1 Stack Pointer (SP)
0xffffff
7
0
0x000000
Figure 2.4.2.1 SP and Stack (1)
Seiko Epson Corporation
Size
R/W
24 bits
R/W
2
1
0
0 0
Fixed
(read only)
0xffffff
7
0x00
PC[23:16]
PC[15:8]
SP = SP - 4
PC[7:0]
0x000000
Initial value
0x000000
0
S1C17 CORE MANUAL
(REV. 1.2)

Advertisement

Table of Contents
loading

Table of Contents