Saturday, September 12, 2009

Multiply two 8-bit numbers(8085)


Statement: Multiply two 8-bit numbers stored in memory locations 2200H and 2201H by repetitive addition and store the result in memory locations 2300H and 2301H

Sample problem:
(2200H) = 03H
(2201H) = B2H
Result = B2H + B2H + B2H = 216H
= 216H
(2300H) = 16H
(2301H) = 02H
Source program
LDA 2200H
MOV E, A
MVI D, 00 : Get the first number in DE register pair
LDA 2201H
MOV C, A : Initialize counter
LX I H, 0000 H : Result = 0
BACK: DAD D : Result = result + first number
DCR C : Decrement count
JNZ BACK : If count 0 repeat
SHLD 2300H : Store result
HLT : Terminate program execution

3 comments:

  1. This seems inefficient...
    When doing longhand arithmetic, you only need, at most, as many additions as you have number positions.

    Since you work off decrementing a counter, it would seem you could have as many as 256 adds, with an average case of 128.

    Further, you only need to "add" if the bit you're multiplying each time is a 1. You always need a shift, but if the multiplier is a zero, you can skip the addition.

    ReplyDelete
  2. This comment has been removed by the author.

    ReplyDelete
  3. MVI C,00
    LDA 2000
    MOV B,A
    LDA 2001
    MOV D,A
    MVI A,00
    UP ADD B
    DCR D
    JNZ UP
    JNZ DN
    INR C
    STA 2000
    MOV A,C
    STA 2201
    HLT

    ReplyDelete