Re: [Dev-C++] assembly (not inline!)
Open Source C & C++ IDE for Windows
Brought to you by:
claplace
|
From: Paul I. <pi...@ot...> - 2004-07-06 19:56:31
|
Quoting Marco Ribeiro <ma...@ne...>: > Hello all, >=20 > =20 >=20 > I wish to know if is there a way to make a function in assembly, compil= e it > in masm and then use it in c++. I search the web but found nothing abou= t it. > My idea is something like linking the masm result with my c++ program. >=20 Have you looked at http://www.masm32.com/ ? A would guess that masm produces a normal object file. Just declare the f= unction as extern C to avoid problem with name-mangling. Hmm... need to try it before saying too much... downloading masm32... (some sounds of your choice to illustrate work) Results: I tried this simple example: .386 .model flat,stdcall option casemap:none include \masm32\include\windows.inc .code asmfunc proc inp:UINT mov eax, (inp) add eax, 10 ret asmfunc endp end linked the resulting .obj (project->project options, parameters add libra= ry or object) with the following: #include <iostream> #include <stdlib.h> extern "C" int asmfunc(int); using namespace std; int main(int argc, char *argv[]) { =20 int x =3D 15;=20 x =3D asmfunc(x);=09 =20 cout << x << endl; =20 system("PAUSE");=09 return 0; } I do get a linker warning, but it does work. So, I guess the answer is yes... |