flat assembler
Message board for the users of flat assembler.

Index > Main > Parameters passing, calling convention

Author
Thread Post new topic Reply to topic
Juras



Joined: 18 Jun 2003
Posts: 23
Location: Belarus
Juras
What calling convention (not only a standard one) would you recommend as the fastest and still bug-safe? I used several particular registers for every function but then decided to keep a kind of standard in order not to make mistakes, keep consistency. E.g. pass params through registers: EAX, EDX, ECX, EBX; return value in EAX; ESI/EDI/EBP are always saved etc... What do you use when write a completely asm-programme?

_________________
Best Regards, Juras aka Exhu (aka YBX)
Post 12 Nov 2004, 18:54
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Matrix



Joined: 04 Sep 2004
Posts: 1171
Location: Overflow
Matrix
i couldn't keep a standard, as some functions are faster if using other registers.
you can only make a standard if you're using stack procedures (stdcall) but it won't be fast,
so decide what whould you like : fast, or uniform.
Post 12 Nov 2004, 19:00
View user's profile Send private message Visit poster's website Reply with quote
Juras



Joined: 18 Jun 2003
Posts: 23
Location: Belarus
Juras
well, there are some register-based parameter-passing techniques:

- FREE PASCAL's 2.0
- Open Watcom's

Probably, I'll choose one of them.
Post 12 Nov 2004, 22:17
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
Frank



Joined: 17 Jun 2003
Posts: 100
Frank
I am writing for Win32 where API calls may destroy the contents of EAX, ECX, EDX, and the flags, but will preserve the contents of EBX, EDI, ESI, EBP, and ESP. It appeared most useful (i.e., least prone to bugs) to have the same subsets of registers destroyed (EAX, EDX, ECX, flags) versus preserved (all others) when calling API-functions as when calling my own functions. So I use the following convention:

First function parameter in EAX, second parameter in EDX, third parameter in ECX, any remaining parameters on the stack (theoretically at least -- I don't recall having any function that requires more than three parameters). Return values: first value in EAX, second one in EDX, third value in ECX.

That's probably similar to Delphi's FASTCALL convention, but I'm not sure about the details.

As an important aid against bugs, there are two different keywords for API-calls versus calls of my own functions (INVOKE vs. FCALL), so that the macro system alerts me during compilation if I mix them up.

Other stuff: Callee (not caller) clears the stack (again, just because API-functions do it so); no stack frame by default (to keep EBP free for the function); avoid RET after CALL (JMP instead -- when passing parameters in registers, that is possible much more often than when passing parameters on the stack). No rule yet for using the coprocessor across calls of my own functions.
Post 13 Nov 2004, 22:47
View user's profile Send private message Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  


< Last Thread | Next Thread >
Forum Rules:
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Copyright © 1999-2020, Tomasz Grysztar.

Powered by rwasa.