vc下如何编译带汇编代码的C程序文件?

azmiao 2003-05-08 11:03:02
vc下如何编译带汇编代码的C程序文件?
如何设置?
TC3下有TASM.EXE编译汇编代码,但是在VC下如何编译?
...全文
27 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
Tue 2003-05-16
  • 打赏
  • 举报
回复
另外变量名也是可以在ASM段中使用的。
taianmonkey 2003-05-11
  • 打赏
  • 举报
回复
收藏!
masterz 2003-05-11
  • 打赏
  • 举报
回复
主  题: 在VC中嵌入汇编程序时遇到call指令时,编译器提示lable错误,该怎么办?
回复人: Focus(老鱼)
asm{
.....
call wrt
}
wrt: asm{or al,80h
call wr2

mov bh,bl
or bh,10000000b ;110xxxxxx:read;110A5------A0(01)
call wr1
and al,7fh ;di=0
out dx,al
mov dx,379h ;????????????????????????
mov cx,0003h
}
wr2:asm{
...
}


If you asm use stdcall like this:
.386
.MODEL flat, stdcall
.CODE
....

Then you should define __stdcall in your C/C++ header file
extern "C" int __stdcall myproc();//notice the __stdcall
add xxx.obj(generated from your asm file) to the VC project by menu Project->Add to project->Files...


memcpy是C的运行时函数,汇编里面调用应该将名字改成_memcpy。同理,对于C的函数名字my_funciton1在目标模块里会变成_my_function1,因此在汇编中也应该将函数名字改成_my_function1、_my_function2。
另外,Borland的目标文件与Mirosoft的目标文件格式可能不兼容(我没试过,不能确信),你最好都用COFF格式。有的函数还要加上比如导入htonl要声明成_htonl@4,后面还要加@4,这个"4"是根据参数的多少确定的

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 masm32V6(you can get it from http://www.movsd.com/masmdl.htm) at D:\masm32
truesideleft 2003-05-10
  • 打赏
  • 举报
回复
VC下嵌入ASM
__asm
{

}

2,586

社区成员

发帖
与我相关
我的任务
社区描述
VC/MFC 资源
社区管理员
  • 资源
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧