Exam 2 Practice Questions ========================= 1) Write one lea instruction that computes eax = 3x + 456, assuming x is in ecx. 2) Write an x86 loop that computes 1 + 2 + 3 + ... + N. Use ecx for your loop variable, eax for the result, and assume edx initially holds N (which is at least 1). 3) Encode -5 and 11/16 as a 12-bit normalized FP number (1 sign bit, 5 exponent bits, and 6 fraction bits). 4) Write one mov instruction that would correspond to the C code 'short a = 123;', assuming 'a' is stored in memory location rcx + 2 * rdx - 16. Use an appropriate instruction suffix. 5) Draw an x86 (32-bit) stack frame for a function with 2 local variables and 3 parameters. Ensure you include the return address and any saved registers. 6) Suppose IEEE adds a new FP format for 9-bit values: one sign bit, four exponent bits, and four fraction bits. What's the bit pattern for -0? What's the bit pattern/value for the smallest positive denormal? What's the bit pattern/value for the largest denormal? What's the bit pattern/value for the smallest positive normal? What's the bit pattern/value for the largest normal? What's the bit pattern for one? What's the bit pattern for +infinity? What's the bit pattern for a NaN? 7) Why are parameters passed differently in 32-bit and 64-bit code? How are they passed? 8) What are the condition codes and how are they used? Discuss cmp, test, setX, and jX (jump) instructions. 9) What's sizeof(char), sizeof(short), sizeof(int), sizeof(long), sizeof(float), sizeof(double), and sizeof(void*)? 10) What are the instructions needed to setup and tear down a stack frame? Explain each of them. 11) Explain how FP values are multiplied. Explain how FP values are added.