8 ms·
AT&T Syntax versus Intel Syntax (2001)
- dboreham 4y agoHmm. "AT&T"? I thought it at least came from DEC via the PDP-11,7 assembler. And I'm guessing Intel didn't invent doing it backwards in their own either.
- ksherlock 4y agoWikipedia confirms it. https://en.wikipedia.org/wiki/X86_assembly_language#Syntax https://en.wikipedia.org/wiki/X86_assembly_language#Syntax "The AT&T syntax is nearly universal to all other architectures with the same mov order; it was originally a syntax for PDP-11 assembly. The Intel syntax is specific to the x86 architecture, and is the one used in the x86 platform's documentation." https://en.wikipedia.org/wiki/As_(Unix) https://en.wikipedia.org/wiki/As_(Unix) "As of November 1971, an assembler invoked as as was available for Unix. Implemented by Bell Labs staff, it was based upon the Digital Equipment Corporation's PAL-11R assembler."
- deleted 4y ago[deleted]
- monocasa 4y agoAT&T as in Bell Labs in the work that would become Unix.
- masklinn 4y agoIt's the AT&T syntax because AT&T are the one who unleashed that on the world against the wishes of everyone. See the sibling comment: > The AT&T folks did not even wait for Intel's assembler [...] Nor did they closely model their assembler after it. They just took the assembler they already had for the PDP-11 and adapted it with minimal changes for the 8086.
- AnimalMuppet 4y agoWow, is your bias showing. "Against the wishes of everyone"? How about the wishes of those who wanted an x86 assembler before Intel got around to releasing theirs? And who wanted to be able to not have to switch their brains into a backward syntax when working on an x86?
- musicale 4y agoProbably "against the wishes of assembly language programmers who were familiar with microprocessors like the 8080 and Z-80 - and those who would have preferred to standardize on the official intel syntax rather than deal with two different and incompatible assembly language syntaxes."
- AnimalMuppet 4y agoSo, reading the comments here I got the impression that the 8086/8088 order was backwards from everything else before it. Did the 8080 and Z-80 have the same order as the 8086? But even then, you have worlds converging. The 8086 was (barely) capable of running Unix, whereas the Z-80 definitely was not. Was the 8086 a part of the PDP-11 minicomputer world, or was it part of the 8080/Z-80 world? Well, it was both. Complaining that one world produced an assembler before the other did is... a bit exclusivist. Also whiny.
- userbinator 4y agoThe 8086 was (barely) capable of running Unix, whereas the Z-80 definitely was not. https://github.com/chettrick/uzics https://github.com/chettrick/uzics You're wrong ;-) Neither the 8086 nor the Z80 have virtual memory. The x86 has a larger instruction set and address space (1MB) but as it turns out, early Unix kernels didn't need that much RAM either.
- Graziano_M 4y agoAT&T vs. Intel syntax has caused many arguments in some of my circles. AT&T is an atrocity and if you disagree... you're wrong. :)
- mixmastamyk 4y agoop src dest is the logical order, the rest of the syntax I don’t care about much.
- sph 4y agoBe that as it may, the AT&T indirect memory reference `section:disp(base, index,scale)` is an abomination unto God. At least the Intel one makes actual mathematical sense: `section:[base + index*scale + disp]`
- SoftTalker 4y agoTFA says "The `source, dest' convention is maintained for compatibility with previous Unix assemblers."
- pjmlp 4y agoIn mathematics variable = value, variable receives value, ergo op dest src. That is logic.
- pavlov 4y agoIndeed. Besides, “let there be light” is clearly destination-first, so this matter was already resolved by Genesis 1:3.
- Eleison23 4y agoWhich direction was the Hebrew text written in?
- LudwigNagasena 4y agoThat doesn’t follow. variable = value, ergo dest op src.
- pjmlp 4y agoIn a dumb idea to depend only on GAS, before it had good support for Intel syntax, I ported some code from Intel syntax into AT&T many moons ago, quite dumb idea, if i was doing it today I would have listed nasm or yasm as a requirement and be done with it.
- Taniwha 4y agoI'm pretty sure all this predates the existence of gas
- _tomcat_ 4y ago
- retrac 4y agoHere's the why for the curious. It's just a historical quirk. It's "AT&T syntax" because it dates to the 1978 AT&T Labs effort to port UNIX to the 8086. [1] While the 8086 did not have virtual memory or hardware protection, its memory segmentation model was still adequate to support UNIX. It was the first microprocessor practically capable of running UNIX, and this was realized before the chip was even released. The porting effort started immediately. (Though most of the energy would soon switch to the 68000 when that was released a year later.) The AT&T folks did not wait for Intel's assembler. (Written in Fortran, to run on mainframes, or on Intel's development systems). Nor did they closely model their assembler after it. They just took the assembler they already had for the PDP-11 and adapted it with minimal changes for the 8086. Quick and dirty. Which was okay. You're not supposed to write assembly on UNIX systems, anyway. Only the poor people who had to write kernel drivers and compilers would ever have to deal with it. [1] https://www.bell-labs.com/usr/dmr/www/otherports/newp.pdf https://www.bell-labs.com/usr/dmr/www/otherports/newp.pdf (see section III)
- bluedino 4y agoIt's funny how many things come down to 'UNIX hackers did it this way when they had to work with a PC'
- bbanyc 4y agoI think there's a bit more to the story. It was before my time, but as I understand it the most widely used Unix for the 8086 was XENIX (initially a Microsoft product, later sold to SCO), which used Intel-syntax MASM as its assembler. XENIX for 386 was based on AT&T System V/386, which introduced the AT&T syntax to 32-bit x86. I've found some references to 32-bit XENIX still using an assembler called "masm" but I don't know if it was still based on Microsoft's MASM or just called that for compatibility, or whether it was AT&T or Intel syntax. Also by that point compilers and assemblers weren't included in the base OS anymore, but a "development kit" sold separately. The Minix compiler and assembler also used Intel syntax.
- bbanyc 4y agoReplying to my own comment since I was curious - it was certainly Microsoft MASM, and cc was the Microsoft C Compiler as well. [1] So probably Intel syntax. There was also something called "SCO UNIX" which was apparently more of a straight adaptation of AT&T System V and might have used a pcc compiler and AT&T syntax. It's hard to figure out what happened when because there are a zillion different versions of Xenix/SCO Unix/OpenServer out there. [1] https://www.scosales.com/ta/kb/100187.html https://www.scosales.com/ta/kb/100187.html
- jcalvinowens 4y agoI initially learned the Intel syntax, and preferred it for awhile. But the more I work with non-x86 CPUs, the more I prefer AT&T just because it feels less different than everything else.
- aap_ 4y agoMuch agreed. Intel syntax just seems somewhat alien.
- secondcoming 4y agoBut all the Intel instruction documentation unsurprisingly uses the Intel syntax!
- yakaccount4 4y agoThat's interesting. My entire world revolves around x86 and ARM, so "Intel" syntax (which to me mostly means op dest, src) is what seems normal to me.
- aap_ 4y agoOrder of dst and src i have no strong feelings about, it's all the rest that i find weird about intel syntax.
- GeorgeTirebiter 4y agodest = src That's how I think of it. ALSO: I really do not like the MOV instruction; I much prefer LD. The Z-80 instruction names got everything mostly right.
- stevekemp 4y agoI started with Z80, and later moved to X86. To me intel order is the correct order, and everything else is weird and wrong!
- userbinator 4y ago
- jart 4y agoAT&T syntax is the most elite syntax. I've used it to write some famous hacks, like Actually Portable Executable, which is a 16-bit BIOS bootloader shell script ELF / Mach-O / PE executable. People dislike it because writing assembly Bell Labs style requires great responsibility. What makes AT&T syntax so powerful is its tight cooperation with the linker. I don't think it would have been possible for me to invent APE had I been using tools like NASM and YASM and FASM because PC assemblers were traditionally written as isolated tools that weren't able to take a holistic view with linker scripts and the C preprocessor. https://raw.githubusercontent.com/jart/cosmopolitan/master/ape/ape.S https://raw.githubusercontent.com/jart/cosmopolitan/master/a...
- chrisseaton 4y agoIsn't this a function of the tools you were using, not the syntax? Couldn't any of these tools support any syntax and do the same thing?
- JonChesterfield 4y agoThe line between syntax and functionality is pretty thin for an assembler. I've definitely had code that some assemblers accepted and others didn't on the same arch, so even if they could be equally expressive in practice they aren't. Fairly sure that's also true of inline assembly on clang x64, had to change between intel and at&t for something a while ago.
- throwawaylinux 4y agoNot really. Intel vs AT&T syntax is about how to generate machine code from mnemonics. Cooperation with the linker comes with other directives and options. gas has tight cooperation with GNU ld via directives (which mostly are just implemented with ELF constructs AFAIK), not instruction syntax. It can actually be set to accept either AT&T or Intel syntax, without losing any support for other features.
- JonChesterfield 4y ago
- mshockwave 4y agoSimilar thing also happens on 68k: Motorola syntax v.s. "MIT" syntax which is probably only used by GNU toolchain
- ack_complete 4y agoPractically, 68k is far more usable in AT&T syntax than x86. When I used to do PalmPilot development, you could basically write standard 68k asm with just some extra %s sprinkled before registers and as would be fine with it. The x86 AT&T syntax is far more alien compared to the syntax in the official manuals, with arguments backward and nonstandard instruction names like addl and movabsq.
- kccqzy 4y agoI never understood the need for names for movabsq. The top comment on this HN discussion is about how this is all a historical quirk, people wanting to get a job done quick and dirty. But movabsq is a new instruction introduced only with x86-64 (then known as AMD64). With the 64-bit transition why didn't they take the opportunity to clean up and reorganize this mess?
- bmc7505 4y agoInteresting bit of trivia, Prof. Ratzer, the author of this piece, was the first graduate student in computing at McGill University [1] and one of the founding members of the School of Computer Science [2], which just recently celebrated its 50th anniversary. [3] [1]: https://en.wikipedia.org/wiki/McGill_University_School_of_Computer_Science https://en.wikipedia.org/wiki/McGill_University_School_of_Co... [2]: https://www.cs.mcgill.ca/~ratzer/backup/welcome.html https://www.cs.mcgill.ca/~ratzer/backup/welcome.html [3]: https://mcgill.imodules.com/controls/email_marketing/view_in_browser.aspx?sid=1762&gid=2&sendId=168741 https://mcgill.imodules.com/controls/email_marketing/view_in...
- userbinator 4y agoIMHO the most confusing part is that AT&T/GAS syntax inverts the comparisons, which are otherwise natural in Intel syntax: cmp eax, ebx ; eax ? ebx jg foo ; jump if eax > ebx Related: http://x86asm.net/articles/what-i-dislike-about-gas/ http://x86asm.net/articles/what-i-dislike-about-gas/
- mrjin 4y agoAlso the % before register names is completely unnecessary, it just another extra character to type.
- deleted 4y ago[deleted]
- rwmj 4y agoIt disambiguates labels from registers, assuming of course you allow labels to have register names. eg this is valid: mov rax,%rax rax: .ascii "hello\0" Stupid perhaps, but valid.
- jck 4y agoI wonder if it would have been more ergonomic to have the labels be % prefixed instead of registers.
- int_19h 4y agoThe above-linked article specifically points out that registers are referenced much more often than labels.
- userbinator 4y agoProbably an artifact of the original use of the assembler being to process compiler output, and causing variable names to appear. One of the x86 assemblers I remember trying out in the late 80s had a slight variant of Intel syntax in that everything that wasn't a reserved word/mnemonic was automatically assumed to be a label.
- PaulHoule 4y agoI never liked the syntax used by gas. It feels like something intended to be part of a C compiler, not like something you'd use for the joy of assembly language.
- ufo 4y agoOn Linux, is there a way to convert an assembly language file from one syntax to the other? I know that there are ways to ask GCC to emit one syntax or the other, as well as ways to assemble code in either syntax. However I don't know any program that just translates one to the other.
- johannes1234321 4y agoAssemble and disassemble? While that will of course lose your labels etc. :-D
- pclmulqdq 4y agoI'm in the Intel syntax camp, pretty thoroughly. I use other assemblers, too, and the Intel syntax is a lot more similar to ARM, RISC-V, and assemblies used by DSPs (which are surprisingly C-like). The order of operations, the order of comparisons, the addressing syntax, and the lack of spurious wingdings characters all make it easier to read and write. The one thing AT&T syntax has going for it is the "strong typing" of operand widths: `addl` is slightly more readable than `add` + operand-inferred width. If you want the C preprocessor, you can have it with Intel syntax too (gas can use either), but I think the preprocessing syntax designed for assembly is cleaner with assembly code, and some of those preprocessors are surprisingly powerful.
- shadowofneptune 4y agoA point in favor of the Intel syntax is that it is, well, Intel's. It's much easier to use listings published by Intel, with only a few changes to the macros and label usage needed.
- WalterBright 4y agoIn grade school, they showed us a movie where researchers attached special glasses to a volunteer, and the volunteer had to wear them 24/7 or a mask for sleeping. The glasses turned everything upside down. After a few days, suddenly everything was right side up for the volunteer. Until he took the glasses off ... The movie ended with a warning to never try this yourself. Anyhow, I'm reminded of that movie every time I have to switch between AT&T vs Intel syntax. My brain just hurts, and the asm code I write is all wrong. So, the dmd D compiler's inline assembler syntax is Intel regardless of the OS, and the builtin disassembler is Intel syntax.
- pjmlp 4y agoI love that dmd follows the home computer school of having inline Assembly done properly, instead of mini-languages stuffed inside strings.
- B1FF_PSUVM 4y ago> glasses turned everything upside down https://www.madsci.org/posts/archives/mar97/858984531.Ns.r.html https://www.madsci.org/posts/archives/mar97/858984531.Ns.r.h... """ [...] first investigated by George Stratton in the 1890 s [...] he ran another experiment where he wore it for eight days in a row. On the fourth day, things seemed to be upright rather than inverted. On the fifth day, he was able to walk around his house fairly normally but he found that if he looked at objects very carefully, they again seemed to be inverted. On the whole, Stratton reported that his environment never really felt normal especially his body parts, although it was difficult to describe exactly how he felt. He also found that after removing the reversing lenses, it took several hours for his vision to return to normal. [...] """
- WalterBright 4y agoThanks for the references. I saw the black&white film around 1967.
- B1FF_PSUVM 4y agoYou're welcome. I had heard the story before, but couldn't remember the attributed date, got curious and looked it up.
- ordu 4y agoI like AT&T more, because it have no of that "dword ptr" nonsense. AT&T more logical when it comes to differentiating between an immediate value and an address of a value. Everything else can be done both ways and do not matter much, but using dollar sign or not using it to distinguish immediates from addresses is a really nice touch.