HW: MIPS (Part A)

    22 pts total

  1. Write a MIPS assembly program (with comments) that corresponds to the following C program. Do not use pseudo-instructions.
            int C[4] = {3, 4, 5, 7};
            main ()
              int i;
              int a = 0;
              for (	i=0; i < 4; i++) 
                 a += C[i];
    The global array C should be set up in the data segment of your program. (Optional: step through your program using MARS to be sure that it works as expected.)
  2. 15 pts

  3. (2.27) Translate the following C code to MIPS assembly code. Use a minimum number of instructions. Assume that the values of a, b, i and j are in registers $s0, $s1, $t0 and $t1, respectively. Also assume that register $s2 holds the base address of the array D. Do not use pseudo-instructions.
        for ( i = 0; i < a; i++ )
            for ( j = 0; j < b; j++ )
                D[4*j] = i + j;
  4. 5 pts

  5. (2.28) For the C code in the previous question, how many MIPS instructions does it take to implement the C code? If the variables a and b are initialized to 10 and 1 and all elements of D are initially 0, what is the total number of MIPS instructions that is executed to complete the loop?
  6. 2 pts