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: