Q. Write an 8085 program and draw a flowchart to Multiply 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 | B, M | 46 | Move the 1st operand from memory to reg. B. |
2004 | INX | H | 23 | Increment H-L pair. |
2005 | MOV | C, M | 4E | Move the 2nd operand from memory to reg. C. |
2006 | MVI | A, 00H | 3E | Initialize accumulator with 00H. |
2007 | 00 | |||
2008 | ADD | B | 80 | Add B with A. |
2009 | DCR | C | 0D | Decrement reg. C (counter). |
200A | JNZ | 2008H | C2 | Jump back to address 2008H if C ^ 0. |
200B | 08 | |||
200C | 20 | |||
200D | INX | H | 23 | Increment H-L pair. |
200E | MOV | M, A | 77 | Move the result from accumulator to memory. |
200F | HLT | 76 | Halt |
Output
Before Execution:
3000H: 02H
3001H: 05H
After Execution:
3002H: 0AH
Program Explanation
- This program multiplies two operands stored in memory location 3000H and 3001H, using successive addition method.
- In successive addition method, the second operand is considered as the counter, and the first number is added to itself until counter decrements to zero.
- Let us assume that the operands stored at memory location 3000H are 02H and 3001H is 05H.
- Then, by using successive addition method, we get 02H + 02H + 02H + 02H + 02H = 0AH.
- Initially, H-L pair is loaded with the address of first memory location.
- The first operand is moved to register B from memory location 3000H and H-L pair is incremented to point to next memory location.
- The second operand is moved to register C from memory location 3001H to act as the counter.
- The accumulator is initialized to 00H.
- Register B is added to the accumulator and the result is stored in the accumulator.
- Register C (counter) is decremented by 1.
- Then, the counter is checked for zero. If it hasn’t become zero yet, then register B is again added to the accumulator, and the counter is again checked for zero.
- If counter becomes zero, then H-L pair is incremented and the result is moved from the accumulator to memory location 3002H.
Great explanation of the multiplication process for 8-bit numbers! The step-by-step guide makes it easy to follow along. I especially appreciated the examples provided. Looking forward to more posts like this!