Largest Number
Largest Number
using 8085?
Algorithm
1) Load the address of the first element of the array in HL pair.
2) Copy the count to register B.
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 = 0, go to step 10 or if Carry = 1 go to step 9.
9) Copy the content of the memory addressed by HL to Accumulator.
10) Decrement the count.
11) Check for Zero of the count. If Zero Flag (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.
Program
MEMORY
LABEL
4400
4401
4402
4403
4404
4405
LXI H,4200
MOV B,M
INX H
MOV A,M
HEX
CODE
21
00
42
46
23
7E
4406
4407
4408
DCR B
INX H
CMP M
05
23
BE
JNC AHEAD
MOV A,M
D2
0D
44
7E
DCR B
05
LOOP
4409
440A
440B
440C
440D
AHEAD
MNEMONIC
COMMENT
Load the array size to the HL pair
440E
440F
4410
4411
4412
4413
4414
JNZ LOOP
STA 4300
HLT
C2
07
44
32
00
43
76
Observation
Input at
Output at
4200 :
4201 :
4202 :
4203 :
4204 :
4205 :
4300 :
Statement: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 maximum number in memory location 2300H. Assume that the numbers in the
block are all 8 bit unsigned binary numbers.
Home
8085 Forum
8085 Tutorials
8085 details
Interfacing Techniques
Electronic Tutorials
Electronic Projects
Assembler/ IDE
Datasheets
Guest Book
About Me
Sample problem
(2200H) = 04
(2201H) = 34H
(2202H) = A9H
(2203H) = 78H
(2204H) =56H
Result = (2202H) = A9H
Source program
LDA 2200H
MOV C, A
XRA A
LXI H, 2201H
BACK: CMP M
JNC SKIP
MOV A, M
SKIP: INX H
DCR C
JNZ BACK
STA 2300H
HLT
: Initialize counter
: Maximum = Minimum possible value = 0
: Initialize pointer
: Is number> maximum
: Yes, replace maximum