Sample MIPS Assembly Code

I/O

Addition

add.asm
addmain.asm

These demonstrate I/O by adding 2 numbers entered by the user.
They are identical except the second program uses main instead of __start.

Overdue Letter

letter.asm

Inputs a name, then outputs a personalized letter.

XOR

xor.asm

Inputs x and y, outputs x XOR y.

Loops

Loops

loops.asm

A simple program to print the integers from 1 to 10.

Do/While

do_while1.asm

do_while2.asm

Shows one way to convert a do/while loop to assembler code. The only difference between these two programs is that the C instruction

j = list[i]

is translated using a different addressing mode (one line of MIPS pseudocode or two).

Memory Array

array.asm

This program generates 100 values, stores them in a static array, then prints the values to the screen.

Procedures

fact.asm

A program to demonstrate a recursive procedure to calculate the factorial of an integer.

foo.asm

A basic procedure call which takes input and provides output (no stack manipulation).

exp.asm

Demonstrates a procedure that calculates an exponent (i^j). The procedure itself uses a loop of the form while(...) {...}.

sum.asm

A program to calculate the sum of array 1+2+3+...+N using recursive procedure.