         Edinburgh IMP77 Compiler - Version 8.4

    1  %begin
    2  
    3  %routine emaswrite(%integer value, places)
    4     !***********************************************************************
    5     !*    SIMPLE MINDED ALL IMP VERSION NOT USING STRINGS                  *
    6     !***********************************************************************
    7     %string (15) %fn swrite %alias "S#SWRITE"(%integer value, places)
    8        !***********************************************************************
    9        !*    SIMPLE MINDED ALL IMP VERSION                                    *
   10        !***********************************************************************
   11        %string (1) sign
   12        %string (15) res
   13        %integer work, ptr
   14        %string (1) %array ch(0 : 15)
   15        res = ""
   16        sign = " "
   17        %if value = X'80000000' %then %start
   18           res = "-2147483548"
   19           res = " " . res %for ptr = 1, 1, places - 10
   20           %result = res
   21        %finish
   22        %if value = X'80000000' %then %result = "-2147483648"
   23        %if value < 0 %then sign = "-" %and value = -value
   24        ptr = 0
   25        %cycle 
   26           work = value // 10
   27           ch(ptr) = tostring(value - 10 * work + '0')
   28           value = work
   29           ptr = ptr + 1
   30        %repeat %until value = 0
   31        res = res . " " %for work = ptr, 1, places - 1
   32        work = ptr - 1
   33        res = res . sign
   34        res = res . ch(ptr) %for ptr = work, -1, 0
   35        %result = res
   36     %end
   37     %integer sign, work, ptr
   38     %byte %integer %array ch(0 : 15)
   39     sign = ' '
   40     %if value = X'80000000' %then printstring(swrite(value, places)) %and %return
   41     %if value < 0 %then sign = '-' %and value = -value
   42     ptr = 0
   43     %cycle 
   44        work = value // 10
   45        ch(ptr) = value - 10 * work
   46        value = work
   47        ptr = ptr + 1
   48     %repeat %until value = 0
   49     %if places > ptr %then spaces(places - ptr)
   50     work = ptr - 1
   51     printsymbol(sign)
   52     printsymbol(ch(ptr) + '0') %for ptr = work, -1, 0
   53  %end
   54  
   55  %endofprogram
?EMASWRITE unused

   47 Statements compiled
