The IMUL instruction
Signed multiplication.
The IMUL instruction format
| Instruction | Description |
|---|---|
| IMUL reg/mem8 | Signed multiplication (AX := AL ∗ reg/mem8). |
| IMUL reg/mem16 | Signed multiplication (DX:AX := AX ∗ reg/mem16). |
| IMUL reg16, reg/mem16, imm8 | Multiplies reg16/mem16 by imm8 and stores the result in reg16. (186/286C) |
Multiplies the contents of the specified register or memory location by the al register (8-bit operation) or the ax register (16-bit operation), treating both operands as signed binary numbers, i.e. it performs signed multiplication.
If an 8-bit operation is performed, the 8 least significant bits of the result are stored in the al register, and the 8 most significant bits of the result are stored in the ah register. If a 16-bit operation is performed, the least significant 16 bits of the result are stored in the ax register, and the most significant 16 bits of the result are stored in the dx register. If the high half of the result is a sign extension of the low half of the result, the overflow and carry flags are set to 0; otherwise they are set to 1.
Usage example
title .286C .model small .stack 100h code segment public ; Start of the code segment assume cs:code main proc ; Start of the main procedure mov ax, -2 ; Copy the value -2 into the ax register mov bx, 4 ; Copy the value 4 into the bx register imul bx ; Perform signed multiplication of ax by bx mov ax, 5 ; Copy the value 5 into the ax register imul bx, ax, 2 ; Perform signed multiplication of ax by 2. The result is in bx mov ax, 4C00h ; Copy the process termination function number into ah and the value into al int 21h ; Call the interrupt main endp ; End of the main procedure code ends ; End of the code segment end main ; End of file. The main procedure is the entry point
Example taken from the textbook "HANDYFAR - MASM (Evgeny Sergeevich Dovgopolov)".