Question: Task: At the point in IP 1 . part 2 . asm marked PUT SELECTION SORT CODE HERE , translate the following lines of code,

Task: At the point in IP1.part2.asm marked PUT SELECTION SORT CODE HERE, translate the following
lines of code, which run selection sort in Java, to MIPS:
int i, j, k; // Assume arr and N declared and initialized
Translating: Variables to Registers
I mentioned that I already stored arr in $s0, and N in $s1. Thus the translations of those variables in
MIPS are $s0 and $s1, respectively. You will need a new $s registers for all other Java variables.
Remember do not reuse $s0, or $s1- or you will overwrite arr and N. I suggest the next available
$s registers. Importantly:
$t registers (being temporary) can lose their contents if a function is called.
Subtracting A Constant
Note the outer loop involves subtracting a constant: N 1. MIPS has add and sub instructions for
adding and subtracting two registers, and an addi instruction for adding a register and a constant.
However, MIPS does not have a subi instruction. Thus:
for (int j =0; j < N-1; j++)
{
int i = j;
for (int k = j+1; k < N; k++){
if (arr[i]>= arr[k]){
i = k;
}
}
int tmp = arr[i];
arr[i]= arr[j];
arr[j]= tmp;
}

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!