Hardware Reference
In-Depth Information
If the IJVC opcode is
DUP
,
POP
,or
SWAP
, the stack must be adjusted. The
DUP
instruction simply replicates the top word of the stack. Since the value of this
word is already stored in
TOS
, the operation is as simple as incrementing
SP
to
point to the new location and storing
TOS
to that location. The
POP
instruction is
almost as simple, just decrementing
SP
to discard the top word on the stack. How-
ever, in order to maintain the top word in
TOS
it is now necessary to read the new
top word in from memory and write it into
TOS
. Finally, the
SWAP
instruction
involves swapping the values in two memory locations: the top two words on the
stack. This is made somewhat easier by the fact that
TOS
already contains one of
those values, so it need not be read from memory. This instruction will be dis-
cussed in more detail later.
The
BIPUSH
instruction is a little more complicated because the opcode is fol-
lowed by a single byte, as shown in Fig. 4-18. The byte is to be interpreted as a
signed integer. This byte, which has already been fetched into
MBR
in
Main1
, must
be sign-extended to 32 bits and pushed onto the top of the stack. This sequence,
therefore, must sign-extend the byte in
MBR
to 32 bits, and copy it to
MDR
. Finally,
SP
is incremented and copied to
MAR
, permitting the operand to be written out to
the top of stack. Along the way, this operand must also be copied to
TOS
. Note
that before returning to the main program,
PC
must be incremented and a fetch op-
eration started so that the next opcode will be available in
Main1
.
BIPUSH
(0
BYTE
10)
×
Figure 4-18.
The
BIPUSH
instruction format.
Next consider the
ILOAD
instruction.
ILOAD
also has a byte following the op-
code, as shown in Fig. 4-19(a), but this byte is an (unsigned) index to identify the
word in the local variable space that is to be pushed onto the stack. Since there is
only 1 byte, only 2
8
256 words can be distinguished, namely, the first 256 words
in the local variable space. The
ILOAD
instruction requires both a read (to obtain
the word) and a write (to push it onto the top of the stack). In order to determine
the address for reading, however, the offset, contained in
MBR
, must be added to
the contents of
LV
. Since both
MBR
and
LV
can be accessed only through the B bus,
first
LV
is copied into
H
(in
iload1
), then
MBR
is added. The result of this addition
is copied into
MAR
and a read initiated (in
iload2
).
=
ILOAD
(0x15)
WIDE
(0xC4)
ILOAD
(0x15)
INDEX
BYTE 1
INDEX
BYTE 2
INDEX
(b)
(a)
Figure 4-19.
(a)
ILOAD
with a 1-byte index. (b)
WIDE ILOAD
with a 2-byte index.