Professional Documents
Culture Documents
14 Arithmetic Circuits
14 Arithmetic Circuits
Arithmetic Circuits
Montek Singh
1
Topics
Adder circuits
How to subtract
Why complemented representation works out so well
Overflow
2
Iterative Circuit
Like a hierachy, except functional blocks per bit
3
Adders
Great example of this type of design
Design 1-bit circuit, then expand
Lets look at
Half adder 2-bit adder, no carry in
Inputs are bits to be added
Outputs: result and possible carry
Full adder includes carry in, really a 3-bit adder
4
Half Adder
S = X Y
C = XY
5
Full Adder
Three inputs. Third is Cin
Two outputs: sum and carry
6
Two Half Adders (and an OR)
7
Ripple-Carry Adder
8
Hierarchical 4-Bit Adder
We can easily use hierarchy here
Design half adder
Use in full adder
Use full adder in 4-bit adder
9
Behavioral Verilog
// 4-bit Adder: Behavioral Verilog
10
Whats Problem with Design?
Delay
Approx how much?
Imagine a 64-bit adder
Look at carry chain
11
Carry Lookahead Adder
Note that add itself just 2 level
12
Four-bit Ripple Carry
Reference
Adder function
separated from
carry
13
Propagate
The P signal is called propagate
P = A B
Means to propagate incoming carry
14
What Does This Mean?
No Carry Here
So the propagate signal indicates that condition of
incoming should pass on
15
Generate
The G is generate
Its G = AB, so new carry created
So its ORed with incoming carry
16
Said Differently
If A B and theres incoming carry, carry will be
propagated
And S will be 0, of course
17
Ripple Carry Delay: 8 Gates
18
Turn Into Two Gate Delays
19
C1 Just Like Ripple Carry
20
C2 Circuit Two Levels
G from before and P to pass on This checks two propagates and a carry in
21
C3 Circuit Two Levels
Generate from
level 0 and two
propagates
22
What Happens as Scale Up?
23
Making 4-Bit Adder Module
24
Group Propagate
25
Group Generate
26
Hierarchical Carry
A B A B
4-bit adder 4-bit adder
S G P Cin S G P Cin
C8 C4
Look Ahead C0
28
On to Subtraction
First, look at unsigned numbers
Motivates why we typically use complemented representation
29
One-bit Subtractor
Inputs: Borrow in, minuend and subtrahend
Review: subtrahend is subtracted from minuend
Outputs: Difference, borrow out
Could use like adder
One per bit
M S
Bout 1-bit sub Bin
D
30
Example
31
Correcting Result
32
Correcting Result 2
If M is minuend and N subtrahend of numbers length
n, difference was
2n + M N
What we want is magnitude of N-M (with minus sign
in front)
Can get by subtracting previous result from 2n
N - M = 2n (M N + 2n)
This is called
2s complement
33
Put Another Way
This is equivalent to how we do subtraction in our
heads
Decide which is greater
Swap if necessary
Subtract
34
Algorithm
1. Subtract N from M
2. If no borrow, then M N and result is OK
3. Otherwise, N > M so result must be subtracted
from 2n (and minus sign prepended)
35
Pretty Expensive Hardware!
36
That Complex Design not Used
Thats why people use complemented interpretation
for numbers
2s complement
1s complement
37
1s Complement
2n - 1 1 1 1 1 1 1 1
-N 1 0 1 1 0 0 1
1s Compl. 0 1 0 0 1 1 0
38
2s Complement
39
Important Property
Complement of a complement generates original
number
40
New Algorithm for M-N
1. Add 2s complement of N to M
This is M + (2n N) = M N + 2n
2. If M N, will generate carry (why?)
Discard carry
Result is positive M - N
3. If M < N, no end carry (why?)
Take 2s complement of result
Place minus sign in front
41
Example
X = 101_0100 minus Y = 100_0011
X 1 0 1 0 1 0 0
+ 2s comp Y 0 1 1 1 1 0 1
Sum 1 0 0 1 0 0 0 1
42
Example 2
Y = 100_0011 minus X = 101_0100
Y 1 0 0 0 0 1 1
+ 2s comp X 0 1 0 1 1 0 0
Sum 1 1 0 1 1 1 1
No end carry
Answer: - (2s complement of Sum)
- 0010001
43
Adder-Subtractor
Need only adder and complementer for input to
subtract
44
Design of Adder/Subtractor
Adds 1 to
make 2s
complement
45
Signed Arithmetic
Review characteristics of signed representations
Signed magnitude
Left bit is sign, 0 positive, 1 negative
Other bits are number
2s complement
1s complement
46
Observations
47
Advantages/Disadvantages
Signed magnitude has problem that we need to
correct after subtraction
Ones complement has a positive and negative zero
Twos complement is most popular
Arithmetic operations easy
48
Conclusion: 2s Complement
Addition easy on any combination of positive and
negative numbers
To subtract
Take 2s complement of subtrahend
Add
This performs A + ( -B), same as A B
49
Overflow
Two cases of overflow for addition of signed numbers
Two large positive numbers overflow into sign bit
Not enough room for result
Two large negative numbers added
Same not enough bits
Carry out can be OK
50
Examples
4-bit signed numbers
7 + 7
7 7
Generates carry but result OK
-7 -7
4 + 4
Generates no Cout, but overflowed
51
Overflow Detection
Condition is that either Cn-1 or Cn is high, but not
both
52