In the last program, we learned how we can arrange an array of 8-bit hexadecimal numbers in ascending, now in this program, we are going to arrange the same 8-bit hexadecimal numbers in descending order.
For this program also we are going to use five 8-bit hexadecimal numbers, hence, we will be requiring five memory locations; 2000H – 2004H.
The 8-bit hexadecimal numbers which we are going to use are C2H, ABH, 1DH, F9H, and 9BH.
MVI C, 05H // C register will be used as the main counter which we will keep decrementing as we compare one 8-bit number after another
Label3 MVI B, 04H // B register will also be used as another counter which we will need for comparison
LXI H, 2000H // HL register pair will be loaded and will point to the content of 2000H memory location
Label2 MOV A, M // the content of 2000H ML pointed by HL register will be copied to the accumulator
INX H// HL register pair will get incremented by one
CMP M// the content of accumulator will be compared with the content of memory location pointed by HL register pair
JNC Label1 // JNC will jump if the content of ML pointed by HL register pair is smaller than the content of accumulator
MOV D, M // the content which is pointed by HL register will be moved to D register
MOV M, A // the content of accumulator will be moved to the memory location pointed by HL register
DCX H // using DCX we decremented the HL register pair by 1
MOV M, D // now the 8-bit number stored in D register will be moved to the memory location pointed by HL register
INX H // HL register pair will be incremented by 1
Label1 DCR B // the content of B register pair will be decremented by 1
JNZ Label2 // JNZ will keep on working unless the content of ML doesn’t become null
DCR C // the content of C register pair will be decremented by 1
JNZ Label3 // JNZ will keep on jumping until the content of B register becomes null
|Memory Location||OPCODE||Operand||Label||Hex Code|