2008-04-04 03:47 AM
Call 'C' functions from assembly
2011-05-17 03:28 AM
Hi,
We are trying to call a 'C' function from assembly code and are not terribly successful (i.e won't assemble). Does anyone know how this is done or know of any links to example(s) of how this is done? We are using Keil RealView compiler as well as the ARMASM assembler. Thanks in advance, Glenn2011-05-17 03:28 AM
It should be fairly simple. I'm using IAR's EWARM but I think the syntax is pretty much the same.
Keep in mind that r0-r3 and r12 are used for parameter passing and may be modified by the 'C' function. r0-r1 are used for return values (depending on the type) Refer to 'Procedure call Standard for the ARM Architecture (AAPCS) http://infocenter.arm.com/help/index.jsp?topic=/com.arm.doc.ihi0042a/ The following example returns the value passed by r1 (value2) into r0Code:
/***** 'C' Function ******/
int foo_c(int value1, int value2) { return value2; }Code:
; ASM Function
IMPORT foo_c foo_asm push {lr} ; save the Load Register before calling the subroutine ldr r0, =0x01010101 ldr r1, =0x02020202 bl foo_c ; call foo_c pop {pc} ; puts the PUSHed value of the load register into the Program Counter2011-05-17 03:28 AM
Thank you very much.