1*47837Sbostic/*- 2*47837Sbostic * Copyright (c) 1991 The Regents of the University of California. 3*47837Sbostic * All rights reserved. 413421Sroot * 5*47837Sbostic * %sccs.include.redist.c% 613421Sroot */ 7*47837Sbostic 8*47837Sbostic#if defined(LIBC_SCCS) && !defined(lint) 9*47837Sbostic .asciz "@(#)urem.s 5.3 (Berkeley) 04/08/91" 10*47837Sbostic#endif /* LIBC_SCCS and not lint */ 11*47837Sbostic 1213421Sroot#include "DEFS.h" 1313421Sroot 1417717Sralph/* 15*47837Sbostic * Unsigned modulus, PCC flavor. 16*47837Sbostic * urem() takes an ordinary dividend/divisor pair; 17*47837Sbostic * aurem() takes a pointer to a dividend and an ordinary divisor. 1817717Sralph */ 1917717Sralph 20*47837Sbostic#define DIVIDEND 4(ap) 21*47837Sbostic#define DIVISOR 8(ap) 22*47837Sbostic 23*47837SbosticASENTRY(urem,0) 24*47837Sbostic movl DIVISOR,r2 25*47837Sbostic jlss Leasy # big divisor: settle by comparison 26*47837Sbostic movl DIVIDEND,r0 27*47837Sbostic jlss Lhard # big dividend: need extended division 28*47837Sbostic divl3 r2,r0,r1 # small divisor and dividend: signed modulus 29*47837Sbostic mull2 r2,r1 30*47837Sbostic subl2 r1,r0 3117717Sralph ret 32*47837SbosticLhard: 33*47837Sbostic clrl r1 34*47837Sbostic ediv r2,r0,r1,r0 3517717Sralph ret 36*47837SbosticLeasy: 37*47837Sbostic subl3 r2,DIVIDEND,r0 38*47837Sbostic jcc Ldifference # if divisor goes in once, return difference 39*47837Sbostic movl DIVIDEND,r0 # if divisor is bigger, return dividend 40*47837SbosticLdifference: 41*47837Sbostic ret 42*47837Sbostic 43*47837SbosticASENTRY(aurem,0) 44*47837Sbostic movl DIVISOR,r2 45*47837Sbostic jlss Laeasy # big divisor: settle by comparison 46*47837Sbostic movl DIVIDEND,r3 47*47837Sbostic movl (r3),r0 48*47837Sbostic jlss Lahard # big dividend: need extended division 49*47837Sbostic divl3 r2,r0,r1 # small divisor and dividend: signed modulus 50*47837Sbostic mull2 r2,r1 51*47837Sbostic subl3 r1,r0,(r3) 52*47837Sbostic ret 53*47837SbosticLahard: 54*47837Sbostic clrl r1 55*47837Sbostic ediv r2,r0,r1,(r3) 56*47837Sbostic ret 57*47837SbosticLaeasy: 58*47837Sbostic subl3 r2,(r3),r0 59*47837Sbostic jcs Ldividend # if divisor is bigger, leave dividend alone 60*47837Sbostic movl r0,(r3) # if divisor goes in once, store difference 61*47837SbosticLdividend: 62*47837Sbostic ret 63