passing data from c to asm

Question about which tools to use, bugs, the best way to implement a function, etc should go here. Don't forget to see if your question is answered in the wiki first! When in doubt post here.
Mastermind

Re:passing data from c to asm

Post 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")
_mark

Re:passing data from c to asm

Post 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
_mark

Re:passing data from c to asm

Post 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()
Mastermind

Re:passing data from c to asm

Post 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?
Tim

Re:passing data from c to asm

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

Re:passing data from c to asm

Post 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!!
Post Reply