本文介绍了RAX、RBX、RCX、RDX、RSI、RDI、RBP、RSP、R8-R15 是否可以互换?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

x64 寄存器是否可以互换,从某种意义上说,使用它们的一种组合的任何指令都可以与其他任何组合一起使用?除了名称之外,是否存在性能差异或任何其他考虑因素使它们彼此不同?

Are x64 registers interchangable, in the sense that any instruction that works with one combination of them will work with any other? Is there performance difference or any other considerations that make them different from each other, apart from the names?

推荐答案

有一些限制,以及一些编码差异.

There are some restrictions, and some differences in encoding.

rsp(和 esp 等)不能用作索引寄存器.有许多指令在特定寄存器中接受参数或返回结果 - 例如,变量移位指令仅在 cl 中接受它们的参数.

rsp (and esp, etc) may not be used as an index register. There are many instructions which take arguments or return results in particular registers - for example, the variable shift instructions only take their argument in cl.

算术指令(和 test)有 rax 的短编码加上 32 位立即数:

The arithmetic instructions (and test) have short encodings for rax plus a 32-bit immediate:

8:  48 05 ff ff 00 00       add    $0xffff,%rax
e:  48 81 c3 ff ff 00 00    add    $0xffff,%rbx

我确定还有一些其他的点点滴滴我现在想不起来:请查阅架构手册以了解详细信息.

I'm sure there are some other bits and pieces I can't bring to mind at the moment: consult the architecture manual for the gory details.

这篇关于RAX、RBX、RCX、RDX、RSI、RDI、RBP、RSP、R8-R15 是否可以互换?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-13 14:41