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 –––––––
  • Leaves every flag unchanged

Forms

Operands

reg
The destination register, usually wider than the source, as in movzx eax, bl.
r/m
The source register or memory location, usually narrower than the destination. The high-byte registers ah, bh, ch and dh cannot be used when the destination is a 64-bit register or one of r8 to r15 at any size.

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