147837Sbostic/*- 247837Sbostic * Copyright (c) 1991 The Regents of the University of California. 347837Sbostic * All rights reserved. 413421Sroot * 547837Sbostic * %sccs.include.redist.c% 613421Sroot */ 747837Sbostic 847837Sbostic#if defined(LIBC_SCCS) && !defined(lint) 9*47866Sdonn .asciz "@(#)urem.s 5.5 (Berkeley) 04/08/91" 1047837Sbostic#endif /* LIBC_SCCS and not lint */ 1147837Sbostic 1213421Sroot#include "DEFS.h" 1313421Sroot 1417717Sralph/* 1547837Sbostic * Unsigned modulus, PCC flavor. 1647837Sbostic * urem() takes an ordinary dividend/divisor pair; 1747837Sbostic * aurem() takes a pointer to a dividend and an ordinary divisor. 1817717Sralph */ 1917717Sralph 2047837Sbostic#define DIVIDEND 4(ap) 2147837Sbostic#define DIVISOR 8(ap) 2247837Sbostic 2347837SbosticASENTRY(urem,0) 2447837Sbostic movl DIVISOR,r2 2547837Sbostic jlss Leasy # big divisor: settle by comparison 2647837Sbostic movl DIVIDEND,r0 2747837Sbostic jlss Lhard # big dividend: need extended division 2847837Sbostic divl3 r2,r0,r1 # small divisor and dividend: signed modulus 2947837Sbostic mull2 r2,r1 3047837Sbostic subl2 r1,r0 3117717Sralph ret 3247837SbosticLhard: 3347837Sbostic clrl r1 3447837Sbostic ediv r2,r0,r1,r0 3517717Sralph ret 3647837SbosticLeasy: 3747837Sbostic subl3 r2,DIVIDEND,r0 3847837Sbostic jcc Ldifference # if divisor goes in once, return difference 3947837Sbostic movl DIVIDEND,r0 # if divisor is bigger, return dividend 4047837SbosticLdifference: 4147837Sbostic ret 4247837Sbostic 4347837SbosticASENTRY(aurem,0) 44*47866Sdonn movl DIVIDEND,r3 4547837Sbostic movl DIVISOR,r2 4647838Sbostic jlss La_easy # big divisor: settle by comparison 4747837Sbostic movl (r3),r0 4847838Sbostic jlss La_hard # big dividend: need extended division 4947837Sbostic divl3 r2,r0,r1 # small divisor and dividend: signed modulus 5047837Sbostic mull2 r2,r1 5147838Sbostic subl2 r1,r0 5247838Sbostic movl r0,(r3) # leave the value of the assignment in r0 5347837Sbostic ret 5447838SbosticLa_hard: 5547837Sbostic clrl r1 5647838Sbostic ediv r2,r0,r1,r0 5747838Sbostic movl r0,(r3) 5847837Sbostic ret 5947838SbosticLa_easy: 6047837Sbostic subl3 r2,(r3),r0 6147838Sbostic jcs La_dividend # if divisor is bigger, leave dividend alone 6247837Sbostic movl r0,(r3) # if divisor goes in once, store difference 6347837Sbostic ret 6447838SbosticLa_dividend: 6547838Sbostic movl (r3),r0 6647838Sbostic ret 67