The GNU Assembler, commonly known as gas or as, is the
assembler developed by the
GNU Project. 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, monolithic, modular, multitasking, Unix-like operating system kernel. It was originally authored in 1991 by Linus Torvalds for his i386-based PC, and it was soon adopted as the kernel for the GNU ope ...
, and various other software. It is a part of the
GNU Binutils package.
The GAS
executable
In computing, 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), instructi ...
is named , the standard name for a
Unix assembler. GAS is
cross-platform, and both runs on and assembles for a number of different
computer architectures. GAS is
free software released under the
GNU General Public License 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
''The C Programming Language'' (sometimes termed ''K&R'', after its authors' initials) is a computer programming book written by Brian Kernighan and Dennis Ritchie, the latter of whom originally designed and implemented the language, as well as ...
. 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,
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
* A
semicolon (;) —
AMD 29k family,
ARC
ARC may refer to:
Business
* Aircraft Radio Corporation, a major avionics manufacturer from the 1920s to the '50s
* Airlines Reporting Corporation, an airline-owned company that provides ticket distribution, reporting, and settlement services
* ...
,
H8/300 family,
HPPA,
PDP-11
The PDP-11 is a series of 16-bit minicomputers sold by Digital Equipment Corporation (DEC) from 1970 into the 1990s, one of a set of products in the Programmed Data Processor (PDP) series. In total, around 600,000 PDP-11s of all models were sold, ...
,
picoJava, Motorola, and
M32C
is a Japanese semiconductor manufacturer headquartered in Tokyo, Japan, initially incorporated in 2002 as Renesas Technology, the consolidated entity of the semiconductor units of Hitachi and Mitsubishi excluding their dynamic random-access ...
* The
at sign (@) —
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
...
(, ) —
680x0
* An
exclamation mark (!) —
Renesas SH
Usage
Being the back-end for a popular compiler suite, namely GCC, the GNU Assembler is very widely used in compiling modern 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 since
OS X
macOS (; previously OS X and originally Mac OS X) is a Unix operating system developed and marketed by Apple Inc. since 2001. It is the primary operating system for Apple's Mac computers. Within the market of desktop and lapt ...
.
Example program
A standard "Hello, world!" program for
Linux on
IA-32:
.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 # address of msg string -> ECX (2nd argument)
movl $len, %edx # len (32 bit address) -> 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 compilers and interpreters
GNU Project software
Linux programming tools
Unix programming tools