COMP541 Arithmetic Circuits - PowerPoint PPT Presentation

About This Presentation
Title:

COMP541 Arithmetic Circuits

Description:

Carry Lookahead Adder. Note that add itself just 2 level. Idea is to ... Can I realistically make 64-bit adder like this? Have to AND 63 propagates and Cin! ... – PowerPoint PPT presentation

Number of Views:78
Avg rating:3.0/5.0
Slides: 53
Provided by: Montek5
Learn more at: http://www.cs.unc.edu
Category:

less

Transcript and Presenter's Notes

Title: COMP541 Arithmetic Circuits


1
COMP541Arithmetic Circuits
  • Montek Singh
  • Mar 20, 2007

2
Topics
  • Adder circuits
  • How to subtract
  • Why complemented representation works out so well
  • Overflow

3
Iterative Circuit
  • Like a hierachy, except functional blocks per bit

4
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

5
Half Adder
  • S X ? Y
  • C XY

6
Full Adder
  • Three inputs. Third is Cin
  • Two outputs sum and carry

7
Two Half Adders (and an OR)
8
Ripple-Carry Adder
  • Straightforward connect full adders
  • Carry-out to carry-in chain
  • C0 in case this is part of larger chain, or just
    0

9
Hierarchical 4-Bit Adder
  • We can easily use hierarchy here
  • Design half adder
  • Use in full adder
  • Use full adder in 4-bit adder
  • Verilog code in textbook

10
Behavioral Verilog
  • // 4-bit Adder Behavioral Verilog
  • module adder_4_b_v(A, B, C0, S, C4)
  • input30 A, B
  • input C0
  • output30 S
  • output C4
  • assign C4, S A B C0
  • endmodule

Addition (unsigned)
Concatenation operation
11
Whats Problem with Design?
  • Delay
  • Approx how much?
  • Imagine a 64-bit adder
  • Look at carry chain

12
Carry Lookahead Adder
  • Note that add itself just 2 level
  • Idea is to separate carry from adder function
  • Then make carry approx 2-level all way across
    larger adder

13
Four-bit Ripple Carry
Reference
Adder function separated from carry
Notice adder has A, B, C in and S out, as well as
G,P out.
14
Propagate
  • The P signal is called propagate
  • P A ? B
  • Means to propagate incoming carry

15
What Does This Mean?
  • No Carry Here
  • So the propagate signal indicates that condition
    of incoming should pass on

16
Generate
  • The G is generate
  • Its G AB, so new carry created
  • So its ORed with incoming carry

17
Said Differently
  • If A ? B and theres incoming carry, carry will
    be propagated
  • And S will be 0, of course
  • If AB, then will create carry
  • Incoming will determine whether S is 0 or 1

18
Ripple Carry Delay 8 Gates
19
Turn Into Two Gate Delays
  • Design changed from deep (in delay) to wide

20
C1 Just Like Ripple Carry
21
C2 Circuit Two Levels
G from before and P to pass on
This checks two propagates and a carry in
22
C3 Circuit Two Levels
Generate from level 0 and two propagates
G from before and P to pass on
This checks three propagates and a carry in
23
What Happens as Scale Up?
  • Can I realistically make 64-bit adder like this?
  • Have to AND 63 propagates and Cin!
  • Compromise
  • Hierarchical design
  • More levels of gates

24
Making 4-Bit Adder Module
  • Create propagate and generate signals for whole
    module

25
Group Propagate
  • Make propagate of whole 4-bit block
  • P0-3 P3P2P1P0

26
Group Generate
  • Does G created upstream pass on because of string
    of Ps (also G3)?
  • Indicates carry generated in block

27
Hierarchical Carry
Left lookahead block is exercise for you
28
Practical Matters
  • FPGAs like ours have limited inputs per block
  • Instead they have special circuits to make adders
  • So dont expect to see same results as theory
    would suggest

29
On to Subtraction
  • First, look at unsigned numbers
  • Motivates why we typically use complemented
    representation
  • Then look at 2s complement
  • Imagine a subtractor circuit (next)

30
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

31
Example
32
Correcting Result
  • What, mathematically, does it mean to borrow?
  • If borrowing at digit i-1 you are adding 2i
  • Next Slide

33
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
34
Put Another Way
  • This is equivalent to how we do subtraction in
    our heads
  • Decide which is greater
  • Swap if necessary
  • Subtract
  • Could build a circuit this way
  • Or just look at borrow bit

35
Algorithm
  • Subtract N from M
  • If no borrow, then M ? N and result is OK
  • Otherwise, N gt M so result must be subtracted
    from 2n (and minus sign prepended)

36
Pretty Expensive Hardware!
37
That Complex Design not Used
  • Thats why people use complemented interpretation
    for numbers
  • 2s complement
  • 1s complement

38
1s Complement
  • Given binary number N with n digits
  • 1s complement defined as
  • (2n 1) - N

39
2s Complement
  • Given binary number N with n digits
  • 2s complement defined as
  • 2n N for N ? 0
  • 0 for N 0
  • Exception is so result will always have n bits
  • 2s complement is just a 1 added to 1s complement

40
Important Property
  • Complement of a complement generates original
    number
  • NOTE We havent talked about negative numbers
    yet. Still looking at unsigned
  • Lets look at new design for subtractor

41
New Algorithm for M-N
  • Add 2s complement of N to M
  • This is M (2n N) M N 2n
  • If M ? N, will generate carry (why?)
  • Discard carry
  • Result is positive M - N
  • If M lt N, no end carry (why?)
  • Take 2s complement of result
  • Place minus sign in front

42
Example
  • X 101_0100 minus Y 100_0011

43
Example 2
  • Y 100_0011 minus X 101_0100
  • No end carry
  • Answer - (2s complement of Sum)
  • - 0010001

44
Adder-Subtractor
  • Need only adder and complementer for input to
    subtract
  • Need selective complementer to make negative
    output back from 2s complement
  • Or go through adder again. See next slide

45
Design of Adder/Subtractor
S low for add, high for subtract
Inverts each bit of B if S is 1
Adds 1 to make 2s complement
  • Output is 2s complement if B gt A

46
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

47
Observations
  • 1s C and Signed Mag have two zeros
  • 2s C has more negative than positive
  • All negative numbers have 1 in high-order

48
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

49
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

50
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

51
Examples
  • 4-bit signed numbers
  • 7 7
  • 7 7
  • Generates carry but result OK
  • -7 -7
  • 4 4
  • Generates no Cout, but overflowed

52
Overflow Detection
  • Condition is that either Cn-1 or Cn is high, but
    not both
Write a Comment
User Comments (0)
About PowerShow.com