Name: Date:

HW3.

  1. (10 points) Consider the following 32-bit binary items.

    0000 0000 1000 0100 0000 0100 0011 0011
    0100 0000 0101 0100 1000 0100 0011 0011

    a. Assuming the items above are instructions, what RISC-V assembly instructions do they represent? Include all operands to the instruction in your answer. Hint: decoding RISC-V instructions always start with the opcode.

    b. Assuming the items above are data (i.e. base 10 integers), what value do they represent?

    c. If the above 32 bits are stored in a register in the register file, are they representing instructions or data? What if they are stored in memory? How can you tell if the bits represent instructions or data? Explain your answer.

    d. Could the bit patterns represent anything else besides instructions, integers, and memory addresses? If so, give some examples. Hint: think about primitive data types in C and Java.

(Continues on next page)
  1. (6 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 and that the base address of arrays A and B are in registers x8 and x9 respectively. A and B are arrays of 4-byte integers (this is important). 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 = 1; A[f] = 0;

    b. B[1] = A[f-5];

  2. (4 points) Show the hexadecimal representation of the following RISC-V instructions. Show all your work.
    a. addi x7, x7, 4

    b. lw x9, 8(x5)