Page 200 - ARM 64 Bit Assembly Language
P. 200

188 Chapter 7

                  Example 11. Ten’s complement subtraction.


                    Suppose we wish to calculate 384 10 − 56 10 using the complements method. We first pad
                    the numbers, so that they have leading zeros (the sign digit), and are the same length,
                    resulting in 0384 10 − 0056 10 From Chapter 1, the ten’s complement of 0056 10 is 9944 10 .
                    Adding them together gives us 0384 10 + 9944 10 = 10328 10 . Since we are using four
                    digits for the operation, we expect a four digit result. After discarding the leading ‘1’,
                    we have 328, which is the correct result. Note that if the carry into the most significant
                    column does not match the final carry out, then overflow has occurred. Both methods of
                    subtraction are shown below:

                                                7  14            1  1
                                              3   8   4          0384
                                                          =
                                            −   56             +9944
                                              328                10328


                  Example 12. Ten’s complement subtraction with a negative result.
                  Suppose we want to calculate 284 − 481. First, we pad with leading zeros (sign digits), to get
                  0284 − 0481. Then, we take the tens complement of 0481, which is 9519. Adding the ten’s
                  complement of the subtrahend to the menuend gives 0284 + 9519 = 9803. The First digit is
                  greater than 4, indicating that the result is negative. Therefore, we take the ten’s complement
                  of the result to get −0197.
                  Example 13. Signed addition and subtraction in decimal and binary.


                                             023             00010111

                                         +   015     =   +   00001111
                                             038             00100110



                                     023             023             00010111
                                 −   015     =   +   985     =   +   11110001
                                     008             1008            100001000



                                  −   23            977             11101001
                                  +   15    =   +   015     =   +   00001111
                                    −   8           992             11111000
   195   196   197   198   199   200   201   202   203   204   205