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

Defined functions

__doprnt declared in line 9; defined in line 15; used 2 times
charac defined in line 215; used 1 times
  • in line 84
compute defined in line 163; used 1 times
decimal defined in line 132; used 1 times
  • in line 81
formp defined in line 4; used 12 times
gnum defined in line 268; used 2 times
hex defined in line 120; used 1 times
  • in line 83
lhex defined in line 124; used 2 times
loct defined in line 114; used 2 times
long defined in line 142; used 2 times
longorunsg defined in line 97; used 2 times
loop defined in line 20; used 2 times
lunsigned defined in line 153; used 2 times
ndfnd defined in line 6; used 3 times
ndigit defined in line 7; used 4 times
octal defined in line 111; used 1 times
  • in line 82
prbuf defined in line 246; used 4 times
prstr defined in line 248; used 1 times
remote defined in line 241; used 1 times
  • in line 89
rjust defined in line 5; used 3 times
string defined in line 223; used 1 times
  • in line 85
unsigned defined in line 138; used 2 times
width defined in line 3; used 2 times
zfill defined in line 8; used 5 times

Defined variables

nulstr defined in line 292; used 1 times
swtab defined in line 80; used 1 times
  • in line 69
Last modified: 1982-09-22
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 756
Valid CSS Valid XHTML 1.0 Strict