Programming Assignment 1

CS 5621

10 points, Due Thursday, February 1


Overview

This assignment will, for most of you, be a chance to learn MIPS machine language (MAL) and the SPIM and XSPIM simulators for it. MAL, SPIM, and XSPIM are described in more detail in the SPIM/MAL Documentation web pages and also in appendix A of Patterson and Hennessy.

You should write a MAL program with a main program and two subprograms: mread and mwrite. The mread subprogram should read in a matrix. The mwrite subprogram should write out a matrix.

Input and Output Format

The input to mread and the output from mwrite should both have the same format consisting of two lines specifying the number of rows and number of columns in the matrix, followed by the entries of the matrix. For example, the matrix

1.0 2.0 3.0
4.0 5.0 6.0

is represented by input or output of the following form.

2
3
1.0
2.0
3.0
4.0
5.0
6.0

Internal Matrix Representation

To represent a matrix in the computer, you should set up a matrix descriptor struct with three entries: the number of rows, the number of columns, and the address of an array containing the entries. The descriptor and the entries array should be created dynamically when a matrix is read. The MAL sbrk system call can be used to allocate the memory for the struct and the entries array.

Subprogram Parameters and Return Values

The mread subprogram should have no parameters. It should return the address of the matrix descriptor that it creates.

The mwrite subprogram should have one parameter: the address of a matrix descriptor. It should not have a return value.

The Main Program

The main program is the easy part. Just call mread, print a newline, and then call mwrite. The return value from mread should be used as the parameter for mwrite.

Integers and Reals

You should use words (4 bytes) for all integers and floats (also 4 bytes) for all real numbers. The read_int, print_int, read_float, and print_float system calls can be used for integer and real input and output. The instructions lw and sw can be used to move integer data between memory and integer registers. The instructions l.s and s.s can be used to move real data between memory and real registers. You will only need arithmetic instructions for integers in this program. Keep in mind that MIPS has a load-store architecture: you can only do arithmetic with registers. The third operand of an arithmetic instruction can be an immediate value literal.

What to Turn In

You will need to demonstrate your program using xspim on the due date. At that time you should also turn in a copy of your code. Of course, it will be well commented if you want full credit.