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));
}
//==========================================