I've just started to learn 6502 because I want to create an Atari 2600 game.
I have tried this code:
LDA #$01
STA $01
LDX #$02
TXA
SBC $01
BRK
And I get the value A=$00, and flags Z and C set to 1. But I think the value in A must be $01.
If I change the values because I probably doing wrong the subtract:
LDA #$02
STA $01
LDX #$01
TXA
SBC $01
BRK
I get the value A=$fe, and flag N set to 1.
What's happening?
SBC is subtract with carry. If C is 0 prior to the SBC instruction, it subtracts one more than you expect.
Put SEC before the SBC.