xref: /csrg-svn/usr.bin/ex/OTHER/ovdoprnt.s (revision 48257)
1*48257Sbostic/ Copyright (c) 1991 The Regents of the University of California.
2*48257Sbostic/ All rights reserved.
3*48257Sbostic/
4*48257Sbostic/ %sccs.include.proprietary.c%
5*48257Sbostic/
6*48257Sbostic/	@(#)ovdoprnt.s	1.3 (Berkeley) 04/17/91
7*48257Sbostic/
8*48257Sbostic
9724Sroot/ C library -- conversions
10724Sroot/ Overlay modification -- wfj 8/80
11724Sroot/ stack frame is one word larger...
12724Sroot
13724Sroot/ width=-8.
14724Sroot/ formp=-10.
15724Sroot/ rjust=-12.
16724Sroot/ ndfnd=-14.
17724Sroot/ ndigit=-16.
18724Sroot/ zfill=-18.
19724Srootwidth=-10.
20724Srootformp=-12.
21724Srootrjust=-14.
22724Srootndfnd=-16.
23724Srootndigit=-18.
24724Srootzfill=-20.
25724Sroot.globl	__doprnt
26724Sroot
27724Sroot.globl	__strout
28724Sroot.globl	csv
29724Sroot.globl	cret
30724Sroot
31724Sroot__doprnt:
32724Sroot	jsr	r5,csv
33724Sroot	sub	$128.+12.,sp
34724Sroot	mov	4(r5),formp(r5)		/ format
35724Sroot	mov	6(r5),r4
36724Srootloop:
37724Sroot	mov	sp,r3
38724Sroot	mov	formp(r5),r1
39724Sroot2:
40724Sroot	movb	(r1)+,r2
41724Sroot	beq	2f
42724Sroot	cmp	r2,$'%
43724Sroot	beq	2f
44724Sroot	movb	r2,(r3)+
45724Sroot	br	2b
46724Sroot2:
47724Sroot	mov	r1,formp(r5)
48724Sroot	cmp	r3,sp
49724Sroot	beq	2f
50724Sroot	mov	sp,r0
51724Sroot	mov	8(r5),-(sp)
52724Sroot	clr	-(sp)
53724Sroot	mov	r3,-(sp)
54724Sroot	sub	r0,(sp)
55724Sroot	mov	r0,-(sp)
56724Sroot	jsr	pc,__strout
57724Sroot	add	$8,sp
58724Sroot2:
59724Sroot	tst	r2
60724Sroot	bne	2f
61724Sroot	jmp	cret
62724Sroot2:
63724Sroot	mov	sp,r3
64724Sroot2:
65724Sroot	clr	rjust(r5)
66724Sroot	clr	ndigit(r5)
67724Sroot	mov	$' ,zfill(r5)
68724Sroot	cmpb	*formp(r5),$'-
69724Sroot	bne	2f
70724Sroot	inc	formp(r5)
71724Sroot	inc	rjust(r5)
72724Sroot2:
73724Sroot	cmpb	*formp(r5),$'0
74724Sroot	bne	2f
75724Sroot	mov	$'0,zfill(r5)
76724Sroot2:
77724Sroot	jsr	r3,gnum
78724Sroot	mov	r1,width(r5)
79724Sroot	clr	ndfnd(r5)
80724Sroot	cmp	r0,$'.
81724Sroot	bne	1f
82724Sroot	jsr	r3,gnum
83724Sroot	mov	r1,ndigit(r5)
84724Sroot1:
85724Sroot	mov	$swtab,r1
86724Sroot1:
87724Sroot	mov	(r1)+,r2
88724Sroot	bne	2f
89724Sroot	movb	r0,(r3)+
90724Sroot	jmp	prbuf
91724Sroot2:
92724Sroot	cmp	r0,(r1)+
93724Sroot	bne	1b
94724Sroot	jmp	(r2)
95724Sroot	.data
96724Srootswtab:
97724Sroot	decimal;	'd
98724Sroot	octal;		'o
99724Sroot	hex;		'x
100724Sroot	charac;		'c
101724Sroot	string;		's
102724Sroot	longorunsg;	'l
103724Sroot	longorunsg;	'L
104724Sroot	unsigned;	'u
105724Sroot	remote;		'r
106724Sroot	long;		'D
107724Sroot	loct;		'O
108724Sroot	lhex;		'X
109724Sroot	lunsigned;	'U
110724Sroot	0;  0
111724Sroot	.text
112724Sroot
113724Srootlongorunsg:
114724Sroot	movb	*formp(r5),r0
115724Sroot	inc	formp(r5)
116724Sroot	cmp	r0,$'o
117724Sroot	beq	loct
118724Sroot	cmp	r0,$'x
119724Sroot	beq	lhex
120724Sroot	cmp	r0,$'d
121724Sroot	beq	long
122724Sroot	cmp	r0,$'u
123724Sroot	beq	lunsigned
124724Sroot	dec	formp(r5)
125724Sroot	br	unsigned
126724Sroot
127724Srootoctal:
128724Sroot	clr	r0
129724Sroot	br	1f
130724Srootloct:
131724Sroot	mov	(r4)+,r0
132724Sroot1:
133724Sroot	mov	$8.,r2
134724Sroot	br	2f
135724Sroot
136724Sroothex:
137724Sroot	clr	r0
138724Sroot	br	1f
139724Sroot
140724Srootlhex:
141724Sroot	mov	(r4)+,r0
142724Sroot1:
143724Sroot	mov	$16.,r2
144724Sroot2:
145724Sroot	mov	(r4)+,r1
146724Sroot	br	compute
147724Sroot
148724Srootdecimal:
149724Sroot	mov	(r4)+,r1
150724Sroot	sxt	r0
151724Sroot	bmi	3f
152724Sroot	br	2f
153724Sroot
154724Srootunsigned:
155724Sroot	clr	r0
156724Sroot	br	1f
157724Sroot
158724Srootlong:
159724Sroot	mov	(r4)+,r0
160724Sroot	bge	1f
161724Sroot	mov	(r4)+,r1
162724Sroot3:
163724Sroot	neg	r0
164724Sroot	neg	r1
165724Sroot	sbc	r0
166724Sroot	movb	$'-,(r3)+
167724Sroot	br	2f
168724Sroot
169724Srootlunsigned:
170724Sroot	mov	(r4)+,r0
171724Sroot1:
172724Sroot	mov	(r4)+,r1
173724Sroot2:
174724Sroot	mov	$10.,r2
175724Sroot
176724Sroot/
177724Sroot/ Algorithm courtesy Keith Davis
178724Sroot/
179724Srootcompute:
180724Sroot	mov	r5,-(sp)
181724Sroot	mov	r4,-(sp)
182724Sroot	mov	r0,r4
183724Sroot	mov	ndigit(r5),r0
184724Sroot	mov	r1,r5
185724Sroot	ashc	$0,r4
186724Sroot	beq	1f
187724Sroot	tst	r0
188724Sroot	beq	1f
189724Sroot	movb	$'0,(r3)+
190724Sroot1:
191724Sroot	jsr	pc,1f
192724Sroot	mov	(sp)+,r4
193724Sroot	mov	(sp)+,r5
194724Sroot	br	prbuf
195724Sroot
196724Sroot1:
197724Sroot	clr	r0
198724Sroot	mov	r4,r1
199724Sroot	beq	2f
200724Sroot	div	r2,r0
201724Sroot	mov	r0,r4
202724Sroot	mov	r1,r0
203724Sroot2:
204724Sroot	mov	r5,r1
205724Sroot	asl	r2
206724Sroot	div	r2,r0
207724Sroot	asr	r2
208724Sroot	asl	r0
209724Sroot	cmp	r2,r1
210724Sroot	bgt	2f
211724Sroot	sub	r2,r1
212724Sroot	inc	r0
213724Sroot2:
214724Sroot	mov	r1,-(sp)
215724Sroot	mov	r0,r5
216724Sroot	bne	2f
217724Sroot	tst	r4
218724Sroot	beq	1f
219724Sroot2:
220724Sroot	jsr	pc,1b
221724Sroot1:
222724Sroot	mov	(sp)+,r0
223724Sroot	add	$'0,r0
224724Sroot	cmp	r0,$'9
225724Sroot	ble	1f
226724Sroot	add	$'a-'0-10.,r0
227724Sroot1:
228724Sroot	movb	r0,(r3)+
229724Sroot	rts	pc
230724Sroot
231724Srootcharac:
232724Sroot	mov	$' ,zfill(r5)
233724Sroot	mov	(r4)+,r0
234724Sroot	bic	$!377,r0
235724Sroot	beq	prbuf
236724Sroot	movb	r0,(r3)+
237724Sroot	br	prbuf
238724Sroot
239724Srootstring:
240724Sroot	mov	$' ,zfill(r5)
241724Sroot	mov	ndigit(r5),r1
242724Sroot	mov	(r4),r2
243724Sroot	mov	r2,r3
244724Sroot	bne	1f
245724Sroot	mov	$nulstr,r2
246724Sroot	mov	r2,r3
247724Sroot	mov	r2,(r4)
248724Sroot1:
249724Sroot	tstb	(r2)+
250724Sroot	beq	1f
251724Sroot	inc	r3
252724Sroot	sob	r1,1b
253724Sroot1:
254724Sroot	mov	(r4)+,r2
255724Sroot	br	prstr
256724Sroot
257724Srootremote:
258724Sroot	mov	(r4)+,r4
259724Sroot	mov	(r4)+,formp(r5)
260724Sroot	jmp	loop
261724Sroot
262724Srootprbuf:
263724Sroot	mov	sp,r2
264724Srootprstr:
265724Sroot	sub	r2,r3
266724Sroot	mov	width(r5),r1
267724Sroot	sub	r3,r1
268724Sroot	bge	1f
269724Sroot	clr	r1
270724Sroot1:
271724Sroot	tst	rjust(r5)
272724Sroot	bne	1f
273724Sroot	neg	r1
274724Sroot1:
275724Sroot	mov	zfill(r5),-(sp)
276724Sroot	mov	8(r5),-(sp)
277724Sroot	mov	r1,-(sp)
278724Sroot	mov	r3,-(sp)
279724Sroot	mov	r2,-(sp)
280724Sroot	jsr	pc,__strout
281724Sroot	add	$10.,sp
282724Sroot	jmp	loop
283724Sroot
284724Srootgnum:
285724Sroot	clr	ndfnd(r5)
286724Sroot	clr	r1
287724Sroot1:
288724Sroot	movb	*formp(r5),r0
289724Sroot	inc	formp(r5)
290724Sroot	sub	$'0,r0
291724Sroot	cmp	r0,$'*-'0
292724Sroot	bne	2f
293724Sroot	mov	(r4)+,r0
294724Sroot	br	3f
295724Sroot2:
296724Sroot	cmp	r0,$9.
297724Sroot	bhi	1f
298724Sroot3:
299724Sroot	inc	ndfnd(r5)
300724Sroot	mul	$10.,r1
301724Sroot	add	r0,r1
302724Sroot	br	1b
303724Sroot1:
304724Sroot	add	$'0,r0
305724Sroot	rts	r3
306724Sroot
307724Sroot.data
308724Srootnulstr:
309724Sroot	<(null)\0>
310