Your algorithm is really over-worked.
Remember, that each bit in the multiplier represents a binary power. So the result of multiplying is the result of adding powers of the multiplicand.
For example, if we multiply 5 and 10:
0101 <-- bits in multiplier
--------
1010 <-- bits in multiplicand, right-aligned with the first set bit in the multiplier
+ 1010 <-- same, right-aligned with the next set bit in the multiplier
--------
110010 <-- sum
|
The algorithm to do this is very simple. (For simplicity, I'll refer to the integers being multiplied as
a and
b.)
result = 0
Loop while a is not zero:
if a's least-significant bit is set:
result += b
a >>= 1
b <<= 1
|
This works, of course, only with an
unsigned value for
a. If you wish to work with signed integers, you will have to do a little extra work to make sure that
a is unsigned for the algorithm. If you think carefully, that should only take an extra test and a couple of sign-inversions before entering the loop.
That leaves a very short, clean assembly routine, where the only conditions you must test are a less-than-zero for the extra test for signed numbers, and a test for zero for the loop.
Good luck!