Tom Kelliher, CS 220
Sept. 30, 2009
% spim
(spim) load "addn.spim"Note that the quotes are required.
(spim) run
(spim) reinitialize
(spim) quit
help command gives a list of the available commands.
.globl) label.
(spim) br while
(spim) co
(spim) stStep through next
n instructions:
(spim) st n
n:
(spim) print $nThis also works for the symbolic register names.
(spim) print_all_regs
n:
(spim) print n
Exercise:
addn.spim so that you can break on the unconditional
branch which terminates the loop.
addn.spim, and set a breakpoint at the end of
the loop.
The easiest way to write an assembly language program is to first write a HLL program and then compile it manually. Rewrite the following C program in MIPS assembly and run it in SPIM.
/***********************************************************************
* fibonacci.c --- Compute and display the Fibonacci sequence.
*
* Tom Kelliher
*
* Input: Length of sequence to generate.
*
* Output: Fibonacci sequence of given length.
*
* Notes: The boundary conditions of lengths 0 and 1 aren't handled
* properly. Correcting this is left as an exercise to the
* student.
***********************************************************************/
#include <stdio.h>
#include <stdlib.h>
int main()
{
int len; /* Use $s0. */
int i; /* Use $s1. */
int current; /* Etc. */
int old;
int older;
printf("Enter sequence length: ");
scanf("%d", &len);
len = len - 2;
old = 1;
older = 1;
printf("1\n1\n");
for (i = 0; i < len; ++i)
{
current = old + older;
printf("%d\n", current);
older = old;
old = current;
}
exit(0);
}