(all PDP-8 blog entries can be seen by clicking here)
Since I figured out how to assemble PDP-8 PAL assembly language, I figured I should try to compile a FORTRAN program.
The PDP-8 has two FORTRAN compilers: FORTRAN II and FORTRAN IV. FORTRAN II is particularly primitive. In my second job, I some times had to translate FORTRAN II code to COBOL and detested FORTRAN II – mainly because the IF test was so cryptic.
The FORTRAN II if statement is in the form
IF (expression) label1, label2, label3
The is evaluated. If < 0, it branches to label1. If = 0, it branches to label2. If > 0, it branches to label3. Ugh.
FORTRAN IV has a proper IF statement so that is the FORTRAN I want to use.
And, of course, insisting on using FORTRAN IV created a headache. The initial disk image I have been using (which doesn’t have a working BASIC) also doesn’t have a working FORTRAN IV compiler.
If you attempt to compile a program in FORTRAN IV, I get the error ‘SY’ which indicates one of the additional programs (PASS2, PASS2O, or RALF) are missing or there isn’t enough memory. I know I have the programs, and SIMH provides the maximum possible memory (32K), so the problem would appear to be the compiler.
After doing a lot of searching I found an image that has a working FORTRAN IV compiler (I found the same SY error on several of the other OS/8 images). The working image can be found at
To copy the necessary files, I did the following:
PDP-8 simulator V3.9-0 Type 'boot rk0' to begin and 'control-e' to return to SIMH prompt sim> attach rk0 rk0.dsk #this is my primary drive sim> attach rk1 f2.rk0 #this is the image downloaded above sim> boot rk0 .ASSIGN RKA0: C .ASSIGN RKA1: A .COPY C:
Now let’s create a ‘Hello World!’ program in FORTRAN:
.CREATE HELLO.FT #A WRITE(4,10) 10 FORMAT(' HELLO WORLD!'); END <ctl-G to exit Add mode> #L WRITE(4,10) 10 FORMAT(' HELLO WORLD!'); END #E
To compile this, you must manually run the compiler and loader. I tried various combinations of using the COMPILE and LOAD commands and never got them to work.
To compile and load:
.R F4 *HELLO
and, finally to run the program:
.EXE HELLO.LD HELLO WORLD! .
Apr 2016 Update:
Based on some comments, I need to make a few additional comments.
Though I swear I had the F4 compiler working as above, others have had problems getting it to run using that syntax, and now I have the same issue.
Looking at the Fortran IV manual it appears the proper way to compile, link, load&save is to use the syntax:
.R F4 *PROG,PROG,PROG<PROG
Further, a short cut that will compile, link, load, save, and execute is to type:
.R F4 *PROG/G$
where the ‘$’ is actually the escape key.
The manual referenced above appears to match the compiler properly and is quite useful for trying to make sense of the cryptic compile errors you might get (like ‘MK 4’).