Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

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

image text in transcribedimage text in transcribedimage text in transcribed

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

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image

Step: 3

blur-text-image

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

Databases And Python Programming MySQL MongoDB OOP And Tkinter

Authors: R. PANNEERSELVAM

1st Edition

9357011331, 978-9357011334

More Books

Students also viewed these Databases questions

Question

Explain the nature of human resource management.

Answered: 1 week ago

Question

Write a note on Quality circles.

Answered: 1 week ago

Question

Describe how to measure the quality of work life.

Answered: 1 week ago

Question

2. Discuss various aspects of the training design process.

Answered: 1 week ago