Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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:

int tmp = nums[i];

nums[i] = nums[j];

nums[j] = tmp;

We will assume i has already been loaded into register $s1 and j into $s2 (I have code that sets $s1 to 2 and $s2 to 5, but it should work for any i and j between 0 and 11). You may use any available $s register for tmp (Remember $s1 and $s2 are currently occupied, as are $s0 and $s5). Use temporaries as appropriate (do not overwrite variables with intermediate results).

Your job is to translate the above code to MIPS, within the block labeled PUT SWAP CODE HERE. If you keep $s1 at 2 and $s2 at 5 the code should swap elements 2 and 5 (which are the third and sixth elements of the array). You can check this by viewing the state of the RAM in MARS after the program runs.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Database Application Development And Design

Authors: Michael V. Mannino

1st Edition

0072463678, 978-0072463675

More Books

Students also viewed these Databases questions

Question

Explain the strength of acid and alkali solutions with examples

Answered: 1 week ago

Question

Introduce and define metals and nonmetals and explain with examples

Answered: 1 week ago

Question

Understand why empowerment is so important in many frontline jobs.

Answered: 1 week ago