Explicit-based addressing
Explicit-based addresses are specified as a base register number, RA, and a displacement, D
Explicit-based addresses are specified as a base register number, RA, and a displacement, D. The base register holds a base address. At run time, the processor adds the displacement to the contents of the base register to obtain the effective address. If an instruction does not have an operand form of D(RA), then the instruction cannot have an explicit-based address. Error 159 is reported if the D(RA) form is used for these instructions.
A displacement can be an absolute expression, a relocatable expression, a restricted external expression, or a TOC-relative expression. A displacement can be an external expression only if it is a csect (control section) name or the name of a common block specified defined by a .comm pseudo-op.
- An externalized label is still relocatable, so an externalized label can also be used as a displacement.
- When a relocatable expression is used for the displacement, no RLD entry is generated, because only the offset from the label (that is, the relocatable expression) for the csect is used for the displacement.
Although programmers must use an absolute expression to specify the base register itself, the contents of the base register can be specified by an absolute, a relocatable, or an external expression. If the base register holds a relocatable value, the effective address is relocatable. If the base register holds an absolute value, the effective address is absolute. If the base register holds a value specified by an external expression, the type of the effective address is absolute if the expression is eventually defined as absolute, or relocatable if the expression is eventually defined as relocatable.
When using explicit-based addressing, remember that:
- GPR 0 cannot be used as a base register. Specifying 0 tells the assembler not to use a base register at all.
- Because D occupies a maximum of 16 bits, a displacement
must be in the range -2**15 to (2**15)-1. Therefore, the difference
between the base address and the address of the item to which reference
is made must be less than 2**15 bytes. Note: D and RA are required for the D(RA) form. The form 0(RA) or D(0) may be used, but both the D and RA operands are required. There are two exceptions:
- When D is an absolute expression,
- When D is a restricted external expression.