The fourth installment of The Retro Desk’s 65C02 Assembly Tutorial focuses entirely on arithmetic and logic instructions for the Commander X16 computer. This updated edition works with real hardware and tools, presenting a hands-on learning experience for anyone curious about low-level programming. Covering both 8-bit and 16-bit operations, it guides viewers step-by-step through the quirks and workflow of math on the 65C02 processor.
If you’ve followed the earlier episodes, you already understand memory access and program control flow. Now it’s time to put that foundation to practical use. As the video host puts it—light-heartedly quoting Barbie—”math’s not that hard!” Just a few new opcodes and a firm grasp of carry logic are enough to get started.
Basic Math: ADC and SBC
This lesson explains how ADC (Add with Carry) and SBC (Subtract with Carry) operate. Since the 65C02 is an 8-bit CPU, every math operation is byte-based and often extended to 16-bit using carry logic. You’ll learn how these instructions interact with the Carry, Zero, Negative, and Overflow flags—critical to chaining multi-byte calculations.
Special attention is given to how Carry behaves differently in addition vs. subtraction, and why forgetting to set or clear it can throw off your results. With a humorous but clear tone, the tutorial carefully walks through examples converting C-like expressions into multiple assembly steps.
Beyond 8 Bits: 16-Bit Arithmetic
The lesson then scales things up. Using the same logic, you’ll build a 16-bit math routine. This part emphasizes memory layout (little-endian), result handling, and when and why extra care is needed with high-byte operations.
The tutorial’s example: adding $1234 and $5678, then displaying the result ($68AC) on screen in hexadecimal. The process includes managing carry between low and high bytes, which echoes how we once did math by hand in school—only with memory locations.
Shifting, Rotation, and Bitwise Logic
The second half of the episode turns to bit-level operations. You’ll explore how ASL, LSR, ROL, and ROR shift or rotate bits and how these are essential substitutes for multiplication and division on a CPU without dedicated instructions.
Bitwise logic with AND, ORA, and EOR is also covered. These operations are essential for masking and manipulating data. Examples demonstrate how to translate compound C expressions into efficient assembly routines, reinforcing how much control you have when working directly with hardware.
Code Walkthrough and Demonstration
To bring it all together, the video shows a complete program that performs a 16-bit addition and prints the result using custom subroutines. You’ll see how to split a byte into two nibbles, convert each into a printable PETSCII character, and send them to the screen using the CHROUT kernel routine.
The walkthrough balances technical clarity with light humor. It even explains quirks like PETSCII’s offset values and how to distinguish between letters and numbers in hexadecimal output.
Why This Tutorial Works
What makes this 65C02 Assembly Tutorial compelling is its grounded, no-fluff explanation of real code that runs on actual hardware. It doesn’t gloss over how things work—every bit and byte is accounted for. And the video’s light tone keeps things approachable even when the instruction sets get dense.
If you’re working with the Commander X16 or just interested in how early computers did math, this episode offers an entertaining and valuable window into low-level programming. For the full code, examples, and further reading, check out SlithyMatt’s GitHub repository.