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...
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.