1/*- 2 * Copyright (c) 1991, 1993 3 * The Regents of the University of California. All rights reserved. 4 * 5 * This code is derived from software contributed to Berkeley by 6 * Donn Seeley at UUNET Technologies, Inc. 7 * 8 * %sccs.include.redist.c% 9 */ 10 11#if defined(LIBC_SCCS) && !defined(lint) 12 .asciz "@(#)urem.s 8.1 (Berkeley) 06/04/93" 13#endif /* LIBC_SCCS and not lint */ 14 15#include "DEFS.h" 16 17/* 18 * Unsigned modulus, PCC flavor. 19 * urem() takes an ordinary dividend/divisor pair; 20 * aurem() takes a pointer to a dividend and an ordinary divisor. 21 */ 22 23#define DIVIDEND 4(ap) 24#define DIVISOR 8(ap) 25 26ASENTRY(urem,0) 27 movl DIVISOR,r2 28 jlss Leasy # big divisor: settle by comparison 29 movl DIVIDEND,r0 30 jlss Lhard # big dividend: need extended division 31 divl3 r2,r0,r1 # small divisor and dividend: signed modulus 32 mull2 r2,r1 33 subl2 r1,r0 34 ret 35Lhard: 36 clrl r1 37 ediv r2,r0,r1,r0 38 ret 39Leasy: 40 subl3 r2,DIVIDEND,r0 41 jcc Ldifference # if divisor goes in once, return difference 42 movl DIVIDEND,r0 # if divisor is bigger, return dividend 43Ldifference: 44 ret 45 46ASENTRY(aurem,0) 47 movl DIVIDEND,r3 48 movl DIVISOR,r2 49 jlss La_easy # big divisor: settle by comparison 50 movl (r3),r0 51 jlss La_hard # big dividend: need extended division 52 divl3 r2,r0,r1 # small divisor and dividend: signed modulus 53 mull2 r2,r1 54 subl2 r1,r0 55 movl r0,(r3) # leave the value of the assignment in r0 56 ret 57La_hard: 58 clrl r1 59 ediv r2,r0,r1,r0 60 movl r0,(r3) 61 ret 62La_easy: 63 subl3 r2,(r3),r0 64 jcs La_dividend # if divisor is bigger, leave dividend alone 65 movl r0,(r3) # if divisor goes in once, store difference 66 ret 67La_dividend: 68 movl (r3),r0 69 ret 70