What does AT&T syntax do about ambiguity between other mnemonics and operand-size suffixes?

谁说我不能喝 提交于 2021-02-05 07:12:05

问题


In AT&T syntax instructions often have to be suffixed with the appropriate operand size, with q for operations on 64-bit operands. However in MMX and SSE there is also movq instruction, with the q being in the original Intel mnemonic and not an additional suffix.

So how will this be represented in AT&T? Is another q suffix needed like

movqq %mm1, %mm0
movqq %xmm1, %xmm0

or not?

And if there are any other instructions that end like AT&T suffixes (like paddd, slld), do they work the same way?


回答1:


AT&T syntax basically doesn't do anything about conflicts between mnemonic+suffix vs. other mnemonics. Register operands always disambiguate between a mov mnemonic with a q operand-size suffix vs. the movq mnemonic

movq %xmm0, %xmm0, movq %rax, %xmm0, and movq %xmm0, %rax are 3 different opcodes that all use the same mnemonic (movq in both Intel and AT&T syntax).

A suffix is not allowed on the movq mnemonic: Error: invalid instruction suffix for 'movq'. This is normal because there's no possible ambiguity with respect to operand-size. movq always moves 64 bits, so a q suffix would be redundant.


Does this make parsing AT&T harder than parsing Intel syntax? Well before MMX even existed (thus also before x86-64), movl was still the mnemonic for 6 different opcodes (Intel's insn set ref manual entry for mov lists them all, with their numeric opcode):

  • MOV r/m32,r32
  • MOV r32,r/m32 (assembler can choose either opcode if both operands are regs)
  • MOV r32, imm32 (short form)
  • MOV r/m32, imm32 (with a modr/m, usable for memory operands).
  • also MOV moffs32,EAX and MOV EAX,moffs32, as an optimization (no ModR/M) for storing/loading with a 32-bit absolute address.

And that's not counting mov to/from segment, control, and debug registers. Just like with movq %xmm0, %rax, AT&T syntax has always had to deal with mov %ds, %ax.

Adding a few more forms with different registers to disambiguate is probably not much harder to parse.


Besides that, operand-size suffixes are optional when registers determine the operand-size anyway. mov %rax, %rcx is legal, and a suffix is only needed for moving an immediate to memory. mov $1, (%rsi) is illegal because neither operand implies an operand-size, and there's no suffix to make it explicit.




回答2:


movq was introduced with MMX to facilitate movement of quadwords between MMX registers and non-MMX registers. It's a general-purpose opcode; you can move a quadword between an mmx register and any other register (mmx or non-mmx), or even between non-mmx registers.

In other words, there aren't two different opcodes. Consequently, the syntax is always movq.



来源:https://stackoverflow.com/questions/27990177/what-does-att-syntax-do-about-ambiguity-between-other-mnemonics-and-operand-siz

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