Question
Q5 C RISC-V 4 Points In each of the following questions, you'll be given either C or RISC-V code, and asked to examine a translation
Q5 C RISC-V
4 Points
In each of the following questions, you'll be given either C or RISC-V code, and asked to examine a translation into RISC-V or C, respectively.
The translation may have a bug or logic error. Your task is to identify the line number containing the error, or enter "none" if no problem exists.
(a) Given this C code:
if (x < 3) { goto label; }
Identify the buggy line in the following RISC-V translation. Select "None", if there is no error.
/* x = s0 */ 1. addi t0 x0 3 2. slt t1 s0 t0 3. beq t1 x0 label
(b) Given this C code:
int x[2] = {1, 2} int y = x[0] + x[1] + 2;
identify the buggy line in the following RISC-V translation or enter "none", if there is none:
/* x = s0, y = s1 */ 1. lw t0 0(s0) 2. lw t1 1(s0) 3. add s1,t0,t1 4. addi s1,s1,2
(c) Given this RISC-V code:
add s0 s0 s2 sub s1 s2 s1 j end
identify the buggy line in the following C translation or enter "none", if there is none. (Hint: register order matters):
/* x = s0, y = s1, z = s2 */ 1. x += z 2. y -= z 3. goto end
(d) Given this RISC-V code:
slli s0 s0 4 xori s0 s0 3 sw s0 8(s1)
identify the buggy line in the following C translation or enter "none", if there is none:
1. int x; // x = s0 2. int y[3]; // y = s1 3. x *= math.pow(2, 4); 4. x ^= 3 5. y[4] = x;
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started