Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

I don't understand what's going on with SBC

Tags:

assembly

6502

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?

like image 857
VansFannel Avatar asked Dec 05 '25 04:12

VansFannel


1 Answers

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.

like image 80
prl Avatar answered Dec 08 '25 21:12

prl



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!