- 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
8085 Program to perform sorting using bubble sort
In this program we will see how to sort a block of bytes using bubble sorting technique.
Problem Statement
Write8085 Assembly language program to sort numbers in ascending order where n number of numbers are stored in consecutive memory locations starting from 8041H and the value of n is available in memory location 8040H (Using BUBBLE sort).
Discussion
In this program we will arrange the numbers in bubble sorting technique. In this sorting technique, it will be executed in different pass. In each pass the largest number is stored at the end of the list. Here we are taking the numbers from location 8041H to 8046H. The array size is stored at 8040H.
Input
Address | Data |
---|---|
... | ... |
8040 | 06 |
8041 | 06 |
8042 | 05 |
8043 | 04 |
8044 | 01 |
8045 | 02 |
8046 | 03 |
... | ... |
Flow Diagram
Program
Address | HEX Codes | Labels | Mnemonics | Comments |
---|---|---|---|---|
8000 | 21, 40, 80 | START | LXI H, 8040H | Pointer to the IN-BUFFER |
8003 | 16, 00 | MVI D, 00H | The D register is used as a flag register | |
8005 | 4E | MOV C, M | Initialize reg. C with data count | |
8006 | 0D | DCR C | Set Reg. C for comparison count | |
8007 | 23 | INX H | Pointing to the next location | |
8008 | 7E | CHECK | MOV A, M | Get the number |
8009 | 23 | INX H | Go to next location | |
800A | BE | CMP M | Compare the contents of the current memory location with the contents of the accumulator | |
800B | DA, 14, 80 | JC NEXTBYT | If (A) < second byte, do not exchange | |
800E | 46 | MOV B, M | Get second byte for exchange | |
800F | 77 | MOV M, A | Store first byte in second location | |
8010 | 2B | DCX H | Point to first location | |
8011 | 70 | MOV M, B | Store second byte in first location | |
8012 | 23 | INX H | Get ready for next comparison | |
8013 | 16, 01 | MVI D, 01H | Load 1 in D as a remainder for exchange | |
8015 | 0D | NEXTBYT | DCR C | Decrement comparison count |
8016 | C2, 08, 80 | JNZ CHECK | If comparison count not 0, go back | |
8019 | 7A | MOV A, D | Get flag bit in A | |
801A | 0F | RRC | Place flag bit D0in carry | |
801B | DA, 00, 80 | JC START | If flag is 1, exchange occurred | |
801E | 76 | HLT | Terminate the program |
Output
Address | Data |
---|---|
... | ... |
8041 | 01 |
8042 | 02 |
8043 | 03 |
8044 | 04 |
8045 | 05 |
8046 | 06 |
... | ... |
Advertisements