Lab 7, Function Pointers

| categories: Labs

Due 28 October before lab.

In this assignment, you will get more practice with pointers including passing functions as arguments to other functions. You will implement a general version of the bubble sort from Lab 4 that can sorts based on a comparison function passed as an argument.

Download bubble_generic.c and study it. It is very similar to bubble.c from Lab 4 except it factors the sort into a function and replaces the comparison x[i-1] > x[i] with a call to a function compare_fn whose actual definition is an argument/parameter passed into the source routine. Thus the same bubble sort function can be used to sort floats in increasing or decreasing order by simply handing it different compare functions. Carefully study this generic implementation, compile, and run it.

Exercise 1. Code bubble_generic in MIPS assembly (100 points)

Translate bubble_generic into MIPS assembly. You should use single-precision floating-point operands and instructions (Appendix B-73 to B-80).

Submit your MIPS code and a copy of the program output.