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

Output and input operands

B8.3.2 Output and input operands

The inline assembly statement can optionally accept two lists of operand specifiers, the first for outputs and the second for inputs. These lists are used to pass values between the assembly code and the enclosing C/C++ function.

Syntax

Each list is a comma-separated list of operand specifiers. Each operand specifier can take one of the following two forms:

[<name>] "<constraint>" (<value>)
         "<constraint>" (<value>)

Where:

<name>
Is a name for referring to the operand in templates inside the inline assembly string. If the name for an operand is omitted, it must be referred to by number instead.
<constraint>
Is a string that tells the compiler how the value will be used in the assembly string, including:
  • For output operands, whether it is only written to, or both read from and written to. Also whether it can be allocated to the same register as an input operand. See B8.4.1 Constraint modifiers.
  • Whether to store the value in a register or memory, or whether it is a compile-time constant. See B8.4.2 Constraint codes.
<value>
Is a C/C++ value that the operand corresponds to. For output operands, this value must be a writable value.

Example

foo.c:
int saturating_add(int a, int b) {
	int result;
	__asm(
		  // The assembly string uses templates for the registers which hold output
		  // and input values. These will be replaced with the names of the
		  // registers that the compiler chooses to hold the output and input
		  // values.
		  
		  "qadd %0, %[lhs], %[rhs]"
		  
		  // The output operand, which corresponds to the "result" variable. This
		  // does not have a name assigned, so must be referred to in the assembly
		  // string by its number ("%0").
		  // The "=" character in the constraint string tells the compiler that the
		  // register chosen to hold the result does not need to have any
		  // particular value at the start of the inline assembly.
		  // The "r" character in the constraint tells the compiler that the value
		  // should be placed in a general-purpose register (r0-r12 or r14).
		  
		: "=r" (result)
		
		  // The two input operands also use the "r" character in their
		  // constraints, so the compiler will place them in general-purpose
		  // registers.
		  // These have names specified, which can be used to refer to them in
		  // the assembly string ("%[lhs]" and "%[rhs]").
		  
		: [lhs] "r" (a), [rhs] "r" (b)
	);
	
	return result;
}

Build this example with the following command:

armclang --target=arm-arm-none-eabi -march=armv7-a -O2 -c -S foo.c -o foo.s

The assembly language source file foo.s that is generated contains:

	.section	.text.saturating_add,"ax",%progbits
	.hidden saturating_add			@ -- Begin function saturating_add
	.globl  saturating_add
    .p2align    2
    .type   saturating_add,%function
    .code   32						@ @saturating_add
saturating_add:
	.fnstart
@ %bb.0:							@ %entry
	@APP
	qadd r0,r0,r1
	@NO_APP
	bx lr
.Lfunc_end0:
	.size saturating_add, .Lfunc_end0-saturating_add
	.cantunwind
	.fnend

In this example:

  • The compiler places the C function saturating_add() in a section that is called .text.saturating_add.
  • Within the body of the function, the compiler expands the inline assembly statement into the qadd r0, r0, r1 instruction between the comments @APP and @NO_APP. In -S output, the compiler always places code that it expands from inline assembly statements within a function between a pair of @APP and @NO_APP comments.
  • The compiler uses the general-purpose register R0 for:
    • The int a parameter of the saturating_add() function.
    • The inline assembly input operand %[lhs].
    • The inline assembly output operand %0.
    • The return value of the saturating_add() function.
  • The compiler uses the general-purpose register R1 for:
    • The int b parameter of the saturating_add() function.
    • The inline assembly input operand %[rhs].
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.