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