Friday, September 25, 2026

Largest element in an array | 8085 Lab Program

 Section: Array Operations & Code Conversions

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

Apparatus Required: 8085 microprocessor kit, keyboard.

Algorithm:

  1. Place all the elements of an array in 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 (or total comparisons \(n-1\)).
  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 (largest element) 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
4100LXIH, 4200Initialize HL reg. to data location
4103MVIB, 04Initialize B reg with no. of comparisons (\(n-1\))
4105MOVA, MTransfer first data to accumulator
4106LOOP1INXHIncrement HL reg. to point next memory location
4107CMPMCompare M & A
4108JNCLOOPIf A is greater 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:
    • 4200: 01
    • 4201: 06
    • 4202: 03
    • 4203: 07
    • 4204: 02
  • Output:
    • 4205: 07

Result: Thus the largest 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 the instruction CMP M?
  2. What the instruction JNZ will do?
  3. State the logic behind the finding of largest element.
  4. List out the similarities b/w the CALL-RET and PUSH-POP instructions?
  5. What is the need of ALE signal in 8085?
  6. What are the addressing modes of 8085?


For all 2026 published articles list: click here: 

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

No comments:

Post a Comment