I want to generate the 1st N fibonacci numbers in x86 asm using the Irvine Library. That means whenever I will give N = 5, it should print : 0,1,1,2,3, But whenever I run it suppose with N =5 then it gives output as : 0,1,2,3,4.
Below is my program
TITLE MASM Irvine
INCLUDE Irvine32.inc
.data
message1 BYTE "The first ",0
message2 BYTE " numbers in the Fibonacci sequence are the following.",0
N DWORD 10
intialVal WORD 0,1
.code
main PROC
call Clrscr ; clears screen
mov edx,OFFSET message1
call WriteString ; display message1
mov eax, N
call WriteDec ; display num
mov edx,OFFSET message2
call WriteString ; display message2
call Crlf ; new line
mov eax,0
mov bx, [intialVal]
mov cx, [intialVal + 2]
StartLoop:
mov edx,0 ;setting edx to 0 every time
add dx,bx ;adding bx to dx
add dx,cx ;adding cx to dx
call WriteDec
call Crlf ;trying to print dx
mov bx,cx ;moving numbers. so now cx goes to bx
mov cx,dx ;dx goes to cx
inc eax ;increment eax (as a counter)
cmp eax,N ;compare to variable N
jne StartLoop ;if eax = N exit loop, else jump to start of loop
exit
main ENDP
END main