calling a asm function with a c function?
Posted: Sun Apr 18, 2010 12:01 pm
Ok , I know how to call an asm function from a c function and visa-versa.
But I only know the above if their is no parameters/arguments being passed.
I have been reading the wiki
http://en.wikipedia.org/wiki/X86_calling_conventions
However I am still haveing trouble.
basically I could declare int i to be a global/external variable and just put the value in that varible before returning but then I would have to always use i to assign the resulting value to another variable.
I am just wondering how they do it int i = func1(3) ;
Basically I want func1 just to take in one argument and return that argument just as a test it is working.
I know the x86 convention is to push the arguments on backwards then call the function.
So I am assuming in the function I would just pop the values
like this func( a , b , c ,d ) ;
func:
pop ax ; gets a
pop bx ; gets b
pop cx ; gets c
pop dx ; gets d
;does what it wants to with the varibles
ret ; returns but how do you return a value?
Unless you assign the value to a varible that is external and global their is know way I can figure it out?
Curious when you are in c and create a function how they break it down in asm to make a value return.
ret doesn't allow you to pass an argument to a varible ...etc
Thanks for any help
But I only know the above if their is no parameters/arguments being passed.
I have been reading the wiki
http://en.wikipedia.org/wiki/X86_calling_conventions
However I am still haveing trouble.
Code: Select all
#include <stdio.h>
int main()
{
int i = func1( 3 ) ;
printf( "Hi this is " + i ) ;
return 0 ;
}
Code: Select all
global _func1
_func1:
pop ax
; don't know what to do here to return the value into int i in main
ret
I am just wondering how they do it int i = func1(3) ;
Basically I want func1 just to take in one argument and return that argument just as a test it is working.
I know the x86 convention is to push the arguments on backwards then call the function.
So I am assuming in the function I would just pop the values
like this func( a , b , c ,d ) ;
func:
pop ax ; gets a
pop bx ; gets b
pop cx ; gets c
pop dx ; gets d
;does what it wants to with the varibles
ret ; returns but how do you return a value?
Unless you assign the value to a varible that is external and global their is know way I can figure it out?
Curious when you are in c and create a function how they break it down in asm to make a value return.
ret doesn't allow you to pass an argument to a varible ...etc
Thanks for any help