请问那位大峡给讲解一下用vc写汇编程序

magelfly 2003-08-20 03:10:55
我只知道_asm
{
写,但是al,ah都编译不过

}
...全文
30 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
同桌老王 2003-08-21
  • 打赏
  • 举报
回复
vc中使用inline asm,如果要用call的话,要保证要call的函数在一个asm{}中。如果你要call一个系统函数,比如printf,就不必计较这么多了.
紫郢剑侠 2003-08-21
  • 打赏
  • 举报
回复
要注意申明参数传递约定.
windows3000 2003-08-20
  • 打赏
  • 举报
回复
mark
masterz 2003-08-20
  • 打赏
  • 举报
回复
主  题: 在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

21,458

社区成员

发帖
与我相关
我的任务
社区描述
汇编语言(Assembly Language)是任何一种用于电子计算机、微处理器、微控制器或其他可编程器件的低级语言,亦称为符号语言。
社区管理员
  • 汇编语言
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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