
             Edinburgh IMP77 Compiler - Version 8.4


        LANG 0000
        PUSHI #0x00000000
        DEF V_0001 NIL  record, name, format=0, constant
        INIT 1
        DEF V_0002 REM  integer, function, format=1, prim-spec-indirect
        START
        DEF V_0003 P  integer, simple, format=1, 0
        DEF V_0004 Q  integer, simple, format=1, 0
        FINISH
        DEF V_0003 FLOAT  real, function, format=1, prim-spec-indirect
        START
        DEF V_0004 N  integer, simple, format=1, 0
        FINISH
        DEF V_0004 TOSTRING  string, function, format=1, prim-spec-indirect
        START
        DEF V_0005 C  integer, simple, format=1, 0
        FINISH
        DEF V_0005 ADDR  integer, function, format=1, prim-spec-indirect
        START
        DEF V_0006 P  type=0, name, format=0, 0
        FINISH
        DEF V_0006 INTEGER  integer, map, format=1, prim-spec
        START
        DEF V_0007 N  integer, simple, format=1, 0
        FINISH
        DEF V_0007 BYTEINTEGER  byte-integer, map, format=2, prim-spec
        START
        DEF V_0008 N  integer, simple, format=1, 0
        FINISH
        DEF V_0008 STRING  string, map, format=0, prim-spec
        START
        DEF V_0009 N  integer, simple, format=1, 0
        FINISH
        DEF V_0009 RECORD  record, map, format=0, prim-spec
        START
        DEF V_000a N  integer, simple, format=1, 0
        FINISH
        DEF V_000a REAL  real, map, format=1, prim-spec
        START
        DEF V_000b N  integer, simple, format=1, 0
        FINISH
        DEF V_000b LONGREAL  long-real, map, format=4, prim-spec
        START
        DEF V_000c N  integer, simple, format=1, 0
        FINISH
        DEF V_000c LENGTH  byte-integer, map, format=2, prim-spec
        START
        DEF V_000d S  string, simple, format=255, 0
        FINISH
        DEF V_000d CHARNO  byte-integer, map, format=2, prim-spec
        START
        DEF V_000e S  string, simple, format=255, 0
        DEF V_000f N  integer, simple, format=1, 0
        FINISH
        DEF V_000e INT  integer, function, format=1, prim-spec-indirect
        START
        DEF V_000f R  long-real, simple, format=4, 0
        FINISH
        DEF V_000f SHORTINTEGER  short-integer, map, format=3, prim-spec
        START
        DEF V_0010 N  integer, simple, format=1, 0
        FINISH
        DEF V_0010 TYPEOF  integer, function, format=1, external-spec-indirect
        START
        DEF V_0011 N  type=0, name, format=0, 0
        FINISH
        DEF V_0011 SIZEOF  integer, function, format=1, external-spec-indirect
        START
        DEF V_0012 N  type=0, name, format=0, 0
        FINISH
        DEF V_0012 TYPENAME  string, function, format=255, external-spec-indirect
        START
        DEF V_0013 T  integer, simple, format=1, 0
        FINISH
        DEF V_0013 ARRAYENTRYSIZE  integer, function, format=1, external-spec-indirect
        START
        DEF V_0014 N  type=0, name, format=0, 0
        FINISH
        DEF V_0014 ARRAYENTRYTYPE  integer, function, format=1, external-spec-indirect
        START
        DEF V_0015 N  type=0, name, format=0, 0
        FINISH
        DEF V_0015 ARRAYDIMENSIONS  integer, function, format=1, external-spec-indirect
        START
        DEF V_0016 N  type=0, name, format=0, 0
        FINISH
        DEF V_0016 ARRAYLOWERBOUND  integer, function, format=1, external-spec-indirect
        START
        DEF V_0017 N  type=0, name, format=0, 0
        DEF V_0018 INDEX  integer, simple, format=1, 0
        FINISH
        DEF V_0017 ARRAYUPPERBOUND  integer, function, format=1, external-spec-indirect
        START
        DEF V_0018 N  type=0, name, format=0, 0
        DEF V_0019 INDEX  integer, simple, format=1, 0
        FINISH
        DEF V_0018 EVENTFM  record, record-format, format=24, 0
        START
        DEF V_0000 EVENT  integer, simple, format=1, 0
        DEF V_0000 SUB  integer, simple, format=1, 0
        DEF V_0000 INFO  integer, simple, format=1, 0
        DEF V_0000 LINE  integer, simple, format=1, 0
        DEF V_0000 MESSAGE  string, simple, format=255, 0
        FINISH
        DEF V_0019 EVENT  record, map, format=24, external-spec
        START
        FINISH
        DEF V_001a INPUTSTREAM  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_001b INPUTNAME  string, function, format=255, external-spec-indirect
        START
        FINISH
        DEF V_001c SELECTINPUT  type=0, routine, format=0, external-spec
        START
        DEF V_001d N  integer, simple, format=1, 0
        FINISH
        DEF V_001d OPENINPUT  type=0, routine, format=0, external-spec
        START
        DEF V_001e N  integer, simple, format=1, 0
        DEF V_001f FD  string, simple, format=255, 0
        FINISH
        DEF V_001e OPENBINARYINPUT  type=0, routine, format=0, external-spec
        START
        DEF V_001f N  integer, simple, format=1, 0
        DEF V_0020 FD  string, simple, format=255, 0
        FINISH
        DEF V_001f CLOSEINPUT  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0020 RESETINPUT  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0021 SEEKINPUT  type=0, routine, format=0, external-spec
        START
        DEF V_0022 DISPLACEMENT  integer, simple, format=1, 0
        DEF V_0023 STARTPOINT  integer, simple, format=1, 0
        FINISH
        DEF V_0022 TELLINPUT  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_0023 READSYMBOL  type=0, routine, format=0, external-spec
        START
        DEF V_0024 P  type=0, name, format=0, 0
        FINISH
        DEF V_0024 NEXTSYMBOL  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_0025 READBUFFER  integer, function, format=1, external-spec-indirect
        START
        DEF V_0026 PTR  type=0, name, format=0, 0
        DEF V_0027 COUNT  integer, simple, format=1, 0
        FINISH
        DEF V_0026 PROMPT  type=0, routine, format=0, external-spec
        START
        DEF V_0027 S  string, simple, format=31, 0
        FINISH
        DEF V_0027 CURRENTPROMPT  string, function, format=31, external-spec-indirect
        START
        FINISH
        DEF V_0028 GETMAXINPUTSTREAM  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_0029 FILEEND  type=0, predicate, format=0, external-spec
        START
        FINISH
        DEF V_002a ALLOWEOFEVENT  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_002b BLOCKEOFEVENT  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_002c OUTPUTSTREAM  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_002d OUTPUTNAME  string, function, format=255, external-spec-indirect
        START
        FINISH
        DEF V_002e SELECTOUTPUT  type=0, routine, format=0, external-spec
        START
        DEF V_002f N  integer, simple, format=1, 0
        FINISH
        DEF V_002f OPENOUTPUT  type=0, routine, format=0, external-spec
        START
        DEF V_0030 N  integer, simple, format=1, 0
        DEF V_0031 FD  string, simple, format=255, 0
        FINISH
        DEF V_0030 OPENBINARYOUTPUT  type=0, routine, format=0, external-spec
        START
        DEF V_0031 N  integer, simple, format=1, 0
        DEF V_0032 FD  string, simple, format=255, 0
        FINISH
        DEF V_0031 CLOSEOUTPUT  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0032 RESETOUTPUT  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0033 SEEKOUTPUT  type=0, routine, format=0, external-spec
        START
        DEF V_0034 DISPLACEMENT  integer, simple, format=1, 0
        DEF V_0035 STARTPOINT  integer, simple, format=1, 0
        FINISH
        DEF V_0034 TELLOUTPUT  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_0035 PRINTSYMBOL  type=0, routine, format=0, external-spec
        START
        DEF V_0036 SYM  integer, simple, format=1, 0
        FINISH
        DEF V_0036 WRITEBUFFER  integer, function, format=1, external-spec-indirect
        START
        DEF V_0037 PTR  type=0, name, format=0, 0
        DEF V_0038 COUNT  integer, simple, format=1, 0
        FINISH
        DEF V_0037 DEBUGSYMBOL  type=0, routine, format=0, external-spec
        START
        DEF V_0038 SYM  integer, simple, format=1, 0
        FINISH
        DEF V_0038 DEBUGREAL  type=0, routine, format=0, external-spec
        START
        DEF V_0039 D  long-real, simple, format=4, 0
        FINISH
        DEF V_0039 GETMAXOUTPUTSTREAM  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_003a FLUSHOUTPUT  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_003b SKIPSYMBOL  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_003c PRINTSTRING  type=0, routine, format=0, external-spec
        START
        DEF V_003d S  string, simple, format=255, 0
        FINISH
        DEF V_003d DEBUGSTRING  type=0, routine, format=0, external-spec
        START
        DEF V_003e S  string, simple, format=255, 0
        FINISH
        DEF V_003e DEBUGNEWLINE  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_003f DEBUGSPACE  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0040 DEBUGSPACES  type=0, routine, format=0, external-spec
        START
        DEF V_0041 COUNT  integer, simple, format=1, 0
        FINISH
        DEF V_0041 WRITE  type=0, routine, format=0, external-spec
        START
        DEF V_0042 V  integer, simple, format=1, 0
        DEF V_0043 P  integer, simple, format=1, 0
        FINISH
        DEF V_0042 SPACE  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0043 SPACES  type=0, routine, format=0, external-spec
        START
        DEF V_0044 N  integer, simple, format=1, 0
        FINISH
        DEF V_0044 NEWLINE  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0045 NEWLINES  type=0, routine, format=0, external-spec
        START
        DEF V_0046 N  integer, simple, format=1, 0
        FINISH
        DEF V_0046 PRINTFL  type=0, routine, format=0, external-spec
        START
        DEF V_0047 F  long-real, simple, format=4, 0
        DEF V_0048 DP  integer, simple, format=1, 0
        FINISH
        DEF V_0047 PRINTREAL  type=0, routine, format=0, external-spec
        START
        DEF V_0048 F  long-real, simple, format=4, 0
        DEF V_0049 SF  integer, simple, format=1, 0
        DEF V_004a PLACES  integer, simple, format=1, 0
        FINISH
        DEF V_0048 PRINTFLOAT  type=0, routine, format=0, external-spec
        START
        DEF V_0049 F  long-real, simple, format=4, 0
        DEF V_004a SF  integer, simple, format=1, 0
        FINISH
        DEF V_0049 INTPT  integer, function, format=1, external-spec-indirect
        START
        DEF V_004a R  long-real, simple, format=4, 0
        FINISH
        DEF V_004a TOUPPER  type=0, routine, format=0, external-spec
        START
        DEF V_004b S  string, name, format=0, 0
        FINISH
        DEF V_004b TOLOWER  type=0, routine, format=0, external-spec
        START
        DEF V_004c S  string, name, format=0, 0
        FINISH
        DEF V_004c ITOS  string, function, format=255, external-spec-indirect
        START
        DEF V_004d N  integer, simple, format=1, 0
        DEF V_004e PLACES  integer, simple, format=1, 0
        FINISH
        DEF V_004d FTOS  string, function, format=255, external-spec-indirect
        START
        DEF V_004e F  long-real, simple, format=4, 0
        DEF V_004f SF  integer, simple, format=1, 0
        DEF V_0050 PLACES  integer, simple, format=1, 0
        FINISH
        DEF V_004e FTOSP  string, function, format=255, external-spec-indirect
        START
        DEF V_004f F  long-real, simple, format=4, 0
        DEF V_0050 PLACES  integer, simple, format=1, 0
        FINISH
        DEF V_004f READ  type=0, routine, format=0, external-spec
        START
        DEF V_0050 PTR  type=0, name, format=0, 0
        FINISH
        DEF V_0050 SUBSTRING  string, function, format=255, external-spec-indirect
        START
        DEF V_0051 S  string, simple, format=255, 0
        DEF V_0052 FROM  integer, simple, format=1, 0
        DEF V_0053 TO  integer, simple, format=1, 0
        FINISH
        DEF V_0051 TRIM  string, function, format=255, external-spec-indirect
        START
        DEF V_0052 S  string, simple, format=255, 0
        DEF V_0053 MAX  integer, simple, format=1, 0
        FINISH
        DEF V_0052 SETDEBUG  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0053 CLEARDEBUG  type=0, routine, format=0, external-spec
        START
        FINISH
        DEF V_0054 DEBUGMODE  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_0055 SHOWDEBUG  type=0, predicate, format=0, external-spec
        START
        FINISH
        DEF V_0056 SETDEBUGLEVEL  type=0, routine, format=0, external-spec
        START
        DEF V_0057 LVL  integer, simple, format=1, 0
        FINISH
        DEF V_0057 INT2ASCII  string, function, format=255, external-spec-indirect
        START
        DEF V_0058 NN  integer, simple, format=1, 0
        DEF V_0059 BASE  integer, simple, format=1, 0
        DEF V_005a PLACES  integer, simple, format=1, 0
        FINISH
        DEF V_0058 FORMATNUMBER  string, function, format=255, external-spec-indirect
        START
        DEF V_0059 N  integer, simple, format=1, 0
        DEF V_005a BASE  integer, simple, format=1, 0
        DEF V_005b PLACES  integer, simple, format=1, 0
        FINISH
        DEF V_0059 INT2HEX  string, function, format=255, external-spec-indirect
        START
        DEF V_005a NN  integer, simple, format=1, 0
        DEF V_005b PLACES  integer, simple, format=1, 0
        FINISH
        DEF V_005a INT2BIN  string, function, format=32, external-spec-indirect
        START
        DEF V_005b NN  integer, simple, format=1, 0
        FINISH
        DEF V_005b SHORT2BIN  string, function, format=16, external-spec-indirect
        START
        DEF V_005c NN  short-integer, simple, format=3, 0
        FINISH
        DEF V_005c GETENVCOUNT  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_005d GETENVNAME  string, function, format=255, external-spec-indirect
        START
        DEF V_005e INDEX  integer, simple, format=1, 0
        FINISH
        DEF V_005e GETENV  string, function, format=255, external-spec-indirect
        START
        DEF V_005f INDEX  integer, simple, format=1, 0
        FINISH
        DEF V_005f GETENVINDEX  integer, function, format=1, external-spec-indirect
        START
        DEF V_0060 VARNAME  string, simple, format=255, 0
        FINISH
        DEF V_0060 GETENVASSTRING  string, function, format=255, external-spec-indirect
        START
        DEF V_0061 ENVNAME  string, simple, format=255, 0
        FINISH
        DEF V_0061 GETENVASINTEGER  integer, function, format=1, external-spec-indirect
        START
        DEF V_0062 VARNAME  string, simple, format=255, 0
        FINISH
        DEF V_0062 GETARGCOUNT  integer, function, format=1, external-spec-indirect
        START
        FINISH
        DEF V_0063 GETARG  string, function, format=255, external-spec-indirect
        START
        DEF V_0064 INDEX  integer, simple, format=1, 0
        FINISH
        ALIAS "_imp_cliparam"
        DEF V_0064 CLIPARAM  string, function, format=255, external-spec-indirect
        START
        FINISH
        DEF V_0065 NEW  record, map, format=0, external-spec
        START
        DEF V_0066 TEMPLATE  type=0, name, format=0, 0
        FINISH
        DEF V_0066 DISPOSE  type=0, routine, format=0, external-spec
        START
        DEF V_0067 TEMPLATE  type=0, name, format=0, 0
        FINISH
        DEF V_0067 SQRT  long-real, function, format=4, external-spec-indirect
        START
        DEF V_0068 X  long-real, simple, format=4, 0
        FINISH
        DEF V_0068 PI  long-real, function, format=4, external-spec-indirect
        START
        FINISH
        DEF V_0069 SINE  long-real, function, format=4, external-spec-indirect
        START
        DEF V_006a X  long-real, simple, format=4, 0
        FINISH
        DEF V_006a COSINE  long-real, function, format=4, external-spec-indirect
        START
        DEF V_006b X  long-real, simple, format=4, 0
        FINISH
        DEF V_006b LOG2  long-real, function, format=4, external-spec-indirect
        START
        DEF V_006c X  long-real, simple, format=4, 0
        FINISH
        DEF V_006c LOG  long-real, function, format=4, external-spec-indirect
        START
        DEF V_006d X  long-real, simple, format=4, 0
        FINISH
        DEF V_006d LOG10  long-real, function, format=4, external-spec-indirect
        START
        DEF V_006e X  long-real, simple, format=4, 0
        FINISH
        DEF V_006e EXIT  type=0, routine, format=0, external-spec
        START
        DEF V_006f STATUS  integer, simple, format=1, 0
        FINISH
        LINE 55
     1  !
     2  ! The hand-generated code below should be producable by PSR's compiler if it:
     3  ! A) delays stores as late as possible
     4  !
     5  ! B) remembers registers over procedure calls
     6  !
     7  ! C) has a general algorithm for drop-through conditionally executed
     8  !    instructions, i.e. if there are no instructions between a conditional 
     9  !    branch and its destination which set the condition codes, and the
    10  !    sequence is less that a certain length, then all the instructions
    11  !    within the sequence can be made conditional.
    12  !
    13  ! D) does as above, but also allows instructions within the sequence
    14  !    whose subsequent execution depends on the same condition, e.g.
    15  !
    16  !    %if a=b %and c=d %then a=b
    17  !
    18  !    CmpS   R0,R1            NAIVE STYLE
    19  !    Bne    elsepart
    20  !    Cmps   R2,R3
    21  !    Bne    elsepart
    22  !    Mov    R0,R2
    23  !
    24  !    CmpS   R0,R1            RULE (C) ABOVE
    25  !    Bne    elsepart
    26  !    CmpS   R2,R3
    27  !    MovEQ  R0,R2
    28  !
    29  !    CmpS   R0,R1            RULE (D) SPECIAL CASE
    30  !    CmpSEQ R2,R3
    31  !    MovEQ  R0,R2
    32  !
    33  ! E) alters conditions to generate similar condition codes on
    34  !    condition AND condition AND condition to generate more cases
    35  !    to which rule (D) can be applied.
    36  !
    37  ! F) adjusts constants in < or <= cases to favour above, i.e. turning
    38  !    CMP R,#const & BLE ... into CMP R,#const-1 & BLT ... etc.
    39  !
    40  ! G) changes Newline back from the current implicit printsymbol(10) -
    41  !    there is no run-time overhead in moving the MOV R0,#10 over to
    42  !    the procedure body instead of having it in every call where it
    43  !    takes up space - after all, Peter's code-moving stuff ought to
    44  !    get %permroutine newline;printsymbol(10);%end correct - it will
    45  !    place the Mov R0,#10 before the body of %permroutine printsymbol
    46  !    and generate a suitable entry point for it...
    47  !       Personally, I would recommend stacking/restoring R0 as well
    48  !    as it might keep another variable in a register for a bit longer...
    49  !
    50  ! I've only suggested optimisations which fit into the style of PSR's
    51  ! compilers...
    52  !
    53  
    54  
    55  %begin
        BEGIN
        LINE 56
    56  %integer a,i,b
        DEF V_006f A  integer, simple, format=1, 0
        DEF V_0070 I  integer, simple, format=1, 0
        DEF V_0071 B  integer, simple, format=1, 0
        LINE 58
    57  
    58    read(a)
        PUSH V_004f
        PUSH V_006f
        ASSPAR
        CALL
        LINE 62
    59  ! BL     read_fn
    60  
    61  ! Str    R0,a
    62    read(i)
        PUSH V_004f
        PUSH V_0070
        ASSPAR
        CALL
        LINE 66
    63  ! BL     read_fn
    64  
    65  ! Str    R0,i
    66    read(b)
        PUSH V_004f
        PUSH V_0071
        ASSPAR
        CALL
        LINE 69
    67  ! BL     read_fn
    68  
    69    %if a <= i <= b %start
        PUSH V_006f
        PUSH V_0070
        JUMPIFD > L_0004
        PUSH V_0071
        JUMPIF > L_0004
        LINE 74
    70  ! Ldr R1,a
    71  ! Ldr R2,i
    72  ! CmpS   R1,R2
    73  ! CmpSLE R2,R0
    74      i = 22
        PUSH V_0070
        PUSHI #0x00000016
        ASSVAL
        LINE 76
    75  ! MovLE  R2,#22
    76    %finish
        LOCATE L_0004
        LINE 78
    77  
    78    %if 22 <= i <= b %start
        PUSHI #0x00000016
        PUSH V_0070
        JUMPIFD > L_0004
        PUSH V_0071
        JUMPIF > L_0004
        LINE 81
    79  ! CmpS   R2,#22-1
    80  ! CmpSGT R2,R0
    81      i = 44
        PUSH V_0070
        PUSHI #0x0000002c
        ASSVAL
        LINE 83
    82  ! MovGT  R2,#44
    83    %finish
        LOCATE L_0004
        LINE 85
    84  
    85    %if a <= i <= 77 %start
        PUSH V_006f
        PUSH V_0070
        JUMPIFD > L_0004
        PUSHI #0x0000004d
        JUMPIF > L_0004
        LINE 88
    86  ! CmpS   R1,R2
    87  ! CmpSLE R2,#77
    88      i = 99
        PUSH V_0070
        PUSHI #0x00000063
        ASSVAL
        LINE 90
    89  ! MovLE  R2,#99
    90    %finish
        LOCATE L_0004
        LINE 92
    91  
    92    %if 11 <= i <= 100 %start     ;! Peter's special case when both const is good
        PUSHI #0x0000000b
        PUSH V_0070
        JUMPIFD > L_0004
        PUSHI #0x00000064
        JUMPIF > L_0004
        LINE 95
    93  ! Sub   R2,#11                  ;! but usually corrupts a register needed later
    94  ! CmpS  R2,#100-11
    95      i = 1
        PUSH V_0070
        PUSHI #0x00000001
        ASSVAL
        LINE 97
    96  ! MovLS R2,#1
    97    %finish
        LOCATE L_0004
        LINE 100
    98  
    99  ! Str   R0,b
   100    write(a,0)
        PUSH V_0041
        PUSH V_006f
        ASSPAR
        PUSHI #0x00000000
        ASSPAR
        CALL
        LINE 105
   101  ! Mov   R0,R1
   102  ! Mov   R1,#0
   103  ! Bl    Write
   104  
   105    newline
        PUSH V_0044
        CALL
        LINE 109
   106  ! Bl    Newline
   107  
   108  ! Mov   R0,R2
   109    write(i,0)
        PUSH V_0041
        PUSH V_0070
        ASSPAR
        PUSHI #0x00000000
        ASSPAR
        CALL
        LINE 112
   110  ! Bl    write
   111  
   112    newline
        PUSH V_0044
        CALL
        LINE 115
   113  ! Bl    newline
   114  
   115    write(b,0)
        PUSH V_0041
        PUSH V_0071
        ASSPAR
        PUSHI #0x00000000
        ASSPAR
        CALL
        LINE 119
   116  ! Ldr   R0,b
   117  ! Bl    write
   118  
   119    newline
        PUSH V_0044
        CALL
        LINE 122
   120  ! Bl    newline
   121  
   122  %endofprogram
        END
        END
