This is a C program to find the sum of 4 integers
//sum.c
main()
{
int a[4]={2,3,4,5};
int i,sum=0;
for(i=0;i<4;i++)
sum=sum+a[i];
}
I am compiled this code :gcc -g -o sum sum.c //-g for gdb
gcc version: 4.3.3,i386
The assembler output from gdb is
0x08048334 : push %ebp
0x08048335 : mov %esp,%ebp
0x08048337 : sub $0x28,%esp
0x0804833a : and $0xfffffff0,%esp
0x0804833d : mov $0x0,%eax
0x08048342 : add $0xf,%eax
0x08048345 : add $0xf,%eax
0x08048348 : shr $0x4,%eax
0x0804834b : shl $0x4,%eax
0x0804834e : sub %eax,%esp
0x08048350 : movl $0x2,0xffffffe8(%ebp)
0x08048357 : movl $0x3,0xffffffec(%ebp)
0x0804835e : movl $0x4,0xfffffff0(%ebp)
0x08048365 : movl $0x5,0xfffffff4(%ebp)
0x0804836c : movl $0x0,0xffffffe0(%ebp)
0x08048373 : movl $0x0,0xffffffe4(%ebp)
0x0804837a : cmpl $0x3,0xffffffe4(%ebp)
0x0804837e : jg 0x8048393
0x08048380 : mov 0xffffffe4(%ebp),%eax
0x08048383 : mov 0xffffffe8(%ebp,%eax,4),%edx
0x08048387 : lea 0xffffffe0(%ebp),%eax
0x0804838a : add %edx,(%eax)
I am fully doubted with this code.I haven't much knowledge in assembly.
Anyone can briefly explain the assembly code?
*yawn*
People, proofread your postings! There is a preview-button and you can use the edit-feature, if things went wrong. I am bored of C code stopping when it gets interesting (at the first for()-loop because of the <).