![](/img/trans.png)
[英]Call C function from Assembly, passing args and getting the return value in the ARM calling convention
[英]Parameter passing convention for Function call from ARM Assembly to C
我有一個C代碼,該代碼調用ARM Assembly中定義的函數。 必須傳遞兩個參數。
如果函數調用如下所示:
functionName(a, b)
寄存器x0
和x1
以什么順序保存這些值? 是x0
持有a
而x1
持有b
還是相反?
問這個問題比僅僅嘗試花了更長的時間。
extern void bar ( unsigned int, unsigned int );
void foo ( void )
{
bar(5,7);
}
編譯然后反匯編
傳統手臂
00000000 <foo>:
0: e3a00005 mov r0, #5
4: e3a01007 mov r1, #7
8: eafffffe b 0 <bar>
aarch64
0000000000000000 <foo>:
0: 528000e1 mov w1, #0x7 // #7
4: 528000a0 mov w0, #0x5 // #5
8: 14000000 b 0 <bar>
c: d503201f nop
msp430
00000000 <foo>:
0: 3e 40 07 00 mov #7, r14 ;#0x0007
4: 3f 40 05 00 mov #5, r15 ;#0x0005
8: b0 12 00 00 call #0x0000
c: 30 41 ret
pdp-11
00000000 <_foo>:
0: 1166 mov r5, -(sp)
2: 1185 mov sp, r5
4: 15e6 0007 mov $7, -(sp)
8: 15e6 0005 mov $5, -(sp)
c: 09f7 fff0 jsr pc, 0 <_foo>
10: 65c6 0004 add $4, sp
14: 1585 mov (sp)+, r5
16: 0087 rts pc
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.