S
Shi Jin
Hi there,
I am now having a puzzle regarding what a function call actually does when
called.
I have a simple code to see what's going on. It is simply calling another
simple function from main().
The disassembled code for the function under linux (with gcc) looks like this:
pushl %ebp ;push old %ebp
movl %esp, %ebp ;make new stack frame
subl $4, %esp ;make room for local variable---x
;then the code doing the calculation inside the function
But the corresponding instructions under WinXP(with MSVC7, same code ) is
push ebp
mov ebp,esp
sub esp,0CCh ; 0CCh=204
push ebx
push esi
push edi
.....
The problem is why doesn't linux push the registers ebx,esi,edi into the
stack to save them. Since the C calling convetion assumes that function
call do not modify ESI,EDI and EBX.
Is that because in the code under linux, those registers are not used. So
it is not necessary to back them up? Maybe in some other cases, they are
actually used, then there would be some push instructions, just like the
windows disassembled code. Is that true?
Another puzzle for me is that in the function, there is only one integer
as a local variable. So "subl $4, %esp" is enough for that. But I don't
know why the windows code uses "sub esp,0CCh", which sounds like 51 32-bit
variables are there. Or the number 51 is just some randomly large number?
Thanks for any comment or advice.
Shi
I am now having a puzzle regarding what a function call actually does when
called.
I have a simple code to see what's going on. It is simply calling another
simple function from main().
The disassembled code for the function under linux (with gcc) looks like this:
pushl %ebp ;push old %ebp
movl %esp, %ebp ;make new stack frame
subl $4, %esp ;make room for local variable---x
;then the code doing the calculation inside the function
But the corresponding instructions under WinXP(with MSVC7, same code ) is
push ebp
mov ebp,esp
sub esp,0CCh ; 0CCh=204
push ebx
push esi
push edi
.....
The problem is why doesn't linux push the registers ebx,esi,edi into the
stack to save them. Since the C calling convetion assumes that function
call do not modify ESI,EDI and EBX.
Is that because in the code under linux, those registers are not used. So
it is not necessary to back them up? Maybe in some other cases, they are
actually used, then there would be some push instructions, just like the
windows disassembled code. Is that true?
Another puzzle for me is that in the function, there is only one integer
as a local variable. So "subl $4, %esp" is enough for that. But I don't
know why the windows code uses "sub esp,0CCh", which sounds like 51 32-bit
variables are there. Or the number 51 is just some randomly large number?
Thanks for any comment or advice.
Shi