Search code examples
assemblyx86-64instructionsmachine-codeimmediate-operand

x64 MOV 32-bit immediate to 64-bit register


The second instruction on this page in the code section:

x86

Looks like this: MOV r9d, 0. Encoded like this: 41 B9 00 00 00 00

The only problem is... There's no MOV instruction in the Intel x64 manual that takes a 4-byte immediate and puts it in a 64-bit register.

These are the instructions from the Intel manual:

B0+ rb          MOV r8, imm8 Move imm8 to r8.
REX + B0+ rb    MOV r8***, imm8 Move imm8 to r8.
B8+ rw          MOV r16, imm16 Move imm16 to r16.
B8+ rd          MOV r32, imm32 Move imm32 to r32.
REX.W + B8+ rd  MOV r64, imm64 OI Valid N.E. Move imm64 to r64.

The instruction appears to work, but how?


Solution

  • r9d isn't a 64 bit register. It is the low 32 bits of the r9 register, as such it is a 32 bit register.