Section: Array Operations & Code Conversions
Aim: To sort the given numbers in the ascending 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 larger than the second, then interchange the numbers.
- If the first number is smaller, go to step 4.
- Repeat steps 2 and 3 until the numbers are in the 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 | JC | LOOP1 | If A is less 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:01 - Address
4201:02 - Address
4202:03 - Address
4203:06 - Address
4204:07
- Address
Result: Thus the ascending order program is executed and the numbers are arranged in ascending order.
Flowchart:
+-------------------+ | START | +---------+---------+ | v +-------------------+ | [B] <- 04H | +---------+---------+ | v <-------------------------------+ +-------------------+ | | [HL] <- 4200H | | +---------+---------+ | | | v | +-------------------+ | | [C] <- 04H | | +---------+---------+ | | | v <-------------------+ | +-------------------+ | | | [A] <- [M] | | | +---------+---------+ | | | | | v | | +-------------------+ | | | [HL] <- [HL] + 1 | | | +---------+---------+ | | | | | v | | / \ | | / Is \ | | / [A] < [M]?\ | | < (CY = 1) > | | \ / | | \ / | | \ / | | | | | +------------+------------+ | | | | | | 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:
Explain the INX operation.
State the logic behind sorting an array of data in descending order.
What are the advantages of using memory segmentation in 8085?
What is a macro and when is it used?
What is the function of the direction flag?
What is DMA?
Define machine cycle and instruction cycle.
For all 2026 published articles list: click here:
…till the next post, bye-bye & take care