7.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. Then:

Note

Any assembly language code used in this manner must conform to the APCS where appropriate.

Example 7.6. 

	/**********************
	*       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
	; *****
	AREA  Arm,CODE,READONLY,INTERWORK
								; 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 tcc -c thumb.c to compile the thumb code.

  2. Type armasm arm.s to assemble the arm code.

  3. Type armlink arm.o thumb.o -o add to link the two object files.

Copyright © 1997, 1998 ARM Limited. All rights reserved.ARM DUI 0040D
Non-Confidential