A fundamental introduction to x86 assembly programming
The x86 instruction set architecture is at the heart of CPUs that power our home computers and remote servers for over two decades. Being able to write code at the lowest level, in assembly language, is a powerful skill to have. It enables you to write faster code, use features unavailable in C, and reverse-engineer compiled code.
But starting out can be a daunting task. The official documentation manuals from Intel are well over a thousand pages long. Twenty years of continual evolution with backward compatibility has produced a landscape with clashing design principles from different eras, deprecated features occupying space, layers upon layers of mode switches, and an exception to every pattern.
In this tutorial, I will help you gain a solid understanding of the x86 ISA from basic principles. I will focus more on building a mental model of what’s happening, rather than giving every detail precisely (which would be long and boring to read). If you want to make use of this knowledge, you should simultaneously refer to another tutorial that shows you how to write and compile a simple function, and also have a list of CPU instructions open for referencing. My tutorial will start out clear and simple, and add complexity in manageable steps – unlike other documentation that tend to lay out the information all at once.
The prerequisites to reading this tutorial are binary numbers, moderate experience programming in an imperative language (C/C++/Java/Python/etc.), and the concept of memory pointers (C/C++). You do not need to know how CPUs work internally or have prior exposure to assembly language.