Article by Ayman Alheraki on January 11 2026 10:36 AM
The GNU Assembler (GAS) is the default assembler for the GNU operating system. It is a part of the GNU Binutils package and serves as the assembler used by GCC (GNU Compiler Collection). GAS is portable, supporting multiple CPU architectures, and is widely used in Unix-like operating systems.
GAS stands out due to its:
Cross-platform support: Works with x86, ARM, RISC-V, PowerPC, and MIPS architectures.
Integration with GCC and LLVM/Clang: Ensures compatibility with modern compilers.
Open-source and actively maintained: Part of the GNU project, ensuring continuous updates.
Supports both AT&T and Intel syntax: Offers flexibility in writing assembly code.
Lightweight and efficient: Designed for speed and portability.
GAS plays a crucial role in:
System programming: Writing low-level OS and kernel code.
Embedded systems: Used in microcontroller and real-time systems.
Compiler development: Acts as a backend for GCC.
Reverse engineering & security: Used for binary analysis and exploit development.
A simple Hello World in GAS for Linux:
.section .datamsg: .asciz "Hello, World!\n"
.section .text.global _start
_start: mov $1, %rax # syscall: write mov $1, %rdi # file descriptor: stdout mov $msg, %rsi # message address mov $14, %rdx # message length syscall
mov $60, %rax # syscall: exit xor %rdi, %rdi # status 0 syscallCompile and run:
as hello.s -o hello.old hello.o -o hello./helloGAS was developed by the Free Software Foundation (FSF) as an open-source alternative to proprietary assemblers like Microsoft MASM and NASM.
Initially designed as part of the GNU toolchain.
Became the default assembler for Linux distributions.
Integrated into GCC, making it the most widely used assembler in open-source software.
Support for RISC-V, ARM64, and PowerPC.
Introduction of macros, debugging symbols, and optimization directives.
A simple RISC-V assembly program using GAS:
.global _start.section .text_start: li a0, 42 # Load immediate value 42 into register a0 li a7, 93 # syscall: exit ecall # Call kernelCompile with:
riscv64-linux-gnu-as program.s -o program.oriscv64-linux-gnu-ld program.o -o programqemu-riscv64 programGAS supports:
x86 (32-bit and 64-bit)
ARM (AArch64, Thumb)
MIPS (R3000, R4000, R6000, etc.)
PowerPC (Power ISA)
RISC-V (32-bit and 64-bit)
SPARC, SuperH (SH), and more
Each architecture has unique registers, instruction formats, and addressing modes.
AT&T syntax (default in GAS):
movl $5, %eax # Move 5 into eax (AT&T: source, destination)Intel syntax (enable with .intel_syntax noprefix):
mov eax, 5 # Move 5 into eax (Intel: destination, source)Lightweight and efficient assembly generation
Seamless integration with embedded toolchains
Better portability than proprietary assemblers
.global _start.section .text_start: mov x0, #1 // stdout adr x1, msg // Load address of msg mov x2, #14 // Message length mov x8, #64 // syscall: write svc #0 // System call
mov x8, #93 // syscall: exit svc #0
.section .datamsg: .asciz "Hello, ARM!\n"Compile:
as hello.s -o hello.old hello.o -o hello./helloGAS is the default assembler in GCC and compatible with LLVM/Clang.
Developers can:
Set breakpoints.
Inspect registers.
Step through assembly instructions.
VS Code, Code::Blocks, Eclipse support GAS
Syntax highlighting, debugging tools available
Godbolt provides an online playground for exploring GAS-generated assembly.
Preinstalled on Linux and BSD distributions.
Available in Xcode for macOS.
MinGW: Native Windows binaries.
Cygwin: Unix-like environment.
WSL: Run GAS inside Ubuntu on Windows.
Switching to Intel syntax:
.intel_syntax noprefixmov eax, 10Use registers efficiently (avoid unnecessary memory access).
Optimize loops (unrolling, pipelining).
Minimize stack operations.
Macros reduce redundancy:
.macro PRINT_MSG msg mov $1, %rax mov $1, %rdi mov $msg, %rsi syscall.endmDirectives like .global and .section help with symbol visibility and memory layout.
Programming from the Ground Up (Good for beginners)
Online courses on x86 & ARM Assembly
Linux Kernel (low-level system code)
GNU Coreutils (performance optimizations)
GAS is open-source; contribute via GNU Binutils Git repository.
Supports modern architectures
Integral to compiler toolchains
Used in security analysis and low-level programming
RISC-V & ARM adoption growing
GAS continues evolving with new optimizations and debugging features