CS 366 - First SPIM Programming Assignment

Due: Wednesday November 20, 2002 at 11:59 pm

This programming assignment is not a group project. Each student will get graded on his/her own assignment. Each student must electronically submit his/her own assignment using the UNIX turnin command on the CS Department's computers. Use the project name of spim1 with the turnin command.

While this assignment is not a group project, it will be assumed that each student is part of a study group consisting of one or two other students and similarity of code between members of the study group is expected. You must include a list of the other members in your study group in a comment near the top of your source code file. Not listing any other students will indicate that you worked on this project completely by yourself and that there should be no similarity between your program and any other program in the class. Note: the next spim programming project will be done in groups of 2 or 3.

For this program, you are to write a program using the MAL assembly language to run under the SPIM/XPSIM software. This program is to allocate space for three arrays. Each array should be able to store up to 100 integer values in it. Your program is to perform the following steps:

  1. Read in integer values and store them in the first array in order that they were read in. The program will stop reading in values when a negative value is read in or 100 values have been read in. When a negative value is read in, store that value in the array. Your program is to print a descriptive prompt before the numbers are read in to describe to the user what he/she should do.

  2. Print out the values in the first array in order that they were read in with 10 values per line. Your program must print out some descriptive text explaining what is occurring.

  3. Copy the values from the first array to the second array and then sort the values in the second array. Note there is code for sorting an array in the Goodman and Miller text.

  4. Print out the values in the second array in sorted order with 10 values per line. Your program must print out some descriptive text explaining what is occurring.

  5. Fill in the values in the third array with the result of applying a "personalized" quadratic equation to the values in the second array. The following psuedo code indicates what is to occur:
         for (i = 0; i < size; i++)
             {
              x = arr2[i];
              arr3[i] = Ax2 + Bx + C;
             }
    
    where A, B and C are the last three digits from your Student Identification Number (i.e. SSN) incremented by 1. Thus if your Student Identification Number is 319-96-8521. The last three digits are 5, 2 and 1. The value for A is 6 (5 + 1). The value for B is 3 (2 + 1). The value for C is 2 (1 + 1). The values for A, B and C are to be hardcoded into your program.

    Note: the reason for incrementing the values by 1 is that the last three digits may contain zeros.

  6. Print out the values in the third array in order created with 10 values per line. Your program must print out some descriptive text explaining what is occurring.
Your program must be well commented and should use blank lines to separate logical sections of your code.

You may earn up to 10 pts of extra credit with this assignment.

Alternative Register Names in SPIM

This is from Figure 9.9 in the Goodman&Miller text
Register NameAlternative NameDescription
$0the value 0
$1$atreserved by the assembler
$2 - $3$v0 - $v1expression evaluation and function results
$4 - $7$a0 - $a3the first four parameters -
  not preserved across procedure calls
$8 - $15$t0 - $t7temporaries -
  not preserved across procedure calls
$16 - $23$s0 - $s7saved values -
  preserved across procedure calls
$24 - $25$t8 - $t9temporaries -
  not preserved across procedure calls
$26 - $27$k0 - $kreserved for use by the operating system
$28$gpglobal pointer
$29$spstack pointer
$30$s8saved value -
  preserved across procedure calls
$31$rareturn address
$f0 - $f2floating point function results
$f4 - $f10temporaries -
  not preserved across procedure calls
$f12 - $f14the first two floating point parameters -
  not preserved across procedure calls
$f16 - $18temporaries -
  not preserved across procedure calls
$f20 - $f30saved values -
  preserved across procedure calls

Input and Output in SPIM

I/O is done in SPIM using the syscall opcode. For each I/O operation, a specific value is placed in the $2 register (also referred to as $v0). Depending on the I/O operation to be performed, other registers may be involved. The following table lists the possible syscall services.
ServiceSystem Call Code
placed in $2/$v0
Arguments Results
print_int1$a0 = integer
print_float2$f12 = float
print_double3$f12 = double
print_string4$a0 = address of string
read_int5integer (in $v0)
read_float6float (in $f0)
read_double7double (in $f0)
read_string8$a0 = address of string buffer
$a1 = length of string buffer
sbrk9$a0 = amountaddress (in $v0)
exit10
Spim Input/Output Example Program

The following special characters are used with character strings in SPIM. The special characters follow the C language convention:
CharacterEncoding Sequence
Newline\n
Tab\t
Double quote\"