Professional Documents
Culture Documents
1
Pressure Inverter Pressure Inverter (Low to High)
High High
P-Valve P-Valve
N-Valve N-Valve
Low Low
High High
P-Valve P-Valve
High Low
N-Valve N-Valve
Low Low
2
Analogy Explained Transistors as Switches
Pressure differential → electrical potential (voltage)
• Air molecules → electrons Two types N-Valve N-MOSFET
• High pressure → high voltage • N-type
• Low pressure → low voltage • P-type
Valve → transistor
• The transistor: one of the century’s most important inventions
CSE 240 3-9 CSE 240 3-10
3
P-type MOS Transistor Inverter (NOT Gate)
P-type is complementary to n-type Power
• When Gate has positive voltage,
open circuit between #1 and #2
(switch open)
• When Gate has zero voltage,
short circuit between #1 and #2
(switch closed)
Terminal #1 connected 0 1
to POWER Gate = 0
1 0
(in this example, +2.9V)
For all inputs, make sure that output is either connected to GROUND 0 0 1
or to POWER, but not both! (why?) 0 1 1
1 0 1
Ground
1 1 0
CSE 240 3-15 CSE 240 Note: Parallel structure on top, serial on bottom. 3-16
4
AND Gate NOR Gate (NOT-OR)
A B C
Power Power
0 0 0
0 1 0
1 0 0
1 1 1
A B C
0 0 1
0 1 0
Add inverter to NAND. 1 0 0
Ground Ground
1 1 0
CSE 240 3-17 CSE 240 Note: Serial structure on top, parallel on bottom. 3-18
5
More than 2 Inputs? Visual Shorthand for Multi-bit Gates
AND/OR can take any number of inputs Use a cross-hatch mark to group wires
• AND = 1 if all inputs are 1 • Example: calculate the AND of a pair of 4-bit numbers
• OR = 1 if any input is 1 • A3 is “high-order” or “most-significant” bit
• Similar for NAND/NOR • If “A” is 1000, then A3 = 1, A2 = 0, A1 = 0, A0 = 0
Implementation
• Multiple two-input gates or single CMOS circuit A0 Out0
B0
A1 4
Out1 A 4
B1 Out
B
A2 Out2 4
B2
A3 Out3
B3
6
Logical Completeness via PLAs DeMorgan's Law
Any truth table as a Programmable Logic Array (PLA) Converting AND to OR (with some help from NOT)
• Traditionally a grid of AND and OR gates
Consider the following gate: To convert AND to OR
• Configurable by removing wires
(or vice versa),
A AND B = A OR B
Single-output custom PLA (as on previous slide): invert inputs and output.
• One AND gate per row with “1” in output in truth table
A AND B = A OR B
• Maximum number of AND gates: 2n for n inputs
• One OR gate
A B A B A AND B A AND B
0 0 1 1 1 0
Multiple-output custom PLA:
• Build multiple single-output PLAs 0 1 1 0 0 1 A AND B = A OR B
• Share AND gates “in common” 1 0 0 1 0 1
• One OR gate per output column in truth table
1 1 0 0 0 1
CSE 240 3-25 CSE 240 Why might this be useful? 3-26
7
AND, OR, NOT Gates: What Good Are They?
Last time:
• Transistors and gates
• Can implement any logical function using gates (using PLAs)
Chapter 3 Today:
• We’ll use gates to create some building blocks of a processor
Digital Logic • One goal: automate binary arithmetic from Chapter 2
• Continuing on our bottom-up journey
Structures Next time:
• Storing bits (memory)
Based on slides © McGraw-Hill • Circuits with “state”
Additional m aterial © 2004/2005 Lewis/Martin
8
Aside: XOR N-bit Incrementer
Chain N 1-bit incrementers together
An Cin Sn Cout CarryIn0
A 1 1
0 0 0 0 S A0 S0
+1
0 1 1 0
CarryOut0
CarryIn1
1 0 1 0
1 1
1 1 0 1 Cout A1 +1 S1
Cin
CarryOut1 …but how do we
4-bit CarryIn2
A Cin correctly handle the
example 1 1
A2 +1 S2 least-significant bit?
XOR
CarryOut2
A CarryIn3
S 1 1
Cin A3 +1 S3
CarryOut3
CSE 240 3-33 CSE 240 3-34
9
One-bit Adder CarryInn N-bit Adder
1 CarryIn
Add two bits and carry-in An 1 CarryIn
produce one-bit sum and carry-out 1 Add Sn 16
Bn
CarryIn0 A 16
CarryOutn A0 + S
S0 16
A B Cin S Cout B0 Add
B
0 0 0 0 0 CarryOut0
CarryIn1 CarryOut
0 0 1 1 0 A1
0 1 0 1 0 Add S1
B1
0 1 1 0 1 CarryOut1 CarryOut: useful for
CarryIn2
1 0 0 1 0
A2
detecting overflow
1 0 1 0 1 S2
B2 Add
1 1 0 0 1
CarryOut2 CarryIn: assumed to
1 1 1 1 1
be zero if not present
...
CSE 240 3-37 CSE 240 3-38
10
…But First, The Multiplexer (MUX) The Multiplexer (MUX)
Selector/Chooser of signals In general
• Multi-way switch • N select bits chooses from 2N inputs
2-to-1 Mux 4-to-1 Mux • An incredibly useful building block
0 1 00 01 10 11
2 2 2 2 Multi-bit muxes
• Can switch an entire “bus” or group of signals
• Switch n-bits with n muxes with the same select bits
S
16 2
S 16
16
A 16
O
16
B
16
CSE 240 3-43 CSE 240 3-44
11
Ok, So We Can Add and Subtract
12
Storage - NANDs Storage - Cross-Coupled NANDs (R-S Latch)
Option #2: “Digital” alternative for changing state Write either a zero or one
Write: change Q to one Maintains state • When S=1 and R=1, “quiescent” state; maintains value
1 1
1 even after S = 1 S S
1Q 0Q
0 1
S S S 0 1
1 0Q 0 1Q 0 1Q
1 1
R R
Write: change Q to zero • When S=0 and R=1, state changes to one (“set”)
• When S=1 and R=0, state changes to zero (“reset” or “clear”)
0 1Q 1 0Q 1 0Q 0 1
S S
0 1Q 1 0Q
1 0 1
R R R
Maintains state 1 0
even after R = 1 3-49 R R
CSE 240 CSE 240 3-50
13
Register Aside: More on Representing Multi-bit Values
A register stores a multi-bit value Number bits from right (0) to left (n-1)
• A collection of D-latches, controlled by a common WE • Just a convention -- could be left to right, but must be consistent
• When WE=1, n-bit value D is written to register Use brackets to denote range:
WE D[l:r] denotes bit l to bit r, from left to right
15 12 8 4 0
Q0
D0 A = 0101 0011 0101 0101
WE
3 3
Q1 D D Q A[14:9] = 101001 A[2:0] = 101
D1
16
3
May also see A<14:9> [2:0]
Q1 • Especially in hardware block diagrams. 6
D2 [14:9]
CSE 240 3-53 CSE 240 3-54
“1”
“0”
How quickly will this count? One time→
14
Let’s Try Again: a Counter Example of Incorrect Operation
Clock Initial state: 0102
3 3 3 WE 1
Cnt +1 0
1 D 0 A0 S
+1 1 0
latch
Remaining problem 0
0 D 0 A2 0 S2
• When clock=1, same problem +1
latch
• D-latches are still transparent
0 0
1 D 1 A1 S 1 D 1 A1 S
+1 1 1 +1 1 1
latch latch
0 0
0 D 0 A2 S 0 D 0 A2 S
+1 0 2 +1 0 2
latch latch
15
Example of Incorrect Operation Example of Incorrect Operation
Incrementer calculates 1st bit Incrementer calculates 2nd bit, 1st bit latched
WE 1 WE 1
1 1
0 D 1 A0 S 0 D 0 A0 S
+1 0 0 +1 0 0
latch latch
1 1
1 D 1 A1 1 S1 0 D 1 A1 0 S1
+1 +1
latch latch
0 1
0 D 0 A2 0 S2 0 D 0 A2 0 S2
+1 +1
latch latch
0 0
0 D 0 A1 S 0 D 0 A1 S
+1 0 1 +1 0 1
latch latch
1 1
1 D 0 A2 S 1 D 1 A2 S
+1 1 2 +1 1 2
latch latch
16
Correct Operation Correct Operation
Additional D-latches, WE is NOT(Clock) and Clock Clock switches to 1, 2nd latch WE = 1
Initial state: 0102
Clock 1 Clock 1
0 1
1 D 1 Q0 D 0 A0 1 S0 1 D 1 Q0 D 0 A0 1 S0
+1 +1
latch latch latch latch
0 0
1 D 1 Q1 D 1 A1 1 S1 1 D 1 Q1 D 1 A1 1 S1
+1 +1
latch latch latch latch
0 0
0 D 0 Q2 D 0 A2 S 0 D 0 Q2 D 0 A2 S
+1 0 2 +1 0 2
latch latch latch latch
0 1
1 D 1 Q1 D 1 A1 S 1 D 1 Q1 D 1 A1 S
+1 1 1 +1 1 1
latch latch latch latch
0 0
0 D 0 Q2 D 0 A2 S 0 D 0 Q2 D 0 A2 S
+1 0 2 +1 0 2
latch latch latch latch
17
Correct Operation Correct Operation
Incrementer calculates 2nd bit, Incrementer calculates 3rd bit,
First bit not written to latch 1st, 2nd bits not written to latch
Clock 1 Clock 1
1 1
0 D 1 Q0 D 1 A0 0 S0 0 D 1 Q0 D 1 A0 0 S0
+1 +1
latch latch latch latch
1 1
0 D 1 Q1 D 1 A1 0 S1 0 D 1 Q1 D 1 A1 0 S1
+1 +1
latch latch latch latch
1 1
0 D 0 Q2 D 0 A2 S 1 D 0 Q2 D 0 A2 S
+1 0 2 +1 1 2
latch latch latch latch
Clock 1 Clock 1
1 0
0 D 1 Q0 D 1 A0 S 0 D 1 Q0 D 1 A0 S
+1 0 0 +1 0 0
latch latch latch latch
1 1
0 D 1 Q1 D 1 A1 S 0 D 1 Q1 D 1 A1 S
+1 0 1 +1 0 1
latch latch latch latch
1 1
1 D 0 Q2 D 0 A2 S 1 D 0 Q2 D 0 A2 S
+1 1 2 +1 1 2
latch latch latch latch
18
Correct Operation Correct Operation
2nd set of latches write correct value, circuit quiescent Clock changes back to 1, next increment begins
Clock 1 Clock 1
0 1
0 D 0 Q0 D 1 A0 0 S0 0 D 0 Q0 D 0 A0 0 S0
+1 +1
latch latch latch latch
1 1
0 D 0 Q1 D 1 A1 0 S1 0 D 0 Q1 D 0 A1 0 S1
+1 +1
latch latch latch latch
1 1
1 D 1 Q2 D 0 A2 S 1 D 1 Q2 D 1 A2 S
+1 1 2 +1 1 2
latch latch latch latch
D Q 0 1
WE 0 1
Clock
x
WE
Clock When WE = 0
• Latch 1: writing disabled (output is stable Q inter)
Two phases:
• Latch 2: writing enabled (Q = Q inter)
• Clock = 1, Clock = 0
19
D Flip-Flop - Phase 1 Latch #2 D Flip-Flop - Phase 2 Latch #2
Latch #1 Latch #1
Qinter Q Qinter Q
D D
0 1 1 0
WE 1 1 WE 1 0
Clock Clock
1
Phase 2 0
Phase 1 • Clock = 0
• Clock = 1 • Latch 1: writing enabled (Qinter = D)
• Latch 1: writing disabled (output is stable Q inter) • Latch 2: writing disabled (output is stable Q)
• Latch 2: writing enabled (Q = Q inter) Back to Phase 1
• Q becomes Q inter
Addressability:
Use WE input for conditional counter (stop watch) number of bits per location m bits
(e.g., byte-addressable)
20
Memory Interface 22 by 3-bit memory
n Read operation 2
A A
m
Din
WE
3 3 3 3
D0 D0
Decoder Memory
3 3 3 3
(2n by m-bit)
D1 m
D1 3
Dout Dout
22 or 4 registers
3 3 3 3
D2 D2
3 3 3 3
D3 D3
CSE 240 3-81 CSE 240 3-82
3 3
D0
Decoder
3 3
3
D1 Dout 2-bit
3 3
decoder
D2
3 3
D3
CSE 240 3-83 CSE 240 3-84
21
22 by 3-bit memory - Multiple “Ports” 22 by 3-bit memory - Multiple Read Ports
Independent Read/Write AR1
2 2
AR AR2
3 3
DW DW
WE WE
AW AW
2 3 3 3 3
D0 D0
Decoder
Decoder
3 3 3 3 3
3 DR1
D1 DR D1 3
DR2
3 3 3 3
D2 D2
3 3 3 3
D3 D3
CSE 240 3-85 CSE 240 3-86
22
State Machine Combinational vs. Sequential
Another type of sequential circuit Two types of “combination” locks
• Combines combinational logic with storage
• “Remembers” state, and changes output (and state)
based on inputs and current state
30
25 5
State Machine 4 1 8 4 20 10
15
23
Sequential Lock State Diagram Finite State Machine
Shows states and actions that cause a transition A description of a system with the following
between states components:
State Machine
Examples
Inputs Outputs • Sequential lock
Combinational
Logic Circuit Four states – two bits
• Basketball scoreboard
8 bits for each score, 5 bits for minutes, 6 bits for seconds,
Storage
Elements
1 bit for possession arrow, 1 bit for half, …
Clock
24
Complete Example Traffic Sign State Diagram
A blinking traffic sign
• No lights on
• 1 & 2 on
3
• 1, 2, 3, & 4 on 4
1
• 1, 2, 3, 4, & 5 on 5
2
Switch on
• (repeat as long as switch
is turned on) Switch off
DANGER
MOVE
RIGHT State bit S1
State bit S0
Outputs
Traffic Sign State Diagram: State 00 Traffic Sign State Diagram: State 01
25
Traffic Sign State Diagram: State 10 Traffic Sign State Diagram: State 11
Lights 3 and 4 In S1 S 0 S 1’ S 0’
Light 5
0 X X 0 0
S1 S0 Z Y X Don’t care 1 0 0 0 1
(1 or 0)
0 0 0 0 0 1 0 1 1 0
0 1 1 0 0 1 1 0 1 1
1 0 1 1 0 1 1 1 0 0
1 1 1 1 1
Whenever In=0, next state is 00.
26
Traffic Sign Logic Programmable State Machines
What if we want to change the pattern of the sign?
• An alternative state machine implementation
In/S1 /S0 S
• Use a memory indexed by state number
000 00
001 00
1 23 by 2-bit 010 00
Input [2] 3 2
011 00
S1’ 2
[1:0] 100 01
2 3 101 10
Output
(Z, Y, X) 110 11
S0’
22 by 3-bit 111 00
S1 S X/Y/Z
Master-slave 00 000
flip-flop
2 01 100
State
S0 10 110
11 111
CSE 240 3-105 CSE 240 3-106
10 111
11 --
CSE 240 3-107 CSE 240 3-108
27
LC-3 Data Path Looking Forward…
We’ve touched upon basic digital logic
Combinational • Transistors
Logic • Gates
• Storage (latches, flip-flops, memory)
• State machines
Storage
Build some simple circuits
• Incrementer, adder, subtracter, adder/subtracter
• Counter (consisting of register and incrementer)
• Hard-coded traffic sign state machine
• Programmable traffic sign state machine
State Machine
Next Time
Topic
• The von Neumann Model
Readings
• Chapter 4.0 - 4.2
Online quiz
• You know the drill!
28