CS 366 - Floating Point Vectors

Due: Monday, February 16, 2004 at 11:59 pm

For this assignment, you are to prompt the user for two vectors, calculate the sum and dot product of the two vectors and print the results. After you have done this for one pair of vectors, ask the user if they wish to processes another pair of vectors or quit the program.

The vectors may have up to 20 dimensions and will hold floating point numbers. When prompting for the vectors, your program must first ask for the number of dimensions the pair of vectors will have (i.e. the size of the vector). This should be an integer value in the range from 1 to 20. An entered value outside of this range should result in some error message and reprompting to user to enter this value.

After a valid number of dimensions in read in, prompt the user for the values of the first vector. After the first vector is read in, prompt the user for the values of the second vector. The values for the vectors are to be floating point numbers (you may use double precision floating point numbers if you wish, but single precision is just fine). After both vectors have been read in, print out both vectors in some nice format. Use the letters A through T to identify each dimension. For example if you had a vector with 3 dimensions the letters A, B and C would be used:

     Vector 1:   3.14159000000000000 A + 2.00500000000000000 B + -3.50000000000000000 C
     Vector 2:   4.20000000000000000 A + -6.1b000000000000000 B + 5.55550000000000000 C

After both numbers are displayed, compute the sum of the vectors and print out this result. Remember the sum for each dimension is calculated seperately by adding the numbers values for the dimension from each of the vectors. After the sum is displayed, compute the dot product of the two vectors and display this result. Remember the dot product is calculated by summing together the result of multiplying the values for each dimension.

For the vectors of:
	x A + y B + z C
	w A + v B + u C
The sum is:
	(x+w) A + (y+v) B + (z+u) C
The dot product is:
	(x*w) + (y*v) + (z*u)

After you have done this, prompt the user if they wish to continue the program and process another pair of vectors. Your program should look for a Y or an N from the user (this response can be in either upper or lower case. In the past, students have found it easier to allow the input to be up to 80 or 100 characters long and then just check the first character of the input and ignore anything else that might be input by the user.

Your vectors are to be stored in arrays in memory. The main purpose of allowing upto 20 dimensions was to make sure that the vector values could not all be stored in registers. Also, refer to Appendix F of the book for the list of the various floating point operations. Remember that in MIPS all floating point operations are performed in co-processor 1.

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 mp2. Your program must be well commented and use blank lines to separate logical sections of your code.

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\"