Question: 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 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

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