# Test #1 Review Sheet

Here's a review sheet for the first test. The ommission of a topic does not mean it is not on the test. You are responsible for class lectures 00-06, homework assignments 1-3, and most of lab1.

Note that the existence of an exam #1 review sheet does not imply the existence of a review sheet for exams #2, #3, and #4. Also, I credit the Bryant and O'Hallaron textbook and slides as providing problems #1 and #2.

## Questions

1. Which of the following are true. x and y are of type int. ux and uy are of type unsigned int.
• x & 7 == 7 ===> (x<<30) < 0
• x > y ===> -x < -y
• x <= 0 ===> -x >= 0
• x >= 0 ===> -x <= 0
2. Write a c-expression to yield a bit string of w-length that sequentially contains w-(k+j) 0's, k 1's, and j 0's.
3. Write a c-expression that yields a mask 0xFFFF...FF00FF using each of the following operations once: ~ << |
4. Write a c-expression that yields a mask 0xFFFF...FF00FF using each of the following operations once: ~ ^
5. Hard and I will not cover myself: Without using control constructs (for, if, etc.), write a function to count the number of binary 0's in a 32-bit integer. For example 0b1111...11110000 would return the integer 4. Restrict yourself to straightline C code, similar to lab 1. Think about how to decompose the problem into multiple operations with results stored in clearly labeled variables.
6. Given a floating point format with 1 sign bit, 5 exponent bits, and 5 fraction bits:
• A. give the bit representation for the number 333, using the "round-to-zero" rounding method.
• B. What number does the hexadecimal string 0x558 represent?
• C. What number does the hexadecimal string 0x3F0 represent?
7. What is the difference between a normalized and denormalized floating point number? What are the three types of denormalized floating point numbers?
8. How many exponent and significand bits are there in an IEEE single-precision (32-bit) floating point number?
9. Which register does the x86 architecture use to return a value from a subroutine?
10. Does gcc push operands from right to left or from left to right?
11. Write C-code for the following assembly:
```	.file	"for.c"
.text
.globl foo
.type	foo, @function
foo:
pushl	%ebp
movl	%esp, %ebp
subl	\$4, %esp
movl	\$0, -4(%ebp)
.L2:
cmpl	\$99, -4(%ebp)
jle	.L5
jmp	.L3
.L5:
movl	12(%ebp), %eax