Q. Write an 8085 program and draw a flowchart to find the smallest number in an array.(8085 Microprocessor Program)
Flowchart/Algorithm
Program
Address |
Mnemonics | Operand | Opcode |
Comments |
2000 | LXI | H, 3000H | 21 | Load H-L pair with address 3000H. |
2001 | 00 | |||
2002 | 30 | |||
2003 | MOV | C, M | 4E | Move the counter from memory to reg. C. |
2004 | INX | H | 23 | Increment H-L pair. |
2005 | MOV | A, M | 7E | Move the 1st number from memory to reg. A. |
2006 | DCR | C | 0D | Decrement counter. |
2007 | INX | H | 23 | Increment H-L pair. |
2008 | MOV | B, M | 46 | Move the next number from memory to reg. B. |
2009 | CMP | B | B8 | Compare B with A. |
200A | JC | 200EH | DA | Jump to address 200EH if there is no carry. |
200B | 0E | |||
200C | 20 | |||
200D | MOV | A, B | 78 | Move smallest from reg. B to reg. A. |
200E | DCR | C | 0D | Decrement counter. |
200F | JNZ | 2007H | C2 | Jump to address 2007H if the counter is not zero. |
2010 | 07 | |||
2011 | 20 | |||
2012 | INX | H | 23 | Increment H-L pair. |
2013 | MOV | M, A | 77 | Move the result from reg. A to memory. |
2014 | HLT | 76 | Halt |
Output
Before Execution:
3000H: 05H (Counter)
3001H: 15H
3002H: 01H
3003H: 65H
3004H: E2H
3005H: 83H
After Execution:
3006H: 01H
Program Explanation
- This program finds the smallest number in an array.
- Initially, the counter is initialized with the size of an array.
- Then, two numbers are moved to registers A and B and compared.
- After comparison, the smallest of two must be in the accumulator. If it is already in the accumulator, then its fine, otherwise it is moved to the accumulator.
- The counter is decremented and checked whether it has reached zero. If it has, the loop terminates otherwise, the next number is moved to register and compared.
- Let us assume that the memory location 3000H stores the counter. The next memory locations store the array.
- Initially, H-L pair is loaded with the address of the counter and is moved to register C.
- Then, H-L pair is incremented to point to the first number in the array.
- The first number is moved from memory to accumulator and counter is decremented by one.
- H-L pair is again incremented and the second number is moved to register B.
- The two numbers are compared.
- After comparison, if A > B, then CF = 0, and if A < B, then CF = 1.
- Carry flag is checked for carry. If there is no carry, it means B is smaller than A and it is moved to the accumulator.
- The counter is decremented and checked whether it has become zero.
- If it hasn’t become zero, it means there are numbers left in the array. In this case, the control jumps back to increment the H-L pair and moves the next number to register B.
- This process continues until counter becomes zero, i.e. all the numbers in the array are compared.
- At last, H-L pair is incremented and the smallest number is moved from accumulator to memory.
thank you for providing program.
I have lab today. you save me. thnx a lot.
Thanks a lot
it was of great help
Keep uploading the programs
Also tell us if different programs can be written for the same task
nice explanation.and it’s very simple to understand