# `imul`

[x86-64 Documentation](https://asm-editor.specy.app/documentation/x86.md) › [Instructions](https://asm-editor.specy.app/documentation/x86/instruction.md)

Web page: https://asm-editor.specy.app/documentation/x86/instruction/imul

**Signed multiply**

Category: Arithmetic

Multiplies signed integers, producing a full implicit product with one operand or a destination-width result with two or three.

8086 and later

[Intel's reference: IMUL](https://intel.github.io/SDM/instruction/IMUL.html)

Used in: [The x86-64 instruction set](https://asm-editor.specy.app/learn/courses/x86/introduction/the-x86-instruction-set.md) (x86-64 assembly), [Arithmetic, logic and bits](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/arithmetic-logic-and-bits.md) (x86-64 assembly), [call, ret and the System V convention](https://asm-editor.specy.app/learn/courses/x86/think-in-assembly/call-ret-and-the-system-v-convention.md) (x86-64 assembly), [Moving values around](https://asm-editor.specy.app/learn/courses/x86/examples/moving-values.md) (x86-64 assembly), [Variables in memory and constants](https://asm-editor.specy.app/learn/courses/x86/examples/variables-in-memory.md) (x86-64 assembly), [Multiply and divide, with the remainder](https://asm-editor.specy.app/learn/courses/x86/examples/multiply-and-divide.md) (x86-64 assembly), [Recursion: factorial and Fibonacci](https://asm-editor.specy.app/learn/courses/x86/examples/factorial-and-fibonacci.md) (x86-64 assembly), [A 2D array](https://asm-editor.specy.app/learn/courses/x86/examples/two-dimensional-array.md) (x86-64 assembly), [Drawing shapes on the screen](https://asm-editor.specy.app/learn/courses/x86/examples/drawing-on-the-screen.md) (x86-64 assembly), [A bouncing ball](https://asm-editor.specy.app/learn/courses/x86/examples/bouncing-ball.md) (x86-64 assembly)

## Flags

| Flag | Effect |
| --- | --- |
| CF | depends on the result |
| PF | undefined (do not rely on it) |
| AF | undefined (do not rely on it) |
| ZF | undefined (do not rely on it) |
| SF | undefined (do not rely on it) |
| DF | not changed |
| OF | depends on the result |

## Forms

- `imul r/m` (8, 16, 32, 64)
  - `imul r/m8`
  - `imul r/m16`
  - `imul r/m32`: 386 and later
  - `imul r/m64`
- `imul reg, r/m` (16, 32, 64)
  - `imul reg16, r/m16`: 386 and later
  - `imul reg32, r/m32`: 386 and later
  - `imul reg64, r/m64`
- `imul reg, r/m, imm` (16, 32, 64)
  - `imul reg16, r/m16, imm8`: 186 and later
  - `imul reg32, r/m32, imm8`: 386 and later
  - `imul reg64, r/m64, imm8`
  - `imul reg16, r/m16, imm16`: 186 and later
  - `imul reg32, r/m32, imm32`: 386 and later
  - `imul reg64, r/m64, imm32`

## Operands

- `r/m`: A general-purpose register or memory location matching the operation’s size, for example `rax` or `qword [rbp-8]`.
- `reg`: A general-purpose register matching the operation’s size, for example `al`, `ax`, `eax` or `rax`.
- `imm`: An immediate value: a constant written in the instruction as a number, a character or a label, for example `10`, `0x1f`, `'a'` or `msg`. Open a row to see the size it has in each form, such as `imm8` or `imm32`.

## Description

With one explicit source, its width selects the implicit factor and full product: 8 bits multiplies `al` into `ax`; 16 bits multiplies `ax` into `dx:ax`; 32 bits multiplies `eax` into `edx:eax`; 64 bits multiplies `rax` into `rdx:rax`.

With two operands, the destination register is multiplied by the source and keeps only the low destination-width bits. With three, the last two operands are multiplied into the first. `imul rax, 5` is shorthand for `imul rax, rax, 5`.

With one operand, CF and OF are set when the high half of the product is more than a sign extension of the low half, so the product does not fit the operand width. With two or three, they are set when the product had to be truncated to fit the destination. SF, ZF, AF and PF are undefined.

An 8-bit immediate used with a wider operand is sign-extended from −128 through 127. For a 64-bit operation, the longer immediate field is only 32 bits and is also sign-extended; there is no full 64-bit immediate form. The encoded bits determine the value used by the operation. For example, a 32-bit field of `0xffffffff` becomes `0xffffffffffffffff` (−1), not positive 4294967295. An out-of-range constant can produce a warning and truncated bits; use a register for a value that cannot be represented by these sign extensions.

NASM normally chooses the short immediate encoding when it preserves the value; a `byte` qualifier is not required. `strict` with an immediate size can prevent that shortening.

## Example

```x86
global _start

section .text
_start:
        mov rax, 12
        mov rbx, 5
        mov rcx, 3
        mov rsi, 9

        imul rax

        mov rax, 60         ; syscall 60: exit
        xor rdi, rdi
        syscall
```
