CSCI 255 — Arrays and Functions with MIPS32 Assembly

We are going to do a few little array computations today to make sure you have everything ready for the upcoming homework assignments. You may to consult the MIPS “Green Card” for this lab. The MPLAB® XC32 Assembler, Linker and Utilities User’s Guide remains the ultimate resource.

You should work by yourself today.

Getting Started

Downloading a starter project

Download a tar.gz file containing a compressed MPLAB X project called ArrayTester. You should be able to expand it from the browser. Be sure to store it in your MPLABXProjects directory.

It might also be useful to bring up the Arrays with the MIPS32 Assembly lab in another browser window to jog your memory about UART simulation and MIPS32 arrays.

Looking at the code

Take a look at the following files within the project.

Note the header for the testArrayFunctions function in misc.c . This is how you declare function prototypes. The physicists using C (and FORTRAN) love to pass functions to functions. In this case, the testArrayFunctions is passed two arrays, f1 and f2, of functions and a third argument, size, giving the size of the arrays. Both of the function receive two arguments, a pointer to a int32_t and a int32_t value.

void testArrayFunctions(
        int32_t (*f1)(int32_t *, int32_t),
        int32_t (*f2)(int32_t *, int32_t),
        int32_t size)

Even stranger is the prototype for testArrayFunctions in tester.h . It doesn’t contain parameter names. No other programming language has a (*).

void testArrayFunctions(
        int32_t (*)(int32_t *, int32_t),
        int32_t (*)(int32_t *, int32_t),
        int32_t) ;

Java doesn’t allow functions to be used as parameters. However, you can use interfaces to accomplish a similar task.

public interface ArrayFunctionTester<T> {
    int arrayFunction(T[] vector, T element) ;

Your task for today

First, comment out the #define for BORINGTEST and comment in the #define for EXCINGTEST. This will cause your program to use the MIPS32 assembly routines rather than their C equivalents.

// #define BORINGTEST 1

Debug your project. You should now have lots of errors for the Exciting tests.

One at a time, fix all four MIPS32 functions.