Skip to content

Instantly share code, notes, and snippets.

@jpf
Last active August 29, 2015 14:00
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save jpf/6c0e042420487eae0093 to your computer and use it in GitHub Desktop.
Save jpf/6c0e042420487eae0093 to your computer and use it in GitHub Desktop.
This is a program written in AUTOCODER for the IBM 1401. It prints the first 10 numbers in the Fibonacci sequence.
A DCW @001@ * VARIABLE "A"
B DCW @001@ * VARIABLE "B"
C DCW @000@ * VARIABLE "C"
COUNT DCW @000@ * VARIABLE "COUNT"
START MCS A,201+3 * MOVE A VARIABLE TO PRINT BUFFER
W * PRINT
LOOP BCE DONE,COUNT-1,1 * WHILE COUNT < 10
MCS B,201+3 * MOVE B VARIABLE TO PRINT BUFFER
W * PRINT
A @1@,COUNT * COUNT++
MCW A,C * C=A
A B,C * C+=B
MCW B,A * A=B
MCW C,B * B=C
B LOOP * GOTO LOOP
DONE H *-3 * HALT, SET PROGRAM COUNTER AT HALT INSTRUCTION
END START
@dgies
Copy link

dgies commented May 1, 2014

Am I misunderstanding something or is there a typo on line 7? I read it as

Label 'LOOP', jump to 'DONE' if COUNT-1==1

Shouldn't it be?

LOOP BCE DONE,COUNT-1,10

@jpf
Copy link
Author

jpf commented May 2, 2014

All data on the IBM 1401 is stored as "characters" and BCE can only compare one character with another, so what we're doing here is comparing COUNT-1, which is whatever address COUNT starts at, minus 1. This selects the "middle digit" in that variable.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment