Top Banner
Multiplication More complicated than addition A straightforward implementation will involve shifts and adds. More complex operation can lead to More space (on silicon) and/or More time (multiple cycles or longer clock cycle time)
21

Multiplication and Division

Mar 01, 2023

Download

Documents

Khang Minh
Welcome message from author
This document is posted to help you gain knowledge. Please leave a comment to let me know what you think about it! Share it to your friends and learn new things together.
Transcript
Page 1: Multiplication and Division

Multiplication

• More complicated than addition

• A straightforward implementation will involve shifts and adds.

• More complex operation can lead to

• More space (on silicon) and/or

• More time (multiple cycles or longer clock cycle time)

Page 2: Multiplication and Division

Multiplying Integers (Unsigned/Signed)

Solution 1: (Unsigned Integers)

• Multiply using Straightforward Algorithm.

• The Straightforward algorithm only works for unsigned integers.

Solution 2: (Signed Integers)

• Multiply only magnitudes using Straightforward Algorithm.

• If signs are different, negate the answer.

Solution 3: (Signed Integers)

• Booth’s algorithm

• Developed by A.D. Booth in 1950 at Birkbeck College in Bloomsbury,

London.

• Works for signed integers.

Page 3: Multiplication and Division

Booth’s Algorithm

n – Required bits in 2’s complement representation

A - n-bits register

M - n-bits register

Q - n-bits register

Q-1

- 1-bit Register

Page 4: Multiplication and Division

Booth’s Algorithm

• If the multiplicand/multiplier is negative

• Represent in Two’s Complement Representation

• If any carry is generated in addition

• Discard the carry

n - Minimum required bits to represent both M and Q in Two’s Complement Representation

A - n-bits register

M - n-bits register

Q - n-bits register

Q-1

- 1-bit Register

Final Product in A,Q

Page 5: Multiplication and Division

Booth’s Algorithm

❑3X7

❑How many bits are required ?

❑Check Range: -2n-1

to (2n-1

-1)

❑4-bits

❑ Initialize values-

Page 6: Multiplication and Division

Booth’s Algorithm

Result (AQ) = 0001 0101 (Positive Integer) = 21

Page 7: Multiplication and Division

Booth’s Algorithm

n – Required bits in 2’s complement representation

A - n-bits register

M - n-bits register

Q - n-bits register

Q-1

- 1-bit Register

Page 8: Multiplication and Division

Multiplying Signed Integers

• Example: (3) X (-7) using 4-bit Two’s Complement.

• 0011 X 1001

A Q Q -1 M Operations Count

0000 0011 0 1001 -- 4

Q0Q-1 == 10,

A = A – M = A + 2’s complement of M

A = 0000 + 2’s complement of 1001 = 0000 + 0111 =

A = A – M = 0111

0111 0011 0 1001 Subtract (A = A – M)

0011 1001 1 1001 ARS 3

Page 9: Multiplication and Division

Multiplying Signed Integers

• Example: (3) X (-7) using 4-bit Two’s Complement.

• 0011 X 1001

A Q Q -1 M Operations Count

0000 0011 0 1001 -- 4

0111 0011 0 1001 Subtract (A = A – M)

0011 1001 1 1001 ARS 3

0001 1100 1 1001 ARS 2

A = A +M = 0001 + 1001 = 1010

1010 1100 1 1001 Add (A = A + M)

1101 0110 0 1001 ARS 1

1110 1011 0 1001 ARS 0

Page 10: Multiplication and Division

Multiplying Signed Integers

• Example: (3) X (-7) using 4-bit Two’s Complement.

• 0011 X 1001

A Q Q -1 M Operations Count

1110 1011 0 1001 ARS 0

Result = 1110 1011 (Negative Integer)

= Two’s complement of (1110 1011)

= - (0001 0101) = -21

Page 11: Multiplication and Division

Multiplying Signed Integers

Exercise-1

Multiply 20 and 15

Exercise-2

Multiply 20 and -15

Exercise-3

Multiply -20 and 15

Exercise-4

Multiply -20 and -15

Page 12: Multiplication and Division

Why Booth Algorithm works?

• The multiplicand/multiplier (M/Q) may be positive or negative.

• Positive (M/Q) - n-bit binary equivalent

• Negative (M/Q) - n-bit Two’s complement

Page 13: Multiplication and Division

Why Booth Algorithm works?

• Booth's algorithm performs an Arithmetic Right Shift for all combinations of

0 and 1

• 00, 11, 01, 10

• When it encounters Q0Q-1 = 01

• It performs an addition

• When it encounters the end of the block of ones (01)

• When it encounters Q0Q-1 = 10

• It performs a subtraction

• When it encounters the first digit of a block of ones (10)

Page 14: Multiplication and Division

Why Booth Algorithm works?

Page 15: Multiplication and Division

Why Booth Algorithm works?

Property: The sum of series of numbers (Which can be represented in continuous

power of 2) can be reduced to two operations i.e. one addition and one subtraction

2n +2n-1 + ———— +2n-K = 2n+1 - 2n-K

Example

• (24 + 23 + 22 + 21) = (25 - 21)

• (27 + 26 + 23 + 22) = (28 – 26 + 24 - 22)

• 22 = (23 - 22)

Page 16: Multiplication and Division

Why Booth Algorithm works?

• First check for unsigned numbers,

• 19X 30

• M X Q

• 0001 0011 X 0001 1110

• M X 0001 1110

• 0001 0011 X (24 + 23 + 22 + 21)

• 0001 0011 X (30)

• 0001 0011 X (32-2)

• 0001 0011 X (25 - 21)

• 19X (25 - 21)

Page 17: Multiplication and Division

Why Booth Algorithm works?

Positive Integers

Due to previous property, the product can be generated by one addition and one

subtraction of the multiplicand.

• M X Q

• 0001 0011 X 0001 1110

• 0001 0011 X (24 + 23 + 22 + 21)

• 0001 0011X (25 - 21)

• Check it using Booth’s Algorithm

This scheme extends to any number of blocks of 1s in a multiplier, including

the case in which a single 1 is treated as a block.

• 0001 1110 X 0001 0011

• 0001 1110 X (24 + 21 + 20)

• 0001 1110 X (25 - 24 + 22 - 20)

• Check it using Booth’s Algorithm

Page 18: Multiplication and Division

Why Booth Algorithm works?

Negative Integers

The MSB is 1 for negative integers.

• X = 1xn-2xn-3…….x1x0

• X = -2n-1 + xn-2*2n-2 + xn-3*2n-3 ……… + x1*21 + x0*20

Example:

(-97)10 = -(0110 0001) = 1001 1111

1001 1111 = -27 + 1*24 + 1*23 + 1*22 + 1*21 + 1*20

1001 1111 = -128 + 16 + 8 + 4 + 2 + 1

1001 1111 = -128 + 31 = -97

Page 19: Multiplication and Division

Why Booth Algorithm works?

Assume X = 1 1 1….110xk-1

xk-2

….x1x

0

• X = -2n-1 + 2n-2 + 2n-3 +…… 2k+1 + xk-1*2k-1 + xk-2*2k-2 +…… + x1*21 +

x0*20

• X = -2n-1 + 2n-2+1 - 2k+1 + xk-1*2k-1 + xk-2*2k-2 +…… + x1*21 + x0*20

• X = - 2k+1 + xk-1*2k-1 + xk-2*2k-2 +…… + x1*21 + x0*20

As the algorithm scans over the leftmost 0 and encounters the next 1 (2k + 1

), a 1–0 transition occurs and a

subtraction takes place ( - 2k + 1

).

Page 20: Multiplication and Division

Why Booth Algorithm works?

Negative Integers

In Two's complement representation, using an 8-bit word, (-6) is represented as 1111 1010

M*(-6) = M* (Two’s complement of 6) = M*(One’s complement of 6 + 1)

= M*1111 1010

1111 1010 = -27 +2

6 +2

5 +2

4 +2

3 +2

1

M*(11111010) = M*(-27 +2

6 +2

5 +2

4 +2

3+ 2

1) = M*(-2

7 +2

7 - 2

3+ 2

2 -2

1)

M*(11111010)=M*(-23 + 2

2 -2

1)

Replace M = 7 = 0000 0111, Compute using Booth’s Algorithm

Page 21: Multiplication and Division

Why Booth Algorithm works?

Negative Integers

In twos complement representation, using an 8-bit word, (-15) is represented as 1111 0001

M*(-63) = M* (Two complement of 63) = M*(One’s complement of 63 + 1)

= M* 1111 0001

1111 0001 = -27 +2

6 +2

5+2

4 +2

0

M*(1100 0001) = M*(-27 +2

6 +2

5 +2

4 +2

0) = M*(-2

7 +2

7 - 2

4+ 2

1 -2

0)

M*(1100 0001) = M*(-24 + 2

1 -2

0)

Replace M = 7 = 0000 0111, Compute using Booth’s Algorithm