Re: A86: ASM Programming Test - div 3


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

Re: A86: ASM Programming Test - div 3




This is SO freaking nifty! Thank you to Josh and everyone who helped make this
possible! Now anyone want to tackle double-register division? :)


In a message dated 12/10/98 5:51:16 PM Pacific Standard Time, electrum@tfs.net
writes:

> Awsome!  That routine is definitely going in my toolbox of useful routines.
>  You forgot the  with the <inc d>, but I figured that out from the
>  comments.  Do you think you could explain how it works?
>  
>  ;=========================================
>  ; Divide
>  ;  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            ; a = a - c
>   inc d            ; set bit in d
>  DivideS:
>   djnz DivideL     ; loop
>   pop bc           ; restore bc
>   ret              ; done