Файл: Digital design with CPLD applications and VHDL (R. Dueck, 2000).pdf

ВУЗ: Не указан

Категория: Не указан

Дисциплина: Не указана

Добавлен: 13.06.2025

Просмотров: 8160

Скачиваний: 6

ВНИМАНИЕ! Если данный файл нарушает Ваши авторские права, то обязательно сообщите нам.

6.3 • Signed Binary Arithmetic

227

6.3

Signed Binary Arithmetic

K E Y T E R M

Signed binary arithmetic Arithmetic operations performed using signed binary

numbers.

Signed Addition

Signed addition is done in the same way as unsigned addition. The only difference is that

both operands must have the same number of magnitude bits, and each has a sign bit.

EXAMPLE 6.8

Add 3010 and 7510. Write the operands and the sum as 8-bit signed binary numbers.

SOLUTION

30

00011110

75

01001011

105

01101001

(Magnitude bits)

(Sign bit)

Subtraction

The real advantage of complement notation becomes evident when we subtract signed binary numbers. In complement notation, we add a negative number instead of subtracting a positive number. We thus have only one kind of operation—addition—and can use the same circuitry for both addition and subtraction.

This idea does not work for true-magnitude numbers. In the complement forms, the magnitude bits change depending on the sign of the number. In true-magnitude form, the magnitude bits are the same regardless of the sign of the number.

Let us subtract 8010 6510 1510 using 1’s complement and 2’s complement addition. We will also show that the method of adding a negative number to perform subtraction is not valid for true-magnitude signed numbers.

1’s Complement Method

K E Y T E R M

End-around carry An operation in 1’s complement subtraction where the carry

bit resulting from a sum of two 1’s complement numbers is added to that sum.

Add the 1’s complement values of 80 and 65. If the sum results in a carry beyond the sign bit, perform an end-around carry. That is, add the carry to the sum.

8010

01010000

6510

01000001

6510

10111110

(1’s complement)

80

01010000

65

10111110

1

00001110

→ 1 (End-around carry)

15

00001111


228

C H A P T E R 6 • Digital Arithmetic and Arithmetic Circuits

2’s Complement Method

Add the 2’s complement values of 80 and 65. If the sum results in a carry beyond the sign bit, discard it.

8010

01010000

6510

01000001

6510

10111110

(1’s complement)

1

10111111

(2’s complement)

80

01010000

65

10111111

15

1 00001111

(Discard carry)

True-Magnitude Method

8010 01010000

6510 010000016510 11000001

80

01010000

65

11000001

?

1

00010001

If we perform an end-around carry, the result is 00010010 1810. If we discard the carry, the result is 00010001 1710. Neither answer is correct. Thus, adding a negative true-magnitude number is not equivalent to subtraction.

Negative Sum or Difference

All examples to this point have given positive-valued results. When a 2’s complement addition or subtraction yields a negative sum or difference, we can’t just read the magnitude from the result, since a 2’s complement operation modifies the bits of a negative number. We must calculate the 2’s complement of the sum or difference, which will give us the positive number that has the same magnitude. That is, ( x) x.

EXAMPLE 6.9

Subtract 6510 8010 in 2’s complement form.

SOLUTION

6510

01000001

8010

01010000

8010

10101111

(1’s complement)

1

10110000

(2’s complement)

65 0100000180 10110000 11110001

Take the 2’s complement of the difference to find the positive number with the same magnitude.

11110001

( 15)←

00001110

(1’s complement)

1

00001111

(2’s complement)

( 15)


6.3 • Signed Binary Arithmetic

229

00001111 1510. We generated this number by complementing 11110001. Thus, 11110001 1510.

Table 6.1

4-bit 2’s

Complement Numbers

Decimal

2’s Complement

7

0111

6

0110

5

0101

4

0100

3

0011

2

0010

1

0001

0

0000

1

1111

2

1110

3

1101

4

1100

5

1011

6

1010

7

1001

8

1000

Range of Signed Numbers

The largest positive number in 2’s complement notation is a 0 followed by n 1s for a number with n magnitude bits. For instance, the largest positive 4-bit number is 0111 710. The negative number with the largest magnitude is not the 2’s complement of the largest positive number. We can find the largest negative number by extension of a sequence of 2’s complement numbers.

The 2’s complement form of 710 is 1000 1 1001. The positive and negative numbers with the next largest magnitudes are 0110 ( 610) and 1010 ( 610). If we continue this process, we will get the list of numbers in Table 6.1.

We have generated the 4-bit negative numbers from 110 (1111) through 710 (1001) by writing the 2’s complement forms of the positive numbers 1 through 7. Notice that these numbers count down in binary sequence. The next 4-bit number in the sequence (which is the only binary number we have left) is 1000. By extension, 1000 810. This number is its own 2’s complement. (Try it.) It exemplifies a general rule for the n-bit negative number with the largest magnitude.

N O T E

A 2’s complement number consisting of a 1 followed by n 0s is equal to 2n. Therefore, the range of a signed number, x, is 2n x 2n 1 for a number with n magnitude bits.

EXAMPLE 6.10

Write the largest positive and negative numbers for an 8-bit signed number in decimal and

2’s complement notation.

SOLUTION

01111111 127 (7 magnitude bits: 27 1 127)

10000000 128 (1 followed by seven 0s: 27 128)

EXAMPLE 6.11

Write 1610

a. As an 8-bit 2’s complement number

b. As a 5-bit 2’s complement number

(8-bit numbers are more common than 5-bit numbers in digital systems, but it is use-

ful to see how we must write the same number differently with different numbers of bits.)

SOLUTION

a. An 8-bit number has 7 magnitude bits and 1 sign bit.

16 00010000

16 11101111

(1’s complement)

1

11110000

(2’s complement)

b.A 5-bit number has 4 magnitude bits and 1 sign bit. Four magnitude bits are not enough to represent 16. However, a 1 followed by n 0s is equal to 2n. For a 1 and four 0s, 2n

24 16. Thus, 10000 1610.


230

C H A P T E R 6 • Digital Arithmetic and Arithmetic Circuits

The last five bits of the binary equivalent of 16 are the same in both the 5-bit and 8-bit numbers.

N O T E

The 8-bit number is padded with leading 1s. This same general pattern applies for any negative number with a power-of-2 magnitude. ( 2n n 0s preceded by all 1s within the defined number size.)

SECTION 6.3 REVIEW PROBLEM

6.5Write 32 as an 8-bit 2’s complement number.

6.6Write 32 as a 6-bit 2’s complement number.

Sign Bit Overflow

K E Y T E R M

Overflow An erroneous carry into the sign bit of a signed binary number that results from a sum or difference larger than can be represented by the number of magnitude bits.

Signed addition of positive numbers is performed in the same way as unsigned addition. The only problem occurs when the number of bits in the sum of two numbers exceeds the number of magnitude bits and overflows into the sign bit. This causes the number to appear to be negative when it is not. For example, the sum 75 96 171 causes an overflow in 8-bit signed addition. In unsigned addition the binary equivalent is:

10010111100000 10101011

In signed addition, the sum is the same, but has a different meaning.

0

1001011

0

1100000

1

0101011

(Sign bit)

(Magnitude bits)

The sign bit is 1, indicating a negative number, which cannot be true, since the sum of two positive numbers is always positive.

N O T E

A sum of positive signed binary numbers must not exceed 2n 1 for numbers having n magnitude bits. Otherwise, there will be an overflow into the sign bit.

Overflow in Negative Sums

Overflow can also occur with large negative numbers. For example, the addition of 8010 and 6510 should produce the result:

8010 ( 6510) 14510