Question
Assembly language, MASM. I am to calculate the Nth number in the fibonacci sequence. Here is what I have so far and it is giving
Assembly language, MASM.
I am to calculate the Nth number in the fibonacci sequence. Here is what I have so far and it is giving me garbage values...Please help me fix it!!
.586
.MODEL FLAT
INCLUDE io.h ; header file for input/output
.STACK 4096
.DATA ; declarations
mov eax, 1 ;a
mov ebx, 1 ;b
n WORD ?
prompt1 BYTE "Enter number to calculate to:", 0
string BYTE 40 DUP (?)
resultLbl BYTE "The sequence is", 0
sum BYTE 11 DUP (?), 0
.CODE
_MainProc PROC
input prompt1, string, 40 ; read ASCII characters
atod string ; convert to integer
mov ax, n ; store in memory
mov cx,0
_fib:
cmp cx,ax
jnl endFib
mov edx, eax ;move 1
add edx, ebx ;sum = a + b
mov eax, ebx ;a = b
mov ebx, edx ;b = sum
jmp _fib
endFib:
dtoa sum,ebx
output resultLbl, sum ; output label and sum
mov eax, 0 ; exit with return code 0
ret
_MainProc ENDP
END ; end of source code
Step by Step Solution
There are 3 Steps involved in it
Step: 1
Get Instant Access to Expert-Tailored Solutions
See step-by-step solutions with expert insights and AI powered tools for academic success
Step: 2
Step: 3
Ace Your Homework with AI
Get the answers you need in no time with our AI-driven, step-by-step assistance
Get Started