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 5 2078
In order to make it clearer, I put the code here. Those who have interst
may actually try it.
//begin
#include<stdio.h>
#include<stdlib.h>
int lincomp(int a,int b,int c, int d)
{
int x;
x=a*b+c*d;
return x;
}
int main()
{
int y;
y=lincomp(0,1,10,16);
printf("y=%d\n",y);
exit(0);
}
//end
On Tue, 09 Sep 2003 19:09:31 -0400, Shi Jin wrote: 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
Shi Jin wrote:
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 convention 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.
Sorry, this is off-topic in the comp.lang.c newsgroup.
Try the gnu.gcc.help newsgroup instead.
Shi Jin <ji********@hotmail.com> scribbled the following: In order to make it clearer, I put the code here. Those who have interst may actually try it. //begin #include<stdio.h> #include<stdlib.h>
int lincomp(int a,int b,int c, int d) { int x; x=a*b+c*d; return x; }
int main() { int y; y=lincomp(0,1,10,16); printf("y=%d\n",y); exit(0); }
//end On Tue, 09 Sep 2003 19:09:31 -0400, Shi Jin wrote: 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:
(snip assembler stuff)
This is not a C question at all. This concerns a particular
implementation, and the ISO C standard does not mandate any particular
implementation to be used.
Please ask on comp.unix.programmer, comp.gcc.help, or a Linux
newsgroup. Thanks.
--
/-- Joona Palaste (pa*****@cc.helsinki.fi) ---------------------------\
| Kingpriest of "The Flying Lemon Tree" G++ FR FW+ M- #108 D+ ADA N+++|
| http://www.helsinki.fi/~palaste W++ B OP+ |
\----------------------------------------- Finland rules! ------------/
"All that flower power is no match for my glower power!"
- Montgomery Burns
"Joona I Palaste" <pa*****@cc.helsinki.fi> wrote in message
news:bj**********@oravannahka.helsinki.fi...
(snip) This is not a C question at all. This concerns a particular implementation, and the ISO C standard does not mandate any particular implementation to be used.
(snip)
It may or may not be off topic. A question as to whether the generated code
of a particular compiler is legal within ISO C should be on topic. That may
be questionable in this case.
-- glen This thread has been closed and replies have been disabled. Please start a new discussion. Similar topics
by: Valeriu Catina |
last post by:
Hi,
given the next code:
#define ENUM_CAST(x) int(x)
template<class T,int N>
class Array
{
|
by: mangi03 |
last post by:
Hi,
I came acrosss g++ compile errors whenever I make a function call by
reference and found out from the test program that compiler is
treating the function argument differently when another...
|
by: Shi Jin |
last post by:
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...
|
by: Yann Laviolette |
last post by:
Hi!
I look for a function like the Windows function getdate(&d); and
gettime(&t); to have the date and the time. Also I look for a function
like spawnl to call another program. These function...
|
by: anonymous |
last post by:
Thanks your reply.
The article I read is from
www.hakin9.org/en/attachments/stackoverflow_en.pdf.
And you're right. I don't know it very clearly. And that's why I want
to understand it; for it's...
|
by: Plissken.s |
last post by:
I have a template function which print out the content of a list: The
following compiles:
void PrintInt2 (int i) {
cout << i << " ";
}
template <class T>
void printList(T& list) {
|
by: waitan |
last post by:
#include <algorithm>
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <sstream>
#include <iterator>
#include <iomanip>
using namespace std;
|
by: golden |
last post by:
Hello,
I am going to ask a question regarding
write and lseek. I will provide code at the end of this, but first
some background.
I am trying to identify the cause of some latency in...
|
by: jwwicks |
last post by:
C/C++ Programs and Debugging in Linux
This tutorial will give you a basic idea how to debug a program in Linux using GDB. As you are aware Visual Studio doesn’t run on Linux so you have to use...
|
by: emmanuelkatto |
last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud.
Please let me know.
Thanks!
Emmanuel
|
by: BarryA |
last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
|
by: Sonnysonu |
last post by:
This is the data of csv file
1 2 3
1 2 3
1 2 3
1 2 3
2 3
2 3
3
the lengths should be different i have to store the data by column-wise with in the specific length.
suppose the i have to...
|
by: Hystou |
last post by:
There are some requirements for setting up RAID:
1. The motherboard and BIOS support RAID configuration.
2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
|
by: marktang |
last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
|
by: Hystou |
last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
|
by: Oralloy |
last post by:
Hello folks,
I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>".
The problem is that using the GNU compilers,...
|
by: jinu1996 |
last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
|
by: tracyyun |
last post by:
Dear forum friends,
With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...
| |