MIPS Assembly Language Programming Part 1

We start with a basic template for creating MIPS assembly language programming. Our target assembler is SPIM, available here for free. SPIM assembles and executes MIPS assembly language programs. It also provides some debugging tools. It does not require a MIPS hardware platform.

# File Name:
#  
# Author: nicomp
# Revision date: 
# References: 
# Starting Conditions / Assumptions:
#    What the registers should contain when the program begins...
#
# Ending Condition:
#    What the registers will contain when the program finishes...
#******************************************
#* Description:                           *
#*                                        *
#******************************************
.text 
.globl main 
main: 
#    Your code here



#    Graceful Exit
    li    $v0,10            # exit command for following syscall
    syscall 

.data
#your data here


Lines starting with # are comments, therefore the assembler ignores them. The majority of the template is comments. Like any assembly language, MIPS assembly language is notoriously not self-documenting, so we include several cues in the comments to remind you what's important. Don't be shy about adding more comments throughout the template. Imagine that you will have to revisit the program in a year; what would you want to know about it?

When creating a new program, don't start from scratch. Begin with the template, fill in the comments, then add your code following the main: label.

If you are writing a stand-alone program, leave the exit code in the template:

#   Graceful Exit
    li    $v0,10            # exit command for following syscall
    syscall


This code performs a system call that tells SPIM your program is finished.


More by this Author


Comments 1 comment

nicomp profile image

nicomp 6 years ago from Ohio, USA Author

MIPS rocks

    Sign in or sign up and post using a HubPages Network account.

    0 of 8192 characters used
    Post Comment

    No HTML is allowed in comments, but URLs will be hyperlinked. Comments are not for promoting your articles or other sites.


    Click to Rate This Article
    working