CS 366 - Functions

Due: Monday, March 8, 2004 at 11:59 pm

For this assignment, you will write functions in SPIM. These functions MUST follow the MIPS Convention for Register Usage. You are to write functions that will:

Your program may have other functions, but the above must be included.

Your program is to have a data section that contains two floating point arrays. Each array should be able to store up to 100 values; however, may actually hold fewer values. All access to the arrays and any supporting variables (like a length or size information) from the functions must be made through the use of parameters. Any information about the arrays that is accessed directly by a function will result in a grade of zero for the assignment.

Your program is to perform the following steps:

  1. Fill in the first array with values from input using a function.
  2. Fill in the second array with values from input using a function.
  3. Print out the values in each array using a function. This function should be called once for each array.
  4. Call the function that will loop through the arrays comparing the corresponding values in each position of the array. This function is to print out both corresponding values and then print out the smaller of the two values. This function MUST call the function that determines the smaller of two floating point parameters to find the smaller value. If the arrays are not the same size, stop comparing values once you get to the end of the smaller array.
  5. Sort both floating point arrays. This function should be called once for each array. This function MUST call the function that determines the smaller of two floating point parameters to find the smaller value.
  6. Again call the function that will loop through the arrays comparing the corresponding values in each position of the array. This function is to print out both corresponding values and then print out the smaller of the two values. This function MUST call the function that determines the smaller of two floating point parameters to find the smaller value. If the arrays are not the same size, stop comparing values once you get to the end of the smaller array.

Specifics about each function you are to write

The programs will be graded based on how they execute on xspim running in the CS Department computers. You are to submit your program electronically using the the turnin command with the project name of mp3. Your program must be well commented and use blank lines to separate logical sections of your code.

You can earn 10 points extra credit on this assignment by using a recursive quicksort or recursive mergesort sorting algorithm for your sorting function. Note that the recursive sorting function will still need to use the "isLessThan()" function to compare two floating point numbers. If you are doing this, you MUST have your program print out the appropriate message:

     This program uses the recursive quicksort algorithm.
or
     This program uses the recursive mergesort algorithm.
at the beginning of your program. If you do not print out the message, the TA will NOT look for the recursive sorting function and you will not get any extra credit.

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
View Spim Input/Output Example Program or download 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\"