Question: Convert into MIPS for (int i = size-1; i > 0; i--) for (int j = 0; j < i; j++) { if (nums[j] >

Convert into MIPS

for (int i = size-1; i > 0; i--) for (int j = 0; j < i; j++) { if (nums[j] > nums[j+1]) { int tmp = nums[j]; nums[j] = nums[j+1]; nums[j+1] = tmp; } } }

use following MIPS code

#int tmp = nums[j]; #nums[j] = nums[j+1]; #nums[j+1] = tmp; sll $t0, $s1, 2 # sll Shift left logical add $t0, $s1, $s0 # this is for j lw $s2, 0($t0) # Since tmp is a variable, it must be a register. Since nums is an array, nums[j]is in RAM. The code #takes nums[j]and puts it in tmp. It therefore is taking RAM and putting it in a register (so, a lw).

addi $t1, $t0, 4 # address of j+1 lw $t2, 0 ($t1) # Repeat line 65 also using lw sw $t2, 0($t0) # nums[j+1] to nums[j] sw $s2, 0($t1) # tmp to nums[j+1]

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!