Question: 5. Translating between C and RISC-V Translate between the C and RISC-V code. You may want to use the RISC-V Reference Card for more information

5. Translating between C and RISC-V Translate between the C and RISC-V code. You may want to use the RISC-V Reference Card for more information on the instruction set and syntax. In all of the C examples, we show you how the different variables map to registers - you don't have to worry about the stack or any memory- related issues. You may assume all registers are initialized to zero. RISC-V // s0 ->a, sl -> b // s2 ->c, s3 ->z int a = 1, b = 2, c = 3, z; z= a + b + c + 5; // s0 -> int * p = intArr; // sl ->a; int *p; *p = 0; int a = 2; P[1] = a; P[a] = a; // s0 ->a, sl ->b int a = 5, b= 10; if(4 *a == b) { a=0; else { b= a - 1; addi so, x0, 0 addi s1, x0,1 addi to, x0, 30 loop: beq so, to, exit add si, si, si addi so, so, 1 jal x0, loop exit
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
