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

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

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

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

Добавлен: 13.06.2025

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

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

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

In 2’s complement notation, we get:

8010 010100008010 10101111

1 10110000

6510 010000016510 10111110

1 10111111

80 10110000

( 65)8 10111111

?1 01101111

6.3 • Signed Binary Arithmetic

231

(1’s complement)

(2’s complement)

(1’s complement)

(2’s complement)

(Incorrect magnitude 11110) (Erroneous sign bit 0) (Discard carry)

This result shows a positive sum of two negative numbers—clearly incorrect. We can extend the statement we made earlier about permissible magnitudes of sums to include negative as well as positive numbers.

N O T E

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

For an 8-bit signed number in 2’s complement form, the permissible range of sums is 10000000 sum 01111111. In decimal, this range is 128 sum 127.

N O T E

A sum of two positive numbers is always positive. A sum of two negative numbers is always negative. Any 2’s complement addition or subtraction operation that appears to contradict these rules has produced an overflow into the sign bit.

EXAMPLE 6.12

Which of the following sums will produce a sign bit overflow in 8-bit 2’s complement no-

tation? How can you tell?

a.

6710 3310

b.

6710 6310

c. 9610 2210 d. 9610 4210

SOLUTION A sign bit overflow is generated if the sum of two positive numbers appears to produce a negative result or the sum of two negative numbers appears to produce a positive result. In other words, overflow occurs if the operand sign bits are both 1 and the sum sign bit is 0 or vice versa. We know this will happen if an 8-bit sum is outside the range ( 128 sum 127).

a.

6710

01000011

(no overflow;

3310

00100001

sum of positive numbers

10010

01100100

is positive.)


232

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

b.

6710

01000011

(Overflow; sum of

6310

00111111

positive numbers is negative.

13010

10000010

Sum 127; out of range.)

c.

96

01100000

96

10011111

(1’s complement)

1

10100000

(2’s complement)

22

00010110

22

11101001

(1’s complement)

1

11101010

(2’s complement)

96

10100000

22

11101010

118

1 10001010

(Magnitude bits)

(Sign bit)

(Discard carry)

(No overflow; sum of two negative numbers is negative.)

d.

96

01100000

96

10011111

(1’s complement)

1

10100000

(2’s complement)

42

00101010

42

11010101

(1’s complement)

1

11010110

(2’s complement)

96

10100000

42

11010110

138

1 01110110

(Magnitude bits)

(Sign bit)

(Discard carry)

(Overflow; sum of two negative numbers is positive. Sum 128; out of range.)

N O T E

The carry bit generated in 1’s and 2’s complement operations is not the same as an overflow bit. (See Example 6.12, parts c and d.) An overflow is a change in the sign bit, which leads us to believe that the number is opposite in sign from its true value. A carry is the result of an operation carrying beyond the physical limits of an n-bit number. It is similar to the idea of an odometer rolling over from 999999.9 to

1 000000.0. There are not enough places to hold the new number, so it goes back to the beginning and starts over.

6.4 Hexadecimal Arithmetic

(This section may be omitted without loss of continuity.)

The main reason to be familiar with addition and subtraction in the hexadecimal system is that it is useful for calculations related to microcomputer and memory systems.


6.4 • Hexadecimal Arithmetic

233

Microcomputer systems often use binary numbers of 8, 16, 20, or 32 bits. Rather than write out all these bits, we use hex numbers as shorthand. Binary numbers having 8, 16, 20, or 32 bits can be represented by 2, 4, 5, or 8 hex digits, respectively.

Hex Addition

Hex addition is very much like decimal addition, except that we must remember how to deal with the hex digits A to F. A few sums are helpful:

F 1 10

F F 1E

F F 1 1F

The positional multipliers for the hexadecimal system are powers of 16. Thus, the most significant bit of the first sum is the 16’s column. The equivalent sum in decimal is:

1510 110 1610 10H

The second sum is the largest possible sum of two hex digits; the carry to the next position is 1. This shows that the sum of two hex digits will never produce a carry larger than 1. The second sum can be calculated as follows:

FH FH 1510 151030101610 1410

10H EH

1EH

The third sum shows that if there is a carry from a previous sum, the carry to the next bit will still be 1.

N O T E

It is useful to think of any digits larger than 9 as their decimal equivalents. For any digit greater than 1510 (FH), subtract 1610, convert the difference to its hex equivalent, and carry 1 to the next digit position.

EXAMPLE 6.13

Add 6B3H A9CH.

SOLUTION

Hex

Decimal Equivalents

6B3

( 6)

(11) ( 3)

A9C

(10)

( 9) (12)

(16)

(20) (15)

For sums greater than 15, subtract 16 and carry 1 to the next position:

Hex

Decimal Equivalents

(Carry) 11

(

1) (

1)

6B3

(

6)

(11)

( 3)

A9C

(10)

(

9)

(12)

114F

(

1) (

1)

(

4)

(15)

Sum: 6B3H A9CH 114FH.


234

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

Hex Subtraction

There are two ways to subtract hex numbers. The first reverses the addition process in the previous section. The second is a complement form of subtraction.

EXAMPLE 6.14

Subtract 6B3H 49CH.

SOLUTION

Hex

Decimal Equivalent

6B3

(6)

(11) ( 3)

49C

(4)

( 9) (12)

To subtract the least significant digits, we must borrow 10H (1610) from the previous position. This leaves the subtraction looking like this:

Hex

Decimal Equivalent

(Borrow) 1

6A3

(6)

(10)

(16 3)

49C

(4)

(

9)

(12)

217

(2)

(

1)

( 7)

The second subtraction method is a complement method, where, as in 2’s complement subtractions, we add a negative number to subtract a positive number.

Calculate the 15’s complement of a hex number by subtracting it from a number having the same number of digits, all Fs. Calculate the 16’s complement by adding 1 to this number. This is the negated value of the number.

EXAMPLE 6.15

Negate the hex number 15AC by calculating its 16’s complement.

SOLUTION

FFFF

15AC

EA53

(15’s complement)

1

EA54

(16’s complement)

The original value, 15AC, can be restored by calculating the 16’s complement of

EA54. Try it.

EXAMPLE 6.16

Subtract 8B63 55D7 using the complement method.

SOLUTION Find the 16’s complement of 55D7.

FFFF

55D7

AA28

(15’s complement)

1

AA29

(16’s complement)


6.5 • Numeric and Alphanumeric Codes

235

Therefore, 55D7 AA29.

1

8B63

AA29

1

358C

(Discard

carry)

Difference: 8B63 55D7 358C.

SECTION 6.4 REVIEW PROBLEM

6.7Perform the following hexadecimal calculations:

a.A25F 74A2

b.7380 5FFF

6.5Numeric and Alphanumeric Codes

BCD Codes

K E Y T E R M

Binary-coded decimal (BCD). A code that represents each digit of a decimal

number by a binary value.

BCD stands for binary-coded decimal. As the name implies, BCD is a system of writing decimal numbers with binary digits. There is more than one way to do this, as BCD is a code, not a positional number system. That is, the various positions of the bits do not necessarily represent increasing powers of a specified number base.

Two commonly used BCD codes are 8421 code, where the bits for each decimal digit are weighted, and Excess-3 code, where each decimal digit is represented by a binary number that is 3 larger than the true binary value of the digit.

Table 6.2 Decimal Digits and

Their 8421 BCD Equivalents

Decimal BCD

Digit (8421)

00000

10001

20010

30011

40100

50101

60110

70111

81000

91001

8421 Code

K E Y T E R M

8421 code A BCD code that represents each digit of a decimal number by its 4-

bittrue binary value.

The most straightforward BCD code is the 8421 code, also called Natural BCD. Each decimal digit is represented by its 4-bit true binary value. When we talk about BCD code, this is usually what we mean.

This code is called 8421 because these are the positional weights of each digit. Table 6.2 shows the decimal digits and their BCD equivalents.

8421 BCD is not a positional number system, because each decimal digit is encoded separately as a 4-bit number.

EXAMPLE 6.17

Write 498710 in both binary and 8421 BCD.

SOLUTION The binary value of 498710 can be calculated by repeated division by 2:

498710 1 0011 0111 10112