Keil Logo

Technical Support

On-Line Manuals

Compiler Reference Guide

Preface Arm Compiler Tools Overview armclang Reference armclang Command-line Options Summary of armclang command-line options -C (armclang) -c (armclang) -D -E -e -fbare-metal-pie -fbracket-depth=N -fcommon, -fno-common -fdata-sections, -fno-data-sections -ffast-math, -fno-fast-math -ffixed-rN -ffp-mode -ffunction-sections, -fno-function-sections -fident, -fno-ident @file -fldm-stm, -fno-ldm-stm -fno-builtin -fno-inline-functions -flto, -fno-lto -fexceptions, -fno-exceptions -fomit-frame-pointer, -fno-omit-frame-pointer -fpic, -fno-pic -fropi, -fno-ropi -fropi-lowering, -fno-ropi-lowering -frwpi, -fno-rwpi -frwpi-lowering, -fno-rwpi-lowering -fsanitize -fshort-enums, -fno-short-enums -fshort-wchar, -fno-short-wchar -fstack-protector, -fstack-protector-all, -fstack- -fstrict-aliasing, -fno-strict-aliasing -fsysv, -fno-sysv -ftrapv -fvectorize, -fno-vectorize -fvisibility -fwrapv -g, -gdwarf-2, -gdwarf-3, -gdwarf-4 (armclang) -I -include -L -l -M, -MM -MD, -MMD -MF -MG -MP -MT -march -marm -masm -mbig-endian -mbranch-protection -mcmodel -mcmse -mcpu -mexecute-only -mfloat-abi -mfpu -mimplicit-it -mlittle-endian -mno-neg-immediates -moutline, -mno-outline -mpixolib -munaligned-access, -mno-unaligned-access -mthumb -nostdlib -nostdlibinc -o (armclang) -O (armclang) -pedantic -pedantic-errors -Rpass -S -save-temps -shared (armclang) -std --target -U -u (armclang) -v (armclang) --version (armclang) --version_number (armclang) --vsn (armclang) -W -Wl -Xlinker -x (armclang) -### Compiler-specific Keywords and Operators Compiler-specific keywords and operators __alignof__ __asm __declspec attributes __declspec(noinline) __declspec(noreturn) __declspec(nothrow) __inline __promise __unaligned Global named register variables Compiler-specific Function, Variable, and Type Att Function attributes __attribute__((always_inline)) function attribute __attribute__((cmse_nonsecure_call)) function attr __attribute__((cmse_nonsecure_entry)) function att __attribute__((const)) function attribute __attribute__((constructor(priority))) function at __attribute__((format_arg(string-index))) function __attribute__((interrupt("type"))) function attrib __attribute__((malloc)) function attribute __attribute__((naked)) function attribute __attribute__((noinline)) function attribute __attribute__((nonnull)) function attribute __attribute__((noreturn)) function attribute __attribute__((nothrow)) function attribute __attribute__((pcs("calling_convention"))) functio __attribute__((pure)) function attribute __attribute__((section("name"))) function attribut __attribute__((unused)) function attribute __attribute__((used)) function attribute __attribute__((value_in_regs)) function attribute __attribute__((visibility("visibility_type"))) fun __attribute__((weak)) function attribute __attribute__((weakref("target"))) function attrib Type attributes __attribute__((aligned)) type attribute __attribute__((packed)) type attribute __attribute__((transparent_union)) type attribute Variable attributes __attribute__((alias)) variable attribute __attribute__((aligned)) variable attribute __attribute__((deprecated)) variable attribute __attribute__((packed)) variable attribute __attribute__((section("name"))) variable attribut __attribute__((unused)) variable attribute __attribute__((used)) variable attribute __attribute__((visibility("visibility_type"))) var __attribute__((weak)) variable attribute __attribute__((weakref("target"))) variable attrib Compiler-specific Intrinsics __breakpoint intrinsic __current_pc intrinsic __current_sp intrinsic __disable_fiq intrinsic __disable_irq intrinsic __enable_fiq intrinsic __enable_irq intrinsic __force_stores intrinsic __memory_changed intrinsic __schedule_barrier intrinsic __semihost intrinsic __vfp_status intrinsic Compiler-specific Pragmas #pragma clang system_header #pragma clang diagnostic #pragma clang section #pragma once #pragma pack(...) #pragma unroll[(n)], #pragma unroll_completely #pragma weak symbol, #pragma weak symbol1 = symbol Other Compiler-specific Features ACLE support Predefined macros Inline functions Half-precision floating-point data types Half-precision floating-point number format Half-precision floating-point intrinsics Library support for _Float16 data type BFloat16 floating-point number format TT instruction intrinsics Non-secure function pointer intrinsics armclang Integrated Assembler Syntax of assembly files for integrated assembler Assembly expressions Alignment directives Data definition directives String definition directives Floating-point data definition directives Section directives Conditional assembly directives Macro directives Symbol binding directives Org directive AArch32 Target selection directives AArch64 Target selection directives Space-filling directives Type directive Integrated assembler support for the CSDB instruct armclang Inline Assembler Inline Assembly File-scope inline assembly Inline assembly statements within a function Assembly string Output and input operands Clobber list volatile Inline assembly constraint strings Constraint modifiers Constraint codes Constraint codes common to AArch32 state and AArch Constraint codes for AArch32 state Constraint codes for AArch64 state Using multiple alternative operand constraints Inline assembly template modifiers Template modifiers common to AArch32 state and AAr Template modifiers for AArch32 state Template modifiers for AArch64 state Forcing inline assembly operands into specific reg Symbol references and branches into and out of inl Duplication of labels in inline assembly statement armlink Reference fromelf Reference armar Reference armasm Legacy Assembler Reference Appendixes

Assembly expressions

B7.2 Assembly expressions

Expressions 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.

Constants

Numeric literals are accepted in the following formats:

  • Decimal integer in range 0 to (264)-1.
  • Hexadecimal integer in range 0 to (264)-1, prefixed with 0x.
  • Octal integer in range 0 to (264)-1, prefixed with 0.
  • Binary integer in range 0 to (264)-1, prefixed with 0b.

Some directives accept values larger than (264)-1. These directives only accept simple integer literals, not expressions.

Note:

These ranges do not include negative numbers. Negative numbers can instead be represented using the unary operator, -.

Symbol References

References 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 (.) is a special symbol that can be used to reference the current location in the output file.

For AArch32 targets, a symbol reference might optionally be followed by a modifier in parentheses. The following modifiers are supported:

Table B7-1 Modifiers

Modifier Meaning
None Do not relocate this value.
got_prel Offset from this location to the GOT entry of the symbol.
target1 Defined by platform ABI.
target2 Defined by platform ABI.
prel31 Offset from this location to the symbol. Bit 31 is not modified.
sbrel Offset to symbol from addressing origin of its output segment.
got Address of the GOT entry for the symbol.
gotoff Offset from the base of the GOT to the symbol.

Operators

The following operators are valid expressions:

Table B7-2 Unary operators

Unary operator Meaning
-expr Arithmetic negation of expr.
+expr Arithmetic addition of expr.
~expr Bitwise negation of expr.

Table B7-3 Binary operators

Binary operator Meaning
expr1 - expr2 Subtraction.
expr1 + expr2 Addition.
expr1 * expr2 Multiplication.
expr1 / expr2 Division.
expr1 % expr2 Modulo.

Table B7-4 Binary logical operators

Binary logical operator Meaning
expr1 && expr2 Logical and. 1 if both operands non-zero, 0 otherwise.
expr1 || expr2 Logical or. 1 if either operand is non-zero, 0 otherwise.

Table B7-5 Binary bitwise operators

Binary bitwise operator Meaning
expr1 & expr2 expr1 bitwise and expr2.
expr1 | expr2 expr1 bitwise or expr2.
expr1 ^ expr2 expr1 bitwise exclusive-or expr2.
expr1 >> expr2 Logical shift right expr1 by expr2 bits.
expr1 << expr2 Logical shift left expr1 by expr2 bits.

Table B7-6 Binary comparison operators

Binary comparison operator Meaning
expr1 == expr2 expr1 equal to expr2.
expr1 != expr2 expr1 not equal to expr2.
expr1 < expr2 expr1 less than expr2.
expr1 > expr2 expr1 greater than expr2.
expr1 <= expr2 expr1 less than or equal to expr2.
expr1 >= expr2 expr1 greater than or equal to expr2.

The order of precedence for binary operators is as follows, with highest precedence operators listed first:

  1. *, /, %, >>, <<
  2. |, ^, &
  3. +, -
  4. ==, !=, <, >, <=, >=
  5. &&
  6. ||

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 specifiers

For 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

Relocation specifier Meaning
:lower16: Use the lower 16 bits of the expression value.
:upper16: Use the upper 16 bits of the expression value.

These relocation specifiers are only valid for the operands of the movw and movt instructions. They can be combined with an expression involving the current place to create a place-relative relocation, and with the sbrel symbol modifier to create a static-base-relative relocation. The current place is the location that the assembler is emitting code or data at. A place-relative relocation is a relocation that generates the offset from the relocated data to the symbol it references.

In AArch64 state, the following relocation specifiers are available:

Table B7-8 Relocation specifiers for AArch64 state

Relocation specifier Relocation type Bits to use Overflow checked
:lo12: Absolute [11:0] No
:abs_g3: Absolute [63:48] Yes
:abs_g2: Absolute [47:32] Yes
:abs_g2_s: Absolute, signed [47:32] Yes
:abs_g2_nc: Absolute [47:32] No
:abs_g1: Absolute [31:16] Yes
:abs_g1_s: Absolute, signed [31:16] Yes
:abs_g1_nc: Absolute [31:16] No
:abs_g0: Absolute [15:0] Yes
:abs_g0_s: Absolute, signed [15:0] Yes
:abs_g0_nc: Absolute [15:0] No
:got: Global Offset Table Entry [32:12] Yes
:got_lo12: Global Offset Table Entry [11:0] No

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 - .
Non-ConfidentialPDF file icon PDF version101754_0613_00_en
Copyright © 2019 Arm Limited or its affiliates. All rights reserved. 
  Arm logo
Important information

This site uses cookies to store information on your computer. By continuing to use our site, you consent to our cookies.

Change Settings

Privacy Policy Update

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.