Page 199 - ARM 64 Bit Assembly Language
P. 199

CHAPTER 7

                     Integer mathematics




                     There are some differences between the way calculations are performed in a computer versus
                     the way most of us were taught as children. The first difference is that calculations are per-
                     formed in binary instead of base ten. Another difference is that the computer is limited to a
                     fixed number of binary digits, which raises the possibility of having a result that is too large to
                     fit in the number of bits available. This occurrence is referred to as overflow. The third differ-
                     ence is that subtraction is performed using complement addition.
                     Addition in base b is very similar to base ten addition, except that the result of each column is
                     limited to b − 1. For example, binary addition works exactly the same as decimal addition, ex-
                     cept that the result of each column is limited to 0 or 1. The following figure shows an addition
                     in base ten and the equivalent addition in base two.


                                                1                          11
                                                75               01001011
                                                        =
                                            +   19           +   00010011
                                                94               01011110


                     The carry from one column to the next is shown as a small number above the column that it
                     is being carried into. Note that carries from one column to the next are done the same way
                     in either base. The only difference is that there are more columns in the base two addition
                     because it takes more binary digits to represent a number than it does in decimal.


                     7.1 Subtraction by addition


                     Finding the complement was explained in Section 1.3.3.3. Subtraction can be computed by
                     adding the radix complement of the subtrahend to the menuend. Example 11 shows a com-
                     plement subtraction with positive results. When the menuend is less than the subtrahend, the
                     result will be negative. In the complement method, we deal with this possibility by adding a
                     sign digit at the beginning of the numbers. Example 12 shows complement subtraction with
                     negative results. Example 13 shows several more signed addition and subtraction operations
                     in base ten and binary.


                     ARM 64-Bit Assembly Language
                     https://doi.org/10.1016/B978-0-12-819221-4.00014-6  187
                     Copyright © 2020 Elsevier Inc. All rights reserved.
   194   195   196   197   198   199   200   201   202   203   204