NO

Author Topic: how using assembly and C together  (Read 3454 times)

blzbb

  • Guest
how using assembly and C together
« 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

Offline Vortex

  • Member
  • *
  • Posts: 802
    • http://www.vortex.masmcode.com
Re: how using assembly and C together
« Reply #1 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
Code it... That's all...

blzbb

  • Guest
Re: how using assembly and C together
« Reply #2 on: April 07, 2008, 09:04:29 PM »
thank you Vortex for your help and your example
now understand how do i do it :)