Designing A CPU: Let's Build A Computer!
Designing A CPU: Let's Build A Computer!
Designing A CPU: Let's Build A Computer!
Designing a CPU
CPU: central processing unit computer: CPU + display + optical disk + metal case + power supply + ...
Last lecture: circuit that implements an adder This lecture: circuit that implements a CPU
Introduction to Computer Science Robert Sedgewick and Kevin Wayne Copyright 2008 http://www.cs.Princeton.EDU/IntroCS
TOY Lite
TOY machine. 256 16-bit words of memory.
opcode
Rs
Rd1
Rd2
4 bits to specify one of 16 registers
opcode
Rs
addr
Memory
8 bits to specify one of 256 memory words
opcode
Rs
Rd1
Rd2
2 bits to specify one of 4 registers
Toy-Lite Registers
opcode
Rs
addr
Control Goal: CPU circuit for TOY-Lite (same design extends to TOY, your computer)
3 4
SR Flip-Flop
x y OR x+y x y NOR ( x + y )
Output determined solely by inputs. Ex: majority, adder, decoder, MUX, ALU. Output determined by inputs and current state. Ex: memory, program counter, CPU. Two controlled switches A and B, both connected
to power, each blocked by the other. State determined by whichever switches first.
Sequential circuits.
Two cross-coupled NOR gates A way to control the feedback loop. Abstraction that "remembers" one bit. Basic building block for memory and registers.
OR gate
memory bit
Stable.
Aside. Feedback with an odd number of switches is a buzzer (not stable). Doorbell: buzzer made with relays. Caveat. Timing, switching delay.
Memory Overview
Computers and TOY have several memory components. Program counter and other processor registers.
TOY registers (4 10-bit words in Toy-Lite). Main memory (16 10-bit words in Toy-Lite).
write 0
write 1
memory bit
read
Access mechanism: when are contents available? Processor registers: enable write.
Main memory: select and enable write. TOY register: dual select and enable write
[ TOY PC, IR ]
[ TOY registers ]
[ TOY PC, IR ]
[ TOY registers ]
10
Processor Register
Processor register. Stores k bits.
don't confuse with TOY register
Processor Register
Processor register. Stores k bits.
don't confuse with TOY register
Register contents always available on output bus. If enable write is asserted, k input bits get copied into register.
Register contents always available on output bus. If enable write is asserted, k input bits get copied into register.
Ex 1. TOY-Lite program counter (PC) holds 4-bit address. Ex 2. TOY-Lite instruction register (IR) holds 10-bit current instruction.
Ex 1. TOY program counter (PC) holds 8-bit address. Ex 2. TOY instruction register (IR) holds 16-bit current instruction.
(4-bit)
11
12
Processor Register
Processor register.
don't confuse with TOY register
Memory Bank
Memory bank.
Stores k bits. Register contents always available on output bus. If enable write is asserted, k input bits get copied into register.
Ex 1. TOY program counter (PC) holds 8-bit address. Ex 2. TOY instruction register (IR) holds 16-bit current instruction.
Bank of n registers; each stores k bits. Read and write information to one of n registers. Address inputs specify which one. log n address bits needed Addressed bits always appear on output. If write enabled, k input bits are copied into addressed register.
2
Ex 0 (for lecture). 4-by-6 (four 6-bit words) Ex 1. Main memory bank. TOY: 256-by-16
(4-bit)
TOY-Lite: 16-by-10 TOY: 16-by-16 TOY Lite: 4-by-10 Two output buses.
Ex 2. Registers.
13
14
Memory: Interface
6-bit
2-bit 6-bit
15
16
TOY-Lite Memory
input connected to registers for store output connected to registers for load addr connect to processor Instruction Register (IR)
to registers (out)
to registers (in) to IR
17
18
19
20
Toy-Lite Registers
4 10-bit words
Dual-ported to support connecting two different registers to ALU Input MUX to support input connection to ALU, memory, IR, PC
to ALU (in) MUX select to ALU (out)
! ALU
Memory
Registers
Control
to PC to memory, IR
21 22
"flow" of bits.
Increment: add one to value. Enable Write: make value available on output bus.
23
24
Register. Incrementer. Multiplexer (to provide connections for both load and increment).
25
26
27
28
! ALU
!
1. load: copy input to register 3. increment: output plus 1 available in MUX copy to register
Memory
Toy-Lite Registers
Control
2. enable write: register contents available on output 4. enable write: register contents available on output
29 30
TOY-Lite: Interface
"flow" of bits.
31
32
TOY-Lite: Components
TOY-Lite: Layout
33
34
Execute
Fetch
0 1 halt add subtract and xor shift left shift right load address load store load indirect store indirect branch zero branch positive jump register jump and link
... ...
Fetch.
IR opcode to control control to ALU two registers to ALU ALU to register MUX
Execute
3 4 5 6 7 8 9 A B C D E F
Execute.
...
35
36
Datapath: Add
control wires
fetch:
Memory[PC] to IR
execute:
IR opcode to control
increment
datapaths
increment PC
37
Datapath: Load
Last step
Control. Each instruction corresponds to a sequence of control signals. Q. How do we create the sequence? A. Need a physical clock.
Solution 2: Use a buzzer [need sufficiently long cycle to cover CPU switching]
clock
Solution 1: Use some other technology
fetch:
Memory[PC] to IR
CPU
CPU
execute:
IR opcode to control
increment
increment PC
39
40
Clock
Clock.
Solution 3?
Expressed in hertz. Frequency of 1 Hz means that there is 1 cycle per second. 1 kilohertz (kHz) means 1000 cycles/sec. 1 megahertz (MHz) means 1 million cycles/sec.
1 1
Synchronizes operations of different circuit elements. Requirement: clock cycle longer than max switching time.
gigahertz (GHz) means 1 billion cycles/sec. terahertz (THz) means 1 trillion cycles/sec.
cycle time
on
Clock
off
41
42
Clocking Methodology
Two-cycle design. Each control signal is in one of four epochs.
fetch fetch
execute execute
[set memory address from pc] [write instruction to IR] [set ALU inputs from registers] [write result of ALU to registers]
Fetch
Tick-Tock
CPU is a circuit, driven by a clock. Switches initialize memory, PC contents Clock ticks
Execute
45
46
TOY-Lite CPU
47
48
Layers of Abstraction
Abstraction Abstract Switch Connector Clock Logic Gates Built From raw materials raw materials raw materials abstract switches, connectors logic gates, connectors logic gates, clock, connector decoder, multiplexer, adder, flip-flop components Examples transistor, relay wire crystal oscillator AND, OR, NOT decoder, multiplexer, adder, ALU flip-flop registers, ALU, counter, control TOY
49
History + Future
Computer constructed by layering abstractions.
Better implementation at low levels improves everything. Ongoing search for better abstract switch! 1820s: mechanical switches. 1940s: relays, vacuum tubes. 1950s: transistor, core memory. 1960s: integrated circuit. 1970s: microprocessor. 1980s: VLSI. 1990s: integrated systems. 2000s: web computer. Future: quantum, optical soliton,
History.
Combinational Circuit
Sequential Circuit
Components Computer
Ray Kurzweil
http://en.wikipedia.org/wiki/Image:PPTMooresLawai.jpg
50