Initial revision
[ssr] / StraySrc / Libraries / Sapphire / csapph / s / crts
1 ;
2 ; crts.s
3 ;
4 ; C run-time support functions for Sapphire
5 ;
6 ; © 1995 Straylight
7 ;
8
9 ;----- Standard header ------------------------------------------------------
10
11 GET libs:header
12 ; GET libs:swis
13
14 GET libs:stream
15
16 ;----- External dependencies ------------------------------------------------
17
18 GET sapphire:divide
19 IMPORT div_byZero
20
21 ;----- Main code ------------------------------------------------------------
22
23 AREA |Sapphire$$Code|,CODE,READONLY
24
25 ; --- __rt_udiv10 ---
26 ;
27 ; On entry: R0 == value to divide
28 ;
29 ; On exit: R0 == value / 10
30 ; R1 == value % 10
31 ;
32 ; Use: Divides an unsigned number by 10.
33
34 EXPORT |__rt_udiv10|
35 EXPORT |_kernel_udiv10|
36
37 |__rt_udiv10| ROUT
38 |_kernel_udiv10|
39
40 MOV R1,R0
41 ADD R0,R0,R0,LSR #1
42 ADD R0,R0,R0,LSR #4
43 ADD R0,R0,R0,LSR #8
44 ADD R0,R0,R0,LSR #16
45 MOV R0,R0,LSR #4
46 ADD R2,R0,R0,LSL #2
47 SUB R1,R1,R2,LSL #1
48 SUBS R1,R1,#10
49 ADDGE R0,R0,#1
50 ADDLT R1,R1,#10
51 MOVS PC,R14
52
53 LTORG
54
55 ; --- __rt_sdiv10 ---
56 ;
57 ; On entry: R0 == value to divide
58 ;
59 ; On exit: R0 == value / 10
60 ; R1 == value % 10
61 ;
62 ; Use: Divides a signed number by 10.
63
64 EXPORT |__rt_sdiv10|
65 EXPORT |_kernel_sdiv10|
66
67 |__rt_sdiv10| ROUT
68 |_kernel_sdiv10|
69
70 MOVS R3,R0
71 RSBMI R0,R0,#0
72 MOV R1,R0
73 ADD R0,R0,R0,LSR #1
74 ADD R0,R0,R0,LSR #4
75 ADD R0,R0,R0,LSR #8
76 ADD R0,R0,R0,LSR #16
77 MOV R0,R0,LSR #4
78 ADD R2,R0,R0,LSL #2
79 SUB R1,R1,R2,LSL #1
80 SUBS R1,R1,#10
81 ADDGE R0,R0,#1
82 ADDLT R1,R1,#10
83 CMP R3,#0
84 RSBMI R0,R0,#0
85 RSBMI R1,R1,#0
86 MOVS PC,R14
87
88 LTORG
89
90 ; --- __rt_udiv ---
91 ;
92 ; On entry: R0 == divisor
93 ; R1 == dividend
94 ;
95 ; On exit: R0 == quotient
96 ; R1 == remainder
97 ;
98 ; Use: Divides in an unsigned way.
99
100 EXPORT |__rt_udiv|
101 EXPORT |x$udivide|
102
103 |__rt_udiv| ROUT
104 |x$udivide|
105
106 EOR R0,R1,R0
107 EOR R1,R1,R0
108 EOR R0,R1,R0
109 B div_unsigned
110
111 LTORG
112
113 ; --- __rt_sdiv ---
114 ;
115 ; On entry: R0 == divisor
116 ; R1 == dividend
117 ;
118 ; On exit: R0 == quotient
119 ; R1 == remainder
120 ;
121 ; Use: Divides in a signed way.
122
123 EXPORT |__rt_sdiv|
124 EXPORT |x$divide|
125
126 |__rt_sdiv| ROUT
127 |x$divide|
128
129 EOR R0,R1,R0
130 EOR R1,R1,R0
131 EOR R0,R1,R0
132 B divide
133
134 LTORG
135
136 ; --- __rt_divtest ---
137 ;
138 ; On entry: R0 == a number
139 ;
140 ; On exit: --
141 ;
142 ; Use: If R0 is zero, a `divide by zero' error is raised.
143
144 EXPORT |__rt_divtest|
145 EXPORT |x$divtest|
146
147 |__rt_divtest| ROUT
148 |x$divtest|
149
150 CMP R0,#0
151 MOVNES PC,R14
152 B div_byZero
153
154 LTORG
155
156 ;----- That's all, folks ----------------------------------------------------
157
158 END