Chapter4 Arithmetic
Chapter4 Arithmetic
Example:
X 7 0 1 1 1 Carryout xi Carryin
+ Y = +6 = +00 1 1 1 1 0 0 0 yi
ci+1 ci
Z 13 1 1 0 1 si
Legendforstage i
Sum Carry
yi
c
i
xi
xi
yi si c
c i +1
i
ci
x
xi yi i
yi
ci + 1 Fulladder ci
(FA)
s
i
xn 1
yn 1 x1 y1 x0 y0
cn 1
c1
cn FA FA FA c0
sn 1
s1 s0
Mostsignificantbit Leastsignificantbit
(MSB)position (LSB)position
xk n 1 yk n 1 x2n 1 y2n 1
xn y n xn 1
yn 1 x0 y0
cn
nbit nbit nbit c
c kn 0
adder adder adder
s s s s s s
kn 1 k 1 n 2n 1 n n 1 0
xn 1
yn 1 x1 y1 x0 y0
cn 1
c1
cn FA FA FA 1
sn 1
s1 s0
Mostsignificantbit Leastsignificantbit
(MSB)position (LSB)position
y y y
n 1 1 0
Add/Sub
control
x x x
n 1 1 0
c nbitadder
n c
0
s s s
n 1 1 0
Overflow cn cn 1
x0 y0
Consider 0th stage:
c1 is available after 2 gate delays.
s1 is available after 1 gate delay.
c1 FA c0
s0
Sum Carry
yi
c
i
xi
xi
yi si c
c i +1
i
ci
x
i
yi
Cascade of 4 Full Adders, or a 4-bit adder
x0 y0 x0 y0 x0 y0 x0 y0
FA FA FA FA c0
c4 c3 c2 c1
s3 s2 s1 s0
si xi yi ci
ci 1 xi yi xi ci yi ci
Second equation can be written as:
ci 1 xi yi ( xi yi )ci
We can write:
ci 1 Gi Pi ci
where Gi xi yi and Pi xi yi
c4
c
3
c
2
c
1
. c
4-bit
carry-lookahead
Bcell Bcell Bcell Bcell 0
adder
s s s s
3 2 1 0
G3 P3 G2 P2 G P G P
1 1 0 0
Carrylookaheadlogic
xi yi
. .
. c
i
Gi P i
si
Carry lookahead adder (contd..)
Performing n-bit addition in 4 gate delays independent of n is
good only theoretically because of fan-in constraints.
Last AND gate and OR gate require a fan-in of (n+1) for a n-bit
adder.
For a 4-bit adder (n=4) fan-in of 5 is required.
Practical limit for most gates.
In order to add operands longer than 4 bits, we can cascade 4-bit
Carry-Lookahead adders. Cascade of Carry-Lookahead adders is
called Blocked Carry-Lookahead adder.
Carry-out from a 4-bit block can be given as:
c4 G3 P3 G2 P3 P2 G1 P3 P2 P1 G0 P3 P2 P1P0 c0
Rewrite this as:
P0I P3 P2 P1 P0
G0I G3 P3 G2 P3 P2 G1 P3 P2 P1G0
Subscript I denotes the blocked carry lookahead and identifies the block.
I I I I I I I I 0 I I I 0 0
c16 G3 P3 G2 P3 P2 G1 P3 P2 P1 G0 P3 P2 P1 P0 c0
x1512 y1512 x118 y118 x74 y74 x30 y30
c16 4bitadder
c12
4bitadder
c8
4bitadder
c4
4bitadder . c0
G3 I P3 I G2 I P 2I G 1I P 1I G 0I P0 I
Carrylookaheadlogic
Bitofincomingpartialproduct(PPi)
jthmultiplicandbit
ithmultiplierbit ithmultiplierbit
carryout FA carryin
r
lie
PP2
tip
p1
ul
q2
M
0
PP3 p2
q3
0
,
p7 p6 p5 p4 p3
Shiftright
C an a0 q q
1 n 1 0
MultiplierQ
Add/Noadd
control
n-bit
Adder
MUX Control
sequencer
0 0
m m0
n 1
MultiplicandM
M
1101
Initialconfiguration
0 0000 1011
C A Q
0 1101 1011 Add
Shift Firstcycle
0 0110 1101
Product
Signed Multiplication
Considering 2s-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
Signextensionis
showninblue 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
Signextensionofnegativemultiplicand.
Signed Multiplication
For a negative multiplier, a straightforward solution is
to form the 2s-complement of both the multiplier and
the multiplicand and proceed as in the case of a
positive multiplier.
This is possible because complementation of both
operands does not change the value or the sign of the
product.
A technique that works equally well for both negative
and positive multipliers Booth algorithm.
Booth Algorithm
Consider in a multiplication, the multiplier is positive
0011110, how many appropriately shifted versions of
the multiplicand are added in a standard procedure?
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'scomplementof
1 1 1 1 1 1 1 0 1 0 0 1 1
themultiplicand
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
In general, in the Booth scheme, -1 times the shifted multiplicand is
selected when moving from 0 to 1, and +1 times the shifted
multiplicand is selected when moving from 1 to 0, as the multiplier
is scanned from right to left.
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
Boothrecodingofamultiplier.
Booth Algorithm
0 1 1 0 1 ( + 13) 0 1 1 0 1
X1 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
Boothmultiplicationwithanegativemultiplier.
Booth Algorithm
Multiplier
V ersionofmultiplicand
selectedbybiti
Bit i Bit i 1
0 0 0 XM
0 1 + 1 XM
1 0 1 XM
1 1 0 XM
Boothmultiplierrecodingtable.
Booth Algorithm
Best case a long string of 1s (skipping over 1s)
Worst case 0s and 1s are alternating
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
Worstcase
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
Bit-Pair Recoding of Multipliers
Bit-pair recoding halves the maximum number of
summands (versions of the multiplicand).
Signextension Implied0torightofLSB
1 1 1 0 1 0 0
0 0 1 +1 1 0
0 1 2
(a)ExampleofbitpairrecodingderivedfromBoothrecoding
Bit-Pair Recoding of Multipliers
Multiplierbitpair Multiplierbitontheright Multiplicand
selectedatposition i
i+1 i i1
0 0 0 0 XM
0 0 1 +1 XM
0 1 0 +1 XM
0 1 1 +2 XM
1 0 0 2 XM
1 0 1 1 XM
1 1 0 1 XM
1 1 1 0 XM
(b)Tableofmultiplicandselectiondecisions
Bit-Pair Recoding of Multipliers 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
Figure6.15.Multiplicationrequiringonlyn/2summands.39
Carry-Save Addition of Summands
CSA speeds up the addition process.
P7 P6 P5 P4 P3 P2 P1 40P0
Carry-Save Addition of Summands(Cont.,)
P7 P6 P5 P4 P3 P2 P1 P0
Carry-Save Addition of
Summands(Cont.,)
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
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
Figure6.17.AmultiplicationexampleusedtoillustratecarrysaveadditionasshowninFigure6.18.
1 0 1 1 0 1 M
x 1 1 1 1 1 1 Q
1 0 1 1 0 1 A
1 0 1 1 0 1 B
1 0 1 1 0 1 C
1 1 0 0 0 0 1 1 S
1
0 0 1 1 1 1 0 0 C
1
1 0 1 1 0 1 D
1 0 1 1 0 1 E
1 0 1 1 0 1 F
1 1 0 0 0 0 1 1 S
2
0 0 1 1 1 1 0 0 C
2
1 1 0 0 0 0 1 1 S1
0 0 1 1 1 1 0 0 C
1
1 1 0 0 0 0 1 1 S2
1 1 0 1 0 1 0 0 0 1 1 S
3
0 0 0 0 1 0 1 1 0 0 0 C3
0 0 1 1 1 1 0 0 C2
0 1 0 1 1 1 0 1 0 0 1 1 S4
+ 0 1 0 1 0 1 0 0 0 0 0 C
4
1 0 1 1 0 0 0 1 0 0 1 1 Product
Figure6.18. ThemultiplicationexamplefromFigure6.17performedusing
carrysaveaddition.
Manual Division
21 10101
13 274 1101 100010010
26 1101
14 10000
13 1101
1 1110
1101
1
Longhanddivisionexamples.
Longhand Division Steps
Position the divisor appropriately with respect to the
dividend and performs a subtraction.
If the remainder is zero or positive, a quotient bit of 1
is determined, the remainder is extended by another
bit of the dividend, the divisor is repositioned, and
another subtraction is performed.
If the remainder is negative, a quotient bit of 0 is
determined, the dividend is restored by adding back
the divisor, and the divisor is repositioned for another
subtraction.
Circuit Arrangement
Shiftleft
an an1 a0 qn1 q0
DividendQ
A Quotient
Setting
N+1bit Add/Subtract
adder
Control
Sequencer
0 mn1 m0
DivisorM
Figure6.21.Circuitarrangementforbinarydivision.
Restoring Division
Shift A and Q left one binary position
Subtract M from A, and place the answer back in A
If the sign of A is 1, set q0 to 0 and add M back to A
(restore A); otherwise, set q0 to 1
Repeat these steps n times
Examples Initially 0
Shift
0
0
0
0
0
0
0
0
0
1
0
0
1
1
1 0 0 0
0 0 0
Subtract 1 1 1 0 1 Firstcycle
Set q0 1 1 1 1 0
Restore 1 1
0 0 0 0 1 0 0 0 0
1 0 Shift 0 0 0 1 0 0 0 0
1 1 1 0 0 0 Subtract 1 1 1 0 1
1 1 Set q0 1 1 1 1 1 Secondcycle
Restore 1 1
1 0 0 0 0 1 0 0 0 0 0
Shift 0 0 1 0 0 0 0 0
Subtract 1 1 1 0 1
Set q0 0 0 0 0 1 Thirdcycle
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 Fourthcycle
Restore 1 1
0 0 0 1 0 0 0 1 0
Remainder Quotient
Figure6.22.Arestoringdivisionexample.
Nonrestoring Division
Avoid the need for restoring A after an
unsuccessful subtraction.
Any idea?
Step 1: (Repeat n times)
If the sign of A is 0, shift A and Q left one bit position and
subtract M from A; otherwise, shift A and Q left and add M
to A.
Now, if the sign of A is 0, set q0 to 1; otherwise, set q0 to 0.
Step2: If the sign of A is 1, add M to A
Examples Initially
Shift
0
0
0
0
0
0
0
0
0
0
1
0
0
1
1
1 0 0 0
0 0 0 Firstcycle
Subtract 1 1 1 0 1
Set q 0 1 1 1 1 0 0 0 0 0
Shift 1 1 1 0 0 0 0 0
Add 0 0 0 1 1 Secondcycle
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 Thirdcycle
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 Fourthcycle
Set q 1 1 1 1 1 0 0 1 0
0
Quotient
Anonrestoringdivisionexample.
If b is a binary vector, then we have seen that it can be interpreted as
an unsigned integer by:
V(b)=b31.231+b30.230+bn3.229+....+b1.21+b0.20
Suppose if the binary vector is interpreted with the implicit binary point is
just left of the sign bit:
implicitbinarypoint .b31b30b29....................b1b0
V(b)=b31.21+b30.22+b29.23+....+b1.231+b0.232
The value of the unsigned binary fraction is:
V(b)=b31.21+b30.22+b29.23+....+b1.231+b0.232
0 V (b) 1 2 32 0.9999999998
0 V (b) 1 2 n
Previous representations have a fixed point. Either the point is to the immediate
right or it is to the immediate left. This is called Fixed point representation.
Fixed point representation suffers from a drawback that the representation can
only represent a finite range (and quite small) range of numbers.
x m1 .m2 m3 m4 b e
Components of these numbers are:
000000000000000000000001=5.96046x108
0.0000001x264<=|x|<=0.9999999x263
0.5421x1020<=|x|<=9.2237x1018
1724
SignExponentFractionalmantissa
bit
24-bit mantissa with an implied binary point to the immediate left
7-bit exponent in 2s complement form, and implied base is 2.
Consider the number: x=0.0004056781x1012
If the number is shifted so that as many significant digits are brought into
7 available slots:
x=0.4056781x109=0.0004056x1012
0001101000(10110)x28=1101000101(10)x25
A floating point number is in normalized form if the most significant
1 in the mantissa is in the most significant bit of the mantissa.
All normalized floating point numbers in this system will be of the form:
0.1xxxxx.......xx
x=m16e
Then:
y=(m.16).16e1(m.24).16e1=m.16e=x
E = Etrue + 64
In general, excess-p coding is represented as:
E = Etrue + p
This enables efficient comparison of the relative sizes of two floating point numbers.
IEEE Floating Point notation is the standard representation in use. There are two
representations:
- Single precision.
- Double precision.
Both have an implied base of 2.
Single precision:
- 32 bits (23-bit mantissa, 8-bit exponent in excess-127 representation)
Double precision:
- 64 bits (52-bit mantissa, 11-bit exponent in excess-1023 representation)
Fractional mantissa, with an implied binary point at immediate left.
This is because the IEEE uses the exponents -127 and 128 (and -1023 and
1024), that is the actual values 0 and 255 to represent special conditions:
- Exact zero
- Infinity
Addition:
3.1415 x 108 + 1.19 x 106 = 3.1415 x 108 + 0.0119 x 108 = 3.1534 x 108
Multiplication:
3.1415 x 108 x 1.19 x 106 = (3.1415 x 1.19 ) x 10(8+6)
Division:
3.1415 x 108 / 1.19 x 106 = (3.1415 / 1.19 ) x 10(8-6)