Chapter 6 Further Reading: The NASM Assembler

NASM-Specific References


1. NASM Manual (nasm.us/doc) H. Peter Anvin, Frank Kotler, and others. Free at nasm.us/doc

The definitive NASM reference. For Chapter 6's content, focus on: Chapter 2 (running NASM), Chapter 3 (NASM language: tokens, expressions, labels), Chapter 4 (the NASM preprocessor: macros, conditionals, includes), Chapter 5 (assembler directives: SECTION, GLOBAL, EXTERN, EQU, TIMES), and Chapter 6 (output formats). Chapter 4 on the preprocessor is particularly detailed — it covers every feature of %macro, including rotates (%rotate), variadic macros, local labels in macros, and context-sensitive macros. The online version is searchable; use it as a reference rather than reading linearly.


2. NASM Tutorial at cs.lmu.edu Ron Mak. Free at cs.lmu.edu/~ray/notes/nasmtutorial

A concise, well-organized tutorial that covers the practical subset of NASM needed for most assembly programming. Goes through data types, instructions, system calls, functions, and macros with working examples. Good for readers who want a gentler introduction before tackling the full NASM manual. The section on calling C from NASM and calling NASM from C is particularly practical.


GNU Assembler (GAS)


3. "Using as: The GNU Assembler" GNU Project. Free at gnu.org/software/binutils/manual

The complete GAS documentation. Chapter 2 covers command-line options. Chapter 3 covers syntax (AT&T syntax, sections, symbols, expressions). Chapter 7 covers machine-specific features for x86/x86-64. The chapter on directives (Chapter 5) documents all the .byte, .long, .quad, .ascii, .globl, .equ, etc. directives that appear in GCC output. If you'll be reading or writing GAS source, this is the reference. If you just need to read GCC's -S output, the comparison table in Case Study 6.2 is sufficient.


4. GCC Internals: "Describing Instruction Patterns" GCC Project. Part of the GCC Internals Manual. Free at gcc.gnu.org/onlinedocs

For readers who want to understand how GCC generates assembly from C, the GCC internals manual describes the RTL (Register Transfer Language) intermediate representation, machine description files, and code generation. This is deep compiler internals territory — not necessary for using assembly, but illuminating for understanding why GCC generates specific patterns. The section on "Constraints for asm Statements" (describing inline assembly in C) is particularly relevant when you need to embed assembly in C code.


x86 Assembly Syntax History


5. "Intel 64 and IA-32 Architectures Software Developer's Manual, Volume 2" Intel Corporation. The instruction reference chapters. Free at intel.com/sdm

Intel's own instruction reference uses Intel syntax, which is (not coincidentally) the syntax NASM uses. For each instruction, Intel documents: the full mnemonic with all operand forms, the operation description in pseudocode, the flags affected, and the encoding. Consulting this for an instruction tells you the authoritative description of what it does. For NASM syntax questions, Volume 2 is the ground truth that NASM follows.


6. "x86 Assembly Language Reference Manual" Sun Microsystems (Oracle), 2010. Available in Oracle documentation archives

Sun's assembly language reference for the x86 architecture, focusing on the differences between AT&T and Intel syntax. Written when Sun was porting Solaris to x86 and their engineers needed clear documentation of the syntax differences. Still the clearest explanation of why AT&T syntax evolved the way it did and how each syntax element maps to the other. Useful for building a complete mental mapping between the two syntaxes.


Assembler Internals


7. "Assemblers and Loaders" D. Salomon, Ellis Horwood, 1993. Partial text available online

One of the few books dedicated to the internals of assemblers — how they work, not just how to use them. Covers two-pass assembly (forward reference resolution), symbol tables, relocation, macro processing, and output file generation. Understanding how NASM processes your source (two passes: first pass to assign addresses, second pass to generate code with resolved addresses) explains why some constructs work and others don't. The macro processor chapter explains how multi-line macros are expanded.


8. "Linkers and Loaders" John R. Levine, Morgan Kaufmann, 1999. Free at iecc.com/linker

Companion to Chapter 5's reading. Specifically relevant to Chapter 6: the discussion of symbols (local vs global, strong vs weak, defined vs undefined) explains how NASM's global/extern declarations work and what the linker does with them. Chapter 2 on object files explains what's inside the ELF64 object file NASM produces and why relocations exist. Understanding the assembler's output (the object file) and the linker's consumption of that output is the bridge between NASM's source-level abstractions and the final executable.


Macro Assembly Techniques


9. "The Art of Assembly Language, Chapter 8: Macros" Randall Hyde, No Starch Press

Hyde's treatment of macro assembly is one of the most thorough available. Covers macro design principles, macro libraries, the pitfalls of token pasting, context-dependent macros, and the trade-offs between macros and procedures (functions). While the book uses HLA (High Level Assembly), the macro design principles apply directly to NASM macros. The discussion of "macros versus procedures" — when to use each and why — is particularly relevant after this chapter.


10. NASM on GitHub (netwide-assembler/nasm) H. Peter Anvin and contributors. github.com/netwide-assembler/nasm

The NASM source code and issue tracker. When you encounter unexpected NASM behavior or want to understand why a specific encoding is generated, reading the NASM source (particularly assemble.c, expr.c, and the instruction patterns in insns.dat) answers the question definitively. The issue tracker also contains useful discussions of edge cases and design decisions. The test suite (test/) contains hundreds of small examples that demonstrate correct and incorrect NASM usage — a practical reference for edge cases.