Artifact
5bac8ab3e8dbee65fda2f064f9d98c61b7c504c4:
Wiki page
[PEP001.BA] by
tangent
2019-11-01 12:20:19.
0000: 44 20 32 30 31 39 2d 31 31 2d 30 31 54 31 32 3a D 2019-11-01T12:
0010: 32 30 3a 31 39 2e 30 33 31 0a 4c 20 50 45 50 30 20:19.031.L PEP0
0020: 30 31 2e 42 41 0a 4e 20 74 65 78 74 2f 78 2d 6d 01.BA.N text/x-m
0030: 61 72 6b 64 6f 77 6e 0a 50 20 35 61 39 62 39 65 arkdown.P 5a9b9e
0040: 65 38 32 31 37 30 65 37 30 38 31 64 62 38 30 39 e82170e7081db809
0050: 30 66 63 64 66 30 36 64 33 35 66 39 64 34 30 33 0fcdf06d35f9d403
0060: 30 64 0a 55 20 74 61 6e 67 65 6e 74 0a 57 20 34 0d.U tangent.W 4
0070: 36 38 35 0a 23 20 41 6e 20 4f 53 2f 38 20 42 41 685.# An OS/8 BA
0080: 53 49 43 20 49 6d 70 6c 65 6d 65 6e 74 61 74 69 SIC Implementati
0090: 6f 6e 20 6f 66 20 50 72 6f 6a 65 63 74 20 45 75 on of Project Eu
00a0: 6c 65 72 20 50 72 6f 62 6c 65 6d 20 23 31 0d 0a ler Problem #1..
00b0: 0d 0a 42 65 66 6f 72 65 20 79 6f 75 20 62 65 67 ..Before you beg
00c0: 69 6e 2c 20 79 6f 75 20 6d 61 79 20 77 69 73 68 in, you may wish
00d0: 20 74 6f 20 73 74 61 72 74 20 77 69 74 68 20 74 to start with t
00e0: 68 65 20 63 6f 6d 70 61 6e 69 6f 6e 20 61 72 74 he companion art
00f0: 69 63 6c 65 2c 20 5b 47 65 74 74 69 6e 67 20 54 icle, [Getting T
0100: 65 78 74 20 49 6e 5d 28 2f 77 69 6b 69 3f 6e 61 ext In](/wiki?na
0110: 6d 65 3d 47 65 74 74 69 6e 67 2b 54 65 78 74 2b me=Getting+Text+
0120: 49 6e 29 2e 0d 0a 0d 0a 54 68 65 20 42 41 53 49 In).....The BASI
0130: 43 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e C implementation
0140: 20 6f 66 20 61 20 70 72 6f 67 72 61 6d 20 74 6f of a program to
0150: 20 73 6f 6c 76 65 20 5b 50 72 6f 6a 65 63 74 20 solve [Project
0160: 45 75 6c 65 72 20 50 72 6f 62 6c 65 6d 20 23 31 Euler Problem #1
0170: 5d 28 68 74 74 70 73 3a 2f 2f 70 72 6f 6a 65 63 ](https://projec
0180: 74 65 75 6c 65 72 2e 6e 65 74 2f 70 72 6f 62 6c teuler.net/probl
0190: 65 6d 3d 31 29 20 74 75 72 6e 65 64 20 6f 75 74 em=1) turned out
01a0: 20 74 6f 20 62 65 20 73 75 72 70 72 69 73 69 6e to be surprisin
01b0: 67 6c 79 20 64 69 66 66 69 63 75 6c 74 20 74 6f gly difficult to
01c0: 20 77 72 69 74 65 20 66 6f 72 20 74 68 69 73 20 write for this
01d0: 6f 6c 64 20 5b 41 70 70 6c 65 73 6f 66 74 20 42 old [Applesoft B
01e0: 41 53 49 43 5d 28 68 74 74 70 73 3a 2f 2f 65 6e ASIC](https://en
01f0: 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f 77 .wikipedia.org/w
0200: 69 6b 69 2f 41 70 70 6c 65 73 6f 66 74 5f 42 41 iki/Applesoft_BA
0210: 53 49 43 29 20 68 61 6e 64 2e 20 54 68 65 72 65 SIC) hand. There
0220: 20 61 72 65 20 61 20 6e 75 6d 62 65 72 20 6f 66 are a number of
0230: 20 64 69 66 66 65 72 65 6e 63 65 73 20 62 65 74 differences bet
0240: 77 65 65 6e 20 74 68 65 73 65 20 74 77 6f 20 64 ween these two d
0250: 69 61 6c 65 63 74 73 20 6f 66 20 42 41 53 49 43 ialects of BASIC
0260: 2e 20 54 68 65 72 65 20 61 72 65 20 61 6c 73 6f . There are also
0270: 20 73 6f 6d 65 20 73 75 72 70 72 69 73 69 6e 67 some surprising
0280: 20 6c 69 6d 69 74 61 74 69 6f 6e 73 20 69 6e 20 limitations in
0290: 74 68 65 20 4f 53 2f 38 20 64 69 61 6c 65 63 74 the OS/8 dialect
02a0: 20 72 65 6c 61 74 69 76 65 20 74 6f 20 41 70 70 relative to App
02b0: 6c 65 73 6f 66 74 20 42 41 53 49 43 2e 0d 0a 0d lesoft BASIC....
02c0: 0a 48 65 72 65 20 69 73 20 74 68 65 20 63 6f 64 .Here is the cod
02d0: 65 20 49 20 63 61 6d 65 20 75 70 20 77 69 74 68 e I came up with
02e0: 3a 0d 0a 0d 0a 60 60 60 62 61 73 69 63 0d 0a 31 :....```basic..1
02f0: 30 20 46 4f 52 20 49 20 3d 20 31 20 54 4f 20 39 0 FOR I = 1 TO 9
0300: 39 39 0d 0a 32 30 20 41 20 3d 20 49 20 2f 20 33 99..20 A = I / 3
0310: 20 5c 20 42 20 3d 20 49 20 2f 20 35 0d 0a 33 30 \ B = I / 5..30
0320: 20 49 46 20 49 4e 54 28 41 29 20 3d 20 41 20 47 IF INT(A) = A G
0330: 4f 54 4f 20 36 30 0d 0a 34 30 20 49 46 20 49 4e OTO 60..40 IF IN
0340: 54 28 42 29 20 3d 20 42 20 47 4f 54 4f 20 36 30 T(B) = B GOTO 60
0350: 0d 0a 35 30 20 47 4f 54 4f 20 37 30 0d 0a 36 30 ..50 GOTO 70..60
0360: 20 54 20 3d 20 54 20 2b 20 49 0d 0a 37 30 20 4e T = T + I..70 N
0370: 45 58 54 20 49 0d 0a 38 30 20 50 52 49 4e 54 20 EXT I..80 PRINT
0380: 22 54 4f 54 41 4c 3a 20 22 3b 20 54 0d 0a 39 30 "TOTAL: "; T..90
0390: 20 45 4e 44 0d 0a 60 60 60 0d 0a 0d 0a 41 20 73 END..```....A s
03a0: 75 72 70 72 69 73 69 6e 67 20 61 73 70 65 63 74 urprising aspect
03b0: 20 6f 66 20 74 68 69 73 20 69 6d 70 6c 65 6d 65 of this impleme
03c0: 6e 74 61 74 69 6f 6e 20 6f 66 20 42 41 53 49 43 ntation of BASIC
03d0: 20 69 73 20 74 68 61 74 20 69 74 20 73 65 65 6d is that it seem
03e0: 73 20 74 6f 20 62 65 20 75 73 69 6e 67 20 66 6c s to be using fl
03f0: 6f 61 74 69 6e 67 2d 70 6f 69 6e 74 20 6e 75 6d oating-point num
0400: 62 65 72 73 20 66 6f 72 20 69 6e 74 65 67 65 72 bers for integer
0410: 20 63 61 6c 63 75 6c 61 74 69 6f 6e 73 20 73 75 calculations su
0420: 63 68 20 61 73 20 74 68 69 73 2e 20 53 69 6e 63 ch as this. Sinc
0430: 65 20 74 68 65 20 5b 6d 61 6e 74 69 73 73 61 5d e the [mantissa]
0440: 28 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b 69 (https://en.wiki
0450: 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 53 pedia.org/wiki/S
0460: 69 67 6e 69 66 69 63 61 6e 64 29 20 69 73 20 36 ignificand) is 6
0470: 20 73 69 67 6e 69 66 69 63 61 6e 74 20 64 69 67 significant dig
0480: 69 74 73 20 69 6e 20 74 68 69 73 20 69 6d 70 6c its in this impl
0490: 65 6d 65 6e 74 61 74 69 6f 6e 20 6f 66 20 42 41 ementation of BA
04a0: 53 49 43 2c 20 69 74 20 6d 65 61 6e 73 20 77 65 SIC, it means we
04b0: 20 65 66 66 65 63 74 69 76 65 6c 79 20 67 65 74 effectively get
04c0: 20 66 75 6c 6c 20 69 6e 74 65 67 65 72 20 70 72 full integer pr
04d0: 65 63 69 73 69 6f 6e 20 66 6f 72 20 6f 75 72 20 ecision for our
04e0: 63 61 6c 63 75 6c 61 74 69 6f 6e 2c 20 73 69 6e calculation, sin
04f0: 63 65 20 74 68 65 20 61 6e 73 77 65 72 20 69 73 ce the answer is
0500: 20 6c 65 73 73 20 74 68 61 6e 20 37 20 64 69 67 less than 7 dig
0510: 69 74 73 2e 20 28 41 6e 64 20 74 68 61 74 27 73 its. (And that's
0520: 20 61 6c 6c 20 49 27 6d 20 67 6f 69 6e 67 20 74 all I'm going t
0530: 6f 20 73 61 79 20 61 62 6f 75 74 20 74 68 65 20 o say about the
0540: 61 6e 73 77 65 72 20 68 65 72 65 2e 29 0d 0a 0d answer here.)...
0550: 0a 28 53 75 72 70 72 69 73 65 64 3f 20 4a 61 76 .(Surprised? Jav
0560: 61 53 63 72 69 70 74 20 77 61 73 20 64 65 73 69 aScript was desi
0570: 67 6e 65 64 20 74 68 65 20 73 61 6d 65 20 77 61 gned the same wa
0580: 79 2c 20 73 75 63 68 20 74 68 61 74 20 79 6f 75 y, such that you
0590: 20 6e 65 65 64 20 65 69 74 68 65 72 20 75 6e 75 need either unu
05a0: 73 75 61 6c 20 63 6c 65 76 65 72 6e 65 73 73 20 sual cleverness
05b0: 69 6e 20 74 68 65 20 4a 61 76 61 53 63 72 69 70 in the JavaScrip
05c0: 74 20 65 6e 67 69 6e 65 20 6f 72 20 6e 6f 6e 73 t engine or nons
05d0: 74 61 6e 64 61 72 64 20 65 78 74 65 6e 73 69 6f tandard extensio
05e0: 6e 73 20 6c 69 6b 65 20 5b 54 79 70 65 53 63 72 ns like [TypeScr
05f0: 69 70 74 5d 28 68 74 74 70 73 3a 2f 2f 65 6e 2e ipt](https://en.
0600: 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 wikipedia.org/wi
0610: 6b 69 2f 54 79 70 65 53 63 72 69 70 74 29 20 74 ki/TypeScript) t
0620: 6f 20 66 6f 72 63 65 20 75 73 65 20 6f 66 20 61 o force use of a
0630: 6e 20 69 6e 74 65 67 65 72 20 64 61 74 61 20 74 n integer data t
0640: 79 70 65 20 69 6e 73 74 65 61 64 20 6f 66 20 61 ype instead of a
0650: 20 74 72 75 6e 63 61 74 65 64 20 66 6c 6f 61 74 truncated float
0660: 69 6e 67 20 70 6f 69 6e 74 20 76 61 6c 75 65 2e ing point value.
0670: 29 0d 0a 0d 0a 54 68 61 74 20 66 65 61 74 75 72 )....That featur
0680: 65 20 6d 65 61 6e 73 20 49 20 64 69 64 6e 27 74 e means I didn't
0690: 20 6e 65 65 64 20 74 68 65 20 64 69 72 74 79 20 need the dirty
06a0: 73 75 62 74 6f 74 61 6c 69 6e 67 20 74 72 69 63 subtotaling tric
06b0: 6b 20 49 20 75 73 65 64 20 69 6e 20 74 68 65 20 k I used in the
06c0: 5b 50 41 4c 38 20 61 73 73 65 6d 62 6c 79 20 76 [PAL8 assembly v
06d0: 65 72 73 69 6f 6e 5d 28 2f 77 69 6b 69 3f 6e 61 ersion](/wiki?na
06e0: 6d 65 3d 50 45 50 30 30 31 2e 50 41 29 2e 0d 0a me=PEP001.PA)...
06f0: 0d 0a 0d 0a 23 23 20 4c 69 6d 69 74 61 74 69 6f ....## Limitatio
0700: 6e 73 20 4d 61 6b 69 6e 67 20 74 68 65 20 50 72 ns Making the Pr
0710: 6f 67 72 61 6d 20 4c 6f 6e 67 65 72 0d 0a 0d 0a ogram Longer....
0720: 31 2e 20 4f 53 2f 38 20 42 41 53 49 43 20 6f 6e 1. OS/8 BASIC on
0730: 6c 79 20 61 63 63 65 70 74 73 20 61 20 60 47 4f ly accepts a `GO
0740: 54 4f 60 20 61 73 20 74 68 65 20 22 74 68 65 6e TO` as the "then
0750: 22 20 63 6c 61 75 73 65 20 6f 66 20 60 49 46 60 " clause of `IF`
0760: 2e 20 49 6e 20 66 61 63 74 2c 20 79 6f 75 20 63 . In fact, you c
0770: 61 6e 20 61 6c 73 6f 20 77 72 69 74 65 20 60 49 an also write `I
0780: 46 20 63 6f 6e 64 69 74 69 6f 6e 20 47 4f 54 4f F condition GOTO
0790: 20 78 78 60 20 61 73 20 60 49 46 20 63 6f 6e 64 xx` as `IF cond
07a0: 69 74 69 6f 6e 20 54 48 45 4e 20 78 78 60 3b 20 ition THEN xx`;
07b0: 62 6f 74 68 20 6d 65 61 6e 20 74 68 65 20 73 61 both mean the sa
07c0: 6d 65 20 74 68 69 6e 67 2e 0d 0a 0d 0a 32 2e 20 me thing.....2.
07d0: 59 6f 75 20 63 61 6e 27 74 20 68 61 76 65 20 6d You can't have m
07e0: 75 6c 74 69 70 6c 65 20 60 4e 45 58 54 60 20 73 ultiple `NEXT` s
07f0: 74 61 74 65 6d 65 6e 74 73 20 66 6f 72 20 61 20 tatements for a
0800: 67 69 76 65 6e 20 60 46 4f 52 60 20 73 74 61 74 given `FOR` stat
0810: 65 6d 65 6e 74 3b 20 69 74 20 64 6f 65 73 6e 27 ement; it doesn'
0820: 74 20 68 61 70 70 65 6e 20 69 6e 20 74 68 69 73 t happen in this
0830: 20 70 72 6f 67 72 61 6d 2c 20 62 75 74 20 74 68 program, but th
0840: 69 73 20 6c 69 6d 69 74 61 74 69 6f 6e 20 63 61 is limitation ca
0850: 6e 20 72 65 71 75 69 72 65 20 79 6f 75 20 74 6f n require you to
0860: 20 75 73 65 20 61 20 60 47 4f 54 4f 60 20 74 6f use a `GOTO` to
0870: 20 6a 75 6d 70 20 74 6f 20 74 68 65 20 73 69 6e jump to the sin
0880: 67 6c 65 20 6c 69 6e 65 20 63 6f 6e 74 61 69 6e gle line contain
0890: 69 6e 67 20 74 68 65 20 60 4e 45 58 54 60 20 73 ing the `NEXT` s
08a0: 74 61 74 65 6d 65 6e 74 2e 0d 0a 0d 0a 33 2e 20 tatement.....3.
08b0: 54 68 65 20 60 45 4e 44 60 20 73 74 61 74 65 6d The `END` statem
08c0: 65 6e 74 20 69 73 20 6e 6f 74 20 6f 70 74 69 6f ent is not optio
08d0: 6e 61 6c 2e 20 4f 53 2f 38 20 42 41 53 49 43 20 nal. OS/8 BASIC
08e0: 77 69 6c 6c 20 66 6c 61 74 6c 79 20 72 65 66 75 will flatly refu
08f0: 73 65 20 74 6f 20 72 75 6e 20 74 68 65 20 70 72 se to run the pr
0900: 6f 67 72 61 6d 20 77 69 74 68 6f 75 74 20 69 74 ogram without it
0910: 2e 0d 0a 0d 0a 34 2e 20 59 6f 75 20 63 61 6e 20 .....4. You can
0920: 63 68 61 69 6e 20 65 78 70 72 65 73 73 69 6f 6e chain expression
0930: 73 20 74 6f 67 65 74 68 65 72 20 69 6e 20 61 6e s together in an
0940: 20 60 49 46 60 20 73 74 61 74 65 6d 65 6e 74 2c `IF` statement,
0950: 20 62 75 74 20 4f 53 2f 38 20 62 61 73 69 63 20 but OS/8 basic
0960: 64 6f 65 73 20 6e 6f 74 20 63 6f 6e 73 69 64 65 does not conside
0970: 72 20 61 20 72 65 6c 61 74 69 6f 6e 20 61 73 20 r a relation as
0980: 61 6e 20 65 78 70 72 65 73 73 69 6f 6e 2e 20 49 an expression. I
0990: 74 20 6f 6e 6c 79 20 63 6f 6e 73 69 64 65 72 73 t only considers
09a0: 20 73 69 6d 70 6c 65 20 61 72 69 74 68 6d 65 74 simple arithmet
09b0: 69 63 20 61 73 20 61 6e 20 65 78 70 72 65 73 73 ic as an express
09c0: 69 6f 6e 2e 20 54 68 75 73 2c 20 77 65 20 6d 75 ion. Thus, we mu
09d0: 73 74 20 74 65 73 74 20 74 68 65 20 74 77 6f 20 st test the two
09e0: 63 6f 6e 64 69 74 69 6f 6e 73 20 69 6e 20 73 65 conditions in se
09f0: 70 61 72 61 74 65 20 60 49 46 60 20 73 74 61 74 parate `IF` stat
0a00: 65 6d 65 6e 74 73 2e 0d 0a 0d 0a 35 2e 20 4f 53 ements.....5. OS
0a10: 2f 38 20 42 41 53 49 43 20 6f 6e 6c 79 20 73 75 /8 BASIC only su
0a20: 70 70 6f 72 74 73 20 60 41 4e 44 60 20 66 6f 72 pports `AND` for
0a30: 20 74 65 73 74 69 6e 67 20 6d 75 6c 74 69 70 6c testing multipl
0a40: 65 20 63 6f 6e 64 69 74 69 6f 6e 73 20 69 6e 20 e conditions in
0a50: 61 20 73 69 6e 67 6c 65 20 60 49 46 60 20 73 74 a single `IF` st
0a60: 61 74 65 6d 65 6e 74 3b 20 74 68 65 72 65 20 69 atement; there i
0a70: 73 20 6e 6f 20 60 4f 52 60 2e 0d 0a 0d 0a 41 70 s no `OR`.....Ap
0a80: 70 6c 65 73 6f 66 74 20 42 41 53 49 43 20 e2 80 plesoft BASIC â€
0a90: 94 20 61 6e 64 20 69 6e 20 66 61 63 74 2c 20 73 ” and in fact, s
0aa0: 65 76 65 72 61 6c 20 6f 74 68 65 72 20 6d 69 63 everal other mic
0ab0: 72 6f 63 6f 6d 70 75 74 65 72 20 42 41 53 49 43 rocomputer BASIC
0ac0: 73 20 66 72 6f 6d 20 74 68 65 20 6c 61 74 65 20 s from the late
0ad0: 31 39 37 30 73 20 e2 80 94 20 64 69 64 6e 27 74 1970s — didn't
0ae0: 20 68 61 76 65 20 61 6e 79 20 6f 66 20 74 68 65 have any of the
0af0: 73 65 20 6c 69 6d 69 74 61 74 69 6f 6e 73 2c 20 se limitations,
0b00: 61 6c 6c 6f 77 69 6e 67 20 74 68 65 20 70 72 6f allowing the pro
0b10: 67 72 61 6d 20 74 6f 20 62 65 20 61 20 6c 6f 74 gram to be a lot
0b20: 20 73 68 6f 72 74 65 72 20 61 6e 64 20 63 6c 65 shorter and cle
0b30: 61 72 65 72 3a 0d 0a 0d 0a 60 60 60 62 61 73 69 arer:....```basi
0b40: 63 0d 0a 31 30 20 46 4f 52 20 49 20 3d 20 31 20 c..10 FOR I = 1
0b50: 54 4f 20 39 39 39 0d 0a 32 30 20 41 20 3d 20 49 TO 999..20 A = I
0b60: 20 2f 20 33 20 3a 20 42 20 3d 20 49 20 2f 20 35 / 3 : B = I / 5
0b70: 0d 0a 33 30 20 49 46 20 49 4e 54 28 41 29 20 3d ..30 IF INT(A) =
0b80: 20 41 20 4f 52 20 49 4e 54 28 42 29 20 3d 20 42 A OR INT(B) = B
0b90: 20 54 48 45 4e 20 54 20 3d 20 54 20 2b 20 49 0d THEN T = T + I.
0ba0: 0a 34 30 20 4e 45 58 54 20 49 0d 0a 35 30 20 50 .40 NEXT I..50 P
0bb0: 52 49 4e 54 20 22 54 4f 54 41 4c 3a 20 22 3b 20 RINT "TOTAL: ";
0bc0: 54 0d 0a 60 60 60 0d 0a 0d 0a 57 65 27 72 65 20 T..```....We're
0bd0: 64 6f 77 6e 20 74 6f 20 35 20 6c 69 6e 65 73 2c down to 5 lines,
0be0: 20 61 20 6c 65 6e 67 74 68 20 49 20 66 65 65 6c a length I feel
0bf0: 20 69 73 20 65 78 61 63 74 6c 79 20 72 69 67 68 is exactly righ
0c00: 74 20 66 6f 72 20 74 68 69 73 20 70 72 6f 62 6c t for this probl
0c10: 65 6d 27 73 20 70 72 6f 70 65 72 20 73 6f 6c 75 em's proper solu
0c20: 74 69 6f 6e 2e 0d 0a 0d 0a 57 68 69 6c 65 20 69 tion.....While i
0c30: 74 20 69 73 6e 27 74 20 65 78 61 63 74 6c 79 20 t isn't exactly
0c40: 5b 73 74 72 75 63 74 75 72 65 64 20 70 72 6f 67 [structured prog
0c50: 72 61 6d 6d 69 6e 67 5d 28 68 74 74 70 73 3a 2f ramming](https:/
0c60: 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 /en.wikipedia.or
0c70: 67 2f 77 69 6b 69 2f 53 74 72 75 63 74 75 72 65 g/wiki/Structure
0c80: 64 5f 70 72 6f 67 72 61 6d 6d 69 6e 67 29 2c 20 d_programming),
0c90: 69 74 20 61 74 20 6c 65 61 73 74 20 68 61 73 20 it at least has
0ca0: 6e 6f 20 60 47 4f 54 4f 60 73 20 61 6e 64 20 6f no `GOTO`s and o
0cb0: 6e 6c 79 20 61 20 73 69 6e 67 6c 65 20 60 4e 45 nly a single `NE
0cc0: 58 54 60 2e 0d 0a 0d 0a 0d 0a 23 23 20 46 75 72 XT`.......## Fur
0cd0: 74 68 65 72 20 4c 69 6d 69 74 61 74 69 6f 6e 73 ther Limitations
0ce0: 20 4e 6f 74 20 41 66 66 65 63 74 69 6e 67 20 50 Not Affecting P
0cf0: 72 6f 67 72 61 6d 20 4c 65 6e 67 74 68 0d 0a 0d rogram Length...
0d00: 0a 45 72 72 6f 72 20 72 65 70 6f 72 74 61 67 65 .Error reportage
0d10: 20 69 73 20 74 79 70 69 63 61 6c 20 6f 66 20 69 is typical of i
0d20: 74 73 20 65 72 61 2c 20 77 68 69 63 68 20 69 73 ts era, which is
0d30: 20 74 6f 20 73 61 79 20 71 75 69 74 65 20 70 72 to say quite pr
0d40: 69 6d 69 74 69 76 65 2c 20 65 76 65 6e 20 62 79 imitive, even by
0d50: 20 6d 69 64 2d 31 39 37 30 73 20 6d 69 63 72 6f mid-1970s micro
0d60: 63 6f 6d 70 75 74 65 72 20 73 74 61 6e 64 61 72 computer standar
0d70: 64 73 2e 20 49 20 74 72 69 65 64 20 74 6f 20 73 ds. I tried to s
0d80: 74 72 75 63 74 75 72 65 20 74 68 65 20 61 62 6f tructure the abo
0d90: 76 65 20 70 72 6f 67 72 61 6d 20 77 69 74 68 20 ve program with
0da0: 74 77 6f 20 60 4e 45 58 54 60 20 73 74 61 74 65 two `NEXT` state
0db0: 6d 65 6e 74 73 2c 20 6f 6e 65 20 66 6f 72 20 74 ments, one for t
0dc0: 68 65 20 60 41 60 20 61 6e 64 20 60 42 60 20 63 he `A` and `B` c
0dd0: 6f 64 65 20 70 61 74 68 73 2c 20 77 68 69 63 68 ode paths, which
0de0: 20 79 69 65 6c 64 65 64 20 74 68 65 20 73 75 70 yielded the sup
0df0: 65 72 2d 68 65 6c 70 66 75 6c 20 60 4e 46 60 20 er-helpful `NF`
0e00: 65 72 72 6f 72 2c 20 77 68 69 63 68 20 79 6f 75 error, which you
0e10: 20 61 72 65 20 6d 65 61 6e 74 20 74 6f 20 75 6e are meant to un
0e20: 64 65 72 73 74 61 6e 64 20 6d 65 61 6e 73 20 60 derstand means `
0e30: 4e 45 58 54 20 77 69 74 68 6f 75 74 20 46 4f 52 NEXT without FOR
0e40: 60 2e 20 41 6e 64 20 6e 65 76 65 72 20 6d 69 6e `. And never min
0e50: 64 20 74 68 61 74 20 69 74 27 73 20 6d 69 73 6c d that it's misl
0e60: 65 61 64 69 6e 67 2c 20 73 69 6e 63 65 20 6f 66 eading, since of
0e70: 20 63 6f 75 72 73 65 20 74 68 65 72 65 20 2a 69 course there *i
0e80: 73 2a 20 61 20 60 46 4f 52 60 20 73 74 61 74 65 s* a `FOR` state
0e90: 6d 65 6e 74 2c 20 72 69 67 68 74 20 74 68 65 72 ment, right ther
0ea0: 65 20 6f 6e 20 6c 69 6e 65 20 31 30 2e 0d 0a 0d e on line 10....
0eb0: 0a 4a 75 73 74 20 61 73 20 77 69 74 68 20 74 68 .Just as with th
0ec0: 65 20 50 41 4c 38 20 61 73 73 65 6d 62 6c 79 20 e PAL8 assembly
0ed0: 6c 61 6e 67 75 61 67 65 20 76 65 72 73 69 6f 6e language version
0ee0: 2c 20 4f 53 2f 38 20 42 41 53 49 43 20 68 61 73 , OS/8 BASIC has
0ef0: 20 6e 6f 20 6d 6f 64 75 6c 6f 20 6f 70 65 72 61 no modulo opera
0f00: 74 6f 72 2c 20 73 6f 20 49 20 68 61 64 20 74 6f tor, so I had to
0f10: 20 72 65 73 6f 72 74 20 74 6f 20 66 6c 6f 61 74 resort to float
0f20: 69 6e 67 2d 70 6f 69 6e 74 20 61 72 69 74 68 6d ing-point arithm
0f30: 65 74 69 63 20 77 69 74 68 20 74 72 75 6e 63 61 etic with trunca
0f40: 74 69 6f 6e 20 74 6f 20 64 65 74 65 63 74 20 61 tion to detect a
0f50: 6e 20 65 76 65 6e 20 64 69 76 69 73 69 6f 6e 2e n even division.
0f60: 20 54 68 69 73 20 6d 61 6b 65 73 20 6d 65 20 75 This makes me u
0f70: 6e 65 61 73 79 2c 20 62 75 74 20 69 74 20 67 69 neasy, but it gi
0f80: 76 65 73 20 74 68 65 20 72 69 67 68 74 20 61 6e ves the right an
0f90: 73 77 65 72 2c 20 73 6f 20 63 6c 65 61 72 6c 79 swer, so clearly
0fa0: 20 49 20 68 61 76 65 20 65 6e 6f 75 67 68 20 70 I have enough p
0fb0: 72 65 63 69 73 69 6f 6e 20 74 6f 20 70 75 6c 6c recision to pull
0fc0: 20 74 68 69 73 20 6f 66 66 2c 20 61 74 20 6c 65 this off, at le
0fd0: 61 73 74 20 66 6f 72 20 74 68 65 20 31 2e 2e 39 ast for the 1..9
0fe0: 39 39 20 63 61 73 65 2e 0d 0a 0d 0a 49 20 61 6c 99 case.....I al
0ff0: 73 6f 20 6e 6f 74 69 63 65 64 20 74 68 61 74 20 so noticed that
1000: 4f 53 2f 38 20 42 41 53 49 43 20 75 73 65 73 20 OS/8 BASIC uses
1010: 74 68 65 20 62 61 63 6b 73 6c 61 73 68 20 63 68 the backslash ch
1020: 61 72 61 63 74 65 72 20 69 6e 73 74 65 61 64 20 aracter instead
1030: 6f 66 20 61 20 63 6f 6c 6f 6e 20 66 6f 72 20 6d of a colon for m
1040: 75 6c 74 69 70 6c 65 20 73 74 61 74 65 6d 65 6e ultiple statemen
1050: 74 73 20 6f 6e 20 61 20 6c 69 6e 65 2c 20 77 68 ts on a line, wh
1060: 65 72 65 61 73 20 6d 69 63 72 6f 63 6f 6d 70 75 ereas microcompu
1070: 74 65 72 20 42 41 53 49 43 73 20 6f 66 20 74 68 ter BASICs of th
1080: 65 20 6c 61 74 65 20 31 39 37 30 73 20 74 79 70 e late 1970s typ
1090: 69 63 61 6c 6c 79 20 75 73 65 64 20 74 68 65 20 ically used the
10a0: 63 6f 6c 6f 6e 20 69 6e 73 74 65 61 64 2e 0d 0a colon instead...
10b0: 0d 0a 0d 0a 23 23 20 4f 74 68 65 72 20 50 72 6f ....## Other Pro
10c0: 67 72 61 6d 73 20 69 6e 20 74 68 65 20 53 65 72 grams in the Ser
10d0: 69 65 73 0d 0a 0d 0a 49 27 76 65 20 73 6f 6c 76 ies....I've solv
10e0: 65 64 20 74 68 69 73 20 73 61 6d 65 20 70 72 6f ed this same pro
10f0: 62 6c 65 6d 20 69 6e 20 6d 61 6e 79 20 6f 74 68 blem in many oth
1100: 65 72 20 6c 61 6e 67 75 61 67 65 73 20 61 76 61 er languages ava
1110: 69 6c 61 62 6c 65 20 66 6f 72 20 74 68 65 20 50 ilable for the P
1120: 69 44 50 2d 38 2f 49 3a 0d 0a 0d 0a 2a 20 20 20 iDP-8/I:....*
1130: 5b 43 5d 28 2f 77 69 6b 69 3f 6e 61 6d 65 3d 50 [C](/wiki?name=P
1140: 45 50 30 30 31 2e 43 29 0d 0a 2a 20 20 20 5b 46 EP001.C)..* [F
1150: 4f 52 54 52 41 4e 20 49 49 20 61 6e 64 20 49 56 ORTRAN II and IV
1160: 5d 28 2f 77 69 6b 69 3f 6e 61 6d 65 3d 50 45 50 ](/wiki?name=PEP
1170: 30 30 31 2e 46 54 29 0d 0a 2a 20 20 20 5b 55 2f 001.FT)..* [U/
1180: 57 20 46 4f 43 41 4c 5d 28 2f 77 69 6b 69 3f 6e W FOCAL](/wiki?n
1190: 61 6d 65 3d 50 45 50 30 30 31 2e 46 43 29 0d 0a ame=PEP001.FC)..
11a0: 2a 20 20 20 5b 50 41 4c 38 20 41 73 73 65 6d 62 * [PAL8 Assemb
11b0: 6c 79 5d 28 2f 77 69 6b 69 3f 6e 61 6d 65 3d 50 ly](/wiki?name=P
11c0: 45 50 30 30 31 2e 50 41 29 0d 0a 0d 0a 59 6f 75 EP001.PA)....You
11d0: 20 6d 61 79 20 66 69 6e 64 20 69 74 20 69 6e 74 may find it int
11e0: 65 72 65 73 74 69 6e 67 20 74 6f 20 63 6f 6d 70 eresting to comp
11f0: 61 72 65 20 74 68 65 69 72 20 73 6f 6c 75 74 69 are their soluti
1200: 6f 6e 73 2e 0d 0a 0d 0a 0d 0a 23 23 20 4c 69 63 ons.......## Lic
1210: 65 6e 73 65 0d 0a 0d 0a 43 6f 70 79 72 69 67 68 ense....Copyrigh
1220: 74 20 c2 a9 20 32 30 31 37 20 62 79 20 57 61 72 t © 2017 by War
1230: 72 65 6e 20 59 6f 75 6e 67 2e 20 54 68 69 73 20 ren Young. This
1240: 64 6f 63 75 6d 65 6e 74 20 69 73 20 6c 69 63 65 document is lice
1250: 6e 73 65 64 20 75 6e 64 65 72 20 74 68 65 20 74 nsed under the t
1260: 65 72 6d 73 20 6f 66 20 5b 74 68 65 20 53 49 4d erms of [the SIM
1270: 48 20 6c 69 63 65 6e 73 65 5d 5b 73 6c 5d 2e 0d H license][sl]..
1280: 0a 0d 0a 5b 73 6c 5d 3a 20 68 74 74 70 73 3a 2f ...[sl]: https:/
1290: 2f 74 61 6e 67 65 6e 74 73 6f 66 74 2e 63 6f 6d /tangentsoft.com
12a0: 2f 70 69 64 70 38 69 2f 64 6f 63 2f 74 72 75 6e /pidp8i/doc/trun
12b0: 6b 2f 53 49 4d 48 2d 4c 49 43 45 4e 53 45 2e 6d k/SIMH-LICENSE.m
12c0: 64 0a 5a 20 39 37 62 34 37 39 31 62 61 35 37 65 d.Z 97b4791ba57e
12d0: 31 36 33 61 39 31 63 66 31 39 38 32 64 38 35 32 163a91cf1982d852
12e0: 32 32 30 63 0a 220c.