|
|||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Technical Support On-Line Manuals Compiler Reference Guide ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() ![]() |
Assembly expressions
B7.2 Assembly expressionsExpressions consist of one or more integer literals or symbol references, combined using operators. You can use an expression when an instruction operand or directive argument expects an integer value or label. Not all instruction operands and directive arguments accept all possible expressions. For example, the alignment directives require an absolute expression for the boundary to align to. Therefore, alignment directives cannot accept expressions involving labels, but can accept expressions involving only integer constants. On the other hand, the data definition directives can accept a wider range of expressions, including references to defined or undefined symbols. However, the types of expressions accepted is still limited by the ELF relocations available to describe expressions involving undefined symbols. For example, it is not possible to describe the difference between two symbols defined in different sections. The assembler reports an error when an expression is not valid in the context in which it is used. Expressions involving integer constants are evaluated as signed 64-bit values internally to the assembler. If an intermediate value in a calculation cannot be represented in 64 bits, the behavior is undefined. The assembler does not currently emit a diagnostic when this happens. ConstantsNumeric literals are accepted in the following formats:
Some directives accept values larger than Note:These ranges do not include negative numbers. Negative numbers can instead be represented using the unary operator,- . Symbol ReferencesReferences to symbols are accepted as expressions. Symbols do not need to be defined in the same assembly language source file, to be referenced in expressions. The period symbol ( For AArch32 targets, a symbol reference might optionally be followed by a modifier in parentheses. The following modifiers are supported: Table B7-1 Modifiers
OperatorsThe following operators are valid expressions: Table B7-2 Unary operators
Table B7-3 Binary operators
Table B7-4 Binary logical operators
Table B7-5 Binary bitwise operators
Table B7-6 Binary comparison operators
The order of precedence for binary operators is as follows, with highest precedence operators listed first:
Operators listed on the same line have equal precedence, and are evaluated from left to right. All unary operators have higher precedence than any binary operators. Note:The precedence rules for assembler expressions are not identical to those for C.Relocation specifiersFor some instruction operands, a relocation specifier might be used to specify which bits of the expression should be used for the operand, and which type of relocation should be used. These relocation specifiers can only be used at the start of an expression. They can only be used in operands of instructions that support them. In AArch32 state, the following relocation specifiers are available: Table B7-7 Relocation specifiers for AArch32 state
These relocation specifiers are only valid for the operands of the In AArch64 state, the following relocation specifiers are available: Table B7-8 Relocation specifiers for AArch64 state
These relocation specifiers can only be used in the operands of instructions that have matching relocations defined in ELF for the Arm 64-bit Architecture (AArch64). They can be combined with an expression involving the current place to create a place-relative relocation. Examples// Using an absolute expression in an instruction operand: orr r0, r0, #1<<23 // Using an expression in the memory operand of an LDR instruction to // reference an offset from a symbol. func: ldr r0, #data+4 // Will load 2 into r0 bx lr data: .word 1 .word 2 // Creating initialized data that contains the distance between two // labels: size: .word end - start start: .word 123 .word 42 .word 4523534 end: // Load the base-relative address of 'sym' (used for 'RWPI' // position-independent code) into r0 using movw and movt: movw r0, #:lower16:sym(sbrel) movt r0, #:upper16:sym(sbrel) // Load the address of 'sym' from the GOT using ADRP and LDR (used for // position-independent code on AArch64): adrp x0, #:got:sym ldr x0, [x0, #:got_lo12:sym] // Constant pool entry containing the offset between the location and a // symbol defined elsewhere. The address of the symbol can be calculated // at runtime by adding the value stored in the location of the address // of the location. This is one technique for writing position- // independent code, which can be executed from an address chosen at // runtime without re-linking it. adr r0, address ldr r1, [r0] add r0, r0, r1 address: .word extern_symbol - . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Arm’s Privacy Policy has been updated. By continuing to use our site, you consent to Arm’s Privacy Policy. Please review our Privacy Policy to learn more about our collection, use and transfers
of your data.