Documente Academic
Documente Profesional
Documente Cultură
REPORT LAB 3
Group 1:
L Vn V An
Ng Thanh Quang
Trn Phc T Tm
Class: 11ES
Page 1 of 20
Table of Contents
I.
Introduction.................................................................................................... 3
II.
Implementation .............................................................................................. 3
1. Overview.......................................................................................................... 4
2. Multiplexer 2to1 (5bit) .................................................................................... 5
3. Multiplexer 2to1 (32bit) .................................................................................. 6
4. Module Shift left 2 ........................................................................................... 6
5. Module Extension ............................................................................................ 7
6. Adder 32bit ...................................................................................................... 8
7. Program Counter .............................................................................................. 8
8. ALU Control .................................................................................................... 9
9. MIPS Controller............................................................................................. 10
10.How it works.................................................................................................. 12
11.Simulation ...................................................................................................... 12
III.
Conclusion .................................................................................................... 20
Page 2 of 20
I.
Introduction:
Controller
ALU/ALU control
Registers
Instruction Memory
Data Memory
Instruction and Data memory are already available, not to mention the
implementation of register file and ALU are handled in previous labs. Therefore,
we only need to implement the main controller, ALU control and a few
connections to put all things together.
Page 3 of 20
II.
Implementation:
1. Overview:
The figure above indicates a MIPS processor that is capable of handling the
following instructions: LW, SW, J, BNE, XORI, ADD, SUB, and SLT.
However, according to the requirement, this processor must be able to process
the JR instruction. To solve this problem, we add a few lines and blocks to the
figure above, which is illustrated below.
Page 4 of 20
Before moving on to the essential blocks which constitute the whole MIPS
processor, lets take a look at the smaller blocks first.
Page 5 of 20
The way to implement this Mux is quite familiar as we already mentioned in the
previous lab. Firstly, we create a Mux2to1. Then by combining 5 of this Mux,
we have a Mux2to1 (5bit).
3. Multiplexer 2to1 (32bit)
Page 6 of 20
b. 26bit to 28bit:
5. Module Extension
a. Zero extension:
b. Signed extension:
Page 7 of 20
6. Adder 32bit:
Note: The Verilog code for D_FF (D flip flop) is in the regfile.v
Page 8 of 20
8. ALU Control:
Instruction
ALUOp
Load/Store
00
XOR
01
BNE
10
10
R
11
JR
Function
ALUCtrl
00 (Add)
01 (Xor)
10 (Sub)
XX
100000
00 (Add)
100010
10 (Sub)
101010
11 (SLT)
001000
XX
Page 9 of 20
9. MIPS Controller:
Basically, this controller handles all the controlling signals for the above blocks
and modules.
We implement the controller based on this table with corresponding values.
Instruction
ADD
SUB
SLT
JR
LW
SW
BNE
XORI
RegDst
ALUSrc
MemToReg
RegWrite
MemRead
MemWrite
Branch
Jump
JumpReg
SignEx
Opcode
Funct
1
0
0
1
0
0
0
0
0
0
0x00
0x20
1
0
0
1
0
0
0
0
0
0
0x00
0x22
1
0
0
1
0
0
0
0
0
0
0x00
0x2A
0
0
0
0
0
0
1
0
1
0
0x00
0x08
0
1
1
1
1
0
0
0
0
1
0x23
xx
x
1
x
0
x
1
0
0
0
1
0x2B
xx
x
0
x
0
x
0
1
0
0
1
0x05
xx
0
1
0
1
x
0
0
0
0
0
0x0E
xx
x
x
x
0
x
0
1
1
0
x
0x02
xx
Page 10 of 20
Note: By applying SOP (Sum of Product) for ALUOp, the value of ALUOp is
as following:
ALUOp[1]: BNE + R + J + JR
ALUOp[0]: XORI + R + JR
Page 11 of 20
10.How it works:
The explanation of how the MIPS (single cycle) functions is described in detail
in the textbook.
Reference:
MK Computer Organization and Design 5th Edition (Oct 2013) Start with
section 4.
Therefore, it is not necessary to explain it again in this report.
Now we come to an interesting part simulation.
11.Simulation:
For this section, we will show the illustrations corresponding to specific
instructions handled by the MIPS processor (LW, SW, J, BNE, XORI, ADD,
SUB, and SLT).
To begin with, we would like to start with LW and SW. Since these instructions
have relation to the Data Memory, there is something tricky here.
Take a look at these examples:
sw $13, 0($18)
lw $20, 0($18)
For the MIPS to deal with these instructions, there must have some values in
register $18 which is the address of memory location pointed to.
According to this function call:
To get the value of ReadData, ALUResult and ReadData2 must have values as
well.
Register file is the module that decides whether ReadData2 has value or not.
Page 12 of 20
Before the LW and SW instructions, $16, $17 and $18 had not been used. We
can conclude that:
Case #1: MIPS processor will work just fine with LW and SW since $16,
$17 and $18 already have initial value (zero).
Case #2: MIPS processor cannot handle LW and SW instructions as there
is no value in those three registers.
Therefore, for these examples:
sw $13, 0($18)
lw $20, 0($18)
Page 13 of 20
Only in the case #1, the MIPS processor can work properly with the file
instr.dat for LW, SW instructions since $18 (mentioned above) has initial
value 0.
Note: We attached two regfile (one with controlling signal reset and another
does not have) so you can use those files respectively to compare the results
between two cases (case #1 and case #2). Remember to adjust the function call
regfile before change the regfile.
sw $13, 0($18)
Case #1: $18 has initial value (zero).
Page 14 of 20
lw $20, 0($18)
Case #1: $18 has initial value (zero).
Page 15 of 20
c. Jump (J):
j 0x00400070
In this case, the PC (PC_In) must be 0x00400070 and the instruction will be
0x0810001C.
Page 16 of 20
ALUOp = 2b10
ALUCtrl = 2b10
Page 17 of 20
e. XORI:
f. ADD:
ALUOp = 2b11
ALUCtrl = 2b00
WriteData to $11: 5 + 6 = 11
Page 18 of 20
g. SUB:
ALUOp = 2b11
ALUCtrl = 2b10
WriteData to $13: 14 1 = 13
h. SLT:
$2 = 1 while $0 has value zero. Since $2 > $0, $21 will get value 0.
We can see that WriteData to $21 = 0 as expected.
Page 19 of 20
III.
Conclusion:
According to the simulation section, we can conclude that our design for MIPS
single cycle works properly with no problem so far. Although there exist some
signal delay, it still does not affect the overall results.
One thing that causes trouble for us is the file instr.dat. To have our design works
with this file (LW and SW in particular), we have to change our regfile.v a bit and
this is not comfortable.
In brief, we got much experience after handling this lab. We can comprehend
thoroughly how the instructions are dealt with as well as the functions of the
internal parts which constitute the processor.
Page 20 of 20