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 IPpartasm 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 $s and N in $s Thus the translations of those variables in
MIPS are $s and $s respectively. You will need a new $s registers for all other Java variables.
Remember do not reuse $s or $s 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 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 ; j N; j
int i j;
for int k j; k N; k
if arri arrk
i k;
int tmp arri;
arri arrj;
arrj tmp;
Step by Step Solution
There are 3 Steps involved in it
1 Expert Approved Answer
Step: 1 Unlock
Question Has Been Solved by an Expert!
Get step-by-step solutions from verified subject matter experts
Step: 2 Unlock
Step: 3 Unlock
