Download - Een echte re stack-machine
![Page 1: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/1.jpg)
Een echtere stack-machine
Memory
Registers
R0
R1
R2
R3
R4
PC
SP
MP
Memory Program Stack Memory
Registers Progr.counter Stack pointer Mark pointer
![Page 2: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/2.jpg)
Instructies: load on stack
R0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
HALT
LDCLoad from constant
![Page 3: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/3.jpg)
Instructies: load on stack
LDCLoad from constantR
0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
HALT
17 LDR
Load from register
![Page 4: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/4.jpg)
Instructies: load on stack
LDCLoad from constantR
0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
HALT
17 LDR
Load from register
43
LDLLoad from local
![Page 5: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/5.jpg)
Instructies: load on stack
LDCLoad from constantR
0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
HALT
17 LDR
Load from register
43
LDLLoad from local
75
LDSLoad from stack
![Page 6: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/6.jpg)
Instructies: load on stack
LDCLoad from constantR
0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
HALT
17 LDR
Load from register
43
LDLLoad from local
75
LDSLoad from stack
12
LDLALoad local address
![Page 7: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/7.jpg)
Instructies: load on stack
LDCLoad from constantR
0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
HALT
17 LDR
Load from register
43
LDLLoad from local
75
LDSLoad from stack
12
LDLALoad local address
LDALoad via address
![Page 8: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/8.jpg)
Instructies: load on stack
LDCLoad from constantR
0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
HALT
17 LDR
Load from register
43
LDLLoad from local
75
LDSLoad from stack
12
LDLALoad local address
81
LDALoad via address
![Page 9: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/9.jpg)
Instructies: load on stack
LDCLoad from constantR
0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
HALT
17 LDR
Load from register
43
LDLLoad from local
75
LDSLoad from stack
12
LDLALoad local address
81
LDALoad via address
![Page 10: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/10.jpg)
Instructies: store from stack
LDCLoad from constant
LDRLoad from register
LDLLoad from local
LDSLoad from stack
LDLALoad local address
LDALoad via address
STRStore to register
STLStore to local
STSStore to stack
STAStore via address
![Page 11: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/11.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
31
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75 12 81
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
![Page 12: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/12.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
43
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75 12 81
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
AJSAdjust stackpointer
![Page 13: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/13.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
43
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75 12 81
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
AJSAdjust stackpointer
BRABranch (Jump)
![Page 14: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/14.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
43
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75 12 81
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
AJSAdjust stackpointer
BRABranch (Jump)
BSRBranch to subroutine
![Page 15: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/15.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
43
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75
81
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
AJSAdjust stackpointer
BRABranch (Jump)
BSRBranch to subroutine
![Page 16: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/16.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
43
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75
91
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
AJSAdjust stackpointer
BRABranch (Jump)
BSRBranch to subroutine
![Page 17: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/17.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
91
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75
91
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
AJSAdjust stackpointer
BRABranch (Jump)
BSRBranch to subroutine
RETReturn from subroutine
![Page 18: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/18.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
91
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75
91
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
AJSAdjust stackpointer
BRABranch (Jump)
BSRBranch to subroutine
RETReturn from subroutine
![Page 19: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/19.jpg)
Instructies: Register
LDRRLoad reg. to reg.R
0
R1
R2
R3
R4
PC
SP
MP
91
43
59 63 75 81
LDC 17
LDR R4
LDL 2
LDS -3
LDLA 1
LDA 2
NOP
12
LDRR 3 4
17 43 75
91
AJS -2
BRA +3
BSR -4
LDC 91
STR R3
RET
LDR R3
AJSAdjust stackpointer
BRABranch (Jump)
BSRBranch to subroutine
RETReturn from subroutine
91
![Page 20: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/20.jpg)
Instructies: Arithmetic
ADD SUB MUL DIV MOD
Haal twee waarden van de stack,
en vervang ze door het resultaat van…
AND OR XOR
EQ NE LT GT LE GE
NOT NEG
één of
![Page 21: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/21.jpg)
Instructies: Branch
BRAOnvoorwaardelijke sprong
BSRZet eerst returnadres op stack
BRTVoorwaardelijke sprong:alleen als er True op stack staat
BRFVoorwaardelijke sprong: …False…
![Page 22: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/22.jpg)
Codegeneratie voor Expressies
3 5
+
3 2
*
3 5
+ 32
*
3 5
+ 3 7
?:
1 2
== 3
3 5
+
LDC 3
LDC 5
ADD
LDC 3
LDC 5
ADD
LDC 2
MUL
LDC 3
LDC 5
ADD
LDC 2
MUL
LDC 1
LDC 2
EQ
BRF +2
LDC 7
BRA +3
LDC 3
LDC 5
ADD
![Page 23: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/23.jpg)
Codegenereer-Algebracode b = foldExpr codeAlg bwhere codeAlg :: ExpAlg Code =(\n ,\x y ,\x y ,\x y ,\x y z
)
[LDC n] x ++ y ++ [ADD] x ++ y ++ [MUL] x ++ y ++ [EQ]
x ++[BRF (sy+1)] ++ y ++[BRA sz] ++ z
\e
data Expr= Con Int| Add Expr Expr| Mul Expr Expr| Eq Expr Expr| If Expr Expr Expr let sy=size y
; sz=size z in
,\s ,\s d b
| Var Str| Let Str Expr Expr
[LDL s ] [LDL (e?s) ]
(EnvCode)
\e \e \e \e \e
e ee e
ee
ye=y e;ze=z e;
e
yeze
yeze
\e d e ++ [STL (length e)] ++ b ((s,a):e)
[ ]
![Page 24: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/24.jpg)
Codegenereer-Algebracode b = foldStEx codeAlg bwhere codeAlg :: StExAlg Code =((\s d \e ,\c b a \e
,\c b \e
,\m ps \e
), (…))
data Stat= Asmt Str Expr| If Expr Stat Stat
| While Expr Stat
| Call Str [Expr]
(EnvCode)[ ]
d e ++ [STL (e?s)] ce ++ [BRF(size be+1)]++be ++ [BRA(size ae)]++ae ce ++ [BRF (n+1)] ++be ++ [BRA –(n+k+2)]where n = size be k = size ceconcat [p e | pps]++ [BSR (f e m)]
![Page 25: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/25.jpg)
Codegenereer-Algebracode b = foldStEx codeAlg bwhere codeAlg :: StExAlg Code =((\s d \e ,\c b a \e
,\c b \e
,\m ps \e
), (…))
data Stat= Asmt Str Expr| If Expr Stat Stat
| While Expr Stat
| Call Str [Expr]
(EnvCode)[ ]
d e ++ [STL (e?s)] ce ++ [BRF(size be)] ++be ++ [BRA(size ae)]++ae [BRA n] ++ be ++ ce++ [BRT –(n+k+1)]where n = size be k = size ceconcat [p e | pps]++ [BSR (f e m)]
![Page 26: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/26.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
Method-definitie
m(7, 12);
void m(int x, int y){ p(x+37); q(x*y);}
![Page 27: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/27.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDS -2
LDC 37
7 12
BSR p
LDS -2
STS -2
LDS -2
MUL
BSR q
AJS -1
ADD
RET
Method-definitie
m(7, 12);
m:void m(int x, int y){ p(x+37); q(x*y);}
![Page 28: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/28.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDS -2
LDC 37
7 12
BSR p
LDS -2
STS -2
LDS -2
MUL
BSR q
AJS -1
ADD
RET
Method-definitie
m(7, 12);
m:
7 37
void m(int x, int y){ p(x+37); q(x*y);}
![Page 29: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/29.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDS -2
LDC 37
7 12
BSR p
LDS -2
STS -2
LDS -2
MUL
BSR q
AJS -1
ADD
RET
Method-definitie
m(7, 12);
m:
44 37
void m(int x, int y){ p(x+37); q(x*y);}
![Page 30: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/30.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDS -2
LDC 37
7 12
BSR p
LDS -2
STS -2
LDS -2
MUL
BSR q
AJS -1
ADD
RET
Method-definitie
m(7, 12);
void m(int x, int y){ p(x+37); q(x*y);}
m:
44 37
Wij ruimen onze eigen rommel op!
![Page 31: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/31.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDS -2
LDC 37
7 12
BSR p
LDS -2
STS -2
LDS -2
MUL
BSR q
AJS -1
ADD
RET
Method-definitie
m(7, 12);
void m(int x, int y){ p(x+37); q(x*y);}
m:
96 12
Wij ruimen onze eigen rommel op!
![Page 32: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/32.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDS -2
LDC 37
12
BSR p
LDS -2
STS -2
LDS -2
MUL
BSR q
AJS -1
ADD
RET
Method-definitie
m(7, 12);
void m(int x, int y){ p(x+37); q(x*y);}
m:
96 12
Wij ruimen onze eigen rommel op!
![Page 33: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/33.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDS -2
LDC 37
12
BSR p
LDS -2
STS -2
LDS -2
MUL
BSR q
AJS -1
ADD
RET
Method-definitie
m(7, 12);
void m(int x, int y){ p(x+37); q(x*y);}
m:
96 12
Wij ruimen onze eigen rommel op!
![Page 34: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/34.jpg)
Methodes met parameters
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDS -2
LDC 37
12
BSR p
LDS -2
STS -2
LDS -2
MUL
BSR q
AJS -1
ADD
RET
Method-definitie
m(7, 12);
void m(int x, int y){ p(x+37); q(x*y);}
m:
96 12
Wij ruimen onze eigen rommel op!
![Page 35: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/35.jpg)
Methodes met n parameters
Methode-aanroep Zet parameters
op de stack Call
Methode-definitie
Gebruik parameters …
Ruim stack op
Return
BSR m
LDS –(n+d) LDS –(1+d)
STS –n
AJS –(n-1)
RET
Methode-aanroep Zet parameters
op de stack Call Ruim stack op
Methode-definitie Gebruik parameters
… Return
BSR m
RET
AJS -n
Alternatieve strategie:
aanroeper ruimt op
LDS –(n+d) LDS –(1+d)
![Page 36: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/36.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
7 12
![Page 37: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/37.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
7 12
MP=SP
![Page 38: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/38.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
7 12
MP=SP
AJS +2
![Page 39: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/39.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
7 12
MP=SP
AJS +2
LDL -3
NEG
![Page 40: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/40.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
7 12
MP=SP
AJS +2
LDL -3
NEG
-7
STL +1
![Page 41: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/41.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
7 12
MP=SP
AJS +2
LDL -3
NEG
-7
STL +1
-7
SP=MP
![Page 42: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/42.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
7 12
MP=SP
AJS +2
LDL -3
NEG
-7
STL +1
SP=MP
STR MP
-7
![Page 43: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/43.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
7 12
MP=SP
AJS +2
LDL -3
NEG
-7
STL +1
SP=MP
STR MP
-7
STS -2
![Page 44: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/44.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
12
MP=SP
AJS +2
LDL -3
NEG
-7
STL +1
SP=MP
STR MP
-7
STS -2
AJS -1
![Page 45: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/45.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
12
MP=SP
AJS +2
LDL -3
NEG
-7
STL +1
SP=MP
STR MP
-7
STS -2
AJS -1
RET
![Page 46: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/46.jpg)
Methode met lokale variabelen
Method-aanroepR0
R1
R2
R3
R4
PC
SP
MP
LDC 7
LDC 12
BSR m
LDR MP
Method-definitie
m(7, 12);
void m(int x, int y){ int a, b; a = -x; ……}
m:
12
MP=SP
AJS +2
LDL -3
NEG
-7
STL +1
SP=MP
STR MP
-7
STS -2
AJS -1
RET
![Page 47: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/47.jpg)
Methode met n parameters en k lokale variabelen
Creëer ruimte voor lokalen Bewaar oude MP MP wijst naar stukje stack
Gebruik variabelen in de body Parameters Lokale variabelen
Opruimen Lokale variabelen Parameters
LDR MP
MP=SP
AJS +k
LDL –(n+1)LDL –2
LDL +1 LDL +k
STR MP
SP=MP
STS –n
AJS –(n-1) RET
LINK k
UNLINK
![Page 48: Een echte re stack-machine](https://reader036.vdocuments.net/reader036/viewer/2022062518/56814556550346895db224ab/html5/thumbnails/48.jpg)
Methoden met een resultaat
Laat het resultaat achter op de stack(nog meer gepruts bij het opruimen)
Laat het resultaat achter in R3
òf