# 8085 Program to Find the Largest Number in an Array of Data

In the article, Microprocessor 8085 program to find the largest 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 largest 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 largest number in memory location 2300H. Assume that the numbers in the block are all 8-bit unsigned binary numbers.

### Algorithm for Program 1:

1)       Load the address of the first element of the array in HL pair

2)       Move the count to B – reg.

3)       Increment the pointer.

4)       Get the first data in A – reg.

5)       Decrement the count.

6)       Increment the pointer.

7)       Compare the content of memory addressed by HL pair with that of A – reg.

8)       If Carry = 0, go to step 10 or if Carry = 1 go to step 9.

9)       Move the content of memory addressed by HL to A – reg.

10)     Decrement the count

11)     Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.

12)     Store the largest data in memory.

13)     Terminate the program.

### Flowchart ### Program 1:

LXI H,2200H                   ; Set pointer for array.

MOV B, M                  ;Load the Count.

INX H

MOV A, M                   ; Set 1st element as largest data.

DCR B                          ; Decrement the count.

LOOP: INX      H

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

MOV A, M                   ; Set the new value as largest.

JNZ LOOP                    ; Repeat comparisons till count = 0.

STA 2300H                     ; Store the largest value at 2300.

HLT                              ; Terminate program execution.

### Program 2:

LDA 2200H

MOV C, A                     ; Initialize counter.

XRA A                         ; Maximum = Minimum possible value = 0.

LXI H, 2201H               ; Initialize pointer.

BACK: CMP M             ; Is number> maximum.

JNC SKIP                      ; Yes, replace maximum.

MOV A, M

SKIP: INX H

DCR C

JNZ BACK

STA 2300H                  ; Store maximum number.

HLT                              ; Terminate program execution.

### Sample Example:

(2200H) = 04

(2201H) = 34H

(2202H) = A9H

(2203H) = 78H

(2204H) = 56H

Result = (2300H) = A9H.