LinuxCommandLibrary

as

Assemble assembly language source code

TLDR

Assemble a file, writing the output to a.out

$ as [path/to/file.s]
copy

Assemble the output to a given file
$ as [path/to/file.s] -o [path/to/output_file.o]
copy

Generate output faster by skipping whitespace and comment preprocessing. (Should only be used for trusted compilers)
$ as -f [path/to/file.s]
copy

Include a given path to the list of directories to search for files specified in .include directives
$ as -I [path/to/directory] [path/to/file.s]
copy

SYNOPSIS

as [options] [-o objfile] [infile...]

PARAMETERS

-o file
    Specifies the name of the output object file. By default, a.out is used as the output filename if not specified.

-I dir
    Adds dir to the list of directories to be searched for files specified in .include directives within the assembly source.

-g
    Generates debugging information (in STABS format by default) for use with a debugger like gdb. This helps in debugging assembly code.

-L
    Normally, local symbols are deleted from the symbol table to save space. This option retains them, which is particularly useful for debugging.

--target-help
    Displays architecture-specific help for the currently configured target, detailing target-specific options and directives.

--version
    Prints the GNU Assembler's version number to standard output and exits.

--help
    Prints a summary of the command-line options and exits.

-msyntax={att|intel}
    For x86 targets, specifies the assembly syntax to use. Defaults to AT&T syntax. Use att for AT&T syntax, or intel for Intel syntax.

DESCRIPTION

as is the GNU Assembler, a fundamental component of the GNU Binutils package. It translates assembly language source files (typically ending in .s or .S) into relocatable object files (commonly ending in .o).

These object files contain machine code and data, along with information for the linker (such as ld) to combine them into an executable program, a shared library, or another object file. as supports a vast array of processor architectures, making it highly versatile for various embedded systems and general-purpose computing environments. It's often invoked indirectly by compilers like gcc when compiling high-level languages, but it can also be used directly for low-level programming or system-specific tasks. Key features include support for macros, conditional assembly, and generation of debugging information.

CAVEATS

The default assembly syntax for x86 architectures in as is AT&T, which differs significantly from the Intel syntax commonly seen in documentation and other assemblers. This can be a source of confusion for new users.

Error messages from as can sometimes be cryptic, requiring a good understanding of assembly language and the specific directives being used. Debugging assembly errors can be challenging.

INPUT AND OUTPUT FILES

Input files are typically assembly source code, often with a .s or .S extension. as processes these files and produces relocatable object files, conventionally named with a .o extension. These object files are not directly executable but are linked together by a linker to form a complete program or library.

ASSEMBLY DIRECTIVES

Assembly source code processed by as includes both machine instructions and assembler directives (also known as pseudo-ops). Directives control the assembly process itself, defining data, allocating memory, setting up sections, and providing information to the linker and debugger. Common examples include .data, .text, .bss, .globl, .byte, and .align.

HISTORY

The GNU Assembler (as) is a fundamental part of the GNU Project's Binutils package. Its development began early in the GNU project to provide a free and open-source alternative to proprietary assemblers. It was designed to be highly portable, supporting a wide range of CPU architectures and operating systems. as has been a stable and critical component of the GNU toolchain for decades, evolving to support new architectures and assembly features, and continues to be actively maintained as a cornerstone of Linux and other Unix-like systems.

SEE ALSO

gcc(1), ld(1), objdump(1), readelf(1), gdb(1), make(1)

Copied to clipboard