Overview of Multiplication and Division
Course Code: COE 3205 Course Title: Computer Organization &
Architecture
Dept. of Computer Science
Faculty of Science and Technology
Lecturer No: 12 Week No: 13 Semester:
Lecturer: Name & email
Lecture Outline
1. Overview
2. Multiplication
3. Division
Overview
In this chapter, we introduce Instructions for multiplying
and dividing any numbers
The process of multiplication and division is different for
signed and unsigned numbers. So there are different
Instructions for signed and unsigned multiplication and
division.
Again, these instructions have byte and word forms
Signed versus Unsigned
Multiplication
MUL and IMUL
Syntax of MUL and IMUL
Byte Form Multiplication
Word Form Multiplication
Effect of MUU/MUL on the status flags
Simple Applications· of MUL and IMUL
Signed versus Unsigned
Multiplication
In binary multiplication, signed· and unsigned numbers must be
treated differently.
For example, suppose we want to multiply the eight-bit numbers
10000000 and 11111111. Interpreted as unsigned numbers, they
represent 128 and 255 respectively.
The product is 32,640 = 0111111110000000b.
However, taken as signed numbers, they represent-128 and -1,
respectively; and the product is 128 = 0000000010000000b
Signed versus Unsigned
Multiplication
MUL and IMUL
Since signed and unsigned multiplication lead to different
results. There are two multiplication Instructions:
MUL (multiply for unsigned multiplication.
IMUL for signed multiplication.
Signed versus Unsigned
Multiplication
Syntax of MUL and IMUL
MUL source
IMUL Source
Signed versus Unsigned
Multiplication
Byte and Word Form of MUL and IMUL
MUL and IMUL instructions multiply bytes or words.
Byte Form: If two bytes are multiplied, then product is a word
(16 bits).
Word Form: If two words are multiplied, the product is a
doubleword (32 bits).
Signed versus Unsigned
Multiplication
Byte Form Multiplication
For byte multiplication, one number is contained in the source
and the other is assumed to be in AL.
The 16-bit product will be in AX.
The source may be a byte register or memory byte, but cannot
be a constant
Signed versus Unsigned
Multiplication
Byte Form Multiplication
For word form multiplication, one number is contained in the
source and the other is assumed to be in AX.
The most significant 16 bits of the doubleword product will be
in DX,
And the least significant 16 bits will be in AX
Sometimes it is written as DX:AX.
The source may be a 16-bit register or memory word, but not
a· constant.
Signed versus Unsigned
Multiplication
Effect of MUU/MUL on the status flags
SF,ZF,AF, PF: undefined
CF/OF:
• After MUL, CF/OF : = 0 if the upper half of the result is·
zero , otherwise CF/OF = 1
• After IMUL, CF/OF = 0 if the upper half of the result is the
sign extension of the lower half (this means that the bits of
the upper half are the same as the sign bit of the lower half).
= otherwise CF/OF = 1.
Signed versus Unsigned
Multiplication
Meaning of CF/OF = 1 on MUL and IMUL
For both MUL and IMUL, CF/OF = l means that the product is
too big to fit' in 'the lower half of the destination (AL for byte
multiplication, AX for word multiplication).
Signed versus Unsigned
Multiplication
Example of Multiplication
Example 1: Suppose AX contains, 1 and BX contains FFFFh
Instructions Decimal Hex DX AX CF/OF
Product Product
MUL BX 65535 0000FFFF 0000 FFFF 0
IMUL BX -1 FFFFFFFF FFFF FFFF 0
For MUL. DX = 0, so CF/OF= 0.
for IMUL, the signed interpretation of BX is -1, and the product is
also -1. In 32 bits, this is FFFFFFFFh. CF/OF = 0 because DX is the
sign extension of AX.
Signed versus Unsigned
Multiplication
Example of Multiplication
Example 9.1: Suppose AX contains, 1 and BX contains FFFFh
Instructions Decimal Hex DX AX CF/OF
Product Product
MUL BX 65535 0000FFFF 0000 FFFF 0
IMUL BX -1 FFFFFFFF FFFF FFFF 0
For MUL. DX = 0, so CF/OF= 0.
for IMUL, the signed interpretation of BX is -1, and the product is
also -1. In 32 bits, this is FFFFFFFFh. CF/OF = 0 because DX is the
sign extension of AX.
Signed versus Unsigned
Multiplication
Example of Multiplication
Signed versus Unsigned
Multiplication
Example of Multiplication
Signed versus Unsigned
Multiplication
Example of Multiplication
Signed versus Unsigned
Multiplication
Example of Multiplication
Signed versus Unsigned
Multiplication
Simple Applications· of MUL and IMUL
Signed versus Unsigned
Multiplication
Simple Applications (1) of MUL and IMUL
Signed versus Unsigned
Multiplication
Simple Applications (2) of MUL and IMUL continues…
Signed versus Unsigned
Multiplication
Simple Applications of MUL and IMUL
Signed versus Unsigned
Division
Division Syntax
Division Syntax
Division Byte Form
Division Word Form
Division Overflow
Sign Extension of the Dividend
Signed versus Unsigned
Division
Division Syntax
When division is performed, we obtain two results, the quotient
and the remainder.
As with multiplication, there are separate Instructions for
unsigned and signed division
DIV (divide) is used for unsigned division
IDIV-(lnteger divide) is used for signed division.
The syntax :
• DIV divisor
• IDIV divisor
Signed versus Unsigned
Division
Division Byte Form
The divisor is an 8-bit register or memory byte.
The 16-bit dividend is assumed to be in AX.
After division, the 8-bit quotient is in AL and the 8-bit
remainder is in AH.
The divisor may not be a constant
Signed versus Unsigned
Division
Division Word Form
Here the divisor is a 16-bit register or memory word
The 32-bit dividend is assumed to be in DX:AX
After division, the 16-bit quotient is nn AX and the 16-bit
remainder is in DX.
The divisor may not he a constant.
For signed division, the remainder has the same sign as the
dividend. If both dividend and divisor are positive, DIV and IDIV
give the same result.
The effect of DIV /IDIV on the flags is that all status flags are
undefined
Signed versus Unsigned
Division
Division Overflow
It is possible that the quotient will be too big to fit in the
specified destination· (AL or AX).
This can happen if the divisor is much smaller than the dividend
When this happens, the program terminates and the system
displays the message "Divide Overflow"
Signed versus Unsigned
Division
Division Example
Signed versus Unsigned
Division
Division Example
Signed versus Unsigned
Division
Division Example
Signed versus Unsigned
Division
Division Example
Signed versus Unsigned
Division
Division Example
Signed versus Unsigned
Division
Sign Extension of the Dividend
Word Division
In word division, the dividend Is in DX:AX even if the actual
dividend will fit in AX. In this case DX should be prepared as
follows:
1. For DIV, DX should be cleared.
2. For IDIV, DX should be made the sign extension of AX.
The instruction CWD (convert word to doubleword) will do the
extension.
Signed versus Unsigned
Division
Sign Extension of the Dividend - Example
Signed versus Unsigned
Division
Sign Extension of the Dividend – Byte Division
Byte Division
In the byte division, dividend is in AX.
If the actual dividend is a byte; then AH should be prepared as
follows:
1. For DIV, AH should be cleared.
2. For IDIV AH, should the sign extension of AL.
The instruction CBW (convert byte to word) will do the
extension.
Signed versus Unsigned
Division
Sign Extension of the Dividend – Byte Division example
Books
• Assembly Language Programing and
Organization of the IBM PC
Ytha Yu
Charles Marut
References
• Multiplication and Division Instrution in Assembly
• https://www.youtube.com/watch?v=LDXI8OW7kfk&t=348s
• Carry and Overflow Details
• https://www.youtube.com/watch?v=9cXe_T99nL4