flat assembler
Message board for the users of flat assembler.

Index > Main > Functions in Asm

Author
Thread Post new topic Reply to topic
denial



Joined: 12 Sep 2004
Posts: 98
denial
Hi.

I know how to code procedures, but is it also possible to pass a parameterlist?

like in C:

Code:
int function(char* x, int y, float z){...}
    


I would like to use something like this in fAsm like the code below, but of course it doens't work that way Wink But is there a way to do this?

Code:
proc function x rb 50, y dd 0, z dd 0
    


Thank you Smile
Post 27 Nov 2004, 11:27
View user's profile Send private message Reply with quote
roticv



Joined: 19 Jun 2003
Posts: 374
Location: Singapore
roticv
char * is a pointer....

it should be

proc function, x, y, z
Post 27 Nov 2004, 12:30
View user's profile Send private message Visit poster's website MSN Messenger Reply with quote
bogdanontanu



Joined: 07 Jan 2004
Posts: 403
Location: Sol. Earth. Europe. Romania. Bucuresti
bogdanontanu
in C
Code:
My_Function(param_01,param_02, unsigned long * param_03);
    


in TASM:
Code:
Call My_Function STDCALL, [param_01],[param_02], offset param_03
    

you do not need [] arround params if they are scalars: numerical constants, registers etc

in MASM:
Code:
Invoke My_Function, param_01,param_02,addr param_03
    


in FASM:
there are variouse macros that will allow you to do either:
Code:
Call My_Function,[param_01],[param_02],param_03
    

or:
Code:
 STDCALL My_Function, [param_01],[param_02],param_03
    


There are evem more advanced macros in FASM, TASM,MASM that will allow you to do something like this:
Code:
Call My_Function, CSTRING("My first parameter"), Other_Function(other_param),offset param_03
    


However nice those things might look like... IMHO you should start with the basics like
Code:
push param_01
push param_02
push offset param_03
Call My_Function
    


And improve in small steeps until you completly understand what you are doing and using...

Also you should understand about ARGUMENTS and LOCAL variables inside functions ... and function PROTOTYPES

There are also variavle numer of parameters lists like :VARARG for both functions and macros

Usually the macro system of assemblers is much more powerfull than the one of C/C++ (a few magnitule levels better)
Post 27 Nov 2004, 13:39
View user's profile Send private message Visit poster's website Reply with quote
Nikolay Petrov



Joined: 22 Apr 2004
Posts: 101
Location: Bulgaria
Nikolay Petrov
if you interest how translate "C" program of assembler use free bcc32 borland compiler with option "-S", when you compiled "C" or "C++" file - this option generate assempler file with detailed comment. In Windows - header "C" function you will "invoke" from crtdll.dll or msvcrt.dll
Post 27 Nov 2004, 17:35
View user's profile Send private message Reply with quote
gunblade



Joined: 19 Feb 2004
Posts: 209
gunblade
bogdanontanu, shouldnt that be:

Code:
push offset param_03
push param_02
push param_01
call My_Function
    


(as parameters require to be pushed in reverse order)

gunblade
Post 28 Nov 2004, 01:12
View user's profile Send private message Reply with quote
denial



Joined: 12 Sep 2004
Posts: 98
denial
thank your for all your replys Smile
Post 29 Nov 2004, 18:33
View user's profile Send private message Reply with quote
LiuJunfeng



Joined: 28 Nov 2003
Posts: 48
Location: China
LiuJunfeng
I think you are asking how to define a function in fasm, not how to call a function defined in C.

The code in a function starts like this:
Code:
MyFunc:
  push ebp
  mov ebp, esp  ; use ebp as the frame pointer
    


Then push callee save registers to be used and allocate memory on stack for local variables.

Use [ebp+8],[ebp+12]...to access parameters passed to function.
Post 01 Dec 2004, 12:55
View user's profile Send private message Reply with quote
vid
Verbosity in development


Joined: 05 Sep 2003
Posts: 7105
Location: Slovakia
vid
and ends with
Code:
mov esp,ebp
pop ebp
    

like, C's
Code:
int MyFunc(int a,int b)
{
  int loc1,loc2 ;local variables
  return 0
}
    

in asm
Code:
MyFunc:
label b dword at ebp+8
label a dword at ebp+12
label loc1 dword at ebp-4
label loc2 dword at ebp-8
push ebp
mov ebp,esp
sub esp,8 ;8 is size of local variables
... code ...
mov esp,ebp
pop ebp
retn
    

this is low-level structure of procedure. However you can use FASM's standard "proc" macros to have less typing and have few more abilities (like if you don't use procedure anywhere, then it won't be defined, so you'll save some space in executable).
Post 01 Dec 2004, 15:07
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:  


< 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.