← Back to list

A New Challenge: Implementing PL/M in Prolog

A New Challenge: Implementing PL/M in Prolog

Kenichi Sasagawa · 2026-02-19 08:45 · 5 claps · 1.4 min read
#prolog #z80
Open on Medium ↗

A New Challenge: Implementing PL/M in Prolog

A New Challenge: Implementing PL/M in Prolog

With the help of AI, I was able to build a basic Z80 assembler and simulator in a surprisingly short time.

While revisiting the Z80 era, I found myself thinking about the achievements of Gary Kildall. CP/M is well known, of course. But at the same time, he also developed PL/M — a high-level language designed for Intel processors in the early days of microcomputing.

And then a thought occurred to me:

Could I implement PL/M in Prolog?

At first, just like with the assembler, I considered writing a PL/M cross-compiler in C. That would have been the straightforward approach. But I began to wonder if there might be a more efficient and elegant method.

Then it struck me:

Why not use Prolog?

I have often heard that Prolog is well suited for compiler construction. Is that really true? The best way to find out is to try it myself.

PL/M was originally developed for the 8080 processor. Its language specification is not overwhelmingly complex. It feels manageable — perhaps even ideal as an experimental target.

If I can demonstrate that Prolog is also powerful in compiler construction, that would be both technically interesting and personally satisfying.

And so, I now have one more challenge to pursue.

Reference: What PL/M Looks Like

Here is an example of PL/M source code:

FIND: PROCEDURE(PA,PB) BYTE;
   DECLARE (PA,PB) BYTE;
   /* Search SCRATCH for a substring starting at PA and ending at PB */
   DECLARE J ADDRESS,
       (K, MATCH) BYTE;
   J = BACK ;
   MATCH = FALSE;
       DO WHILE NOT MATCH AND (MAXM > J);
       LAST,J = J + 1; /* Start search from J */
       K = PA ; /* Check if string matches starting at K */
           DO WHILE SCRATCH(K) = MEMORY(LAST) AND
               NOT (MATCH := K = PB);
           /* One more character matched */
           K = K + 1; LAST = LAST + 1;
           END;
       END;
   IF MATCH THEN /* Move destination */
       DO; LAST = LAST - 1; CALL MOVER;
       END;
   RETURN MATCH;
   END FIND;

This is not just nostalgia.

It is a small but meaningful experiment: Can a declarative language like Prolog serve as a practical tool for building a compiler?

I intend to find out.


메타데이터
post_id
d02d5ae9c2c5
slug
a-new-challenge-implementing-pl-m-in-prolog-d02d5ae9c2c5
url
https://medium.com/@kenichisasagawa/a-new-challenge-implementing-pl-m-in-prolog-d02d5ae9c2c5
canonical_url
https://medium.com/@kenichisasagawa/a-new-challenge-implementing-pl-m-in-prolog-d02d5ae9c2c5
author_url
https://medium.com/@kenichisasagawa
status
ok
fetched_at
2026-06-14 11:28:49