1

I was trying to understand some assembly code for x86 written to be assembled using the GNU's assembler - GAS .
Can anyone suggest some ref. for looking up the syntax for the opcodes/mnemonics in GAS.

Peter Cordes
  • 328,167
  • 45
  • 605
  • 847
HungryFoolish
  • 542
  • 1
  • 9
  • 27
  • That was easy: https://www.sourceware.org/binutils/docs-2.12/as.info/index.html. The opcodes can be downloaded from [Intel](http://www.intel.com/content/www/us/en/processors/architectures-software-developer-manuals.html), although they use the Intel syntax, while (G)AS uses the AT&T syntax: http://www.imada.sdu.dk/Courses/DM18/Litteratur/IntelnATT.htm – Rudy Velthuis Oct 07 '16 at 15:20
  • @RudyVelthuis: not all the opcodes are identical. e.g. AT&T uses `movzbl` / `movzwl` / etc. instead of the same `movzx` mnemonic for all combinations of operand-size. The suffix (w/l/q) works like normal in AT&T syntax, determining the destination operand-size (and can be inferred from the register), but `movzb` and `movzw` are separate mnemonics for the separate opcodes. There probably is a complete insn set reference for AT&T syntax somewhere, but I'm not sure where, and it would be nice to have a link to one for the [x86 tag wiki](http://stackoverflow.com/tags/x86/info). – Peter Cordes Oct 07 '16 at 16:46
  • 2
    Anyway, failing that you can always assemble something with NASM (using Intel mnemonics) and disassemble it using `objdump -d` to get AT&T syntax. – Peter Cordes Oct 07 '16 at 16:46
  • @PeterCordes: I see the `b`, `w`, `l`and `q` as suffixes to the general opcodes as described by Intel. In other words, in my view they are part of the syntax, not of the opcode. – Rudy Velthuis Oct 07 '16 at 18:12
  • @RudyVelthuis: That's a valid way of looking at it, but that makes the mnemonic `movz`, not MOVZX. It's also not how it actually behaves in detail in gas. (I.e. it will infer the `w` / `l` / `q` operand size from the destination register size, but won't infer the `b` / `w` / `l` opcode choice from the source register size. AMD decided that MOVSXD would be special, but it isn't in AT&T). There are other differences, too: `movabs` for the forms of MOV with a 64-bit immediate or 64-bit absolute address and `cltq` instead of CDQ (although I think `cdq` is recognized as a synonym). – Peter Cordes Oct 07 '16 at 19:26
  • @PeterCordes: so there are a few exceptions. – Rudy Velthuis Oct 07 '16 at 19:57
  • @RudyVelthuis: yeah. Normally it works fine to use the Intel mnemonic from the manual, and just reverse the order of the operands (no matter how many operands there are, always just reverse them). But there are gotchas, so assembling with NASM / disassembling with `objdump` can help to sort that out. Oh, same for the known AT&T syntax bug (with non-commutative FP ops like `fdiv` vs. `fdivr`: https://sourceware.org/binutils/docs/as/i386_002dBugs.html). – Peter Cordes Oct 07 '16 at 20:02
  • 1
    Actually, whoever at AT&T thought it was a good idea to have an alternative syntax, when there was an already existing Intel syntax, and to make the syntax so different as well? Tsk, tsk, tsk. – Rudy Velthuis Oct 07 '16 at 20:34
  • 1
    @RudyVelthuis, as much as I loath PDP11 syntax. To be fair AT&T predated Intel by quite a few years. The PDP11 was introduced in '70 and the 8086 in '78. Oops '67 so actually more than a decade before. Unix was born on the PDP11 and so was AT&T syntax. – Johan Oct 07 '16 at 23:21
  • You can also get GAS to accept Intel syntax with `.intel_syntax noprefix`, don't forget to put the default back after you're done: `.att_syntax noprefix` http://stackoverflow.com/questions/9347909/can-i-use-intel-syntax-of-x86-assembly-with-gcc – Johan Oct 07 '16 at 23:28
  • I don't mind that they used a different syntax for a different processor (whatever the DEC PDP11 used). For a new processor range, it doesn't make sense to use an opcode syntax that does not match the original syntax of that producer, IMO. – Rudy Velthuis Oct 07 '16 at 23:33
  • 1
    @PeterCordes the AT&T instruction reference can be found in [Solaris' document](https://docs.oracle.com/cd/E53394_01/html/E54851/index.html) – phuclv Feb 25 '18 at 01:24
  • @LưuVĩnhPhúc: Interesting, but that documentation is very minimal. You have to go look up the Intel mnemonic in the real manuals to find out what order to put the operands. It doesn't even document what `movabs` vs. `movq` does, and doesn't document the `fdiv` vs. `fdivr` AT&T syntax bug for register operands. – Peter Cordes Feb 25 '18 at 01:33
  • Possible duplicate of [Is there a complete x86 assembly language reference that uses AT&T syntax?](https://stackoverflow.com/questions/1776570/is-there-a-complete-x86-assembly-language-reference-that-uses-att-syntax) – phuclv Feb 25 '18 at 01:40
  • A list with the mnemonics can be found on https://github.com/Shirk/vim-gas/blob/master/syntax/gas.vim – Andreas Abel Dec 20 '18 at 00:06

0 Answers0