Question: MIPS Assembly Language: Implement a MIPS assembly language program that defines main, and function1 procedures. The function1 is recursive and should be defined as: function1(n)

MIPS Assembly Language:

Implement a MIPS assembly language program that defines "main", and "function1" procedures.

The function1 is recursive and should be defined as:

function1(n) = (3*n) - 7 if n <= 4

= function1(n-2) + n*function1(n-4) - n + 2 otherwise.

The main asks a user to enter an integer for n and calls the function1 by passing the n value, then prints the result. If your program causes an infinite loop, press Control and 'C' keys at the same time to stop it.

C program that will ask a user to enter an integer, calls the function1, and prints the returned value from the function1.

// The function1 is a recursive procedure/function defined by: // function1(n) = (3*n) - 7 if n <= 4 // = function1(n-2) + n*function1(n-4) - n + 2 otherwise. int function1(int n) { if (n <= 4) { int ans1 = (3*n)-7; return ans1; } else { int ans1 = function1(n-2) + n*function1(n-4) - n + 2; return ans1; } } // The main calls function1 by entering an integer given by a user. void main() { int ans, n; printf("Enter an integer: "); // read an integer from user and store it in "n" scanf("%d", &n); ans = function1(n); // print out the solution computed by function 1 printf("The solution is: %d ", ans); return; } 

The following is a sample output (user input is in bold):

Enter an integer: 9 The solution is: -208

--------------------------------------------------

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!