Вы находитесь на странице: 1из 8

525.412 Computer Architecture

Assignment 7 Solutions

6.13 Repeat Exercise 6.8 but perform multiplications

a. using Booth recoding.

b. using bit-pair encoding.

 a. 101 101 b. 011 110 c. 111 100 d. 101 010 110 100 101 011 011 101 110 111 e. 011 100 f. 110 101 g. 110 001 h. 101 101 100 010 110 010 011 011 110 111 Solution

a. In the solutions below the multiplier has been encoded using Booth enc oding in which each bit has been replaced with a symbol based on the original bit as well as its neighbor to the right:

Bit and its right-hand neighbor Booth encoding

 00 0 01 1 10 1 11 0

Multiplying by 1 and adding is the same as adding in the two’s complement of the multiplic and.

 a. 101 101 × 0 11 100 000 001 001 100 111 101 101 000 100 11 000 011 100 100 − 19 × − 12 = 228 e. 011 100 × 100 1 10 11 111 001 000 00 001 110 0 10 010 0 10 010 111 000

28 × − 30 = 840

 b. 011 110 × 11 1 10 1 c. 111 100 × 100 11 1 11 111 100 010 00 000 000 100 00 001 111 0 11 111 111 00 11 100 010 00 000 010 0 00 111 10 11 110 0 10 001 0 11 110 001 100 10 110 001 010 − 4 × 29 = − 116 30 × − 21 = − 630 f. 110 101 × 0 10 1 10 g. 110 001 × 10 1 10 1 0 000 010 110 00 000 001 111 1 111 010 1 11 111 000 1 0 010 11 00 001 111 0 010 011 010 11 000 1 − 11 × − 14 = 154 11 001 101 011 − 15 × 27 = − 405 1
 d. 101 010 × 0 11 00 1 0 000 010 110 1 101 010 0 101 10 0 011 000 110 − 22 × − 9 = 198 h. 101 101 × 0 11 00 1 0 000 010 011 1 101 101 0 100 11 0 010 101 011

19 × − 9 = 171

b. In the solutions below the multiplier has been encoded using bit-pair encoding (Booth radix-4 encoding) in which each pair of bits has been replaced with a symbol ba sed on the original pair of bits as well as its neighbor to the right: Bit and its
Bit and its
right-hand neighbor Bit-pair encoding right-hand neighbor Bit-pair encoding
000
00
100
10
001
01
101
0
1
010
01
110
0
1
011
10
111
00

Multiplying by 1 and adding is the same as adding in the two’s complement of the multiplic and.

 a. 101 101 × 0 10 100 1 110 110 100 0 100 11 0 011 100 100 − 19 × − 12 = 228 e. 011 100 × 100 1 10 11 111 001 000 00 001 110 0 10 010 0 10 010 111 000

28 × − 30 = 840

 b. 011 110 × 0 10 10 1 c. 111 100 × 100 101 d. 101 010 × 0 11 00 1 11 111 100 010 11 111 111 100 0 010 110 11 110 001 0 00 000 010 0 1 101 010 11 000 10 11 110 0 0 101 10 10 110 001 010 11 110 001 100 0 011 000 110 30 × − 21 = − 630 − 4 × 29 = − 116 − 22 × − 9 = 198 f. 110 101 × 0 10 1 10 g. 110 001 × 100 10 1 h. 101 101 × 0 11 00 1 0 000 010 110 0 000 001 111 0 000 010 011 1 111 010 1 0 000 111 1 1 101 101 0 010 11 1 000 1 0 100 11 0 010 011 010 11 001 101 011 − 15 × 27 = − 405 0 010 101 011 − 11 × − 14 = 154 − 19 × − 9 = 171 2

6.28

Convert the following decimal numbers to IEEE single-precision ﬂoating-point numbers. Re- port the results as hexadecimal values. You need not e4xtend the calculation of the signiﬁcand value beyond its most signiﬁcant 8 bits.

 b. 6.5125 e. 56,000,135

f. 23 . 23

g. 6 . 02 × 10 23

 Solution 6.28 b.

6 . 5125 10 = 1 . 628 16 × 2 2

1 . A0CCCCD 16 × 2 2

= 1 . 1010 0000 1100 1100 1100 1100 1101

The number is positive, so the sign bit s = 0.

The exponent, expressed in excess-127 notation, is e = 127 10 + 2 10 = 128 10 + 1 = 1000 0001 2 .

The ﬁrst 23 bits of the fraction, excluding the initial 1-bit, are 1010 0000 1100 1100 1100 110 2 .

Piecing this together as s e f gives

sign

0

signiﬁcand

1000 0001 1010 0000 1100 1100 1100 110

exponent

= 0100 0000 1101 0000 0110 0110 0110 0110

= 40D06666 16

If only the most signiﬁcant eight bits of the signiﬁcand are included (a ssuming the bit to the left of the binary point is one of them,) then the result can be shorte ned to 40D00000 16

3

6.28

e.

56 , 000 , 135 10 = 1 . 6689 × 2 25

= 1.AB3F438 16 × 2 25

= 1 . 1010 1011 0011 1111 0100 0011 1000 2 × 2 25

1 . 1010 1011 0011 1111 0100 010 2 × 2 25 .

Here we round oﬀ to 23 bits after the binary point. If the truncate d digits are exactly 1 with inﬁnitely many trailing zeroes, round in the direction which yields a 0 in the least signiﬁcant remaining bit.

The sign bit s = 0 since this number is positive.

The exponent e = 127 + 25 = 128 + 24 = 1001 1000 2 .

Piecing these together gives

0 1001 1000 1010 1011 0011 1111 0100 010 = 0100 1100 0101 0101 10 01 1111 1010 0010

= 4C55 9FA2 16

4C56 0000 16 .

 6.28 f. − 23 . 23 = − 1 . 451875 × 2 4 ≈ − 1.73AE148 16 × 2 4 = 1 . 0111 0011 1010 1110 0001 0100 1000 16 × 2 4 . The sign bit s = 1 since this number is negative. The exponent e = 127 + 4 = 128 + 3 = 1000 0011 2 . Piecing these together gives 1 1000 0011 0111 0011 1010 1110 0001 010 = 1100 0001 1011 1001 1101 0111 0000 1010 = C1B9 D70A 16 ≈ C1BA 0000 16 . 6.28 g. Consider ﬁrst the exponent part of 6 . 02 × 10 23 .
 6 . 02 × 10 23 = 1 . 99185 × 2 78 ≈ 1 . FDE9F11 × 2 78

= 1 . 1111 1101 1110 1001 1111 0001 0001 2 × 2 78

1 . 1111 1101 1110 1001 1111 001 2 × 2 78 .

The sign bit s = 0 since this number is positive.

The exponent e = 127 + 78 = 128 + 77 = 1100 1101 2 .

Piecing these together gives

0 1100 1101 1111 1101 1110 1001 1111 001 = 0110 0110 1111 1110 11 11 0100 1111 1001

= 66FE F4F9 16

66FF 0000 16 .

4

6.29

Convert the following IEEE single-precision ﬂoating-point numbers to their decimal values. Report the answers to three signiﬁcant ﬁgures. Use scientiﬁc notation if needed to maintain precision:

a. 0x21E0 0000

b. 0x8906 0000

c. 0x4B90 0000

d. 0xf1A6 0000

Solution

6.29 a.

0x21E0 0000 = 0010 0001 1110 0000 0000 0000 0000 0000

= 0 0100 0011 1100 0000 0000 0000 0000 000

The sign bit is 0, meaning the number is positive.

The exponent eˆ = 0100 0011 = e + 0111 111. Solving this yields e = 60.

The signiﬁcand is

1 . 1100 0000 0000 0000 0000 000 2 = 1 .C000 00 16

= 1 . 75

The ﬂoating point number, therefore, is 1 . 75 × 2 60 = 1 . 518 × 10 18 1 . 52 × 10 18 .

6.29 b.

0x8906 0000 = 1000 1001 0000 0110 0000 0000 0000 0000

= 1 0001 0010 0000 1100 0000 0000 0000 000

The sign bit is 1, meaning the number is negative.

The exponent eˆ = 0001 0010 = e + 0111 111. Solving this yields e = 109.

The signiﬁcand is

1 . 0000 1100 0000 0000 0000 000 2 = 1 .0C00 00 16

= 1 . 047

The ﬂoating point number, therefore, is 1 . 047 × 2 109 = 1 . 613 × 10 33 ≈ − 1 . 61 × 10 33 .

5

6.29

c.

0x4B90 0000 = 0100 1011 1001 0000 0000 0000 0000 0000

= 0 1001 0111 0010 0000 0000 0000 0000 000

The sign bit is 0, meaning the number is positive.

The exponent eˆ = 1001 0111 = e + 0111 111. Solving this yields e = 24.

The signiﬁcand is

1 . 0010 0000 0000 0000 0000 000 2 = 1 .2000 00 16

= 1 . 047

The ﬂoating point number, therefore, is 1 . 125 × 2 24 = 1 . 887 × 10 7 1 . 89 × 10 7 .

6.29 d.

0xF1A6 0000 = 1111 0001 1010 0110 0000 0000 0000 0000

= 1 1110 0011 0100 1100 0000 0000 0000 000

The sign bit is 1, meaning the number is negative.

The exponent eˆ = 1110 0011 = e + 0111 111. Solving this yields e = 100.

The signiﬁcand is

1 . 0100 1100 0000 0000 0000 000 2 = 1 .4C00 00 16

= 1 . 297

The ﬂoating point number, therefore, is 1 . 297 × 2 100 = 1 . 644 × 10 30 ≈ − 1 . 64 × 10 30 .

6

6.31

In ﬂoating-point addition, can you give an example where a + b = a for some nonzero value of b ?

Solution

Let a = 1 × 2 24 and let b = 1. In the IEEE single-precision ﬂoating-point format there are only 24 bits of precision available, including the implied 1-bit in a norma lized number. When we add them in ﬂoating-point hardware, they must ﬁrst be aligned, which means the lesser number needs to be shifted to the right until its exponent ma tches that of the larger number. As a result we do not get the same results as when we add them using inﬁnitely precise real numbers, as shown in the table below.

Real Numbers with Unlimited Precision

Aligned Floating-point Numbers with 24 Bits Precision

 1 × 2 24 1 . 0000 0000 0000 0000 0000 000 × 2 24 + 1 + 0 . 0000 0000 0000 0000 0000 000 × 2 24

1 . 0000 0000 0000 0000 0000 0001 × 2 24

7

1 . 0000 0000 0000 0000 0000 000 × 2 24

6.32

Show that for ﬂoating-point addition, the associative law, (a + b ) + c = a + (b + c ), does not hold.

Solution

It is suﬃcient to show that the associative law fails in even one instanc e. The law fails, gener- ally, because there is a limited number of bits in the representation. When doing ﬂoating-point addition or subtraction, the arguments must be aligned, that is, they must have the same ex- ponent. One of the numbers—usually the lesser—is scaled so that it has the same exponent as the other. This means using a denormalized version of the number , that is, it requires that there be leading zeroes before the addition can be performed.

Consider the addition problem (a + b ) + c = (1 × 2 24 + 1) + 1. The 1 inside the parentheses must be scaled by shifting it to the right 24 places, making its exponent 24 also. However, with only 24 bits in the number, the result is zero:

Real Numbers with Unlimited Precision

Aligned Floating-point Numbers with 24 Bits Precision

 1 × 2 24 1 . 0000 0000 0000 0000 0000 000 × 2 24 0 . 0000 0000 0000 0000 0000 000 × 2 24 + 1 + 1 . 0000 0000 0000 0000 0000 0001 × 2 24 1 . 0000 0000 0000 0000 0000 000 × 2 24 1 . 0000 0000 0000 0000 0000 0001 × 2 24 1 . 0000 0000 0000 0000 0000 000 × 2 24 0 . 0000 0000 0000 0000 0000 000 × 2 24 + 1 +

1 . 0000 0000 0000 0000 0000 0010 × 2 24

1 . 0000 0000 0000 0000 0000 000 × 2 24

When we instead perform the addition problem a + (b + c ) = 1 × 2 24 + (1 + 1) we get quite a diﬀerent result:

Real Numbers with Unlimited Precision

Aligned Floating-point Numbers with 24 Bits Precision

 1 1 . 0000 0000 0000 0000 0000 000 × 2 0 1 . 0000 0000 0000 0000 0000 000 × 2 0 + 1 + 2 1 . 0000 0000 0000 0000 0000 000 × 2 1 2 0 . 0000 0000 0000 0000 0000 001 × 2 24 1 . 0000 0000 0000 0000 0000 000 × 2 24 + 1 × 2 24 +

1 . 0000 0000 0000 0000 0000 0010 × 2 24

1 . 0000 0000 0000 0000 0000 001 × 2 24

We get the correct answer the second way but not the ﬁrst way. Not only does this show that addition of ﬂoating point numbers does not obey the associative law, it also suggests errors can be reduced by doing addition and subtraction of the smallest numbers ﬁrst.

8