flat assembler
Message board for the users of flat assembler.

Index > Main > varargs with stdcall

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



Joined: 27 Dec 2004
Posts: 805
r22
Octavio - you don't preserve the original value of ebp

varargs are ugly, passing an [array] [size] [static args] is the cleanest implementation but it also has a high overhead.

Quote:

I think you mean ccall. yes, i want to make usage nicer from pure assembly, so you don't need to count arguments sized and write "lea esp, [esp+XYZ]" every time yourself. And I CAN do it, so question is: Is there some reason NOT to do it?

vid - you have to count the arguments anyways if your using some sort of format string you need to make sure it matches up with the number of args you push. But there's no reason not to use your idea for yoru implementation. Although a macro would be just as simple and still arguably pure asm ~ish.
Post 19 Jan 2007, 04:10
View user's profile Send private message AIM Address Yahoo Messenger Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
r22: and don't forget i also support MASM, NASM and YASM, maybe more in future. nice !pure assembly usage! is my goal
Post 19 Jan 2007, 06:22
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
Kain



Joined: 26 Oct 2003
Posts: 108
Kain
Isn't something like this best done at compile time via macros? I believe all the assemblers mentioned have capable macro processors.
Post 19 Jan 2007, 06:30
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
Kain: i don't want to force users to use macros, which they may be unfamiliar with. I am doing library for assembly language, not for assembly language customized with macros. It's matter of opinion.
Post 19 Jan 2007, 22:17
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
i realized that in this specific case (printf-like), i don't need return value, so i can trash return value in EAX. So epiloque code simplified to something like this:

Code:
.r:     lea     eax, [edx-4]  ;eax = pointer to last argument
        pop     edi esi edx   ;restore regs
        pop     ebp           ;restore ebp
        pop     dword [eax]   ;copy return address to place of last argument
        mov     esp, eax      ;move stack pointer there
        retn                  ;and return Wink    


problem is just in case of error, in the middle of function, when you don't already know number if arguments. you have to find all non-escaped "%" in format string and skip appropriate number of dwords... but what wouldn't i do for FASMLIB users. Wink Very Happy


EDIT: realized this works only in case without error. when error is returned, EAX is used Smile

also, it's pretty hard to return in some error case, i am doing my best, but if you mess up format string too much, then it's same as calling function with wrong number of arguments - unbalanced stack.
Post 23 Jan 2007, 23:51
View user's profile Send private message Visit poster's website AIM Address MSN Messenger ICQ Number 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-2020, Tomasz Grysztar. Also on GitHub, YouTube, Twitter.

Website powered by rwasa.