mul

Unsigned multiply

Multiplies unsigned integers into the full implicit product in the one-operand form.

8086 and later

Intel's reference: MUL

CFPFAFZFSFDFOF ●????–●
  • ● set from the result
  • ? undefined afterwards
  • – not changed

Forms

Operands

r/m
A general-purpose register or memory location matching the operation’s size, for example rax or qword [rbp-8]. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, including when the memory address uses r8–r15.
reg
A general-purpose register matching the operation’s size, for example al, ax, eax or rax. The byte registers ah, bh, ch and dh cannot be used with a REX prefix, which is required by spl, bpl, sil, dil and r8–r15.
imm
An immediate value encoded in the instruction, written as a number, character or label. Its encoded width and any sign extension depend on the instruction; arithmetic immediates may be sign-extended, while shift counts are used without sign extension.

Its explicit source width selects the implicit other factor and full product: 8 bits uses al and produces ax; 16 bits uses ax and produces dx:ax; 32 bits uses eax and produces edx:eax; 64 bits uses rax and produces rdx:rax. The register before the colon holds the high half. CF and OF are set when that high half is nonzero.

NASM also accepts two- and three-operand mul spellings as aliases of the corresponding imul forms. These keep only the destination-width low product; their overflow flags follow signed imul rules. Use the one-operand form when you need the full unsigned product.

global _start

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

        mul rax

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