Compiler Stack Machine Code review

liunx

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