Write C expressions for the following values as expressions using the variable x. The result for x = 0x98FDECBA and a 32-bit word size shown in square brackets next to each question. Although the examples assume a 32-bit word size, your code should work for any word size
For the following int, unsigned int and float types mark each of the following as "always true" or "sometimes false". Assume the variables have some random initial value. But assume the float values are NOT + or - infinitiy and also NOT Nan.
int x, y; unsigned int u, v; float f, g;
Given register and memory contents, give the memory address indicated by different operands. (See quiz3 review)
Given register and memory contents give the value stored by a movl or a leal instruction.
Given 3 C code function versions, and 1 assembly code version. Identify which C code compiles to the assembly code.
int fun1(int x, int y) { if ( x < y ) { return x; } else { return y; } } int fun2(int x, int y) { if ( x < y ) { return y; } else { return x; } } int fun3(int x, int y) { unsigned ux = (unsigned) x; if (ux < y) { return x; } else { return y; } }
pushl %ebp movl %esp,%ebp movl 8(%ebp),%edx movl 12(%ebp),%eax cmpl %eax,%edx jge .L9 movl %edx,%eax .L9: movl %ebp,%esp popl %ebp ret
Practice problem 3.41
For each of the following structure declarations, determine the offset of each field, the total size of the structure, and its alignment requirements under Linux/IA32.
Alignment: shorts: 2 byte boundary; larger: 4 byte boundary.
Alignment: structs must be aligned on a boundary that is a multiple of the alignment of the largest field.
A. struct P1 { int i; char c; int j; char d; }; B. struct P2 { int i; char c; char d; int j; }; C. struct P3 { short w[3]; char c[3]; }; D. struct P4 { short w[3]; char *c[3]; }; E. struct P5 { struct P1 a[2]; struct P2 *p;}; F. struct P6 { short s; char c; char d; int n; };
Cache Lookup ( Feb 22 Lecture notes and Practice problems 6.10 and 6.14)