0

I was wondering if anyone has a link to a formal grammar for x64 assembly language, as I have been searching online but have not been able to find one. The grammar would ideally be in AT&T syntax and specify which registers, addresses, and values are allowed for each instruction. I am decently skilled at reading formal grammars but assembly language is new to me so I would use it as a reference.

P.S. if this is not the right place to ask this question, please tell me where else I could ask it instead. Thank you.

Agent 008
  • 141
  • 8
  • The only place there might be such a thing is in the GNU as source code. The manual doesn't have a grammar and I'm not sure if there is one anywhere else. – fuz Mar 08 '21 at 22:28
  • There isn't one single *x64 assembly language*. Every assembler has their own variation. Although AT&T syntax is the closest to standard between GNU Binutils, clang's built-in assembler, and so on. But there are quirks like the fact that GAS allows (but now warns about) ambiguous operand-size instructions like `add $1, (%rdi)`, but errors on the same ambiguity for `mov $1, (%rdi)`. Clang correctly rejects both. – Peter Cordes Mar 09 '21 at 01:56
  • 1
    Asm is pretty simple syntactically, the kinds of things you'd learn from an actual formal grammar are I think pretty limited. Better to read the manual like https://www.felixcloutier.com/x86/add to find forms of each insn. Although I guess a formal grammar could help learn addressing modes. https://stackoverflow.com/tags/att/info has some links, e.g. [What is the meaning of MOV (%r11,%r12,1), %edx?](https://stackoverflow.com/q/2883850) and you can omit any of the components like `(%rdi, %rsi)` or `1234(,%rsi,4)` – Peter Cordes Mar 09 '21 at 01:56

0 Answers0