Answered step by step
Verified Expert Solution
Question
1 Approved Answer
Swap Code Central to many sorting algorithms is the ability to swap array elements that are in the wrong order. Since we have not yet
Swap Code Central to many sorting algorithms is the ability to swap array elements that are in the wrong order. Since we have not yet covered conditional (if) statements in MIPS and we would need that to check for ordering, we will for now just concern ourselves with swapping two elements i and j, i.e. in Java. Task: At the point in IP1.part2.asm marked "PUT CODE HERE FOR SWAP", translate the following lines: int tmp = nums[i]; nums [i] = nums [j]; nums [j] = tmp; to MIPS. You can assume that the starting address of nums is in $50, i is in $51, and j is in $s2. Note: Your code should work for any i and ; between 0 and 11. Some points to remember: 1. You will need another $s register for tmp. Remember do not use $50, $sl, or $s2 - or you will overwrite nums, i, and j. Also do not use $85, as that is the size. Remember: Variables in MIPS should always use $s registers. This is important, as I outlined in lecture - $t registers (being "temporary") can lose their contents if a function is called
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