Name: Date:

HW8

  1. (3 points) In your own words explain what the "saver" column means on the RISC-V green sheet register table, make sure you explain the difference between what ''caller'' and ''callee'' mean in this table.

  2. (3 points) In a few words or diagram briefly describe caller's responsibilities in the RISC-V calling conventions for procedures. For full credit your answer must address how all the different kinds of registers are used before and after a calling convention. Including t's, s's, a's, ra, and sp.

  3. (3 points) In a few words or diagram briefly describe callee's responsibilities in the RISC-V calling conventions for procedures. For full credit address all the register types listed in the previous problem.

  4. (7 points) The following RISC-V 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, x0
        jal ra, BAR
        lw t0, 4(sp)
        add a0, a0, t0
        lw ra, 0(sp)
        addi sp, sp, 8
        jalr x0, 0(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 RISC-V 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, x0
        jal ra, BAR
        lw t0, 4(sp)
        add a0, a0, t0
        lw s0, 0(sp)
        addi sp, sp, 8
        jalr x0, 0(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 RISC-V procedure (FOO) that calls another procedure (BAR). This code has an error in it that does not follow the procedure calling conventions. The error in this one is subtle. If you get stuck consult the green sheet and your answers to problems 1 and 2.

    FOO:   addi sp, sp, -8
        sw s0, 0(sp)
        sw ra, 4(sp)
        add s0, a0, a2
        add a0, a2, x0
        jal ra, BAR
        add a0, a0, a2
        lw ra, 4(sp)
        lw s0, 0(sp)
        addi sp, sp, 8
        jalr x0, 0(ra)

    a. Circle the instructions that cause the error.

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