Rdi寄存器用于无参数功能的目的 [英] Purpose of rdi register for no argument function

查看:454
本文介绍了Rdi寄存器用于无参数功能的目的的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

考虑以下简单功能:

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?

推荐答案

请参见

如果该类型具有MEMORY类,则调用方将为 返回值,并以%rdi的形式传递此存储的地址,就好像它 是该函数的第一个参数.实际上,这个地址 成为隐藏"的第一个参数.

If the type has class MEMORY, then the caller provides space for the return value and passes the address of this storage in %rdi as if it were the first argument to the function. In effect, this address becomes a "hidden" first argument.

返回时,%rax将包含由 %rdi中的呼叫者.

On return %rax will contain the address that has been passed in by the caller in %rdi.

这篇关于Rdi寄存器用于无参数功能的目的的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆