linux – GCC错误消息“错误:不支持’mov’”是什么意思?

前端之家收集整理的这篇文章主要介绍了linux – GCC错误消息“错误:不支持’mov’”是什么意思?前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。

我只是想编译一些我从书中输入的简单示例代码,GCC给出了上述错误.这是我的代码

  1. $cat -n test.cpp
  2. 1 #define READ_COMMAND 3
  3. 2
  4. 3 #define MSG_LENGTH 128
  5. 4
  6. 5 #include dio.h>
  7. 7
  8. 8 int main(int argc,char *arg[])
  9. 9 {
  10. 10 int syslog_command = READ_COMMAND;
  11. 11 int bytes_to_read = MSG_LENGTH;
  12. 12 int retval;
  13. 13 char buffer[MSG_LENGTH];
  14. 14
  15. 15 asm volatile(
  16. 16 "movl %1,%%ebx\n\t"
  17. 17 "movl %2,%%ecx\n\t"
  18. 18 "movl %3,%%edx\n\t"
  19. 19 "movl $103,%%eax\n\t"
  20. 20 "int $128\n\t"
  21. 21 "movl %%eax,%0"
  22. 22 :"=r" (retval)
  23. 23 :"m"(syslog_command),"r"(buffer),"m"(bytes_to_read)
  24. 24 :"%eax","%ebx","%ecx","%edx");
  25. 25 if (retval > 0) printf("%s\n",buffer);
  26. 26
  27. 27 }
  28. 28
  29. 29

代码应该调用syslog()系统调用来从内核printk()环形缓冲区读取最后128个字节.以下是有关我的操作系统和系统配置的一些信息:

uname -a:

Linux 3.2.0-26-generic #41-Ubuntu SMP Thu Jun 14 17:49:24 UTC 2012 x86_64 x86_64 x86_64 GNU/Linux

gcc -v:

  1. Using built-in specs.
  2. COLLECT_GCC=gcc
  3. COLLECT_LTO_WRAPPER=/usr/lib/gcc/x86_64-linux-gnu/4.6/lto-wrapper
  4. Target: x86_64-linux-gnu

Configured with: ../src/configure -v –with-pkgversion=’Ubuntu/Linaro 4.6.3-1ubuntu5′ –with-bugurl=file:///usr/share/doc/gcc-4.6/README.Bugs –enable-languages=c,c++,fortran,objc,obj-c++ –prefix=/usr –program-suffix=-4.6 –enable-shared –enable-linker-build-id –with-system-zlib –libexecdir=/usr/lib –without-included-gettext –enable-threads=posix –with-gxx-include-dir=/usr/include/c++/4.6 –libdir=/usr/lib –enable-nls –with-sysroot=/ –enable-clocale=gnu –enable-libstdcxx-debug –enable-libstdcxx-time=yes –enable-gnu-unique-object –enable-plugin –enable-objc-gc –disable-werror –with-arch-32=i686 –with-tune=generic –enable-checking=release –build=x86_64-linux-gnu –host=x86_64-linux-gnu –target=x86_64-linux-gnu

  1. Thread model: posix
  2. gcc version 4.6.3 (Ubuntu/Linaro 4.6.3-1ubuntu5)

下面是完整的错误

  1. $gcc test.cpp
  2. test.cpp: Assembler messages:
  3. test.cpp:25: Error: unsupported for `mov'
最佳答案
您正在尝试在64位计算机上编译32位汇编代码.您列出的内联汇编编译为:

  1. movl -24(%rbp),%ebx
  2. movl %rsi,%ecx <--- error here
  3. movl -28(%rbp),%edx
  4. movl $103,%eax
  5. int $128
  6. movl %eax,%r12d

如您所见,您试图在32位寄存器中存储64位寄存器,这是非法的.更重要的是,这也不是64位ABI系统调用协议.

尝试使用-m32进行编译以强制使用32位ABI.

猜你在找的Linux相关文章