03~solutions_for_chapter_3_exercises

更新时间:2023-05-15 17:00:01 阅读量: 实用文档 文档下载

说明:文章内容仅供预览,部分内容可能不全。下载后的文档,内容与下面显示的完全一致。下载之前请确认下面内容是否您想要的,是否完整无缺。

Solutions for Chapter 3 Exercises1

Solutions for Chapter 3 Exercises

3.10000 0000 0000 0000 0001 0000 0000 0000two3.21111 1111 1111 1111 1111 1000 0000 0001two3.31111 1111 1110 0001 0111 1011 1000 0000two3.4–250ten3.5–17ten

3.62147483631ten3.7

addu $t2, $zero, $t3 # copy $t3 into $t2

bgez $t3, next # if $t3 >= 0 then done

sub $t2, $zero, $t3 # negate $t3 and place into $t2Next:

3.9The problem is that A_lower will be sign-extended and then added to $t0.

The solution is to adjust A_upper by adding 1 to it if the most significant bit ofA_lower is a 1. As an example, consider 6-bit two’s complement and the address23 = 010111. If we split it up, we notice that A_lower is 111 and will be sign-extended to 111111 = –1 during the arithmetic calculation. A_upper_adjusted= 011000 = 24 (we added 1 to 010 and the lower bits are all 0s). The calculation isthen 24 + –1 = 23.

3.10Either the instruction sequence

addu $t2, $t3, $t4sltu $t2, $t2, $t4

or

addu $t2, $t3, $t4sltu $t2, $t2, $t3

works.

3.12To detect whether $s0 < $s1, it’s tempting to subtract them and look at the

sign of the result. This idea is problematic, because if the subtraction results in anoverflow, an exception would occur! To overcome this, there are two possiblemethods: You can subtract them as unsigned numbers (which never produces anexception) and then check to see whether overflow would have occurred. Thismethod is acceptable, but it is lengthy and does more work than necessary. Analternative would be to check signs. Overflow can occur if $s0 and (–$s1) share

2Solutions for Chapter 3 Exercises

the same sign; that is, if $s0 and $s1 differ in sign. But in that case, we don’t needto subtract them since the negative one is obviously the smaller! The solution inpseudocode would be

if ($s0<0) and ($s1>0) then

$t0:=1

else if ($s0>0) and ($s1<0) then

$t0:=0

else

$t1:=$s0–$s1 if ($t1<0) then $t0:=1else

$t0:=0

3.13Here is the equation:

Sum = (a b CarryIn) + (a b CarryIn)

CarryIn

a

Sum

Solutions for Chapter 3 Exercises3

3.23

One example of 6-bit operands that run faster when Booth’s algorithm looks at 3bits at a time is 21ten × 27ten = 567ten.Two-bit Booth’s algorithm:

010101 × 011011 – 010101000000+ 010101– 010101000000+ 010101= 21ten= 27ten

10 string (always start with padding 0 to right of LSB)11 string, middle of a string of 1s, no operation01 string, add multiplicand10 string, subtract multiplicand11 string01 string

11111101011two’s complement with sign extension as needed0000000000zero with sign extension shown

000010101positive multiplicand with sign extension111010110000000+ 01010101000110111 = 567ten

4Solutions for Chapter 3 Exercises

Don’t worry about the carry out of the MSB here; with additional sign extensionfor the addends, the sum would correctly have an extended positive sign. Now,using the 3-bit Booth’s algorithm:

010101 × 011011 – 010101 – 010101+ 0101010= 21ten= 27ten

110 string (always start with padding 0 to right of LSB)101 string, subtract the multiplicand

011 string, add twice the multiplicand (i.e., shifted left 1 place)

11111101011two’s complement of multiplicand with sign extension111101011two’s complement of multiplicand with sign extension+ 0101010 01000110111

= 567 ten

Using the 3-bit version gives only 3 addends to sum to get the product versus 6addends using the 2-bit algorithm.

Booth’s algorithm can be extended to look at any number of bits b at a time. Theamounts to add or subtract include all multiples of the multiplicand from 0 to2(b–1). Thus, for b > 3 this means adding or subtracting values that are other thanpowers of 2 multiples of the multiplicand. These values do not have a trivial“shift left by the power of 2 number of bit positions” method of computation.3.25

l.d $f0, –8($gp)l.d $f2, –16($gp)l.d $f4, –24($gp)

fmadd $f0, $f0, $f2, $f4s.d $f0, –8($gp)

3.26a.

x = 0100 0000 0110 0000 0000 0000 0010 0001y = 0100 0000 1010 0000 0000 0000 0000 0000Exponents

100 0000 0+100 0000 11000 0000 1–011 1111 1100 0001 0

Solutions for Chapter 3 Exercises5

xy

1.100 0000 0000 0000 0010 0001×1.010 0000 0000 0000 0000 0000

1 100 0000 0000 0000 0010 0001 000 0000 0000 0000 0000 0000+ 11 0000 0000 0000 0000 1000 010 0000 0000 0000 0000 0000 1.111 0000 0000 0000 0010 1001 010 0000 0000 0000 0000 0000 Round result for part b.

1.111 1100 0000 0000 0010 1001

z 0011 1100 1110 0000 0000 1010 1100 0000Exponents

100 0001 0–11 1100 1

100 1 --> shift 9 bits

1.111 0000 0000 0000 0010 1001 010 0000 00 + z 111 0000 0000 0101 011 0000 001.111 0000 0111 0000 0010 1110 101 GRSResult:

0100 0001 0111 0000 0111 0000 0100 1111b.

1.111 1100 0000 0000 0000 1001 result from mult.+ z 111 0000 0000 0101 0111.111 1100 0111 0000 0001 1110 011 GRS0100 0001 0111 0000 0111 0000 0100 1110

6Solutions for Chapter 3 Exercises

3.27

a.

Solutions for Chapter 3 Exercises7

3.28

a.

c.

8Solutions for Chapter 3 Exercises

d.Convert to positive:

100010

00

0000

0000

11011000

010|0111Since signs differ, convert quotient to negative:

1111 1111 1111 1111 1111 1111 1110 0101two

3.29Start

Set subtract bit to true

1.If subtract bit true: Subtract the Divisor register from the Remainder andplace the result in the remainder register. else Add the Divisor register to the Remainder and place the result in theremainder register.Test Remainder>=0

2.a. Shift the Quotient register to the left, setting rightmost bit to 1.<0

2.b. Set subtract bit to false.3.Shift the Divisor register right 1 bit.<33rd rep ---> repeatTest remainder<0

Solutions for Chapter 3 Exercises9

Add Divisor register to remainder and place in Remainder register.DoneExample:

Perform n + 1 iterations for n bitsRemainder 0000 1011Divisor 0011 0000Iteration 1:(subtract)

Rem 1101 1011Quotient 0

Divisor 0001 1000Iteration 2:(add)

Rem 1111 0011Q 00

Divisor 0000 1100Iteration 3:(add)

Rem 1111 1111Q 000

Divisor 0000 0110Iteration 4:(add)

Rem 0000 0101Q 0001

Divisor 0000 0011

Iteration 5:(subtract)

Rem 0000 0010Q 0001 1

Divisor 0000 0001

Since remainder is positive, done.Q = 0011 and Rem = 0010

10Solutions for Chapter 3 Exercises

3.30

a.–1 391 460 350b.2 903 506 946c.–8.18545 × 10–12

d.sw $s0, $t0(16) sw $r16, $r8(2)

3.31

a.613 566 756b.613 566 756c.6.34413 × 10–17

d.addiu, $s2, $a0, 18724 addiu $18, $4, 0x8924

3.35

.285 × 104+9.84 × 10410.125 × 1041.0125 × 104

with guard and round: 1.01 × 105without: 1.01 × 105

3.36

3.63 × 104+.687 × 1044.317 × 104

with guard and round: 4.32 × 104without: 4.31 × 104

3.37

Solutions for Chapter 3 Exercises11

Single precisionDoubleprecision3.38

0 1000 011 010 0000 0000 0000 0000 0000

0 1000 0000 011 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

Single precision

Doubleprecision3.39

0 1000 0011 010 0100 0000 0000 0000 0000

0 1000 0000 011 0100 1000 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

01111011

10011001100110011001100

10011001100110011001101

truncround

Single precision

01111111011

10011001100110011001100110011001100110011001100110011001100110011001100110011001100110011001100110011010

truncround

Doubleprecision

12precisionSingle precision

DoubleSolutions for Chapter 3 Exercises

3.40

1 0001 1110 101 0101 0101 0101 0101 0101

1 0111 1111 110 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 t runc

1 0111 1111 110 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1010 1011 round

3.41No, since floating point adds are not associative, doing them simultaneously

is not the same as doing them serially.3.42

a.

Convert +1 . 1011 * 214 + –1 . 11 * 2–21.1011 0000 0000 0000 0000 000

–0.0000 0000 0000 0001 1100 0001.1010 1111 1111 1110 0100 0000100 0110 1101 0111 1111 1111 0010 0000b.Calculate new exponent:111 11 1100 0110 1+011 1110 11000 0101 0

–011 1111 1 minus bias1111 1111

100 0101 1 new exponentMultiply signi cands:

×1.101 1000 0000 0000 0000 00001.110 0000 0000 0000 0000 0000

1 11 11

1 1011 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000 11 0110 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000+1.10 1100 0000 0000 0000 0000 0000 0000 0000 0000 0000 000010.11 1101 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000

Solutions for Chapter 3 Exercises13

Normalize and round:

exponent 100 0110 0signi cand

1.011 1010 0000 0000 0000 0000Signs differ, so result is negative:

1100 0110 0011 1010 0000 0000 0000 00003.43

0 101 1111 1 011 1110 0100 0000 0000 00000 101 0001 1 111 1000 0000 0000 0000 0000a.Determine difference in exponents:1011 1111–1010 0011001 1100 --> 28

Add signi cands after scaling:

1.011 1110 0100 0000 0000 0000 0000 0000 0000 0000 0000 0000 0000+0.000 0000 0000 0000 0000 0000 0000 1111 1000 0000 0000 0000 00001.011 1110 0100 0000 0000 0000 0000 1111 1000 0000 0000 0000 0000Round (truncate) and repack:

0 101 1111 1 011 1110 0100 0000 0000 0000 0101 1111 1011 1110 0100 0000 0000 0000b.Trivially results in zero:

0000 0000 0000 0000 0000 0000 0000 0000

c.We are computing (x + y) + z, where z = –x and y ≠ 0(x + y) + –x = y intuitively

(x + y) + –x = 0 with nite oating-point accuracy

14Solutions for Chapter 3 Exercises

3.44

a.215 – 1 = 32767b.

2.0ten × 22 11

22 = 3.23 × 10616

12

22 = 1.04 × 10123313

22 = 1.09 × 10246614

22 = 1.19 × 10493215

15

22 = 1.42 × 109864so

as small as 2.0ten × 10–9864

and almost as large as 2.0ten × 109864

c.20% more signi cant digits, and 9556 orders of magnitude more exibility.(Exponent is 32 times larger.)3.45The implied 1 is counted as one of the significand bits. So, 1 sign bit, 16

exponent bits, and 63 fraction bits.3.46

Load 2 × 10308

Square it 4 × 10616Square it 1.6 × 101233Square it 2.5 × 102466Square it 6.2 × 104932Square it 3.6 × 109865

Min 6 instructions to utilize the full exponent range.

本文来源:https://www.bwwdw.com/article/u9y4.html

Top