Answered step by step
Verified Expert Solution
Question
1 Approved Answer
URGENT!! I need the following code converted to MIPS assembly code. I have already done the conversion for int main() and void print_it. Thanks! Please
URGENT!! I need the following code converted to MIPS assembly code. I have already done the conversion for int main() and void print_it. Thanks! Please let me know if you need any more information or more skeleton code I have been working on.
#includevoid do_task(int a, int b); int NchooseK(int n, int k); int Fibonacci(int i); void print_it(int i); int main() { int a, b; // read values for registers $s0-$s7 here int s0, s1, s2, s3, s4, s5, s6, s7; printf("Enter initial values for registers $s0-$s7 "); scanf("%d%d%d%d%d%d%d%d", &s0, &s1, &s2, &s3, &s4, &s5, &s6, &s7); // the above is simply a placeholder for what to do in assembly while (1) { printf("Enter a and b: "); scanf("%d", &a); if(a==0) break; scanf("%d", &b); do_task(a, b); } // print final values of registers $s0-$s7 here // they should be the same as the values read in at the top printf("Here are the final values of registers $s0-$s7 "); printf("%d %d %d %d %d %d %d %d ", s0, s1, s2, s3, s4, s5, s6, s7); } void do_task(int a, int b) { int n, k, result; n = a+b; k = a; result = NchooseK(n, k); print_it(result); result = Fibonacci(b); print_it(result); } int NchooseK(int n, int k) { if((k==0) || (n==k)) return 1; else return NchooseK(n-1, k-1) + NchooseK(n-1, k); } int Fibonacci(int i) { if((i==0) || (i==1)) return i; else return Fibonacci(i-1) + Fibonacci(i-2); } void print_it(int i) { printf("%d ", i); }
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