Components of a MIPS Program
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 ( Identifiers. A sequence of alphanumeric characters
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 Strings.
A string of text is enclosed in double quotes. The usual escape sequences from C can be used: (
|