2.34 / February 1, 2020
|License||GNU General Public License v3|
The GNU Assembler, commonly known as gas or simply as, its executable name, is the assembler used 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, and various other software. It is a part of the GNU Binutils package.
The GAS executable is named as, the standard name for a Unix assembler. GAS is cross-platform, and both runs on and assembles for a number of different computer architectures. Released under the GNU General Public License v3, GAS is free software.
GAS supports a general syntax that works for all of the supported architectures. The general syntax includes assembler directives and a method for commenting.
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.
GAS supports two comment styles:
As in C multi-line comments start and end with mirroring slash-asterisk pairs:
/* comment */
Single line comments have a few different formats varying on which architecture is being assembled for.
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 GNU/Linux operating systems in conjunction with other GNU software. A modified version of GAS can also be found in the Macintosh operating system's development tools package since OS X.
.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 value of (current address - address of msg start) to symbol "len"
Edited: 2021-06-18 19:34:04