hi everyone
 
how to create functions and call them in win32 asm
Posted on 2006-08-28 23:45:43 by AssemblyBeginner
Please use the forum search function as this topic has been covered an enormous amount of times.

Beyond that, your question is way too broad... it is like asking "how does one operate a motor vehicle". You would probably answer by asking "which brand/make/model/etc..." in return.

As you start reading older posts, you will find yourself developing more specific questions... such "as how do I do this for that assembler package", and these type of questions are what is needed for us to successfully guide you... and it shows us that you are making an attempt to learn on your own ;)
Posted on 2006-08-29 00:56:35 by SpooK
Hi AssemblyBeginner,

First, welcome to the wonderful world of assembly language programming. As SpooK said your question is very broad, perhaps more than you realize at this point. So here are a few questions that will help you narrow the search...

1. Are the functions you want to create dynamic or static ? Dynamic functions are contained in a DLL and can be loaded and executed by many applications at the same time, this however creates external dependancies, static functions reside in your executable and creates no dependancies.

2. Do the functions require a variable number of parameters or is the number fixed ? This will help you decide on a calling convention. For a variable number of parameters you would use the C calling convention, for a fixed number the STDCALL convention. In the case of Win64 you would be using the FASTCALL calling convention but I would stick to 32 bit for the time being. The choice of calling convention will also determine what has to be done to fix up the stack after the call, though in both cases MASM will do this automatically for you other assemblers may not.

3. How is the result to be returned ? There are essentially 2 ways to return information from a function, the first and most common is to return a value in EAX or some other register, though EAX is by far the "standard" as Windows uses it for returned values. The other is to pass an address as one of the parameters and fill that address on return, this can also be used in conjunction with register returns.

4. Do you require a stack frame ? Functions without parameters or local variable do not require a stack frame, if they have either you will require one. This is an intermeadiate topic but one that it is never too early to start thinking about.

Donkey
Posted on 2006-08-30 14:39:19 by donkey
flipping heck donkey!
That's one hell of an answer for a one line question! :lol:
Credit to ya
Posted on 2006-08-30 17:53:01 by Nice Eddie

flipping heck donkey!
That's one hell of an answer for a one line question! :lol:
Credit to ya


:lol: Thanks, the problem with searching is that when you're a beginner you don't always know what to search for precisely because you are a beginner. I find that it helps to give a broad answer to this type of question and they can pick out the specifics themselves based on what they need. After all searching for "Function" would return quite a few hits while STDCALL would narrow the search to what he is interested in.
Posted on 2006-08-30 19:35:00 by donkey
thks donkey

i want to create static functiom with fixed no of parameters and return values in eax

Posted on 2006-09-01 01:48:32 by AssemblyBeginner
I think the problem most of the beginner have with the assembly language is that they don't know the fact that a function IS a procedure and vice versa. A function is a procedure in fact because the code you write for a function is exactly the same as what you write for a procedure, although not necessarily. The difference is that a function returns a value in *somewhere* but a procedure doesn't have to do that, although it can. In Win32, the return values of functions are put in the EAX register and you can create a "PROC" so that it can return a value in either the stack, a variable or any of the general purpose registers.

Now look at the below code:

Posted on 2006-09-01 05:06:56 by XCHG
thks xhcg
Posted on 2006-09-01 11:26:56 by AssemblyBeginner