This page contains some FAQ:s for the course in "datorteknik" at BTH. It describes some common problems with MIPS assembly
To use these, you need to include a file which has their definitions, iregdef.h. Add:
#include <iregdef.h>
To the top of your assembly-file.
These define "sections" in your program. The .text section contains program code and the .data section contain data (numbers, strings etc).
For example:
.data
NBR: .word 1
.text
la t0, NBR
A .data or .text section is valid from the point where you write it and onwards.
The C calling convention specifies how functions/procedures/subroutines are called. It contains several things, among which:
# int hello(int a)
sub sp, sp, 4 # space for one argument on the stack
li a0, 1
jal hello # hello(1)
lw a0, 0(sp) # restore a0
add sp, sp, 4 # restore stack
Printf expects an address to a format string in register a0 and then other arguments in a1..a3 followed by stacked arguments.
.data
fmt: .asciiz "hello and goodbye. The number is %d\n"
.text
sub sp, sp, 16 # space for 4 arguments
la a0, fmt # address of fmt in a0
li a1, 5 # number to printout
jal printf # This will printout "hello and goodbye. The number is 5" followed by a newline.
add sp, sp, 16 # restore stack
You should write a test program which tests the functions together with each other. This is very important, it is not enough with an implementation where all functions work when run by themselves.
For instance, if implemented in C, such a test program could look as follows:
/* Read a line */ inimage(); /* Test getchar/putchar */ ch = getchar(); putchar(ch); /* Test setinpos, getint and putint */ setinpos(3); nr = getint(); putint(nr); /* Print the result */ outimage();
Note that this example is not complete, you also need to test getint(), putint() etc.
There is a PDF describing the needed information for the interrupt lab here (in Swedish).