Page 210 - ARM 64 Bit Assembly Language
P. 210
198 Chapter 7
1110110101
1101 11000000111001
1101000000000
1011000111001
949 110100000000
13 12345 100100111001
11700 11010000000
645 1010111001
520 110100000
125 100011001
117 11010000
8 1001001
110100
10101
1101
1000
Figure 7.4: Longhand division in decimal and binary.
above technique to perform four eight bit multiplies with 16-bit results, then shift and add
the 16-bit results to obtain the final 32-bit result. This technique can be extended to perform
multiplication with any number of bits, even with limited hardware multiplication instruc-
tions.
7.3 Binary division
Binary division can be implemented as a sequence of shift and subtract operations. When per-
forming binary division by hand, it is convenient to perform the operation in a manner very
similar to the way that decimal division is performed. As shown in Fig. 7.4, the operation is
identical, but takes more steps in binary.
7.3.1 Division by a power of two
If the divisor is a power of two, then division can be accomplished with a shift to the right.
Using the same approach as was used in Section 7.2.1, it can be shown that a shift right by n
n
bits is equivalent to division by 2 . However, care must be taken to ensure that an arithmetic
shift is used if the dividend is a signed two’s complement number, and a logical shift is used if
the dividend is unsigned.