Lab 1: Intro to MIPS

Due: Sunday, March 13 at 23:59

Your task is to write a program which takes in a number and stores it in a four-element array at a user-specified index, then prints the contents of the array. You will write this program using the MARS MIPS simulator, which you can download here.


First, download MARS.

If you don’t already have a GitHub account, make one. As a student, you can get additional GitHub benefits such as unlimited private repositories here, but you don’t need to for this course. All of your repositories will be private to you and course instructors.

You’ll need Git installed in order to download and submit assignments. On macOS, Git is included with Xcode which can be installed from the App Store. On Linux, Git can be installed using your distribution’s package manager. You can install any of the many other Git tools instead, including GitHub Desktop on macOS and Windows.

Click on the assignment link.

Once you have accepted the assignment, you can clone the repository on your computer by following the instruction and begin working.

Be sure to ask any questions on Piazza.

Program specification

Read two input values from the keyboard:

  1. a number to enter in the array; and
  2. the index of the array where you should store the first number.

Print out each index of the array, and its contents. It should look like this.

  Please enter a number 6
  Which element of the array would you like this to be? 1
  0: 0
  1: 6
  2: 0
  3: 0

Or like this.

  Please enter a number 3
  Which element of the array would you like this to be? 0
  0: 3
  1: 0
  2: 0
  3: 0

You can assume the user will not input any indexes outside of the bounds of the array. You are required to store the user’s value in memory at the specified position, and to load every value in the array from memory into a register to print it out.

Note that you will need to translate between indices, which are word addresses, and values in memory, which are byte addresses.

Make sure to document your programs thoroughly. (This is especially important in assembly language programs, since the code itself is less easily read than high-level language code.) This should include:

  1. A block of comment lines at the beginning of the source file, giving the name and author of the program and a black-box description of what it does.
  2. A few comment lines between major sections of the program, describing the contents of each section.
  3. A comment at the end of most source lines, describing what the instruction on that line does.

Helpful resources


  1. You will need to use various system calls to print strings, integers, etc. These are all provided on the list of system calls linked above.
  2. The la instruction loads the address of a label. You can use this to load the addresses of any of the variables in the .data section of your code.
  3. The mul instruction will allow you to multiply a register by a constant.
  4. I have included some strings you may find helpful in the .data section.
  5. You do not need to write any loops.
  6. Your array must be 4-byte aligned. You can use
    .align 2
    arr: .space 16

    to get a 4-byte aligned array.


Submit the lab by committing your code and pushing it to your GitHub repository. From the command line, you would enter the commands

$ git commit -m "Finished!" lab01.asm
$ git push

from inside your repository’s directory.

The first command instructs Git to take the changes that you made to lab01.asm and record those changes on your computer. Usually, when writing software, you would make multiple commits. This allows you to “easily” go back to previous versions. (“Easily” is in quotes because nothing with Git is ever actually easy.)

The second command instructs Git to take all of the changes that you have committed and push them to your repository on GitHub. You can push each time you commit, or you can push after several commits have been made and all commits that haven’t yet been pushed to GitHub will be pushed at that time.

If you don’t push after comitting the final version of your code, the graders will not be able to see your changes (because they’ve only been recorded on your local computer).

Rather than use the command line, you can visit the web page for your repository on GitHub and drag and drop the files on the page. I don’t recally recommend doing this; it’s better to learn how to use Git properly. But it does work and you’re welcome to do it.