jeffma
jeffma

Reputation: 51

"movl" instruction in assembly

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.

Upvotes: 0

Views: 2081

Answers (1)

Nate Eldredge
Nate Eldredge

Reputation: 58132

The GNU assembler doesn't accept movl %eax,%rdx. It also doesn't make sense for the encoding, since mov must have a single operand size (using a prefix byte if needed), not two different sized operands.

The effect you want is achieved by movl %eax, %edx since writes to a 32-bit register always zero-extend into the corresponding 64-bit register. See Why do x86-64 instructions on 32-bit registers zero the upper part of the full 64-bit register?.

movzlq %eax, %rdx might make logical sense, but it's not supported since it would be redundant.

Upvotes: 5

Related Questions