Comp Arc A
Comp Arc A
INTRODUCTION
Arithmetic 1
REVIEW OF NUMBER REPRESENTATIONS
2. 1’s – complement
3. 2’s – complement
Arithmetic 2
Positive values have identical representations in all
systems.
Example:
+5 = 0101
-5 = 1101
Example:
+3 = 0011
-3 = 1100
Arithmetic 3
In the 2’s-complement system, a negative number is
obtained by subtracting the positive number from 2n.
Hence, the 2’s-complement representation is obtained
by adding 1 to the 1’s-complement representation.
Example:
+3 = 0011
-3 = 1101
Arithmetic 4
ADDITION OF POSITIVE NUMBERS
0 1 0 1
+ 0 + 0 + 1 + 1
0 1 1 10
Carry-out
Example:
X 7 0 1 1 1
+ Y + 6 + 0 0 1 1 1 1 0 0 0
Z 13 1 1 0 1
xi
Carry-out yi Carry-in
ci+1 si ci
Arithmetic 5
The truth table for the sum and carry-out functions for
adding two equally weighted bits xi and yi:
xi yi ci si ci+1
0 0 0 0 0
0 0 1 1 0
0 1 0 1 0
0 1 1 0 1
1 0 0 1 0
1 0 1 0 1
1 1 0 0 1
1 1 1 1 1
si = xi yi ci + xi yi ci + xi yi ci + xi yi ci
ci+1 = yi ci + xi ci + xi yi
Arithmetic 6
A straightforward, 2-level, combinational logic circuit
implementation of the truth table for addition is shown
below:
xi
yi
yi
ci
ci
xi
yi
ci xi
si ci+1
xi ci
yi
ci
xi
xi
yi yi
ci
xi yi
Adder
ci+1 ci
(A)
si
Arithmetic 7
A cascaded connection of n adder blocks can be used
to add two n-bit numbers.
xn-1 yn-1 x1 y1 x0 y0
cn-1 c1
Adder Adder Adder
cn c0
(A) (A) (A)
sn-1 s1 s0
MS B Position LS B Position
A cascade of k n-adders:
Arithmetic 8
DESIGN OF FAST ADDERS
si = xi yi ci + xi yi ci + xi yi ci + xi yi ci
ci+1 = xi yi + yi ci + xi ci
Arithmetic 9
By doing the following:
Let Gi = xi yi and Pi = xi + yi
ci+1 = Gi + Pi ci
ci+1 = Gi + Pi ci
Arithmetic 10
Continuing this type of expansion, the final expression
for any carry variable is:
PiPi-i…P1G0 + PiPi-1…P0c0
Arithmetic 11
Example:
c1 = G0 + P0c0
c2 = G1 + P1G0 + P1P0c0
Arithmetic 12
Fast adders that form carry functions are called carry-
lookahead adders.
Arithmetic 13
For the 8-bit addition:
x7 y7 x6 y6 x5 y5 x4 y4 x3 y3 x2 y2 x1 y1 x0 y0
c8 c4 c0
4-bit Adder 4-bit Adder
s7 s6 s5 s4 s3 s2 s1 s0
Arithmetic 14
SIGNED ADDITION AND SUBTRACTION
Arithmetic 15
Examples:
Arithmetic 16
Binary addition-subtraction logic network:
yn-1 y1 y0
. . . Add/S ub
Control
. . .
xn-1 x1 x0
. . .
c0
cn
n-bit adder
x0
. . .
sn-1 s1 s0
Arithmetic 17
When the result does not fall within the representable
range, then an arithmetic overflow has occurred.
Arithmetic 18
MULTIPLICATION OF POSITIVE NUMBERS
1 1 0 1 (13) Multiplicand M
1 0 1 1 (11) Multiplier Q
1101
1101
0000
1101
1 0 0 0 1 1 1 1 (143) Product P
Arithmetic 19
Block diagram for the sequential circuit binary
multiplier:
Register A (initially 0)
Multiplier Q
Add/Noadd
Control
n-bit
adder
Control
MPX
S equencer
0
0
mn-1 ... m0
Multiplicand M
1 1 0 1
Initial
0 0 0 0 0 1 0 1 1
C A Q
0 1 1 0 1 1 0 1 1 Add 1st
0 0 1 1 0 1 1 0 1 S hift Cycle
1 0 0 1 1 1 1 0 1 Add 2nd
0 1 0 0 1 1 1 1 0 S hift Cycle
0 1 0 0 1 1 1 1 0 No Add 3rd
0 0 1 0 0 1 1 1 1 S hift Cycle
1 0 0 0 1 1 1 1 1 Add 4th
0 1 0 0 0 1 1 1 1 S hift Cycle
Product
Arithmetic 20
The sequential multiplier circuit performs
multiplication by using a single adder n times.
Arithmetic 21
SIGNED-OPERAND MULTIPLICATION
Example:
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
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)
Arithmetic 22
Booth Algorithm
0100000 (32)
- 0000010 (2)
0011110 (30)
Arithmetic 23
Normal multiplication algorithm:
0101101
0011110
0000000
0101101
0101101
0101101
0101101
0000000
0000000
00010101000110
0101101
0+10 0 0 -10
00000000000000
1111111010011
000000000000
00000000000
0000000000
000101101
00000000
00010101000110
Arithmetic 24
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.
Multiplier Version of
Bit i Bit i – 1 multiplicand selected
by bit i
0 0 0xM
0 1 +1 x M
1 0 -1xM
1 1 0xM
Example:
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
Arithmetic 25
The Booth algorithm can also be used for negative
numbers.
01101 (+13)
x 11010 (-6)
01101
0-1+1-10
0000000000
111110011
00001101
1110011
000000
1 1 1 0 1 1 0 0 1 0 (-78)
Arithmetic 26
However, in the worst case – that of alternating 1s and
0s in the multiplier – each bit of the multiplier selects
a summand. In fact, this results in more summands
than if the Booth algorithm were not used.
Examples:
Worst-case Multiplier:
0 1 0 1 0 1 0 1 0 1 0 1 0 1 0 1
+1-1+1-1 +1-1 +1 -1+1-1 +1-1+1 -1 +1-1
Ordinary Multiplier:
1 1 0 0 0 1 0 1 1 0 1 1 1 1 0 0
0 -1 0 0 +1-1+1 0 -1 +1 0 0 0 -1 0 0
Good Multiplier:
0 0 0 0 1 1 1 1 1 0 0 0 0 1 1 1
0 0 0 0 +1 0 0 0 0 -1 0 0 0 +1 0 -1
Arithmetic 27
The Booth algorithm has two attractive features:
Arithmetic 28
FAST MULTIPLICATION
Arithmetic 29
Example:
0 0 -1 +1 -1 0
0 -1 -2
Arithmetic 30
The complete set of eight cases is shown below:
Examples:
0 1 1 0 1
+1 -1 +1
1 0 1 1 1
+1 +2 +1
Arithmetic 31
Multiplication Examples:
01101 (+13)
x 11010 (- 6)
01101
0 -1 -2
1111100110
11110011
000000
1 1 1 0 1 1 0 0 1 0 (- 78)
01010 (+10)
x 10111 (- 9)
01101
- 1 +2 - 1
1111110110
00010100
110110
1 1 1 0 1 0 0 1 1 0 (- 90)
Arithmetic 32
INTEGER DIVISION
21 10101
13 274 1101 100010010
26 1101
14 10000
13 1101
1 1110
1101
1
Arithmetic 33
The logic circuit arrangement that implements this
restoring-division technique is shown below:
Register A
Shift Left
Dividend Q
Quotient
Setting
n+1-bit Add/Subtract
adder
Control
Sequencer
0 mn-1 ... m0
Divisor M
Arithmetic 34
An n-bit divisor is loaded into register M and an n-bit
positive dividend is loaded into register Q at the start
of the operation. Register A is set to 0.
Arithmetic 35
A restoring-division example:
10
11 1000
11
10
Initially 0 0 0 0 0 1 0 0 0
0 0 0 1 1
S hift 0 0 0 0 1 0 0 0 0
S ubtract 1 1 1 0 1 1st
Cycle
S et q0 1 1 1 1 0
Restore 1 1
0 0 0 0 1 0 0 0 0
S hift 0 0 0 1 0 0 0 0 0
S ubtract 1 1 1 0 1
2nd
S et q0 1 1 1 1 1 Cycle
Restore 1 1
0 0 0 1 0 0 0 0 0
S hift 0 0 1 0 0 0 0 0 0
S ubtract 1 1 1 0 1
3rd
S et q0 0 0 0 0 1 Cycle
0 0 0 1
S hift 0 0 0 1 0 0 0 1 0
S ubtract 1 1 1 0 1
4th
S et q0 1 1 1 1 1 Cycle
Restore 1 1
0 0 0 1 0 0 0 1 0
Remainder Quotient
Arithmetic 36
This algorithm can be improved by avoiding the need
for restoring A after an unsuccessful subtraction
(subtraction is said to be unsuccessful if the result is
negative).
Arithmetic 37
A nonrestoring-division example:
Initially 0 0 0 0 0 1 0 0 0
0 0 0 1 1
S hift 0 0 0 0 1 0 0 0 0 1st
S ubtract 1 1 1 0 1 Cycle
S et q0 1 1 1 1 0 0 0 0 0
S hift 1 1 1 0 0 0 0 0 0
Add 0 0 0 1 1 2nd
Cycle
S et q0 1 1 1 1 1 0 0 0 0
S hift 1 1 1 1 0 0 0 0 0
Add 0 0 0 1 1 3rd
Cycle
S et q0 0 0 0 0 1 0 0 0 1
S hift 0 0 0 1 0 0 0 1 0
S ubtract 1 1 1 0 1 4th
Cycle
S et q0 1 1 1 1 1 0 0 1 0
Quotient
Add 1 1 1 1 1
0 0 0 1 1 Restore
Remainder
0 0 0 1 0
Remainder
Arithmetic 38
FLOATING-POINT NUMBERS AND OPERATIONS
B = b0.b-1b-2 … b- (n-1)
is given by:
-1 F 1 – 2-(n-1)
Arithmetic 39
Neither of these ranges is sufficient for scientific
calculations, which might involve parameters like
Avogadro’s number (6.0247 x 1023) or Planck’s
constant (6.6254 x 10-27).
Arithmetic 40
The standard for representing floating-point numbers
in 32 bits has been developed and specified in detail
by the IEEE.
32 bits
S E' M
Sign of
Numbers:
0 signifies +
1 signifies - 8-bit signed exponent 23-bit
in excess-127 mantissa fraction
representation
Arithmetic 41
Examples:
Arithmetic 42
The last 23 bits represent the mantissa. Since binary
normalization is used, the most significant bit of the
mantissa is always equal to 1. This bit is not
explicitly represented; it is assumed to be to the
immediate left of the binary point. The 23 bits stored
in the M field represent the fractional part of the
mantissa, that is, the bits to the right of the binary
point.
Example:
0 00101000 001010 . . . 0
Arithmetic 43
To provide more precision and range for floating-
point numbers, the IEEE standard also specifies a
double-precision format for floating-point number
representation:
64 bits
S E' M
Sign of
Numbers:
0 signifies +
1 signifies - 11-bit signed exponent 52-bit
in excess-1023 mantissa fraction
representation
Arithmetic 44
If a number is not normalized, it can always be put in
normalized form by shifting the fraction and adjusting
the exponent.
Example:
excess-127 exponent
0 10001000 0010110 . . .
Unnormalized Value
0 10000101 0110 . . .
Normalized Value
Arithmetic 45
Arithmetic Operations on Floating-Point Numbers
2.9400 x 102
+ 4.3100 x 104
0.0294 x 104
+ 4.3100 x 104
4.3394 x 104
Arithmetic 46
Add/Subtract Rule
Arithmetic 47
Example: 6-bit to 3-bit truncation
Example:
Arithmetic 48
Implementation of Floating-Point Operations
E A' EB'
MA MB
8-bit
S ubtractor S WAP
M of number
with smaller E'
M of number
sign with larger E'
n = | EA' - EB' | S HIFTER
n bits
SB to right
SA
Add /
Subtract
Combinational Add / Subtract Mantissa
CONTROL
Adder/S ubtractor
Network
Sign
Magnitude M
E A' EB'
Leading Zeros
Detector
MPX
X
Normalize
E' and
Round
8-bit
S ubtractor
E' - X
32-bit
R : SR E R' MR Result
R=A+B
Arithmetic 49
Let the signs, exponents, and mantissas of operands A
and B be represented by SA, EA, MA and SB, EB, MB,
respectively.
Arithmetic 50
Step 3 involves the major component, the mantissa
adder-subtractor in the middle of the figure. The
CONTROL logic determines whether the mantissas
are to be added or subtracted. This is decided by the
signs of the operands (SA and SB) and the operation
(add or subtract) that is to be performed on the
operands. The CONTROL logic also determines the
sign of the result, SR.
Example:
Arithmetic 51
Multiplication and division are somewhat easier than
addition and subtraction, in that no alignment of
mantissas is needed.
Multiply Rule
Divide Rule
Arithmetic 52