Starting from:
$35

$29

CS MIPS Single-Cycle Datapath and Controller Solution


Part 1 & 2. Preliminary Work (50 points)

For the preliminary work, you need to prepare a PDF file containing your answers to Part 1.a, 1.e, 1.f, 1.g and Part 2. You also need to put your MIPS code to you developed for Part 1.e to a txt file. As a result, you will submit two different files (one pdf, one txt).

Provide following five lines at the top of your submission for preliminary (both txt and pdf) and lab

work (make sure that you include the course no. CS224, important for ABET documentation).

CS224

Lab No.

Section No.

Your Full Name

Bilkent ID

Make sure that you identify what is what at the beginning of each program by using proper com-ments.

Important Notes

    1. Assume that all Inputs are Correct. In all lab works, if it is not explicitly stated, you may as-sume that program inputs are correct.



Instruc
Opcode
RegWrit
RegDst
ALUSrcA
ALUSrcB
Branch
Mem
MemToReg
ALU
Jump
tion

e




Write

Op












R-type
000000
1
01
0
0
0
0
00
10
0











srl
000000
1
01
1
0
0
0
00
10
0








































Figure 1: Datapath for Original12
Instruc
Opcode
RegWrit
RegDst
ALUSrcA
ALUSrcB
Branch
Mem
MemToReg
ALU
Jump
tion

e




Write

Op












lw
100011
1
00
0
1
0
0
01
00
0











sw
101011
0
X
0
1
0
1
XX
00
0











beq
000100
0
X
0
0
1
0
01
01
0











addi
001000
1
00
0
1
0
0
00
00
0











j
000010
0
X
X
X
X
0
XX
XX
1











jal
000011
1
10
X
X
X
0
10
XX
1












Table 1: Main Decoder for Original12

ALUOp
Funct
ALUControl



00
X
010 (add)



X1
X
110 (subtract)



1X
100000 (add)
010 (add)



1X
100010 (sub)
110 (subtract)



1X
100100 (and)
000 (and)



1X
100101 (or)
001 (or)



1X
101010 (slt)
111 (set less than)



1X
000010 (srl)
011 (srl)




Table 2: ALU Decoder for Original12



Part 1.

    a) [3 Points] Determine the assembly language equivalent of the machine codes given in the imem module in the ―Complete MIPS model.txt‖ file posted on Moodle for this lab. In the given

System Verilog module for imem, the hex values are the MIPS machine language instructions for a small test program. Dis-assemble these codes into the equivalent assembly language instructions and give a 3- column table for the program, with one line per instruction, containing its location, machine instruction (in hex) and its assembly language equivalent. [Note: you may do dis-assembly by hand or use a program tool.]

    b) Make a new Playground, giving it a meaningful name (from the ―Add a title to help you find your playground box in the share tab below), for your single-cycle MIPS-lite. Create design files for the SystemVerilog modules given in ―Complete MIPS model.txt‖, and Save everything (you don’t have to use Complete MIPS model.txt, you can write your code if you find it more convenient).

This file contains implementation of Original12 instructions in ―MIPS-lite‖ which are the following: add, sub, and, or, slt, lw, sw, beq, addi, j, jal, srl.

    c) Study the code and convince yourselves that the datapath module exactly corresponds to Figure 1 and controller module (including maindec and aludec modules) to Table 1 and Table 2. In the decoder tables, X means it is a ―don’t care‖. That is, it does not matter if it is 0 or 1. Although srl is an R-type instruction, in the Table 1, we added a new row for srl since its ALUSrcA bit is dif-ferent than other R-type instructions.

    d) [10 Points] Now make the changes in the code to support the ―jr‖ instruction whose neces-sary datapath and controller changes are given in the ―JR Changes‖ file.

    e) [10 Points] Now make a SystemVerilog testbench file on EDAPlayground and simulate your MIPS-lite processor executing the test program (Refer to How to Visualize Waveform in EdaPlayground). Do not change the instructions in the imem module use it as is. Study the gener-ated waveform. Find each instruction, and understand its values. Take a screenshot of the wave-form and paste it to the report. Your waveform should be similar to the below image (see Figure 2, some part of the image is obfuscated intentionally). Make sure that your output shows the exact same variables. Be aware that if you run the ―Complete MIPS Model.txt‖ without implementing ―jr‖ instruction you will see continuous X values towards the end.























Figure 2: Example Waveform




    f) [5 Points] Make some observations on the waveform that you generated. These questions assume that you have used imem module as is without modifying any instruction there.
        i) In an R-type instruction what does writedata correspond to?

        ii) Why is writedata undefined for some of the early instructions in the program?

        iii) Why is readdata most of the time undefined?

        iv) In an R-type instruction what does dataadr correspond to?

        v) Why does dataadr become undefined at some point?

    g) [2 Points] Make some observations on the architecture (see Figure 1).

        i) Do you need to make any changes to support srlv instruction?

        ii) Which module would you modify to support sll instruction? How would you modify it?



Part 2.
Section
MIPS instructions



1
Base: Original12 +
―jr‖

New: ―sw+‖




2
Base: Original12  +
―jr‖

New: ―subi‖




3
Base: Original12  +
―jr‖

New: ―jalm‖




4
Base: Original12 +
―jr‖

New: ―bge‖




5
Base: Original12 +
―jr‖

New: ―ble‖




6
Base: Original12 +
―jr‖

New: ―jm‖





Table 3: Section-wise distribution of the instructions


Instructions in quotes (e.g. ―subi‖, except for ―jr‖) are not defined in the MIPS instruction set. They don’t exist in any MIPS documentation; they are completely new to MIPS. You will create them, according to the definitions below, then implement them.

subi: this I-type instruction subtracts, using a sign-extended immediate value. Example: subi $t2, $t7, 4

jm: this I-type instruction is a jump, to the address stored in the memory location indicated in the

standard way. Example: jm 40($s3)

jalm: this I-type instruction is a jump, to the address stored in the memory location indicated in the

standard way. But it also puts the return address into the register specified. Example: jalm $t5, 40($s3)

bge, ble: these I-type instructions do what you would expect—branch to the target address, if the

condition is met. Otherwise, the branch is not taken. Example: bge $t2, $t7, TopLoop

sw+: this I-type instruction does the normal store, as expected, plus an increment (by 4, since it is a

word transfer) of the base address in RF[rs]. {Note: these kind of auto-increment instructions are

useful when moving through an array of data words.} Example: sw+ $t0, 4($t1)

    a) [2 Points] Register Transfer Level -Language- (RTL) expressions for the new instruction that you are adding (see Table 3), including the fetch and the updating of the PC.

    b) [10 Points] Make any additions or changes to the datapath which are needed in order to make the RTLs for the instructions possible. The base datapath should be in black, with changes marked in red. Make your changes on “Final Datapath.png” file.

    c) [8 Points] Make a new row in the main decoder table for each new instruction being added, and if necessary, add new columns for any new control signals that are needed (input or output). You can use any opcode value you want unless it conflicts with the existing opcodes in the Table 1.
Be sure to completely fill in the table—all values must be specified. Make your changes on the Main Decoder Table at the “JR Changes” document. If any changes are needed in the ALU de-coder table (Table 2), give this table in its new form (with new rows, columns, etc). The base table should be in black, with changes marked in red. {Note: if you need new ALUOp bits to encode new values, you should also give a new version of Table 2, showing the new encodings}

Part 3. Lab Work (50 points)

For the lab work, you only need to submit resulting code file in the txt format.

Part 3.

    a) [50 Points] Now make necessary changes to your ―Complete MIPS model.txt‖ code so that it supports the instruction assigned to your section (refer to Table 3, you already implemented ―jr‖ in the form of a prelim work, you ought to implement the section-specific instruction for this part). You will code up the changes that you proposed in the Part 2. Note that the Original12 and ―jr‖ instruction should still work. That is, at this stage your MIPS architecture should be able to support Original12, jr and the assigned instruction.

    b) You can prepare a test MIPS program yourself to see if your architecture works correctly. In the lab day, we will provide you with our test program and grade you based on that.

Aim to complete lab part at home before coming to the online lab.

Part 6. Submit Your Code for MOSS Similarity Testing

    1. Submit your Lab Work MIPS codes for similarity testing to Moodle.

    2. You will upload one file. Use filename Studen-

tID_FirstName_LastName_SecNo_LAB_LabNo.txt

    3. Only a NOTEPAD FILE (txt file) is accepted. No txt file upload means you get 0 from the lab. Please note that we have several students and efficiency is important.

    4. Even if you didn’t finish, or didn’t get the MIPS codes working, you must submit your code to the Moodle Assignment for similarity checking.

    5. Your codes will be compared against all the other codes in the class, by the MOSS program, to determine how similar it is (as an indication of plagiarism). So be sure that the code you submit is code that you actually wrote yourself !

Part 7. Lab Policies (Reminder)

    1. As indicated in Lab1: Attendance is mandatory and the preliminary work is graded only if you submit your lab work with the observation/permission of your TA.

    2. You can do the lab only in your section. Missing your section time and doing in another day is not allowed.

    3. The questions asked by the TA will have an effect on your lab score.

    4. Lab score will be reduced to 0 if the code is not submitted for similarity testing, or if it is plagia-rized. MOSS-testing will be done, to determine similarity rates. Trivial changes to code will not hide plagiarism from MOSS—the algorithm is quite sophisticated and powerful. Please also note that obviously you should not use any program available on the web, or in a book, etc.

since MOSS will find it. The use of the ideas we discussed in the classroom is not a problem.

Your lab attendance is tracked by the Zoom system. Please also see lab policies no. 1 item.

More products