BRK

From Wikipedia, the free encyclopedia

In 6502 assembly language programming, BRK is an opcode that causes a software interrupt or trap. The generalized actions of BRK are as follows:

Note that neither the accumulator or index registers are pushed on to the stack. Also, the vector (0xFFFE) through which the processor jumps in response to BRK is the same as that for an interrupt request, requiring that the IRQ service routine get a copy of the status register from the stack to check the B bit so as to determine whether the interrupt was hardware or software.

In the original 6502, the simultaneous assertion of a hardware interrupt line and execution of BRK was not accounted for in the design—the BRK instruction will be ignored in such a case. Also, the status of the decimal mode flag in the processor status register was preserved, which could potentially result in a difficult to locate bug in the interrupt handler if decimal mode happened to be enabled at the time of BRK being executed. This was fixed in the CMOS versions of the processor.