CPSC220: Introduction to Computer Architecture (Fall 2013)

Assignment #4

Due at the end of class on Thursday, 10/10/2013

Reading

To do

  1. Translate the following code into MIPS assembly code, using as few instructions as possible. Assume that variables a, b, and i are all declared with type int:

    for (int i = 0;  i < a; i += 1) {
        a += b;
    }
    
  2. Translate the following code into MIPS assembly code, using as few instructions as possible. Assume that variables a, b, i, and j are all declared with type int, and that D is an int array.

    for (int i = 0;  i < a; i += 1) {
        for (int j = 0; j < b; j += 1) {
            D[4 * j] = i + j;
        }
    }
    
  3. Translate the following loop into equivalent C/C++/Java code:

            addi    $t1, $0, 50
    LOOP:   lw      $s1, 0($s0)
            add     $s2, $s2,  $s1
            lw      $s1, 4($s0)
            add     $s2, $s2,  $s1
            addi    $s0, $s0, 8
            subi    $t1, $t1, 1
            bne     $t1, $0,  LOOP
    
  4. Rewrite the loop above to reduce the number of MIPS instructions executed.


Turn in:

To hand in your files: