C, C++, and assembly language interworking using veneers

This example shows interworking between Thumb code in C and ARM code in assembly language using veneers.

Example 35. C, C++, and assembly language interworking using veneers

     /**********************
     *       thumb.c      *
     **********************/

     #include <stdio.h>
     extern int arm_function(int);
     int main(void)
     {
          int i = 1;
          printf("i = %d\n", i);
          printf("And i+4 = %d\n", arm_function(i));
          return (0);
     }

     ; *****
     ; arm.s	
     ; *****	

     PRESERVE8
     AREA  Arm,CODE,READONLY ; Name this block of code.	
     EXPORT arm_function	
arm_function
     ADD   R0,R0,#4           ; Add 4 to first parameter.	
     BX    lr                 ; Return	
     END

Show/hideBuilding the example

Follow these steps to build and link the modules:

  1. To compile the Thumb code for interworking, type:

    armcc --thumb --debug -c --apcs=/interwork thumb.c
    
  2. To assemble the ARM code for interworking, type:

    armasm --debug --apcs=/interwork arm.s
    
  3. To link the object files, type:

    armlink arm.o thumb.o -o add.axf
    

    Alternatively, to view the size of the interworking veneers, type:

    armlink arm.o thumb.o -o add.axf --info=veneers
    
  4. Run the image using a compatible debugger with an appropriate debug target.

Show/hideSee also

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