[A83] Re: Division


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

[A83] Re: Division




This is a good one:

;=========================================
; 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


> Does anybody have a fast division routine, or know how to make one?
> I need it for my triangle routine...






Follow-Ups: References: