8085 Program to Find the Smallest Number in An Array of Data

In the article, Microprocessor 8085 program to find the smallest number from an array of data in assembly language programming (ALP) is explained.

It is highly recommended to learn the instruction set of 8085 in detail before programming.

Problem:

Find the smallest number in a block of data. The length of the block is in memory location 2200H and the block itself starts from memory location 2201H.

Store the smallest number in memory location 2300H. Assume that the numbers in the block are all 8-bit unsigned binary numbers.

Algorithm:

  1. Load the address of the first element of the array in HL pair
  2. Move the count to B – register.
  3. Increment the pointer.
  4. Get the first data in Accumulator.
  5. Decrement the count.
  6. Increment the pointer.
  7. Compare the content of memory addressed by HL pair with that of Accumulator.
  8. If carry = 1, go to step 10 or if Carry = 0 go to step 9.
  9. Move the content of memory addressed by HL to Accumulator.
  10. Decrement the count.
  11. Check for Zero of the If ZF = 0, go to step 6, or if ZF = 1 go to next step.
  12. Store the smallest data in memory.
  13. Terminate the program.

Program:

LXI H,2200H ; Initialize the memory pointer

MOV B, M ; Copy contents of memory to register B

INX H ; Set pointer for array Load the Count

MOV A, M ; Set 1st element as smallest number

DCR B ; Decrement the count

LOOP:INX H ; Get the next number

CMP M ; If A- reg < M go to AHEAD

JC AHEAD ; Jump to ahead if Carry=1

MOV A, M ; Set the new value as smallest

AHEAD: DCR B ; Decrement the counter

JNZ LOOP ; Repeat comparisons till count = 0

STA 2300H ; Store the largest value at 2300

HLT ; Terminate the program

Sample Example:

Input:

(2200H) = 04

(2201H) = 34H

(2202H) = A9H

(2203H) = 78H

(2204H) = 56H

Result = (2300H) = 34H

Recent posts

Leave a Comment

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