Calls to assembly language from C++

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

Example 19. Defining the assembly language function

    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

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

Example 20. Calling assembly language from 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;

Show/hideSee also

Copyright © 2010-2012 ARM. All rights reserved.ARM DUI 0471G