WARNING! Pedantry coming!
From the referenced Rockwell 6502 page:
Code:
ChkBrk: ; Check if Interrupt was caused by a BRK
TSX ; Get Stack Pointer to X
INX ; =Address where Y is stored
INX ; =Address where X is stored
INX ; =Address where A is stored
INX ; =Address where P is stored
LDA $0100,X ; Get Stack copy of PSW to A
AND A,$10 ; Isolate P.B
BEQ NotBrk ; If P.B=0, skip BRK Handling code
Now, I don't intend to pick on anyone's effort to improve their understanding of the 6502. However, some of the code examples on that page don't necessarily set forth an optimum style to the assembly language programmer who is learning the craft. I think most experienced programmers would write the above as:
Code:
ChkBrk: ; Check if Interrupt was caused by a BRK
TSX ; Get Stack Pointer to X
LDA $0104,X ; Get Stack copy of PSW to A
AND A,$10 ; Isolate P.B
BNE IsBrk ; If P B=1 handle BRK
;
;
; fall thru to IRQ handler...
;
A fundamental programming principle that should be observed, especially in time-sensitive functions, is to arrange branches so that they are not taken in the most common of cases. Also, there is no need to consume eight clock cycles with aligning
.X to point at the stack copy of
SR, given that the 6502's stack is in an immutable place. Might as well make the assembler do the grunt work. Of course, the above will blow up if
$0104,X evaluates to an address that is higher than
$01FF. However, that would only occur if the stack pointer was
$03 or lower when the interrupt occurred.