Pelles C forum

C language => Expert questions => Topic started by: blzbb on April 06, 2008, 02:12:50 PM

Title: how using assembly and C together
Post by: blzbb on April 06, 2008, 02:12:50 PM
how can i use an assembly funcyion in C
i write two file one in assemble, something like this

Code: [Select]
.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
Title: Re: how using assembly and C together
Post by: Vortex on April 07, 2008, 07:40:38 PM
Welcome to the forum.

Here is a quick example :

Code: [Select]
#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;
}

Code: [Select]
.386
.model flat,stdcall
option casemap:none

.code

testproc PROC x:DWORD,y:DWORD

mov eax,x
add eax,y
ret

testproc ENDP
Title: Re: how using assembly and C together
Post by: blzbb on April 07, 2008, 09:04:29 PM
thank you Vortex for your help and your example
now understand how do i do it :)