Beruflich Dokumente
Kultur Dokumente
yi
Carry-in ci
Sumsi
Carry-out ci +1
0
0
0
0
1
1
1
1
0
0
1
1
0
0
1
1
0
1
0
1
0
1
0
1
0
1
1
0
1
0
0
1
0
0
0
1
0
1
1
1
si = xi yi ci + xi yi ci + xi yi ci + xi yi ci = x i yi ci
ci +1 = yi ci + xi ci + xi yi
Example:
X
7
+Y = +6
13
Z
0
= + 00
1
1
1
1
1
1
0
1
0
1
Carry-out
ci+1
xi
yi
si
Carry-in
ci
Carry
yi
c
i
xi
yi
xi
c
si
ci
xi
ci + 1
yi
Full adder
(FA)
yi
ci
i +1
n-bit adder
Cascade n full adder (FA) blocks to form a n-bit adder.
Carries propagate or ripple through this cascade, n-bit ripple carry adder.
xn - 1
cn
yn - 1
x1
y1
cn - 1
x0
y0
c1
FA
FA
FA
sn - 1
Most significant bit
(MSB) position
s1
s0
c0
K n-bit adder
K n-bit numbers can be added by cascading k n-bit adders.
xk n - 1 yk n - 1
n-bit
adder
c kn
kn - 1
xn - 1 y n - 1 x 0 y 0
x2n - 1 y2n - 1 xn y n
cn
n-bit
adder
s(
k - 1) n
2n - 1
n-bit
adder
n- 1
n-bit subtractor
Recall X Y is e ui ale t to addi g s o ple e t of Y to X.
s o ple e t is e ui ale t to s o ple e t + .
X Y = X + Y + 1
s o ple e t of positi e a d egati e u e s is o puted si ila l .
xn - 1
cn
yn - 1
x1
x0
y1
cn - 1
y0
c1
FA
FA
FA
sn - 1
Most significant bit
(MSB) position
s1
s0
Least significant bit
(LSB) position
n- 1
Add/Sub
control
n- 1
n-bit adder
n
n- 1
Detecting overflows
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.
Recall that the MSB represents the sign.
xn-1, yn-1, sn-1 represent the sign of operand x, operand y and result s
respectively.
Overflow cn cn1
x0
c1
FA
c0
s0
Carry
Sum
yi
c
xi
yi
ci
si
xi
c
i
yi
i +1
y0
x0
c4
FA
s3
y0
x0
c3
FA
s2
y0
x0
c2
FA
s1
x0
c1
y0
FA
s0
c0
Fast addition
Recall the equations:
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
Carry lookahead
ci 1 Gi Pi ci
ci Gi 1 Pi 1ci 1
ci1 Gi Pi (Gi 1 Pi 1ci 1 )
continuing
ci1 Gi Pi (Gi 1 Pi 1 (Gi 2 Pi 2 ci 2 ))
until
ci1 Gi PiGi 1 Pi Pi1 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 adder
x
c4
G3
B cell
P2
B cell
G2
B cell
P3
B cell
P
1
G
1
4-bit
carry-lookahead
adder
P
0
G
0
Carry-lookahead logic
xi
yi
. .
.
Gi
si
bit adder.
P0 P3 P2 P1 P0
I
G0I G3 P3 G2 P3 P2 G1 P3 P2 P1G0
Subscript I denotes the blocked carry lookahead and identifies the block.
Cascade 4 4-bit adders, c16 can be expressed as:
c16 G3 P3 G2 P3 P2 G1 P3 P2 P1 G0 P3 P2 P1 P0 c0
I
c16
y15-12
4-bit adder
x11-8
c12
4-bit adder
s15-12
G3I
P3I
y11-8
x7-4
c8
y7-4
4-bit adder
s11-8
G2I
P2I
x3-0
c4
4-bit adder
s7-4
G1I
P1I
y3-0
s3-0
G0I
P0I
Carry-lookahead logic
c0
Multiplication of unsigned
numbers (contd..)
We added the partial products at end.
Alternative would be to add the partial products at each stage.
carry out
FA
carry in
m3 0
m2 0
m1 0
m0
q0
0
PP1
q1
0
PP2
q2
0
PP3
q3
0
p0
p1
p2
,
p7
p6
p5
p4
p3
Sequential multiplication
Recall the rule for generating partial products:
If the ith bit of the multiplier is 1, add the appropriately shifted multiplicand
n - 1
n - 1
Multiplier Q
Add/Noadd
control
n-bit
Adder
Control
sequencer
MUX
0
m
n - 1
Multiplicand M
0 0 0 0
1 0 1 1
1 1 0 1
1 0 1 1
0 1 1 0
1
0
1 1 0 1
Add
Shift
First cycle
0 0 1 1
1 0 0 1
1 1 0 1
1 1 1 0
Add
Shift
Second cycle
0
0
1 0 0 1
0 1 0 0
1 1 1 0
1 1 1 1
No add
Shift
Third cycle
0 0 0 1
1 1 1 1
1 0 0 0
1 1 1 1
Add
Shift
Fourth cycle
Product
Signed Multiplication
Considering s-complement signed operands, what will happen to (-
Sign extension is
shown in blue
1
1
( - 13)
( + 11)
( - 143)
Signed Multiplication
For a negative multiplier, a straightforward solution is
Booth Algorithm
0
1
0
1
0
0
1
0
1
0
0
1 0 1 1 0
0 +1 +1 + 1+1
1
0
0
1
0
1
1
0
0
1
1
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
0
1
1
0
1
0
1
0
1
0
0
1
0
1
Booth Algorithm
Since 0011110 = 0100000 0000010, if we use the
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's complement of
the multiplicand
Booth
Algorithm
In general, in the Booth scheme, -1 times the shifted multiplicand is
0 +1 -1 +1
0 - 1
0 +1
0 - 1 +1 - 1 + 1
0 - 1
Booth Algorithm
0 1 1 0 1
X1 1 0 1 0
0 1 1 0 1
0 - 1 +1 - 1 0
( + 13)
(- 6)
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
( - 78)
Booth Algorithm
Multiplier
Version of multiplicand
selected by biti
Bit i
Bit i -1
0 XM
+1 XM
1 XM
0 XM
Booth Algorithm
Best case a long string of s skipping over s
Worst case s and s are alternating
0
Worst-case
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
1 +1 1
Multiplicand
selected at position i
i +1
i 1
X M
+1
X M
+1
X M
+2
X M
X M
X M
X M
X M
0 1 1 0 1 ( + 13)
1 1 0 1 0 (- 6 )
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 ( - 78)
0 1 1 0 1
-1
-2
0
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
39
Figure 6.15. Multiplication requiring only n/2 summands.
P7
P6
P5
P4
P3
P2
P1
40P0
P7
P6
P5
P4
P3
P2
P1
P0
(45)
(63)
B
C
D
E
F
(2,835)
Product
Figure 6.17. A multiplication example used to illustrate carry-save addition as shown in Figure 6.18.
x 1
+ 0
S1
S2
B
C
C3
C2
S4
Product
Figure 6.18. The multiplication example from Figure 6.17 performed using
carry-save addition.
Manual Division
13
21
274
26
10101
1101 100010010
1101
14
13
1
10000
1101
1110
1101
1
Circuit Arrangement
Shift left
an
qn-1
a0
an-1
Dividend Q
N+1 bit
adder
q0
Quotient
Setting
Add/Subtract
Control
Sequencer
0
m0
mn-1
Divisor M
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
Examples
10
11
1000
11
10
Initially 0
0
Shift
0
Subtract 1
Set q0 1
Restore
0
Shift
0
Subtract 1
Set q0 1
Restore
0
Shift
0
Subtract 1
Set q0 0
0
0
0
1
1
0
0
0
1
1
1 0 0 0
0
0
1
1
0
0
1
1
0
0
1
0
0
1
1
0
0
1
1
1
0
1
1
0
1
1
1
0
0
1
1
Shift
0
Subtract 1
Set q0 1
Restore
0
0 0 1 0
1 1 0 1
1 1 1 1
1 1
0 0 1 0
0 0 0 1
0 0 1
0
1
0
0
1
1
0
1
0
1
1
1
0
0
0
Remainder
0 0 0
First cycle
0 0 0 0
0 0 0
Second cycle
0 0 0 0
0 0 0
Third cycle
Fourth cycle
0 0 1 0
Quotient
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
Examples
1 1 1 1 1
0 0 0 1 1
Add 0 0 0 1 0
Remainder
Restore
remainder
Initially
Shift
Subtract
Set q0
0
0
0
1
1
0
0
0
1
1
0
0
0
1
1
0
1
0
0
1
0
1
1
1
0
Shift
Add
Set q
0
1 1 1 0 0
0 0 0 1 1
1 1 1 1 1
Shift
Add
Set q
0
1 1 1 1 0
0 0 0 1 1
0 0 0 0 1
0 0 0
Shift
Subtract
Set q
0
0 0 0 1 0
1 1 1 0 1
1 1 1 1 1
0 0 1
A nonrestoring-division example.
1 0 0 0
0 0 0
First cycle
0 0 0 0
0 0 0
Second cycle
0 0 0 0
Third cycle
0 0 0 1
Fourth cycle
0 0 1 0
Quotient
Fractions
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 + bn-3.229 + .... + b1.21 + b0.20
This vector has an implicit binary point to its immediate right:
b31b30b29....................b1b0.
Suppose if the binary vector is interpreted with the implicit binary point is
just left of the sign bit:
implicit binary point
.b31b30b29....................b1b0
Range of fractions
The value of the unsigned binary fraction is:
V(b) = b31.2-1 + b30.2-2 + b29.2-3 + .... + b1.2-31 + b0.2-32
The range of the numbers represented in this format is:
0 V (b) 1 2 n
Scientific notation
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.m2m3m4 b
Significant digits
A number such as the following is said to have 7 significant digits
x 0.m1m2m3m4m5m6m7 b
111111111111111111111111 = 0.9999999404
Not every real number between 0 and 0.9999999404 can be represented
by a 24-bit fractional number.
The smallest non-zero number that can be represented is:
A sample representation
1
24
Sign
Exponent
Fractional mantissa
bit
24-bit mantissa with an implied binary point to the immediate left
7- it e po e t i s o ple e t fo , a d i plied ase is .
Normalization
Consider the number:
x = 0.0004056781 x 1012
Normalization (contd..)
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
Range of numbers representable in this system, if every number must be
normalized is:
0.5 x 2-64 <= | x | < 1 x 263
.000111001110....0010 x 2-62
.111001110........
1.00111000............x 263
0.100111..............x 264
x 2-65
Excess notation
IEEE notation
IEEE Floating Point notation is the standard representation in use. There are two
representations:
- Single precision.
- Double precision.
Sign
1
Exponent
8 or 11
Mantissa
23 or 52
Exponent field
In the IEEE representation, the exponent is in excess-127 (excess-1023)
notation.
The actual exponents represented are:
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
result.
Normalize the result (if necessary).
Truncate/round the mantissa of the result.
result.
Normalize the result if necessary.
Truncate/round the mantissa of the result.
Note: Multiplication and division does not require alignment of the
mantissas the way addition and subtraction does.
Guard bits
While adding two floating point numbers with 24-bit mantissas, we shift
the mantissa of the number with the smaller exponent to the right until
the two exponents are equalized.
This implies that mantissa bits may be lost during the right shift (that is,
bits of precision may be shifted out of the mantissa being shifted).
To prevent this, floating point operations are implemented by keeping
guard bits, that is, extra bits of precision at the least significant end
of the mantissa.
The arithmetic on the mantissas is performed with these extra bits of
precision.
After an arithmetic operation, the guarded mantissas are:
- Normalized (if necessary)
- Converted back by a process called truncation/rounding to a 24-bit
mantissa.
Truncation/rounding
Straight chopping:
The guard bits (excess bits of precision) are dropped.
set to 1.
Rounding:
If there is a 1 in the MSB of the guard bit then a 1 is added to the LSB of the
retained bits.
Rounding
Rounding is evidently the most accurate truncation
method.
However,
Rounding requires an addition operation.
Rounding may require a renormalization, if the addition operation de-