1: #ifdef LIBC_SCCS
   2:         <@(#)doprnt.s	5.4 (Berkeley) 1/25/87\0>
   3:         .even
   4: #endif LIBC_SCCS
   5: 
   6: /*
   7:  * doprnt(fmt, argl, iop)
   8:  *	char	*fmt, *argl;
   9:  *	FILE	*iop;
  10:  *
  11:  * Output argl to iop using fmt - implements printf, etc.  Special version of
  12:  * doprnt for csh which doesn't need any floating point support.
  13:  */
  14: 
  15: .data
  16: nulstr:
  17:         <(null)\0>
  18:         .even
  19: swtab:
  20:         decimal;        'd
  21:         octal;          'o
  22:         hex;            'x
  23:         charac;         'c
  24:         string;         's
  25:         longorunsg;     'l
  26:         longorunsg;     'L
  27:         unsigned;       'u
  28:         remote;         'r
  29:         long;           'D
  30:         loct;           'O
  31:         lhex;           'X
  32:         lunsigned;      'U
  33:         0;  0
  34: .text
  35: 
  36: .globl  __strout, csv, cret
  37: 
  38: width   = -10.
  39: formp   = -12.
  40: rjust   = -14.
  41: ndfnd   = -16.
  42: ndigit  = -18.
  43: zfill   = -20.
  44: 
  45: .globl  __doprnt
  46: __doprnt:
  47:         jsr     r5,csv
  48:         sub     $128.+12.,sp
  49:         mov     4(r5),formp(r5)         / format
  50:         mov     6(r5),r4
  51: loop:
  52:         mov     sp,r3
  53:         mov     formp(r5),r1
  54: 2:
  55:         movb    (r1)+,r2
  56:         beq     2f
  57:         cmp     r2,$'%
  58:         beq     2f
  59:         movb    r2,(r3)+
  60:         br      2b
  61: 2:
  62:         mov     r1,formp(r5)
  63:         cmp     r3,sp
  64:         beq     2f
  65:         mov     sp,r0
  66:         mov     8(r5),-(sp)
  67:         clr     -(sp)
  68:         mov     r0,-(sp)        / string
  69:         mov     r3,-(sp)        / count
  70:         sub     r0,(sp)
  71:         jsr     pc,__strout
  72:         add     $8,sp
  73: 2:
  74:         tst     r2
  75:         bne     2f
  76:         jmp     cret
  77: 2:
  78:         mov     sp,r3
  79: 2:
  80:         clr     rjust(r5)
  81:         clr     ndigit(r5)
  82:         mov     $' ,zfill(r5)
  83:         cmpb    *formp(r5),$'-
  84:         bne     2f
  85:         inc     formp(r5)
  86:         inc     rjust(r5)
  87: 2:
  88:         cmpb    *formp(r5),$'0
  89:         bne     2f
  90:         mov     $'0,zfill(r5)
  91: 2:
  92:         jsr     r3,gnum
  93:         mov     r1,width(r5)
  94:         clr     ndfnd(r5)
  95:         cmp     r0,$'.
  96:         bne     1f
  97:         jsr     r3,gnum
  98:         mov     r1,ndigit(r5)
  99: 1:
 100:         mov     $swtab,r1
 101: 1:
 102:         mov     (r1)+,r2
 103:         bne     2f
 104:         movb    r0,(r3)+
 105:         jmp     prbuf
 106: 2:
 107:         cmp     r0,(r1)+
 108:         bne     1b
 109:         jmp     (r2)
 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: remote:
 256:         mov     (r4)+,r4
 257:         mov     (r4)+,formp(r5)
 258:         jmp     loop
 259: 
 260: prbuf:
 261:         mov     sp,r2
 262: prstr:
 263:         sub     r2,r3
 264:         mov     width(r5),r1
 265:         sub     r3,r1
 266:         bge     1f
 267:         clr     r1
 268: 1:
 269:         tst     rjust(r5)
 270:         bne     1f
 271:         neg     r1
 272: 1:
 273:         mov     zfill(r5),-(sp)
 274:         mov     8(r5),-(sp)
 275:         mov     r1,-(sp)
 276:         mov     r2,-(sp)        / string
 277:         mov     r3,-(sp)        / count
 278:         jsr     pc,__strout
 279:         add     $10.,sp
 280:         jmp     loop
 281: 
 282: gnum:
 283:         clr     ndfnd(r5)
 284:         clr     r1
 285: 1:
 286:         movb    *formp(r5),r0
 287:         inc     formp(r5)
 288:         sub     $'0,r0
 289:         cmp     r0,$'*-'0
 290:         bne     2f
 291:         mov     (r4)+,r0
 292:         br      3f
 293: 2:
 294:         cmp     r0,$9.
 295:         bhi     1f
 296: 3:
 297:         inc     ndfnd(r5)
 298:         mul     $10.,r1
 299:         add     r0,r1
 300:         br      1b
 301: 1:
 302:         add     $'0,r0
 303:         rts     r3

Defined functions

__doprnt declared in line 45; defined in line 46; used 2 times
charac defined in line 229; used 1 times
  • in line 23
compute defined in line 177; used 1 times
decimal defined in line 146; used 1 times
  • in line 20
formp defined in line 39; used 12 times
gnum defined in line 282; used 2 times
hex defined in line 134; used 1 times
  • in line 22
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 51; used 2 times
lunsigned defined in line 167; used 2 times
ndfnd defined in line 41; used 3 times
ndigit defined in line 42; used 4 times
octal defined in line 125; used 1 times
  • in line 21
prbuf defined in line 260; used 4 times
prstr defined in line 262; used 1 times
remote defined in line 255; used 1 times
  • in line 28
rjust defined in line 40; used 3 times
string defined in line 237; used 1 times
  • in line 24
unsigned defined in line 152; used 2 times
width defined in line 38; used 2 times
zfill defined in line 43; used 5 times

Defined variables

nulstr defined in line 16; used 1 times
swtab defined in line 19; used 1 times
Last modified: 1987-02-24
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 3147
Valid CSS Valid XHTML 1.0 Strict