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

C and C++ code compiled to run in one state can call assembly language code designed to run in the other state, and vice versa. To do this, write the caller routine as any non-interworking routine and, if calling from assembly language, use a BL instruction to make the call (see Example 4.8). Then:

Note

Any assembly language code or user library code used in this manner must conform to the AAPCS where appropriate.

Example 4.8. 

     /**********************
     *       thumb.c      *
     **********************/
     #include <stdio.h>
     extern int arm_function(int);
     int main(void)
     {
          int i = 1;
          printf("i = %d\n", i);
          printf("And now i = %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

Follow these steps to build and link the modules:

  1. Type armcc --thumb -g -c --apcs /interwork thumb.c to compile the Thumb code.

  2. Type armasm -g --apcs /interwork arm.s to assemble the ARM code.

  3. Type armlink arm.o thumb.o -o add --info veneers to link the two object files and view the size of the interworking veneers.

  4. Run the image using a compatible debugger (for example, RealView Debugger or AXD) with an appropriate debug target.

Copyright © 2002-2006 ARM Limited. All rights reserved.ARM DUI 0203G
Non-Confidential