Source Code of fibonaci series in 8085

Monday, January 19, 2009

  • Introduction:
Fibonaci series is a series whose first two terms are 1 and others term are the summation of previous two terms. Now we will generate a fibonaci series up to nth terms .
  • How we will do This:
So the first two term of the series are 1, at first we will initialize them in two variables, suppose A and B. Now we will add this two numbers and will keep another variable suppose C, that’s mean our statement is C=A+B. Now we have got three terms of the series. The fourth term will be the summation of three and two ,fifth will be summation of four and three, sixth will be summation of five and four and so on. So now we can understand that after finding the third term we have to perform a repetate operation. Thats mean we have to perform the operation C=A+B repetatedly .so we will take a loop to do this. In the body of the loop the value of A and B will be updated. In the statement C=A+B, we can say if C is the 7th number then A and B will be the 6th and 5th number. At the next time exucation C will be the 8th number and A, B will be the 7th and 6th number. So to update the value of A and B we will perform the following statement Loop until N C=A+B; A=C; B=A; After this we will get our desired output.
  • Algorithm:
Start A=1; B=1; store A,B; C=00; D=N; Loop (i=3 to N) { C=A+B; store C A=C; B=A; } End
  • Source code:
  • MVI A 01
  • MVI B 01
  • MVI C 00
  • MVI D 09
  • LXIH F01D
  • MOV M, A
  • INX H
  • DCR D
  • MOV M, B
  • INX H
  • DCR D
  • ADD B
  • MOV M, A
  • MOV C, A
  • MOV A, B
  • MOV B, C
  • INX H
  • DCR D
  • JNZ FO11
  • HLT
  • Source Code Analysis:
MVI A, MVI B, MVI C,MVI D are variable declearation. Variable A,B indicate the first two term of the series.Variable D indicate the Nth term of the series.LXI H indicate from which location we will start to store the series element.We store the value of A in memory location F01D.Then we increase the memory location and decrease the Nth term.Again we store the value of B,increase memory and decrease D,that means N.Then we add two number and keep in accumulator A and store memory.After that just interchange the varianle A and B with the help of an extra variable C.To store value in memory we increase the memory.We have decreased the value of D, if the value of D is not 0 then it will jump and will go to the statement ADD B;After that HLT means the end of the program:
  • The figure of the programming code and output are given below.

0 comments:

Visitors

PlugIn.ws - Free Hit Counter, Web Site Statistics, Traffic Analysis

  © Blogger template Leaving by Ourblogtemplates.com 2008

Back to TOP