Name: Box: Date:


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

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

    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, $t2, and $t3 correspond to variables i, a, and t respectively, write the equivalent C code for the loop. Note: you probably won't end up with a t variable in your answer.

  1. (20 points) Below is a snippet from a Checkers game program in C.

    void setKing(int row, int col, int isKing)
      int* rowAddr = getRowAddr(row); //returns the memory address of row
      rowAddr[col] = isKing;

    Fill in the missing portions of the setKing function below, adhering to the MIPS procedure call conventions. You should assume setKing is called according to MIPS convention.

    setKing:   #entry point to setKing procedure
    jal     getRowAddr  #call to getRowAddr
    jr    $ra   #return form setKing