CSCI 237

Computer Organization

Home | Schedule | Assignments | Links | Slack | Williams CS

The table below lists practice problems that test topics we emphasized in class. We recommend completing these practice problems to reinforce the course material in prepration for quizzes and exams. Some questions have answers in the textbook, but the TAs and instructors are available to answer any questions that you have about the material. You're encouraged to work together on these problems.

Problem Page Topics Covered (Notes)
PP1 PP1 Practice Problems 1
- - How do you include libraries in C? What is the return type of main? How do you compile a C program?
- - Write a C program that takes a positive integer as a command line argument and sums together that many numbers read from stdin before printing the sum to stdout.
- - Write a C program that declares an integer array of 10 elements, initializes the elements of that array to random values between 0 and 100 inclusive (see driver.c from lab 1 for help with random number generation), prints out the contents of the array, and prints out the median value in the array to stdout.
PP2 PP2 Practice Problems 2
- - What is the 8 digit binary representation for 15? 16? 31? 32? 255?
2.17 65 Converting Hexadecimal to binary representations; unsigned vs. twos-complement.
-- -- Write the 16-bit twos-complement representation of the following numbers: -1, 2864, -1573
- - If w bits are able to store the two's complement representation of a positive whole number, can the negation of that number also be stored in w bits using two's complement representation? If w bits are able to store the two's complement representation of a negative whole number, can the negation of that number also be stored in w bits using two's complement representation?
2.61 (A, B) 129 C and bitwise representations of integers.
2.22 79 Sign extension. (Equation 2.3 is on page 64)
2.23 80 Arithmetic shifting.
2.24 82 Effect of truncating on signed/unsigned.
2.29 93 Signed addition; overflow.
2.30 94 Overflow.
- - How can overflow be detected when adding/subtracting 2 unsigned numbers? 2 signed numbers?
2.68 132 C and bitwise representations of integers.
PP3 PP3 Practice Problems 3
- - Why does a machine's endianness (i.e. little endian vs. big endian) matter when dealing with ints but not with chars?
- - Consider the following C code snippet. Draw a picture of each of the variables indicating what is stored in each.
	    int val = 4, val2 = 0, val3 = 12;
	    int *ptr;
	    ptr = &val;
	    val2 = *ptr;
	    int **ptr2 = &ptr;
	    val3 = **ptr2;
	  
- - Consider the following C code snippet. Draw a picture of each of the variables indicating what is stored in each.
	    int arr[4];
	    arr[0] = arr[1] = arr[2] = arr[3] = 0;
	    int *ptr;
	    ptr = arr;
	    *ptr = 7;
	    *(ptr+1) = 5;
	    ptr[2] = 10;
	    ptr = &arr[3];
	    *ptr = 100;
	  
Consider the following C code snippet. Draw a picture of what the memory associated with argv looks like when the program is invoked with the command "./hello Donuts! Yum!". Indicate what is stored in each memory cell. What will be stored in the variables c and d?
	    int main(int argc, char *argv[])
	    {
	         if(argc == 3){
                     char c = argv[1][3];
	             char d = argv[2][4];
                 }
            }
	  
2.45 111 Binary fractional values
2.47 117 IEEE Floating point encoding/decoding.
2.48 119 Bitwise representation of floating point numbers
- - Consider the decimal value -718.40625.
  1. Convert this number to its IEEE single precision (32-bit) floating point representation.
  2. Convert the 32-bit binary number from the previous problem to hexadecimal.
- - Consider the hexadecimal value 0xC295D000.
  1. Convert the hexadecimal number to a 32 bit binary number.
  2. Assume this 32 bit number is an IEEE single precision (32b) floating point number. What is its decimal floating point value?
- - Write down the binary representation of the decimal number -316.5625 assuming IEEE single-precision floating point format.
- - Why did the IEEE floating point designers choose to use biased representation for the exponent field? What is the benefit of using a biased representation instead of two's complement representation?
- - In the IEEE floating point standard, representable numbers are denser closer to zero than they are at distant locations on the numberline of representable values. Why?
PP4 PP4 Practice Problems 4
3.1 182 Addressing/Operand Forms
3.2 185 Operand sizes
3.5 189 Assembly -> C conversion
3.6 192 Load Effective Address
3.7 193 Assembly -> C conversion
3.8 194 Arithmetic Operations
3.10 197 Assembly -> C conversion
- - Suppose %rsp is storing 0x100. You then push the contents of %rbx onto the stack followed by pushing the contents of %r8 onto the stack. What memory addresses are the contents of %rbx stored at? What memory address are the contents of %r8 stored at?
3.58 311 Assembly -> C conversion
3.11(A) 197 Assembly Tricks
PP5 PP5 Practice Problems 5
3.13 204 Comparisons
- - What causes the values of the condition codes to be set?
3.16 212 C if/else ↔ C goto code
3.18 213 if/else ↔ assembly
3.23 223 Compiler optimizations and mapping ASM -> C
3.24 224 while loops ↔ assembly
3.26 228 Loop translations
3.27 231 C for loop ↔ C goto code
3.28 231 for ↔ assembly
3.30 236 Switch Statements
- - How do conditional move instructions potentially improve performance? When can they negatively impact performance? When can their use result in erroneous behavior?
3.60 312 C <-> Assembly Loop transformations
PP6 PP6 Practice Problems 6
3.33 246 Procedure Arguments, Registers, & the Stack
- - Where is the 7th argument to a function call stored?
3.34 253 Local storage & caller/callee saved registers
- - If a function intends to use a callee-saved register, what must it do to ensure the application functions correctly?
- - What happens on a call instruction?
- - Which values in function() must be stored on the stack before the function call to bar() in the following code? Assume all register call conventions are followed and that you know nothing about what bar() does.
            void function(int a, int b, int c){
	          int result = 0;
                  result = bar(a, b) + bar(a, c);
	          return result;
            }
	   
3.35 254 Recursion
PP7 PP7 Practice Problems 7
3.36 256 Arrays and addressing
3.37 257 Array/pointer/address ops and assembly
3.41 268 Struct data types
- - Explain why reordering the fields in a struct can change the amount of memory needed for an array of that struct type.
3.64 316 Multi-dimensional arrays and memory layouts
- - Suppose you had a single dimension array of ints with 100 elements. How could you use this array to represent a two dimensional array with 2 rows, where each row contained 50 entries? How would you convert the two dimensional indices, row_index and col_index, to a single value used to index into the single dimension array?
3.65 317 Arrays ↔ pointers
PP8 PP8 Practice Problems 8
4.1 360 Encoding Y86_64
4.2 360 Decoding Y86_64
4.4 370 C ↔ Y86_64
4.13 387 Instruction Processing Stages
- - Why is the latency of an instruction longer in a pipelined datapath versus a single cycle datapath?
- - What is a pipeline register and what does it do?
- - What is the ideal change in clock cycle time obtained when switching from a single cycle datapath to a n-stage pipelined datapath? What prevents us from actually achieving that ideal clock cycle time?