Building (and Breaking) Your First X86 Assembly Program
We build a minimal X86 assembly program, run it… and hit a crash. But that crash is exactly what makes this program worth writing.
Introduction
Recap from the previous article: In the last couple of articles, we built a simple but complete mental model of how a basic computer executes instructions. We explored how an ALU performs arithmetic operations, how registers serve as fast-access storage, and how the control unit fetches and executes instructions stored in memory. We also introduced the structure of assembly programs, the use of labels, and how data and instructions are laid out in different sections like
.text
and.data
. That article provided the conceptual foundation we need to now dive into real X86-64 assembly code.
This article is part of my series on the basics of X86-64 assembly programming. Until now, we have been working mostly with ideas. We talked about what it means for a computer to execute a program, how computation is carried out by hardware, and how memory is laid out to store data and instructions. We have seen snippets of assembly here and there, but we haven’t written a full program yet. That changes now.
In this article, we will write our first complete (well, almost) assembly program. It won’t do anything exciting, but that’s the point. Like “Hello, world” in high-level languages, this program is just a vehicle to help us understand the mechanics of how an assembly program is written, assembled, linked, and executed. Along the way, we’ll revisit some of the concepts we’ve discussed before and see how they manifest in actual code.
If you haven’t read the previous articles in this series, here’s what you have missed:
This article is part of a paid subscriber series.
If you’re enjoying the content, please consider upgrading to a paid plan to unlock the rest of this series. Paid subscribers also get access to recordings of past live sessions, early and discounted access to courses and books, and more.
Alternatively, you can purchase an ebook version of this series. (If you're already a paid subscriber, email me for a discounted link.)