106 lines
4.6 KiB
Plaintext
106 lines
4.6 KiB
Plaintext
#import "@preview/tablex:0.0.4": tablex, rowspanx, colspanx, hlinex, vlinex
|
||
|
||
#show link: set text(blue)
|
||
#set text(font: "Calibri")
|
||
#show raw: set text(font: "Fira Code")
|
||
|
||
#set page(margin: (x: .5in, y: .5in))
|
||
#let solve(solution) = [
|
||
#let solution = align(
|
||
center,
|
||
block(
|
||
inset: 5pt,
|
||
stroke: blue + .3pt,
|
||
fill: rgb(0, 149, 255, 15%),
|
||
radius: 4pt,
|
||
)[#align(left)[#solution]],
|
||
)
|
||
#solution
|
||
]
|
||
|
||
#let note(content) = [
|
||
#align(
|
||
center,
|
||
block(
|
||
inset: 5pt,
|
||
stroke: luma(20%) + .3pt,
|
||
fill: luma(95%),
|
||
radius: 4pt,
|
||
)[#align(left)[#content]],
|
||
)
|
||
]
|
||
|
||
#align(center)[
|
||
= CS 3843 Computer Organization
|
||
HW 5\
|
||
#underline[Price Hiller] *|* #underline[zfp106]
|
||
]
|
||
#line(length: 100%, stroke: .25pt)
|
||
|
||
[This is a bonus HW]
|
||
\
|
||
\
|
||
|
||
1. The word size is 5 bits. How many integers can you represent with that? What is the range for unsigned integers? What is the range for signed integers?
|
||
#solve[
|
||
- Can represent $2^5$ integers, or $32$ integers in total.
|
||
- Range of unsigned integers: $0 -> 2^(w)-1$, from $0 -> 31$
|
||
- Range of signed integers: $-2^(w-1) -> 2^(w-1) - 1$, from $-16 -> 15$
|
||
]
|
||
2. Show that the negation of Tmin is Tmin. You can pick any Tmin (Tmin for 4-bits, Tmin for 5 bits etc). Also, explain why the negation of Tmin is Tmin. (Hint: "negation" and "not operator" is not the same thing)
|
||
#solve[
|
||
The negation of a number in 2's complement is as follows:
|
||
- ∵ $~x + x ≡ 1111...111 ≡ -1$
|
||
- $~x + 1 == -x$
|
||
For example, using the negation of $T_(min)$ for a word size of 4 bits:
|
||
+ $T_(min_4) = -2^(4-1) = -8$
|
||
+ Negate $-8$, binary: $1000$
|
||
+
|
||
|
||
]
|
||
3. Suppose that a and b have byte values 0x55 and 0x46, respectively. What will be the value for this expression: a & !b ? What will be the value for this expression: a && ~b?
|
||
4. You have two decimal values as 12 and 4. The word size is 5 bits. Perform the 2's complement addition and identify if overflow (positive or negative) happens or not. Mention the final result as well.
|
||
#solve[
|
||
+ Solve $12 +^t_5 4$
|
||
+ Note that $T_(max_5) = 15$
|
||
+ Not that $T_(min_5) = -16$
|
||
+ Convert $12$ to binary: `01100`
|
||
+ Convert $4$ to binary: `00100`
|
||
+ Add `01100` $+$ `00100`
|
||
+ #table(
|
||
stroke: none,
|
||
align: right,
|
||
[`01100`],
|
||
[`+ 00100`],
|
||
table.hline(),
|
||
[`10000`]
|
||
)
|
||
+ The most significant bit is $1$, positive overflow has occured
|
||
+ Apply 2's complement:
|
||
+ Simplify: $16 mod 32$
|
||
+ $16 mod 32 = 16$
|
||
+ Check bounds, $16 > T_(max_5)$ is True
|
||
+ Thus there is a positive overflow
|
||
+ Remove all bits beyond the $w - 1$ bit for bounds, where $w - 1 = 4$
|
||
+ $16$ to binary is $10000$
|
||
+ Remove the bit at $w_5$, $0000$
|
||
+ ∴ $12 +^t_5 4 = 0$
|
||
]
|
||
|
||
*You need to explain for each question why you chose True/False as your answer.*
|
||
|
||
5. If you multiply (-2) with (-2), and the word size is 3-bits, then the final result will be (+4). T/F
|
||
#solve[
|
||
*False*.
|
||
|
||
|
||
]
|
||
6. Assume data type int is 32 bits long and uses a two's-complement representation for signed values. The variables are declared and initialized as follows: int x = foo(); /* Arbitrary value */ int y = bar(); /* Arbitrary value */ unsigned ux = x; unsigned uy = y; The following C expression is true (evaluates to 1) for all values of x and y: x+y == uy+ux. Hint: Think about what happens at bit-level T/F
|
||
7. Assume variables x, f, and d are of type int, float, and double, respectively. Their values are arbitrary, except that neither f nor d equals +∞, −∞, or NaN. The following C expression is false (evaluates to 1) for all values of f: f == (float)(double) f. T/F
|
||
8. Bias is a bias value equal to 2 k-1 − 1 (127 for single precision and 1023 for double). This yields exponent ranges from −126 to +127 for single precision and −1022 to +1023 for double precision. Here, k is the size of exp bits. T/F
|
||
9. When the sign bit is 1, but the other fields are all zeros, we get the value −0.0. T/F
|
||
10. Round-to-Even rounding mode is the default rounding mode for most of the machines for floating- point numbers. T/F
|
||
11. Assuming the expressions are evaluated when executing a 32-bit program on a machine that uses two's-complement arithmetic See below the expression: -1 < 0U; What is the evaluation for this expression? T/F
|
||
12. We can represent -1 in Hex with 0xFFFFFFFF for 32-bits. T/F
|
||
13. Assume variables x, f, and d are of type int, float, and double, respectively. Their values are arbitrary, except that neither f nor d equals +∞, −∞, or NaN. For the following C expressions, it will always be true (i.e., evaluate to 1): d*d >= 0.0 T/F
|