CSE3101 Fall 2005 Exam #1, open book, open notes. Name ___________________ For all questions, you may use masm, nasm, or gas. Assume IA-32 (x86) architecture with C calling conventions where all registers except eax, ecx, edx and flags are preserved across function calls. 1. Write a C function f() equivalent to the following (15 pts): _f: mov eax, [esp+4] lea eax, [eax+eax*4] sal eax, 1 ret // ANSWER. (lea works like mov with the [] removed, so // the above multiplies eax * 5) int f(int a) { return a*10; // I will accept equivalent expressions like (a*4+a)<<1 } 2. Convert the following to assembler (30 pts each). // Return sum of a[0]+a[1]+...+a[n-1] int addup(unsigned char* a, int n) { // assume n > 0 int sum=0, i; for (i=0; i