Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Write subprograms allocate_array, array_contains, and print_nth read_array and print_array have been (mostly) completed for you -- you just need to write the code to retrieve
- Write subprograms allocate_array, array_contains, and print_nth
- read_array and print_array have been (mostly) completed for you -- you just need to write the code to retrieve the arguments IN and put them in the proper registers (hint: look at the TODO comments)
- Write the calls to allocate_array, read_array, and print_array in main
- The other calls have been done for you -- you should put the necessary code by the relevant TODO sections in main
- Store the base address and the length obtained from allocate_array into the provided integer variables
- array_contains does not have to be an efficient search algorithm
- Return the first instance of the number if it is found, or -1 if it is not in the array
- print_nth should return the number found at the provided index
- You can assume the given index is a valid index -- the logic to handle invalid indices is already provided for you in main
- Arrays in MIPS start at "index" 0
- RECALL: given an array base address in a register (say $t0), the format to obtain a value from a memory address is as follows:
lw $t1, 0($t0)
Where $t1 contains the value in the array once the instruction has been executed. We cannot replace the offset 0 with a register, as this will give a syntax error, so you will need to alter the base address itself.
To find the correct location, you will need to multiply the index with the number of bytes each integer takes up in memory (4), and add that to the base address to get the correct position.
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started