Addition and Subtraction: Signed Numbers

Addition of two numbers in 2's complement representation proceeds simply as if the two numbers were unsigned integers. To add two numbers, add their n-bit representations, ignoring the carry-out bit from the most significant bit position. The sum will be the algebraically correct value in the 2's complement notation as long as the answer lies in the range of -2" ~1 through +2" ~1 - 1. Addition of two negative numbers sometimes requires discarding the carry bit, and the sum value is then 2's complemented to obtain the correct result in the usual form. Still, there may be some instances in any addition process when the result may be larger than can be held in the п-bit length being used. This condition is called overflow, which will be discussed in the next section.

Subtraction of two numbers in 2's complement representation can be easily carried out using the rule which tells that to subtract two numbers, A and B, i.e. to perform A - B, form the 2's complement (negation) of B, and then add it to A. Here, В is the subtrahend and A is the minuend. As usual, the result will be algebraically correct if the answer lies in the range of -2"-1 through +2"1 -1 in the 2's complement representation system. When the answers do not fall into the representable range, it is said that arithmetic overflow has occurred, which will be discussed in the next section.

Overflow: Integer Arithmetic

In the 2's complement number system, n bits can represent the values that must lie within the range -2" “1 to +2" ~1 - 1. For example, with 4 bits, the range of numbers that can be represented is -8 through +7. When the result of an arithmetic operation falls outside the representable range, it is said that an arithmetic overflow has occurred. When an overflow occurs, the ALU within the processor must signal this event so that no further attempt would be taken henceforth to use the result.

With и-bit unsigned numbers, overflow is indicated by an output carry bit c„., = 1. For example, adding the (8-bit) unsigned numbers X = 230]O = 11100110 and Y = 4010 = 00101000 using an adder yields Z = X + У = 11100110 + 00101000 = 00001110 with a carry bit = 1 from c„ _ у i.e. from c7. Now the result Z = 00001110 corresponds to 1410, which is 23010 + 40lo (modulo 2s = 256) and is the result of this addition that "wraps around" when the largest number 2" - 1, in this case 11111111 = 25510, is exceeded. On appending c7 (= 1) to Z, we get

c7Z = 100001110 = 27010 = 25610 + 1410, which is the sum in ordinary (modulo infinity) arithmetic. Unsigned arithmetic operations are often viewed as modulo-2" operations only, and overflow is not explicitly detected. This happens when computing memory addresses in a computer system, for instance, when addresses simply wraparound to 0 after the highest address is reached.

However, this does not work when signed numbers are added (or are involved in arithmetic operation). For example, with 4-bit signed numbers, if we go to add numbers +6 (ОНО) and +5 (0101), the output in 4-bit will be 1011, which is the code of-5, an incorrect result. Here, the carry-out signal from the most significant bit (here, it is 4th bit) position is 0. Similarly, if we try to add-5 (1011) and -4 (1100), we get the output in 4-bit as 0111, which is equal to +7, another incorrect result, and in this case, the carry-out signal from the most significant bit (here it is 4th bit) position is 1. Thus, overflow is caused by carry (not always, see Figure 7.2a), but the implication of carry and overflow is not the same. Usual carry can be ignored, and the result is still correct. Unusual carry results in overflow, and the answer of an arithmetic operation then becomes incorrect. Overflow may occur if both summands have the same sign, as shown in Figure 7.2. Clearly, the addition of numbers with different signs cannot cause overflow. This leads to the following conclusions:

  • 1. Overflow can occur only when two numbers are added that have the same sign;
  • 2. The carry-out signal from the most significant bit position is not a sufficient indicator to designate the overflow when adding signed numbers.

Instead, a simple way to detect overflow is to examine the sign of the two summands A and В and the sign of the result. When both the operands A and В have the same sign, and the result is not the same as the sign of A and B, an overflow then occurs. In summary, the prescribed rule is:

Overflow rule: When two numbers are added, and they are either both positive or both negative, then overflow occurs, if and only if the result has the opposite sign.


Representation of overflow with signed numbers.


Representation of overflow with signed numbers.

Alternative approach: Overflow can be identified and detected using a different mechanism, but, of course, keeping intact the fundamental requirements as mentioned above in conclusions (1) and (2). This means that overflow may occur if the two numbers being added are of the same sign. Numbers having different sign when added will not give rise to any overflow, because the result after addition will produce a result which will be always smaller than the larger of the two original numbers. To explain and exhibit the overflow, consider the following examples of 8-bit addition, as shown in Figure 7.3, with 8-bit signed integers in 2's complement form in which the most significant bit in each binary number is the sign bit.

Clearly, the results as obtained in both the cases are incorrect. The 8-bit result as obtained in (a) should have been positive but has a negative sign bit. Similarly, the 8-bit result as obtained in (b) should have been negative but has a positive sign bit. However, if the carryout from the sign bit position is treated as the sign (it is 0 in (a), and it is 1 in (b) as shown by the underline at the top of the figure) of the result, then the 9-bit answer thus obtained in each case is found to be correct. Since the 9-bit result cannot be accommodated in 8-bit storage, it is declared that overflow has occurred.

A simple way to detect overflow in this approach is to examine the carry into the sign bit position (i.e. C„ _, at a„ _ г bit position of the integer, which is 1 in example (a)) and the carry out from the sign bit position (i.e. C„ at an assumed bit position an which is at the left of the sign bit an _, of the integer, which is 0 in example (a)). If these two carries are both 0 or are both 1, then there is no overflow. If these two bits are different (i.e. the carries jointly are either 01 or 10), then an overflow exists. In other words, the overflow occurs if the Boolean expression С„ФС„ _, is 1 (i.e. true).


Similar to the representation of numbers as is carried out by the computer, it must be able to handle non-numeric text information consisting of alphabetic as well as special characters. Set of characters represented by computers can be letters of the alphabet, decimal digits (treated as characters, and not their values), punctuation marks, special characters, and similar other characters. They are represented by specific prescribed codes that are 8-bits (one byte) long. One of the most widely used such standard code is the American Standards Committee on Information Interchange, in short ASCII code, in which each character is represented as a 7-bit code. Another standard code, especially used by IBM and others, is EBCDIC code (Extended Binary Coded Decimal Interchange Code) in which eight bits are used to denote a character.

Arithmetic and Logic Unit (ALU)

Most computer operations, including arithmetic and logical operations on data, are executed in the ALU within the processor at the machine instruction level. The ALU is many times faster than any other resources connected to a computer system. To facilitate ALU to work, all other components of the computer system, such as memory, registers, I/O (input/output) units, control unit, and buses, participate in the working of ALU operation, mainly to supply data into the ALU for it to process, and subsequently to take the results back out, if required. Operands are brought for specific operation and are temporarily stored in the highest-speed storage elements called registers connected with the ALU within the processor. Each register can store one word (32 bits or 64 bits) of data. A block representation of an ALU along with its interconnections with the rest of the processor is depicted in Figure 7.4. The ALU, in fact, is a combinational circuit so that most of its operations, including entire register transfer operations from the source registers through the ALU, and finally into the destination register, can be performed mostly in one clock pulse period. The control unit actually provides the necessary appropriate signals to monitor and control the entire operation of the ALU as well as the movement of data (operands) to and from the ALU.

Compared with arithmetic operations, logic operations are relatively simple to implement using combinational circuitry. They require only independent Boolean operations on individual bit positions of the operands, whereas carry/borrow lateral signals are required in arithmetic operations.

< Prev   CONTENTS   Source   Next >