Why isn't my inline assembly in C++ working?

我的梦境 提交于 2019-12-06 13:01:11

问题


Strangest error output:

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

It complains, and here is the error from GCC:

t.s: Assembler messages:

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


回答1:


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

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.



来源:https://stackoverflow.com/questions/19778272/why-isnt-my-inline-assembly-in-c-working

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!