Question: The following high-level language procedure recursively performs a binary search for a key within an array of sorted (ascending) integers. Translate this procedure into MIPS

The following high-level language procedure recursively performs a binary search for a key within an array of sorted (ascending) integers. Translate this procedure into MIPS code. Write a main procedure to dynamically allocate an array of n integers (n is a user input that must be greater than 1), read an array of n sorted (ascending) integers, print the array of n sorted integers, print the index of the matching element if the key is found, otherwise print the value -(index where the key can be inserted). You need to write procedures for reading and printing the array, and pass parameters properly a MIPS convention. ccording to the Search sortedArray[first]..sortedArray[last] for key. index of the matching element if it finds key, otherwise - (index where it could be inserted) sortedArray: array of sorted (ascending) integers first, last: lower and upper subscript bounds. integer to search for. // procedure // returns: // parameters: // key: int BinarySearch (int sortedArray[], int first, int last, int key) f if (first last) { int mid = (first + 1ast) / 2; // compute mid point. if (key sortedArray[mid]) return mid; return BinarySearch(sortedArray, first, mid-1, key); return BinarySearch(sortedArray, mid+1, last, key); else if (key
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
