1: / Long remainder
2:
3: .globl alrem
4: .globl csv, cret
5: alrem:
6: jsr r5,csv
7: mov 8.(r5),r3
8: sxt r4
9: bpl 1f
10: neg r3
11: 1:
12: cmp r4,6.(r5)
13: bne hardlrem
14: mov 4.(r5),r0
15: mov 2(r0),r2
16: mov (r0),r1
17: mov r1,r4
18: bge 1f
19: neg r1
20: neg r2
21: sbc r1
22: 1:
23: clr r0
24: div r3,r0
25: mov r1,-(sp) / Stash interim result.
26: mov r1,r0
27: mov r2,r1
28: div r3,r0
29: bvc 1f
30: mov (sp),r0 / Recover interim result.
31: mov r2,r1 / (Regs may be clobbered by failed div.)
32: sub r3,r0
33: div r3,r0
34: tst r1
35: beq 9f
36: add r3,r1
37: 1:
38: tst (sp)+ / Pop temp off stack.
39: tst r4
40: bpl 9f
41: neg r1
42: 9:
43: sxt r0
44: mov 4.(r5),r3
45: mov r0,(r3)+
46: mov r1,(r3)
47: jmp cret
48:
49: / The divisor is known to be >= 2^15. Only 16 cycles are
50: / needed to get a remainder.
51: hardlrem:
52: mov 4.(r5),r0
53: mov 2(r0),r2
54: mov (r0),r1
55: bpl 1f
56: neg r1
57: neg r2
58: sbc r1
59: 1:
60: clr r0
61: mov 6.(r5),r3
62: bge 1f
63: neg r3
64: neg 8.(r5)
65: sbc r3
66: 1:
67: mov $16.,r4
68: 1:
69: clc
70: rol r2
71: rol r1
72: rol r0
73: cmp r3,r0
74: blt 2f
75: bgt 3f
76: cmp 8.(r5),r1
77: blos 2f
78: 3:
79: sob r4,1b
80: br 1f
81: 2:
82: sub 8.(r5),r1
83: sbc r0
84: sub r3,r0
85: sob r4,1b
86: 1:
87: mov 4.(r5),r3
88: tst (r3)
89: bge 1f
90: neg r0
91: neg r1
92: sbc r0
93: 1:
94: mov r0,(r3)+
95: mov r1,(r3)
96: jmp cret
Defined functions
alrem
declared in line
3; defined in line
5; used 1 times