Saturday, September 12, 2009

Multiply two eight bit numbers with shift and add method(8085)

Statement:Multiply the 8-bit unsigned number in memory location 2200H by the 8-bit unsigned number in memory location 2201H. Store the 8 least significant bits of the result in memory location 2300H and the 8 most significant bits in memory location 2301H.

Sample problem:

(2200) = 1100 (0CH)
(2201) = 0101 (05H)
Multiplicand = 1100 (1210)
Multiplier = 0101 (510)
Result = 12 x 5 = (6010)

Source program

LXI H, 2200 : Initialize the memory pointer
MOV E, M : Get multiplicand
MVI D, 00H : Extend to 16-bits
INX H : Increment memory pointer
MOV A, M : Get multiplier
LXI H, 0000 : Product = 0
MVI B, 08H : Initialize counter with count 8
MULT: DAD H : Product = product x 2
JNC SKIP : Is carry from multiplier 1 ?
DAD D : Yes, Product =Product + Multiplicand
SKIP: DCR B : Is counter = zero
JNZ MULT : no, repeat
SHLD 2300H : Store the result
HLT : End of program


  1. This comment has been removed by the author.

  2. i wrote the prog and it seems not to be giving the right result... got a question for the line:
    "DAD D : Yes, Product =Product + Multiplicand"

    why do we need to add the product and the multiplicand if we already have RAL the product before hand ?

  3. Ramesh Goankar solved problem.
    If multiplying by 1 then Product =Product + Multiplicand and then rotate

    otherwise just rotate left content of HL pair by DAD H command