Unit 3 - Instruction Set Overview and the SPIM Simulator

Instruction Set Overview:

For an overview of the MIPS R2000 Assembly language instructions, look here.

Installing SPIM:

Introduction to SPIM:

Assignment:

You are to write an assembly language program which will read a packed string of eight characters from a specified memory location, check to make sure that each character is a digit from (0-9), and then convert the string of digits into its corresponding integer value and place this value in a specified register.  If a character is not recognized as a decimal digit, then call an error routine which sets the value of the result register to 0xFFFFFFFF.  The string will be initialized into memory using a .data section in your assembly language code to store an ascii string 8 characters:

                .data
STRING1:        .asciiz "76543210"

 

The above code will load the ascii character '7' into the byte at address STRING1, the ascii character '6' into the byte at address (STRING1 + 1), etc. The ASCII string is terminated by a NULL (value 0) character.

It may be useful to use the R2000 Assembly language routines mult rs, rt ; div rs, rt ; and mflo rd, rs

Here is a rough sketch of an algorithm that can be used to accomplish this:

  1. Clear the result and index registers
  2. Load the byte at label STRING1 using your index register into a register $x
  3. Check to make sure that the character is not the NULL character. If so, branch out of the loop.
  4. Check to make sure that the character is a decimal digit (between 0x30 and 0x39). If not, branch to an error routine.
  5. Multiply the result register by 10.
  6. Subtract 0x30 from the value (to convert from ASCII to binary) and add it to the result register.
  7. Return to step 2.
  8. Return to calling routing (jr $31)

Remember, DO not use register $0, $1 or $31 in your code (except for jr $31 to return), SPIM reserves them for its use.