
    Alick Glennie Autocode compiler 

    Rewriten by Roberto Sancho Apr/2023 
    using doc on compiler form original author
            
    https://archiveshub.jisc.ac.uk/data/gb133-muc/5-9/muc/9/14

      (a) Photocopy of a 16-page typewritten manual describing 
          Glennies AUTOCODE routine. (Probably a draft for a 
          manual to be entitled The Routine AUTOCODE and its use).   

      (b) Photocopy of 14 pages of Glennies lecture notes on 
          The automatic coding of an electronic computer dated 
          14th December 1952.


    [Col /          E ]                 [Col @          A ]              
                                                                          
    | $$$$ | / | XAYG |                 | L//P | / | EAQO |                                         
    | $$$$ | E | @E/T |                 | //// | E | Q$$$ |               
    | TA/P | @ | #E$$ |                 | $/// | @ | AA/P |                                        
    | DST/ | A | $$$$ |                 |      | A | Y@$$ |                                        
    | MD/S | : | //O: |                 | BIYO | : |      |                                        
    | VD/S | S | V:/C |                 | A:YG | S | S:QO |                                        
    | DSQO | I | TI/N |                 | L//T | I | AA/P |                                        
    | XIQB | U | ://J |                 | DSYG | U |      |               
    | //O: | # | TI/A |                 | A:/O | # | #AQO |                                        
    | TI/A | D | /KUP |                 | LIQB | D | QS/P |                                        
    | LI/A | R |      |                 | E:/Q | R | IC/V |                                        
    | HI/A | J | E:YO |                 | WIQB | J |      |               
    | PI/A | N | OIYG |                 | BIYO | N | NAQO |               
    | OI/A | F | CE/T |                 | DSYG | F | QS/P |               
    | GI/A | C | U/$$ |                 | BIYB | C | #C/V |               
    | $$$$ | K | KEQO |                 | L//P | K | EA@: | load perm mag instr
    | $$$$ | T | QS/P |                 |      | T | KA/: |               
    | $$$$ | Z | /C/V |                 | OIYO | Z | TA$$ |               
    | L/$$ | L |      |                 | A:YG | L | MAQO |               
    | TSO: | W | /KUC |                 | L//T | W | WAO: |               
    | W//: | H | //O: |                 | Y@QO | H | RIUS |               
    | ://A | Y | Y:/N |                 | P$$$ | Y | A:QG |               
    | ://C | P | E@TR |                 | PIQB | P | WA/T |                                    
    | J:/N | Q | ///S |                 | L//P | Q | "AZO |                                    
    | ///A | O | E/QO |                 |      | O | GA/: |                                    
    | //QO | B | E:YO |                 | OIYO | B | "A/P |                                    
    | //T/ | G | BIYG |                 | A:YG | G | R/EC | load INPUT.9 mag instr
    | VATN | " | ME/T |                 | E:YG | " | @/I/ | initial value of B1
    | L//H | M | VE$$ |                 | L//T | M | HI// | const 212
    | OIYO | X | YIQB |                 | DSYG | X | D/// |               
    | DSYG | V | L//P |                 | $@/T | V | $/// |               
    | OIYB | $ | HIQB |                 | :A$$ | $ | //// |               
                                                                      
       
    [End]


Memory map during compilation

             S0 S1   S2    S3    S4 S5    S6 S7
             /E @A   :S    IU    #D RJ    NF CK
             INPUT1  PERM  VARS  GENCODE  INPUT9

vars for Loop repeat to address 

    [RI] loop address for index 2 
    [JI] index 3
    [NI] index 4 
    [FI] index 5 
    [CI] index 6 
    [KI] index 7 

vars when parsing a sentence

    [TI, ZI] cmd - command read so far    
    [LI] var0
    [WI] var1
    [HI] index0
    [YI] index1
    [PI] OP operation to assemble
    [QI] FUNC to assemble
    [OI] nchars - number of chars read from sentence (0..)
    [BI] nvars - number of vars present in sentence (0,1,2)
    [GI] Label - the label param of command
    ["I] 

vars for routine

    [MI] Use AM in arth: 0=use AL, 1=use AM
    [XI] Clear acc flag: 0=no clear acc, -1=clear acc before use
    [VI] sgen - next pos free in routine for generated instr
    [$I]

colum [/U] var addr
colum [/N] label addresses
    

  
                 read new routine - init all - start autocode compiler

    0  //  $$$$
    1  E/  $$$$
    2  @/  TA/P  goto init and clear mem
    3  A/  DST/  AL=$$$$ $$$$
    4  :/  MD/S  [MD, XD]=AL  set end of S4 as no-op
    5  S/  VD/S  [VD, $D]=AL
    6  I/  DSQO  B7=-1
    7  U/  XIQB  [XI]=-1 -> Clear acc flag: -1=clear acc before use

                 read a sentence

    8  #/  //O:  Clear Acc
    9  D/  TI/A  [TI, ZI]=0 -> clear cmd - command read so far
   10  R/  LI/A  clear all the vars
   11  J/  HI/A
   12  N/  PI/A
   13  F/  OI/A
   14  C/  GI/A
   15  K/  $$$$
   16  T/  $$$$
   17  Z/  $$$$
   18  L/  L/$$  cn goto read a ch

                 read a ch - read and process next char from sentence

   19  W/  TSO:  clear acc
   20  H/  W//:  read PTR char
   21  Y/  ://A  [:/ S/]=AM -> Save char //// ///c, AM=0
   22  P/  ://C  D=//// ///c char read
   23  Q/  J:/N  shift -> AL=0, AM=c/// ////
   24  O/  ///A  [// E/]=AM=c/// ////, AM=0
   25  B/  //QO  B7=c read char 0..31

                 check if $ char, if so go back to read ch
 
   26  G/  //T/  AL=c/// ////, AM=0
   27  "/  VATN  AL=AL-$/// ////
   28  M/  L//H  if (A>=0) goto 19 -> read ch was $ -> ignore char -> read again

                 incr count of read chars, check if cmd is full

   29  X/  OIYO  B5=[OI] nchars - number of chars read from sentence (0..) 
   30  V/  DSYG  incr B5                                                   
   31  $/  OIYB  [OI]=B5 -> save nchars. It has been incremented                    
   32  /E  XAYG  B5=B5-9
   33  EE  @E/T  if (B>=0) goto 41 -> if (nchars >= 8) cmd is full, do not append ch to it
   34  @E  #E$$  cn goto 41
   35  AE  $$$$

                 cmd not full, so append ch to cmd

   36  :E  //O:  Acc=0
   37  SE  V:/C  shift [TI, ZI] = abcd efgh = cmd - command read so far (ch not appended to it yet)
   38  IE  TI/N  to AM = bcde fgh/      
   39  UE  ://J  AM=AM+//// ///C -> char has beed appended to cmd on the right side
   40  #E  TI/A  [TI, ZI]=AM, AM=0 -> save cmd

                 process the char

   41  DE  /KUP  goto [B7+ /K] char jump table
                 on entry: [// E/]=c/// ////, B7=c///            
                   if / -> goto 43 -> separator
                   if KLNOQR -> goto 50 -> index
                   if :#ABCDEFGHIJ STUVWXYZ -> goto 68 -> var
                   if P -> goto 81 -> plus
                   if M -> goto 89 -> minus
                   if " -> goto 104 -> assign
                   if @ -> goto 108 -> define var addr

   42  RE  

                 Separator

   43  JE  E:YO  B5=1
   44  NE  OIYG  B5=B5-[OI] nchars - number of chars read from sentence
   45  FE  CE/T  if (B>=0) goto 8 -> if (nchars <= 1 -> the only read char is this "/" -> it is a leading "/" -> skip it
   46  CE  U/$$  cn goto 8           this goto to read a full sentence again

                 sentence terminator /
                 goto set op to set the operation OP the sentence perform

   47  KE  KEQO  B7=*  
   48  TE  QS/P  transfer to adroutine
   49  ZE  /C/V  cue to INPUT.2 (set op)
   50  LE  

                 index

   51  WE  /KUC  D=[/K + B7] -> get the flags for index
   52  HE  //O:  clear acc
   53  YE  Y:/N  shift. Now AL=xxxx ixxx  where i=index num 1..6
   54  PE  E@TR  AL=AL AND //// $/// 
   55  QE  ///S  [// E/]=//// i/// save in temp
   56  OE  E/QO  B7=index 1..6
   57  BE  E:YO  B5=1
   58  GE  BIYG  B5=B5-[BI] nvars - number of vars present in sentence (0,1,2)
   59  "E  ME/T  if (B>=0) goto 63 -> if (nvars <= 1 -> is index0 for var0
   60  ME  VE$$  cn goto 63
   61  XE  YIQB  [index1]=B7 the second index used in sentence
   62  VE  L//P  goto 19 read_ch                              
   63  $E  HIQB  [index0]=B7 the first index used in sentence
   64  /@  L//P  goto 19 read_ch       
   65  E@  ////  const
   66  @@  $///  const
   67  A@   

                 vars

   68  :@  BIYO  B5=[BI] nvars - number of vars present in sentence (0,1,2)
   69  S@  A:YG  B5=B5-2
   70  I@  L//T  if (B>=0) goto 19 -> if (nvars >= 2) goto read_ch because vars 0,1 already scanned
   71  U@  DSYG  B5=B5+1
   72  #@  A:/O  if (B>=0) skip 2 instr -> if (nvars = 1) goto set var1
   73  D@  LIQB  Set var0 [LI] = B7 = the var ch
   74  R@  E:/Q  skip next instr
   75  J@  WIQB  Set var1 [WI] = B7 = the var ch
   76  N@  BIYO  B5=[BI] nvars 
   77  F@  DSYG  B5=B5+1
   78  C@  BIYB  nvars = B5 -> nvars has been incremented
   79  K@  L//P  goto 19 read_ch       
   80  T@   

                 plus  

   81  Z@  OIYO  B5=[OI] nchars - number of chars read from sentence
   82  L@  A:YG  B5=B5-2
   83  W@  L//T  if (B>=0) goto 19 -> if (nchars >= 2) goto read_ch because not the first char of sentence. so interpreted as a letter

                 SENTENCE +expr (OP=-10)
 
   84  H@  Y@QO  B7=-10
   85  Y@  P$$$  const -10

                 set sentence OP then goto read_ch 

   86  P@  PIQB  [PI] OP operation to assemble = B7
   87  Q@  L//P  goto 19 read_ch       
   88  O@   

                 minus

   89  B@  OIYO  B5=[OI] nchars - number of chars read from sentence
   90  G@  A:YG  B5=B5-2
   91  "@  E:YG  B5=B5-1
   92  M@  L//T  if (B>=0) goto 19 -> if (nchars >= 3) goto read_ch because not the first/second char of sentence. so interpreted as a letter
   93  X@  DSYG  B5=B5+1
   94  V@  $@/T  if (B>=0) goto 101 -> if (nchars = 2) goto decr index sentence
   95  $@  :A$$  cn goto 101

                 SENTENCE -expr (OP=-9)

   96  /A  EAQO  B7=-9
   97  EA  Q$$$  const -9
   98  @A  AA/P  goto 86
   99  AA  Y@$$  cn goto 86
  100  :A   

                 SENTENCE r-a  (decrement index, OP=4)

  101  SA  S:QO  B7=4
  102  IA  AA/P  goto 86
  103  UA   

                 assign

  104  #A  #AQO  B7=*  
  105  DA  QS/P  transfer to adroutine
  106  RA  IC/V  cue to INPUT.2 (assign)
  107  JA   

                 define var addr

  108  NA  NAQO  B7=*  
  109  FA  QS/P  transfer to adroutine
  110  CA  #C/V  cue to INPUT.2 (define)
  111  KA  const  

                 Init Autocode compiler
                 load perm, INPUT.9
                 clears mem

  112  TA  KA/:  Mag Instr Load PERM from track 97 to tubes S2 S3
  113  ZA  $$$$  
  114  LA  MAQO  B7=212             \ clear mem address RI..$N   
  115  WA  WAO:  clear acc          !                            
  116  HA  RIUS  [RI+B7]=AL         !                            
  117  YA  A:QG  B7=B7-2            !                            
  118  PA  WA/T  if (B>=0) goto 115 /                            
  119  QA  "AZO  Init RCS/B Stack pointer to B1=@/I/             
  120  OA  GA/:  Mag Instr Load INPUT.9 from track 12 to tubes S6 S7
  121  BA  "A/P  goto 3
  122  GA  const
  123  "A  
  124  MA  
  125  XA  
  126  VA  
  127  $A  
