Presentasi sedang didownload. Silahkan tunggu

Presentasi sedang didownload. Silahkan tunggu

Pembentukan Kode (Simulasi)

Presentasi serupa


Presentasi berjudul: "Pembentukan Kode (Simulasi)"— Transcript presentasi:

1 Pembentukan Kode (Simulasi)

2 Lihat Class Hmachine & Machine
public static int[] memory = new int[memorySize]; public static int[] display = new int[displaySize]; public static int pc, mt; …. Etc…

3 Class Machine Method ‘machine’ inisialisasi display, pc, mt dengan 0. (lalu pada class generate rule R0, pc diset ke awal index stack dan mt diset ke puncak stack memory yang kosong). Method ‘memoryDump’ mencetak isi memory ke stdout Method ‘execute’ mengeksekusi isi memory. Eksekusi dilakukan dengan menginterpretasikan isi ‘memory’ dari pc 0 sampai instruksi HALT dengan statement java. (simulasi dengan java). Pengertian PUSH, POP dan TOP mengacu pada array atau stack ‘memory’. TOP adalah isi dari puncak stack.

4 Arti simulasi instruksi
0. NAME LL ON Push(display[LL]+ON) 1. LOAD a:top,pop; jika memory[a]=undefined maka error; push (memory[a]) 2. STORE v := top; pop; a := top; pop; memory[a] := v; 3. PUSH V push(v) 4. PUSHMT Push(mt)

5 5. SETD LL display[LL] := top; pop 6. POP n := top; pop; pop n 7. DUP n := top; pop; v := top; pushn(v) 8. BR a := top; pop; goto a 9. BF a := top; pop; v := top; jika Bv maka goto a

6 X:=top;pop Y:=top;pop Push(x op y) 10. ADD 11. SUB 12. MUL 13. DIVI
14. EQ 15. LT 16. ORI X:=top;pop Y:=top;pop Push(x op y)

7 HALT (berhenti) 17. FLIP x := top; pop; y := top; push(x); push(y)
18. READC satu karakter input dibaca dan dipush 19. PRINTC cetak top sebagai karakter; pop 20. READI baca integer n; push(n) 21. PRINTI cetak top sebagai integer; pop 22. HALT HALT (berhenti)

8 contoh 0 NAME 0 0 3 PUSHMT 4 SETD 0 6 PUSH -32768 8 NAME 0 0 11 PUSH 0
13 STORE 14 NAME 0 0 LOAD 18 PRINTI 19 PUSH 10 21 PUSH 13 23 PRINTC 24 PRINTC 25 NAME 0 0 28 NAME 0 0 31 LOAD 32 PUSH 1 34 ADD 35 STORE 36 NAME 0 0 39 LOAD 40 PUSH 14 42 FLIP 43 LT 44 PUSH 50 46 BF 47 PUSH 53 49 BR 50 PUSH 14 52 BR 53 PUSHMT 54 NAME 0 0 57 SUB 58 POP 59 SETD 0 61 HALT { var A : integer; A := 0 loop put A A := A+1 if A > 14 then exit end if end loop }

9 Untuk PR Proc and Func Please revise the parser.cup so that it accommodates the rules needed for proc and func. Please revise parts of the generate and context checker class that define the semantic action of the rules. The revision mainly accommodates the calling sequence and the return sequence.


Download ppt "Pembentukan Kode (Simulasi)"

Presentasi serupa


Iklan oleh Google