Lecture 9. MIPS Processor Design - Instruction Fetch: Prof. Taeweon Suh Computer Science Education Korea University
Lecture 9. MIPS Processor Design - Instruction Fetch: Prof. Taeweon Suh Computer Science Education Korea University
Research
Introduction
Microarchitecture:
How to implement an
architecture in hardware
Multicycle
Pipeline
Application
Software
programs
Operating
Systems
device drivers
Architecture
instructions
registers
Microarchitecture
datapaths
controllers
Logic
adders
memories
Digital
Circuits
AND gates
NOT gates
Analog
Circuits
amplifiers
filters
Devices
transistors
diodes
Physics
electrons
Korea Univ
Processor Performance
Program execution time
Execution Time = (#instructions)(cycles/instruction)
(seconds/cycle)
Korea Univ
Overview
In chapter 4, we are going to implement (design) MIPS CPU
The implemented CPU should be able to execute the machine
code we discussed so far
Real-PC system
CPU
FSB
(Front-Side Bus)
North
Bridge
DMI
(Direct Media I/F)
Main
Memor
y
(DDR)
Simplified
Address Bus
MIPS
CPU
Data Bus
Memory
(Instruction,
data)
South
Bridg
e
Korea Univ
Address Bus
Instruction
Memory
Data Bus
MIPS CPU
Address Bus
Data
Memory
Data Bus
Korea Univ
Processor
Our MIPS implementation is simplified by implementing
only
memory-reference instructions: lw, sw
arithmetic-logical instructions: add, sub, and, or, slt
Control flow instructions: beq, j
MIPS CPU
Fetch
PC = PC +4
Instruction
Memory
Data Bus
Address Bus
Execute
Decode
Data Bus
Data
Memory
Korea Univ
Decoding
Extract opcode: Determine what operation should be done
Extract operands: Register numbers or immediate from fetched
instruction
Read registers from register file
Execution
Use ALU to calculate (depending on instruction class)
Arithmetic result
Memory address for load/store
Branch target address
Address Bus
MIPS CPU
Next Fetch
Fetch
PC = PC +4
PC target address or PC + 4
Instruction
Memory
Data Bus
Address Bus
Execute
Decode
Data Bus
Data
Memory
Korea Univ
Sequential logic
Output is determined not only by input, but
also by internal state
Sequential logic needs state elements to store
information
Flip-flop and latch are used to store the state
information
But, avoid using latch in digital design
Korea Univ
AND gate
Y=A&B
A
B
Y=A+
B
+
Multiplexer
Y = S ? I1 : I0
I0
I1
M
u
x
Y = F(A, B)
A
ALU
F
9
Korea Univ
D
Clk
Clk
D
Q
10
Korea Univ
Clk
D
Write
Clk
Write
D
Q
11
Korea Univ
Clocking Methodology
Virtually all digital systems are essentially synchronous to
the clock
Combinational logic sits between state elements (registers)
Combinational logic transforms data during clock cycles
12
Korea Univ
Building a Datapath
Processor is composed of datapath and control
Datapath
Control
For example, the lowest modules (such as ALU and register files) will be
designed with the behavioral modeling
For example, the top module (such as MIPS_CPU) will be designed with the
structural modeling
13
Korea Univ
Address Bus
Instruction
Memory
MIPS
CPU
Data Bus
Address Bus
Data
Memory
Data Bus
mips_tb.v (testbench)
mips_cpu_mem.v
reset
mips_cpu.v
Address
imem.v
(Instruction
Memory)
clock
fetch,
pc
Decodin
g
Register
File
ALU
Memory
Access
Instruction
Address
dmem.v
DataOut
(Data
Memory)
DataIn
14
Binary
(machine
code)
Data in
your
program,
Stack,
Heap
Korea Univ
Instruction Fetch
MIPS CPU
Increment by 4 for
next instruction
4
Add
Instructio
n Memory
reset
clock
Address
PC
Out
32
instruction
32-bit register (flip-flops)
What is PC on reset?
15
Korea Univ
reset
clock
Add
PC
`include "delay.v"
`include "delay.v"
`include "delay.v"
module pc (input
clk, reset,
output reg [31:0] pc,
input
[31:0] pcnext);
module mips_cpu(input
clk, reset,
output [31:0] pc,
input [31:0] instr);
assign #`mydelay y = a + b;
wire [31:0] pcnext;
endmodule
// instantiate pc and adder modules
pc
pcreg (clk, reset, pc, pcnext);
adder pcadd4 (pc, 32'b100, pcnext);
endmodule
endmodule
16
Korea Univ
Memory
As studied in the Computer Logic Design,
memory is classified into RAM (Random Access
Memory) and ROM (Read-Only Memory)
RAM is classified into DRAM (Dynamic RAM) and SRAM
(Static RAM)
DDR is a DRAM
Short form of DDR (Double Data Rate) SDRAM (Synchronous
DRAM)
17
Korea Univ
assemble
18
Korea Univ
128
words
Instruction
Memory
Word
(32-bit)
initial
begin
$readmemh("memfile.dat",RAM);
end
Compiled
binary file
a[6:0]
2002000
5
2003000
c
2067fff7
00e2202
5
0064282
4
00a4282
0
10a7000
a
0064202
a
1080000
1
2005000
0
00e2202
a
0085382
0
00e2382
2
ac67004
4
8c02005
0
0800001
1
2002000
1
ac02005
4
rd[31:0] 32
memfile.dat
Depending on your needs, you can increase or decrease the memory size
Examples
19
Korea Univ
clk;
reset;
endmodule
// generate clock to sequence tests
initial
begin
clk <= 0;
forever #10 clk <= ~clk;
end
endmodule
20
Korea Univ
Synthesis
Try to synthesis pc and adder with
Quartus-II
21
Korea Univ