使用嵌入式汇编器编译错误
我不明白为什么这段代码
#include <iostream>
using namespace std;
int main(){
int result=0;
_asm{
mov eax,3;
MUL eax,3;
mov result,eax;
}
cout<<result<<endl;
return 0;
}
显示以下错误。
1>c:\users\david\documents\visual studio 2010\projects\assembler_instructions\assembler_instructions.cpp(11): 错误 C2414: 操作数数量非法
一切看起来都很好,但为什么我会收到此编译器错误?
I don't understand why this code
#include <iostream>
using namespace std;
int main(){
int result=0;
_asm{
mov eax,3;
MUL eax,3;
mov result,eax;
}
cout<<result<<endl;
return 0;
}
shows the following error.
1>c:\users\david\documents\visual studio 2010\projects\assembler_instructions\assembler_instructions.cpp(11): error C2414: illegal number of operands
Everything seems fine, and yet why do I get this compiler error?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
根据此页,
mul
指令只需要一个单一参数:According to this page, the
mul
instruction only takes a single argument:因此,请按照贾斯汀的链接进行注释:
Thus following the notes as per Justin's link:
使用:
或:
这样你就不需要担心 edx -register 被破坏。它是“有符号整数乘法”。你似乎有 'int' -结果,所以无论你使用 mul 还是 imul 都不重要。
有时,我会因除法或乘法时未将 edx 寄存器清零而出现错误。 CPU 是 Intel core2 四核 Q9550
您可以阅读一些过度设计但正确的 Intel 指令参考手册。尽管英特尔不久前破坏了其网站。不过,您可以尝试从 AMD 网站找到相同的参考手册。
更新:我找到了手册:http://www.intel.com/design /pentiumii/manuals/243191.htm
我不知道他们什么时候会再次破坏他们的网站,所以你真的总是需要搜索它。
更新2:啊啊!这些都是 1999 年的……不幸的是,大多数细节都是一样的。
Use:
or:
That way you don't need to worry about edx -register being clobbered. It's "signed integer multiply". You seem to have 'int' -result so it shouldn't matter whether you use mul or imul.
Sometimes I've gotten errors from not having edx register zeroed when dividing or multiplying. CPU was Intel core2 quad Q9550
There's numbingly overengineered but correct intel instruction reference manuals you can read. Though intel broke its websites while ago. You could try find same reference manuals from AMD sites though.
Update: I found the manual: http://www.intel.com/design/pentiumii/manuals/243191.htm
I don't know when they are going to again break their sites, so you really always need to search it up.
Update2: ARGHL! those are from year 1999.. well most details are unfortunately the same.
您应该下载英特尔架构手册。
http://www.intel.com/products/processor/manuals/
对于您的目的,第 2 卷将对您有最大帮助。
截至 2010 年 7 月访问时,它们是最新的。
You should download the Intel architecture manuals.
http://www.intel.com/products/processor/manuals/
For your purpose, volume 2 is going to help you the most.
As of access in July 2010, they are current.