movzx

Move with zero extension

Copies a source into a register, filling added high bits with zeros when the destination is wider.

386 and later

Intel's reference: MOVZX

CFPFAFZFSFDFOF –––––––
  • Changes no flag

Forms

Operands

reg
The destination register. Its width is selected independently of the source width; widening uses a larger destination.
r/m
The source register or memory value, whose width may differ from the destination’s. For example, a byte source can be extended to a 64-bit register. High-byte registers such as ah cannot be used with a REX prefix.

For example, movzx rax, byte [rdi] turns 0xff into 255. The source has its own width; it need not match the destination.

For a 32-bit source and 64-bit destination, NASM uses an ordinary 32-bit move: movzx rax, ebx has the effect of mov eax, ebx, whose write clears the upper half of rax. movzxd is another spelling for this case.

Some accepted aliases do not widen: movzx ax, bx copies a word, while movzx ax, ebx retains only the low 16 bits. These leave the rest of rax unchanged. The equal-width 32-bit alias is unavailable in 64-bit mode; use mov eax, ebx for that copy.

global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        movzx rax, bl

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall