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:
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:
Select one of the following 1. Change vector to the current value of vector A 2. Change vector to the current value of vector B 3. Change vector to the current value of vector C 4. Input new coefficent values 5. Leave vector values unchanged Enter choice:The same function is to called for either option. Based on the choice entered, the function will perform the proper task. The addresses of the vectors A, B and C must be passed as parameters as must the address of the vector to be changed (note: this means that the address of either A or B will be passed twice). If option 4 (Input new values) is selected, prompt the user for three integer values (or call another function that prompt for three integers or perhaps call another function three times that will prompt for a single integer each time). After the function completes, redisplay the main prompt.
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.
Register Name | Alternative Name | Description |
---|---|---|
$0 | the value 0 | |
$1 | $at | reserved by the assembler |
$2 - $3 | $v0 - $v1 | expression evaluation and function results |
$4 - $7 | $a0 - $a3 | the first four parameters - not preserved across procedure calls |
$8 - $15 | $t0 - $t7 | temporaries - not preserved across procedure calls |
$16 - $23 | $s0 - $s7 | saved values - preserved across procedure calls |
$24 - $25 | $t8 - $t9 | temporaries - not preserved across procedure calls |
$26 - $27 | $k0 - $k | reserved for use by the operating system |
$28 | $gp | global pointer |
$29 | $sp | stack pointer |
$30 | $s8 | saved value - preserved across procedure calls |
$31 | $ra | return address |
$f0 - $f2 | floating point function results | |
$f4 - $f10 | temporaries - not preserved across procedure calls | |
$f12 - $f14 | the first two floating point parameters - not preserved across procedure calls | |
$f16 - $18 | temporaries - not preserved across procedure calls | |
$f20 - $f30 | saved values - preserved across procedure calls |
Service | System Call Code placed in $2/$v0 | Arguments | Results |
---|---|---|---|
print_int | 1 | $a0 = integer | |
print_float | 2 | $f12 = float | |
print_double | 3 | $f12 = double | |
print_string | 4 | $a0 = address of string | |
read_int | 5 | integer (in $v0) | |
read_float | 6 | float (in $f0) | |
read_double | 7 | double (in $f0) | |
read_string | 8 | $a0 = address of string buffer $a1 = length of string buffer | |
sbrk | 9 | $a0 = amount | address (in $v0) |
exit | 10 |
The following special characters are used with character strings in SPIM. The special characters follow the C language convention:
Character | Encoding Sequence |
---|---|
Newline | \n |
Tab | \t |
Double quote | \" |