PLEASE INCLUDE ALL COMMENTS AND OUTPUT PLEASE USE $s0 TO STORE THE ADDRESS OF TH
ID: 3593355 • Letter: P
Question
PLEASE INCLUDE ALL COMMENTS AND OUTPUT
PLEASE USE $s0 TO STORE THE ADDRESS OF THE ARRAY
PLEASE USE $SP
Given this starter code:
.data
array: .word 2 19 3 8 6 54 34 17
size: .word 8
.text
la $s0,array
1) Implement Insertion Sort using MIPS in-place
PLEASE INCLUDE ALL COMMENTS AND OUTPUT
PLEASE USE $SP
THANKS
Explanation / Answer
. # Procedure: bubbleSort 2. # Objective: sort an array of integer elements in nondecreasing order 3. # Input: an address of an array of integers 4. # Output: an array sorted in nondecreasing order 5. 6. bubbleSort: 7. 8. move $t0, $a0 # move address of the array into $t0 9. li $s0, 1 # boolean swap = false. 0 --> false, 1 --> true 10. li $t1, 0 # j = 0; 11. li $t2, 0 # i = 0; 12. li $s1, 9 # array length 13. loop: 14. beqz $s0, exit # exit if swap = false 15. li $s0, 0 # swap = false; 16. addiu $t1, $t1, 1 # j++; 17. move $t2, $0 # i = 0; 18. subu $s2, $s1, $t1 # s2 = length - j 19. forLoop: 20. bge $t2, $s2, exitForLoop # if i>=s2, exit 21. lw $a0, 0($t0) # a0 = array[i] 22. lw $a1, 4($t0) # a1 = array[i+1] 23. ble $a0, $a1, update # if array[i] 31. j forLoop 32. exitForLoop: 33. j loop 34. exit: 35. jr $raRelated Questions
Hire Me For All Your Tutoring Needs
Integrity-first tutoring: clear explanations, guidance, and feedback.
Drop an Email at
drjack9650@gmail.com
drjack9650@gmail.com
Navigate
Integrity-first tutoring: explanations and feedback only — we do not complete graded work. Learn more.