Microprocessor-8085-LARGEST/SMALLEST ELEMENT IN AN ARRAY
LARGEST ELEMENT IN AN ARRAY
AIM:
To find the largest element in an array.
ALGORITHM:
- Place all the elements of an array in the consecutive memory locations.
- Fetch the first element from the memory location and load it in the accumulator.
- Initialize a counter (register) with the total number of elements in an array.
- Decrement the counter by 1.
- Increment the memory pointer to point to the next element.
- Compare the accumulator content with the memory content (next element).
- If the accumulator content is smaller, then move the memory content (largest element) to the accumulator. Else continue.
- Decrement the counter by 1.
- Repeat steps 5 to 8, until the counter reaches zero.
- Store the result (accumulator content) in the specified memory location.
RESULT:
Thus the largest number in the given array is found out.
PROGRAM:
ADDRESS
|
OPCO
DE
|
LABEL
|
MNEMONICS
|
OPERAND
|
COMMENTS
|
8001
|
LXI
|
H,8100
|
Initialize HL reg. to 8100H
| ||
8002
| |||||
8003
| |||||
8004
|
MVI
|
B,04
|
Initialize B reg with no. of comparisons (n-1)
| ||
8005
| |||||
8006
|
MOV
|
A,M
|
Transfer first data to acc.
| ||
8007
|
LOOP1
|
INX
|
H
|
Increment HL reg. to point next memory location
| |
8008
|
CMP
|
M
|
Compare M & A
| ||
8009
|
JNC
|
LOOP
|
If A is greater than M then go to loop
| ||
800A
| |||||
800B
| |||||
800C
|
MOV
|
A,M
|
Transfer data from M to A reg
| ||
800D
|
LOOP
|
DCR
|
B
|
Decrement B reg
| |
800E
|
JNZ
|
LOOP1
|
If B is not Zero go to loop1
| ||
800F
| |||||
8010
| |||||
8011
|
STA
|
8105
|
Store the result in a memory location.
| ||
8012
| |||||
8013
| |||||
8014
|
RST 5
|
Stop the program
|
OBSERVATION:
INPUT
|
OUTPUT
| |||||
ADDRESS
|
DATA
|
ADDRESS
|
DATA
| |||
8100
|
8105
| |||||
8101
| ||||||
8102
| ||||||
8103
| ||||||
8104
| ||||||
AIM:
To find the smallest element in an array.
ALGORITHM:
- Place all the elements of an array in the consecutive memory locations.
- Fetch the first element from the memory location and load it in the accumulator.
- Initialize a counter (register) with the total number of elements in an array.
- Decrement the counter by 1.
- Increment the memory pointer to point to the next element.
- Compare the accumulator content with the memory content (next element).
- If the accumulator content is smaller, then move the memory content (largest element) to the accumulator. Else continue.
- Decrement the counter by 1.
- Repeat steps 5 to 8 until the counter reaches zero
- Store the result (accumulator content) in the specified memory location.
RESULT:
Thus the smallest number in the given array is found out.
PROGRAM:
ADDRESS
|
OPCODE
|
LABEL
|
MNEMONICS
|
OPERAND
|
COMMENTS
|
8001
|
LXI
|
H,8100
|
Initialize HL reg. to 8100H
| ||
8002
| |||||
8003
| |||||
8004
|
MVI
|
B,04
|
Initialize B reg with no. of comparisons (n-1)
| ||
8005
| |||||
8006
|
MOV
|
A,M
|
Transfer first data to acc.
| ||
8007
|
LOOP1
|
INX
|
H
|
Increment HL reg. to point next memory location
| |
8008
|
CMP
|
M
|
Compare M & A
| ||
8009
|
JC
|
LOOP
|
If A is lesser than M then go to loop
| ||
800A
| |||||
800B
| |||||
800C
|
MOV
|
A,M
|
Transfer data from M to A reg
| ||
800D
|
LOOP
|
DCR
|
B
|
Decrement B reg
| |
800E
|
JNZ
|
LOOP1
|
If B is not Zero go to loop1
| ||
800F
| |||||
8010
| |||||
8011
|
STA
|
8105
|
Store the result in a memory location.
| ||
8012
| |||||
8013
| |||||
8014
|
RST 5
|
Stop the program
|
OBSERVATION:
INPUT
|
OUTPUT
| |||||
ADDRESS
|
DATA
|
ADDRESS
|
DATA
| |||
8100
|
8105
| |||||
8101
| ||||||
8102
| ||||||
8103
| ||||||
8104
| ||||||
No comments:
Post a Comment