Question
please help me to convert this quicksort in C code to MIPS version of it. below things are quicksort with c-code and unfinished MIPS quicksort
please help me to convert this quicksort in C code to MIPS version of it.
below things are quicksort with c-code and unfinished MIPS quicksort
please finish MIPS quicksort
#include
int data[] = {8,5,14,10,12,3,9,6,1,15,7,4,13,2,11}; int size = 15;
//Below functions is for debugging purpose only. Don't implement this /* void debug(){ int i; for(i=0;i printf("%d, ", data[i]);
printf(" "); } */
int partition(int * data, int start, int end){ int left=start; int right=end; int pivot=data[start];
while(left
while (data[right] > pivot){ right--; }
while((left < right) && (data[left] <= pivot)){ left++; }
if(left int temp = data[right]; data[right] = data[left]; data[left] = temp; } }
data[start]=data[right]; data[right]=pivot;
return right; }
void quick_sort(int *data, int start, int end){ int pivot_position;
if(start < end){ pivot_position = partition(data, start, end); quick_sort(data, start, pivot_position-1); quick_sort(data, pivot_position+1, end); } } void main(){ quick_sort(data,0,size-1); //debug(); }
---------------------------------------------------------------------------------------
.data data: .word 8,5,14,10,12,3,9,6,1,15,7,4,13,2,11 size: .word 15 #use below sample if above example is too large to debug #data: .word 4,2,5,3,1 #size: .word 5 .text
partition: # TODO: fill in your code here jr $ra
quick_sort: # TODO: fill in your code here jr $ra
main: la $a0, data #load address of "data"."la" is pseudo instruction, see Appendix A-66 of text book. addi $a1, $zero, 0 lw $a2, size #loads data "size" addi $a2, $a2, -1
addi $sp, $sp, -4 sw $ra, 0($sp)
jal quick_sort #quick_sort(data,0,size-1)
lw $ra, 0($sp) addi $sp, $sp, 4
jr $ra
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