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