how using assembly and C together

Started by blzbb, April 06, 2008, 02:12:50 PM

Previous topic - Next topic

blzbb

how can i use an assembly funcyion in C
i write two file one in assemble, something like this

.386
.model flat, stdcall
option casemap:none

.code
ftest proc
mov eax, esp
ret
ftest endp
end


and i want use ftest() function in C language

is it possible?

thx

Vortex

Welcome to the forum.

Here is a quick example :

#include <stdio.h>

extern int __stdcall testproc(int x, int y);

int main(int argc,char *argv[])
{
int x=125,y=75;
printf("125 + 75 = %d",testproc(x,y));
return 0;
}


.386
.model flat,stdcall
option casemap:none

.code

testproc PROC x:DWORD,y:DWORD

mov eax,x
add eax,y
ret

testproc ENDP
Code it... That's all...

blzbb

thank you Vortex for your help and your example
now understand how do i do it :)