Using function fibonacci(n), the sequence of numbers 1, 1, 2, 3, 5, 8, 13, 21, ......
Fantastic news! We've Found the answer you've been seeking!
Question:
Transcribed Image Text:
Using function fibonacci(n), the sequence of numbers 1, 1, 2, 3, 5, 8, 13, 21, ... for values of n equal to 1, 2, 3, 4, 5, 6, 7, 8, ... can be generated. The result for each n is calculated as follows: fibonacci (1) = 1, fibonacci(2) = 1, fibonacci(n) = fibonacci(n-1) + fibonacci(n-2) for n>2 (Note that the function is called recursively). int fibonacci(int n) { if (n<1) return 0; else if (n == 1 || n=2) return 1; else return (fibonacci(n-1) + fibonacci(n - 2)); } (a) Write the MIPS assembly code for function fibonacci (2.5 Marks) (b) Write the main program, which reads the value of n from keyboard (n<12) and prints the Fibonacci numbers up to the calculated value for n on SPIM Console. (For example, if n is 10, then the following sequence will be printed). 1, 1, 2, 3, 5, 8, 13, 21, 34, To test your code using SPIM, consider two different values for n (6 and 11). Using function fibonacci(n), the sequence of numbers 1, 1, 2, 3, 5, 8, 13, 21, ... for values of n equal to 1, 2, 3, 4, 5, 6, 7, 8, ... can be generated. The result for each n is calculated as follows: fibonacci (1) = 1, fibonacci(2) = 1, fibonacci(n) = fibonacci(n-1) + fibonacci(n-2) for n>2 (Note that the function is called recursively). int fibonacci(int n) { if (n<1) return 0; else if (n == 1 || n=2) return 1; else return (fibonacci(n-1) + fibonacci(n - 2)); } (a) Write the MIPS assembly code for function fibonacci (2.5 Marks) (b) Write the main program, which reads the value of n from keyboard (n<12) and prints the Fibonacci numbers up to the calculated value for n on SPIM Console. (For example, if n is 10, then the following sequence will be printed). 1, 1, 2, 3, 5, 8, 13, 21, 34, To test your code using SPIM, consider two different values for n (6 and 11).
Expert Answer:
Answer rating: 100% (QA)
Answer text main la a0prompt li v04 syscall li v05 syscall move t2v0 mo... View the full answer
Posted Date:
Students also viewed these algorithms questions
-
Two machines are used to fill plastic bottles with dishwashing detergent. Two random samples of "1 = 12 bottles from machine 1 and n2 = 10 bottles from machine 2 are selected, and the sample mean and...
-
A mutual fund company has 6 funds that invest in the U.S. market and 4 that invest in international markets. A customer wants to invest in two U.S. funds and 2 international funds. a. How many...
-
You are going to invest in a stock mutual fund with a 5 percent front-end load and a 1.30 percent expense ratio. You also can invest in a money market mutual fund with a 5.2 percent return and an...
-
The Electronic Industries Association reports that about 50% of U.S. households have a camcorder. For a randomly selected sample of 800 U.S. households, use the normal approximation to the binomial...
-
A customer has ordered a custom-made product that will require 5 purchase orders, 6 material issues, 2 production orders and 4 deliveries. The overhead to be allocated to the product is: b) 760
-
The information provided in this assignment is in relation to a Nova Scotia company named Fairness Enterprise that is owned and run by G. Steinem. Faimess Enterprise offers consulting services to...
-
What benefits should entities expect from preparing sustainability reports?
-
Timmins Company of Emporia, Kansas, spreads herbicides and applies liquid fertilizer for local farmers. On May 31, 2017, the company's Cash account per its general ledger showed a balance of...
-
Malimali Fish Products Ltd, A Malindi-based firm dealing in fish products, conducts training programmes for all its line managers. The managers ar expected to master, in particular, procedures in...
-
The chart of accounts for Kims Tree Trimming Service is as follows: Kims Tree Trimming Service completed the following transactions during the month of October: A. Sam Kim invested $30,000 in the...
-
Critique the role of social responsibility and ethics in improving marketing performance. Research and provide reasoning and provide reasoning; especially matching with the course concepts.
-
A jet flying directly over you at an altitude of \(3000 \mathrm{~m}\) produces a shock wave. If the angle of the shock wave is \(42^{\circ}\). (a) how long will it be until the sonic boom reaches...
-
The beam from a laser is focused with a lens, reducing the area of the beam by a factor of 2 . By what factor does the amplitude of the electric field increase? A. The amplitude does not change. B....
-
Small-plane pilots regularly compete in "message drop" competitions, dropping heavy weights (for which air resistance can be ignored) from their low-flying planes and scoring points for having the...
-
At White Sands, New Mexico, a car powered by a rocket engine passes you while you are standing still. If you hear the sonic boom \(0.045 \mathrm{~s}\) after the car passes and the angle of the shock...
-
What is the definition of frequency for a nonharmonic periodic wave?
-
On January 1, 2022 the Red Corp. leased an equipment with the following information: Fixed annual payments at the end of each year Lease term Useful life of equipment Residual value at the end of the...
-
The graph of an equation is given. (a) Find the intercepts. (b) Indicate whether the graph is symmetric with respect to the x-axis, the y-axis, or the origin. -3 6 -6 3 x
-
If you look at the light spectrum reflected from the surface of a DVD compared to the spectrum reflected from the surface of a CD, youll see that the rainbows from the DVD are more spread out, with...
-
DVDs and Blu-ray disks store information in patterns that are read by laser light. The shorter the wavelength of the light, the closer the data tracks can be placed on the disk. A Blu-ray player uses...
-
Increasing the density of a material tends to increase the index of refraction. Does light travel faster in seawater or in fresh water?
Study smarter with the SolutionInn App