Keil Logo

Technical Support

On-Line Manuals

Compiler User Guide

Preface Overview of the Compiler Getting Started with the Compiler Compiler Features Compiler Coding Practices Compiler Diagnostic Messages Using the Inline and Embedded Assemblers of the AR Compiler support for inline assembly language Inline assembler support in the compiler Restrictions on inline assembler support in the co Inline assembly language syntax with the __asm key Inline assembly language syntax with the asm keywo Inline assembler rules for compiler keywords __asm Restrictions on inline assembly operations in C an Inline assembler register restrictions in C and C+ Inline assembler processor mode restrictions in C Inline assembler Thumb instruction set restriction Inline assembler Vector Floating-Point (VFP) restr Inline assembler instruction restrictions in C and Miscellaneous inline assembler restrictions in C a Inline assembler and register access in C and C++ Inline assembler and the # constant expression spe Inline assembler and instruction expansion in C an Expansion of inline assembler instructions that us Expansion of inline assembler load and store instr Inline assembler effect on processor condition fla Inline assembler expression operands in C and C++ Inline assembler register list operands in C and C Inline assembler intermediate operands in C and C+ Inline assembler function calls and branches in C Inline assembler branches and labels in C and C++ Inline assembler and virtual registers Embedded assembler support in the compiler Embedded assembler syntax in C and C++ Effect of compiler ARM and Thumb states on embedde Restrictions on embedded assembly language functio Compiler generation of embedded assembly language Access to C and C++ compile-time constant expressi Differences between expressions in embedded assemb Manual overload resolution in embedded assembler __offsetof_base keyword for related base classes i Compiler-supported keywords for calling class memb __mcall_is_virtual(D, f) __mcall_is_in_vbase(D, f) __mcall_offsetof_vbase(D, f) __mcall_this_offset(D, f) __vcall_offsetof_vfunc(D, f) Calling nonstatic member functions in embedded ass Calling a nonvirtual member function Calling a virtual member function Accessing sp (r13), lr (r14), and pc (r15) Differences in compiler support for inline and emb Compiler Command-line Options Language Extensions Compiler-specific Features C and C++ Implementation Details What is Semihosting? Via File Syntax Summary Table of GNU Language Extensions Standard C Implementation Definition Standard C++ Implementation Definition C and C++ Compiler Implementation Limits

Compiler generation of embedded assembly language functions

6.30 Compiler generation of embedded assembly language functions

The bodies of all the __asm functions in a translation unit are assembled as if they are concatenated into a single file that is then passed to the ARM assembler.

The order of __asm functions in the assembly language file that is passed to the assembler is guaranteed to be the same order as in the source file, except for functions that are generated using a template instantiation.


This means that it is possible for control to pass from one __asm function to another by falling off the end of the first function into the next __asm function in the file, if the return instruction is omitted.
When you invoke armcc, the object file produced by the assembler is combined with the object file of the compiler by a partial link that produces a single object file.
The compiler generates an AREA directive for each __asm function, as in the following example:
#include <cstddef>
struct X
    int x,y;
    void addto_y(int);
__asm void X::addto_y(int)
    LDR      r2, [r0, #__cpp(offsetof(X, y))]
    ADD      r1, r2, r1
    STR      r1, [r0, #__cpp(offsetof(X, y))]
    BX       lr
For this function, the compiler generates:
    AREA ||.emb_text||, CODE, READONLY
    EXPORT |_ZN1X7addto_yEi|
#line num "file"
|_ZN1X7addto_yEi| PROC
    LDR r2, [r0, #4]
    ADD r1, r2, r1
    STR r1, [r0, #4]
    BX lr
The use of offsetof must be inside __cpp() because it is the normal offsetof macro from the cstddef header file.
Ordinary __asm functions are put in an ELF section with the name .emb_text. That is, embedded assembly functions are never inlined. However, implicitly instantiated template functions and out-of-line copies of inline functions are placed in an area with a name that is derived from the name of the function, and an extra attribute that marks them as common. This ensures that the special semantics of these kinds of functions are maintained.


Because of the special naming of the area for out-of-line copies of inline functions and template functions, these functions are not in the order of definition, but in an arbitrary order. Therefore, do not assume that code execution falls out of an inline or template function and into another __asm function.
Related information
Non-ConfidentialPDF file icon PDF versionARM DUI0375H
Copyright © 2007, 2008, 2011, 2012, 2014-2016 ARM. 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.