Question: Part 4: Subroutine call and return Using two important instructions of MARIE ( JnS and JumpI ), implement a subroutine (a function) such that when

Part 4: Subroutine call and return

Using two important instructions of MARIE (JnS and JumpI ), implement a subroutine (a function) such that when this function is called, it will calculate, print and save the next element in a Fibonacci series. As you know, Fibonacci numbers can be calculated based on the following equations.

In this Part, you should implement a subroutine and a program that calls that subroutine. Assume your subroutine is called FIBO, such that when FIBO is called it will first calculate the next element in Fibonacci series, then it will print and save the calculated Fibonacci number in an array in MARIE memory. At the beginning, the first two elements in your array will be one (1) and all other elements will be zero, and then at the end of the program your array will have 16 elements of Fibonacci series including those two initial values of 1. (Hint: you can implement the following Pseudo code that will call your FIBO subroutine. You also should implement FIBO subroutine to calculate next Fibonacci number.)

F1 := 1; // F1: Starting element 1 F2 := 1; // F2: Starting element 2 FOR X:=1to16DO

Call FIBO (this part calls your FIBO subroutine, which Calculates, prints and then save the next FIBONACCI number in your array)

ENDFOR;

If F1=1 and F2=1, at the end of your program, array (A) will look like as follows:

Array (A)

Addresses of array A in HEX (for example: If array A starts at address 300 HEX)

Content of Memory location (in Decimal)

A= 300 HEX

1 Decimal

301 HEX

1 Decimal

302 HEX

2 Decimal

303 HEX

3 Decimal

304 HEX

5 Decimal

305 HEX

8 Decimal

306 HEX

13 Decimal

..............

..............

..............

..............

..............

..............

30F HEX

..............

Run your program in MarieSim environment, and print your MARIE assembly codes and the result of your program. Then change the starting elements of F1 and F2 in the above program to 10, and 11 respectively (F1=10, F2=11), and see the new results of your program and report all your codes and your results. Show the content of memory and all registers at each important step.

Step by Step Solution

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Databases Questions!