DATA SEGMENT
counter db 10
fibonacci db 10 DUP(0)
DATA ENDS
CODE SEGMENT
ASSUME CS:CODE , DS:DATA
START:
MOV AX , data
MOV DS , AX
MOV AL , 00H ;Stored First Number of the Fibnonacci Series in AL
LEA SI , fibonacci ;Store offeset address of fibonacci in SI
pointer ;Using SI to store result in memory location
MOV [SI] , AL ;Stores 0 into the first memory location
INC SI ;increment SI to point to next memory location
INC AL ;increment AL , so AL now has second element of the sequence
MOV [SI] , AL ;Moving 01H into second position memory location
MOV CL , counter ;Moving the value stored in counter into CX counter
MOV CH , 00H
SUB CX , 02H ;We decrement the counter by 2 as we have already initialised
first 2 elements of the series
Loop1: ;It is loop label defining start of loop
MOV AL , [SI-1] ;Moves the element in the (i-1)th position in the
AL
ADD AL , [SI] ;Add the present element of SI with present value of
AL and stored in AL
DAA ;This will convert the Hexadecimal numbers into BCD (Decimal
Numbers)
INC SI ;Increments SI so that it points to next memory location
MOV [SI] , AL ;Store the sum done previously in the new position
LOOP Loop1 ;The instructions written between Label Loop1 and this
instruction are executed CX times
MOV AH , 4CH
INT 21H ;It invokes interrupt 21 after storing 4C into AH which helps us
terminate the program and give control to the operating system
CODE ends
end START