         Edinburgh IMP77 Compiler - Version 8.4

    1  ! NOT REALLY:
    2  %constinteger minint = x'80000000'
    3  %constinteger maxint = x'7FFFFFFF'
    4  %constinteger minintlastdigit = 0
    5  %constinteger maxdigits = 12
    6  
    7  %routine EMAS I77 write(%integer num, pl)
    8     %string (63) %function itos(%integer n, places)
    9        !
   10        ! ITOS0
   11        !
   12        ! Returns a string representing the argument as
   13        ! a decimal number, without any space justification
   14        ! or padding.
   15        !
   16        %const %integer maxdigits = 255
   17        %string (maxdigits) %function itos0(%integer n)
   18           %string (maxdigits) res
   19           %integer s, p, e
   20           s = 0
   21           %if n < 0 %start
   22              s = -1
   23              ! mark -ve
   24              %if n = minint %start
   25                 ! special case
   26                 n = maxint
   27                 ! rely on  "max int = (-min int) - 1"
   28                 s = 1
   29                 ! mark special
   30              %finish %else %start
   31                 n = -n
   32              %finish
   33           %finish
   34           p = addr(res) + maxdigits
   35           e = p
   36           ! end point
   37           byteinteger(p) = rem(n, 10) + '0' %and n = n // 10 %and p = p - 1 %until n = 0
   38           %if s # 0 %start
   39              ! negative
   40              byteinteger(p) = '-'
   41              p = p - 1
   42              %if s > 0 %start
   43                 ! min int
   44                 charno(res, maxdigits) = minintlastdigit
   45              %finish
   46           %finish
   47           byteinteger(p) = e - p
   48           ! length byte
   49           %result = string(p)
   50        %end
   51  !!      %string (63 + maxdigits) res
   52        %string (255) res
   53        %integer p, slen
   54        p = addr(res) + 62
   55        ! digit string right justified
   56        string(p) = itos0(n)
   57        slen = byteinteger(p)
   58        %if n > 0 %and places > 0 %start
   59           byteinteger(p) = ' '
   60           p = p - 1
   61           slen = slen + 1
   62        %finish
   63        %if places <= 0 %start
   64           places = -places
   65        %finish %else %start
   66           places = places + 1
   67        %finish
   68        places = 63 %if places > 63
   69        %while slen < places %cycle
   70           byteinteger(p) = ' '
   71           p = p - 1
   72           slen = slen + 1
   73        %repeat
   74        byteinteger(p) = slen
   75        %result = string(p)
   76     %end
   77     %string (63) res
   78     res = itos(num, pl)
   79     pl = \pl %if pl < 0
   80     spaces(pl - 62)
   81     printstring(res)
   82  %end
   83  
   84  %endoffile

   64 Statements compiled
