         Edinburgh IMP77 Compiler - Version 8.4

    1  !!%CONTROL 0
    2  %BEGIN
    3  
    4  %routine newpage
    5    printsymbol('L'&31)
    6  %end
    7  
    8  %routine xreadsym(%integername sym)
    9    readsymbol(sym) ; printsymbol(sym)
   10  %end
   11  
   12  %routine readsymbol(%integername sym)
   13    xreadsym(sym)
   14  %end
   15  
   16  %routine xread(%integername num)
   17    read(num) ; write(num,0)
   18  %end
   19  
   20  %routine read(%integername num)
   21    xread(num)
   22  %end
   23  
   24  %INTEGERARRAY RMN,REG(0:15)
   25  %INTEGERARRAY IMN(1:31)
   26  %INTEGERARRAY LMN,LAD(1:20)
   27  %INTEGERARRAY R(1:4000)
   28  %INTEGERARRAY S(0:16383)
   29  %INTEGER LP,RP,SP,I,J,K,L,M,N,F,MR,TR,ST,CT
   30  %ROUTINESPEC READMN(%INTEGERNAME MN,NEXT)
   31  %ROUTINESPEC FAULT(%INTEGER I,J,K,L)
   32  %ROUTINESPEC OUT(%INTEGER I)
   33  %ROUTINESPEC DUMP
   34  %SWITCH INS(1:31)
   35  %SWITCH IOR(0:10)
   36  !!%EXTERNALROUTINESPEC DEFINE(%STRING(63) S)
   37       RMN(0)=M'BR0'  ;  RMN(1)=M'BR1'  ;  RMN(2)=M'BR2'
   38       RMN(3)=M'BR3'  ;  RMN(4)=M'BR4'  ;  RMN(5)=M'BR5'
   39       RMN(6)=M'BR6'  ;  RMN(7)=M'BR7'  ;  RMN(8)=M'BR8'
   40       RMN(9)=M'BR9'  ;  RMN(10)=M'BR10';  RMN(11)=M'BR11'
   41       RMN(12)=M'BR12';  RMN(13)=M'WK'  ;  RMN(14)=M'STP'
   42       RMN(15)=M'ACC'
   43       IMN(1)=M'LOAD' ;  IMN(2)=M'LDA'  ;  IMN(3)=M'ADD'
   44       IMN(4)=M'SUB'  ;  IMN(5)=M'MLT'  ;  IMN(6)=M'DIV'
   45       IMN(7)=M'EXP'  ;  IMN(8)=M'STR'  ;  IMN(9)=M'NEG'
   46       IMN(10)=M'NOT' ;  IMN(11)=M'SHL' ;  IMN(12)=M'SHR'
   47       IMN(13)=M'AND' ;  IMN(14)=M'OR'  ;  IMN(15)=M'XOR'
   48       IMN(16)=M'BAL' ;  IMN(17)=M'B'   ;  IMN(18)=M'BZ'
   49       IMN(19)=M'BNZ' ;  IMN(20)=M'BG'  ;  IMN(21)=M'BNG'
   50       IMN(22)=M'BL'  ;  IMN(23)=M'BNL' ;  IMN(24)=M'STOP'
   51       IMN(25)=M'ADDF';  IMN(26)=M'SUBF';  IMN(27)=M'MLTF'
   52       IMN(28)=M'DIVF';  IMN(29)=M'EXPF';  IMN(30)=M'NEGF'
   53       IMN(31)=M'FLT'
   54       LP=1
   55       RP=1
   56       SP=0
   57       F=0
   58       MR=0
   59       TR=0
   60  !!     DEFINE('STREAM01,SKIMPO')
   61       open input(1, "skimp77.asm")
   62       SELECT INPUT(1)
   63  !!L1:  READ SYMBOL(I)
   64  L1:  %begin
   65         %on %event 9 %start
   66           print string("End of file reading skimp77.asm, not while executing it..."); newline
   67           ! So what is supposed to signify end of the skimp assembly code?
   68           %stop
   69         %finish
   70         READ SYMBOL(I)
   71       %end
   72       %if i = ';' %then %start
   73         %cycle  ;! skip comments.  comments with a '.' in them were causing errors.
   74           read symbol(i)
   75         %repeat %until i = NL
   76         ->L1
   77       %finish
   78       %IF I='''' %THEN %START
   79  L10:    READ SYMBOL(I)
   80          %IF I\='''' %THEN ->L10
   81          ->L1 ; %FINISH
   82       %IF I\='.' %THEN ->L1
   83       READMN(I,J)
   84       %IF J=':' %THEN %START
   85          %IF LP=1 %THEN ->L2
   86          K=1
   87  L4:     %IF I=LMN(K) %THEN %START
   88             %IF LAD(K)>=0 %THEN FAULT(M'LABE',M'L SE',M'T TW',M'ICE ')
   89             ->L3 ; %FINISH
   90          K=K+1
   91          %IF K<LP %THEN ->L4
   92          %IF LP>20 %THEN %START
   93             FAULT(M'TOO ',M'MANY',M' LAB',M'ELS ')
   94             ->L25 ; %FINISH
   95  L2:     LMN(LP)=I
   96          K=LP
   97          LP=LP+1
   98  L3:     LAD(K)=SP
   99  L25:    %IF I=M'ST' %THEN %START
  100             ST=SP
  101             ->L18 ; %FINISH
  102          ->L1 ; %FINISH
  103       %IF J='=' %THEN %START
  104          READ(K)
  105          %IF K<0 %OR K>15 %THEN %START
  106             FAULT(M'EQUA',M'TE N',M'UMBE',M'R ? ')
  107             ->L1 ; %FINISH
  108          RMN(K)=I
  109          ->L1 ; %FINISH
  110       %IF I=M'REGS' %AND J=10 %THEN %START
  111          MR=MR!128
  112          ->L1 ; %FINISH
  113       %IF I=M'TON' %AND J=10 %THEN %START
  114          MR=MR!64
  115          ->L1 ; %FINISH
  116       %IF I=M'TOFF' %AND J=10 %THEN %START
  117          MR=MR!32
  118          ->L1 ; %FINISH
  119       %IF J\=',' %THEN FAULT(M'SYNT',M'AX ?',0,0)
  120       %IF I=0 %THEN %START
  121          READMN(I,J)
  122          %IF I\=0 %OR J\=',' %THEN FAULT(M'SYNT',M'AX ?',0,0)
  123          READMN(I,J)
  124          %IF I\=0 %OR J\=',' %THEN FAULT(M'SYNT',M'AX ?',0,0)
  125          %IF SP>=16384 %THEN %START
  126             FAULT(M'PROG',M'RAM ',M'TOO ',M'BIG ')
  127             %STOP ; %FINISH
  128          READ(S(SP))
  129          SP=SP+1
  130          MR=0
  131          ->L1 ; %FINISH
  132       K=1
  133  L6:  %IF I=IMN(K) %THEN ->L5
  134       K=K+1
  135       %IF K<=31 %THEN ->L6
  136       FAULT(M'INST',M'RUCT',M'ION ',M'?   ')
  137  L5:  READMN(I,J)
  138       %IF J\=',' %THEN FAULT(M'SYNT',M'AX ?',0,0)
  139       %IF I=0 %THEN L=0 %ELSE %START
  140          L=0
  141  L8:     %IF I=RMN(L) %THEN ->L7
  142          L=L+1
  143          %IF L<=15 %THEN ->L8
  144          FAULT(M'REGI',M'STER',M' ?  ',0)
  145          %FINISH
  146  L7:  K=K<<4!L
  147       READMN(I,J)
  148       %IF J='+' %THEN %START
  149          READ(M)
  150          %IF M>=65536 %THEN FAULT(M'DISP',M'. TO',M'O BI',M'G   ')
  151          %IF LP=1 %THEN ->L9
  152          L=1
  153  L12:    %IF I=LMN(L) %THEN %START
  154             %IF LAD(L)<0 %THEN ->L11
  155             K=K<<20!(LAD(L)+M)
  156             ->L13 ; %FINISH
  157          L=L+1
  158          %IF L<LP %THEN ->L12
  159          %IF LP>20 %THEN %START
  160             FAULT(M'TOO ',M'MANY',M' LAB',M'ELS ')
  161             ->L11 ; %FINISH
  162  L9:     LMN(LP)=I
  163          LAD(LP)=-1
  164          L=LP
  165          LP=LP+1
  166  L11:    %IF RP>4000 %THEN %START
  167             FAULT(M'TOO ',M'MANY',M' REL',M'OCS.')
  168             %STOP ; %FINISH
  169          R(RP)=L<<16!SP
  170          RP=RP+1
  171  L14:    K=K<<20!M
  172  L13:    %IF SP>=16384 %THEN %START
  173             FAULT(M'PROG',M'RAM ',M'TOO ',M'BIG ')
  174             %STOP ; %FINISH
  175          S(SP)=K!MR<<24
  176          SP=SP+1
  177          MR=0
  178          ->L1 ; %FINISH
  179       %IF ('A'<=J %AND J<='Z') %OR J=10 %THEN %START
  180          %IF I=M'READ' %AND J='S' %THEN %START
  181             M=16384
  182  L15:       READMN(I,J)
  183             %IF I\=M'YMBO' %OR J\='L' %THEN ->L26
  184             READ SYMBOL(I)
  185             %IF I\=10 %THEN ->L26
  186             ->L14 ; %FINISH
  187          %IF I=M'NEXT' %AND J='S' %THEN %START
  188             M=16385
  189             ->L15 ; %FINISH
  190          %IF I=M'SKIP' %AND J='S' %THEN %START
  191             M=16386
  192             ->L15 ; %FINISH
  193          %IF I=M'PRIN' %AND J='T' %THEN %START
  194             READ SYMBOL(I)
  195             %IF I\='S' %THEN ->L26
  196             M=16387
  197             ->L15 ; %FINISH
  198          %IF I=M'SPAC' %AND J='E' %THEN %START
  199             READMN(I,J)
  200             %IF I=0 %AND J=10 %THEN %START
  201                M=16388
  202                ->L14 ; %FINISH
  203             %IF I='S' %AND J=10 %THEN %START
  204                M=16389
  205                ->L14 ; %FINISH
  206             ->L26
  207             %FINISH
  208          %IF I=M'NEWL' %AND J='I' %THEN %START
  209             READMN(I,J)
  210             %IF I=M'NE' %AND J=10 %THEN %START
  211                M=16390
  212                ->L14 ; %FINISH
  213             %IF I=M'NES' %AND J=10 %THEN %START
  214                M=16391
  215                ->L14 ; %FINISH
  216             ->L26
  217             %FINISH
  218          %IF I=M'NEWP' %AND J='A' %THEN %START
  219             READMN(I,J)
  220             %IF I\=M'GE' %OR J\=10 %THEN ->L26
  221             M=16392
  222             ->L14 ; %FINISH
  223          %IF I=M'READ' %AND J=10 %THEN %START
  224             M=16393
  225             ->L14 ; %FINISH
  226          %IF I=M'WRIT' %AND J='E' %THEN %START
  227             READ SYMBOL(I)
  228             %IF I\=10 %THEN ->L26
  229             M=16394
  230             ->L14 ; %FINISH
  231  L26:    FAULT(M'I-O ',M'NAME',M' ?  ',0)
  232          ->L13
  233          %FINISH
  234       %IF J\=',' %THEN FAULT(M'SYNT',M'AX ?',0,0)
  235       %IF I=0 %THEN L=0 %ELSE %START
  236          L=0
  237  L17:    %IF I=RMN(L) %THEN ->L16
  238          L=L+1
  239          %IF L<=15 %THEN ->L17
  240          FAULT(M'BASE',M' REG',M'ISTE',M'R ? ')
  241          %FINISH
  242  L16: K=K<<4!L
  243       READ(M)
  244       %IF M>=65536 %THEN FAULT(M'DISP',M'. TO',M'O BI',M'G   ')
  245       K=K<<16!M
  246       ->L13
  247  L18: READ(I)
  248       %IF I\=0 %THEN %START
  249          NEWLINE
  250          OUT(M'PROG') ; OUT(M'RAM ') ; OUT(M'FAUL') ; OUT(M'TY !')
  251          NEWLINE
  252          %STOP ; %FINISH
  253  L38: READ SYMBOL(I)
  254       %IF I\='.' %THEN ->L38
  255       SELECT INPUT(0)
  256       I=ST
  257  L28: %IF I>16383 %THEN ->L29
  258       S(I)=999999
  259       I=I+1
  260       ->L28
  261  L29: NEWLINE
  262       OUT(M'LABE') ; OUT(M'LS  ')
  263       NEWLINE
  264       I=0
  265       J=1
  266  L20: OUT(LMN(J)) ; OUT(M'  : ')
  267       %IF LAD(J)<0 %THEN %START
  268          OUT(M'NOT ') ; OUT(M'SET ')
  269          I=1
  270          %FINISH %ELSE WRITE(LAD(J),1)
  271       NEWLINE
  272       %IF LMN(J)=M'CT' %THEN CT=LAD(J)
  273       J=J+1
  274       %IF J<LP %THEN ->L20
  275       %IF I\=0 %OR F\=0 %THEN %STOP
  276       %IF RP=1 %THEN ->L21
  277       M=1
  278  L22: I=R(M)>>16
  279       J=R(M)&65535
  280       K=S(J)&65535
  281       L=LAD(I)+K
  282       %IF L>=65536 %THEN %START
  283          OUT(M'ADDR') ; OUT(M' TRU') ; OUT(M'NCAT') ; OUT(M'ED  ')
  284          WRITE(J,1)
  285          NEWLINE
  286          L=L&65535
  287          %FINISH
  288       S(J)=S(J)>>16<<16!L
  289       M=M+1
  290       %IF M<RP %THEN ->L22
  291  L21: I=0
  292  L23: REG(I)=0
  293       I=I+1
  294       %IF I<=15 %THEN ->L23
  295       SP=0
  296  L24: %IF SP<0 %OR SP>=CT %THEN %START
  297          %IF SP>=16384 %AND SP<=16394 %THEN ->IOR(SP-16384)
  298          NEWLINE
  299          OUT(M'**  ')
  300          WRITE(SP,1)
  301          SPACES(4)
  302          OUT(M'INST') ; OUT(M'R AD') ; OUT(M'DR ?')
  303          %STOP ; %FINISH
  304       I=S(SP)
  305       J=I>>20&15
  306       K=I>>16&15
  307       L=I&65535
  308       %IF K=0 %THEN M=L %ELSE M=REG(K)+L
  309       I=I>>24
  310       %IF I>128 %THEN %START
  311          NEWLINE
  312          N=0
  313  L27:    OUT(RMN(N))
  314          OUT(M'  : ')
  315          WRITE(REG(N),1)
  316          NEWLINE
  317          N=N+1
  318          %IF N<=15 %THEN ->L27
  319          I=I-128
  320          %FINISH
  321       %IF I>64 %THEN %START
  322          TR=1
  323          I=I-64
  324          %FINISH
  325       %IF I>32 %THEN %START
  326          TR=0
  327          I=I-32
  328          %FINISH
  329       %IF X'3E00F9FA'>>I&1\=0 %AND (M<CT %OR M>=16384) %THEN %START
  330          NEWLINE
  331          OUT(M'**  ')
  332          WRITE(SP,1)
  333          SPACES(4)
  334          OUT(M'EFFE') ; OUT(M'CTIV') ; OUT(M'E AD') ; OUT(M'DR ?')
  335          WRITE(M,1)
  336          DUMP
  337          %STOP ; %FINISH
  338       %IF I=0 %THEN %START
  339          NEWLINE
  340          OUT(M'**  ')
  341          WRITE(SP,1)
  342          SPACES(4)
  343          OUT(M'INST') ; OUT(M'RUCT') ; OUT(M'ION?')
  344          DUMP
  345          %STOP ; %FINISH
  346       %IF TR#0 %THEN %START
  347          NEWLINE
  348          WRITE(SP,3)
  349          SPACES(2)
  350          OUT(IMN(I))
  351          SPACES(2)
  352          OUT(RMN(J))
  353          WRITE(M,4)
  354          SPACES(6)
  355          %FINISH
  356       ->INS(I)
  357  INS(1):! LOAD
  358       REG(J)=S(M)
  359       SP=SP+1
  360       ->L24
  361  INS(2):! LDA
  362       REG(J)=M
  363       SP=SP+1
  364       ->L24
  365  INS(3):! ADD
  366       REG(J)=REG(J)+S(M)
  367       SP=SP+1
  368       ->L24
  369  INS(4):! SUB
  370       REG(J)=REG(J)-S(M)
  371       SP=SP+1
  372       ->L24
  373  INS(5):! MLT
  374       REG(J)=REG(J)*S(M)
  375       SP=SP+1
  376       ->L24
  377  INS(6):! DIV
  378       REG(J)=REG(J)//S(M)
  379       SP=SP+1
  380       ->L24
  381  INS(7):! EXP
  382       REG(J)=REG(J)^^S(M)
  383  !!     REG(J)=REG(J)**S(M)
  384       SP=SP+1
  385       ->L24
  386  INS(8):! STR
  387       S(M)=REG(J)
  388       SP=SP+1
  389       ->L24
  390  INS(9):! NEG
  391       REG(J)=-REG(J)
  392       SP=SP+1
  393       ->L24
  394  INS(10):! NOT
  395       REG(J)=\REG(J)
  396       SP=SP+1
  397       ->L24
  398  INS(11):! SHL
  399       REG(J)=REG(J)<<S(M)
  400       SP=SP+1
  401       ->L24
  402  INS(12):! SHR
  403       REG(J)=REG(J)>>S(M)
  404       SP=SP+1
  405       ->L24
  406  INS(13):! AND
  407       REG(J)=REG(J)&S(M)
  408       SP=SP+1
  409       ->L24
  410  INS(14):! OR
  411       REG(J)=REG(J)!S(M)
  412       SP=SP+1
  413       ->L24
  414  INS(15):! XOR
  415       REG(J)=REG(J)!!S(M)
  416       SP=SP+1
  417       ->L24
  418  INS(16):! BAL
  419       REG(J)=SP+1
  420       SP=M
  421       ->L24
  422  INS(17):! B
  423       SP=M
  424       ->L24
  425  INS(18):! BZ
  426       %IF REG(J)=0 %THEN SP=M %ELSE SP=SP+1
  427       ->L24
  428  INS(19):! BNZ
  429       %IF REG(J)\=0 %THEN SP=M %ELSE SP=SP+1
  430       ->L24
  431  INS(20):! BG
  432       %IF REG(J)>0 %THEN SP=M %ELSE SP=SP+1
  433       ->L24
  434  INS(21):! BNG
  435       %IF REG(J)<=0 %THEN SP=M %ELSE SP=SP+1
  436       ->L24
  437  INS(22):! BL
  438       %IF REG(J)<0 %THEN SP=M %ELSE SP=SP+1
  439       ->L24
  440  INS(23):! BNL
  441       %IF REG(J)>=0 %THEN SP=M %ELSE SP=SP+1
  442       ->L24
  443  INS(24):! STOP
  444       NEWLINE
  445       OUT(M'STOP') ; OUT(M'PED ') ; OUT(M'AT  ')
  446       WRITE(SP,1)
  447       %STOP
  448  INS(25):! ADDF
  449       REAL(ADDR(REG(J)))=REAL(ADDR(REG(J)))+REAL(ADDR(S(M)))
  450       SP=SP+1
  451       ->L24
  452  INS(26):! SUBF
  453       REAL(ADDR(REG(J)))=REAL(ADDR(REG(J)))-REAL(ADDR(S(M)))
  454       SP=SP+1
  455       ->L24
  456  INS(27):! MLTF
  457       REAL(ADDR(REG(J)))=REAL(ADDR(REG(J)))*REAL(ADDR(S(M)))
  458       SP=SP+1
  459       ->L24
  460  INS(28):! DIVF
  461       REAL(ADDR(REG(J)))=REAL(ADDR(REG(J)))/REAL(ADDR(S(M)))
  462       SP=SP+1
  463       ->L24
  464  INS(29):! EXPF
  465       REAL(ADDR(REG(J)))=REAL(ADDR(REG(J)))^S(M)
  466  !!     REAL(ADDR(REG(J)))=REAL(ADDR(REG(J)))**S(M)
  467       SP=SP+1
  468       ->L24
  469  INS(30):! NEGF
  470       REAL(ADDR(REG(J)))=-REAL(ADDR(REG(J)))
  471       SP=SP+1
  472       ->L24
  473  INS(31):! FLT
  474       REAL(ADDR(REG(J)))=REG(J)
  475       SP=SP+1
  476       ->L24
  477  IOR(0):! READ SYMBOL
  478       READ SYMBOL(S(S(REG(14)+10)))
  479       SP=REG(13)
  480       ->L24
  481  IOR(1):! NEXT SYMBOL
  482       REG(15)=NEXT SYMBOL
  483       SP=REG(13)
  484       ->L24
  485  IOR(2):! SKIP SYMBOL
  486       SKIP SYMBOL
  487       SP=REG(13)
  488       ->L24
  489  IOR(3):! PRINT SYMBOL
  490       PRINT SYMBOL(S(REG(14)+10))
  491       SP=REG(13)
  492       ->L24
  493  IOR(4):! SPACE
  494       SPACE
  495       SP=REG(13)
  496       ->L24
  497  IOR(5):! SPACES
  498       SPACES(S(REG(14)+10))
  499       SP=REG(13)
  500       ->L24
  501  IOR(6):! NEWLINE
  502       NEWLINE
  503       SP=REG(13)
  504       ->L24
  505  IOR(7):! NEWLINES
  506       NEWLINES(S(REG(14)+10))
  507       SP=REG(13)
  508       ->L24
  509  IOR(8):! NEWPAGE
  510       NEWPAGE
  511       SP=REG(13)
  512       ->L24
  513  IOR(9):! READ
  514       READ(S(S(REG(14)+10)))
  515       SP=REG(13)
  516       ->L24
  517  IOR(10):! WRITE
  518       WRITE(S(REG(14)+10),S(REG(14)+11))
  519       SP=REG(13)
  520       ->L24
  521  %ROUTINE READMN(%INTEGERNAME MN,NEXT)
  522  %INTEGER I,J,K
  523  L1:  READ SYMBOL(I)
  524       %IF I=' ' %THEN ->L1
  525       %IF I<'A' %OR I>'Z' %THEN %START
  526          MN=0
  527          NEXT=I
  528          %RETURN ; %FINISH
  529       J=1
  530  L2:  READ SYMBOL(K)
  531       %IF J=4 %OR K<'0' %OR (K>'9' %AND K<'A') %OR K>'Z' %THEN %START
  532          MN=I
  533          NEXT=K
  534          %RETURN ; %FINISH
  535       I=I<<8!K
  536       J=J+1
  537       ->L2
  538  %END
  539  %ROUTINE FAULT(%INTEGER I,J,K,L)
  540       OUT(M'*** ')
  541       WRITE(SP,4)
  542       SPACES(6)
  543       OUT(I)
  544       OUT(J)
  545       OUT(K)
  546       OUT(L)
  547       NEWLINE
  548       F=F+1
  549  %END
  550  %ROUTINE OUT(%INTEGER I)
  551       PRINT SYMBOL(I>>24) %if I>>24 # 0
  552       PRINT SYMBOL(I>>16&255) %if I>>16&255 # 0
  553       PRINT SYMBOL(I>>8&255) %if I>>8&255 # 0
  554       PRINT SYMBOL(I&255) %if I&255 # 0
  555  %END
  556  %ROUTINE DUMP
  557  %INTEGER I,J
  558       NEWLINE
  559       I=0
  560  L1:  OUT(RMN(I))
  561       OUT(M'  : ')
  562       WRITE(REG(I),1)
  563       NEWLINE
  564       I=I+1
  565       %IF I<=15 %THEN ->L1
  566       %IF REG(14)<ST %THEN %START
  567          OUT(M'STP<')
  568          OUT(M'ST: ')
  569          NEWLINE
  570          %RETURN ; %FINISH
  571       I=ST
  572       J=0
  573  L2:  %IF J=0 %THEN %START
  574          NEWLINE
  575          WRITE(I,5)
  576          SPACES(4)
  577          %FINISH
  578       WRITE(S(I),6)
  579       I=I+1
  580       J=J+1
  581       %IF J=8 %THEN J=0
  582       %IF I<=REG(14) %THEN ->L2
  583  %END
  584  %ENDOFPROGRAM

  615 Statements compiled
