cancel
Showing results for 
Search instead for 
Did you mean: 

Call 'C' functions from assembly

eng1
Associate II
Posted on April 04, 2008 at 12:47

Call 'C' functions from assembly

3 REPLIES 3
eng1
Associate II
Posted on May 17, 2011 at 12:28

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,

Glenn

ryan2399
Associate II
Posted on May 17, 2011 at 12:28

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 r0

Code:

/***** '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 Counter

eng1
Associate II
Posted on May 17, 2011 at 12:28

Thank you very much.