Several Simple Programs in the MIPS Assembly Language
This repository contains six simple programs written in the MIPS Assembly language. MIPS is an acronym for Microprocessor without Interlocked Pipeline Stages. It was developed by Dr. John Hennessey and his graduate students at Stanford University in the 1980s. MIPS is a low-level language that communicates more directly with the computer's hardware. The language is not built like most modern assembly languages given that it has been simplified for educational purposes. You can find more information about the MIPS Assembly language here: https://www.d.umn.edu/~gshute/mips/mal-introduction.html. The assembly language programs in this project are run in a Mars simulator that is included in this repository as a Mars4_5.jar file. Each program performs a certain function such as repeatedly subtracting numbers, adding up a series of numbers, or recursively sorting an array. Details about each assembly program as well as how to run it are shown below the steps to setting up the Mars environment.
Resources for Project:
- MIPS Assembly Language
- Mars (IDE)
- NOTE: For additional visual assistance, see the screenshots below under the "Screenshots for Setting up Mars Environment" section. You can access this section by scrolling down this page or clicking on the link: Screenshots for Setting up Mars Environment.
- Click on the green
Code
button in the righthand corner of the project page (SeeScreenshot 1.0
below for visual details). - Click the
Download Zip
option in the dropdown menu that appears after you click the green Code button. - Go to your
Downloads
on your computer and drag / move the zipped folder onto your Desktop or any location that is easy for you to access. - Double click on the zipped folder to open its contents. A folder called "Assembly-Programs-master" should appear in the same location as the zipped file after you double click the zipped file to open it.
- Double click on the "Assembly-Programs-master" folder to see its contents. Then double click on the Mars4_5.jar file to open it.
- IMPORTANT: You will likely get an error saying that the Mars4_5.jar file cannot be opened because it is from an unidentified developer. To solve this issue, first navigate to your
System Preferences / Settings
on your computer (SeeScreenshot 2.0
below for visual details). - In your System Preferences / Settings, click on the
Security and Privacy
icon / settings (SeeScreenshots 3.0, 4.0, and 5.0
below for visual details). - Inside of the Security and Privacy settings, under the
General
tab, you should see a message that says: "Mars4_5.jar file was blocked from use because it is not from an identified developer." Click theOpen Anyway
button, which should be appearing alongside the message. (SeeScreenshot 6.0
below for visual details). - After clicking the "Open Anyway" button, you will likely get a message that asks if you are sure that you want to open the Mars4_5.jar file. Click the "Open" button on the message (See
Screenshot 7.0
below for visual details). - Your Mars4_5.jar file should now open on your computer. See
Screenshot 8.0
if you want to compare what your Mars workspace looks like compared to the attached screenshot (they should look very similar). - See the following project descriptions below this step to run whichever assembly program you would like using the Mars environment.
- IMPORTANT: I would recommend starting with the first program, which is
helloprogram0mips.asm
. How you open the file in the Mars environment and run it is very similar to the other programs you can run in this project. However, "helloprgram0mips.asm" is the only assembly program that has detailed screenshots on opening and running it. The other programs follow the same process. If you are running a different program and cannot remember how to open a file, refer back to the "helloprogram0mips.asm" program screenshots for help. - For more information on the Mars environemnt (IDE), click the following link: http://courses.missouristate.edu/kenvollmar/mars/.
Program 1: helloprogram0mips.asm
(Refer back to screenshots here if you get stuck on running the other programs)
Simple Hello World Program
The program, when run, prints out a simple "Hello World" message in the Mars "Run I/O" tab. The value of a variable is also printed out as it is changed in a loop within the program. Steps to running the program are listed below:
- First, click on "File" in the Mars environemnt. Then click "Open". A window should open where you can select a .asm file to open in the Mars environment.
-
If you do not see any .asm files you can select to open, navigate to the project folder you downloaded from this repository. Select the "helloprogram0mips.asm" file. Click "Open".
-
To run the program, click on the "Run" option at the top of the Mars environment window, and then click "Assemble".
- You should recieve a message in the "Mars Messages" tab at the bottom of the Mars environment window indicating that the execution completed successfully (See the screenshot shown below).
- After you see the confirmation message, "execution completed successfully", click the green run icon (See screenshots shown below). The program should run, and you should see the output on the "Run I/O" tab at the bottom of the Mars environment window.
- At this point, the program should have been executed. Keep in mind that the more program files you open, the more tabs will appear in your Mars environment (each tab is for each program opened). To close a certain program down, click "File" and then click "Close" to close the program you want taken out of the Mars environment. Click "Close All" to take all the programs out of the Mars environement (See screenshot shown below).
- Try the other programs! Keep in mind that some of the programs will require you to enter some input in the form of numbers.
Program that Lists Numbers
The program displays 12 values in decreasing order by the value of 7. The program starts with the value of 700, and decrements the value from that point onward. The decrementation will be printed out on the screen. If you need to see any screenshots, which were shown in "Program 1: helloprogram0mips.asm", click the following link: See screenshots on opening and running the program. Steps to running the program are listed below.
- First, click on "File" in the Mars environemnt. Then click "Open". A window should open where you can select a .asm file to open in the Mars environment.
- If you do not see any .asm files you can select to open, navigate to the project folder you downloaded from this repository. Select the "firstnumberlist.asm" file. Click "Open".
- To run the program, click on the "Run" option at the top of the Mars environment window, and then click "Assemble".
- You should recieve a message in the "Mars Messages" tab at the bottom of the Mars environment window indicating that the execution completed successfully.
- After you see the confirmation message, "execution completed successfully", click the green run icon. The program should run, and you should see the output on the "Run I/O" tab at the bottom of the Mars environment window.
- At this point, the program should have been executed. Keep in mind that the more program files you open, the more tabs will appear in your Mars environment (each tab is for each program opened). To close a certain program down, click "File" and then click "Close" to close the program you want taken out of the Mars environment. Click "Close All" to take all the programs out of the Mars environement.
Program that Sums the Numbers in an Array
The program adds together the indices of a while loop that runs 10 times. The previous value of the indice is printed off before being added to the value of the next indice. After the program is run, the following values should appear in the "Run I/O" section of the Mars environment: 0 1 3 6 10 15 21 28 36 45. If you need to see any screenshots, which were shown in "Program 1: helloprogram0mips.asm", click the following link: See screenshots on opening and running the program. Steps to running the program are listed below.
- First, click on "File" in the Mars environemnt. Then click "Open". A window should open where you can select a .asm file to open in the Mars environment.
- If you do not see any .asm files you can select to open, navigate to the project folder you downloaded from this repository. Select the "indicesum.asm" file. Click "Open".
- To run the program, click on the "Run" option at the top of the Mars environment window, and then click "Assemble".
- You should recieve a message in the "Mars Messages" tab at the bottom of the Mars environment window indicating that the execution completed successfully.
- After you see the confirmation message, "execution completed successfully", click the green run icon. The program should run, and you should see the output on the "Run I/O" tab at the bottom of the Mars environment window.
- At this point, the program should have been executed. Keep in mind that the more program files you open, the more tabs will appear in your Mars environment (each tab is for each program opened). To close a certain program down, click "File" and then click "Close" to close the program you want taken out of the Mars environment. Click "Close All" to take all the programs out of the Mars environement.
Program that Lists Numbers with Additional Features
This program is slightly different compared to programs 1-3. The program requires the user to enter in a numerical value in the "Run I/O" tab at the bottom of the Mars environment. The program then takes that numerical value and subtracts the value of 7 from it 12 times. The original value entered by the user as well as the results of the subtractions made on that value are printed out within the "Run I/O" tab at the bottom of the Mars environment after the program finishes running. If you need to see any screenshots for opening the file, which were shown in "Program 1: helloprogram0mips.asm", click the following link: See screenshots on opening and running the program. Steps to running the program are listed below.
- First, click on "File" in the Mars environemnt. Then click "Open". A window should open where you can select a .asm file to open in the Mars environment.
- If you do not see any .asm files you can select to open, navigate to the project folder you downloaded from this repository. Select the "listnumbers.asm" file. Click "Open".
- To run the program, click on the "Run" option at the top of the Mars environment window, and then click "Assemble".
- You should recieve a message in the "Mars Messages" tab at the bottom of the Mars environment window indicating that the execution completed successfully.
- After you see the confirmation message, "execution completed successfully", click the green run icon. The program should run, and you should see the output on the "Run I/O" tab at the bottom of the Mars environment window.
- ENTER INPUT (Number): Enter a numerical value in the "Run I/O" tab window, and hit your
ENTER / RETURN
keyboard on your computer. The program should then execute. - At this point, the program should have been executed. Keep in mind that the more program files you open, the more tabs will appear in your Mars environment (each tab is for each program opened). To close a certain program down, click "File" and then click "Close" to close the program you want taken out of the Mars environment. Click "Close All" to take all the programs out of the Mars environement.
Program that Recursively Sorts an Array
Like Program 4
, this program requires the user to enter in some numerical input in order the program to execute. The program recursively sorts through an array of values, and displays the value in numerical order from least to greatest. If you need to see any screenshots for opening the file, which were shown in "Program 1: helloprogram0mips.asm", click the following link: See screenshots on opening and running the program. Steps to running the program are listed below.
- First, click on "File" in the Mars environemnt. Then click "Open". A window should open where you can select a .asm file to open in the Mars environment.
- If you do not see any .asm files you can select to open, navigate to the project folder you downloaded from this repository. Select the "recursivesort.asm" file. Click "Open".
- To run the program, click on the "Run" option at the top of the Mars environment window, and then click "Assemble".
- You should recieve a message in the "Mars Messages" tab at the bottom of the Mars environment window indicating that the execution completed successfully.
- After you see the confirmation message, "execution completed successfully", click the green run icon. The program should run, and you should see the output on the "Run I/O" tab at the bottom of the Mars environment window.
- ENTER INPUT (Number for array size): Enter a numerical value in the "Run I/O" tab window. This number will represent the size of your array. Remeber, the number you enter here corresponds to the number of values you will have to enter after you hit your
ENTER / RETURN
keyboard on your computer. For example, if I enter the value of3
in the "Run I/O" window, I will have to enter three other numbers (see the next step below). - ENTER INPUT (Number value(s) in array): In the same "Run I/O" window, enter the numbers that will go into the array. Remember that the number of numerical values you enter here depends on the number you entered in the last step. In the last step, I used the value of
3
for the size of the array. So I could enter 12, -3, and 27 as the3
values in my array. I specified three numbers (make them all different from each other) to put in the array. Each time you enter a number, you need to hit theENTER / RETURN
keyboard on your computer before entering the next number. After you enter the last number and hitENTER / RETURN
, the program should execute. - At this point, the program should have been executed. Keep in mind that the more program files you open, the more tabs will appear in your Mars environment (each tab is for each program opened). To close a certain program down, click "File" and then click "Close" to close the program you want taken out of the Mars environment. Click "Close All" to take all the programs out of the Mars environement.
Program that uses the Simple Sort Algorithm on Arrays
This program is very similar to Program 5
. However, a key difference is that the program utilizes the a simple sorting algorithm as opposed to recursion. If you want additional information on different kinds of simple sorts, click the following link: https://www.geeksforgeeks.org/sorting-algorithms/. If you need to see any screenshots for opening the file, which were shown in "Program 1: helloprogram0mips.asm", click the following link: See screenshots on opening and running the program. Steps to running the program are listed below. The steps are very similar to Program 5
.
- First, click on "File" in the Mars environemnt. Then click "Open". A window should open where you can select a .asm file to open in the Mars environment.
- If you do not see any .asm files you can select to open, navigate to the project folder you downloaded from this repository. Select the "simplesort.asm" file. Click "Open".
- To run the program, click on the "Run" option at the top of the Mars environment window, and then click "Assemble".
- You should recieve a message in the "Mars Messages" tab at the bottom of the Mars environment window indicating that the execution completed successfully.
- After you see the confirmation message, "execution completed successfully", click the green run icon. The program should run, and you should see the output on the "Run I/O" tab at the bottom of the Mars environment window.
- ENTER INPUT (Number for array size): Enter a numerical value in the "Run I/O" tab window. This number will represent the size of your array. Remeber, the number you enter here corresponds to the number of values you will have to enter after you hit your
ENTER / RETURN
keyboard on your computer. For example, if I enter the value of3
in the "Run I/O" window, I will have to enter three other numbers (see the next step below). - ENTER INPUT (Number value(s) in array): In the same "Run I/O" window, enter the numbers that will go into the array. Remember that the number of numerical values you enter here depends on the number you entered in the last step. In the last step, I used the value of
3
for the size of the array. So I could enter 12, -3, and 27 as the3
values in my array. I specified three numbers (make them all different from each other) to put in the array. Each time you enter a number, you need to hit theENTER / RETURN
keyboard on your computer before entering the next number. After you enter the last number and hitENTER / RETURN
, the program should execute. - At this point, the program should have been executed. Keep in mind that the more program files you open, the more tabs will appear in your Mars environment (each tab is for each program opened). To close a certain program down, click "File" and then click "Close" to close the program you want taken out of the Mars environment. Click "Close All" to take all the programs out of the Mars environement.
Screenshot 2.0: You will Receive an Error Message that States you Cannot Open the File because it is from an Unidentified Developer
Screenshot 7.0: After Clicking the "Open Anyway" Button, Click the "Open" Button in the Pop-up Message (if it appears)
@Author: Andrew Krause
LinkedIn: https://www.linkedin.com/in/andrew-krause-b6aa21179/
Portfolio: https://andrewkrause.dev/
Instagram: https://www.instagram.com/aek.krause/
Facebook: https://www.facebook.com/andrew.krause.35325