Name: Date:

HW2

  1. (20 points) Convert the following C code to RISC-V assembly instructions. Use the minimum number of instructions necessary. Assume that variables f, g and h are 32- bit integers stored in registers x5, x6 and x7 respectively.

    Be careful not to modify the initial variable values unintentionally. If you need to store temporary values, use one of the other registers.

    a. f = g + h;

    b. f = g - (h - 5);

    c. f = 0x12345000 Hint: you cannot achieve this with a singular addi instruction, get creative with multiple instructions or review the reference sheet.

    d. g = 0x11111111 Hint: you cannot achieve this with a singular addi instruction, get creative with multiple instructions or review the reference sheet.

    e. h = 0x00000FFF Be careful with how RISC-V sign extends immediates!

(Continues on next page)
  1. (5 points) Consider changing the RISC-V instruction set to support 64 registers instead of 32. Draw the new R-type instruction format. You may not change the size of the opcode, funct3, nor funct7; you may only make changes to the register fields. You may go beyond 32 bits if necessary. Be sure to label each field and include its size.

  2. (5 points) How many possible R-type instructions does RISC-V support if every possible combination of opcode, funct7, and funct3 are valid instructions? (You can ignore other instruction types for this question.)