Adders - facultystaff.richmond.edu

63
Adders Lecture 12 CS301

Transcript of Adders - facultystaff.richmond.edu

Page 1: Adders - facultystaff.richmond.edu

Adders

Lecture 12CS301

Page 2: Adders - facultystaff.richmond.edu

Administrative

•  Read Appendix C.5, C.7-C.10•  Program #1 due 10/24

Page 3: Adders - facultystaff.richmond.edu

FP Bias

•  Infinity is represented asw exponent is all 1sw significand is all 0s

Page 4: Adders - facultystaff.richmond.edu

Review

•  MUX

•  DeMux

•  Decoder

•  Encoder

Page 5: Adders - facultystaff.richmond.edu

Combinational Logic

•  Half-Adderw No carry in A B Sum Carry

Out 0 0 0 0 0 1 1 0 1 0 1 0 1 1 0 1

A⊕B AB

Page 6: Adders - facultystaff.richmond.edu

1-bit Full Adder

•  Three inputs:w  Aw  Bw  Cin

•  Two outputs:w  Sum = (A⊕B) ⊕ Cin

w  Cout = AB + (A⊕B) Cin

Page 7: Adders - facultystaff.richmond.edu

Combinational Logic

•  Full Adder

Note: Cout = (b Cin) + (a Cin) + (a b) + (a b Cin) = (b Cin) + (a Cin) + (a b) = (a b) + (a + b) Cin

Page 8: Adders - facultystaff.richmond.edu

Ripple Carry Adder

•  Construct n-bit adder with n 1-bit adders

•  Delay is problem•  Faster alternative:

w  Carry-lookahead adder

Page 9: Adders - facultystaff.richmond.edu

Designing connections

•  Problem: Ripple-carry adder is too sloww Each carry must wait for all previous units

to complete execution•  Solution:

Page 10: Adders - facultystaff.richmond.edu

Designing connections

•  Problem: Ripple-carry adder is too sloww Each carry must wait for all previous units

to complete execution•  Solution:

w Quickly get information for carriesw Compute carries in parallel

Page 11: Adders - facultystaff.richmond.edu

1b Adder

•  Three inputs:w  Aw  Bw  Cin

•  Two outputs:w  Sum = (A⊕B) ⊕ Cin

w  Cout = AB + (A⊕B) Cinw  Cout = AB + ACin +

BCin

Page 12: Adders - facultystaff.richmond.edu

Carry Look-ahead

We already know:ci+1 = (bi � ci) + (ai � ci) + (ai � bi)

= (ai � bi) + ci � (ai + bi)

Page 13: Adders - facultystaff.richmond.edu

Carry Look-ahead

We already know:ci+1 = (bi � ci) + (ai � ci) + (ai � bi)

= (ai � bi) + ci � (ai + bi)

= Gi + Ci � PiLet’s calculate ci+1 without waiting for ci

Generate Propagate

Page 14: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

P3 G3 P2 G2 P1 G1 P0 G0

Carry Lookahead Logic C0

C1 = G0 + C0 * P0

C1

Page 15: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

P3 G3 P2 G2 P1 G1 P0 G0

Carry Lookahead Logic C0

C1 = G0 + C0 * P0

C1

Page 16: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Lookahead Logic C0

C1 = G0 + C0 * P0

P3 G3 P2 G2 P1 G1 P0 G0 C1

Page 17: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Lookahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2

Page 18: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Lookahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2

Page 19: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Lookahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2

Page 20: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Lookahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2

Page 21: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Look-ahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2

Page 22: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Look-ahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1 C3 = G2 + C2 * P2

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2 C3

Page 23: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Look-ahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1 C3 = G2 + C2 * P2 = G2 + (G1 + G0 * P1 + C0 * P0 * P1) * P2

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2 C3

Page 24: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Look-ahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1 C3 = G2 + C2 * P2 = G2 + (G1 + G0 * P1 + C0 * P0 * P1) * P2 = G2 + G1 * P2 + G0 * P1 * P2 + C0 * P0 * P1 * P2

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2 C3

Page 25: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Look-ahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1 C3 = G2 + C2 * P2 = G2 + (G1 + G0 * P1 + C0 * P0 * P1) * P2 = G2 + G1 * P2 + G0 * P1 * P2 + C0 * P0 * P1 * P2

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2 C3

Page 26: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Look-ahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1 C3 = G2 + C2 * P2 = G2 + (G1 + G0 * P1 + C0 * P0 * P1) * P2 = G2 + G1 * P2 + G0 * P1 * P2 + C0 * P0 * P1 * P2

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2 C3

Page 27: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Look-ahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1 C3 = G2 + C2 * P2 = G2 + (G1 + G0 * P1 + C0 * P0 * P1) * P2 = G2 + G1 * P2 + G0 * P1 * P2 + C0 * P0 * P1 * P2

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2 C3

Page 28: Adders - facultystaff.richmond.edu

Carry Look-ahead

1-bit ALU 1-bit ALU 1-bit ALU 1-bit ALU

B[3] B[2] B[1] B[0] A[3] A[2] A[1] A[0]

Carry Look-ahead Logic C0

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1 C3 = G2 + C2 * P2 = G2 + (G1 + G0 * P1 + C0 * P0 * P1) * P2 = G2 + G1 * P2 + G0 * P1 * P2 + C0 * P0 * P1 * P2

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2 C3

Page 29: Adders - facultystaff.richmond.edu

Why is it Faster?

Page 30: Adders - facultystaff.richmond.edu
Page 31: Adders - facultystaff.richmond.edu

Why is it Faster?

•  4th bit waits only for p&g to be calculated, not all of the computations from bits 0-2

•  Only three levels of computation

w  Gi and Piw  ANDw  OR

C1 = G0 + C0 * P0 C2 = G1 + C1 * P1 = G1 + ( G0 + C0 * P0 ) * P1 = G1 + G0 * P1 + C0 * P0 * P1 C3 = G2 + C2 * P2 = G2 + (G1 + G0 * P1 + C0 * P0 * P1) * P2 = G2 + G1 * P2 + G0 * P1 * P2 + C0 * P0 * P1 * P2

Page 32: Adders - facultystaff.richmond.edu

The Next Step

4-bit ALU 4-bit ALU 4-bit ALU 4-bit ALU

B[12-15] B[8-11] B[4-7] B[0-3] A[12-15] A[8-11] A[4-7] A[0-3]

Carry Look-ahead Logic C0

P3 G3 P2 G2 P1 G1 P0 G0 C1 C2 C3

Now what is the equation for Pi & Gi? They are for the 4-bit ALU, not just one bit!

Page 33: Adders - facultystaff.richmond.edu

Basic Memory Cells and Sequential Logic

Page 34: Adders - facultystaff.richmond.edu

Sequential Logic and Clocks

•  Sequential logic retains state•  Clocks specify when that state should

be updated•  System using clocks called

synchronous

Page 35: Adders - facultystaff.richmond.edu

Clock

•  Signal with fixed cycle time (Tcycle)

•  Frequency: 1/Tcycle•  Tcycle has two parts

delineated by two edgesw  Clock highw  Clock low

Tcycle

Rising edge

Falling edge

Page 36: Adders - facultystaff.richmond.edu

Clocks (cont.)

Page 37: Adders - facultystaff.richmond.edu

Memory Elements

•  All memory elements store statew Output depends both on inputs and the

value stored inside the memory element•  Thus: All logic blocks containing

memory elements contain state and are sequential!

Page 38: Adders - facultystaff.richmond.edu

Unclocked Latch

Page 39: Adders - facultystaff.richmond.edu

Clocked Latch

Page 40: Adders - facultystaff.richmond.edu

D Flip-Flop

•  D flip flop stores 1 bit of data•  Created from 2 edge triggered D

latches•  Only takes in new inputs when clock is

high

Page 41: Adders - facultystaff.richmond.edu

Register

•  D flip-flop allows us to store 1 bit•  Programmers don’t programming in bits, but

w  char = 8 bw  integer = 32 bw  ...

•  String n D flip-flops together to store n bits

4b register implement with D flip-flops

b3 b2 b1 b0

Page 42: Adders - facultystaff.richmond.edu

Register Files

•  Contains set of registers accessed by register numw  Input: register

numberw Output: data in

registern entry register file

Page 43: Adders - facultystaff.richmond.edu

Register Files

•  Componentsw  Array of registers built

from flip-flops•  Port

w  Access pointw  Read port

§  register numw  Write port

§  register num, clock, data

2 read ports / 1 write port

Page 44: Adders - facultystaff.richmond.edu

Register File:Read Ports

Page 45: Adders - facultystaff.richmond.edu

Register File:Write Port

Page 46: Adders - facultystaff.richmond.edu

Comparator

•  Comparator has three output linesw A<Bw A=Bw A>B

Page 47: Adders - facultystaff.richmond.edu

Comparator

Page 48: Adders - facultystaff.richmond.edu

Comparator

Page 49: Adders - facultystaff.richmond.edu

Comparator

Page 50: Adders - facultystaff.richmond.edu

We Almost Have All the Pieces

•  Inverter, AND, OR•  Multiplexor and demultiplexor•  Decode and encoder•  Comparator•  Ripple carry adder and carry lookahead adder

w  Half and full adder•  Register file

w  Registersw D flip flop

Page 51: Adders - facultystaff.richmond.edu

Arithmetic Logic Unit

•  Circuitry that does arithmetic (+/-) and logical operations (AND/OR)

•  MIPS has 32b quantities so ALU needs to handle 32b numbers

•  Combine 32 1-b ALUs to create 32b ALU

Page 52: Adders - facultystaff.richmond.edu

AND/OR

Page 53: Adders - facultystaff.richmond.edu

1b Adder

•  Three inputs:w  Aw  Bw  Cin

•  Two outputs:w  Sum = (A⊕B) ⊕ Cin

w  Cout = AB + (A⊕B) Cin

Page 54: Adders - facultystaff.richmond.edu

1b ALU

Page 55: Adders - facultystaff.richmond.edu

32b ALU

Page 56: Adders - facultystaff.richmond.edu

Subtraction

•  Add negative version of operand

•  Recall to get two’s complement number:w  Invert all bitsw  Add 1

•  In hardwarew  Use complements of

all bitsw  Set CarryIn for LSB to

1A+(B+1) = A+(-B)=A-B

Page 57: Adders - facultystaff.richmond.edu

SLT

if (A < B) C=1 else C=0

•  Resulting 32bw  31b set to 0w  Least significant bit set

according to operation•  Least significant bit

w  Sign bit of (a-b)•  In hardware,

w  Set input for MUX to 0 for 31 MSB (Less)

Page 58: Adders - facultystaff.richmond.edu

SLT

•  Resulting 32bw  31b set to 0w  Least significant bit set

according to operation•  Least significant bit

w  Sign bit of (a-b)•  In hardware,

w  Set input for MUX to 0 for 31 MSB

w  For LSB, need to grab output of adder of MSB (SET) and set it as input to MUX ALU for MSB

Page 59: Adders - facultystaff.richmond.edu

32b ALU w/ SLT

Page 60: Adders - facultystaff.richmond.edu

32b ALU w/ SLT

Page 61: Adders - facultystaff.richmond.edu

Conditional Branch Instructions

•  Branch if 2 registers equal or unequal

•  Easiest way:w  Test (a-b) == 0

•  In hardware,w OR all outputs togetherw  InvertZero = (o31+o30+...+o0)

Page 62: Adders - facultystaff.richmond.edu

Review: ALU

•  AND/OR•  Addition/

Subtraction•  SLT•  Conditional

branches

Page 63: Adders - facultystaff.richmond.edu

What More Do We Need?

•  Multiplication•  Division