CS 366 - First SPIM Programming Assignment

Due: Monday, February 10, 2003 at 11:59 pm

For this assignment, we will decode three different values from a integer value received from input. The decoding is done based on the following information:

Your program is to prompt the user to enter in the input. Your program is to continue prompting, reading and decoding integer values until a negative value is entered. When an negative value is entered, print some appropriate message and quit the program. For a non-negative integer input, print a message clearly showing the three decoded values. When printing the ASCII character value, print out the actual character when possible. If the character is a non-printable character, print out a message stating the character is non-printable and print out the numeric value of the ASCII character.

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 coomand with the project name of mp1. Your program must be well commented and should 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
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\"