Booths Algorithm
Booths Algorithm
Booths Algorithm
and Division
Unsigned Multiplication
Signed Multiplication
Faster Multiplication
Unsigned Division
Signed Division
Multiplication and Division in MIPS
Shah Murtaza Rashid Al Masud
Unsigned Multiplication
Paper and Pencil Example:
Multiplicand
11002 = 12
Multiplier
11012 = 13
1100
0000
1100
1100
Product
100111002 = 156
m-bit multiplicand n-bit multiplier = (m+n)-bit product
Accomplished via shifting and addition
Consumes more time and more chip area
Initialize Product = 0
Multiplicand is zero extended
Start
=1
shift left
Multiplicand
=0
64 bits
add
64-bit ALU
Multiplier[0]?
64 bits
write
Product
Control
64 bits
shift right
Multiplier
32 bits
32nd Repetition?
Yes
Multiplier[0]
Shah Murtaza Rashid Al Masud
Done
4
No
Signed Multiplication
Version 1 of Signed Multiplication
Convert multiplier and multiplicand into positive numbers
If negative then obtain the 2's complement and remember the sign
Refined Version:
Use the refined version of the unsigned multiplication hardware
When shifting right, extend the sign of the product
If multiplier is negative, the last step should be a subtract
Shah Murtaza Rashid Al Masud
11002 = -4
01012 = +5
11111100
111100
Product
111011002 = -20
11002 = -4
11012 = -3
11111100
111100
00100
(2's complement of 1100)
Product
000011002 = +12
Shah Murtaza Rashid Al Masud
Multiplicand
32 bits
=1
32 bits
33-bit ALU
add, sub
33 bits
sign
32 bits
=0
LO[0]?
shift right
HI
LO
64 bits
write
Control
LO[0]
32nd Repetition?
Yes
Done
No
Unsigned Division
10
Initialize:
Remainder = Dividend (0-extended)
Load Upper 32 bits of Divisor
Quotient = 0
shift right
Divisor
0
64 bits
64-bit ALU
Remainder
<0
sub
2. Remainder = Difference
Set least significant bit of Quotient
sign
Difference
Difference?
write
Control
64 bits
shift left
Quotient
32 bits
32nd Repetition?
Yes
set lsb
Done
11
No
12
13
Start
Divisor
Difference?
<0
32 bits
2. Remainder = Difference
Set least significant bit of Quotient
sub
32-bit ALU
sign
Difference
write
Remainder Quotient
32 bits
32 bits
Control
shift left
set lsb
Shah Murtaza Rashid Al Masud
32nd Repetition?
Yes
Done
14
No
15
Signed Division
Simplest way is to remember the signs
Convert the dividend and divisor to positive
Obtain the 2's complement if they are negative
16
1.
1.
Quotient = 5
Remainder = +2
1.
Remainder = +2
1.
Quotient = +5
Quotient = 5
Remainder = 2
Quotient = +5
Remainder = 2
17
Multiplication in MIPS
Two Multiply instructions
mult
$s1,$s2Signed multiplication
$0
$1
..
$31
LO = low-order 32-bit
Multiply
Divide
HI
18
LO
Division in MIPS
Two Divide instructions
div
$s1,$s2
divu $s1,$s2
Signed division
Unsigned division
$0
$1
..
$31
Multiply
Divide
HI
19
LO
Arithmetically shift the value obtained in the 2nd step by a single place to the right.
Let P now equal this new value.
Repeat steps 2 and 3 until they have been done y times.
Drop the least significant (rightmost) bit from P. This is the product of m and r.
Shah Murtaza Rashid Al Masud
20
Example1
Find 3 4, with m = 3 and r = 4, and x = 4 and y = 4:
A = 0011 0000 0
S = 1101 0000 0
P = 0000 1100 0
Perform the loop four times:
P = 0000 1100 0. The last two bits are 00.
P = 0000 0110 0. Arithmetic right shift.
21
Example2
The above mentioned technique is inadequate when the multiplicand is
the largest negative number that can be represented (i.e. if the multiplicand has 8 bits
then this value is 128). One possible correction to this problem is to add one more bit
to the left of A, S and P. Below, we demonstrate the improved technique by multiplying
8 by 2 using 4 bits for the multiplicand and the multiplier:
A = 1 1000 0000 0
S = 0 1000 0000 0
P = 0 0000 0010 0
Perform the loop four times:
P = 0 0000 0010 0. The last two bits are 00.
P = 0 0000 0001 0. Right shift.
The product is 11110000 (after discarding the first and the last bit) which is 16.
22
23
Example
Find 3 -4:
A = 0011 0000 0
S = 1101 0000 0
P = 0000 1100 0
Perform the loop four times :
P = 0000 1100 0. The last two bits are 00.
P = 0000 0110 0. A right shift.
P = 0000 0110 0. The last two bits are 00.
P = 0000 0011 0. A right shift.
P = 0000 0011 0. The last two bits are 10.
P = 1101 0011 0. P = P + S.
P = 1110 1001 1. A right shift.
P = 1110 1001 1. The last two bits are 11.
P = 1111 0100 1. A right shift.
24