Page 32 - ARM 64 Bit Assembly Language
P. 32
Introduction 15
are easily performed using the complement method, which is explained in Section 1.3.3.3.
This representation is just the same as unsigned math, with the addition of a bias which is
usually (2 n−1 − 1). So, zero is represented as zero plus the bias. In n = 12 bits, the bias is
2 12−1 − 1 = 2047 10 , or 011111111111 2 . This method is commonly used to store the exponent
in floating-point numbers, as will be explained in Chapter 8.
1.3.3.3 Complement representation
A very efficient method for dealing with signed numbers involves representing negative num-
bers as the radix complements of their positive counterparts. The complement is the amount
that must be added to something to make it “whole.” For instance, in geometry, two angles are
◦
complementary if they add to 90 . In radix mathematics, the complement of a digit x in base
b is simply b − x − 1. For example, in base ten, the complement of 4 is 10 − 4 − 1 = 5.
In complement representation, the most significant digit of a number is reserved to indicate
whether or not the number is negative. If the first digit is less than b (where b is the radix),
2
b
then the number is positive. If the first digit is greater than or equal to , then the number is
2
negative. The first digit is not part of the magnitude of the number, but only indicates the sign
of the number. For example, numbers in ten’s complement notation are positive if the first
digit is less than 5, and negative if the first digit is greater than 4. This works especially well
in binary, since the number is considered positive if the first bit is zero and negative if the first
bit is one. The magnitude of a negative number can be obtained by taking the radix comple-
ment. Because of the nice properties of the complement representation, it is the most common
method for representing signed numbers in digital computers.
Finding the complement
The radix complement of an n digit number y in radix (base) b is defined as
n
C(y b ) = b − y b . (1.1)
4
For example, the ten’s complement of the four digit number 8734 10 is 10 − 8734 = 1266.
In this example, we directly applied the definition of the radix complement from Eq. (1.1).
That is easy in base ten, but not so easy in an arbitrary base, because it involves performing
a subtraction. However, there is a very simple method for calculating the complement which
does not require subtraction. This method involves finding the diminished radix complement,
n
which is (b − 1) − y by substituting each digit with its complement from a complement
table. The radix complement is found by adding one to the diminished radix complement.
Fig. 1.5 shows the complement tables for base ten and base two. Examples 4 and 5 show how