D16/M Software

4-Aug-2005: XPL0 Runs on Homebrew Machine

Two years ago John Doran designed and built a computer based on the 7400-series TTL chip set. A thorough description of it is on his webpage ( http://timefracture.org/D16.html). Our local computer club (the 6502 Group) was blown away by John's unique tribute to the minicomputer - that, and his craftsmanship, productivity, and professional documentation.

However some of us whined about its lack of indexed addressing. Without this it was awkward to run a high level language, which depends heavily on indexing to access local variables and array elements. Recently John saw the light and added, not just one, but three index registers along with a bunch of instructions to support them. This was all the stimulation needed to port XPL0 to it.

Porting the Compiler

I began by modifying the 16-bit native version of the XPL0 compiler used by the PC (XPLN.XPL) to generate D16/M assembly code instead of 8088 code.

Next, a supporting package of runtime routines were written (D16RUN.ASM). These were built upon an existing debugger (DMON), and include essentials such as multiply and divide routines and some basic intrinsics that do things like display text and input and output integers.

The simulator (D16SIMX) was updated with the new instructions and used to verify and debug both the runtime code and the code generated by the compiler.

Although the compiler doesn't have a completely separate "back-end" code generator, it was fairly straightforward to replace the 8088 instructions with their equivalent D16 instructions. Admittedly the compiler source code is far from user-friendly, and an intimate familiarity came in handy.

The whole operation took about five days. At a 6502 Group meeting I was able to demonstrate the simulator running compiled D16 code for such classics as Hello World, the Sieve of Eratosthenes, the Fibonacci and Pi calculators, a maze generator, and even a couple large programs: Star Trek and Eliza.

You'd think this would be enough, but I didn't like the code that was compiled. Sure it worked, but it was ugly!

Porting the Optimized Compiler

From the get-go I wanted to convert the optimized XPLX compiler, but wisely backed off that ambition and got things working with the unoptimized XPLN instead. This probably saved time in the long run by not getting bogged down in a bunch of obscure bugs. After all, the first rule of optimization is: DON'T!

However I could resist no longer.

XPLX is about twice as big as XPLN, and most of that is due to the code generator. At least I'd have a working compiler with XPLN that would come in handy for tracking down and terminating any bugs that might occur in the optimized version.

Getting XPLX to work only took a few more days, but the project stretched out for a couple weeks as more and more refinements were made to the code generator. The effort seemed justified by the idea that some optimizations could be incorporated into the PC version. However the differences in architectures were such that nothing significant could be applied to the PC. The number of instructions generated for the Sieve benchmark shrank from 226 to 129, which is 57%, or almost half the size.

The simulator contains a crude profiler that counts the number of times each assembly instruction is executed. This showed that the Pi calculator was spending a lot of time doing multiplies and divides. Optimizing these two routines alone made the Pi program run twice as fast.

Because of the development that was done on the simulator, when the D16 hardware was finally ready with its new index registers, XPL0 programs were able to run without a hitch. (Actually there was one small hitch: a miswire.)

The Code

Here are examples of how the Fibonacci and Sieve programs get compiled into D16 assembly language.

The source code for the compiler and runtime code are here, along with some example XPL0 programs. Download D16XPLX.ZIP (125k).

A third-party assembler is required which can be obtained here: http://www.datasynceng.com/c32doc.htm. Unfortunately the demo version (C32DEMO.ZIP) is crippled and will not output a valid .HEX file.

-Loren Blaney

12-Mar-2003: D16/M Plays Chess

John Doran's homebrew D16/M computer became artificially intelligent at last night's 6502 Group meeting. It was injected with a chess-playing program written by yours truly.

Richard Ottosen demonstrated his chess prowess by losing his queen on the 4th move! :-)

The complete software, including a D16/M simulator that runs on a PC, can be downloaded here: CHESS03.ZIP (132k).

A description of the D16/M instruction set is available here: D16_DOC.PDF.

Screen image This is a screen shot of the chess program being run from the simulator. (Image courtesy of Dave Eisler's CaptureWizPro.)

John John explaining the operation of his D16/M.

Dave Dave toggles in a test program.

Below are some close-ups of the D16/M.

Any problems with this webpage may be blamed on: loren_blaney@idcomm.com

Back to the XPL0 home page