Commit | Line | Data |
---|---|---|
c75d7778 | 1 | /*- |
7217fa4b KB |
2 | * Copyright (c) 1991, 1993 |
3 | * The Regents of the University of California. All rights reserved. | |
43e1c702 | 4 | * |
a3714316 DS |
5 | * This code is derived from software contributed to Berkeley by |
6 | * Donn Seeley at UUNET Technologies, Inc. | |
43e1c702 | 7 | * |
c0567266 KB |
8 | * Redistribution and use in source and binary forms, with or without |
9 | * modification, are permitted provided that the following conditions | |
10 | * are met: | |
11 | * 1. Redistributions of source code must retain the above copyright | |
12 | * notice, this list of conditions and the following disclaimer. | |
13 | * 2. Redistributions in binary form must reproduce the above copyright | |
14 | * notice, this list of conditions and the following disclaimer in the | |
15 | * documentation and/or other materials provided with the distribution. | |
16 | * 3. All advertising materials mentioning features or use of this software | |
17 | * must display the following acknowledgement: | |
18 | * This product includes software developed by the University of | |
19 | * California, Berkeley and its contributors. | |
20 | * 4. Neither the name of the University nor the names of its contributors | |
21 | * may be used to endorse or promote products derived from this software | |
22 | * without specific prior written permission. | |
23 | * | |
24 | * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND | |
25 | * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE | |
26 | * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE | |
27 | * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE | |
28 | * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL | |
29 | * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS | |
30 | * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) | |
31 | * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT | |
32 | * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY | |
33 | * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF | |
34 | * SUCH DAMAGE. | |
43e1c702 BJ |
35 | */ |
36 | ||
c75d7778 | 37 | #if defined(LIBC_SCCS) && !defined(lint) |
ad787160 | 38 | .asciz "@(#)udiv.s 8.1 (Berkeley) 6/4/93" |
c75d7778 | 39 | #endif /* LIBC_SCCS and not lint */ |
294ae850 RC |
40 | |
41 | /* | |
c75d7778 KB |
42 | * Unsigned division, PCC flavor. |
43 | * udiv() takes an ordinary dividend/divisor pair; | |
44 | * audiv() takes a pointer to a dividend and an ordinary divisor. | |
294ae850 RC |
45 | */ |
46 | ||
47 | #include "DEFS.h" | |
48 | ||
c75d7778 KB |
49 | #define DIVIDEND 4(ap) |
50 | #define DIVISOR 8(ap) | |
51 | ||
52 | ASENTRY(udiv,0) | |
53 | movl DIVISOR,r2 | |
54 | jlss Leasy # big divisor: settle by comparison | |
55 | movl DIVIDEND,r0 | |
56 | jlss Lhard # big dividend: extended division | |
57 | divl2 r2,r0 # small divisor and dividend: signed division | |
43e1c702 | 58 | ret |
c75d7778 KB |
59 | Lhard: |
60 | clrl r1 | |
61 | ediv r2,r0,r0,r1 | |
43e1c702 | 62 | ret |
c75d7778 KB |
63 | Leasy: |
64 | cmpl DIVIDEND,r2 | |
65 | jgequ Lone # if dividend is as big or bigger, return 1 | |
66 | clrl r0 # else return 0 | |
67 | ret | |
68 | Lone: | |
69 | movl $1,r0 | |
43e1c702 | 70 | ret |
294ae850 | 71 | |
c75d7778 | 72 | ASENTRY(audiv,0) |
2242a324 | 73 | movl DIVIDEND,r3 |
c75d7778 | 74 | movl DIVISOR,r2 |
cb962cfd | 75 | jlss La_easy # big divisor: settle by comparison |
c75d7778 | 76 | movl (r3),r0 |
cb962cfd KB |
77 | jlss La_hard # big dividend: extended division |
78 | divl2 r2,r0 # small divisor and dividend: signed division | |
79 | movl r0,(r3) # leave the value of the assignment in r0 | |
c75d7778 | 80 | ret |
cb962cfd | 81 | La_hard: |
c75d7778 | 82 | clrl r1 |
cb962cfd KB |
83 | ediv r2,r0,r0,r1 |
84 | movl r0,(r3) | |
294ae850 | 85 | ret |
cb962cfd | 86 | La_easy: |
c75d7778 | 87 | cmpl (r3),r2 |
cb962cfd KB |
88 | jgequ La_one # if dividend is as big or bigger, return 1 |
89 | clrl r0 # else return 0 | |
90 | clrl (r3) | |
294ae850 | 91 | ret |
cb962cfd KB |
92 | La_one: |
93 | movl $1,r0 | |
94 | movl r0,(r3) | |
294ae850 | 95 | ret |