Project 1: The ABI Inspector

A collection of simple C functions and a corresponding “ABI report” where you document the generated assembly code, explaining how arguments are passed, how values are returned, and how the stack is managed.

Quick Reference

Attribute Value
Primary Language C
Alternative Languages Assembly (for reading)
Difficulty Level 2: Intermediate
Time Estimate Weekend
Knowledge Area Assembly / Calling Conventions
Tooling GCC, Clang, GDB
Prerequisites C programming, comfort with the command line.

What You Will Build

A collection of simple C functions and a corresponding “ABI report” where you document the generated assembly code, explaining how arguments are passed, how values are returned, and how the stack is managed.

Why It Matters

This project builds core skills that appear repeatedly in real-world systems and tooling.

Core Challenges

  • Reading x86-64 assembly → maps to understanding mov, push, pop, call, ret
  • Mapping C variables to registers → maps to tracking which argument goes into RDI, RSI, RDX, etc.
  • Understanding the function prologue/epilogue → maps to push rbp; mov rbp, rsp and its purpose
  • Analyzing struct passing → maps to seeing how the compiler breaks down structs into registers or passes them on the stack

Key Concepts

  • System V AMD64 ABI: The standard calling convention for Linux/macOS on x86-64. Search for the official PDF.
  • x86-64 Assembly: “Computer Systems: A Programmer’s Perspective” Ch. 3 - Bryant & O’Hallaron
  • Disassembly with GDB: Use the disassemble command in GDB.

Real-World Outcome

// A function with many arguments
long func1(long a, long b, long c, long d, long e, long f, long g, long h) {
    return a + b + c + d + e + f + g + h;
}

// A function that takes a struct
struct Point { double x; double y; };
double func2(struct Point p) {
    return p.x + p.y;
}

Implementation Guide

  1. Reproduce the simplest happy-path scenario.
  2. Build the smallest working version of the core feature.
  3. Add input validation and error handling.
  4. Add instrumentation/logging to confirm behavior.
  5. Refactor into clean modules with tests.

Milestones

  • Milestone 1: Minimal working program that runs end-to-end.
  • Milestone 2: Correct outputs for typical inputs.
  • Milestone 3: Robust handling of edge cases.
  • Milestone 4: Clean structure and documented usage.

Validation Checklist

  • Output matches the real-world outcome example
  • Handles invalid inputs safely
  • Provides clear errors and exit codes
  • Repeatable results across runs

References

  • Main guide: LEARN_C_ABI_DEEP_DIVE.md
  • “Computer Systems: A Programmer’s Perspective” by Bryant & O’Hallaron