multiply two 8 bit numbers
DESCRIPTION
comTRANSCRIPT
-
8085 Programs
Gursharan Singh Tatla Page 1 of 3
Program 16: Multiply two 8-bit numbers.
Flowchart:
Initialize register A with 0.
Stop
Add B with A.
Decrement register C.
Is
C = 0?
Increment H-L pair.
Start
Load H-L pair with address
of first operands memory location.
Move the first operand from
memory to register B.
Increment H-L pair to point
to next memory location.
Move the second operand
from memory to register C.
Move the result from
accumulator to memory.
Yes
No
-
8085 Programs
Gursharan Singh Tatla Page 2 of 3
Program:
Address Mnemonics Operand Opcode Remarks
2000 LXI H, 3000H 21 Load H-L pair with address 3000H.
2001 00 Lower-order of 3000H.
2002 30 Higher-order of 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.
2007 00 Immediate value 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.
200B 08 Lower-order of 2008H.
200C 20 Higher-order of 2008H.
200D INX H 23 Increment H-L pair.
200E MOV M, A 77 Move the result from accumulator to memory.
200F HLT 76 Halt.
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 counter, and the first
number is added with itself until counter decrements to zero.
Let us assume that the operands stored at memory location 3000H is 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 counter.
Accumulator is initialized to 00H.
Register B is added with accumulator and the result is stored in accumulator.
Register C (counter) is decremented by 1.
Then, counter is checked for zero. If it hasnt become zero yet, then register B is again added
with accumulator, and counter is again checked for zero.
-
8085 Programs
Gursharan Singh Tatla Page 3 of 3
If counter becomes zero, then H-L pair is incremented and the result is moved from
accumulator to memory location 3002H.
Output:
Before Execution:
3000H: 02H
3001H: 05H
After Execution:
3002H: 0AH