I am learning assembly and reading "Computer Systems: A programmer's perspective". In Practice Problem 3.3, it says movl %eax,%rdx
will generate an error. The answer keys says movl %eax,%dx Destination operand incorrect size
. I am not sure if this is a typo or not, but my question is: is movl %eax,%rdx
a legal instruction? I think it is moving the 32 bits in %eax
with zero extension to %rdx
, which will not be generated as movzql
since
an instruction generating a 4-byte value with a register as the destination will fill the upper 4 bytes with zeros` (from the book).
I tried to write some C code to generate it, but I always get movslq %eax, %rdx
(GCC 4.8.5 -Og). I am completely confused.
%dx
in the answer is probably a typo and should be%rdx
to match the question. Note that if you are using the Global Edition, its exercises and typos are filled with severe errors and should probably be ignored altogether. See stackoverflow.com/questions/57998998/…movslq
, apparently you used signedint
instead ofunsigned
oruint32_t
. C semantics require sign-extension when promoting a signed type to any wider type, preserving the value. So cast to unsigned first, orlong foo(unsigned x){ return x; }
. godbolt.org/z/YhevPfEvc