Question: Consider the following C code snippet.? (a) Implement the C code snippet in MIPS assembly language. Use $s0 to hold the variable i. Be sure
Consider the following C code snippet.?
![// C code void setArray (int num) { int i; int array[10];](https://dsd5zvtm8ll6.cloudfront.net/si.experts.images/questions/2022/11/636a7bda9e4a0_906636a7bda8dbf3.jpg)
(a) Implement the C code snippet in MIPS assembly language. Use $s0 to hold the variable i. Be sure to handle the stack pointer appropriately. The array is stored on the stack of the setArray function.(b) Assume setArray is the first function called. Draw the status of the stack before calling setArray and during each function call. Indicate the names of registers and variables stored on the stack, mark the location of $sp, and clearly mark each stack frame.(c) How would your code function if you failed to store $ra on the stack?
// C code void setArray (int num) { int i; int array[10]; for (i = 0; i < 10; i = i + 1) { array[i] = compare(num, i); } } int compare(int a, int b) { if (sub(a, b) >= 0) return 1; else return 0; } int sub(int a, int b) { return a - b;
Step by Step Solution
3.45 Rating (165 Votes )
There are 3 Steps involved in it
a b c If ra were never stored on the stack the compare function would return to the instruction afte... View full answer
Get step-by-step solutions from verified subject matter experts
