explanation of an assembly code



Can someone explain me what the following assembly code does?

..file "myfile.c"
.def ___main; .scl 2; .type 32; .endef
.text
.align 2
.p2align 4,,15
..globl _main
.def _main; .scl 2; .type 32; .endef
_main:
; why does the program save ebp?
pushl %ebp
; why move 16 in eax?
movl $16, %eax
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
call __alloca
; where is ___alloca? what are its functions?
call ___main
; where is ___main?
leave
; what does leave do?
xorl %eax, %eax
; does ret automatically return eax?
ret


It was written by gcc for a trivial C program.

Thanks,
--j

.



Relevant Pages

  • Re: [patch] spinlocks: remove volatile
    ... uint32_t spinvar = 1; ... movl spinvar, %eax ... movl %esp, %ebp ...
    (Linux-Kernel)
  • Re: Stack Exploit
    ... -> saved %ebp ... value saved in %ebp to %esp? ... movl %esp, %ebp ... movl %eax, -24 ...
    (alt.lang.asm)
  • Re: Newbie question...
    ... and esp, -16 ... mov ebp, esp ... Since the x86 increments esp with "pop", the new stack pointer is aligned ... add eax, 15 ...
    (alt.lang.asm)
  • Re: Stack Exploit
    ... It invokes undefined behaviour as far as the C ... movl %esp, %ebp ... movl %eax, -24 ...
    (alt.lang.asm)
  • Re: Stack Exploit
    ... It invokes undefined behaviour as far as the C ... movl %esp, %ebp ... movl %eax, -24 ...
    (alt.lang.asm)