This is the mail archive of the
gcc-help@gcc.gnu.org
mailing list for the GCC project.
stack pointer instructions in subroutine
- From: Anitha Boyapati <anithab at sankhya dot com>
- To: gcc-help at gcc dot gnu dot org
- Date: Thu, 9 Aug 2007 19:07:18 +0530 (IST)
- Subject: stack pointer instructions in subroutine
Hi,
I am trying to map high level code to assembly language while
analysing ABI(intel) for a trivial c++ program shown below. I have this
doubt regarding stack pointer usage in foo (). I should say a very basic
doubt probably.
class test {
};
void foo() {
test t;
}
A part of the assembly listing is as follows for foo :
(I tried adding comments to each line)
.align 2
.globl _Z3foov
.type _Z3foov,@function
_Z3foov:
.LFB5:
pushl %ebp ; push ebp
.LCFI0:
movl %esp, %ebp ; ebp = esp
.LCFI1:
subl $8, %esp ; esp = esp - 8 (?)
.LCFI2:
subl $12, %esp ; esp = esp - 12 (??)
leal -1(%ebp), %eax
pushl %eax
.LCFI3:
call _ZN4testC1Ev
addl $16, %esp ; Why pop off 4 bytes ?
...
_ZN4testC1Ev:
.LFB6:
pushl %ebp
.LCFI4:
movl %esp, %ebp
...
ret
As far as I know, arguments are pushed onto the stack before entering
a subroutine. Hence ebp makes sense. From here onwards, I feel lame.
Summarizing :
1. Why should subl $8 and sub $12 from esp happen ?
2. After the call to constructor, why are 16 bytes being poped
off? According to me, only 4 bytes ( for another round of ebp
in constructor) should be popped off.
I could be missing some basic details which are what I am after.
Any help appreciated.
Here is my version : gcc 3.2.3, host i386 redhat.
--
Regards,
Anitha B
@S A N K H Y A