PROGRAM STRUCTURE
The following is a template on how to organize your program.
.data
(Constant and variable declarations go here.)
.text # Main (must be global).
.globl main
main: (Your program starts here.)
li $v0, 10 # Syscall to exit.
syscall
REMARKS
1- The order of the data and main sections is interchangeable
2- The main label always must be declare as global.
3- Always finish your program with a syscall to exit
REGISTERS
Registers are what we call variables in a high level language. A MISP
processor has 32 register named from 0 to 1 and distributed in the
following way.
zero : It always contains the value 0
at, k0, k1 : Used by the assembler to comunicate with the operating
system.
v0, v1 : v0 is used to set the value for a system call, and also it
can be use in addition to v1 to store values returned from a
system call
a0 - a3 : Used by the assembler to store the values of the arguments
passed to a system call.
t0 - t9 : temporary registers whose values are not preseved after a
function call.
s1 - s7 : Temporary registers whose values are preserved during a
function call
sp : Stack pointer. It points to the first free location on the
stack.
fp : Frame pointer. It is used to save the value of a frame in a
function call.
gp : Global pointer. It points into the middle of a 64k block of
memory in the heap that holds constant and global variables.
ra : Return address. It is use to save and restore the address
before and after a function call.
ASSEMBLER DIRECTIVES
Assembler directives are used to declare a section of a program, variables, strings and/or to align data in memory. The most important are:
.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.
.asciiz str
Store the string in memory and null-terminate it.
.data
The following data items should be stored in the data segment. If
the optional argument addr is present, the items are stored
beginning at address addr.
.float f1, ..., fn
Store the floating point single precision numbers in successive
memory locations.
.globl sym
Declare that symbol sym is global and can be referenced from other
files.
.space n
Allocate 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 may only be instructions or words (see the .word directive
below). If the optional argument addr is present, the items are
stored beginning at address addr.
.word w1, ..., wn
Store the 32-bit quantities in successive memory words.
SYSTEM CALLS
System calls are a set I/O operations that let you read and print
data. To request a system call do the following:
1- Select the system call that you are going to use an store it in the
$v0 register.
li $v0,4
2- Set the value of the arguments if the system call requires arguments.
la $a0,message
3- Use the keyword SYSCALL to execute the system call
SYSCALL
4- Some system calls return values. this values are stored in the $v0 or
$f0 (floating point) registers
A complete table containing all the system calls can be found on page 8
of the developers reference.