Next: System Calls
Up: SPIM S20: A MIPS
Previous: Surprising Features
Comments in assembler files begin with a sharp-sign (#).
Everything from the sharp-sign to the end of the line is ignored.
Identifiers are a sequence of alphanumeric characters, underbars (
_), and dots (.) that do not begin with a number. Opcodes for
instructions are reserved words that are not valid identifiers.
Labels are declared by putting them at the beginning of a line
followed by a colon, for example:
.data
item: .word 1
.text
.globl main # Must be global
main: lw $t0, item
Strings are enclosed in double-quotes ("). Special characters
in strings follow the C convention:
newline \n
tab \t
quote \"
SPIM supports a subset of the assembler directives provided by the
MIPS assembler:
-
- .align n
Align the next datum on a
byte
boundary. For example, .align 2 aligns the next value on a word
boundary. .align 0 turns off automatic alignment of
.half, .word, .float, and .double directives until
the next .data or .kdata directive.
-
- .ascii str
Store the string in memory, but do
not null-terminate it.
-
- .asciiz str
Store the string in memory and
null-terminate it.
-
- .byte b1, ..., bn
Store the n values in
successive bytes of memory.
-
- .data
The following data items should be
stored in the data segment.
-
- .double d1, ..., dn
Store the n floating
point double precision numbers in successive memory locations.
-
- .extern sym size
Declare that the datum
stored at sym is size bytes large and is a global symbol.
This directive enables the assembler to store the datum in a portion
of the data segment that is efficiently accessed via register
$gp.
-
- .float f1, ..., fn
Store the n floating
point single precision numbers in successive memory locations.
-
- .globl sym
Declare that symbol sym is
global and can be referenced from other files.
-
- .half h1, ..., hn
Store the n 16-bit
quantities in successive memory halfwords.
-
- .kdata
The following data items should be
stored in the kernel data segment.
-
- .ktext
The next items are put in the kernel
text segment. In SPIM, these items must be instructions or words (see
the .word directive below).
-
- .space n
Allocate n bytes of space in the
current segment (which must be the data segment in SPIM).
-
- .text
The next items are put in the user text
segment. In SPIM, these items must be instructions or words (see the
.word directive below).
-
- .word w1, ..., wn
Store the n 32-bit
quantities in successive memory words.
SPIM does not distinguish various parts of the data segment (
.data, .rdata, and .sdata).
Next: System Calls
Up: SPIM S20: A MIPS
Previous: Surprising Features
Mitch Roth
Fri Sep 6 23:25:26 ADT 1996