# Program to find the Largest of two 8-bit numbers

Q. Write a program and draw a flowchart to find the Largest of two 8-bit numbers.(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 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 JNC 200BH D2 Jump to address 200BH if there is no carry. 2008 0B 2009 20 200A MOV A, B 78 Move largest 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. 200D HLT 76 Halt

Before Execution:

3000H: 25H
3001H: 15H

After Execution:

3002H: 25H

Program Explanation

1. This program compares the two operands to find the largest out of them.
2. After comparison, the largest of two must be in the accumulator. If it is already in the accumulator, then it is moved to memory.
3. If it is not in the accumulator, then first it is moved to the accumulator and then from there, it is moved to memory.
4. Let us assume that the operands stored at memory location 3000H are 25H and 3001H is 15H.
5. Initially, H-L pair is loaded with the address of first memory location.
6. The first operand is moved to accumulator from memory location 3000H and H-L pair is incremented to point to next memory location.
7. The second operand is moved to register B from memory location 3001H.
8. The two operands are compared.
9. After comparison, if A > B, then CF = 0, and if A < B, then CF = 1.
10. Carry flag is checked for carry. If there is a carry, it means B is greater than A and it is moved to the accumulator.
11. At last, H-L pair is incremented and the largest number is moved from the accumulator to memory location 3002H.

This site uses Akismet to reduce spam. Learn how your comment data is processed.