Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

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

Programming The Perl DBI Database Programming With Perl

Authors: Tim Bunce, Alligator Descartes

1st Edition

1565926994, 978-1565926998

More Books

Students also viewed these Databases questions

Question

=+ Who is the negotiation partner at company level?

Answered: 1 week ago

Question

Why is the System Build Process an iterative process?

Answered: 1 week ago