Hardware Reference
In-Depth Information
Step
Remaining string
Instruction
Stack
1
825 × +132 × +4 /
BIPUSH 8
8
2 5
×
+132
×
+4
/
BIPUSH 2
8, 2
3 × +132 × +4 /
BIPUSH 5
8, 2, 5
4
× +132 × +4 /
IMUL
8, 10
5
+132
×
+4
/
IADD
18
6
132 × +4 /
BIPUSH 1
18, 1
7 2
×
+4
/
BIPUSH 3
18, 1, 3
8 × +4 /
BIPUSH 2
18, 1, 3, 2
9
× +4 /
IMUL
18, 1, 6
10
+ 4
/
IADD
18, 7
11
4 /
BIPUSH 4
18, 7, 4
12
/
ISUB
18, 3
13
/
IDIV
6
Figure 5-23. Use of a stack to evaluate a reverse Polish notation formula.
Another option is PC -relative addressing. In this mode, the (signed) offset in
the instruction itself is added to the program counter to get the target address. In
fact, this is simply indexed mode, using PC as the register.
5.4.10 Orthogonality of Opcodes and Addressing Modes
From a software point of view, instructions and addressing should have a regu-
lar structure, with a minimum number of instruction formats. Such a structure
makes it much easier for a compiler to produce good code. All opcodes should
permit all addressing modes wherever that makes sense. Furthermore, all registers
should be available for all register modes [including the frame pointer ( FP ), stack
pointer ( SP ), and program counter ( PC )].
As an example of a clean design for a three-address machine, consider the
32-bit instruction formats of Fig. 5-24. Up to 256 opcodes are supported. In for-
mat 1, each instruction has two source registers and a destination register. All
arithmetic and logical instructions use this format.
The unused 8-bit field at the end can be used for further instruction dif-
ferentiation. For example, one opcode could be allocated for all the floating-point
operations, with the extra field distinguishing among them. In addition, if bit 23 is
set, format 2 is used and the second operand is no longer a register but a 13-bit
signed immediate constant. LOAD and STORE instructions can also use this format
to reference memory in indexed mode.
A small number of additional instructions are needed, such as conditional
branches, but they could easily fit in format 3. For example, one opcode could be
 
 
Search WWH ::




Custom Search