Imported Upstream version 2.9.0
[debian/cc1111] / device / lib / pic16 / libc / utils / cnvint.S
1 ;
2 ; Convertion routine of 24 bits integer to ASCII
3 ;
4 ; written by Vangelis Rokas <vrokas AT otenet.gr>, 2004
5 ;
6 ;
7 ;
8 ; This program is free software; you can redistribute it and/or
9 ; modify it under the terms of the GNU Library General Public License
10 ; as published by the Free Software Foundation; either version 2
11 ; of the License, or (at your option) any later version.
12 ;
13 ; This library is distributed in the hope that it will be useful,
14 ; but WITHOUT ANY WARRANTY; without even the implied warranty of
15 ; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
16 ; GNU General Public License for more details.
17 ;
18 ; You should have received a copy of the GNU General Public License
19 ; along with this program; if not, write to the Free Software
20 ; Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
21 ;
22 ;
23 ; $Id: cnvint.S 3711 2005-03-31 16:25:17Z vrokas $
24 ;
25
26         radix dec
27         list
28         nolist
29
30
31 POSTINC0        equ     0xfee
32 POSTDEC1        equ     0xfe5
33 PREINC1 equ     0xfe4
34 STATUS  equ     0xfd8
35
36
37         global  _convert_int
38
39
40 .registers      udata_ovr       0x000
41 r0x00   res     1
42 r0x01   res     1
43 r0x02   res     1
44 r0x03   res     1
45 d0x00   res     1
46 d0x01   res     1
47 d0x02   res     1
48 d0x03   res     1
49 d0x04   res     1
50 d0x05   res     1
51 d0x06   res     1
52 d0x07   res     1
53 d0x08   res     1
54 d0x09   res     1
55 digit_count     res     1
56
57
58 S__convert_int  code
59 _convert_int:
60
61         movff   r0x00, POSTDEC1
62         movff   r0x01, POSTDEC1
63         movff   r0x02, POSTDEC1
64         movff   r0x03, POSTDEC1
65         movff   d0x00, POSTDEC1
66         movff   d0x01, POSTDEC1
67         movff   d0x02, POSTDEC1
68         movff   d0x03, POSTDEC1
69         movff   d0x04, POSTDEC1
70         movff   d0x05, POSTDEC1
71         movff   d0x06, POSTDEC1
72         movff   d0x07, POSTDEC1
73         movff   d0x08, POSTDEC1
74         movff   d0x09, POSTDEC1
75         movff   digit_count, POSTDEC1
76
77
78 ; adding digit 0
79         movlw   0
80
81         btfsc   r0x00, 0                ; bit 0
82         addlw   1
83
84         btfsc   r0x00, 1                ; bit 1
85         addlw   2
86
87         btfsc   r0x00, 2                ; bit 2
88         addlw   4
89
90         btfsc   r0x00, 3                ; bit 3
91         addlw   8
92
93         btfsc   r0x00, 4                ; bit 4
94         addlw   6
95
96         btfsc   r0x00, 5                ; bit 5
97         addlw   2
98
99         btfsc   r0x00, 6                ; bit 6
100         addlw   4
101
102         btfsc   r0x00, 7                ; bit 7
103         addlw   8
104
105         btfsc   r0x01, 0                ; bit 8
106         addlw   6
107
108         btfsc   r0x01, 1                ; bit 9
109         addlw   2
110
111         btfsc   r0x01, 2                ; bit 10
112         addlw   4
113
114         btfsc   r0x01, 3                ; bit 11
115         addlw   8
116
117         btfsc   r0x01, 4                ; bit 12
118         addlw   6
119
120         btfsc   r0x01, 5                ; bit 13
121         addlw   2
122
123         btfsc   r0x01, 6                ; bit 14
124         addlw   4
125
126         btfsc   r0x01, 7                ; bit 15
127         addlw   8
128
129         btfsc   r0x02, 0                ; bit 16
130         addlw   6
131
132         btfsc   r0x02, 1                ; bit 17
133         addlw   2
134
135         btfsc   r0x02, 2                ; bit 18
136         addlw   4
137
138         btfsc   r0x02, 3                ; bit 19
139         addlw   8
140
141         btfsc   r0x02, 4                ; bit 20
142         addlw   6
143
144         btfsc   r0x02, 5                ; bit 21
145         addlw   2
146
147         btfsc   r0x02, 6                ; bit 22
148         addlw   4
149
150         btfsc   r0x02, 7                ; bit 23
151         addlw   8
152
153
154         clrf    d0x01
155 @1:
156         addlw   -10
157         bnc     @2
158         incf    d0x01, f
159         bra     @1
160 @2:
161         addlw   10
162         movwf   d0x00
163
164 ; adding digit 1
165         movf    d0x01, w
166
167         btfsc   r0x00, 4                ; bit 4
168         addlw   1
169
170         btfsc   r0x00, 5                ; bit 5
171         addlw   3
172
173         btfsc   r0x00, 6                ; bit 6
174         addlw   6
175
176         btfsc   r0x00, 7                ; bit 7
177         addlw   2
178
179         btfsc   r0x01, 0                ; bit 8
180         addlw   5
181
182         btfsc   r0x01, 1                ; bit 9
183         addlw   1
184
185         btfsc   r0x01, 2                ; bit 10
186         addlw   2
187
188         btfsc   r0x01, 3                ; bit 11
189         addlw   4
190
191         btfsc   r0x01, 4                ; bit 12
192         addlw   9
193
194         btfsc   r0x01, 5                ; bit 13
195         addlw   9
196
197         btfsc   r0x01, 6                ; bit 14
198         addlw   8
199
200         btfsc   r0x01, 7                ; bit 15
201         addlw   6
202
203         btfsc   r0x02, 0                ; bit 16
204         addlw   3
205
206         btfsc   r0x02, 1                ; bit 17
207         addlw   7
208
209         btfsc   r0x02, 2                ; bit 18
210         addlw   4
211
212         btfsc   r0x02, 3                ; bit 19
213         addlw   8
214
215         btfsc   r0x02, 4                ; bit 20
216         addlw   7
217
218         btfsc   r0x02, 5                ; bit 21
219         addlw   5
220
221
222         clrf    d0x02
223 @3:
224         addlw   -10
225         bnc     @4
226         incf    d0x02, f
227         bra     @3
228 @4:
229         addlw   10
230         movwf   d0x01
231
232 ; adding digit 2
233         movf    d0x02, w
234
235         btfsc   r0x00, 7                ; bit 7
236         addlw   1
237
238         btfsc   r0x01, 0                ; bit 8
239         addlw   2
240
241         btfsc   r0x01, 1                ; bit 9
242         addlw   5
243
244         btfsc   r0x01, 5                ; bit 13
245         addlw   1
246
247         btfsc   r0x01, 6                ; bit 14
248         addlw   3
249
250         btfsc   r0x01, 7                ; bit 15
251         addlw   7
252
253         btfsc   r0x02, 0                ; bit 16
254         addlw   5
255
256         btfsc   r0x02, 2                ; bit 18
257         addlw   1
258
259         btfsc   r0x02, 3                ; bit 19
260         addlw   2
261
262         btfsc   r0x02, 4                ; bit 20
263         addlw   5
264
265         btfsc   r0x02, 5                ; bit 21
266         addlw   1
267
268         btfsc   r0x02, 6                ; bit 22
269         addlw   3
270
271         btfsc   r0x02, 7                ; bit 23
272         addlw   6
273
274
275         clrf    d0x03
276 @5:
277         addlw   -10
278         bnc     @6
279         incf    d0x03, f
280         bra     @5
281 @6:
282         addlw   10
283         movwf   d0x02
284
285 ; adding digit 3
286         movf    d0x03, w
287
288         btfsc   r0x01, 2                ; bit 10
289         addlw   1
290
291         btfsc   r0x01, 3                ; bit 11
292         addlw   2
293
294         btfsc   r0x01, 4                ; bit 12
295         addlw   4
296
297         btfsc   r0x01, 5                ; bit 13
298         addlw   8
299
300         btfsc   r0x01, 6                ; bit 14
301         addlw   6
302
303         btfsc   r0x01, 7                ; bit 15
304         addlw   2
305
306         btfsc   r0x02, 0                ; bit 16
307         addlw   5
308
309         btfsc   r0x02, 1                ; bit 17
310         addlw   1
311
312         btfsc   r0x02, 2                ; bit 18
313         addlw   2
314
315         btfsc   r0x02, 3                ; bit 19
316         addlw   4
317
318         btfsc   r0x02, 4                ; bit 20
319         addlw   8
320
321         btfsc   r0x02, 5                ; bit 21
322         addlw   7
323
324         btfsc   r0x02, 6                ; bit 22
325         addlw   4
326
327         btfsc   r0x02, 7                ; bit 23
328         addlw   8
329
330
331         clrf    d0x04
332 @7:
333         addlw   -10
334         bnc     @8
335         incf    d0x04, f
336         bra     @7
337 @8:
338         addlw   10
339         movwf   d0x03
340
341 ; adding digit 4
342         movf    d0x04, w
343
344         btfsc   r0x01, 6                ; bit 14
345         addlw   1
346
347         btfsc   r0x01, 7                ; bit 15
348         addlw   3
349
350         btfsc   r0x02, 0                ; bit 16
351         addlw   6
352
353         btfsc   r0x02, 1                ; bit 17
354         addlw   3
355
356         btfsc   r0x02, 2                ; bit 18
357         addlw   6
358
359         btfsc   r0x02, 3                ; bit 19
360         addlw   2
361
362         btfsc   r0x02, 4                ; bit 20
363         addlw   4
364
365         btfsc   r0x02, 5                ; bit 21
366         addlw   9
367
368         btfsc   r0x02, 6                ; bit 22
369         addlw   9
370
371         btfsc   r0x02, 7                ; bit 23
372         addlw   8
373
374
375         clrf    d0x05
376 @9:
377         addlw   -10
378         bnc     @10
379         incf    d0x05, f
380         bra     @9
381 @10:
382         addlw   10
383         movwf   d0x04
384
385 ; adding digit 5
386         movf    d0x05, w
387
388         btfsc   r0x02, 1                ; bit 17
389         addlw   1
390
391         btfsc   r0x02, 2                ; bit 18
392         addlw   2
393
394         btfsc   r0x02, 3                ; bit 19
395         addlw   5
396
397         btfsc   r0x02, 6                ; bit 22
398         addlw   1
399
400         btfsc   r0x02, 7                ; bit 23
401         addlw   3
402
403
404         clrf    d0x06
405 @11:
406         addlw   -10
407         bnc     @12
408         incf    d0x06, f
409         bra     @11
410 @12:
411         addlw   10
412         movwf   d0x05
413
414 ; adding digit 6
415         movf    d0x06, w
416
417         btfsc   r0x02, 4                ; bit 20
418         addlw   1
419
420         btfsc   r0x02, 5                ; bit 21
421         addlw   2
422
423         btfsc   r0x02, 6                ; bit 22
424         addlw   4
425
426         btfsc   r0x02, 7                ; bit 23
427         addlw   8
428
429
430         clrf    d0x07
431 @13:
432         addlw   -10
433         bnc     @14
434         incf    d0x07, f
435         bra     @13
436 @14:
437         addlw   10
438         movwf   d0x06
439
440 ; adding digit 7
441         movf    d0x07, w
442
443         clrf    digit_count
444
445
446 ; finalization
447         bnz     @15
448         movf    d0x06, w
449         bnz     @16
450         movf    d0x05, w
451         bnz     @17
452         movf    d0x04, w
453         bnz     @18
454         movf    d0x03, w
455         bnz     @19
456         movf    d0x02, w
457         bnz     @20
458         movf    d0x01, w
459         bnz     @21
460         movf    d0x00, w
461         bra     @22
462 @15:
463         incf    digit_count, f
464         addlw   48
465         movwf   POSTINC0
466         movf    d0x06, w
467 @16:
468         incf    digit_count, f
469         addlw   48
470         movwf   POSTINC0
471         movf    d0x05, w
472 @17:
473         incf    digit_count, f
474         addlw   48
475         movwf   POSTINC0
476         movf    d0x04, w
477 @18:
478         incf    digit_count, f
479         addlw   48
480         movwf   POSTINC0
481         movf    d0x03, w
482 @19:
483         incf    digit_count, f
484         addlw   48
485         movwf   POSTINC0
486         movf    d0x02, w
487 @20:
488         incf    digit_count, f
489         addlw   48
490         movwf   POSTINC0
491         movf    d0x01, w
492 @21:
493         incf    digit_count, f
494         addlw   48
495         movwf   POSTINC0
496         movf    d0x00, w
497 @22:
498         incf    digit_count, f
499         addlw   48
500         movwf   POSTINC0
501
502         movf    digit_count, w
503
504         movff   PREINC1, digit_count
505         movff   PREINC1, d0x09
506         movff   PREINC1, d0x08
507         movff   PREINC1, d0x07
508         movff   PREINC1, d0x06
509         movff   PREINC1, d0x05
510         movff   PREINC1, d0x04
511         movff   PREINC1, d0x03
512         movff   PREINC1, d0x02
513         movff   PREINC1, d0x01
514         movff   PREINC1, d0x00
515         movff   PREINC1, r0x03
516         movff   PREINC1, r0x02
517         movff   PREINC1, r0x01
518         movff   PREINC1, r0x00
519         return
520
521         end
522
523 ; Converstion table
524 ;
525 ;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 
526 ;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 
527 ;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 
528 ;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 
529 ;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 
530 ;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 
531 ;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 
532 ;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 
533 ;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 
534 ;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 
535 ;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 
536 ;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 
537 ;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 
538 ;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 
539 ;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 
540 ;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 
541 ;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 
542 ;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 
543 ;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 
544 ;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 
545 ;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 
546 ;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 
547 ;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 
548 ;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