PDF 2
PDF 2
ASSIGNMENT 1
Implement 5-stage MIPS pipelined processor in Verilog along with a hazard units which resolves
data hazards. This processor supports load word (lw), store word (sw), jump (j), set on less than
immediate (slti) and nor (nor) instructions only. The processor should implement forwarding to
resolve data hazards. The processor has Reset, CLK as inputs and no outputs. The processor has
instruction Fetch, Decode, Execution, Memory and Writeback units. The processor also contains
four pipelined registers IF/ID, ID/EX, EX/MEM and MEM/WB. When reset is activated the PC,
IF/ID, ID/EX, EX/MEM and MEM/WB registers are initialized to 0, the instruction memory and
register file get loaded by predefined values. When the instruction unit starts fetching the first
instruction the pipeline registers contain unknown values. When the second instruction is being
fetched in IF unit, the IF/ID registers will hold the instruction code for first instruction. When the
third instruction is being fetched by IF unit, the IF/ID register contains the instruction code of
second instruction, ID/EX register contains information related to first instruction and so on.
(Assume 32-bit PC. Also Assume Address and Data size as 32-bits)
The instruction and its 32-bit instruction format are shown below:
slti DestinationReg, S ourceReg, ImmediateData
Instruction format - Opcode:RS:RT/RD:IMMEDIATE
Opcode:-31:26
RS:-25:21
RT/RD:-20:16
IMMEDIATE:-15:0
Example:- slti R2,R0,2 ⇒ R2=R0 < 2
Opcode for slti = 6’d10
lw DestinationReg,SourceReg,Offset
Instruction format - Opcode:RS:RT/RD:IMMEDIATE
Opcode:-31:26
RS:-25:21
RT/RD:-20:16
IMMEDIATE:-15:0
Example:- lw R2,R0,2 ⇒ R2=DMEM[R0+2], Here DMEM stands for data memory
Opcode for lw=6’d35
j address
Instruction format - Opcode:Address
Opcode:-31:26
Address:-25:0
Example:- j 8 ⇒ PC = (PC + 4)[31:28] concatenated with 8 sign-extended to 28 bits [The resulting
value of the PC should be the highest 4 bits of the (PC + 4) concatenated with a 28-bit sign-
extended value of the operand].
Opcode for sw=6’d2
Assume the register file contains 32 registers (R0-R31) each register can hold 32-bit data. On reset
register file should get initialized such that R1 = 32, R2 = 28, R3 = 24 … R9 = 0 and R0, R10 to
R31 are initialized to 0. Ensure R0 is always 0. Each location in DMEM has 8 bit data. So, to store
a 32-bit value you need 4 locations in the DMEM, in big-endian format. The DMEM should get
initialized with values DMEM[0]=32’d0, DMEM[4]=32’d1, DMEM[8]=32’d2,.......,
DMEM[36]=32’d9. Here 32’dx stands for representing a decimal integer x as a 32-bits binary data.
On reset ensure that the instruction memory gets initialized with the following instructions, starting
at address 0:
slti R9,R4,16
slti R8,R3,4
lw R3,R9,0
nor R1,R7,R4
nor R2,R3,R6
L: jL
The above code should run correctly on the processor implementation. Ensure that you handle the
data hazards present, if any.
CL
K RESET
1. PDF version of this document with all the Questions below answered with the file name as
IDNO_NAME.pdf.
2. Design Verilog Files for all the Sub-modules (instruction fetch, Register file, forwarding unit).
______________________________________________________________________________
_______
1. Draw the complete Datapath and show control signals of the 5-stage pipelined processor.
Answer:
2. List the control signals used and also the values of control signals for different
instructions in a tabular format as follows:
Answer:
Answer:
4. Implement the Instruction Decode block. Copy the image of Verilog code of the
Instruction decode block here
Answer:
5. Implement the Register File and copy the image of Verilog code of Register file unit here.
Answer:
6. Determine the condition that can be used to detect data hazard?
1a. EX/MEM.RegWrite = 1
2b. MEM/WB.RegWrite = 1
Answer:
8. Implement complete processor in Verilog (using all the Datapath blocks). Copy the image
of Verilog code of the processor here. (Use comments to describe your Verilog
implementation)
Answer:
9. Test the processor design by generating the appropriate clock and reset. Copy the image
of your testbench code here.
Answer:
10. Verify if the register file is getting updated according to the set of instructions
(mentioned earlier).
Copy verified Register file waveform here (show only the Registers that get updated, CLK, and
RESET):
11. What are the total number of cycles needed to issue the program given above on the
pipelined MIPS Processor? What is the CPI of the program?
nor R2, R3, R6 Write backstage is considered for total no. of cycles required.
CPI=9/6=1.5.
12. Make a diagram of the pipelined processor executing each instruction in the program
given above. Also show in which cycles and instructions are stalls and forwarding required.
Answer:
13. Consider the following delay elements for the pipelined MIPS Processor. Which unit
should one consider for the greatest speedup of the overall processor? How fast should it
be? What is the cycle time of the improved processor?
Data memory should be considered for the greatest speedup of the overall processor.
Multiplexer tmux 25
AND tAND 15
Using the improved cycle time and the CPI of the program calculated in Question 11, find
the execution time of the program given above.
ET=6*1.5*200=1.8ns
Unrelated Questions
What were the problems you faced during the implementation of the processor?
Did you implement the processor on your own? If you took help from someone whose help
did you take? Which part of the design did you take help for?
Answer: I took some help from my friends for implementing Forwarding Unit.
Honor Code Declaration by student: