Section: Array Operations & Code Conversions
Aim: To sort the given numbers in the descending order using 8085 microprocessor.
Apparatus Required: 8085 microprocessor kit, key board.
Algorithm:
- Get the numbers to be sorted from the memory locations.
- Compare the first two numbers and if the first number is smaller than second then interchange the number.
- If the first number is larger, go to step 4.
- Repeat steps 2 and 3 until the numbers are in required order.
Program:
| Address | Label | Mnemonics | Operand | Comment |
|---|---|---|---|---|
| 4100 | MVI | B, 04 | Initialize B reg with number of comparisons (n-1) | |
| 4102 | LOOP3 | LXI | H, 4200 | Initialize HL reg. to 4200H |
| 4105 | MVI | C, 04 | Initialize C reg with no. of comparisons (n-1) | |
| 4107 | LOOP2 | MOV | A, M | Transfer first data to acc. |
| 4108 | INX | H | Increment HL reg. to point next memory location | |
| 4109 | CMP | M | Compare M & A | |
| 410A | JNC | LOOP1 | If A is greater than M then go to loop1 | |
| 410D | MOV | D, M | Transfer data from M to D reg | |
| 410E | MOV | M, A | Transfer data from acc to M | |
| 410F | DCX | H | Decrement HL pair | |
| 4110 | MOV | M, D | Transfer data from D to M | |
| 4111 | INX | H | Increment HL pair | |
| 4112 | LOOP1 | DCR | C | Decrement C reg |
| 4113 | JNZ | LOOP2 | If C is not zero go to loop2 | |
| 4116 | DCR | B | Decrement B reg | |
| 4117 | JNZ | LOOP3 | If B is not Zero go to loop3 | |
| 4118 | HLT | Stop the program |
Observation:
- Input:
- Address
4200:01 - Address
4201:06 - Address
4202:03 - Address
4203:07 - Address
4204:02
- Address
- Output:
- Address
4200:07 - Address
4201:06 - Address
4202:03 - Address
4203:02 - Address
4204:01
- Address
Result: Thus the descending order program is executed and the numbers are arranged in descending order.
Flowchart:
+-------------------+
| START |
+---------+---------+
|
v
+-------------------+
| [B] <- 04H |
+---------+---------+
|
v
+-------------------+
| [HL] <- 4200H |
+---------+---------+
|
v
+-------------------+
| [C] <- 04H |
+---------+---------+
|
v
+-------------------+
| [A] <- [M] |
+---------+---------+
|
v
+-------------------+
| [HL] <- [HL] + 1 |
+---------+---------+
|
v
/ \
/ Is \
/ [A] >= [M]?\
< (CY = 0) >
\ /
\ /
\ /
|
+-----------+------------+
| |
YES NO
| |
| v
| +-------------------+
| | [D] <- [M] |
| | [M] <- [A] |
| | [HL] <- [HL] - 1 |
| | [M] <- [D] |
| | [HL] <- [HL] + 1 |
| +---------+---------+
| |
+-----------+------------+
|
v
+-------------------+
| [C] <- [C] - 1 |
+---------+---------+
|
v
/ \
/ Is \
/ [C] = 0? \
< >
\ Is zero? / --- NO ---> (To LOOP2)
\ /
\ /
| YES
v
+-------------------+
| [B] <- [B] - 1 |
+---------+---------+
|
v
/ \
/ Is \
/ [B] = 0? \
< >
\ Is zero? / --- NO ---> (To LOOP3)
\ /
\ /
| YES
v
+-------------------+
| STOP |
+-------------------+
Viva Questions:
- Give out the purpose of the instruction DCX.
- What is meant by CALL instruction?.
- Briefly give out the LHLD instruction.
- State the logic behind the Sorting an array of data in Descending order.
- Name the various flag bits available in 8085 microprocessor?.
- Give the significance of SIM and RIM instructions available in 8085?.
- How do the address and data lines are demultiplexed in 8085?.
For all 2026 published articles list: click here:
…till the next post, bye-bye & take care