Name: Box: Date:

HW5

  1. (3 points) In your own words explain what "preserved across call'" means on the MIPS green sheet.

  2. (3 points) In a few words or diagram briefly describe caller's responsibilities in the MIPS calling conventions for procedures.

  3. (3 points) In a few words or diagram briefly describe callee's responsibilities in the MIPS calling conventions for procedures.

  4. (7 points) The following MIPS procedure (FOO) calls another procedure (BAR). This code has an error in it that does not follow the procedure calling conventions.

    FOO:   addi $sp, $sp, -8
        sw $ra, 0($sp)
        sw $a1, 4($sp)
        add $s0, $a0, $a1
        add $a0, $a1, $0
        jal BAR
        lw $t0, 4($sp)
        add $v0, $v0, $t0
        lw $ra, 0($sp)
        addi $sp, $sp, 8
        jr $ra

    a. Circle the instructions that cause the error.

    b. Explain why this error could cause problems if the code was not changed.

  5. (7 points) The following snippet of MIPS procedure (FOO) that calls another procedure (BAR). This code has an error in it that does not follow the procedure calling conventions.

    FOO:   addi $sp, $sp, -8
        sw $s0, 0($sp)
        sw $a1, 4($sp)
        add $s0, $a0, $a1
        add $a0, $a1, $0
        jal BAR
        lw $t0, 4($sp)
        add $v0, $v0, $t0
        lw $s0, 0($sp)
        addi $sp, $sp, 8
        jr $ra

    a. Circle the instructions that cause the error.

    b. Explain why this error could cause problems if the code was not changed.

  6. (7 points) The following snippet of MIPS procedure (FOO) that calls another procedure (BAR). This code has an error in it that does not follow the procedure calling conventions.

    FOO:   addi $sp, $sp, -8
        sw $s0, 0($sp)
        sw $ra, 4($sp)
        add $s0, $a0, $a1
        add $a0, $a1, $0
        jal BAR
        add $v0, $v0, $a1
        lw $ra, 4($sp)
        lw $s0, 0($sp)
        addi $sp, $sp, 8
        jr $ra

    a. Circle the instructions that cause the error.

    b. Explain why this error could cause problems if the code was not changed.