Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

1. (a) The Fibonacci numbers are the numbers in the following integer sequence,

ID: 3809115 • Letter: 1

Question

1. (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)-0 Fib(1)-1 Fib(2)-1 Fib(3)-2 Fib(4)-3 Fib(5)-4 Fib(6)-8 Fib(7)-13 Fib(8)-21 Fib(9)-34 Fib(10)-55

Fib(11)-89 Fib(12)-144 Fib(13)-233 Fib(14)-377 Fib(15)-610 Fib(16)-987 Fib(17)-1597 Fib(18)-2584 Fib(19)-4181 Fib(20)-6765 Fib(21)- 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.[10 marks] (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? Please comment on this [

Explanation / Answer

ORG 0

LOOP1, LOAD N / load the N value into AC

SKIPCOND 000 /skipcond 000 if AC=0

JUMP END /End loop1

LOOP2, LOAD F1 // load the f value into AC

ADD F2 // add f2 to AC

STORE F3 // F3=F1+F2

LOAD F2 /store f2 into f1

STORE F1

LOAD F3 /store f3 into f2

STORE F2

LOAD N //load N into Ac

SUBT ONE //subtract 1 from N

SKIPCOND 000 //if AC =0

JUMP LOOP2 //Call the loop 2

JUMP END // End loop2

/output

LOAD F3 // AC=F

OUTPUT // output the AC value

END, HALT //halt the process

/variables

N, DEC 10 // you can change the value.

F1, DEC 0 //initilaised f1=0;

F2, DEC 1

F3, DEC 0

/constant

ONE, DEC 1

to fine the fibonaic series for n:

the function i have used here:

L1:fib(n){

while(n>0) // loop runs for n times.

{

f=0;

f=f(1)+f(2)

f1=f2, f2=f

fib(n)

}

b)the maximum value of n for which your program produces a correct result

solution: the varibles contains upto 8 integers maximum. if ORG 100-> starts from memory 100.