You are on page 1of 38

Computer Arithmetic

Hamcher Chapter 6

yn 1

y1

y0
Add/Sub
control

xn 1

x1

x0

nbitadder

cn

sn

Figure6.3.

s1

c0

s0

Binaryadditionsubtractionlogicnetwork.

RegisterA(initially0)
Shiftright
an

a0

qn

q0

MultiplierQ
Add/Noadd
control

nbit
adder

Control
sequencer

MUX
0

mn

0
m0

MultiplicandM
(a)Registerconfiguration
M
1101
0
C
0
0

0000
A
1101
0110

1011
Q
1011
1101

1
0

0011
1001

0
0
1
0

Initialconfiguration
Add
Shift

Firstcycle

1101
1110

Add
Shift

Secondcycle

1001
0100

1110
1111

Noadd
Shift

Thirdcycle

0001
1000

1111
1111

Add
Shift

Fourthcycle

Product
(b)Multiplicationexample

Figure6.7.Sequentialcircuitbinarymultiplier.

0
0

1 0 1 1 0
0 +1 +1 + 1 +1

1
0

0
0
1
1
0

0
1
0
1

0
1
0
1
1

0
1
1
0
1

0
1
0
1

0
0
1

0
1

0
1

0
1
0

0
0

0
0

0
0

0
0

0
0

0
0

0 1
0 +1

0
0

1
0

1 0
0 1

1
0

0
1
0
0
0
0
0

0
1
0
0
0
0
0

0
1
0
0
0
0
0

0
1
0
0
0
1
0

0
1
0
0
0
0
0

0
1
0
0
0
1
0

0
1
0
0
0
1
0

0
0
0
0
0
0
0

0
1
0
0
0
1

0
0
0
0
0

0
0
0
0

0
1
0

0
1

2'scomplementof
themultiplicand

Figure6.9.NormalandBoothmultiplicationschemes .

0 +1 1 +1

0 1

0 +1

0 1 +1 1 + 1

Figure6.10.Boothrecodingofamultiplier.

0 1

0 1 1 0 1
1 1 0 1 0

( + 13)
6

0 1 1 0 1
0 1 +1 1 0
0
1
0
1
0

0
1
0
1
0

0
1
0
1
0

0
1
0
0
0

0
1
1
0
0

0
0
1
1
0

0 0 0 0
0 1 1
0 1
1

1 1 1 0 1 1 0 0 1 0

Figure6.11.Boothmultiplicationwithanegativemultiplier.

78

Multiplier
Biti

Biti 1

Versionofmultiplicand
selectedbybit i

0M

+1M

1M

0M

Figure6.12.Boothmultiplierrecodingtable.

Worstcase
multiplier
+1 1 +1 1 +1 1 +1 1 +1 1 +1 1 +1 1 +1 1

Ordinary
multiplier
0 1 0

0 +1 1 +1

0 1 +1

0 1

0 +1

0 1

0 +1

0 1

Good
multiplier

Figure6.13.Boothrecodedmultipliers.

Signextension

+1

Implied0torightofLSB

(a)ExampleofbitpairrecodingderivedfromBoothrecoding

Multiplierbitpair
i + 1

0
0
0
0
1
1
1
1

0
0
1
1
0
0
1
1

Multiplierbitontheright
i 1
0
1
0
1
0
1
0
1

(b)Tableofmultiplicandselectiondecisions

Figure6.14Multiplierbitpairrecoding.

Multiplicand
selectedatposition
+
+
+

0
1
1
2
2
1
1
0

M
M
M
M
M
M
M
M

0
1
0
1
0
1

1
1
0
1

0
1
0
1
0
1

1
1
0
1

0
1
0
1
0
1

1
1
0
1

0
1
0
0
0
0

1
1
0
0

0
1

1
1

1
0

0
1

1
0

0
1
1
0
0
1

0 1 1 0
0 1 +1 1
0 0 0 0
0 0 1 1
1 0 1
1 1
0
1 0 0 1

1
0
0

1
0
0
1

0
0
0
0
0
1

1
1
0 1
1 1

( + 13 )
6

78

1
2
1 0
0

Figure6.15.Multiplicationrequiringonlyn/2summands.

DIVISION

13

21
274
26

10101
1101 100010010
1101

14
13
1

10000
1101
1110
1101
1

Figure6.20.Longhanddivisionexamples.

Shiftleft
an

an 1

a0

q n 1

q0
DividendQ
Quotient
setting

Add/Subtract

n +1bit
adder

Control
sequencer

mn 1

m0
DivisorM

Figure6.21.Circuitarrangementforbinarydivision.

11

10
1000
11
10

Initially
Shift
Subtract
Set q 0
Restore
Shift
Subtract
Set q 0
Restore
Shift
Subtract
Set q 0
Shift
Subtract
Set q 0
Restore

0
0
0
1
1

0
0
0
1
1

0
0
0
1
1

0
0
1
1

0
0
1
1

0
0
1
1

0
0
1
0

0
0
1
0

0
1
1
0

0
1
1

0
1
1

0
1
1

0
1
0
0
1
1
0
1
0
1
1
1
0
0
0

0
1
1
1
0
1
1
0
1
1
1
0
0
1
1

0
0

0
0

0
0

1
0
1
1
1

0
1
1
1
0

0
0

Remainder

0
Firstcycle
0
Secondcycle

0
0

0
0

0
0

0
Thirdcycle

0
0

0
1

1
Fourthcycle

Quotient

Figure6.22.Arestoringdivisionexample.

Initially

0
0
0
1
1

0
0
0
1
1

0
1
0
0
1

0
1
1
1
0

Shift
Subtract
Set q 0

0
0
0
1
1

Shift
Add
Set q 0

1
0
1

1
0
1

1
0
1

0
1
1

0
1
1

Shift
Add
Set q 0

1
0
0

1
0
0

1
0
0

1
1
0

0
1
1

Shift
Subtract
Set q 0

0
1
1

0
1
1

0
1
1

1
0
1

0
1
1

0
Firstcycle
0

Secondcycle

Thirdcycle

Fourthcycle

Quotient
Add

1
0
0

1
0
0

1
0
0

1
1
1

1
1
0

Remainder

Figure6.23.Anonrestoringdivisionexample.

Restoreremainder

3. Arithmetic for Computer


1. Introduction
2. Unsigned Numbers
3. Signed Number
4. Addition and Subtraction
5. Multiplication
6. Division
7. Floating Point

NTK 2009

3.5.

Multiplication

3.5.1. Multiplication of unsigned


numbers
3.5.2. Multiplication of signed
numbers

NTK 2009

3.5.1. Multiplication of unsigned


numbers
1000
x 1001
1000
0000
0000
1000
1001000

Multiplicand (+8)
Multiplier
(+9)

Product

(+72)

Multiplication of two n-bit unsigned


numbers, the product is one 2n-bit
unsigned number.
NTK 2009

Multiplication implementation - 1 st version

Multiplicand, ALU, product are 64 bit


Multiplier is 32 bit

NTK 2009

Multiplication algorithm

NTK 2009

Multiplication implementation 2nd version

Multiplicand, ALU, multiplier are 32 bit


Product is 64 bit

NTK 2009

3.5.2. Multiplication of signed


numbers
Use unsigned multiplication:
Convert multiplicand & multiplier to
positive numbers
Multiply using unsigned multiplication
algorithm
Change the sign of product:
If the signs of multiplicand and multiplier are
the same, the product is the result of step 2.
If the signs disagree, the product is twos
complement of the result of step 2.
NTK 2009

Multiplication
Complex
Work out partial product for each
digit
Take care with place value (column)
Add partial products

Multiplication Example (unsigned)


(long hand)

1011 Multiplicand (11 dec)


x 1101 Multiplier
(13 dec)
1011 Partial products
00000
Note: if multiplier bit is 1
copy
101100
multiplicand (place value)
1011000
otherwise zero
10001111 Product (143 dec)
Note: need double length result

Flowchart for Unsigned Binary


Multiplication

Execution of Example

Multiplying Negative
Numbers
This does not work!
Solution 1
Convert to positive if required
Multiply as above
If signs were different, negate answer

Solution 2
Booths algorithm

Booths Algorithm

Example of Booths
Algorithm

3*7
First setup the columns and initial
values.

This case 3 is in Q and M is 7.


But could put 7 in Q and M as 3

Example of Booths
Algorithm
First cycle: Now look at Q and Q

With a 10, we Sub (A=A-M), then shift (always to the right)

-1

Second cycle: looking at Q0 and Q-1


With a 11, we only shift.

Example of Booths
Algorithm
nd
2 cycle Result

Third cycle, Q0 and Q-1 have 01


So we will Add (A=A+M), then shift

Example of Booths
Algorithm

3nd cycle Result

4th cycle, Q0 and Q-1 have 00


So we only shift

Example of Booths
Algorithm
4nd cycle Result

5th cycle, Q0 and Q-1 have 00


So we only shift

5th

Example of Booths
Algorithm
cycle Result

Since we are working in 5 bits, we only repeat 5 times

Example of Booths
Algorithm

Result is A and Q so 0000010101 which is 21.


Note: The sign bit is the last bit in A.

Division
More complex than multiplication
Negative numbers are really bad!
Based on long division

Division of Unsigned Binary Integers


00001101
Divisor
1011 10010011
1011
001110
Partial
1011
Remainders
001111
1011
100

Quotient
Dividend

Remainder

Flowchart for Unsigned Binary


Division

You might also like