CSE140 Computer Architecture (Fall semester 2007): project 1

This projects tests your understanding of assembly language programming with the MIPS instruction set architecture (ch. 2-3 in the textbook). You may do in in groups of up to 2 students. You will:

  1. Write a well-commented C program project1.c that:
    1. Reads an integer n from the terminal.
    2. Reads n more integers from the terminal and saves them in an array a in memory.
    3. Computes the two functions process_array1 and process_array2, saving the results in a1 and a2 in memory.
    4. Prints a1, a2 to the terminal.
    5. Terminates.
  2. Translate it into a well-commented MIPS assembly language. You may need to use several system calls (for terminal I/O, memory allocation, etc.); see appendix A of the textbook.
  3. Debug it with SPIM to ensure it runs correctly.
  4. Compare your MIPS program with the one obtained by the MIPS C cross-compiler: mips-gcc -mips32 -mrnames -S project1.c. Try the different levels of optimisation -O0 (no optimisation, the default), -O1, -O2, -O3, -Os. See the optimisation options and the MIPS options in the gcc manual. See also section 2.11 of the textbook.

Your program must contain at least the following functions:

  1. *int readints(int n), which reads n integers (positive or negative) from the terminal, stores them in an array in memory and returns its address.
  2. *float process_array1(int *a), which creates an array a1 of floats (single precision) where a1[i] = sqrt(a[i]/(a[i]-a[n-1-i])).
  3. float sqrt(float a), which computes (to the highest precision) the square root. The MIPS ISA does have a sqrt.s instruction, but your sqrt function may not use it. However, for debugging purposes, you should compare the result of sqrt.s with your sqrt function's. To implement it, use Newton's method (an iterative method with second-order convergence); you need to provide a starting value for the iteration and a stopping criterion.
  4. int process_array2(int *a), which returns an integer a2 equal to the sum a[0]^5 + ... + a[n-1]^5.
  5. void print_int_array(int *a), void print_float_array(float *a), which print to the terminal a list of numbers (if overflow or infinity they should print a suitable message).

Give these constraints, you have some freedom as to how to implement the program (in a reasonable way), but you have to explain your decisions as to how you deal with:

We have several example programs in C and their translation into assembly language (by hand rather than by a compiler) that you can use to test things. Also, if you find it useful you can use the following Matlab (or Octave) code to compute test values of a1, a2:

a=[12 6 8];
a0=a./(a-a(end:-1:1)); a0(a0<0)=NaN; a1=sqrt(a0), a2=sum(a.^5)

Some examples of inputs and outputs:

What you have to submit is a single file project1.tar.gz, by email to the TA, containing:


Miguel A. Carreira-Perpinan
Last modified: Tue Nov 27 23:48:00 PST 2007

UC Merced | EECS | MACP's Home Page