Retro prof in the lab University of Washington Computer Science & Engineering
 CSE 378 Spring 2007
  CSE Home   About Us    Search    Contact Info 

Homework # 1- MIPS Assembly Language Introduction

Assigned: 3/27/2007
Due:4/3/2007 at 5pm

Introduction

This assignment will introduce you to the MIPS assembly language. To gain some familiarity with this, you will have GCC compile some provided C functions into MIPS assembly and comment the assembly produced to show how it lines up with the code. This provides you a chance to see how programs written in a high-level language like you are used to can be broken down into the simpler instructions required by the processor.

Getting the assembly

We have provided you with three functions that you will compile into assembly code and comment:
  • add.c: A simple function involving 2 variables
  • loop.c: A function involving a loop
  • strcpy.c: The standard C strcpy function. Involves a loop and memory accesses
For each of these programs, you will use the GCC cross-compiler for MIPS available on the machines in 003 (the hardware lab) to generate the corresponding assembly code for each function. This cross-compiler will be used again once you have finished constructing your pipelined MIPS processor in Lab 3, so it doesn't hurt to become familiar with the environment in which it operates. Do NOT use cross-compilers other than the one available in 003. Here are the steps that you should use to get the assembly for your programs:
  1. Write your program and store it in a location that you can access from Windows machines (Z: is generally the best choice).
  2. Start up MSYS/MinGW (A program similar to Cygwin). The MSYS icon is on the desktop for the machines in 003.
  3. Navigate to the directory containing the file that you want to compile. To access Windows drives, use something like "cd z:" to access the Z drive.
  4. Run the command "mipsbe-elf-linux-gcc -S 'file.c'" to generate a corresponding .s file. The -S flag tells GCC to generate a readable version of the assembly code that corresponds to the given function.
Once you have done this, you will have the .s files that you need to comment.

Commenting the code

Now that you have the .s files along with the original .c files, you will be able to add comments to the .s files in order to show the correspondence. There will not be a line-by-line correspondence between the original C code and the assembly due to the fact that a line of C may require multiple assembly instructions to correctly implement. So, for this assignment, you will be identifying the segments of assembly that correspond to each line of code in the C program and marking them with comments. Here's an example of what you should do:
Original C code:

a = b++;
b = a + 3;

Generated ASM (for simplicity's sake, we will assume that a is stored in $t1, and b in $t2):

add $t1, $t2, $0;
addi $t2, $t2, 1;
addi $t2, $t1, 3;

Commented ASM:

#a = b++;
add $t1, $t2, $0;
addi $t2, $t2, 1;
#b = a + 3;
addi $t2, $t1, 3;
Notice that the comments indicating the corresponding line are inserted before the assembly code for that line. The compiler's code will not be as tidy as this example, but try to segment it to match the original C code as best possible. You can ignore any code that isn't an instruction on the green card (For example: .frame, .mask, etc.). Do this for all the functions that you are provided.

Turnin

Once you have commented all the files, submit them for grading via turnin. Place the three .s files in a location accessible via UNIX, and log into attu via SSH. Change your directory so that you are in the same directory as the files that you wish to submit. Once there, run "turnin -c cse378 -p hw1 add.s loop.s strcpy.s" to submit the files for grading. You do not need to zip the files up or compress them in any other way, as this will be handled by turnin.

A few notes about turnin:
  • You may submit your assignment as many times as you wish until the due date. Only the latest version of what you have turned in will be kept and graded.
  • If you are using a late day, run "turnin -c cse378 -p hw1_late add.s loop.s strcpy.s" to turn in your assignment. The late turnin will be available for 24 hours starting at the end of the regular turnin.


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