A86: Re: Re: Division
[Prev][Next][Index][Thread]
A86: Re: Re: Division
I almost forgot, Joshua Grams posted this routine a while ago, and it's
really fast:
;=========================================
; Divide (d = d / c ... a = d % c)
; by Joshua Grams <j3grams@earthling.net>
; input: d = dividend, c = divisor
; output: d = quotient, a = remainder
; total: 15b/355t to 363t (exluding RET)
;=========================================
Divide:
push bc ; save bc
sub a ; clear a
ld b,8 ; 8 shifts
DivideL:
sla d ; shift left d
rla ; into a
cp c ; is a >= c
jr c,DivideS ; skip if not
sub c
inc d ; a = a-c, set bit in d
DivideS:
djnz DivideL ; loop
pop bc ; restore bc
ret ; done
>
> _divHLbyA equ 4048h ; hl = hl/a
>
>
>
> >
> > Does anyone know where in the rom the os calls to
> > perform a division operation, or how I could perform
> > simple division? I have a really cool basic program I
> > put together that will find the number of decimal
> > places in 1/N before it ends or starts repeating for
> > any whole number N, and I wanted to port it to assembly
> > (seeing as it is S-L-O-W for large numbers), but I
> > don't know how I would do the division. All I need is
> > the integer part of the quotient, so I don't need to
> > work with decimal places or anything. Thanks!
> > -David Thomas
>
>
>
>
References: