为什么我的C ++内联程序无法正常工作? [英] Why isn't my inline assembly in C++ working?

查看:58
本文介绍了为什么我的C ++内联程序无法正常工作?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

最奇怪的错误输出:

#include <iostream>
int main(int arg, char **LOC[])
{
asm
(
"mov eax, 0CF;"
"pusha;"
);
return 0;
}

它抱怨了,这是GCC的错误:

It complains, and here is the error from GCC:

t.s:汇编程序消息:

t.s: Assembler messages:

t.s:31:错误:'mov'的内存引用过多

t.s:31: Error: too many memory references for `mov'

推荐答案

由于程序集格式错误,您会收到此错误.寄存器访问的完成方式类似于%eax$用于立即操作数.此外,默认情况下,GCC(请参阅DanielKO的评论)使用AT& T语法,该语法的目的地在右侧,而源在左侧.这是您要找的吗?

You get this error because your assembly is malformatted. Register accesses are done like %eax, $ is used for immediate operands. Furthermore, GCC, by default (see DanielKO's comment), uses the AT&T syntax, which has the destination on the right and the source on the left. Is this what you are looking for?

mov $0xcf, %eax

此外,您的pusha是不平衡的,即在从函数返回之前,您没有正确清理堆栈.很高兴知道您的总体目标是什么,因为现在看来您仅复制并粘贴了部分不完整的源代码.

Also, your pusha is unbalanced, ie you don't clean up the stack correctly before you return from your function. It would be nice to know what your overall goal is, because right now it seems like you copied and pasted only an incomplete fraction of the source.

这篇关于为什么我的C ++内联程序无法正常工作?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆