Lab 1 - Assembling MIPS code on Sleipnir

Due: Noon on Wednesday

The software installed on Sleipnir is MIPS Technologies SDE (Software Development Environment) Lite version 6.0. This differs from the SPIM software available on the book CD. All code turned in for the class should assemble using SDE Lite. You may use SPIM at home if you cannot access Sleipnir remotely, but confirm that the code also works on Sleipnir using the methods described in this lab before turning it in.

Setting up SDE

Do the following shell commands when logged in to Sleipnir to set up SDE Lite:
. /usr/local/sde6/bin/sdeenv.sh
mkdir cs321
chmod og-rx cs321
cd cs321
sdemklocal
ln -s sde-6.06.01/examples/make.mk
This creates a directory structure similar to the following:
                                cs321
                         ______/  |  \_____
                        /         |        \
                       /          |         \
                 sde-6.06.01   make.mk  <lab_subdirs>
                    /    \
                   |      |
                  kit  examples
Each time you log into Sleipnir and you want to run the SDE Lite tools, you will need to rerun the command . /usr/local/sde6/bin/sdeenv.sh. Note that there is a period at the start of this command. That is the shell command to do "source" a shell script. You need to source /usr/local/sde6/bin/sdeenv.sh before you can use the SDE Lite tools. You may wish to add that line to your .profile for the duration of this class so that the file is automatically sourced when you log in.

The other commands set up a cs321 directory and copy the SDE files over to your cs321 directory. At this point, you can make subdirectories off your cs321 directory that will contain the assembly code you are creating.

Testing SDE with "Hello World" in MIPS assembly

Make a directory off cs321 called hello. Copy and paste the Makefile and hello.s files from http://www.cs.csubak.edu/~mdanfor/cs321-w07/code/hello/ to like-named files in your hello directory. When pasting in vi on Sleipnir, be sure to issue the following command to turn off indenting:
:set paste
When you are done pasting, you can turn indenting back on for coding using:
:set nopaste
Once you have copied Makefile and hello.s, you can compile and run the assembly with the following two commands:
sde-make
sde-run helloram
If sde-make fails, the most likely issue is not having your directory structure set up correctly. If hello is not a subdirectory of cs321, then sde-make will fail.

If this is the first time you have seen a MIPS assembly program, refer to Appendix A in the book for more details about the allowed syntax. In brief, the code has two sections, a data section for the "Hello world" string and a text portion containing the code to be executed. The la instruction loads the address into the register, which is most useful for arrays and strings. The li instruction loads a constant into the register. The syscall instruction executes the specified syscall (see page A-44 for the syscall codes).

Assignment

Create a subdirectory called lab2 and change to that directory. Copy the Makefile from hello and edit it to change all instances of hello to sum. Create an assembly file called sum.s that takes two constants and adds them together.

You can use printf to print the results by adding the following to your .data section:

format:
        .asciiz "The sum is %d\n"
and by adding the following to your .text section:
        la      $a0,format      # Put format string in $a0
        move    $a1,$v0         # Put the sum in $a1, $v0 contains the sum
        jal     printf          # Call the printf function
Email your sum.s file to me before noon on Wednesday.