147836Sbostic/*- 247836Sbostic * Copyright (c) 1991 The Regents of the University of California. 347836Sbostic * All rights reserved. 447836Sbostic * 547836Sbostic * %sccs.include.redist.c% 647836Sbostic */ 713420Sroot 847836Sbostic#if defined(LIBC_SCCS) && !defined(lint) 9*47838Sbostic .asciz "@(#)udiv.s 5.4 (Berkeley) 04/08/91" 1047836Sbostic#endif /* LIBC_SCCS and not lint */ 1147836Sbostic 1213420Sroot/* 1347836Sbostic * Unsigned division, PCC flavor. 1447836Sbostic * udiv() takes an ordinary dividend/divisor pair; 1547836Sbostic * audiv() takes a pointer to a dividend and an ordinary divisor. 1613420Sroot */ 1713420Sroot 1813420Sroot#include "DEFS.h" 1913420Sroot 2047836Sbostic#define DIVIDEND 4(ap) 2147836Sbostic#define DIVISOR 8(ap) 2247836Sbostic 2347836SbosticASENTRY(udiv,0) 2447836Sbostic movl DIVISOR,r2 2547836Sbostic jlss Leasy # big divisor: settle by comparison 2647836Sbostic movl DIVIDEND,r0 2747836Sbostic jlss Lhard # big dividend: extended division 2847836Sbostic divl2 r2,r0 # small divisor and dividend: signed division 2913420Sroot ret 3047836SbosticLhard: 3147836Sbostic clrl r1 3247836Sbostic ediv r2,r0,r0,r1 3313420Sroot ret 3447836SbosticLeasy: 3547836Sbostic cmpl DIVIDEND,r2 3647836Sbostic jgequ Lone # if dividend is as big or bigger, return 1 3747836Sbostic clrl r0 # else return 0 3813420Sroot ret 3947836SbosticLone: 4047836Sbostic movl $1,r0 4147836Sbostic ret 4217718Sralph 4347836SbosticASENTRY(audiv,0) 4447836Sbostic movl DIVISOR,r2 45*47838Sbostic jlss La_easy # big divisor: settle by comparison 4647836Sbostic movl DIVIDEND,r3 4747836Sbostic movl (r3),r0 48*47838Sbostic jlss La_hard # big dividend: extended division 49*47838Sbostic divl2 r2,r0 # small divisor and dividend: signed division 50*47838Sbostic movl r0,(r3) # leave the value of the assignment in r0 5117718Sralph ret 52*47838SbosticLa_hard: 5347836Sbostic clrl r1 54*47838Sbostic ediv r2,r0,r0,r1 55*47838Sbostic movl r0,(r3) 5617718Sralph ret 57*47838SbosticLa_easy: 5847836Sbostic cmpl (r3),r2 59*47838Sbostic jgequ La_one # if dividend is as big or bigger, return 1 60*47838Sbostic clrl r0 # else return 0 61*47838Sbostic clrl (r3) 6217718Sralph ret 63*47838SbosticLa_one: 64*47838Sbostic movl $1,r0 65*47838Sbostic movl r0,(r3) 6647836Sbostic ret 67