Name: Box: Date:

HW7

  1. In the following assembly code fragment, registers $t1 and $t2 are initialized to N and zero respectively.

    LOOP: beq  $t1, $0, DONE
          addi $t2, $t2, 1
          addi $t1, $t1, -1
          j LOOP
    DONE:

    a. (2 points) What is the value in register $t2 for when the code reaches the label DONE:?

    b. (2 points) How many MIPS instructions are executed?

    c. (6 points) If the registers $t1 and $t2 correspond to variables i and a respectively, write the equivalent C code for the loop.

  1. Consider the following C code fragment.

    for (i=0; i<a; i++) {
      a = a + b;
    }

    a. (4 points) Assuming that the values of i, a, and b in registers $t0, $t1 and $t2, translate the C code to MIPS assembly. Use a minimum number of instructions.

    b. (4 points) If the variables a and b are initialized to 10 and 1, what is the total number of MIPS instructions executed?