0% found this document useful (0 votes)
26 views1 page

Fibonacci Series Code Mic

The document describes a program that calculates the Fibonacci sequence and stores the results in memory locations. It initializes the first two elements of the sequence to 0 and 1. It then uses a loop to calculate each subsequent element by adding the previous two and storing the result. The loop runs for a number of iterations specified by a counter variable.

Uploaded by

Roman Empire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
26 views1 page

Fibonacci Series Code Mic

The document describes a program that calculates the Fibonacci sequence and stores the results in memory locations. It initializes the first two elements of the sequence to 0 and 1. It then uses a loop to calculate each subsequent element by adding the previous two and storing the result. The loop runs for a number of iterations specified by a counter variable.

Uploaded by

Roman Empire
Copyright
© © All Rights Reserved
We take content rights seriously. If you suspect this is your content, claim it here.
Available Formats
Download as TXT, PDF, TXT or read online on Scribd

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

You might also like