Compiling to Assembly
from Scratch

   $49
Buy hardcover
at lulu.com
Read online for free


Have you been trying to learn how compilers and programming languages work?

Then come along! Let’s make a compiler that goes all the way from source to assembly from scratch—no shortcuts!

This book will teach you enough compiler theory and assembly programming to get going. It uses a subset of TypeScript that reads like pseudocode and targets ARM 32-bit instruction set.

 

Table of Contents

  1. Introduction
  2. TypeScript Basics

Part I: Baseline Compiler

  1. High-level Compiler Overview
  2. Abstract Syntax Tree
  3. Parser Combinators
  4. First Pass: The Parser
  5. ARM Assembly Programming
  6. Second Pass: Code Generation

Part II: Compiler Extensions

  1. Introduction to Part II
  2. Primitive Scalar Data Types
  3. Arrays and Heap Allocation
  4. Visitor Pattern
  5. Static Type Checking and Inference
  6. Dynamic Typing
  7. Garbage Collection

Appendices

  1. Running ARM Programs
  2. GAS v. ARMASM Syntax

Author

My name is Vladimir Keleshev. I am a software developer living and working just outside of Copenhagen. I have worked with embedded systems, safety-critical systems, compilers, and now in finance with domain-specific languages.

Illustrator

The cover is illustrated by Katiuska Pino. She also drew 15 chapter illustrations that are exclusive to the print edition of the book.

Print edition consists of 207 pages, size 6×9” (152×229 mm), in matte hard cover, available at lulu.com. ISBN: 978-87-980078-0-7.

Ebook edition

This book was originally published in 2020 as ebook. The online edition replaces the ebook edition.

Citation

@book{Keleshev:2024,
  author="Vladimir Keleshev",
  title="Compiling to Assembly from Scratch",
  publisher="keleshev.com",
  year=2024,
  isbn="978-87-980078-0-7",
  note="Originally published in 2020 as ebook",
}

Source code

Source code from the book is available on GitHub. Python and OCaml ports of the compiler are available as well.

Questions? Comments? Feedback?