Homework 1 - Chapter 2

Due: Tuesday, January 20, 2009 at 5:00pm

  1. (2 pts) Why are some instructions listed in Appendix A marked as pseudoinstructions? How is a pseudoinstruction different than a regular instruction?
  2. (2 pts) Construct a flow graph for the following snippet of C code:
        for(i = 0; i < size; i++)
          a[i] = i + 5;
        
  3. (4 pts) Translate the loop in Question 2 to MIPS assembly.
  4. (4 pts) Translate the MIPS assembly in Question 3 to binary instructions.
  5. (4 pts) Translate the following C code into MIPS assembly:
        int main() {
          printf("The 5th Fibonacci number is %d\n", fib(5));
        }
        int fib(int n) {
          if(n == 0) return 0;
          if(n == 1) return 1;
          return fib(n-1) + fib(n-2);
        }
        
  6. (4 pts) Show the sequence of actual MIPS instructions needed to implement the following pseudoinstructions:
    1. move $t1, $s3
      Equivalent to: $t1 = $s3
    2. bgt $t0, $s2, Label
      Equivalent to: if($t0 > $s2) go to Label