; dividend is in BIGNUM, little-endian ; divisor is in accu sta DIVISOR lda #0 ldx #BIGNUMBYTES longdivmod ldy #8 asl BIGNUM - 1,x - rol cmp DIVISOR bcc + sbc DIVISOR + rol BIGNUM - 1,x dey bne - dex bne longdivmod ; quotient is in BIGNUM, little-endian ; remainder is in accu
ldx #BIGNUMBYTES
ldx #BIGNUMBYTES + 1 - ldy BIGNUM - 1,x bne longdivmod dex bne -
Some correction on your routine
ldx #2; BIGNUMBYTES + 1 - ldy BIGNUM - 1,x; BIGNUM + 1, BIGNUM + 0 bne longdivmod dex bne -
To speed up the algorithm, I think it is best to skip zeros before going into the loop in case the number of bytes is always fixed and the value is low.
As i'm continuously extracting values, dividend and quotient are getting smaller and smaller. So the size of the byte array can be decreased whenever a most significant byte becomes zero. This should neatly halve overall execution time.