Re: A86: long division
[Prev][Next][Index][Thread]
Re: A86: long division
This won't work if hl is less than 7. Once the loop is executed 256 times, the
carry flag sets and sends the subtraction amiss.
David Phillips wrote:
> You could run a loop, subtracting hl from your number once each time, and
> keep track of how many times you subtracted it, until the remaining number
> is smaller than hl. That number would be the remainder, and the number of
> times you subtracted would be the quotient.
>
>
> ; NOT tested!
> ; in: de = dividend, hl = divisor
> ; out: a = quotient, hl = remainder - dividend (add dividend to get remainder)
> de_div_hl:
> ex de,hl
> xor a
> loop:
> sbc hl,de
> ret c
> inc a
> jr loop ; or use jp, to add 1 byte/save 2 t-states
>
>
> At 02:03 AM 8/3/98 EDT, you wrote:
> >
> >Lets say that I only need to save the integer part of the quotient...would
> >that change anything?
> >
>
> --
> David Phillips
> mailto:electrum@tfs.net
> ICQ: 13811951
> AOL/AIM: electrum32
References: