Hello all,
Ed suggested I start a thread about my adventures over the last week trying to find C compiler that would produce PDP-11 machine code, for running on one of the BBC Micro’s PDP-11 Co Processors, of which there are two:
These are the Pi/ARM-based PiTubeDirect Co Pro and the FPGA-based Matchbox Co Pro.
In addition, the B-em emulator also contains a PDP-11 Co Pro emulation, so maybe that counts as three! This is actually a great development environment, as it saves having to mess around with BBC Micro SD Cards.
As an example, I set out to try to compile a version of the famous Pi Spigot.
This short C program prints the first 1000 digits of Pi:
#include <stdio.h>
#define N 3500
main() {
short r[N + 1], i, k, b, c;
long d;
c = 0;
for (i = 1; i <= N; i++)
r[i] = 2000;
for (k = N; k > 0; k -= 14) {
d = 0;
i = k;
for(;;) {
d += r[i]*10000L;
b = i*2 - 1;
r[i] = d%b;
d /= b;
i--;
if (i == 0) break;
d *= i;
}
printf("%.4d", (int)(c + d/10000));
c = d%10000;
}
}
For it to work, it needs signed 32-bit arithmetic (longs in C on the PDP-11) to operate properly.
Here are links to the three chapters of the adventure:
-
Attempt 2 - Compiling on Linux using PCC PDP-11 Cross Compiler
-
Attempt 3 - Compiling on Linux using GCC PDP-11 Cross Compiler
The first two appoaches lead to dead-ends for various reasons (detailed if you follow the links).
The third approach (using GCC) proved surprisingly chanllening, as I rapidly hit bugs in the GCC PDP-11 target backend. Based on my experiences, I think it’s safe to say this probably isn’t getting much use these days.
Anyway, I was ultimately successful in my goal:
This has taken about a week, mostly trying to understand enought about how a GCC backend works to be able to fix the two bugs.
It would be nice to try to run some kind of a C test suite, but I suspect this will not be possible in an environment with only 62KB of RAM and no access to the standard libc.
Is anyone aware of any other compilers I could try?
Dave