CSCI 210: Lab 1
Intro
to
MIPS
Due:
9:59
PM
on
Monday,
February 20th
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.
Preliminaries
You will write this program using the MARS MIPS simulator, which you can download here. I have posted a short video demo about how to use MARS, which I recommend you watch.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 instructions and begin working.
Be sure to ask any questions on Piazza.
Program Specification
Read two input values from the keyboard:
- a number to enter in the array
- the index of the array where you should store it.
Print out each index of the array, and its contents. This will look like:
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
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:
- 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.
- A few comment lines between major sections of the program, describing the contents of each section.
- A comment at the end of most source lines, describing what the instruction on that line does.
Helpful Resources
Hints
- You will need to use various system calls to print strings, integers, etc - these are all provided on the list of system calls linked from the lab.
- 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.
- The mul instruction will allow you to multiply a register by a constant.
- I have included some strings you may find helpful in the .data section.
- Your array must be 4-byte aligned. You can use
.align 2 arr: .space 16
Submission
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 really recommend doing this; it’s better to learn how to use Git properly. But it does work and you’re welcome to do it.
C. Taylor, S. Checkoway