8085 Program to Arrange an Array of Data in Ascending Order


Write a microprocessor 8085 program to arrange an array of data in ascending order. The length of the block is in memory location 4200H and the block itself starts from memory location 4201H.

Arrange the numbers in ascending order and store them at memory location from 4201H. Assume that the numbers in the block are all 8-bit unsigned binary numbers.


  1. Initialize HL pair as memory pointer.
  2. Get the count at 4200 into C – register.
  3. Copy it in D – register (for bubble sort (N-1) times required).
  4. Get the first value in Accumulator.
  5. Compare it with the value at next location.
  6. If they are out of order, exchange the contents of Accumulator and Memory.
  7. Decrement D –register content by 1.
  8. Repeat steps 5 and 7 till the value in D- register become zero.
  9. Decrement contents of C –register by 1.
  10. Repeat steps 3 to 9 till the value in C – register becomes zero.


8085 Program to Arrange an Array of Data in Ascending Order


LXI H, 4200H ; Set pointer for array.

MOV C, M ; Load the count value.

DCR C ; Decrement counter.


LXI H, 4201H ; Set the memory pointer for data.

LOOP: MOV A, M ; Move the number into accumulator.

INX H ; Increment memory pointer.

CMP M ; Compare memory and accumulator.

JC SKIP ; jump to skip if carry generated.

MOV B, M ; copy content of memory location to B – Register.

MOV M, A ; copy content of Accumulator to memory location.

DCX H ; Decrement content of HL pair of registers.

MOV M, B ; copy content of B – Register to memory location.

INX H ; Increment content of HL pair of registers.

SKIP: DCR D ; Decrement content of Register – D.

JNZ LOOP ; jump to loop if not equal to zero.

DCR C ; decrement counter.

JNZ REPEAT ; jump to repeat if not equal to zero.

HLT ; Terminate Program.

Sample Example:


4200 05 (Array Size)

4201 45

4202 DE

4203 17

4204 20

4205 50


4200 05(Array Size)

4201 17

4202 20

4203 45

4204 50

4205 DE

Recent posts

1 thought on “8085 Program to Arrange an Array of Data in Ascending Order”

  1. We are a ցroup of volunteers and starting a new scheme in our community.
    Your site offеred us with useful informatіon to woгk on. You’ve performed an impressive task
    and our еntire neighborhood will be thankful to you.

Leave a Comment

Your email address will not be published. Required fields are marked *