In: Computer Science
Microsoft Visual C++ Assembly language
Problem 3. Write a program that uses a loop to calculate the first seven values of the Fibonacci number sequence, described by the following formula: Fib(1) = 1, Fib(2) = 2, … Fib(n) = Fib(n-1) + Fib(n-2). Place each value in the EAX register and display it with a call DumpRegs statement inside the loop
For example:
Fib(1) = 1,
Fib(2) = 2,
Fib(3) = Fib(1) + Fib(2) = 3,
Fib(4) = Fib(2) + Fib(3) = 5,
Fib(5) = Fib(3) + Fib(4) = 8,
Fib(6) = Fib(4) + Fib(5) = 13,
Fib(7) = Fib(5) + Fib(6) = 21
Below is an assembly program template that you can refer, and complete the programming by filling in the codes into the specified place:
TITLE Midterm Programming Question 3
Comment !
Description: Write a program that uses a loop to calculate the first
seven values in the Fibonacci number sequence { 1,1,2,3,5,8,13 }.
Place each value in the EAX register and display it with a
call DumpRegs statement inside the loop.
!
INCLUDE Irvine32.inc
.code
main PROC
please fill in your code here
exit
main ENDP
END main
Please submit the source code of your assembly file (i.e. .asm) and the screenshot to show that your program works well
Code:
INCLUDE Irvine32.inc
.code
main PROC
mov eax,1
call DumpRegs
mov ebx,0 ;
mov edx,1
mov ecx,6 ; Counter set to 6
;loop will run 0 to 6 = 7 times to print 7 values
LOOP1: mov eax, ebx
add eax, edx
call DumpRegs ;calling DumpRegs inside loop
mov ebx, edx
mov edx, eax
Loop LOOP1
exit
main ENDP
END main