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
RAL
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

5 comments: