Open main menu
Home
Random
Recent changes
Special pages
Community portal
Preferences
About Wikipedia
Disclaimers
Incubator escapee wiki
Search
User menu
Talk
Dark mode
Contributions
Create account
Log in
Editing
GNU Assembler
Warning:
You are not logged in. Your IP address will be publicly visible if you make any edits. If you
log in
or
create an account
, your edits will be attributed to your username, along with other benefits.
Anti-spam check. Do
not
fill this in!
{{Short description|Free and open-source assembler}} {{Infobox software | name = GNU Assembler | logo = Heckert GNU white.svg | logo size = 100px | developer = [[GNU Project]] | latest release version = GNU Binutils {{wikidata|property|reference|edit|Q1144975|P348}} | latest release date = {{start date and age|{{wikidata|qualifier|Q1144975|P348|P577}}}} | programming language = [[C (programming language)|C]] | platform = [[Cross-platform]] | genre = [[Assembly language#Assembler|Assembler]] | license = [[GNU General Public License]] v3 | website = {{URL|https://www.gnu.org/software/binutils/}} }} The '''GNU Assembler''', commonly known as '''gas''' or '''as''', is the [[Assembler (computer programming)|assembler]] developed by the [[GNU Project]]. It is the default [[Front and back ends|back-end]] of [[GNU Compiler Collection|GCC]]. It is used to assemble the [[GNU operating system]] and the [[Linux kernel]], and various other software. It is a part of the [[GNU Binutils]] package. The GAS [[executable]] is named {{mono|[[As (Unix)|as]]}}, the standard name for a [[Unix]] assembler. GAS is [[cross-platform]], and both runs on and assembles for a number of different [[computer architecture]]s. GAS is [[free software]] released under the [[GNU General Public License]] v3. ==History== The first version of GAS was released in 1986β1987.<ref name="gasdoc1">{{cite CiteSeerX|title=The GNU Assembler|citeseerx=10.1.1.32.4503}}</ref> It was written by Dean Elsner and supported the [[VAX]] architecture.<ref name="gasdoc1"/> ==General syntax== GAS supports a general syntax that works for all of the supported architectures. The general syntax includes assembler directives and a method for commenting. The default syntax is [[AT&T syntax]]. ===Directives=== GAS uses assembler [[directive (programming)|directives]] (also known as pseudo ops), which are keywords beginning with a period that behave similarly to preprocessor directives in the [[C (programming language)|C programming language]]. While most of the available assembler directives are valid regardless of the target architecture, some directives are machine dependent.<ref>{{cite web | title = The GNU Assembler - Assembler Directives | url = http://sources.redhat.com/binutils/docs-2.12/as.info/Pseudo-Ops.html#Pseudo%20Ops | access-date = 2008-04-13 | archive-date = 2012-02-22 | archive-url = https://web.archive.org/web/20120222005603/http://sources.redhat.com/binutils/docs-2.12/as.info/Pseudo-Ops.html#Pseudo%20Ops | url-status = dead }}</ref> Since version 2.10, Intel syntax can be used through use of the <code>.intel_syntax</code> directive.<ref>{{cite web| title = GNU Assembler News| url = https://sourceware.org/git/?p=binutils-gdb.git;a=blob;f=gas/NEWS;hb=HEAD |quote=A new pseudo-op .intel_syntax has been implemented to allow gas to parse i386 assembly programs with intel syntax.}}</ref><ref>{{cite web| title = AT&T Syntax versus Intel Syntax| url = http://sources.redhat.com/binutils/docs-2.12/as.info/i386-Syntax.html| access-date = 28 July 2014| archive-date = 20 June 2011| archive-url = https://web.archive.org/web/20110620054249/http://sources.redhat.com/binutils/docs-2.12/as.info/i386-Syntax.html| url-status = dead}}</ref><ref>{{cite web| title = Linux assemblers: A comparison of GAS and NASM| author = Ram Narayan| date = 2007-10-17| publisher = IBM DeveloperWorks| url = http://www.ibm.com/developerworks/linux/library/l-gas-nasm.html| archive-url = https://web.archive.org/web/20090303224539/http://ibm.com/developerworks/linux/library/l-gas-nasm.html| archive-date = 3 March 2009| access-date = 28 July 2014}}</ref> ===Comments=== GAS supports two comment styles.<ref>{{cite web|last=Red Hat Inc.|title=Using as|url=http://sources.redhat.com/binutils/docs-2.12/as.info/Comments.html#Comments|access-date=Jan 10, 2013|archive-date=June 20, 2011|archive-url=https://web.archive.org/web/20110620054223/http://sources.redhat.com/binutils/docs-2.12/as.info/Comments.html#Comments|url-status=dead}}</ref> '''Multi-line''' As in C, multi-line comments start and end with mirroring slash-asterisk pairs: <syntaxhighlight lang="c"> /* comment */ </syntaxhighlight> '''Single-line''' Single line comments have a few different formats varying on which architecture is being assembled for. * A [[hash symbol]] (#) β [[i386]], [[x86-64]], [[i960]], [[68HC11]], [[68HC12]], [[VAX]], [[V850]], [[M32R]], [[PowerPC]], [[MIPS architecture|MIPS]], [[Motorola 68000 series|M680x0]], and [[RISC-V]] * A [[semicolon]] (;) β [[AMD 29k]] family, [[Advanced RISC Computing|ARC]], [[H8/300]] family, [[PA-RISC|HPPA]], [[PDP-11]], [[picoJava]], Motorola, and [[M32C]] * The [[at sign]] (@) β 32-bit [[ARM architecture|ARM]] * A double [[Slash (punctuation)|slash]] (//) β [[AArch64]] * A [[vertical bar]] (|) β [[Motorola 68000 series|M680x0]] * An [[exclamation mark]] (!) β [[SuperH|Renesas SH]] ==Usage== Being the back-end for a popular compiler suite, namely GCC, the GNU Assembler is very widely used in compiling modern [[free and open source software]]. GAS is often used as the assembler on Linux operating systems in conjunction with other GNU software. A modified version of GAS can also be found in the [[macOS]] development tools package. ==Example program== A standard "Hello, world!" program for [[Linux]] on [[IA-32]]: <syntaxhighlight lang="asm"> .global _start .text _start: movl $4, %eax # 4 (code for "write" syscall) -> EAX register movl $1, %ebx # 1 (file descriptor for stdout) -> EBX (1st argument to syscall) movl $msg, %ecx # 32-bit address of msg string -> ECX (2nd argument) movl $len, %edx # length of msg string -> EDX (3rd arg) int $0x80 # interrupt with location 0x80 (128), which invokes the kernel's system call procedure movl $1, %eax # 1 ("exit") -> EAX movl $0, %ebx # 0 (with success) -> EBX int $0x80 # see previous .data msg: .ascii "Hello, world!\n" # inline ascii string len = . - msg # assign (current address - address of msg start) to symbol "len" </syntaxhighlight> ==See also== {{Portal|Free and open-source software}} * [[GNU toolchain]] * [[Binary File Descriptor library]] * [[Comparison of assemblers]] ==References== {{Reflist}} ==External links== {{Wikibooks|X86 Assembly|GAS Syntax}} * {{official website}} * [http://sourceware.org/binutils/docs/as/ Gas manual] * {{man|1|as|die.net|the portable GNU assembler}} {{GNU}} {{X86 assembly topics}} {{DEFAULTSORT:Gnu Assembler}} [[Category:Assemblers]] [[Category:Free and open source compilers]] [[Category:GNU Project software|Assembler]] [[Category:Linux programming tools]] [[Category:Unix programming tools]]
Edit summary
(Briefly describe your changes)
By publishing changes, you agree to the
Terms of Use
, and you irrevocably agree to release your contribution under the
CC BY-SA 4.0 License
and the
GFDL
. You agree that a hyperlink or URL is sufficient attribution under the Creative Commons license.
Cancel
Editing help
(opens in new window)
Pages transcluded onto the current version of this page
(
help
)
:
Template:Cite CiteSeerX
(
edit
)
Template:Cite web
(
edit
)
Template:GNU
(
edit
)
Template:Infobox software
(
edit
)
Template:Man
(
edit
)
Template:Mono
(
edit
)
Template:Official website
(
edit
)
Template:Portal
(
edit
)
Template:Reflist
(
edit
)
Template:Short description
(
edit
)
Template:Wikibooks
(
edit
)
Template:X86 assembly topics
(
edit
)