MIPS Reference


Components of a MIPS Program

<< Registers | Table of Contents | Assembler Directives >>

This section reviews some of the basic components of a MIPS assembly language program. Consider the following sample program

# ex1.asm
# This is an example that illustrates the various components of
# an assembly language program.
#
        .text
                # Program code goes in the text segment. This is an
                # example of an assembler directive.

main:           # default starting position

        add $t2, $t1, $t0

        li $v0, 10    # These two lines serve as a halt statement.
        syscall       # More on this later - just use them for now.

        .data

grade:   .word      50
code:    .half      0x10
array:   .byte      5, 70, -20, 65
name:    .ascii     "A string"
message: .asciiz    "Another string"

Instructions. The instruction set includes both the base machine instructions and the pseudo-instructions. We will learn the syntax as we deal with the various instructions.

Comments. Comments begin with a hash symbol (#) and continue to the end of the line.

Identifiers. A sequence of alphanumeric characters

  • can include underscore (_) and a dot (.)
  • cannot start with a digit
  • opcodes are reserved (keywords representing the instructions or operations).

Labels. An identifier at the beginning of the line followed by a colon. These are used to identify sections of code and for branching.

Numbers. Are base-10 by default. Hexadecimal values are denoted by preceding the value with 0x. (i.e. 0x100 denotes 256).

Strings. A string of text is enclosed in double quotes. The usual escape sequences from C can be used: (\n \t \").


<< Registers | Table of Contents | Assembler Directives >>


MIPS Processor and Assembly Language Reference

Print - Changes - Search
Last modified: September 03, 2009, at 10:10 AM.