Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
979 views
in Technique[技术] by (71.8m points)

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

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?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

Perhaps this is a tad better:

shl     rax,32
shrd    rax,rdx,32

Does not assume that high dwords are zero.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to WuJiGu Developer Q&A Community for programmer and developer-Open, Learning and Share
...