Question: CONVERT C-CODE INTO MIPS ASSEMBLY CODE /* Comments The function returns the index to the maximum value in array p. p is the starting address

CONVERT C-CODE INTO MIPS ASSEMBLY CODE

/* Comments The function returns the index to the maximum value in array p. p is the starting address of the array. n is the number of words in the array. The function returns -1 if n is less than 1 (no elements in the array). */

int find_max(int *p, int n) {

/* Define two variables. */

int maxi, i;

/* The array must have at least one element. */

if (n <= 0)

return -1;

/* Assume the first word (p[0], index is 0) is the largest at the beginning */

maxi = 0;

/* Check the rest of the words in the array, p[1], p[2], index i changes from 1 to n 1, n 1 is the last word in the array. if the word you are checking (p[i]) is larger than the current max you have found (p[maxi]), let maxi be i. */

for (i = 1; i < n; i = i + 1)

{

if (p[i] > p[maxi]) maxi = i;

}

return maxi;

}

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!