100% found this document useful (1 vote)
85 views58 pages

CS 19 Circuits

Circuits

Uploaded by

Baba Hans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
100% found this document useful (1 vote)
85 views58 pages

CS 19 Circuits

Circuits

Uploaded by

Baba Hans
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as PDF, TXT or read online on Scribd
You are on page 1/ 58

COMPUTER SCIENCE

S E D G E W I C K / W A Y N E
PA R T I I : A L G O R I T H M S , M A C H I N E S , a n d T H E O R Y
Computer Science

19. Combinational
Computer Circuits
Science An Interdisciplinary Approach

ROBERT SEDGEWICK
K E V I N WAY N E
Section 6.1
http://introcs.cs.princeton.edu
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
PA R T I I : A L G O R I T H M S , M A C H I N E S , a n d T H E O R Y

19. Combinational Circuits


• Building blocks
• Boolean algebra
• Digital circuits
• Adder circuit
• Arithmetic/logic unit

CS.19.A.Circuits.Basics
Context

Q. What is a combinational circuit?

A. A digital circuit (all signals are 0 or 1) with no feedback (no loops).


analog circuit: signals vary continuously sequential circuit: loops allowed (stay tuned)

Q. Why combinational circuits?

A. Accurate, reliable, general purpose, fast, cheap.

Basic abstractions
• On and off.
• Wire: propagates on/off value.
• Switch: controls propagation of on/off values through wires.

Applications. Smartphone, tablet, game controller, antilock brakes, microprocessor, …


3
Wires

Wires propagate on/off values


• ON (1): connected to power.
• OFF (0): not connected to power.
• Any wire connected to a wire that is ON is also ON.
• Drawing convention: "flow" from top, left to bottom, right.

thick wires are ON

1
power

connection

0
thin wires are OFF

4
Controlled Switch

Switches control propagation of on/off values through wires.


• Simplest case involves two connections: control (input) and output.
• control OFF: output ON
• control ON: output OFF

control input OFF control input ON

output ON output OFF

5
Controlled Switch

Switches control propagation of on/off values through wires.


• General case involves three connections: control input, data input and output.
• control OFF: output is connected to input
• control ON: output is disconnected from input

control input OFF control input ON

data input OFF output OFF data input OFF output OFF

control input OFF control input ON

data input ON output ON data input ON output OFF

Idealized model of pass transistors found in real integrated circuits. 6


Controlled switch: example implementation

A relay is a physical device that controls a switch with a magnet


• 3 connections: input, output, control.
• Magnetic force pulls on a contact that cuts electrical flow.

schematic control off control on

magnet on
magnet pulls
(off ) contact up
connection
contact broken

spring

7
First level of abstraction

Switches and wires model provides separation between


physical world and logical world.
• We assume that switches operate as specified.
• That is the only assumption.
• Physical realization of switch is irrelevant to design.

Physical realization dictates performance


• Size.
• Speed.
• Power.

New technology immediately gives new computer.

Better switch? Better computer.


all built with
"switches and wires"
Basis of Moore's law.

8
Switches and wires: a first level of abstraction

technology switch

technology “information” switch


relay
(1940s)

pneumatic air pressure


vacuum tube

water transistor
fluid
pressure

“pass transistor” in
integrated circuit
relay electric
(now) potential
atom-thick
transistor
Amusing attempts that do not
scale but prove the point Real-world examples that prove the point
9
Switches and wires: a first level of abstraction

VLSI = Very Large Scale Integration

Technology
Deposit materials on substrate.

Key properties
Lines are wires.

Certain crossing lines are controlled switches.

Key challenge in physical world


Fabricating physical circuits with
billions of wires and controlled switches

Key challenge in “abstract” world



Understanding behavior of circuits with
billions of wires and controlled switches

Bottom line. Circuit = Drawing (!)

10
Circuit anatomy

Need more levels of abstraction


to understand circuit behavior

11
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E

Image sources

http://upload.wikimedia.org/wikipedia/commons/f/f4/1965_c1960s_vacuum_tube%2C_7025A-12AX7A%2C_QC%2C_Philips%2C_Great_Britain.jpg
http://electronics.howstuffworks.com/relay.htm

CS.19.A.Circuits.Basics
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
PA R T I I : A L G O R I T H M S , M A C H I N E S , a n d T H E O R Y

19. Combinational Circuits


• Building blocks
• Boolean algebra
• Digital circuits
• Adder circuit
• Arithmetic/logic unit

CS.19.B.Circuits.Algebra
Boolean algebra

Developed by George Boole in 1840s to study logic problems


• Variables represent true or false (1 or 0 for short).
• Basic operations are AND, OR, and NOT (see table below).
Widely used in mathematics, logic and computer science.

George Boole
circuit design 1815−1864
operation Java notation logic notation
(this lecture)
AND x && y x⋀y xy
various notations
OR x || y x⋁y x + y in common use

NOT !x ¬x x'

DeMorgan's Laws
(xy)' = (x' + y' )
Example: (stay tuned for proof )
(x + y)' = x'y'

Relevance to circuits. Basis for next level of abstraction. Copyright 2004, Sidney Harris

http://www.sciencecartoonsplus.com
14
Truth tables

A truth table is a systematic way to define a Boolean function


• One row for each possible set of arguments.
• Each row gives the function value for the specified arguments.
• N inputs: 2N rows needed.

x x' x y xy x y x+y x y NOR x y XOR

0 1 0 0 0 0 0 0 0 0 1 0 0 0
1 0 0 1 0 0 1 1 0 1 0 0 1 1
NOT 1 0 0 1 0 1 1 0 0 1 0 1
1 1 1 1 1 1 1 1 0 1 1 0

AND OR NOR XOR

15
Truth table proofs

Truth tables are convenient for establishing identities in Boolean logic


• One row for each possibility.
• Identity established if columns match.

Proofs of DeMorgan's laws


NOR NOR
(xy) x y x' y' x' + y' (x + x y x' y' x'y'
x y xy x y x+y
' y)'
0 0 0 1 0 0 1 1 1 0 0 0 1 0 0 1 1 1

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

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

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

(xy)' = (x' + y' ) (x + y)' = x'y'

16
All Boolean functions of two variables

Q. How many Boolean functions of two variables?

A. 16 (all possibilities for the 4 bits in the truth table column).

Truth tables for all Boolean functions of 2 variables


x y ZERO AND x y XOR OR NOR EQ ¬y ¬x NAND ONE

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

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

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

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

17
Functions of three and more variables

Q. How many Boolean functions of three variables?

A. 256 (all possibilities for the 8 bits in the truth table column).

all extend to N variables


x y z AND OR NOR MAJ ODD Examples

AND logical AND 0 iff any inputs is 0 (1 iff all inputs 1)


0 0 0 0 0 1 0 0
OR logical OR 1 iff any input is 1 (0 iff all inputs 0)
0 0 1 0 1 0 0 1 NOR logical NOR 0 iff any input is 1 (1 iff all inputs 0)
MAJ majority 1 iff more inputs are 1 than 0
0 1 0 0 1 0 0 1
ODD odd parity 1 iff an odd number of inputs are 1
0 1 1 0 1 0 1 0

1 0 0 0 1 0 0 1 Q. How many Boolean functions of N variables?


1 0 1 0 1 0 1 0 N number of Boolean functions with N variables
2 24 = 16
1 1 0 0 1 0 1 0
3 28 = 256
A. 2 (2 )
N
1 1 1 1 1 0 1 1 4 216 = 65,536
5 232 = 4,294,967,296
Some Boolean functions of 3 variables 6 264 = 18,446,744,073,709,551,616
18
Universality of AND, OR and NOT

Every Boolean function can be represented as a sum of products


• Form an AND term for each 1 in Boolean function.
• OR all the terms together.
x'yz + xy'z + xyz' + xyz = MAJ
x y z MAJ x'yz xy'z xyz' xyz

0 0 0 0 0 0 0 0 0

0 0 1 0 0 0 0 0 0

0 1 0 0 0 0 0 0 0

0 1 1 1 1 0 0 0 1 Def. A set of operations is universal if


1 0 0 0 0 0 0 0 0 every Boolean function can be expressed
using just those operations.
1 0 1 1 0 1 0 0 1

1 1 0 1 0 0 1 0 1 Fact. { AND, OR, NOT } is universal.


1 1 1 1 0 0 0 1 1

Expressing MAJ as a sum of products 19


COMPUTER SCIENCE
S E D G E W I C K / W A Y N E

Image sources
http://en.wikipedia.org/wiki/George_Boole#/media/File:George_Boole_color.jpg

CS.19.B.Circuits.Algebra
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
PA R T I I : A L G O R I T H M S , M A C H I N E S , a n d T H E O R Y

19. Combinational Circuits


• Building blocks
• Boolean algebra
• Digital circuits
• Adder circuit
• Arithmetic/logic unit

CS.19.C.Circuits.Digital
A basis for digital devices

Claude Shannon connected circuit design with Boolean algebra in 1937.

Claude Shannon
“ Possibly the most important, and also the 1916−2001
most famous, master's thesis of the [20th]

− Howard Gardner

Key idea. Can use Boolean algebra to


systematically analyze circuit behavior.

22
A second level of abstraction: logic gates

boolean classic under the cover


notation truth table our symbol proof
function symbol circuit (gate)

x x'
x x'
NOT x' 0
1
1
0
x ¬ x' 1 iff x is 0

x y NOR x y x y
0 0 1
(x + y )' (x + y )' 1 iff x and y
NOR (x + y )' 0 1 0 (x + y )' NOR
1 0 0 are both 0
1 1 0

x y OR x y x y
0 0 0
x+y x+y NOR ¬
OR x + y 0 1 1
OR
1 0 1
x + y = ((x + y )')'
1 1 1

x y AND x y x y
0 0 0
¬ ¬
AND xy 0 1 0 AND xy xy NOR
1 0 0
1 1 1 x y = (x ' + y ')'
23
Multiway OR gates

OR gates with multiple inputs.


• 1 if any input is 1.
• 0 if all inputs are 0.

classic symbol our symbol under the cover


u v w x y z u v w x y z u v w x y z
u+v+w+x+y+z u+v+w+x+y+z
OR
0 if inputs are 000000;
u+v+w+x+y+z 1 if any input is 1

examples
0 1 1 0 0 0
1
Multiway OR gates are oriented vertically

in our circuits. Learn to recognize them! 0 0 0 0 0 1
1

0 0 0 0 0 0
0
24
Multiway generalized AND gates

Multiway generalized AND gates.


• 1 for exactly 1 set of input values.
• 0 for all other sets of input values.
gate function inputs that output 1 another set of inputs
u v w x y z 1 1 1 1 1 1 0 1 1 0 0 0

AND uvwxyz 1 0

0 1 1 0 0 1 0 1 1 0 0 0
u v w x y z

generalized u'vwx'y'z 1 0

u v w x y z 0 0 0 0 0 0 0 1 0 1 0 0
NOR
u'v'w'x'y'z' 1 0

same as (u + v + w + x + y + z)'

Might also call these "generalized NOR gates"; we consistently use AND. 25
Pop quiz on generalized AND gates
x y z
Q. Give the Boolean function computed by these gates.

x y z
Q. Also give the inputs for which the output is 1.

u v w x y z x y z

x y z

u v w x y z
x y z

x y z

x y z

x y z

26
Pop quiz on generalized AND gates
x y z
Q. Give the Boolean function computed by these gates.
x'y'z' 000
x y z
Q. Also give the inputs for which the output is 1.
x'y'z 001
u v w x y z x y z

x'yz' 010
uv'wxy'z 101101 x y z

x'yz 011
u v w x y z
x y z

u'vwx'y'z 011001 xy'z' 100


x y z

xy'z 101
x y z
Get the idea? If not, replay this slide, like flash cards.
xyz' 110
x y z
Note. From now on, we will not label these gates.
xyz 111
27
A useful combinational circuit: decoder
110 = 6
Decoder
Example: 3-to-8 decoder
• n input lines (address).
• 2n outputs. 0
• Addressed output is 1.
• All other outputs are 0. 1

3
outputs 0-5
and 7 are 0
4

output 6
6 is 1

28
A useful combinational circuit: decoder
110 = 6
Decoder
Example: 3-to-8 decoder
• n input lines (address).
• 2n outputs.
• Addressed output is 1.
• All other outputs are 0.

Implementation
• Use all 2n generalized AND gates with n inputs. outputs 0-5
and 7 are 0
• Only one of them matches the input address.

Application (next lecture) output 6


is 1
• Select a memory word for read/write.
• [Use address bits of instruction from IR.]
29
Another useful combinational circuit: demultiplexer (demux)
101 = 5 x
Demultiplexer
Example: 3-to-8 demux
• n address inputs.
• 1 data input with value x. 0

• 2n outputs.
• Addressed output has value x. 1

• All other outputs are 0.


2

3
outputs 0-4
and 6-7 are 0
4

output 5
5 has value x

30
Another useful combinational circuit: demultiplexer (demux)
101 = 5 x
Demultiplexer
Example: 3-to-8 demux
• n address inputs.
0
• 1 data input with value x.
• 2n outputs. 1
• Addressed output has value x.
• All other outputs are 0. 2

Implementation 3

• Start with decoder. outputs 0-4


and 6-7 are 0
• Add AND x to each gate. 4

5 output 5
has value x

Application (next lecture) 6

• Turn on control wires to implement instructions.


• [Use opcode bits of instruction in IR.] 7

31
Decoder/demux
101 = 5 x

Decoder/demux
Example: 3-to-8 decoder/demux
• n address inputs.
• 1 data input with value x. 0

• 2n output pairs.
• Addressed output pair has 1

value (1, x ).
2
• All other outputs are 0.
3
output pairs 0-4
and 6-7 are (0, 0)
4

5 output pair 5
has value (1, x)

32
Decoder/demux
101 = 5 x
Decoder/demux
Example: 3-to-8 decoder/demux
• n address inputs.
• 1 data input with value x.
• 2n output pairs.
• Addressed output pair has
value (1, x ).
• All other outputs are 0.

output pairs 0-4


Implementation and 6-7 are (0, 0)
• Add decoder output to demux.
output pair 5
has value (1, x)

Application (next lecture)


• Access and control write of memory word
• [Use addr bits of instruction in IR.]
33
Creating a digital circuit that computes a boolean function: majority

Use the truth table


• Identify rows where the function is 1.
• Use a generalized AND gate for each.
• OR the results together.
110
multiway
Example 1: Majority function xyz OR gate

x y z MAJ MAJ

0 0 0 0
0 0 1 0
term gate
0 1 0 0
0 1 1 1 x'yz

1 0 0 0
1 0 1 1 xy'z

1 1 0 1 xyz'

1 1 1 1 xyz
MAJ MAJ is 1
MAJ = x'yz + xy'z + xyz' + xyz majority circuit example 34
Creating a digital circuit that computes a boolean function: odd parity

Use the truth table


• Identify rows where the function is 1.
• Use a generalized AND gate for each.
• OR the results together.
110
multiway
Example 2: Odd parity function xyz OR gate

x y z ODD ODD

0 0 0 0 term gate
0 0 1 1 x'y'z

0 1 0 1 x'yz'
0 1 1 0
1 0 0 1 xy'z'
1 0 1 0
1 1 0 0
1 1 1 1 xyz
ODD ODD is 0
ODD = x'y'z + x'yz' + xy'z' + xyz example
odd parity circuit 35
Combinational circuit design: Summary

x y z MAJ x y z ODD
Problem: Design a circuit that computes a given boolean function.
0 0 0 0 0 0 0 0
0 0 1 0 0 0 1 1
Ingredients 0 1 0 0 0 1 0 1

• OR gates. 0 1 1 1 0 1 1 0
1 0 0 0 1 0 0 1
• NOT gates. 1 0 1 1 1 0 1 0
• NOR gates. use to make generalized AND gates
1 1 0 1 1 1 0 0

• Wire. 1 1 1 1 1 1 1 1

Method xyz xyz


MAJ ODD
• Step 1: Represent input and output with Boolean variables.
• Step 2: Construct truth table to define the function.
• Step 3: Identify rows where the function is 1.
• Step 4: Use a generalized AND for each and OR the results.

Bottom line (profound idea): Yields a circuit for ANY function.


Caveat: Circuit might be huge (stay tuned).
MAJ ODD
36
Pop quiz on combinational circuit design

Q. Design a circuit to implement XOR(x, y).

37
Pop quiz on combinational circuit design

Q. Design a circuit to implement XOR(x, y).

A. Use the truth table


• Identify rows where the function is 1.
• Use a generalized AND gate for each.
• OR the results together.

XOR function circuit interface


x y XOR xy

0 0 0 term gate

0 1 1 x'y

1 0 1
xy'
1 1 0
XOR
XOR = x'y + xy' XOR
38
Encapsulation

Encapsulation in hardware design mirrors familiar principles in software design


• Building a circuit from wires and switches is the implementation.
• Define a circuit by its inputs, controls, and outputs is the API.
• We control complexity by encapsulating circuits as we do with ADTs.

NOT

DECODER/DEMUX
DEMULTIPLEXER
DECODER

AND

ODD

MAJ
OR
XOR 39
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E

Image sources

http://en.wikipedia.org/wiki/Claude_Shannon#/media/File:Claude_Elwood_Shannon_(1916-2001).jpg

CS.19.C.Circuits.Digital
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
PA R T I I : A L G O R I T H M S , M A C H I N E S , a n d T H E O R Y

19. Combinational Circuits


• Building blocks
• Boolean algebra
• Digital circuits
• Adder circuit
• Arithmetic/logic unit

CS.19.D.Circuits.Adder
Let's make an adder circuit!

Adder
• Compute z = x + y for
n-bit binary integers.
• 2n inputs. 0 0 0 1 0 1 1 23
• n outputs. 0 0 1 1 0 0 0 + 49

• Ignore overflow. ADD

Example: 8-bit adder

carry

out

0 0 1 1 0 1 1 1 0
0 0 0 1 0 1 1 1
+ 0 0 1 1 0 0 0 1
0 1 0 0 1 0 0 0

0 1 0 0 1 0 0 = 72
42
Let's make an adder circuit!

Adder
• Compute z = x + y for
n-bit binary integers.
• 2n inputs. x7 y7 x6 y6 x5 y5 x4 y4 x3 y3 x2 y2 x1 y1 x0 y0
• n outputs.
• Ignore overflow. ADD

Example: 8-bit adder

carry

out

c8 c7 c6 c5 c4 c3 c2 c1 0
x7 x6 x5 x4 x3 x2 x1 x0
+ y7 y6 y5 y4 y3 y2 y1 y0
z7 z6 z5 z4 z3 z2 z1 z0

z7 z6 z5 z4 z3 z2 z1 z0
43
Let's make an adder circuit!

Goal: z = x + y for 8-bit integers. c8 c7 c6 c5 c4 c3 c2 c1 0


x7 x6 x5 x4 x3 x2 x1 x0
Strawman solution: Build truth tables for each output bit. + y7 y6 y5 y4 y3 y2 y1 y0
z7 z6 z5 z4 z3 z2 z1 z0

x7 x6 x5 x4 x3 x2 x1 x0 y7 y6 y5 y4 y3 y2 y1 y0 c4 z7 z6 z5 z4 z3 z2 z1 z0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1
0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 0 0 0 1 0 0 0 1 0
8-bit adder
truth table 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 1 0 0 0 1 1 0 0 1 1 216 = 65536 rows!
... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ... ...

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

Q. Not convinced this a bad idea?

A. 128-bit adder: 2256 rows >> # electrons in universe!


44
Let's make an adder circuit!

Goal: z = x + y for 8-bit integers. c8 c7 c6 c5 c4 c3 c2 c1 0


x7 x6 x5 x4 x3 x2 x1 x0
Do one bit at a time. A surprise! + y7 y6 y5 y4 y3 y2 y1 y0
• Build truth table for carry bit. • Carry bit is MAJ. z7 z6 z5 z4 z3 z2 z1 z0
• Build truth table for sum bit. • Sum bit is ODD.

xi yi ci c i+1 MAJ xi yi ci zi ODD


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

0 1 0 0 0 0 1 0 1 1

carry bit 0 1 1 1 1 sum bit 0 1 1 0 0

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

1 1 0 1 1 1 1 0 0 0

1 1 1 1 1 1 1 1 1 1

45
Let's make an adder circuit!

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

x7 y7 x6 y6 x5 y5 x4 y4 x3 y3 x2 y2 x1 y1 x0 y0
c7 c6 c5 c4 c3 c2 c1 c0

Do one bit at a time.


• Carry bit is MAJ.
• Sum bit is ODD.
• Chain 1-bit adders
to "ripple" carries.

c8 c7 c6 c5 c4 c3 c2 c1 0
x7 x6 x5 x4 x3 x2 x1 x0
+ y7 y6 y5 y4 y3 y2 y1 y0
z7 z6 z5 z4 z3 z2 z1 z0

z7 z6 z5 z4 z3 z2 z1 z0
46
An 8-bit adder circuit

47
Layers of abstraction
MAJ ODD

Lessons for software design apply to hardware


• Interface describes behavior of circuit.
• Implementation gives details of how to build it. NOT OR AND
• Exploit understanding of behavior at each level.

Layers of abstraction apply with a vengeance


ADD
• On/off.
• Controlled switch. [relay, pass transistor]
• Gates. [NOT, OR, AND]
• Boolean functions. [MAJ, ODD]
• Adder.
• Arithmetic/Logic unit (next).
• CPU (next lecture, stay tuned).

Vastly simplifies design of complex systems and enables use of new technology at any layer
48
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E

CS.19.D.Circuits.Adder
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
PA R T I I : A L G O R I T H M S , M A C H I N E S , a n d T H E O R Y

19. Combinational Circuits


• Building blocks
• Boolean algebra
• Digital circuits
• Adder circuit
• Arithmetic/logic unit

CS.19.E.Circuits.ALU
Next layer of abstraction: modules, busses, and control lines

Basic design of our circuits


• Organized as modules (functional units of TOY: ALU, memory, register, PC, and IR).
• Connected by busses (groups of wires that propagate information between modules).
• Controlled by control lines (single wires that control circuit behavior).

Conventions input
• Bus inputs are at the top,
 busses

input connections are at the left.


• Bus outputs are at the bottom,

control
output connections are at the right. lines

• Control lines are blue.


output
bus
These conventions make circuits easy to understand.
(Like style conventions in coding.)

51
Arithmetic and logic unit (ALU) module

Ex. Three functions on 8-bit words input


busses
• Two input busses (arguments).
ALU (8-bit)
• One output bus (result).
• Three control lines.

ADD

control
lines XOR

AND

output
bus
52
Arithmetic and logic unit (ALU) module

Ex. Three functions on 8-bit words input


busses
• Two input busses (arguments).
• One output bus (result).
• Three control lines.
• Left-right shifter circuits omitted
(see book for details).

Implementation
• One circuit for each function.
• Compute all values in parallel. ADD

Q. How do we select desired output? control


lines
XOR

A. "One-hot muxes" (see next slide).


AND


output
"Calculator" at the heart of your computer. bus
53
A simple and useful combinational circuit: one-hot multiplexer

One-hot multiplexer selection


• m selection lines inputs 0
all other
• m data inputs 0 select data inputs
input 3 ignored
• 1 output. this is a precondition
1

• At most one selection line is 1. unlike other circuits


we consider
1 data
input 3
• Output has value of selected input. 2
is 0

2
output
3 is 0

data
 4
inputs

data
input 3
is 1

output
output
is 1
54
A simple and useful combinational circuit: one-hot multiplexer
multiway
OR gate
One-hot multiplexer
• m selection lines 0

• m data inputs AND gate


0 select
input 3
• 1 output. 1

• At most one selection line is 1. 1 data


input 3
• Output has value of selected input. 2
is 0

2
output
Implementation 3 is 0

• AND corresponding selection and data inputs. 3

• OR all results (at most one is 1). 4

4
Applications
• Arithmetic-logic unit (previous slide). data
• Main memory (next lecture). input 3
is 1

Important to note. No direct connection from input to output. a virtual selection switch output
is 1
55
Summary: Useful combinational circuit modules

ALU

DECODER/DEMUX
DEMUX

Next: Registers, memory, connections, and control.


56
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E

CS.19.D.Circuits.Adder
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
PA R T I I : A L G O R I T H M S , M A C H I N E S , a n d T H E O R Y
Computer Science

19. Combinational
Computer Circuits
ScienceAn Interdisciplinary Approach

ROBERT SEDGEWICK
K E V I N WAY N E
Section 6.1−2
http://introcs.cs.princeton.edu

You might also like