Q. Write an 8085 program and draw a flowchart to find the Smallest of two 8-bit numbers.(8085 Microprocessor Program)
|2000||LXI||H, 3000H||21||Load H-L pair with address 3000H.|
|2003||MOV||A, M||7E||Move the 1st operand from memory to reg. A.|
|2004||INX||H||23||Increment H-L pair.|
|2005||MOV||B, M||46||Move the 2nd operand from memory to reg. B.|
|2006||CMP||B||B8||Compare B with A.|
|2007||JC||200BH||DA||Jump to address 200BH if there is no carry.|
|200A||MOV||A, B||78||Move smallest from reg. B to reg. A.|
|200B||INX||H||23||Increment H-L pair.|
|200C||MOV||M, A||77||Move the result from reg. A to memory.|
- This program compares two operands to find the smallest out of them.
- After comparison, the smallest of two must be in the accumulator. If it is already in the accumulator, then it is moved to memory.
- If it is not in the accumulator, then first it is moved to the accumulator and then from there, it is moved to memory.
- Let us assume that the operands stored at memory location 3000H are 25H and 3001H is 15H.
- Initially, H-L pair is loaded with the address of first memory location.
- The first operand is moved to accumulator from memory location 3000H and H-L pair is incremented to point to next memory location.
- The second operand is moved to register B from memory location 3001H.
- The two operands 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.
- At last, H-L pair is incremented and the smallest number is moved from the accumulator to memory location 3002H.