Section: Array Operations & Code Conversions
Aim: To find the smallest element in an array of data stored in memory and also to verify the result.
Apparatus Required: 8085 microprocessor kit, key board.
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 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.
Program:
| Address | Label | Mnemonics | Operand | Comment |
|---|---|---|---|---|
| 4100 | START | LXI | H, 4200 | Initialize HL reg. to 4200H |
| 4103 | MVI | B, 04 | Initialize B reg with no. of comparisons (n-1) | |
| 4105 | MOV | A, M | Transfer first data to acc. | |
| 4106 | LOOP1 | INX | H | Increment HL reg. to point next memory location |
| 4107 | CMP | M | Compare M & A | |
| 4108 | JC | LOOP | If A is lesser than M then go to loop | |
| 410B | MOV | A, M | Transfer data from M to A reg | |
| 410C | LOOP | DCR | B | Decrement B reg |
| 410D | JNZ | LOOP1 | If B is not Zero go to loop1 | |
| 4110 | STA | 4205 | Store the result in a memory location | |
| 4113 | HLT | Stop the program |
Observation:
- Input:
- Address
4200:01 - Address
4201:06 - Address
4202:03 - Address
4203:07 - Address
4204:02
- Address
- Output:
- Address
4205:01
- Address
Result: Thus the smallest number in the given array is found and it is stored at location 4205.
Flowchart:
+-------------------+
| START |
+---------+---------+
|
v
+-------------------+
| [HL] <- 4200H |
+---------+---------+
|
v
+-------------------+
| [B] <- 04H |
+---------+---------+
|
v
+-------------------+
| [A] <- [M] |
+---------+---------+
|
v <------------------+
+-------------------+ |
| [HL] <- [HL] + 1 | |
+---------+---------+ |
| |
v |
/ \ |
/ Is \ |
/ [A] < [HL]? \ |
< (CY = 1) > |
\ / |
\ / |
\ / |
| / |
+-----------+--+ |
| | |
YES NO |
| | |
| v |
| +-------------------+ |
| | [A] <- [HL] | |
| +---------+---------+ |
| | |
+-------+------+ |
| |
v |
+-------------------+ |
| [B] <- [B] - 1 | |
+---------+---------+ |
| |
v |
/ \ |
/ Is \ |
/ [B] = 0? \ |
< > |
\ Is Zero? / -- NO -----------+
\ /
\ /
| YES
v
+-------------------+
| <- [A] |
+---------+---------+
|
v
+-------------------+
| STOP |
+-------------------+
Viva Questions:
- What is meant by instruction JC?
- Tell about the instruction SHLD.
- Summarize the instruction STAX B.
- State the logic behind the finding of smallest element.
- Why address bus is unidirectional?
- List few instructions to clear accumulator?
- What is the function of NOP instruction?