[Coco] Mod10 Suggestions
William Mikrut
wmikrut72 at gmail.com
Thu Feb 16 20:26:55 EST 2017
For years I have been an IBM programmer and have done well in that area --
for 30 years now.
I started with a CoCo2 back in 84/85 - and ML has always fascinated me --
yet eluded me to a degree.
With the advent of hardware (FPGAs) -- seems like we could do some pretty
coll stuff.
So, I try to enter into the 8 Bit world that is CoCo and get down to some
programming.
Following is a MOD10 program I have used for years in IBM programs.
I have translated it the best I can...I am sure it is not the most
efficient... and I have much to learn.
Attached is the MOD10 code.
I am hoping for constructive comments so I can learn, and move on to other
projects!
-------------- next part --------------
ORG $1200
CCD RMB 16 ;Credit Card Number
RESULT RMB 1 ;Result for caluclations
STATUS RMB 1 ;#$00=Bad CCD #, #$FF=Good CCD#
START LEAX CCD,pcr ;Load the location of the number
CLRB
STB #RESULT ;Clear the result field
LDA #16 ;16 Times through the loop
LOOP.00 DECA
LDB A,X ;Load a With X
BITA #1 ;Test for Even/Odd Numbers
BNE PROC.02
PROC.00 PSHS A ;We need to multiply the number by 2
LDA #2
MUL
PULS A
CMPB #10
BLO PROC.02
PROC.01 SUBB #10 ;If over 10, Add the 2 numbers together.
INCB ;Since the biggest# can be 18, Sub 10 and Increment B once
PROC.02 ADDB RESULT ;Accumulate the result
STB #RESULT
CMPA #0 ;Are we done with all 16 numbers?
BNE LOOP.00
CHK.00 CMPB #10 ;This is a division trick. If the result is divisible by 10
BLO CHK.01 ;it's a good card number. Keep sbtracting 10 until the result
SUBB #10 ;is under 10. If so and B is zero, we have a good number.
BRA CHK.00 ;Else it's a bad number
CHK.01 CMPB #0
BEQ GOOD.00
LDA #$00
BRA SHOW.00
GOOD.00 LDA #$FF
SHOW.00 STA #STATUS
ENDPGM RTS
END START
More information about the Coco
mailing list