3.12 Calls to assembly language from C++

You can call an assembly language routine from C++ by exporting the assembly function symbol and declaring the routine as extern "C" in C++.

Defining the assembly language function

To be able to call an assembly language routine from C++, you must use the EXPORT directive to export the function symbol:

    AREA Asm, CODE
    EXPORT asmfunc
asmfunc                ; the definition of the Asm
    LDR R1, [R0]       ; function to be called from C++
    ADD R1, R1, #5
    STR R1, [R0]
    BX  lr

Calling assembly language from C++

To call the assembly language routine from C++, declare it with extern "C":

struct S {        // has no base classes
                  // or virtual functions
    S(int s) : i(s) { }
    int i;
extern "C" void asmfunc(S *); // declare the Asm function
                              // to be called
int f() {
    S s(2);                   // initialize 's'
    asmfunc(&s);              // call 'asmfunc' so it can change 's'
    return s.i * 3;
Non-ConfidentialPDF file icon PDF versionARM DUI0471M
Copyright © 2010-2016 ARM Limited or its affiliates. All rights reserved.