Monday, September 28, 2026

Sorting an array of data in Descending order | 8085 Lab Program

 Section: Array Operations & Code Conversions

Aim: To sort the given numbers in the descending order using 8085 microprocessor.

Apparatus Required: 8085 microprocessor kit, key board.

Algorithm:

  1. Get the numbers to be sorted from the memory locations.
  2. Compare the first two numbers and if the first number is smaller than second then interchange the number.
  3. If the first number is larger, go to step 4.
  4. Repeat steps 2 and 3 until the numbers are in required order.

Program:

AddressLabelMnemonicsOperandComment
4100MVIB, 04Initialize B reg with number of comparisons (n-1)
4102LOOP3LXIH, 4200Initialize HL reg. to 4200H
4105MVIC, 04Initialize C reg with no. of comparisons (n-1)
4107LOOP2MOVA, MTransfer first data to acc.
4108INXHIncrement HL reg. to point next memory location
4109CMPMCompare M & A
410AJNCLOOP1If A is greater than M then go to loop1
410DMOVD, MTransfer data from M to D reg
410EMOVM, ATransfer data from acc to M
410FDCXHDecrement HL pair
4110MOVM, DTransfer data from D to M
4111INXHIncrement HL pair
4112LOOP1DCRCDecrement C reg
4113JNZLOOP2If C is not zero go to loop2
4116DCRBDecrement B reg
4117JNZLOOP3If B is not Zero go to loop3
4118HLTStop the program

Observation:

  • Input:
    • Address 4200: 01
    • Address 4201: 06
    • Address 4202: 03
    • Address 4203: 07
    • Address 4204: 02
  • Output:
    • Address 4200: 07
    • Address 4201: 06
    • Address 4202: 03
    • Address 4203: 02
    • Address 4204: 01

Result: Thus the descending order program is executed and the numbers are arranged in descending order.

Flowchart:

               +-------------------+
               |       START       |
               +---------+---------+
                         |
                         v
               +-------------------+
               |    [B] <- 04H     |
               +---------+---------+
                         |
                         v
               +-------------------+
               |   [HL] <- 4200H   |
               +---------+---------+
                         |
                         v
               +-------------------+
               |    [C] <- 04H     |
               +---------+---------+
                         |
                         v
               +-------------------+
               |    [A] <- [M]     |
               +---------+---------+
                         |
                         v
               +-------------------+
               |  [HL] <- [HL] + 1 |
               +---------+---------+
                         |
                         v
                       /   \
                     /  Is   \
                   / [A] >= [M]?\
                  <  (CY = 0)   >
                   \           /
                     \       /
                       \   /
                        |
            +-----------+------------+
            |                        |
           YES                       NO
            |                        |
            |                        v
            |              +-------------------+
            |              |    [D] <- [M]     |
            |              |    [M] <- [A]     |
            |              |  [HL] <- [HL] - 1 |
            |              |    [M] <- [D]     |
            |              |  [HL] <- [HL] + 1 |
            |              +---------+---------+
            |                        |
            +-----------+------------+
                        |
                        v
              +-------------------+
              |   [C] <- [C] - 1  |
              +---------+---------+
                        |
                        v
                      /   \
                    /  Is   \
                  /  [C] = 0? \
                 <            >
                  \ Is zero? / --- NO ---> (To LOOP2)
                    \      /
                      \  /
                       | YES
                       v
              +-------------------+
              |   [B] <- [B] - 1  |
              +---------+---------+
                        |
                        v
                      /   \
                    /  Is   \
                  /  [B] = 0? \
                 <            >
                  \ Is zero? / --- NO ---> (To LOOP3)
                    \      /
                      \  /
                       | YES
                       v
              +-------------------+
              |       STOP        |
              +-------------------+

Viva Questions:

  1. Give out the purpose of the instruction DCX.
  2. What is meant by CALL instruction?.
  3. Briefly give out the LHLD instruction.
  4. State the logic behind the Sorting an array of data in Descending order.
  5. Name the various flag bits available in 8085 microprocessor?.
  6. Give the significance of SIM and RIM instructions available in 8085?.
  7. How do the address and data lines are demultiplexed in 8085?.


For all 2026 published articles list: click here: 

…till the next post, bye-bye & take care