This is my very simple FASM code:

format MS COFF
include ''

public _demo

section '.code' code readable executable
proc _demo, MyVar
mov eax, 02

then i link the obj file to a C program:

#include <stdio.h>
#include <stdlib.h>

extern "C"
void demo(int);

int main(){
int i = 0;

return 1;

The program works, but during execution it complains that the argument count or whatever is wrong:
"The value of ESP was not properly saved across a function call..." Anyway, my point is, can some1 explain to me how FASM procedure arguments work, are the vars passed by value or address, or what? This info isnt in the FASM doco unfortunately. Thanks.
Posted on 2003-03-10 06:01:27 by osushkov
you're defining your routine as stdcall which takes care of the stackpointer inside the routine. C based languages expect to take care of the stackpointer themselves (caller, not called).

So don't make it a stdcall routine :)
Posted on 2003-03-10 06:15:34 by Hiroshimator
That's right, use CDECL.INC instead of STDCALL.INC
Posted on 2003-03-10 07:51:44 by Tomasz Grysztar
Ok thanks, ill try that when i get home, but also, is the assembler proc take the input values as call by value or call by reference. As in, in the above example. will MyVar be the actual value of the variable (in this case i = 0), or the address of the variable, in this case i. Also, if it isnt call by reference, then how do i return a value of some calculation? Because my goal is to write samothing like
result = AssemblerProc(input); in C, and then AssemblerProc is an assembler procedure. Currently i have no idea how to return a value from an assembler proc.
Posted on 2003-03-10 22:07:16 by osushkov
The names of procedure arguments are labels in the stack area pointed by EBP. So to get the value of MyVar argument in your proc to EAX you should use "mov eax," instruction, to get an address of it into EAX, use "lea eax," - because "mov eax,MyVar" won't work as it is the same as trying to assemble "mov eax,ebp+8" - there's no such x86 instruction.
Posted on 2003-03-11 04:16:54 by Tomasz Grysztar
Ok, thanks, it works now. Also, I assume there wouldnt be any problems passing floats to procedures and using the same technique to extract the value...
Posted on 2003-03-12 03:45:20 by osushkov