UMBC CMSC 211

CSEE | 211 | Current | lectures | news | help


Multiplication and Division

Multiplication is truly a shortcut for addition, while division is a shortcut for subtraction. Four times three is equal to four plus four plus four. Division is 1) twelve minus four 2) eight minus four and 3) four minus four. Forunately, the hardware designers now let us do it with a single instruction.

However, it is still a little more complex than before. First of all, it takes longer. There is also the problem with the size of numbers (even more so than addition and subtraction!) 99 times 99 is 9801. A byte times a byte can result in a word! Multiplying two n-digit numbers will probably result in a 2n-digit number. Division goes the other direction, but is even more difficult because we have to keep track of the remainder. Then comes the wrinkle of signs!

So when you multiply two sixteen bit numbers, expect the answer to require more bits! The 80x86 CPU requires special registers for this:
Operand Size Multiplicand Multiplier Product
BYTE AL Reg or Memory AX
WORD AX Reg or Memory AX (low) and DX (high)

Division is similar:
Operand Size Dividend Divisor Quotient Remainder
BYTE AX Reg or Memory AL AH
WORD AX and DX Reg or Memory AX DX

You can not use a constant operand with multiplication or division. Use the mov instruction to put a constant into the appropriate register.

Did I mention something about the sign? There are different instructions based on whether or not it is a signed or unsigned operation. That leads us to the following:
Instruction Description
mul unsigned multiplication
div unsigned division
imul signed multiplication
idiv signed division

Yes, but....