Re: Any explanations
- From: Dirk Wolfgang Glomp <spamtrap@xxxxxxxxxx>
- Date: Sun, 27 Aug 2006 08:13:38 +0200
John schrieb:
I would like to understand the following C++/C program in assembly
int main(void){
return 0;
}
================g++ -O -S compile.cpp
.file "x.c"
.def ___main; .scl 2; .type 32; .endef
.file "x.c"
.def ___main; .scl 2; .type 32; .endef
.text
.align 2
.p2align 4,,15
.globl _main
.def _main; .scl 2; .type 32; .endef
_main:
pushl %ebp
movl $16, %eax
movl %esp, %ebp
subl $8, %esp
andl $-16, %esp
call __alloca
call ___main
leave
xorl %eax, %eax
ret
What is actually going on? Why subtract 8 from esp (is that the stack
pointer?)
why this magical -16?
$ is the actual programm-counter.
what happens when alloca and main are called?
I´m not familar with C.
I guess alloca allocate some memory?
What is leave and xorl?
Leave destroy the stackframe, where normaly the enter-instruction
build one. A stackframe is only used in highlevel-language like C,
to put some values on the stack for subroutines.
When xor used with destination and source the same register,
the register will be cleared. This instruction is smaller
then movl &0,%eax.
Dirk
.
- Prev by Date: Re: newbie questions text code...
- Next by Date: Re: Could not open hla.hw
- Previous by thread: Could not open hla.hw
- Next by thread: Re: Any explanations
- Index(es):
Relevant Pages
|