473,395 Members | 1,696 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,395 software developers and data experts.

Saving registers in C functions

Yan
Hi.

I found weird gcc/vc behaviour when generating functions code.
According to the docs I read, C functions don't save any registers
except ebp (on x86), but I see that both gcc and cl (VC++) seem
to save ebx, esi and edi while inside functions - even with
optimizations. I wonder if this is one of the "language extensions"
that these compilers offer, or is it some part of standard C behaviour
I overlooked in docs?
The way I know there should be stack frames (push ebp, mov ebp, esp ...)
in functions, but both gcc and cl don't create those, so is this register
saving thing part of that "non-standard" behaviour?

Yan
Nov 14 '05 #1
2 1960

"Yan" <Ya*****@hotmail.com> a écrit dans le message de
news:37**************************@posting.google.c om...
Hi.

I found weird gcc/vc behaviour when generating functions code.
According to the docs I read, C functions don't save any registers
except ebp (on x86), but I see that both gcc and cl (VC++) seem
to save ebx, esi and edi while inside functions - even with
optimizations. I wonder if this is one of the "language extensions"
that these compilers offer, or is it some part of standard C behaviour
I overlooked in docs?
You are at the assembly language level here

Assembly conventions rule here. Gcc saves ebx,esi,edi as all
other compilers in the x86 world. Think a bit about it. All the
software under linux/windows assumes that values stored
in ebx/esi/edi are preserved across calls. To make different programs
interoperate, it is essential that the same conventions are respected
by all compilers.
The way I know there should be stack frames (push ebp, mov ebp, esp ...)
in functions, but both gcc and cl don't create those, so is this register
saving thing part of that "non-standard" behaviour?


gcc and many other compilers will create a stack frame when
optimizations are not enabled. Sometimes, the compiler
discovers that a stack frame is not really needed, and
eliminates it. This is a normal optimization that makes
the code faster but less debuggable.

Nov 14 '05 #2

"Yan" <Ya*****@hotmail.com> wrote in message
I found weird gcc/vc behaviour when generating functions code.
According to the docs I read, C functions don't save any registers
except ebp (on x86), but I see that both gcc and cl (VC++) seem
to save ebx, esi and edi while inside functions - even with
optimizations.
ANSI C itself doesn't define how functions are to be written. On most
platforms there is a register usage convention for sharing information
between register, and compilers should adhere to that.
I wonder if this is one of the "language extensions"
that these compilers offer, or is it some part of standard C
behaviour I overlooked in docs?
It's nothing to do with the C language. You need to ask on a Wintel group
why the compiler seems to be saving registers unnecessarily.
The way I know there should be stack frames (push ebp, mov ebp, > esp ...) in functions, but both gcc and cl don't create those, so is this register saving thing part of that "non-standard" behaviour?

It could well be that parameters are being passed in registers instead of on
the stack. This sort of detail generally doesn't matter, unless you want to
call a C function from assembly.
Nov 14 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: Ruby Deepdelver | last post by:
Hello, I'm having trouble in find certain information, i've search over the web and through the documentation but i haven't had lucky. I need to know if there is some limit in the amount of...
5
by: volvox | last post by:
hi, is it possible to access protected mode registers (EAX , EBX,ECX...) via assembly in C .
0
by: Chirag Shukla | last post by:
Colleagues, I wanted to share a function to find if a date is in Daylight Saving Time or not. I was able to make this function faster than reading MSDN to find functions that .NET provides. I...
3
by: jefftyzzer | last post by:
Friends: I have a stored procedure declared as: CREATE PROCEDURE X.Y LANGUAGE SQL DYNAMIC RESULT SETS 1 READS SQL DATA SPECIFIC Y INHERIT SPECIAL REGISTERS
2
by: neat2006 | last post by:
This is somewhat of a strange issue. Allow me to detail it as much as I can. We use the Blackboard Transaction System (BTS) for all students dinning services. The "ENVISION" server is Running...
0
by: neat2006 | last post by:
This is somewhat of a strange issue. Allow me to detail it as much as I can. We use the Blackboard Transaction System (BTS) for all students dinning services. The "ENVISION" server is Running...
0
by: neat2006 | last post by:
This is somewhat of a strange issue. Allow me to detail it as much as I can. We use the Blackboard Transaction System (BTS) for all students dinning services. The "ENVISION" server is Running...
4
by: Ismail | last post by:
Hello, I am using asp.net20 membership. I have some properties in web.config <properties> <add name="FirstName" type="System.String" allowAnonymous="true"/> <add name="LastName"...
16
by: dspfun | last post by:
In general, how do you read contents of the CPU's registers and how do you get hold of the addresses of the CPU's registers?
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
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...
0
marktang
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,...
0
Oralloy
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,...
0
jinu1996
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...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
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...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.