Created
June 21, 2018 05:06
-
-
Save shirriff/3310e13cb02d6e67980ead2e8f7cb599 to your computer and use it in GitHub Desktop.
Generate primes up to 255 on the IBM 1401
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
job prime1.s | |
* Compute primes 2-255 for toggle challenge | |
* Ken Shirriff http://righto.com | |
ctl 6641 | |
org 201 * Start of print buffer | |
num dcw 002 * Current number | |
org 333 * Start of code memory | |
outer mcw @002@, factor * Start with factor 2 | |
inner c factor, num | |
be print * If factor == num: found a prime | |
za num, divbuf * divbuf = 0 + num | |
d factor, divbuf-2 * divide factor into divbuf | |
c divbuf, @00?@ * If remainder == +0: not a prime, go to next | |
be next | |
a @1@, factor * Add 1 to factor | |
b inner * Branch to inner to test next factor | |
print w * Write the prime to the printer | |
next a @1@, num * Add 1 to num | |
c @0255@, num * If not done, branch to outer | |
bu outer | |
h * Done: halt | |
h | |
factor dcw @ @ * Reserve 3 digits for factor | |
divbuf dcw @ @ * Reserve 7 digits for divide buffer | |
end outer |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment