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

Inline assembler function calls and branches in C and C++ code

6.23 Inline assembler function calls and branches in C and C++ code

The BL and SVC instructions of the inline assembler enable you to specify three optional lists following the normal instruction fields.

These instructions have the following format:
SVC{cond} svc_num, {input_param_list}, {output_value_list}, {corrupt_reg_list}
BL{cond} function, {input_param_list}, {output_value_list}, {corrupt_reg_list}

Note

RVCT v3.0 renamed the SWI instruction to SVC. The inline assembler still accepts SWI in place of SVC.
If you are compiling for architecture 5TE or later, the linker converts BL function instructions to BLX function instructions if appropriate. However, you cannot use BLX function instructions directly within inline assembly code.
  • input_param_list specifies the expressions or variables that are the input parameters to the function call or SVC instruction, and the physical registers that contain the expressions or variables. They are specified as assignments to physical registers or as physical register names. A single list can contain both types of input register specification.
    The inline assembler ensures that the correct values are present in the specified physical registers before the BL or SVC instruction is entered. A physical register name that is specified without assignment ensures that the value in the virtual register of the same name is present in the physical register. This ensures backwards compatibility with existing inline assembly language code.
    For example, the instruction:
    BL foo, { r0=expression1, r1=expression2, r2 }
    
    generates the following pseudocode:
    MOV (physical) r0, expression1
    MOV (physical) r1, expression2
    MOV (physical) r2, (virtual) r2
    BL foo
    
    By default, if you do not specify any input_param_list input parameters, registers r0 to r3 are used as input parameters.

    Note

    It is not possible to specify the lr, sp, or pc registers in the input parameter list.
  • output_value_list specifies the physical registers that contain the output values from the BL or SVC instruction and where they must be stored. The output values are specified as assignments from physical registers to modifiable lvalue expressions or as single physical register names.
    The inline assembler takes the values from the specified physical registers and assigns them into the specified expressions. A physical register name specified without assignment causes the virtual register of the same name to be updated with the value from the physical register.
    For example, the instruction:
    BL foo, { }, { result1=r0, r1 }
    
    generates the following pseudocode:
    BL foo
    MOV result1, (physical) r0
    MOV (virtual) r1, (physical) r1
    
    By default, if you do not specify any output_value_list output values, register r0 is used for the output value.

    Note

    It is not possible to specify the lr, sp, or pc registers in the output value list.
  • corrupt_reg_list specifies the physical registers that are corrupted by the called function. If the condition flags are modified by the called function, you must specify the PSR in the corrupted register list.
    The BL and SVC instructions always corrupt lr.
    If corrupt_reg_list is omitted then for BL and SVC, the registers r0-r3, lr and the PSR are corrupted.
    Only the branch instruction, B, can jump to labels within a single C or C++ function.
    By default, if you do not specify any corrupt_reg_list registers, r0 to r3, r14, and the PSR can be corrupted.

    Note

    It is not possible to specify the lr, sp, or pc registers in the corrupt register list.
If you do not specify any lists, then:
  • r0-r3 are used as input parameters.
  • r0 is used for the output value and can be corrupted.
  • r0-r3, r14, and the PSR can be corrupted.

Note

  • The BX, BLX, and BXJ instructions are not supported in the inline assembler.
  • It is not possible to specify the lr, sp, or pc registers in any of the input, output, or corrupted register lists.
  • The sp register must not be changed by any SVC instruction or function call.
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.