Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic...

91
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright © 2005 http://www.cs.Princeton.EDU/IntroCS Combinational Circuits

Transcript of Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic...

Page 1: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

Introduction to Computer Science • Robert Sedgewick and Kevin Wayne • Copyright © 2005 • http://www.cs.Princeton.EDU/IntroCS

Combinational Circuits

Page 2: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

2

Virtual machines

High-Level Language

Assembly Language

Operating System

Instruction SetArchitecture

Microarchitecture

Digital Logic Level 0

Level 1

Level 2

Level 3

Level 4

Level 5

Abstractions for computers

Page 3: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

3

A simple microcomputer from the year of 2005

IR

DECODE

CONTROLAND

SEQUENCING

PC

ACC B

ALU

CLOCK

I/OD

EVICE

I/OD

EVICE

DATA BUS

CONTROL BUS

ADDRESS BUS

MEMORYI/OPORT

FLAG

Page 4: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

4

Instruction set

OPCODE MNEMONIC OPCODE MNEMONIC 0 NOP A CMP 1 LDA B JG2 STA C JE 3 ADD D JL4 SUB5 IN6 OUT7 JMP8 JN9 HLT

OPCODE OPERAND

4 12

Page 5: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

Introduction to Computer Science • Robert Sedgewick and Kevin Wayne • Copyright © 2005 • http://www.cs.Princeton.EDU/IntroCS

The Princeton TOY Machine

Page 6: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

6

What is TOY?

An imaginary machine similar to:ν Ancient computers. (PDP-8, world's first

commercially successful minicomputer. 1960s)

– 12-bit words– 2K words of memory– Used in Apollo project

Page 7: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

7

What is TOY?

An imaginary machine similar to:ν Ancient computers.ν Today's microprocessors.

Pentium Celeron

Page 8: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

8

What is TOY?

An imaginary machine similar to:ν Ancient computers.ν Today's microprocessors.

Why study TOY?ν Machine language programming.

– how do high-level programs relate to computer?– a favor of assembly programming

ν Computer architecture.– how is a computer put together?– how does it work?

ν Optimized for understandability, not cost or performance.

Page 9: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

9

Inside the Box

Switches. Input data and programs.

Lights. View data.

Memory.ν Stores data and programs.ν 256 "words." (16 bits each)ν Special word for stdin /

stdout.

Program counter (PC).ν An extra 8-bit register.ν Keeps track of next

instruction to be executed.

Registers.ν Fastest form of storage.ν Scratch space during

computation.ν 16 registers. (16 bits each)ν Register 0 is always 0.

Arithmetic-logic unit (ALU). Manipulate data stored in registers.

Standard input, standard output. Interact with outside world.

Page 10: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

10

Instruction set architecture (level 2)

Machine contents at a particular place and time.ν Record of what program has done.ν Completely determines what machine will do.

0008 0005 0000 0000 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000 0000

8A00 8B01 1CAB 9C02 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000 0000

0000 0000 0000 0000 0000 0000 0000 0000

00:

08:

10:

18:

20:

28:

.

.

E8:

F0:

F8: 0000 0000 0000 0000 0000 0000 0000 0000

Main Memorypc10

nextinstruction

program

Registers

0000

R2

0000

R3

0000

R8

0000

R9

R0

0000

R1

0000

RA

0000

RB

0000

0000

R6

0000

R7

0000

RC

0000

RD

R4

0000

R5

0000

RE

0000

RF

0000

variables

data

Page 11: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

11

Instruction set architecture (level 2)

Program: Sequence of instructions.

16 instruction types:ν 16-bit word (interpreted one way).ν Changes contents of registers,

memory, andPC in specified, well-defined ways.

Data:ν 16-bit word (interpreted other way).

Program counter (PC):ν Stores memory address of "next

instruction."

0: haltInstructions

1: add2: subtract3: and4: xor5: shift left6: shift right7: load address8: load9: storeA: load indirectB: store indirectC: branch zeroD: branch positiveE: jump registerF: jump and link

Page 12: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

12

TOY Architecture (level 1)

Page 13: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

13

level 0

Page 14: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

14

Boolean Algebra

Based on symbolic logic, designed by George BooleBoolean variables take values as 0 or 1.Boolean expressions created from:

ν NOT, AND, OR

Page 15: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

15

NOT

NOT

Digital gate diagram for NOT:

X X’

Page 16: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

16

AND

AND

Digital gate diagram for AND:

X⋅Y XY

Page 17: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

17

OR

OR

Digital gate diagram for OR:

X+Y

Page 18: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

18

Operator Precedence

Examples showing the order of operations: NOT > AND > OR

Use parentheses to avoid ambiguity

Page 19: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

19

Defining a function

Description: square of x minus 1Algebraic form : x2-1Enumeration:

::245154833201

f(x)x

Page 20: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

20

Defining a function

Description: number of days of the x-th month of a non-leap yearAlgebraic form: ?Enumeration:

311230113110309318317306315304313282311

f(x)x

Page 21: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

21

Truth Table

Truth table.ν Systematic method to describe Boolean function.ν One row for each possible input combination.ν N inputs ⇒ 2N rows.

AND truth table

0 0

0 1

1 0

1 1

0

0

0

1

x y x y

Page 22: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

22

Proving the equivalence of two functions

Prove that x2-1=(x+1)(x-1)

Using algebra: (you need to follow some rules)(x+1)(x-1) = x2+x-x-1= x2-1

Using enumeration:

:::2424515154883332001

x2-1(x+1)(x-1)x

Page 23: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

23

Important laws

x + 1 = 1x + 0 = xx + x = 1

x.1 = xx.0 = 0x.x = 0

DeMorgan Law

x.y = x + y

Page 24: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

24

Truth Tables (1 of 3)

A Boolean function has one or more Boolean inputs, and returns a single Boolean output.A truth table shows all the inputs and outputs of a Boolean function

Example: ¬X ∨ Y

Page 25: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

25

Truth Tables (2 of 3)

Example: X ∧ ¬Y

Page 26: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

26

Truth Tables (3 of 3)

When s=0, return x; otherwise, return y.Example: (Y ∧ S) ∨ (X ∧ ¬S)

muxX

Y

S

Z

Two-input multiplexer

Page 27: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

27

Truth Table for Functions of 2 Variables

Truth table.ν 16 Boolean functions of 2 variables.

ZERO

Truth table for all Boolean functions of 2 variables

y

0 0

0 1 0

1 0 0

1 1 0

0

0

1

0

0

1

0

0

x

0

0

1

1

AND

0

0

0

1

y

0

1

0

1

XOR

0

1

1

0

OR

0

1

1

1

x

0

NOR

Truth table for all Boolean functions of 2 variables

y

0 1

0 1 0

1 0 0

1 1 0

y'

1

0

1

0

x'

1

1

0

0

1

0

1

1

EQ

1

0

0

1

1

1

0

1

NAND

1

1

1

0

ONE

1

1

1

1

x

0

every 4-bit value represents one

Page 28: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

28

Truth Table for Functions of 3 Variables

Truth table.ν 16 Boolean functions of 2 variables.ν 256 Boolean functions of 3 variables.ν 2^(2^n) Boolean functions of n variables!

AND

some functions of 3 variables

z

0 0

0 1 0

1 0 0

1 1 0

y

0

x

0

0

0

0

0

0 1

1 0

1 1

01

1

1

1

0

0

0

1

OR

0

1

1

1

1

1

1

1

MAJ

0

0

0

1

0

1

1

1

ODD

0

1

1

0

1

0

0

1

every 4-bit value represents one

every 8-bit value represents one

every 2n-bit value represents one

Page 29: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

29

Sum-of-Products

Sum-of-products. Systematic procedure for representing a Boolean function using AND, OR, NOT.

ν Form AND term for each 1 in Boolean function.ν OR terms together.

x'yz

expressing MAJ using sum-of-products

z xyz' xyzxy'zMAJyx

0

0

0

1

0

1

1

1

0

1

0

1

0

1

0

1

0

0

1

1

0

0

1

1

0

0

0

0

1

1

1

1

0

0

0

1

0

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

1

x'yz + xy'z + xyz' + xyz

0

0

0

1

0

1

1

1

proves that { AND, OR, NOT }are universal

Page 30: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

30

Universality of AND, OR, NOT

Fact. Any Boolean function can be expressed using AND, OR, NOT.

ν { AND, OR, NOT } are universal.ν Ex: XOR(x,y) = xy' + x'y.

Exercise. Show {AND, NOT}, {OR, NOT}, {NAND}, {NOR} are universal.Hint. DeMorgan's law: (x'y')' = x + y.

x'

Expressing XOR Using AND, OR, NOT

y

0 1

1 1

0 0

1 0

x'y

0

1

0

0

x'y + xy'

0

1

1

0

xy'

0

0

1

0

y'

1

0

1

0

x XOR y

0

1

1

0

x

0

0

1

1

NOT xx'x AND yx yx OR y

MeaningNotation

x + y

Page 31: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

31

Computer Architecture

This lecture. Boolean circuits.

Ahead. Putting it all together and building a TOY machine.

same issues apply to modern day microprocessors, just a matter of scale and speed.

Page 32: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

32

Digital Circuits

What is a digital system?ν Analog: signals vary continuously.ν Digital: signals are 0 or 1.

Why digital systems?ν Accuracy and reliability.ν Staggeringly fast and cheap.

Basic abstractions.ν On, off.ν Wire: propagates on/off value.ν Switch: controls propagation of on/off values

through wires.

0.0V0.5V

2.8V3.3V

0 1 0

Page 33: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

33

Wires

Wires.ν On (1): connected to power.ν Off (0): not connected to power.ν If a wire is connected to a wire that is on, that

wire is also on.ν Typical drawing convention: "flow" from top, left

to bottom, right.

0

powerconnection

1

1

1

Page 34: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

34

Controlled switch. [relay implementation]ν 3 connections: input, output, control.ν Magnetic force pulls on a contact that cuts

electrical flow.ν Control wire affects output wire, but output does

not affect control; establishes forward flow of information over time.

Controlled Switch

X

X

Page 35: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

35

Circuit Anatomy

Page 36: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

36

Logic Gates: Fundamental Building Blocks

Page 37: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

37

NOT

Page 38: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

38

NOT

1

0

0

1

Page 39: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

39

OR

Page 40: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

40

Series relays = NOR

0 10 0

101 1

0

0

0

1

Page 41: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

41

NOR

Page 42: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

42

AND

Page 43: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

43

AND

Page 44: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

44

Logic Gates: Fundamental Building Blocks

Page 45: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

45

What about parallel relays?

0

11

0

0

1

=NAND

Page 46: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

46

Can we implement AND/OR using parallel relays?

Now we know how to implement AND,OR and NOT. We can just use them as black boxes without knowing how they were implemented. Principle of information hiding.

Page 47: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

47

Multiway Gates

Multiway gates.ν OR: 1 if any input is 1; 0 otherwise.ν AND: 1 if all inputs are 1; 0 otherwise.ν Generalized: negate some inputs.

Page 48: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

48

Multiway Gates

Multiway gates.ν OR: 1 if any input is 1; 0 otherwise.ν AND: 1 if all inputs are 1; 0 otherwise.ν Generalized: negate some inputs.

Page 49: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

49

Translate Boolean Formula to Boolean Circuit

Sum-of-products. XOR.

Page 50: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

50

Translate Boolean Formula to Boolean Circuit

Sum-of-products. XOR.

Page 51: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

51

Translate Boolean Formula to Boolean Circuit

Sum-of-products. XOR.

Page 52: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

52

Translate Boolean Formula to Boolean Circuit

Sum-of-products. Majority.

Page 53: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

53

Translate Boolean Formula to Boolean Circuit

Sum-of-products. Majority.

Page 54: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

54

Translate Boolean Formula to Boolean Circuit

Sum-of-products. Majority.

Page 55: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

55

Simplification Using Boolean Algebra

Every function can be written as sum-of-product

Many possible circuits for each Boolean function.ν Sum-of-products not necessarily optimal in:

– number of switches (space)– depth of circuit (time)

Page 56: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

56

Boolean expression simplification

Karnaugh map

Page 57: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

57

Example

xy z

Page 58: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

58

Simplification Using Boolean Algebra

Many possible circuits for each Boolean function.ν Sum-of-products not necessarily optimal in:

– number of switches (space)– depth of circuit (time)

MAJ(x, y, z) = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

Page 59: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

59

Layers of Abstraction

Layers of abstraction.ν Build a circuit from wires and switches.

[implementation]ν Define a circuit by its inputs and outputs. [API]ν To control complexity, encapsulate circuits.

[ADT]

Page 60: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

60

Layers of Abstraction

Layers of abstraction.ν Build a circuit from wires and switches.

[implementation]ν Define a circuit by its inputs and outputs. [API]ν To control complexity, encapsulate circuits.

[ADT]

Page 61: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

61

ODD Parity Circuit

ODD(x, y, z).ν 1 if odd number of inputs are 1. ν 0 otherwise.

x'y'z

Expressing ODD using sum-of-products

z xy'z' xyzx'yz'ODDyx

0

1

1

0

1

0

0

1

0

1

0

1

0

1

0

1

0

0

1

1

0

0

1

1

0

0

0

0

1

1

1

1

0

1

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

0

1

0

0

0

0

0

0

0

0

0

0

1

x'y'z + x'yz' + xy'z' + xyz

0

1

1

0

1

0

0

1

Page 62: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

62

ODD Parity Circuit

ODD(x, y, z).ν 1 if odd number of inputs are 1. ν 0 otherwise.

Page 63: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

63

ODD Parity Circuit

ODD(x, y, z).ν 1 if odd number of inputs are 1. ν 0 otherwise.

Page 64: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

64

Expressing a Boolean Function Using AND, OR, NOT

Ingredients.ν AND gates.ν OR gates.ν NOT gates.ν Wire.

Instructions.ν Step 1: represent input and output signals with

Boolean variables.ν Step 2: construct truth table to carry out

computation.ν Step 3: derive (simplified) Boolean expression using

sum-of products.ν Step 4: transform Boolean expression into circuit.

Page 65: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

65

Let's Make an Adder Circuit

Goal. x + y = z for 4-bit integers.ν We build 4-bit adder: 9 inputs, 4 outputs.ν Same idea scales to 128-bit adder.ν Key computer component.

842 7

753 9+

606 6

111 0

Page 66: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

66

Let's Make an Adder Circuit

Step 1. Represent input and output in binary.

x1x2x3 x0

y1y2y3 y0+

z1z2z3 z0

100 0

110 1+

001 1

011 0

Page 67: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

67

Let's Make an Adder Circuit

Goal. x + y = z for 4-bit integers.

Step 2. [first attempt]ν Build truth table.

Q. Why is this a bad idea?A. 128-bit adder: 2256+1 rows >> # electrons in universe!

x1x2x3 x0

y1y2y3 y0+

z1z2z3 z0

4-Bit Adder Truth Table

y2y30

0

0

0

1

.

1

0

0

0

0

0

.

1

x0x10

0

0

0

0

.

1

0

0

0

0

0

.

1

x2x30

0

0

0

0

.

1

0

0

0

0

0

.

1

y0y10

1

0

1

0

.

1

0

0

1

1

0

.

1

z2z30

0

0

0

1

.

1

0

0

0

0

0

.

1

z0z10

1

0

1

0

.

1

0

0

1

1

0

.

1

28+1 = 512 rows!

c00

0

0

0

0

.

1

cincout

Page 68: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

68

1-bit half adder

x y s c

ADDxy

cs

We add numbers one bit at a time.

Page 69: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

69

1-bit full adder

x y s

ADD

x

Cout

Cin

y

s

CoutCin

Page 70: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

70

8-bit adder

Page 71: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

71

Let's Make an Adder Circuit

Goal. x + y = z for 4-bit integers.

Step 2. [do one bit at a time]ν Build truth table for carry bit.ν Build truth table for summand bit.

x1x2x3 x0

y1y2y3 y0+

z1z2z3 z0

c1c2c3 c0 = 0

Carry Bit

ci ci+1yixi

0

0

0

1

0

1

1

1

0

1

0

1

0

1

0

1

0

0

1

1

0

0

1

1

0

0

0

0

1

1

1

1

Summand Bit

ci ziyixi

0

1

1

0

1

0

0

1

0

1

0

1

0

1

0

1

0

0

1

1

0

0

1

1

0

0

0

0

1

1

1

1

cout

Page 72: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

72

Let's Make an Adder Circuit

Goal. x + y = z for 4-bit integers.

Step 3.ν Derive (simplified) Boolean expression.

MAJ

0

0

0

1

0

1

1

1

ODD

0

1

1

0

1

0

0

1

ci ci+1yixi

0

0

0

1

0

1

1

1

0

1

0

1

0

1

0

1

0

0

1

1

0

0

1

1

0

0

0

0

1

1

1

1

ci ziyixi

0

1

1

0

1

0

0

1

0

1

0

1

0

1

0

1

0

0

1

1

0

0

1

1

0

0

0

0

1

1

1

1

Carry Bit Summand Bit

Page 73: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

73

Let's Make an Adder Circuit

Goal. x + y = z for 4-bit integers.

Step 4.ν Transform Boolean expression into circuit.ν Chain together 1-bit adders.

Page 74: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

74

Adder: Interface

Page 75: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

75

Adder: Component Level View

Page 76: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

76

Adder: Switch Level View

Page 77: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

77

Subtractor

Subtractor circuit: z = x – y.ν One approach: design like adder circuitν Better idea: reuse adder circuit

– 2’s complement: to negate an integer, flip bits, then add 1

Page 78: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

78

Shifter

4-bit Shifter

SHIFT

s0 s1 s2 s3

z0 z1 z2 z3

x0

x1

x2

x3

Only one of them will be on at a time.

Page 79: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

79

Shifter

x0000s3

x1x000s2

x2x1x00s1

x3x2x1x0s0

z3z2z1z0

z0 = s0‧x0 + s1‧0 + s2‧0 + s3‧0z1 = s0‧x1 + s1‧x0 + s2‧0 + s3‧0z2 = s0‧x2 + s1‧x1 + s2‧x0 + s3‧0z3 = s0‧x3 + s1‧x2 + s2‧x1 + s3‧x0

Page 80: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

80

Shifter

z0 = s0‧x0 + s1‧0 + s2‧0 + s3‧0z1 = s0‧x1 + s1‧x0 + s2‧0 + s3‧0z2 = s0‧x2 + s1‧x1 + s2‧x0 + s3‧0z3 = s0‧x3 + s1‧x2 + s2‧x1 + s3‧x0

Page 81: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

81

N-bit Decoder

N-bit decoderν N address inputs, 2N data outputsν Addresses output bit is 1;

all others are 0

Page 82: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

82

N-bit Decoder

N-bit decoderν N address inputs, 2N data outputsν Addresses output bit is 1;

all others are 0

Page 83: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

83

2-Bit Decoder Controlling 4-Bit Shifter

Ex. Put in a binary amount to shift.r0r1

Page 84: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

84

Arithmetic Logic Unit

Arithmetic logic unit (ALU). Computes all operations in parallel.

ν Add and subtract.ν Xor.ν And.ν Shift left or right.

Q. How to select desired answer?

Page 85: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

85

1 Hot OR

1 hot OR.ν All devices compute their answer;

we pick one.ν Exactly one select line is on.ν Implies exactly one output line is

relevant.

adder

xor

shifter

x.1 = xx.0 = 0

x + 0 = x

Page 86: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

86

Bus

16-bit busν Bundle of 16 wiresν Memory transfer

Register transfer

8-bit busν Bundle of 8 wiresν TOY memory address

4-bit busν Bundle of 4 wiresν TOY register address

Page 87: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

87

Bitwise AND, XOR, NOT

Bitwise logical operationsν Inputs x and y: n bits eachν Output z: n bitsν Apply logical operation to each corresponding pair

of bits

Page 88: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

88

ALU

TOY ALUν Big combinational logic ν 16-bit busν Add, subtract, and, xor, shift left, shift right,

copy input 2

Page 89: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

89

Device Interface Using Buses

Device. Processes a word at a time.Input bus. Wires on top.Output bus. Wires on bottom.Control. Individual wires on side.

16-bit words for TOY memory

Page 90: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

90

ALU

Arithmetic logic unit.ν Add and subtract.ν Xor.ν And.ν Shift left or right.

Arithmetic logic unit.ν Computes all operations in parallel.ν Uses 1-hot OR to pick each bit answer.

Page 91: Combinational Circuits - csie.ntu.edu.twb95088/temp/print/%b2%d5%bby/lec02... · ν Systematic method to describe Boolean function. ... = x'yz + xy'z + xyz' + xyz = xy + yz + xz.

91

Summary

Lessons for software design apply to hardware design!

ν Interface describes behavior of circuit.ν Implementation gives details of how to build it.

Layers of abstraction apply with a vengeance!ν On/off.ν Controlled switch. [relay, transistor]ν Gates. [AND, OR, NOT]ν Boolean circuit. [MAJ, ODD]ν Adder.ν Shifter.ν Arithmetic logic unit.ν …ν TOY machine.