Stack Pointer Setting - NEC 78K0S/K 1+ Series Application Note

Led lighting switch control sample program (initial settings)
Hide thumbs Also See for 78K0S/K 1+ Series:
Table of Contents

Advertisement

4.3

Stack Pointer Setting

A stack area is a memory area in which data, such as of program counters, register values, and PSW (program
status word) is temporarily stored. A stack area can be specified only to the internal high-speed RAM area. The start
address of this stack area is set with a stack pointer to secure the stack area.
A stack area is used when the following instructions are executed or interrupts occur.
• PUSH, CALL, CALLT, interrupt: Saving data to a stack area
• POP, RET, RETI: Restoring data from a stack area
The securing of a stack area is a required setting when coding in assembly language. When coding in C language,
this setting is not required, since a stack area is automatically secured in the startup routine.
[Example 1] Using FEE0H to FEFFH (32 bytes) in the internal high-speed RAM area as the stack area
(Same as in the sample program setting)
XSTK
DSEG
STACKEND:
DS
STACKTOP:
XMAIN CSEG
RESET_START:
MOVW
MOVW
In this example, address FF00H (= FEE0H + 20H) is specified for the stack pointer. FF00H is not only a high-
speed RAM area, but also an SFR area, so it is converted into a high-speed RAM area, and the stack pointer
becomes FB00H.
When actually storing data to the stack, the stack pointer becomes FAFFH, as a result of decrementing (−1)
FB00H, into which FF00H was converted. This, however, is not a high-speed RAM area, so it is converted into
a high-speed RAM area, and becomes FEFFH. This is the same value as when address FF00H is specified to
the stack pointer, and data is stored starting from address FEFFH.
Thanks to the description above, the last 32 bytes (FEE0H to FEFFH) of the internal high-speed RAM area can
be secured as the stack area.
[Example 2] Using FE00H to FE1FH (32 bytes) in the internal high-speed RAM area as the stack area
XSTK
DSEG
STACKEND:
DS
STACKTOP:
XMAIN CSEG
RESET_START:
MOVW
MOVW
In this example, address FE20H (= FE00H + 20H) is specified for the stack pointer. This setting avoids the
saddr area and secures the stack area.
Caution The setting of example 2, above, can only be set to products with a 256-byte internal high-speed
RAM.
CHAPTER 4 SETTING METHODS
AT
0FEE0H
20H
UNIT
AX, #STACKTOP
SP, AX
AT
0FE00H
20H
UNIT
AX, #STACKTOP
SP, AX
Application Note U18752EJ2V0AN
A stack area is secured in
the internal high-speed
RAM area.
A stack pointer is set
after reset release.
A stack area is secured in
the internal high-speed
RAM area.
A stack pointer is set
after reset release.
13

Advertisement

Table of Contents
loading

This manual is also suitable for:

78k0s/ka1+78k0s/kb1+78k0s/ku1+78k0s/ky1+

Table of Contents