Annotation of 43BSD/lib/libc/vax/gen/urem.s, revision 1.1

1.1     ! root        1: #ifdef LIBC_SCCS
        !             2:        .asciz  "@(#)urem.s     5.2 (Berkeley) 3/9/86"
        !             3: #endif LIBC_SCCS
        !             4: 
        !             5: /*
        !             6:  * urem - unsigned remainder for vax-11
        !             7:  *
        !             8:  * arguments: dividend, divisor
        !             9:  * result: remainder
        !            10:  * uses r0-r2
        !            11:  *
        !            12:  * if 1 < divisor <= 2147483647, zero-extend the dividend
        !            13:  * to 64 bits and let ediv do the work.  If the divisor is 1,
        !            14:  * ediv will overflow if bit 31 of the dividend is on, so
        !            15:  * just return 0.  If the divisor is 0, do the ediv also,
        !            16:  * so it will generate the proper exception.  All other values
        !            17:  * of the divisor have bit 31 on: in this case the remainder
        !            18:  * must be the dividend if divisor > dividend, and the dividend
        !            19:  * minus the divisor otherwise.  The comparison must be unsigned.
        !            20:  */
        !            21: #include "DEFS.h"
        !            22: 
        !            23: ASENTRY(urem, 0)
        !            24:        movl    4(ap),r0        /* dividend */
        !            25:        movl    8(ap),r2        /* divisor */
        !            26:        jeql    1f              /* if divisor=0, force exception */
        !            27:        cmpl    r2,$1           /* if divisor <= 1 (signed), */
        !            28:        jleq    2f              /*  no division is necessary */
        !            29: 1:
        !            30:        clrl    r1              /* zero-extend the dividend */
        !            31:        ediv    r2,r0,r2,r0     /* divide.  q->r2 (discarded), r->r0 */
        !            32:        ret
        !            33: 2:
        !            34:        jneq    1f              /* if divisor=1, return 0 */
        !            35:        clrl    r0              /*  (because doing the divide will overflow */
        !            36:        ret                     /*  if the dividend has its high bit on) */
        !            37: 1:
        !            38:        cmpl    r0,r2           /* if dividend < divisor (unsigned) */
        !            39:        jlssu   1f              /*  remainder is dividend */
        !            40:        subl2   r2,r0           /*  else remainder is dividend - divisor */
        !            41: 1:
        !            42:        ret
        !            43: 
        !            44: /*
        !            45:  * aurem - unsigned remainder for vax-11
        !            46:  *
        !            47:  * arguments: *dividend, divisor
        !            48:  * result: remainder in r0 and *dividend
        !            49:  * uses r0-r2
        !            50:  */
        !            51: #include "DEFS.h"
        !            52: 
        !            53: ASENTRY(aurem, 0)
        !            54:        movl    *4(ap),r0       /* dividend */
        !            55:        movl    8(ap),r2        /* divisor */
        !            56:        jeql    1f              /* if divisor=0, force exception */
        !            57:        cmpl    r2,$1           /* if divisor <= 1 (signed), */
        !            58:        jleq    2f              /*  no division is necessary */
        !            59: 1:
        !            60:        clrl    r1              /* zero-extend the dividend */
        !            61:        ediv    r2,r0,r2,r0     /* divide.  q->r2 (discarded), r->r0 */
        !            62:        movl    r0,*4(ap)       /* save result */
        !            63:        ret
        !            64: 2:
        !            65:        jneq    1f              /* if divisor=1, return 0 */
        !            66:        clrl    r0              /*  (because doing the divide will overflow */
        !            67:        clrl    *4(ap)          /*  if the dividend has its high bit on) */
        !            68:        ret     
        !            69: 1:
        !            70:        cmpl    r0,r2           /* if dividend < divisor (unsigned) */
        !            71:        jlssu   1f              /*  remainder is dividend */
        !            72:        subl2   r2,r0           /*  else remainder is dividend - divisor */
        !            73: 1:
        !            74:        movl    r0,*4(ap)       /* save result */
        !            75:        ret

unix.superglobalmegacorp.com

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