vdub_bobby Posted February 23, 2022 Share Posted February 23, 2022 So normal 16-bit subtraction with carry: sec lda NumberOne sbc #CONSTANT sta NumberOne lda NumberTwo sbc #0 sta NumberTwo But I have a situation where I am adding to NumberOne but I still want to decrement NumberTwo when NumberOne overflows clc lda NumberOne adc #CONSTANT sta NumberOne lda NumberThree sbc #0 ;--won't work !! sta NumberThree So I've come up with these two ways: ;Method #1 clc lda NumberOne adc #CONSTANT sta NumberOne lda NumberTwo bcs ClearCarry clc .byte $24 ;--skip (via BIT ZP) over next byte ClearCarry sec sbc #0 sta NumberTwo ;Method #2 clc lda NumberOne adc #CONSTANT sta NumberOne php ;push processor flags onto stack (carry in lowest bit) pla eor #1 ;flip it lsr ;and shove it back into the carry flag lda NumberTwo sbc #0 sta NumberTwo Seems like there must be a better way? Anyone have some sneaky trick to share? Quote Link to comment Share on other sites More sharing options...
+splendidnut Posted February 23, 2022 Share Posted February 23, 2022 If you only need to change decrement NumberTwo by 1, just use DEC. clc lda NumberOne adc #CONSTANT sta NumberOne bcc .skip dec NumberTwo .skip: 2 Quote Link to comment Share on other sites More sharing options...
+Bruce-Robert Pocock Posted February 23, 2022 Share Posted February 23, 2022 For the record, though, if you really did want to invert the carry flag, this gem is from one Lee Davison: http://web.archive.org/web/20130212081017/http://mycorner.no-ip.org/6502/shorts/togglecarry.html ROL A ; Cb into b0 EOR #$01 ; toggle bit ROR A ; b0 into Cb 3 Quote Link to comment Share on other sites More sharing options...
vdub_bobby Posted February 24, 2022 Author Share Posted February 24, 2022 Thanks to you both, I knew I was overthinking this LOL. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.