Question
This problem is to be solved in MIPS assembly language and submitted as a .s file. Run on QtSpim. Write a main program that prompts
This problem is to be solved in MIPS assembly language and submitted as a .s file. Run on QtSpim.
Write a main program that prompts the user to enter a decimal integer between 1 and 12, inclusive. The main program should call a recursive function (recurse) and pass the integer as an argument to the function.
The recursive function accepts a single positive integer as an input argument and is defined as:
recurse(n) = 1 if n=0
recurse(n) = n * recurse(n-1) + 1 if n >0
In addition, the recursive function should print an entry message each time that the function is entered and an exit message upon each return from the recursive function.
The entry message should consist of 2n spaces (where n is the function argument), followed by Recursing , followed by the decimal value of the argument n.
The exit message should consist of 2n spaces, followed by Returning , followed by the decimal value of the returned result.
While you don't need to completely follow the MIPS procedure call conventions, you should at least save and restore any registers that are modified in your procedure and are designated as "preserved across a call" on the MIPS green card.
Make sure that you include a comment block at the head of the source file that specifies your name and explains the purpose of the program. Also comment the code to make it easier to read and follow the program logic. After you have written and tested your program using the SPIM simulator, submit a text-only version of the source code with a .s file extension.
The figures below show output for inputs 0 and 7, respectively.
Enter an integer between 0 and 12: 0
Recursing 0
Returning 1
Goodbye
Enter an integer between 0 and 12: 7
Recursing 7
Recursing 6
Recursing 5
Recursing 4
Recursing 3
Recursing 2
Recursing 1
Recursing 0
Returning 1
Returning 2
Returning 5
Returning 16
Returning 65
Returning 326
Returning 1957
Returning 13700
Goodbye
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