Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 6: (17 pts) Part 1: (9 pts) Implement the following C code in RISC-V assembly. Part 2: (3 pts) What is the total number

image text in transcribedProblem 6: (17 pts) Part 1: (9 pts) Implement the following C code in RISC-V assembly. Part 2: (3 pts) What is the total number of RISC-V instructions needed to execute the function? int fib (int n) { if (n==0) return 0; else if (n==1) return 1; else return fib(n-1) + fib(n-2); } Part 3: (5 pts) For each function call above, show the contents of the stack after the function call is made. Assume the stack pointer is originally at address 0x7ffffffc, and follow the register convention of RISC-V (argument, saved, temporary, sp, RET, etc etc). Solution: Problem 7: (9 pts) Part 1: (6 pts) Translate function f into RISC-V assembly language. Assume that the function declaration for function 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); } Part 2: (3 pts) Can we determine the contents of registers: x10 x14, x8, x1, and sp? We know what the entire function f looks like, but for function g we only know its declaration. Solution:

Problem 6: (17 pts) Part 1: (9 pts) Implement the following C code in RISC-V assembly Part 2: (3 pts) What is the total number of RISC-V instructions needed to execute the function? int fib (int n) ( if (n--0) return 0; else if (n--1) return 1; else return fib (n-1) + fib(n-2); Part 3: (5 pts) For each function call above, show the contents of the stack after the function call is made. Assume the stack pointer is originally at address 0x7ffffffc, and follow the register convention of RISC-V (argument, saved, temporary, sp, RET, etc etc Solution Problem 7:(9 pts) Part 1: (6 pts) Translate function f into RISC-V assembly language. Assume that the function declaration for function 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), ctd); Part 2: (3 pts) Can we determine the contents of registers: x10 - x14, x8, x1, and sp? We know what the entire function f looks like, but for function g we only know its declaration. Solution Problem 6: (17 pts) Part 1: (9 pts) Implement the following C code in RISC-V assembly Part 2: (3 pts) What is the total number of RISC-V instructions needed to execute the function? int fib (int n) ( if (n--0) return 0; else if (n--1) return 1; else return fib (n-1) + fib(n-2); Part 3: (5 pts) For each function call above, show the contents of the stack after the function call is made. Assume the stack pointer is originally at address 0x7ffffffc, and follow the register convention of RISC-V (argument, saved, temporary, sp, RET, etc etc Solution Problem 7:(9 pts) Part 1: (6 pts) Translate function f into RISC-V assembly language. Assume that the function declaration for function 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), ctd); Part 2: (3 pts) Can we determine the contents of registers: x10 - x14, x8, x1, and sp? We know what the entire function f looks like, but for function g we only know its declaration. Solution

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

Students also viewed these Databases questions