Immediate Addressing
A high percentage of arithmetic operations involve one
constant operand.Without special
instructions, all of the constants would have to be loaded into memory
locations before they could be used.MIPS
provides a set of instructions that contain the constant operand inside the
operation itself, using the I-type or immediate format.
op – operation code (6 bits)
|
rs – target location (5 bits)
|
rt – first operand
(5 bits)
|
Constant – second operand (16 bits)
|
I-type format
Using this instruction format, any constant that can be
represented in 16 bits can be added to a register.Constants larger than 16 bits must be loaded into a register, using the
lui
instruction to load the high 16-bits and then the
addi
instruction to add the last 16 bits.
Register Addressing
Register addressing is used in arithmetic functions
when the value for the operand is translated into the number of the register to
access.
Base Addressing
Base or displacement addressing is used
in data transfer functions.A byte-offset
is added to a register to determine what value should be loaded or stored.
PC-relative Addressing
The I-type format is used by branch and transfer instructions,
with the constant field being used as the low bits of the address where control
should be transferred.Since all MIPS
instructions are stored on word boundaries, there is no need to access
individual bytes within an instruction when transferring control.Thus,
the last 16 bits of a branch or transfer instruction are used as an offset, and
are added to the program counter.This is
called PC-relative addressing.
Since MIPS instructions are stored on word boundaries, there
is no need to access individual bytes when transferring control.Thus
the operand in branch, transfer, jump, and jump-and-link instructions is a word
value.In the case of branch instructions, this allows them to reach new operations within ±215
words of the current location, or four times as far as if byte-offsets were
used.Branch instructions are usually
found in if-then-else constructs and loops, and almost all of these constructs
can fit in 216 words.
Pseudodirect Addressing
Jump and jump-and-link instructions use a different
instruction format, J-type.
Op – operation code (6 bits)
|
Target address (26 bits)
|
The target address is absolute on jumps and jump-and-links,
but is still word based.This means that
the highest four bits of the PC are concatenated to the low 28 bits determined
by the target address word value.This is
called pseudodirect addressing.
References:
Hennesey, John L. and David A.
Patterson (1998). Computer Organization and Design: the Hardware/Software
Interface (2nd ed.). San Francisco: Morgan Kaufmann.
|