- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
Program to perform bubble sort based on choice in 8085 Microprocessor
Here we will see one 8085 microprocessor program that will help to arrange the numbers in ascending or descending order based on our choice. Sort using bubble sort technique.
Problem Statement −
Write an 8085 Assembly language program to perform bubble sorting operation on a set of data, and arrange them into ascending or descending order based on choice.
Discussion −
In this program we are arranging some numbers into ascending or descending order based on some choice. We are storing the choice at location A000H. If the choice value is 00H, then data will be sorted in ascending order, otherwise it will be sorted in descending order. The 8000H is holding the block size, and 8001H onwards is holding the data.
Input
First input
Address | Data |
---|---|
… | … |
8000 | 06 |
8001 | 22 |
8002 | 55 |
8003 | 33 |
8004 | 66 |
8005 | 44 |
8006 | 11 |
… | … |
A000 | 00 |
… | … |
Second input
Address | Data |
---|---|
… | … |
8000 | 06 |
8001 | 22 |
8002 | 55 |
8003 | 33 |
8004 | 66 |
8005 | 44 |
8006 | 11 |
… | … |
A000 | 45 |
… | … |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
F000 | 31, 00, 90 | LXI SP,9000H | Initialize Stack | |
F003 | 21, 00, 80 | LXI H,8000H | Point to get the block size | |
F006 | 4E | MOV C,M | Get the count | |
F007 | 0D | DCR C | Decrease C by 1 | |
F008 | 1E, 01 | L1 | MVI E,01H | E will store one more than number of swaps in a pass |
F00A | 41 | MOV B,C | Store number of comparisons | |
F00B | 23 | INX H | Point to next location | |
F00C | 7E | L2 | MOV A,M | Load Memory to A |
F00D | 23 | INX H | Point to next location | |
F00E | BE | CMP M | Compare memory element with A | |
F00F | F5 | PUSH PSW | Store AF into stack | |
F010 | 3A, 00, A0 | LDA A000 | Get the choice | |
F013 | FE, 00 | CPI 00H | Compare choice with 00H | |
F015 | CA, 1F, F0 | JZ ASC | If Z = 1, sort in Ascending order | |
F018 | F1 | POP PSW | Pop AF from stack | |
F019 | D2, 29, F0 | JNC SKIP | Jump to SKIP if CY = 0 | |
F01C | C3, 23, F0 | JMP EXG | otherwise Jump to exchange | |
F01F | F1 | ASC | POP PSW | Pop AF from stack |
F020 | DA, 29, F0 | JC SKIP | If CY = 1, go to skip | |
F023 | 56 | EXG | MOV D,M | Load memory to D |
F024 | 77 | MOV M,A | Load A to memory | |
F025 | 2B | DCX H | Point to previous location | |
F026 | 72 | MOV M,D | Load D to Memory | |
F027 | 23 | INX H | Point to next location | |
F028 | 1C | INR E | Increase number of exchanges | |
F029 | 05 | SKIP | DCR B | Decrease B by 1 |
F02A | C2, 0C, F0 | JNZ L2 | if Z = 0, go to L2 loop | |
F02D | 1D | DCR E | Decrease E register by 1 | |
F02E | CA, 38, F0 | JZ DONE | If Z = 1, terminate the program | |
F031 | 21, 00, 80 | LXI H,8000H | Point to initial address of block | |
F034 | 0D | DCR C | Decrease the count | |
F035 | C2, 08, F0 | JNZ L1 | If Z = 0, go to L1 | |
F038 | 76 | DONE | HLT | Terminate the program |
Output
First output
Address | Data |
---|---|
… | … |
8000 | 06 |
8001 | 11 |
8002 | 22 |
8003 | 33 |
8004 | 44 |
8005 | 55 |
8006 | 66 |
… | … |
Second Output
Address | Data |
---|---|
… | … |
8000 | 06 |
8001 | 66 |
8002 | 55 |
8003 | 44 |
8004 | 33 |
8005 | 22 |
8006 | 11 |
… | … |