内联汇编求助

ustc2007 2011-03-14 01:50:27
#include "stdio.h"
int main( int argc, char* argv[])
{
int cpu_iid;

__asm__ __volatile__(
"mov %0, 1\n"
:"=m"(cpu_iid)
:
);
}

$gcc test.c -o a.out
test.c: Assembler messages:
test.c:6: Error: too many memory references for `mov'

这是怎么回事,哪里错了?
谢谢
...全文
663 6 打赏 收藏 转发到动态 举报
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
bluejays 2011-03-15
  • 打赏
  • 举报
回复
[Quote=引用 4 楼 ustc2007 的回复:]
test.c:7: Error: no instruction mnemonic suffix given and no register operands; can't size instruction
[/Quote]
这里是在用mov给一个内存单元赋值为一个立即数,需要指定这个内存单元的大小,是1个、2个、还是4个字节
AT&T汇编里面是用 movb(byte) movw(word) movl(long)
bluejays 2011-03-15
  • 打赏
  • 举报
回复
"movl $1, %0\n"
ustc2007 2011-03-15
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 bluejays 的回复:]

引用 2 楼 ustc2007 的回复:
我掉换顺序之后仍然不对。

我用gcc编译你的代码得到同样的错误,编译1楼的就通过了。
掉换顺序之后还是原来的错误,还是别的错误?
不只是要掉换顺序。 movl $1都改过来了吗?
[/Quote]

两种都在这里,都有错误:

#include "stdio.h"
int main( int argc, char* argv[])
{
int cpu_iid;

__asm__ __volatile__(
"mov 1, %0\n"
:"=m"(cpu_iid)
:
);
}
$gcc test.c -o a.out
test.c: Assembler messages:
test.c:7: Error: too many memory references for `mov'



#include "stdio.h"
int main( int argc, char* argv[])
{
int cpu_iid;

__asm__ __volatile__(
"mov $1, %0\n"
:"=m"(cpu_iid)
:
);
}

$gcc test.c -o a.out
test.c: Assembler messages:
test.c:7: Error: no instruction mnemonic suffix given and no register operands; can't size instruction

bluejays 2011-03-14
  • 打赏
  • 举报
回复
[Quote=引用 2 楼 ustc2007 的回复:]
我掉换顺序之后仍然不对。
[/Quote]
我用gcc编译你的代码得到同样的错误,编译1楼的就通过了。
掉换顺序之后还是原来的错误,还是别的错误?
不只是要掉换顺序。 movl $1都改过来了吗?
ustc2007 2011-03-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 bluejays 的回复:]

"movl $1, %0\n"
gcc好像是只支持AT&T格式的汇编吧
[/Quote]

我掉换顺序之后仍然不对。
bluejays 2011-03-14
  • 打赏
  • 举报
回复
"movl $1, %0\n"
gcc好像是只支持AT&T格式的汇编吧

23,125

社区成员

发帖
与我相关
我的任务
社区描述
Linux/Unix社区 应用程序开发区
社区管理员
  • 应用程序开发区社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

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