Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

 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

3.42 Rating (155 Votes )

There are 3 Steps involved in it

Step: 1

Solution Here is the MIPS version of the quicksort algorithm data data word 851410123961157413211 si... blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Income Tax Fundamentals 2013

Authors: Gerald E. Whittenburg, Martha Altus Buller, Steven L Gill

31st Edition

1111972516, 978-1285586618, 1285586611, 978-1285613109, 978-1111972516

More Books

Students also viewed these Algorithms questions

Question

19. How do amphetamine and cocaine influence dopamine synapsespg78

Answered: 1 week ago

Question

23. What are the effects of cannabinoids on neuronspg78

Answered: 1 week ago