- (5 points) For the following C statement, write the corresponding RISC-V assembly code. Assume that the C variables f, g, and h, have already been placed in registers x5, x6, and x7 respectively. Use a minimal number of RISC-V assembly instructions.
- (5 points) For the following C statement, write the corresponding RISC-V assembly code. Assume that the variables f, g, h, i, and j are assigned to registers x5, x6, x7, x28, and x29, respectively. Assume that the base address of the arrays A and B are in registers x10 and x11, respectively.
- (10 points) For the RISC-V assembly instructions below, what is the corresponding C statement? Assume that the variables f, g, h, i, and j are assigned to registers x5, x6, x7, x28, and x29, respectively. Assume that the base address of the arrays A and B are in registers x10 and x11, respectively.
- (5 points) Show how the value 0xabcdef12 would be arranged in memory of a littleendian and a big-endian machine. Assume the data are stored starting at word address 0.
- (5 points) Find the shortest sequence of RISC-V instructions that extracts bits 16 down to 11 from register x5 and uses the value of this field to replace bits 31 down to 26 in register x6 without changing the other bits of registers x5 or x6. (Be sure to test your code using x5 = 0 and x6 = 0xffffffff. Doing so may reveal a common oversight.)
- (10 points) Assume x5 holds the value 0x01010000. What is the value of x6 after the following instructions?
- Consider the following RISC-V loop:
- (10 points) Assume that the register x6 is initialized to the value 10. What is the final value in register x5 assuming the x5 is initially zero?
- (10 points) For the loop above, write the equivalent C code. Assume that the registers x5 and x6 are integers acc and i, respectively.
- (5 points) For the loop written in RISC-V assembly above, assume that the register x6 is initialized to the value N. How many RISC-V instructions are executed?
- (5 points) For the loop written in RISC-V assembly above, replace the instruction beq x6, x0, DONE with the instruction blt x6, x0, DONE and write the equivalent C code.
- (20 points) Translate function f into RISC-V assembly language. Assume the function declaration for g is int g(int a, int b). The code for function f is as follows: int f(int a, int b, int c, int d){
return g(g(a,b), c+d);
}
- (10 points) Right before your function f from Problem 8 returns, what do we know about contents of registers x10-x14, x8, x1, and sp? Keep in mind that we know what the entire function f looks like, but for function g we only know its declaration.

![[Solved] Ve370 Homework 1 Solution](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip.jpg)

![[Solved] Ve370 Introduction to Computer Organization Lab 5 Resolving Hazards](https://assignmentchef.com/wp-content/uploads/2022/08/downloadzip-1200x1200.jpg)
Reviews
There are no reviews yet.