.title $$ltoa Convert long to Ascii .ident "V02.00" ;+ ; Index Convert long to Ascii (any radix) ; ; Usage ; ; Internal ; ; $$ltoa(buffer, radix, value); ; char *buffer; /* Where it goes */ ; int radix; /* Conversion radix */ ; long value; /* What to convert */ ; ; Description ; ; Called by format to convert a long integer from binary to ; ascii, storing the result in buffer. The radix argument ; determines the conversion: ; ; d Signed decimal ; o Octal ; u Unsigned decimal ; X Hex (10-15 = A-F) ; x Hex (10-15 = a-f) ;- ; Edit history ; V02.00 19-Oct-82 TTC Rework of old CS library ; .psect c$data ; ; Double precision power of ten table. ; Used by the decimal conversion. ; tab: .word 052013, 162000 .word 035632, 145000 .word 002765, 160400 .word 000230, 113200 .word 000017, 041100 .word 000001, 103240 .word 000000, 023420 .word 000000, 001750 .word 000000, 000144 .word 000000, 000012 tabe: ; End of table .psect c$code $$ltoa:: jsr r5,csv$ mov c$pmtr+0(r5),r4 mov c$pmtr+4(r5),r2 mov c$pmtr+6(r5),r3 clr -(sp) cmp c$pmtr+2(r5),#'d beq 70$ cmp c$pmtr+2(r5),#'u beq 80$ ; ; Octal. ; Hexadecimal. ; mov #8.,r1 cmp c$pmtr+2(r5),#'o bne 10$ mov #11.,r1 clr r0 br 20$ 10$: clr r0 asl r3 rol r2 rol r0 20$: asl r3 rol r2 rol r0 asl r3 rol r2 rol r0 cmp c$pmtr+2(r5),#'o beq 30$ asl r3 rol r2 rol r0 30$: cmp r1,#1 beq 40$ tst r0 bne 40$ tst (sp) beq 60$ 40$: inc (sp) add #'0,r0 cmp r0,#'9 blos 50$ add #'A-'0-10.,r0 cmp c$pmtr+2(r5),#'X beq 50$ add #'a-'A,r0 50$: movb r0,(r4)+ 60$: dec r1 bne 10$ br 150$ ; ; Decimal. ; Unsigned. ; 70$: tst r2 bpl 80$ movb #'-,(r4)+ neg r2 neg r3 sbc r2 80$: mov #tab,r1 90$: clr r0 100$: cmp r2,(r1) blo 120$ bhi 110$ cmp r3,2(r1) blo 120$ 110$: sub (r1),r2 sub 2(r1),r3 sbc r2 inc r0 br 100$ 120$: tst r0 bne 130$ tst (sp) beq 140$ 130$: inc (sp) add #'0,r0 movb r0,(r4)+ 140$: add #4,r1 cmp r1,#tabe blo 90$ add #'0,r3 movb r3,(r4)+ 150$: clrb (r4) jmp cret$ .end