Write a microprocessor 8085 program to arrange an array of data in descending order. The length of the block is in memory location 4200H and the block itself starts from memory location 4201H.
Arrange the numbers in descending order and store them at memory location from 4201H. Assume that the numbers in the block are all 8-bit unsigned binary numbers.
- Initialize HL pair as memory pointer
- Get the count at 4200 into C – register
- Copy it in D – register (for bubble sort (N-1) times required)
- Get the first value in accumulator.
- Compare it with the value at next location.
- If they are out of order, exchange the contents of accumulator and Memory.
- Decrement D –register content by 1.
- Repeat steps 5 and 7 till the value in D- register become zero.
- Decrement C –register content by 1.
- Repeat steps 3 to 9 till the value in C – register becomes zero.
LXI H, 4200H
MOV C, M
REPEAT: MOV D, C
LXI H, 2201H LOOP: MOV A, M
MOV B, M
MOV M, A
MOV M, B
SKIP: DCR D
4200 05 (Array Size)
4200 05(Array Size)