本文共 1405 字,大约阅读时间需要 4 分钟。
c调用汇编//main.c#includeextern int myadd(int a, int b);int main(void){int a = 3;int b = 5;int c;c = myadd(a, b);printf("%d\n", c);return 0;}//myadd.sAREA MYADD, CODE, READONLY;ENTRYEXPORT myaddmyaddADD R2, R0, R1MOV R0, R2MOV R15, R14;MOV PC, LREND--------------------------汇编调用c//main.c#include extern int fun(int a, int b);int add(int a, int b){return a+b;}int main(void){int res;int a = 3, b = 5;res = fun(a, b);printf("%d\n", res);return 0;}//fun.sAREA FUN ,CODE, READONLYIMPORT addEXPORT funfunadd r0, r0, #1add r1, r1, #1mov r8, r14bl addmov r5, r0mov r14, r8mov pc, r14end----------------------------------内嵌汇编//main.c#include int main(void){__asm {mrs r5, CPSRbic r5, r5, #0xforr r5, r5, #0x2msr CPSR_cxsf, r5}printf("hello\n");return 0;}