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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started