5-10
DATA TYPES AND ADDRESSING MODES
Base
A base alone represents an indirect offset to the operand. Since the value in the base register can
change, it can be used for dynamic storage of variables and data structures.
Base + Displacement
A base register and a displacement can be used together for two distinct purposes:
As an index into an array when the element size is not 2, 4, or 8 bytesThe displacement
component encodes the static offset to the beginning of the array. The base register holds
the results of a calculation to determine the offset to a specific element within the array.
To access a field of a recordThe base register holds the address of the beginning of the
record, while the displacement is an static offset to the field.
An important special case of this combination is access to parameters in a procedure activation
record. A procedure activation record is the stack frame created when a procedure is entered.
Here, the EBP register is the best choice for the base register, because it automatically selects
the stack segment. This is a compact encoding for this common function.
(Index
?
Scale) + Displacement
This address mode offers an efficient way to index into a static array when the element size is 2,
4, or 8 bytes. The displacement locates the beginning of the array, the index register holds the
subscript of the desired array element, and the processor automatically converts the subscript
into an index by applying the scaling factor.
Base + Index + Displacement
Using two registers together supports either a two-dimensional array (the displacement holds the
address of the beginning of the array) or one of several instances of an array of records (the
displacement is an offset to a field within the record).
Base + (Index
?
Scale) + Displacement
Using all the addressing components together allows efficient indexing of a two-dimensional
array when the elements of the array are 2, 4, or 8 bytes in size.
5.3.3.3.ASSEMBLER AND COMPILER ADDRESSING MODES
At the machine-code level, the selected combination of displacement, base register, index
register, and scale factor is encoded in an instruction. All assemblers permit a programmer to
use any of the allowable combinations of these addressing components to address operands.
High-level language (HLL) compilers will select an appropriate combination of these compo-
nents based on the HHL construct a programmer defines.