(all PDP-8 blog entries can be seen by clicking here)
Today’s objective is to write, assemble, and run an extremely easy PAL8 (PDP-8’s assembly language) program.
First, let me enumerate some resources necessary to make this happen.
- If you haven’t already you must create the PDP-8 simulation and get it to boot from the OS/8 operating system. I’ve covered that topic in the past.
- This website was useful for figuring out how to invoke the assembler and is a nice summary of many other things as well:
- This is DEC’s manual for the assembler. It is a good introduction to PDP-8 architecture and PAL8. It was written prior to OS/8 and does not discuss how to assemble in that environment. Instead it discusses loading the assembler and program from paper tape. Not what I’m trying to achieve at the moment.
- This is a book on PAL8 and the PDP-8. Quite a lot of good stuff in it.
Getting the Program onto Disk
The last blog entry was about using the PDP-8’s EDIT program. Go take a look if you need more of an explanation.
We will copy this program into the clipboard:
/ Test program that adds 3 and 4 and leaves the sum in the accumulator *200 /Start assembling program at Memory location %200 (octal 200) CLA /Clear the accumulator TAD A /Add contents of memory location A to accumulator TAD B /Add contents of memory location B to accumulator HLT /Halt the CPU JMP I [7600 /Return to OS/8 A, 0003 /Define A as %3 B, 0004 /Define B as %4
Now fire up the editor and have it append text into the buffer:
.CREATE PROG1.PA #A
Now paste the program into EDIT. At the end of the paste operation, type control-L to return to command mode and then type E to save and exit. Then I do a DIR command to verify the file is there:
A, 0003 /DEFINE A AS %3 B, 0004 /DEFINE B AS %4 #E .DIR PROG1.PA PROG1 .PA 2 1 FILES IN 2 BLOCKS - 2386 FREE BLOCKS
You should also “TYPE PROG1.PA” just to verify it is like you expect it to be.
Now that the program source is on disk, we are ready to assemble it. The simple format of the PAL command is
To compile PROG1.PA, simply type:
If any errors are found, an error count is displayed and you need to re-assemble the program using this format of the PAL command:
This assembles the program AND produces a listing. You can look at this listing to determine the problem. Let’s have a look at the listing generated:
.TYPE PROG1.LS / TEST PROGRAM THAT ADDS 3 AND 4 AND LEAVES THE SUM IN THE ACCUMULATOR 0200 *200 /START ASSEMBLING PROGRAM AT MEMORY LOCATION %200 (OCTAL 200) 00200 7200 CLA /CLEAR THE ACCUMULATOR 00201 1205 TAD A /ADD CONTENTS OF MEMORY LOCATION A TO ACCUMULATOR 00202 1206 TAD B /ADD CONTENTS OF MEMORY LOCATION B TO ACCUMULATOR 00203 7402 HLT /HALT THE CPU 00204 5577 JMP I [7600 /RETURN TO OS/8 00205 0003 A, 0003 /DEFINE A AS %3 00206 0004 B, 0004 /DEFINE B AS %4 $ 00177 7600 A 0205 B 0206 ERRORS DETECTED: 0 LINKS GENERATED: 0
In the listing, there are 2 columns before the source code. The first column is the location of the instruction. We told the assembler to start at %200 and, indeed, the first instruction (CLA) starts at %200.
The second column is the instruction opcode that is placed into memory. The Opcode for clearing the accumulator is %7200.
I believe the $ is the indication that is the end of the source. The next line has something to do with the indirect jump to %7600. I think I kind of understand what is happening, but not well enough to explain it🙂
Below that are the addresses for the labels. For example, A is at location %205.
Finally the number of errors is listed. If you get errors, take a look in the PAL manual for an explanation of the codes.
Now that we have successfully assembled the test program, we are ready to load the binary image into memory. For our test program, the binary image is in the file PROG1.BN. Unless you specify otherwise with the PAL8 program, the extension is always BN.
To load the program into memory we will use the absolute loader which is called ABSLDR. ABSLDR is invoked using the LOAD command:
.LOAD PROG1 .
And now the program is loaded into memory, starting at location %200. To start the program you use the START command:
Usually you will just want to LOAD and START at the same time, so just type this:
As soon as you do this, you will be bounced back to the SIMH prompt!!!!
.LOAD PROG1/G HALT instruction, PC: 00204 (JMP I 177) sim>
This happened because of the HLT (Halt) instruction in the simple program. That instruction literally tells the CPU to stop EVERYTHING (not something you really get to do in any modern operating system).
I am stopping the CPU because I want to be able to examine contents of memory and the accumulator since there is no other way for this simple program to communicate as to what 3+4 is.
Now that we are in simh, let’s dump the contents of memory locations 200-206 which is the location of the simple test program:
sim> e 200-206 200: 7200 201: 1205 202: 1206 203: 7402 204: 5577 205: 0003 206: 0004
Compare the memory contents with the 2nd column in the program listing and you will see the memory matches what the assembler created.
Where is the answer? Well it is in the accumulator which we can see by typing:
sim> e ac AC: 0007
And there is the answer: %3 + %4 is %7. Since the values are < 8 octal looks like decimal and you can verify the answer is correct.
To get simh running OS/8 again, simply type
sim> go .
The next instruction in the simple program is executed which is the indirect jump to restart OS/8.
A simple PAL8 program for the PDP-8 entered, assembled, loaded, and executed!