Commit | Line | Data |
---|---|---|
dadab5a2 | 1 | /* udiv.s 4.3 84/11/01 */ |
43e1c702 BJ |
2 | |
3 | /* | |
4 | * udiv - unsigned division for vax-11 | |
5 | * | |
6 | * arguments: dividend, divisor. | |
7 | * result: quotient. | |
8 | * uses r0-r2 | |
9 | * | |
10 | * If 1 < divisor <= 2147483647, zero-extend the dividend | |
11 | * to 64 bits and let ediv do the work. If the divisor is 1, | |
12 | * ediv will overflow if bit 31 of the dividend is on, so | |
13 | * just return the dividend unchanged. If the divisor is 0, | |
14 | * do the ediv also, so it will generate the proper exception. | |
15 | * All other values of the divisor have bit 31 on: in this case | |
16 | * the quotient must be 0 if divisor > dividend, and 1 otherwise, | |
17 | * provided that the comparison is made as unsigned. | |
18 | */ | |
19 | ||
20 | #include "DEFS.h" | |
21 | ||
dadab5a2 | 22 | ASENTRY(udiv, 0) |
43e1c702 BJ |
23 | movl 4(ap),r0 /* dividend */ |
24 | movl 8(ap),r2 /* divisor */ | |
25 | jeql 1f /* if divisor=0, force exception */ | |
26 | cmpl r2,$1 /* if divisor <= 1 (signed), */ | |
27 | jleq 2f /* no division is necessary */ | |
28 | 1: | |
29 | clrl r1 /* zero-extend the dividend */ | |
30 | ediv r2,r0,r0,r2 /* divide. q->r0, r->r2 (discarded) */ | |
31 | ret | |
32 | 2: | |
33 | jeql 1f /* if divisor=1, return dividend */ | |
34 | cmpl r0,r2 /* unsigned comparison between */ | |
35 | jgequ 2f /* dividend and divisor */ | |
36 | clrl r0 /* dividend < divisor, return 0 */ | |
37 | ret | |
38 | 2: | |
39 | movl $1,r0 /* dividend >= divisor, return 1 */ | |
40 | 1: | |
41 | ret |