skilldrick / easy6502

http://skilldrick.github.com/easy6502/
1.23k stars 251 forks source link

SBC (subtract with carry) #51

Open meCodeUp opened 2 years ago

meCodeUp commented 2 years ago

It seems that SBC is not calculating correctly

Address  Hexdump   Dissassembly
-------------------------------
$0600    a9 09     LDA #$09
$0602    e9 01     SBC #$01

0600: a9 09 e9 01

A=$07 X=$00 Y=$00
SP=$ff PC=$0605
NV-BDIZC
00110001
chipster6502 commented 2 years ago

The calculation is correct.

SBC is subtract with carry. If C is 0 prior to the SBC instruction, it subtracts one more than you expect.

To avoid the problem, always use SEC instruction before SBC