Java Reference
In-Depth Information
Operation code
Meaning
Input/output operations:
final int
READ
=
10
;
Read a word from the keyboard into a specific location in memory.
final int
WRITE
=
11
;
Write a word from a specific location in memory to the screen.
Load/store operations:
final int
LOAD
=
20
;
Load a word from a specific location in memory into the accumulator.
final int
STORE
=
21
;
Store a word from the accumulator into a specific location in memory.
Arithmetic operations:
final int
ADD
=
30
;
Add a word from a specific location in memory to the word in the
accumulator (leave the result in the accumulator).
final int
SUBTRACT
=
31
;
Subtract a word from a specific location in memory from the word in
the accumulator (leave the result in the accumulator).
final int
DIVIDE
=
32
;
Divide a word from a specific location in memory into the word in
the accumulator (leave result in the accumulator).
final int
MULTIPLY
=
33
;
Multiply a word from a specific location in memory by the word in
the accumulator (leave the result in the accumulator).
Transfer-of-control operations:
final int
BRANCH
=
40
;
Branch to a specific location in memory.
final int
BRANCHNEG
=
41
;
Branch to a specific location in memory if the accumulator is negative.
final int
BRANCHZERO
=
42
;
Branch to a specific location in memory if the accumulator is zero.
final int
HALT
=
43
;
Halt. The program has completed its task.
Fig. 7.33
|
Simpletron Machine Language (SML) operation codes.
The first SML program (Fig. 7.34) reads two numbers from the keyboard and computes and
displays their sum. The instruction
+1007
reads the first number from the keyboard and places it
into location
07
(which has been initialized to 0). Then instruction
+1008
reads the next number
into location
08
. The
load
instruction,
+2007
, puts the first number into the accumulator, and the
add
instruction,
+3008
, adds the second number to the number in the accumulator.
All SML arith-
metic instructions leave their results in the accumulator.
The
store
instruction,
+2109
, places the result
back into memory location
09
, from which the
write
instruction,
+1109
, takes the number and dis-
plays it (as a signed four-digit decimal number). The
halt
instruction,
+4300
, terminates execution.
Location
Number
Instruction
00
(Read A)
+1007
01
(Read B)
+1008
02
(Load A)
+2007
03
(Add B)
+3008
04
(Store C)
+2109
Fig. 7.34
|
SML program that reads two integers and computes their sum. (Part 1 of 2.)