
Instruction Set
4-162
MUL
MUL
Flag Settings After Instruc tion
Examples
This example multiplies a 16-bit unsigned number in CX by a 16-bit unsigned number in
AX. If the product is small enough to fit in only the low word of the destination, this example
stores only the low word of the destination in memory.
T ips
Use SHL instead of MUL to multiply unsigned numbers by powers of 2. When multiplying
an unsigned number by a power of 2, it is faster to use SHL than MUL.
Much of the time, you can ignore the high half of the result because the product is small
enough to fit in only the low half of the destination. If it is, MUL clears CF and OF to 0;
otherwise, MUL sets CF and OF to 1.
If the result will fit in a register that is the size of the multiplicand, and you either want to
multiply an unsigned number by an immediate number or you don’t want the result to
overwrite AL or AX, use the second and third forms of IMUL instead of MUL. Although
designed for multiplying integers, these forms of IMUL calculate the same result as MUL
while letting you specify more than one operand.
Related Instruc tions
If you want to
Convert an 8-bit unsigned binary product to its unpacked decimal equivalent
Multiply two integers
Multiply an unsigned number by a power of 2
See
AAM
IMUL
SHL
15
14
13
12
11
10
9
8
7
6
5
4
3
2
1
0
Processor Status
Flags Register
reserved
OF DF
IF TF SF ZF
–
–
AF
PF
CF
= undefined; – = unchanged
OF and CF = 0 if upper half of result is 0
OF and CF = 1 otherwise
–
res res res
WPRODUCTH
WPRODUCTL
DW
DW
; 16-bit unsigned multiplication: DX::AX = CX * AX
MOV
CX,32
MOV
AX,300
MUL
CX
; DX::AX = 00002580h = 9600
; store low word of product
MOV
WPRODUCTL,AX
; if product fits in only low half of destination, then jump
JNC
CONTINUE
; ignore high half
; store high word of product
MOV
WPRODUCTH,DX
CONTINUE:
...