as
Assemble assembly language source code
TLDR
Assemble a file, writing the output to a.out
Assemble the output to a given file
Generate output faster by skipping whitespace and comment preprocessing. (Should only be used for trusted compilers)
Include a given path to the list of directories to search for files specified in .include directives
SYNOPSIS
as [options] [files] [-o output.o]
PARAMETERS
-o objfile
Place output in specified objfile (default: a.out)
-g, --gdb-debug
Generate source-level debug info for GDB
--gdwarf-<version>
Generate DWARF debugging info (e.g., --gdwarf-5)
-I dir
Add dir to search path for input files
-a[dlms][=file]
Enable listing: d=debug, l=no macros, m=ignore versions, s=symbols
-f
Fast assembly: skip whitespace/comments
-L, --keep-locals
Retain local symbols (not strip them)
-march=ARCH[+ext]
Generate code for specific ARCH and extensions
-mcpu=CPU
Assemble for specific CPU variant
-mtune=CPU
Optimize for specific CPU
--32, --64, --x32
Select 32/64-bit code model (x86/x86_64)
-R, --generate-missing-build-notes
Add GNU build attributes notes
-T script
Read linker script for layout
-v, --version
Print assembler version
--help
Display summary of options
--target-help
Show target-specific options
-W, --no-warn
Suppress all warnings
--fatal-warnings
Treat warnings as errors
-S
Omit debug info (strips symbols)
DESCRIPTION
The as command, part of GNU Binutils, is a portable assembler that translates assembly language source files into relocatable object files for linking with ld. It supports numerous CPU architectures including x86, ARM, MIPS, PowerPC, and RISC-V, with architecture-specific options for instructions, ABI, tuning, and extensions.
as processes directives (e.g., .section, .global), macros, expressions, and symbols. It generates debugging information in DWARF or stabs format, supports listing files for verification, and offers optimizations like relaxation for smaller code. Input files typically end in .s or .S (preprocessed).
Invoked directly or automatically by compilers like gcc (e.g., gcc -c foo.s). Output defaults to a.out unless specified with -o. It includes assemblers for many targets, selectable via --target.
Extensible via linker scripts (-T) and highly configurable for embedded systems, kernel development, or performance-critical code.
CAVEATS
Many options are architecture-specific; use as --target-help for details. Not all CPUs/extensions supported on every host. Defaults to host architecture unless --target specified. Large files may require significant memory.
COMMON USAGE
as foo.s -o foo.o
as -64 foo.s -o foo.o (x86_64)
gcc foo.s -o foo (assembles/links)
LISTING CONTROL
Use -a flags for detailed output: as -al foo.s > foo.lst lists source with symbols.
MACROS
Supports .macro/.endm; preprocess with cpp for .S files: as -f foo.S.
HISTORY
Developed 1987-1988 by Dean Elsner, Jay Fenlason, et al., for GNU Project. Integrated into Binutils (first 2.1 in 1991); evolved with GCC/Binutils releases, adding multi-arch support, DWARF3+, relaxation in 2.10+ (1999). Maintained by GNU.


