Sign in Join

Live chat for Free Pascal, Lazarus, Delphi and every Pascal programmer.

Catalog · How the catalog works

Random project

pasauto-re

View on GitHub

Anyone may press Interesting, signed in or not. It helps others find this project.

Member rating

No ratings yet.

Sign in to rate this project.

README

Decompiling the Pascal-Autocode compiler (the first Pascal compiler for the BESM-6).

The work on the compiler started in February of 1975, and a beta version released in early 1976. The presented version, with major number 9, is dated May 17, 1988. There is a newer minor fix, dated December 9, 1988 (the differences are trivial).

The BESM-6 Pascal system operated in an interactive environment, allowing to compile and execute a Pascal program with a single CLI command.

The compiler is called as an overlay by the helper program and compiles to an "autocode" language which used Cyrillic mnemonics for opcodes and used neither spaces nor newlines as separators. The lack of newlines allowed to form the assembly code in the standard output file without a single call to writeln, causing the runtime system to buffer everything on a magnetic drum.

The assembler is then called, to which the contents of the drum are given as input. It produces an executable binary in memory. The helper program either jumps to it (by default), or saves it to a file, if requested.

There was no need for a (static) linker: the runtime library was loaded into a predefined location, and the compiler spewed a list of equivalences which had to be in sync with the library. There was a mechanism to declare external subroutines and to dynamically load overlays containing those subroutines.

The overall format of the autocode instruction is {optional octal index}{two-letter opcode}{optional octal or mnemonic offset}{separator}, where {separator} is a comma to separate instruction words, or an equal sign to separate the two instructions in a word.

Here is an example of a small program and its assembly listing:

pascal
           ?????????????? ?????????????? ???????????? 1.7.76
         1. (*=Р-,Т-,L+*)_??R??GR???? ??RI????S;
         2. _????NS?? ??RI????LI??I?? = 1023;
         3.
         4. _V??R
         5.  ??RI????S: _??RR???? [2..??RI????LI??I??] _??F ??????L????N;
         6.  N, ??, WID????, ????S: IN????G??R;
         7.
         8. _????GIN
         9.  (* САLСULАТЕ ТНЕ РRIМЕS *)
        10.   _F??R N := 2 _???? ??RI????LI??I?? _D?? ??RI????S[N] := ??RU??;
        11.   _F??R N := 2 _???? ??RUN??(SQR??(??RI????LI??I??)) _D?? _????GIN
        12.     _IF ??RI????S[N] _??????N _????GIN
        13.       ?? := SQR(N);
        14.       _W??IL?? ?? <= ??RI????LI??I?? _D?? _????GIN
        15.         ??RI????S[??] := F??LS??;
        16.         ?? := ?? + N
        17.        _??ND
        18.      _??ND
        19.   _??ND;
        20.
        21.   (* ОUТРUТ ТНЕ РRIМЕS *)
        22.   ????S := 1;
        23.   _F??R N := 2 _???? ??RI????LI??I?? _D??
        24.    _IF ??RI????S[N] _??????N _????GIN
        25.       WID???? := ??RUN??(LN(N)/LN(10)+1)+1;
        26.       ????S := ????S + WID????;
        27.       WRI????(N:WID????);
        28.       _IF ????S > 120 _??????N _????GIN
        29.          WRI????LN; ????S := 1;
        30.      _??ND
        31.    _??ND;
        32.    _IF ????S <> 1 _??????N WRI????LN
        33. _??ND.
        34.
 ??????????????-?????????????? 9.(17.05.88)
________________________________________________________________________________________________________________________________
                ??????????????  00.00.70. ????????           N 000001 ???????? 000000

??;????=0021,????????=77040,L????D,UNL????D,????,??=12,LI=4,????=74000,????????=????(3),
  Z0=????????(2),??????15,??F,??,??,??,????=??(5),SL=????(2),Z64,??R=SL(10),????D=??R(3),
  VR,??????,??????,RF=VR(5),????1,????=RF(5),R??=????(6),????=R??(4),????,????,RWF,????????=????(5),
  WS,W??,W??,W??,WI,WR,WL,??WS,??W??,??W??,??W??,??WI,??WR,??WL,????=??WL(2),????,
  ????,????=74136,??R=74141,D=74145,N=74151,????=74173,R=74202,??L=74206,
  GI=74222,RI=74251,????=74257,R??=74313,??I=74323,UN=74337,??F=74715,
  GF=74760,??L=75075,????=75104,??????=75115,??NL=75165,??V=75241,I??=75361,
  ??I=75363,????=75365,??=75675,RSR=75714,
   ??;           ????,
   ??;      ????:  14 ????   Z1=             ,                     ??RI????S                             00021  14 31 00103 00 000 0000
                17 ????   ????=                ????   15,                                              00022  17 25 02014 00 010 0015
                 1 ????   2010=           ,                                                        00023  01 000 2010 00 000 0000
           ??2:   1 ????   2010=              ????   14,                                              00024  01 010 2010 00 006 0014
                   ??1   ??3=                ????   13,                                              00025  00 27 00031 00 010 0013
                 1 ????   2010=            1 ????   10,                                              00026  01 23 02010 01 000 0010
                 1 ????   2010=              ????   13,                                              00027  01 010 2010 00 004 0013
                 1 ????   2010=              ????   ??2,                                              00030  01 000 2010 00 30 00024
           ??3:     ????   15=              1 ????   2010,                                            00031  00 010 0015 01 000 2010
           ??4:     ????   14=             16 ????   R,                                               00032  00 010 0014 16 31 74202
                   ??050 =               ,                                                        00033  00 050 0000 00 000 0000
                16 ????   ??R=             ,                                                        00034  16 31 74141 00 000 0000
                 1 ????   2010=           17 ????   ,                                                00035  01 003 2010 17 006 0000
                   ??1   ??5=              1 ????   2010,                                            00036  00 27 00053 01 23 02010
                 1 ????   10=                ??0   ??6,                                              00037  01 010 0010 00 26 00051
                 1 ????   2010=           17 ????   ,                                                00040  01 010 2010 17 000 0000
                   ????   Z64=            17 ????   ,                                                00041  00 115 4022 17 017 0000
                16 ????   ????=             ,                                                        00042  16 31 74136 00 000 0000
                 1 ????   2011=           ,                                                        00043  01 000 2011 00 000 0000
           ??7:   1 ????   2011=              ????   14,                                              00044  01 010 2011 00 006 0014
                   ??1   ??10=               ????   12,                                              00045  00 27 00051 00 010 0012
                 1 ????   2011=            1 ????   10,                                              00046  01 23 02011 01 000 0010
                 1 ????   2011=            1 ????   2010,                                            00047  01 010 2011 01 004 2010
                 1 ????   2011=              ????   ??7,                                              00050  01 000 2011 00 30 00044
          ??10:
           ??6:   1 ????   2010=              ????   13,                                              00051  01 010 2010 00 004 0013
                 1 ????   2010=              ????   ??4,                                              00052  01 000 2010 00 30 00032
           ??5:     ????   13=              1 ????   2013,                                            00053  00 010 0013 01 000 2013
                   ????   15=              1 ????   2010,                                            00054  00 010 0015 01 000 2010
          ??11:   1 ????   2010=              ????   14,                                              00055  01 010 2010 00 006 0014
                   ??1   ??12=             1 ????   2010,                                            00056  00 27 00100 01 23 02010
                 1 ????   10=                ??0   ??13,                                             00057  01 010 0010 00 26 00076
                   ????   16=             16 ????   R,                                               00060  00 010 0016 16 31 74202
                   ??050 5=              ,                                                        00061  00 050 0005 00 000 0000
                 1 ????   2010=           16 ????   R,                                               00062  01 003 2010 16 31 74202
                   ??050 5=              ,                                                        00063  00 050 0005 00 000 0000
                17 ????   =                  ????   17,                                              00064  17 016 0000 00 004 0017
                16 ????   ??R=             ,                                                        00065  16 31 74141 00 000 0000
                   ????   13=              1 ????   2012,                                            00066  00 004 0013 01 000 2012
                 1 ????   2013=            1 ????   2012,                                            00067  01 010 2013 01 004 2012
                 1 ????   2013=            1 ????   2012,                                            00070  01 000 2013 01 010 2012
                17 ????   =                1 ????   2010,                                            00071  17 000 0000 01 010 2010
                16 ????   ??WI=            ,                                                        00072  16 31 74104 00 000 0000
                 1 ????   2013=              ????   20,                                              00073  01 010 2013 00 006 0020
                   ??0   ??14=            16 ????   ??R,                                              00074  00 26 00076 16 31 74031
                   ????   13=              1 ????   2013,                                            00075  00 010 0013 01 000 2013
          ??14:
          ??13:   1 ????   2010=              ????   13,                                              00076  01 010 2010 00 004 0013
                 1 ????   2010=              ????   ??11,                                             00077  01 000 2010 00 30 00055
          ??12:   1 ????   2013=              ????   13,                                              00100  01 010 2013 00 012 0013
                   ??0   ??15=            16 ????   ??R,                                              00101  00 26 00102 16 31 74031
          ??15:     ????   ??=              ,                                                        00102  00 30 74012 00 000 0000
   ??;           ??1,
   ??;      Z1:     ????   3=                 ????   5,                                               00103  00 037 0003 00 010 0005
                   ????   1=               1 ????   17,                                              00104  00 040 0001 01 044 0017
________________________________________________________________________________________________________________________________
                ??????????????  00.00.70. ????????           N 000001 ???????? 000001

                 1 ????   13=             15 ????   RI,                                              00105  01 044 0013 15 31 74251
                   ????   =                1 ????   LI,                                              00106  00 010 0000 01 000 0004
                14 ????   16=                ????   R??,                                              00107  14 044 0016 00 30 74313
            ??:
   ??;           11,
   ??;           64000,                                                                           00011  00 000 0000 00 006 4000
                0,                                                                               00012  00 000 0000 00 000 0000
                1,                                                                               00013  00 000 0000 00 000 0001
                1777,                                                                            00014  00 000 0000 00 000 1777
                2,                                                                               00015  00 000 0000 00 000 0002
                12,                                                                              00016  00 000 0000 00 000 0012
                4050000000000000,                                                                00017  10 050 0000 00 000 0000
                170,                                                                             00020  00 000 0000 00 000 0170
   ??;           1,
   ??;           1404350213022510,                                                                00001  03 004 3502 02 30 22510
                0040400001201001,                                                                00002  00 040 4000 00 120 1001
   ??;           5,
   ??;           ????,                                                                              00005  00 000 0000 00 000 0110
   ??;           7,
   ??;           10 ????   ????????=              ????   =                                                00007  10 31 74003 00 22 00000
                10 ????   -10=            10 ????   ????,                                              00010  10 25 77770 10 30 00021
   ??;      ????:2014,
   ??;
   ??;           66005,
??;
________________________________________________________________________________________________________________________________
                ??????????????  00.00.70. ????????           N 000001 ???????? 000001

 2 3 5 7 11 13 17 19 23 29 31 37 41 43 47 53 59 61 67 71 73 79 83 89 97 101 103 107 109 113 127 131 137 139 149 151 157 163
 167 173 179 181 191 193 197 199 211 223 227 229 233 239 241 251 257 263 269 271 277 281 283 293 307 311 313 317 331 337
 347 349 353 359 367 373 379 383 389 397 401 409 419 421 431 433 439 443 449 457 461 463 467 479 487 491 499 503 509 521
 523 541 547 557 563 569 571 577 587 593 599 601 607 613 617 619 631 641 643 647 653 659 661 673 677 683 691 701 709 719
 727 733 739 743 751 757 761 769 773 787 797 809 811 821 823 827 829 839 853 857 859 863 877 881 883 887 907 911 919 929
 937 941 947 953 967 971 977 983 991 997 1009 1013 1019 1021
?????? ??????????????.

(Legend: СЧ = "load" (СМ = "stack push and load") , ЗЧ = "store", ИК provides an indirect address for the next instruction, У0/У1 are "branch if zero/nonzero", АС, ОВ, АУ, АД are ADD, SUB (negated), MUL and DIV respectively, ПВ = call, ПБ = jump, СА modifies an index register, Э050 is an "extracode" for transcendental functions.

The implementation was somewhat incomplete, but with some extensions for low-level programming. Packed arrays and structures were not implemented; explicit bit field selection and insertion intrinsics (SEL and INS) have been provided instead.