Title: Control Unit: Hard-Wired and Microcoded Chapter 5
1Control Unit Hard-Wiredand MicrocodedChapter 5
- Vishwani D. Agrawal
- James J. Danaher Professor
- Department of Electrical and Computer Engineering
- Auburn University
- http//www.eng.auburn.edu/vagrawal
- vagrawal_at_eng.auburn.edu
2Alternatives for Control Unit (CU)
- Hard-wired or hardware
- Random logic, programmable logic array (PLA), or
ROM - Fast
- Inflexible
- Firmware
- Microprogrammed or microcoded CU
- Control implemented like a computer
(microcomputer) - Microinstructions
- Microprogramming
- Flexible
- Changes to instruction set possible
- Completely different instruction sets can be
emulated - Speed limited by microcomputer memory
3Hardwired CU Single-Cycle
- Implemented by combinational logic.
Control logic
Datapath
6
funct. code
Control signals
To ALU
6
opcode
3
ALU control
2
ALUOp
4Jump
0-25
Shift left 2
0 mux 1
4
Add
1 mux 0
ALU
Branch
opcode
MemtoReg
CONTROL
26-31
ALUSrc
RegWrite
21-25
MemWrite MemRead
zero
ALU
Instr. mem.
PC
Reg. File
Data mem.
1 mux 0
16-20
0 mux 1
1 mux 0
11-15
Single-cycle Datapath
RegDst
ALU Cont.
ALUOp
Sign ext.
Shift left 2
0-15
0-5
5Single-Cycle Control Logic
Op5 Op4 Op3 Op2 Op1 Op0
Inputs Inputs Inputs Inputs Inputs Inputs Inputs Outputs Outputs Outputs Outputs Outputs Outputs Outputs Outputs Outputs Outputs
Instr. type
R 0 0 0 0 0 0 1 0 0 1 0 0 0 1 0 0
lw 1 0 0 0 1 1 0 1 1 1 1 0 0 0 0 0
sw 1 0 1 0 1 1 X 1 X 0 0 1 0 0 0 0
beq 0 0 0 1 0 0 X 0 X 0 0 0 1 0 1 0
J 0 0 0 0 1 0 X X X X X X X X X 1
ALUOp1
MemtoReg
ALUOp0
MemRead
MemWrite
RegWrite
RegDst
Branch
Jump
ALUSrc
6Single-Cycle Control Circuit
Op5 Op4 Op3 Op2 Op1 Op0
lw
sw
beq
J
R
RegDst ALUSrc MemtoReg RegWrite MemRead MemWr
ite Branch ALUOp1 ALUOp0 Jump
7ALU Control Logic
Inputs Inputs Inputs Inputs Inputs Inputs Inputs Inputs Outputs to ALU Outputs to ALU
From CU From CU Funct. Code from IR (bits 0-5) Funct. Code from IR (bits 0-5) Funct. Code from IR (bits 0-5) Funct. Code from IR (bits 0-5) Funct. Code from IR (bits 0-5) Funct. Code from IR (bits 0-5) 3-bit code Opera-tion
ALUOp1 ALUOp0 F5 F4 F3 F2 F1 F0 3-bit code Opera-tion
0 0 X X X X X X 010 Add
X 1 X X X X X X 110 Subtract
1 X X X 0 0 0 0 010 Add
1 X X X 0 0 1 0 110 Subtract
1 X X X 0 1 0 0 000 AND
1 X X X 0 1 0 1 001 OR
1 X X X 1 0 1 0 111 slt
8ALU Control
Operation select from control
From Control Circuit
ALUOp1 ALUOp0
3
zero
ALU
result
F3 F2 F1 F0
overflow
Operation select ALU function 000 AND
001 OR 010 Add 110 Subtract 111 Set on
less than
9Hardwired Control Unit Multicycle
Start
State 0
1
lw or sw
J
R
B
2
3
lw
6
8
9
sw
4
5
7
10States and Outputs
- 10 states are encoded 0000 through 1001.
- State code completely determines what 16 control
signals are. - Next state ? present state 1, with two
exceptions - State 1 (0001) opcode must decide next state
- State 2 (0010) for lw or sw
- State 6 (0110) for R-type of instruction
- State 8 (1000) for branch instruction
- State 9 (1001) for jump instruction
- State 2 (0010) opcode must decide next state
- State 3 (0011) for lw
- State 5 (0101) for sw
11A ROM Implementation
Control ROM Sixteen 18-bit words 4-bit address
16
Control signals to datapath
2
0001
AddrCtl go to 00 st. 0 11 Next
st. 01 st. 2,6,8,9 10 st. 3,5
Addr.
4-bit state flip-flops
4
4
MUX 11 10 01 00
Adder
Adv. state
0000
Dispatch ROM 2
Dispatch ROM 1
Opcode from IR
6
12Dispatch ROM Contents
Each dispatch ROM has sixty-four 4-bit
words Address is 6-bit opcode Content is next
state (4-bits)
Dispatch ROM 1 Dispatch ROM 1 Dispatch ROM 1
Opcode Address Content
lw 100011 0010
sw 101011 0010
R 000000 0110
B 000100 1000
J 000010 1001
Dispatch ROM 2 Dispatch ROM 2 Dispatch ROM 2
Opcode Address Content
lw 100011 0011
sw 101011 0101
13Control ROM Contents
Addr. bits 17-2 bits 1-0
0000 1001010000001000 11
0001 0000000000011000 01
0010 0000000000010100 10
0011 0011000000000000 11
0100 0000001000000010 00
0101 0010100000000000 00
0110 0000000001000100 11
0111 0000000000000011 00
1000 0100000010100100 00
1001 1000000100000000 00
- Control ROM has sixteen 18-bit words
- bits 0-1, AddrCtl to control mux
- bits 2-17, sixteen control signals for datapath
- Address is 4-bit state.
14Microprogram Basic Idea
- The control unit in a computer generates an
output (sequence of control signals) for each
opcode - Implement the control unit as a computer, within
a computer, that executes a program for each
opcode. - M. V. Wilkes, The Best Way to Design an
Automatic Calculating Machine, Report of
Manchester University Computer Inaugural
Conference, pp. 16-18, 1951. - Reprinted in E. E. Swartzlander (editor),
Computer Design Development Principal Papers,
pp. 266-270, Rochelle Park, NJ Hayden, 1976.
15Maurice V. Wilkes
Born June 26, 1913, Staffordshire, UK
1967 Turing Award citation Professor Wilkes Is
best known as the builder and designer of the
EDSAC, the first computer with an internally
stored program. Built in 1949, the EDSAC used a
mercury delay line memory. He is also known as
the author, with Wheeler and Gill, of a volume on
Preparation of Programs for Electronic Digital
Computers in 1951, in which program libraries
were effectively introduced.
16Microcoded CU
Microcode word
Sixteen 18-bit words 4-bit address
16
Control signals to datapath
Microcode memory
0001
AddrCtl
Addr.
Sequencing field
2
4-bit state flip-flops
4
4
µPC
MUX 11 10 01 00
Adder
0000
Dispatch ROM 2
Dispatch ROM 1
Opcode from IR
Address select logic
lw or sw
sw, lw, R, B or J
6
17Microprogramming
- A microinstruction set is defined.
- To program the control of a computer for an
instruction set, a programmer writes a
microprogram for each machine instruction. - Each micrprogram is converted into microcode,
specific to the datapath hardware, by a
microassembler and the microcodes are loaded in
the microcode memory of the CU.
18Microinstruction Format
- Label or name
- Seven fields
- ALU control add, subtract or funct. code
result to ALUOut - SRC1 PC or A
- SRC2 B, 4, extend or extend-shift
- Reg. control Read read two reg. specified by
IR into A B - Write ALU write ALUOut to register file
- Write MDR MDR ? register file
- Memory Read PC read memory using PC address
- Read ALU MDR ? MALUOut
- Write ALU MALUOut ? B
- PCWrite ALU write PC from ALU
- ALU cond. If zero1, PC ? ALUOut
- Jump addr. PC ? jump address
- Sequencing Seq choose next µInst.
Sequentially - fetch go to first µInst. to begin new
instruction - Dispatch i use Dispatch ROM i, i 1 or 2
19Sequencing
Start
State 0
1
Sequencing seq
Dispatch 1
lw or sw
J
R
B
2
3
lw
6
Dispatch 2
8
seq
9
sw
seq
Fetch
Fetch
4
5
7
Fetch
Fetch
Fetch
20Microinstruction Fetch
Label ALU SRC1 SRC2 Reg. Mem. PCWrite Seq. ctr
l. ctrl. ctrl. Fetch Add PC 4 Read
PC ALU Seq Microassembler produces the
following microcode 00 0 01 0 0 0 1 0 1
0 00 1 0 11
MemRead IorD IRWrite MemWrite
RegWrite RegDst MemtoReg
ALUOp
PCSource PCWrite PCWriteCond
Addrctl
ALUSrcA
ALUSrcB
21Microinstruction Decode
Label ALU SRC1 SRC2 Reg. Mem. PCWrite Seq. ctr
l ctrl ctrl Decode Add PC ExtShft Read
Dispatch 1 Microassembler produces the
following microcode 00 0 11 0 0 0 0 0 0
0 00 0 0 01
MemRead IorD IRWrite MemWrite
RegWrite RegDst MemtoReg
ALUOp
ALUSrcB
PCSource PCWrite PCWriteCond
ALUSrcA
AddrCtl
22µInstruction and µCode
Field µInstr. value µCode value Action
ALU Ctrl Add ALUOp 00 ALU adds
ALU Ctrl Subt ALUOp 01 ALU subtracts for beq
ALU Ctrl Funct code ALUOp 10 ALU executes R-type instruction
SRC1 PC ALUSrcA 0 PC is first ALU input
SRC1 A ALUSrcA 1 Reg A is first ALU input
SRC2 B ALUSrcB 00 Reg B is second ALU input
SRC2 4 ALUSrcB 01 Constant 4 is second ALU input
SRC2 Extend ALUSrcB 10 Sign extension unit is sec. ALU input
SRC2 Extshft ALUSrcB 11 2-bit shift unit is second ALU input
23µInstruction and µCode (Cont.)
Field µInstr. value µCode value Action
Reg Ctrl Read Register file loads A and B
Reg Ctrl Write ALU RegWrite 1 RegDst 1 MemtoReg 0 An IR-specified register in Register file is written from ALUOut
Reg Ctrl Write MDR RegWrite 1 RegDst 0 MemtoReg 1 An IR-specified register in Register file is written from MDR
Memory Read PC MemRead 1 IorD 0 IRWrite 1 IR ? MPC MDR ? MPC
Memory Read ALU MemRead 1 IorD 1 MDR ? MALUOut
Memory Write ALU MemWrite 1 IorD 1 MALUOut ? B
24µInstruction and µCode (Cont.)
Field µInstr. value µCode value Action
PC Write Ctrl ALU PCSource 00 PCWrite 1 Register file loads A and B
PC Write Ctrl ALUOut-cond PCSource 01 PCWriteCond 1 An IR-specified register in Register file is written from ALUOut
PC Write Ctrl Jump address PCSource 10 PCWrite 1 An IR-specified register in Register file is written from MDR
Sequencing Seq AddrCtl 11 Choose next µInstr. sequentially
Sequencing Fetch AddrCtl 00 Go to first µInstr. to begin new instruction
Sequencing Dispatch 1 AddrCtl 01 Use Dispatch ROM 1
Sequencing Dispatch 2 AddrCtl 10 Use Dispatch ROM 2
25Microprogram for Fetch
Label ALU SRC1 SRC2 Reg. Mem. PCWrite Seq. ctr
l. ctrl. ctrl. Fetch Add PC 4 Read
PC ALU Seq Decode Add PC ExtShft Read
Dispatch 1 Microassembler produces the
following microcode 00 0 01 0 0 0 1 0 1
0 00 1 0 11 00 0 11 0 0 0 0 0 0 0 00 0
0 01
MemRead IorD IRWrite MemWrite
RegWrite RegDst MemtoReg
PCSource PCWrite PCWriteCond
ALUOp
Addrctl
ALUSrcA
ALUSrcB
26Microprogram for lw and sw
Label ALU SRC1 SRC2 Reg. Mem. PCWrite Seq. ct
rl. ctrl. ctrl. Mem1 Add A Extend
Dispatch 2 LW2 Read ALU Seq
Write MDR Fetch SW2 Write
ALU Fetch Microprogram consists of four
microinstructions.
27Microprogram for R-Type Instruction
Label ALU SRC1 SRC2 Reg. Mem. PCWrite Seq. ctrl.
ctrl. ctrl. Rformat1 Funct code A B
Seq Write ALU Fetch Go to next
µInstr. Go to µInstr. Fetch Microprogram
consists of two microinstructions.
28Microprogram for beq Instruction
Label ALU SRC1 SRC2 Reg. Mem. PCWrite Seq. ctrl.
ctrl. ctrl. BEQ1 Subt A B
ALUOut-cond Fetch If (zero) then PC ?
ALUOut Go to µInstr. Fetch Microprogram
consists of one microinstruction.
29Microprogram for jump Instruction
Label ALU SRC1 SRC2 Reg. Mem. PCWrite Seq. ctrl.
ctrl. ctrl. JUMP1 Jump
address Fetch Microprogram consists of one
microinstruction.
30Summary
- Hard-wired control A finite state machine
implemented typically using programmable logic
array (PLA) or random logic. - Microinstruction A one-clock instruction that
asserts a set of control signals to the datapath
and specifies what microinstruction to execute
next. - Microprogram A sequence of microinstructions
that implements a multicycle (or single cycle)
instruction. - Microcode Machine code of a microprogram,
generally produced by a microassembler. - Microprogrammed or microcoded control A method
of specifying control that uses microcode rather
than a finite state machine.