Largest number in an array of data using 8085
Ø An
Assembly Language Program to find the largest number in an array of data 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
|
MNEMONIC
|
HEX CODE
|
COMMENT
|
4400
|
LXI H,4200
|
21
|
Load the array
size to the HL pair
|
|
4401
|
00
|
|||
4402
|
42
|
|||
4403
|
MOV B,M
|
46
|
Copy the array
size to B register
|
|
4404
|
INX H
|
23
|
Increment the
memory
|
|
4405
|
MOV A,M
|
7E
|
Copy the first
data to the Accumulator
|
|
4406
|
DCR B
|
05
|
Decrement the
Array size by 1
|
|
4407
|
LOOP
|
INX H
|
23
|
Increment the
memory
|
4408
|
CMP M
|
BE
|
Compare
accumulator content and memory
|
|
4409
|
JNC AHEAD
|
D2
|
Jump on no
carry to label AHEAD
|
|
440A
|
0D
|
|||
440B
|
44
|
|||
440C
|
MOV A,M
|
7E
|
Copy the
memory content to the accumulator
|
|
440D
|
AHEAD
|
DCR B
|
05
|
Decrement
register B by 1
|
440E
|
JNZ LOOP
|
C2
|
Jump on
non-zero to label LOOP
|
|
440F
|
07
|
|||
4410
|
44
|
|||
4411
|
STA 4300
|
32
|
Store
accumulator content to 4300
|
|
4412
|
00
|
|||
4413
|
43
|
|||
4414
|
HLT
|
76
|
Program ends
|
Observation
Input at 4200 : 05H --------------- Array
Size
4201 : 0AH
4202 : F1H
4203 : 1FH
4204 : 26H
4205 : FEH
Output at 4300 : FEH
----------------------------------------------------------------------------------------------
Ø An
Assembly Language Program to find the smallest number in an array of data 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 = 1, go to step 10 or if Carry = 0 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 smallest data in memory.
13) Terminate
the program.
Program
MEMORY
|
LABEL
|
MNEMONIC
|
HEX CODE
|
COMMENT
|
4400
|
LXI H,4200
|
21
|
Load the array
size to the HL pair
|
|
4401
|
00
|
|||
4402
|
42
|
|||
4403
|
MOV B,M
|
46
|
Copy the array
size to B register
|
|
4404
|
INX H
|
23
|
Increment the
memory
|
|
4405
|
MOV A,M
|
7E
|
Copy the first
data to the Accumulator
|
|
4406
|
DCR B
|
05
|
Decrement the
Array size by 1
|
|
4407
|
LOOP
|
INX H
|
23
|
Increment the
memory
|
4408
|
CMP M
|
BE
|
Compare
accumulator content and memory
|
|
4409
|
JC AHEAD
|
DA
|
Jump on carry
to label AHEAD
|
|
440A
|
0D
|
|||
440B
|
44
|
|||
440C
|
MOV A,M
|
7E
|
Copy the
memory content to the accumulator
|
|
440D
|
AHEAD
|
DCR B
|
05
|
Decrement
register B by 1
|
440E
|
JNZ LOOP
|
C2
|
Jump on
non-zero to label LOOP
|
|
440F
|
07
|
|||
4410
|
44
|
|||
4411
|
STA 4300
|
32
|
Store
accumulator content to 4300
|
|
4412
|
00
|
|||
4413
|
43
|
|||
4414
|
HLT
|
76
|
Program ends
|
Observation
Input at 4200 : 05H ---------- Array Size
4201 : 0AH
4202 : F1H
4203 : 1FH
4204 : 26H
4205 : FEH
Output at 4300 : 0AH
-----------------------------------------------------------------------------------------------
No comments:
Post a Comment