Java Reference
In-Depth Information
Instruction
Description
read:
Display the prompt "Enter an integer" , then input the integer and store it
in location memory[operand] .
load:
accumulator = memory[operand];
add:
accumulator += memory[operand];
halt:
This instruction displays the message
*** Simpletron execution terminated ***
Fig. 7.36 | Behavior of several SML instructions in the Simpletron.
REGISTERS:
accumulator +0000
instructionCounter 00
instructionRegister +0000
operationCode 00
operand 00
MEMORY:
0 1 2 3 4 5 6 7 8 9
0 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
10 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
20 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
30 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
40 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
50 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
60 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
70 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
80 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
90 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000 +0000
Fig. 7.37 | A sample dump.
Let's proceed with the execution of our program's first instruction—namely, the +1009 in loca-
tion 00 . As we've indicated, the switch statement simulates this task by prompting the user to enter
a value, reading the value and storing it in memory location memory[operand ]. The value is then
read into location 09 .
At this point, simulation of the first instruction is completed. All that remains is to prepare
the Simpletron to execute the next instruction. Since the instruction just performed was not a
transfer of control, we need merely increment the instruction-counter register as follows:
instructionCounter++;
This action completes the simulated execution of the first instruction. The entire process (i.e., the
instruction-execution cycle) begins anew with the fetch of the next instruction to execute.
Now let's consider how the branching instructions—the transfers of control—are simulated.
All we need to do is adjust the value in the instruction counter appropriately. Therefore, the
unconditional branch instruction ( 40 ) is simulated within the switch as
instructionCounter = operand;
The conditional “branch if accumulator is zero” instruction is simulated as
if (accumulator == 0 )
instructionCounter = operand;
 
Search WWH ::




Custom Search