>> Ok.
>> Here are some routines I wrote a few years ago. I never
measured/calculated their
Now that I'm busy spreading my sources anyway, I will also please
you with some integer division routines. One routine was written by
me. It is a 32-bit division routine. The other routine is ripped from
the driver rom. It is a 16-bit division routine. The drive-rom uses it
to translate the (logical) sector number into a track/side/physical
sector number.

The first routine calculates : HL:DE = HL:AC div DE
                                 HL' = HL:AC mod DE

The second routine calculates: BC = BC div DE
                               HL = BC mod DE

I will put these routines also on my homepage and/or on
ftp.funet.fi/pub/msx/something

Best regards,
Alex Wulms

 
--START OF FILE1: DIV32B.GEN
; **************************************
; * calculate 32 bit division
; * Written by XelaSoft. May be used by anyone
; * out:       HL:DE = HL:AC div DE
; *              HL' = HL:AC mod DE
; * changes: DE', AF, B
div32b:         push    de
                exx
                pop     de      ; divider = DE'
                ld      hl,0    ; x15..x0 = HL'
                exx
                ld      d,a     ; teller  = HL:DA
                ld      a,c
                ld      b,32
                or      a
div32b2:        rla             ; shift result in and counter to left
                rl      d
                rl      l
                rl      h
                exx
                rl      l
                rl      h       ; x15..x0 must be shifted too
                or      a
                sbc     hl,de   ; try to subtract DE
                jr      nc,div32b3 ; success => 1-bit in result 
                add     hl,de   ; failure => restore HL' (and SCF)
div32b3:        exx             ; switch back to normal set
                ccf             ; substraction failed => 0, success => 1
                djnz    div32b2
                rla             ; shift result in
                rl      d
                rl      l
                rl      h
                ld      e,a
                ret
--END OF FILE1: DIV32B.GEN

--START OF FILE2: DIVIDE.GEN
 ; word-divide routine ripped from drive rom
 ; bc=bc\de
 ; hl=bc mod de
 
 ld hl,0
 ld a,b
 ld b,16
 rl c
 rla
div1: rl l
 rl h
 jr c,div2
 sbc hl,de
 jr nc,div3
 add hl,de
div3: ccf
div4: rl c
 rla
 djnz div1
 ld b,a
 ret
div2: or a
 sbc hl,de
 jr div4
--END OF FILE2: DIVIDE.GEN




Reply via email to