The GNU Assembler, commonly known as gas or as, is the
assembler developed by the
GNU Project
The GNU Project ( ) is a free software, mass collaboration project announced by Richard Stallman on September 27, 1983. Its goal is to give computer users freedom and control in their use of their computers and Computer hardware, computing dev ...
. It is the default
back-end of
GCC. It is used to assemble the
GNU operating system and the
Linux kernel
The Linux kernel is a Free and open-source software, free and open source Unix-like kernel (operating system), kernel that is used in many computer systems worldwide. The kernel was created by Linus Torvalds in 1991 and was soon adopted as the k ...
, and various other software. It is a part of the
GNU Binutils package.
The GAS
executable
In computer science, executable code, an executable file, or an executable program, sometimes simply referred to as an executable or binary, causes a computer "to perform indicated tasks according to encoded instruction (computer science), in ...
is named , the standard name for a
Unix
Unix (, ; trademarked as UNIX) is a family of multitasking, multi-user computer operating systems that derive from the original AT&T Unix, whose development started in 1969 at the Bell Labs research center by Ken Thompson, Dennis Ritchie, a ...
assembler. GAS is
cross-platform
Within computing, cross-platform software (also called multi-platform software, platform-agnostic software, or platform-independent software) is computer software that is designed to work in several Computing platform, computing platforms. Some ...
, and both runs on and assembles for a number of different
computer architectures. GAS is
free software
Free software, libre software, libreware sometimes known as freedom-respecting software is computer software distributed open-source license, under terms that allow users to run the software for any purpose as well as to study, change, distribut ...
released under the
GNU General Public License
The GNU General Public Licenses (GNU GPL or simply GPL) are a series of widely used free software licenses, or ''copyleft'' licenses, that guarantee end users the freedom to run, study, share, or modify the software. The GPL was the first ...
v3.
History
The first version of GAS was released in 1986–1987.
It was written by Dean Elsner and supported the
VAX architecture.
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
directives (also known as pseudo ops), which are keywords beginning with a period that behave similarly to preprocessor directives in the
C programming language. While most of the available assembler directives are valid regardless of the target architecture, some directives are machine dependent.
Since version 2.10, Intel syntax can be used through use of the
.intel_syntax
directive.
Comments
GAS supports two comment styles.
Multi-line
As in C, multi-line comments start and end with mirroring slash-asterisk pairs:
/*
comment
*/
Single-line
Single line comments have a few different formats varying on which architecture is being assembled for.
* A
hash symbol (#) —
i386
The Intel 386, originally released as the 80386 and later renamed i386, is the third-generation x86 architecture microprocessor from Intel. It was the first 32-bit processor in the line, making it a significant evolution in the x86 archite ...
,
x86-64,
i960,
68HC11,
68HC12,
VAX,
V850,
M32R,
PowerPC
PowerPC (with the backronym Performance Optimization With Enhanced RISC – Performance Computing, sometimes abbreviated as PPC) is a reduced instruction set computer (RISC) instruction set architecture (ISA) created by the 1991 Apple Inc., App ...
,
MIPS,
M680x0, and
RISC-V
RISC-V (pronounced "risk-five") is an open standard instruction set architecture (ISA) based on established reduced instruction set computer (RISC) principles. The project commenced in 2010 at the University of California, Berkeley. It transfer ...
* A
semicolon (;) —
AMD 29k family,
ARC,
H8/300 family,
HPPA,
PDP-11,
picoJava, Motorola, and
M32C
* The
at sign (@) — 32-bit
ARM
* A double
slash (//) —
AArch64
* A
vertical bar
The vertical bar, , is a glyph with various uses in mathematics, computing, and typography. It has many names, often related to particular meanings: Sheffer stroke (in logic), pipe, bar, or (literally, the word "or"), vbar, and others.
Usage
...
(, ) —
M680x0
* An
exclamation mark
The exclamation mark (also known as exclamation point in American English) is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or to show wikt:emphasis, emphasis. The exclamation mark often marks ...
(!) —
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
Free and open-source software (FOSS) is software available under a Software license, license that grants users the right to use, modify, and distribute the software modified or not to everyone free of charge. FOSS is an inclusive umbrella term ...
. 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
macOS, previously OS X and originally Mac OS X, is a Unix, Unix-based operating system developed and marketed by Apple Inc., Apple since 2001. It is the current operating system for Apple's Mac (computer), Mac computers. With ...
development tools package.
Example program
A standard "Hello, world!" program for
Linux
Linux ( ) is a family of open source Unix-like operating systems based on the Linux kernel, an kernel (operating system), operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically package manager, pac ...
on
IA-32
IA-32 (short for "Intel Architecture, 32-bit", commonly called ''i386'') is the 32-bit version of the x86 instruction set architecture, designed by Intel and first implemented in the i386, 80386 microprocessor in 1985. IA-32 is the first incarn ...
:
.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"
See also
*
GNU toolchain
*
Binary File Descriptor library
*
Comparison of assemblers
References
External links
*
Gas manual*
{{DEFAULTSORT:Gnu Assembler
Assemblers
Free and open source compilers
Assembler
Linux programming tools
Unix programming tools