summaryrefslogtreecommitdiff
path: root/device/lib/pic16/libc/utils/cnvint.S
blob: 85a35dcac6004eb6a089af1d25e57b2e089b0ebc (plain) (blame)
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
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
;--------------------------------------------------------------------------
;  cnvint.S - convertion routine of 24 bits integer to ASCII
;
;  Copyright (C) 2004, Vangelis Rokas <vrokas at otenet.gr>
;
;  This library is free software; you can redistribute it and/or modify it
;  under the terms of the GNU General Public License as published by the
;  Free Software Foundation; either version 2, or (at your option) any
;  later version.
;
;  This library is distributed in the hope that it will be useful,
;  but WITHOUT ANY WARRANTY; without even the implied warranty of
;  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
;  GNU General Public License for more details.
;
;  You should have received a copy of the GNU General Public License 
;  along with this library; see the file COPYING. If not, write to the
;  Free Software Foundation, 51 Franklin Street, Fifth Floor, Boston,
;   MA 02110-1301, USA.
;
;  As a special exception, if you link this library with other files,
;  some of which are compiled with SDCC, to produce an executable,
;  this library does not by itself cause the resulting executable to
;  be covered by the GNU General Public License. This exception does
;  not however invalidate any other reasons why the executable file
;  might be covered by the GNU General Public License.
;--------------------------------------------------------------------------

	radix dec
	list
	nolist


POSTINC0	equ	0xfee
POSTDEC1	equ	0xfe5
PREINC1	equ	0xfe4
STATUS	equ	0xfd8


	global	_convert_int


.registers	udata_ovr	0x000
r0x00	res	1
r0x01	res	1
r0x02	res	1
r0x03	res	1
d0x00	res	1
d0x01	res	1
d0x02	res	1
d0x03	res	1
d0x04	res	1
d0x05	res	1
d0x06	res	1
d0x07	res	1
d0x08	res	1
d0x09	res	1
digit_count	res	1


S__convert_int	code
_convert_int:

	movff	r0x00, POSTDEC1
	movff	r0x01, POSTDEC1
	movff	r0x02, POSTDEC1
	movff	r0x03, POSTDEC1
	movff	d0x00, POSTDEC1
	movff	d0x01, POSTDEC1
	movff	d0x02, POSTDEC1
	movff	d0x03, POSTDEC1
	movff	d0x04, POSTDEC1
	movff	d0x05, POSTDEC1
	movff	d0x06, POSTDEC1
	movff	d0x07, POSTDEC1
	movff	d0x08, POSTDEC1
	movff	d0x09, POSTDEC1
	movff	digit_count, POSTDEC1


; adding digit 0
	movlw	0

	btfsc	r0x00, 0		; bit 0
	addlw	1

	btfsc	r0x00, 1		; bit 1
	addlw	2

	btfsc	r0x00, 2		; bit 2
	addlw	4

	btfsc	r0x00, 3		; bit 3
	addlw	8

	btfsc	r0x00, 4		; bit 4
	addlw	6

	btfsc	r0x00, 5		; bit 5
	addlw	2

	btfsc	r0x00, 6		; bit 6
	addlw	4

	btfsc	r0x00, 7		; bit 7
	addlw	8

	btfsc	r0x01, 0		; bit 8
	addlw	6

	btfsc	r0x01, 1		; bit 9
	addlw	2

	btfsc	r0x01, 2		; bit 10
	addlw	4

	btfsc	r0x01, 3		; bit 11
	addlw	8

	btfsc	r0x01, 4		; bit 12
	addlw	6

	btfsc	r0x01, 5		; bit 13
	addlw	2

	btfsc	r0x01, 6		; bit 14
	addlw	4

	btfsc	r0x01, 7		; bit 15
	addlw	8

	btfsc	r0x02, 0		; bit 16
	addlw	6

	btfsc	r0x02, 1		; bit 17
	addlw	2

	btfsc	r0x02, 2		; bit 18
	addlw	4

	btfsc	r0x02, 3		; bit 19
	addlw	8

	btfsc	r0x02, 4		; bit 20
	addlw	6

	btfsc	r0x02, 5		; bit 21
	addlw	2

	btfsc	r0x02, 6		; bit 22
	addlw	4

	btfsc	r0x02, 7		; bit 23
	addlw	8


	clrf	d0x01
@1:
	addlw	-10
	bnc	@2
	incf	d0x01, f
	bra	@1
@2:
	addlw	10
	movwf	d0x00

; adding digit 1
	movf	d0x01, w

	btfsc	r0x00, 4		; bit 4
	addlw	1

	btfsc	r0x00, 5		; bit 5
	addlw	3

	btfsc	r0x00, 6		; bit 6
	addlw	6

	btfsc	r0x00, 7		; bit 7
	addlw	2

	btfsc	r0x01, 0		; bit 8
	addlw	5

	btfsc	r0x01, 1		; bit 9
	addlw	1

	btfsc	r0x01, 2		; bit 10
	addlw	2

	btfsc	r0x01, 3		; bit 11
	addlw	4

	btfsc	r0x01, 4		; bit 12
	addlw	9

	btfsc	r0x01, 5		; bit 13
	addlw	9

	btfsc	r0x01, 6		; bit 14
	addlw	8

	btfsc	r0x01, 7		; bit 15
	addlw	6

	btfsc	r0x02, 0		; bit 16
	addlw	3

	btfsc	r0x02, 1		; bit 17
	addlw	7

	btfsc	r0x02, 2		; bit 18
	addlw	4

	btfsc	r0x02, 3		; bit 19
	addlw	8

	btfsc	r0x02, 4		; bit 20
	addlw	7

	btfsc	r0x02, 5		; bit 21
	addlw	5


	clrf	d0x02
@3:
	addlw	-10
	bnc	@4
	incf	d0x02, f
	bra	@3
@4:
	addlw	10
	movwf	d0x01

; adding digit 2
	movf	d0x02, w

	btfsc	r0x00, 7		; bit 7
	addlw	1

	btfsc	r0x01, 0		; bit 8
	addlw	2

	btfsc	r0x01, 1		; bit 9
	addlw	5

	btfsc	r0x01, 5		; bit 13
	addlw	1

	btfsc	r0x01, 6		; bit 14
	addlw	3

	btfsc	r0x01, 7		; bit 15
	addlw	7

	btfsc	r0x02, 0		; bit 16
	addlw	5

	btfsc	r0x02, 2		; bit 18
	addlw	1

	btfsc	r0x02, 3		; bit 19
	addlw	2

	btfsc	r0x02, 4		; bit 20
	addlw	5

	btfsc	r0x02, 5		; bit 21
	addlw	1

	btfsc	r0x02, 6		; bit 22
	addlw	3

	btfsc	r0x02, 7		; bit 23
	addlw	6


	clrf	d0x03
@5:
	addlw	-10
	bnc	@6
	incf	d0x03, f
	bra	@5
@6:
	addlw	10
	movwf	d0x02

; adding digit 3
	movf	d0x03, w

	btfsc	r0x01, 2		; bit 10
	addlw	1

	btfsc	r0x01, 3		; bit 11
	addlw	2

	btfsc	r0x01, 4		; bit 12
	addlw	4

	btfsc	r0x01, 5		; bit 13
	addlw	8

	btfsc	r0x01, 6		; bit 14
	addlw	6

	btfsc	r0x01, 7		; bit 15
	addlw	2

	btfsc	r0x02, 0		; bit 16
	addlw	5

	btfsc	r0x02, 1		; bit 17
	addlw	1

	btfsc	r0x02, 2		; bit 18
	addlw	2

	btfsc	r0x02, 3		; bit 19
	addlw	4

	btfsc	r0x02, 4		; bit 20
	addlw	8

	btfsc	r0x02, 5		; bit 21
	addlw	7

	btfsc	r0x02, 6		; bit 22
	addlw	4

	btfsc	r0x02, 7		; bit 23
	addlw	8


	clrf	d0x04
@7:
	addlw	-10
	bnc	@8
	incf	d0x04, f
	bra	@7
@8:
	addlw	10
	movwf	d0x03

; adding digit 4
	movf	d0x04, w

	btfsc	r0x01, 6		; bit 14
	addlw	1

	btfsc	r0x01, 7		; bit 15
	addlw	3

	btfsc	r0x02, 0		; bit 16
	addlw	6

	btfsc	r0x02, 1		; bit 17
	addlw	3

	btfsc	r0x02, 2		; bit 18
	addlw	6

	btfsc	r0x02, 3		; bit 19
	addlw	2

	btfsc	r0x02, 4		; bit 20
	addlw	4

	btfsc	r0x02, 5		; bit 21
	addlw	9

	btfsc	r0x02, 6		; bit 22
	addlw	9

	btfsc	r0x02, 7		; bit 23
	addlw	8


	clrf	d0x05
@9:
	addlw	-10
	bnc	@10
	incf	d0x05, f
	bra	@9
@10:
	addlw	10
	movwf	d0x04

; adding digit 5
	movf	d0x05, w

	btfsc	r0x02, 1		; bit 17
	addlw	1

	btfsc	r0x02, 2		; bit 18
	addlw	2

	btfsc	r0x02, 3		; bit 19
	addlw	5

	btfsc	r0x02, 6		; bit 22
	addlw	1

	btfsc	r0x02, 7		; bit 23
	addlw	3


	clrf	d0x06
@11:
	addlw	-10
	bnc	@12
	incf	d0x06, f
	bra	@11
@12:
	addlw	10
	movwf	d0x05

; adding digit 6
	movf	d0x06, w

	btfsc	r0x02, 4		; bit 20
	addlw	1

	btfsc	r0x02, 5		; bit 21
	addlw	2

	btfsc	r0x02, 6		; bit 22
	addlw	4

	btfsc	r0x02, 7		; bit 23
	addlw	8


	clrf	d0x07
@13:
	addlw	-10
	bnc	@14
	incf	d0x07, f
	bra	@13
@14:
	addlw	10
	movwf	d0x06

; adding digit 7
	movf	d0x07, w

	clrf	digit_count


; finalization
	bnz	@15
	movf	d0x06, w
	bnz	@16
	movf	d0x05, w
	bnz	@17
	movf	d0x04, w
	bnz	@18
	movf	d0x03, w
	bnz	@19
	movf	d0x02, w
	bnz	@20
	movf	d0x01, w
	bnz	@21
	movf	d0x00, w
	bra	@22
@15:
	incf	digit_count, f
	addlw	48
	movwf	POSTINC0
	movf	d0x06, w
@16:
	incf	digit_count, f
	addlw	48
	movwf	POSTINC0
	movf	d0x05, w
@17:
	incf	digit_count, f
	addlw	48
	movwf	POSTINC0
	movf	d0x04, w
@18:
	incf	digit_count, f
	addlw	48
	movwf	POSTINC0
	movf	d0x03, w
@19:
	incf	digit_count, f
	addlw	48
	movwf	POSTINC0
	movf	d0x02, w
@20:
	incf	digit_count, f
	addlw	48
	movwf	POSTINC0
	movf	d0x01, w
@21:
	incf	digit_count, f
	addlw	48
	movwf	POSTINC0
	movf	d0x00, w
@22:
	incf	digit_count, f
	addlw	48
	movwf	POSTINC0

	movf	digit_count, w

	movff	PREINC1, digit_count
	movff	PREINC1, d0x09
	movff	PREINC1, d0x08
	movff	PREINC1, d0x07
	movff	PREINC1, d0x06
	movff	PREINC1, d0x05
	movff	PREINC1, d0x04
	movff	PREINC1, d0x03
	movff	PREINC1, d0x02
	movff	PREINC1, d0x01
	movff	PREINC1, d0x00
	movff	PREINC1, r0x03
	movff	PREINC1, r0x02
	movff	PREINC1, r0x01
	movff	PREINC1, r0x00
	return

	end

; Converstion table
;
;00	000000000000000000000001	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 
;01	000000000000000000000002	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 
;02	000000000000000000000004	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 
;03	000000000000000000000008	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 
;04	000000000000000000000016	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 6 
;05	000000000000000000000032	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 
;06	000000000000000000000064	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 4 
;07	000000000000000000000128	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 2 8 
;08	000000000000000000000256	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 5 6 
;09	000000000000000000000512	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 1 2 
;10	000000000000000000001024	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 2 4 
;11	000000000000000000002048	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 4 8 
;12	000000000000000000004096	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 0 9 6 
;13	000000000000000000008192	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 1 9 2 
;14	000000000000000000016384	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 6 3 8 4 
;15	000000000000000000032768	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 3 2 7 6 8 
;16	000000000000000000065536	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 6 5 5 3 6 
;17	000000000000000000131072	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 3 1 0 7 2 
;18	000000000000000000262144	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 6 2 1 4 4 
;19	000000000000000000524288	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 5 2 4 2 8 8 
;20	000000000000000001048576	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 1 0 4 8 5 7 6 
;21	000000000000000002097152	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 2 0 9 7 1 5 2 
;22	000000000000000004194304	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 4 1 9 4 3 0 4 
;23	000000000000000008388608	0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0 8 3 8 8 6 0 8