In: Computer Science
(a) The Fibonacci numbers are the numbers in the following integer sequence, called the Fibonacci sequence, and are characterised by the fact that every number after the first two is the sum of the two preceding ones: 0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 114, … etc. By definition, the first two numbers in the Fibonacci sequence are 0 and 1, and each subsequent number is the sum of the previous two. We define Fib(0)=0, Fib(1)=1, Fib(2)=1, Fib(3)=2, Fib(4)=3, etc. The first 22 Fibonacci numbers given below: Fib(0) Fib(1) Fib(2) Fib(3) Fib(4) Fib(5) Fib(6) Fib(7) Fib(8) Fib(9) Fib(10) 0 1 1 2 3 5 8 13 21 34 55 Fib(11) Fib(12) Fib(13) Fib(14) Fib(15) Fib(16) Fib(17) Fib(18) Fib(19) Fib(20) Fib(21) 89 144 233 377 610 987 1597 2584 4181 6765 10946 Write a MARIE program to calculate Fib(n), where the user inputs n. For example, if the user inputs 7, the program outputs the value 13; if the user inputs 15, the program outputs the value 610; if the user inputs 20, the program outputs the value 6765 etc. You need to write and run the program using MARIE simulator. Please include appropriate comments to make your code readable. Important:Please run the mas file in the MARIE simulator to check if it works correctly. Try inputting numbers like 0, 1, 5, 10, 22 etc. 1 mark would be deducted if the codes are not commented. (b) For some values of n, your program will not produce correct results. You can check this by gradually increasing the values of n and checking for the correct outputs. What is the maximum value of n for which your program produces a correct result? Why?
# Fibonacci Sequence Using MERIE SIMULATOR :-
ORG 100
INPUT /get input fromuser
STORE num /store the input
Cond, LOAD COUNT / Load count value
SUBT num / Remove num from count to get exact output
ADD ONE
SKIPCOND 000 / if 0 , skip
JUMP End / loop ends
Loop, LOAD COUNT
ADD ONE
STORE COUNT
JNS Fibb
JUMP Cond
Fibb, HEX 000
CLEAR / clear the accumulator
/ add f1 and f2
ADD F1
ADD F2
STORE Fi
/ store f2 in f1
LOAD F2
STORE F1
/ store f1 in f2
LOAD Fi
STORE F2
/ print the output
LOAD Fi
OUTPUT
JUMPI Fibb
End, HALT / Halt the process
/ variables declarations
COUNT, DEC 0
Fi, DEC 0
F1, DEC 0
F2, DEC 1
num, DEC 0/ constant values dealrations
ONE, DEC 1
OUTPUT : will be the Fibonacci Sequence
0,0,1,2,3,5,,8,13,,21,34,55,89.... so on
Note : Please i don't have Marie compiler so i show output by written
b) For some values of n, the program is not producing appropriate results as it should behave. This abnormality is occurring due to the limit of the integers being crossed by the system. There is a limit to the value that can be stored by data type. In this case after careful analysis of the output we have seen that the output produced is correct for values of n up to n= 24. After this threshold is reached or crossed the program starts displaying results in the negative value ranges.