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:
    PRESERVE8
    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
    END

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;
}
Related concepts
3.11 Calls to C from C++
Non-ConfidentialPDF file icon PDF versionARM DUI0471K
Copyright © 2010-2014 ARM. All rights reserved.