x86_64的装配约定节能参数寄存器 [英] x86_64 assembly conventions saving argument registers

查看:158
本文介绍了x86_64的装配约定节能参数寄存器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在写一些x86_64的组件来调用C函数。我的C函数接受1参数,所以组装放在%RDI 的说法。 ABI的PDF(下面的链接)说,其他6参数寄存器(RSI,RDX,RCX,R8,R9)不是在函数调用pserved $ P $。但是,因为我的C函数只需要一个的说法,我对C函数是否会揍其他5个寄存器任何保证?我的假设是,如果一个参数的值被改变参数寄存器只打一顿:

I'm writing some x86_64 assembly to call a C function. My C function takes in 1 argument, so the assembly places the argument in %rdi. The ABI pdf (linked below) says that the other 6 argument registers (rsi, rdx, rcx, r8, r9) are not preserved across function calls. However, since my C function only takes one long argument, do I have any guarantees about whether or not the C function will clobber the other 5 registers? My assumption was that the argument registers are only clobbered if an argument's value is changed:

void foo(int a, int b) {
    a++; /* %rdi will be changed, but %rsi won't be changed when control returns. */
}

我这么问是因为我想preserve其他5参数寄存器的值在我的C函数调用(而无需显式推/手动从栈中弹出它们)。

I'm asking because I'd like to preserve the values of the other 5 argument registers across my C function call (without having to explicitly push/pop them from the stack manually).

x86_64的ABI - http://www.x86-64.org/documentation /abi-0.99.pdf

x86_64 ABI - http://www.x86-64.org/documentation/abi-0.99.pdf

推荐答案

有没有保证。您必须将它们保存在栈上,以确保它们没有改变。它们是否改变将取决于编译器。

There is no guarantee. You will have to save them on the stack to ensure they are not changed. Whether they are changed will depend on the compiler.

如果你想以某种方式确保它们不会改变,你可以写在装配的功能。

If you want to somehow ensure they are not changed, you could write the function in assembly.

这篇关于x86_64的装配约定节能参数寄存器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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