8354 sync regcomp(3C) with upstream (fix make catalog)
[unleashed/tickless.git] / usr / src / cmd / vi / port / ovdoprnt.s
bloba76133d178737e78e1df76542df221b60a75177c
1 # Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T
2 # All Rights Reserved
5 # CDDL HEADER START
7 # The contents of this file are subject to the terms of the
8 # Common Development and Distribution License, Version 1.0 only
9 # (the "License"). You may not use this file except in compliance
10 # with the License.
12 # You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
13 # or http://www.opensolaris.org/os/licensing.
14 # See the License for the specific language governing permissions
15 # and limitations under the License.
17 # When distributing Covered Code, include this CDDL HEADER in each
18 # file and include the License file at usr/src/OPENSOLARIS.LICENSE.
19 # If applicable, add the following below this CDDL HEADER, with the
20 # fields enclosed by brackets "[]" replaced with your own identifying
21 # information: Portions Copyright [yyyy] [name of copyright owner]
23 # CDDL HEADER END
27 # University Copyright- Copyright (c) 1982, 1986, 1988
28 # The Regents of the University of California
29 # All Rights Reserved
31 # University Acknowledgment- Portions of this document are derived from
32 # software developed by the University of California, Berkeley, and its
33 # contributors.
36 #pragma ident "%Z%%M% %I% %E% SMI"
38 / #ident "@(#)vi:port/ovdoprnt.s 1.5"
39 / C library -- conversions
40 / Overlay modification -- wfj 8/80
41 / stack frame is one word larger...
44 / width=-8.
45 / formp=-10.
46 / rjust=-12.
47 / ndfnd=-14.
48 / ndigit=-16.
49 / zfill=-18.
50 width=-10.
51 formp=-12.
52 rjust=-14.
53 ndfnd=-16.
54 ndigit=-18.
55 zfill=-20.
56 .globl __doprnt
58 .globl __strout
59 .globl csv
60 .globl cret
62 __doprnt:
63 jsr r5,csv
64 sub $128.+12.,sp
65 mov 4(r5),formp(r5) / format
66 mov 6(r5),r4
67 loop:
68 mov sp,r3
69 mov formp(r5),r1
71 movb (r1)+,r2
72 beq 2f
73 cmp r2,$'%
74 beq 2f
75 movb r2,(r3)+
76 br 2b
78 mov r1,formp(r5)
79 cmp r3,sp
80 beq 2f
81 mov sp,r0
82 mov 8(r5),-(sp)
83 clr -(sp)
84 mov r3,-(sp)
85 sub r0,(sp)
86 mov r0,-(sp)
87 jsr pc,__strout
88 add $8,sp
90 tst r2
91 bne 2f
92 jmp cret
94 mov sp,r3
96 clr rjust(r5)
97 clr ndigit(r5)
98 mov $' ,zfill(r5)
99 cmpb *formp(r5),$'-
100 bne 2f
101 inc formp(r5)
102 inc rjust(r5)
104 cmpb *formp(r5),$'0
105 bne 2f
106 mov $'0,zfill(r5)
108 jsr r3,gnum
109 mov r1,width(r5)
110 clr ndfnd(r5)
111 cmp r0,$'.
112 bne 1f
113 jsr r3,gnum
114 mov r1,ndigit(r5)
116 mov $swtab,r1
118 mov (r1)+,r2
119 bne 2f
120 movb r0,(r3)+
121 jmp prbuf
123 cmp r0,(r1)+
124 bne 1b
125 jmp (r2)
126 .data
127 swtab:
128 decimal; 'd
129 octal; 'o
130 hex; 'x
131 charac; 'c
132 string; 's
133 longorunsg; 'l
134 longorunsg; 'L
135 unsigned; 'u
136 remote; 'r
137 long; 'D
138 loct; 'O
139 lhex; 'X
140 lunsigned; 'U
141 0; 0
142 .text
144 longorunsg:
145 movb *formp(r5),r0
146 inc formp(r5)
147 cmp r0,$'o
148 beq loct
149 cmp r0,$'x
150 beq lhex
151 cmp r0,$'d
152 beq long
153 cmp r0,$'u
154 beq lunsigned
155 dec formp(r5)
156 br unsigned
158 octal:
159 clr r0
160 br 1f
161 loct:
162 mov (r4)+,r0
164 mov $8.,r2
165 br 2f
167 hex:
168 clr r0
169 br 1f
171 lhex:
172 mov (r4)+,r0
174 mov $16.,r2
176 mov (r4)+,r1
177 br compute
179 decimal:
180 mov (r4)+,r1
181 sxt r0
182 bmi 3f
183 br 2f
185 unsigned:
186 clr r0
187 br 1f
189 long:
190 mov (r4)+,r0
191 bge 1f
192 mov (r4)+,r1
194 neg r0
195 neg r1
196 sbc r0
197 movb $'-,(r3)+
198 br 2f
200 lunsigned:
201 mov (r4)+,r0
203 mov (r4)+,r1
205 mov $10.,r2
208 / Algorithm courtesy Keith Davis
210 compute:
211 mov r5,-(sp)
212 mov r4,-(sp)
213 mov r0,r4
214 mov ndigit(r5),r0
215 mov r1,r5
216 ashc $0,r4
217 beq 1f
218 tst r0
219 beq 1f
220 movb $'0,(r3)+
222 jsr pc,1f
223 mov (sp)+,r4
224 mov (sp)+,r5
225 br prbuf
228 clr r0
229 mov r4,r1
230 beq 2f
231 div r2,r0
232 mov r0,r4
233 mov r1,r0
235 mov r5,r1
236 asl r2
237 div r2,r0
238 asr r2
239 asl r0
240 cmp r2,r1
241 bgt 2f
242 sub r2,r1
243 inc r0
245 mov r1,-(sp)
246 mov r0,r5
247 bne 2f
248 tst r4
249 beq 1f
251 jsr pc,1b
253 mov (sp)+,r0
254 add $'0,r0
255 cmp r0,$'9
256 ble 1f
257 add $'a-'0-10.,r0
259 movb r0,(r3)+
260 rts pc
262 charac:
263 mov $' ,zfill(r5)
264 mov (r4)+,r0
265 bic $!377,r0
266 beq prbuf
267 movb r0,(r3)+
268 br prbuf
270 string:
271 mov $' ,zfill(r5)
272 mov ndigit(r5),r1
273 mov (r4),r2
274 mov r2,r3
275 bne 1f
276 mov $nulstr,r2
277 mov r2,r3
278 mov r2,(r4)
280 tstb (r2)+
281 beq 1f
282 inc r3
283 sob r1,1b
285 mov (r4)+,r2
286 br prstr
288 remote:
289 mov (r4)+,r4
290 mov (r4)+,formp(r5)
291 jmp loop
293 prbuf:
294 mov sp,r2
295 prstr:
296 sub r2,r3
297 mov width(r5),r1
298 sub r3,r1
299 bge 1f
300 clr r1
302 tst rjust(r5)
303 bne 1f
304 neg r1
306 mov zfill(r5),-(sp)
307 mov 8(r5),-(sp)
308 mov r1,-(sp)
309 mov r3,-(sp)
310 mov r2,-(sp)
311 jsr pc,__strout
312 add $10.,sp
313 jmp loop
315 gnum:
316 clr ndfnd(r5)
317 clr r1
319 movb *formp(r5),r0
320 inc formp(r5)
321 sub $'0,r0
322 cmp r0,$'*-'0
323 bne 2f
324 mov (r4)+,r0
325 br 3f
327 cmp r0,$9.
328 bhi 1f
330 inc ndfnd(r5)
331 mul $10.,r1
332 add r0,r1
333 br 1b
335 add $'0,r0
336 rts r3
338 .data
339 nulstr:
340 <(null)\0>