1: / C library -- printf
   2: 
   3: 
   4: .globl  _printf
   5: 
   6: .globl  pfloat
   7: .globl  pscien
   8: .globl  _putchar
   9: 
  10: .globl  csv
  11: .globl  cret
  12: 
  13: _printf:
  14:         jsr     r5,csv
  15:         sub     $126.,sp
  16:         mov     4(r5),formp             / format
  17:         mov     r5,r4
  18:         add     $6,r4                   / arglist
  19: loop:
  20:         movb    *formp,r0
  21:         beq     1f
  22:         inc     formp
  23:         cmp     r0,$'%
  24:         beq     2f
  25: 3:
  26:         mov     r0,(sp)
  27:         jsr     pc,*$_putchar
  28:         br      loop
  29: 1:
  30:         jmp     cret
  31: 2:
  32:         clr     rjust
  33:         clr     ndigit
  34:         cmpb    *formp,$'-
  35:         bne     2f
  36:         inc     formp
  37:         inc     rjust
  38: 2:
  39:         jsr     r3,gnum
  40:         mov     r1,width
  41:         clr     ndfnd
  42:         cmp     r0,$'.
  43:         bne     1f
  44:         jsr     r3,gnum
  45:         mov     r1,ndigit
  46: 1:
  47:         mov     sp,r3
  48:         add     $4,r3
  49:         mov     $swtab,r1
  50: 1:
  51:         mov     (r1)+,r2
  52:         beq     3b
  53:         cmp     r0,(r1)+
  54:         bne     1b
  55:         jmp     (r2)
  56:         .data
  57: swtab:
  58:         decimal;        'd
  59:         octal;          'o
  60:         hex;            'x
  61:         float;          'f
  62:         scien;          'e
  63:         charac;         'c
  64:         string;         's
  65:         logical;        'l
  66:         remote;         'r
  67:         0;  0
  68:         .text
  69: 
  70: decimal:
  71:         mov     (r4)+,r1
  72:         bge     1f
  73:         neg     r1
  74:         movb    $'-,(r3)+
  75:         br      1f
  76: 
  77: logical:
  78:         mov     (r4)+,r1
  79: 1:
  80:         jsr     pc,1f
  81:         br      prbuf
  82: 1:
  83:         clr     r0
  84:         div     $10.,r0
  85:         mov     r1,-(sp)
  86:         mov     r0,r1
  87:         beq     1f
  88:         jsr     pc,1b
  89: 1:
  90:         mov     (sp)+,r0
  91:         add     $'0,r0
  92:         movb    r0,(r3)+
  93:         rts     pc
  94: 
  95: charac:
  96:         movb    (r4)+,(r3)+
  97:         bne     1f
  98:         dec     r3
  99: 1:
 100:         movb    (r4)+,(r3)+
 101:         bne     prbuf
 102:         dec     r3
 103:         br      prbuf
 104: 
 105: string:
 106:         mov     ndigit,r1
 107:         clr     r3
 108:         mov     (r4),r2
 109: 1:
 110:         tstb    (r2)+
 111:         beq     1f
 112:         inc     r3
 113:         sob     r1,1b
 114: 1:
 115:         mov     (r4)+,r2
 116:         br      prstr
 117: 
 118: hex:
 119:         mov     $1f,r2
 120:         .data
 121: 1:
 122:         -4; !17
 123:         .text
 124:         br      2f
 125: 
 126: octal:
 127:         mov     $1f,r2
 128:         .data
 129: 1:
 130:         -3; !7
 131:         .text
 132: 2:
 133:         mov     (r4)+,r1
 134:         beq     2f
 135:         tst     ndigit
 136:         beq     2f
 137:         movb    $'0,(r3)+
 138: 2:
 139:         clr     r0
 140:         jsr     pc,1f
 141:         br      prbuf
 142: 1:
 143:         mov     r1,-(sp)
 144:         ashc    (r2),r0
 145:         beq     1f
 146:         jsr     pc,1b
 147: 1:
 148:         mov     (sp)+,r0
 149:         bic     2(r2),r0
 150:         add     $'0,r0
 151:         cmp     r0,$'9
 152:         ble     1f
 153:         add     $'A-'0-10.,r0
 154: 1:
 155:         movb    r0,(r3)+
 156:         rts     pc
 157: 
 158: float:
 159:         mov     ndigit,r0
 160:         mov     ndfnd,r2
 161:         jsr     pc,pfloat
 162:         br      prbuf
 163: 
 164: scien:
 165:         mov     ndigit,r0
 166:         mov     ndfnd,r2
 167:         jsr     pc,pscien
 168:         br      prbuf
 169: 
 170: remote:
 171:         mov     (r4)+,r4
 172:         mov     (r4)+,formp
 173:         jmp     loop
 174: 
 175: prbuf:
 176:         mov     sp,r2
 177:         add     $4,r2
 178:         sub     r2,r3
 179: prstr:
 180:         mov     r4,-(sp)
 181:         mov     $' ,-(sp)
 182:         mov     r3,r4
 183:         neg     r3
 184:         add     width,r3
 185:         ble     1f
 186:         tst     rjust
 187:         bne     1f
 188: 2:
 189:         jsr     pc,*$_putchar
 190:         sob     r3,2b
 191: 1:
 192:         tst     r4
 193:         beq     2f
 194: 1:
 195:         movb    (r2)+,(sp)
 196:         jsr     pc,*$_putchar
 197:         sob     r4,1b
 198: 2:
 199:         tst     r3
 200:         ble     1f
 201:         mov     $' ,(sp)
 202: 2:
 203:         jsr     pc,*$_putchar
 204:         sob     r3,2b
 205: 1:
 206:         tst     (sp)+
 207:         mov     (sp)+,r4
 208:         jmp     loop
 209: 
 210: gnum:
 211:         clr     ndfnd
 212:         clr     r1
 213: 1:
 214:         movb    *formp,r0
 215:         inc     formp
 216:         sub     $'0,r0
 217:         cmp     r0,$'*-'0
 218:         bne     2f
 219:         mov     (r4)+,r0
 220:         br      3f
 221: 2:
 222:         cmp     r0,$9.
 223:         bhi     1f
 224: 3:
 225:         inc     ndfnd
 226:         mul     $10.,r1
 227:         add     r0,r1
 228:         br      1b
 229: 1:
 230:         add     $'0,r0
 231:         rts     r3
 232: 
 233: .bss
 234: width:  .=.+2
 235: formp:  .=.+2
 236: rjust:  .=.+2
 237: ndfnd:  .=.+2
 238: ndigit: .=.+2

Defined functions

_printf declared in line 4; defined in line 13; used 944 times
charac defined in line 95; used 1 times
  • in line 63
decimal defined in line 70; used 1 times
  • in line 58
float defined in line 158; used 1 times
  • in line 61
gnum defined in line 210; used 2 times
hex defined in line 118; used 1 times
  • in line 60
logical defined in line 77; used 1 times
  • in line 65
loop defined in line 19; used 3 times
octal defined in line 126; used 1 times
  • in line 59
prbuf defined in line 175; used 6 times
prstr defined in line 179; used 1 times
remote defined in line 170; used 1 times
  • in line 66
scien defined in line 164; used 1 times
  • in line 62
string defined in line 105; used 1 times
  • in line 64

Defined variables

formp defined in line 235; used 8 times
ndfnd defined in line 237; used 5 times
ndigit defined in line 238; used 6 times
rjust defined in line 236; used 3 times
swtab defined in line 57; used 1 times
  • in line 49
width defined in line 234; used 2 times
Last modified: 1975-05-14
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 1546
Valid CSS Valid XHTML 1.0 Strict