GNU Assembler
   HOME

TheInfoList



OR:

The GNU Assembler, commonly known as gas or as, is the
assembler Assembler may refer to: Arts and media * Nobukazu Takemura, avant-garde electronic musician, stage name Assembler * Assemblers, a fictional race in the ''Star Wars'' universe * Assemblers, an alternative name of the superhero group Champions of ...
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 computing devices by collaborat ...
. It is the default back-end of GCC. It is used to assemble the
GNU operating system GNU () is an extensive collection of free software (383 packages as of January 2022), which can be used as an operating system or can be used in parts with other operating systems. The use of the completed GNU tools led to the family of operat ...
and the Linux kernel, and various other software. It is a part of the
GNU Binutils The GNU Binary Utilities, or , are a set of programming tools for creating and managing binary programs, object files, libraries, profile data, and assembly source code. Tools They were originally written by programmers at Cygnus Solutions. ...
package. The GAS executable is named , the standard name for a
Unix Unix (; trademarked as UNIX) is a family of multitasking, multiuser 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, an ...
assembler. GAS is
cross-platform In 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 platforms. Some cross-platform software ...
, and both runs on and assembles for a number of different
computer architecture In computer engineering, computer architecture is a description of the structure of a computer system made from component parts. It can sometimes be a high-level description that ignores details of the implementation. At a more detailed level, the ...
s. GAS is
free software Free software or libre software is computer software distributed under terms that allow users to run the software for any purpose as well as to study, change, and distribute it and any adapted versions. Free software is a matter of liberty, no ...
released under the
GNU General Public License The GNU General Public License (GNU GPL or simply GPL) is a series of widely used free software licenses that guarantee end users the four freedoms to run, study, share, and modify the software. The license was the first copyleft for general ...
v3.


History

The first version of GAS was released in 1986-1987. It was written by Dean Elsner, and supported the
VAX VAX (an acronym for Virtual Address eXtension) is a series of computers featuring a 32-bit instruction set architecture (ISA) and virtual memory that was developed and sold by Digital Equipment Corporation (DEC) in the late 20th century. The V ...
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 x86 assembly language is the name for the family of assembly languages which provide some level of backward compatibility with CPUs back to the Intel 8008 microprocessor, which was launched in April 1972. It is used to produce object code for t ...
.


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 The symbol is known variously in English-speaking regions as the number sign, hash, or pound sign. The symbol has historically been used for a wide range of purposes including the designation of an ordinal number and as a Typographic ligature, ...
(#) —
i386 The Intel 386, originally released as 80386 and later renamed i386, is a 32-bit microprocessor introduced in 1985. The first versions had 275,000 transistorsx86-64 x86-64 (also known as x64, x86_64, AMD64, and Intel 64) is a 64-bit version of the x86 instruction set, first released in 1999. It introduced two new modes of operation, 64-bit mode and compatibility mode, along with a new 4-level paging ...
,
i960 Intel's i960 (or 80960) was a RISC-based microprocessor design that became popular during the early 1990s as an embedded microcontroller. It became a best-selling CPU in that segment, along with the competing AMD 29000. In spite of its success, ...
,
68HC11 The 68HC11 (6811 or HC11 for short) is an 8-bit microcontroller (µC) family introduced by Motorola in 1984. Now produced by NXP Semiconductors, it descended from the Motorola 6800 microprocessor by way of the 6801. The 68HC11 devices are more p ...
,
68HC12 The 68HC12 (6812 or HC12 for short) is a microcontroller family from Freescale Semiconductor. Originally introduced in the mid-1990s, the architecture is an enhancement of the Freescale 68HC11. Programs written for the HC11 are usually compatibl ...
,
VAX VAX (an acronym for Virtual Address eXtension) is a series of computers featuring a 32-bit instruction set architecture (ISA) and virtual memory that was developed and sold by Digital Equipment Corporation (DEC) in the late 20th century. The V ...
,
V850 V850 is a 32-bit RISC CPU architecture produced by Renesas Electronics for embedded microcontrollers. It was designed by NEC as a replacement for their earlier NEC V60 family, and was introduced shortly before NEC sold their designs to Renesas ...
,
M32R The M32R is a 32-bit RISC instruction set architecture (ISA) developed by Mitsubishi Electric for embedded microprocessors and microcontrollers. The ISA is now owned by Renesas Electronics Corporation, and the company designs and fabricates M32R im ...
, PowerPC, MIPS,
M680x0 The Motorola 68000 series (also known as 680x0, m68000, m68k, or 68k) is a family of 32-bit complex instruction set computer (CISC) microprocessors. During the 1980s and early 1990s, they were popular in personal computers and workstations and w ...
, and
RISC-V RISC-V (pronounced "risk-five" where five refers to the number of generations of RISC architecture that were developed at the University of California, Berkeley since 1981) is an open standard instruction set architecture (ISA) based on estab ...
* A
semicolon The semicolon or semi-colon is a symbol commonly used as orthographic punctuation. In the English language, a semicolon is most commonly used to link (in a single sentence) two independent clauses that are closely related in thought. When a ...
(;) — AMD 29k family, ARC,
H8/300 H8 is the name of a large family of 8-bit, 16-bit and 32-bit microcontrollers made by Renesas Technology, originating in the early 1990s within Hitachi Semiconductor. An administrator on the Renesas user community boards commented in 2011 that ...
family, HPPA, PDP-11,
picoJava picoJava is a microprocessor specification dedicated to native code, native execution of Java bytecode without the need for an interpreter (computing), interpreter or just-in-time compilation. The aim is to speed bytecode execution up by up to 20 ti ...
, Motorola, and M32C * The
at sign The at sign, , is normally read aloud as "at"; it is also commonly called the at symbol, commercial at, or address sign. It is used as an accounting and invoice abbreviation meaning "at a rate of" (e.g. 7 widgets @ £2 per widget = £14), but ...
(@) —
ARM In human anatomy, the arm refers to the upper limb in common usage, although academically the term specifically means the upper arm between the glenohumeral joint (shoulder joint) and the elbow joint. The distal part of the upper limb between th ...
* A double
slash Slash may refer to: * Slash (punctuation), the "/" character Arts and entertainment Fictional characters * Slash (Marvel Comics) * Slash (''Teenage Mutant Ninja Turtles'') Music * Harry Slash & The Slashtones, an American rock band * Nash ...
(//) —
AArch64 AArch64 or ARM64 is the 64-bit extension of the ARM architecture family. It was first introduced with the Armv8-A architecture. Arm releases a new extension every year. ARMv8.x and ARMv9.x extensions and features Announced in October 2011, AR ...
* A vertical bar (, ) —
680x0 The Motorola 68000 series (also known as 680x0, m68000, m68k, or 68k) is a family of 32-bit complex instruction set computer (CISC) microprocessors. During the 1980s and early 1990s, they were popular in personal computers and workstations and ...
* An
exclamation mark The exclamation mark, , or exclamation point (American English), is a punctuation mark usually used after an interjection or exclamation to indicate strong feelings or to show emphasis. The exclamation mark often marks the end of a sentence, f ...
(!) — 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 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 ...
development tools package since OS X.


Example program

A standard "Hello, world!" program for
Linux Linux ( or ) is a family of open-source Unix-like operating systems based on the Linux kernel, an operating system kernel first released on September 17, 1991, by Linus Torvalds. Linux is typically packaged as a Linux distribution, w ...
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 80386 microprocessor in 1985. IA-32 is the first incarnation o ...
: .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 The GNU toolchain is a broad collection of programming tools produced by the GNU Project. These tools form a toolchain (a suite of tools used in a serial manner) used for developing software applications and operating systems. The GNU toolchain pl ...
*
Binary File Descriptor library The Binary File Descriptor library (BFD) is the GNU Project's main mechanism for the portable manipulation of object files in a variety of formats. , it supports approximately 50 file formats for some 25 instruction set architectures. History ...
*
Comparison of assemblers This is an incomplete list of assemblers: computer programs that translate assembly language source code into binary programs. Some assemblers are components of a compiler system for a high level language and may have limited or no usable functio ...


References


External links

*
Gas manual
* {{DEFAULTSORT:Gnu Assembler Assemblers Free compilers and interpreters GNU Project software Linux programming tools Unix programming tools