Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

Please help write a MIPS program that: 1.Place the given array in memory: my_arr

ID: 3591938 • Letter: P

Question

Please help write a MIPS program that:

1.Place the given array in memory: my_array=[1,4,5,7,9,12,15,17,18,20,21,30]

2.Place the size of the array in memory: array_size=11

3.Load the base address of your array into $s0 using ‘la’ and load the size of your array into $s1 using ‘lw’

4.Write a function: binary_search to perform binary search on my_array. The function will take the following 3 inputs from registers in main:
<1> the base address of the array from $s0
<2> size of the array from $s1 and

<3> the element you’re searching for in the array from $s2. It will return the index of the element search for in $v0.

5. Run

the following 4 tests in main to check the correctness of your code:

(a) Perform binary_search to find the index of element ‘15’ and save the index on $s3

(b) Perform binary_search to find the index of element ‘4’ and save the index on $s4

(c) Perform binary_search to find the index of element ‘30’ and save the index on $s5

(d) Perform binary_search to find the index of element ‘0’ and save the index i.e. (-1) onto $s6. Since ‘0’ is not in my_array, the binary_search should return (-1) as the index.

Explanation / Answer

//Returns the number of days in month (in year) public static int daysIn (int month, int year) throws IllegalArgumentException { if (year < 1) throw new IllegalArgumentException ("daysIn: year ("+year+") not positive"); if (month DECEMBER) throw new IllegalArgumentException ("daysIn: month ("+month+") not in range [1,12]"); //Thirty days hath September, April, June and November... if (month == APRIL || month == JUNE || month == SEPTEMBER || month == NOVEMBER) return 30; //...all the rest have thirty one... else if (month == JANUARY || month == MARCH || month == MAY || month == JULY || month == AUGUST || month == OCTOBER || month == DECEMBER) return 31; //...except February (must be FEBRUARY in else: see possible exception) else /* if (month == FEBRUARY) */ return 28 + (isLeapYear(year) ? 1 : 0); } //Returns the ordinal (1st, 2nd, 3rd, etc) representing month, day, year public static int ordinalDate (int month, int day, int year) { int ordinal = 0; //Scan every earlier month, summing the # of days in that month... for (int m=JANUARY; m