r/Assembly_language • • 5d ago

Intel versus AT&T syntax

Hi everyone! I am back two Assembly after three decades and I would appreciate some input. At the time, I programmed x86 using TASM in a DOS environment for finance (valuation of derivatives when that was a thing...). I never programmed in a windows environment nor in an ARM CPU. Now in my first attempt to catch up, I am reading a book called "Programming from the ground up" which I like very much but the syntax used is AT&T. I didn't even know there was such a thing...Bottomline: what should I take into account when deciding what syntax to use? I work with macOS, Windows and Linux. What I'm looking for is to be able to program in a "modern" assembly that works in contemporary x86 CPUs with Windows or linux and maybe later, learn ARM assembly. Any suggestion regarding the path I should take to is welcome. Thanks!

5 Upvotes

10 comments sorted by

2

u/[deleted] 5d ago

It's a matter of preference. Coming from DOS I strongly prefer Intel syntax. Both are usable with gcc/gas and llvm. If you use NASM, it will only support Intel syntax (but a different flavor than gas).

1

u/No_feeer_Nordik 5d ago

Thanks! I'll just start with what I am familiar with.

1

u/Mediocre-Pumpkin6522 4d ago

'AT&T' syntax goes back to PDP-11 assembler and Unix. GNU followed it with early gcc/gas although now both are supported. Some of what seem like extraneous prefixes or suffixes goes back to that evnironment. I've always worked with Intel syntax, including on MCUs that aren't even in the Intel family.

https://comp.anu.edu.au/courses/comp2300/resources/03-ARM-cheat-sheet/

1

u/kneelian_ 4d ago

ARM assembly is in an Intel-like style, with the destination first and sources second, so if you want to move to that, maybe building a bit of an Intel habit won't hurt. You can probably get some use out of translating the exercises or code listings in the book from AT&T syntax to Intel syntax

1

u/Key_Detail15 3d ago

Most people prefer Intel-style synax. AT&T is more for machine-generated code, and for that purposes it works well (eg. identifiers can't clash with register names because the latter have a %-prefix).

The trouble is that there are too many assemblers for Intel-style, all slightly different; AT&T is more standardised because people tend to use the 'as' assembler.

AT&T is useable, especially if you turn off the option to have registerer prefixes, and it can be made to support Intel-style too. For example, if generating AT&T assemmbly, I use this directive:

    .intel_syntax prefix

This uses Intel-style opcodes and data-direction, but keeps registers as "%rax" rather than "rax", because I can't have clashes.

Note that if using ARM assembly, then AT&T is more tolerable (there is no Intel option anyway).

1

u/braaaaaaainworms 1d ago

Machine-generated code shouldn't use assembly source code as an IR anyway

1

u/FedUp233 3d ago

Just some things to think about:

First, note that I haven’t done this particular type of thing for a while, so my memory may be wrong or options may have changed, so feel free to correct me if wrong.

First, if you are going to use “as” I think the arm syntax is also at$t unless they support an “arm style” alternate like for intel.

And if you plan to do any inline assembler in C or C++ code in gcc or clang, I believe that is only AT&T style with a bunch of extra declarations added to connect the assembler to the surrounding high level code. This may not be an issue for you but if you plan to do any low level stuff where you want the assembler to be able to inline function calls in the C or C++ code then I think this is the way you have to go - if you write separate .s files for assembler than any assembler stuff you do must be separate functions with normal full function calls from C. This is used in lots of low level libraries for things like implementing atomic variable, mutex, semaphores and such that need instructions you can’t get C to generate like those for spinlocks or fences and such.

So it may be good for future use to just go with AT&T style even if you don’t really like it - neither do I.

1

u/ilnarildarovuch 2d ago

Depends on personal preferences. I like AT&T for determinism

1

u/tomysshadow 1d ago edited 1d ago

I see Intel syntax much more often personally (maybe AT&T is more of a Linux thing.) AT&T syntax has some quirks to it you have to watch out for, see: http://x86asm.net/articles/what-i-dislike-about-gas/

1

u/braaaaaaainworms 1d ago

AT&T syntax doesn't match Intel's documentation and should only be used if you have to use it