SLAU131Y October 2004 – June 2021
The assembler supports MSP430-specific ELF relocation generating built-in operators. The operators are used in compiler-generated code to support symbolic addressing of objects.
$HI16 and $LO16 create an ELF relocation representing the high and low 16 bits respectively of a link-time constant (such as an address). These operators are sometimes necessary when treating a 20-bit data or function pointer as a 32-bit unsigned long value.
The argument to these operators must be a relocatable constant expression.
Example:
The following C function, when compiled for EABI in large data model, will generate the following assembly code to load the appropriate 32-bit value into the return registers.
/* cl430 --abi=eabi -ml -vmspx */
extern int xyz;
unsigned long func() { return _symval(&xyz); }
MOV.W #$LO16(xyz),r12
MOV.W #$HI16(xyz),r13 ; after this instruction, the register
; pair r13:r12 holds the 32-bit value of &x.
RETA