Re: Design ASM routine to be called from C



On Sun, 12 Jun 2005 21:36:39 +0000 (UTC), "Matt"
<spamtrap@xxxxxxxxxx> wrote in comp.lang.asm.x86:

> Cheok Yan Cheng wrote:
> > Hi, from the PC Assembly Language document written by Paul, I was
> > understand that
> >
> > " C assumes that a subroutine maintains the values of EBX, ESI, EDI,
> > EBP, CS, DS, SS, ES after function call "
> >
> > I hold this rule when I design my ASM subroutine which will be used in
> > C program. For most of the register which is used (for example, EDX)
> > in the subroutine, I didn't explicitly store (push) just after the
> > call, and restore (pop) just before ret.
> >
> > However, I was wondering whether this rule is applicable to all the c
> > compiler (gcc, visual c++......)? Is it an ANSI C standard?
>
> ANSI C doesn't specify which registers are used for what. It doesn't even
> specify how large short, int, & long are. It is convention that we preserve
> the contents of those registers. It is a UNIX standard, and it is a
> convention that the Microsoft platform also follows. There is no requirement
> that every C compiler generate code according to that convention, but for
> practical reasons every popular C compiler for these platforms will.
>
> -Matt

I'm sorry, but this is just plain silly. There is nothing in the
POSIX standard about what register usage is or should be on 32-bit x86
processors. UNIX existed long before the original 8086, let alone the
32-bit processors of today.

There isn't even a standardized ABI across different versions of UNIX
running on the same processor type, in general.

--
Jack Klein
Home: http://JK-Technology.Com
FAQs for
comp.lang.c http://www.eskimo.com/~scs/C-faq/top.html
comp.lang.c++ http://www.parashift.com/c++-faq-lite/
alt.comp.lang.learn.c-c++
http://www.contrib.andrew.cmu.edu/~ajo/docs/FAQ-acllc.html

.



Relevant Pages

  • Re: Recursive Call
    ... On IBM mainframes there was/is a standard linkage convention to be followed ... Register 15 contains the "branch to" address and Register ... this save area at entry to the subroutine. ...
    (comp.lang.cobol)
  • VMI Interface Proposal Documentation for I386, Part 5
    ... to three register arguments. ... of the native instruction set. ... Most of these calls behave as standard C functions, and as such, may ... clobber registers EAX, EDX, ECX, flags. ...
    (Linux-Kernel)
  • Re: multiple threads and volatile
    ... Yet the standard tries to guarantee that your code will work. ... ensured to be copied from memory to register, ... threads conceptual machine nor the POSIX threads conceptual machine ...
    (comp.programming.threads)
  • Re: [PATCH] Generic platform device IDE driver
    ... It's likely that ARM will switch over to using the MMIO resources if ... or we can simply have an element for the spacing interval if you ... Here's the decision matrix for libata: Will the hardware use the standard taskfile push/pull functions like ata_tf_load, ata_tf_read, ata_exec_command, etc.? ... If the hardware requires non-standard I/O accessors, or the register sizes themselves changed, then you must implement your own taskfile I/O ...
    (Linux-Kernel)
  • Questions about @Self (Address of Self)
    ... Under the register convention, Self behaves as if it were declared before ... other parameters (including the additional var parameter sometimes passed ... Self is probably stored on the stack! ...
    (alt.comp.lang.borland-delphi)