例如
extern int addfunction(int,int);
main() {
int a = 5, b = 6, z;
z = addfunction(a, b);
printf("%d", c);
}
addfunction()
在另一个 .s 文件中的定义,例如
.global addfunction
addfunction:
@ value a will be in R0 & R1 respectively
add r2, r0, r1 @ r2=r0+r1
现在如何返回存储的值r2
,以便C程序中的变量z
获得正确的值?我可以使用 C 中的指针并更新 asm 中的地址。我不想这样。帮助!
最佳答案
看here
The standard 32-bit ARM calling convention allocates the 16 ARM registers as:
block 引用>r0 to r3: used to hold argument values passed to a subroutine, and also hold results returned from a subroutine.
所以将r0设置为返回值
.global addfunction addfunction: @ value a will be in R0 & R1 respectively add r0, r0, r1 @ r0=r0+r1
关于c - 如何将寄存器的值从 ARM 汇编返回到 C 函数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44898977/