|
|
1.1 root 1: # udiv.s 6.1 83/07/29
2: #
3: # udiv - unsigned division for vax-11
4: #
5: # arguments: dividend, divisor.
6: # result: quotient.
7: # uses r0-r2
8: #
9: # If 1 < divisor <= 2147483647, zero-extend the dividend
10: # to 64 bits and let ediv do the work. If the divisor is 1,
11: # ediv will overflow if bit 31 of the dividend is on, so
12: # just return the dividend unchanged. If the divisor is 0,
13: # do the ediv also, so it will generate the proper exception.
14: # All other values of the divisor have bit 31 on: in this case
15: # the quotient must be 0 if divisor > dividend, and 1 otherwise,
16: # provided that the comparison is made as unsigned.
17: #
18: .text
19: .align 1
20: .globl udiv
21: udiv: .word 0x0000
22: movl 4(ap),r0 # Dividend
23: movl 8(ap),r2 # Divisor
24: jeql div # If divisor=0, force exception
25: cmpl r2,$1 # If divisor <= 1 (signed),
26: jleq nodiv # no division is necessary
27: div: clrl r1 # Zero-extend the dividend
28: ediv r2,r0,r0,r2 # Divide. q->r0, r->r2 (discarded)
29: ret
30: nodiv: jeql retn # If divisor=1, return dividend
31: cmpl r0,r2 # Unsigned comparison between
32: jgequ one # dividend and divisor
33: clrl r0 # Dividend < divisor, return 0
34: ret
35: one: movl $1,r0 # Dividend >= divisor, return 1
36: retn: ret
37:
38:
This archive runs on limited infrastructure. Preserving old code on modern bandwidth. Automated agents are requested to crawl responsibly.