Download Assemblers and Loaders

Transcript
256 Addressing Modes
Append. A
(and to other arguments), and that the function itself depends on the mode m. So
for different modes we have different functions, different ways of calculating the
EA. We will see that those functions depend on things like the PC, index registers,
and the contents of memory locations. The notation EA = fm (displacement, . . .)
therefore illustrates the nature of addressing modes.
Before looking at specific modes, it is important to mention the second property
of addressing modes. They serve to make the machine instructions more powerful.
We will see examples where a single instruction, using a powerful mode, can do the
work of several instructions.
A.2 Examples of Modes
We will start by describing the main addressing modes, and follow by a brief
discussion of less important ones.
The five main addressing modes, found on all modern computers and many old
ones, are: direct, relative, immediate, index, and indirect.
A.2.1 The Direct mode
When an instruction uses a small address, an address that fits in the displacement field, there is no need for any calculations and the EA is simply the displacement. This is the direct mode. It is a simple mode and, in the form described here,
used only by absolute assemblers. A typical example is:
LC
0
19
xx
Obj. Code
A
.
.
..
.
.
MUL A
Opc m dis
xxx 0 19
Since the value of A is a small number, the assembler uses the direct mode
for the MUL instruction. It should again be emphasized that the assembler does not
need to know what the MUL instruction is, how it works, or even the precise meaning
of the direct mode. It follows a simple rule that says: if the value of the symbol is <
the maximum value of the displacement field, put the symbol in the displacement
field and set the mode field to 0 (or whatever the code for direct mode is). This,
however, implies that the instruction cannot be relocated by the loader. Assuming
that the loader decides to load the program starting at address 1000, it would want
to relocate the displacement field to 1019, which may be too large. This mode is
thus not useful in a relocatable assembler but, as we will see later, certain versions
of it are.
Exercise A.2 What if A is a future symbol. Does that generate a problem for the
assembler?