从 ARM 汇编到 C 的函数调用的参数传递约定

use*_*261 1 c assembly arm parameter-passing

我有一个 C 代码,它调用 ARM Assembly 中定义的函数。必须传递两个参数。

如果函数调用如下所示:

functionName(a, b)
Run Code Online (Sandbox Code Playgroud)

寄存器x0并按x1什么顺序保存这些值?是x0一直持有a还是一直x1持有b,还是相反?

old*_*mer 5

提出问题比尝试要花费更长的时间。

extern void bar ( unsigned int, unsigned int );

void foo ( void )
{
    bar(5,7);
}
Run Code Online (Sandbox Code Playgroud)

编译然后反汇编

传统手臂

00000000 <foo>:
   0:   e3a00005    mov r0, #5
   4:   e3a01007    mov r1, #7
   8:   eafffffe    b   0 <bar>
Run Code Online (Sandbox Code Playgroud)

架构64

0000000000000000 <foo>:
   0:   528000e1    mov w1, #0x7                    // #7
   4:   528000a0    mov w0, #0x5                    // #5
   8:   14000000    b   0 <bar>
   c:   d503201f    nop
Run Code Online (Sandbox Code Playgroud)

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         
Run Code Online (Sandbox Code Playgroud)

等离子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
Run Code Online (Sandbox Code Playgroud)

  • 无论什么处理器,arm,aarch64,mips,x86,pdp-11。如果您有一个编译器并且想知道两个简单参数的调用约定。应该只需要大约 40 到 50 秒就能找到答案。 (3认同)