Module 2 - Number System Arithmetic
Module 2 - Number System Arithmetic
Introduction
Algorithm – solution to any problem that is stated
by a finite number of well-defined procedural
steps.
Algorithms for addition, subtraction, multiplication
and division
Fixed point binary data in signed magnitude
representation
Fixed point binary data in signed 2’s complement
representation
Floating point binary data
Signed Numbers
Need to be able to represent both positive and negative numbers
- Following 3 representations
01102 610
+00112 +310
10012 -710 not good!
Underflow Example
Assume 4-bit restriction and 2’s complement
Minimum possible value: -(24-1) = -8
10112 -510
+10112 +-510
01102 610 not good!
Signed Overflow
carry and overflow
carry generated, but no overflow
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 0 1 1 1 Carry-out xi Carry-in
+Y = +6 = + 00 1 1 1 1 0 0 0 yi
ci+1 ci
Z 13 1 1 0 1 si
ci + 1 Full adder ci
(FA)
s
i
xn - 1 yn - 1 x1 y1 x0 y0
cn - 1 c1
cn FA FA FA c0
sn - 1 s1 s0
Most significant bit Least significant bit
(MSB) position (LSB) position
xk n - 1 yk n - 1 x2n - 1 y2n - 1 xn y n xn - 1 y n - 1 x 0 y 0
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
xn - 1 yn - 1 x1 y1 x0 y0
cn - 1 c1
cn FA FA FA 1
sn - 1 s1 s0
Most significant bit Least significant bit
(MSB) position (LSB) position
n-bit adder/subtractor (contd..)
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
Overflow cn cn1
Computing the add time
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
Computing the add time (contd..)
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
ci 1 xi yi ( xi yi )ci
We can write:
ci 1 Gi Pi ci
where Gi xi yi and Pi xi yi
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
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 (contd..)
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
Shift First cycle
0 0 1 1 0 1 1 0 1
1 0 0 1 1 1 1 0 1 Add
Shift Second cycle
0 1 0 0 1 1 1 1 0
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
Shift Fourth cycle
0 1 0 0 0 1 1 1 1
Product
Signed 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 blue 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)
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
Multiplier
Version of multiplicand
selected by biti
Bit i Bit i -1
0 0 0 XM
0 1 +1 XM
1 0 1 XM
1 1 0 XM
0 +1 -1 +1 0 - 1 0 +1 0 0 - 1 +1 - 1 + 1 0 - 1 0 0
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
Refer to Booth algorithm and Modified booth algorithm
illustration
Manual Division
21 10101
13 274 1101 100010010
26 1101
14 10000
13 1101
1 1110
1101
1
Let,
Dividend, D=1001011
Divisor, M=1000
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.
Fixed Point Division
an an-1 a0 qn-1 q0
Dividend Q
A Quotient
Setting
0 mn-1 m0
Divisor M
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 First cycle
Set q0 1 1 1 1 0
Restore 1 1
0 0 0 0 1 0 0 0 0
10 Shift 0 0 0 1 0 0 0 0
11 1000 Subtract 1 1 1 0 1
11 Set q0 1 1 1 1 1 Second cycle
Restore 1 1
10 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 Third cycle
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
Solution:
Quotient =0010=2
Remainder=0001=1
Non-restoring Division
Modifying the basic division algorithm by eliminating restoring step
is non-restoring division
Algorithm
1. Start by initializing register A to 0 and repeat steps (2-4) n times
2. If A is positive,
2.1 Shift A and Q left by one bit position
2.2 Subtract M from A
3. If A is negative
3.1 Shift A and Q left by one bit position
3.2 Add M to A
4. If A is positive, set Q0 to 1, else Q0 to 0
5. If A is negative, add M to A as a final corrective step
Non-Restoring Division
Flowchart
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 First cycle
Subtract 1 1 1 0 1
Set q0 1 1 1 1 0 0 0 0 0
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.
Q=7=0111
M=3=0011
Solution:
Quotient =0010=2
Remainder=0001=1
Floating Point Numbers : Scientific Notation
Small number:
Mass of neutron=1.67 x 10-27 kg
Seconds in nanosecond=1.0 x 10-9 s
Large number:
Mass of earth=5.92 x 1024 kg
Seconds in a century=3.16 x 109 s
Nanoseconds in a day=8.64 x 1013 ns
Scientific notation
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 e
Possibility : numbers(large)
IEEE 754 Floating Point Standard Cntd…
This floating point number takes two 32-bit word. S is single bit sign,
11-bits exponent field, 52-bits fraction field.
Floating Point Numbers :Normalized Scientific Notation
The procedure for normalizing a floating point number is:
Do (until MSB of mantissa = = 1)
Shift the mantissa left (or right)
Decrement (increment) the exponent by 1
end do
Biased Exponent Representation