在汇编语言中调用C语言的函数,需要在汇编语言中IMPORT对应的C语言函数名,然后将C语言的代码放在一个独立的C语言文件中进行编译,剩下的工作由连接器来处理。
实例代码:
;the details of parameters transfer comes from ATPCS
;if there are more than 4 args, stack will be usedEXPORT mainAREA main, CODE, READONLYIMPORT cFun
ENTRYmov r0,#11mov r1,#22mov r2,#33BL cFunEND
/*C file, called by asmfile*/
int cFun(int a,int b,int c)
{return a + b + c;
}
修改main入口的地方:
;Enter the C code -------------------------------------------
IMPORT __main
LDR R0,=__main
BX R0
改为
; Enter the C code -------------------------------------
IMPORT asmfile
BL asmfile