Page 2 of 2

Re:passing data from c to asm

Posted: Thu Apr 17, 2003 10:51 am
by Mastermind
Wait... what's this "exit()" thingy about? In the main function, exit() is the same as return()... At least they both seem to exit the program...

_mark() :
I think that the "typedef int (*fnptr)(void)" should be "typedef void (*fnptr)(void)"...

Ok. Now I have a working version of mark() and tim's examples. I have a function that receives the fname as a char*. How do I call that from my asm code? I usually do this:

Code: Select all

call _function
But how to pass the var?
Is there any way to do this:

Code: Select all

call _function("something")

Re:passing data from c to asm

Posted: Thu Apr 17, 2003 11:17 am
by _mark
Tim Robinson wrote: You can avoid the warning after exit() if exit() is declared properly. IIRC in gcc it's something like:

Code: Select all

void exit(int) __attribute__((noreturn));
"#include <stdlib>" is much easier to type. After all guys this was just an example of a working function table.

_mark

Re:passing data from c to asm

Posted: Thu Apr 17, 2003 11:25 am
by _mark
Mastermind wrote: Wait... what's this "exit()" thingy about? In the main function, exit() is the same as return()... At least they both seem to exit the program...

_mark() :
I think that the "typedef int (*fnptr)(void)" should be "typedef void (*fnptr)(void)"...

Ok. Now I have a working version of mark() and tim's examples. I have a function that receives the fname as a char*. How do I call that from my asm code? I usually do this:

Code: Select all

call _function
But how to pass the var?
Is there any way to do this:

Code: Select all

call _function("something")
typedef int (*fnptr)(void)
is a pointer to function with no parameters returning an int

typedef void (*fnptr)(void)
would be a pointer to a function with no parameters returning void

typedef long (*fnptr)(int,char*)
would be a pointer to a function take an int and char * parameter returning a long.

To call your lookup routine from ASM, just:
[EXTERN _myfnlookup]
CALL _myfnlookup

good luck
_mark()

Re:passing data from c to asm

Posted: Thu Apr 17, 2003 11:32 am
by Mastermind
Wait... How do you CALL a function in ASM with parameters? Like, if you have this c function:

Code: Select all

int function(double arg);
You could do CALL _function, but how to pass the double arg?

Re:passing data from c to asm

Posted: Thu Apr 17, 2003 1:52 pm
by Tim
It's easier to explain with integer or pointer parameters (floats and doubles are another topic).

Just PUSH the parameters right-to-left, then use the CALL instruction, and ADD ESP, <number of parameters>*4 after that. NASMDOC.TXT should explain everything.

Re:passing data from c to asm

Posted: Fri Apr 18, 2003 8:08 am
by Mastermind
Tim Robinson wrote: It's easier to explain with integer or pointer parameters (floats and doubles are another topic).

Just PUSH the parameters right-to-left, then use the CALL instruction, and ADD ESP, <number of parameters>*4 after that. NASMDOC.TXT should explain everything.
Tim:
Where can I obtain NASMDOC.TXT? Is it in the NASM distrib package? And you give an example with integer parameters? Thanks!!