Do you know how a CPU works? How does the CPU know when to add two numbers or grab something from a memory location? What exactly are all those 1s and 0s doing?
In this presentation, I’ll break down how I learned about assembly language programming, machine code, digital electronics, and the exciting early days of computing by writing a 6502 CPU emulator in Elixir. By utilizing Elixir’s amazing pattern matching abilities and memory-safe operations, we can watch a virtual 6502 CPU step through each instruction it encounters. Furthermore, with the magic of Phoenix LiveView, we can take it a step further by displaying the entire memory stack and disassembler in a web browser – including interacting with virtual hardware!
The 6502 CPU was first introduced in 1975 and eventually made its way into many very popular and influential early computers such as the Apple II, Commodore 64, Atari 2600 (and other families), BBC Micro, and even the Nintendo Entertainment System. With a history that strong and old, you may think that its best days are behind it. However, according to the manufacturer, hundreds of millions of 6502 CPUs are produced and shipped every year. It has a relatively small but powerful instruction set, making it a great beginner’s introduction into bare-bones and/or retro computing.
-----------------
Geoffrey Lessel has been learning Elixir since 2014 and has spoken at multiple conferences over the years, including 2 previous ElixirConf’s and a Lonestar ElixirConf. He is the author of Phoenix in Action and loves experimenting with new and creative ways to use Elixir.