flat assembler
Message board for the users of flat assembler.

Index > Main > What's the calling convention used in fasm source?

Author
Thread Post new topic Reply to topic
acel



Joined: 22 Jul 2012
Posts: 8
acel
There are many procedure calls which accept varies parameters, is there a unified calling convention in fasm source?
Post 02 Oct 2012, 16:21
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777
No assembler defines a specific calling convention, but the standard (stdcall/invoke) is to push parameters backwards for forward access inside of the procedure.

Universal call macro:

Code:
; create successive powers of 2 starting
; at BIT0, from right to left

macro powers [id] {
common idn=0
forward id=1 shl idn
idn=idn+1
}

; call convention flags

powers C.NUMBER, C.FORWARD, C.REVERSE,\
C.DIRECT, C.INDIRECT, C.ADJUST

C.STDCALL  = C.REVERSE+C.DIRECT
C.INVOKE   = C.REVERSE+C.INDIRECT
C.CCALL    = C.REVERSE+C.DIRECT+C.ADJUST
C.CINVOKE  = C.REVERSE+C.INDIRECT+C.ADJUST
C.VARIADIC = C.REVERSE+C.DIRECT+C.NUMBER

C.DEFAULT  = C.STDCALL

; universal call: c/onvention, name, p/arameter/s

macro ucall c,\
name, [p] {
?ps equ p
common ?n=0         ; # parameters
forward ?n=?n+1
common ?size=?n*4   ; total size
if c and C.NUMBER   ; send # parameters?
 push ?n
end if
if ~p eq            ; any parameters?
 if c and C.REVERSE ; push reverse? for
  reverse push p    ; forward access
  common
 else               ; push forward? for
  forward push p    ; reverse access
  common
 end if
end if
if c and C.DIRECT   ; call direct? address,
 call name          ; label, register
else                ; call indirect? pointer,
 call [name]        ; method, import
end if
if c and C.ADJUST   ; balance stack?
 add esp, ?size
end if
}    
Post 03 Oct 2012, 03:36
View user's profile Send private message Reply with quote
acel



Joined: 22 Jul 2012
Posts: 8
acel
Thanks, uart777. I am reading the fasm source code, so I am wondering that whether there are some calling convention in assembler itself which could increase its readability.
Post 03 Oct 2012, 04:08
View user's profile Send private message Reply with quote
JohnFound



Joined: 16 Jun 2003
Posts: 3502
Location: Bulgaria
JohnFound
FASM itself uses register parameter passing to the subroutines.
Post 03 Oct 2012, 05:37
View user's profile Send private message Visit poster's website ICQ Number Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777
acel: Most readable "calling convention" is this Smile LOL.

Code:
f:
; ...
ret

call f    


Last edited by uart777 on 17 Nov 2013, 00:51; edited 1 time in total
Post 03 Oct 2012, 06:28
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17338
Location: In your JS exploiting you and your system
revolution
Be careful when you mention fastcall because it is a defined standard calling convention that is not followed by fasm internally.
Post 03 Oct 2012, 10:03
View user's profile Send private message Visit poster's website Reply with quote
acel



Joined: 22 Jul 2012
Posts: 8
acel
Thanks for you replies. Sounds like fasm used registers to pass parameters, is fixed set and order of registers been used? Such as eax for the first parameter, and ebx for the second one.
Post 03 Oct 2012, 10:45
View user's profile Send private message Reply with quote
Tomasz Grysztar



Joined: 16 Jun 2003
Posts: 7734
Location: Kraków, Poland
Tomasz Grysztar
Does there really need to be a order of parameters? It is a concept of many modern languages and perhaps programmers got so used to it that it may sound as a very bizarre concept when one states that parameters don't have to be ordered in any way... Though there are still some languages (like Python) which at least allow to alternatively use "named parameters" syntax, and there too the order doesn't matter.

Back in the DOS days, when most of the API you used were BIOS and DOS interrupts calls, it was nothing strange for an assembly programmer that different kinds of parameters simply had an "usual" place through which they were passed. For example, DOS interrupt usually expected pointer to some data passed through DS:DX, while a file handle would be passed in BX. Close file function requires a file handle, but doesn't need any data? Use only BX to pass the handle. Write string expects buffer with data, but nothing else? Pass pointer to data in DS:DX as usual. The concept of "first" or "second" parameter is not really applicable here.
Post 03 Oct 2012, 10:58
View user's profile Send private message Visit poster's website Reply with quote
shutdownall



Joined: 02 Apr 2010
Posts: 518
Location: Munich
shutdownall
I don't understand the approach. Every communication regardless between computer or persons (humans) follow a (public or private) convention. If you trained a dog to bring the newspaper, you can not just simply tell him you want the sausage instead when you did not train with him before. Laughing
Post 03 Oct 2012, 11:05
View user's profile Send private message Send e-mail Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17338
Location: In your JS exploiting you and your system
revolution
acel wrote:
Sounds like fasm used registers to pass parameters, is fixed set and order of registers been used? Such as eax for the first parameter, and ebx for the second one.
I think you are trying to apply HLL concepts here. fasm doesn't use the concept of 1st (or any particular) parameter.

edit: I see Tomasz has already explained that.
Post 03 Oct 2012, 11:26
View user's profile Send private message Visit poster's website Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777
revolution: Quote from Wikipedia: "Conventions entitled fastcall have not been standardized, and have been implemented differently, depending on the compiler vendor. Typically fastcall calling conventions pass one or more arguments in registers which reduces the number of memory accesses required for the call".

Please forgive me for being an innovative thinker. I apologize for being a real programmer who actually makes programs instead of a fool who prides themselves in knowing how but has absolutely nothing to show in their lifetime.
Post 03 Oct 2012, 22:04
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777
Sorry Sad


Last edited by uart777 on 04 Oct 2012, 18:37; edited 1 time in total
Post 04 Oct 2012, 08:42
View user's profile Send private message Reply with quote
revolution
When all else fails, read the source


Joined: 24 Aug 2004
Posts: 17338
Location: In your JS exploiting you and your system
revolution
uart777 wrote:
revolution: Primitive minded fool Razz 10,000+ comments and not one single useful program to show.
Yep. I'm just posting nonsense constantly.
Post 04 Oct 2012, 08:43
View user's profile Send private message Visit poster's website Reply with quote
nop



Joined: 01 Sep 2008
Posts: 165
Location: right here left there
nop
revolution wrote:
Yep. I'm just posting nonsense constantly.
yes and you post silly new threads as a mod using other user names not your own like the bitness of a cpu nonsense which i jus asked you to fix again Evil or Very Mad
Post 04 Oct 2012, 17:01
View user's profile Send private message Reply with quote
MazeGen



Joined: 06 Oct 2003
Posts: 977
Location: Czechoslovakia
MazeGen
uart777, nop, you're nobody comparing to revolution's contributions to this board so shut up. revolution should delete your offtopic posts.
Post 04 Oct 2012, 17:43
View user's profile Send private message Visit poster's website Reply with quote
yoshimitsu



Joined: 07 Jul 2011
Posts: 96
yoshimitsu
Tomasz, so what are your criteria for parameters, like what kind of parameter do you place in which register? I'd like to know more about your coding style because it looks so professional and oldschool Wink
btw. did you ever actually publish an article about coding style? I'd love to read it, hehe
Post 04 Oct 2012, 19:00
View user's profile Send private message Reply with quote
nop



Joined: 01 Sep 2008
Posts: 165
Location: right here left there
nop
MazeGen wrote:
uart777, nop, you're nobody comparing to revolution's contributions to this board so shut up. revolution should delete your offtopic posts.
whoa mazegen im just objecting to a thread that revolution created in my user name which imho looks silly thats all Shocked

about parameter passing in registers intel have designed the x86 instuction set with some default ideas in mind like ecx for count values ebx for base data pointer eax for general or alu data edx for general data address ebp for base stack pointer esi and edi for index addreses and so on


Last edited by nop on 04 Oct 2012, 19:37; edited 1 time in total
Post 04 Oct 2012, 19:27
View user's profile Send private message Reply with quote
uart777



Joined: 17 Jan 2012
Posts: 369
uart777
MazeGen: Sorry for being off-topic and offensive Sad but it seems that I get critisized for no reason other than jealousy. revolution claimed that "fastcall" is a defined standard and I merely responded. You let "typedef" get by with murder - he comes here and annoys, disrespects, curses, etc - but I can't defend myself and prove that my position is logical?

Nothing compared to revolution? Behold, the best art/image application ever created in ASM in the history of mankind: http://s1291.photobucket.com/albums/b546/uart777/Programming/?action=view&current=IMAGEEDITOR_zps10525b1d.jpg 100% pure custom controls/interface using only 386 instructions. Only 23K .EXE. I intended to contribute this source code to help programmers make art programs in ASM. Maybe I shouldn't Neutral
Post 04 Oct 2012, 19:30
View user's profile Send private message Reply with quote
nop



Joined: 01 Sep 2008
Posts: 165
Location: right here left there
nop
uart777 your image editor looks awsome Smile only 23k is amazing i would love to see your source
Post 04 Oct 2012, 19:55
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. Also on YouTube, Twitter.

Website powered by rwasa.