Lesson 4. The Processor: Fundamentals of Computers
Lesson 4. The Processor: Fundamentals of Computers
The Processor
FUNDAMENTALS OF COMPUTERS
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 1 / 115
Outline I
1 Introduction
2 Instruction Set
3 MIPS: an example of RISC ISA
4 CPU Design: Datapath and Control
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 2 / 115
Introduction
Outline
1 Introduction
2 Instruction Set
3 MIPS: an example of RISC ISA
4 CPU Design: Datapath and Control
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 3 / 115
Introduction
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 4 / 115
Introduction
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 4 / 115
Introduction
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 5 / 115
Introduction
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 5 / 115
Introduction
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 5 / 115
Introduction
Computer Organization
Hardware level
PROCESSOR (CPU)
PC IR
Instructions
INPUT
REGISTERS
MEMORY
Data
OUTPUT
CONTROL
ALU
UNIT
Computer Operation
Instructions and Data
Instructions
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 7 / 115
Introduction
Computer Operation
Instructions and Data
Instructions
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 7 / 115
Introduction
Instruction cycle
fetch-decode-execute cycle
Basic operation cycle of a computer
⇒ Loop repeated continuously by CPU, from bootup to shutdown
4 basic steps:
1 Fetching the instruction: instruction to be executed is retrieved from
memory.
⇒ 2 registers involved: PC & IR
Instruction is fetched from mem address stored in Program Counter (PC)
and is stored in Instruction Register (IR)
IR ← MEM[PC]
2 Decode the instruction: encoded instruction in IR is interpreted by
the decoder.
3 Execute the instruction: Control Unit sends signals to perform
actions required by the decoded instructions (Registers, ALU, Mem).
4 Next instruction address calculation: PC is updated.
⇒ instructions are executed sequentially, or as otherwise directed by control
flow instructions (jump, branch. . . )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 8 / 115
Introduction
Instruction cycle
fetch-decode-execute cycle
Basic operation cycle of a computer
⇒ Loop repeated continuously by CPU, from bootup to shutdown
4 basic steps:
1 Fetching the instruction: instruction to be executed is retrieved from
memory.
⇒ 2 registers involved: PC & IR
Instruction is fetched from mem address stored in Program Counter (PC)
and is stored in Instruction Register (IR)
IR ← MEM[PC]
2 Decode the instruction: encoded instruction in IR is interpreted by
the decoder.
3 Execute the instruction: Control Unit sends signals to perform
actions required by the decoded instructions (Registers, ALU, Mem).
4 Next instruction address calculation: PC is updated.
⇒ instructions are executed sequentially, or as otherwise directed by control
flow instructions (jump, branch. . . )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 8 / 115
Introduction
Instruction cycle
fetch-decode-execute cycle
Basic operation cycle of a computer
⇒ Loop repeated continuously by CPU, from bootup to shutdown
4 basic steps:
1 Fetching the instruction: instruction to be executed is retrieved from
memory.
⇒ 2 registers involved: PC & IR
Instruction is fetched from mem address stored in Program Counter (PC)
and is stored in Instruction Register (IR)
IR ← MEM[PC]
2 Decode the instruction: encoded instruction in IR is interpreted by
the decoder.
3 Execute the instruction: Control Unit sends signals to perform
actions required by the decoded instructions (Registers, ALU, Mem).
4 Next instruction address calculation: PC is updated.
⇒ instructions are executed sequentially, or as otherwise directed by control
flow instructions (jump, branch. . . )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 8 / 115
Introduction
Instruction cycle
fetch-decode-execute cycle
Basic operation cycle of a computer
⇒ Loop repeated continuously by CPU, from bootup to shutdown
4 basic steps:
1 Fetching the instruction: instruction to be executed is retrieved from
memory.
⇒ 2 registers involved: PC & IR
Instruction is fetched from mem address stored in Program Counter (PC)
and is stored in Instruction Register (IR)
IR ← MEM[PC]
2 Decode the instruction: encoded instruction in IR is interpreted by
the decoder.
3 Execute the instruction: Control Unit sends signals to perform
actions required by the decoded instructions (Registers, ALU, Mem).
4 Next instruction address calculation: PC is updated.
⇒ instructions are executed sequentially, or as otherwise directed by control
flow instructions (jump, branch. . . )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 8 / 115
Introduction
Instruction cycle
fetch-decode-execute cycle
Basic operation cycle of a computer
⇒ Loop repeated continuously by CPU, from bootup to shutdown
4 basic steps:
1 Fetching the instruction: instruction to be executed is retrieved from
memory.
⇒ 2 registers involved: PC & IR
Instruction is fetched from mem address stored in Program Counter (PC)
and is stored in Instruction Register (IR)
IR ← MEM[PC]
2 Decode the instruction: encoded instruction in IR is interpreted by
the decoder.
3 Execute the instruction: Control Unit sends signals to perform
actions required by the decoded instructions (Registers, ALU, Mem).
4 Next instruction address calculation: PC is updated.
⇒ instructions are executed sequentially, or as otherwise directed by control
flow instructions (jump, branch. . . )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 8 / 115
Instruction Set
Outline
1 Introduction
2 Instruction Set
Instruction types and format
ISA design aspects
Execution model
Addressing modes
3 MIPS: an example of RISC ISA
4 CPU Design: Datapath and Control
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 9 / 115
Instruction Set
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 10 / 115
Instruction Set
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 10 / 115
Instruction Set Instruction types and format
Machine instructions
a.k.a. machine code or machine language
Set of instructions executed directly by a CPU
Machine code (i.e., not assembly code) is the lowest-level
programming language
▶ it’s just binary code
▶ it’s completely hardware-dependent
Instruction types:
Data handling and memory operations
▶ Registers ↔ Memory transfers
▶ I/O operations (peripherals)
Arithmetic and logic operations
▶ ALU and related stuff
Control flow operations
▶ Branch/Jump (cond, uncond, indirect)
▶ Subroutine call
System control operations and others
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 11 / 115
Instruction Set Instruction types and format
Machine instructions
a.k.a. machine code or machine language
Set of instructions executed directly by a CPU
Machine code (i.e., not assembly code) is the lowest-level
programming language
▶ it’s just binary code
▶ it’s completely hardware-dependent
Instruction types:
Data handling and memory operations
▶ Registers ↔ Memory transfers
▶ I/O operations (peripherals)
Arithmetic and logic operations
▶ ALU and related stuff
Control flow operations
▶ Branch/Jump (cond, uncond, indirect)
▶ Subroutine call
System control operations and others
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 11 / 115
Instruction Set Instruction types and format
Machine instructions
Instruction format
Parts of an instruction: (common fields)
▶ Operation code (opcode): operation to perform.
▶ Operand specifiers: zero or more.
⋆ registers, memory locations, or literal data
▶ Destination operand specifier: where to store result, if any.
▶ Predicate field: encode the specific condition in Conditional
Instructions.
▶ Next instruction reference: usually implicit: sequential order.
Otherwise, all necessary stuff to compute next instruction address is
provided.
Execution model
How many operands and their internal storage in CPU
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 15 / 115
Instruction Set Execution model
Execution model
How many operands and their internal storage in CPU
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 15 / 115
Instruction Set Execution model
Execution model
Main models
Accumulator 1 explicit operand (reg or mem)
1 implicit operand (acc)
add A acc ← acc + A
Stack 0 explicit operands
All operands implicit (on TOS)
add tos ← tos + next
General Purpose Regs & Memory
all operands explicit either registers or mem. locat.
register–register (load/store arch.)
2 regs: add A B RA ← RA + RB
3 regs: add A B C RA ← RB + RC
register–memory
1 reg, 1 mem: add A B RA ← RA + mem(B)
memory–memory
3 mem: add A B C mem(A) ← mem(B) + mem(C )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 16 / 115
Instruction Set Execution model
Execution model
Main models
Accumulator 1 explicit operand (reg or mem)
1 implicit operand (acc)
add A acc ← acc + A
Stack 0 explicit operands
All operands implicit (on TOS)
add tos ← tos + next
General Purpose Regs & Memory
all operands explicit either registers or mem. locat.
register–register (load/store arch.)
2 regs: add A B RA ← RA + RB
3 regs: add A B C RA ← RB + RC
register–memory
1 reg, 1 mem: add A B RA ← RA + mem(B)
memory–memory
3 mem: add A B C mem(A) ← mem(B) + mem(C )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 16 / 115
Instruction Set Execution model
Execution model
Main models
Accumulator 1 explicit operand (reg or mem)
1 implicit operand (acc)
add A acc ← acc + A
Stack 0 explicit operands
All operands implicit (on TOS)
add tos ← tos + next
General Purpose Regs & Memory
all operands explicit either registers or mem. locat.
register–register (load/store arch.)
2 regs: add A B RA ← RA + RB
3 regs: add A B C RA ← RB + RC
register–memory
1 reg, 1 mem: add A B RA ← RA + mem(B)
memory–memory
3 mem: add A B C mem(A) ← mem(B) + mem(C )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 16 / 115
Instruction Set Execution model
Execution model
Main models
Accumulator 1 explicit operand (reg or mem)
1 implicit operand (acc)
add A acc ← acc + A
Stack 0 explicit operands
All operands implicit (on TOS)
add tos ← tos + next
General Purpose Regs & Memory
all operands explicit either registers or mem. locat.
register–register (load/store arch.)
2 regs: add A B RA ← RA + RB
3 regs: add A B C RA ← RB + RC
register–memory
1 reg, 1 mem: add A B RA ← RA + mem(B)
memory–memory
3 mem: add A B C mem(A) ← mem(B) + mem(C )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 16 / 115
Instruction Set Execution model
Execution model
Main models
Accumulator 1 explicit operand (reg or mem)
1 implicit operand (acc)
add A acc ← acc + A
Stack 0 explicit operands
All operands implicit (on TOS)
add tos ← tos + next
General Purpose Regs & Memory
all operands explicit either registers or mem. locat.
register–register (load/store arch.)
2 regs: add A B RA ← RA + RB
3 regs: add A B C RA ← RB + RC
register–memory
1 reg, 1 mem: add A B RA ← RA + mem(B)
memory–memory
3 mem: add A B C mem(A) ← mem(B) + mem(C )
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 16 / 115
Instruction Set Execution model
Execution model
Comparison: number of instructions
Example:
Code sequence for C = A + B for four classes of instruction sets
Stack Accum Reg-Mem Reg-Reg
Push A Load A Load R1, A Load R1, A
Push B Add B Add R1, B Load R2, B
Add Store C Store C, R1 Add R3, R1, R2
Pop C Store C, R3
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 17 / 115
Instruction Set Execution model
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 18 / 115
Instruction Set Execution model
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 18 / 115
Instruction Set Addressing modes
Addressing modes
how do we specify the operand we want?
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 19 / 115
Instruction Set Addressing modes
Addressing modes
Immediate addressing
Instruction
opcode ... operand (literal)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 20 / 115
Instruction Set Addressing modes
Addressing modes
Direct addressing
Instruction Memory
opcode ... address (literal)
operand
mem
Addressing modes
Register direct addressing
Instruction
Operand is located in a register.
opcode ... Reg.ID
Register ID is indicated in an
Bank of Registers instruction’s field.
+ Advantages:
R ✓ Few bits needed to index registers
⇒ small field
✓ Registers are much faster than
operand memory (lower access time)
✗ Drawback: few registers! (scarce
good)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 22 / 115
Instruction Set Addressing modes
Addressing modes
Register indirect addressing
Instruction Memory
opcode ... Reg.ID
Bank of Registers
R
operand
mem. address
mem
Addressing modes
Memory indirect addressing
Instruction Memory
opcode ... address (literal)
operand
mem2
operand's address
mem1
Addressing modes
Base plus offset, and variations
Effective address is computed as the addition of a base address and
an offset or displacement
Common approach for data: base register plus offset
▶ Base address is in a register indicated in the instruction
▶ Offset is a literal constant also included in an instruction’s field
operand := memory[R + offset]
Instruction Memory
opcode ... Reg.ID offset
Bank of Registers
R dis
operand
effec.
mem
base address
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 25 / 115
Instruction Set Addressing modes
Addressing modes
Base plus offset, and variations
Effective address is computed as the addition of a base address and
an offset or displacement
Common approach for code: PC-relative addressing
▶ Base register is implicit (PC in this case)
▶ PC-relative offset in instruction’s field
instruction := memory[PC + offset]
Instruction Memory
opcode ... offset
Bank of Registers
dis
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 25 / 115
MIPS: an example of RISC ISA
Outline
1 Introduction
2 Instruction Set
3 MIPS: an example of RISC ISA
MIPS R2000 architecture
MIPS instruction types
MIPS instruction formats
MIPS addressing modes
Subroutines/Functions in MIPS
MIPS assembly & machine code examples
4 CPU Design: Datapath and Control
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 26 / 115
MIPS: an example of RISC ISA MIPS R2000 architecture
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 27 / 115
MIPS: an example of RISC ISA MIPS R2000 architecture
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 29 / 115
MIPS: an example of RISC ISA MIPS R2000 architecture
4 byte word
Big Endian
MSB LSB
byte byte byte byte
3 2 1 0
Little Endian
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 30 / 115
MIPS: an example of RISC ISA MIPS instruction types
Main features:
▶ Fixed width: 32 bits.
▶ Operands in arithmetic-logic operations are always registers.
▶ Memory access is always by means of load/store instructions (data
transfer).
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 31 / 115
MIPS: an example of RISC ISA MIPS instruction formats
op rs rt rd shamt funct
6 bits 5 bits 5 bits 5 bits 5 bits 6 bits
I-type
op rs rt address/immediate
6 bits 5 bits 5 bits 16 bits
J-type
op target immediate
6 bits 26 bits
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 32 / 115
MIPS: an example of RISC ISA MIPS instruction formats
0 3 6 7 0 32
op rs rt rd shamt funct
sub $7,$3,$6
0 3 6 7 0 34
op rs rt rd shamt funct
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 33 / 115
MIPS: an example of RISC ISA MIPS instruction formats
8 6 8 4
op rs rt immediate
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 34 / 115
MIPS: an example of RISC ISA MIPS instruction formats
35 15 8 1200
op rs rt address (offset)
sw $8,1200($15)
43 15 8 1200
op rs rt address (offset)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 35 / 115
MIPS: an example of RISC ISA MIPS instruction formats
Content of reg. $8
after its execution:
Reg.
$8 0000 0000 1111 1111 0000 0000 0000 0000
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 36 / 115
MIPS: an example of RISC ISA MIPS instruction formats
Example
beq $19, $20, Label ▶ Jump address is indicated wih a label in asm
bne $19, $20, Label
▶ Assembler computes a PC-relative offset for
machine code:
jump address − branch instr . address
offset =
4
▶ Then, when instr. is executed:
jump to (PC + 4) + 4 ∗ offset if $rs = $rt (beq)
| {z }
effective address
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 37 / 115
MIPS: an example of RISC ISA MIPS instruction formats
slt $8,$19,$20
0 19 20 8 0 42
op rs rt rd shamt funct
slti $8,$19,10
10 19 8 10
op rs rt immediate
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 38 / 115
MIPS: an example of RISC ISA MIPS instruction formats
jr $8
0 8 0 0 0 8
op rs rt rd shamt funct
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 39 / 115
MIPS: an example of RISC ISA MIPS addressing modes
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 40 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
Subroutine sequence of program instructions that perform a specific
task, packaged as a unit.
Powerful programming tool that allows a structured programming
approach
▶ Increasing code legibility
▶ Reducing duplicate code within a program and enabling reuse of code
across multiple programs
Steps to perform a subroutine call:
▶ Passing the arguments: place subroutine parametes in an appropriate
location, where they can be accessed.
▶ Branching: transfer control to the procedure’s body by a simple jump.
▶ Allocate required storage resources for the task
▶ Carry out the task
▶ Place subroutine result (return value) in an appropriate location, where
it can be found by the caller.
▶ Branching back to the caller: return control to the caller code.
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 41 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
Subroutine sequence of program instructions that perform a specific
task, packaged as a unit.
Powerful programming tool that allows a structured programming
approach
▶ Increasing code legibility
▶ Reducing duplicate code within a program and enabling reuse of code
across multiple programs
Steps to perform a subroutine call:
▶ Passing the arguments: place subroutine parametes in an appropriate
location, where they can be accessed.
▶ Branching: transfer control to the procedure’s body by a simple jump.
▶ Allocate required storage resources for the task
▶ Carry out the task
▶ Place subroutine result (return value) in an appropriate location, where
it can be found by the caller.
▶ Branching back to the caller: return control to the caller code.
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 41 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
Subroutine sequence of program instructions that perform a specific
task, packaged as a unit.
Steps to perform a subroutine call:
▶ Passing the arguments: place subroutine parametes in an appropriate
location, where they can be accessed.
▶ Branching: transfer control to the procedure’s body by a simple jump.
▶ Allocate required storage resources for the task
▶ Carry out the task
▶ Place subroutine result (return value) in an appropriate location, where
it can be found by the caller.
▶ Branching back to the caller: return control to the caller code.
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 41 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
MIPS Memory Layout and Stack
$sp 7 f f f f f f f hex Stack
Reserved
0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 42 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
Passing arguments through stack
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 43 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
Passing arguments through registers
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 44 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
Jumping to subroutine code and returning control when finish
jal Subroutine_label
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 45 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
Jumping to subroutine code and returning control when finish
jal Subroutine_label
Usage:
▶ Caller loads parameters in $a0–$a3 (or in stack) and calls jal.
▶ Subroutine perform the computation, puts results in $v0–$v1 (or in
stack) and return control.
▶ If more than 4 arguments are needed, or more than 2 results are
returned, stack is used.
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 45 / 115
MIPS: an example of RISC ISA Subroutines/Functions in MIPS
Subroutine calls
Saving register contents
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 46 / 115
MIPS: an example of RISC ISA MIPS assembly & machine code examples
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 47 / 115
MIPS: an example of RISC ISA MIPS assembly & machine code examples
g = h + A[8]
g → $s1 h → $s2 &A[0] → $s3
lw $t0, 32($s3)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 48 / 115
MIPS: an example of RISC ISA MIPS assembly & machine code examples
while(save[i]==k)
i = i + 1
i → $s3 k → $s5 &save[0] → $s6
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 49 / 115
MIPS: an example of RISC ISA MIPS assembly & machine code examples
$a0 $a1
add ( a, b )
{
sum = a + b;
return sum;
} $v0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 50 / 115
MIPS: an example of RISC ISA MIPS assembly & machine code examples
Outline
1 Introduction
2 Instruction Set
3 MIPS: an example of RISC ISA
4 CPU Design: Datapath and Control
MIPS Datapath Design
Datapath design: Control signals
Control Unit Design
Control Sequential System
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 52 / 115
CPU Design: Datapath and Control
CPU
Datapath and Control
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 53 / 115
CPU Design: Datapath and Control
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 54 / 115
CPU Design: Datapath and Control
We’ll study a simple CPU design (datapath and control unit) able of
executing this subset from MIPS ISA:
▶ Data transfer instructions: lw and sw.
▶ Arithmetic-logic instructions: add, sub, and, or and slt.
▶ Control flow instructions: beq and j.
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 55 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Instruction fetching
MIPS Datapath Design
Adder
PC Address
Instruction IR
Instruction
Memory
Arithmetic-logic instructions
MIPS Datapath Design
3
Reg. to Operation
read 1
REGISTERS
Instruction Reg. to
Operand 1 ALU
read 2 Zero
Reg. to
Result
write
Operand 2
Result to
write
WriteReg
R-Type instructions deal with 3 regs: two for reading, one for writing.
Operation is carried out by ALU
Example: add $t1, $t2, $t3
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 57 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Arithmetic-logic instructions
MIPS Datapath Design
3
Reg. to Operation
read 1
REGISTERS
Instruction Reg. to
Operand 1 ALU
read 2 Zero
Reg. to
Result
write
Operand 2
Result to
write
WriteReg
Arithmetic-logic instructions
ALU: Arithmetic-Logic Unit
ALU
Operation
Carry out
This ALU’s design was depicted in the last slides of the Combinational Systems
lesson.
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 58 / 115
CPU Design: Datapath and Control MIPS Datapath Design
REGISTERS
Instruction Reg. to
Operand 1 ALU WriteMem
read 2 Zero
Read
Reg. to Address
Result data
write
Operand 2 Data
Result to
write
Memory
Data
WriteReg to write
ReadMem
16 32
Sign
Extension
I-Type instructions
Addressing modes: base+displacement (base register) and
register-direct
Examples: lw $t1, offset($t2) sw $t1, offset($t2)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 59 / 115
CPU Design: Datapath and Control MIPS Datapath Design
REGISTERS
Instruction Reg. to
Operand 1 ALU WriteMem
read 2 Zero
Read
Reg. to Address
Result data
write
Operand 2 Data
Result to
write
Memory
Data
WriteReg to write
ReadMem
16 32
Sign
Extension
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 59 / 115
CPU Design: Datapath and Control MIPS Datapath Design
REGISTERS
Instruction Reg. to
Operand 1 ALU WriteMem
read 2 Zero
Read
Reg. to Address
Result data
write
Operand 2 Data
Result to
write
Memory
Data
WriteReg to write
ReadMem
16 32
Sign
Extension
Result Jump
2-bit destination
left shifting
3
Reg. to Operation
read 1
comp
REGISTERS
Instruction Operand 1
Reg. to
read 2 Zero Jump decision
Reg. to
write ALU
Operand 2
WriteReg
16 32
Sign
Extension
Result Jump
2-bit destination
left shifting
3
Reg. to Operation
read 1
comp
REGISTERS
Instruction Operand 1
Reg. to
read 2 Zero Jump decision
Reg. to
write ALU
Operand 2
WriteReg
16 32
Sign
Extension
Comparison:
▶ a subtraction is performed, so ALU’s Zero output is used to check jump
condition
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 60 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Result Jump
2-bit destination
left shifting
3
Reg. to Operation
read 1
comp
REGISTERS
Instruction Operand 1
Reg. to
read 2 Zero Jump decision
Reg. to
write ALU
Operand 2
WriteReg
16 32
Sign
Extension
Unconditional jumps
MIPS Datapath Design
j L1
6 bits 26 bits
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 61 / 115
CPU Design: Datapath and Control MIPS Datapath Design
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 62 / 115
CPU Design: Datapath and Control MIPS Datapath Design
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 62 / 115
CPU Design: Datapath and Control MIPS Datapath Design
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 62 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Full Datapath
High-level design ⇒ See complete datapath
Instruction Read
Register Reg. 1 Read
Memory A
REGISTERS
P Address Read Data 1
C Reg. 2 ALU
Instructions ALU
or Data Write output
Reg. 1 Read
Data B
Memory Write Data 2
Data Register Data
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 63 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Full Datapath
High-level design ⇒ See complete datapath
Instruction Read
Register Reg. 1 Read
Memory A
REGISTERS
P Address Read Data 1
C Reg. 2 ALU
Instructions ALU
or Data Write output
Reg. 1 Read
Data B
Memory Write Data 2
Data Register Data
ALU operations:
▶ Instruction fetching: Add PC+4.
▶ Data transfer instructions: computation of effective address to access
data.
▶ R-Type instructions: Arithmetic-logic operations.
▶ Conditional jumps:
⋆ Jump condition evaluation.
⋆ Computation of destination address to jump
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 63 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Full Datapath
High-level design ⇒ See complete datapath
Instruction Read
Register Reg. 1 Read
Memory A
REGISTERS
P Address Read Data 1
C Reg. 2 ALU
Instructions ALU
or Data Write output
Reg. 1 Read
Data B
Memory Write Data 2
Data Register Data
Temporary registers:
▶ Instruction Register (IR) and Memory Data Register (MDR):
⋆ Storage for instructions and data read from memory, respectively.
▶ A and B Registers: operands read from Register File (bank of registers).
▶ ALU Output
▶ IR needs a Write control signal, since it keeps content for multiple
cycles.
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 63 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Full Datapath
High-level design ⇒ See complete datapath
Instruction Read
Register Reg. 1 Read
Memory A
REGISTERS
P Address Read Data 1
C Reg. 2 ALU
Instructions ALU
or Data Write output
Reg. 1 Read
Data B
Memory Write Data 2
Data Register Data
Full Datapath
High-level design ⇒ See complete datapath
Instruction Read
Register Reg. 1 Read
Memory A
REGISTERS
P Address Read Data 1
C Reg. 2 ALU
Instructions ALU
or Data Write output
Reg. 1 Read
Data B
Memory Write Data 2
Data Register Data
Full Datapath
High-level design ⇒ See complete datapath
Instruction Read
Register Reg. 1 Read
Memory A
REGISTERS
P Address Read Data 1
C Reg. 2 ALU
Instructions ALU
or Data Write output
Reg. 1 Read
Data B
Memory Write Data 2
Data Register Data
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 63 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Full Datapath
High-level design ⇒ See complete datapath
Instruction Read
Register Reg. 1 Read
Memory A
REGISTERS
P Address Read Data 1
C Reg. 2 ALU
Instructions ALU
or Data Write output
Reg. 1 Read
Data B
Memory Write Data 2
Data Register Data
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 63 / 115
CPU Design: Datapath and Control MIPS Datapath Design
Full Datapath
0
1
M
Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 66 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 66 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 67 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 67 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 67 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
1 Concurrent load base register (temp reg A) and data to store (temp reg B)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 68 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
1 Concurrent load base register (temp reg A) and data to store (temp reg B)
2 Compute effective mem. address: base reg. + offset
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 68 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
1 Concurrent load base register (temp reg A) and data to store (temp reg B)
2 Compute effective mem. address: base reg. + offset
3 Memory access and save date from reg B (mem write)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 68 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 69 / 115
CPU Design: Datapath and Control MIPS Datapath Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
Control signals
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 71 / 115
CPU Design: Datapath and Control Datapath design: Control signals
Control signals
ALU Control Unit
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 72 / 115
CPU Design: Datapath and Control Datapath design: Control signals
0
I/D Mem2Reg 1
M
Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit ALU
Sign
shift Control
16 Ext. 32
left Unit
ALUop
Control signals
Datapath and Control Unit
PCWriteCond
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite Control ALUSrcA
Mem2Reg 0
RegWrite
M
IRWrite OPCODE DestReg 1
[31-26] Uncond. u
Instruction [25-0]
26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
4 1
Register Data u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit ALU
Sign
shift Control
Ext.
16 32 left Unit
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 74 / 115
CPU Design: Datapath and Control Control Unit Design
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 75 / 115
CPU Design: Datapath and Control Control Unit Design
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 76 / 115
CPU Design: Datapath and Control Control Unit Design
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 77 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 78 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
State 0 [15-0] u 3
MemRead
Memory 1x
ALUSrcA = 0 Data Reg. 2-bit
Sign ALU
ALUSrcB = 01 shift
Init ALUOp = 00
to State 1 16 Ext. 32
left
Control
Unit
I/D = 0
IRWrite
PCWrite
PCSrc = 00
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 78 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
Instruction is decoded
Some potentially useful tasks get ahead:
▶ Regs rt and rs are read and content load in A and B
GAC (Dpt.▶ Potential
Computer jump addressLesson
Engineering) is computed (beq)
4. The Processor Fundamentals of Computers 79 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
State 1
Memory 1x
Data Reg. 2-bit ALU
Sign
ALUSrcA = 0 shift
from State 0 to State ? 16 Ext. 32
left
Control
ALUSrcB = 11 Unit
ALUOp = 00
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 79 / 115
CPU Design: Datapath and Control Control Unit Design
State 0
(Instruction fetch) State 1
(Instruction decode/Register fetch)
MemRead
ALUSrcA = 0
Init ALUSrcB = 01 ALUSrcA = 0
ALUOp = 00 ALUSrcB = 11
I/D = 0 ALUOp = 00
IRWrite
PCWrite )
w' ) ic
= 's og (O
PCSrc = 00
(Op l p
(Op
) or ic- =
'j
= 'lw' m et ')
= 'b
(Op h
it
ar
eq')
=
( Op
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 80 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 81 / 115
CPU Design: Datapath and Control Control Unit Design
PCWriteCond
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg 0
RegWrite
M
IRWrite OPCODE DestReg 1
[31-26] Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
State 2 (lw/sw)
Memory 1x
Data Reg. 2-bit ALU
Sign
ALUSrcA = 1 shift
from State 1 to State ? 16 Ext. 32
left
Control
ALUSrcB = 10 Unit
ALUOp = 00 select base reg.
select sign-extended
offset
ALU op: addition
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 81 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 82 / 115
CPU Design: Datapath and Control Control Unit Design
PCWriteCond
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg 0
RegWrite
M
IRWrite OPCODE DestReg 1
[31-26] Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
State 3 (lw)
Memory 1x
Data Reg. 2-bit ALU
Sign
shift Control
16 Ext. 32
left
MemRead: memory read operation Unit
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 83 / 115
CPU Design: Datapath and Control Control Unit Design
PCWriteCond
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg 0
RegWrite
M
IRWrite OPCODE DestReg 1
[31-26] Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
State 4 (lw)
Memory 1x
Data Reg. 2-bit ALU
Sign RegWrite: write operation in Reg. File
shift Control
16 Ext. 32
left
Mem2Reg = 1: data to write
Unit comes from
mem.
DestReg = 0: dest. reg indexed by bits 16:20
of instruction (field rt)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 83 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 84 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit ALU
Sign
shift Control
16 Ext. 32
left Unit
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 84 / 115
CPU Design: Datapath and Control Control Unit Design
State 3 State 5
MemRead MemWrite
I/D = 1 I/D = 1
Memory Memory
access access
State 4
Memory read completion:
RegWrite write stage
Mem2Reg = 1 Return to
DestReg = 0 State 0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 85 / 115
CPU Design: Datapath and Control Control Unit Design
Arithmetic-logic Instructions
Stage 3. Execution
0
1
M
Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 86 / 115
CPU Design: Datapath and Control Control Unit Design
Arithmetic-logic Instructions
Stage 3. Execution
PCWriteCond
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg 0
RegWrite
M
IRWrite OPCODE DestReg 1
[31-26] Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
State 6 (arithmetic-logic)
Memory 1x
Data Reg. 2-bit ALU
Sign
shift Control
16 Ext. 32
left
ALUSrcA = 1: Reg A is ALU's 1st operand (rs) Unit
Arithmetic-logic Instructions
Stage 4. Execution
0
1
M
Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 87 / 115
CPU Design: Datapath and Control Control Unit Design
Arithmetic-logic Instructions
Stage 4. Execution
PCWriteCond
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg 0
RegWrite
M
IRWrite OPCODE DestReg 1
[31-26] Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0
M State 7 (arithmetic-logic)
2
x
[15-0] u 3
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 87 / 115
CPU Design: Datapath and Control Control Unit Design
Arithmetic-logic Instructions
State diagram
From State 1
(Op = arithmetic-logic)
State 6
ALUSrcA = 1
ALUSrcB = 00 Execution
ALUOp = 10
State 7
RegWrite R-Type completion:
Mem2Reg = 0
DestReg = 1
write result stage
Return to
State 0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 88 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 89 / 115
CPU Design: Datapath and Control Control Unit Design
PCWriteCond
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg 0
RegWrite
M
IRWrite OPCODE DestReg 1
[31-26] Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr.
State 8 (beq) [15-0]
[15-11]
u Reg. 1 Read
ALU ALU
B 0 Result output
Data Instruction 1x Write Data 2 M
Comparison: Register Data 4 1
u
0 2
ALUSrcA = 1: Reg A is ALU's 1st operandInstr.
(rs) M x
[15-0] u 3
ALUSrcB = 00: Reg B is ALU's 2nd operand (rt)
Memory 1x
From State 1
(Op = 'beq')
State 8
ALUSrcA = 1 Branch completion
ALUSrcB = 00
ALUOp = 01
PCWriteCond
PCSrc = 01
Return to
State 0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 90 / 115
CPU Design: Datapath and Control Control Unit Design
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x
Data Reg. 2-bit
Sign
shift
16 Ext. 32
left
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 91 / 115
CPU Design: Datapath and Control Control Unit Design
PCWriteCond
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg 0
RegWrite
M
IRWrite OPCODE DestReg 1
[31-26] Uncond. u
Instruction [25-0] 26 2-bit 28 Jump [31-0] x
shift 2
left
PC [31-28]
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
State 3 (j) Instr. 0
M 2
x
[15-0] u 3
Memory 1x
PCWrite: sets unconditional PCData
write
Reg. 2-bit ALU
Sign
PCSrc = 10: new PC is obtained by shifting 16 Ext. 32
shift Control
left
left 2 bits Instruction's 0:25 bits and Unit
concatenating with 4 most significant bits
from PC
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 91 / 115
CPU Design: Datapath and Control Control Unit Design
From State 1
(Op = 'j')
State 9
PCWrite
Jump completion
PCSrc = 10
Return to
State 0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 92 / 115
CPU Design: Datapath and Control Control Sequential System
(Op
) or c =
ti 'j
= 'lw' me ')
= 'b
(Op th
i
ar
eq')
=
p
State 2 (O
State 6 State 8 State 9
ALUSrcA = 1 Memory address
ALUSrcB = 10 computation ALUSrcA = 1 Branch completion
ALUSrcA = 1
ALUSrcB = 00 PCWrite
ALUOp = 00 Execution
ALUSrcB = 00 PCSrc = 10
ALUOp = 01
ALUOp = 10
PCWriteCond
PCSrc = 01 Jump completion
(Op = 'lw') (Op = 'sw')
State 3 State 5
State 7
MemRead MemWrite
I/D = 1 I/D = 1 RegWrite R-Type completion:
Memory Memory Mem2Reg = 0
write result stage
access DestReg = 1
access
State 4
Memory read completion:
RegWrite write stage
Mem2Reg = 1
DestReg = 0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 93 / 115
CPU Design: Datapath and Control Control Sequential System
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 94 / 115
Microprogram Control Unit
Outline
1 Introduction
2 Instruction Set
3 MIPS: an example of RISC ISA
4 CPU Design: Datapath and Control
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 95 / 115
Microprogram Control Unit
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 96 / 115
Microprogram Control Unit
Microinstruction Register
.......
control signals
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 97 / 115
Microprogram Control Unit
Sequencing
Let’s implement a microprogram Control Unit with explicit
sequencing for our subset of MIPS ISA.
Every finite state is transformed into a microinstruction.
Next microinstruction? Three possible actions:
▶ Increase current microinstruction address:
⇒ so next contiguous microinstruction
▶ Reset microprogram (set state to 0):
⇒ so jump to first microinstruction to start execution of a new instruction
▶ Choose next microinstruction as a function of current state and
instruction’s opcode being executed.
⋆ this operation is called ‘a dispatch’
⋆ ‘dispatch table’: table with the possible destination addresses
⋆ one ‘dispatch table’ is needed for each state with multiple destination
states
According to these possibilities, an additional set of control outputs
indicates what’s the next instruction to be executed (reset, next or
dispatch): AddrCtl
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 98 / 115
Microprogram Control Unit
Sequencing
Two Dispatch tables are needed for implementing our MIPS subset
Control Unit.
Two AddrCtl bits are needed to specify next microinstructions:
AddrCtl Action
0 (00) Set state to 0
1 (01) Dispatch with table 1
2 (10) Dispatch with table 2
3 (11) Use the incremented state
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 98 / 115
Microprogram Control Unit
Implementation
PCSrc (2)
ALUop (2)
ALUSrcA
ALUSrcB (2)
RegWrite
DestReg
Outputs PCWriteCond
PCWrite
Control Logic I/D
MemRead
Operation Code
Bits [31-26] from
instruction register
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 99 / 115
Microprogram Control Unit
Implementation
Logic for obtaining next microinstruction
ROM AddrCtl
Inputs
1
2
MUX
3 2 1 0
Address
select logic
Operation Code
Bits [31-26] from
instruction register
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 100 / 115
Microprogram Control Unit
Implementation
Microprogram
PCWriteCond
ALUSrcB (2)
AddrCtl (2)
PCSrc (2)
ALUOp (2)
MemWrite
RegWrite
PCWrite
MemRead
IRWrite
Mem2Reg
ALUSrcA
DestReg
I/D
1 0 1 1 0 0 1 0 3 State 0
0 3 0 1 State 1
Mem1 0 2 1 2State 2
Lw2 1 1 3 State 3
1 1 0 0 State 4
Sw2 1 1 0 State 5
Rformat1 2 0 1 3 State 6
0 1 1 0 State 7
Beq1 1 1 1 0 1 0 State 8
Jump1 1 2 0 State 9
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 101 / 115
Microprogram Control Unit
Implementation
Microprogram and dispatch tables
PCWriteCond
ALUSrcB (2)
AddrCtl (2)
PCSrc (2)
ALUOp (2)
MemWrite
RegWrite
PCWrite
MemRead
IRWrite
Mem2Reg
ALUSrcA
DestReg
I/D
1 0 1 1 0 0 1 0 3 State 0
0 3 0 1 State 1
Mem1 0 2 1 2State 2
Lw2 1 1 3 State 3
1 1 0 0 State 4
Sw2 1 1 0 State 5
Rformat1 2 0 1 3 State 6
0 1 1 0 State 7
Beq1 1 1 1 0 1 0 State 8
Jump1 1 2 0 State 9
Opcode field Opcode name Value ⇐ Dispatch table 1
000000 R-format Rformat1
⇓ Dispatch table 2
000010 jmp Jump1
000100 beq Beq1 Opcode field Opcode name Value
100011 lw Mem1 100011 lw lw2
101011 sw Mem1 101011 sw sw2
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 101 / 115
Timing
Outline
1 Introduction
2 Instruction Set
3 MIPS: an example of RISC ISA
4 CPU Design: Datapath and Control
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 102 / 115
Timing
Timing
Clock cycle
Clock cycle must be at least as long as the longest operation in
datapath takes
Example:
Reg. RegFile Mem. ALU Mem.
Update Access Read Write Total
(5 ns) (10 ns) (25 ns) (15 ns) (30 ns)
Load instruction ✓ ✓ 30 ns
Decodification ✓ ✓ 20 ns
Computation ✓ ✓ 20 ns
Memory read ✓ ✓ 30 ns
Memory write ✓ ✓ 35 ns
Write register ✓ ✓ 15 ns
⇒ Clock cycle ≥ 35 ns
⇒ Instruction latency:
▶ lw: 175 ns (5 cycles)
▶ sw & A-L instructions: 140 ns (4 cycles)
▶ beq & j: 105 ns (3 cycles)
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 103 / 115
Exception Handling
Outline
1 Introduction
2 Instruction Set
3 MIPS: an example of RISC ISA
4 CPU Design: Datapath and Control
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 104 / 115
Exception Handling
Exceptions
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 105 / 115
Exception Handling
Exception Handling
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 106 / 115
Exception Handling
Modified Datapath
Exception Handling
CauseWrite
IntCause
PCWriteCond EPCWrite
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg RegWrite
IRWrite OPCODE DestReg 0
[31-26] Uncond. 1
M
26 2-bit 28 Jump [31-0] u
Instruction [25-0] 2
shift x
left 3
PC [31-28] 0xC0000000
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output EPC
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x 0 0
Data Reg. 2-bit
M
Sign ALU u Cause
shift Control
Ext. 32
16 left 1 1x
Unit
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 107 / 115
Exception Handling
Modified Datapath
Exception Handling
CauseWrite
IntCause
PCWriteCond EPCWrite
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg RegWrite
IRWrite OPCODE DestReg 0
[31-26] Uncond. 1
M
26 2-bit 28 Jump [31-0] u
Instruction [25-0] 2
shift x
left 3
PC [31-28] 0xC0000000
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output EPC
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x 0 0
Data Reg. 2-bit
M
Sign ALU u Cause
shift Control
Ext. 32
16 left 1 1x
Unit
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 107 / 115
Exception Handling
Exception processing
CauseWrite
IntCause
PCWriteCond EPCWrite
PCWrite PCSrc
I/D ALUop
MemRead ALUSrcB
MemWrite ALUSrcA
Mem2Reg RegWrite
OPCODE
IRWrite DestReg 0
[31-26] Uncond. 1
M
26 2-bit 28 Jump [31-0] u
Instruction [25-0] 2
shift x
left 3
PC [31-28] 0xC0000000
Instruction Read 0
P [25-21] Reg. 1 M
0
C M Read u
REGISTERS
Memory Instruction Read A
u Address Data 1
1x
ALU
[20-16] Reg. 2
1x Instructions 0 Zero
Instruction M Write
or Data Instr. ALU ALU
[15-0] u Reg. 1 Read
[15-11] B 0 Result output EPC
Data Instruction 1x Write Data 2 M
Register Data 4 1
u
Instr. 0 2
M x
[15-0] u 3
Memory 1x 0 0
Data Reg. 2-bit
M
Sign ALU u Cause
shift Control
Ext. 32
16 left 1 1x
Unit
Exception processing
New states in Control Automaton
State 10 State 11
IntCause = 0 IntCause = 1
CauseWrite CauseWrite
ALUSrcA = 0 ALUSrcA = 0
ALUSrcB = 01 ALUSrcB = 01
ALUOp = 01 ALUOp = 01
EPCWrite EPCWrite
PCWrite PCWrite
PCSrc = 11 PCSrc = 11
Return to State 0
Init new instruction
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 109 / 115
Exception Handling
(Op = 'b
) or c =
ti 'j
'lw' ')
(O
(Op
= me
th
p
i
=
ar
ot
eq')
=
he
p
State 2 (O State 9
r)
State 6 State 8
ALUSrcA = 1 Memory address Jump PCWrite
ALUSrcA = 1
ALUSrcB = 10 computation
ALUSrcA = 1 ALUSrcB = 00 completion PCSrc = 10
ALUOp = 00 Execution
ALUSrcB = 00 ALUOp = 01
Branch
ALUOp = 10 PCWriteCond
Ov PCSrc = 01 completion
(Op = 'lw') (Op = 'sw') er
fl
ow
State 3 State 5 !
State 10 State 11
State 7 IntCause = 0 IntCause = 1
MemRead MemWrite CauseWrite CauseWrite
I/D = 1 I/D = 1 RegWrite R-Type completion: ALUSrcA = 0 ALUSrcA = 0
Memory Memory Mem2Reg = 0 ALUSrcB = 01 ALUSrcB = 01
DestReg = 1
write result stage ALUOp = 01
access access ALUOp = 01
EPCWrite EPCWrite
PCWrite PCWrite
PCSrc = 11 PCSrc = 11
State 4
Memory read completion:
RegWrite write stage
Mem2Reg = 1
DestReg = 0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 110 / 115
Exception Handling
(Op = 'b
r =
w') o
c 'j
= 'l ti ')
(O
(Op me
th
p
i
=
ar
ot
eq')
=
he
p
State 2 (O State 9
) r
State 6 State 8
ALUSrcA = 1 Memory address Jump PCWrite
ALUSrcA = 1
ALUSrcB = 10 computation
ALUSrcA = 1 ALUSrcB = 00 completion PCSrc = 10
ALUOp = 00 Execution
ALUSrcB = 00 ALUOp = 01
Branch
ALUOp = 10 PCWriteCond
Ov PCSrc = 01 completion
(Op = 'lw') (Op = 'sw') er
fl
ow
State 3 State 5 !
State 10 State 11
State 7 IntCause = 0 IntCause = 1
MemRead MemWrite CauseWrite CauseWrite
I/D = 1 I/D = 1 RegWrite R-Type completion: ALUSrcA = 0 ALUSrcA = 0
Memory Memory Mem2Reg = 0 ALUSrcB = 01 ALUSrcB = 01
DestReg = 1
write result stage ALUOp = 01
access access ALUOp = 01
EPCWrite EPCWrite
PCWrite PCWrite
PCSrc = 11 PCSrc = 11
State 4
Memory read completion:
RegWrite write stage
Mem2Reg = 1
DestReg = 0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 110 / 115
Exception Handling
(Op = 'b
r =
w') o
c 'j
= 'l ti ')
(O
(Op me
th
p
i
=
ar
ot
eq')
=
he
p
State 2 (O State 9
) r
State 6 State 8
ALUSrcA = 1 Memory address Jump PCWrite
ALUSrcA = 1
ALUSrcB = 10 computation
ALUSrcA = 1 ALUSrcB = 00 completion PCSrc = 10
ALUOp = 00 Execution
ALUSrcB = 00 ALUOp = 01
Branch
ALUOp = 10 PCWriteCond
Ov PCSrc = 01 completion
(Op = 'lw') (Op = 'sw') er
fl
ow
State 3 State 5 !
State 10 State 11
State 7 IntCause = 0 IntCause = 1
MemRead MemWrite CauseWrite CauseWrite
I/D = 1 I/D = 1 RegWrite R-Type completion: ALUSrcA = 0 ALUSrcA = 0
Memory Memory Mem2Reg = 0 ALUSrcB = 01 ALUSrcB = 01
DestReg = 1
write result stage ALUOp = 01
access access ALUOp = 01
EPCWrite EPCWrite
PCWrite PCWrite
PCSrc = 11 PCSrc = 11
State 4
Memory read completion:
RegWrite write stage
Mem2Reg = 1
DestReg = 0
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 110 / 115
Exception Handling
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 111 / 115
Exception Handling
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 112 / 115
Exception Handling
PCWriteCond
ALUSrcB (2)
AddrCtl (3)
CauseWrite
PCSrc (2)
ALUOp (2)
MemWrite
RegWrite
IntCause
EPCWrite
PCWrite
MemRead
IRWrite
Mem2Reg
ALUSrcA
DestReg
1 I/D
0 1 1 0 0 1 0 3 State 0
0 3 0 1 State 1
Mem1 0 2 1 2 State 2
Lw2 1 1 3 State 3
1 1 0 0 State 4
Sw2 1 1 0 State 5
Rformat1 2 0 1 4 State 6
Arit3 0 1 1 0 State 7
Beq1 1 1 1 0 1 0 State 8
Jump1 1 2 0 State 9
Ov3 1 3 1 1 0 0 0 1 1 State 10
Nodef1 1 3 1 1 0 0 1 1 1 State 11
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 113 / 115
Final Remarks
Outline
1 Introduction
2 Instruction Set
3 MIPS: an example of RISC ISA
4 CPU Design: Datapath and Control
5 Microprogram Control Unit
6 Timing
7 Exception Handling
8 Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 114 / 115
Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 115 / 115
Final Remarks
GAC (Dpt. Computer Engineering) Lesson 4. The Processor Fundamentals of Computers 115 / 115