Questions about MIPS Programming and Calling Conventions

 

 

Below are the questions. You can also check the questions in the attachment.

1. Read the description of the simplified MIPS calling convention here: https://ucsb-cs64.github.io/w20/info/calling_convention/
Work through the examples and make sure you understand the pain points it seeks to avoid

2. [ Basic ] Translate the following to MIPS instructions, minimize the number of instructions: f = g + h + i + j; f = g + (h + 5);

If f, g, h, i, and j equal 1, 2, 3, 4, 5, then what is the final value of f?

3.[ Accessing memory ] Translate the following to MIPS instructions, minimize the number of instructions: f = g + h + B[4]; g = g – A[B[4]]; Assume f, g, h, i, and j are assigned to $s0, $s1, $s2, $s3, and $s4. Also assume the base (starting) address of arrays A and B are in registers $s6 and $s7

4. [ Loops and branches ] Translate the following to MIPS instructions, minimize the number of instructions. You must use branch instructions, think about how to implement loops using the control (branch/jump) instructions. Two loops are given in C, implement them separately. for(i=0; i < 10; i++){ a += b; } while (a < 10){ D[a] = b + a; a += 1; }

5. [ Recursive functions ] Implement factorial (code below) in the MIPS ISA. Pay careful attention to the return address register. int fact (int n){ if (n < 1){ return 1; } else{ return (n × fact( n – 1 )); } }

 

 

This question has been answered.

Get Answer