1: .globl _preadn
   2: .text
   3: /
   4: / preadn(pfloat, pdigits, pbuf)
   5: / char *pbuf;
   6: /
   7: / This routine reads a number from the current active file.
   8: / pdigits is the size of pbuf in characters.
   9: / pfloat is 0 to read an integer, 1 to read a real number.
  10: / it returns with the carry bit set if it reaches EOF before
  11: / reading any characters of the number while EOF was not true
  12: / before the call.
  13: /
  14: pfloat = 2.
  15: pdigits = 4.
  16: pbuf = 6.
  17: /
  18: _preadn:
  19:         mov     pbuf(sp),r2
  20:         mov     pdigits(sp),r3
  21:         jsr     pc,iosync
  22:         mov     buf,r0
  23:         mov     FUNIT(r0),flags
  24:         bit     $EOF,flags
  25:         bne     9f
  26:         br      2f
  27: /
  28: / skip white space
  29: /
  30: 1:
  31:         jsr     pc,get
  32:         jsr     pc,iosync
  33:         bit     $EOF,FUNIT(r0)
  34:         bne     prsec
  35: 2:
  36:         movb    *buf,r0
  37:         cmp     r0,$'
  38:         beq     1b
  39:         cmp     r0,$'\t
  40:         beq     1b
  41:         cmp     r0,$14
  42:         beq     1b
  43:         cmp     r0,$'\n
  44:         beq     1b
  45: /
  46: / starting point for
  47: / a signed number
  48: / record + and - if present
  49: /
  50: psignd:
  51:         clr     r1              / digit count
  52:         cmp     r0,$'-
  53:         bne     1f
  54:         dec     r3
  55:         ble     prtood
  56:         movb    r0,(r2)+
  57:         br      2f
  58: 1:
  59:         cmp     r0,$'+
  60:         bne     1f
  61: 2:
  62:         jsr     pc,get
  63:         br      1f
  64: /
  65: / starting point for
  66: / a unsigned number
  67: /
  68: punsd:
  69:         clr     r1
  70: 1:
  71:         jsr     pc,iosync
  72:         bit     $EOF,flags
  73:         bne     2f
  74:         movb    *buf,r0
  75:         cmp     r0,$'0
  76:         blt     2f
  77:         cmp     r0,$'9
  78:         bgt     2f
  79:         dec     r3
  80:         ble     prtood
  81:         movb    r0,(r2)+
  82:         inc     r1
  83:         jsr     pc,get
  84:         br      1b
  85: /
  86: / got a non digit or EOF
  87: /
  88: 2:
  89:         tst     r1
  90:         beq     prerr
  91: 1:
  92:         mov     pfloat(sp),r1
  93:         beq     4f
  94:         cmp     r1,$1
  95:         bne     1f
  96:         cmp     r0,$'.
  97:         beq     3f
  98:         inc     r1
  99: 1:
 100:         cmp     r1,$2
 101:         bne     4f
 102: 2:
 103:         cmp     r0,$'e
 104:         beq     3f
 105:         cmp     r0,$'E
 106:         bne     4f
 107: 3:
 108:         dec     r3
 109:         ble     prtood
 110:         movb    r0,(r2)+
 111:         jsr     pc,get
 112:         inc     r1
 113:         mov     r1,pfloat(sp)
 114:         sub     $2,r1
 115:         beq     punsd
 116:         jsr     pc,iosync
 117:         bit     $EOF,flags
 118:         bne     6f
 119:         movb    *buf,r0
 120:         br      psignd
 121: 4:
 122:         dec     r3
 123:         ble     prtood
 124:         clrb    (r2)+
 125:         rts     pc
 126: prsec:
 127:         sec
 128:         rts     pc
 129: prtood:
 130:         mov     $ETOODIGITS,_perrno
 131:         error   ETOODIGITS
 132: prerr:
 133:         tst     pfloat(sp)
 134:         beq     1f
 135: 6:
 136:         mov     $EBADFNUM,_perrno
 137:         error   EBADFNUM
 138: 1:
 139:         mov     $EBADINUM,_perrno
 140:         error   EBADINUM
 141: 9:
 142:         mov     $EPASTEOF,_perrno
 143:         error   EPASTEOF
 144: /
 145: / long atol(str)
 146: / char *str;
 147: /
 148: / Convert string str to an integer
 149: /
 150: _atol:
 151:         mov     2(sp),r3
 152:         clr     r0
 153:         clr     r1
 154:         cmpb    (r3),$'-
 155:         bne     1f
 156:         inc     r3
 157: 1:
 158:         movb    (r3)+,r2
 159:         beq     1f
 160:         ashc    $1,r0
 161:         bvs     9f
 162:         mov     r1,-(sp)
 163:         mov     r0,-(sp)
 164:         ashc    $2,r0
 165:         bvs     9f
 166:         add     (sp)+,r0
 167:         bvs     9f
 168:         add     (sp)+,r1
 169:         adc     r0
 170:         bvs     9f
 171:         sub     $'0,r2
 172:         add     r2,r1
 173:         adc     r0
 174:         bvs     9f
 175:         br      1b
 176: 1:
 177:         cmpb    *2(sp),$'-
 178:         bne     1f
 179:         neg     r0
 180:         neg     r1
 181: 1:
 182:         sbc     r0
 183:         rts     pc
 184: 9:
 185:         mov     $EBIGGIE,_perrno
 186:         error   EBIGGIE
 187: .bss
 188: flags:  .=.+2
 189: .text

Defined functions

_atol defined in line 150; never used
_preadn declared in line 1; defined in line 18; used 3 times
pbuf defined in line 16; used 1 times
  • in line 19
pdigits defined in line 15; used 1 times
  • in line 20
pfloat defined in line 14; used 3 times
prerr defined in line 132; used 1 times
  • in line 90
prsec defined in line 126; used 1 times
  • in line 34
prtood defined in line 129; used 4 times
psignd defined in line 50; used 1 times
punsd defined in line 68; used 1 times

Defined variables

flags defined in line 188; used 4 times
Last modified: 1981-07-10
Generated: 2016-12-26
Generated by src2html V0.67
page hit count: 2335
Valid CSS Valid XHTML 1.0 Strict