How to move two 32 bit registers in to one 64 bit?

佐手、 提交于 2019-12-18 05:54:43

问题


Let's say that I want to put two 32 bit registers EAX as low 32 bit word and EDX as high 32 bit word into RAX. I have found one way:

shl   rdx, 32
or    rax, rdx

This method works only if we are sure that bits from 32 to 61 of RAX are 0. If we are not sure about that, then we must first clear the high 32 bit word, like:

mov   eax, eax      //This instruction should clear the high 32 bit word of RAX

Is this the shortest way?

Is there a single asm x86-64 instruction that does this operation?


回答1:


Perhaps this is a tad better:

shl     rax,32
shrd    rax,rdx,32

Does not assume that high dwords are zero.



来源:https://stackoverflow.com/questions/8580838/how-to-move-two-32-bit-registers-in-to-one-64-bit

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