Jump to content

GNU Assembler

From Wikipedia, the free encyclopedia

This is an old revision of this page, as edited by 213.131.238.28 (talk) at 10:49, 31 May 2012 (Example Programs). The present address (URL) is a permanent link to this revision, which may differ significantly from the current revision.

GNU Assembler
Developer(s)GNU Project
Stable release
2.21 / December 8, 2010 (2010-12-08)
Written inC
PlatformCross-platform
TypeAssembler
LicenseGNU General Public License v3
Websitewww.gnu.org/software/binutils/

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 after as, 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.

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.[1]

Comments

GAS supports two comment styles:[2]

Multi-line comments

As in C multi-line comments start and end with mirroring slash-asterisk pairs:

(on i386):

/* 
comment
some more comment
*/
popl %edx /*
pushl %esp
addl $4, %esp
*/

Single-Line

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, and M880x0.
  • Semicolons are used on: AMD 29K family, ARC, H8/300 family, HPPA,PDP-11, picoJava, Motorola, and PowerPC.
  • The at sign is used on the ARM platform.
  • A vertical bar is used to signify comments when assembling on 680x0.

(on i386):

# comment
popl %edx # comment

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 Macintosh operating system's development tools package since OS X.

Example Programs

A standard “Hello, world!” program for Linux on IA-32:

	.data

msg:
	.asciz	"Hello, world!\n"
MSGLEN	= . - msg

	.text

	.globl	_start
_start:
	movl	$MSGLEN,%edx
	movl	$msg,%ecx
	movl	$1,%ebx
	movl	$4,%eax
	int	$0x80
	xorl	%ebx,%ebx
	movl	$1,%eax
	int	$0x80

A standard “Hello, world!” program for FreeBSD and Mac OS X on IA-32:

	.data

msg:
	.asciz	"Hello, world!\n"
MSGLEN	= . - msg

	.text

	.globl	_start
_start:
	pushl	$MSGLEN
	pushl	$msg
	pushl	$1
	movl	$4,%eax
	subl	$4,%esp
	int	$0x80
	addl	$16
	pushl	$0
	movl	$1,%eax
	subl	$4,%esp
	int	$0x80

Criticism

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.

However, since version 2.10 [3] Intel syntax can be used though use of the .intel_syntax directive, rendering the earlier criticisms null and void. [4] [5]

See also

References

  1. ^ "The GNU Assembler - Assembler Directives".
  2. ^ Red Hat Inc. "Using as". Retrieved Mar 11, 1012. {{cite web}}: Check date values in: |accessdate= (help)
  3. ^ "GNU Assembler News".
  4. ^ "AT&T Syntax versus Intel Syntax". Using as, the GNU Assembler.
  5. ^ Ram Narayan (2007-10-17). "Linux assemblers: A comparison of GAS and NASM". IBM DeveloperWorks. Retrieved 2007-10-17.