ECE232: Hardware Organization and Design Lecture 7: Binary Numbers - - PowerPoint PPT Presentation

ece232 hardware organization and design
SMART_READER_LITE
LIVE PREVIEW

ECE232: Hardware Organization and Design Lecture 7: Binary Numbers - - PowerPoint PPT Presentation

ECE232: Hardware Organization and Design Lecture 7: Binary Numbers and Adders Adapted from Computer Organization and Design , Patterson & Hennessy, UCB Computer Organization 5 classic components of any computer Computer Processor


slide-1
SLIDE 1

Adapted from Computer Organization and Design, Patterson & Hennessy, UCB

ECE232: Hardware Organization and Design

Lecture 7: Binary Numbers and Adders

slide-2
SLIDE 2

ECE232: Adders 2

Computer Organization

  • 5 classic components of any computer
  • Today we will look at datapaths (adder, multiplier, …)

Processor (CPU) Computer Control Datapath Memory Devices Input Output

slide-3
SLIDE 3

ECE232: Adders 3

Unsigned Binary Integers

  • Given an n-bit number

1 1 2 n 2 n 1 n 1 n

2 x 2 x 2 x 2 x x     

   

  • Range: 0 to +2n – 1
  • Example
  • 0000 0000 0000 0000 0000 0000 0000 10112

= 0 + … + 1×23 + 0×22 +1×21 +1×20 = 0 + … + 8 + 0 + 2 + 1 = 1110

  • Using 32 bits
  • 0 to +4,294,967,295

x0 xn-1

slide-4
SLIDE 4

ECE232: Adders 4

2’s-Complement Signed Integers

  • Given an n-bit number

1 1 2 n 2 n 1 n 1 n

2 x 2 x 2 x 2 x x      

   

  • Bit n-1 is sign bit
  • 1/0 for negative/non-negative numbers
  • Range: –2n – 1 to +2n – 1 – 1
  • Example
  • 1111 1111 1111 1111 1111 1111 1111 11002

= –1×231 + 1×230 + … + 1×22 +0×21 +0×20 = –2,147,483,648 + 2,147,483,644 = –410

  • Using 32 bits
  • –2,147,483,648 to +2,147,483,647
  • Most-negative:

1000 0000 … 0000

  • Most-positive:

0111 1111 … 1111 x0 xn-1

2’s comp. binary decimal

1000

  • 8

1001

  • 7

1010

  • 6

1011

  • 5

1100

  • 4

1101

  • 3

1110

  • 2

1111

  • 1

0000 0001 1 0010 2 0011 3 0100 4 0101 5 0110 6 0111 7

slide-5
SLIDE 5

ECE232: Adders 5

Signed Negation

  • To get –X complement X and add 1
  • Complement means 1 → 0,

0 → 1

x 1 x 1 1111...111 x x

2

      

  • Example: negate +2
  • +2 = 0000 0000 … 00102
  • –2 = 1111 1111 … 11012 + 1

= 1111 1111 … 11102

  • Subtraction: y – x = y + (x +1)
  • Representing a number using more bits
  • Preserve the numeric value
  • Replicate the sign bit to the left
  • Examples: 8-bit to 16-bit
  • +5: 0000 0101 => 0000 0000 0000 0101
  • –5: 1111 1011 => 1111 1111 1111 1011

Sign Extension

slide-6
SLIDE 6

ECE232: Adders 6

Overflow in 2’s Comp Add/Subtract (1)

  • Example -

01001 9 11001 -7 1 00010 2 Carry-out discarded - does not indicate overflow

  • In general, if X and Y have opposite signs - no overflow

can occur regardless of whether there is a carry-out or not

  • Examples -
slide-7
SLIDE 7

ECE232: Adders 7

  • If X and Y have the same sign and result has different sign -
  • verflow occurs
  • Examples -

10111 -9 10111 -9 1 01110 14 = -18 mod 32

  • Carry-out and overflow

01001 9 00111 7 0 10000 -16 = 16 mod 32

  • No carry-out but overflow

Overflow in 2’s Comp Add/Subtract (2)

slide-8
SLIDE 8

ECE232: Adders 8

Ripple Carry Adder

  • Addition
  • most frequent operation
  • used also for multiplication and division
  • fast two-operand adder essential
  • Simple parallel adder
  • for adding xn-1,xn-2,...,x0 and yn-1,yn-2,…,y0
  • using n full adders
  • Full adder
  • combinational digital circuit with input bits xi,yi and

incoming carry bit ci, producing output sum bit si and

  • utgoing carry bit ci+1
  • incoming carry for next FA with input bits xi+1,yi+1
  • si = xi  yi  ci
  • ci+1 = xi  yi + ci  (xi + yi)
slide-9
SLIDE 9

ECE232: Adders 9

Full-Adder (FA)

  • Examine the Full Adder table

0 0 0 0 0 1 1 0 1 0 1 0 1 1 1 1 0 0 0 1 1 0 1 1 1 1 0 1 1 1 1 1 1

x y Cin Cout S

Cout = x • y + Cin • (x + y) S = x’y’c + x’yc’ + xy’c’ + xyc = x  y  c In general, for bit i: ci+1 = xi yi + ci (xi+yi) where ci+1 = Cout, ci= Cin

Half adder has 2 inputs. In principle HA is same as FA, with Cin set to 0.

x y

Cin Cout

Sum

slide-10
SLIDE 10

ECE232: Adders 10

Parallel Adder: Ripple Carry

  • In a parallel arithmetic unit
  • All 2n input bits available at the same time
  • Carry propagates from the FA to the right to FA to the left
  • Carries ripple through all n FAs before we can claim that the

sum outputs are correct and may be used in further calculations

  • Each FA has a finite delay
slide-11
SLIDE 11

ECE232: Adders 11

Example

  • x3,x2,x1,x0=1111
  • y3,y2,y1,y0=0001
  • FA - operation time - delay
  • Assuming equal delays for sum

and carry-out

  • Longest carry propagation

chain when adding two 4-bit numbers

  • In synchronous arithmetic units -

time allowed for adder's operation is worst-case delay - nFA

slide-12
SLIDE 12

ECE232: Adders 12

Subtraction using Ripple Carry Adder

  • Suppose you are performing X-Y operation
  • Complement Y bits
  • Force C0 to 1
  • add
  • Example: X = 0101, Y = 0010; Compute X – Y
  • First step: Complement Y
  • 1101
  • Second step: add 0101 + 1101 + 1 = 0011
slide-13
SLIDE 13

ECE232: Adders 13

Carry Select Adder

  • Principle: speculative

n-bit adder n-bit adder Carry propagate delay CP(2n) = 2*CP(n) n-bit adder n-bit adder n-bit adder 1 Cout CP(2n) = CP(n) + CP(mux)

Carry-select adder

Compute both, select one

MUX

slide-14
SLIDE 14

ECE232: Adders 14

Summary

  • Implement hardware for performance
  • Ripple Carry: least hardware, slowest
  • Carry Select: even faster, even more hardware
  • Other techniques available, e.g., Carry skip adder
  • Combination of these techniques – hybrid adders