Question: How could this be translated into MIPS Assembly from C? #include int lookup(int arr[], int num, int cnt){ for(int i = 0; i if(arr[i] ==
How could this be translated into MIPS Assembly from C?
#include
int lookup(int arr[], int num, int cnt){
for(int i = 0; i
if(arr[i] == num){
printf(" %d", i); return I;
}
}
printf(" -1");
return -1;
}
int main() {
int arr[] = {5,2,1,4,6,3};
lookup(arr,5,3);
lookup(arr,1,3);
lookup(arr,7,6);
lookup(arr,4,3);
return 0;
}

You will implement a simple function, lookup (int arr[], int num, int cnt). The function finds the integer value (num) from the integer array (arr). The last argument (cnt) is used to set the last index of array to be checked. The function returns the index of array if num is found in arr, else -1. For example, assume an array arr[] = 521 4 63 Return values for each function call. 1. lookup (arr, 5, 3) = 0 (the index of '5' in the array) 2. lookup (arr, 1, 3) 2 (the index of 'l' in the array) 3. lookup (arr, 7, 6) +-1(*7' is not found in the array) 4. lookup (arr, 4, 3) +-1 (the last parameter indicates to check only first 3 values in the array) The main function will call lookup to see if the integer array (arr) stores the integer value (num)
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
