2.3: First Program in MIPS Assembly

The following is a first MIPS assembly program. It prints out the string " Hello World ". To run the program, first start the MARS program. Choose the File->New menu option, which will open an edit window, and enter the program. How to run the program will be covered in the following the program.

Program 2-1: Hello World program # Program File: Program2-1.asm # Author: Charles Kann # Purpose: First program, Hello World .text # Define the program instructions. main: # Label to define the main program. li $v0,4 # Load 4 into $v0 to indicate a print string. la $a0, greeting # Load the address of the greeting into $a0. syscall # Print greeting. The print is indicated by # $v0 having a value of 4, and the string to # print is stored at the address in $a0. li $v0, 10 # Load a 10 (halt) into $v0. syscall # The program ends. .data # Define the program data. greeting: .asciiz "Hello World" #The string to print.

Once the program has been entered into the edit window, it needs to be assembled. The option to assemble the program is shown circled in red below. Screen Shot 2020-06-28 at 10.50.51 PM.pngIf you entered the program correctly you should get the edit screen below. If you made any errors, the errors will be displayed in a box at the bottom of the screen. To run the program, click the green arrow button circled in the figure below. You should get the string " Hello World " printed on the Run I/O box. You have successfully run your first MIPS program. Screen Shot 2020-06-28 at 10.57.12 PM.png

2.3.1: Program 2-1 Commentary

Screen Shot 2020-06-28 at 11.02.07 PM.png

Program 2-1 was used to show how to compile and run a program. This is not an introductory programming class, and most readers probably are less interested in how to make the program work, and more interested in the details of the program. This section will go over a number of those details, and help the reader understand the program.

This page titled 2.3: First Program in MIPS Assembly is shared under a CC BY 4.0 license and was authored, remixed, and/or curated by Charles W. Kann III.

  1. Back to top