Question: 5. (30%) Compile C to RISC-V assembly code. Instructions that you might use include: add rd, rs1, rs2 #rd = rs1 + rs2 addi rd,

 5. (30%) Compile C to RISC-V assembly code. Instructions that youmight use include: add rd, rs1, rs2 #rd = rs1 + rs2addi rd, rsl, #immediate #rd = rs1 + #immediate sub rd, rs1,

5. (30%) Compile C to RISC-V assembly code. Instructions that you might use include: add rd, rs1, rs2 #rd = rs1 + rs2 addi rd, rsl, #immediate #rd = rs1 + #immediate sub rd, rs1, rs2 #rd = rs1 rs2 slli rd, rs1, #immediate #shift left logic rs1 by #immediate number # of bits and store results in rd lw rd, #offset(rs1) # load a word from memory at address rs1+#offset to rd sw rs2, #offset(rs1) # store a word from rs2 to memory at address rsl + #offset beq rs1, rs2, #label # if rs1 rs2, branch to the instruction labeled as #label bne rs1, rs2, #label #if rs1 != rs2, branch to the instruction labeled as #label bge rs1, rs2, #label # if rs1 >= rs2, branch to the instruction labeled as #label. 1) (5%) Using ONLY the add, sub and slli instruction to convert the following C statement to the corresponding RISC-V assembly. Assume that the variables f, g, and j are integers assigned to registers to, tl, and t2 respectively. You can use other temporary registers such as t3, t4, t5, t6, etc. f g * 3 - j * 16; 2) (10%) Convert the following C statement to its corresponding RISC-V assembly code using arithmetic/logic and load/store instructions. Assume that the base address of array 2) (10%) Convert the following C statement to its corresponding RISC-V assembly code using arithmetic/logic and load/store instructions. Assume that the base address of array A is in register so and each element is a 4-byte word. i is in register to and f is in register tl. You can use temp registers t2, t3, t4 ... A[i] += A[i-1] + f; 3) (15%) The following C code check whether two arrays (int A[N] and int B[N]) are the same or not. Convert the C code to its corresponding RISC-V assembly code using arithmetic/logic, load and branch instructions. Assume that the base address of array A and B is in register so and s1 respectively. i is in register to and N's value is already in register t. You can use temp registers t2, t3, etc. Register x0 always contains 0. The break statement terminates the loop. i = 0; while (A[i] B[i]) { i++; if (i == == N) break; } 5. (30%) Compile C to RISC-V assembly code. Instructions that you might use include: add rd, rs1, rs2 #rd = rs1 + rs2 addi rd, rsl, #immediate #rd = rs1 + #immediate sub rd, rs1, rs2 #rd = rs1 rs2 slli rd, rs1, #immediate #shift left logic rs1 by #immediate number # of bits and store results in rd lw rd, #offset(rs1) # load a word from memory at address rs1+#offset to rd sw rs2, #offset(rs1) # store a word from rs2 to memory at address rsl + #offset beq rs1, rs2, #label # if rs1 rs2, branch to the instruction labeled as #label bne rs1, rs2, #label #if rs1 != rs2, branch to the instruction labeled as #label bge rs1, rs2, #label # if rs1 >= rs2, branch to the instruction labeled as #label. 1) (5%) Using ONLY the add, sub and slli instruction to convert the following C statement to the corresponding RISC-V assembly. Assume that the variables f, g, and j are integers assigned to registers to, tl, and t2 respectively. You can use other temporary registers such as t3, t4, t5, t6, etc. f g * 3 - j * 16; 2) (10%) Convert the following C statement to its corresponding RISC-V assembly code using arithmetic/logic and load/store instructions. Assume that the base address of array 2) (10%) Convert the following C statement to its corresponding RISC-V assembly code using arithmetic/logic and load/store instructions. Assume that the base address of array A is in register so and each element is a 4-byte word. i is in register to and f is in register tl. You can use temp registers t2, t3, t4 ... A[i] += A[i-1] + f; 3) (15%) The following C code check whether two arrays (int A[N] and int B[N]) are the same or not. Convert the C code to its corresponding RISC-V assembly code using arithmetic/logic, load and branch instructions. Assume that the base address of array A and B is in register so and s1 respectively. i is in register to and N's value is already in register t. You can use temp registers t2, t3, etc. Register x0 always contains 0. The break statement terminates the loop. i = 0; while (A[i] B[i]) { i++; if (i == == N) break; }

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!