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.

call pushes the return address (of the call statement in the L(VM) program)<br />

then it jumps to the first body instruction.<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 />

arg i pushes the i th argument onto the 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 />

Comparison turns out false, so we push 0.<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 />

cjp pops the truth value and jumps (on false).<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 />

we first push 1<br />

2<br />

0<br />

32 0<br />

10 -1<br />

2 -2<br />

0<br />

32 0<br />

10 -1<br />

2 -2<br />

32 0<br />

10 -1<br />

2 -2<br />

2<br />

1<br />

32 0<br />

10 -1<br />

2 -2<br />

then we push the second argument (from the call frame position −2)<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 />

172<br />

1<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!