Re: Calling convention odd?





"Qyz" wrote:
Hi all,

While doing some asm coding recently I noticed that
when I called _malloc, my ECX register was getting trashed.
I did some digging and was surprised to learn that this is
normal, that callers to C library routines are expected to
save EAX, ECX, and EDX.

Seems to me that if one is doing a lot of such calls,
it is best to not use ECX and EDX for local variables at all,
lest one has to push/pop over and over which is more expensive
than storing data on the stack.

My question is, what is the historical basis for this
practice?

perhaps it came from the original naming of registers
and their dedicated use in most complex instructions:

0 Accumulator
1 Count
2 Data
3 Base
4 Stack Pointer
5 Block Pointer
6 Source Index
7 Destination Index

It seems ironic that given a CPU architecture like
x86 that has so few registers, a practice like this
is in place that discourages use of registers.

I don't use any C-stuff nor the so commen calling convention,
so I got seven registers free for anything desired, but also
then register are used mainly as instructions are designed.

btw: pushad/popad timing isn't too bad (~ like three push/pop-reg).

__
wolfgang


.



Relevant Pages

  • Re: Compiling to the Intel instruction set
    ... the 32-bit registers are completely orthogonal with the only ... but newer x86 processors can ... mov ecx, 100 ... lea esi, ...
    (comp.lang.asm.x86)
  • Re: Calling convention odd?
    ... perhaps it came from the original naming of registers ... Stack Pointer ... Source Index ... you think this supports the choice of volatile registers in the calling ...
    (comp.lang.asm.x86)
  • Re: More information about how parameter are passed, and which registers are save to use in help ple
    ... If no third parameter then probably ecx is free to use. ... In which registers are the parameters passed? ...
    (alt.comp.lang.borland-delphi)
  • Calling convention odd?
    ... my ECX register was getting trashed. ... save EAX, ECX, and EDX. ... x86 that has so few registers, a practice like this ... is in place that discourages use of registers. ...
    (comp.lang.asm.x86)
  • Re: Calling convention odd?
    ... my ECX register was getting trashed. ... is in place that discourages use of registers. ... it can be noted that a good number of historical instructions are hard-coded ... usable as memory base or index, used by a few instructions (movsb, ...
    (comp.lang.asm.x86)