| Answer Key
| |
Quiz #6 Solution
|
1. (10 points)
Write a MAL code fragment that enables interrupts.
mfc0 $8, $12 # get copy of Status register
ori $8, $8, 0x0001 # set LSB to a 1, without changing other bits
mtc0 $8, $12 # write modified copy back to Status register
2. (10 points)
The two representations (given in hexadecimal) 0xfe7a0004 and 0xfefa0007
are IEEE single precision floating point numbers.
Show all work in adding the two numbers.
Give the result both in binary and in hexadecimal and
use round to nearest for rounding.
The representations (in binary): 1111 1110 0111 1010 0000 0000 0000 0100 1111 1110 1111 1010 0000 0000 0000 0111 Re-spaced to show the fields: S EXP MANTISSA 1 11111100 111 1010 0000 0000 0000 0100 1 11111101 111 1010 0000 0000 0000 0111 The mantissa of the top one needs to be shifted right by one place to align the binary points. 1.111 1010 0000 0000 0000 0100 becomes 0.1111 1010 0000 0000 0000 010 0 (last bit kept for rounding) The addition of the mantissas: 0.1111 1010 0000 0000 0000 010 0 (last bit kept for rounding) + 1.1111 0100 0000 0000 0000 111 ------------------------------------- 10.1110 1110 0000 0000 0001 001 0 This mantissa needs to be put in a normalized form by shifting it right by one place (increasing the exponent by 1). Keep the bit that falls of the end for rounding: 10.1110 1110 0000 0000 0001 001 0 becomes 1.01110 1110 0000 0000 0001 00 10 (last 2 kept for rounding) Round: this is the case where the value calculated is exactly halfway between the 2 representations we have available. Therefore, we choose the representation that ends in a zero. The mantissa (still including the hidden bit) rounded is: 1.01110 1110 0000 0000 0001 00 The exponent will be 11111101 + 1 = 11111110 The representation (in binary) of the result: S EXP MANT 1 11111110 01110111000000000000100 The representation (in hexadecimal) of the result: 1111 1111 0011 1011 1000 0000 0000 0100 0x f f 3 b 8 0 0 4