Fall 2000

Lab 4: DEBUGGING MIPS

CS61C

Purpose:

To practice debugging of MIPS programs. MAKE SURE YOU DO THE PRELAB BEFORE COMING TO LAB.

Prelab: The prelab deals with how to do debug in SPIM or XSPIM

    1. Once a breakpoint occurs, how do you get the program to continue?


    2. Once a breakpoint occurs, how do you step through the program?


    3. What are the registers ($0 to $31) that correspond to a) &source[0] b) &dest[0]?

Introduction:

This weeks lab tests your debugging skills. You will be given a C program and two potential MIPS programs that are supposed to implement the C code. Each has (at least) one bug. Load these MIPS programs into SPIM or XSPIM, set breakpoints to see the state of the loop, correct the bugs, and submit the required files. Copy lab4a.s and lab4b.s from ~cs61c/lab4.

Task:

This program just copies the given array from source to dest, but stops and does not copy when it finds a 0 (in the last element).

Here is the C version:
main( ) {
  int *sourceptr;
  int *destptr;
  int source[7] = {3, 1, 4, 1, 5, 9, 0}
  int dest[7];
  sourceptr = source;
  destptr = dest;
  while (*sourceptr != 0) {
          *destptr = *sourceptr;
          sourceptr++;
          destptr++;
  }
}


Here is the first MIPS version (actually taken from fa'96 61c lecture notes):

Assume that $s0 has the address of the source array, $s1 has the address of the dest array. This is in lab4a.s
loop:	lw  $t0, $0($s0)
	   sw $t0, $0($s1)
	   addiu $s0, $s0, 4
	   addiu $s1, $s1, 4
	   bne $t0, $0, loop 
1) Set a breakpoint at the address corresponding to instruction labeled by "loop". Run the program and look at the values of the registers.

2) What is/are the bug(s) in the first version?

3)Modify the code to fix the bugs and run it.

Here is the second MIPS version in lab4b.s:

loop:	addiu $s0, $s0, 4
	   addiu $s1, $s1, 4
	   lw $t0, $0($s0)
	   sw $t0, $0($s1)
	   bne $t0, $0, loop


4) Set the breakpoint at the loop again at "loop:" and look at the values in registers and memory.

5) What is/are the bug(s) in the second version?

6) How can you modify the code to fix it?

To Submit:

For check-off, create a directory named lab4 in your home directory, You are required to submit three files, lab4fixeda.s (contains the first MIPS program fixed), lab4fixedb.s (contains the second MIPS programs fixed) and lab4.txt (which contains the answer to the above questions). cd into lab4, and type submit lab4.

Last updated: 9/14