X = (A + B * C) / (D - E * F)
for each of the four machines. The instructions available for use are as follows:
3 Address - assume instructions can access operands in memory | 2 Address - assume instructions can access operands in memory | 1 Address (Accumulator machine - one register the "accumulator") |
0 Address (Stack machine - no registers) |
MOVE (X Y) | MOVE (X Y) | LOAD M | PUSH M |
POP M |   | STORE M | POP M |
ADD (X Y + Z) | ADD (X X + Y) | ADD M | ADD |
SUB (X Y - Z) | ADD (X X - Y) | SUB M | SUB |
MUL (X Y * Z) | MUL (X X * Y) | MUL M | MUL |
DIV (X Y / Z) | DIV (X X / Y) | DIV M | DIV |
3-Address Program |
2-Address Program | 1-Address Program | 0-Address Program |
2) Writing the program to compute X = (A + B * C) / (D - E * F) on a Load/Store machine.
Load/Store Machine arithmetic instructions only access register operands |
Load and Store Program |
LOAD R1, M | |
STORE R1, M | |
MOVE (R2 R1) | |
ADD (R3 R2 + R1) | |
SUB (R3 R2 - R1) | |
MUL (R3 R2 * R1) | |
DIV (R3 R2 / R1) |
3) Write a test-and-jump template for the following while-loop:
while (x >= y) do
// body of while
end while
4) Write a test-and-jump template for the following do-while-loop:
do
// body of do-while
while (x < y)
5) Write a test-and-jump template for the following if-then-else statement:
if (x > z) and (z < y) then
// then-body
else
// else-body
end if
6) Write a test-and-jump template for the following if-then-else statement:
if (x > z) or (z < y) then
// then-body
else
// else-body
end if