Skip to main content

Arrange in ascending order

Write a program to sort given 10 numbers from memory location 2200H in the ascending order.

  1. MVI B, 09 :"Initialize counter"
  2. START :"LXI H, 2200H: Initialize memory pointer"
  3. MVI C, 09H :"Initialize counter 2"
  4. BACK: MOV A, M :"Get the number"
  5. INX H :"Increment memory pointer"
  6. CMP M :"Compare number with next number"
  7. JC SKIP :"If less, don’t interchange"
  8. JZ SKIP :"If equal, don’t interchange"
  9. MOV D, M
  10. MOV M, A
  11. DCX H
  12. MOV M, D
  13. INX H :"Interchange two numbers"
  14. SKIP:DCR C :"Decrement counter 2"
  15. JNZ BACK :"If not zero, repeat"
  16. DCR B :"Decrement counter 1"
  17. JNZ START
  18. HLT :"Terminate program execution"

Comments