Page 207 - ARM 64 Bit Assembly Language
P. 207
Integer mathematics 195
217 11011001
× 73 × 01001001
511 0000000011011001
=
73 0000011011001
146 0011011001
15841 0011110111100001
Figure 7.2: In unsigned 8-bit math, 11011001 2 is 217 10 .
If the CPU provides only an unsigned multiply, then a signed multiply can be accomplished
by using the unsigned multiply operation along with a conditional complement. The following
procedure can be used to implement signed multiplication.
1. if the multiplier is negative, take the two’s complement,
2. if the multiplicand is negative, take the two’s complement,
3. perform unsigned multiply, and
4. if the multiplier or multiplicand was negative (but not both), then take two’s complement
of the result.
Example 16. Signed multiplication using unsigned math.
73 ×−39 = 73 × 39 ×−1
00100111
× 01001001
73
00100111
× 39
00100111
657
00100111
219 =
0000101100011111
2847
one’s complement:
× −1
1111010011100000
−2847
two’s complement:
1111010011100001
7.2.4 Multiplication of a variable by a constant
If x or y is a small constant, then we don’t need the loop. We can directly translate the multi-
plication into a sequence of shift and add operations. This will result in much more efficient