SPNU118Z September 1995 – March 2023 66AK2E05 , 66AK2H06 , 66AK2H12 , 66AK2H14 , AM1705 , AM1707 , AM1802 , AM1806 , AM1808 , AM1810 , AM5K2E04 , OMAP-L132 , OMAP-L137 , OMAP-L138 , SM470R1B1M-HT , TMS470R1A288 , TMS470R1A384 , TMS470R1A64 , TMS470R1B1M , TMS470R1B512 , TMS470R1B768
Following are examples of expressions that use relocatable and absolute symbols. These examples use four symbols that are defined in the same section:
.global extern_1 ; Defined in an external module
intern_1: .word '"D' ; Relocatable, defined in current
; module
LAB1: .set 2 ; LAB1 = 2
intern_2 ; Relocatable, defined in current
; module
intern_3 ; Relocatable, defined in current
; module
The statements in this example use an absolute symbol, LAB1, which is defined to have a value of 2. The first statement loads the value 51 into R0. The second statement loads the value 27 into R0.
MOV R0, #LAB1 + ((4+3) * 7) ; R0 = 51
; 2 + ((7) * 7)
; 2 + (49) = 51
MOV R0, #LAB1 + 4 + (3*7) ; R0 = 27
; 2 + 4 + (21) = 27
The first statement in the following example is valid; the statements that follow it are invalid.
LDR R1, intern_1 - 10 ; Legal
LDR R1, 10-intern_1 ; Can't negate reloc. symbol
LDR R1, -(intern_1) ; Can't negate reloc. symbol
LDR R1, intern_1/10 ; / isn't additive operator
LDR R1, intern_1 + intern_2 ; Multiple relocatables
The first statement below is legal; although intern_1 and intern_2 are relocatable, their difference is absolute because they are in the same section. Subtracting one relocatable symbol from another reduces the expression to relocatable symbol + absolute value. The second statement is illegal because the sum of two relocatable symbols is not an absolute value.
LDR R1, intern_1 - intern_2 + intern_3 ; Legal
LDR R1, intern_1 + intern_2 + intern_3 ; Illegal
A relocatable symbol's placement in the expression is important to expression evaluation. Although the statement below is similar to the first statement in the previous example, it is illegal because of left-to-right operator precedence; the assembler attempts to add intern_1 to extern_3.
LDR R1, intern_1 + intern_3 - intern_2 ; Illegal