written 2.8 years ago by |
To find the largest number in an array :-
Aim:
To find the largest number in an array of data using 8085 instruction set.
Algorithm :-
Load the address of the first element of the array in HL pair
Move the count to B – reg.
Increment the pointer
Get the first data in A – reg.
Decrement the count.
Increment the pointer
Compare the content of memory addressed by HL pair with that of A - reg.
If Carry = 0, go to step 10 or if Carry = 1 go to step 9
Move the content of memory addressed by HL to A – reg.
Decrement the count
Check for Zero of the count. If ZF = 0, go to step 6, or if ZF = 1 go to next step.
Store the largest data in memory.
Terminate the program.
Program :
LXI H,4200 Set pointer for array
MOV B,M Load the Count
INX H Set 1st element as largest data
MOV A,M
DCR B Decrements the count
LOOP: INX H
CMP M f A- reg > M go to AHEAD
JNC AHEAD
MOVA,M Set the new value as largest
AHEAD:DCR B
JNZ LOOP Repeat comparisons till count = 0
STA 4300 Store the largest value at 4300
HLT
Observation :-
Input: 05 (4200) ----- Array Size
Output: 0A (4201)
F1 (4202)
1F (4203)
26 (4204)
FE (4205)
FE (4300)
Result :-
Thus the program to find the largest number in an array of data was executed.