In this program, we will write an 8085 Program to Find Maximum Number in Array in the 8085 microprocessor with a program flow chart and explanation of the program.
8085 Program to Find Maximum Number in Array
Program Statement
Given an array of numbers. Write a program in ALP of 8085 to find the maximum number amongst the numbers in the array. Assume that the length of the array is stored at memory location D000 H and the array begins from memory location D001 H. Store the maximum number at memory location E000 Н.
Explanation of Program
For example: we have an array of 10 numbers. So we initialize the counter with 10. Also, we initialize a pointer to point these numbers.
Compare the first number with the initial maximum number i.e. zero. If number > maximum number, save number otherwise increment the pointer to compare the next number. Decrement counter, compare till all the numbers are compared. Store the maximum number in memory location E000 Н.
Flow Chart of Program
Assembly Language Program
Label | Instruction | Comment | Operation |
---|---|---|---|
LDA D000H | Load accumulator with count. | A = 10H | |
MOV C, A | Initialize counter | C = 10H | |
XRA A | Initialize A = 0 | A = 00H | |
LXI H, D001H | Initialize memory pointer | H = D0H, L = 01H | |
BACK: | CMP M | Is number > maximum | |
JNC SKIP | |||
MOV A, M | if number > maximum then interchange | ||
SKIP: | INX H | increment memory pointer | HL = HL + 1 |
DCR C | Decrement counter | C = C – 1 | |
JNZ BACK | if count ≠ 0, repeat | ||
STA E000H | Store maximum number | E000H = max number result | |
HLT | Terminate program execution | Stop |