Page 31 - ARM 64 Bit Assembly Language
P. 31

14 Chapter 1

                                                        Sign                  Two’s
                                  Binary   Unsigned  Magnitude  Excess-127  Complement
                                 00000000     0          0        −127          0
                                 00000001     1          1        −126          1
                                    .         .          .          .           .
                                    .         .          .          .           .
                                    .         .          .          .           .
                                 01111110    126        126        −1          126
                                 01111111    127        127         0          127
                                 10000000    128        −0          1         −128
                                 10000001    129        −1          2         −127
                                    .         .          .          .           .
                                    .         .          .          .           .
                                    .         .          .          .           .
                                 11111110    254       −126        127         −2
                                 11111111    255       −127        128         −1

                                 Figure 1.4: Four different representations for binary integers.


                  interpreting integers whose value can be both positive and negative. Programmers and hard-
                  ware designers have developed several standard schemes for encoding such numbers The
                  three main methods for storing and interpreting signed integer data are two’s complement,
                  sign-magnitude, and excess-N,Fig. 1.4 shows how the same binary pattern of bits can be in-
                  terpreted as a number in four different ways.


                  1.3.3.1 Sign-magnitude representation

                  The sign-magnitude representation simply reserves the most significant bit to represent the
                  sign of the number, and the remaining bits are used to store the magnitude of the number. This
                  method has the advantage that it is easy for humans to interpret, with a little practice. How-
                  ever, addition and subtraction are slightly complicated. The addition/subtraction logic must
                  compare the sign bits, complement one of the inputs if they are different, implement an end-
                  around carry, and complement the result if there was no carry from the most significant bit.
                  Complements are explained in Section 1.3.3.3. Because of the complexity, most integer CPUs
                  do not directly support addition and subtraction of integers in sign-magnitude form. However,
                  this method is commonly used for mantissa in floating-point numbers, as will be explained
                  in Chapter 8. Another drawback to sign-magnitude is that it has two representations for zero,
                  which can cause problems if the programmer is not careful.


                  1.3.3.2 Excess-(2 n−1  − 1) representation

                  Another method for representing both positive and negative numbers is by using an excess-N
                  representation. With this representation, the number that is stored is N greater than the actual
                  value. This representation is relatively easy for humans to interpret. Addition and subtraction
   26   27   28   29   30   31   32   33   34   35   36