Answered step by step
Verified Expert Solution
Question
1 Approved Answer
PLEASE COMPLETE THE QUICK SORT IN MIPS .data smallTable: .word 7,8,1,9,2,6,3,10,4,5 .text # test quicksort with smallTable la $a0, smallTable li $a1, 0 li $a2,
PLEASE COMPLETE THE QUICK SORT IN MIPS
.data smallTable: .word 7,8,1,9,2,6,3,10,4,5
.text # test quicksort with smallTable la $a0, smallTable li $a1, 0 li $a2, 6 jal qs # terminate li $v0, 10 syscall #void quicksort (int v[], int start, int end){ # if (start < end){ # int q = partition(v, start, end); # quicksort(v, start, q - 1); # quicksort(v,q + 1,end); # } #} # arguments: $a0 = v[], $a1 = start, $a2 = end # saved variables: $s0 = q, $s1 = v[], $s2 = start, $s3 = end qs: addi $sp,$sp, -20 sw $ra, 16($sp) sw $s3,12($sp) # save $s3 on stack sw $s2, 8($sp) # save $s2 on stack sw $s1, 4($sp) # save $s1 on stack sw $s0, 0($sp) # save $s0 on stack ################################################### # YOUR CODE HERE ################################################### done: lw $s0, 0($sp) # restore $s0 from stack lw $s1, 4($sp) # restore $s1 from stack lw $s2, 8($sp) # restore $s2 from stack lw $s3,12($sp) # restore $s3 from stack lw $ra,16($sp) # restore $ra from stack addi $sp,$sp, 20 # restore stack pointer jr $ra #int partition (int v[], int start, int end){ # int pivot = v[end]; # int i = start; # for (int j = start; j < end; j++ ){ # if (v[j] <= pivot){ # swap(v,i,j); # i++; # } # } # swap(v, i, end); # return i; #} # arguments: $a0 for v[], $a1 = start, $a2 = end # saved values: $s0 for pivot, $s1 for i, $s2 for j, $s3 for v[], $s4 for start, $s5 for end # return value: $v0 for return i partition: addi $sp,$sp, -28 sw $ra, 24($sp) sw $s5, 20($sp) sw $s4, 16($sp) sw $s3,12($sp) # save $s3 on stack sw $s2, 8($sp) # save $s2 on stack sw $s1, 4($sp) # save $s1 on stack sw $s0, 0($sp) # save $s0 on stack ################################################### # YOUR CODE HERE ################################################### lw $s0, 0($sp) # restore $s0 from stack lw $s1, 4($sp) # restore $s1 from stack lw $s2, 8($sp) # restore $s2 from stack lw $s3,12($sp) # restore $s3 from stack lw $s4,16($sp) lw $s5,20($sp) lw $ra,24($sp) # restore $ra from stack addi $sp,$sp, 28 # restore stack pointer jr $ra # swap procedure: $a0 is address of array, $a1 is k, $a2 is j swap: ################################################### # YOUR CODE HERE ###################################################
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