Title: CSCE 212 Chapter 5 The Processor: Datapath and Control
1CSCE 212Chapter 5The Processor Datapath and
Control
- Instructor Jason D. Bakos
2Goal
- Design a CPU that implements the following
instructions - lw, sw
- add, sub, and, or, slt
- beq, j
3Datapath
4Instruction Fetch Datapaths
5Register File and ALU
6BEQ Datapath
7Load, Store, and R-type Datapath
8Combined Datapaths
9ALU Control
- ALU performs function based on 4-bit
ALU_operation input - Add a lookup table that instructs ALU to perform
- add (for LW, SW), or
- subtract (for BEQ), or
- perform operation as dictated by R-type function
code
Instruction opcode ALUOp Instruction Funct field Desired ALU action ALU control input
LW 00 add 0010
SW 00 add 0010
BEQ 01 subtract 0110
R-type 10 add 100000 add 0010
R-type 10 sub 100010 subract 0110
R-type 10 and 100100 and 0000
R-type 10 or 100101 or 0001
R-type 10 slt 101010 set on less than 0111
10MIPS Datapath
11MIPS Datapath with Control
12MIPS Datapath with Jump
13Single-Cycle
- This is a single-cycle implementation
- Each instruction is executed within one clock
cycle - Must be set for worst-case delay (LW)
Instruction class Functional units used Functional units used Functional units used Functional units used Functional units used
Instruction class Instruction fetch Register read ALU Memory access Register write
R-type X X X X
LW X X X X X
SW X X X X
BEQ X X X
J X
14Multicycle Implementation
- Break instruction execution into a sequence of
steps - Adjust cycle time to be long enough to perform
one basic operation - fetch, register read, ALU, memory access,
register write - Must add registers to carry computed values from
one cycle to next - Still can perform independent operations in
parallel, i.e. - fetch instruction and compute next PC address
- read registers and compute branch address
- Allows us to re-use ALU
15Multicycle MIPS Implementation
16Multicycle Control
- Instruction fetch
- Information available PC
- Performed for all instructions
- RTL
- IR lt MemoryPC
- PC lt PC 4
- Instruction decode and register fetch
- Information available PC, instruction
- Performed for all instructions
- RTL
- A lt RegIR2521
- B lt RegIR2016
- ALUOut lt PC (sign-extend(IR150) ltlt 2)
17Multicycle Control
- Execution, memory address computation, or branch
completion - Information available PC, instruction, (rs),
(rt), (ALUOut) - Memory reference
- ALUOut lt A sign-extend(IR150)
- Arithmetic-logical instruction (R-type)
- ALUOut lt A op B
- Branch
- if (A B) PC lt ALUOut
- Jump
- PC lt PC3128, IR250, 00
18Multicycle Control
- Memory access or R-type completion step
- Information available PC, instruction, (rs),
(rt), (ALUOut) - Load
- MDR lt MemoryALUOut
- Store
- MemoryALUOut lt B
- Arithmetic-logical instruction (R-type)
- RegIR1511 lt ALUOut
19Multicycle Control
- Memory read completion step
- Information available PC, instruction, (rs),
(rt), (ALUOut), (MDR) - Load
- RegIR2016 lt MDR
20Multicycle Control
21Adding Datapaths and Control
- How to add these instructions
- addi rt, rs, imm
- bgtz rs, target
- bgtzal rs, target
22Exceptions and Interrupts
- Events other than branches or jumps that change
the normal flow of instruction execution - Examples
- I/O device request (external, interrupt)
- System call (internal, exception)
- Arithmetic overflow (internal, exception)
- Invalid instruction (internal, exception)
- Hardware malfunction (internal or external,
exception or interrupt)
23Interrupts and Exceptions
- What to do?
- Execute code in response to event (handler)
- Save PC (EPC reg,)
- Record cause (Cause reg.)
- Set new PC (4)
- Return from handler
- Restore PC
- Enable e/i (shift Status reg.)
- Determining type of exception
- Use vectored exceptions
- Infer type from address
- Use polled exceptions
- Use Cause register
- This is what MIPS does
24Example Implementation
- Example
- Use polled approach
- All exceptions and interrupts jump to single
handler at address 8000 0180 - The cause is recorded in the cause register
- The address of affected instruction is stored in
EPC
25Example Implementation
26Example Implementation