Question
please trace this is sort program and base address s0, number of element s1
please also complete the program(..)
explain the program too thanks
sit $t4, $t1, $to beq $t4, $zero, Skip sll $s1, $s1, 2 add $s2, $s0, $s1 addi $t2, $so, 0 Skip: oopl: addi $t3, $t2, 0 oopJ:
0 0
Add a comment Improve this question Transcribed image text
Answer #1

Complete sorting program along with comment :- (it's actually MIPS implementation of bubble sort)

sll $s1, $s1, 2       #count the offset value of the last element
add $s2, $s0, $s1   #store the address of end of the array
addi $t2, $s0, 0   #store the starting address of the array

LoopI:                        #Outside loop
   addi $t3, $t2, 0       #store the starting address of the array
LoopI:                        #Inside loop
   addi $t3, $t3, 4       #poiniting to next element address
   beq $t3, $s2, NextI   #condition for checking the end of the array
   lw $t0, 0($t2)       #loading the value at address pointed by $t2
   lw $t1, 0($t3)       #loading the value at address pointed by $t3
   slt $t3, $t1, $t0       #comparing two values; if value of $t1 is less than set value in $t4
   beq $t4, $zero,Skip   #checking for value in $t4 is set or not;if not then swap the values in memory
                           #otherwise Skip the swapping part
                           #swapping the values
   sw $t0, 0($t3)
   sw $t1, 0($t2)
Skip:
   j LoopJ                   #jumping back to inner loop
NextI:
   addi $t2, $t2, 4       #pointing to next element
   bne $t2, $s2, LoopI   #if not the end of the array; jump back to LoopI
End:

Add a comment
Know the answer?
Add Answer to:
please trace this is sort program and base address s0, number of element s1 please also complete the program(..) explai...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here...

    Please comment the MIPS code to help me understand. Here is what the code accomplishes. Here is the code, partially commented. .data Matrix: .word 41,45,5, 34,8, 15,16,23,44,48,12,32,18,47,22,8,22 .word 46,40,42,33,13,38,27,6, 29,25,18,40,47,22,26,14,3 .word 7, 48,35,9, 43,38,9, 49,28,25,42,5, 44,10,5, 38,14 .word 46,33,16,6, 13,20,31,1, 8, 17,1, 47,28,46,14,28,7 .word 32,2, 48,25,41,29,14,39,43,46,3, 39,32,49,41,28,46 .word 5, 43,2, 48,13,4, 33,41,32,19,9, 25,30,22,2, 9, 40 .word 14,47,22,18,47,3, 35,44,18,6, 33,22,11,6, 47,50,4 .word 28,34,20,30,18,27,38,5, 26,40,37,23,16,13,37,8,7 .word 48,38,39,12,10,39,23,20,21,20,33,16,24,21,25,3,46 .word 49,38,40,38,13,47,5, 13,4, 13,23,26,12,30,29,29, 3 .word 8, 20,10,13,31,7, 12,41,12,21,28,26,43,14,35,10,19 .word 49,33,25,26,24,29,46,22,7, 5, 15,41,10,31,19,41,27 .word 48,9,...

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT