Hardware Reference
In-Depth Information
but since
IFLT
pops a word off the stack, the new top of stack must be read in to
store in
TOS
. This read is started in
iflt1
.In
iflt2
, the word to be tested is saved in
OPC
for the moment, so the new value can be put in
TOS
shortly without losing the
current one. In
iflt3
the new top-of-stack word is available in
MDR
, so it is copied
to
TOS
. Finally, in
iflt4
the word to be tested, now saved in
OPC
, is run through the
ALU without being stored and the
N
bit latched and tested. This microinstruction
also contains a branch, choosing either
T
if the test was successful or
F
otherwise.
If successful, the remainder of the operation is essentially the same as at the
beginning of the
GOTO
instruction, and the sequence simply continues in the mid-
dle of the
GOTO
sequence, with
goto2
. If unsuccessful, a short sequence (
F
,
F2
,
and
F3
) is necessary to skip over the rest of the instruction (the offset) before re-
turning to
Main1
to continue with the next instruction.
The code in
ifeq2
and
ifeq3
follows the same logic, only using the
Z
bit instead
of the
N
bit. In both cases, it is up to the assembler for
MAL
to recognize that the
addresses
T
and
F
are special and to make sure that their addresses are placed at
control store addresses that differ only in the leftmost bit.
The logic for
IF ICMPEQ
is roughly similar to
IFEQ
except that here we need to
read in the second operand as well. It is stored in
H
in
if icmpeq3
, where the read
of the new top-of-stack word is started. Again the current top-of-stack word is
saved in
OPC
and the new one installed in
TOS
. Finally, the test in
if icmpeq6
is
similar to
ifeq4
.
Now, we consider the implementation of
INVOKEVIRTUAL
and
IRETURN
, the in-
structions for invoking a procedure call and return, as described in Sec. 4.2.3.
INVOKEVIRTUAL
, a sequence of 22 microinstructions, is the most complex IJVM in-
struction implemented. Its operation was shown in Fig 4-12. The instruction uses
its 16-bit offset to determine the address of the method to be invoked. In our im-
plementation, the offset is simply an offset into the constant pool. This location in
the constant pool points to the method to be invoked. Remember, however, that the
first 4 bytes of each method are
not
instructions. Instead they are two 16-bit point-
ers. The first one gives the number of parameter words (including
OBJREF
—see
Fig. 4-12). The second one gives the size of the local variable area in words.
These fields are fetched through the 8-bit port and assembled just as if they were
two 16-bit offsets within an instruction.
Then, the linkage information necessary to restore the machine to its previous
state—the address of the start of the old local variable area and the old
PC
—is stor-
ed immediately above the newly created local variable area and below the new
stack. Finally, the opcode of the next instruction is fetched and
PC
is incremented
before returning to
Main1
to begin the next instruction.
IRETURN
is a simple instruction containing no operands. It simply uses the ad-
dress stored in the first word of the local variable area to retrieve the linkage infor-
mation. Then it restores
SP
,
LV
, and
PC
to their previous values and copies the re-
turn value from the top of the current stack onto the top of the original stack, as
shown in Fig 4-13.