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 contains the starting address and register 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 and The compare procedure returns the value in register if the first parameter is considered "less than" the second parameter, and otherwise returns the value
Then, your program must determine if compareAi Ai for each i such that i n In other words, do the elements "strictly increase" according to the compare procedure? If so store in register If not, store in register 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 $ and its second parameter in $ It returns the result of the comparison in $ The result is if the value in $ is considered "less than" the value in $ and otherwise, the result is The compare procedure will preserve all registers except for $
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 $ 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 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
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
