nasm-know-hows

nasm assembly related stuff

View on GitHub

๐ŸŽ“ NASM Assembly Programming - Complete Tutorial

Welcome to your comprehensive NASM assembly programming course! This tutorial will take you from beginner to advanced assembly programmer through structured, hands-on lessons.

๐Ÿ“š Course Structure

This course is organized into progressive levels with 20 core topics plus advanced projects.

๐Ÿ“ Directory Structure

nasm-tutorial/
โ”œโ”€โ”€ README.md                    # This file - course overview
โ”œโ”€โ”€ topics/                      # Individual topic lessons
โ”‚   โ”œโ”€โ”€ topic-01-setup.md
โ”‚   โ”œโ”€โ”€ topic-02-registers.md
โ”‚   โ””โ”€โ”€ ...
โ””โ”€โ”€ qna/                        # Common questions and deep dives
    โ”œโ”€โ”€ push-pop-explained.md
    โ”œโ”€โ”€ int-vs-syscall.md
    โ”œโ”€โ”€ memory-addressing.md
    โ””โ”€โ”€ sections-and-optimization.md

๐ŸŽฏ Complete Curriculum

LEVEL 1: Foundation (Weeks 1-2)

โœ… Topic 1: Setup & First Program

โœ… Topic 2: Registers & Data Types

๐Ÿ“š Supplementary: Instruction Encoding

โœ… Topic 3: Basic Instructions


LEVEL 2: Control Flow (Weeks 3-4)

โœ… Topic 4: Flags & Comparisons

โœ… Topic 5: Conditional Jumps

โœ… Topic 6: Loops


LEVEL 3: The Stack (Week 5)

โœ… Topic 7: Stack Operations

โœ… Topic 8: Stack Frames


LEVEL 4: Functions & Procedures (Weeks 6-7)

โœ… Topic 9: Calling Conventions

โœ… Topic 10: Procedures


LEVEL 5: Memory & Addressing (Week 8)

โœ… Topic 11: Memory Addressing Modes

โœ… Topic 12: Arrays & Strings


LEVEL 6: Advanced Operations (Weeks 9-10)

โœ… Topic 13: Multiplication & Division

โœ… Topic 14: Shifts & Rotates (Advanced)

โœ… Topic 15: Macros & Directives


LEVEL 7: System Programming (Weeks 11-12)

โœ… Topic 16: Linux System Calls

โœ… Topic 17: Interfacing with C


LEVEL 8: Optimization & Advanced (Weeks 13-14)

โœ… Topic 18: SIMD Instructions

โœ… Topic 19: Performance & Optimization

โœ… Topic 20: Debugging & Tools


โ“ Q&A Section - Deep Dives

These files contain detailed explanations of specific questions that came up during learning:

  1. Push and Pop Explained
    • Stack mechanics
    • LIFO behavior
    • Swapping values with push/pop
  2. int 0x80 vs syscall
    • When to use each
    • Register differences
    • Syscall number differences
    • Performance implications
  3. Memory Addressing with [ ] Brackets
    • Dereferencing explained
    • All addressing modes
    • Practical examples
    • Common mistakes
  4. Sections (.text, .data, .bss) and XOR Optimization
    • Memory layout
    • Section purposes
    • Relation to C code
    • Why xor reg, reg is better than mov reg, 0
  5. CMP vs TEST - Whatโ€™s the Difference?
    • CMP does subtraction, TEST does AND
    • When to use each instruction
    • Performance comparison
    • Common mistakes and decision tree
  6. Linux x86-64 Syscall Reference
    • Complete syscall register usage (RAX, RDI, RSI, RDX, R10, R8, R9)
    • Common syscalls with examples (read, write, open, close, exit)
    • File I/O, process control, memory management
    • Complete syscall number tables
    • Error handling and return values
    • Practical examples for each syscall
  7. All Types of Jumps - Complete Reference
    • Unconditional jumps (JMP)
    • Conditional jumps: signed (JG, JL, etc.) and unsigned (JA, JB, etc.)
    • Flag-specific jumps (JZ, JS, JC, JO, JP)
    • Loop instructions (LOOP, LOOPE, LOOPNE)
    • Function calls (CALL/RET)
    • Indirect jumps and jump tables (switch statements)
    • Conditional move (CMOVcc) as branchless alternative
    • Complete reference table with all 40+ jump variants
    • Performance optimization patterns
  8. Instruction Size (Bytes) vs Execution Time (Cycles)
    • Why we measure BOTH bytes and cycles
    • Bytes = space in memory (code size, cache efficiency)
    • Cycles = execution time (performance, speed)
    • How instruction size affects I-cache performance
    • Real-world examples showing both measurements matter
    • When to optimize for bytes vs cycles
    • Measuring techniques for each (objdump, RDTSC, perf)
    • Complete comparison with benchmarks

๐ŸŽ“ Progress Tracking

โœ… Foundation (Weeks 1-2):

โœ… Control Flow (Weeks 3-4):

โœ… The Stack (Week 5):

โœ… Functions & Procedures (Weeks 6-7):

โœ… Memory & Addressing (Week 8):

โœ… Advanced Operations (Weeks 9-10):

โœ… System Programming (Weeks 11-12):

โœ… Optimization & Advanced (Weeks 13-14):

Supplementary:

๐ŸŽ‰ ALL 20 TOPICS COMPLETED! Over 30,000 lines of comprehensive content!


๐Ÿ“– How to Use This Tutorial

  1. Sequential Learning: Follow topics in order - each builds on previous knowledge
  2. Hands-On Practice: Type and run every code example
  3. Complete Exercises: Practice problems reinforce concepts
  4. Check Understanding: Review knowledge checks before moving on
  5. Reference Q&A: Deep dive into specific questions as needed

๐Ÿ› ๏ธ Prerequisites


๐Ÿ“ Quick Command Reference

# Assemble 64-bit
nasm -f elf64 program.asm -o program.o

# Link
ld -o program program.o

# Run
./program

# Check exit code
echo $?

# Assemble with debug info
nasm -f elf64 -g -F dwarf program.asm

# Debug with GDB
gdb ./program

๐ŸŽฏ Learning Goals

By completing this course, you will be able to:

โœ… Write complete assembly programs from scratch โœ… Understand x86-64 architecture deeply โœ… Read and understand compiler output โœ… Optimize code at the lowest level โœ… Debug assembly with confidence โœ… Interface assembly with high-level languages โœ… Work with system calls and OS interfaces โœ… Apply assembly knowledge to reverse engineering and security


๐Ÿ“š Additional Resources


๐Ÿค Contributing

Found an error? Have a question? Want to add content? Feel free to modify and extend these materials!


Current Status: ๐ŸŽ‰ ALL 20 TOPICS COMPLETED! Over 30,000 lines of comprehensive NASM assembly programming content with C equivalents throughout!


Happy Assembly Programming! ๐Ÿš€