Friday, March 16, 2012

Here is the IA32 assembly code produced by gcc when compiling the file mystery.c:?

Question by Igotaquestion: Here is the IA32 assembly code produced by gcc when compiling the file mystery.c:?
.file “mystery.c”
.text
.globl mystery
.type mystery, @function
mystery:
pushl %ebp
movl %esp, %ebp
subl $ 16, %esp
movl $ 0, -8(%ebp)
movl $ 0, -4(%ebp)
jmp .L2
.L3:
movl -4(%ebp), %eax
sall $ 2, %eax
addl 8(%ebp), %eax
movl (%eax), %eax
addl %eax, -8(%ebp)
addl $ 1, -4(%ebp)
.L2:
movl -4(%ebp), %eax
cmpl 12(%ebp), %eax
jl .L3
movl -8(%ebp), %eax
leave ret


What does this function do? Include in your explanation (a) what (if any) arguments are passed to mystery; and (b) the answer (if any) which is passed back to the calling function.


Best answer:


Answer by IZECKSOHNint totalize (int *const array, const int length)
{
int ret = 0;
int i = 0;
while (i < length) ret += array[i++];
return ret;
}


What do you think? Answer below!


share save 171 16 Here is the IA32 assembly code produced by gcc when compiling the file mystery.c:?

No comments:

Post a Comment