easmith Posted July 14, 2019 Share Posted July 14, 2019 This is a dumb question I'm sure , but I am having trouble with a BCD calculation. I am using the Collect Tutorial 2 digit score display , which uses BCD encoded values. In the past , all of the numbers I have used have been obtainable by sed clc lda numberbcd adc #10 ( some fixed value) sta numberbcd But now I am trying to subtract two variables and store as BCD. No combination I have tried works. ( having both BCD before arithmetic or converting after ) Any help would be appreciated ! ES Quote Link to comment https://forums.atariage.com/topic/293300-bcd-issue/ Share on other sites More sharing options...
RevEng Posted July 14, 2019 Share Posted July 14, 2019 44 minutes ago, easmith said: sed clc lda numberbcd adc #10 ( some fixed value) sta numberbcd Not exactly your question, but I figured I'd point out that for BCD operations you use the hex representations of the decimal numbers. So "ADC #$10" instead of "ADC 10". The latter will mess up your BCD math for any operand greater than 9. (since $0=0, $1=1, ..., $9=9) Subtraction with BCD math isn't any more complicated than addition (use SEC instead of CLC), so I'm wondering if your problem isn't with the issue I've mentioned above. Quote Link to comment https://forums.atariage.com/topic/293300-bcd-issue/#findComment-4309521 Share on other sites More sharing options...
Nukey Shay Posted July 14, 2019 Share Posted July 14, 2019 Yup...gotta be $hex values only. Decimal mode then treats $00 - $99 as base 10 values 0 - 99. You also cannot use any other method other than ADC and SBC when doing your math (unless you know for a fact that it won't result in a carry or borrow from either column). Quote Link to comment https://forums.atariage.com/topic/293300-bcd-issue/#findComment-4309528 Share on other sites More sharing options...
easmith Posted July 14, 2019 Author Share Posted July 14, 2019 What about subtracting RAM variables x and y ? Quote Link to comment https://forums.atariage.com/topic/293300-bcd-issue/#findComment-4309530 Share on other sites More sharing options...
Nukey Shay Posted July 14, 2019 Share Posted July 14, 2019 Variables, Rom data, registers, doesn't matter. They need to contain numeric digits only when being used for BCD. Those that hold values only up to 9 could be safe in certain cases when BCD is not invoked (when it's guaranteed that a carry or borrow isn't going to happen to/from the 1's column in the result). Quote Link to comment https://forums.atariage.com/topic/293300-bcd-issue/#findComment-4309550 Share on other sites More sharing options...
Nukey Shay Posted July 14, 2019 Share Posted July 14, 2019 If X or Y do contain $hex values, you'd need to convert them to decimal before BCD arithmetic. It might be easier to use a conversion table in Rom for such a case. It's wiser just not to use those specific variables for anything BUT decimal mode, so no conversion is necessary. Quote Link to comment https://forums.atariage.com/topic/293300-bcd-issue/#findComment-4309553 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.