B-10 Appendix B Instruction Set Principles and Examples
modes (even though the value they access is in the instruction stream), although
registers are often separated since they don’t normally have memory addresses.
We have kept addressing modes that depend on the program counter, called PC-
relative addressing, separate. PC-relative addressing is used primarily for speci-
fying code addresses in control transfer instructions, discussed in Section B.6.
Figure B.6 shows the most common names for the addressing modes, though
the names differ among architectures. In this figure and throughout the book, we
will use an extension of the C programming language as a hardware description
notation. In this figure, only one non-C feature is used: The left arrow (←) is used
for assignment. We also use the array Mem as the name for main memory and the
array Regs for registers. Thus, Mem[Regs[R1]] refers to the contents of the memory
location whose address is given by the contents of register 1 (R1). Later, we will
introduce extensions for accessing and transferring data smaller than a word.
Addressing modes have the ability to significantly reduce instruction counts;
they also add to the complexity of building a computer and may increase the
average CPI (clock cycles per instruction) of computers that implement those
modes. Thus, the usage of various addressing modes is quite important in helping
the architect choose what to include.
Figure B.7 shows the results of measuring addressing mode usage patterns in
three programs on the VAX architecture. We use the old VAX architecture for a
few measurements in this appendix because it has the richest set of addressing
modes and the fewest restrictions on memory addressing. For example, Figure
B.6 on page B-9 shows all the modes the VAX supports. Most measurements in
this appendix, however, will use the more recent register-register architectures to
show how programs use instruction sets of current computers.
As Figure B.7 shows, displacement and immediate addressing dominate
addressing mode usage. Let’s look at some properties of these two heavily used
modes.
Displacement Addressing Mode
The major question that arises for a displacement-style addressing mode is that of
the range of displacements used. Based on the use of various displacement sizes,
a decision of what sizes to support can be made. Choosing the displacement field
sizes is important because they directly affect the instruction length. Figure B.8
shows the measurements taken on the data access on a load-store architecture
using our benchmark programs. We look at branch offsets in Section B.6—data
accessing patterns and branches are different; little is gained by combining them,
although in practice the immediate sizes are made the same for simplicity.
Immediate or Literal Addressing Mode
Immediates can be used in arithmetic operations, in comparisons (primarily for
branches), and in moves where a constant is wanted in a register. The last case
occurs for constants written in the code—which tend to be small—and for