Chapter 7: Assembly Language and the Dark Heart of Computer Science

Every program that we have written in this course, from finding frequent words to simulating gravity and building evolutionary trees, eventually runs as a sequence of tiny instructions on a processor that only understands ones and zeros. In this chapter, we leave Python behind for a while and travel down to that level, which we affectionately call the dark heart of computer science.

We start by seeing how a computer’s processor and memory work together, and how numbers are stored in binary and written in hexadecimal. We then meet X-Toy, a virtual computer simple enough to understand completely, with sixteen registers, 256 words of memory, and sixteen instructions. Along the way, we learn bitwise operations, how computers represent negative numbers with two’s complement, and how branching lets us build if/else statements, loops, and functions in assembly language, ending with a multiplication function written entirely in X-Toy.

Core text (coming soon)

The core text for this chapter, which presents these ideas independently of any particular machine, is coming soon. In the meantime, the code alongs below are complete, and each one contains the video in which we work through the ideas and write the programs together.

Python code alongs

Find all of the code alongs on the Chapter 7 Python Code Alongs page, or jump straight to a lesson:

  1. The CPU, Memory, and Binary
  2. Hexadecimal: A Shorthand for Binary
  3. Meet X-Toy, a Virtual Computer
  4. Bitwise Operations in X-Toy: AND, XOR, Shifts, and Bit Masks
  5. Negative Numbers and Two’s Complement in X-Toy
  6. Indirect Memory, Branching, and If/Else in X-Toy
  7. Loops and Functions in X-Toy: Multiplication
Scroll to Top
Programming for Lovers banner no background
programming for lovers logo cropped

Join our community!