This assignment has two parts. The first part is to do a MIPS implementation of the second exercise of Lab 9 (the bedtime story exercise). The second part is an exercise in passing functions as parameters (using function pointers).
Take your C implementation of bedtimestory() from Lab 9, and implement it in MIPS assembly. All of the specifications remain the same. Write a main function as well, and use the same sample input and output files.
Your implementation of bedtimestory() must be recursive. A non-recursive implementation of the function will receive zero credit. Name the file with your MIPS code ex1.asm. Test it using your own inputs, and also the sample inputs provided for the C part of this exercise in Lab 9.
You will essentially re-implement bubble sort from Labs 4 and 5, but this time a more general version that can accept as an argument a function to compare two objects. Thus, whether the sorting is to be in ascending order or descending order can be determined simply by passing an appropriate compare function (less-than vs. greater-than).
Understand, compile and run bubble.c and bubble_generic.c. The first program, bubble.c is basically identical to the bubble sort implementation from Lab 4, except that the code has been partitioned into procedures, and it involves floating-point numbers. The second program, bubble_generic.c replaces the simple comparison operation "A > B" with a generic function compare_fn whose actual definition is an argument/parameter passed into the sort routine. Thus, the same bubble sort function can be used to sort floats in increasing order or in decreasing order simply by handing it a different compare function. Carefully study this generic implementation, compile it, and run it. (This implementation comes closer to how you can specify a "compare object/method" to a generic sort routine in C++ or Java.)
Take the C code for bubble_generic, and code the entire program in MIPS assembly, including the main function. Use single-precision floating-point operands and instructions in MIPS. Name the file with your MIPS code ex2.asm.
Hint: You should use the jalr instruction to implement function pointers, i.e., calling a function whose address is available in an argument register, instead of being a constant label.
Sample inputs: A sample input is provided within the C source code. Your MIPS program must generate the same output as the C program, except for differences in formatting of the floating-point numbers. In particular, use syscall 2 in MARS to print floats; it is okay if the output precision and format do not match the C output exactly.
Due Date: Mon Nov 16, 11:59pm for full extra credit; Fri Nov 20, 11:59pm for half extra credit; no credit thereafter.
If you have created multiple files for each exercise (e.g., following my instructions for earlier labs to use a separate file per assembly procedure), that is okay, but for submission you will need to join them because I did not specify the file names, so different students may be using different names. Concatenate all the files for Exercise 1 into the file ex1.asm, with the code for main at the top, and everything else below; make sure it compiles and runs fine in MARS. Similarly, concatenate all the files for Exercise 2 into the file ex2.asm, with its main at the top.
Submit your MIPS code (files ex1.asm and ex2.asm only), using the commands:
% cd ~/comp411lab/lab10
% /home/montek/comp411/bin/submitlab10
No self-checking is performed for this extra-credit assignment. You are responsible for checking your programs before submission. You can use the sample input/output files from Lab 9 for bedtimestory(); Exercise 2 has its input supplied internally.