{[ promptMessage ]}

Bookmark it

{[ promptMessage ]}

03~solutions_for_chapter_3_exercises

# 03~solutions_for_chapter_3_exercises - Solutions for...

This preview shows pages 1–4. Sign up to view the full content.

Solutions for Chapter 3 Exercises 1 Solutions for Chapter 3 Exercises 3.1 0000 0000 0000 0000 0001 0000 0000 0000 two 3.2 1111 1111 1111 1111 1111 1000 0000 0001 two 3.3 1111 1111 1110 0001 0111 1011 1000 0000 two 3.4 –250 ten 3.5 –17 ten 3.6 2147483631 ten 3.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 \$t2 Next: 3.9 The 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 of A_lower is a 1. As an example, consider 6-bit two’s complement and the address 23 = 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 is then 24 + –1 = 23. 3.10 Either the instruction sequence addu \$t2, \$t3, \$t4 sltu \$t2, \$t2, \$t4 or addu \$t2, \$t3, \$t4 sltu \$t2, \$t2, \$t3 works. 3.12 To 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 an overflow, an exception would occur! To overcome this, there are two possible methods: You can subtract them as unsigned numbers (which never produces an exception) and then check to see whether overflow would have occurred. This method is acceptable, but it is lengthy and does more work than necessary. An alternative would be to check signs. Overflow can occur if \$s0 and ( –\$s1 ) share

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
2 Solutions for Chapter 3 Exercises the same sign; that is, if \$s0 and \$s1 differ in sign. But in that case, we don’t need to subtract them since the negative one is obviously the smaller! The solution in pseudocode 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:=1 else \$t0:=0 3.13 Here is the equation: Sum = (a b C ar r yI n ) + (a b C ar r yI n ) + (a b CarryIn) + (a b CarryIn) Sum CarryIn a b
Solutions for Chapter 3 Exercises 3 3.23 One example of 6-bit operands that run faster when Booth’s algorithm looks at 3 bits at a time is 21 ten × 27 ten = 567 ten . Two-bit Booth’s algorithm: 010101± =±21 ten × 011011 = 27 ten – 010101 10 string (always start with padding 0 to right of LSB) 000000 0 11 string, middle of a string of 1s, no operation + 010101 00 01 string, add multiplicand – 010101 000 10 string, subtract multiplicand 000000 0000 11 string + 010101 00000 01 string 11111101011 two’s complement with sign extension as needed 0000000000 0 zero with sign extension shown 000010101 00 positive multiplicand with sign extension 11101011 000 0000000 0000 + 010101 00000 01000110111 = 567 ten Current bits Prev. bits ai + 1 ai ai – 1 Operation Reason 0 0 0 None Middle of a string of 0s 0 0 1 Add the multiplicand End of a string of 1s 0 1 0 Add the multiplicand A string of one 1, so subtract the multiplicand at

This preview has intentionally blurred sections. Sign up to view the full version.

View Full Document
This is the end of the preview. Sign up to access the rest of the document.

{[ snackBarMessage ]}

### Page1 / 14

03~solutions_for_chapter_3_exercises - Solutions for...

This preview shows document pages 1 - 4. Sign up to view the full document.

View Full Document
Ask a homework question - tutors are online