您的位置:首页 > 其它

vc中使用汇编asm文件

2008-05-27 10:25 260 查看
use ASM and CPP together:
1. create an ASM file
;;;;;;;;;;;;; asmsrc.asm:
.386
.model flat, stdcall
option casemap :none
.code

myasmproc proc dw1:DWORD,dw2:DWORD
mov eax,dw1
add eax,dw2
ret
myasmproc endp
end
;;;;;;;;;;;;end of asmsrc.asm

2. create a VC project name: useasm, type console application, A "Hello World" application

3. move the asm file to your project directory, then in VC project menu->Add to Project...->Files...
Files of type change to "all files", then you can select the asmsrc.asm, and click OK

4.in workspace window, FileView tab, select asmsrc.asm, right click to select "settings..." menu, custom build tab, put the following in commands edit box :
d:/masm32/bin/ml.exe /nologo /coff /Zf /c /Sa $(InputName).asm
put the following in Outputs edit box:
$(InputName).obj

5.edit your useasm.cpp as the following:
//////////////////////useasm.cpp///////////////////////////////
#i nclude "stdafx.h"
#i nclude <windows.h>
extern "C" int __stdcall myasmproc(DWORD d1,DWORD d2);
int main(int argc, char* argv[])
{
printf("test of using cpp and asm together, if it works, it is done by masterz,otherwise I don't know who write this^_^/n");
int ret=myasmproc(22,33);
printf("ASM result:%d/n",ret);
return 0;
}

//////////////////////end of useasm.cpp///////////////////////////////

6. build the project and run it, it works.

notes: I assume you have installed masm32V8(you can get it from http://www.movsd.com/masmdl.htm) at D:/masm32

http://www.oioj.net/blog/user2/16215/archives/2005/103563.shtml
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: