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

Defined functions

charac defined in line 229; used 1 times
  • in line 92
compute defined in line 177; used 1 times
decimal defined in line 146; used 1 times
  • in line 86
float defined in line 255; used 1 times
  • in line 89
formp defined in line 5; used 12 times
general defined in line 105; used 1 times
  • in line 91
gnum defined in line 299; used 2 times
hex defined in line 134; used 1 times
  • in line 88
lhex defined in line 138; used 2 times
loct defined in line 128; used 2 times
long defined in line 156; used 2 times
longorunsg defined in line 111; used 2 times
loop defined in line 25; used 2 times
lunsigned defined in line 167; used 2 times
ndfnd defined in line 7; used 6 times
ndigit defined in line 8; used 7 times
octal defined in line 125; used 1 times
  • in line 87
prbuf defined in line 277; used 7 times
prstr defined in line 279; used 1 times
remote defined in line 272; used 1 times
  • in line 97
rjust defined in line 6; used 3 times
scien defined in line 261; used 1 times
  • in line 90
string defined in line 237; used 1 times
  • in line 93
unsigned defined in line 152; used 2 times
width defined in line 4; used 2 times
zfill defined in line 9; used 5 times

Defined variables

nulstr defined in line 323; used 1 times
swtab defined in line 85; used 1 times
  • in line 74
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 939
Valid CSS Valid XHTML 1.0 Strict