16-bit x 16-bit = 16-bit 16-bit x 16-bit = 16-bit Operation

This operation is valid for both unsigned and signed numbers, even though only the unsigned multiply instruction (MUL) is needed. This is illustrated in the figure below. A mathematical explanation is given:

When A and B are positive numbers, or at least one of them is zero, the algorithm is clearly correct, provided that the product C = A • B is less than 216 if the product is to be used as an unsigned number, or less than 215 if the product is to be used as a signed number.

When both factors are negative, the two’s complement notation is used; A = 216 - |A| and B = 216 - |B|:

C=A*B=(216|A|)*(216|B|)=|A*B|+232216*(|A|+|B|)

Here we are only concerned with the 16 LSBs; the last part of this sum will be discarded and we will get the (correct) result C = |A • B|.

Figure 1. 16-bit Multiplication, 16-bit Result

When one factor is negative and one factor is positive, for example, A is negative and B is positive:

C=A*B=(216|A|)*|B|=(216*|B|)|A*B|=(216|A*B|)+216*(|B|1)

The MSBs will be discarded and the correct two’s complement notation result will be C = 216 - |A • B|.

The product must be in the range 0 ≤ C ≤ 216 - 1 if unsigned numbers are used, and in the range -215 ≤ C ≤ 215 - 1 if signed numbers are used.

When doing integer multiplication in C language, this is how it is done. The algorithm can be expanded to do 32-bit multiplication with 32-bit result.