Question: home / study / engineering / computer science / computer science questions and answers /' mips insertion sort outline: for i 1 to length(a) j

home / study / engineering / computer science / computer science questions and answers /'

mips insertion sort outline:

for i 1 to length(a) j i

while j > 0 and a[j-1] > a[j] ... Question: MIPS Insertion sort Outline: for i 1 to length(A) j i while j > 0 and A[j-1] > A[j... MIPS Insertion sort Outline: for i 1 to length(A) j i while j > 0 and A[j-1] > A[j] swap A[j] and A[j-1] j j - 1 end while end for Code: I have already started on it, but there is error that I couldn't figure out why :( .text #------------------------------------------- # Procedure: insertion_sort # Argument: # $a0: Base address of the array # $a1: Number of array element # Return: # None # Notes: Implement insertion sort, base array # at $a0 will be sorted after the routine # is done. #------------------------------------------- insertion_sort: # Caller RTE store (TBD) addi $sp, $sp, -40 sw $fp, 36($sp) sw $ra, 32($sp) sw $a0, 28($sp) sw $a1, 24($sp) sw $a2, 20($sp) sw $a3, 16($sp) sw $s0, 12($sp) sw $s1, 8($sp) addi $fp, $sp, 40 # Implement insertion sort (TBD) move $a2, $zero # counter i for: add $a2, $a2, 1 #increment counter i by 1 beq $a2, $a1, insertion_sort_end #if i == number of array element move $a3, $a2 # a3 is the counter j, set j = i whilestatement: ble $a3, $zero, for #if j is less than 0, jump to bgt $a3, $zero, while # while the counter j is less than a1(#of array element), jump to while while: move $t0, $a3 mul $t0, $t0, 4 # multiply j * 4 add $s0, $t0, $a0 #A[j] add $s1, $s0, -4 #A[J-1] bgt $s1, $s0, swap # if A[j-1] > A[j] swap: move $t4, $s0 # set t4 to A[j] move $s0, $s1 move $s1, $t4 add $a3, $a3, -1 j whilestatement insertion_sort_end: # Caller RTE restore (TBD) lw $fp, 36($sp) lw $ra, 32($sp) lw $a0, 28($sp) lw $a1, 24($sp) lw $a2, 20($sp) lw $a3, 16($sp) lw $s0, 12($sp) lw $s1, 8($sp) addi $sp, $sp, 40 # Return to Caller jr $ra

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!