GNU Assembler
Template:Short description {{#invoke:Infobox|infobox}}Template:Template other {{#invoke:Check for unknown parameters|check|unknown=Template:Main other|preview=Page using Template:Infobox software with unknown parameter "_VALUE_"|ignoreblank=y| AsOf | author | background | bodystyle | caption | collapsetext | collapsible | developer | discontinued | engine | engines | genre | included with | language | language count | language footnote | latest preview date | latest preview version | latest release date | latest release version | latest_preview_date | latest_preview_version | latest_release_date | latest_release_version | licence | license | logo | logo alt | logo caption | logo class | logo size | logo title | logo upright | logo_alt | logo_caption | logo_class | logo_size | logo_title | logo_upright | middleware | module | name | operating system | operating_system | other_names | platform | programming language | programming_language | qid | released | replaced_by | replaces | repo | screenshot | screenshot alt | screenshot class | screenshot size | screenshot title | screenshot upright | screenshot_alt | screenshot_class | screenshot_size | screenshot_upright | service_name | size | standard | title | ver layout | website }}Template:Main other{{#invoke:Check for conflicting parameters|check | template = Template:Infobox software | cat = Template:Main other | logo size; logo_size | logo class; logo_class | logo alt; logo_alt | logo title; logo_title | logo caption; logo_caption | screenshot size; screenshot_size | screenshot upright; screenshot_upright | screenshot class; screenshot_class | screenshot alt; screenshot_alt | screenshot title; screenshot title | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | latest release version; latest_release_version | latest release date; latest_release_date | latest preview version; latest_preview_version | latest preview date; latest_preview_date | programming language; programming_language | operating system; operating_system }}
The GNU Assembler, commonly known as gas or as, is the assembler developed by the GNU Project. It is the default final pass of GCC, generating machine code from the assembly-language output of the code generator. It is used to assemble the assembly-language portions of 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 Template:Mono, 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.[1] It was written by Dean Elsner and supported the VAX architecture.[1]
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.[2]
Since version 2.10, Intel syntax can be used through use of the .intel_syntax directive.[3][4][5]
Comments
GAS supports two comment styles.[6]
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, M680x0, and RISC-V
- 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 (|) — M680x0
- An exclamation mark (!) — Renesas SH
Usage
Being the final stage 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
{{#invoke:Portal|portal}}
- GNU toolchain
- Binary File Descriptor library
- Comparison of assemblers
- List of assembly software and tools
References
External links
Template:GNU Template:RISC-V Template:X86 assembly topics
- ↑ 1.0 1.1 Template:Cite CiteSeerX
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}
- ↑ {{#invoke:citation/CS1|citation |CitationClass=web }}