1*17717Sralph/* urem.s 4.4 85/01/16 */ 213421Sroot 313421Sroot/* 413421Sroot * urem - unsigned remainder for vax-11 513421Sroot * 613421Sroot * arguments: dividend, divisor 713421Sroot * result: remainder 813421Sroot * uses r0-r2 913421Sroot * 1013421Sroot * if 1 < divisor <= 2147483647, zero-extend the dividend 1113421Sroot * to 64 bits and let ediv do the work. If the divisor is 1, 1213421Sroot * ediv will overflow if bit 31 of the dividend is on, so 1313421Sroot * just return 0. If the divisor is 0, do the ediv also, 1413421Sroot * so it will generate the proper exception. All other values 1513421Sroot * of the divisor have bit 31 on: in this case the remainder 1613421Sroot * must be the dividend if divisor > dividend, and the dividend 1713421Sroot * minus the divisor otherwise. The comparison must be unsigned. 1813421Sroot */ 1913421Sroot#include "DEFS.h" 2013421Sroot 2117329SsamASENTRY(urem, 0) 2213421Sroot movl 4(ap),r0 /* dividend */ 2313421Sroot movl 8(ap),r2 /* divisor */ 2413421Sroot jeql 1f /* if divisor=0, force exception */ 2513421Sroot cmpl r2,$1 /* if divisor <= 1 (signed), */ 2613421Sroot jleq 2f /* no division is necessary */ 2713421Sroot1: 2813421Sroot clrl r1 /* zero-extend the dividend */ 2913421Sroot ediv r2,r0,r2,r0 /* divide. q->r2 (discarded), r->r0 */ 3013421Sroot ret 3113421Sroot2: 3213421Sroot jneq 1f /* if divisor=1, return 0 */ 3313421Sroot clrl r0 /* (because doing the divide will overflow */ 3413421Sroot ret /* if the dividend has its high bit on) */ 3513421Sroot1: 3613421Sroot cmpl r0,r2 /* if dividend < divisor (unsigned) */ 3713421Sroot jlssu 1f /* remainder is dividend */ 3813421Sroot subl2 r2,r0 /* else remainder is dividend - divisor */ 3913421Sroot1: 4013421Sroot ret 41*17717Sralph 42*17717Sralph/* 43*17717Sralph * aurem - unsigned remainder for vax-11 44*17717Sralph * 45*17717Sralph * arguments: *dividend, divisor 46*17717Sralph * result: remainder in r0 and *dividend 47*17717Sralph * uses r0-r2 48*17717Sralph */ 49*17717Sralph#include "DEFS.h" 50*17717Sralph 51*17717SralphASENTRY(aurem, 0) 52*17717Sralph movl *4(ap),r0 /* dividend */ 53*17717Sralph movl 8(ap),r2 /* divisor */ 54*17717Sralph jeql 1f /* if divisor=0, force exception */ 55*17717Sralph cmpl r2,$1 /* if divisor <= 1 (signed), */ 56*17717Sralph jleq 2f /* no division is necessary */ 57*17717Sralph1: 58*17717Sralph clrl r1 /* zero-extend the dividend */ 59*17717Sralph ediv r2,r0,r2,r0 /* divide. q->r2 (discarded), r->r0 */ 60*17717Sralph movl r0,*4(ap) /* save result */ 61*17717Sralph ret 62*17717Sralph2: 63*17717Sralph jneq 1f /* if divisor=1, return 0 */ 64*17717Sralph clrl r0 /* (because doing the divide will overflow */ 65*17717Sralph clrl *4(ap) /* if the dividend has its high bit on) */ 66*17717Sralph ret 67*17717Sralph1: 68*17717Sralph cmpl r0,r2 /* if dividend < divisor (unsigned) */ 69*17717Sralph jlssu 1f /* remainder is dividend */ 70*17717Sralph subl2 r2,r0 /* else remainder is dividend - divisor */ 71*17717Sralph1: 72*17717Sralph movl r0,*4(ap) /* save result */ 73*17717Sralph ret 74