16 bit multiplication using 8085 microprocessor

6.5k views Asked by At

Following is assembly language for multiplying two 16 bit numbers.

   LHLD 0002H ;DATA 1
   SPHL
   LHLD 0004H ;DATA 2
   XCHG
   LXI  H,0000H
   LXI  B,0000H
NEXT:
   DAD  SP
   JNC  LOOP
   INX  B
LOOP:
   DCX  D
   MOV  A,E
   ORA  D
   JNZ  NEXT
   SHLD 0006H ;LSB
   MOV  L,C
   MOV  H,B
   SHLD 0008H ;MSB
   HLT

I did not understand the instruction ORA D. Why ORing is done here? Please can anyone explain it. Thank You!

2

There are 2 answers

0
wallyk On

ORA D is used as a test instruction. It is logically ORing the accumulator with the D register. If the result is zero, it then exits the loop. Otherwise, the JNZ instruction following it reenters the loop.

The D and E registers hold a countdown for the number of loops. The overall logic is hard for me to follow: it has been 30+ years since I have used the 8085, so I need to look up most of the instructions to unravel the logic. But hopefully this answers your question.

0
Satvik Singh On

DCX instruction decrement Register pair without affecting any flags. On the other hand, logical instruction like ORA can set flags.

DCX  D
     MOV  A,E
     ORA  D
     JNZ  NEXT

Loop will exit only when contents of both D and E registers are zero (because 0 OR 0 = 0 is the only way for an OR to produce zero).

An ORA instruction will set Zero flag at this point and loop will exit. So ORA has been used to explicitly set Zero flag.

So it's using A as a temporary to check whether the 16-bit E:D pair is zero by doing A = E|D and setting flags.