Practice 3: Let’s compile following C sequence for MIPS and run on the emulator: int divide(int N, int M) { // map q and i to $s2 and $s3 int q = 0; int i = N; while(i > 0) { q += 1; i = i - M; } return q; } int multiply(int N, int M) { // map sum and i to $s0 and $s1 int sum = 0; for(int i = 0; i < N; ++i) { sum += M; } return sum; } int main() { // map a, b, c, k, and j to $s0, $s1, $s2, $s3, and $s4 int a = 4; int b = 5; int c = 120; int k = multiply(a, b); int j = divide(c, k); } Make sure multiply procedure properly gets backup of $s0 to $s4. Verify that after running this sequence: • value of S0 is (4)10 • value of S1 is (5)10 • value of S2 is (120)10 • value of S3 is (20)10 • value of S4 is (6)10 When ready, copy your MIPS assembly code from emulator and save as a text file.
Practice 3: Let’s compile following C sequence for MIPS and run on the emulator:
int divide(int N, int M)
{
// map q and i to $s2 and $s3
int q = 0;
int i = N;
while(i > 0)
{
q += 1;
i = i - M;
}
return q;
}
int multiply(int N, int M)
{
// map sum and i to $s0 and $s1
int sum = 0;
for(int i = 0; i < N; ++i)
{
sum += M;
}
return sum;
}
int main()
{
// map a, b, c, k, and j to $s0, $s1, $s2, $s3, and $s4
int a = 4;
int b = 5;
int c = 120;
int k = multiply(a, b);
int j = divide(c, k);
}
Make sure multiply procedure properly gets backup of $s0 to $s4. Verify that after running this sequence:
• value of S0 is (4)10
• value of S1 is (5)10
• value of S2 is (120)10
• value of S3 is (20)10
• value of S4 is (6)10
When ready, copy your MIPS assembly code from emulator and save as a text file.
Step by step
Solved in 5 steps with 2 images