Question: Modify the code so that it now has a main that simply calls a RECURSIVE fibonacci function with a single parameter of 16 (that is
Modify the code so that it now has a main that simply calls a RECURSIVE fibonacci function with a single parameter of 16 (that is retrieved from a memory labeled fibinput). This function will return the 16th fibonacci value and the main will then store only this one value back into memory in a memory location labeled fibnumber. Fibonacci will have to save at least the two parameters to the runtime stack in addition to the return addresses.
The code:
fib_sequence: .skip 25 # Define a label and allocate 25 memory words, initialized to 0
num_terms = 25 # Define the number of terms to compute
current_term = 1 # Initialize the current and previous terms to 1
previous_term = 1
for i in range(num_terms): # Iterate over the number of terms to compute
next_term = current_term + previous_term # Compute the next term by adding the current and previous terms
fib_sequence[i] = current_term # Store the current term in the ith memory location
previous_term = current_term # Copy the current term to the previous term
current_term = next_term # Copy the next term to the current term
for i in range(num_terms): # Iterate over the memory locations containing the Fibonacci sequence
print(fib_sequence[i]) # Print the value stored in each memory location
Step by Step Solution
There are 3 Steps involved in it
Get step-by-step solutions from verified subject matter experts
