CS U380 - Lab 4, Spring, 2009

Adapted from: CS61C, UCBerkeley

Debugging MIPS

Prelab:

Think about these questions before you try the lab. They should make the lab easier.

    1. In MARS, how do you get the program to continue after it stops at a breakpoint?


    2. In MARS, how do you step through a stopped program?


    3. What are the registers that correspond to &source[0] and &dest[0] in this lab's C program?

Introduction:

This week's 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 MARS, set breakpoints to see the state of the loop, correct the bugs, and give me a paper copy of the required files. Copy lab4a.s and lab4b.s from /course/csu380jc/.www/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 (from a teacher's 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)
        addi    $s0,$s0,4
        addi    $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:   addi    $s0,$s0,4
        addi    $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?

Checkoff:

Get ready to explain the bugs in each version of the MIPS code. Then, get a fixed version of the code running in MARS. Then print out a copy and hand it to me.




This page last modified 10/16/2008.