Relocation operands are generally useful in three situations:
Some macro instructions (for example, lda) require special coordination between the machine-code instructions and the relocation sequences given to the linker. By using the macro instructions, the assembler programmer relies on the assembler to generate the appropriate relocation sequences.
In some instances, the use of macro instructions may be undesirable. For example, a compiler that supports the generation of assembly language files may not want to defer instruction scheduling to the assembler. Such a compiler will want to schedule some or all of the machine-code instructions. To do this, the compiler must have a mechanism for emitting an object file's relocation sequences without using macro instructions. The mechanism for establishing these sequences is the relocation operand. A relocation operand is placed after the normal operand on an assembly language statement, as illustrated below:
opcode operand relocation_operand
The syntax of the relocation_operand is as follows:
![[relocation_type!]] sequence_number
Relocation type
The following table lists relocation_type values:
Relocation type | Windows NT description |
braddr | Branch address. |
hint | Jump hint. |
poffset | Procedure offset. |
refhi | High reference. Associated with an ldah instruction, this is normally accompanied by a pair relocation. |
Sechi | Similar to refhi. This is for use by TLS. |
Reflo | This is associated with a load, store, or lda instruction. The associated instruction may be the target of a pair relocation. |
Seclo | Similar to reflo. This is for use by TLS. |
Reflong | Longword relative reference. This is used when the address of a symbol is stored by a .long directive. |
Refquad | Quadword relative reference. This is used when the address of a symbol is stored by a .quad directive. |
Snum | Section number. |
soffset | Section offset. |
The relocation types must be enclosed within a pair of exclamation points (!) and are not case sensitive. Only refhi, sechi, reflo, and seclo are useful in the Alpha assembler.
Sequence number
The sequence_number value is a positive integer constant with a value range of 1 to 2147483647. The sequence number may be specified in decimal, hex, or octal notations.
The following examples contain relocation operands in the source code:
# Equivalent C statement:
# extern __int64 sym1, sym2;
# sym1 += sym2;
Assembly statements containing macro instructions:
ldq $1, sym1
ldq $2, sym2
addq $1, $2, $3
stq $3, sym1
Assembly statements containing machine-code instructions requiring relocation operands:
In the Alpha assembler, an ldah instruction using a symbol without a relocation operand will produce a syntax error. By using the relocation operands, an ldah instruction is eliminated.
ldah $4, sym1!refhi!1 # Load high value for sym1.
ldah $5, sym2!refhi!2 # Load high value for sym2.
ldq $1, sym1($4)!reflo!1 # Load sym1. Paired to ldah.
ldq $2, sym2($5)!reflo!2 # Load sym2. Paired to ldah.
addq $1, $2, $3
stq $3, sym1($4)!reflo!1 # Store value in sym1 unpaired.