2 ; Ullrich von Bassewitz, 31.05.1998
4 ; char* itoa (int value, char* s, int radix);
5 ; char* utoa (unsigned value, char* s, int radix);
11 .importzp sp, sreg, ptr2, ptr3, tmp1
15 .byte '-', '3', '2', '7', '6', '8', 0
19 ; Common subroutine to pop the parameters and put them into core
22 dopop: sta tmp1 ; will loose high byte
37 jmp addysp1 ; Bump stack pointer
43 _itoa: jsr dopop ; pop the arguments
45 ; We must handle $8000 in a special way, since it is the only negative
46 ; number that has no positive 16-bit counterpart
57 L1: lda specval,y ; copy -32768
63 ; Check if the value is negative. If so, write a - sign and negate the
66 L2: lda sreg+1 ; get high byte
70 sta (ptr2),y ; store sign
90 _utoa: jsr dopop ; pop the arguments
92 ; Convert to string by dividing and push the result onto the stack
97 ; Divide sreg/tmp1 -> sreg, remainder in a
111 tay ; get remainder into y
112 lda __hextab,y ; get hex character
113 pha ; save char value on stack
119 ; Get the characters from the stack into the string
124 beq L10 ; jump if sentinel
128 ; Done! Return the target string