This is the algorithm for bubble sort in 8085 assembly language. Here, the size of the list is to be stored by the user at 0040H, and the contents of the list form 0041H. The sorted list will be printed at the same memory location in sorted after the complete execution of the algorithm. The algorithm is given as follows:
Address | Label | Mnemonics | Comments |
---|---|---|---|
0000H | START | LXI H, 0040H | Load the address where the size of the list is stored in the HL pair |
0003H | MVI D, 00 | Initialize 00 to D register | |
0005H | MOV C, M | ||
0006H | DCR C | Decrement C register | |
0007H | INX H | Increment HL pair | |
0008H | CHECK | MOV A, M | Load the element in the accumulator |
0009H | INX H | Increment HL pair | |
000AH | CMP M | Compare accumulator and the next element | |
000BH | JC NEXT | If accumulator is less, then carry flag is set and NEXT label is reaches | |
000EH | MOV B, M | Swaping is done, otherwise | |
000FH | MOV M, A | Swapping | |
0010H | DCX H | Swapping | |
0011H | MOV M, B | Incr | |
0012H | INX H | Incr | |
00013H | MVI D, 01 | 01 is stored to remember that exchange was taken place | |
0015H | NEXT | DCR C | Decrement C |
0016H | JNZ CHECK | Check if the lenght of the array is traversed or not | |
0019H | MOV A, D | Move contents of D in accumulator | |
001AH | CPI 01 | Compare accumulator contents with 01 | |
001CH | JZ START | Jump to start if D=01H | |
001FH | HLT | Terminate the program |