GAS: Difference between revisions

[unchecked revision][unchecked revision]
Content deleted Content added
No edit summary
Rewrite article to remove "you"
 
(10 intermediate revisions by 8 users not shown)
Line 1:
{{In ProgressStub}}
{{Infobox_Tool
The GNU Assembler ("gas", executable named 'as') is part of the [http://www.gnu.org/software/binutils/ binutils] package. If you are using [[GCC]], you are also using gas - basically, GCC generates Assembler source which is turned into machine code by a subsequent (automatic) call to gas. Moreover, when you are using inline assembler in GCC code, you are also using gas.
|name=GNU Assembler
|website=http://www.gnu.org/software/binutils/
}}
The '''GNU Assembler''' ('''GAS''', executable named 'as') is part of the [[binutils]] package. [[GCC]] generates [[Assembly|assembly]] source code and automatically invokes GAS which assembles the code into machine code in an [[Object Files|object file]]. GCC allows developers to forward assembly directly to the assembler using inline assembly feature.
 
Actually, gasGAS is not ''one'' assembler, but a collection of assemblers - one for each of the platforms supported by GCC. - whichThey are very similar in their available options, their macro language, and so on. GAS provides a very solid and well-supported assembler that is fully integrated with the other GNU tools (implicit <tt>make</tt> rules, inline assembly from C/C++ sources, the ability to be called as <tt>gcc -o myfile.o myfile.s</tt>, the same assembly syntax used by all the etctools).
 
== Usage ==
Up until v2.10 of binutils, gas supported only AT&T syntax, which differs significantly from the Intel syntax used by virtually every other assembler. Today, gas supports both syntax sets (<tt>.intel_syntax</tt> and the default <tt>.att_syntax</tt>), and even allows disabling the otherwise mandatory '%' register prefix (<tt>..._syntax noprefix</tt>).
 
=== AT&T Syntax ===
There ''are'' some pitfalls - several FP opcodes suffer from a reverse operand ordering that is bound to stay in there for compatibility reasons, <tt>.intel_syntax</tt> generates less optimized opcodes on occassion (try <tt>mov</tt>'ing to %si...). But if you can learn to live with them
<!-- (like, reading the manual and our helpful HowAtandtSyntaxDiffersFromNasm) add this back when manual is there -->
, gas provides you with a very solid and well-supported assembler that is fully integrated with the other GNU tools (like, implicit <tt>make</tt> rules, inline calling from C/C++ sources, and the ability to be called as <tt>gcc -o myfile.o myfile.s</tt>).
<!-- add this back later
AT&T versions of some of the assembly examples around the Wiki can be found on the [GasAllInOne] page.
-->
GAS defaults to 32bit code, but can be switched to <tt>.code16</tt>. This requires some additional attention - you will want to check the [http://sourceware.org/binutils/docs-2.17/as/i386_002d16bit.html documentation] on that matter.
 
The AT&T assembly syntax is traditional for Unix-like operating systems on the [[x86]] and [[x86-64]] platforms. The syntax is reminiscent of the original assembler format used in the original Unix operating system. The operand order for instructions is source and then destination. The assembly language is unambiguous as registers must be prefixed with a <tt>%</tt> character and constants must be prefixed with the <tt>$</tt> character.
==See Also==
 
===Articles===
=== Intel Syntax Support ===
*[[Assembly]]
 
*[[Tool Comparison]]
Up until v2.10 of binutils, gasGAS supported only the AT&T syntax for [[x86]] and [[x86-64]], which differs significantly from the Intel syntax used by virtually every other assembler. Today, gasGAS supports both syntax sets (<tt>.intel_syntax</tt> and the default <tt>.att_syntax</tt>), and even allows disabling the otherwise mandatory operand prefixes '%' registeror prefix'$' (<tt>..._syntax noprefix</tt>). There ''are'' some pitfalls - several FP opcodes suffer from a reverse operand ordering that is bound to stay in there for compatibility reasons, <tt>.intel_syntax</tt> generates less optimized opcodes on occasion (try <tt>mov</tt>'ing to %si...).
*[[NASM]]
 
*[[Wikipedia:GNU Assembler|GNU Assembler]] - Wikipedia
It is generally discouraged to use the support for Intel Syntax because it can subtly and surprisingly different than the real Intel Syntax found in other assemblers. [[Tool Comparison|A different assembler]] should be considered if Intel Syntax is desired.
*[[Wikibooks:X86 Assembly/GAS Syntax|GAS Syntax]] - Wikibook
 
===External Links===
== See Also ==
*[http://sourceware.org/binutils/docs-2.17/as/index.html GNU as official manual]
 
=== Articles ===
* [[Assembly]]
* [[Tool Comparison]]
* [[Wikipedia:GNU Assembler|GNU Assembler]] - Wikipedia
* [[Wikibooks:X86 Assembly/GAS Syntax|GAS Syntax]] - Wikibook
 
=== External Links ===
* [httphttps://sourceware.org/binutils/docs-2.17/as/index.html GNU as official manual]
 
[[Category:Assemblers]]
[[Category:Binutils]]