12 Digital Devices
12 Digital Devices
S E D G E W I C K / W A Y N E
SEDGEWICK
ntist WAYNE
Computer Science
ary
A N I N T E R D I S C I P L I N A RY A P P R O A C H
or
d
gs,
of
omputer
C cience 12 Digital Devices
hem
h.
S
nce
d
wick
ysis
orics;
ver
An Interdisciplinary Approach
ROBERT SEDGEWICK
ANADA
K E V I N WAY N E
Sections 7.5
http://introcs.cs.princeton.edu
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
12 Digital Devices
• TOY 8
• Bits, registers, and memory
• Program counter
• Components and connections
A smaller computing machine: TOY-8
opcode addr
0
Add two numbers from memory and
opcode operation pseudo-code A TOY-8 program put sum in memory
0 halt halt
Memory
PC
2 add R = R + M[addr]
1 1 A 5 R = M[5]
4 bitwise and R = R & M[addr]
2 2 2 6 R = R + M[6]
6 bitwise xor R = R ^ M[addr]
M[7] = R
3 3 C 7
8 load addr R = addr 4 halt
4 0 0
A load R = M[addr]
5 0 5
C store M[addr] = R
6 0 8
E branch zero if (R == 0) PC = addr 7 0 D
...
ZERO M[0] is always 0.
TOY-8 CPU
• ALU (adder, AND, XOR)
• Memory ALU
CLOCK
• Register (R)
MEMORY
• PC CONTROL
• IR
• Control PC
• Clock
IR
Goal. Complete CPU circuit for TOY-8 (same design extends to TOY and to your computer).
5
Review: Components, busses, and control lines
Conventions input
• Bus inputs are at the top, busses
Q. Why TOY-8?
TOY
TOY-8
Sobering fact. The circuit for your computer is thousands to millions of times wider.
Reassuring fact. Design of all three is based on the same fundamental ideas.
7
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
12 Digital Devices
• TOY 8
• Bits, registers, and memory
• Program counter
• Components and connections
Memory bit application: Register
Register
• w memory bits.
input
0101 = 5
Memory bank
• 2n words, each w bits. Example: 4-words, each 6 bits
• n-bit address input. input
bus
• w-bit input bus.
• value of selected word WRITE
addr
output
bus
10
Memory bit application: Memory bank
Memory bank
• 2n words, each w bits. Example: 4-words, each 6 bits
• n-bit address input. input
bus
• w-bit input bus.
BIT BIT BIT BIT BIT BIT
• value of selected word WRITE
DECODER/DEMUX
word on WRITE pulse.
to output bus.
Interface
input
• Input bus (for store) bus MEMORY
Connections
• Input bus from registers
• Output bus to IR and R
• Address bits from PC and IR
TOY 256 16 8
12 Digital Devices
• TOY 8
• Bits, registers, and memory
• Program counter
• Components and connections
Designing a digital circuit: overview
14
Pop quiz on combinational circuit design
15
Pop quiz on combinational circuit design
J Q B0
Q. Design a circuit to compute x + 1. C
Count
K
Enable
A. Use a 4-bit synchronous counter
J Q B1
(see Sequential Circuits slides)
C
K
J Q B2
C
K
J Q B3
C
K
Output
Carry
Clock
16
Multiple bus connections
ALU
If component inputs come from multiple other components
• Problem.
?
• Values on the busses are different. MEMORY
R
• Example: ALU, memory, and IR connect to register.
• Solution: Need a selector switch (bus multiplexer).
IR
17
Program counter (PC)
Components
• PC register (4-bit).
input
• Incrementer (add 1). bus
INCREMENT
LOAD
Connections
need 2-way
• Input bus to PC register. bus multiplexer
• Incrementer to PC register.
WRITE
• PC register to incrementer.
• PC register to output bus.
output
18
bus
Program counter (PC)
Components
• PC register (4-bit).
input
• Incrementer (add 1). bus
• 2-way bus mux. increment
INCREMENT
2-way bus mux
load
LOAD
Connections
• Input bus to bus mux.
• Incrementer to bus mux.
write
WRITE
• Bus mux to PC register.
PC register
• PC register to incrementer. output
• PC register to output bus. bus
output
19
bus
Summary of TOY-8 PC circuit
PC PC
incrementer incrementer
input input
bus bus
increment 2-way bus mux increment
2-way bus mux
INCREMENT
increment Next. CPU circuit.
LOAD
load
load load
write
write
WRITE write
WRITE
write
PC register PC register
output output
bus bus
Important note: write pulse must be very short because of the cycle in this circuit. 20
COMPUTER SCIENCE
S E D G E W I C K / W A Y N E
12 Digital Devices
• TOY 8
• Bits, registers, and memory
• Program counter
• Components and connections
TOY-8: Interface
CPU is a circuit inside the machine
RUN
TOY-8 CPU
• ALU (adder, AND, XOR)
• Memory
CLOCK
ALU
• Register (R)
MEMORY
• PC
•
CONTROL
IR
PC
• Control
• Clock
R mux
addr mux
R
IR
Also needed (see next slide): Bus muxes for R and memory addr. "mux" is short for multiplexer
23
Connections for TOY-8 CPU
PC to memory addr
fetch (all)
memory to IR
need 2-way
CLOCK bus mux
ALU halt none
MEMORY
IR addr to memory addr
CONTROL
memory to ALU 1
add, and, xor
R to ALU 0
`
PC
ALU to R
R mux `
`
load address IR addr to R
need 3-way
addr mux bus mux
R IR addr to memory addr
load
IR memory to R
24
Control wires for TOY-8 CPU
R MUX IR
`
R R WRITE
R IR IR WRITE
addr mux
memory MEMORY WRITE
IR
PC INCREMENT
PC
PC LOAD
PC WRITE
ADDR MUX PC
addr mux
ADDR MUX IR
25
One final combinational circuit: Control
FETCH
FETCH WRITE EXECUTE EXECUTE
WRITE
Control. Circuit for control wire sequencing.
opcode
Inputs
HALT
• Four control wires from clock.
ALU ADD
• opcode from IR. ALU XOR
Outputs
• 15 control wires for CPU components.
MEMORY WRITE
R PC INCREMENT
PC LOAD
R MUX ALU
FETCH IR WRITE IR = C7
05
0D R WRITE
PC INCREMENT
EXECUTE
ADDR MUX IR
A5
26
C7
00 EXECUTE MEMORY WRITE M[7] = 0D
WRITE PC WRITE PC = 4
FETCH ADDR MUX PC
FETCH IR WRITE IR = 00
WRITE
PC INCREMENT
And THAT . . . is how your computer works! EXECUTE
HALT
27
TOY-8 CPU
RUN
MEMORY
CLOCK
CLOCK
CONTROL
ALU ADD
CONTROL
HALT PC
ALU XOR
ALU AND PC
PC LOAD
PC INCREMENT
ADDR MUX PC
R WRITE ADDR MUX IR
addr MUX
R
R 2-way
IR WRITE
IR
IR
28
TOY-8 CPU
RUN
MEMORY
CLOCK
ALU FETCH
FETCH WRITE
EXECUTE
EXECUTE WRITE
MEMORY WRITE
CONTROL
ALU ADD
HALT PC
ALU XOR
ALU AND
PC LOAD
PC INCREMENT
R MUX ALU
PC WRITE
R MUX MEM
R MUX IR
ADDR MUX PC
R WRITE ADDR MUX IR
IR WRITE
IR
29
Scanning electron microscope image of a real microprocessor
modern
25 billion
microprocessor
TOY-8 1
30
How does your computer work?
MEMORY
CLOCK
MEMORY WRITE
CONTROL
HALT PC
ALU XOR
PC LOAD
PC INCREMENT
R MUX ALU
PC WRITE
ADDR MUX PC
•
R WRITE ADDR MUX IR
Required Reading
• Course textbook chapter 7.5
Suggested learning activities:
• Take more CS courses!
32