
Data Structure
Networking
RDBMS
Operating System
Java
MS Excel
iOS
HTML
CSS
Android
Python
C Programming
C++
C#
MongoDB
MySQL
Javascript
PHP
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
8085 Program to Generate Fibonacci Sequence
In this program we will see how to generate Fibonacci sequence.
Problem Statement
Write 8085 Assembly language program to generate the first ten elements of the Fibonacci sequence using registers only and store them in memory locations 8050H to 8059H.
Discussion
This program will generate the Fibonacci numbers. The Fibonacci numbers follows this relation F(i) = F(i - 1) + F(i - 2) for all i >2 with F(1) = 0, F(2) = 1.
Input
In this case we are not providing any input, this program will generate ten Fibonacci numbers.
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
8000 | 21, 50, 80 | START | LXI H 8050H | Pointer to the OUT-BUFFER |
8003 | AF | XRA A | Clear accumulator and reg. B | |
8004 | 47 | MOV B, A | ||
8005 | 77 | MOV M, A | Copying content to the target location | |
8006 | 3C | INR A | Increment A | |
8007 | 23 | INX H | Go to the next dest. address. | |
8008 | 77 | MOV M, A | Moving the content | |
80 09 | 0E, 08 | MVI C, 08H | Initialize counter | |
800B | 80 | LOOP | ADD B | Getting the next term |
800C | 46 | MOV B, M | Initializing term e.g. F1 = F2 | |
800D | 23 | INX H | Go to the next dest. address. | |
800E | 77 | MOV M, A | Writing to the OUT-BUFFER | |
800F | 0D | DCR C | Decrement count until 0 is reached F3= F1 + F2 (A) = (A) + (B) This is done with instruction ADDB. | |
8010 | C2, 0B, 80 | JNZ LOOP | ||
8013 | 76 | HLT | Terminate the program |
Output
Address | Data |
---|---|
... | ... |
8050 | 00 |
8051 | 01 |
8052 | 01 |
8053 | 02 |
8054 | 03 |
8055 | 05 |
8056 | 08 |
8057 | 0D |
8058 | 15 |
8059 | 22 |
... | ... |
Advertisements