Q. Write an 8085 program and draw a flowchart to Multiply two 8-bit numbers.(8085 Microprocessor Program)
|2000||LXI||H, 3000H||21||Load H-L pair with address 3000H.|
|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.|
|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.|
|200D||INX||H||23||Increment H-L pair.|
|200E||MOV||M, A||77||Move the result from accumulator to memory.|
- 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.