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

Let's say that I want to put two 32-bit registers EAX as the low-order 32-bit word and EDX as the 32-bit word in RAX. I found one way:

  shl rdx, 32 or rax, rdx 

This method only works if we are sure that bits 32 to 61 of RAX are 0. If we do not avoid this, we must first clear the high 32-bit word, for example:

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

Is this the shortest way?

Is there one asm x86-64 instruction that performs this operation?

+6
source share
1 answer

Maybe this is a little better:

 shl rax,32 shrd rax,rdx,32 

Does not assume that high words are zero.

+12
source

Source: https://habr.com/ru/post/904188/


All Articles