5 ms·
What a train wreck! It’s hard to imagine a more confusing state of affairs. I'd say that's more attributed to someone many many years ago deciding they would n
by userbinator 10y ago
What a train wreck! It’s hard to imagine a more confusing state of affairs.
I'd say that's more attributed to someone many many years ago deciding they would not follow the official Intel syntax (for what reason I do not know), and somehow convincing the rest of the community to follow them. That's actually one of the things that could make for a very interesting article: how one processor family got two different and incompatible Asm syntaxes. The fact that the mnemonics and syntax don't correspond to those found in the manufacturer's datasheets and manuals just increases the barrier to understanding. As far as I know, the same didn't happen to ARM, MIPS, SPARC, and the others. Especially when the sense of the comparisons/conditional jumps is reversed, and some of the more advanced addressing modes look less-than-obvious, it's hard to imagine why anyone would adopt such a syntax:
http://x86asm.net/articles/what-i-dislike-about-gas/ http://x86asm.net/articles/what-i-dislike-about-gas/
Note that the GNU tools have option to use Intel syntax too, so you can avoid some of the confusion (in the DOS/Windows and embedded world at least until recently, Intel syntax is overwhelmingly the norm.)
- pcwalton 10y agoAnd Golang uses a separate syntax from Intel syntax and AT&T syntax, so now there are three incompatible syntaxes in common use. What a mess. :( In Go's case it's because they wanted to have the syntax reflect the MachineInstr-like abstraction they have in place. I wouldn't be surprised if something similar was responsible for the AT&T syntax as well. (In case it isn't clear, my preference is to do what LLVM does and to treat MachineInstr and machine code as distinct objects, and to use the vendor syntax for the human readable representation of the latter.)
- flamedoge 10y agoThey should all have same binary encoding, which means they can all be decoded to any human readable format regardless...
- theparanoid 10y agoFor extra points the Go syntax has /no/ spec. To quote "The details vary with architecture, and we apologize for the imprecision; the situation is not well-defined." [0] [0] https://golang.org/doc/asm https://golang.org/doc/asm
- adamnemecek 10y ago> how one processor family got two different and incompatible Asm syntaxes Do you know the reason for this?
- userbinator 10y agoUnfortunately not, but I'd love to hear from those who do.
- adamnemecek 10y agoI wouldn't be surprised if the reason was that people at Bell labs were mimicking some older syntax.
- pcwalton 10y agoYeah, I suspect this too. They did something similar with Golang (and Rob Pike still defends it, sadly).
- gens 10y agoI remember reading a long time ago about the syntaxes and the author said that it is because AT&T assembled faster. Makes sense considering that the intel syntax requires some backtracking (or more of temporary data). (please don't upvote if you agree, i'm at 69 points :)
- aap_ 10y ago
- pjmlp 10y agoA few years ago I decided to convert the Asm syntax of my toy compiler from Intel to AT&T, because I wanted to rely only on as, not forcing people to install another Assembler. Since as had some issues with the Intel syntax I was using, I decided to not use its support for the syntax and convert it to AT&T. Never again, it is just plain ugly. Compared with DOS/Windows Macro Assemblers (TASM, MASM, NASM, ...), AT&T ones are just plain pre-historic.
- haberman 10y agoThis. The AT&T syntax for x86 thing is a huge mistake. All the official docs are Intel syntax. Intel syntax is easier to read and write. Half the gotchas in this article are problems that don't exist in Intel syntax, like the instruction suffixes. The instruction suffixes get even weirder when you get to the sign extending instructions. I wrote an article about this here: http://blog.reverberate.org/2009/07/giving-up-on-at-style-assembler-syntax.html http://blog.reverberate.org/2009/07/giving-up-on-at-style-as...
- pjmlp 10y agoAdditionally Intel syntax Macro Assemblers offer higher level constructs providing almost C like experience while using machine opcodes.
- Annatar 10y agoThe AT&T syntax for x86 thing is a huge mistake. For someone who grew up on normal processors (MC68000 and UltraSPARC) AT&T syntax is the best thing since sliced bread: it's perfectly logical to move something to somewhere, instead of "move to somewhere something".
- userbinator 10y agoI haven't done any 68K Asm and barely glanced at SPARC, but how does src, dst interact with noncommutative operations like subtraction and comparison? E.g. with x86 Intel syntax, cmp eax, 5 ; eax - 5 jg morethan5 ; eax > 5 ? then jump. sub eax, ecx ; eax = eax - ecx This is one of the most confusing things about AT&T x86 --- the comparisons and subtractions have their operands reversed, and you have to identify and manually reverse them to understand the code correctly. With Intel syntax, the operands to a subtraction appear in the usual arithmetic order. Or do those processors' syntax keep the order but instead replace the subtrahend with the result?? sub A, B ; B = A - B ??
- haberman 10y agoExactly this. The instruction set is designed around Intel syntax. When you flip operands around because you prefer a different ordering, it messes up things like jg/ja/jl/jb/etc. And it's all arbitrary anyway. Some people might prefer a [src, dest] ordering, but it's not inherently any more natural than [dest, src]. Look at variable assignments: "x = y" in almost any programming language will assign y to x.