CO Module4
CO Module4
CO Module4
ARITHMETIC
Computer Organization, Fifth Edition
Carl Hamacher, Zvonko Vranesic, Safwat Zaky
OUTLINE
▪ Fast Multiplication
▪ Integer Division
Number, Arithmetic Operations, And Characters
▪ We obviously need to represent both positive and negative numbers.
▪ Three systems are used for representing such numbers :
▪ Sign-and-magnitude
▪ 1’s-complement
▪ 2’s-complement
▪ In all three systems, the leftmost bit is 0 for positive numbers and 1 for
negative numbers.
B Values represented
Sign and
b3 b2b1b0 magnitude 1's complement 2's complement
0 1 1 1 + 7 +7 + 7
0 1 1 0 + 6 +6 + 6
0 1 0 1 + 5 +5 + 5
0 1 0 0 + 4 +4 + 4
0 0 1 1 + 3 +3 + 3
0 0 1 0 + 2 +2 + 2
0 0 0 1 + 1 + 1 + 1
0 0 0 0 + 0 +0 + 0
1 0 0 0 - 0 -7 - 8
1 0 0 1 - 1 -6 - 7
1 0 1 0 - 2 -5 - 6
1 0 1 1 - 3 -4 - 5
1 1 0 0 - 4 -3 - 4
1 1 0 1 - 5 -2 - 3
1 1 1 0 - 6 - 1 - 2
1 1 1 1 - 7 -0 - 1
▪ 0111
▪ 1000
▪ + 1
▪ 1001
▪ 1
▪ 1
▪ 1 0
Sign And Magnitude Representation
-7 +0
-6 1111 0000 +1
1110 0001
-5 +2 +
1101 0010
-4 1100 0011 +3 0 100 = + 4
-0 +0
-1 1111 0000 +1
1110 0001
-2 +2 +
1101 0010
-3 1100 0011 +3 0 100 = + 4
-1 +0
-2 1111 0000 +1
1110 0001
-3 +2 +
1101 0010
-4 1100 0011 +3 0 100 = + 4
like 1's comp
except shifted -5 1011 1 100 = - 4
one position
0100 +4
clockwise 1010 0101
-6 +5 -
1001 0110
-7 1000 0111 +6
-8 +7
4 0100 -4 1100
+3 0011 + (-3) 1101
If carry-in to the high
order bit = 7 0111 -7 11001
carry-out then ignore carry
X 7 0 1 1 1 Carry-out xi Carry-in
+ Y = +6 = + 00 1 1 1 1 0 0 0 yi
c i+1 ci
Z 13 1 1 0 1 si
Sum Carry
yi
c
i
xi
xi
yi si c
c i +1
i
ci
x
xi yi i
yi
ci + 1 Full adder ci
(FA)
s
i
y y y
n- 1 1 0
Add/Sub
control
x x x
n- 1 1 0
c n-bit adder
n c
0
s s s
n- 1 1 0
• Overflows can only occur when the sign of the two operands is the
same.
• Overflow occurs if the sign of the result is different from the sign of
the operands.
• xn-1, yn-1, sn-1 represent the sign of operand x, operand y and result
s respectively.
n-Bit Adder Formation
S is the Sum bits, Cout is the final Carry out of the adder.
x y x y x y
n- 1 n- 1 1 1 0 0
c c
n- 1 1
c c
n FA FA FA
0
s s s
n- 1 1 0
Spatial Expansion is also known as Parallel Adder. The other name for
this method is Ripple Carry adder as the carry is propagated internally.
However, for large n-value, the carry propagation delay for clean and
settled output proportionately increases.
This is also a spatial expansion and ripple carry type. The Carry Look
Ahead Adder (CLA) uses specialized logic called Carry Look ahead
Logic to compute carries in parallel and hence is faster than Ripple
Carry Adder.
CLA Adder generates two other signals namely Propagate Carry and
Generate Carry which can be used by the next stage for Carry
Calculation.
Propagate Carry Pi = Ai + Bi
i.e when either of the number has '1' in the bit position, the carry is
likely depending on the Ci.
cn
n-bit n-bit n-bit c
c kn 0
adder adder adder
s s( s s s s
kn - 1 k - 1) n 2n - 1 n n- 1 0
ci +1 = Gi + Pi ci
ci = Gi −1 + Pi −1ci −1
ci+1 = Gi + Pi (Gi −1 + Pi −1ci −1 )
continuing
ci+1 = Gi + Pi (Gi −1 + Pi −1 (Gi − 2 + Pi− 2 ci −2 ))
until
ci+1 = Gi + PiGi −1 + Pi Pi−1 Gi −2 + .. + Pi Pi −1 ..P1G0 + Pi Pi −1 ...P0 c 0
•All carries can be obtained 3 gate delays after X, Y and c0 are applied.
-One gate delay for Pi and Gi
-Two gate delays in the AND-OR circuit for ci+1
•All sums can be obtained 1 gate delay after the carries are computed.
•Independent of n, n-bit addition requires only 4 gate delays.
•This is called Carry Lookahead adder.
Carry-lookahead Addition
x y x y x y x y
3 3 2 2 1 1 0 0
c4
c
3
c
2
c
1
.
4-bit
c
B cell B cell B cell B cell 0
carry-lookahead
s
3
s
2
s
1
s
0
adder
G3 P3 G2 P2 G P G P
1 1 0 0
Carry-lookahead logic
xi yi
. .
. c
i
B-cell for a single stage
B cell
G i
P i
si
Carry-lookahead Addition
c 16 4-bit adder
c 12
4-bit adder
c8
4-bit adder
c4
4-bit adder . c0
G3I P3I G2 I P 2I G 1I P 1I G 0I P0 I
Carry-lookahead logic
• C is the 1-bit register which holds the carry bit resulting from
addition.
• Now, the control logic reads the bits of the multiplier one at a time.
• Then all the bits of CAQ are shifted to the right 1 bit so that C bit goes
to An-1, A0 goes to Qn-1 and Q0 is lost.
Multiplicand
0 m3 0 m2 0 m1 0 m0
(PP0)
q0
0
PP1 p0
q1
0
PP2 p1
q2
0
PP3 p2
q3
0
,
p7 p6 p5 p4 p3
▪ Multiplicand has been shifted left when added to the partial product.
Register A (initially 0)
Shift right
C a a q q
n - 1 0 n - 1 0
Multiplier Q
Add/Noadd
control
n-bit
Adder
MUX Control
sequencer
0 0
m m
n - 1 0
Multiplicand M
Sequential Multiplication
▪ Step 1: Initially Register A is loaded with PPi as Zero and Register Q
with Multiplier.
▪ Step 5: Go back to Step 2 and repeat the step (2-5) for (n-1) cycle.
Sequential Multiplication
M
1 1 0 1
Initial configuration
0 0 0 0 0 1 0 1 1
C A Q
0 1 1 0 1 1 0 1 1 Add
First cycle
0 0 1 1 0 1 1 0 1 Shift
1 0 0 1 1 1 1 0 1 Add
Second cycle
0 1 0 0 1 1 1 1 0 Shift
0 1 0 0 1 1 1 1 0 No add
Shift Third cycle
0 0 1 0 0 1 1 1 1
1 0 0 0 1 1 1 1 1 Add
Fourth cycle
0 1 0 0 0 1 1 1 1 Shift
Product
Multiplying Negative Numbers
•
This does not work!
• Solution 1
—Convert to positive if required.
—Multiply as above.
• Solution 2
—Booth’s algorithm.
Signed-operand Multiplication
▪ Considering 2’s-complement signed operands, what will happen to
(-13)(+11) if following the same method of unsigned multiplication?
1 0 0 1 1 ( - 13)
0 1 0 1 1 ( + 11)
1 1 1 1 1 1 0 0 1 1
1 1 1 1 1 0 0 1 1
Sign extension is
shown in red 0 0 0 0 0 0 0 0
1 1 1 0 0 1 1
0 0 0 0 0 0
1 1 0 1 1 1 0 0 0 1 ( - 143 )
A technique that works equally well for both negative and positive
multipliers – Booth algorithm.
What is Booth’s algorithm?
History
The algorithm was invented by Andrew Donald Booth in 1950 while
doing research on crystallography at Birkbeck College in Bloomsbury,
London.
Booth Algorithm
0 1 0 1 1 0 1
0 0 +1 +1 + 1+1 0
0 0 0 0 0 0 0
0 1 0 1 1 0 1
0 1 0 1 1 0 1
0 1 0 1 1 0 1
0 1 0 1 1 0 1
0 0 0 0 0 0 0
0 0 0 0 0 0 0
0 0 0 1 0 1 0 1 0 0 0 1 1 0
Booth Algorithm
▪ Since 0011110 = 0100000 – 0000010, if we use the expression to the
right, what will happen?
0 1 0 1 1 0 1
0 +1 0 0 0-1 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 2's complement of
1 1 1 1 1 1 1 0 1 0 0 1 1 the multiplicand
0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0
0 0 0 1 0 1 1 0 1
0 0 0 0 0 0 0 0
0 0 0 1 0 1 0 1 0 0 0 1 1 0
Booth Algorithm
0 0 1 0 1 1 0 0 1 1 1 0 1 0 1 1 0 0
0 + 1 - 1 + 1 0 - 1 0 +1 0 0 - 1 +1 - 1 + 1 0 - 1 0 0
0 1 1 0 1 ( + 13) 0 1 1 0 1
X 1 1 0 1 0 (- 6) 0 - 1 +1 - 1 0
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 1 1
0 0 0 0 1 1 0 1
1 1 1 0 0 1 1
0 0 0 0 0 0
1 1 1 0 1 1 0 0 1 0 (- 78)
Multiplier
Version of multiplicand
selected by biti
Bit i Bit i -1
0 0 0 xM
0 1 +1 x M
1 0 −1 x M
1 1 0 xM
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Worst-case
multiplier
+1 - 1 +1 - 1 +1 - 1 +1 - 1 +1 - 1 +1 - 1 +1 - 1 +1 - 1
1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0
Ordinary
multiplier
0 - 1 0 0 +1 - 1 +1 0 - 1 +1 0 0 0 - 1 0 0
0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1
Good
multiplier
0 0 0 +1 0 0 0 0 - 1 0 0 0 +1 0 0 - 1
Fast Multiplication
Bit-pair Recoding of Multipliers
0 0 −1 +1 −1 0
0 −1 −2
0 0 0 0 X M
0 0 1 +1 X M
0 1 0 +1 X M
0 1 1 +2 X M
1 0 0 −2 X M
1 0 1 −1 X M
1 1 0 −1 X M
1 1 1 0 X M
0 1 1 0 1
0 - 1 +1 - 1 0
0 0 0 0 0 0 0 0 0 0
1 1 1 1 1 0 0 1 1
0 0 0 0 1 1 0 1
1 1 1 0 0 1 1
0 1 1 0 1 ( + 13) 0 0 0 0 0 0
´ 1 1 0 1 0 (- 6) 1 1 1 0 1 1 0 0 1 0 ( - 78)
0 1 1 0 1
0 -1 - 2
1 1 1 1 1 0 0 1 1 0
1 1 1 1 0 0 1 1
0 0 0 0 0 0
1 1 1 0 1 1 0 0 1 0
P7 P6 P5 P4 P3 P2 P1 P0
Fast Multiplication
Carry-save Addition of Summands
▪ Carry-save array
P7 P6 P5 P4 P3 P2 P1 P0
Fast Multiplication
Carry-save Addition of Summands
▪ Consider the addition of many summands, we can:
➢ Group the summands in threes and perform carry-save addition on
each of these groups in parallel to generate a set of S and C vectors
in one full-adder delay.
➢ Group all of the S and C vectors into threes, and perform carry-
save addition on them, generating a further set of S and C vectors
in one more full-adder delay.
➢ Continue with this process until there are only two vectors
remaining.
➢ They can be added in a RCA or CLA to produce the desired
product.
Fast Multiplication
Carry-save Addition of Summands
1 0 1 1 0 1
(45) M
X 1 1 1 1 1 1
(63) Q
1 0 1 1 0 1
A
1 0 1 1 0 1
B
1 0 1 1 0 1
C
1 0 1 1 0 1
D
1 0 1 1 0 1
E
1 0 1 1 0 1
F
1 0 1 1 0 0 0 1 0 0 1 1
(2,835) Product
Figure 6.17. A multiplication example used to illustrate carry-save addition as shown in Figure 6.18.
1 0 1 1 0 1
x 1 1 1 1 1 1 M
Q
1 0 1 1 0 1
1 0 1 1 0 1 A
1 0 1 1 0 1 B
1 1 0 0 0 0 1 1 C1
0 0 1 1 1 1 0 0 S1
C
1 0 1 1 0 1
1 0 1 1 0 1 D
1 0 1 1 0 1 E
1 1 0 0 0 0 1 1 F2
0 0 1 1 1 1 0 0 S2
1 1 0 0 0 0 1 1 C1
0 0 1 1 1 1 0 0 S1
1 1 0 0 0 0 1 1 C2
1 1 0 1 0 1 0 0 0 1 1 S3
0 0 0 0 1 0 1 1 0 0 0 S3
0 0 1 1 1 1 0 0 C2
0 1 0 1 1 1 0 1 0 0 1 1 C4
+ 0 1 0 1 0 1 0 0 0 0 0 S4
1 0 1 1 0 0 0 1 0 0 1 1 C
Product
Figure 6.18. The multiplication example from Figure 6.17 performed using carry-save addition.
Integer Division
Manual Division
21 10101
13 274 1101 100010010
26 1101
14 10000
13 1101
1 1110
1101
1
Shift left
an an-1 a0 qn-1 q0
Dividend Q
A Quotient
Setting
0 mn-1 m0
Divisor M
Shift 0 0 0 1 0 0 0 0 1
Subtract 1 1 1 0 1 0 0 1
Set q0 1 1 1 1 1 Fourth cycle
Restore 1 1
0 0 0 1 0 0 0 1 0
Remainder Quotient
Figure 6.22. A restoring-division example.
Integer Division
Nonrestoring Division
▪ Avoid the need for restoring A after an unsuccessful subtraction.
Shift 1 1 1 0 0 0 0 0
Add 0 0 0 1 1 Second cycle
Set q 1 1 1 1 1 0 0 0 0
0
Shift 1 1 1 1 0 0 0 0
1 1 1 1 1 Add 0 0 0 1 1 Third cycle
Restore
0 0 0 1 1 Set q 0 0 0 0 1 0 0 0 1
remainder 0
Add 0 0 0 1 0
Remainder Shift 0 0 0 1 0 0 0 1
Subtract 1 1 1 0 1 Fourth cycle
Set q 1 1 1 1 1 0 0 1 0
0
Quotient
A nonrestoring-division example.
Model Questions
1. Explain with figure the design and working of a 16 bit carry look
ahead adder built from 4 bit adders.
2. Explain booth algorithm. Apply booth algorithm to multiply the
signed numbers +13 x -6 and -13 x +9.
3. Write circuit arrangement for sequential binary multiplier, explain
with example.
4. Differentiate between restoring and non - restoring division. Perform
restoring division for the given binary numbers 1000/11, show all
cycles.
5. Design 4 bit carry look ahead logic and explain how it is faster than 4
bit ripple adder.
6. Multiply 14 x -8 using booth's algorithm.
7. With figure explain circuit arrangements for binary division.
8. Design a logic circuit to perform addition/ subtraction of two 'n' bit
numbers X and Y.
9. How do you design FAST ADDERS? Explain a 4 bit carry
look ahead adder.