Unformatted text preview:

1 Sample problems for midterm exam Text practice problems 2.1 to 2.15 and 2.30 to 2.37. Also text practice problems 3.1 to 3.23. In the following assume the variables a and b are signed integers and that the machine uses two’s complement representation. Also assume that MAX_INT is the maximum integer, MIN_INT is the minimum integer, and W is one less than the word length (e.g., W = 31 for 32-bit integers). Match each of the descriptions on the left with a line of code on the right (write in the letter). These are worth two points each. (i) a _______________ a. ((a ^ b) & ~b) | (~(a ^ b) & b) b. (a << 3) + ~a + 1 (ii) a & b _______________ c. (a << 4) + (a << 2) + (a << 1) d. ~(~a | (b ^ (MIN_INT + MAX_INT))) (iii) a * 7 _______________ e. a ^ (MIN_INT + MAX_INT) f. ~((a >> W) << 1) (iv) a / 4 _______________ g. a >> 22 Match each of the assembler routines on the left with the equivalent C function on the right. foo1: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax sall $4,%eax subl 8(%ebp),%eax movl %ebp,%esp popl %ebp ret foo2: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax testl %eax,%eax jge .L4 addl $15,%eax .L4: sarl $4,%eax movl %ebp,%esp popl %ebp ret foo3: pushl %ebp movl %esp,%ebp movl 8(%ebp),%eax shrl $31,%eax movl %ebp,%esp popl %ebp ret int choice1(int x) { return (x < 0); } int choice2(int x) { return ((x << 31) & 1); } int choice3(int x) { return (15 * x); } int choice4(int x) { return ((x + 15) / 4); } int choice5(int x) { return (x / 16); } int choice6(int x) { return (x >> 31); } Fill in your answers here: foo1 corresponds to choice_______. foo2 corresponds to choice_______. foo3 corresponds to choice_______.Problem 2. (9 points):Assume we are running code on a 6-bit machine using two’s complement arithmetic for signed integers. A“short” integer is encoded using 3 bits. Fill in the empty boxes in the table below. The following definitionsareusedinthetable:short sy = -3;int y = sy;int x = -17;unsigned ux = x;Note: You need not fill in entries marked with “–”.Expression Decimal Representation Binary RepresentationZero 0– −6– 01 0010uxyx>>1TMax−TMinTMin + TMinExpression decimal binary-----------------------------------Zero | 0 | 00 0000--- | -6 | 11 1010--- | 18 | 01 0010ux | 47 | 10 1111y | -3 | 11 1101x >> 1 | -9 | 11 0111TMax | 31 | 01 1111-TMin | -32 | 10 0000TMin+TMin | 0 | 00 0000-----------------------------------Page 3 of 10Problem 3. (8 points):Consider the following 5-bit floating point representation based on the IEEE floating point format:• There is a sign bit in the most significant bit.• The next two bits are the exponent. The exponent bias is 1.• The last two bits are the significand.The rules are like those in the IEEE standard (normalized, denormalized, representation of 0, ∞, and NAN).As described in class, the floating point format encodes numbers in a form:(−1)s× m × 2Ewhere m is the mantissa and E is the exponent. The table below enumerates the entire non-negative rangefor this 5-bit floating point representation. Fill in the blank table entries using the following directions:E: The integer value of the exponent.m: The fractional value of the mantissa. Your answer must be expressed as a fraction of the form x/4.Value: The numeric value represented. Your answer must be expressed as a fraction of the form x/4.You need not fill in entries marked “—”.Bits E m Value00000 — — 000001 0 1/4 1/400010 0 2/4 2/400011 0 3/4 3/400100 0 4/4 4/400101 0 5/4 5/400110 0 6/4 6/400111 0 7/4 7/401000 1 4/4 8/401001 1 5/4 10/401010 1 6/4 12/401011 1 7/4 14/4Page 4 of 10Problem 4. (8 points):Consider the source code below, where M and N are constants declared with #define.int mat1[M][N];int mat2[N][M];int sum_element(int i, int j){return mat1[i][j] + mat2[i][j];}A. Suppose the above code generates the following assembly code:sum_element:pushl %ebpmovl %esp,%ebpmovl 8(%ebp),%eaxmovl 12(%ebp),%ecxsall $2,%ecxleal 0(,%eax,8),%edxsubl %eax,%edxleal (%eax,%eax,4),%eaxmovl mat2(%ecx,%eax,4),%eaxaddl mat1(%ecx,%edx,4),%eaxmovl %ebp,%esppopl %ebpretWhat are the values of M and N?M =Answer:M=5N =AnswerN=7Page 5 of


View Full Document

WUSTL CSE 361S - Sample problems for midterm exam

Documents in this Course
Load more
Download Sample problems for midterm exam
Our administrator received your request to download this document. We will send you the file to your email shortly.
Loading Unlocking...
Login

Join to view Sample problems for midterm exam and access 3M+ class-specific study document.

or
We will never post anything without your permission.
Don't have an account?
Sign Up

Join to view Sample problems for midterm exam 2 2 and access 3M+ class-specific study document.

or

By creating an account you agree to our Privacy Policy and Terms Of Use

Already a member?