There is a decent chance that you have never really heard of PL/M. Even if you are as old as I am, this one might have slipped by you. The truth is, it really is a bit before my time. I first heard of PL/M about the time that the CP/M sources started to become publicly available, and even then the complaint was that there would be no way to compile much of the source anymore. PL/M had been nearly forgotten by the mid-90's, even by those of us who were already interested in retrocomputing. But do not worry! This post will (or may?) get you started!
Everyone has this on their bookshelf, right? ;-)
Hello, world!
Or, at least something similar? An example program or two that output some text. Unlike many/most languages, PL/M lacks any form of standard I/O. Instead, that exercise is mostly left "for the reader". That is to say that rather than simply including a language feature for writing a string of text for output, the programmer must format any such string internally, and output each character sequentially. Fortunately the plm09 runtime provides PUTCH and PUTDEC procedures to simplify the actual output tasks, so let's look at an example that makes use of those:
/* hello.plm */
HELLO: DO;
PUTCH: PROCEDURE (C) EXTERNAL; DECLARE C BYTE; END PUTCH;
PUTDEC: PROCEDURE (N) EXTERNAL; DECLARE N ADDRESS; END PUTDEC;
DECLARE I BYTE;
I = 1;
DO WHILE I <= 5;
CALL PUTDEC(I * I);
I = I + 1;
END;
CALL PUTCH('!');
END HELLO;
Here we see a DO WHILE loop which counts to 5 while calling PUTDEC to print each value to the output. PUTCH is used at the end to pring a final '!' character.
I used the following Makefile to execute the build procedures and to run the result:
PLM09_SHARE = /usr/share/plm09
PLMC = plmc
LWASM = lwasm -9
SIM6809 = sim6809
%.asm: %.plm
$(PLMC) -o $@ $<
%.s19: %.asm
$(LWASM) -f srec -I $(PLM09_SHARE)/runtime -I $(PLM09_SHARE)/runtime/sim -o $@ $<
%: %.s19
$(SIM6809) $<
With the program save in "hello.plm", a simple 'make hello' is sufficient to run the binary to see the result below:
sim6809 hello.s19
1
4
9
16
25
!
Let's try one more example!
/* sum.plm */
SUM: DO;
PUTDEC: PROCEDURE (N) EXTERNAL; DECLARE N ADDRESS; END PUTDEC;
DECLARE I BYTE, TOTAL ADDRESS;
TOTAL = 0;
I = 1;
DO WHILE I <= 10;
TOTAL = TOTAL + I;
I = I + 1;
END;
CALL PUTDEC (TOTAL);
END SUM;
This program similarly uses a DO WHILE loop to count to 10, this time keeping the sum of each iterated value in TOTAL. Finally PUTDEC is used to output TOTAL at the end. Typing 'make sum' will yield the following output:
sim6809 sum.s19
55
Simple enough... What can you do with plm09?
