CS 366 - Vector Processing with SPIM

Due: Wednesday December 4, 2002 at 11:59 pm

This project may be done in groups of two or three students. Your program must clearly list the names and email addresses of all members of your group.

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 spim2 with the turnin command.

This program is to be written in assembly language that will run under the SPIM/XPSIM software. This program must use functions under the conventions described for the MIPS machine. This program will also use the base displacement addressing mode for access to the vectors. These vectors will be vectors in 3 dimensions: x, y and z. The vectors will be written using the parenthesized notation of (i, j, k) where i is the coefficent in the x direction, j is the coefficent in the y direction and k is the coefficent in the z direction. This program will only use integer coefficents.

In addition to input and output, the program will perform the following operations:

Each vector is to be maintained as a "structure" of three integer values. This structure will use the base displacement addressing mode to access the different coefficents of the vector. Assume the register $4 has the address of the structure, the x coefficent will be accessed using 0($4), the y coefficent will be accessed by using 4($4) and the z coefficent will be accessed by using 8($4).

The program is to maintain three vector in three structures as described above. Failure to do so will result in a grade of zero for the assignment. These vectors will all be initialized to the value of (0, 0, 0) when the program starts. We shall refer to these vectors as A, B and C. The operations of Dot Product and Scalar Multiplication both use a scalar value that we shall refer to as S. The scalar value will also be an integer value. The usage of these three vectors and the scalar for these operations is:
Cross Product C <- A x B
Dot Product S <- A . B
Vector Addition C <- A + B
Scalar Multiplication C <- S(A)

This program is to run in a loop. Each time though the loop the following prompt should appear. Note the values i, j, k, m, n, o, p, q and r should be replaced with the actual coefficents of the vectors A, B and C.

	The current vector values are:
	   A: (i, j, k)
	   B: (m, n, o)
	   C: (p, q, r)
	
	Select one of the following operations:
	   1. Change value for vector A
	   2. Change value for vector B
	   3. Compute Cross Product
	   4. Compute Dot Product
	   5. Compute Vector Addition
	   6. Compute Scalar Multiplication
	   7. List information about this program's authors
	   8. Exit the program
	
	Enter choice:

Your program must be well commented and should use blank lines to separate logical sections of your code. Your program must have a large comment at the top of the program describing what the program does and who wrote the program. Also each function in your program must have a large comment at its beginning stating the purpose of the function and what is in each parameter and return value and where each parameter and return value is implemented (i.e. in a register or on the stack. If a register is used, specify which register is being used).

All data items that are being used by any function must be passed to that function via a parameter. All data items that are being returned from a function must be returned using the specified return registers or via a pass-by-reference parameter. This means that all access to data section is forbidden except in the main section of your program. Any program that violates this will receive a grade of zero for the assignment. There is one exception to this rule static textual output can be accessed directly from the data section in any function. Examples of "static textual output" include prompts for input and output used to make output of data more readable.

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