Saturday, September 26, 2026

Smallest element in an array | 8085 Lab Program

Section: Array Operations & Code Conversions 

Aim: To find the smallest element in an array of data stored in memory and also to verify the result.

Apparatus Required: 8085 microprocessor kit, key board.

Algorithm:

  1. Place all the elements of an array in the consecutive memory locations.
  2. Fetch the first element from the memory location and load it in the accumulator.
  3. Initialize a counter (register) with the total number of elements in an array.
  4. Decrement the counter by 1.
  5. Increment the memory pointer to point to the next element.
  6. Compare the accumulator content with the memory content (next element).
  7. If the accumulator content is smaller, then move the memory content to the accumulator; else continue.
  8. Decrement the counter by 1.
  9. Repeat steps 5 to 8 until the counter reaches zero.
  10. Store the result (accumulator content) in the specified memory location.

Program:

AddressLabelMnemonicsOperandComment
4100STARTLXIH, 4200Initialize HL reg. to 4200H
4103MVIB, 04Initialize B reg with no. of comparisons (n-1)
4105MOVA, MTransfer first data to acc.
4106LOOP1INXHIncrement HL reg. to point next memory location
4107CMPMCompare M & A
4108JCLOOPIf A is lesser than M then go to loop
410BMOVA, MTransfer data from M to A reg
410CLOOPDCRBDecrement B reg
410DJNZLOOP1If B is not Zero go to loop1
4110STA4205Store the result in a memory location
4113HLTStop the program

Observation:

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

Result: Thus the smallest number in the given array is found and it is stored at location 4205.

Flowchart:

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

Viva Questions:

  1. What is meant by instruction JC?
  2. Tell about the instruction SHLD.
  3. Summarize the instruction STAX B.
  4. State the logic behind the finding of smallest element.
  5. Why address bus is unidirectional?
  6. List few instructions to clear accumulator?
  7. What is the function of NOP instruction?

For all 2026 published articles list: click here: 

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