user2039981
user2039981

Reputation:

Difference between MOVZX r32, r/m16 and MOVZX r64, r/m16 in 64-bit x86

Both MOVZX r32, r/m16 and MOVZX r64, r/m16 have the opcode 0F B7, but the latter has a REX.W prefix. What makes these two instructions different? Shouldnt both of them zero the upper 32-bits of the destination operand anyways since according to

Intel 64 and IA-32 Architectures - Software Developer’s Manual, Volume 1, 3.4.1.1
    : General-Purpose Registers in 64-Bit Mode.

the following statement holds:

32-bit operands generate a 32-bit result,
    zero-extended to a 64-bit result in the destination general-purpose register.

Upvotes: 3

Views: 334

Answers (1)

Ross Ridge
Ross Ridge

Reputation: 39581

There is no difference in what these two instructions do, just how they're encoded. This is no different than how XOR EAX, EAX and XOR RAX, RAX do the same thing, but the former is one byte shorter. (XOR RAX, RAX also has the disadvantage of not breaking dependencies on Silvermont, but this difference doesn't apply to MOVZX.)

Even before x86-64 there were various ways of encoding what was effectively the same instruction (eg. SUB EAX, EAX), the automatic zeroing of the upper part of registers just adds more.

Upvotes: 3

Related Questions