Exercise 1: IRQ vs. NMI Maskability, and Why BRK Counts as an Interrupt — Possible Solution ==================================================================== IRQ VS. NMI — MASKABILITY ------------------------------ Per this chapter's own explanation, IRQ is MASKABLE — the I flag in the 6502's status register (P, from cpu8bit1-3) can be set specifically to disable IRQ entirely, meaning the CPU will simply ignore an IRQ signal while that flag is set. NMI is the opposite: it is NON-MASKABLE by definition (that's literally what the "NM" in NMI stands for) — no flag, no instruction, no setting can prevent an NMI from being serviced. This is a deliberate design choice: NMI is reserved specifically for events considered too critical to ever be allowed to wait or be ignored, while IRQ is meant for ordinary peripheral requests a program might legitimately need to postpone at certain points (for instance, during a timing-critical section of code). WHY BRK IS CATEGORIZED ALONGSIDE THEM DESPITE BEING SOFTWARE-TRIGGERED ------------------------------ BRK isn't triggered by any external hardware device at all — it's an actual, real opcode that a running program deliberately executes itself. It's grouped with IRQ and NMI because, once triggered, it produces THE SAME hardware response as a genuine interrupt: per this chapter's own description, PC and the status register both get pushed onto the stack, and execution jumps to a vector — in BRK's case, the SAME shared vector IRQ itself uses. From the CPU's mechanical point of view, BRK IS an interrupt in every way that matters at the hardware level; what makes it different is only WHERE it comes from (a deliberate instruction in the program's own code, not an external signal), not HOW the CPU responds to it. This is exactly why the B flag exists at all (per cpu8bit1-3's own earlier mention): since BRK and a genuine hardware IRQ share the same vector and produce identical-looking CPU behavior, the handler routine needs some way to distinguish which one actually happened — and the B flag, visible in the status register value pushed to the stack, is that distinguishing signal. WHY THIS WORKS AS AN ANSWER ------------------------------ It explains IRQ/NMI's maskability difference by naming the specific mechanism (the I flag) and the specific reasoning (critical vs. ordinary events), and explains BRK's inclusion by distinguishing its TRIGGER (software, not hardware) from its RESPONSE (identical to a real interrupt), tying that distinction directly to the B flag's own stated purpose.