Rdi寄存器用于无参数功能的目的 [英] Purpose of rdi register for no argument function
问题描述
考虑以下简单功能:
struct Foo {
int a;
int b;
int c;
int d;
int e;
int f;
};
Foo foo() {
Foo f;
f.a = 1;
f.b = 2;
f.c = 3;
f.d = 4;
f.e = 5;
f.f = 6;
return f;
}
它将生成以下程序集:
0000000000400500 <foo()>:
400500: 48 ba 01 00 00 00 02 movabs rdx,0x200000001
400507: 00 00 00
40050a: 48 b9 03 00 00 00 04 movabs rcx,0x400000003
400511: 00 00 00
400514: 48 be 05 00 00 00 06 movabs rsi,0x600000005
40051b: 00 00 00
40051e: 48 89 17 mov QWORD PTR [rdi],rdx
400521: 48 89 4f 08 mov QWORD PTR [rdi+0x8],rcx
400525: 48 89 77 10 mov QWORD PTR [rdi+0x10],rsi
400529: 48 89 f8 mov rax,rdi
40052c: c3 ret
40052d: 0f 1f 00 nop DWORD PTR [rax]
基于程序集,我知道调用方在其堆栈上为Foo
创建了空间,并将该信息在rdi
中传递给了被调用方.
Based on the assembly, I understand that the caller created space for Foo
on its stack, and passed that information in rdi
to the callee.
我正在尝试查找有关此约定的文档. Linux中的调用约定指出rdi
包含第一个整数参数.在这种情况下,foo
没有任何参数.
I am trying to find documentation for this convention. Calling convention in linux states that rdi
contains the first integer argument. In this case, foo
doesn't have any arguments.
此外,如果我让foo
接受一个整数参数,则该参数现在作为rsi
(第二个参数的寄存器)传递,其中rdi用作返回对象的地址.
Moreover, if I make foo
take one integer argument, that is now passed as rsi
(register for second argument) with rdi used for address of the return object.
任何人都可以提供有关在系统V ABI中如何使用rdi
的一些文档和说明吗?
Can anyone provide some documentation and clarity on how rdi
is used in system V ABI?