[Coco] Mod10 Suggestions

Brett Gordon beretta42 at gmail.com
Fri Feb 17 23:15:05 EST 2017


Ok.. this actually works on a calculator on my bank card.  A zero is
prepended so it shifts the odd/even digits around, and we do need to add
digits of shifted bytes ;(

   Ldy #num     y points to beg of number
   Ldx #0           x is an 16 bit accumulator
loop:
   ldd ,y++      get next word
    abx             accum even digit
   lsla             shift odd digit
    cmpa #10 add digits if > 9
    blo skip
    suba #9
skip:
   tfr a,b            no aax ;(
  abx              accum odd byte
   cmpy #num+16
   bne loop
* find mod
   tfr x,d        full bit tests only in D :(
again
   subd #10   subtract 10 until we go neg
   bpl again
   addd #10  went too far! Add back last 10
* result in D (0= good cksum)
   beq beep   like at the supermarket
   bra boop   bad swipe

I get ~34 bytes of code + 16 data + 0 stack. Although the pcr addressing
would add a few bytes of code and data.

cheers


More information about the Coco mailing list