使用Clang的指令movq的操作数无效 [英] Invalid operand for instruction movq using clang

查看:390
本文介绍了使用Clang的指令movq的操作数无效的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在具有LLVM的clang-902.0.39.1编译器的Intel Core i5上使用了movq X86_64汇编指令.

I'm using the movq X86_64 assembly instruction on an Intel Core i5 with the LLVM-based clang-902.0.39.1 compiler.

Intel语法中的简化代码(位于my_asm.S文件中)如下所示:

The simplified code (at the my_asm.S file) in Intel syntax looks like this:

.intel_syntax noprefix

#define a_const   0xFFFFFFFFFFFFFFFF

movq   rax, a_const

我正在使用

clang -c -g -O3 -fwrapv -fomit-frame-pointer -march=native my_asm.S

编译器给我以下消息:

错误:指令的无效操作数
movq rax,0xFFFFFFFFFFFFFFFFFF
^

error: invalid operand for instruction
movq rax, 0xFFFFFFFFFFFFFFFF
^

我还尝试了注释中建议的AT& T语法:

I've also tried the AT&T syntax as suggested in the comments:

movq   $a_const, %rax

出现错误

错误:表达式中的未知标记
movq $ 0xFFFFFFFFFFFFFFFFFF,%rax
^

error: unknown token in expression
movq $0xFFFFFFFFFFFFFFFF, %rax
^

该指令用于Intel语法,因为我包括了 我的.S文件开头的.intel_syntax noprefix标志. 在更新Mac OS(更新LLVM编译器,链接器和Make)后,似乎开始显示错误消息.

This instruction was used to work for Intel syntax since I included the .intel_syntax noprefix flag in the beginning of my .S file. It seems that the error message started showing up after I updated my Mac OS (which updated the LLVM compiler, linker and Make).

有人知道这可能是什么原因吗?

Does anyone have a clue on what might be causing this?

推荐答案

使用AT& T语法为mov $-1, %raxmov $0xFFFFFFFFFFFFFFFF, %raxmovq为我工作,而不是隐含操作数大小.

Works for me in AT&T syntax with mov $-1, %rax or mov $0xFFFFFFFFFFFFFFFF, %rax, or with movq instead of leaving operand-size implicit.

在Intel语法中,您不能再使用操作数大小的后缀q来设置操作数大小;它由寄存器或在内存操作数上的qword ptr覆盖表示.

In Intel syntax, you can no longer use an operand-size q suffix to set the operand-size; it's implied by the register or with a qword ptr override on a memory operand.

movq是类似movq xmm0, raxmovq xmm0, xmm1的指令的助记符(两个单独的操作码/指令集手动条目都使用movq助记符,一个是REX形式的movd xmm, r/m32,另一个是xmm/mmx movq xmm, xmm/m64)

movq is the mnemonic for instructions like movq xmm0, rax or movq xmm0, xmm1 (two separate opcodes / instruction set manual entries that both use the movq mnemonic, one being the REX form of movd xmm, r/m32, and the other being the xmm/mmx movq xmm, xmm/m64)

mov    $-1, %rax
mov    $0xFFFFFFFFFFFFFFFF, %rax

.intel_syntax noprefix
mov    rax, -1
mov    rax, 0xFFFFFFFFFFFFFFFF

clang -c可以很好地汇编为同一指令的4个副本:

assembles just fine with clang -c, to 4 copies of the same instruction:

0:   48 c7 c0 ff ff ff ff    mov    rax,0xffffffffffffffff

请注意,-f...-O3代码生成选项仅在组装,不编译C/C ++时不起作用,-march=native也不起作用. Clang的汇编器不限制基于-march的指令选择;它仅设置编译器的代码源将面向的对象. (您没有给伤害提供任何选项,但是除了-g以外,它们对.S没有任何作用.)

Note that -f... and -O3 code-gen options have no effect when only assembling, not compiling C/C++, nor does -march=native. Clang's assembler doesn't restrict instruction choice based on -march; it only sets what the compiler's code-gen will target. (None of the options you gave hurts, but they have no effect with a .S except for maybe -g.)

这篇关于使用Clang的指令movq的操作数无效的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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