A lot of confusion around ADC/SBC seems to be around the overflow flag, however I've found the carry flag equally confusing for a particular case.
What should be the result of:
Code: Select all
clc
lda #0
sbc #$ff
At first glance I thought it would be A=0, C=1. Klaus' tests are looking for A=0, C=0. Surely the carry flag should be set because we have to borrow a bit to subtract $ff from it?
Then I thought about it as a signed number, where $ff has the value -1. 0 - (-1) = 1, so wouldn't the result be A=1, C=0?
I've run this through a few of the web based simulators and they all concur with A=0, C=0.
However, fake6502 (or at least the version I use) returns A=0, C=1.
I'm loathe to start fiddling with my simulator until I can understand what the behaviour should be - what am I missing?