Re: A86: ASM Programming Test - div 3


[Prev][Next][Index][Thread]

Re: A86: ASM Programming Test - div 3




>David Phillips wrote:
>>
>> I spent about a day trying to figure this out.  It's not possible.  To
>> divide by shifting requires at least a 16 or 32 bit fixed-point number, and
>> it still comes out a little too bit too small (reference: "More Tricks of
>> the Game Programming Gurus").

Shift routines work just fine. If I remember correctly, that's basically
the way hardware dividers (integer) work. This routine divides a by c,
returns quotient in d, remainder in a. Actually, it might not work, I just
kind of dashed it off, let me know if it doesn't. . .

; divisor in c
push bc
ld d,a	; put dividend in d
sub a	; clear a
ld b,8	; 8 shifts
l0: sla d	; shift left d
rla	; into a
cp c	;if a >= c, a = a-c, set bit in d
jr c,l1
inc d
l1: djnz l0	; loop
pop bc
ret

--Joshua



References: