Steam-powered Turing Machine University of Washington Computer Science & Engineering
 CSE 378 Fall 2006
  CSE Home     CSE 378 Fall 2006  About Us    Search    Contact Info 

 Home
Administrative
 Syllabus
 Office Hours
 Mailing List
Assignments
 Reading
 Homework
 Labs
 Exams
Resources
 Lecture Slides
 Handouts
 Wiki
 MIPS Resources
 AHDL Resources
Anonymous Feedback
 Feedback Form
   

Assignment 1 - Introduction to MIPS Assembly (Wikified Version)

Assigned: 9/27/2006
Due: 10/4/2006

Objective

The objective of the first assignment is to write a basic program in the MIPS assembly language and run it through SPIM to verify that it works. For this purpose, you will write an assembly version of the strchr function and simulate execution in SPIM.

Writing assembly code

There are several things that you should keep in mind when writing an assembly program. The first is to write good comments as you write your code, rather than inserting them when you are done with the program. This will make it much easier for you to track down problems as you are writing, and will save you a lot of time when debugging. Leave the comments in the program when you turn it in as this will make it much easier for the TAs to figure out what you were trying to do with your code, and will be essential to getting partial credit if necessary.

Secondly, you should follow proper conventions when writing your program. For this assignment, we will focus on register usage conventions. Each register has a name associated with it and a purpose, and it is good style to follow these conventions. For example, the register a0 is meant to be used to pass arguments to a function, while the register t0 is used for temporary storage of data and could be erased by a called function. A list of register names and uses can be found on your green card.

Last but not least, simplicity is key when writing your assembly programs. There will often be ways to write programs that are more compact or faster than the straightforward solution, but you should focus on getting a working program rather than an optimized program. Always make sure that you have a working version to start from when you begin trying to optimize your program. Remember, an optimized program that fails to perform the required tasks is going to get a lower score than an unoptimized program that succeeds. If you do choose to work on optimizing your programs, be sure to clearly comment and explain your code where necessary as the purpose of some optimizations is not immediately apparent.

Assembly Warmup Exercises

The following five problems are short exercises that will get you thinking about the details of assembly programming. Most of these problems can be completed successfully in 5 instructions or less.

Note: Do No Harm! The problems describe the available registers. Your solutions may not use other registers, or destroy the input values.

  1. Put 0x12348ABC in register 9 ($9). (Be Careful)
  2. There is a 32-bit signed integer in $8. Put the complement of $8 in $9
  3. $8 and $9 contain 32-bit signed integers. Put the larger of the two in $10
  4. $8 contains 4 Ascii characters in the range [a-z]. Make the first and third characters upper-case. You may use $9 as a temporary register
  5. $8 holds the main memory address of an array of bytes. $9 is a signed integer index to the array, which we'll call N. Set the Nth entry in the array to 0x00000001. You may use $10 and $11 as temporaries.

Writing the Strchr function

The purpose of strchr is to read a string in one location of memory and to find the first instance of a given character in the string. Your program will be provided with the memory address of the first character in the string and the character that you should look for. The memory address of the first character will be provided in the register a0, while the ASCII value of the character to look for will be in register a1. Your program should look through the string character by character and return the address of the first instance of the character that it is told to look for. If the character is not in the string, return the address 0.

You can write your program in just about any text editor. For convenience, a template has been provided that you can insert your program into to test it out. Download the template and write your program. When you are done, you can test your program in SPIM to see if it works.

Using SPIM

SPIM is a MIPS simulator which is capable of executing your assembly programs and displaying the results. It is available on both Windows and Linux, as well as as a command line application or a GUI based application. A tutorial on using the Windows version of SPIM can be found here.

Load your program into SPIM and execute it. If your code works, you will see output indicating that your program correctly located the character (or not if it was not in the string).

Turnin

When you are satisfied with your solutions, produce a zip file containing two files: solutions to the problems, and your strchr function. Place the resulting zip file in a location accessible via attu and use "turnin -c cse378 -p a1 'your .zip file'" to submit your program for grading.


CSE logo Computer Science & Engineering
University of Washington
Box 352350
Seattle, WA  98195-2350
(206) 543-1695 voice, (206) 543-2969 FAX
[comments to Course Staff]