Hi folks,
> At 23:56 -0600 3/7/11, Jules wrote:
>Yes, that seems to be the 'famous' one that gets mentioned everywhere.
> It
>seems it was of the shift-add variety. Anyone recall if it would work
> with
>signed integers? (I'm just trying to work out how the math works for
> signed multiplies at the moment)
Mark Tapley wrote:
MUL is unsigned arithmetic only.
Actually this isn't *quite* true. An n x n bit unsigned multiplier producing a 2n bit
result also produces the correct signed results for the bottom n bits. Thus the 6809's
MUL instruction produces the correct answer to A = -20 * B = -3 as it will store -60 in
the B register.
The reason is because with the n x n bit multiplier multiplying a * b, where b is -ve
=> a* ((2^n) - (-b) ) = a*(2^n) + a*b = a*b since a*(2^n) doesn't contribute to to
the lower n bits.
Consider a 2-bit multiplier dealing with the -ve * -ve and -ve * +ve cases:
01 * 10 = 0010, = -2 correct.
01 * 11 = 0011, = -1 correct.
10 * 10 = 0100, = 0 correct.
10 * 11 = 0110, = 2 (or -2) correct.
11 * 11 = 1001, = 1 correct.
-cheers from julz