| |||
| Home > Symbols, Literals, Expressions, and Operators > Register-relative and PC-relative expressions | |||
Addresses can be represented as a register-relative or PC-relative expression.
A register-relative expression evaluates to a named register combined with a numeric expression.
A PC-relative expression is written in source code as the
PC or a label combined with a numeric expression. It can also be
expressed in the form [PC, #number]. It is
represented in the instruction as the PC value plus or minus a numeric
offset. The assembler calculates the required offset from the label
and the address of the current instruction. If the offset is too
big, the assembler produces an error.
It is recommended to write PC-relative expressions using labels rather than PC because the value of PC depends on the instruction set.
In ARM state, the value of the PC is the address of the current instruction plus 8 bytes.
In Thumb state:
For B, BL, CBNZ,
and CBZ instructions, the value of the PC is the address
of the current instruction plus 4 bytes.
For all other instructions that use labels, the value of the PC is the address of the current instruction plus 4 bytes, with bit[1] of the result cleared to 0 to make it word-aligned.
LDR r4,=data+4*n ; n is an assembly-time variable
; code
MOV pc,lr
data DCD value_0
; n-1 DCD directives
DCD value_n ; data+4*n points here
; more DCD directives