Annotation of coherent/b/lib/libc/crt/i8086/vdiv.m, revision 1.1

1.1     ! root        1: //////////
        !             2: / i8086 C library runtime support.
        !             3: / vdiv()
        !             4: / Unsigned long division and remainder support.
        !             5: //////////
        !             6: 
        !             7: #include "larges.h"
        !             8: 
        !             9: //////////
        !            10: / Returns  (dx ax) / (bx cx) in (si di)
        !            11: /     and  (dx ax) % (bx cx) in (dx ax).
        !            12: / All are unsigned longs.
        !            13: //////////
        !            14: 
        !            15:        .globl  vdiv
        !            16: 
        !            17: vdiv:  mov     si, bx
        !            18:        or      si, cx
        !            19:        mov     si, $-1         / does not affect flags
        !            20:        mov     di, si
        !            21:        jne     0f
        !            22:        sub     si, si
        !            23:        mov     di, si          / divisor = 0
        !            24:        Gret
        !            25: 
        !            26: 1:     shr     si, $1          / "count" quotient bits
        !            27:        rcr     di, $1
        !            28: 0:     cmp     dx, bx
        !            29:        jb      1f
        !            30:        shl     cx, $1          / shift until big enough
        !            31:        rcl     bx, $1
        !            32:        jnc     1b
        !            33:                                / oops!
        !            34: 3:     rcr     bx, $1          / carry!=0  only if drop from above
        !            35:        rcr     cx, $1
        !            36: 1:     sub     ax, cx
        !            37:        sbb     dx, bx
        !            38:        jnc     2f
        !            39:        add     ax, cx
        !            40:        adc     dx, bx          / produces another carry
        !            41: 2:     rcl     di, $1          / collect inverted quotient
        !            42:        rcl     si, $1
        !            43:        jnc     3b              / use above "count"
        !            44: 
        !            45:        not     si
        !            46:        not     di
        !            47:        Gret
        !            48: 
        !            49: / end of vdiv.m

unix.superglobalmegacorp.com

This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.