imul
Signed Multiply
Signed multiply.
Details
Performs signed multiplication of destination register by source operand, storing result in destination. Sets OF and CF if result overflows destination width; SF, ZF, AF, PF undefined. Two-operand form (dest ← dest * src) is commonly used for scalar multiplies; one-operand form multiplies into EDX:EAX.
Pseudocode Operation
result ← dest * src; dest ← result; if (result overflows dest width) { CF ← 1; OF ← 1; } else { CF ← 0; OF ← 0; }
Example
Encoding
Operands
-
dest
General-purpose register -
src
Register or memory operand
Reference (Intel® SDM)
Instruction Forms
| Opcode | Instruction | Op/En | 64/32-bit Mode | CPUID | Description |
|---|---|---|---|---|---|
| F6 /5 | IMUL r/m8 | M | Valid Valid | AX:= AL ∗ r/m byte. | |
| F7 /5 | IMUL r/m16 | M | Valid Valid | DX:AX := AX ∗ r/m word. | |
| F7 /5 | IMUL r/m32 | M | Valid Valid | EDX:EAX := EAX ∗ r/m32. | |
| REX.W + F7 /5 | IMUL r/m64 | M | Valid N.E. | RDX:RAX := RAX ∗ r/m64. | |
| 0F AF /r | IMUL r16, r/m16 | RM | Valid Valid | Word register := word register ∗ r/m16. | |
| 0F AF /r | IMUL r32, r/m32 | RM | Valid Valid | Doubleword register := doubleword register ∗ r/m32. | |
| REX.W + 0F AF /r | IMUL r64, r/m64 | RM | Valid N.E. | Quadword register := Quadword register ∗ r/m64. | |
| 6B /r ib | IMUL r16, r/m16, imm8 | RMI | Valid Valid | Word register := r/m16 ∗ sign-extended immediate byte. | |
| 6B /r ib | IMUL r32, r/m32, imm8 | RMI | Valid Valid | Doubleword register := r/m32 ∗ signextended immediate byte. | |
| REX.W + 6B /r ib | IMUL r64, r/m64, imm8 | RMI | Valid N.E. | Quadword register := r/m64 ∗ sign-extended immediate byte. | |
| 69 /r iw | IMUL r16, r/m16, imm16 | RMI | Valid Valid | Word register := r/m16 ∗ immediate word. | |
| 69 /r id | IMUL r32, r/m32, imm32 | RMI | Valid Valid | Doubleword register := r/m32 ∗ immediate doubleword. | |
| REX.W + 69 /r id | IMUL r64, r/m64, imm32 | RMI | Valid N.E. | Quadword register := r/m64 ∗ immediate doubleword. |
Description
Operation
IF (NumberOfOperands = 1) THEN IF (OperandSize = 8) THEN TMP_XP := AL ∗ SRC (* Signed multiplication; TMP_XP is a signed integer at twice the width of the SRC *); AX := TMP_XP[15:0]; IF SignExtend(TMP_XP[7:0]) = TMP_XP THEN CF := 0; OF := 0; ELSE CF := 1; OF := 1; FI; ELSE IF OperandSize = 16 THEN TMP_XP := AX ∗ SRC (* Signed multiplication; TMP_XP is a signed integer at twice the width of the SRC *) DX:AX := TMP_XP[31:0]; IF SignExtend(TMP_XP[15:0]) = TMP_XP THEN CF := 0; OF := 0; ELSE CF := 1; OF := 1; FI; ELSE IF OperandSize = 32 THEN TMP_XP := EAX ∗ SRC (* Signed multiplication; TMP_XP is a signed integer at twice the width of the SRC*) EDX:EAX := TMP_XP[63:0]; IF SignExtend(TMP_XP[31:0]) = TMP_XP THEN CF := 0; OF := 0; ELSE CF := 1; OF := 1; FI; ELSE (* OperandSize = 64 *) TMP_XP := RAX ∗ SRC (* Signed multiplication; TMP_XP is a signed integer at twice the width of the SRC *) EDX:EAX := TMP_XP[127:0]; IF SignExtend(TMP_XP[63:0]) = TMP_XP THEN CF := 0; OF := 0; ELSE CF := 1; OF := 1; FI; FI; FI; IMUL—Signed Multiply Vol. 2A 3-452 ELSE IF (NumberOfOperands = 2) THEN TMP_XP := DEST ∗ SRC (* Signed multiplication; TMP_XP is a signed integer at twice the width of the SRC *) DEST := TruncateToOperandSize(TMP_XP); IF SignExtend(DEST) ≠ TMP_XP THEN CF := 1; OF := 1; ELSE CF := 0; OF := 0; FI; ELSE (* NumberOfOperands = 3 *) TMP_XP := SRC1 ∗ SRC2 (* Signed multiplication; TMP_XP is a signed integer at twice the width of the SRC1 *) DEST := TruncateToOperandSize(TMP_XP); IF SignExtend(DEST) ≠ TMP_XP THEN CF := 1; OF := 1; ELSE CF := 0; OF := 0; FI; FI; FI;
Flags Affected
For the one operand form of the instruction, the CF and OF flags are set when significant bits are carried into the upper half of the result and cleared when the result fits exactly in the lower half of the result. For the two- and three-operand forms of the instruction, the CF and OF flags are set when the result must be truncated to fit in the destination operand size and cleared when the result fits exactly in the destination operand size. The SF, ZF, AF, and PF flags are undefined.