Write the equivalent MIPS assembly code for the C-code shown above. Add comments to your assembly code.

Faculty of Science, Engineering and Computing

Title of Assignment: Computer architecture

Coursework Details
Coursework Aim
This exercise will allow you to write programs in the language of the computer.

Submission details

Submission of coursework will be performed using Turnitin on Canvas. You need to upload two files:
-the first file is a Word document that includes the answers to the Q1, Q2 and Q3 below.
-the second file is the MIPS programs for the assignment problem. Upload your files to the submission boxes within the Assignments page of the Canvas module by midnight of the day of the deadline.

Coursework Brief

The coursework consists of one program with three questions to answer: Q1, Q2 and Q3. You should compile your answers to Q1, Q2 and Q3 and related discussion in a document to submit to Canvas. Please add a front page to the document showing your name, student number, module title and code, and assignment title.

The C program shown in the Appendix will add the coursework array marks to the exam array marks and store them in the results array. Assume the number of students is 10. The program will then increase the marks in the results array if half of the students fail. Note that CURVE is a function called by the main program. Finally, the program will create counters for the number of students with a result >= 70, >=60, >=50 and < 50.

Q1 Use the MIPS instruction set and the MARS MIPS simulator to:
(i) Write the equivalent MIPS assembly code for the C-code shown above. Remember to add comments to your assembly code.
(ii) Test the assembly code program via the MARS MIPS simulator.
(iii) Show the assembly code and all test results of running the assembly code in the report.

Q2 Consider the basic MIPS 5-stage pipeline (IF, ID, EX, MEM, WB). Assume that there is full forwarding and branch not taken.

(i) Show the pipeline execution table of your code from Q1.

(ii) Based on the pipeline execution table, does your solution in Q1 have any pipelining hazards?
If yes, then list these hazards and show how these hazard(s) can be resolved by rewriting the code you produced in Q1. You should test the rewritten code and provide the new code and the results in the report.

If your code from Q1 does not have any pipeline hazards, discuss why this is the case and how did you resolve the pipeline hazards issues in Q1.

Q3 Performance measurement.

(i) How many instructions will be executed for your code in Q1 without optimisation?

(ii) Optimise using inline expansions and loop unrolling to use a minimum number of instructions in to run your assembly code and explain the methods done.

(iii) How many instructions will be executed for your code with optimisation conducted?

Appendix

// ————
// MAIN PROGRAM
// ————

int a, b, c, f; // Declare results counters
int i; // Declare loop counter
int y; // Declare total number of students
y = 10; // Initialize y = 10
a=0; b=0; c=0; f=0; // Initialize results counters
int coursework []; // Coursework is an array to store
// the coursework marks that goes
// from 0 to 50.
int exam []; // Exam is an array to store the exam
// marks that goes from 0 to 50.
int results []; // Results is an array to store the
// total marks = coursework + exam. // It goes from 0 to 100.

for (i=0; i<y; i++) {
results [i] = coursework [i] + exam [i];
if (results[i] < 50) f = f + 1; } // ——————————————————- // If the number of failed students is greater than half of // the class size (h) then subtract the highest mark in the // results array from 100 and (via the CURVE function) add the // difference (d) to every mark in the results array // ——————————————————- int h; // half of the class size int d; h=5; // half of the results items = 5 if (f > h) {

d = ??; // d = 100 – the highest
// mark in your results array

for (i=0; i<y; i++) { CURVE(results, i, d); } } //———————————————————- // Finally the program will create counters for the number of // students with a result >=70, >=60, >=50 and < 50
//———————————————————-

f = 0;
for (i=0; i<y; i++) { if (results[i] >= 70)
a = a + 1;
else if(results[i] >= 60)
b = b + 1;
else if(results[i] >= 50)
c = c + 1;
else
f = f + 1;
}

// Main program code ends here
// —————————-

// ——————
// CURVE function code
// ——————

void CURVE (int p[], int z, int k)
{
p[z] = p[z] + k;
}