
Instruction Set
4-162
MUL
MUL
Flag Settings After Instruction
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.
Tips
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 Instructions
If you want to
See
Convert an 8-bit unsigned binary product to its unpacked decimal equivalent
AAM
Multiply two integers
IMUL
Multiply an unsigned number by a power of 2
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
DW
?
WPRODUCTL
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:
...
Summary of Contents for Am186 Series
Page 1: ...Am186 and Am188 Family Instruction Set Manual February 1997...
Page 10: ...Table of Contents x...
Page 18: ...Programming 1 8...
Page 40: ...Instruction Set Listing 3 14...