Hi I need a review on a STACK MACHINE CODE.
There is this language called Simple, small language, used for helping studetns on understanding compiler construction.
So I have an example of the language in this little code:
CODE
let
integer a, b, c, d.
in
d:=10;
c:=1;
while c>0
do c:=2*c;
end;
write c;
end
so the stack machine for this code IS:
CODE
0: DATA 3
1: LD_INT 10
2: STORE 3
3: LD_INT 1
4: STORE 2
5: LD_VAR 2
6: LD_INT 0
7: LT 0
8: JUMP_FALSE 14
9: LD_INT 2
10: LD_VAR 2
11: MULT 0
12: STORE 2
13: GOTO 5
14: LD_VAR 2
15: WRITE 0
16: HALT 0
I need a review about the stack machine code of this code:
CODE
let
integer x, y, n.
in
read n;
y:=1;
repeat
y:=y*5;
x:=x+1;
until x>n
write y;
end
bellow is the code I wrote and I need a review:
CODE
0: DATA 2
1: READ 0
2: STORE 2
3: LD_INT 1
4: STORE 1
5: LD_VAR 1
6: LD_INT 5
7: MULT 0
8: STORE 2
9: LD_VAR 0
10: LD_INT 1
11: ADD 0
12: STORE 1
13: LD_VAR 1
14: LD_VAR 3
15: LT 0
16: JUMP_FALSE 18
17: GOTO 5
18: WRITE 1
19: HALT 0
I hope I'm making any sense if not pls do let me know.
Anybody? Thanks in advance.
This post has been edited by PennyBoki: 5 Sep, 2007 - 12:10 PM