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.

we subtract<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 />

32 0<br />

10 -1<br />

2 -2<br />

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

call jumps to the first body instruction,<br />

22 0<br />

10 -1<br />

1 -2<br />

32<br />

10<br />

2<br />

and pushes the return address (22 this time) 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 />

we augment 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 />

1<br />

0<br />

22 0<br />

10 -1<br />

1 -2<br />

32<br />

10<br />

2<br />

22 0<br />

10 -1<br />

1 -2<br />

32<br />

10<br />

2<br />

we compare the top two, and jump ahead (on false)<br />

173

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

Saved successfully!

Ooh no, something went wrong!