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

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

the L(VM) program store: P (2 24 ) to P (2 32 − 1)<br />

We represent the virtual program counter VPC by the index register IN1 and the stack<br />

pointer by the index register IN2 (with offset 8).<br />

We will use P (0) as an argument store.<br />

choose a numerical representation for the L(VM) instructions: (have lots of space)<br />

halt ↦→ 0, add ↦→ 1, sub ↦→ 2, . . .<br />

c○: Michael Kohlhase 287<br />

Recall that the virtual machine VM is a ASM program, so it will reside in the REMA program store.<br />

This is the program executed by the register machine. So both the VM stack and the L(VM) program<br />

have to be stored in the REMA data store (therefore we treat L(VM) programs as sequences of words<br />

and have to do counting acrobatics for instructions of differing length). We somewhat arbitrarily<br />

fix a boundary in the data store of REMA at cell number 2 24 − 1. We will also need a little piece<br />

of scratch-pad memory, which we locate at cells 0-7 for convenience (then we can simply address<br />

with absolute numbers as addresses).<br />

Memory Layout for the Virtual Machine<br />

Program Store<br />

Operation Argument<br />

2n−bit Cells<br />

CPU<br />

ACC (accumulator)<br />

IN1 (VM prog. cnt.)<br />

IN2 (stack pointer)<br />

IN3 (frame pointer)<br />

PC (program counter)<br />

ASM Program<br />

for VM<br />

Program<br />

Stack<br />

Scratch Area<br />

c○: Michael Kohlhase 288<br />

Data Store<br />

n−bit Cells<br />

To make our implementation of the virtual more convenient, we will extend ASM with a couple of<br />

convenience features. Note that these features do not extend the theoretical expressivity of ASM<br />

(i.e. they do not extend the range of programs that ASM), since all new commands can be replaced<br />

by regular language constructs.<br />

Extending REMA and ASM<br />

Give ourselves another register IN3 (and LOADIN 3, STOREIN 3, MOVE ∗ IN3, MOVE IN3 ∗)<br />

We will use a syntactic variant of ASM for transparency<br />

JUMP and JUMPR with labels of the form 〈foo〉<br />

(compute relative jump distances automatically)<br />

inc R for MOVE R ACC, ADDI 1, MOVE ACC R (dec R similar)<br />

note that inc R and dec R overwrite the current ACC (take care of it)<br />

All additions can be eliminated by substitution.<br />

161

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

Saved successfully!

Ooh no, something went wrong!