Section: Array Operations & Code Conversions
Aim: To find the largest element in an array of data stored in memory and also to verify the result.
Apparatus Required: 8085 microprocessor kit, keyboard.
Algorithm:
- Place all the elements of an array in 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 (or total comparisons \(n-1\)).
- 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.
Program:
| Address | Label | Mnemonics | Operand | Comment |
|---|---|---|---|---|
| 4100 | LXI | H, 4200 | Initialize HL reg. to data location | |
| 4103 | MVI | B, 04 | Initialize B reg with no. of comparisons (\(n-1\)) | |
| 4105 | MOV | A, M | Transfer first data to accumulator | |
| 4106 | LOOP1 | INX | H | Increment HL reg. to point next memory location |
| 4107 | CMP | M | Compare M & A | |
| 4108 | JNC | LOOP | If A is greater 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:
4200:014201:064202:034203:074204:02
- Output:
4205:07
Result: Thus the largest 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 the instruction CMP M?
- What the instruction JNZ will do?
- State the logic behind the finding of largest element.
- List out the similarities b/w the CALL-RET and PUSH-POP instructions?
- What is the need of ALE signal in 8085?
- What are the addressing modes of 8085?
For all 2026 published articles list: click here:
…till the next post, bye-bye & take care
No comments:
Post a Comment