vc中嵌入汇编的一个问题?

lizilily 2004-08-26 04:26:45
我想在vc中加入下面的汇编语言程序,这是我的汇编程序,void HDOutWord(WORD Addr,WORD Value)
{
asm{
push dx
push ax
mov dx,Addr
mov ax,Value
#ifndef _DEBUG_HD_
out dx,ax
#endif
pop ax
pop dx
}
}
结果编译时候出现错误:
E:\2004.8.26\Control.cpp(15) : error C2065: 'push' : undeclared identifier
E:\2004.8.26\Control.cpp(15) : error C2146: syntax error : missing ';' before identifier 'dx'
E:\2004.8.26\Control.cpp(15) : error C2065: 'dx' : undeclared identifier
E:\2004.8.26\Control.cpp(15) : error C2146: syntax error : missing ';' before identifier 'push'
E:\2004.8.26\Control.cpp(16) : error C2146: syntax error : missing ';' before identifier 'ax'
E:\2004.8.26\Control.cpp(16) : error C2065: 'ax' : undeclared identifier
E:\2004.8.26\Control.cpp(16) : error C2146: syntax error : missing ';' before identifier 'mov'
E:\2004.8.26\Control.cpp(16) : error C2065: 'mov' : undeclared identifier
等等,我不知道这是什么原因,是没有包含头文件之类吗?若是应该是什么文件?
...全文
94 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
双杯献酒 2004-08-27
  • 打赏
  • 举报
回复
// VC 6.0
#include <iostream>

using namespace std;
int Add(int x,int y)
{
int retX = 0;
__asm
{
mov eax,x
add eax,y
mov retX,eax
}
return retX;
}
void main()
{
int A = Add(100,200);
cout << "A= " << A <<endl;

}
// 输出:
// A= 300
xlt123 2004-08-27
  • 打赏
  • 举报
回复
在win32下,push,pop指令必须操作32位的数据
也就是说push dx ,push ax得换成push edx,push eax
还有,在ring3下不能访问端口,in,out指令会出错
Avoid 2004-08-26
  • 打赏
  • 举报
回复
你没加__这个下划线当然编译通不过了。__asm才是关键字,asm什么都不是。编译器把asm当作变量了。。。

2,640

社区成员

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

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