| |||||||||
| |||||||||
Using Multiplication Instructions:
The MUL instruction multiplies unsigned numbers. IMUL multiplies signed numbers.
For both instructions, one factor must be in the accumulator register
(AL for 8-bit numbers, AX for 16-bit numbers, EAX for 32-bit numbers).
The other factor can be in any single register or memory operand. However, it cannot be an immediate value.
The result overwrites the contents of the accumulator register.
Multiplying two 8-bit numbers produces a 16-bit result returned in AX.
Multiplying two 16-bit operands yields a 32-bit result in DX:AX.
The following examples illustrate multiplication of unsigned and signed numbers.
A nonzero number in the upper half of the result (AH for byte, DX or EDX for word) sets the overflow and carry flags. On the 80186–80486 processors, the IMUL instruction supports three additional operand combinations. The first syntax option allows for 16-bit multipliers producing a 16-bit product or 32-bit multipliers for 32-bit products on the 80386/486. The result overwrites the destination. The syntax for this operation is: IMUL register16, immediate IMUL register32, immediate The second syntax option specifies three operands for IMUL. The first operand must be a 16-bit register operand, the second a 16-bit memory (or register) operand, and the third a 16-bit immediate operand. IMUL multiplies the memory (or register) and immediate operands and stores the product in the register operand with this syntax: IMUL register16,{ memory16 | register16}, immediate For the 80386/486 only, a third option for IMUL allows an additional operand for multiplication of a register value by a register or memory value. The syntax is: IMUL register,{register | memory}
The destination can be any 16-bit or 32-bit register. The source must be the
same size as the destination.
The IMUL instruction with multiple operands can be used for either signed or unsigned multiplication, since the 16-bit product is the same in either case. To get a 32-bit result, you must use the single-operand version of MUL or IMUL. |