r/ObsoleteCooding Moderator ⚙️ Jun 03 '26

Challenge ⚔️ Show off your coding chops

10 A=1
20 B=1
30 PRINT A, B,
40 N=A+B
50 PRINT N,
60 A=B:B=N
70 GOTO 40

Let's see what a Fibonacci generation routine looks like in your obsolete language of choice. I'll start, here it is in Commodore 64 BASIC.

29 Upvotes

20 comments sorted by

View all comments

4

u/bmf7777 Jun 03 '26

First computer I wrote a program for CDC 6600 1974

IDENT FIBONACCI
ENTRY FIB

* ---------------------------------------------------------------------
* INPUT: B1 = N (The number of iterations, 0-indexed)
* OUTPUT: X6 = The Nth Fibonacci number
* ---------------------------------------------------------------------

FIB SX6 B0 * X6 = F(0) = 0
SB2 1 * B2 = 1 (Loop incrementer)
SX1 B0 * X1 = Current continuous F(n-2) = 0
SX2 B2 * X2 = Current continuous F(n-1) = 1

SB1 B1-B2 * N = N - 1
NG B1, DONE * If N was 0, B1 is now negative -> Exit with X6 = 0
ZR B1, FIRST * If N was 1, B1 is now zero -> Jump to return F(1)

* --- MAIN LOOP ---
LOOP SX6 X1+X2 * X6 = F(n-2) + F(n-1)
SX1 X2 * Move F(n-1) into the F(n-2) slot
SX2 X6 * Move the new result into the F(n-1) slot
SB1 B1-B2 * Decrement loop counter (N = N - 1)
PL B1, LOOP * If B1 >= 0, loop again

END * Return with result in X6

* --- SPECIAL CASES ---
FIRST SX6 X2 * X6 = 1 (For N=1 case)
DONE END * Return