Page 223 - ARM 64 Bit Assembly Language
P. 223
Integer mathematics 211
12 add x0, x0, x3
13 lsl x3, x3, #11 // shift 11 + 2 = 13
14 add x0, x0, x3
15 lsl x3, x3, #11 // shift 11 + 13 = 24
16 add x0, x0, x3
17
18 asr x1, x0, #35
19 sub x0, x1, x0, asr #63 // subtract sign of dividend
7.3.4 Dividing large numbers
Section 7.2.5 showed how large numbers can be multiplied by breaking them into smaller
numbers and using a series of multiplication operations. There is no similar method for syn-
thesizing a large division operation with an arbitrary number of digits in the dividend and
divisor. However, there is a method for dividing a large dividend by a divisor given that the
division operation can operate on numbers with at least the same number of digits as in the
divisor.
Suppose we wish to perform division of an arbitrarily large dividend by a one digit divisor
using a basic division operation that can divide a two digit dividend by a one digit divisor. The
operation can be performed in multiple steps as follows:
1. Divide the most significant digit of the dividend by the divisor. The result is the most sig-
nificant digit of the quotient.
2. Prepend the remainder from the previous division step to the next digit of the dividend,
forming a two-digit number, and divide that by the divisor. This produces the next digit of
the result.
3. Repeat from step 2 until all digits of the dividend have been processed.
4. Take the final remainder as the modulus.
The following example shows how to divide 6189 by 7 using only 2-digits at a time:
0 8 8 4
7 6 7 61 7 58 7 29
56 56 28
5 2 1
x = 6189 ÷ 7 = 0884 remainder 1
This method can be applied in any base and with any number of digits. The only restriction
is that the basic division operation must be capable of dividing a 2n digit dividend by an n