1: 2: / C library -- conversions 3: / doprnt.s - used by nonportable printf 4: 5: width=-8. 6: formp=-10. 7: rjust=-12. 8: ndfnd=-14. 9: ndigit=-16. 10: zfill=-18. 11: .globl __doprnt 12: 13: .globl __strout 14: .globl csv 15: .globl cret 16: 17: __doprnt: 18: jsr r5,csv 19: sub $128.+12.,sp 20: mov 4(r5),formp(r5) / format 21: mov 6(r5),r4 22: loop: 23: mov sp,r3 24: mov formp(r5),r1 25: 2: 26: movb (r1)+,r2 27: beq 2f 28: cmp r2,$'% 29: beq 2f 30: movb r2,(r3)+ 31: br 2b 32: 2: 33: mov r1,formp(r5) 34: cmp r3,sp 35: beq 2f 36: mov sp,r0 37: mov 8(r5),-(sp) 38: clr -(sp) 39: mov r3,-(sp) 40: sub r0,(sp) 41: mov r0,-(sp) 42: jsr pc,__strout 43: add $8,sp 44: 2: 45: tst r2 46: bne 2f 47: jmp cret 48: 2: 49: mov sp,r3 50: 2: 51: clr rjust(r5) 52: clr ndigit(r5) 53: mov $' ,zfill(r5) 54: cmpb *formp(r5),$'- 55: bne 2f 56: inc formp(r5) 57: inc rjust(r5) 58: 2: 59: cmpb *formp(r5),$'0 60: bne 2f 61: mov $'0,zfill(r5) 62: 2: 63: jsr r3,gnum 64: mov r1,width(r5) 65: clr ndfnd(r5) 66: cmp r0,$'. 67: bne 1f 68: jsr r3,gnum 69: mov r1,ndigit(r5) 70: 1: 71: mov $swtab,r1 72: 1: 73: mov (r1)+,r2 74: bne 2f 75: movb r0,(r3)+ 76: jmp prbuf 77: 2: 78: cmp r0,(r1)+ 79: bne 1b 80: jmp (r2) 81: .data 82: swtab: 83: decimal; 'd 84: octal; 'o 85: hex; 'x 86: charac; 'c 87: string; 's 88: longorunsg; 'l 89: longorunsg; 'L 90: unsigned; 'u 91: remote; 'r 92: long; 'D 93: loct; 'O 94: lhex; 'X 95: lunsigned; 'U 96: 0; 0 97: .text 98: 99: longorunsg: 100: movb *formp(r5),r0 101: inc formp(r5) 102: cmp r0,$'o 103: beq loct 104: cmp r0,$'x 105: beq lhex 106: cmp r0,$'d 107: beq long 108: cmp r0,$'u 109: beq lunsigned 110: dec formp(r5) 111: br unsigned 112: 113: octal: 114: clr r0 115: br 1f 116: loct: 117: mov (r4)+,r0 118: 1: 119: mov $8.,r2 120: br 2f 121: 122: hex: 123: clr r0 124: br 1f 125: 126: lhex: 127: mov (r4)+,r0 128: 1: 129: mov $16.,r2 130: 2: 131: mov (r4)+,r1 132: br compute 133: 134: decimal: 135: mov (r4)+,r1 136: sxt r0 137: bmi 3f 138: br 2f 139: 140: unsigned: 141: clr r0 142: br 1f 143: 144: long: 145: mov (r4)+,r0 146: bge 1f 147: mov (r4)+,r1 148: 3: 149: neg r0 150: neg r1 151: sbc r0 152: movb $'-,(r3)+ 153: br 2f 154: 155: lunsigned: 156: mov (r4)+,r0 157: 1: 158: mov (r4)+,r1 159: 2: 160: mov $10.,r2 161: 162: / 163: / Algorithm courtesy Keith Davis 164: / 165: compute: 166: mov r5,-(sp) 167: mov r4,-(sp) 168: mov r0,r4 169: mov ndigit(r5),r0 / patch 170: mov r1,r5 171: ashc $0,r4 172: beq 1f 173: / tst ndigit(r5) 174: tst r0 / patch 175: beq 1f 176: movb $'0,(r3)+ 177: 1: 178: jsr pc,1f 179: mov (sp)+,r4 180: mov (sp)+,r5 181: br prbuf 182: 183: 1: 184: clr r0 185: mov r4,r1 186: beq 2f 187: div r2,r0 188: mov r0,r4 189: mov r1,r0 190: 2: 191: mov r5,r1 192: asl r2 193: div r2,r0 194: asr r2 195: asl r0 196: cmp r2,r1 197: bgt 2f 198: sub r2,r1 199: inc r0 200: 2: 201: mov r1,-(sp) 202: mov r0,r5 203: bne 2f 204: tst r4 205: beq 1f 206: 2: 207: jsr pc,1b 208: 1: 209: mov (sp)+,r0 210: add $'0,r0 211: cmp r0,$'9 212: ble 1f 213: add $'a-'0-10.,r0 214: 1: 215: movb r0,(r3)+ 216: rts pc 217: 218: charac: 219: movb (r4)+,(r3)+ 220: bne 1f 221: dec r3 222: 1: 223: movb (r4)+,(r3)+ 224: bne prbuf 225: dec r3 226: br prbuf 227: 228: string: 229: mov ndigit(r5),r1 230: mov (r4),r2 231: mov r2,r3 232: bne 1f 233: mov $nulstr,r2 234: mov r2,r3 235: mov r2,(r4) 236: 1: 237: tstb (r2)+ 238: beq 1f 239: inc r3 240: sob r1,1b 241: 1: 242: mov (r4)+,r2 243: br prstr 244: 245: remote: 246: mov (r4)+,r4 247: mov (r4)+,formp(r5) 248: jmp loop 249: 250: prbuf: 251: mov sp,r2 252: prstr: 253: sub r2,r3 254: mov width(r5),r1 255: sub r3,r1 256: bge 1f 257: clr r1 258: 1: 259: tst rjust(r5) 260: bne 1f 261: neg r1 262: 1: 263: mov zfill(r5),-(sp) 264: mov 8(r5),-(sp) 265: mov r1,-(sp) 266: mov r3,-(sp) 267: mov r2,-(sp) 268: jsr pc,__strout 269: add $10.,sp 270: jmp loop 271: 272: gnum: 273: clr ndfnd(r5) 274: clr r1 275: 1: 276: movb *formp(r5),r0 277: inc formp(r5) 278: sub $'0,r0 279: cmp r0,$'*-'0 280: bne 2f 281: mov (r4)+,r0 282: br 3f 283: 2: 284: cmp r0,$9. 285: bhi 1f 286: 3: 287: inc ndfnd(r5) 288: mul $10.,r1 289: add r0,r1 290: br 1b 291: 1: 292: add $'0,r0 293: rts r3 294: 295: /.bss 296: /width: .=.+2 297: /formp: .=.+2 298: /rjust: .=.+2 299: /ndfnd: .=.+2 300: /ndigit: .=.+2 301: /zfill: .=.+2 302: .data 303: nulstr: 304: <(null)\0>