IMUL-MUL
By Vesper Vei
2 minutes read
Table of Contents
IMUL-MUL (imul / mul)
Basic purpose
IMUL → signed multiplication
MUL → unsigned multiplication
Both may involve a double-register result (EDX:EAX or RDX:RAX).
IMUL instruction formats
There are three forms:
- Implicit form (result stored in edx:eax)
imul r/m32; EDX:EAX = EAX * r/m32(有符号)- Explicit two-operand form
imul reg, r/m32reg = reg * r/m32- Three-operand form
imul reg, r/m32, immreg = r/m32 * immMUL instruction format (unsigned)
mul r/m32 ; EDX:EAX = EAX * r/m32MUL does not have an explicit reg = reg × x form.
Behavioral characteristics
- The high part of the result (EDX or RDX) is used to determine overflow
- If the high part is not 0, OF = CF = 1
- The implicit form must use the accumulator register (EAX / RAX) as an operand
Example
mov eax, 5imul eax, 3 ; eax = 15
mov eax, -10imul eax, -4 ; eax = 40(有符号乘法)Implicit form:
mov eax, 0x10000imul dword ptr [rbp-4] ; rdx:rax = rax * [rbp-4]Common uses
- Mathematical calculations
- Array index calculation (
index × element_size) - Struct offset calculation