easy6502 icon indicating copy to clipboard operation
easy6502 copied to clipboard

SBC (subtract with carry)

Open meCodeUp opened this issue 2 years ago • 1 comments

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

meCodeUp avatar May 06 '22 17:05 meCodeUp

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

chipster6502 avatar Jun 30 '22 19:06 chipster6502