Page 1 of 1

please write risc-v assembly code for the c-code provided above

Posted: Sat May 14, 2022 8:14 pm
by answerhappygod
Please Write Risc V Assembly Code For The C Code Provided Above 1
Please Write Risc V Assembly Code For The C Code Provided Above 1 (122.23 KiB) Viewed 36 times
Please Write Risc V Assembly Code For The C Code Provided Above 2
Please Write Risc V Assembly Code For The C Code Provided Above 2 (63.94 KiB) Viewed 36 times
please write risc-v assembly code for the c-code provided
above
Assume that the register x8 holds the base address of array s which stores the results of the three procedure calls. Registers x10 and x11 are used to hold function arguments, and x10 is also used for the function result. In the provided skeleton code (hw2 2 skeleton.s), line 7 - 10 provide an example of the first call of the procedure mysum and storing the function result in memory. You need to complete the code with the rest two procedure calls and the procedure. = = 1 int my Sum (int x, int y) 2 { 3 if (x > y) { 4 int temp X; 5 X = y; 6 y = temp; 7 } 8 int i; 9 int S = 0; 10 for (i = x; i <= y; i++) { 11 S S + i; 12 } 13 return S; 14 } 15 16 int main() 17 { 18 int s[3]; 19 int a 4; 20 int b 8; 21 s [0] mySum (a, b); 22 a = 8; 23 s [1] mySum (a, b); 24 b = 4; 25 s [2] mySum(a, b); 26 return 0; 27 } = = .

1 .data s: .word 0,0,0 2 3 4 5 6 X8 S 7 .text main: la # put the base address of arrays in x8 addi x10, x0, 4 # a is in X10 addi x11, x0, 8 # b is in x11 jal x1, mysum SW X10, 0(x8) # function result is in X10 # insert your code here and complete the main() function 8 9 10 11 12 13 14 jal x0, exit 15 16 my sum: # insert your code for the my Sum() function 17 18 19 exit: 20 nop 21