De presentatie wordt gedownload. Even geduld aub

De presentatie wordt gedownload. Even geduld aub

Een echte re stack-machine nMemory nRegisters R0 R1 R2 R3 R4 PC SP MP nMemory uProgram uStack uMemory nRegisters uProgr.counter uStack pointer uMark pointer.

Verwante presentaties


Presentatie over: "Een echte re stack-machine nMemory nRegisters R0 R1 R2 R3 R4 PC SP MP nMemory uProgram uStack uMemory nRegisters uProgr.counter uStack pointer uMark pointer."— Transcript van de presentatie:

1 Een echte re stack-machine nMemory nRegisters R0 R1 R2 R3 R4 PC SP MP nMemory uProgram uStack uMemory nRegisters uProgr.counter uStack pointer uMark pointer

2 Instructies: load on stack R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 HALT nLDC Load from constant

3 Instructies: load on stack nLDC Load from constant R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 HALT 17 nLDR Load from register

4 Instructies: load on stack nLDC Load from constant R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 HALT 17 nLDR Load from register 43 nLDL Load from local

5 Instructies: load on stack nLDC Load from constant R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 HALT 17 nLDR Load from register 43 nLDL Load from local 75 nLDS Load from stack

6 Instructies: load on stack nLDC Load from constant R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 HALT 17 nLDR Load from register 43 nLDL Load from local 75 nLDS Load from stack 12 nLDLA Load local address

7 Instructies: load on stack nLDC Load from constant R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 HALT 17 nLDR Load from register 43 nLDL Load from local 75 nLDS Load from stack 12 nLDLA Load local address nLDA Load via address

8 Instructies: load on stack nLDC Load from constant R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 HALT 17 nLDR Load from register 43 nLDL Load from local 75 nLDS Load from stack 12 nLDLA Load local address 81 nLDA Load via address

9 Instructies: load on stack nLDC Load from constant R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 HALT 17 nLDR Load from register 43 nLDL Load from local 75 nLDS Load from stack 12 nLDLA Load local address 81 nLDA Load via address

10 Instructies: store from stack nLDC Load from constant nLDR Load from register nLDL Load from local nLDS Load from stack nLDLA Load local address nLDA Load via address nSTR Store to register nSTL Store to local nSTS Store to stack nSTA Store via address

11 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3

12 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3 nAJS Adjust stackpointer

13 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3 nAJS Adjust stackpointer nBRA Branch (Jump)

14 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3 nAJS Adjust stackpointer nBRA Branch (Jump) nBSR Branch to subroutine

15 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3 nAJS Adjust stackpointer nBRA Branch (Jump) nBSR Branch to subroutine

16 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3 nAJS Adjust stackpointer nBRA Branch (Jump) nBSR Branch to subroutine

17 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3 nAJS Adjust stackpointer nBRA Branch (Jump) nBSR Branch to subroutine nRET Return from subroutine

18 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3 nAJS Adjust stackpointer nBRA Branch (Jump) nBSR Branch to subroutine nRET Return from subroutine

19 Instructies: Register nLDRR Load reg. to reg. R0 R1 R2 R3 R4 PC SP MP LDC 17 LDR R4 LDL 2 LDS -3 LDLA 1 LDA 2 NOP 12 LDRR AJS -2 BRA +3 BSR -4 LDC 91 STR R3 RET LDR R3 nAJS Adjust stackpointer nBRA Branch (Jump) nBSR Branch to subroutine nRET Return from subroutine 91

20 Instructies: Arithmetic nADD nSUB nMUL nDIV nMOD Haal twee waarden van de stack, en vervang ze door het resultaat van… nAND nOR nXOR nEQ nNE nLT nGT nLE nGE nNOT nNEG één of

21 Instructies: Branch nBRA Onvoorwaardelijke sprong nBSR Zet eerst returnadres op stack nBRT Voorwaardelijke sprong: alleen als er True op stack staat nBRF Voorwaardelijke sprong: …False…

22 Codegeneratie voor Expressies * * ?: 12 == 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

23 Codegenereer-Algebra code b = foldExpr codeAlg b where codeAlg :: ExpAlg Code = (\n ,\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) ] (Env  Code) \e  ee ee ee ye=y e; ze=z e; e ye ze ye ze \e  d e ++ [STL (length e)] ++ b ((s,a):e) [ ]

24 Codegenereer-Algebra code b = foldStEx codeAlg b where 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] (Env  Code) [ ] 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 ce concat [p e | p  ps] ++ [BSR (f e m)]

25 Codegenereer-Algebra code b = foldStEx codeAlg b where 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] (Env  Code) [ ] 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 ce concat [p e | p  ps] ++ [BSR (f e m)]

26 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m nMethod-definitie m(7, 12); void m(int x, int y) { p(x+37); q(x*y); }

27 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDS -2 LDC BSR p LDS -2 STS -2 LDS -2 MUL BSR q AJS -1 ADD RET nMethod-definitie m(7, 12); m: void m(int x, int y) { p(x+37); q(x*y); }

28 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDS -2 LDC BSR p LDS -2 STS -2 LDS -2 MUL BSR q AJS -1 ADD RET nMethod-definitie m(7, 12); m: 7 37 void m(int x, int y) { p(x+37); q(x*y); }

29 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDS -2 LDC BSR p LDS -2 STS -2 LDS -2 MUL BSR q AJS -1 ADD RET nMethod-definitie m(7, 12); m: void m(int x, int y) { p(x+37); q(x*y); }

30 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDS -2 LDC BSR p LDS -2 STS -2 LDS -2 MUL BSR q AJS -1 ADD RET nMethod-definitie m(7, 12); void m(int x, int y) { p(x+37); q(x*y); } m: Wij ruimen onze eigen rommel op!

31 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDS -2 LDC BSR p LDS -2 STS -2 LDS -2 MUL BSR q AJS -1 ADD RET nMethod-definitie m(7, 12); void m(int x, int y) { p(x+37); q(x*y); } m: Wij ruimen onze eigen rommel op!

32 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDS -2 LDC BSR p LDS -2 STS -2 LDS -2 MUL BSR q AJS -1 ADD RET nMethod-definitie m(7, 12); void m(int x, int y) { p(x+37); q(x*y); } m: Wij ruimen onze eigen rommel op!

33 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDS -2 LDC BSR p LDS -2 STS -2 LDS -2 MUL BSR q AJS -1 ADD RET nMethod-definitie m(7, 12); void m(int x, int y) { p(x+37); q(x*y); } m: Wij ruimen onze eigen rommel op!

34 Methodes met parameters nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDS -2 LDC BSR p LDS -2 STS -2 LDS -2 MUL BSR q AJS -1 ADD RET nMethod-definitie m(7, 12); void m(int x, int y) { p(x+37); q(x*y); } m: Wij ruimen onze eigen rommel op!

35 Methodes met n parameters nMethode-aanroep uZet parameters op de stack uCall nMethode-definitie uGebruik parameters … uRuim stack op uReturn BSR m LDS –(n+d)LDS –(1+d) STS –n AJS –(n-1) RET nMethode-aanroep uZet parameters op de stack uCall uRuim stack op nMethode-definitie uGebruik parameters … u Return BSR m RET AJS -n Alternatieve strategie: aanroeper ruimt op LDS –(n+d)LDS –(1+d)

36 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-definitie m(7, 12); void m(int x, int y) { int a, b; a = -x; …… } m: 7 12

37 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-definitie m(7, 12); void m(int x, int y) { int a, b; a = -x; …… } m: 7 12 MP=SP

38 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-definitie m(7, 12); void m(int x, int y) { int a, b; a = -x; …… } m: 7 12 MP=SP AJS +2

39 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-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

40 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-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

41 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-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 SP=MP

42 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-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

43 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-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

44 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-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

45 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-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

46 Methode met lokale variabelen nMethod-aanroep R0 R1 R2 R3 R4 PC SP MP LDC 7 LDC 12 BSR m LDR MP nMethod-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

47 Methode met n parameters en k lokale variabelen nCreëer ruimte voor lokalen uBewaar oude MP uMP wijst naar stukje stack nGebruik variabelen in de body uParameters uLokale variabelen nOpruimen uLokale variabelen uParameters LDR MP MP=SP AJS +k LDL –(n+1)LDL –2LDL +1LDL +k STR MP SP=MPSTS –n AJS –(n-1) RET LINK k UNLINK

48 Methoden met een resultaat nLaat het resultaat achter op de stack (nog meer gepruts bij het opruimen) nLaat het resultaat achter in R3 òf


Download ppt "Een echte re stack-machine nMemory nRegisters R0 R1 R2 R3 R4 PC SP MP nMemory uProgram uStack uMemory nRegisters uProgr.counter uStack pointer uMark pointer."

Verwante presentaties


Ads door Google