Academic Integrity: tutoring, explanations, and feedback — we don’t complete graded work or submit on a student’s behalf.

foo: pushl %ebp movl %esp,%ebp movl 12(%eax,%eax) xorl %eax,%eax movl 8(%ebp),%e

ID: 3626121 • Letter: F

Question

foo:
pushl %ebp
movl %esp,%ebp
movl 12(%eax,%eax)
xorl %eax,%eax
movl 8(%ebp),%edx
cmpl %ecx,%edx
jle .L3
.align 4
.L5:
addl %edx,%eax
decl %edx
cmpl %ecx,%edx
jg .L5
.L3:
leave
ret

based on the assembly code above, fill in the blanks below in its corresponding C source code. (Note: you may only use symbolic variables x,y,i and result, from the source code in expressions below --- do not use register names)


int foo(int x, int y)
{
int i, result=0;

for(i=____;______;______) {
_____;
}
return result;
}

Explanation / Answer

Dear, int foo(int x, int y)
{
int i, result=0;

for(i=x;i<=y;i++) { result+=i;
}
return result;
} Hope this will help you