Are RAX, RBX, RCX, RDX, RSI, RDI, RBP, RSP, R8-R15 interchangable?

£可爱£侵袭症+ 提交于 2020-01-24 06:01:05

问题


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?


回答1:


There are some restrictions, and some differences in encoding.

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.

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.




回答2:


No. Although most x86 as well as x86_64 instructions can use any registers as GPRs, some instructions only work with a specific register or set of registers such as movabs, mul, div...

For more detailed information regarding implicit register usage read here

See also Are the data registers EAX, EBX, ECX and EDX interchangeable



来源:https://stackoverflow.com/questions/20810464/are-rax-rbx-rcx-rdx-rsi-rdi-rbp-rsp-r8-r15-interchangable

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!