la R, Label
loads the 32 bit address of Label into register R. TAL has no la instruction and requires two instructions to synthesize a 32 bit address in a register. The lui (load upper immediate) and ori (or immediate) instructions are used to load a 32 bit address in two 16 bit pieces:
lui R, hi_bits ori R, lo_bits
The assembler divides the address of Label into two 16 bit half-words, consisting of the most and least significant halves, called hi_bits and lo_bits. The lui instruction places the most significant 16 bits of the address into the upper half of register R and clears the lower half of R. The ori instruction ORs the least significant 16 bits into the lower half of R, leaving the upper 16 bits unchanged.
For example, suppose that the address of Label is 0x1001 0004. The MAL instruction
la $12, Label
can be synthesized from the TAL instructions
lui $12, 0x1001 ori $12, 0x0004
The information needed to synthesize the la instruction is the address assigned to Label. The assembler produces a symbol table containing labels and their assigned addresses for this purpose.
With the exception of the la instruction, all MAL load/store instructions have corresponding TAL instructions. The TAL load and store instructions all use base-displacement addressing of the form:
lw R, I(B)
where R is the source or destination register, B is the base register, and I is an immediate constant which is added to the contents of B to form the effective address.
The size of the immediate constant, I, is 16 bits in TAL instructions. When a MAL load/store instruction uses a label with an address that is longer than 16 bits, the instruction must be synthesized. For example, the MAL instruction:
lw $10, Label
is equivalent to:
la $10, Label lw $10, 0($10)
The MAL la instruction must be synthesized in TAL to give
lui $10, hi_bits ori $10, lo_bits lw $10, 0($10)
where hi_bits and lo_bits are the upper and lower halves of the 32 bit address assigned to Label.
Note that in the load operation, the address can be synthesized in the register which is loaded. In store operations, a separate register must be used for the destination address. For example, the MAL instruction:
sw $10, Label
could be synthesized as:
lui $1, hi_bits ori $1, lo_bits sw $10, 0($1)
The assembler uses register $1 ($at) as a temporary register when forming the destination address for the store operation.