Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs –...

50
Combinational Logic Computer Organization Ellen Walker Hiram College Figures from Computer Organization and Design 3ed, D.A. Patterson & J.L. Hennessey, Morgan Kauffman © 2005 unless otherwise specified

Transcript of Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs –...

Page 1: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Combinational Logic

Computer Organization Ellen Walker

Hiram College

Figures from Computer Organization and Design 3ed, D.A. Patterson & J.L. Hennessey, Morgan Kauffman © 2005 unless otherwise specified

Page 2: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Types of Logic

•  Combinational Logic –  Outputs depend only on inputs –  Outputs change (after delay) as inputs change

•  Sequential Logic –  Outputs depend on inputs and memory (including

previous output) –  Memory values called state –  Outputs (and state) change synchronously based

on a clock signal

Page 3: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Truth Tables

•  Completely describe combinational logic •  Column for each input and output •  Row for each possible combination of

inputs – For n inputs, there are 2^n entries

Page 4: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Truth Table Example A B C A * B A * (B+C) 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 1 1 0 0 1 0 0 0 0 1 0 1 0 1 1 1 0 1 1 1 1 1 1 1

Page 5: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Primary Boolean Operations

A B A * B

0 0 0

0 1 0

1 0 0

1 1 1

A B A + B

0 0 0

0 1 1

1 0 1

1 1 1

NOT (~) : ~0 = 1 and ~1 = 0 This is written as an overbar in the textbook

Page 6: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Axioms of Boolean Algebra

•  Identity A+0=A, A*1=A •  Zero and One A+1=1, A*0=0 •  Inverse A+ ~A=1, A *~A=0 •  Commutative A+B=B+A, A*B=B*A •  Associative A+(B+C)=(A+B)+C

A*(B*C)=(A*B)*C •  Distributive A+(B*C) = (A+B)*(A+C)

A *(B+C) = (A*B) + (A*C)

Page 7: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

DeMorgan’s Laws

•  The NOT operation is distributed through parentheses by – Negating every variable AND – Changing AND to OR and vice versa

•  ~(A+B) = ~A * ~B •  ~(A * B) = ~A + ~B

Page 8: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Logic Equation Examples

•  Consider 3 inputs A, B, C •  ANY: true if at least one is true

ANY = A+B+C •  MOST: true if two or more are true

MOST = (A*B)+(A*C)+(B*C) •  ONE: true if exactly one is true

ONE = ~A*~B*C + ~A*B*~C + A*~B*~C

Page 9: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Many Possible Equations

•  TWO: Exactly TWO of A,B,C are true TWO = A*B*~C + A*~B*C + ~A*B*C TWO = (A*B + A*C + B*C) * ~(A*B*C)

•  Can we prove these expressions are equivalent? – Yes, if their truth tables are identical – Yes, if we can find a sequence of axioms to

transform one to the other

Page 10: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Gates

•  Gates implement basic logic functions

and

nor

not

nand

or

Page 11: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Negation Shorthand

•  Bubble on input or output can replace a NOT gate

Page 12: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Implementing Equations Directly

•  Gates for + , * and bubbles for ~ •  Wires for inputs and outputs •  TWO = A*B*~C + A*~B*C + ~A*B*C

A B C

TWO

Page 13: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Another Implementation

•  TWO = (A*B + A*C + B*C) * ~(A*B*C) A B C

TWO

Page 14: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Truth Table to Gates

•  AND gate for every “1” in the output column – Bubble 0 inputs in the row, don’t bubble 1

inputs •  OR gate to connect rows together •  This is called Sum of Products

formulation

Page 15: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Example A B C X 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 0

(~A*~B*~C) +

(~A*B*~C) + (~A*B*C) +

(A*B*~C)

Page 16: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Simplifying

•  Group together expressions with common elements

•  ~A~B~C + ~AB~C = ~A~C •  ~AB~C + ~ABC = ~AB •  ~ABC + ABC = BC

Page 17: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Simplified Circuit

Fewer gates and fewer inputs

Page 18: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Karnaugh Map

•  Rewrite truth table in a rectangular matrix

•  “Rows” with common subexpressions are adjacent

•  Find simplifications by circling adjacent 1’s – Circles can wrap around top/bottom

Page 19: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Kmap Example

A B C X 0 0 0 1 0 0 1 0 0 1 0 1 0 1 1 1 1 0 0 0 1 0 1 0 1 1 0 1 1 1 1 0

1 0 1 1 0 0 0 1 A

C

B

Page 20: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

4-Variable Kmap

•  Numbers indicate row of truth table

Page 21: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Example

•  4 variables represent 4 bits of a number representing an hour

•  Outputs are the 4 bits of the next hour (output for 1011 (11) should be 0000)

•  Outputs for 12, 13, 14, and 15 are don’t cares

•  Tool: KV-Diagram Applet

Page 22: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Important Building Blocks

•  Decoder – N inputs form a binary number – Corresponding bit from 2^N outputs is set

•  Multiplexor – 2^N “data” inputs, N “address” inputs – Corresponding bit from “data” is copied to

(single) output bit

Page 23: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

3-to-8 Decoder Truth Table i2 i1 i0 o0 o1 o2 o3 o4 o5 o6 o7 0 0 0 1 0 0 0 0 0 0 0 0 0 1 0 1 0 0 0 0 0 0 0 1 0 0 0 1 0 0 0 0 0 0 1 1 0 0 0 1 0 0 0 0 1 0 0 0 0 0 0 1 0 0 0 1 0 1 0 0 0 0 0 1 0 0 1 1 0 0 0 0 0 0 0 1 0 1 1 1 0 0 0 0 0 0 0 1

Page 24: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

3-to-8 Decoder Symbol

3 Decoder

out0

out7

Input line with slash is a “bus” - indicates 3 inputs bundled together

Page 25: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Multiplexor (2-bit selector)

•  Circuit to “select” one of its data inputs based on address inputs

•  Simplest multiplexor has 2 data inputs (A&B), 1 address (or selector) input Out = ~S * A + S * B

Page 26: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

General Multiplexors

•  Build using N to 2^N decoder – Address bits are input to decoder – N AND gates, each gets 1 data input, and

corresponding decoder output –  OR gate connecting the AND gates

•  O = d0*i0+d1*i1+i2*i2+… – dj is j’th output of decoder –  ij is j’th input to the multiplexor

Page 27: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Multiplexor as Logic Implementor

•  For N inputs, use an N input multiplexor •  Address inputs are actual inputs to circult •  Data inputs fixed to corresponding outputs

from truth table •  Multiplexor “selects” the correct row of the

truth table, hence the correct output •  Any function can be implemented with 1

multiplexor (of the appropriate size)

Page 28: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Programmed Logic Array

•  A Programmed Logic Array implements Sum of Products form directly

•  AND gates (generate product terms) •  OR gates (combine product terms into

outputs) •  Since structure is so regular, build PLA

in silicon, use fuses to connect inputs to gates

Page 29: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

PLA Example

And block

Or Block (only 1)

Page 30: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Read Only Memory

•  ROM is essentially many multiplexors working in parallel

•  Address bits (input) – Choose a memory location

•  Data bits (output) – Value of bits at that memory location

Page 31: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

ROM Size

•  Width = number of bits per address (e.g. word size, number of data lines)

•  Height = number of addresses (e.g. words in memory) –  If there are N input (address) lines, the

height is 2^N •  Total number of bits stored = height x

width

Page 32: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Implementing a Function in ROM

•  Given N inputs, M outputs •  ROM

–  Height = –  Width =

•  Program each word in ROM with the outputs corresponding to that word’s address

•  Connect inputs to: •  Connect outputs to:

Page 33: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Reconfiguring ROMs

•  To create a “taller” ROM, use 2 ROMs and use the high-order address bit to control a MUX that chooses between their outputs. The other address bits go to both individual ROMS.

•  To create a “wider” ROM, use 2 ROMs and combine words from both to create a single wider word. The address bits go to both ROMS.

Page 34: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Building ALU

•  2 inputs •  Operation code •  Based on code, performs operation on

the given inputs

Page 35: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

1-Bit Logic Unit

•  Operation Codes: 0=AND, 1=OR

Page 36: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

1-Bit Adder

a

b

carry out

carry in

sum

Page 37: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

1-Bit ALU (Add, And, Or)

•  Carry in & out lines •  Bigger Multiplexor for

opcode •  Data inputs to

Multiplexor: –  AND –  OR –  Adder

Page 38: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

ALU with Subtraction

•  Ainvert, Binvert operate on negated inputs

•  For subtraction, set both CarryIn and Binvert to true

Page 39: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Preparing for SLT

•  SLT sets low-order bit to 1 if a<b –  Subtract a and b –  Copy sign bit to “Set” –  Output “Set” as result of low-order bit, 0 for all

other) •  Updates:

–  Less is now an input to ALU (1-bit register) –  Set is an output from MSB (only) –  MSB also computes overflow

Page 40: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

ALU Bits

MSB Bits 0-30

Page 41: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

32-Bit ALU with Zero Test

Page 42: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Adders

•  Ripple-carry adder – Carry N = An*Bn + An*Cn-1+Bn*Cn-1 – Delay is O(N) in number of bits

•  Fastest possible adder – Compute all of carries simultaneously – Delay = O(1) – Cost (hardware) proportional to # bits

Page 43: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Equations for Ideal Adder

•  Start with c1 (isolate c0) c1 = a0*b0+a0*c0+b0*c0 = a0*b0+(a0+b0)*c0

•  Same formula for c2, substitute c1 c2 = a1*b1+(a1+b1)*c1 = a1*b1+(a1+b1)*(a0*b0+(a0+b0)*c0)

•  Repeat for c3, substitute c2, etc.

Page 44: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Propagate and Generate

c2 = a1*b1+ (a1+b1)*(a0*b0+(a0+b0)*c0) •  Two factors repeat in each expansion •  Generate: gi = ai*bi

– Generates a new carry for bit i+1 •  Propagate: pi = ai+bi

– Propagates an existing carry for bit i+1

Page 45: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

New Equation for Carry

•  Carry out (ci+1) happens if: – A new carry is generated (gi) – An existing carry is propagated (pi*ci)

•  Therefore, the equation for carry bit ci is: ci+1 = gi + pi*ci

Page 46: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Expanded Equation for 4 bits

•  c1 = g0 + p0*c0 •  c2 = g1 + p1*(g0+p0*c0)

= g1 + p1*g0+p1*p0*c0 •  c3 = g2 + p2*g1+p2*p1*g0 +

p2*p1*p0*c0 •  c4 = g3 + p3*g2 + p3*p2*g1 +

p3*p2*p1*g0 + p3*p2*p1*p0*c0

Page 47: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Trading off speed for hardware

•  Create a set of 4-bit adders that generate as outputs p4 and g4 (now known as Pi and Gi, where the index denotes which block) – Compute all 4 output bits, p4 and g4

simultaneously •  Add carry-lookahead logic that takes

the Pi and Gi values and generates the carry-in value for each 4-bit adder

Page 48: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

16-bit Adder from 4-bit Blocks

Page 49: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

How Much Speedup?

•  Instead of 32 x delay for 32 bits, we have 8 x delay (of the carry-lookahead unit)

•  The base delay might also have changed – compute sum, carry for one bit vs. compute

sum, P, G for 4 bits

Page 50: Combinational Logicwalkerel/cs252/comblogic.pdf• Row for each possible combination of inputs – For n inputs, there are 2^n entries . ... • Gates implement basic logic functions

Carry-Lookahead Adder

•  Compromise between ripple-carry adder and ideal (high-speed, much hardware) adder

•  Build a “carry-lookahead block” that takes