level | operator | operand1 | operand2 | operand3 |
Each quad will execute through the interpreter as follows:
Addressing Modes are:
Number |
Mode |
Effective Operand |
0 |
Immediate |
address |
1 |
global lvalue |
address |
2 |
global rvalue |
stack[address] |
3 |
local lvalue |
ap + address |
4 |
local rvalue |
stack[ap + address] |
Our interpreter will read information from a file as follows:
line 1 to the program end quad |
one quad per line |
next line |
the number of initialized |
next n lines |
the initial contents of these words |
The interpreter will proceed as follows:
1) read quads into memoryOur instruction set is:
2) read initial contents into memory
3) assign PC to the program begin quad
4) fetch, decode, and execute one quad at a time until program end quad
Opcode |
Operands |
Meaning |
|||
1 |
add |
op1 |
op2 |
result |
result <- op1 + op2 |
2 |
subtract |
op1 |
op2 |
result |
result <- op1 - op2 |
3 |
multiply |
op1 |
op2 |
result |
result <- op1 * op2 |
4 |
int divide |
op1 |
op2 |
result |
result <- op1 / op2 |
5 |
modulus |
op1 |
op2 |
result |
result <- op1 % op2 |
6 |
unary minus |
op1 |
|
result |
result <- -op1 |
7 |
increment |
|
|
result |
result <- result + 1 |
8 |
decrement |
|
|
result |
result <- result - 1 |
9 |
dereference |
op1 |
|
result |
results <- (op1) |
10 |
blt |
op1 |
op2 |
label |
if op1 < op2 goto label |
11 |
bgt |
op1 |
op2 |
label |
if op1 > op2 goto label |
12 |
ble |
op1 |
op2 |
label |
if op1 <= op2 goto label |
13 |
bge |
op1 |
op2 |
label |
if op1 >= op2 goto label |
14 |
bne |
op1 |
op2 |
label |
if op1 != op2 goto label |
15 |
beq |
op1 |
op2 |
label |
if op1 == op2 goto label |
16 |
band |
op1 |
op2 |
label |
if op1 and op2 goto label |
17 |
bor |
op1 |
op2 |
label |
if op1 or op2 goto label |
18 |
bnot |
op1 |
|
label |
if op1 == 0 goto label |
19 |
bra |
|
|
label |
goto label |
20 |
load parameter |
op1 |
|
|
push op1 on runtime stack |
21 |
function call |
op1 |
|
label |
op1 = # of parameters already pushed |
22 |
function begin |
op1 |
|
|
op1 = size of local data area |
23 |
function return |
|
|
|
pop activation record off stack and |
24 |
input |
op1 |
|
|
op1 = # items to be read interactively. |
25 |
output |
op1 |
|
|
op1 = # items to be output. Items written |
26 |
assign |
op1 |
|
result |
result <- op1 |
27 |
program begin |
|
|
|
marks beginning of the program |
28 |
program end |
|
|
|
end execution |