Using SPIM

Tom Kelliher, CS 240

Feb. 13, 2004

SPIM Debugging

  1. Modify addn.spim so that you can break on the unconditional branch which terminates the loop. (Remember, addn.spim is in ~kelliher/pub/cs240/unixlab1/ on phoenix.)

  2. Run SPIM, load addn.spim, and set a breakpoint at the end of the loop.

  3. Run the program and examine the values of the sum and loop count at the end of each iteration of the loop. Do these values make sense?

Assembly Language Programming

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);
}



Thomas P. Kelliher
Fri Feb 13 08:20:15 EST 2004
Tom Kelliher