Lab 1: Getting Started

Goals:

        By the conclusion of this lab period, you will have:

1      Launched the PCSpim simulator and learned about some of its commands.

2.      Written, built, and executed a simple assembly language program.

3.      Examined a more complex assembly language program.

Preparation

         Before beginning the lab, you should read about the PCSpim simulator.  In particular, you should read the bottom section of page xvii in the text as well as pages A-38 to A-49 (section A.9).  You should also skim section A.10 so that you will be familiar with its contents.  As you will probably wish to use section A.10 as a reference during the lab, you should bring your textbook to lab this week.

A Note or Two About PCSpim

       The Spim simulator on the PC does not offer its own editor.  Therefore you will need to adopt a working system whereby you edit your files in one application (I suggest NotePad) and study them in another (i.e. the simulator).  When you do this, be sure that your files are text-only and that their names have a .s extension.  Beware of applications such as Word or even NotePad that tend to append their own extensions.  When you save a file for the first time, make sure that you are working under the “All Files” option in the Save Dialog.

       Also be aware that PCSpim writes its output in a Console window that is not normally displayed.  Use the appropriate menu times under the Window menu to clear or display the Console window.

 

Write Your First MIPS Program

1.      Launch PCSpim through the Start Menu, Programs Option, PCSpim Option, and finally PCSpim.  [Note, upon launching PCSpim for Windows for the first time (as a given user), you may get a "trap handler" error message.  If so, simply ask to see the dialog and click on the file C:\ProgramFiles\PCSpim\trap.handler and click OK.  This should be the only file in the dialog window that you see.]

 

2.      Miniaturize PCSpim and start your favorite editor.  (I recommend NotePad.)  Enter the MIPS program found at the end of this lab.  Save it as example.s.

 

3.      Return to PCSpim and load your program.  Run through it several times.  Be sure that you know how to execute the program all at once as well as how to go through it a single step at a time.  You should also experiment with the breakpoint feature; the breakpoint feature allows you to stop the execution at any particular line of the program.

 

4.      Modify the program so that it uses different numbers.  When this is done, modify it so that a more user friendly message is printed.  Print (and save) these modifications.

 

Study A More Complex MIPS Program

 

5.      Copy the file mystery.s to a local folder on your machine.  Examine it in your editor.  Try to figure out how it works.  [To avoid problems with line feed characters, etc. introduced via our web authoring software, we suggest that you follow the link, select the text, and copy/paste it into its own file in your editor.]

 

6.      Load this program into the simulator and run it a few times with different input.  Small positive integers are suggested.

 

7.      Working back and forth between the editor and the simulator, determine what high level language code was written to generate this file.  For each of the blank comment lines, add a comment explaining what is happening from a high level language point of view.  It may be possible to use only one comment for lines that are adjacent, i.e. not separated by white space, in the file.  (You may want to refer to section A.10 to understand some of the instructions.)  Also add a header comment at the top explaining the what the program actually does.  Include your names as “analysts”, but not authors.

 

8.      Print (and save) the annotated file.

 

To Hand In

 

9.      You are to hand in the printouts generated in Steps 4 and 8.

 

Due Date

      This lab is due next Tuesday, at 10:00 a.m.  It should be turned in to Dr. Levine directly.  If you turn it in to Dr. Hunkins in class, it will be considered on time.  If you turn it in to Dr. Hunkins at any other time, it will be considered "late".

 

Help Policy

 

       Help Policy in Effect for This Assignment: Group Project With Limited Collaboration

       In particular, you may discuss the assignment and concepts related to the assignment with the following persons, in addition to an instructor in this course: any Computer Science instructor and any student enrolled in CS 231.

       You may use the following materials produced by other students: materials produced by member of your own group.



# example.s
#
# First assembly language example.
# We will execute the expression:
# printf("%d\n", 10 + 9);
# We have four parts:
#      1. Do the addition.
#      2. Print the result.
#      3. Print the newline.
#      4. Exit.
# The assembler assumes you are in a text segment if 
# you do not indicate otherwise.

.globl     main


# The globl makes a label visible to the debugger.
 
main:


# 1. Do the add
li         $t0, 10         # Put 10 in a register
li         $t1, 9          # Put 9 in a register
add        $a0, $t0, $t1   # a0 = t0 + t1
                           # We put the result in a0
                           # for the syscall

# 2. Now print out the result
li         $v0, 1          # Integer print system call
syscall

# 3. Now print out the newline
la         $a0, newline    # Load the string address 
li         $v0, 4          # String print syscall 
syscall

# 4. Now exit
li         $v0, 10         # Exit syscall 
syscall

.data

newline:       .asciiz     "\n"