Datorteknik, FAQ

This page contains some FAQ:s for the course in "datorteknik" at BTH. It describes some common problems with MIPS assembly

How do I use the symbolic register names (a0, t0 etc)?

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.

What is .text and .data?

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.

What is the C calling convention and how does it work?

The C calling convention specifies how functions/procedures/subroutines are called. It contains several things, among which:

How does printf work?

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

I need a test program for the last MIPS task (input/output system), what should I write?

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.

How do MIPS exceptions/interrupts work (for the lab)?

There is a PDF describing the needed information for the interrupt lab here (in Swedish).


$Id: datorteknik.html 2632 2005-05-31 08:43:55Z ska $