Written Assignment 2

Question 1-a

To avoid trivialization of this problem, the following calculation excludes inf and NaN. Since, without such exclusion, inf will always be the largest value.

Calculating the Range of Exponents

The exponent range can be calculated using the following formula (where k denotes the number of exponent bits we choose to use):

\text{bias} = 2^{k-1} - 1$$ $$\text{e_min} = 1 - \text{bias}$$ $$\text{e_max} = 2^{k} - \text{bias} - 2

Therefore, the range of The Gates cafe's exponent is: [-2, 5] (justified by the following calculation)

\text{bias} = 2^2 - 1 = 3$$ $$\text{e_min} = 1 - 3 = -2$$ $$\text{e_max} = 2^{3} - 3 - 2 = 3

The range of La Prima's exponent is: [-14, 17] (justified by the following calculation)

\text{bias} = 2^{4} - 1 = 15$$ $$\text{e_min} = 1 - 15 = -14$$ $$\text{e_max} = 2^{3} - 15 - 2 = 15

Calculating the Maximum Value

The largest represent-able numerical float number is to have exponent pattern of all ones followed by 1 zero (Gates: 110, La Prima: 11110) and fractional pattern of all ones (Gates: 11111, La Prima: 111).

For the fractional part (denoted by M in my later calculation), since the largest value are in the normalized range, we add one to the binary value of the fractional pattern (Gates: 1.11111, La Prima: 1.111) before converting the binary into decimal (Gates: 15, La Prima: 63). And since these values are in decimals-form of binary, we need to divide by 2^f where f is the number of fractional bits we chose to use. (Gates: \frac{63}{2^5} = \frac{63}{32}, La Prima: \frac{15}{2^3} = \frac{15}{8}).

Finally, the maximum value is V = M*2^{\text{e_max}}.

V_{\text{Gates}} = \frac{63}{32} * 2^{3} = 15.75$$ $$V_{\text{La Prima}} = \frac{15}{8} * 2^{15} = 61440.00

Calculating the Minimum Value and the Range

The minimum represent-able numerical float number is to have all bits be 0 (Gates: 00000000, La Prima: 00000000). And the minimum value for both Gates and La Prima is 0.0.

Therefore, Gates has range [0.0, 15.75] and La Prima has range [0.0, 61440.00]

Calculating the Step Size in Denormalized Range

The step size in denormalized range can be caluclated using the following formula (where f indicates the number of fractional bits we chose to use)

S = \frac{2^{e_min}}{2^f}$$ $$S_{Gates} = \frac{2^{-2}}{2^5} = 0.007812500$$ $$S_{La Prima} = \frac{2^{-14}}{2^3} = 0.000007629

Calculating Average Step Size

We define the average step size as the following (where max is the maximum represent-able value, min is the minimum represent-able value, and n is the number of distinct represent-able value):

n = 2^{k+f} - 2^{f}
n_{\text{Gates}} = 2^{k+f} - 2^{f} = 256 - 32 = 224$$ $$n_{\text{La Prima}} = 2^{k+f} - 2^{f} = 256 - 8 = 248

We exclude inf and NaN here.

R = \frac{max - min}{n}$$ $$R_{\text{Gates}} = \frac{15.75 - 0}{n} = \frac{15.75}{224} = 0.070312500$$ $$R_{\text{La Prima}} = \frac{61440.00 - 0}{n} = \frac{61440.00}{248} = 247.741935484

Calculating Local Step Size

Since step size varies, the best I can do is to tell you the step size around a float (where e is the current exponent of the value).

SL = \frac{2^e}{2^f}

Conclusion

La Prima can represent bigger range, but Gates has higher precision.

Question 1-b

The lowest exponent in Gates is -2, and we know that 4.00 = 16 * 2^{-2}. If it is in normalized range, the lowest fractional value is 32 with all 0 bits. Therefore -4 should be in denormalized range and the fractional bits 10000 represent 16. In summery, the exact value of -4 can be represented by 00010000.

We know that the bit representation of -4 is even.

Knowing this, we search the nearby value of 00010000 which is 00001111(exponent = -2, fractional = 15, value = 15 * 2^{-2} = 3.75) and 00010001 (exponent = -2, fractional = 17, value = 17 * 2^{-2} = 4.25). Since -4 is even, the range in which the price will round to 4 is [4-(4-3.75), 4+(4.25-4)] = [3.75, 4.25].

Question 2

Program 1

1| movq $0x213, (%rcx)
2| leaq 8(%rcx), %rax
3| movq (%rcx), (%rax)

Erroneous / No Info

Program 2

4| movq $0x106, %rcx          # %rcx = 0x106
5| leaq 1(, %rcx, 2), %rdx    # %rdx = 1 + 0x20C = 0x20D
6| movq $0x75, %rbx           # %rbx = 0x75
7| leaq (%rdx, %rbx, 4), %r12 # %r12 = 0x20D + 4*0x75 = 0x20D + 0x1D4 = 0x3E1
8| leaq (%r12), %rax          # %rax = 0x3E1

The value of %rax is 0x3E1 as calculated from above.

Table of Content