In this task you will be writing a quick sort using RISC-V. We have written some code for you, but you have to finish the most important part all by yourself. You can download the src here.
Quick sort can be "partitioned" into two parts:
algorithm partition(A, lo, hi) is
pivot := A[hi]
i := lo - 1
for j := lo to hi - 1 do
if A[j] < pivot then
i := i + 1
swap A[i] with A[j]
swap A[i + 1] with A[hi]
return i + 1
algorithm quicksort(A, lo, hi) is
if lo < hi then
p := partition(A, lo, hi)
quicksort(A, lo, p - 1 )
quicksort(A, p + 1, hi)
Source for the code above: Wikipedia
If you are not familiar with these two process, here are some help.
The code we wrote follows these two procedures too. Mind that you must fill two functions and you MUST NOT combine them or we WILL NOT grade your homework. We enforce this for a reason. One, it's good to get things separated and keep your mind cool; besides, you also need to practice save(and load) from(to) memory before calling a function.
You should take your algorithm on a array which contains 10 integers. The array has been allocated space on static partition in line 40. You can change that array to whatever you like but DO NOT change the line number of it and anything else around them.
Function def_quick_sort
is the quick sort function, you can write your implementation here. And in this function, you should use another function def_partition
.
def_partition
, you should separate a list into two partition. You can choose whatever method you like for detailed implementation.After label exit
, you should set correct parameter to the environment call, which allows exit the program with exit code 0
. For more ecall
information, see here.
Finally, finish the auxiliary function print
. You should print an array form the begin (its address in a1
) to the end. Two numbers will be separated by space. e.g.:
hw3.asm
.