GNU Assembler: Difference between revisions
Citation bot (talk | contribs) m Alter: template type. Add: citeseerx. Removed URL that duplicated unique identifier. | You can use this bot yourself. Report bugs here. | Activated by User:AManWithNoPlan | All pages linked from User:AManWithNoPlan/sandbox2. |
→Example program: commented hello world excerpt (up to editors, personally reading this I had no idea what anything between _start and .data meant, but I guess strictly the article is about GNU assembler and not the minutiae of the linux kernel) |
||
Line 57: | Line 57: | ||
.text |
.text |
||
_start: |
_start: |
||
movl $4, %eax |
movl $4, %eax # 4 (code for "write" syscall) -> EAX register |
||
movl $1, %ebx |
movl $1, %ebx # 1 -> EBX (1st argument to syscall) |
||
movl $msg, %ecx |
movl $msg, %ecx # address of msg string -> ECX (2nd argument) |
||
movl $len, %edx |
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 |
|||
int $0x80 |
|||
movl $1, %eax |
movl $1, %eax # 1 ("exit") -> EAX |
||
movl $0, %ebx |
movl $0, %ebx # 0 (with success) -> EBX |
||
int $0x80 |
int $0x80 # see previous |
||
.data |
.data |
||
msg: |
msg: |
||
.ascii "Hello, world!\n" |
.ascii "Hello, world!\n" # inline ascii string |
||
len = . - msg # assign value of (current address - address of msg start) to symbol "len" |
|||
len = . - msg |
|||
</source> |
</source> |
||
Revision as of 18:01, 7 April 2020
Developer(s) | GNU Project |
---|---|
Stable release | 2.32
/ February 2, 2019 |
Written in | C |
Platform | Cross-platform |
Type | Assembler |
License | GNU General Public License v3 |
Website | www |
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.
History
The first version of GAS was published c. 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.
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]
Comments
GAS supports two comment styles:[3]
Multi-line comments
As in C multi-line comments start and end with mirroring slash-asterisk pairs:
/*
comment
*/
Single-Line comments
Single line comments have a few different formats varying on which architecture is being assembled for.
- Hash symbols (#) are used for the platforms: i386, x86-64, i960, 68HC11, 68HC12, VAX, V850, M32R, PowerPC, MIPS and M680x0.
- Semicolons (;) are used on: AMD 29k family, ARC, H8/300 family, HPPA, PDP-11, picoJava, Motorola, and M32C.
- The at sign (@) is used on the ARM platform.
- A double slash (//) is used on the AArch64 platform.
- A vertical bar (|) is used to signify comments when assembling on 680x0.
- An exclamation mark (!) on the Renesas SH platform.
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 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 macOS.
Example program
A standard “Hello, world!” program for Linux on IA-32 using the default AT&T syntax:
.global _start
.text
_start:
movl $4, %eax # 4 (code for "write" syscall) -> EAX register
movl $1, %ebx # 1 -> 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"
Intel syntax
Those more accustomed to writing in Intel syntax have argued that not supporting the Intel syntax for assembly on the x86 and x86-64 platforms, as many other assemblers do, is a flaw.[according to whom?]
However, since version 2.10, Intel syntax can be used through use of the .intel_syntax
directive.[4][5][6]
See also
References
- ^ a b "The GNU Assembler" (Document).
{{cite document}}
: Cite document requires|publisher=
(help); Unknown parameter|citeseerx=
ignored (help) - ^ "The GNU Assembler - Assembler Directives".
- ^ Red Hat Inc. "Using as". Retrieved Jan 10, 2013.
- ^ "GNU Assembler News".
- ^ "AT&T Syntax versus Intel Syntax". Retrieved 28 July 2014.
- ^ Ram Narayan (2007-10-17). "Linux assemblers: A comparison of GAS and NASM". IBM DeveloperWorks. Archived from the original on 3 Mar 2009. Retrieved 28 July 2014.
External links
- Official website
- Gas manual
- Linux User Commands Manual : the portable GNU assembler –