Thursday, 27 December 2012

Easy way of 16 bit multiplication in 8051

This is the easiest way I found for 16 bit multiplication. After getting this trick you can also multiply two 32 bits, 64 bits, and so on.

Suppose I have two hex number "ABCD" and "EFGH". Here each alphabet is 4 bit binary number. In 8051 we can multiply 8 bit binary number with using MUL instruction.

here AB= MSB1 (most significant bit of 1st number)
        CD= LSB1
        EF= MSB2
        GH= LSB2

Now,

LSB1*LSB2 = W1,W2
LSB1*MSB2 = W3,W4
MSB1*LSB2 = W5,W6
MSB1*MSB2 = W7,W8

Here Wi(where i is number 1 to 8) is word length. e.g. in F01D W1 is "F0" and W2 is "1D".

This operation can done by MUL instruction. Now the final answer is 32 bit long so we have 4 word of 8 bit length. So assume our final answer is
ABCD*EFGH = WXYZ
.
Here  WXYZ  each alphabet represent a word length of 8 bit binary number.

Now Z = W2
         Y+C1 = W1+W4+W6
Here you find one carry byte. e.g. 110 number 01 is carry byte and value of Y is 10.
         X+C2 = W3+W5+W8+C1
         W = W7+C2
If you find any carry in last summation ignore it.


Ex. You have two number FFFF*EF9D

FF*9D=9C 63
FF*EF=EE 11
FF*9D=9C 63
FF*EF=EE 11

Z= 63
Y=9C+11+63=110 where Y=10 and C1=01
X=EE+9C+11+01=19C where X=9C and C2=01
W= EE+01=EF

Our answer is FFFF*EF9D = EF 9C 10 63

You will find assembly program of this multiplication in onward post in Fab,2014.

Using this technique you can also solve 32 bits or 64 bits multiplication.

Thank you.

4 comments:

View My Stats