Adam A
Adam A

Reputation: 177

Assembler i8080 Multiplying two 16bits numbers

I have to prepare program for i8080 processor. My program have to multiplying two 16b numbers. But I don't know how to check multiplier bit by bit.

e.g 1111 * 1011 = first bit of 1011 is 1 so I add 1111 second bit is 1 so I add 11110 third bit is 0 so I don't add 111100 forth is 1 so I add 1111000

result is 1111+11110+1111000=10100101

And my only problem is how to chceck bits of multiplier?

Thanks for help

Upvotes: 0

Views: 513

Answers (1)

user555045
user555045

Reputation: 64904

Probably the easiest way is to shift right and then check the carry, otherwise you have to keep changing which bit you test and that's hard, especially with a register pair. The shifting is however a bit annoying on 8080 since only A can be rotated. Let's say the multiplier is in BC (and the multiplicand in HL and the result in DE so you can shift the multiplicand with DAD H and it takes some XCHG to do the add-to-result but it happens less often)

mov a, b
ora a    ; reset carry
rar
mov b, a
mov a, c
rar
mov c, a
jnc skipadd

Using ora a ensures that the multiplier simply goes to zero, this allows an exit test such as:

mov a, b
ora c
jnz looptop

If you unroll by 16 you can just fill BC from the left with the carry from the left shift of the multiplicand, it won't make any difference.

Upvotes: 1

Related Questions