Two 8-bits numbers (say x,y) are stored
in memory location 0000H and 0001H.This program finds the value of 2(x*y) and
stores the result at 0002H and 0003H.
First we add x with itself y times to
get x*y, the sum is stored in register D and carry in register E(if any). Then
the byte is register D is added twice and if any carry is generated is stored
in register C, finally the carry in register E is added twice withe itself and
then with C to get the result
LXI H,0000H
MOV B,M
INX H
MOV C,M
XRA A
MOV D,A
MOV E,A
LOOP: ADD B
JNC SKIP
INR E
SKIP: DCR C
JNZ LOOP
MOV D,A
XRA A
MOV C,A
MVI B,02H
LOOP1: ADD D
JNC SKIP1
INR C
SKIP1: DCR B
JNZ LOOP1
STA 0002H
MVI B,02H
XRA A
LOOP2: ADD E
DCR B
JNZ LOOP2
ADD C
STA 0003H
HLT
Use GNU simulator to test the program available on
ReplyDeletehttp://gnusim8085.org/