Search code examples
assemblyx86-64cpu-registers

Move smaller operand into larger operand


I'm having a little trouble with imagining how data moves into the RAX register.

Here is the assembly:

.data
dwordVal DWORD 94326732h
.code
mov rax, 0FFFFFFFF00000000h
mov rax, dwordVal

I read that you cannot move a smaller operand into a larger operand with mov. It seems to me that dwordVal would only fill the lower half of the 64-bit RAX register, so this would not be permitted. Please correct me if I'm wrong.


Solution

  • A mov instruction will always fill the destination operand with a complete value, of exactly the same size as the destination operand.

    So, your understanding is incorrect. You cannot fill part of rax with a mov.

    As Jester has already said in a comment, precisely what will happen as a result of that mov rax, dwordVal depends on the conventions followed by your assembler, and some assemblers would actually reject such a thing as illegal.

    One thing I can tell you is that there will be absolutely nothing left in rax from that 0FFFFFFFF00000000h that was previously loaded into it.