Question: Write a Z 8 0 assembly language program which computes the first 2 1 values in the Fibonacci sequence. Recall that the Fibonacci sequence is

Write a Z80 assembly language program which computes the first 21 values in the Fibonacci sequence. Recall that the Fibonacci sequence is defined as follows: ; (add setup and initial statement for inner Fibonacci function loop here)
inner_loop:; (finally, load result to "result" variable for printing when inner loop is finished)print_result:call B2D16 ; convert variable value to number stringld hl, NEWLINE ; start HL at newlineld ; increment "n"ld (n), adec bc ; decrement main counteror chaltprint:
orint: \\\\or a ; has null terminator been reached?push hl ; push HL to stack (will be changed by PRNCHR)pop hl ; pop HL from stackjr print ; repeatSTR_BANNERLABEL_1.byte " ; Zero-Fill Remainder of Cartridge ROM #include "equ.asm" .byte "CS 333 Lab #3(Summer 2024)",13,10,13,10,0
F(0)=0; F(1)=1; F(n)= F(n 1)+ F(n 2) for n >1
As you may recall from your earlier programming classes, this is a recursive definition that is expressed in terms of itself. It also clearly states the base cases; in this case, n =0 and n =1. An iterative implementation of this function, written as it might appear in a C/C++ or Java program, is shown below:
public int fib(int n){
int current =0;
int next =1;
int nextnext =0;
for (int i =0; i n; ++i){
nextnext = current + next;
current = next;
next = nextnext;
}
return current;
Using the attached LAB03.asm program file as a starting point, and following the iterative implementation shown above, implement an algorithm in Z80 assembly language to produce the first 21 values in the Fibonacci sequence (from n =0 to n =20).
The output of your completed program should show the following:
CS 333 Lab #3(Summer 2024)
f(0)=0
f(1)=1
f(2)=1
f(3)=2
f(4)=3
f(5)=5
f(6)=8
f(7)=13
f(8)=21
f(9)=34
f(10)=55
f(11)=89
f(12)=144
f(13)=233
f(14)=377
f(15)=610
f(16)=987
f(17)=1597
f(18)=2584
f(19)=4181
f(20)=6765
Look for the INSERT YOUR CODE HERE comment block in the program file, starting on Line 63; this is where you should begin adding your instructions to complete the program. The other code already provided in the file should not be changed.
Write a Z 8 0 assembly language program which

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 Programming Questions!