What am I doing wrong? This code only generates accurate Fibonacci series up to 13 after that it's giving the wrong value.
Output
1, 1, 2, 3, 5, 8, 13, 29, 37
As its should be 21
after 13
and not the 29
Code
org 100h
.data
num dw 0
.code
main proc
mov ax, @data
mov ds, ax
mov cx, 15
mov bx, 1
mov si, offset num
fibonacci:
mov dx, [si] ;dx=0,1,1,2,3
add [si], bx ;num=1,1,2,3,5
mov bx, dx ;bx=0,1,1,2
mov di, [si]
add si,2
mov [si], di
loop fibonacci
main endp
end main
ret