Project Instructions
Project Instructions
Objective:
The objective of this project is to design, simulate, and implement a simple 32-bit
microprocessor with an instruction set that is similar to a MIPS. Note: some of the details are
intentionally omitted. You must use what you have learned throughout the semester to complete
the project. You are free to implement the MIPS in VHDL any way that you like, as long as it can
execute the provided test programs.
Logistics:
As discussed in class, this is essentially a “mini-project”. It will be worth 350 points (3.5x more
than a normal lab). The grading is based on the completion of a list of deliverables. When
completed, each deliverable will earn the student some amount of points toward the total score
of 350. The list of deliverables, their due dates, and their worth in points will be described later.
Figure 2. General architecture of the MIPS CPU (see included files for more detailed view).
The datapath (the main rectangle in the middle of Figure 2) consists of:
● ALU : performs all the necessary arithmetic/logic/shift operations required to implement
the MIPS instruction set (see instruction set table at end of this document). The ALU
also implements the conditions needed for branches and asserts the “Branch Taken”
output if the condition is true. The ALU should have four inputs: two for the inputs to be
processed, one for a shift amount (shown as IR[10-6]), and one for the operation select.
You can use whatever select values you want for the operations, but I would recommend
looking over the encoding of the r-type instructions first to simplify the logic.
● Register File: 32 registers with two read ports and one write port.
● IR: The Instruction Register (IR) holds the instruction once it is fetched from memory
● PC: The Program Counter (PC) is a 32-bit register that contains the memory address of
the next instruction to be executed.
● Some special-purpose registers, including Data Memory Register, RegA, RegB,
ALUout, HI, and LO. These will be explained in lecture.
● Controller which controls all the datapath and the memory module. (The controller does
not control writing to the input ports). Note that the ALU is controlled by a separate
ALU Control unit that uses signals from both the main controller and the datapath. This
will be explained in lecture. The design of the controllers is one of the main tasks of this
project. You are welcome to add more control signals that are not shown in the datapath
figure.
● ALU Controller : controls the all the ALU Operations. This logic is up to you to figure
out, but it will become more clear after discussing the instructions in lecture.
● Memory: contains the RAM and memory-mapped I/O ports
● Sign Extended: convert a signed 16-bit input to its 32-bit representation when the signal
“isSigned” is asserted.
Execution steps
All instructions :
Step 1: - Fetch instruction, store in IR, PC = PC + 4
Step 2: - Decode instruction
- “Look ahead” steps: Read in rs and rt registers to A and B, respectively.
Compute target branch address using lower 16 bits of instruction -->
ALUOut
Memory access:
Step 3: - Compute memory address
Step 4: - If lw: Retrieve data from memory at specified address and place in MDR
- If sw: Write data (B register) to memory at specified address
Step 5 - (lw only): Write contents of MDR to specified register
R-type:
Step 3: - Perform specified operation --> ALUOut
Step 4: - Write ALUOut contents to specified register
Branch:
Step 3: - Compare two registers
- Use Zero/Branch output to determine if they are equal
- Determine if we branch to the address in ALUOut or to PC+4
NOTE: You must attend lab each week unless you have demoed all deliverables. Missing
a lab will result in -20 points. Unless you are completely finished, you have to stay and
work on the project with the help of your TA.
Week 1: At a minimum, you are to complete Deliverables 1, 2, and 3 by the end of the lab.
Deliverable 1 (15 points): Design and simulation of the ALU. No demonstration on the
board is necessary. Create a testbench that when simulated shows:
addition of 10 + 15
subtraction of 25 - 10
mult (signed) of 10 * -4. Make sure to show both the Result and Result Hi outputs shown
in the datapath.
mult (unsigned) of 65536 * 131072. Make sure to show both the Result and Result Hi
outputs shown in the datapath.
and of 0x0000FFFF and 0xFFFF1234
shift right logical of 0x0000000F by 4
shift right arithmetic of 0xF0000008 by 1
shift right arithmetic of 0x00000008 by 1
set on less than using 10 and 15
set on less than using 15 and 10
Branch Taken output = ‘0’ for for 5 <= 0
Branch Taken output = ‘1’ for for 5 > 0
Show synthesis results verifying no latches (-5 points). For week 1, use whatever select
values you want for each ALU operation, but make sure to have a table that specifies a
mapping between select values and operations to make it easy for the TA. Turn in all
files and the simulation waveform on Canvas.
Extra Credit (10 points): create an exhaustive testbench that tests every possible ALU
input combination using assert statements and show the TA that no assertions fail. For
this exhaustive test, reduce the width of the ALU to 8 bits or your simulation will never
finish.
Deliverable 2 (10 points): Design and simulation of the memory (RAM and ports).
Create a testbench that demonstrates the following:
Deliverable 3 (10 points): Design and synthesis of datapath. Show the datapath to the
TA using RTL viewer.
Week 2: At a minimum, you are to complete Deliverable 4 by the end of the lab.
Week 3: Turn in all files and the simulations on Canvas for each of the deliverables.
Deliverable 5 (100 points, 25 points each): Demonstrate test cases 1,2,4, and 7.
Deliverable 6 (65 points): Convert the GCD assembly code into a MIF file and
demonstrate the correct functionality on the board.
Selected Subset of MIPS Instructions (See Excel sheet for more details)
OpCode
Instruction Type Example Meaning
(Hex)
add - unsigned 0x00 R addu $s1, $s2, $s3 $s1 = $s2 + $s3
add immediate
0x09 I addiu $s1, $s2, IMM $s1 = $s2 + IMM
unsigned
sub unsigned 0x00 R subu $s1, $s2, $s3 $s1 = $s2 - $s3
0x10
sub immediate
(not I subiu $s1, $s2, IMM $s1 = $s2 - IMM
unsigned
MIPS)
mult 0x00 R mult $s, $t $HI,$LO= $s * $t
mult unsigned 0x00 R multu $s, $t $HI,$LO= $s * $t
and 0x00 R and $s1, $s2, $s3 $s1 = $s2 and $s3
andi 0x0C I andi $s1, $s2, IMM $s1 = $s2 and IMM
or 0x00 R or $s1, $s2, $s3 $s1 = $s2 or $s3
ori 0x0D I ori $s1, $s2, IMM $s1 = $s2 or IMM
xor 0x00 R xor $s1, $s2, $s3 $s1 = $s2 xor $s3
xori 0x0E I xori $s1, $s2, IMM $s1 = $s2 xor IMM
srl -shift right $s1 = $s2 >> H (H is bits
0x00 R srl $s1, $s2, H
logical 10-6 of IR)
sll -shift left $s1 = $s2 << H (H is bits
0x00 R sll $s1, $s2, H
logical 10-6 of IR)
sra -shift right
0x00 R sra $s1, $s2, H See XLS sheet
arithmetic
slt -set on less $s1=1 if $s2 < $s3 else
0x00 R slt $s1,$s2, $s3
than signed $s1=0
slti -set on less
$s1=1 if $s2 < IMM else
than immediate 0x0A I slti $s1,$s2, IMM
$s1=0
signed
sltiu- set on less
$s1=1 if $s2 < IMM else
than immediate 0x0B I sltiu $s1,$s2, IMM
$s1=0
unsigned
sltu - set on less $s1=1 if $s2 < $s3 else
0x00 R sltu $s1,$s2, $s3
than unsigned $s1=0
mfhi -move from Hi 0x00 R mfhi $s1 $s1= HI
mflo -move from LO 0x00 R mflo $s1 $s1= LO
load word 0x23 I lw $s1, offset($s2) $s1 = RAM[$s2+offset]
store word 0x2B I sw $s1, offset($s2) RAM[$s2+offset] = $s1
branch on equal 0x04 I beq $s1,$s2, TARGET if $s1=$s2, PC += 4+TARGET
branch not equal 0x05 I bne $s1,$s2, TARGET if $s1/=$s2, PC += 4+TARGET
Branch on Less Than
0x06 I blez $s1, TARGET if $s1 <= 0, PC += 4+TARGET
or Equal to Zero
Branch on Greater
0x07 I bgtz $s1, TARGET if $s1 > 0, PC += 4+TARGET
Than Zero
Branch on Less Than
0x01 I bltz $s1, TARGET if $s1 < 0, PC += 4+TARGET
Zero
Branch on Greater
Than or Equal to 0x01 I bgez $s1, TARGET if $s1 >= 0, PC += 4+TARGET
Zero
jump to address 0x02 J j TARGET PC = TARGET
jump and link 0x03 J jal TARGET $ra = PC+4 and PC = TARGET
jump register 0x00 R jr $ra PC = $ra
Useful for week 2
Fake instruction 0x3F Halt
deliverables