-
Notifications
You must be signed in to change notification settings - Fork 0
/
TastierProjectFooter.s
executable file
·39 lines (35 loc) · 1.31 KB
/
TastierProjectFooter.s
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
; Subroutine enter
; Construct stack frame for procedure
; Input: R0 - lexic level (LL)
; R1 - number of local variables
; Output: new stack frame
enter
STR R0, [TOP,#4] ; set lexic level
STR BP, [TOP,#12] ; and dynamic link
; if called procedure is at the same lexic level as
; calling procedure then its static link is a copy of
; the calling procedure's static link, otherwise called
; procedure's static link is a copy of the static link
; found LL delta levels down the static link chain
LDR R2, [BP,#4] ; check if called LL (R0) and
SUBS R0, R2 ; calling LL (R2) are the same
BGT enter1
LDR R0, [BP,#8] ; store calling procedure's static
STR R0, [TOP,#8] ; link in called procedure's frame
B enter2
enter1
MOV R3, BP ; load current base pointer
SUBS R0, R0, #1 ; and step down static link chain
BEQ enter2-4 ; until LL delta has been reduced
LDR R3, [R3,#8] ; to zero
B enter1+4 ;
STR R3, [TOP,#8] ; store computed static link
enter2
MOV BP, TOP ; reset base and top registers to
ADD TOP, TOP, #16 ; point to new stack frame adding
ADD TOP, TOP, R1, LSL #2 ; four bytes per local variable
BX LR ; return
AREA Memory, DATA, READWRITE
globals SPACE 4096
stack SPACE 16384
END