1: / Long remainder
2:
3: .globl lrem
4: .globl csv, cret
5:
6: lrem:
7: jsr r5,csv
8: mov 10.(r5),r3
9: sxt r4
10: bpl 1f
11: neg r3
12: 1:
13: cmp r4,8.(r5)
14: bne hardlrem
15: mov 6.(r5),r2
16: mov 4.(r5),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: jmp cret
45:
46: / The divisor is known to be >= 2^15. Only 16 cycles are
47: / needed to get a remainder.
48: hardlrem:
49: mov 6.(r5),r2
50: mov 4.(r5),r1
51: bpl 1f
52: neg r1
53: neg r2
54: sbc r1
55: 1:
56: clr r0
57: mov 8.(r5),r3
58: bge 1f
59: neg r3
60: neg 10.(r5)
61: sbc r3
62: 1:
63: mov $16.,r4
64: 1:
65: clc
66: rol r2
67: rol r1
68: rol r0
69: cmp r3,r0
70: blt 2f
71: bgt 3f
72: cmp 10.(r5),r1
73: blos 2f
74: 3:
75: sob r4,1b
76: br 1f
77: 2:
78: sub 10.(r5),r1
79: sbc r0
80: sub r3,r0
81: sob r4,1b
82: 1:
83: tst 4(r5)
84: bge 1f
85: neg r0
86: neg r1
87: sbc r0
88: 1:
89: jmp cret
Defined functions
lrem
declared in line
3; defined in line
6; used 1 times