0% found this document useful (0 votes)
119 views13 pages

DSD Lectures 13 14

Here are solutions to the practice problems using the techniques discussed: -11 * -12 By Booth's Recoding: -11 = (1 1 1 1) -12 = (1 1 0 0) Recoded versions: -11 = (1 -1 1 -1) -12 = (1 -1 0 0) Partial products: p(0) = 0 p(1) = -12 = 128 p(2) = 11 = 112 p(3) = -12 = 128 Sum = 128 + 112 + 128 = 368 45 By multiplication by constants: 45 = (1 0 1 0 1) R

Uploaded by

ammar abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
119 views13 pages

DSD Lectures 13 14

Here are solutions to the practice problems using the techniques discussed: -11 * -12 By Booth's Recoding: -11 = (1 1 1 1) -12 = (1 1 0 0) Recoded versions: -11 = (1 -1 1 -1) -12 = (1 -1 0 0) Partial products: p(0) = 0 p(1) = -12 = 128 p(2) = 11 = 112 p(3) = -12 = 128 Sum = 128 + 112 + 128 = 368 45 By multiplication by constants: 45 = (1 0 1 0 1) R

Uploaded by

ammar abbas
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PPTX, PDF, TXT or read online on Scribd
You are on page 1/ 13

Multiplier

Lectures 13 & 14
Shift/Add Multiplication Algorithms

 Notation for our discussion of multiplication algorithms:


 a Multiplicand ak–1ak–2 . . . a1a0
 x Multiplier xk–1xk–2 . . . x1x0
 p Product (a  x) p2k–1p2k–2 . . . p3p2p1p0
 Initially, we assume unsigned operands
a Multiplicand
 x Multiplier
x0a 20
Partial
x1a 21
products
x2a 22 bit-matrix
x3a 23
p Product
Right Shift & Left Shift Sequential
Multiplier:
 Multiplication with right shifts: top-to-bottom accumulation

 p(j+1) = (p(j) + xj a 2k) 2–1 withp(0) = 0 and


 |–––add–––| p(k) = p = ax + p(0)2–k
 |––shift right––|

Multiplication with left shifts: bottom-to-top accumulation


p(j+1) = 2 p(j) + xk–j–1a withp(0) = 0 and
|shift| p(k) = p = ax + p(0)2k
|––––add––––|
Right Shift & Left Shift Algorithm

• Right-shift algorithm Left-shift algorithm


• ========================
Check:
======================= 10  11
•a 1 0 1 0a 1 0 1 0 = 110
•x 1 0 1 1x 1 0 1 1 = 64 + 32 +
• ======================== 8+4+2
=======================
• p(0) 0 0 0 0 p(0) 0 0 0 0
• +x0a 1 0 1 0 2p(0) 0 0 0 0 0
• ––––––––––––––––––––––––– +x3a 1 0 1 0
• 2p(1) 0 1 0 1 0 ––––––––––––––––––––––––
• p(1) 0 1 0 1 0 p(1) 0 1 0 1 0
• +x1a 1 0 1 0 2p(1) 0 1 0 1 0 0
• ––––––––––––––––––––––––– +x2a 0 0 0 0
• 2p(2) 0 1 1 1 1 0 ––––––––––––––––––––––––
• p(2) 0 1 1 1 1 0 p(2) 0 1 0 1 0 0
• +x2a 0 0 0 0 2p(2) 0 1 0 1 0 0 0
• ––––––––––––––––––––––––– +x1a 1 0 1 0
• 2p(3) 0 0 1 1 1 1 0 ––––––––––––––––––––––––
• p(3) 0 0 1 1 1 1 0 p(3) 0 1 1 0 0 1 0
Hardware realization of the sequential multiplication
algorithm with Right shifts and additions

Shift

Multiplier x

Doublewidth partial prod uct p (j)

Shift

Multiplica nd a
0 p(j+1) = (p(j) + xj a 2k) 2–1
x
0
Mux 1
k
|–––add–––| j
|––shift right––|
xj a k

Adder
cout
k
Hardware realization of the sequential multiplication algorithm
with left shifts and additions.

Shift

Multiplier x

Doublewidth partial prod uct p (j)

Shift

xk -j-1 2k Multiplica nd a
0
0 1
Mux
xk -j-1a k

2k-bit adder
cout
2k
Signed Multiplication:Booth’s Recoding
Table: Radix-2 Booth’s recoding
–––––––––––––––––––––––––––––––––––––
xi xi–1 yi Explanation
–––––––––––––––––––––––––––––––––––––
0 0 0 No string of 1s in sight
0 1 1 End of string of 1s in x
1 0 -
1Beginning of string of 1s in x
1 1 0 Continuation of string of 1s in x
–––––––––––––––––––––––––––––––––––––
Example
1 0 0 1 1 1 0 1 1 0 1 0 1 1 1 0 Operand x
(1) -1 0 1 0 0 -1 1 0 -1 1 -1 1 0 0 -1 0 Recoded version y

Justification
2j + 2j–1 + . . . + 2i+1 + 2i = 2j+1 – 2i
Example Multiplication with Booth’s Recoding

Check:
• ============================ –
10  –11
• a 1 0 1 1 0 = 110
• x 1 0 1 0 1 Multiplier = 64 + 32 +
• y -
1 1 -1 1 -1 Booth-recoded 8+4+2
–––––––––– • ============================
xi–1 yi •
i p(0) 0 0 0 0 0
–––––––––– • +y0a 0 1 0 1 0
0 0 0
• –––––––––––––––––––––––––––––
0 1 1
• 2p(1) 0 0 1 0 1 0
1 0 -
1
1 1 0 • p(1) 0 0 1 0 1 0
–––––––––– • +y1a 1 0 1 1 0
• –––––––––––––––––––––––––––––
• 2p(2) 1 1 1 0 1 1 0
• p(2) 1 1 1 0 1 1 0
• +y2a 0 1 0 1 0
• –––––––––––––––––––––––––––––
• 2p(3) 0 0 0 1 1 1 1 0
• p(3) 0 0 0 1 1 1 1 0
• +y a 1 0 1 1 0
Multiplication by Constants
 Software aspects:
 Optimizing compilers replace multiplications by shifts/adds/subs
 Produce efficient code using as few registers as possible
 Find the best code by a time/space-efficient algorithm
 Three methods used :
 Factorization
 Recoding
 Binary Expansion
Multiplication Using Binary Expansion

 Example: Multiply R1 by the constant 113 = (1 1 1 0 0 0 1)two

 R2  R1 shift-left 1
 R3  R2 + R1
 R6  R3 shift-left 1
 R7  R6 + R1
 R112  R7 shift-left 4
 R113  R112 + R1
Shorter sequence using shift-and-add instructions
R3  R1 shift-left 1 + R1
R7  R3 shift-left 1 + R1
R113  R7 shift-left 4 + R1
Multiplication via Factorization

 Example: Multiply R1 by 119 = 7  17


 = (8 – 1)  (16 + 1)

 R8  R1 shift-left 3
 R7  R8 – R1
 R112  R7 shift-left 4
 R119  R112 + R7

Shorter sequence using shift-and-add/subtract instructions


R7  R1 shift-left 3 – R1
R119  R7 shift-left 4 + R7
Multiplication via Recoding

Example: Multiply R1 by 113 = (1 1 1 0 0 0 1)two = (1 0 0-1 0 0 0 1)two

 R8  R1 shift-left 3
 R7  R8 – R1
 R112  R7 shift-left 4
 R113  R112 + R1

Shorter sequence using shift-and-add/subtract instructions


R7  R1 shift-left 3 – R1
R113  R7 shift-left 4 + R1
Practice Problems
 By Booth’s Recoding
 -11* -12
 By Multiplcation by constants:
 45
 119

You might also like