C cross-compiler

23 views
Skip to first unread message

Oscar Vermeulen

unread,
Oct 8, 2025, 4:37:25 AM (2 days ago) Oct 8
to [PiDP-1]
I tried out this C compiler for the PDP-1:

Amazingly, it works!

git clone https://github.com/fkokosinski/pdp1-playground.git
cd pdp1-playground
git submodule update --init --recursive

...and follow the instructions on the Github.

Screenshot From 2025-10-08 10-36-45.png

Huh! Modern times.

Oscar Vermeulen

unread,
Oct 8, 2025, 4:42:58 AM (2 days ago) Oct 8
to [PiDP-1]
...and the PiDP-1 command 'pdp' clashes with the identically named simh simulator that's included.
So do 
sudo mv /usr/local/bin/pdp1 /usr/local/bin/pdp1apps

To rename the PiDP-1 command for controlling the apps (not many people use that anyway) to pdp1apps.

Alen Shapiro

unread,
Oct 8, 2025, 6:18:27 PM (2 days ago) Oct 8
to [PiDP-1]
Oh my... it works gcc->PDP-1 order code!! (and it does not even output the numbers in reverse). I'll try my generated C code next.

% make main.s main.rim run # gives (among lots of other stuff...)

PDP-1 simulator V3.8-1
0, 1, 1, 2, 3, 5, 8, 13, 21, 34, 55, 89, 144, 233, 377, 610, 987, 1597, 2584, 4181
HALT instruction, PC: 000460 (DAC I 131)
Goodbye

using this fibonacci C code in "main.c" (and a copy of a Makefile from the original c-print-fibonacci folder)

//==========================================main.c
static void putc(int);
static void puti(int);
static int fib(int);

/* TODO: this sample fails to compile on higher -O values */

#define F_DIGITS 20

void
main(void) {
int n;

for(int i=0 ; i < F_DIGITS ; i++) {
puti(fib(i));
if(i < F_DIGITS-1) {
putc(033);
putc(0);
}
}
}

static void
putc(int c) {
asm volatile ("lio %0" : : "r"(c) : "$io");
asm volatile ("tyo");
}

#if defined(OLD_VERSION)
static void
puti(int i) {
int mod;

do {
mod = i % 10;
putc((mod == 0) ? 020 : mod);
i /= 10;
} while (i != 0);
}
#else /* defined(OLD_VERSION) */
void
puti(int num) {
if (num == 0) {
putc(020);
return;
}

if (num < 0) { // make the number positive
putc('-'); // after printing minus sign
num = -num;
}

int divisor = 1;
// How many digits (powers of 10)
while (num / divisor >= 10)
divisor *= 10;

// Print digits from most sig to least sig
while (divisor > 0) {
int digit = num / divisor;
putc((digit == 0) ? 020 : digit); // non ASCII (bummer)
num %= divisor; // remove the printed digit from num
divisor /= 10; // next digit
}
}
#endif /* defined(OLD_VERSION) */

static int
fib(int n) {
if(n <= 1)
return(n);
else
return(fib(n-1) + fib(n-2));
}
//==========================================


Reply all
Reply to author
Forward
0 new messages