Docsity

Introduction to Computer Science: Combinational Circuits and Boolean Algebra, Study notes of Computer Science

Toggle sidebar
bg1
Introduction to Computer Scienc e • Sedgewick and Wayne • Copyright © 2007 • http://www.cs .Princeton.EDU/IntroCS
6. Combinational Circuits
George Boole (1815 – 1864) Claude Shannon (1916 – 2001)
2
Computer Architecture
TOY lectures. von Neumann machine.
This lecture. Boolean circuits.
3
Digital Circuits
Q. What is a digital system?
A. Digital: signals are 0 or 1.
Q. Why digital systems?
A. Accurate, reliable, fast, cheap.
Basic abstractions.
On, off.
Wire: propagates on/off value.
Switch: controls propagation of on/off values through wires.
Applications. Cell phone, iPod, antilock breaks, microprocessors, …
analog: signals vary continu ously
4
Building Blocks
pf3
pf4
pf5
pf8
pf9
pfa
pfd
pfe

Partial preview of the text

Download Introduction to Computer Science: Combinational Circuits and Boolean Algebra and more Study notes Computer Science in PDF only on Docsity!

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

6. Combinational Circuits

George Boole (1815 – 1864) Claude Shannon (1916 – 2001)

2

Computer Architecture

TOY lectures. von Neumann machine.

This lecture. Boolean circuits.

Digital Circuits

Q. What is a digital system?

A. Digital: signals are 0 or 1.

Q. Why digital systems?

A. Accurate, reliable, fast, cheap.

Basic abstractions.

 On, off.

 Wire: propagates on/off value.

 Switch: controls propagation of on/off values through wires.

Applications. Cell phone, iPod, antilock breaks, microprocessors, …

analog: signals vary continuously

Building Blocks

5

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.

power

connection

6

Logic Gates

Logic Gates

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.

13

Truth Table

Truth table.

 Systematic method to describe Boolean function.

 One row for each possible input combination.

 n inputs ⇒ 2

n

rows.

AND truth table

x y x y

14

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

x

AND

y

XOR

OR

x

NOR

truth table for all Boolean functions of 2 variables

y

y'

x'

EQ

NAND

ONE

x

every 4-bit value represents one

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

y

x 0 0 0 0 0

OR

MAJ

ODD

every 4-bit value represents one

every 8-bit value represents one

every 2

n -bit value represents one

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 } are universal.

Hint. DeMorgan's law: ( x' y' ) ' = x + y.

x'

Expressing XOR Using AND, OR, NOT

y

x'y

x'y + xy'

xy'

y'

x XOR y

x

x' NOT x

x AND y x y

x OR y

notation meaning

x + y

17

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

x y z MAJ xy'z xyz' xyz

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

proves that { AND , OR , NOT }

are universal

18

Translate Boolean Formula to Boolean Circuit

Sum-of-products. XOR.

Translate Boolean Formula to Boolean Circuit

Sum-of-products. XOR.

Translate Boolean Formula to Boolean Circuit

Sum-of-products. XOR.

25

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.

26

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

x y z ODD x'yz' xy'z' xyz

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

ODD Parity Circuit

ODD(x, y, z).

 1 if odd number of inputs are 1.

 0 otherwise.

ODD Parity Circuit

ODD(x, y, z).

 1 if odd number of inputs are 1.

 0 otherwise.

29

Adder Circuit

30

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.

Step 1. Represent input and output in binary.

x

1

x

2

x

3

x

0

y

1

y

2

y

3

y

0

z

1

z

2

z

3

z

0

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: 2

256+

rows >> # electrons in universe!

x

1

x

2

x

3

x

0

y

1

y

2

y

3

y

0

z

1

z

2

z

3

z

0

4-bit adder truth table

y 2

y 3 0 0 0 0 1. 1

x 0

x 1 0 0 0 0 0. 1

x 2

x 3 0 0 0 0 0. 1

y 0

y 1 0 1 0 1 0. 1

z 2

z 3 0 0 0 0 1. 1

z 0

z 1 0 1 0 1 0. 1

8+ = 512 rows!

c 0 0 0 0 0 0. 1

c

in

c

out

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.

x

1

x

2

x

3

x

0

y

1

y

2

y

3

y

0

z

1

z

2

z

3

z

0

c

1

c

2

c

3

c

0

carry bit

c

i

c

i+

y

i

x

i 0 0 0 1 0 1 1 1

summand bit

c

i

z

i

y

i

x

i 0 1 1 0 1 0 0 1

c

out

37

Adder: Switch Level View

38

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.

Switch Level

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

41

Circuit Anatomy

42

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]

43

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]

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

Extra Slides

49

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

50

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.

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

Boolean Logic

Copyright 2006, Sidney Harris, http://www.sciencecartoonsplus.com/

Computer

Electrical computer. Same fundamental abstractions.

Abstraction Relay Computer Electrical Computer

Connector Wire Wire

Signal Voltage Voltage

Switch Relay Metal-oxide transistor