CS/COE 447 Quiz 5 February 26, 2007 ==================================== Q1: Assume we are using 8 bits to represent integers. Consider the following operation: 11001000 01000000 + -------- 00001000 Q1.A (4 points): Treating these values as unsigned integers, does unsigned overflow occur as a result of this operation? How do you know? Please explain your answer. Yes. This is unsigned overflow: viewing the numbers as unsigned integers, the sum is too large to fit into 8 bits. The maximum unsigned value that can fit into 8 bits is (2^8) - 1, which is 255. The sum, on the other hand, is 264 (200 + 64). [Specific numbers were not needed in your answers] We can detect this overflow in different ways: (1) there is a carry out of the top bit (2) the sum is larger than the first operand (a homework 2 question) (3) the sum is larger than the second operand (a homework 2 question) Q1.B (4 points): Treating the values as signed integers, does SIGNED overflow result from the operation? Please explain your answer. No, signed overflow does not occur. The first operand is a negative number and the second is a positive number. Signed overflow cannot occur as the result of adding a positive and a negative number. ================================================================= Q2 (4 points): When the following code is executed, what hex values are placed into $t1,$t2, $s1, and $s2? .data nums: .word 0x00008888,0x88888888 .text la $t0,nums lw $t1,0($t0) lw $t2,4($t0) slt $s1,$t1,$t2 sltu $s2,$t1,$t2 $t1 = 0x00008888 $t2 = 0x88888888 $s1 = 0, since the first is a positive number and the second a negative number, so the first is not smaller than the second $s2 = 1, since the first is a smaller unsigned number than the second one is ================================================================= Q3 (8 points): Assume the datapath is only 4 bits. We will multiply two 4-bit unsigned integers, specifically: 0100 X 0010 ------ 00001000 Using the algorithm on slides 15 and 16 of the lecture notes for Chapter 3, Part 2 (the one we announced would be on this quiz), perform the operation. Specifically, complete the table below: Iteration Multiplicand Product --------- ------------- ------- 0 - Initial values: 0100 0000 0010 --------------------------------------------------------------- 1 0100 0000 0001 --------------------------------------------------------------- 2 0100 0100 0001 0010 0000 --------------------------------------------------------------- 3 0100 0001 0000 --------------------------------------------------------------- 4 0100 0000 1000 ---------------------------------------------------------------