English
Language : 

GMS30C2116 Datasheet, PDF (41/322 Pages) Hynix Semiconductor – USERS MANUAL
ARCHITECTURE
1-21
1.7 Stack (continued)
Because the complete stack management is accomplished automatically by the hardware,
programming the stack handling instructions is easy and does not require any knowledge
of the internal working of the stack.
The following example demonstrates how the Call, Frame and Return instructions are
applied to achieve the stack behavior of the register part of the stack shown in the figures
1.13 and 1.14. Figure 1.13 shows the creation and release of stack frames in the register
part of the stack.
Program Example:
A: FRAME L13, L3 ; set frame length FL = 13, decrement FP by 3
:
; parameters passed to A can be addressed
:
; in L0, L1, L2
:
:
code of function A
:
:
MOV
L7, L5
; copy L5 to L7 for use as parameter1
MOVI L8, 4
; set L8 = 4 for use as parameter2
CALL L9, 0, B ; call function B,
:
; save return PC, return SR in L9, L10
:
:
MOVI L0, 20
; set L0 = 20 as return parameter for caller
RET
PC, L3
; return to function calling A,
; restore frame of caller
B: FRAME L11, L2 ; set frame length FL = 11, decrement FP by 2
:
; passed parameter1 can now be addressed in L0
:
; passed parameter2 can now be addressed in L1
:
:
code of function B
:
:
RET
PC, L2
; return to function A, frame A is restored by
; copying return PC and return SR in L2 and L3
; of frame B to PC and SR