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
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started