flat assembler
Message board for the users of flat assembler.

flat assembler > Main > Calling Conventions

Goto page Previous  1, 2
Author
Thread Post new topic Reply to topic
DimonSoft



Joined: 03 Mar 2010
Posts: 419
Location: Belarus
Melissa wrote:
If code is pure assembly, I don't see a reason to use cdecl at all

The already mentioned variadic functions. Not that anyone would need them often but in some cases it might be useful/more efficient than building an array of items and passing a single pointer.

Although, frankly speaking, I see no reason using it for something except sprintf-like, and *printf functions are broken by design anyway.
Post 27 Feb 2018, 06:59
View user's profile Send private message Visit poster's website Reply with quote
Melissa



Joined: 12 Apr 2012
Posts: 60
Well, variadic function calling convention is compiler specific, I think.
Post 27 Feb 2018, 23:52
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 419
Location: Belarus
Melissa wrote:
Well, variadic function calling convention is compiler specific, I think.

But cdecl is the common one, for historical reasons.

There’re two things that should be true for a calling convention to allow easy parameter access in variadic functions: access to the parameters should be uniform and address/location of the parameter that defines the actual parameter count (say, format string in printf) should not change with the change of the parameter count. Definitely thousands of conventions can be invented that pass the requirements.
Post 28 Feb 2018, 10:05
View user's profile Send private message Visit poster's website Reply with quote
Furs



Joined: 04 Mar 2016
Posts: 1258
If the caller behaves, there's no reason to have it pop the stack.

You can pop the stack from the callee even with variadic functions, as long as no "extra parameters" are passed (depending on the function, e.g. with printf, more than the amount of % specifiers). Though you'll need a bit of hackery to pull it off in the callee. Wink (of course assuming you can use your own calling convention)
Post 28 Feb 2018, 15:44
View user's profile Send private message Reply with quote
DimonSoft



Joined: 03 Mar 2010
Posts: 419
Location: Belarus
Furs wrote:
If the caller behaves, there's no reason to have it pop the stack.

You can pop the stack from the callee even with variadic functions, as long as no "extra parameters" are passed (depending on the function, e.g. with printf, more than the amount of % specifiers). Though you'll need a bit of hackery to pull it off in the callee. Wink (of course assuming you can use your own calling convention)

That wouldn’t be a cool trick then. One-operand RET is what makes it cool, other stuff would not differ much on x86 from using POPs to access parameters (from the convenience point of view). I mean, we can also sort arrays by randomly mixing the elements and checking if it got sorted but we don’t. Style points rule Smile
Post 28 Feb 2018, 15:55
View user's profile Send private message Visit poster's website Reply with quote
rugxulo



Joined: 09 Aug 2005
Posts: 2309
Location: Usono (aka, USA)
Melissa wrote:
Well, variadic function calling convention is compiler specific, I think.


AFAIK, old K&R C required variadic functions to rely on assembly. But with ANSI C (C89), you finally got stdarg.h (but you can also find varargs.h in some places, albeit not recommended anymore).

I heard once that functions in "standard" C were limited, portably, to only 32 parameters. A quick search shows someone saying it's 31 for C89 but 127 for C99. (Of course, certain implementations may give more.)
Post 28 Feb 2018, 21:51
View user's profile Send private message Visit poster's website Reply with quote
Display posts from previous:
Post new topic Reply to topic

Jump to:  
Goto page Previous  1, 2

< 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-2018, Tomasz Grysztar.

Powered by rwasa.