0
votes

So, I have a class where we've been handed an implementation of the quicksort algorithm in c code, and we have to make an implentation of that code in mips assembly language. I have succesfully made most of my code, but am having trouble with some of the recursion. This is the part of the c program that i'm concerned about:

...
tmp = v[left];
v[left] = v[last];
v[last] = tmp;
qsort(v, left, last-1);
qsort(v, last+1, right);

The part i'm having trouble with, is the recursive part, ie. qsort(v, left, last-1)...

My question is, when qsort(v, left, last-1) is run, the value last-1 is saved as "right". So when that recursive call is done, I have to recall the previous value(s) of "right". How could I do that, simply?

Edit: the problem is, the bigger the list of numbers is, the more recursive calls there'll be, and as such, the more values i have to store. I guess, what I want to know, is if there's a way to store and recall a variable length of values?

1
Put it in a spare register? Put it somewhere on the stack? - Oliver Charlesworth
Using the stack seems appropriate for a recursive function. - Michael

1 Answers

0
votes

If you code your qsort function according to the standard MIPS calling convention, you can store the right variable in one of the callee-saved registers ($s0,$1,...,$s7).

When the qsort function starts executing, the first thing it should do is save whichever of the callee-saved registers that it uses onto the stack.