x86 Assembly Language Reference Manual

Signed Multiply (imul)

imulb		r/m8
imulw		r/m16
imul{l}		r/m32
imul{wl}		r/m[16|32], reg[16|32]
imul{bwl}		imm[16|32], r/m[16|32], reg[16|32]
Operation

r/m8 x AL -> AX r/m16 x AX -> DX:AX

r/m32 x EAX -> EDX:EAX r/m[16|32] x reg[16|32] -> reg|16|32]

imm[16|32] x r/m[16|32] -> reg|16|32]

Description

The single-operand form of imul executes a signed multiply of a byte, word, or long by the contents of the AL, AX, or EAX register and stores the product in the AX, DX:AX or EDX:EAX register respectively.

The two-operand form of imul executes a signed multiply of a register or memory word or long by a register word or long and stores the product in that register word or long.

The three-operand form of imul executes a signed multiply of a 16- or 32-bit immediate by a register or memory word or long and stores the product in a specified register word or long.

imul clears the overflow and carry flags under the following conditions:

Table 2-5 Clearing OR and CF Flags -- imul

Instruction Form  

Condition for Clearing OF and CF 

r/m8 x AL -> AX 

AL = sign-extend of AL to 16 bits  

r/m16 x AX -> DX:AX 

AX= sign-extend of AX to 32 bits  

r/m32 x EAX -> EDX:EAX 

EDX:EAX= sign-extend of EAX to 32 bits  

r/m[16|32] x reg[16|32] -> reg|16|32] 

Product fits exactly within reg[16|32]  

imm[16|32] x r/m[16|32] -> reg|16|32] 

Product fits exactly within reg[16|32] 

Example

Perform an 8-bit signed multiply of the AL register and the contents of the effective address (addressed by the ESI register plus an offset of 1):

imulb 1(%esi)

Perform a 16-bit signed multiply of the constant, -126, and the contents of the effective address (addressed by the EDI register plus an offset of 4). Store the result in the DX register:

imulw $-126, 4(%edi), %dx

Perform a 32-bit signed multiply of the constant, 12345678, and the contents of the effective address (addressed by the EDI register plus an offset of 4). Store the result in the EDX register:

imull $12345678, 4(%edi), %edx