Date: Tue, 05 Nov 1996 00:32:12 GMT Server: NCSA/1.5 Content-type: text/html Last-modified: Fri, 11 Oct 1996 14:55:46 GMT Content-length: 3975
CS 354
Fall 1996 Section 2 | SOLUTION | |
Quiz #3 for Friday October 11
3 questions, 25 points total |
1. (9 points) Do the following 8-bit two's complement arithmetic calculations. Show all work.
Indicate if overflow occurs by writing the word "overflow"
next to the calculated result. Give a 16-bit result for the multiplication.
01011110 11000000
+ 11011000 + 10001111
----------- -----------
00110110 01001111 OVERFLOW
01010010 01110111
- 10011000 x 11110001
----------- -----------
change to addition negative multiplier, so change problem
(and sign extend partial products)
01100111 10001001 (-119)
+ 1 x 00001111 ( 15)
-------- -----------
01101000 1111111110001001
1111111100010010
1111111000100100
+ 1111110001001000
01010010 ------------------
+ 01101000 1111100100000111 (-1785)
-----------
10111010 OVERFLOW
2. (9 points) Give an algorithm and then write a SAL code
fragment (not a whole program)
that does sign magnitude multiplication (x * y -> z
).
Variables x
and y
are given values elsewhere in the
program.
They contain 32-bit sign magnitude representations.
The result of the multiplication goes in variable z
, which
is also 32 bits and is initialized (elsewhere in the program) to 0.
The code should ignore the possiblility of overflow from 32 bits.
It is OK to modify variables x
and y
.
.data
mask1: .word 0x7fff
mask2: .word 0x8000
.text
xor sign, x, y # figure out sign of result
bgez x, abs_y # get absolute value of x
and x, mask1, x
abs_y: bgez y, multiply # get absolute value of y
and y, mask1, y
multiply: mul z, x, y # do multiplication on absolute values
bgez sign, all_done
or z, mask2, z # set sign bit
all_done:
3. (7 points)
Show the result of addition on the following two IEEE single precision floating
point values. Use round to nearest for all rounding.
0 10000100 11000000000000000010100 + 0 10000111 01000000000000000000011 -------------------------------------
To align binary points, shift the first addend 7-4=3 places to the right, keeping 3 extra digits at the least significant end for later rounding. 10000100 1.11000000000000000010100 10000101 0.11100000000000000001010 0 10000110 0.01110000000000000000101 00 10000111 0.00111000000000000000010 100 Do the addition on the mantissas. 0.00111000000000000000010 100 + 1.01000000000000000000011 000 ------------------------------------- 1.01111000000000000000101 100 This value is already normalized, so only rounding is left. The two values that we could round to are 1.01111000000000000000101 and 1.01111000000000000000110 The result we have is exactly halfway between these two representations. So, IEEE round to nearest says choose the one that ends in a 0. Therefore, the IEEE single precision result is 0 10000111 01111000000000000000110