如何在VC中调用asm函数
2011-06-28 21:25
239 查看
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///////////////////////////////
#include "stdafx.h "
#include <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
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///////////////////////////////
#include "stdafx.h "
#include <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
相关文章推荐
- VC多线程中全局函数如何调用对话框类成员变量及成员函数
- 如何将GTK+-2.0的信号、回调处理映射成类成员函数的调用--VC中测试(单类继承)
- 如何将GTK+-2.0的信号、回调处理映射成类成员函数的调用--VC中测试(虚拟继承类及多继承)
- VC中如何调用DLL中的函数
- VC中如何调用DLL中的函数
- 如何在VC中汇编,调用Nasm编写的函数
- Vc中如何调用Dll中的函数(转载)
- 如何在VC中汇编,调用Nasm编写的函数
- 如何在VC中汇编,调用Nasm编写的函数
- VC中如何调用DLL中的函数
- linux-i2c驱动 之 i2c设备层的注册过程probe函数如何被调用分析
- VC调用 JavaScript 难题:如何使当前程序的对象进入脚本
- VC 6中使用不同调用规范的函数在符号文件里的表示方式
- 如何实现虚函数的规则(VC中 C++ virtual 编译规则)
- C++中使用_asm汇编调用动态库函数的一点问题
- C#调用VC的DLL的接口函数参数类型转换一览表
- VC C/C++ 函数调用约定
- xsl 文件如何定义 Javascript 函数并且调用
- 如何做EL表达式能调用的函数-小例子(转)
- 如何保证某个函数只被调用一次