News for hackers. Stuff that matters.
Re:XOR'ing a register with itself is the idiom for zeroing i... by HarHarVeryFunny on Wednesday April 22, 2026 @08:01AM (#47862357)
The 6502 doesn't support XOR A or SUB A, and in fact doesn't have a SUB opcode at all, only SBC (subtract with carry, requiring an extra opcode to set the carry flag beforehand).
Re:XOR'ing a register with itself is the idiom for zeroing i... by flohofwoe on Wednesday April 22, 2026 @09:07AM (#47863034)
I was handwaving over the details, SBC is identical to SUB when the carry flag is clear, so it's understandable why the 6502 designers didn't waste an instruction slot.

EOR and SBC still have the same cycle counts though.

Re:XOR'ing a register with itself is the idiom for zeroing i... by HarHarVeryFunny on Wednesday April 22, 2026 @10:06AM (#47863874)
Sure, in some contexts you would know that the carry flag was set or clear (depending on what you needed), and it was common to take advantage of that and not add an explicit clc or sec, although you better comment the assumption/dependency on the preceding code.

However the 6502 doesn't support reg-reg ALU operations, only reg-mem, so there simply is no xor a,a or sbc a,a support. You'd either have to do the explicit lda #0, or maybe use txa/tya if there was a free zero to be had.