15.08.2013 Views

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

General Computer Science 320201 GenCS I & II Lecture ... - Kwarc

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

[proc 2 26,<br />

con 0, arg 2, leq, cjp 5,<br />

con 1, return,<br />

con 1, arg 2, sub, arg 1,<br />

call 0, arg 1, mul,<br />

return,<br />

con 2, con 10, call 0,<br />

halt]<br />

1<br />

22 0<br />

10 -1<br />

1 -2<br />

32<br />

10<br />

2<br />

return interprets the top of the stack as the result,<br />

it jumps to the return address memorized right below the top of the stack,<br />

deletes the current frame<br />

and puts the result back on top of the remaining stack.<br />

[proc 2 26,<br />

con 0, arg 2, leq, cjp 5,<br />

con 1, return,<br />

con 1, arg 2, sub, arg 1,<br />

call 0, arg 1, mul,<br />

return,<br />

con 2, con 10, call 0,<br />

halt]<br />

10<br />

1<br />

22 0<br />

10 -1<br />

1 -2<br />

32<br />

10<br />

2<br />

arg pushes the first argument from the (new) current frame<br />

[proc 2 26,<br />

con 0, arg 2, leq, cjp 5,<br />

con 1, return,<br />

con 1, arg 2, sub, arg 1,<br />

call 0, arg 1, mul,<br />

return,<br />

con 2, con 10, call 0,<br />

halt]<br />

10<br />

22 0<br />

10 -1<br />

1 -2<br />

32<br />

10<br />

2<br />

mul multiplies, pops the arguments and pushes the result.<br />

[proc 2 26,<br />

con 0, arg 2, leq, cjp 5,<br />

con 1, return,<br />

con 1, arg 2, sub, arg 1,<br />

call 0, arg 1, mul,<br />

return,<br />

con 2, con 10, call 0,<br />

halt]<br />

176<br />

10<br />

32 0<br />

10 -1<br />

2 -2

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!