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.

Realizing arg<br />

arg i pushes the i th argument from the current frame to the stack.<br />

use the register IN3 for the frame pointer. (extend for first frame)<br />

Realizing call<br />

label instruction effect comment<br />

〈arg〉 LOADIN 1 1 ACC : = P (VPC + 1) load i<br />

STORE 0 P (0): = ACC cache i<br />

MOVE IN3 ACC<br />

STORE 1 P (1): = FP cache FP<br />

SUBI 1<br />

SUB 0 ACC : = FP − 1 − i load argument position<br />

MOVE ACC IN3 FP: = ACC move it to FP<br />

inc IN2 SP: = SP + 1 prepare push<br />

LOADIN 3 0 ACC : = P (FP) load arg i<br />

STOREIN 2 0 P (SP): = ACC push arg i<br />

LOAD 1 ACC : = P (1) load FP<br />

MOVE ACC IN3 FP: = ACC recover FP<br />

MOVE IN1 ACC<br />

ADDI 2<br />

MOVE ACC IN1 VPC: = VPC + 2 next instruction<br />

JUMP 〈jt〉 jump back<br />

c○: Michael Kohlhase 314<br />

call p pushes the current program address, and jumps to the program address p<br />

(pushes the internal cells first!)<br />

label instruction effect comment<br />

〈call〉 MOVE IN1 ACC<br />

STORE 0 P (0): = IN1 cache current VPC<br />

inc IN2 SP: = SP + 1 prepare push for later<br />

LOADIN 1 1 ACC : = P (VPC + 1) load argument<br />

ADDI 2 24 + 3 ACC : = ACC +2 24 + 3 add displacement and skip proc a l<br />

MOVE ACC IN1 VPC: = ACC point to the first instruction<br />

LOADIN 1 − 2 ACC : = P (VPC − 2) stealing a from proc a l<br />

STOREIN 2 0 P (SP): = ACC push the number of arguments<br />

inc IN2 SP: = SP + 1 prepare push<br />

MOVE IN3 ACC ACC : = IN3 load FP<br />

STOREIN 2 0 P (SP): = ACC create anchor cell<br />

MOVE IN2 IN3 FP: = SP update FP<br />

inc IN2 SP: = SP + 1 prepare push<br />

LOAD 0 ACC : = P (0) load VPC<br />

ADDI 2 ACC : = ACC +2 point to next instruction<br />

STOREIN 2 0 P (SP): = ACC push the return address<br />

JUMP 〈jt〉 jump back<br />

c○: Michael Kohlhase 315<br />

Note that with these instructions we have maintained the linear quality. Thus the virtual machine<br />

is still linear in the speed of the underlying register machine REMA.<br />

Realizing return<br />

return takes the current frame from the stack, jumps to previous program address.<br />

(which is cached in the frame)<br />

179

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

Saved successfully!

Ooh no, something went wrong!