[Coco] Mod10 Suggestions
Dave Philipsen
dave at davebiz.com
Fri Feb 17 01:57:42 EST 2017
On 2/16/2017 10:05 PM, Mark McDougall wrote:
>
> Can't help myself! :(
> Here's my take on it.
> Assembles but ***NOT TESTED***!
>
> On optimisation to the algorithm; check the result for >10 on each
> loop iteration - means you don't have to do an extra loop at then end!
>
>
> .list (meb) ; macro expansion binary
> .area idaseg (ABS)
>
> .org 0x1200
>
> ccd: .ds 16 ; credit card number
> result: .ds 1
> status: .ds 1
>
> start: clrb
> stb result ; zero sum
> stb status ; flag=bad
> ldx #result ; ptr CCN
> ldb #16 ; 16 digits
>
> loop: lda ,x+ ; get digit (0-9)
Here's a problem. It's not the credit card digit itself that is being
tested for odd/even. It's the position of the digit. So you need to do
a 'bitb #1' instead of a 'bita #1'.
> bita #1 ; odd/even?
> bne accum ; odd, skip
> lsla ; x2
> cmpa #10 ; 2 digits?
> blo accum ; no, skip
> suba #9 ; add digits
> accum: adda result ; add to result
> cmpa #10 ; less than 10?
> blo store ; yes, skip
> suba #10 ; discard tens
> store: sta result ; store result
>
> decb ; done all digits?
> bne loop ; no, loop
>
> tsta ; result=zero?
> bne done ; no, flagged bad already
> deca ; $FF
> sta status ; update status
>
> done: rts
>
> .end start
>
> Regards,
>
More information about the Coco
mailing list