Question: Write a MIPS program that takes an array as input, where register 1 contains the starting address and register 2 contains the size ( number

Write a MIPS program that takes an array as input, where register 1 contains the starting address and register 2 contains the size (number of elements). The program should determine whether the array is strictly increasing with respect to a custom comparison procedure called compare.
That is, suppose we have an array A of length n, and a procedure called compare which takes two array elements as parameters, in registers 1 and 2. The compare procedure returns the value 1(in register 3) if the first parameter is considered "less than" the second parameter, and otherwise returns the value 0.
Then, your program must determine if compare(A[i], A[i+1])==1 for each i such that 0 i n-2. In other words, do the elements "strictly increase" according to the compare procedure? If so, store 1 in register 3. If not, store 0 in register 3. Then return to the loader.
Marmoset will provide the compare procedure and combine it with your program. For testing, you will need to write your own compare procedure, but you should not submit a compare procedure to Marmoset.
You may assume the array has at least two elements.
The compare procedure will begin with a label compare:. It takes its first parameter in $1 and its second parameter in $2. It returns the result of the comparison in $3. The result is 1 if the value in $1 is considered "less than" the value in $2, and otherwise, the result is 0. The compare procedure will preserve all registers except for $3.
Since you are writing a program in this question, not a procedure, you do not need to preserve any registers, except those that are necessary for your program to function correctly.
Marmoset will only check the final result in $3 to determine if your program is correct.
Thecompareprocedure will be consistent with a certain ordering of the array elements, but you do not know what this ordering is. For example, it is possible the procedure will return 1 for a pair of elements even if, when interpreted as integers, the first element isnotless than the second. Thecompareprocedure might be enforcing a different order on integers, or it may not be interpreting the values as integers at all! Thus, you must use thecompareprocedure to compare elements, rather than relying onsltorsltu.

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 Programming Questions!