Question

Using amd64 assembly, whats the best way to zero out the top 32 bits of a 64-bit register, e.g. zero out the bits of rax that are not covered by eax? It appears that I cannot and the whole register against a 64-bit constant.

Was it helpful?

Solution

movl %eax, %eax or mov eax, eax, depending on the assembler in use.

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

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

I should also add, in regards to @HansPassant's comment: 7.3.1.7 :

The MOVSXD instruction operates on 64-bit data. It sign-extends a 32-bit value to 64 bits.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top