GAS: Difference between revisions

From OSDev.wiki
Jump to navigation Jump to search
[unchecked revision][unchecked revision]
Content added Content deleted
m (typo)
(Rewrite article to remove "you")
 
Line 4: Line 4:
|website=http://www.gnu.org/software/binutils/
|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 lets you forward assembly directly to the assembler using inline assembly feature.
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.


GAS is not ''one'' assembler, but a collection of assemblers - one for each of the platforms supported by GCC. They are very similar in their available options, their macro language, and so on. GAS provides you with 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 tools).
GAS is not ''one'' assembler, but a collection of assemblers - one for each of the platforms supported by GCC. They 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 tools).


== Usage ==
== Usage ==
Line 18: Line 18:
Up until v2.10 of binutils, GAS 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, GAS supports both syntax sets (<tt>.intel_syntax</tt> and the default <tt>.att_syntax</tt>), and even allows disabling the otherwise mandatory operand prefixes '%' or '$' (<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...).
Up until v2.10 of binutils, GAS 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, GAS supports both syntax sets (<tt>.intel_syntax</tt> and the default <tt>.att_syntax</tt>), and even allows disabling the otherwise mandatory operand prefixes '%' or '$' (<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...).


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. If you want that syntax, you should use an [[Tool Comparison|assembler]] that uses it natively.
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.


== See Also ==
== See Also ==

Latest revision as of 21:05, 26 January 2017

This page is a stub.
You can help the wiki by accurately adding more contents to it.

GNU Assembler

[[Image:{{{image}}}|300px|]]
Website:http://www.gnu.org/software/binutils/

The GNU Assembler (GAS, executable named 'as') is part of the binutils package. GCC generates assembly source code and automatically invokes GAS which assembles the code into machine code in an object file. GCC allows developers to forward assembly directly to the assembler using inline assembly feature.

GAS is not one assembler, but a collection of assemblers - one for each of the platforms supported by GCC. They 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 make rules, inline assembly from C/C++ sources, the ability to be called as gcc -o myfile.o myfile.s, the same assembly syntax used by all the tools).

Usage

AT&T Syntax

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 % character and constants must be prefixed with the $ character.

Intel Syntax Support

Up until v2.10 of binutils, GAS 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, GAS supports both syntax sets (.intel_syntax and the default .att_syntax), and even allows disabling the otherwise mandatory operand prefixes '%' or '$' (..._syntax noprefix). There are some pitfalls - several FP opcodes suffer from a reverse operand ordering that is bound to stay in there for compatibility reasons, .intel_syntax generates less optimized opcodes on occasion (try mov'ing to %si...).

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. A different assembler should be considered if Intel Syntax is desired.

See Also

Articles

External Links