Story Details

  • How MOS 6502 Illegal Opcodes Work – Michael Steil

    Posted: 2025-04-20 12:36:05

    Michael Steil's blog post explores the behavior of illegal or undocumented opcodes on the MOS 6502 processor. Rather than simply halting or throwing an error, these opcodes execute as combinations of shorter, legal instructions. The 6502's instruction decoding mechanism, which combines bits from different parts of the opcode byte, leads to these unintended combinations. Steil demonstrates how these combined instructions can be predicted and even utilized for creative programming tricks, offering a deep dive into the processor's architecture. He provides examples of how these illegal opcodes can manipulate registers and flags in unexpected ways, opening a window into the inner workings of this classic CPU.

    Summary of Comments ( 2 )
    https://news.ycombinator.com/item?id=43743399

    HN commenters discuss the cleverness of undocumented opcodes on the 6502, with several sharing their experiences using them in demos and games. Some appreciated the author's clear explanations and visualizations of the normally chaotic behavior, while others reminisced about discovering and exploiting these opcodes in their youth on platforms like the C64 and Apple II. A few highlighted the community effort in meticulously documenting these behaviors, comparing it to similar explorations of the Z80 and other CPUs. Some commenters also pointed out the article's brief mention of the security implications of these undefined instructions in modern contexts.