0000: 23 20 43 43 38 20 4d 61 6e 75 61 6c 0a 0a 0a 23 # CC8 Manual...#
0010: 23 20 41 20 42 69 74 20 6f 66 20 47 72 6f 75 6e # A Bit of Groun
0020: 64 69 6e 67 20 48 69 73 74 6f 72 79 0a 0a 54 68 ding History..Th
0030: 65 20 50 44 50 2d 38 20 77 61 73 20 69 6e 74 72 e PDP-8 was intr
0040: 6f 64 75 63 65 64 20 62 79 20 44 45 43 20 69 6e oduced by DEC in
0050: 20 31 39 36 35 20 77 69 74 68 20 74 68 65 20 69 1965 with the i
0060: 6e 74 65 6e 74 69 6f 6e 20 6f 66 20 62 65 69 6e ntention of bein
0070: 67 20 61 0a 73 6d 61 6c 6c 20 61 6e 64 20 63 68 g a.small and ch
0080: 65 61 70 20 70 72 6f 63 65 73 73 6f 72 20 74 68 eap processor th
0090: 61 74 20 63 6f 75 6c 64 20 62 65 20 75 73 65 64 at could be used
00a0: 20 69 6e 20 61 20 76 61 72 69 65 74 79 20 6f 66 in a variety of
00b0: 20 75 73 65 20 63 61 73 65 73 0a 74 68 61 74 20 use cases.that
00c0: 77 65 72 65 2c 20 61 74 20 74 68 65 20 74 69 6d were, at the tim
00d0: 65 2c 20 63 6f 6e 73 69 64 65 72 65 64 20 6c 6f e, considered lo
00e0: 77 20 65 6e 64 2c 20 63 6f 6d 70 61 72 65 64 20 w end, compared
00f0: 74 6f 20 77 68 65 72 65 20 74 68 65 20 72 65 73 to where the res
0100: 74 0a 6f 66 20 74 68 65 20 6d 69 6e 69 63 6f 6d t.of the minicom
0110: 70 75 74 65 72 20 77 6f 72 6c 64 20 77 61 73 20 puter world was
0120: 61 74 20 74 68 65 20 74 69 6d 65 2e 20 49 74 20 at the time. It
0130: 66 69 6c 6c 65 64 20 6e 69 63 68 65 73 20 61 74 filled niches at
0140: 20 74 68 65 20 74 69 6d 65 0a 74 68 61 74 20 74 the time.that t
0150: 6f 64 61 79 20 77 65 e2 80 99 64 20 66 69 6c 6c oday we’d fill
0160: 20 77 69 74 68 20 65 69 74 68 65 72 20 64 65 73 with either des
0170: 6b 74 6f 70 20 63 6f 6d 70 75 74 65 72 73 20 6f ktop computers o
0180: 72 20 65 6d 62 65 64 64 65 64 0a 70 72 6f 63 65 r embedded.proce
0190: 73 73 6f 72 73 2e 20 54 68 61 74 20 6d 61 6b 65 ssors. That make
01a0: 73 20 74 68 65 20 50 44 50 2d 38 20 74 68 65 20 s the PDP-8 the
01b0: 73 70 69 72 69 74 75 61 6c 20 61 6e 63 65 73 74 spiritual ancest
01c0: 6f 72 20 6f 66 20 74 68 65 20 69 4d 61 63 20 49 or of the iMac I
01d0: e2 80 99 6d 0a 74 79 70 69 6e 67 20 74 68 69 73 ’m.typing this
01e0: 20 6f 6e 20 61 6e 64 20 6f 66 20 74 68 65 20 52 on and of the R
01f0: 61 73 70 62 65 72 72 79 20 50 69 20 74 68 69 73 aspberry Pi this
0200: 20 73 6f 66 74 77 61 72 65 20 69 73 20 69 6e 74 software is int
0210: 65 6e 64 65 64 20 74 6f 20 72 75 6e 0a 6f 6e 2e ended to run.on.
0220: 0a 0a 54 68 65 20 50 69 44 50 2d 38 2f 49 20 70 ..The PiDP-8/I p
0230: 72 6f 6a 65 63 74 20 69 73 20 70 61 72 74 20 6f roject is part o
0240: 66 20 61 6e 20 65 66 66 6f 72 74 20 74 6f 20 70 f an effort to p
0250: 72 65 76 65 6e 74 20 74 68 65 20 50 44 50 2d 38 revent the PDP-8
0260: 20 66 72 6f 6d 0a 73 6c 69 64 69 6e 67 20 69 6e from.sliding in
0270: 74 6f 20 75 6e 64 65 73 65 72 76 65 64 20 6f 62 to undeserved ob
0280: 73 63 75 72 69 74 79 2e 20 57 68 65 74 68 65 72 scurity. Whether
0290: 20 79 6f 75 20 63 6f 6e 73 69 64 65 72 20 69 74 you consider it
02a0: 20 74 68 65 20 61 6e 63 65 73 74 6f 72 0a 6f 66 the ancestor.of
02b0: 20 74 68 65 20 64 65 73 6b 74 6f 70 20 63 6f 6d the desktop com
02c0: 70 75 74 65 72 20 6f 72 20 74 68 65 20 65 6d 62 puter or the emb
02d0: 65 64 64 65 64 20 70 72 6f 63 65 73 73 6f 72 2c edded processor,
02e0: 20 69 74 20 69 73 20 61 20 6d 61 63 68 69 6e 65 it is a machine
02f0: 20 77 6f 72 74 68 0a 75 6e 64 65 72 73 74 61 6e worth.understan
0300: 64 69 6e 67 2e 0a 0a 54 68 65 20 50 44 50 2d 38 ding...The PDP-8
0310: 20 77 61 73 20 72 6f 75 67 68 6c 79 20 63 6f 6e was roughly con
0320: 74 65 6d 70 6f 72 61 6e 65 6f 75 73 20 77 69 74 temporaneous wit
0330: 68 20 61 20 6d 75 63 68 20 6d 6f 72 65 20 66 61 h a much more fa
0340: 6d 6f 75 73 20 6d 61 63 68 69 6e 65 2c 0a 74 68 mous machine,.th
0350: 65 20 50 44 50 2d 31 31 2c 20 75 70 6f 6e 20 77 e PDP-11, upon w
0360: 68 69 63 68 20 74 68 65 20 43 20 70 72 6f 67 72 hich the C progr
0370: 61 6d 6d 69 6e 67 20 6c 61 6e 67 75 61 67 65 20 amming language
0380: 77 61 73 20 63 72 65 61 74 65 64 2e 20 41 6c 74 was created. Alt
0390: 68 6f 75 67 68 0a 61 20 6c 6f 77 2d 65 6e 64 20 hough.a low-end
03a0: 50 44 50 2d 31 31 20 69 73 20 6d 6f 72 65 20 70 PDP-11 is more p
03b0: 6f 77 65 72 66 75 6c 20 74 68 61 6e 20 65 76 65 owerful than eve
03c0: 6e 20 61 20 68 69 67 68 2d 65 6e 64 20 50 44 50 n a high-end PDP
03d0: 2d 38 2c 20 74 68 65 20 66 61 63 74 0a 74 68 61 -8, the fact.tha
03e0: 74 20 74 68 65 69 72 20 63 6f 6d 6d 65 72 63 69 t their commerci
03f0: 61 6c 20 6c 69 66 65 74 69 6d 65 73 20 6f 76 65 al lifetimes ove
0400: 72 6c 61 70 70 65 64 20 62 79 20 73 6f 20 6d 61 rlapped by so ma
0410: 6e 79 20 79 65 61 72 73 20 6d 61 64 65 20 6f 6e ny years made on
0420: 65 20 6f 66 0a 75 73 20 28 49 61 6e 20 53 63 68 e of.us (Ian Sch
0430: 6f 66 69 65 6c 64 29 20 77 6f 6e 64 65 72 20 69 ofield) wonder i
0440: 66 20 74 68 65 20 50 44 50 2d 38 20 63 6f 75 6c f the PDP-8 coul
0450: 64 20 61 6c 73 6f 20 73 75 70 70 6f 72 74 20 61 d also support a
0460: 20 43 20 63 6f 6d 70 69 6c 65 72 2e 0a 0a 54 68 C compiler...Th
0470: 65 20 66 69 72 73 74 20 69 6d 70 6c 65 6d 65 6e e first implemen
0480: 74 61 74 69 6f 6e 20 6f 66 20 43 20 77 61 73 20 tation of C was
0490: 6f 6e 20 74 68 65 20 50 44 50 2d 31 31 20 61 73 on the PDP-11 as
04a0: 20 70 61 72 74 20 6f 66 20 74 68 65 20 65 61 72 part of the ear
04b0: 6c 79 0a 77 6f 72 6b 20 6f 6e 20 74 68 65 20 55 ly.work on the U
04c0: 6e 69 78 20 6f 70 65 72 61 74 69 6e 67 20 73 79 nix operating sy
04d0: 73 74 65 6d 2c 20 61 6e 64 20 69 74 20 77 61 73 stem, and it was
04e0: 20 69 6e 69 74 69 61 6c 6c 79 20 75 73 65 64 20 initially used
04f0: 74 6f 20 77 72 69 74 65 0a 73 79 73 74 65 6d 20 to write.system
0500: 75 74 69 6c 69 74 69 65 73 20 74 68 61 74 20 6f utilities that o
0510: 74 68 65 72 77 69 73 65 20 77 6f 75 6c 64 20 68 therwise would h
0520: 61 76 65 20 62 65 65 6e 20 77 72 69 74 74 65 6e ave been written
0530: 20 69 6e 20 61 73 73 65 6d 62 6c 79 2e 20 41 20 in assembly. A
0540: 43 0a 6c 61 6e 67 75 61 67 65 20 63 6f 6d 70 69 C.language compi
0550: 6c 65 72 20 66 69 72 73 74 20 61 70 70 65 61 72 ler first appear
0560: 65 64 20 70 75 62 6c 69 63 6c 79 20 69 6e 20 56 ed publicly in V
0570: 65 72 73 69 6f 6e 20 32 20 55 6e 69 78 2c 20 72 ersion 2 Unix, r
0580: 65 6c 65 61 73 65 64 0a 6c 61 74 65 72 20 69 6e eleased.later in
0590: 20 31 39 37 32 2e 20 4d 75 63 68 20 6f 66 20 50 1972. Much of P
05a0: 44 50 2d 31 31 20 55 6e 69 78 20 72 65 6d 61 69 DP-11 Unix remai
05b0: 6e 65 64 20 77 72 69 74 74 65 6e 20 69 6e 20 61 ned written in a
05c0: 73 73 65 6d 62 6c 79 20 75 6e 74 69 6c 0a 69 74 ssembly until.it
05d0: 73 20 64 65 76 65 6c 6f 70 65 72 73 20 64 65 63 s developers dec
05e0: 69 64 65 64 20 74 6f 20 72 65 77 72 69 74 65 20 ided to rewrite
05f0: 74 68 65 20 6f 70 65 72 61 74 69 6e 67 20 73 79 the operating sy
0600: 73 74 65 6d 20 69 6e 20 43 2c 20 66 6f 72 20 56 stem in C, for V
0610: 65 72 73 69 6f 6e 0a 34 20 55 6e 69 78 2c 20 72 ersion.4 Unix, r
0620: 65 6c 65 61 73 65 64 20 69 6e 20 31 39 37 33 2e eleased in 1973.
0630: 20 54 68 61 74 20 64 65 63 69 73 69 6f 6e 20 61 That decision a
0640: 6c 6c 6f 77 65 64 20 55 6e 69 78 20 74 6f 20 62 llowed Unix to b
0650: 65 20 72 65 6c 61 74 69 76 65 6c 79 0a 65 61 73 e relatively.eas
0660: 69 6c 79 20 70 6f 72 74 65 64 20 74 6f 20 61 20 ily ported to a
0670: 77 68 6f 6c 6c 79 20 64 69 66 66 65 72 65 6e 74 wholly different
0680: 20 70 6c 61 74 66 6f 72 6d 20 e2 80 94 20 74 68 platform — th
0690: 65 20 49 6e 74 65 72 64 61 74 61 20 38 2f 33 32 e Interdata 8/32
06a0: 20 e2 80 94 20 69 6e 0a 31 39 37 38 20 62 79 20 — in.1978 by
06b0: 77 72 69 74 69 6e 67 20 61 20 6e 65 77 20 63 6f writing a new co
06c0: 64 65 20 67 65 6e 65 72 61 74 6f 72 20 66 6f 72 de generator for
06d0: 20 74 68 65 20 43 20 63 6f 6d 70 69 6c 65 72 2c the C compiler,
06e0: 20 74 68 65 6e 0a 63 72 6f 73 73 2d 63 6f 6d 70 then.cross-comp
06f0: 69 6c 69 6e 67 20 65 76 65 72 79 74 68 69 6e 67 iling everything
0700: 2e 20 54 68 61 74 20 73 75 63 63 65 73 73 20 69 . That success i
0710: 6e 20 70 6f 72 74 69 6e 67 20 55 6e 69 78 20 6c n porting Unix l
0720: 65 64 20 74 6f 20 43 e2 80 99 73 20 6f 77 6e 0a ed to C’s own.
0730: 73 75 63 63 65 73 73 20 66 69 72 73 74 20 61 73 success first as
0740: 20 61 20 73 79 73 74 65 6d 73 20 70 72 6f 67 72 a systems progr
0750: 61 6d 6d 69 6e 67 20 6c 61 6e 67 75 61 67 65 2c amming language,
0760: 20 61 6e 64 20 74 68 65 6e 20 6c 61 74 65 72 20 and then later
0770: 61 73 20 61 0a 67 65 6e 65 72 61 6c 2d 70 75 72 as a.general-pur
0780: 70 6f 73 65 20 70 72 6f 67 72 61 6d 6d 69 6e 67 pose programming
0790: 20 6c 61 6e 67 75 61 67 65 2e 0a 0a 41 6c 74 68 language...Alth
07a0: 6f 75 67 68 20 77 65 20 61 72 65 20 6e 6f 74 20 ough we are not
07b0: 6c 69 6b 65 6c 79 20 74 6f 20 75 73 65 20 43 43 likely to use CC
07c0: 38 20 74 6f 20 77 72 69 74 65 20 61 20 70 6f 72 8 to write a por
07d0: 74 61 62 6c 65 20 6f 70 65 72 61 74 69 6e 67 0a table operating.
07e0: 73 79 73 74 65 6d 20 66 6f 72 20 74 68 65 20 50 system for the P
07f0: 44 50 2d 38 2c 20 69 74 20 69 73 20 70 6f 77 65 DP-8, it is powe
0800: 72 66 75 6c 20 65 6e 6f 75 67 68 20 74 6f 20 66 rful enough to f
0810: 69 6c 6c 20 43 e2 80 99 73 20 6f 72 69 67 69 6e ill C’s origin
0820: 61 6c 20 6e 69 63 68 65 0a 69 6e 20 77 72 69 74 al niche.in writ
0830: 69 6e 67 20 73 79 73 74 65 6d 20 75 74 69 6c 69 ing system utili
0840: 74 69 65 73 20 66 6f 72 20 61 20 70 72 65 65 78 ties for a preex
0850: 69 73 74 69 6e 67 20 4f 53 20 77 72 69 74 74 65 isting OS writte
0860: 6e 20 69 6e 20 61 73 73 65 6d 62 6c 79 2e 0a 0a n in assembly...
0870: 0a 23 23 20 57 68 61 74 20 49 73 20 43 43 38 3f .## What Is CC8?
0880: 0a 0a 54 68 65 20 43 43 38 20 73 79 73 74 65 6d ..The CC8 system
0890: 20 69 6e 63 6c 75 64 65 73 20 74 77 6f 20 64 69 includes two di
08a0: 66 66 65 72 65 6e 74 20 63 6f 6d 70 69 6c 65 72 fferent compiler
08b0: 73 2c 20 65 61 63 68 20 6f 66 20 77 68 69 63 68 s, each of which
08c0: 0a 75 6e 64 65 72 73 74 61 6e 64 73 20 61 20 64 .understands a d
08d0: 69 66 66 65 72 65 6e 74 20 64 69 61 6c 65 63 74 ifferent dialect
08e0: 20 6f 66 20 43 3a 0a 0a 31 2e 20 20 41 20 5b 63 of C:..1. A [c
08f0: 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 5d 28 23 ross-compiler](#
0900: 63 72 6f 73 73 29 20 74 68 61 74 20 62 75 69 6c cross) that buil
0910: 64 73 20 61 6e 64 20 72 75 6e 73 20 6f 6e 20 61 ds and runs on a
0920: 6e 79 20 68 6f 73 74 20 63 6f 6d 70 75 74 65 72 ny host computer
0930: 0a 20 20 20 20 77 69 74 68 20 61 20 43 20 63 6f . with a C co
0940: 6d 70 69 6c 65 72 20 74 68 61 74 20 73 74 69 6c mpiler that stil
0950: 6c 20 75 6e 64 65 72 73 74 61 6e 64 73 20 4b 26 l understands K&
0960: 52 20 43 2e 20 54 68 69 73 20 63 6f 6d 70 69 6c R C. This compil
0970: 65 72 0a 20 20 20 20 75 6e 64 65 72 73 74 61 6e er. understan
0980: 64 73 20 6d 6f 73 74 20 6f 66 20 4b 26 52 20 43 ds most of K&R C
0990: 20 69 74 73 65 6c 66 2c 20 77 69 74 68 20 74 68 itself, with th
09a0: 65 20 65 78 63 65 70 74 69 6f 6e 73 20 64 6f 63 e exceptions doc
09b0: 75 6d 65 6e 74 65 64 0a 20 20 20 20 62 65 6c 6f umented. belo
09c0: 77 2e 0a 0a 32 2e 20 20 41 20 5b 6e 61 74 69 76 w...2. A [nativ
09d0: 65 20 4f 53 2f 38 20 63 6f 6d 70 69 6c 65 72 5d e OS/8 compiler]
09e0: 28 23 6e 61 74 69 76 65 29 2c 20 63 72 6f 73 73 (#native), cross
09f0: 2d 63 6f 6d 70 69 6c 65 64 20 6f 6e 20 74 68 65 -compiled on the
0a00: 20 68 6f 73 74 0a 20 20 20 20 6d 61 63 68 69 6e host. machin
0a10: 65 20 74 6f 20 50 44 50 2d 38 20 61 73 73 65 6d e to PDP-8 assem
0a20: 62 6c 79 20 63 6f 64 65 20 62 79 20 74 68 65 20 bly code by the
0a30: 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 2e 20 cross-compiler.
0a40: 54 68 69 73 20 63 6f 6d 70 69 6c 65 72 0a 20 20 This compiler.
0a50: 20 20 69 73 20 5b 71 75 69 74 65 20 6c 69 6d 69 is [quite limi
0a60: 74 65 64 5d 28 23 6e 6c 69 6d 29 20 63 6f 6d 70 ted](#nlim) comp
0a70: 61 72 65 64 20 74 6f 20 74 68 65 20 63 72 6f 73 ared to the cros
0a80: 73 2d 63 6f 6d 70 69 6c 65 72 2e 0a 0a 43 43 38 s-compiler...CC8
0a90: 20 61 6c 73 6f 20 69 6e 63 6c 75 64 65 73 20 5b also includes [
0aa0: 61 20 73 6d 61 6c 6c 20 43 20 6c 69 62 72 61 72 a small C librar
0ab0: 79 5d 28 23 6c 69 62 63 29 20 73 68 61 72 65 64 y](#libc) shared
0ac0: 20 62 79 20 62 6f 74 68 20 63 6f 6d 70 69 6c 65 by both compile
0ad0: 72 73 2e 0a 0a 0a 23 23 20 43 43 38 e2 80 99 73 rs....## CC8’s
0ae0: 20 44 65 76 65 6c 6f 70 6d 65 6e 74 61 6c 20 53 Developmental S
0af0: 70 61 72 6b 73 0a 0a 54 68 65 20 6c 61 73 74 20 parks..The last
0b00: 68 69 67 68 2d 6c 65 76 65 6c 20 6c 61 6e 67 75 high-level langu
0b10: 61 67 65 20 63 6f 6d 70 69 6c 65 72 20 74 6f 20 age compiler to
0b20: 62 65 20 61 74 74 65 6d 70 74 65 64 20 66 6f 72 be attempted for
0b30: 20 74 68 65 20 50 44 50 2d 38 2c 20 61 73 0a 66 the PDP-8, as.f
0b40: 61 72 20 61 73 20 74 68 69 73 20 64 6f 63 75 6d ar as this docum
0b50: 65 6e 74 e2 80 99 73 20 61 75 74 68 6f 72 73 20 ent’s authors
0b60: 61 72 65 20 61 77 61 72 65 2c 20 77 61 73 20 50 are aware, was P
0b70: 61 73 63 61 6c 20 69 6e 20 31 39 37 39 20 62 79 ascal in 1979 by
0b80: 20 48 65 69 6e 7a 0a 53 74 65 67 62 61 75 65 72 Heinz.Stegbauer
0b90: 2e 0a 0a 49 6e 20 6d 6f 72 65 20 72 65 63 65 6e ...In more recen
0ba0: 74 20 74 69 6d 65 73 2c 20 56 69 6e 63 65 20 53 t times, Vince S
0bb0: 6c 79 6e 67 73 74 61 64 20 61 6e 64 20 50 61 6f lyngstad and Pao
0bc0: 6c 6f 20 4d 61 66 66 65 69 20 77 72 6f 74 65 20 lo Maffei wrote
0bd0: 61 20 43 0a 63 72 6f 73 73 2d 63 6f 6d 70 69 6c a C.cross-compil
0be0: 65 72 20 62 61 73 65 64 20 6f 6e 20 52 6f 6e 20 er based on Ron
0bf0: 43 61 69 6e e2 80 99 73 20 53 6d 61 6c 6c 2d 43 Cain’s Small-C
0c00: 20 75 73 69 6e 67 20 61 20 56 4d 20 61 70 70 72 using a VM appr
0c10: 6f 61 63 68 2e 20 5b 54 68 69 73 0a 63 6f 64 65 oach. [This.code
0c20: 5d 5b 73 6d 73 5d 20 69 73 20 6d 6f 73 74 20 63 ][sms] is most c
0c30: 65 72 74 61 69 6e 6c 79 20 77 6f 72 74 68 20 65 ertainly worth e
0c40: 78 61 6d 69 6e 69 6e 67 2c 20 61 6e 64 20 77 65 xamining, and we
0c50: 20 61 72 65 20 64 65 6c 69 67 68 74 65 64 20 74 are delighted t
0c60: 6f 0a 61 63 6b 6e 6f 77 6c 65 64 67 65 20 74 68 o.acknowledge th
0c70: 69 73 20 77 6f 72 6b 20 61 73 20 77 65 20 68 61 is work as we ha
0c80: 76 65 20 75 73 65 64 20 73 6f 6d 65 20 6f 66 20 ve used some of
0c90: 74 68 65 69 72 20 43 20 6c 69 62 72 61 72 79 20 their C library
0ca0: 63 6f 64 65 20 69 6e 0a 74 68 69 73 20 70 72 6f code in.this pro
0cb0: 6a 65 63 74 2e 0a 0a 46 69 6e 61 6c 6c 79 2c 20 ject...Finally,
0cc0: 77 65 20 77 6f 75 6c 64 20 6c 69 6b 65 20 74 6f we would like to
0cd0: 20 72 65 66 65 72 20 74 68 65 20 72 65 61 64 65 refer the reade
0ce0: 72 20 74 6f 20 5b 46 61 62 72 69 63 65 20 42 65 r to [Fabrice Be
0cf0: 6c 6c 61 72 64 e2 80 99 73 0a 4f 54 43 43 5d 5b llard’s.OTCC][
0d00: 6f 74 63 63 5d 2e 20 41 6c 74 68 6f 75 67 68 20 otcc]. Although
0d10: 69 74 20 74 61 72 67 65 74 73 20 74 68 65 20 69 it targets the i
0d20: 33 38 36 2c 20 69 74 20 77 61 73 20 74 68 69 73 386, it was this
0d30: 20 62 69 74 20 6f 66 20 72 65 6d 61 72 6b 61 62 bit of remarkab
0d40: 6c 65 0a 73 6f 66 74 77 61 72 65 20 74 68 61 74 le.software that
0d50: 20 73 75 67 67 65 73 74 65 64 20 74 68 61 74 20 suggested that
0d60: 74 68 65 72 65 20 6d 61 79 20 62 65 20 61 20 63 there may be a c
0d70: 68 61 6e 63 65 20 74 6f 20 69 6d 70 6c 65 6d 65 hance to impleme
0d80: 6e 74 20 61 20 6e 61 74 69 76 65 0a 50 44 50 2d nt a native.PDP-
0d90: 38 20 63 6f 6d 70 69 6c 65 72 2e 0a 0a 5b 6f 74 8 compiler...[ot
0da0: 63 63 5d 3a 20 68 74 74 70 73 3a 2f 2f 62 65 6c cc]: https://bel
0db0: 6c 61 72 64 2e 6f 72 67 2f 6f 74 63 63 2f 0a 5b lard.org/otcc/.[
0dc0: 73 6d 73 5d 3a 20 20 68 74 74 70 3a 2f 2f 73 6f sms]: http://so
0dd0: 2d 6d 75 63 68 2d 73 74 75 66 66 2e 63 6f 6d 2f -much-stuff.com/
0de0: 70 64 70 38 2f 43 2f 43 2e 70 68 70 0a 0a 0a 23 pdp8/C/C.php...#
0df0: 23 20 52 65 71 75 69 72 65 6d 65 6e 74 73 0a 0a # Requirements..
0e00: 54 68 65 20 43 43 38 20 73 79 73 74 65 6d 20 67 The CC8 system g
0e10: 65 6e 65 72 61 6c 6c 79 20 61 73 73 75 6d 65 73 enerally assumes
0e20: 20 74 68 65 20 61 76 61 69 6c 61 62 69 6c 69 74 the availabilit
0e30: 79 20 6f 66 3a 0a 0a 2a 20 20 20 5b 41 74 20 6c y of:..* [At l
0e40: 65 61 73 74 20 31 36 26 6e 62 73 70 3b 6b 57 6f east 16 kWo
0e50: 72 64 73 20 6f 66 20 63 6f 72 65 5d 28 23 6d 65 rds of core](#me
0e60: 6d 6f 72 79 29 20 61 74 20 72 75 6e 20 74 69 6d mory) at run tim
0e70: 65 20 66 6f 72 20 70 72 6f 67 72 61 6d 73 0a 20 e for programs.
0e80: 20 20 20 63 6f 6d 70 69 6c 65 64 20 77 69 74 68 compiled with
0e90: 20 43 43 38 2e 20 20 54 68 65 20 5b 6e 61 74 69 CC8. The [nati
0ea0: 76 65 20 4f 53 2f 38 20 43 43 38 20 63 6f 6d 70 ve OS/8 CC8 comp
0eb0: 69 6c 65 72 20 70 61 73 73 65 73 5d 28 23 6e 63 iler passes](#nc
0ec0: 70 61 73 73 29 0a 20 20 20 20 72 65 71 75 69 72 pass). requir
0ed0: 65 20 32 30 26 6e 62 73 70 3b 6b 57 6f 72 64 73 e 20 kWords
0ee0: 20 74 6f 20 63 6f 6d 70 69 6c 65 20 70 72 6f 67 to compile prog
0ef0: 72 61 6d 73 2e 0a 0a 20 20 20 20 43 43 38 20 70 rams... CC8 p
0f00: 72 6f 76 69 64 65 73 20 6e 6f 20 62 75 69 6c 74 rovides no built
0f10: 2d 69 6e 20 77 61 79 20 74 6f 20 75 73 65 20 6d -in way to use m
0f20: 6f 72 65 20 6d 65 6d 6f 72 79 20 74 68 61 6e 20 ore memory than
0f30: 74 68 69 73 2c 20 73 6f 20 79 6f 75 0a 20 20 20 this, so you.
0f40: 20 77 69 6c 6c 20 70 72 6f 62 61 62 6c 79 20 68 will probably h
0f50: 61 76 65 20 74 6f 20 72 65 73 6f 72 74 20 74 6f ave to resort to
0f60: 20 5b 69 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c [inline assembl
0f70: 79 5d 28 23 61 73 6d 29 20 6f 72 20 46 4f 52 54 y](#asm) or FORT
0f80: 52 41 4e 0a 20 20 20 20 49 49 20 6c 69 62 72 61 RAN. II libra
0f90: 72 79 20 6c 69 6e 6b 61 67 65 20 74 6f 20 67 65 ry linkage to ge
0fa0: 74 20 61 63 63 65 73 73 20 74 6f 20 6d 6f 72 65 t access to more
0fb0: 20 74 68 61 6e 20 31 36 26 6e 62 73 70 3b 6b 57 than 16 kW
0fc0: 6f 72 64 73 20 6f 66 20 63 6f 72 65 2e 0a 0a 2a ords of core...*
0fd0: 20 20 20 41 20 50 44 50 2d 38 2f 65 20 6f 72 20 A PDP-8/e or
0fe0: 68 69 67 68 65 72 20 63 6c 61 73 73 20 70 72 6f higher class pro
0ff0: 63 65 73 73 6f 72 2e 20 20 54 68 65 20 43 43 38 cessor. The CC8
1000: 20 63 6f 6d 70 69 6c 65 72 20 63 6f 64 65 20 61 compiler code a
1010: 6e 64 20 69 74 73 0a 20 20 20 20 5b 4c 49 42 43 nd its. [LIBC
1020: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 5d implementation]
1030: 28 23 6c 69 62 63 29 20 6d 61 6b 65 20 6c 69 62 (#libc) make lib
1040: 65 72 61 6c 20 75 73 65 20 6f 66 20 74 68 65 20 eral use of the
1050: 4d 51 20 72 65 67 69 73 74 65 72 0a 20 20 20 20 MQ register.
1060: 61 6e 64 20 74 68 65 20 42 53 57 20 4f 50 52 20 and the BSW OPR
1070: 69 6e 73 74 72 75 63 74 69 6f 6e 20 69 6e 74 72 instruction intr
1080: 6f 64 75 63 65 64 20 77 69 74 68 20 74 68 65 20 oduced with the
1090: 50 44 50 2d 38 2f 65 2e 0a 0a 20 20 20 20 54 68 PDP-8/e... Th
10a0: 69 73 20 63 6f 64 65 20 77 69 6c 6c 20 6e 6f 74 is code will not
10b0: 20 72 75 6e 20 6f 6e 2c 20 66 6f 72 20 65 78 61 run on, for exa
10c0: 6d 70 6c 65 2c 20 61 20 50 44 50 2d 38 2f 49 20 mple, a PDP-8/I
10d0: 77 69 74 68 20 74 68 65 20 45 41 45 0a 20 20 20 with the EAE.
10e0: 20 6f 70 74 69 6f 6e 20 69 6e 73 74 61 6c 6c 65 option installe
10f0: 64 2c 20 62 65 63 61 75 73 65 20 61 6c 74 68 6f d, because altho
1100: 75 67 68 20 74 68 65 20 45 41 45 20 61 64 64 73 ugh the EAE adds
1110: 20 74 68 65 20 4d 51 20 72 65 67 69 73 74 65 72 the MQ register
1120: 2c 20 69 74 0a 20 20 20 20 64 6f 65 73 20 6e 6f , it. does no
1130: 74 20 67 69 76 65 20 74 68 65 20 6f 6c 64 65 72 t give the older
1140: 20 70 72 6f 63 65 73 73 6f 72 20 74 68 65 20 42 processor the B
1150: 53 57 20 69 6e 73 74 72 75 63 74 69 6f 6e 2e 0a SW instruction..
1160: 0a 20 20 20 20 43 43 38 20 77 6f 72 6b 73 20 6f . CC8 works o
1170: 6e 20 74 68 65 20 50 69 44 50 2d 38 2f 49 20 62 n the PiDP-8/I b
1180: 65 63 61 75 73 65 20 69 74 20 69 73 20 6f 6e 6c ecause it is onl
1190: 79 20 74 68 65 20 66 72 6f 6e 74 20 70 61 6e 65 y the front pane
11a0: 6c 20 74 68 61 74 0a 20 20 20 20 65 6d 75 6c 61 l that. emula
11b0: 74 65 73 20 61 20 50 44 50 2d 38 2f 49 2e 20 54 tes a PDP-8/I. T
11c0: 68 65 20 75 6e 64 65 72 6c 79 69 6e 67 20 53 49 he underlying SI
11d0: 4d 48 20 50 44 50 2d 38 20 73 69 6d 75 6c 61 74 MH PDP-8 simulat
11e0: 6f 72 20 69 73 20 63 61 74 68 6f 6c 69 63 0a 20 or is catholic.
11f0: 20 20 20 69 6e 20 69 74 73 20 73 75 70 70 6f 72 in its suppor
1200: 74 20 66 6f 72 20 50 44 50 2d 38 20 66 61 6d 69 t for PDP-8 fami
1210: 6c 79 20 66 65 61 74 75 72 65 73 3a 20 69 74 20 ly features: it
1220: 64 6f 65 73 6e e2 80 99 74 20 73 69 6d 75 6c 61 doesn’t simula
1230: 74 65 20 61 6e 79 0a 20 20 20 20 73 69 6e 67 6c te any. singl
1240: 65 20 50 44 50 2d 38 20 66 61 6d 69 6c 79 20 6d e PDP-8 family m
1250: 65 6d 62 65 72 20 65 78 63 6c 75 73 69 76 65 6c ember exclusivel
1260: 79 2e 20 49 74 20 69 73 20 70 72 6f 62 61 62 6c y. It is probabl
1270: 79 20 63 6c 6f 73 65 73 74 20 69 6e 0a 20 20 20 y closest in.
1280: 20 62 65 68 61 76 69 6f 72 20 74 6f 20 61 20 68 behavior to a h
1290: 69 67 68 6c 79 20 74 72 69 63 6b 65 64 2d 6f 75 ighly tricked-ou
12a0: 74 20 50 44 50 2d 38 2f 61 2c 20 6d 65 61 6e 69 t PDP-8/a, meani
12b0: 6e 67 20 69 6e 20 70 61 72 74 20 74 68 61 74 20 ng in part that
12c0: 69 74 0a 20 20 20 20 64 6f 65 73 20 73 75 70 70 it. does supp
12d0: 6f 72 74 20 74 68 65 20 4d 51 20 72 65 67 69 73 ort the MQ regis
12e0: 74 65 72 20 61 6e 64 20 74 68 65 20 42 53 57 20 ter and the BSW
12f0: 69 6e 73 74 72 75 63 74 69 6f 6e 2e 0a 0a 20 20 instruction...
1300: 20 20 28 4d 61 6e 79 20 6f 66 20 74 68 65 20 43 (Many of the C
1310: 50 55 20 66 65 61 74 75 72 65 73 20 6f 66 20 74 PU features of t
1320: 68 65 20 53 49 4d 48 20 50 44 50 2d 38 20 73 69 he SIMH PDP-8 si
1330: 6d 75 6c 61 74 6f 72 20 61 72 65 20 68 61 72 64 mulator are hard
1340: 2d 63 6f 64 65 64 0a 20 20 20 20 69 6e 74 6f 20 -coded. into
1350: 74 68 65 20 69 6e 73 74 72 75 63 74 69 6f 6e 20 the instruction
1360: 64 65 63 6f 64 69 6e 67 20 6c 6f 6f 70 2c 20 73 decoding loop, s
1370: 6f 20 74 68 61 74 20 74 68 65 72 65 20 69 73 20 o that there is
1380: 6e 6f 20 77 61 79 20 74 6f 0a 20 20 20 20 64 69 no way to. di
1390: 73 61 62 6c 65 20 74 68 65 6d 20 61 74 20 72 75 sable them at ru
13a0: 6e 20 74 69 6d 65 20 77 69 74 68 20 63 6f 6e 66 n time with conf
13b0: 69 67 75 72 61 74 69 6f 6e 20 64 69 72 65 63 74 iguration direct
13c0: 69 76 65 73 2e 20 49 66 20 79 6f 75 20 68 61 76 ives. If you hav
13d0: 65 0a 20 20 20 20 61 20 50 69 44 50 2d 38 2f 49 e. a PiDP-8/I
13e0: 20 61 6e 64 20 77 65 72 65 20 65 78 70 65 63 74 and were expect
13f0: 69 6e 67 20 61 20 73 74 72 69 63 74 20 50 44 50 ing a strict PDP
1400: 2d 38 2f 49 20 73 69 6d 75 6c 61 74 69 6f 6e 20 -8/I simulation
1410: 75 6e 64 65 72 6e 65 61 74 68 0a 20 20 20 20 74 underneath. t
1420: 68 61 74 20 70 72 65 74 74 79 20 66 72 6f 6e 74 hat pretty front
1430: 20 70 61 6e 65 6c 2c 20 77 65 e2 80 99 72 65 20 panel, we’re
1440: 73 6f 72 72 79 20 74 6f 20 70 6f 70 20 79 6f 75 sorry to pop you
1450: 72 20 62 75 62 62 6c 65 2c 20 62 75 74 20 74 68 r bubble, but th
1460: 65 0a 20 20 20 20 66 61 63 74 20 6f 66 20 74 68 e. fact of th
1470: 65 20 6d 61 74 74 65 72 20 69 73 20 74 68 61 74 e matter is that
1480: 20 61 20 50 69 44 50 2d 38 2f 49 20 69 73 20 61 a PiDP-8/I is a
1490: 20 46 61 6d 69 6c 79 2d 6f 66 2d 38 20 6d 6f 6e Family-of-8 mon
14a0: 67 72 65 6c 2e 29 0a 0a 2a 20 20 20 41 74 20 62 grel.)..* At b
14b0: 75 69 6c 64 20 74 69 6d 65 2c 20 74 68 65 20 4f uild time, the O
14c0: 53 2f 38 20 46 4f 52 54 52 41 4e 20 49 49 2f 53 S/8 FORTRAN II/S
14d0: 41 42 52 20 73 75 62 73 79 73 74 65 6d 20 6d 75 ABR subsystem mu
14e0: 73 74 20 62 65 20 61 76 61 69 6c 61 62 6c 65 2e st be available.
14f0: 0a 0a 2a 20 20 20 41 74 20 72 75 6e 20 74 69 6d ..* At run tim
1500: 65 2c 20 61 6e 79 20 5b 73 74 64 69 6f 5d 28 23 e, any [stdio](#
1510: 66 69 6f 6c 69 6d 29 20 6f 70 65 72 61 74 69 6f fiolim) operatio
1520: 6e 20 69 6e 76 6f 6c 76 69 6e 67 20 66 69 6c 65 n involving file
1530: 20 49 2f 4f 0a 20 20 20 20 61 73 73 75 6d 65 73 I/O. assumes
1540: 20 69 74 20 69 73 20 72 75 6e 6e 69 6e 67 20 61 it is running a
1550: 74 6f 70 20 4f 53 2f 38 2e 20 46 6f 72 20 69 6e top OS/8. For in
1560: 73 74 61 6e 63 65 2c 20 66 69 6c 65 20 6e 61 6d stance, file nam
1570: 65 20 61 72 67 75 6d 65 6e 74 73 0a 20 20 20 20 e arguments.
1580: 74 6f 20 5b 60 66 6f 70 65 6e 28 29 60 5d 28 23 to [`fopen()`](#
1590: 66 6f 70 65 6e 29 20 61 72 65 20 70 61 73 73 65 fopen) are passe
15a0: 64 20 74 6f 20 4f 53 2f 38 20 66 6f 72 20 69 6e d to OS/8 for in
15b0: 74 65 72 70 72 65 74 61 74 69 6f 6e 2e 0a 0a 54 terpretation...T
15c0: 68 65 72 65 20 69 73 20 6c 69 6b 65 6c 79 20 61 here is likely a
15d0: 20 73 75 62 73 65 74 20 6f 66 20 43 43 38 2d 62 subset of CC8-b
15e0: 75 69 6c 74 20 70 72 6f 67 72 61 6d 73 20 77 68 uilt programs wh
15f0: 69 63 68 20 77 69 6c 6c 20 72 75 6e 0a 69 6e 64 ich will run.ind
1600: 65 70 65 6e 64 65 6e 74 6c 79 20 6f 66 20 4f 53 ependently of OS
1610: 2f 38 2c 20 62 75 74 20 74 68 65 20 62 6f 75 6e /8, but the boun
1620: 64 73 20 6f 6e 20 74 68 61 74 20 63 6c 61 73 73 ds on that class
1630: 20 6f 66 20 70 72 6f 67 72 61 6d 73 20 69 73 20 of programs is
1640: 6e 6f 74 0a 63 75 72 72 65 6e 74 6c 79 20 63 6c not.currently cl
1650: 65 61 72 20 74 6f 20 75 73 2e 0a 0a 0a 3c 61 20 ear to us....<a
1660: 69 64 3d 22 63 72 6f 73 73 22 20 6e 61 6d 65 3d id="cross" name=
1670: 22 70 6f 73 69 78 22 3e 3c 2f 61 3e 0a 23 23 20 "posix"></a>.##
1680: 54 68 65 20 43 72 6f 73 73 2d 43 6f 6d 70 69 6c The Cross-Compil
1690: 65 72 0a 0a 54 68 65 20 43 43 38 20 63 72 6f 73 er..The CC8 cros
16a0: 73 2d 63 6f 6d 70 69 6c 65 72 20 69 73 20 74 68 s-compiler is th
16b0: 65 20 5b 53 6d 61 6c 6c 43 2d 38 35 20 43 20 63 e [SmallC-85 C c
16c0: 6f 6d 70 69 6c 65 72 5d 5b 73 63 38 35 5d 20 77 ompiler][sc85] w
16d0: 69 74 68 20 61 20 50 44 50 2d 38 0a 5b 53 41 42 ith a PDP-8.[SAB
16e0: 52 5d 5b 73 61 62 72 5d 20 63 6f 64 65 20 67 65 R][sabr] code ge
16f0: 6e 65 72 61 74 6f 72 20 73 74 72 61 70 70 65 64 nerator strapped
1700: 20 74 6f 20 69 74 73 20 62 61 63 6b 20 65 6e 64 to its back end
1710: 2e 20 54 68 61 74 20 6d 65 61 6e 73 20 74 68 65 . That means the
1720: 20 43 0a 6c 61 6e 67 75 61 67 65 20 64 69 61 6c C.language dial
1730: 65 63 74 20 75 6e 64 65 72 73 74 6f 6f 64 20 62 ect understood b
1740: 79 20 74 68 65 20 43 43 38 20 63 72 6f 73 73 2d y the CC8 cross-
1750: 63 6f 6d 70 69 6c 65 72 20 69 73 20 5b 4b 26 52 compiler is [K&R
1760: 20 43 0a 28 31 39 37 38 29 5d 5b 6b 72 63 5d 20 C.(1978)][krc]
1770: 6d 69 6e 75 73 20 66 75 6e 63 74 69 6f 6e 20 70 minus function p
1780: 6f 69 6e 74 65 72 73 20 61 6e 64 20 74 68 65 20 ointers and the
1790: 60 66 6c 6f 61 74 60 20 61 6e 64 20 60 6c 6f 6e `float` and `lon
17a0: 67 60 20 64 61 74 61 0a 74 79 70 65 73 2e 0a 0a g` data.types...
17b0: 54 68 65 20 63 6f 64 65 20 66 6f 72 20 74 68 69 The code for thi
17c0: 73 20 69 73 20 69 6e 20 74 68 65 20 60 73 72 63 s is in the `src
17d0: 2f 63 63 38 2f 63 72 6f 73 73 60 20 73 75 62 64 /cc8/cross` subd
17e0: 69 72 65 63 74 6f 72 79 20 6f 66 20 74 68 65 20 irectory of the
17f0: 50 69 44 50 2d 38 2f 49 0a 73 6f 75 72 63 65 20 PiDP-8/I.source
1800: 74 72 65 65 2c 20 61 6e 64 20 69 74 20 69 73 20 tree, and it is
1810: 62 75 69 6c 74 20 61 6c 6f 6e 67 20 77 69 74 68 built along with
1820: 20 74 68 65 20 74 6f 70 2d 6c 65 76 65 6c 20 50 the top-level P
1830: 69 44 50 2d 38 2f 49 20 73 6f 66 74 77 61 72 65 iDP-8/I software
1840: 2e 0a 57 68 65 6e 20 69 6e 73 74 61 6c 6c 65 64 ..When installed
1850: 2c 20 74 68 69 73 20 63 6f 6d 70 69 6c 65 72 20 , this compiler
1860: 69 73 20 69 6e 20 79 6f 75 72 20 60 50 41 54 48 is in your `PATH
1870: 60 20 61 73 20 60 63 63 38 60 2e 0a 0a 43 43 38 ` as `cc8`...CC8
1880: 20 61 6c 73 6f 20 69 6e 63 6c 75 64 65 73 20 61 also includes a
1890: 20 5b 73 6d 61 6c 6c 20 43 20 6c 69 62 72 61 72 [small C librar
18a0: 79 5d 28 23 6c 69 62 63 29 20 69 6e 20 74 68 65 y](#libc) in the
18b0: 20 66 69 6c 65 73 0a 60 73 72 63 2f 63 63 38 2f files.`src/cc8/
18c0: 6f 73 38 2f 6c 69 62 63 2e 5b 63 68 5d 60 2c 20 os8/libc.[ch]`,
18d0: 77 68 69 63 68 20 69 73 20 73 68 61 72 65 64 20 which is shared
18e0: 77 69 74 68 20 74 68 65 20 5b 6e 61 74 69 76 65 with the [native
18f0: 20 4f 53 2f 38 0a 63 6f 6d 70 69 6c 65 72 5d 28 OS/8.compiler](
1900: 23 6e 61 74 69 76 65 29 2e 20 54 68 69 73 20 6c #native). This l
1910: 69 62 72 61 72 79 20 63 6f 76 65 72 73 20 6f 6e ibrary covers on
1920: 6c 79 20 61 20 73 6d 61 6c 6c 20 66 72 61 63 74 ly a small fract
1930: 69 6f 6e 20 6f 66 20 77 68 61 74 0a 74 68 65 20 ion of what.the
1940: 4b 26 52 20 43 20 6c 69 62 72 61 72 79 20 64 6f K&R C library do
1950: 65 73 2c 20 69 6e 20 70 61 72 74 20 64 75 65 20 es, in part due
1960: 74 6f 20 73 79 73 74 65 6d 20 72 65 73 6f 75 72 to system resour
1970: 63 65 20 63 6f 6e 73 74 72 61 69 6e 74 73 2e 0a ce constraints..
1980: 0a 49 61 6e 20 53 63 68 6f 66 69 65 6c 64 20 6f .Ian Schofield o
1990: 72 69 67 69 6e 61 6c 6c 79 20 77 72 6f 74 65 20 riginally wrote
19a0: 74 68 65 20 53 41 42 52 20 63 6f 64 65 20 67 65 the SABR code ge
19b0: 6e 65 72 61 74 6f 72 20 61 74 6f 70 20 61 20 76 nerator atop a v
19c0: 65 72 73 69 6f 6e 20 6f 66 0a 52 6f 6e 20 43 61 ersion of.Ron Ca
19d0: 69 6e e2 80 99 73 20 66 61 6d 6f 75 73 20 5b 53 in’s famous [S
19e0: 6d 61 6c 6c 2d 43 20 63 6f 6d 70 69 6c 65 72 5d mall-C compiler]
19f0: 5b 73 63 38 30 5d 2c 20 6f 72 69 67 69 6e 61 6c [sc80], original
1a00: 6c 79 20 70 75 62 6c 69 73 68 65 64 20 69 6e 20 ly published in
1a10: 5b 44 72 0a 44 6f 62 62 e2 80 99 73 20 4a 6f 75 [Dr.Dobb’s Jou
1a20: 72 6e 61 6c 5d 5b 64 64 6a 5d 2c 20 77 69 74 68 rnal][ddj], with
1a30: 20 6c 61 74 65 72 20 76 65 72 73 69 6f 6e 73 20 later versions
1a40: 70 75 62 6c 69 73 68 65 64 20 65 6c 73 65 77 68 published elsewh
1a50: 65 72 65 2e 20 20 57 69 6c 6c 69 61 6d 0a 43 61 ere. William.Ca
1a60: 74 74 65 79 20 6c 61 74 65 72 20 70 6f 72 74 65 ttey later porte
1a70: 64 20 74 68 69 73 20 63 6f 64 65 20 62 61 73 65 d this code base
1a80: 20 74 6f 20 53 6d 61 6c 6c 43 2d 38 35 2c 20 61 to SmallC-85, a
1a90: 20 6c 69 76 69 6e 67 20 70 72 6f 6a 65 63 74 0a living project.
1aa0: 63 75 72 72 65 6e 74 6c 79 20 5b 61 76 61 69 6c currently [avail
1ab0: 61 62 6c 65 20 6f 6e 20 47 69 74 48 75 62 5d 5b able on GitHub][
1ac0: 73 63 38 35 5d 2e 0a 0a 54 68 65 20 43 43 38 20 sc85]...The CC8
1ad0: 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 20 63 cross-compiler c
1ae0: 61 6e 20 73 75 63 63 65 73 73 66 75 6c 6c 79 20 an successfully
1af0: 63 6f 6d 70 69 6c 65 20 69 74 73 65 6c 66 2c 20 compile itself,
1b00: 62 75 74 20 69 74 20 70 72 6f 64 75 63 65 73 0a but it produces.
1b10: 61 20 53 41 42 52 20 61 73 73 65 6d 62 6c 79 20 a SABR assembly
1b20: 66 69 6c 65 20 74 68 61 74 20 69 73 20 74 6f 6f file that is too
1b30: 20 6c 61 72 67 65 20 28 32 38 4b 29 20 74 6f 20 large (28K) to
1b40: 62 65 20 61 73 73 65 6d 62 6c 65 64 20 6f 6e 20 be assembled on
1b50: 74 68 65 0a 50 44 50 2d 38 2e 20 20 54 68 75 73 the.PDP-8. Thus
1b60: 20 5b 74 68 65 20 73 65 70 61 72 61 74 65 20 6e [the separate n
1b70: 61 74 69 76 65 20 63 6f 6d 70 69 6c 65 72 5d 28 ative compiler](
1b80: 23 6e 61 74 69 76 65 29 2e 0a 0a 54 68 65 20 6b #native)...The k
1b90: 65 79 20 6d 6f 64 75 6c 65 20 66 6f 72 20 74 61 ey module for ta
1ba0: 72 67 65 74 69 6e 67 20 53 6d 61 6c 6c 2d 43 20 rgeting Small-C
1bb0: 74 6f 20 74 68 65 20 50 44 50 2d 38 20 69 73 20 to the PDP-8 is
1bc0: 60 63 6f 64 65 38 2e 63 60 2e 20 49 74 0a 64 6f `code8.c`. It.do
1bd0: 65 73 20 74 68 65 20 63 6f 64 65 20 67 65 6e 65 es the code gene
1be0: 72 61 74 69 6f 6e 20 74 6f 20 65 6d 69 74 20 53 ration to emit S
1bf0: 41 42 52 20 61 73 73 65 6d 62 6c 79 20 63 6f 64 ABR assembly cod
1c00: 65 2e 20 48 6f 77 65 76 65 72 2c 20 74 68 65 0a e. However, the.
1c10: 74 61 72 67 65 74 69 6e 67 20 69 73 20 6e 6f 74 targeting is not
1c20: 20 63 6f 6e 66 69 6e 65 64 20 74 6f 20 74 68 61 confined to tha
1c30: 74 20 6f 6e 65 20 66 69 6c 65 2e 20 54 68 65 72 t one file. Ther
1c40: 65 20 69 73 20 63 6f 64 65 20 69 6e 20 76 61 72 e is code in var
1c50: 69 6f 75 73 0a 6f 66 20 74 68 65 20 6f 74 68 65 ious.of the othe
1c60: 72 20 6d 6f 64 75 6c 65 73 20 74 68 61 74 20 69 r modules that i
1c70: 73 20 73 70 65 63 69 66 69 63 20 74 6f 20 74 68 s specific to th
1c80: 65 20 50 44 50 2d 38 20 70 6f 72 74 20 74 68 61 e PDP-8 port tha
1c90: 74 20 73 68 6f 75 6c 64 20 62 65 0a 61 62 73 74 t should be.abst
1ca0: 72 61 63 74 65 64 20 6f 75 74 20 61 6e 64 20 63 racted out and c
1cb0: 6c 65 61 6e 65 64 20 75 70 20 69 6e 20 74 68 65 leaned up in the
1cc0: 20 66 75 6c 6c 6e 65 73 73 20 6f 66 20 74 69 6d fullness of tim
1cd0: 65 2e 0a 0a 5b 43 75 72 72 65 6e 74 6c 79 5d 28 e...[Currently](
1ce0: 2f 74 6b 74 76 69 65 77 3f 6e 61 6d 65 3d 65 31 /tktview?name=e1
1cf0: 66 36 61 35 65 34 66 65 29 2c 20 74 68 65 20 73 f6a5e4fe), the s
1d00: 69 6d 70 6c 65 73 74 20 77 61 79 20 74 6f 20 67 implest way to g
1d10: 65 74 20 53 41 42 52 0a 6f 75 74 70 75 74 73 20 et SABR.outputs
1d20: 66 72 6f 6d 20 74 68 65 20 43 43 38 20 63 72 6f from the CC8 cro
1d30: 73 73 2d 63 6f 6d 70 69 6c 65 72 20 69 6e 74 6f ss-compiler into
1d40: 20 74 68 65 20 50 69 44 50 2d 38 2f 49 20 73 69 the PiDP-8/I si
1d50: 6d 75 6c 61 74 6f 72 20 69 73 20 74 6f 0a 75 73 mulator is to.us
1d60: 65 20 6f 75 72 20 60 6f 73 38 2d 63 70 60 20 70 e our `os8-cp` p
1d70: 72 6f 67 72 61 6d 20 69 6e 20 41 53 43 49 49 20 rogram in ASCII
1d80: 6d 6f 64 65 20 74 6f 20 63 6f 70 79 20 53 41 42 mode to copy SAB
1d90: 52 20 6f 75 74 70 75 74 73 20 66 72 6f 6d 20 74 R outputs from t
1da0: 68 65 0a 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 he.cross-compile
1db0: 72 20 6f 6e 74 6f 20 74 68 65 20 73 69 6d 75 6c r onto the simul
1dc0: 61 74 6f 72 e2 80 99 73 20 64 69 73 6b 20 69 6d ator’s disk im
1dd0: 61 67 65 3a 0a 0a 20 20 20 20 24 20 6f 73 38 2d age:.. $ os8-
1de0: 63 70 20 2d 61 20 2d 72 6b 30 73 20 2f 6f 70 74 cp -a -rk0s /opt
1df0: 2f 70 69 64 70 38 69 2f 73 68 61 72 65 2f 6d 65 /pidp8i/share/me
1e00: 64 69 61 2f 6f 73 38 2f 76 33 64 2e 72 6b 30 35 dia/os8/v3d.rk05
1e10: 20 5c 0a 20 20 20 20 20 20 73 72 63 2f 63 63 38 \. src/cc8
1e20: 2f 65 78 61 6d 70 6c 65 73 2f 70 73 2e 73 62 20 /examples/ps.sb
1e30: 64 73 6b 3a 0a 0a 54 68 61 74 20 72 65 73 75 6c dsk:..That resul
1e40: 74 73 20 69 6e 20 61 20 66 69 6c 65 20 60 44 53 ts in a file `DS
1e50: 4b 3a 50 53 2e 53 42 60 20 77 69 74 68 20 74 68 K:PS.SB` with th
1e60: 65 20 50 4f 53 49 58 20 4c 46 2d 6f 6e 6c 79 20 e POSIX LF-only
1e70: 6c 69 6e 65 20 65 6e 64 69 6e 67 73 0a 74 72 61 line endings.tra
1e80: 6e 73 6c 61 74 65 64 20 74 6f 20 74 68 65 20 43 nslated to the C
1e90: 52 4c 46 20 6c 69 6e 65 20 65 6e 64 69 6e 67 73 RLF line endings
1ea0: 20 4f 53 2f 38 20 77 61 6e 74 73 2e 20 59 6f 75 OS/8 wants. You
1eb0: 20 63 61 6e 20 74 68 65 6e 20 61 73 73 65 6d 62 can then assemb
1ec0: 6c 65 2c 0a 6c 69 6e 6b 2c 20 61 6e 64 20 72 75 le,.link, and ru
1ed0: 6e 20 77 69 74 68 69 6e 20 74 68 65 20 73 69 6d n within the sim
1ee0: 75 6c 61 74 6f 72 2c 20 61 73 20 64 65 73 63 72 ulator, as descr
1ef0: 69 62 65 64 20 5b 62 65 6c 6f 77 5d 28 23 65 78 ibed [below](#ex
1f00: 65 73 29 2e 0a 0a 46 6f 72 20 72 65 6c 61 74 65 es)...For relate
1f10: 64 20 69 64 65 61 73 2c 20 73 65 65 20 74 68 65 d ideas, see the
1f20: 20 50 69 44 50 2d 38 2f 49 20 77 69 6b 69 20 61 PiDP-8/I wiki a
1f30: 72 74 69 63 6c 65 20 e2 80 9c 5b 47 65 74 74 69 rticle “[Getti
1f40: 6e 67 20 54 65 78 74 20 49 6e 5d 5b 67 74 69 5d ng Text In][gti]
1f50: 2e e2 80 9d 0a 0a 5b 64 64 6a 5d 3a 20 20 68 74 .”..[ddj]: ht
1f60: 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 tps://en.wikiped
1f70: 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 44 72 2e 5f ia.org/wiki/Dr._
1f80: 44 6f 62 62 25 32 37 73 5f 4a 6f 75 72 6e 61 6c Dobb%27s_Journal
1f90: 0a 5b 67 74 69 5d 3a 20 20 2f 77 69 6b 69 3f 6e .[gti]: /wiki?n
1fa0: 61 6d 65 3d 47 65 74 74 69 6e 67 2b 54 65 78 74 ame=Getting+Text
1fb0: 2b 49 6e 0a 5b 6b 72 63 5d 3a 20 20 68 74 74 70 +In.[krc]: http
1fc0: 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 s://en.wikipedia
1fd0: 2e 6f 72 67 2f 77 69 6b 69 2f 54 68 65 5f 43 5f .org/wiki/The_C_
1fe0: 50 72 6f 67 72 61 6d 6d 69 6e 67 5f 4c 61 6e 67 Programming_Lang
1ff0: 75 61 67 65 0a 5b 73 61 62 72 5d 3a 20 2f 77 69 uage.[sabr]: /wi
2000: 6b 69 3f 6e 61 6d 65 3d 41 2b 46 69 65 6c 64 2b ki?name=A+Field+
2010: 47 75 69 64 65 2b 74 6f 2b 50 44 50 2d 38 2b 41 Guide+to+PDP-8+A
2020: 73 73 65 6d 62 6c 65 72 73 23 73 61 62 72 0a 5b ssemblers#sabr.[
2030: 73 63 38 30 5d 3a 20 68 74 74 70 73 3a 2f 2f 65 sc80]: https://e
2040: 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f n.wikipedia.org/
2050: 77 69 6b 69 2f 53 6d 61 6c 6c 2d 43 0a 5b 73 63 wiki/Small-C.[sc
2060: 38 35 5d 3a 20 68 74 74 70 73 3a 2f 2f 67 69 74 85]: https://git
2070: 68 75 62 2e 63 6f 6d 2f 6e 63 62 38 35 2f 53 6d hub.com/ncb85/Sm
2080: 61 6c 6c 43 2d 38 35 0a 0a 0a 3c 61 20 69 64 3d allC-85...<a id=
2090: 22 63 70 70 22 3e 3c 2f 61 3e 0a 23 23 23 20 54 "cpp"></a>.### T
20a0: 68 65 20 43 72 6f 73 73 2d 43 6f 6d 70 69 6c 65 he Cross-Compile
20b0: 72 e2 80 99 73 20 50 72 65 70 72 6f 63 65 73 73 r’s Preprocess
20c0: 6f 72 20 46 65 61 74 75 72 65 73 0a 0a 54 68 65 or Features..The
20d0: 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 20 cross-compiler
20e0: 68 61 73 20 72 75 64 69 6d 65 6e 74 61 72 79 20 has rudimentary
20f0: 43 20 70 72 65 70 72 6f 63 65 73 73 6f 72 20 66 C preprocessor f
2100: 65 61 74 75 72 65 73 3a 0a 0a 2a 20 20 20 4c 69 eatures:..* Li
2110: 74 65 72 61 6c 20 60 23 64 65 66 69 6e 65 60 20 teral `#define`
2120: 6f 6e 6c 79 2e 20 20 59 6f 75 20 63 61 6e 6e 6f only. You canno
2130: 74 20 64 65 66 69 6e 65 20 70 61 72 61 6d 65 74 t define paramet
2140: 65 72 69 7a 65 64 20 6d 61 63 72 6f 73 2e 0a 0a erized macros...
2150: 2a 20 20 20 54 68 65 72 65 20 61 72 65 20 6e 6f * There are no
2160: 20 74 6f 6b 65 6e 20 70 61 73 74 69 6e 67 20 28 token pasting (
2170: 60 23 23 60 29 2c 20 73 74 72 69 6e 67 69 7a 61 `##`), stringiza
2180: 74 69 6f 6e 20 28 60 23 60 29 2c 20 6f 72 0a 20 tion (`#`), or.
2190: 20 20 20 63 68 61 72 69 7a 61 74 69 6f 6e 20 28 charization (
21a0: 60 23 40 60 29 20 66 65 61 74 75 72 65 73 2c 20 `#@`) features,
21b0: 74 68 65 72 65 20 62 65 69 6e 67 20 6c 69 74 74 there being litt
21c0: 6c 65 20 70 6f 69 6e 74 20 74 6f 20 74 68 65 73 le point to thes
21d0: 65 0a 20 20 20 20 66 65 61 74 75 65 72 73 20 6f e. featuers o
21e0: 66 20 74 68 65 20 43 20 70 72 65 70 72 6f 63 65 f the C preproce
21f0: 73 73 6f 72 20 77 69 74 68 6f 75 74 20 70 61 72 ssor without par
2200: 61 6d 65 74 65 72 69 7a 65 64 20 6d 61 63 72 6f ameterized macro
2210: 73 2e 0a 0a 2a 20 20 20 60 23 75 6e 64 65 66 60 s...* `#undef`
2220: 20 72 65 6d 6f 76 65 73 20 61 20 73 79 6d 62 6f removes a symbo
2230: 6c 20 70 72 65 76 69 6f 75 73 6c 79 20 64 65 66 l previously def
2240: 69 6e 65 64 20 77 69 74 68 20 60 23 64 65 66 69 ined with `#defi
2250: 6e 65 60 0a 0a 2a 20 20 20 54 68 65 72 65 20 61 ne`..* There a
2260: 72 65 20 6e 6f 20 60 2d 44 60 20 6f 72 20 60 2d re no `-D` or `-
2270: 55 60 20 66 6c 61 67 73 20 74 6f 20 64 65 66 69 U` flags to defi
2280: 6e 65 20 61 6e 64 20 75 6e 64 65 66 69 6e 65 20 ne and undefine
2290: 6d 61 63 72 6f 73 20 66 72 6f 6d 0a 20 20 20 20 macros from.
22a0: 74 68 65 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 the command line
22b0: 2e 0a 0a 2a 20 20 20 60 23 69 6e 63 6c 75 64 65 ...* `#include
22c0: 60 2c 20 62 75 74 20 6f 6e 6c 79 20 66 6f 72 20 `, but only for
22d0: 66 69 6c 65 73 20 69 6e 20 74 68 65 20 63 75 72 files in the cur
22e0: 72 65 6e 74 20 64 69 72 65 63 74 6f 72 79 2e 20 rent directory.
22f0: 20 54 68 65 72 65 20 69 73 0a 20 20 20 20 6e 6f There is. no
2300: 20 69 6e 63 6c 75 64 65 20 70 61 74 68 2c 20 65 include path, e
2310: 69 74 68 65 72 20 68 61 72 64 2d 63 6f 64 65 64 ither hard-coded
2320: 20 77 69 74 68 69 6e 20 74 68 65 20 63 6f 6d 70 within the comp
2330: 69 6c 65 72 20 6f 72 20 6d 6f 64 69 66 69 61 62 iler or modifiab
2340: 6c 65 0a 20 20 20 20 76 69 61 20 74 68 65 20 74 le. via the t
2350: 72 61 64 69 74 69 6f 6e 61 6c 20 60 2d 49 60 20 raditional `-I`
2360: 63 6f 6d 70 69 6c 65 72 20 66 6c 61 67 2e 20 49 compiler flag. I
2370: 74 20 69 73 20 6c 65 67 61 6c 20 74 6f 20 6e 65 t is legal to ne
2380: 73 74 20 60 23 69 6e 63 6c 75 64 65 60 0a 20 20 st `#include`.
2390: 20 20 73 74 61 74 65 6d 65 6e 74 73 2c 20 62 75 statements, bu
23a0: 74 20 74 68 65 20 64 65 70 74 68 20 69 73 20 63 t the depth is c
23b0: 75 72 72 65 6e 74 6c 79 20 6c 69 6d 69 74 65 64 urrently limited
23c0: 20 74 6f 20 33 20 6c 65 76 65 6c 73 2c 20 6d 61 to 3 levels, ma
23d0: 78 69 6d 75 6d 2e 0a 0a 2a 20 20 20 5b 49 6e 6c ximum...* [Inl
23e0: 69 6e 65 20 61 73 73 65 6d 62 6c 79 5d 28 23 61 ine assembly](#a
23f0: 73 6d 29 20 76 69 61 20 60 23 61 73 6d 60 2e 0a sm) via `#asm`..
2400: 0a 2a 20 20 20 60 23 69 66 64 65 66 60 2c 20 60 .* `#ifdef`, `
2410: 23 69 66 6e 64 65 66 60 2c 20 60 23 65 6c 73 65 #ifndef`, `#else
2420: 60 20 61 6e 64 20 60 23 65 6e 64 69 66 60 20 77 ` and `#endif` w
2430: 6f 72 6b 20 61 73 20 65 78 70 65 63 74 65 64 2c ork as expected,
2440: 20 77 69 74 68 69 6e 0a 20 20 20 20 74 68 65 20 within. the
2450: 6c 69 6d 69 74 61 74 69 6f 6e 73 20 6f 6e 20 6d limitations on m
2460: 61 63 72 6f 73 20 67 69 76 65 6e 20 61 62 6f 76 acros given abov
2470: 65 2e 0a 0a 2a 20 20 20 54 68 65 72 65 20 69 73 e...* There is
2480: 20 6e 6f 20 73 75 70 70 6f 72 74 20 66 6f 72 20 no support for
2490: 60 23 69 66 60 2c 20 6e 6f 74 20 65 76 65 6e 20 `#if`, not even
24a0: 66 6f 72 20 73 69 6d 70 6c 65 20 74 68 69 6e 67 for simple thing
24b0: 73 20 6c 69 6b 65 20 60 23 69 66 0a 20 20 20 20 s like `#if.
24c0: 30 60 2c 20 6d 75 63 68 20 6c 65 73 73 20 66 6f 0`, much less fo
24d0: 72 20 65 78 70 72 65 73 73 69 6f 6e 73 20 73 75 r expressions su
24e0: 63 68 20 61 73 20 60 23 69 66 20 64 65 66 69 6e ch as `#if defin
24f0: 65 64 28 58 58 58 29 20 26 26 0a 20 20 20 20 21 ed(XXX) &&. !
2500: 64 65 66 69 6e 65 64 28 59 59 59 29 60 0a 0a 0a defined(YYY)`...
2510: 23 23 23 20 3c 61 20 69 64 3d 22 6e 68 65 61 64 ### <a id="nhead
2520: 22 3e 3c 2f 61 3e 4e 65 63 65 73 73 61 72 79 20 "></a>Necessary
2530: 48 65 61 64 65 72 73 0a 0a 54 68 65 72 65 20 61 Headers..There a
2540: 72 65 20 74 77 6f 20 68 65 61 64 65 72 20 66 69 re two header fi
2550: 6c 65 73 2c 20 66 6f 72 20 75 73 65 20 77 69 74 les, for use wit
2560: 68 20 74 68 65 20 63 72 6f 73 73 2d 63 6f 6d 70 h the cross-comp
2570: 69 6c 65 72 20 6f 6e 6c 79 3a 0a 0a 2a 20 20 20 iler only:..*
2580: 60 6c 69 62 63 2e 68 60 20 e2 80 94 20 44 65 63 `libc.h` — Dec
2590: 6c 61 72 65 73 20 74 68 65 20 65 6e 74 72 79 20 lares the entry
25a0: 70 6f 69 6e 74 73 20 75 73 65 64 20 62 79 20 5b points used by [
25b0: 4c 49 42 43 5d 28 23 6c 69 62 63 29 20 75 73 69 LIBC](#libc) usi
25c0: 6e 67 0a 20 20 20 20 43 43 38 20 5b 6c 69 62 72 ng. CC8 [libr
25d0: 61 72 79 20 6c 69 6e 6b 61 67 65 20 64 69 72 65 ary linkage dire
25e0: 63 74 69 76 65 73 5d 28 23 6c 69 6e 6b 61 67 65 ctives](#linkage
25f0: 29 2e 20 49 66 20 79 6f 75 72 20 70 72 6f 67 72 ). If your progr
2600: 61 6d 20 6d 61 6b 65 73 0a 20 20 20 20 75 73 65 am makes. use
2610: 20 6f 66 20 61 6e 79 20 6c 69 62 72 61 72 79 20 of any library
2620: 66 75 6e 63 74 69 6f 6e 73 2c 20 79 6f 75 20 6d functions, you m
2630: 75 73 74 20 60 23 69 6e 63 6c 75 64 65 60 20 74 ust `#include` t
2640: 68 69 73 20 61 74 20 74 68 65 20 74 6f 70 20 6f his at the top o
2650: 66 0a 20 20 20 20 79 6f 75 72 20 70 72 6f 67 72 f. your progr
2660: 61 6d 2e 0a 0a 2a 20 20 20 60 69 6e 69 74 2e 68 am...* `init.h
2670: 60 20 e2 80 94 20 49 6e 73 65 72 74 73 20 61 20 ` — Inserts a
2680: 62 6c 6f 63 6b 20 6f 66 20 5b 69 6e 6c 69 6e 65 block of [inline
2690: 20 61 73 73 65 6d 62 6c 79 5d 28 23 61 73 6d 29 assembly](#asm)
26a0: 20 73 74 61 72 74 75 70 20 63 6f 64 65 0a 20 20 startup code.
26b0: 20 20 69 6e 74 6f 20 79 6f 75 72 20 70 72 6f 67 into your prog
26c0: 72 61 6d 2c 20 77 68 69 63 68 20 69 6e 69 74 69 ram, which initi
26d0: 61 6c 69 7a 65 73 20 74 68 65 20 70 72 6f 67 72 alizes the progr
26e0: 61 6d 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 2c 20 am environment,
26f0: 73 65 74 73 0a 20 20 20 20 75 70 20 4c 49 42 43 sets. up LIBC
2700: 2c 20 61 6e 64 20 64 65 66 69 6e 65 73 20 61 20 , and defines a
2710: 66 65 77 20 6c 6f 77 2d 6c 65 76 65 6c 20 72 6f few low-level ro
2720: 75 74 69 6e 65 73 2e 20 55 6e 6c 65 73 73 20 79 utines. Unless y
2730: 6f 75 20 6b 6e 6f 77 20 74 68 69 73 0a 20 20 20 ou know this.
2740: 20 66 69 6c 65 e2 80 99 73 20 63 6f 6e 74 65 6e file’s conten
2750: 74 73 20 61 6e 64 20 68 61 76 65 20 64 65 74 65 ts and have dete
2760: 72 6d 69 6e 65 64 20 74 68 61 74 20 79 6f 75 20 rmined that you
2770: 64 6f 20 6e 6f 74 20 6e 65 65 64 20 61 6e 79 20 do not need any
2780: 6f 66 20 77 68 61 74 0a 20 20 20 20 69 74 20 64 of what. it d
2790: 6f 65 73 20 66 6f 72 20 79 6f 75 2c 20 79 6f 75 oes for you, you
27a0: 20 70 72 6f 62 61 62 6c 79 20 63 61 6e 6e 6f 74 probably cannot
27b0: 20 77 72 69 74 65 20 61 20 76 61 6c 69 64 20 43 write a valid C
27c0: 43 38 20 70 72 6f 67 72 61 6d 20 74 68 61 74 0a C8 program that.
27d0: 20 20 20 20 64 6f 65 73 20 6e 6f 74 20 60 23 69 does not `#i
27e0: 6e 63 6c 75 64 65 60 20 74 68 69 73 20 68 65 61 nclude` this hea
27f0: 64 65 72 2e 0a 0a 42 65 63 61 75 73 65 20 74 68 der...Because th
2800: 65 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 e cross-compiler
2810: 20 6c 61 63 6b 73 20 61 6e 20 69 6e 63 6c 75 64 lacks an includ
2820: 65 20 70 61 74 68 20 66 65 61 74 75 72 65 2c 20 e path feature,
2830: 79 6f 75 20 67 65 6e 65 72 61 6c 6c 79 0a 77 61 you generally.wa
2840: 6e 74 20 74 6f 20 73 79 6d 6c 69 6e 6b 20 74 68 nt to symlink th
2850: 65 73 65 20 66 69 6c 65 73 20 74 6f 20 74 68 65 ese files to the
2860: 20 64 69 72 65 63 74 6f 72 79 20 77 68 65 72 65 directory where
2870: 20 79 6f 75 72 20 73 6f 75 72 63 65 20 66 69 6c your source fil
2880: 65 73 0a 61 72 65 2e 20 54 68 69 73 20 69 73 20 es.are. This is
2890: 61 6c 72 65 61 64 79 20 64 6f 6e 65 20 66 6f 72 already done for
28a0: 20 74 68 65 20 43 43 38 20 65 78 61 6d 70 6c 65 the CC8 example
28b0: 73 20 61 6e 64 20 73 75 63 68 2e 0a 0a 49 66 20 s and such...If
28c0: 79 6f 75 20 63 6f 6d 70 61 72 65 20 74 68 65 20 you compare the
28d0: 65 78 61 6d 70 6c 65 73 20 69 6e 20 74 68 65 20 examples in the
28e0: 73 6f 75 72 63 65 20 74 72 65 65 20 28 60 73 72 source tree (`sr
28f0: 63 2f 63 63 38 2f 65 78 61 6d 70 6c 65 73 60 29 c/cc8/examples`)
2900: 20 74 6f 0a 74 68 6f 73 65 20 77 69 74 68 20 75 to.those with u
2910: 70 70 65 72 63 61 73 65 64 20 76 65 72 73 69 6f ppercased versio
2920: 6e 73 20 6f 66 20 74 68 6f 73 65 20 73 61 6d 65 ns of those same
2930: 20 6e 61 6d 65 73 20 6f 6e 20 74 68 65 20 4f 53 names on the OS
2940: 2f 38 20 60 44 53 4b 3a 60 0a 76 6f 6c 75 6d 65 /8 `DSK:`.volume
2950: 2c 20 79 6f 75 e2 80 99 6c 6c 20 6e 6f 74 69 63 , you’ll notic
2960: 65 20 74 68 61 74 20 74 68 65 73 65 20 60 23 69 e that these `#i
2970: 6e 63 6c 75 64 65 60 20 73 74 61 74 65 6d 65 6e nclude` statemen
2980: 74 73 20 77 65 72 65 20 73 74 72 69 70 70 65 64 ts were stripped
2990: 20 6f 75 74 0a 61 73 20 70 61 72 74 20 6f 66 20 out.as part of
29a0: 74 68 65 20 64 69 73 6b 20 70 61 63 6b 20 62 75 the disk pack bu
29b0: 69 6c 64 20 70 72 6f 63 65 73 73 2e 20 54 68 69 ild process. Thi
29c0: 73 20 69 73 20 5b 6e 65 63 65 73 73 61 72 79 5d s is [necessary]
29d0: 28 23 6f 73 38 70 70 29 3b 20 74 68 65 0a 6c 69 (#os8pp); the.li
29e0: 6e 6b 65 64 20 64 6f 63 75 6d 65 6e 74 61 74 69 nked documentati
29f0: 6f 6e 20 74 65 6c 6c 73 20 79 6f 75 20 77 68 79 on tells you why
2a00: 20 61 6e 64 20 68 6f 77 20 74 68 65 20 4f 53 2f and how the OS/
2a10: 38 20 76 65 72 73 69 6f 6e 20 6f 66 20 43 43 38 8 version of CC8
2a20: 20 67 65 74 73 0a 61 77 61 79 20 77 69 74 68 6f gets.away witho
2a30: 75 74 20 61 20 60 23 69 6e 63 6c 75 64 65 60 20 ut a `#include`
2a40: 66 65 61 74 75 72 65 2e 0a 0a 49 66 20 79 6f 75 feature...If you
2a50: 20 6e 65 65 64 20 74 6f 20 77 72 69 74 65 20 43 need to write C
2a60: 20 70 72 6f 67 72 61 6d 73 20 74 68 61 74 20 62 programs that b
2a70: 75 69 6c 64 20 77 69 74 68 20 62 6f 74 68 20 63 uild with both c
2a80: 6f 6d 70 69 6c 65 72 73 2c 20 79 6f 75 20 63 61 ompilers, you ca
2a90: 6e 0a 63 6f 6e 76 65 72 74 20 74 68 65 20 66 69 n.convert the fi
2aa0: 6c 65 73 20 6c 69 6b 65 20 73 6f 3a 0a 0a 20 20 les like so:..
2ab0: 20 20 73 65 64 20 27 2f 5e 23 69 6e 63 6c 75 64 sed '/^#includ
2ac0: 65 2f 64 27 20 3c 20 6d 79 2d 70 72 6f 67 72 61 e/d' < my-progra
2ad0: 6d 2d 63 72 6f 73 73 2e 63 20 3e 20 4d 59 50 52 m-cross.c > MYPR
2ae0: 4f 47 2e 43 0a 0a 0a 3c 61 20 69 64 3d 22 6e 61 OG.C...<a id="na
2af0: 74 69 76 65 22 20 6e 61 6d 65 3d 22 6f 73 38 22 tive" name="os8"
2b00: 3e 3c 2f 61 3e 0a 23 23 20 54 68 65 20 4e 61 74 ></a>.## The Nat
2b10: 69 76 65 20 4f 53 2f 38 20 43 6f 6d 70 69 6c 65 ive OS/8 Compile
2b20: 72 0a 0a 57 68 65 72 65 61 73 20 74 68 65 20 5b r..Whereas the [
2b30: 43 43 38 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c CC8 cross-compil
2b40: 65 72 5d 28 23 63 72 6f 73 73 29 20 69 73 20 62 er](#cross) is b
2b50: 61 73 69 63 61 6c 6c 79 20 6a 75 73 74 20 61 20 asically just a
2b60: 50 44 50 2d 38 20 63 6f 64 65 0a 67 65 6e 65 72 PDP-8 code.gener
2b70: 61 74 6f 72 20 73 74 72 61 70 70 65 64 20 74 6f ator strapped to
2b80: 20 74 68 65 20 70 72 65 65 78 69 73 74 69 6e 67 the preexisting
2b90: 20 53 6d 61 6c 6c 2d 43 20 63 6f 6d 70 69 6c 65 Small-C compile
2ba0: 72 2c 20 74 68 65 20 6e 61 74 69 76 65 20 4f 53 r, the native OS
2bb0: 2f 38 0a 43 43 38 20 63 6f 6d 70 69 6c 65 72 20 /8.CC8 compiler
2bc0: 77 61 73 20 77 72 69 74 74 65 6e 20 66 72 6f 6d was written from
2bd0: 20 73 63 72 61 74 63 68 20 62 79 20 49 61 6e 20 scratch by Ian
2be0: 53 63 68 6f 66 69 65 6c 64 2e 20 49 74 20 67 65 Schofield. It ge
2bf0: 74 73 0a 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 ts.cross-compile
2c00: 64 2c 20 61 73 73 65 6d 62 6c 65 64 2c 20 6c 69 d, assembled, li
2c10: 6e 6b 65 64 2c 20 61 6e 64 20 73 61 76 65 64 20 nked, and saved
2c20: 74 6f 20 74 68 65 20 4f 53 2f 38 20 64 69 73 6b to the OS/8 disk
2c30: 20 70 61 63 6b 73 20 61 73 0a 70 61 72 74 20 6f packs as.part o
2c40: 66 20 74 68 65 20 50 69 44 50 2d 38 2f 49 20 73 f the PiDP-8/I s
2c50: 6f 66 74 77 61 72 65 20 62 75 69 6c 64 20 70 72 oftware build pr
2c60: 6f 63 65 73 73 2e 20 54 68 65 72 65 61 66 74 65 ocess. Thereafte
2c70: 72 2c 20 69 74 20 69 73 20 61 0a 73 74 61 6e 64 r, it is a.stand
2c80: 61 6c 6f 6e 65 20 73 79 73 74 65 6d 20 75 73 69 alone system usi
2c90: 6e 67 20 6f 6e 6c 79 20 4f 53 2f 38 20 72 65 73 ng only OS/8 res
2ca0: 6f 75 72 63 65 73 2e 0a 0a 42 65 63 61 75 73 65 ources...Because
2cb0: 20 74 68 69 73 20 63 6f 6d 70 69 6c 65 72 20 6d this compiler m
2cc0: 75 73 74 20 77 6f 72 6b 20 65 6e 74 69 72 65 6c ust work entirel
2cd0: 79 20 77 69 74 68 69 6e 20 74 68 65 20 73 74 72 y within the str
2ce0: 69 6e 67 65 6e 74 20 6c 69 6d 69 74 73 20 6f 66 ingent limits of
2cf0: 0a 74 68 65 20 50 44 50 2d 38 20 63 6f 6d 70 75 .the PDP-8 compu
2d00: 74 65 72 20 61 72 63 68 69 74 65 63 74 75 72 65 ter architecture
2d10: 20 61 6e 64 20 69 74 73 20 4f 53 2f 38 20 6f 70 and its OS/8 op
2d20: 65 72 61 74 69 6e 67 20 73 79 73 74 65 6d 2c 20 erating system,
2d30: 69 74 20 73 70 65 61 6b 73 0a 61 20 5b 6d 75 63 it speaks.a [muc
2d40: 68 20 73 69 6d 70 6c 65 72 20 64 69 61 6c 65 63 h simpler dialec
2d50: 74 20 6f 66 20 43 5d 28 23 6e 66 65 61 74 29 20 t of C](#nfeat)
2d60: 74 68 61 6e 20 74 68 65 20 63 72 6f 73 73 2d 63 than the cross-c
2d70: 6f 6d 70 69 6c 65 72 2c 20 77 68 69 63 68 0a 67 ompiler, which.g
2d80: 65 74 73 20 74 6f 20 75 73 65 20 79 6f 75 72 20 ets to use your
2d90: 68 6f 73 74 e2 80 99 73 20 6d 75 63 68 20 67 72 host’s much gr
2da0: 65 61 74 65 72 20 72 65 73 6f 75 72 63 65 73 2e eater resources.
2db0: 0a 0a 55 6e 6c 69 6b 65 20 77 69 74 68 20 74 68 ..Unlike with th
2dc0: 65 20 6f 72 69 67 69 6e 61 6c 20 43 43 38 20 73 e original CC8 s
2dd0: 6f 66 74 77 61 72 65 20 64 69 73 74 72 69 62 75 oftware distribu
2de0: 74 69 6f 6e 2c 20 74 68 65 20 50 69 44 50 2d 38 tion, the PiDP-8
2df0: 2f 49 0a 73 6f 66 74 77 61 72 65 20 70 72 6f 6a /I.software proj
2e00: 65 63 74 20 64 6f 65 73 20 6e 6f 74 20 73 68 69 ect does not shi
2e10: 70 20 61 6e 79 20 70 72 65 2d 62 75 69 6c 74 20 p any pre-built
2e20: 43 43 38 20 62 69 6e 61 72 69 65 73 2e 20 20 49 CC8 binaries. I
2e30: 6e 73 74 65 61 64 2c 20 77 65 0a 62 6f 6f 74 73 nstead, we.boots
2e40: 74 72 61 70 20 43 43 38 20 62 69 6e 61 72 69 65 trap CC8 binarie
2e50: 73 20 66 72 6f 6d 20 73 6f 75 72 63 65 20 63 6f s from source co
2e60: 64 65 20 77 69 74 68 20 74 68 65 20 70 6f 77 65 de with the powe
2e70: 72 66 75 6c 0a 5b 60 6f 73 38 2d 72 75 6e 60 5d rful.[`os8-run`]
2e80: 5b 6f 73 38 72 5d 20 73 63 72 69 70 74 69 6e 67 [os8r] scripting
2e90: 20 6c 61 6e 67 75 61 67 65 20 69 6e 74 65 72 70 language interp
2ea0: 72 65 74 65 72 20 61 6e 64 20 74 68 65 20 50 69 reter and the Pi
2eb0: 44 50 2d 38 2f 49 0a 73 6f 66 74 77 61 72 65 20 DP-8/I.software
2ec0: 62 75 69 6c 64 20 73 79 73 74 65 6d 2e 20 20 28 build system. (
2ed0: 59 6f 75 20 63 61 6e 20 73 75 70 70 72 65 73 73 You can suppress
2ee0: 20 74 68 69 73 20 62 79 20 70 61 73 73 69 6e 67 this by passing
2ef0: 20 74 68 65 0a 60 2d 2d 64 69 73 61 62 6c 65 2d the.`--disable-
2f00: 6f 73 38 2d 63 63 38 60 20 6f 70 74 69 6f 6e 20 os8-cc8` option
2f10: 74 6f 20 74 68 65 20 60 63 6f 6e 66 69 67 75 72 to the `configur
2f20: 65 60 20 73 63 72 69 70 74 2e 29 20 54 68 69 73 e` script.) This
2f30: 20 70 72 6f 63 65 73 73 20 69 73 0a 63 6f 6e 74 process is.cont
2f40: 72 6f 6c 6c 65 64 20 62 79 20 74 68 65 20 5b 60 rolled by the [`
2f50: 63 63 38 2d 74 75 35 36 2e 6f 73 38 60 5d 5b 63 cc8-tu56.os8`][c
2f60: 63 74 75 5d 20 73 63 72 69 70 74 2c 20 77 68 69 ctu] script, whi
2f70: 63 68 20 79 6f 75 20 6d 61 79 20 77 61 6e 74 20 ch you may want
2f80: 74 6f 0a 65 78 61 6d 69 6e 65 20 61 6c 6f 6e 67 to.examine along
2f90: 20 77 69 74 68 20 74 68 65 20 60 6f 73 38 2d 72 with the `os8-r
2fa0: 75 6e 60 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f un` documentatio
2fb0: 6e 20 74 6f 20 75 6e 64 65 72 73 74 61 6e 64 20 n to understand
2fc0: 74 68 69 73 0a 70 72 6f 63 65 73 73 20 62 65 74 this.process bet
2fd0: 74 65 72 2e 0a 0a 49 66 20 79 6f 75 20 63 68 61 ter...If you cha
2fe0: 6e 67 65 20 74 68 65 20 4f 53 2f 38 20 43 43 38 nge the OS/8 CC8
2ff0: 20 73 6f 75 72 63 65 20 63 6f 64 65 2c 20 73 61 source code, sa
3000: 79 69 6e 67 20 60 6d 61 6b 65 60 20 61 74 20 74 ying `make` at t
3010: 68 65 20 50 69 44 50 2d 38 2f 49 0a 62 75 69 6c he PiDP-8/I.buil
3020: 64 20 72 6f 6f 74 20 77 69 6c 6c 20 75 70 64 61 d root will upda
3030: 74 65 20 60 62 69 6e 2f 76 33 64 2e 72 6b 30 35 te `bin/v3d.rk05
3040: 60 20 77 69 74 68 20 6e 65 77 20 62 69 6e 61 72 ` with new binar
3050: 69 65 73 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c ies automaticall
3060: 79 2e 0a 0a 42 65 63 61 75 73 65 20 74 68 65 20 y...Because the
3070: 43 43 38 20 6e 61 74 69 76 65 20 63 6f 6d 70 69 CC8 native compi
3080: 6c 65 72 20 69 73 20 63 6f 6d 70 69 6c 65 64 20 ler is compiled
3090: 62 79 20 74 68 65 20 43 43 38 20 2a 63 72 6f 73 by the CC8 *cros
30a0: 73 2a 2d 63 6f 6d 70 69 6c 65 72 2c 0a 74 68 65 s*-compiler,.the
30b0: 20 5b 73 74 61 6e 64 61 72 64 20 6d 65 6d 6f 72 [standard memor
30c0: 79 20 6c 61 79 6f 75 74 5d 28 23 6d 65 6d 6f 72 y layout](#memor
30d0: 79 29 20 61 70 70 6c 69 65 73 20 74 6f 20 62 6f y) applies to bo
30e0: 74 68 2e 20 20 41 6d 6f 6e 67 20 6f 74 68 65 72 th. Among other
30f0: 0a 74 68 69 6e 67 73 2c 20 74 68 69 73 20 6d 65 .things, this me
3100: 61 6e 73 20 65 61 63 68 20 70 61 73 73 20 6f 66 ans each pass of
3110: 20 74 68 65 20 6e 61 74 69 76 65 20 63 6f 6d 70 the native comp
3120: 69 6c 65 72 20 72 65 71 75 69 72 65 73 0a 61 70 iler requires.ap
3130: 70 72 6f 78 69 6d 61 74 65 6c 79 20 32 30 26 6e proximately 20&n
3140: 62 73 70 3b 6b 57 6f 72 64 73 20 6f 66 20 63 6f bsp;kWords of co
3150: 72 65 2e 0a 0a 54 68 65 20 6e 61 74 69 76 65 20 re...The native
3160: 4f 53 2f 38 20 43 43 38 20 63 6f 6d 70 69 6c 65 OS/8 CC8 compile
3170: 72 e2 80 99 73 20 73 6f 75 72 63 65 20 63 6f 64 r’s source cod
3180: 65 20 69 73 20 69 6e 20 74 68 65 20 60 73 72 63 e is in the `src
3190: 2f 63 63 38 2f 6f 73 38 60 0a 73 75 62 64 69 72 /cc8/os8`.subdir
31a0: 65 63 74 6f 72 79 20 6f 66 20 74 68 65 20 50 69 ectory of the Pi
31b0: 44 50 2d 38 2f 49 20 73 6f 66 74 77 61 72 65 20 DP-8/I software
31c0: 64 69 73 74 72 69 62 75 74 69 6f 6e 2e 0a 0a 3c distribution...<
31d0: 61 20 69 64 3d 22 6e 63 70 61 73 73 22 3e 3c 2f a id="ncpass"></
31e0: 61 3e 54 68 65 20 63 6f 6d 70 69 6c 65 72 20 70 a>The compiler p
31f0: 61 73 73 65 73 20 61 72 65 3a 0a 0a 31 2e 20 20 asses are:..1.
3200: 60 63 38 2e 63 60 20 26 72 61 72 72 3b 20 60 63 `c8.c` → `c
3210: 38 2e 73 62 60 20 26 72 61 72 72 3b 20 60 43 43 8.sb` → `CC
3220: 2e 53 56 60 3a 20 54 68 65 20 63 6f 6d 70 69 6c .SV`: The compil
3230: 65 72 20 64 72 69 76 65 72 3a 20 61 63 63 65 70 er driver: accep
3240: 74 73 0a 20 20 20 20 74 68 65 20 69 6e 70 75 74 ts. the input
3250: 20 66 69 6c 65 20 6e 61 6d 65 20 66 72 6f 6d 20 file name from
3260: 74 68 65 20 75 73 65 72 2c 20 64 6f 65 73 20 73 the user, does s
3270: 6f 6d 65 20 5b 72 75 64 69 6d 65 6e 74 61 72 79 ome [rudimentary
3280: 0a 20 20 20 20 70 72 65 70 72 6f 63 65 73 73 69 . preprocessi
3290: 6e 67 5d 28 23 6f 73 38 70 70 29 20 6f 6e 20 69 ng](#os8pp) on i
32a0: 74 2c 20 61 6e 64 20 63 61 6c 6c 73 20 74 68 65 t, and calls the
32b0: 20 66 69 72 73 74 20 70 72 6f 70 65 72 20 63 6f first proper co
32c0: 6d 70 69 6c 65 72 0a 20 20 20 20 70 61 73 73 2c mpiler. pass,
32d0: 20 60 43 43 31 60 2e 0a 0a 32 2e 20 20 60 6e 38 `CC1`...2. `n8
32e0: 2e 63 60 20 26 72 61 72 72 3b 20 60 6e 38 2e 73 .c` → `n8.s
32f0: 62 60 20 26 72 61 72 72 3b 20 60 43 43 31 2e 53 b` → `CC1.S
3300: 56 60 3a 20 54 68 65 20 70 61 72 73 65 72 2f 74 V`: The parser/t
3310: 6f 6b 65 6e 69 73 65 72 20 73 65 63 74 69 6f 6e okeniser section
3320: 0a 20 20 20 20 6f 66 20 74 68 65 20 63 6f 6d 70 . of the comp
3330: 69 6c 65 72 2e 0a 0a 33 2e 20 20 60 70 38 2e 63 iler...3. `p8.c
3340: 60 20 26 72 61 72 72 3b 20 60 70 38 2e 73 62 60 ` → `p8.sb`
3350: 20 26 72 61 72 72 3b 20 60 43 43 32 2e 53 56 60 → `CC2.SV`
3360: 3a 20 54 68 65 20 74 6f 6b 65 6e 20 74 6f 20 53 : The token to S
3370: 41 42 52 20 63 6f 64 65 0a 20 20 20 20 63 6f 6e ABR code. con
3380: 76 65 72 74 65 72 20 73 65 63 74 69 6f 6e 20 6f verter section o
3390: 66 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 2e 0a f the compiler..
33a0: 0a 54 68 65 72 65 20 69 73 20 61 6c 73 6f 20 60 .There is also `
33b0: 6c 69 62 63 2e 63 60 20 26 72 61 72 72 3b 20 60 libc.c` → `
33c0: 6c 69 62 63 2e 73 62 60 20 26 72 61 72 72 3b 20 libc.sb` →
33d0: 60 4c 49 42 43 2e 52 4c 60 2c 20 74 68 65 20 5b `LIBC.RL`, the [
33e0: 43 0a 6c 69 62 72 61 72 79 5d 28 23 6c 69 62 63 C.library](#libc
33f0: 29 20 6c 69 6e 6b 65 64 20 74 6f 20 61 6e 79 20 ) linked to any
3400: 70 72 6f 67 72 61 6d 20 62 75 69 6c 74 20 77 69 program built wi
3410: 74 68 20 43 43 38 2c 20 69 6e 63 6c 75 64 69 6e th CC8, includin
3420: 67 20 74 68 65 0a 70 61 73 73 65 73 20 61 62 6f g the.passes abo
3430: 76 65 2c 20 62 75 74 20 61 6c 73 6f 20 74 6f 20 ve, but also to
3440: 79 6f 75 72 20 6f 77 6e 20 70 72 6f 67 72 61 6d your own program
3450: 73 2e 0a 0a 41 6c 6c 20 6f 66 20 74 68 65 73 65 s...All of these
3460: 20 62 69 6e 61 72 69 65 73 20 65 6e 64 20 75 70 binaries end up
3470: 20 6f 6e 20 74 68 65 20 61 75 74 6f 6d 61 74 69 on the automati
3480: 63 61 6c 6c 79 2d 62 75 69 6c 74 20 4f 53 2f 38 cally-built OS/8
3490: 20 62 6f 6f 74 20 64 69 73 6b 3a 0a 60 43 43 3f boot disk:.`CC?
34a0: 2e 53 56 60 20 6f 6e 20 60 53 59 53 3a 60 2c 20 .SV` on `SYS:`,
34b0: 61 6e 64 20 65 76 65 72 79 74 68 69 6e 67 20 65 and everything e
34c0: 6c 73 65 20 6f 6e 20 60 44 53 4b 3a 60 2c 20 62 lse on `DSK:`, b
34d0: 61 73 65 64 20 6f 6e 20 74 68 65 20 64 65 66 61 ased on the defa
34e0: 75 6c 74 73 0a 6f 75 72 20 4f 53 2f 38 20 64 69 ults.our OS/8 di
34f0: 73 74 72 69 62 75 74 69 6f 6e 20 69 73 20 63 6f stribution is co
3500: 6e 66 69 67 75 72 65 64 20 74 6f 20 75 73 65 20 nfigured to use
3510: 77 68 65 6e 20 73 65 65 6b 69 6e 67 20 6f 75 74 when seeking out
3520: 20 66 69 6c 65 73 2e 0a 0a 49 6e 70 75 74 20 70 files...Input p
3530: 72 6f 67 72 61 6d 73 20 73 68 6f 75 6c 64 20 67 rograms should g
3540: 6f 20 6f 6e 20 60 44 53 4b 3a 60 2e 20 43 6f 6d o on `DSK:`. Com
3550: 70 69 6c 65 72 20 6f 75 74 70 75 74 73 20 61 72 piler outputs ar
3560: 65 20 61 6c 73 6f 20 70 6c 61 63 65 64 20 6f 6e e also placed on
3570: 0a 60 44 53 4b 3a 60 2e 0a 0a 5b 63 63 74 75 5d .`DSK:`...[cctu]
3580: 3a 20 2f 66 69 6c 65 3f 66 6e 3d 6d 65 64 69 61 : /file?fn=media
3590: 2f 6f 73 38 2f 73 63 72 69 70 74 73 2f 63 63 38 /os8/scripts/cc8
35a0: 2d 74 75 35 36 2e 6f 73 38 0a 5b 6f 73 38 72 5d -tu56.os8.[os8r]
35b0: 3a 20 2e 2f 6f 73 38 2d 72 75 6e 2e 6d 64 0a 0a : ./os8-run.md..
35c0: 0a 3c 61 20 69 64 3d 22 6e 66 65 61 74 22 20 6e .<a id="nfeat" n
35d0: 61 6d 65 3d 22 66 65 61 74 75 72 65 73 22 3e 3c ame="features"><
35e0: 2f 61 3e 0a 23 23 23 20 46 65 61 74 75 72 65 73 /a>.### Features
35f0: 20 6f 66 20 74 68 65 20 4e 61 74 69 76 65 20 4f of the Native O
3600: 53 2f 38 20 43 6f 6d 70 69 6c 65 72 0a 0a 54 68 S/8 Compiler..Th
3610: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 69 73 20 74 e following is t
3620: 68 65 20 73 75 62 73 65 74 20 6f 66 20 43 20 6b he subset of C k
3630: 6e 6f 77 6e 20 74 6f 20 62 65 20 75 6e 64 65 72 nown to be under
3640: 73 74 6f 6f 64 20 62 79 20 74 68 65 20 6e 61 74 stood by the nat
3650: 69 76 65 0a 4f 53 2f 38 20 43 43 38 20 63 6f 6d ive.OS/8 CC8 com
3660: 70 69 6c 65 72 3a 0a 0a 31 2e 20 20 2a 2a 4c 6f piler:..1. **Lo
3670: 63 61 6c 20 61 6e 64 20 67 6c 6f 62 61 6c 20 76 cal and global v
3680: 61 72 69 61 62 6c 65 73 2a 2a 0a 0a 31 2e 20 20 ariables**..1.
3690: 2a 2a 50 6f 69 6e 74 65 72 73 2c 2a 2a 20 77 69 **Pointers,** wi
36a0: 74 68 69 6e 20 6c 69 6d 69 74 61 74 69 6f 6e 73 thin limitations
36b0: 20 67 69 76 65 6e 20 62 65 6c 6f 77 2e 0a 0a 31 given below...1
36c0: 2e 20 20 2a 2a 46 75 6e 63 74 69 6f 6e 73 3a 2a . **Functions:*
36d0: 2a 20 50 61 72 61 6d 65 74 65 72 20 6c 69 73 74 * Parameter list
36e0: 73 20 6d 75 73 74 20 62 65 20 64 65 63 6c 61 72 s must be declar
36f0: 65 64 20 69 6e 20 4b 26 52 20 66 6f 72 6d 3a 0a ed in K&R form:.
3700: 0a 20 20 20 20 20 20 20 20 69 6e 74 20 66 6f 6f . int foo
3710: 20 28 61 2c 20 62 29 0a 20 20 20 20 20 20 20 20 (a, b).
3720: 69 6e 74 20 61 2c 20 62 3b 0a 20 20 20 20 20 20 int a, b;.
3730: 20 20 7b 0a 20 20 20 20 20 20 20 20 20 20 20 20 {.
3740: 2e 2e 2e 0a 20 20 20 20 20 20 20 20 7d 0a 0a 31 .... }..1
3750: 2e 20 20 2a 2a 52 65 63 75 72 73 69 6f 6e 3a 2a . **Recursion:*
3760: 2a 20 53 65 65 20 5b 60 46 49 42 2e 43 60 5d 5b * See [`FIB.C`][
3770: 66 69 62 5d 20 66 6f 72 20 61 6e 20 65 78 61 6d fib] for an exam
3780: 70 6c 65 20 6f 66 20 74 68 69 73 2e 0a 0a 31 2e ple of this...1.
3790: 20 20 2a 2a 53 69 6d 70 6c 65 20 61 72 69 74 68 **Simple arith
37a0: 6d 65 74 69 63 20 6f 70 65 72 61 74 6f 72 73 3a metic operators:
37b0: 2a 2a 20 60 2b 60 2c 20 60 2d 60 2c 20 60 2a 60 ** `+`, `-`, `*`
37c0: 2c 20 60 2f 60 2c 20 65 74 63 2e 0a 0a 31 2e 20 , `/`, etc...1.
37d0: 20 2a 2a 42 69 74 77 69 73 65 20 6f 70 65 72 61 **Bitwise opera
37e0: 74 6f 72 73 3a 2a 2a 20 60 26 60 2c 20 60 7c 60 tors:** `&`, `|`
37f0: 2c 20 60 7e 60 20 61 6e 64 20 60 21 60 0a 0a 31 , `~` and `!`..1
3800: 2e 20 20 2a 2a 53 69 6d 70 6c 65 20 63 6f 6d 70 . **Simple comp
3810: 61 72 69 73 6f 6e 20 6f 70 65 72 61 74 6f 72 73 arison operators
3820: 3a 2a 2a 20 46 61 6c 73 65 20 65 78 70 72 65 73 :** False expres
3830: 73 69 6f 6e 73 20 65 76 61 6c 75 61 74 65 20 61 sions evaluate a
3840: 73 20 30 20 61 6e 64 0a 20 20 20 20 74 72 75 65 s 0 and. true
3850: 20 61 73 20 2d 31 20 69 6e 20 74 77 6f e2 80 99 as -1 in two’
3860: 73 20 63 6f 6d 70 6c 65 6d 65 6e 74 20 66 6f 72 s complement for
3870: 6d 2c 20 6d 65 61 6e 69 6e 67 20 61 6c 6c 20 31 m, meaning all 1
3880: 27 73 20 69 6e 20 62 69 6e 61 72 79 20 66 6f 72 's in binary for
3890: 6d 2e 0a 20 20 20 20 53 65 65 20 74 68 65 20 6c m.. See the l
38a0: 69 73 74 20 6f 66 20 6c 69 6d 69 74 61 74 69 6f ist of limitatio
38b0: 6e 73 20 62 65 6c 6f 77 20 66 6f 72 20 74 68 65 ns below for the
38c0: 20 6f 70 65 72 61 74 6f 72 73 20 65 78 63 6c 75 operators exclu
38d0: 64 65 64 20 62 79 20 6f 75 72 0a 20 20 20 20 22 ded by our. "
38e0: 73 69 6d 70 6c 65 22 20 71 75 61 6c 69 66 69 65 simple" qualifie
38f0: 72 2e 0a 0a 31 2e 20 20 2a 2a 32 2d 63 68 61 72 r...1. **2-char
3900: 61 63 74 65 72 20 6f 70 65 72 61 74 6f 72 73 3a acter operators:
3910: 2a 2a 20 60 2b 2b 60 2c 20 60 2d 2d 60 2c 20 60 ** `++`, `--`, `
3920: 3d 3d 60 2c 20 60 21 3d 60 2c 60 3e 3d 60 2c 20 ==`, `!=`,`>=`,
3930: 60 3c 3d 60 2c 20 60 26 26 60 2c 0a 20 20 20 20 `<=`, `&&`,.
3940: 61 6e 64 20 60 7c 7c 60 2e 20 4e 6f 74 65 20 74 and `||`. Note t
3950: 68 61 74 20 60 2b 2b 60 20 61 6e 64 20 60 2d 2d hat `++` and `--
3960: 60 20 61 72 65 20 70 6f 73 74 66 69 78 20 6f 6e ` are postfix on
3970: 6c 79 2c 20 61 6e 64 0a 20 20 20 20 74 68 61 74 ly, and. that
3980: 20 60 26 26 60 20 61 6e 64 20 60 7c 7c 60 20 61 `&&` and `||` a
3990: 72 65 20 5b 69 6d 70 6c 65 6d 65 6e 74 65 64 20 re [implemented
39a0: 61 73 20 60 26 60 20 61 6e 64 20 60 7c 60 5d 28 as `&` and `|`](
39b0: 23 32 63 62 6f 29 2e 0a 0a 31 2e 20 20 2a 2a 54 #2cbo)...1. **T
39c0: 65 72 6e 61 72 79 20 6f 70 65 72 61 74 6f 72 3a ernary operator:
39d0: 2a 2a 20 54 68 65 20 60 3f 3a 60 20 6f 70 65 72 ** The `?:` oper
39e0: 61 74 6f 72 20 77 6f 72 6b 73 20 61 73 20 6f 66 ator works as of
39f0: 20 4d 61 79 20 32 30 32 30 3b 20 69 74 20 6d 61 May 2020; it ma
3a00: 79 0a 20 20 20 20 62 65 20 6e 65 73 74 65 64 2e y. be nested.
3a10: 0a 0a 31 2e 20 20 2a 2a 4c 69 6d 69 74 65 64 20 ..1. **Limited
3a20: 6c 69 62 72 61 72 79 3a 2a 2a 20 53 65 65 20 5b library:** See [
3a30: 62 65 6c 6f 77 5d 28 23 6c 69 62 63 29 20 66 6f below](#libc) fo
3a40: 72 20 61 20 6c 69 73 74 20 6f 66 20 6c 69 62 72 r a list of libr
3a50: 61 72 79 0a 20 20 20 20 66 75 6e 63 74 69 6f 6e ary. function
3a60: 73 20 70 72 6f 76 69 64 65 64 2c 20 69 6e 63 6c s provided, incl
3a70: 75 64 69 6e 67 20 74 68 65 69 72 20 6b 6e 6f 77 uding their know
3a80: 6e 20 6c 69 6d 69 74 61 74 69 6f 6e 73 20 72 65 n limitations re
3a90: 6c 61 74 69 76 65 20 74 6f 0a 20 20 20 20 53 74 lative to. St
3aa0: 61 6e 64 61 72 64 20 43 2e 0a 0a 20 20 20 20 54 andard C... T
3ab0: 68 65 72 65 20 61 72 65 20 6d 61 6e 79 20 6c 69 here are many li
3ac0: 6d 69 74 61 74 69 6f 6e 73 20 69 6e 20 74 68 69 mitations in thi
3ad0: 73 20 6c 69 62 72 61 72 79 20 72 65 6c 61 74 69 s library relati
3ae0: 76 65 20 74 6f 20 53 74 61 6e 64 61 72 64 20 43 ve to Standard C
3af0: 20 6f 72 0a 20 20 20 20 65 76 65 6e 20 4b 26 52 or. even K&R
3b00: 20 43 2c 20 77 68 69 63 68 20 61 72 65 20 64 6f C, which are do
3b10: 63 75 6d 65 6e 74 65 64 20 62 65 6c 6f 77 2e 0a cumented below..
3b20: 0a 31 2e 20 20 2a 2a 4c 69 6d 69 74 65 64 20 73 .1. **Limited s
3b30: 74 72 75 63 74 75 72 69 6e 67 20 63 6f 6e 73 74 tructuring const
3b40: 72 75 63 74 73 3a 2a 2a 20 60 69 66 60 2c 20 60 ructs:** `if`, `
3b50: 77 68 69 6c 65 60 2c 20 60 66 6f 72 60 2c 20 65 while`, `for`, e
3b60: 74 63 2e 20 61 72 65 0a 20 20 20 20 73 75 70 70 tc. are. supp
3b70: 6f 72 74 65 64 2e 20 54 68 65 72 65 20 69 73 20 orted. There is
3b80: 61 20 6e 65 73 74 69 6e 67 20 6c 69 6d 69 74 20 a nesting limit
3b90: 6f 66 20 31 30 20 77 68 69 63 68 20 69 73 20 72 of 10 which is r
3ba0: 61 72 65 6c 79 20 65 78 63 65 65 64 65 64 20 69 arely exceeded i
3bb0: 6e 20 0a 20 20 20 20 6d 6f 73 74 20 61 70 70 6c n . most appl
3bc0: 69 63 61 74 69 6f 6e 73 2e 20 49 6e 20 61 64 64 ications. In add
3bd0: 69 74 69 6f 6e 2c 20 60 73 77 69 74 63 68 60 20 ition, `switch`
3be0: 73 74 61 74 65 6d 65 6e 74 73 20 61 72 65 20 6e statements are n
3bf0: 6f 77 20 73 75 70 70 6f 72 74 65 64 0a 20 20 20 ow supported.
3c00: 20 76 69 61 20 61 20 63 6f 64 65 20 72 65 2d 77 via a code re-w
3c10: 72 69 74 65 20 69 6e 20 74 68 65 20 43 20 70 72 rite in the C pr
3c20: 65 2d 70 72 6f 63 65 73 73 6f 72 20 28 63 63 2e e-processor (cc.
3c30: 73 76 29 2e 20 53 65 65 20 20 5b 60 46 4f 52 54 sv). See [`FORT
3c40: 48 2e 43 60 5d 5b 66 6f 72 74 68 5d 0a 20 20 20 H.C`][forth].
3c50: 20 66 6f 72 20 61 6e 20 65 78 61 6d 70 6c 65 2e for an example.
3c60: 0a 0a 5b 66 69 62 5d 3a 20 20 20 2f 64 6f 63 2f ..[fib]: /doc/
3c70: 74 72 75 6e 6b 2f 73 72 63 2f 6f 73 38 2f 65 78 trunk/src/os8/ex
3c80: 61 6d 70 6c 65 73 2f 66 69 62 2e 63 0a 5b 66 6f amples/fib.c.[fo
3c90: 72 74 68 5d 3a 20 2f 64 6f 63 2f 74 72 75 6e 6b rth]: /doc/trunk
3ca0: 2f 73 72 63 2f 6f 73 38 2f 65 78 61 6d 70 6c 65 /src/os8/example
3cb0: 73 2f 66 6f 72 74 68 2e 63 0a 0a 3c 61 20 69 64 s/forth.c..<a id
3cc0: 3d 22 6e 6c 69 6d 22 20 6e 61 6d 65 3d 22 6c 69 ="nlim" name="li
3cd0: 6d 69 74 61 74 69 6f 6e 73 22 3e 3c 2f 61 3e 0a mitations"></a>.
3ce0: 23 23 23 20 4b 6e 6f 77 6e 20 4c 69 6d 69 74 61 ### Known Limita
3cf0: 74 69 6f 6e 73 20 6f 66 20 74 68 65 20 4f 53 2f tions of the OS/
3d00: 38 20 43 43 38 20 43 6f 6d 70 69 6c 65 72 0a 0a 8 CC8 Compiler..
3d10: 54 68 65 20 4f 53 2f 38 20 76 65 72 73 69 6f 6e The OS/8 version
3d20: 20 6f 66 20 43 43 38 20 73 75 70 70 6f 72 74 73 of CC8 supports
3d30: 20 61 20 73 75 62 73 65 74 20 6f 66 20 74 68 65 a subset of the
3d40: 20 43 20 64 69 61 6c 65 63 74 20 75 6e 64 65 72 C dialect under
3d50: 73 74 6f 6f 64 20 62 79 0a 5b 74 68 65 20 63 72 stood by.[the cr
3d60: 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 5d 28 23 63 oss-compiler](#c
3d70: 72 6f 73 73 29 2c 20 61 6e 64 20 74 68 75 73 20 ross), and thus
3d80: 6f 66 20 4b 26 52 20 43 3a 0a 0a 31 2e 20 20 3c of K&R C:..1. <
3d90: 61 20 69 64 3d 22 74 79 70 65 6c 65 73 73 22 3e a id="typeless">
3da0: 3c 2f 61 3e 54 68 65 20 6c 61 6e 67 75 61 67 65 </a>The language
3db0: 20 69 73 20 74 79 70 65 6c 65 73 73 20 69 6e 20 is typeless in
3dc0: 74 68 61 74 20 65 76 65 72 79 74 68 69 6e 67 20 that everything
3dd0: 69 73 0a 20 20 20 20 61 20 31 32 20 62 69 74 20 is. a 12 bit
3de0: 69 6e 74 65 67 65 72 2c 20 61 6e 64 20 61 6e 79 integer, and any
3df0: 20 76 61 72 69 61 62 6c 65 2f 61 72 72 61 79 20 variable/array
3e00: 63 61 6e 20 69 6e 74 65 72 70 72 65 74 65 64 20 can interpreted
3e10: 61 73 20 60 69 6e 74 60 2c 0a 20 20 20 20 60 63 as `int`,. `c
3e20: 68 61 72 60 20 6f 72 20 70 6f 69 6e 74 65 72 2e har` or pointer.
3e30: 20 20 41 6c 6c 20 76 61 72 69 61 62 6c 65 73 20 All variables
3e40: 61 6e 64 20 61 72 72 61 79 73 20 6d 75 73 74 20 and arrays must
3e50: 62 65 20 64 65 63 6c 61 72 65 64 20 61 73 0a 20 be declared as.
3e60: 20 20 20 60 69 6e 74 60 2e 20 41 73 20 77 69 74 `int`. As wit
3e70: 68 20 4b 26 52 20 43 2c 20 74 68 65 20 72 65 74 h K&R C, the ret
3e80: 75 72 6e 20 74 79 70 65 20 6d 61 79 20 62 65 20 urn type may be
3e90: 6c 65 66 74 20 6f 66 66 20 6f 66 20 61 0a 20 20 left off of a.
3ea0: 20 20 66 75 6e 63 74 69 6f 6e 27 73 20 64 65 66 function's def
3eb0: 69 6e 69 74 69 6f 6e 3b 20 69 74 20 69 73 20 69 inition; it is i
3ec0: 6d 70 6c 69 63 69 74 6c 79 20 60 69 6e 74 60 20 mplicitly `int`
3ed0: 69 6e 20 61 6c 6c 20 63 61 73 65 73 2e 0a 0a 20 in all cases...
3ee0: 20 20 20 49 74 20 69 73 20 6e 6f 74 20 6e 65 63 It is not nec
3ef0: 65 73 73 61 72 79 20 74 6f 20 67 69 76 65 20 61 essary to give a
3f00: 72 67 75 6d 65 6e 74 20 74 79 70 65 73 20 77 68 rgument types wh
3f10: 65 6e 20 64 65 63 6c 61 72 69 6e 67 20 66 75 6e en declaring fun
3f20: 63 74 69 6f 6e 0a 20 20 20 20 61 72 67 75 6d 65 ction. argume
3f30: 6e 74 73 2c 20 62 75 74 20 79 6f 75 20 6d 75 73 nts, but you mus
3f40: 74 20 64 65 63 6c 61 72 65 20 61 20 72 65 74 75 t declare a retu
3f50: 72 6e 20 74 79 70 65 20 77 69 74 68 20 74 68 65 rn type with the
3f60: 20 4f 53 2f 38 20 43 43 38 0a 20 20 20 20 63 6f OS/8 CC8. co
3f70: 6d 70 69 6c 65 72 3a 0a 0a 20 20 20 20 20 20 20 mpiler:..
3f80: 20 69 6e 74 20 6d 79 66 6e 28 6e 29 20 7b 20 2f int myfn(n) { /
3f90: 2a 20 64 6f 20 73 6f 6d 65 74 68 69 6e 67 20 77 * do something w
3fa0: 69 74 68 20 6e 20 2a 2f 20 7d 0a 0a 20 20 20 20 ith n */ }..
3fb0: 54 68 69 73 20 64 65 63 6c 61 72 65 73 20 61 20 This declares a
3fc0: 66 75 6e 63 74 69 6f 6e 20 74 61 6b 69 6e 67 20 function taking
3fd0: 61 6e 20 60 69 6e 74 60 20 63 61 6c 6c 65 64 20 an `int` called
3fe0: 60 6e 60 20 61 6e 64 20 72 65 74 75 72 6e 69 6e `n` and returnin
3ff0: 67 0a 20 20 20 20 61 6e 20 60 69 6e 74 60 2e 0a g. an `int`..
4000: 20 20 20 20 0a 20 20 20 20 43 6f 6e 74 72 61 73 . Contras
4010: 74 20 74 68 65 20 43 43 38 20 63 72 6f 73 73 2d t the CC8 cross-
4020: 63 6f 6d 70 69 6c 65 72 2c 20 77 68 69 63 68 20 compiler, which
4030: 72 65 71 75 69 72 65 73 20 66 75 6e 63 74 69 6f requires functio
4040: 6e 20 61 72 67 75 6d 65 6e 74 0a 20 20 20 20 74 n argument. t
4050: 79 70 65 73 20 74 6f 20 62 65 20 64 65 63 6c 61 ypes to be decla
4060: 72 65 64 20 62 75 74 20 6e 6f 74 20 74 68 65 20 red but not the
4070: 72 65 74 75 72 6e 20 74 79 70 65 2c 20 70 65 72 return type, per
4080: 20 4b 26 52 20 43 20 72 75 6c 65 73 3a 0a 0a 20 K&R C rules:..
4090: 20 20 20 20 20 20 20 69 6e 74 20 6d 79 66 6e 28 int myfn(
40a0: 6e 29 0a 20 20 20 20 20 20 20 20 69 6e 74 20 6e n). int n
40b0: 3b 0a 20 20 20 20 20 20 20 20 7b 0a 20 20 20 20 ;. {.
40c0: 20 20 20 20 20 20 20 20 2f 2a 20 64 6f 20 73 6f /* do so
40d0: 6d 65 74 68 69 6e 67 20 77 69 74 68 20 6e 2c 20 mething with n,
40e0: 74 68 65 6e 20 5f 6d 61 79 62 65 5f 20 72 65 74 then _maybe_ ret
40f0: 75 72 6e 20 73 6f 6d 65 74 68 69 6e 67 20 2a 2f urn something */
4100: 0a 20 20 20 20 20 20 20 20 7d 0a 0a 20 20 20 20 . }..
4110: 54 68 65 20 74 79 70 65 20 69 6e 74 20 69 73 20 The type int is
4120: 6d 61 6e 64 61 74 6f 72 79 20 66 6f 72 20 61 6c mandatory for al
4130: 6c 20 66 75 6e 63 74 69 6f 6e 73 2e 0a 0a 20 20 l functions...
4140: 20 20 54 68 65 20 63 72 6f 73 73 2d 63 6f 6d 70 The cross-comp
4150: 69 6c 65 72 20 73 75 70 70 6f 72 74 73 20 60 76 iler supports `v
4160: 6f 69 64 60 20 61 73 20 61 6e 20 65 78 74 65 6e oid` as an exten
4170: 73 69 6f 6e 20 74 6f 20 4b 26 52 20 43 2e 20 54 sion to K&R C. T
4180: 68 69 73 20 74 79 70 65 0a 20 20 20 20 69 73 20 his type. is
4190: 63 6f 6e 76 65 72 74 65 64 20 74 6f 20 60 69 6e converted to `in
41a0: 74 60 20 69 6e 20 74 68 65 20 70 72 65 2d 70 72 t` in the pre-pr
41b0: 6f 63 65 73 73 6f 72 2e 20 53 69 6d 69 6c 61 72 ocessor. Similar
41c0: 6c 79 2c 20 74 68 65 20 74 79 70 65 20 60 63 68 ly, the type `ch
41d0: 61 72 60 20 69 73 0a 20 20 20 20 63 6f 6e 76 65 ar` is. conve
41e0: 72 74 65 64 2e 20 54 68 65 73 65 20 74 79 70 65 rted. These type
41f0: 20 6d 61 79 20 62 65 20 75 73 65 64 20 66 6f 72 may be used for
4200: 20 72 65 61 64 61 62 69 6c 69 74 79 20 70 75 72 readability pur
4210: 70 6f 73 65 73 2e 0a 0a 32 2e 20 20 54 68 65 72 poses...2. Ther
4220: 65 20 6d 75 73 74 20 62 65 20 61 6e 20 60 69 6e e must be an `in
4230: 74 20 6d 61 69 6e 28 29 60 2c 20 61 6e 64 20 69 t main()`, and i
4240: 74 20 6d 75 73 74 20 62 65 20 74 68 65 20 6c 61 t must be the la
4250: 73 74 20 66 75 6e 63 74 69 6f 6e 0a 20 20 20 20 st function.
4260: 69 6e 20 74 68 65 20 73 69 6e 67 6c 65 20 69 6e in the single in
4270: 70 75 74 20 43 20 66 69 6c 65 2e 0a 0a 20 20 20 put C file...
4280: 20 53 69 6e 63 65 20 4f 53 2f 38 20 68 61 73 20 Since OS/8 has
4290: 6e 6f 20 77 61 79 20 74 6f 20 70 61 73 73 20 63 no way to pass c
42a0: 6f 6d 6d 61 6e 64 20 6c 69 6e 65 20 61 72 67 75 ommand line argu
42b0: 6d 65 6e 74 73 20 74 6f 20 61 20 70 72 6f 67 72 ments to a progr
42c0: 61 6d 0a 20 20 20 20 e2 80 94 20 61 74 20 6c 65 am. — at le
42d0: 61 73 74 2c 20 6e 6f 74 20 69 6e 20 61 20 77 61 ast, not in a wa
42e0: 79 20 74 68 61 74 20 69 73 20 63 6f 6d 70 61 74 y that is compat
42f0: 69 62 6c 65 20 77 69 74 68 20 74 68 65 20 55 6e ible with the Un
4300: 69 78 20 73 74 79 6c 65 0a 20 20 20 20 63 6f 6d ix style. com
4310: 6d 61 6e 64 20 6c 69 6e 65 73 20 65 78 70 65 63 mand lines expec
4320: 74 65 64 20 62 79 20 43 20 e2 80 94 20 74 68 65 ted by C — the
4330: 20 60 6d 61 69 6e 28 29 60 20 66 75 6e 63 74 69 `main()` functi
4340: 6f 6e 20 69 73 20 6e 65 76 65 72 0a 20 20 20 20 on is never.
4350: 64 65 63 6c 61 72 65 64 20 74 6f 20 74 61 6b 65 declared to take
4360: 20 61 72 67 75 6d 65 6e 74 73 2e 0a 0a 33 2e 20 arguments...3.
4370: 20 57 65 20 64 6f 20 6e 6f 74 20 79 65 74 20 73 We do not yet s
4380: 75 70 70 6f 72 74 20 73 65 70 61 72 61 74 65 20 upport separate
4390: 63 6f 6d 70 69 6c 61 74 69 6f 6e 20 6f 66 20 6d compilation of m
43a0: 75 6c 74 69 70 6c 65 20 43 20 6d 6f 64 75 6c 65 ultiple C module
43b0: 73 0a 20 20 20 20 74 68 61 74 20 67 65 74 20 6c s. that get l
43c0: 69 6e 6b 65 64 20 74 6f 67 65 74 68 65 72 2e 20 inked together.
43d0: 20 59 6f 75 20 63 61 6e 20 70 72 6f 64 75 63 65 You can produce
43e0: 20 72 65 6c 6f 63 61 74 61 62 6c 65 20 6c 69 62 relocatable lib
43f0: 72 61 72 69 65 73 20 69 6e 0a 20 20 20 20 4f 53 raries in. OS
4400: 2f 38 20 60 2a 2e 52 4c 60 20 66 6f 72 6d 61 74 /8 `*.RL` format
4410: 20 61 6e 64 20 6c 69 6e 6b 20 74 68 65 6d 20 77 and link them w
4420: 69 74 68 20 74 68 65 20 4f 53 2f 38 20 4c 4f 41 ith the OS/8 LOA
4430: 44 45 52 2c 20 62 75 74 20 62 65 63 61 75 73 65 DER, but because
4440: 0a 20 20 20 20 6f 66 20 74 68 65 20 70 72 65 76 . of the prev
4450: 69 6f 75 73 20 6c 69 6d 69 74 61 74 69 6f 6e 2c ious limitation,
4460: 20 6f 6e 6c 79 20 6f 6e 65 20 6f 66 20 74 68 65 only one of the
4470: 73 65 20 63 61 6e 20 62 65 20 77 72 69 74 74 65 se can be writte
4480: 6e 20 69 6e 20 43 2e 0a 0a 34 2e 20 20 3c 61 20 n in C...4. <a
4490: 69 64 3d 22 6f 73 38 70 70 22 3e 3c 2f 61 3e 54 id="os8pp"></a>T
44a0: 68 65 20 4f 53 2f 38 20 63 6f 6d 70 69 6c 65 72 he OS/8 compiler
44b0: 20 68 61 73 20 65 78 74 72 65 6d 65 6c 79 20 72 has extremely r
44c0: 75 64 69 6d 65 6e 74 61 72 79 0a 20 20 20 20 73 udimentary. s
44d0: 75 70 70 6f 72 74 20 66 6f 72 20 70 72 65 70 72 upport for prepr
44e0: 6f 63 65 73 73 6f 72 20 64 69 72 65 63 74 69 76 ocessor directiv
44f0: 65 73 2e 0a 0a 20 20 20 20 2a 20 20 20 4c 69 74 es... * Lit
4500: 65 72 61 6c 20 60 23 64 65 66 69 6e 65 60 20 6f eral `#define` o
4510: 6e 6c 79 3a 20 6e 6f 20 70 61 72 61 6d 65 74 65 nly: no paramete
4520: 72 69 7a 65 64 20 6d 61 63 72 6f 73 2c 20 61 6e rized macros, an
4530: 64 20 6e 6f 20 60 23 75 6e 64 65 66 60 2e 0a 0a d no `#undef`...
4540: 20 20 20 20 2a 20 20 20 60 23 69 6e 63 6c 75 64 * `#includ
4550: 65 60 20 69 73 20 6e 6f 74 20 73 75 70 70 6f 72 e` is not suppor
4560: 74 65 64 20 61 6e 64 20 6d 75 73 74 20 6e 6f 74 ted and must not
4570: 20 61 70 70 65 61 72 20 69 6e 20 74 68 65 20 43 appear in the C
4580: 20 73 6f 75 72 63 65 0a 20 20 20 20 20 20 20 20 source.
4590: 63 6f 64 65 20 66 65 64 20 74 6f 20 74 68 65 20 code fed to the
45a0: 4e 61 74 69 76 65 20 4f 53 2f 38 20 43 6f 6d 70 Native OS/8 Comp
45b0: 69 6c 65 72 2e 0a 0a 20 20 20 20 20 20 20 20 54 iler... T
45c0: 68 69 73 20 6d 65 61 6e 73 20 79 6f 75 20 63 61 his means you ca
45d0: 6e 6e 6f 74 20 75 73 65 20 60 23 69 6e 63 6c 75 nnot use `#inclu
45e0: 64 65 60 20 64 69 72 65 63 74 69 76 65 73 20 74 de` directives t
45f0: 6f 20 73 74 72 69 6e 67 0a 20 20 20 20 20 20 20 o string.
4600: 20 6d 75 6c 74 69 70 6c 65 20 43 20 6d 6f 64 75 multiple C modu
4610: 6c 65 73 20 69 6e 74 6f 20 61 20 73 69 6e 67 6c les into a singl
4620: 65 20 70 72 6f 67 72 61 6d 2e 0a 0a 20 20 20 20 e program...
4630: 20 20 20 20 49 74 20 61 6c 73 6f 20 6d 65 61 6e It also mean
4640: 73 20 74 68 61 74 20 69 66 20 79 6f 75 20 74 61 s that if you ta
4650: 6b 65 20 61 20 70 72 6f 67 72 61 6d 20 74 68 61 ke a program tha
4660: 74 20 74 68 65 20 63 72 6f 73 73 2d 63 6f 6d 70 t the cross-comp
4670: 69 6c 65 72 0a 20 20 20 20 20 20 20 20 68 61 6e iler. han
4680: 64 6c 65 73 20 63 6f 72 72 65 63 74 6c 79 20 61 dles correctly a
4690: 6e 64 20 6a 75 73 74 20 63 6f 70 79 20 69 74 20 nd just copy it
46a0: 73 74 72 61 69 67 68 74 20 69 6e 74 6f 20 4f 53 straight into OS
46b0: 2f 38 20 61 6e 64 20 74 72 79 20 74 6f 0a 20 20 /8 and try to.
46c0: 20 20 20 20 20 20 63 6f 6d 70 69 6c 65 20 69 74 compile it
46d0: 2c 20 69 74 20 70 72 6f 62 61 62 6c 79 20 73 74 , it probably st
46e0: 69 6c 6c 20 68 61 73 20 74 68 65 20 60 23 69 6e ill has the `#in
46f0: 63 6c 75 64 65 20 3c 6c 69 62 63 2e 68 3e 60 20 clude <libc.h>`
4700: 6c 69 6e 65 20 61 6e 64 0a 20 20 20 20 20 20 20 line and.
4710: 20 70 6f 73 73 69 62 6c 79 20 6f 6e 65 20 66 6f possibly one fo
4720: 72 20 60 69 6e 69 74 2e 68 60 20 61 73 20 77 65 r `init.h` as we
4730: 6c 6c 2e 20 2a 53 75 63 68 20 63 6f 64 65 20 77 ll. *Such code w
4740: 69 6c 6c 20 66 61 69 6c 20 74 6f 20 63 6f 6d 70 ill fail to comp
4750: 69 6c 65 2e 2a 0a 20 20 20 20 20 20 20 20 59 6f ile.*. Yo
4760: 75 20 6d 75 73 74 20 73 74 72 69 70 20 73 75 63 u must strip suc
4770: 68 20 6c 69 6e 65 73 20 6f 75 74 20 77 68 65 6e h lines out when
4780: 20 63 6f 70 79 69 6e 67 20 43 20 66 69 6c 65 73 copying C files
4790: 20 69 6e 74 6f 20 4f 53 2f 38 2e 0a 0a 20 20 20 into OS/8...
47a0: 20 20 20 20 20 28 54 68 65 20 6e 61 74 69 76 65 (The native
47b0: 20 63 6f 6d 70 69 6c 65 72 20 65 6d 69 74 73 20 compiler emits
47c0: 73 74 61 72 74 75 70 20 63 6f 64 65 20 61 75 74 startup code aut
47d0: 6f 6d 61 74 69 63 61 6c 6c 79 2c 20 61 6e 64 20 omatically, and
47e0: 69 74 0a 20 20 20 20 20 20 20 20 68 61 72 64 2d it. hard-
47f0: 63 6f 64 65 73 20 74 68 65 20 4c 49 42 43 20 63 codes the LIBC c
4800: 61 6c 6c 20 74 61 62 6c 65 20 69 6e 20 74 68 65 all table in the
4810: 20 5b 66 69 6e 61 6c 20 63 6f 6d 70 69 6c 65 72 [final compiler
4820: 0a 20 20 20 20 20 20 20 20 70 61 73 73 5d 28 23 . pass](#
4830: 6e 63 70 61 73 73 29 2c 20 69 6d 70 6c 65 6d 65 ncpass), impleme
4840: 6e 74 65 64 20 69 6e 20 60 70 38 2e 63 60 2c 20 nted in `p8.c`,
4850: 73 6f 20 69 74 20 64 6f 65 73 6e e2 80 99 74 20 so it doesn’t
4860: 6e 65 65 64 0a 20 20 20 20 20 20 20 20 60 23 69 need. `#i
4870: 6e 63 6c 75 64 65 60 20 74 6f 20 6d 61 6b 65 20 nclude` to make
4880: 74 68 65 73 65 20 74 68 69 6e 67 73 20 77 6f 72 these things wor
4890: 6b 2e 29 0a 0a 20 20 20 20 2a 20 20 20 4e 6f 20 k.).. * No
48a0: 63 6f 6e 64 69 74 69 6f 6e 61 6c 20 63 6f 6d 70 conditional comp
48b0: 69 6c 61 74 69 6f 6e 3a 20 60 23 69 66 60 2c 20 ilation: `#if`,
48c0: 60 23 69 66 64 65 66 60 2c 20 60 23 65 6c 73 65 `#ifdef`, `#else
48d0: 60 2c 20 65 74 63 2e 0a 0a 20 20 20 20 2a 20 20 `, etc... *
48e0: 20 5b 49 6e 6c 69 6e 65 20 61 73 73 6d 65 6d 62 [Inline assmemb
48f0: 6c 79 5d 28 23 61 73 6d 29 20 76 69 61 20 60 23 ly](#asm) via `#
4900: 61 73 6d 60 20 2f 20 60 23 65 6e 64 61 73 6d 60 asm` / `#endasm`
4910: 2e 20 53 65 65 0a 20 20 20 20 20 20 20 20 5b 60 . See. [`
4920: 46 49 42 2e 43 60 5d 5b 66 69 62 5d 20 66 6f 72 FIB.C`][fib] for
4930: 20 61 6e 20 65 78 61 6d 70 6c 65 0a 0a 35 2e 20 an example..5.
4940: 20 56 61 72 69 61 62 6c 65 73 20 61 72 65 20 69 Variables are i
4950: 6d 70 6c 69 63 69 74 6c 79 20 60 73 74 61 74 69 mplicitly `stati
4960: 63 60 2c 20 65 76 65 6e 20 77 68 65 6e 20 6c 6f c`, even when lo
4970: 63 61 6c 2e 0a 0a 36 2e 20 20 41 72 72 61 79 73 cal...6. Arrays
4980: 20 6d 61 79 20 6f 6e 6c 79 20 62 65 20 73 69 6e may only be sin
4990: 67 6c 65 20 69 6e 64 65 78 65 64 2e 20 53 65 65 gle indexed. See
49a0: 20 60 50 53 2e 43 60 20 66 6f 72 20 61 6e 20 65 `PS.C` for an e
49b0: 78 61 6d 70 6c 65 2e 0a 0a 37 2e 20 20 54 68 65 xample...7. The
49c0: 20 63 6f 6d 70 69 6c 65 72 20 64 6f 65 73 20 6e compiler does n
49d0: 6f 74 20 79 65 74 20 75 6e 64 65 72 73 74 61 6e ot yet understan
49e0: 64 20 68 6f 77 20 74 6f 20 61 73 73 69 67 6e 20 d how to assign
49f0: 61 20 76 61 72 69 61 62 6c 65 27 73 0a 20 20 20 a variable's.
4a00: 20 69 6e 69 74 69 61 6c 20 76 61 6c 75 65 20 61 initial value a
4a10: 73 20 70 61 72 74 20 6f 66 20 69 74 73 20 64 65 s part of its de
4a20: 63 6c 61 72 61 74 69 6f 6e 2e 20 54 68 69 73 3a claration. This:
4a30: 0a 0a 20 20 20 20 20 20 20 20 69 6e 74 20 69 20 .. int i
4a40: 3d 20 35 3b 0a 0a 20 20 20 20 6d 75 73 74 20 69 = 5;.. must i
4a50: 6e 73 74 65 61 64 20 62 65 3a 0a 0a 20 20 20 20 nstead be:..
4a60: 20 20 20 20 69 6e 74 20 69 3b 0a 20 20 20 20 20 int i;.
4a70: 20 20 20 69 20 3d 20 35 3b 0a 0a 38 2e 20 20 3c i = 5;..8. <
4a80: 61 20 6e 61 6d 65 3d 22 32 63 62 6f 22 3e 3c 2f a name="2cbo"></
4a90: 61 3e 60 26 26 60 20 61 6e 64 20 60 7c 7c 60 20 a>`&&` and `||`
4aa0: 77 6f 72 6b 2c 20 62 75 74 20 62 65 63 61 75 73 work, but becaus
4ab0: 65 20 74 68 65 79 0a 20 20 20 20 61 72 65 20 69 e they. are i
4ac0: 6e 74 65 72 6e 61 6c 6c 79 20 63 6f 6e 76 65 72 nternally conver
4ad0: 74 65 64 20 74 6f 20 60 26 60 20 61 6e 64 20 60 ted to `&` and `
4ae0: 7c 60 2c 20 74 68 65 69 72 20 70 72 65 63 65 64 |`, their preced
4af0: 65 6e 63 65 20 68 61 73 0a 20 20 20 20 63 68 61 ence has. cha
4b00: 6e 67 65 64 2c 20 61 6e 64 20 74 68 65 79 20 64 nged, and they d
4b10: 6f 20 6e 6f 74 20 73 68 6f 72 74 2d 63 69 72 63 o not short-circ
4b20: 75 69 74 20 61 73 20 69 6e 20 61 20 63 6f 6e 66 uit as in a conf
4b30: 6f 72 6d 69 6e 67 20 43 0a 20 20 20 20 63 6f 6d orming C. com
4b40: 70 69 6c 65 72 2e 0a 0a 20 20 20 20 59 6f 75 20 piler... You
4b50: 63 61 6e 20 77 6f 72 6b 20 61 72 6f 75 6e 64 20 can work around
4b60: 73 75 63 68 20 64 69 66 66 65 72 65 6e 63 65 73 such differences
4b70: 20 77 69 74 68 20 63 6c 65 76 65 72 20 63 6f 64 with clever cod
4b80: 69 6e 67 2e 20 46 6f 72 0a 20 20 20 20 65 78 61 ing. For. exa
4b90: 6d 70 6c 65 2c 20 74 68 69 73 20 63 6f 64 65 20 mple, this code
4ba0: 66 6f 72 20 61 20 63 6f 6e 66 6f 72 6d 69 6e 67 for a conforming
4bb0: 20 43 20 63 6f 6d 70 69 6c 65 72 3a 0a 0a 20 20 C compiler:..
4bc0: 20 20 20 20 20 20 69 66 20 28 69 20 21 3d 20 30 if (i != 0
4bd0: 20 7c 7c 20 6a 20 3d 3d 20 35 29 0a 0a 20 20 20 || j == 5)..
4be0: 20 73 68 6f 75 6c 64 20 62 65 20 72 65 77 72 69 should be rewri
4bf0: 74 74 65 6e 20 66 6f 72 20 43 43 38 20 74 6f 20 tten for CC8 to
4c00: 61 76 6f 69 64 20 74 68 65 20 70 72 65 63 65 64 avoid the preced
4c10: 65 6e 63 65 20 63 68 61 6e 67 65 73 20 61 73 3a ence changes as:
4c20: 0a 0a 20 20 20 20 20 20 20 20 69 66 20 28 21 28 .. if (!(
4c30: 69 20 3d 3d 20 30 29 20 7c 7c 20 28 6a 20 3d 3d i == 0) || (j ==
4c40: 20 35 29 29 0a 0a 20 20 20 20 62 65 63 61 75 73 5)).. becaus
4c50: 65 20 61 20 74 72 75 65 20 72 65 73 75 6c 74 20 e a true result
4c60: 69 6e 20 65 61 63 68 20 73 75 62 65 78 70 72 65 in each subexpre
4c70: 73 73 69 6f 6e 20 79 69 65 6c 64 73 20 2d 31 20 ssion yields -1
4c80: 70 65 72 20 74 68 65 0a 20 20 20 20 70 72 65 76 per the. prev
4c90: 69 6f 75 73 20 70 6f 69 6e 74 2c 20 77 68 69 63 ious point, whic
4ca0: 68 20 77 68 65 6e 20 62 69 74 77 69 73 65 20 4f h when bitwise O
4cb0: 52 27 64 20 74 6f 67 65 74 68 65 72 20 6d 65 61 R'd together mea
4cc0: 6e 73 20 79 6f 75 20 67 65 74 20 2d 31 20 69 66 ns you get -1 if
4cd0: 0a 20 20 20 20 65 69 74 68 65 72 20 73 75 62 65 . either sube
4ce0: 78 70 72 65 73 73 69 6f 6e 20 69 73 20 74 72 75 xpression is tru
4cf0: 65 2c 20 77 68 69 63 68 20 6d 65 61 6e 73 20 74 e, which means t
4d00: 68 65 20 77 68 6f 6c 65 20 65 78 70 72 65 73 73 he whole express
4d10: 69 6f 6e 0a 20 20 20 20 65 76 61 6c 75 61 74 65 ion. evaluate
4d20: 73 20 74 6f 20 74 72 75 65 20 69 66 20 65 69 74 s to true if eit
4d30: 68 65 72 20 73 75 62 65 78 70 72 65 73 73 69 6f her subexpressio
4d40: 6e 20 69 73 20 74 72 75 65 2e 0a 0a 20 20 20 20 n is true...
4d50: 49 66 20 74 68 65 20 63 6f 64 65 20 79 6f 75 20 If the code you
4d60: 77 65 72 65 20 67 6f 69 6e 67 20 74 6f 20 77 72 were going to wr
4d70: 69 74 65 20 77 61 73 20 69 6e 73 74 65 61 64 3a ite was instead:
4d80: 0a 0a 20 20 20 20 20 20 20 20 69 66 20 28 69 20 .. if (i
4d90: 21 3d 20 30 20 7c 7c 20 6a 20 21 3d 20 35 29 0a != 0 || j != 5).
4da0: 0a 20 20 20 20 74 68 65 6e 20 74 68 65 20 72 65 . then the re
4db0: 77 72 69 74 65 20 69 73 20 65 76 65 6e 20 73 69 write is even si
4dc0: 6d 70 6c 65 72 20 6f 77 69 6e 67 20 74 6f 20 74 mpler owing to t
4dd0: 68 65 20 72 75 6c 65 73 20 6f 66 20 5b 42 6f 6f he rules of [Boo
4de0: 6c 65 61 6e 0a 20 20 20 20 61 6c 67 65 62 72 61 lean. algebra
4df0: 5d 28 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b ](https://en.wik
4e00: 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f ipedia.org/wiki/
4e10: 42 6f 6f 6c 65 61 6e 5f 61 6c 67 65 62 72 61 29 Boolean_algebra)
4e20: 3a 0a 0a 20 20 20 20 20 20 20 20 69 66 20 28 21 :.. if (!
4e30: 28 69 20 3d 3d 20 30 20 26 20 6a 20 3d 3d 20 35 (i == 0 & j == 5
4e40: 29 29 0a 0a 20 20 20 20 54 68 65 73 65 20 72 75 )).. These ru
4e50: 6c 65 73 20 6d 65 61 6e 20 74 68 61 74 20 69 66 les mean that if
4e60: 20 77 65 20 6e 65 67 61 74 65 20 74 68 65 20 65 we negate the e
4e70: 6e 74 69 72 65 20 65 78 70 72 65 73 73 69 6f 6e ntire expression
4e80: 2c 20 77 65 20 67 65 74 20 74 68 65 0a 20 20 20 , we get the.
4e90: 20 73 61 6d 65 20 74 72 75 74 68 20 74 61 62 6c same truth tabl
4ea0: 65 20 69 66 20 77 65 20 66 6c 69 70 20 74 68 65 e if we flip the
4eb0: 20 6f 70 65 72 61 74 6f 72 73 20 61 72 6f 75 6e operators aroun
4ec0: 64 20 61 6e 64 20 73 77 61 70 20 74 68 65 0a 20 d and swap the.
4ed0: 20 20 20 6c 6f 67 69 63 61 6c 20 74 65 73 74 20 logical test
4ee0: 66 72 6f 6d 20 4f 52 20 74 6f 20 41 4e 44 2c 20 from OR to AND,
4ef0: 77 68 69 63 68 20 69 6e 20 74 68 69 73 20 63 61 which in this ca
4f00: 73 65 20 63 6f 6e 76 65 72 74 73 20 74 68 65 0a se converts the.
4f10: 20 20 20 20 65 78 70 72 65 73 73 69 6f 6e 20 74 expression t
4f20: 6f 20 61 20 66 6f 72 6d 20 74 68 61 74 20 69 73 o a form that is
4f30: 20 6e 6f 77 20 6c 65 67 61 6c 20 69 6e 20 6f 75 now legal in ou
4f40: 72 20 6c 69 6d 69 74 65 64 20 43 20 64 69 61 6c r limited C dial
4f50: 65 63 74 2e 20 41 6c 6c 0a 20 20 20 20 6f 66 20 ect. All. of
4f60: 74 68 69 73 20 63 6f 6d 65 73 20 66 72 6f 6d 20 this comes from
4f70: 74 68 65 20 4c 61 77 73 20 73 65 63 74 69 6f 6e the Laws section
4f80: 20 6f 66 20 74 68 65 20 6c 69 6e 6b 65 64 20 57 of the linked W
4f90: 69 6b 69 70 65 64 69 61 20 61 72 74 69 63 6c 65 ikipedia article
4fa0: 3b 0a 20 20 20 20 69 66 20 79 6f 75 20 6c 65 61 ;. if you lea
4fb0: 72 6e 20 6e 6f 74 68 69 6e 67 20 65 6c 73 65 20 rn nothing else
4fc0: 61 62 6f 75 74 20 42 6f 6f 6c 65 61 6e 20 61 6c about Boolean al
4fd0: 67 65 62 72 61 2c 20 79 6f 75 20 77 6f 75 6c 64 gebra, you would
4fe0: 20 62 65 20 77 65 6c 6c 0a 20 20 20 20 73 65 72 be well. ser
4ff0: 76 65 64 20 74 6f 20 6d 65 6d 6f 72 69 7a 65 20 ved to memorize
5000: 74 68 6f 73 65 20 72 75 6c 65 73 2e 0a 0a 39 2e those rules...9.
5010: 20 44 65 72 65 66 65 72 65 6e 63 69 6e 67 20 70 Dereferencing p
5020: 61 72 65 6e 74 68 65 73 69 7a 65 64 20 65 78 70 arenthesized exp
5030: 72 65 73 73 69 6f 6e 73 20 64 6f 65 73 20 6e 6f ressions does no
5040: 74 20 77 6f 72 6b 3a 20 60 2a 28 3c 65 78 70 72 t work: `*(<expr
5050: 3e 29 60 0a 0a 31 30 2e 20 54 68 65 72 65 20 69 >)`..10. There i
5060: 73 20 6e 6f 20 61 72 67 75 6d 65 6e 74 20 6c 69 s no argument li
5070: 73 74 20 63 68 65 63 6b 69 6e 67 2c 20 6e 6f 74 st checking, not
5080: 20 65 76 65 6e 20 66 6f 72 20 66 75 6e 63 74 69 even for functi
5090: 6f 6e 73 0a 20 20 20 20 70 72 65 76 69 6f 75 73 ons. previous
50a0: 6c 79 20 64 65 63 6c 61 72 65 64 20 69 6e 20 74 ly declared in t
50b0: 68 65 20 73 61 6d 65 20 43 20 66 69 6c 65 2e 20 he same C file.
50c0: 49 66 20 77 65 20 64 69 64 20 66 69 78 20 74 68 If we did fix th
50d0: 69 73 2c 20 74 68 65 0a 20 20 20 20 70 72 6f 62 is, the. prob
50e0: 6c 65 6d 20 77 6f 75 6c 64 20 73 74 69 6c 6c 20 lem would still
50f0: 65 78 69 73 74 20 66 6f 72 20 66 75 6e 63 74 69 exist for functi
5100: 6f 6e 73 20 69 6e 20 6f 74 68 65 72 20 6d 6f 64 ons in other mod
5110: 75 6c 65 73 2c 20 73 75 63 68 20 61 73 0a 20 20 ules, such as.
5120: 20 20 5b 60 4c 49 42 43 60 5d 28 23 6c 69 62 63 [`LIBC`](#libc
5130: 29 2c 20 73 69 6e 63 65 20 4b 26 52 20 43 20 64 ), since K&R C d
5140: 6f 65 73 6e e2 80 99 74 20 68 61 76 65 20 70 72 oesn’t have pr
5150: 6f 74 6f 74 79 70 65 73 3b 20 41 4e 53 49 20 61 ototypes; ANSI a
5160: 64 64 65 64 0a 20 20 20 20 74 68 61 74 20 66 65 dded. that fe
5170: 61 74 75 72 65 20 74 6f 20 43 2e 0a 0a 31 31 2e ature to C...11.
5180: 20 60 64 6f 2f 77 68 69 6c 65 60 20 6c 6f 6f 70 `do/while` loop
5190: 73 20 61 72 65 20 70 61 72 73 65 64 2c 20 62 75 s are parsed, bu
51a0: 74 20 74 68 65 20 63 6f 64 65 20 69 73 20 6e 6f t the code is no
51b0: 74 20 70 72 6f 70 65 72 6c 79 20 67 65 6e 65 72 t properly gener
51c0: 61 74 65 64 2e 0a 20 20 20 20 52 65 67 75 6c 61 ated.. Regula
51d0: 72 20 60 77 68 69 6c 65 60 20 6c 6f 6f 70 73 20 r `while` loops
51e0: 77 6f 72 6b 2c 20 61 73 20 64 6f 65 73 20 60 62 work, as does `b
51f0: 72 65 61 6b 60 2c 20 73 6f 20 6f 6e 65 20 77 6f reak`, so one wo
5200: 72 6b 61 72 6f 75 6e 64 20 66 6f 72 20 61 0a 20 rkaround for a.
5210: 20 20 20 6c 61 63 6b 20 6f 66 20 60 64 6f 2f 77 lack of `do/w
5220: 68 69 6c 65 60 20 69 73 3a 0a 0a 20 20 20 20 20 hile` is:..
5230: 20 20 20 77 68 69 6c 65 20 28 31 29 20 7b 20 2f while (1) { /
5240: 2a 20 64 6f 20 73 6f 6d 65 74 68 69 6e 67 20 75 * do something u
5250: 73 65 66 75 6c 20 2a 2f 3b 20 69 66 20 28 63 6f seful */; if (co
5260: 6e 64 29 20 62 72 65 61 6b 3b 20 7d 0a 0a 20 20 nd) break; }..
5270: 20 20 57 65 20 68 61 76 65 20 6e 6f 20 69 6e 74 We have no int
5280: 65 6e 74 69 6f 6e 20 74 6f 20 66 69 78 20 74 68 ention to fix th
5290: 69 73 2e 0a 0a 31 32 2e 20 41 73 20 6f 66 20 4d is...12. As of M
52a0: 61 79 20 32 30 32 30 2c 20 60 73 77 69 74 63 68 ay 2020, `switch
52b0: 60 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 65 64 ` is implemented
52c0: 20 76 69 61 20 72 65 2d 77 72 69 74 65 20 74 6f via re-write to
52d0: 20 63 61 73 63 61 64 69 6e 67 0a 20 20 20 20 60 cascading. `
52e0: 69 66 60 2f 60 74 68 65 6e 60 20 73 74 61 74 65 if`/`then` state
52f0: 6d 65 6e 74 73 2e 20 54 68 65 72 65 20 61 72 65 ments. There are
5300: 20 61 20 6e 75 6d 62 65 72 20 6f 66 20 6c 69 6d a number of lim
5310: 69 74 61 74 69 6f 6e 73 20 74 6f 20 74 68 69 73 itations to this
5320: 0a 20 20 20 20 61 70 70 72 6f 61 63 68 20 74 68 . approach th
5330: 61 74 20 61 20 43 43 38 20 75 73 65 72 20 73 68 at a CC8 user sh
5340: 6f 75 6c 64 20 62 65 20 61 77 61 72 65 20 6f 66 ould be aware of
5350: 2e 0a 0a 20 20 20 20 54 68 65 20 70 72 69 6d 61 ... The prima
5360: 72 79 20 6f 6e 65 20 74 6f 20 6b 65 65 70 20 69 ry one to keep i
5370: 6e 20 6d 69 6e 64 20 69 73 20 74 68 61 74 20 74 n mind is that t
5380: 68 61 74 20 69 66 20 79 6f 75 20 75 73 65 20 61 hat if you use a
5390: 0a 20 20 20 20 6d 65 6d 6f 72 79 2d 6d 75 74 61 . memory-muta
53a0: 74 69 6e 67 20 65 78 70 72 65 73 73 69 6f 6e 20 ting expression
53b0: 69 6e 20 74 68 65 20 60 73 77 69 74 63 68 60 20 in the `switch`
53c0: 63 6c 61 75 73 65 20 77 69 74 68 20 61 20 63 6f clause with a co
53d0: 6e 66 6f 72 6d 69 6e 67 0a 20 20 20 20 43 20 63 nforming. C c
53e0: 6f 6d 70 69 6c 65 72 2c 20 69 74 20 69 73 20 65 ompiler, it is e
53f0: 76 61 6c 75 61 74 65 64 20 6a 75 73 74 20 6f 6e valuated just on
5400: 63 65 20 61 74 20 74 68 65 20 73 74 61 72 74 20 ce at the start
5410: 6f 66 20 74 68 65 20 62 6c 6f 63 6b 2c 20 62 75 of the block, bu
5420: 74 0a 20 20 20 20 69 6e 20 43 43 38 2c 20 69 74 t. in CC8, it
5430: 20 69 73 20 65 76 61 6c 75 61 74 65 64 20 6f 6e is evaluated on
5440: 63 65 20 66 6f 72 20 65 61 63 68 20 67 65 6e 65 ce for each gene
5450: 72 61 74 65 64 20 60 69 66 60 20 73 75 62 2d 65 rated `if` sub-e
5460: 78 70 72 65 73 73 69 6f 6e 0a 20 20 20 20 74 68 xpression. th
5470: 61 74 20 74 68 65 20 63 6f 64 65 20 76 69 73 69 at the code visi
5480: 74 73 2e 20 54 68 61 74 20 69 73 2c 20 79 6f 75 ts. That is, you
5490: 20 73 68 6f 75 6c 64 20 6e 6f 74 20 73 61 79 20 should not say
54a0: 74 68 69 6e 67 73 20 6c 69 6b 65 20 74 68 69 73 things like this
54b0: 0a 20 20 20 20 69 6e 20 63 6f 64 65 20 6d 65 61 . in code mea
54c0: 6e 74 20 74 6f 20 62 65 20 63 6f 6d 70 69 6c 65 nt to be compile
54d0: 64 20 77 69 74 68 20 74 68 65 20 43 43 38 20 6e d with the CC8 n
54e0: 61 74 69 76 65 20 63 6f 6d 70 69 6c 65 72 3a 0a ative compiler:.
54f0: 0a 20 20 20 20 20 20 20 20 73 77 69 74 63 68 20 . switch
5500: 28 2a 70 2b 2b 29 20 7b 2e 2e 2e 7d 0a 0a 20 20 (*p++) {...}..
5510: 20 20 53 61 79 20 69 6e 73 74 65 61 64 3a 0a 0a Say instead:..
5520: 20 20 20 20 20 20 20 20 69 6e 74 20 74 65 6d 70 int temp
5530: 20 3d 20 2a 70 2b 2b 3b 0a 20 20 20 20 20 20 20 = *p++;.
5540: 20 73 77 69 74 63 68 20 28 74 65 6d 70 29 20 7b switch (temp) {
5550: 2e 2e 2e 2e 7d 0a 0a 20 20 20 20 41 6c 73 6f 2c ....}.. Also,
5560: 20 74 68 65 72 65 20 2a 2a 6d 75 73 74 2a 2a 20 there **must**
5570: 62 65 20 61 20 60 64 65 66 61 75 6c 74 60 20 63 be a `default` c
5580: 61 73 65 2c 20 61 6e 64 20 63 61 73 65 73 20 28 ase, and cases (
5590: 69 6e 63 6c 75 64 69 6e 67 20 74 68 65 0a 20 20 including the.
55a0: 20 20 64 65 66 61 75 6c 74 20 63 61 73 65 29 20 default case)
55b0: 6d 75 73 74 20 62 65 20 74 65 72 6d 69 6e 61 74 must be terminat
55c0: 65 64 20 77 69 74 68 20 61 20 60 62 72 65 61 6b ed with a `break
55d0: 60 2e 20 43 43 38 20 64 6f 65 73 20 6e 6f 74 20 `. CC8 does not
55e0: 61 6c 6c 6f 77 0a 20 20 20 20 66 6f 72 20 63 61 allow. for ca
55f0: 73 65 73 20 74 68 61 74 20 66 61 6c 6c 20 74 68 ses that fall th
5600: 72 6f 75 67 68 20 74 6f 20 74 68 65 20 66 6f 6c rough to the fol
5610: 6c 6f 77 69 6e 67 20 63 61 73 65 2e 20 54 68 65 lowing case. The
5620: 20 66 6f 6c 6c 6f 77 69 6e 67 0a 20 20 20 20 63 following. c
5630: 6f 64 65 20 68 61 73 20 61 74 20 6c 65 61 73 74 ode has at least
5640: 20 74 68 72 65 65 20 73 79 6e 74 61 78 20 65 72 three syntax er
5650: 72 6f 72 73 3a 0a 0a 20 20 20 20 20 20 20 20 73 rors:.. s
5660: 77 69 74 63 68 20 28 78 29 20 7b 0a 20 20 20 20 witch (x) {.
5670: 20 20 20 20 20 20 20 20 63 61 73 65 20 31 3a 20 case 1:
5680: 20 66 6f 6f 28 29 3b 0a 20 20 20 20 20 20 20 20 foo();.
5690: 20 20 20 20 63 61 73 65 20 32 3a 20 20 62 61 72 case 2: bar
56a0: 28 29 3b 0a 20 20 20 20 20 20 20 20 20 20 20 20 ();.
56b0: 64 65 66 61 75 6c 74 3a 20 71 75 78 28 29 3b 0a default: qux();.
56c0: 20 20 20 20 20 20 20 20 7d 0a 0a 31 33 2e 20 60 }..13. `
56d0: 73 69 7a 65 6f 66 28 29 60 20 69 73 20 6e 6f 74 sizeof()` is not
56e0: 20 69 6d 70 6c 65 6d 65 6e 74 65 64 2e 0a 0a 0a implemented....
56f0: 0a 3c 61 20 69 64 3d 22 77 61 72 6e 69 6e 67 22 .<a id="warning"
5700: 3e 3c 2f 61 3e 0a 23 23 23 23 20 47 4f 56 45 52 ></a>.#### GOVER
5710: 4e 4d 45 4e 54 20 48 45 41 4c 54 48 20 57 41 52 NMENT HEALTH WAR
5720: 4e 49 4e 47 0a 0a 2a 2a 59 6f 75 20 61 72 65 20 NING..**You are
5730: 68 65 72 65 62 79 20 77 61 72 6e 65 64 2a 2a 3a hereby warned**:
5740: 20 54 68 65 20 6e 61 74 69 76 65 20 4f 53 2f 38 The native OS/8
5750: 20 63 6f 6d 70 69 6c 65 72 20 64 6f 65 73 20 6e compiler does n
5760: 6f 74 20 63 6f 6e 74 61 69 6e 20 61 6e 79 0a 65 ot contain any.e
5770: 72 72 6f 72 20 63 68 65 63 6b 69 6e 67 20 77 68 rror checking wh
5780: 61 74 73 6f 65 76 65 72 2e 20 49 66 20 74 68 65 atsoever. If the
5790: 20 73 6f 75 72 63 65 20 66 69 6c 65 73 20 63 6f source files co
57a0: 6e 74 61 69 6e 20 61 6e 20 65 72 72 6f 72 20 6f ntain an error o
57b0: 72 20 79 6f 75 0a 6d 69 73 74 79 70 65 20 61 20 r you.mistype a
57c0: 62 75 69 6c 64 20 63 6f 6d 6d 61 6e 64 2c 20 79 build command, y
57d0: 6f 75 20 6d 61 79 20 67 65 74 3a 0a 0a 2a 20 20 ou may get:..*
57e0: 20 41 20 72 75 6e 74 69 6d 65 20 63 72 61 73 68 A runtime crash
57f0: 20 69 6e 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 in the compiler
5800: 0a 2a 20 20 20 53 41 42 52 20 61 73 73 65 6d 62 .* SABR assemb
5810: 6c 79 20 6f 75 74 70 75 74 20 74 68 61 74 20 77 ly output that w
5820: 6f 6e 27 74 20 61 73 73 65 6d 62 6c 65 0a 2a 20 on't assemble.*
5830: 20 20 4f 75 74 70 75 74 20 74 68 61 74 20 61 73 Output that as
5840: 73 65 6d 62 6c 65 73 20 62 75 74 20 77 6f 6e 27 sembles but won'
5850: 74 20 72 75 6e 20 63 6f 72 72 65 63 74 6c 79 0a t run correctly.
5860: 0a 52 61 72 65 6c 79 20 77 69 6c 6c 20 61 6e 79 .Rarely will any
5870: 20 6f 66 20 74 68 65 73 65 20 66 61 69 6c 75 72 of these failur
5880: 65 20 6d 6f 64 65 73 20 67 69 76 65 20 61 6e 79 e modes give any
5890: 20 6b 69 6e 64 20 6f 66 20 73 65 6e 73 69 62 6c kind of sensibl
58a0: 65 20 68 69 6e 74 20 61 73 0a 74 6f 20 74 68 65 e hint as.to the
58b0: 20 63 61 75 73 65 2e 20 4f 53 2f 38 20 43 43 38 cause. OS/8 CC8
58c0: 20 63 61 6e 6e 6f 74 20 61 66 66 6f 72 64 20 74 cannot afford t
58d0: 68 65 20 68 75 6e 64 72 65 64 73 20 6f 66 20 6b he hundreds of k
58e0: 69 6c 6f 62 79 74 65 73 20 6f 66 20 65 72 72 6f ilobytes of erro
58f0: 72 0a 63 68 65 63 6b 69 6e 67 20 61 6e 64 20 74 r.checking and t
5900: 65 78 74 20 72 65 70 6f 72 74 69 6e 67 20 74 68 ext reporting th
5910: 61 74 20 79 6f 75 20 67 65 74 20 69 6e 20 61 20 at you get in a
5920: 6d 6f 64 65 72 6e 20 63 6f 6d 70 69 6c 65 72 20 modern compiler
5930: 6c 69 6b 65 20 47 43 43 0a 6f 72 20 43 6c 61 6e like GCC.or Clan
5940: 67 2e 20 54 68 61 74 20 77 6f 75 6c 64 20 68 61 g. That would ha
5950: 76 65 20 72 65 71 75 69 72 65 64 20 61 20 72 6f ve required a ro
5960: 6f 6d 66 75 6c 20 6f 66 20 63 6f 72 65 20 6d 65 omful of core me
5970: 6d 6f 72 79 20 74 6f 20 61 63 68 69 65 76 65 0a mory to achieve.
5980: 6f 6e 20 61 20 72 65 61 6c 20 50 44 50 2d 38 2e on a real PDP-8.
5990: 20 53 69 6e 63 65 20 77 65 27 72 65 20 77 6f 72 Since we're wor
59a0: 6b 69 6e 67 20 77 69 74 68 69 6e 20 74 68 65 20 king within the
59b0: 63 6f 6e 73 74 72 61 69 6e 74 73 20 6f 66 20 74 constraints of t
59c0: 68 65 20 6f 6c 64 0a 50 44 50 2d 38 20 61 72 63 he old.PDP-8 arc
59d0: 68 69 74 65 63 74 75 72 65 2c 20 77 65 20 6f 6e hitecture, we on
59e0: 6c 79 20 68 61 76 65 20 61 62 6f 75 74 20 33 26 ly have about 3&
59f0: 6e 62 73 70 3b 6b 57 6f 72 64 73 20 74 6f 20 63 nbsp;kWords to c
5a00: 6f 6e 73 74 72 75 63 74 20 74 68 65 20 70 61 72 onstruct the par
5a10: 73 65 0a 72 65 73 75 6c 74 2c 20 66 6f 72 20 65 se.result, for e
5a20: 78 61 6d 70 6c 65 2e 0a 0a 49 6e 20 61 64 64 69 xample...In addi
5a30: 74 69 6f 6e 2c 20 74 68 65 20 6e 61 74 69 76 65 tion, the native
5a40: 20 4f 53 2f 38 20 63 6f 6d 70 69 6c 65 72 20 69 OS/8 compiler i
5a50: 73 20 73 65 76 65 72 65 6c 79 20 6c 69 6d 69 74 s severely limit
5a60: 65 64 20 69 6e 20 63 6f 64 65 20 73 70 61 63 65 ed in code space
5a70: 2c 0a 73 6f 20 69 74 20 64 6f 65 73 20 6e 6f 74 ,.so it does not
5a80: 20 75 6e 64 65 72 73 74 61 6e 64 20 74 68 65 20 understand the
5a90: 66 75 6c 6c 20 43 20 6c 61 6e 67 75 61 67 65 2e full C language.
5aa0: 20 49 74 20 69 73 20 6c 65 73 73 20 66 75 6e 63 It is less func
5ab0: 74 69 6f 6e 61 6c 0a 74 68 61 6e 20 4b 26 52 20 tional.than K&R
5ac0: 43 20 31 39 37 38 3b 20 77 65 20 64 6f 20 6e 6f C 1978; we do no
5ad0: 74 20 68 61 76 65 20 61 20 67 6f 6f 64 20 62 65 t have a good be
5ae0: 6e 63 68 6d 61 72 6b 20 66 6f 72 20 77 68 61 74 nchmark for what
5af0: 20 69 74 20 63 6f 6d 70 61 72 65 73 20 74 6f 0a it compares to.
5b00: 69 6e 20 74 65 72 6d 73 20 6f 66 20 6f 74 68 65 in terms of othe
5b10: 72 20 65 61 72 6c 79 20 43 20 64 69 61 6c 65 63 r early C dialec
5b20: 74 73 2c 20 62 75 74 20 77 65 20 63 61 6e 20 73 ts, but we can s
5b30: 75 6d 20 69 74 20 75 70 20 69 6e 20 61 20 73 69 um it up in a si
5b40: 6e 67 6c 65 0a 77 6f 72 64 3a 20 70 72 69 6d 69 ngle.word: primi
5b50: 74 69 76 65 2e 0a 0a 4e 6f 6e 65 74 68 65 6c 65 tive...Nonethele
5b60: 73 73 2c 20 6f 75 72 20 68 69 67 68 6c 79 20 6c ss, our highly l
5b70: 69 6d 69 74 65 64 20 43 20 64 69 61 6c 65 63 74 imited C dialect
5b80: 20 69 73 20 54 75 72 69 6e 67 20 63 6f 6d 70 6c is Turing compl
5b90: 65 74 65 2e 20 49 74 20 6d 69 67 68 74 0a 62 65 ete. It might.be
5ba0: 20 62 65 74 74 65 72 20 74 6f 20 74 68 69 6e 6b better to think
5bb0: 20 6f 66 20 69 74 20 61 73 20 61 20 68 69 67 68 of it as a high
5bc0: 2d 6c 65 76 65 6c 20 61 73 73 65 6d 62 6c 79 20 -level assembly
5bd0: 6c 61 6e 67 75 61 67 65 20 74 68 61 74 0a 72 65 language that.re
5be0: 73 65 6d 62 6c 65 73 20 43 20 72 61 74 68 65 72 sembles C rather
5bf0: 20 74 68 61 6e 20 61 73 20 22 43 22 20 70 72 6f than as "C" pro
5c00: 70 65 72 2e 0a 0a 0a 23 23 20 3c 61 20 69 64 3d per....## <a id=
5c10: 22 6c 69 62 63 22 3e 3c 2f 61 3e 54 68 65 20 43 "libc"></a>The C
5c20: 43 38 20 43 20 4c 69 62 72 61 72 79 3a 20 44 6f C8 C Library: Do
5c30: 63 75 6d 65 6e 74 61 74 69 6f 6e 0a 0a 49 6e 20 cumentation..In
5c40: 74 68 69 73 20 73 65 63 74 69 6f 6e 2c 20 77 65 this section, we
5c50: 20 77 69 6c 6c 20 65 78 70 6c 61 69 6e 20 73 6f will explain so
5c60: 6d 65 20 68 69 67 68 2d 6c 65 76 65 6c 20 6d 61 me high-level ma
5c70: 74 74 65 72 73 20 74 68 61 74 20 63 75 74 20 61 tters that cut a
5c80: 63 72 6f 73 73 0a 6d 75 6c 74 69 70 6c 65 20 66 cross.multiple f
5c90: 75 6e 63 74 69 6f 6e 73 20 69 6e 20 74 68 65 20 unctions in the
5ca0: 43 20 6c 69 62 72 61 72 79 2e 20 54 68 69 73 20 C library. This
5cb0: 6d 61 74 65 72 69 61 6c 20 69 73 20 74 68 65 72 material is ther
5cc0: 65 66 6f 72 65 20 6e 6f 74 0a 61 70 70 72 6f 70 efore not.approp
5cd0: 72 69 61 74 65 20 74 6f 20 72 65 70 65 61 74 20 riate to repeat
5ce0: 62 65 6c 6f 77 2c 20 69 6e 20 74 68 65 20 5b 43 below, in the [C
5cf0: 20 6c 69 62 72 61 72 79 20 66 75 6e 63 74 69 6f library functio
5d00: 6e 0a 72 65 66 65 72 65 6e 63 65 5d 28 23 6c 69 n.reference](#li
5d10: 62 72 65 66 29 2e 0a 0a 0a 23 23 23 20 3c 61 20 bref)....### <a
5d20: 69 64 3d 22 63 74 79 70 65 22 3e 3c 2f 61 3e 63 id="ctype"></a>c
5d30: 74 79 70 65 0a 0a 54 68 65 20 49 53 4f 20 43 20 type..The ISO C
5d40: 53 74 61 6e 64 61 72 64 20 64 6f 65 73 20 6e 6f Standard does no
5d50: 74 20 64 65 66 69 6e 65 20 77 68 61 74 20 74 68 t define what th
5d60: 65 20 60 69 73 2a 28 29 60 20 66 75 6e 63 74 69 e `is*()` functi
5d70: 6f 6e 73 20 64 6f 20 77 68 65 6e 0a 74 68 65 20 ons do when.the
5d80: 70 61 73 73 65 64 20 63 68 61 72 61 63 74 65 72 passed character
5d90: 20 69 73 20 6e 6f 74 20 72 65 70 72 65 73 65 6e is not represen
5da0: 74 61 62 6c 65 20 61 73 20 60 75 6e 73 69 67 6e table as `unsign
5db0: 65 64 20 63 68 61 72 60 2e 20 53 69 6e 63 65 20 ed char`. Since
5dc0: 74 68 69 73 0a 43 20 63 6f 6d 70 69 6c 65 72 20 this.C compiler
5dd0: 5b 64 6f 65 73 20 6e 6f 74 20 64 69 73 74 69 6e [does not distin
5de0: 67 75 69 73 68 20 74 79 70 65 73 5d 28 23 74 79 guish types](#ty
5df0: 70 65 6c 65 73 73 29 2c 20 6f 75 72 20 60 69 73 peless), our `is
5e00: 2a 28 29 60 0a 66 75 6e 63 74 69 6f 6e 73 20 72 *()`.functions r
5e10: 65 74 75 72 6e 20 66 61 6c 73 65 20 66 6f 72 20 eturn false for
5e20: 61 6e 79 20 76 61 6c 75 65 20 6f 75 74 73 69 64 any value outsid
5e30: 65 20 6f 66 20 74 68 65 20 41 53 43 49 49 20 72 e of the ASCII r
5e40: 61 6e 67 65 2c 20 30 2d 31 32 37 2e 0a 0a 0a 23 ange, 0-127....#
5e50: 23 23 20 3c 61 20 69 64 3d 22 63 73 65 74 22 3e ## <a id="cset">
5e60: 3c 2f 61 3e 43 68 61 72 61 63 74 65 72 20 53 65 </a>Character Se
5e70: 74 0a 0a 54 68 65 20 73 74 64 69 6f 20 69 6d 70 t..The stdio imp
5e80: 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 63 75 72 72 lementation curr
5e90: 65 6e 74 6c 79 20 61 73 73 75 6d 65 73 20 55 53 ently assumes US
5ea0: 2d 41 53 43 49 49 20 37 2d 62 69 74 20 74 65 78 -ASCII 7-bit tex
5eb0: 74 20 49 2f 4f 2e 0a 0a 49 6e 70 75 74 20 63 68 t I/O...Input ch
5ec0: 61 72 61 63 74 65 72 73 20 68 61 76 65 20 74 68 aracters have th
5ed0: 65 69 72 20 75 70 70 65 72 20 35 20 62 69 74 73 eir upper 5 bits
5ee0: 20 6d 61 73 6b 65 64 20 6f 66 66 20 73 6f 20 74 masked off so t
5ef0: 68 61 74 20 6f 6e 6c 79 20 74 68 65 0a 6c 6f 77 hat only the.low
5f00: 65 72 20 37 20 62 69 74 73 20 61 72 65 20 76 61 er 7 bits are va
5f10: 6c 69 64 20 69 6e 20 74 68 65 20 72 65 74 75 72 lid in the retur
5f20: 6e 65 64 20 31 32 20 62 69 74 20 50 44 50 2d 38 ned 12 bit PDP-8
5f30: 20 77 6f 72 64 2e 20 43 6f 64 65 20 75 73 69 6e word. Code usin
5f40: 67 0a 5b 60 66 67 65 74 63 60 5d 28 23 66 67 65 g.[`fgetc`](#fge
5f50: 74 63 29 20 63 61 6e 6e 6f 74 20 62 65 20 75 73 tc) cannot be us
5f60: 65 64 20 6f 6e 20 61 72 62 69 74 72 61 72 79 20 ed on arbitrary
5f70: 62 69 6e 61 72 79 20 64 61 74 61 20 62 65 63 61 binary data beca
5f80: 75 73 65 20 69 74 73 0a e2 80 9c 65 6e 64 20 6f use its.“end o
5f90: 66 20 66 69 6c 65 e2 80 9d 20 72 65 74 75 72 6e f file” return
5fa0: 20 63 61 73 65 20 69 73 20 69 6e 64 69 73 74 69 case is indisti
5fb0: 6e 67 75 69 73 68 61 62 6c 65 20 66 72 6f 6d 20 nguishable from
5fc0: 72 65 61 64 69 6e 67 20 61 20 30 20 62 79 74 65 reading a 0 byte
5fd0: 2e 0a 0a 54 68 65 20 6f 75 74 70 75 74 20 66 75 ...The output fu
5fe0: 6e 63 74 69 6f 6e 73 20 77 69 6c 6c 20 61 74 74 nctions will att
5ff0: 65 6d 70 74 20 74 6f 20 73 74 6f 72 65 20 38 2d empt to store 8-
6000: 62 69 74 20 64 61 74 61 2c 20 62 75 74 20 73 69 bit data, but si
6010: 6e 63 65 20 79 6f 75 0a 63 61 6e e2 80 99 74 20 nce you.can’t
6020: 72 65 61 64 20 69 74 20 62 61 63 6b 20 69 6e 20 read it back in
6030: 73 61 66 65 6c 79 20 77 69 74 68 20 74 68 69 73 safely with this
6040: 20 63 75 72 72 65 6e 74 20 69 6d 70 6c 65 6d 65 current impleme
6050: 6e 74 61 74 69 6f 6e 2c 20 70 65 72 0a 61 62 6f ntation, per.abo
6060: 76 65 2c 20 79 6f 75 20 73 68 6f 75 6c 64 20 6f ve, you should o
6070: 6e 6c 79 20 77 72 69 74 65 20 41 53 43 49 49 20 nly write ASCII
6080: 74 65 78 74 20 74 6f 20 6f 75 74 70 75 74 20 66 text to output f
6090: 69 6c 65 73 20 77 69 74 68 20 74 68 69 73 0a 69 iles with this.i
60a0: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 20 45 mplementation. E
60b0: 76 65 6e 20 69 66 20 79 6f 75 20 61 72 65 20 72 ven if you are r
60c0: 65 61 64 69 6e 67 20 79 6f 75 72 20 66 69 6c 65 eading your file
60d0: 73 20 77 69 74 68 20 73 6f 6d 65 20 6f 74 68 65 s with some othe
60e0: 72 20 63 6f 64 65 0a 77 68 69 63 68 20 69 73 20 r code.which is
60f0: 63 61 70 61 62 6c 65 20 6f 66 20 68 61 6e 64 6c capable of handl
6100: 69 6e 67 20 38 2d 62 69 74 20 64 61 74 61 2c 20 ing 8-bit data,
6110: 74 68 65 72 65 20 61 72 65 20 66 75 72 74 68 65 there are furthe
6120: 72 20 64 69 66 66 69 63 75 6c 74 69 65 73 0a 73 r difficulties.s
6130: 75 63 68 20 61 73 20 61 20 6c 61 63 6b 20 6f 66 uch as a lack of
6140: 20 66 75 6e 63 74 69 6f 6e 73 20 74 61 6b 69 6e functions takin
6150: 67 20 61 6e 20 65 78 70 6c 69 63 69 74 20 6c 65 g an explicit le
6160: 6e 67 74 68 2c 20 6c 69 6b 65 20 60 66 77 72 69 ngth, like `fwri
6170: 74 65 28 29 60 2c 0a 77 68 69 63 68 20 6d 61 6b te()`,.which mak
6180: 65 73 20 64 65 61 6c 69 6e 67 20 77 69 74 68 20 es dealing with
6190: 41 53 43 49 49 20 4e 55 4c 20 64 69 66 66 69 63 ASCII NUL diffic
61a0: 75 6c 74 2e 20 59 6f 75 20 63 6f 75 6c 64 20 77 ult. You could w
61b0: 72 69 74 65 20 61 20 4e 55 4c 20 74 6f 0a 61 6e rite a NUL to.an
61c0: 20 6f 75 74 70 75 74 20 66 69 6c 65 20 77 69 74 output file wit
61d0: 68 20 60 66 70 75 74 63 28 29 60 2c 20 62 75 74 h `fputc()`, but
61e0: 20 6e 6f 74 20 77 69 74 68 20 60 66 70 75 74 73 not with `fputs
61f0: 28 29 60 2c 20 73 69 6e 63 65 20 4e 55 4c 0a 74 ()`, since NUL.t
6200: 65 72 6d 69 6e 61 74 65 73 20 74 68 65 20 6f 75 erminates the ou
6210: 74 70 75 74 20 73 74 72 69 6e 67 2e 0a 0a 0a 23 tput string....#
6220: 23 23 20 3c 61 20 69 64 3d 22 77 6f 72 64 73 74 ## <a id="wordst
6230: 72 22 3e 3c 2f 61 3e 53 74 72 69 6e 67 73 20 61 r"></a>Strings a
6240: 72 65 20 6f 66 20 57 6f 72 64 73 2c 20 4e 6f 74 re of Words, Not
6250: 20 6f 66 20 42 79 74 65 73 20 6f 72 20 43 68 61 of Bytes or Cha
6260: 72 61 63 74 65 72 73 0a 0a 49 6e 20 73 65 76 65 racters..In seve
6270: 72 61 6c 20 70 6c 61 63 65 73 2c 20 74 68 65 20 ral places, the
6280: 53 74 61 6e 64 61 72 64 20 73 61 79 73 20 61 20 Standard says a
6290: 63 6f 6e 66 6f 72 6d 69 6e 67 20 43 20 6c 69 62 conforming C lib
62a0: 72 61 72 79 20 69 73 20 73 75 70 70 6f 73 65 64 rary is supposed
62b0: 0a 74 6f 20 6f 70 65 72 61 74 65 20 6f 6e 20 e2 .to operate on
62c0: 80 9c 62 79 74 65 73 e2 80 9d 20 6f 72 20 e2 80 bytes” or
62d0: 9c 63 68 61 72 61 63 74 65 72 73 2c e2 80 9d 20 characters,”
62e0: 61 74 20 6c 65 61 73 74 20 61 63 63 6f 72 64 69 at least accordi
62f0: 6e 67 20 74 6f 20 5b 6f 75 72 20 63 68 6f 73 65 ng to [our chose
6300: 6e 0a 69 6e 74 65 72 70 72 65 74 61 74 69 6f 6e n.interpretation
6310: 5d 5b 63 70 70 72 5d 2e 20 45 78 63 65 70 74 20 ][cppr]. Except
6320: 66 6f 72 20 74 68 65 20 74 65 78 74 20 49 2f 4f for the text I/O
6330: 20 72 65 73 74 72 69 63 74 69 6f 6e 73 20 63 61 restrictions ca
6340: 6c 6c 65 64 20 6f 75 74 0a 5b 61 62 6f 76 65 5d lled out.[above]
6350: 28 23 63 73 65 74 29 2c 20 4c 49 42 43 20 6f 70 (#cset), LIBC op
6360: 65 72 61 74 65 73 20 6f 6e 20 73 74 72 69 6e 67 erates on string
6370: 73 20 6f 66 20 50 44 50 2d 38 20 77 6f 72 64 73 s of PDP-8 words
6380: 2c 20 6e 6f 74 20 6f 6e 20 74 68 65 73 65 0a 6d , not on these.m
6390: 6f 64 65 72 6e 20 6e 6f 74 69 6f 6e 73 20 6f 66 odern notions of
63a0: 20 66 69 78 65 64 20 38 2d 62 69 74 20 62 79 74 fixed 8-bit byt
63b0: 65 73 20 6f 72 20 74 68 65 20 65 76 65 72 2d 6e es or the ever-n
63c0: 65 62 75 6c 6f 75 73 20 e2 80 9c 63 68 61 72 61 ebulous “chara
63d0: 63 74 65 72 73 2e e2 80 9d 0a 0a 42 65 63 61 75 cters.”..Becau
63e0: 73 65 20 79 6f 75 20 6d 61 79 20 62 65 20 75 73 se you may be us
63f0: 65 64 20 74 6f 20 74 68 65 20 69 64 65 61 20 74 ed to the idea t
6400: 68 61 74 20 73 74 72 69 6e 67 20 61 6e 64 20 6d hat string and m
6410: 65 6d 6f 72 79 20 66 75 6e 63 74 69 6f 6e 73 0a emory functions.
6420: 6c 69 6b 65 20 5b 60 6d 65 6d 63 70 79 28 29 60 like [`memcpy()`
6430: 5d 28 23 6d 65 6d 63 70 79 29 20 61 6e 64 20 5b ](#memcpy) and [
6440: 60 73 74 72 63 61 74 28 29 60 5d 28 23 73 74 72 `strcat()`](#str
6450: 63 61 74 29 20 77 69 6c 6c 20 6f 70 65 72 61 74 cat) will operat
6460: 65 20 6f 6e 0a 62 79 74 65 73 2c 20 77 65 e2 80 e on.bytes, we
6470: 99 76 65 20 6d 61 72 6b 65 64 20 61 6c 6c 20 6f ve marked all o
6480: 66 20 74 68 65 73 65 20 63 61 73 65 73 20 77 69 f these cases wi
6490: 74 68 20 61 20 72 65 66 65 72 65 6e 63 65 20 62 th a reference b
64a0: 61 63 6b 20 74 6f 20 74 68 69 73 0a 73 65 63 74 ack to this.sect
64b0: 69 6f 6e 2e 0a 0a 42 79 20 74 68 65 20 73 61 6d ion...By the sam
64c0: 65 20 74 6f 6b 65 6e 2c 20 6d 6f 73 74 20 66 75 e token, most fu
64d0: 6e 63 74 69 6f 6e 73 20 74 68 61 74 20 6f 70 65 nctions that ope
64e0: 72 61 74 65 20 6f 6e 20 4e 55 4c 2d 74 65 72 6d rate on NUL-term
64f0: 69 6e 61 74 65 64 20 73 74 72 69 6e 67 0a 62 75 inated string.bu
6500: 66 66 65 72 73 20 69 6e 20 61 20 63 6f 6e 66 6f ffers in a confo
6510: 72 6d 69 6e 67 20 43 20 6c 69 62 72 61 72 79 20 rming C library
6520: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 61 implementation a
6530: 63 74 75 61 6c 6c 79 20 63 68 65 63 6b 20 66 6f ctually check fo
6540: 72 20 61 0a 77 6f 72 64 20 65 71 75 61 6c 20 74 r a.word equal t
6550: 6f 20 30 30 30 30 e2 82 88 20 69 6e 20 74 68 69 o 0000₈ in thi
6560: 73 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e s implementation
6570: 2e 20 54 68 65 20 6b 65 79 20 74 68 69 6e 67 20 . The key thing
6580: 74 6f 20 75 6e 64 65 72 73 74 61 6e 64 0a 69 73 to understand.is
6590: 20 74 68 61 74 20 74 68 65 73 65 20 72 6f 75 74 that these rout
65a0: 69 6e 65 73 20 61 72 65 20 6e 6f 74 20 63 61 72 ines are not car
65b0: 65 66 75 6c 6c 79 20 6d 61 73 6b 69 6e 67 20 6f efully masking o
65c0: 66 66 20 74 68 65 20 74 6f 70 20 34 20 6f 72 20 ff the top 4 or
65d0: 35 20 62 69 74 73 0a 74 6f 20 63 68 65 63 6b 20 5 bits.to check
65e0: 2a 6f 6e 6c 79 2a 20 61 67 61 69 6e 73 74 20 61 *only* against a
65f0: 20 37 2d 20 6f 72 20 38 2d 62 69 74 20 4e 55 4c 7- or 8-bit NUL
6600: 20 63 68 61 72 61 63 74 65 72 2e 0a 0a 54 68 69 character...Thi
6610: 73 20 69 73 20 61 6e 6f 74 68 65 72 20 6d 61 6e s is another man
6620: 69 66 65 73 74 61 74 69 6f 6e 20 6f 66 20 5b 43 ifestation of [C
6630: 43 38 e2 80 99 73 20 74 79 70 65 6c 65 73 73 20 C8’s typeless
6640: 6e 61 74 75 72 65 5d 28 23 74 79 70 65 6c 65 73 nature](#typeles
6650: 73 29 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d s)....### <a id=
6660: 22 66 69 6f 6c 69 6d 22 3e 3c 2f 61 3e 46 69 6c "fiolim"></a>Fil
6670: 65 20 49 2f 4f 20 4c 69 6d 69 74 61 74 69 6f 6e e I/O Limitation
6680: 73 0a 0a 42 65 63 61 75 73 65 20 4c 49 42 43 e2 s..Because LIBC
6690: 80 99 73 20 73 74 64 69 6f 20 69 6d 70 6c 65 6d s stdio implem
66a0: 65 6e 74 61 74 69 6f 6e 20 69 73 20 62 75 69 6c entation is buil
66b0: 74 20 61 74 6f 70 20 74 68 65 20 4f 53 2f 38 20 t atop the OS/8
66c0: 46 4f 52 54 52 41 4e 20 49 49 0a 6c 69 62 72 61 FORTRAN II.libra
66d0: 72 79 2c 20 69 74 20 6f 6e 6c 79 20 61 6c 6c 6f ry, it only allo
66e0: 77 73 20 6f 6e 65 20 66 69 6c 65 20 74 6f 20 62 ws one file to b
66f0: 65 20 6f 70 65 6e 20 61 74 20 61 20 74 69 6d 65 e open at a time
6700: 20 66 6f 72 20 72 65 61 64 69 6e 67 20 61 6e 64 for reading and
6710: 0a 6f 6e 65 20 66 6f 72 20 77 72 69 74 69 6e 67 .one for writing
6720: 2e 20 4f 53 2f 38 e2 80 99 73 20 75 6e 64 65 72 . OS/8’s under
6730: 6c 79 69 6e 67 20 6c 69 6d 69 74 20 69 73 20 35 lying limit is 5
6740: 20 6f 75 74 70 75 74 20 66 69 6c 65 73 20 61 6e output files an
6750: 64 20 39 20 69 6e 70 75 74 0a 66 69 6c 65 73 2c d 9 input.files,
6760: 20 77 68 69 63 68 20 61 70 70 65 61 72 73 20 74 which appears t
6770: 6f 20 62 65 20 61 6e 20 61 63 63 6f 6d 6d 6f 64 o be an accommod
6780: 61 74 69 6f 6e 20 73 70 65 63 69 66 69 63 61 6c ation specifical
6790: 6c 79 20 66 6f 72 20 69 74 73 20 46 4f 52 54 52 ly for its FORTR
67a0: 41 4e 0a 49 56 20 69 6d 70 6c 65 6d 65 6e 74 61 AN.IV implementa
67b0: 74 69 6f 6e 2c 20 73 6f 20 69 74 20 69 73 20 70 tion, so it is p
67c0: 6f 73 73 69 62 6c 65 20 74 68 61 74 20 61 20 66 ossible that a f
67d0: 75 74 75 72 65 20 43 43 38 20 77 6f 75 6c 64 20 uture CC8 would
67e0: 62 65 0a 72 65 74 61 72 67 65 74 65 64 20 61 74 be.retargeted at
67f0: 20 46 4f 52 54 52 41 4e 20 49 56 20 74 6f 20 6c FORTRAN IV to l
6800: 69 66 74 20 74 68 69 73 20 6c 69 6d 69 74 61 74 ift this limitat
6810: 69 6f 6e 2c 20 62 75 74 20 69 74 20 77 6f 75 6c ion, but it woul
6820: 64 20 62 65 20 61 0a 6e 6f 6e 74 72 69 76 69 61 d be a.nontrivia
6830: 6c 20 61 6d 6f 75 6e 74 20 6f 66 20 77 6f 72 6b l amount of work
6840: 2e 0a 0a 4d 65 61 6e 77 68 69 6c 65 2c 20 77 65 ...Meanwhile, we
6850: 20 67 65 6e 65 72 61 6c 6c 79 20 64 65 66 65 72 generally defer
6860: 20 74 6f 20 74 68 65 20 4f 53 2f 38 20 46 4f 52 to the OS/8 FOR
6870: 54 52 41 4e 20 49 49 20 6d 61 6e 75 61 6c 20 77 TRAN II manual w
6880: 68 65 72 65 20 69 74 0a 63 6f 6d 65 73 20 74 6f here it.comes to
6890: 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 6f documentation o
68a0: 66 20 74 68 65 73 65 20 66 75 6e 63 74 69 6f 6e f these function
68b0: 73 20 62 65 68 61 76 69 6f 72 2e 20 20 54 68 65 s behavior. The
68c0: 20 6f 6e 6c 79 20 74 69 6d 65 20 77 65 0a 62 72 only time we.br
68d0: 69 6e 67 20 69 74 20 75 70 20 69 6e 20 74 68 69 ing it up in thi
68e0: 73 20 6d 61 6e 75 61 6c 20 69 73 20 77 68 65 6e s manual is when
68f0: 20 74 68 65 72 65 20 69 73 20 65 69 74 68 65 72 there is either
6900: 20 61 20 6d 69 73 6d 61 74 63 68 20 62 65 74 77 a mismatch betw
6910: 65 65 6e 0a 65 78 70 65 63 74 65 64 20 43 20 62 een.expected C b
6920: 65 68 61 76 69 6f 72 20 61 6e 64 20 61 63 74 75 ehavior and actu
6930: 61 6c 20 46 4f 52 54 52 41 4e 20 49 49 20 62 65 al FORTRAN II be
6940: 68 61 76 69 6f 72 20 6f 72 20 62 65 74 77 65 65 havior or betwee
6950: 6e 20 74 68 65 20 77 61 79 0a 4f 53 2f 38 20 46 n the way.OS/8 F
6960: 4f 52 54 52 41 4e 20 49 49 20 69 73 20 64 6f 63 ORTRAN II is doc
6970: 75 6d 65 6e 74 65 64 20 61 6e 64 20 74 68 65 20 umented and the
6980: 77 61 79 20 74 68 69 6e 67 73 20 61 63 74 75 61 way things actua
6990: 6c 6c 79 20 77 6f 72 6b 20 77 68 65 6e 20 69 74 lly work when it
69a0: e2 80 99 73 0a 62 65 69 6e 67 20 64 72 69 76 65 ’s.being drive
69b0: 6e 20 62 79 20 43 43 38 2e 0a 0a 54 68 69 73 20 n by CC8...This
69c0: 75 6e 64 65 72 6c 79 69 6e 67 20 62 61 73 65 20 underlying base
69d0: 68 61 73 20 61 6e 20 69 6d 70 6f 72 74 61 6e 74 has an important
69e0: 20 69 6d 70 6c 69 63 61 74 69 6f 6e 3a 20 70 72 implication: pr
69f0: 6f 67 72 61 6d 73 20 62 75 69 6c 74 20 77 69 74 ograms built wit
6a00: 68 0a 43 43 38 20 77 68 69 63 68 20 75 73 65 20 h.CC8 which use
6a10: 69 74 73 20 66 69 6c 65 20 49 2f 4f 20 66 75 6e its file I/O fun
6a20: 63 74 69 6f 6e 73 20 61 72 65 20 64 65 70 65 6e ctions are depen
6a30: 64 65 6e 74 20 75 70 6f 6e 20 4f 53 2f 38 2e 20 dent upon OS/8.
6a40: 20 54 68 61 74 0a 75 6e 64 65 72 6c 79 69 6e 67 That.underlying
6a50: 20 62 61 73 65 20 64 65 74 65 72 6d 69 6e 65 73 base determines
6a60: 20 68 6f 77 20 66 69 6c 65 20 6e 61 6d 65 73 20 how file names
6a70: 61 72 65 20 69 6e 74 65 72 70 72 65 74 65 64 2c are interpreted,
6a80: 20 77 68 61 74 20 64 65 76 69 63 65 73 0a 67 65 what devices.ge
6a90: 74 20 75 73 65 64 2c 20 65 74 63 2e 0a 0a 42 65 t used, etc...Be
6aa0: 63 61 75 73 65 20 6f 66 20 74 68 69 73 20 73 69 cause of this si
6ab0: 6e 67 6c 65 2d 66 69 6c 65 20 6c 69 6d 69 74 61 ngle-file limita
6ac0: 74 69 6f 6e 2c 20 74 68 65 20 73 74 64 69 6f 20 tion, the stdio
6ad0: 66 75 6e 63 74 69 6f 6e 73 20 6f 70 65 72 61 74 functions operat
6ae0: 69 6e 67 20 6f 6e 0a 66 69 6c 65 73 20 64 6f 20 ing on.files do
6af0: 6e 6f 74 20 74 61 6b 65 20 61 20 60 46 49 4c 45 not take a `FILE
6b00: 2a 60 20 61 72 67 75 6d 65 6e 74 20 61 73 20 69 *` argument as i
6b10: 6e 20 53 74 61 6e 64 61 72 64 20 43 2c 20 74 68 n Standard C, th
6b20: 65 72 65 20 62 65 69 6e 67 20 6e 6f 0a 6e 65 65 ere being no.nee
6b30: 64 20 74 6f 20 73 70 65 63 69 66 79 20 77 68 69 d to specify whi
6b40: 63 68 20 66 69 6c 65 20 69 73 20 6d 65 61 6e 74 ch file is meant
6b50: 2e 20 4f 75 74 70 75 74 20 66 75 6e 63 74 69 6f . Output functio
6b60: 6e 73 20 75 73 65 20 74 68 65 20 6f 6e 65 20 61 ns use the one a
6b70: 6e 64 0a 6f 6e 6c 79 20 6f 75 74 70 75 74 20 66 nd.only output f
6b80: 69 6c 65 2c 20 61 6e 64 20 69 6e 70 75 74 20 66 ile, and input f
6b90: 75 6e 63 74 69 6f 6e 73 20 75 73 65 20 74 68 65 unctions use the
6ba0: 20 6f 6e 65 20 61 6e 64 20 6f 6e 6c 79 20 69 6e one and only in
6bb0: 70 75 74 20 66 69 6c 65 2e 0a 4f 75 72 20 5b 60 put file..Our [`
6bc0: 66 6f 70 65 6e 28 29 60 5d 28 23 66 6f 70 65 6e fopen()`](#fopen
6bd0: 29 20 64 6f 65 73 6e e2 80 99 74 20 72 65 74 75 ) doesn’t retu
6be0: 72 6e 20 61 20 60 46 49 4c 45 2a 60 20 62 65 63 rn a `FILE*` bec
6bf0: 61 75 73 65 20 74 68 65 20 63 61 6c 6c 65 72 0a ause the caller.
6c00: 64 6f 65 73 6e e2 80 99 74 20 6e 65 65 64 20 6f doesn’t need o
6c10: 6e 65 20 74 6f 20 70 61 73 73 20 74 6f 20 61 6e ne to pass to an
6c20: 79 20 6f 66 20 74 68 65 20 6f 74 68 65 72 20 66 y of the other f
6c30: 75 6e 63 74 69 6f 6e 73 2e 20 54 68 61 74 20 6c unctions. That l
6c40: 65 61 76 65 73 20 6f 6e 6c 79 0a 5b 60 66 63 6c eaves only.[`fcl
6c50: 6f 73 65 28 29 60 5d 28 23 66 63 6c 6f 73 65 29 ose()`](#fclose)
6c60: 2c 20 77 68 69 63 68 20 77 6f 75 6c 64 20 62 65 , which would be
6c70: 20 61 6e 20 61 6d 62 69 67 75 6f 75 73 20 63 61 an ambiguous ca
6c80: 6c 6c 20 77 69 74 68 6f 75 74 20 61 0a 60 46 49 ll without a.`FI
6c90: 4c 45 2a 60 20 61 72 67 75 6d 65 6e 74 20 69 66 LE*` argument if
6ca0: 20 69 74 20 77 61 73 6e e2 80 99 74 20 66 6f 72 it wasn’t for
6cb0: 20 74 68 65 20 66 61 63 74 20 74 68 61 74 20 4f the fact that O
6cc0: 53 2f 38 20 46 4f 52 54 52 41 4e 20 49 49 20 64 S/8 FORTRAN II d
6cd0: 6f 65 73 6e e2 80 99 74 0a 68 61 76 65 20 61 6e oesn’t.have an
6ce0: 20 60 49 43 4c 4f 53 45 60 20 6c 69 62 72 61 72 `ICLOSE` librar
6cf0: 79 20 66 75 6e 63 74 69 6f 6e 2c 20 74 68 65 72 y function, ther
6d00: 65 20 61 70 70 61 72 65 6e 74 6c 79 20 62 65 69 e apparently bei
6d10: 6e 67 20 6e 6f 20 72 65 73 6f 75 72 63 65 73 0a ng no resources.
6d20: 74 6f 20 66 72 65 65 20 6f 6e 20 63 6c 6f 73 69 to free on closi
6d30: 6e 67 20 61 6e 20 69 6e 70 75 74 20 66 69 6c 65 ng an input file
6d40: 2e 0a 0a 41 6c 6c 20 6f 66 20 74 68 69 73 20 6d ...All of this m
6d50: 65 61 6e 73 20 74 68 61 74 20 74 6f 20 6f 70 65 eans that to ope
6d60: 6e 20 6d 75 6c 74 69 70 6c 65 20 6f 75 74 70 75 n multiple outpu
6d70: 74 20 66 69 6c 65 73 2c 20 79 6f 75 20 68 61 76 t files, you hav
6d80: 65 20 74 6f 0a 60 66 63 6c 6f 73 65 60 20 65 61 e to.`fclose` ea
6d90: 63 68 20 66 69 6c 65 20 62 65 66 6f 72 65 20 63 ch file before c
6da0: 61 6c 6c 69 6e 67 20 5b 60 66 6f 70 65 6e 28 22 alling [`fopen("
6db0: 46 49 4c 45 4e 41 2e 4d 45 22 2c 20 22 77 22 29 FILENA.ME", "w")
6dc0: 60 5d 28 23 66 6f 70 65 6e 29 20 74 6f 0a 6f 70 `](#fopen) to.op
6dd0: 65 6e 20 74 68 65 20 6e 65 78 74 2e 20 20 54 6f en the next. To
6de0: 20 6f 70 65 6e 20 6d 75 6c 74 69 70 6c 65 20 69 open multiple i
6df0: 6e 70 75 74 20 66 69 6c 65 73 2c 20 73 69 6d 70 nput files, simp
6e00: 6c 79 20 63 61 6c 6c 20 60 66 6f 70 65 6e 28 29 ly call `fopen()
6e10: 60 20 74 6f 0a 6f 70 65 6e 20 65 61 63 68 20 73 ` to.open each s
6e20: 75 62 73 65 71 75 65 6e 74 20 66 69 6c 65 2c 20 ubsequent file,
6e30: 69 6d 70 6c 69 63 69 74 6c 79 20 63 6c 6f 73 69 implicitly closi
6e40: 6e 67 20 74 68 65 20 70 72 69 6f 72 20 69 6e 70 ng the prior inp
6e50: 75 74 20 66 69 6c 65 2e 0a 0a 0a 23 23 23 20 3c ut file....### <
6e60: 61 20 69 64 3d 22 63 72 6c 66 22 3e 3c 2f 61 3e a id="crlf"></a>
6e70: 43 52 2b 4c 46 20 48 61 6e 64 6c 69 6e 67 0a 0a CR+LF Handling..
6e80: 42 65 63 61 75 73 65 20 74 68 65 20 50 44 50 2d Because the PDP-
6e90: 38 20 73 74 61 72 74 65 64 20 6c 69 66 65 20 69 8 started life i
6ea0: 6e 20 61 20 77 6f 72 6c 64 20 77 68 65 72 65 20 n a world where
6eb0: e2 80 9c 74 65 72 6d 69 6e 61 6c e2 80 9d 20 77 “terminal” w
6ec0: 61 73 0a 73 79 6e 6f 6e 79 6d 6f 75 73 20 77 69 as.synonymous wi
6ed0: 74 68 20 e2 80 9c 54 65 6c 65 74 79 70 65 2c e2 th “Teletype,
6ee0: 80 9d 20 4f 53 2f 38 20 75 73 65 73 20 43 52 2b OS/8 uses CR+
6ef0: 4c 46 20 6c 69 6e 65 20 65 6e 64 69 6e 67 73 2c LF line endings,
6f00: 20 61 6e 64 20 69 74 73 0a 46 4f 52 54 52 41 4e and its.FORTRAN
6f10: 20 49 49 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 II implementati
6f20: 6f 6e 20 64 6f 65 73 20 6e 6f 74 20 74 72 61 6e on does not tran
6f30: 73 6c 61 74 65 20 62 61 72 65 20 4c 46 20 74 6f slate bare LF to
6f40: 20 43 52 2b 4c 46 20 6f 6e 20 6f 75 74 70 75 74 CR+LF on output
6f50: 2e 0a 54 68 69 73 20 6d 65 61 6e 73 20 74 68 61 ..This means tha
6f60: 74 20 69 6e 20 6f 72 64 65 72 20 74 6f 20 70 72 t in order to pr
6f70: 6f 70 65 72 6c 79 20 77 72 69 74 65 20 74 65 78 operly write tex
6f80: 74 20 66 69 6c 65 73 2c 20 79 6f 75 20 6d 75 73 t files, you mus
6f90: 74 20 75 73 65 20 61 6e 0a 65 78 70 6c 69 63 69 t use an.explici
6fa0: 74 20 e2 80 9c 60 5c 72 5c 6e 60 e2 80 9d 20 73 t “`\r\n`” s
6fb0: 65 71 75 65 6e 63 65 20 69 6e 20 70 72 6f 67 72 equence in progr
6fc0: 61 6d 73 20 63 6f 6d 70 69 6c 65 64 20 77 69 74 ams compiled wit
6fd0: 68 20 43 43 38 2e 0a 0a 57 65 e2 80 99 76 65 20 h CC8...We’ve
6fe0: 74 72 69 65 64 20 66 69 78 69 6e 67 20 69 74 2c tried fixing it,
6ff0: 20 61 6e 64 20 69 74 e2 80 99 73 20 6d 65 73 73 and it’s mess
7000: 79 20 74 6f 20 64 6f 20 61 20 63 6f 6d 70 6c 65 y to do a comple
7010: 74 65 20 6a 6f 62 20 6f 66 20 69 74 20 67 69 76 te job of it giv
7020: 65 6e 0a 74 68 65 20 63 6f 6e 73 74 72 61 69 6e en.the constrain
7030: 74 73 20 69 6e 76 6f 6c 76 65 64 2e 0a 0a 0a 23 ts involved....#
7040: 23 23 20 3c 61 20 69 64 3d 22 63 74 72 6c 63 22 ## <a id="ctrlc"
7050: 3e 3c 2f 61 3e 43 74 72 6c 2d 43 20 48 61 6e 64 ></a>Ctrl-C Hand
7060: 6c 69 6e 67 0a 0a 55 6e 6c 69 6b 65 20 6f 6e 20 ling..Unlike on
7070: 6d 6f 64 65 72 6e 20 6f 70 65 72 61 74 69 6e 67 modern operating
7080: 20 73 79 73 74 65 6d 73 2c 20 74 68 65 72 65 20 systems, there
7090: 69 73 20 6e 6f 74 68 69 6e 67 20 6c 69 6b 65 20 is nothing like
70a0: 60 53 49 47 49 4e 54 60 20 69 6e 0a 4f 53 2f 38 `SIGINT` in.OS/8
70b0: 2c 20 77 68 69 63 68 20 6d 65 61 6e 73 20 43 74 , which means Ct
70c0: 72 6c 2d 43 20 6f 6e 6c 79 20 6b 69 6c 6c 73 20 rl-C only kills
70d0: 70 72 6f 67 72 61 6d 73 20 74 68 61 74 20 65 78 programs that ex
70e0: 70 6c 69 63 69 74 6c 79 20 63 68 65 63 6b 20 66 plicitly check f
70f0: 6f 72 0a 69 74 2e 20 20 54 68 65 20 6b 65 79 62 or.it. The keyb
7100: 6f 61 72 64 20 69 6e 70 75 74 20 6c 6f 6f 70 20 oard input loop
7110: 69 6e 20 74 68 65 20 43 43 38 20 4c 49 42 43 20 in the CC8 LIBC
7120: 73 74 61 6e 64 61 72 64 20 6c 69 62 72 61 72 79 standard library
7130: 20 64 6f 65 73 20 64 6f 0a 74 68 69 73 2e 0a 0a does do.this...
7140: 54 68 65 20 74 68 69 6e 67 20 74 6f 20 62 65 20 The thing to be
7150: 61 77 61 72 65 20 6f 66 20 69 73 2c 20 74 68 69 aware of is, thi
7160: 73 20 77 6f 6e e2 80 99 74 20 68 61 70 70 65 6e s won’t happen
7170: 20 77 68 69 6c 65 20 61 20 70 72 6f 67 72 61 6d while a program
7180: 20 69 73 20 73 74 75 63 6b 0a 69 6e 20 61 6e 20 is stuck.in an
7190: 69 6e 66 69 6e 69 74 65 20 6c 6f 6f 70 20 6f 72 infinite loop or
71a0: 20 73 69 6d 69 6c 61 72 2e 20 54 68 65 20 6f 6e similar. The on
71b0: 6c 79 20 77 61 79 20 74 6f 20 67 65 74 20 6f 75 ly way to get ou
71c0: 74 20 6f 66 20 73 75 63 68 20 61 0a 70 72 6f 67 t of such a.prog
71d0: 72 61 6d 20 69 73 20 74 6f 20 65 69 74 68 65 72 ram is to either
71e0: 20 72 65 73 74 61 72 74 20 4f 53 2f 38 20 e2 80 restart OS/8
71f0: 94 20 61 73 73 75 6d 69 6e 67 20 74 68 65 20 62 assuming the b
7200: 72 6f 6b 65 6e 20 70 72 6f 67 72 61 6d 20 68 61 roken program ha
7210: 73 6e e2 80 99 74 0a 63 6f 72 72 75 70 74 65 64 sn’t.corrupted
7220: 20 74 68 65 20 4f 53 e2 80 99 73 20 72 65 73 69 the OS’s resi
7230: 64 65 6e 74 20 70 61 72 74 73 20 e2 80 94 20 6f dent parts — o
7240: 72 20 72 65 73 74 61 72 74 20 74 68 65 20 50 44 r restart the PD
7250: 50 2d 38 2e 0a 0a 28 59 6f 75 20 63 61 6e 20 72 P-8...(You can r
7260: 65 73 74 61 72 74 20 4f 53 2f 38 20 62 79 20 63 estart OS/8 by c
7270: 61 75 73 69 6e 67 20 61 20 6a 75 6d 70 20 74 6f ausing a jump to
7280: 20 63 6f 72 65 20 6d 65 6d 6f 72 79 20 6c 6f 63 core memory loc
7290: 61 74 69 6f 6e 20 30 37 36 30 30 2e 0a 57 69 74 ation 07600..Wit
72a0: 68 69 6e 20 74 68 65 20 60 70 69 64 70 38 69 60 hin the `pidp8i`
72b0: 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 2c 20 79 6f environment, yo
72c0: 75 20 63 61 6e 20 68 69 74 20 43 74 72 6c 2d 45 u can hit Ctrl-E
72d0: 2c 20 74 68 65 6e 20 73 61 79 20 e2 80 9c 60 67 , then say “`g
72e0: 6f 0a 37 36 30 30 60 e2 80 9d 2e 20 20 46 72 6f o.7600`”. Fro
72f0: 6d 20 74 68 65 20 66 72 6f 6e 74 20 70 61 6e 65 m the front pane
7300: 6c 2c 20 70 72 65 73 73 20 74 68 65 20 53 74 6f l, press the Sto
7310: 70 20 6b 65 79 2c 20 74 6f 67 67 6c 65 20 37 36 p key, toggle 76
7320: 30 30 20 69 6e 74 6f 20 74 68 65 0a 73 77 69 74 00 into the.swit
7330: 63 68 20 72 65 67 69 73 74 65 72 2c 20 70 72 65 ch register, pre
7340: 73 73 20 74 68 65 20 4c 6f 61 64 20 41 64 64 20 ss the Load Add
7350: 6b 65 79 2c 20 74 68 65 6e 20 70 72 65 73 73 20 key, then press
7360: 74 68 65 20 53 74 61 72 74 20 6b 65 79 2e 29 0a the Start key.).
7370: 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 6d 69 73 ..### <a id="mis
7380: 73 69 6e 67 22 3e 3c 2f 61 3e 4d 69 73 73 69 6e sing"></a>Missin
7390: 67 20 46 75 6e 63 74 69 6f 6e 73 0a 0a 54 68 65 g Functions..The
73a0: 20 62 75 6c 6b 20 6f 66 20 74 68 65 20 53 74 61 bulk of the Sta
73b0: 6e 64 61 72 64 20 43 20 4c 69 62 72 61 72 79 20 ndard C Library
73c0: 69 73 20 6e 6f 74 20 70 72 6f 76 69 64 65 64 2c is not provided,
73d0: 20 69 6e 63 6c 75 64 69 6e 67 20 73 6f 6d 65 0a including some.
73e0: 66 75 6e 63 74 69 6f 6e 73 20 79 6f 75 e2 80 99 functions you’
73f0: 64 20 74 68 69 6e 6b 20 77 6f 75 6c 64 20 67 6f d think would go
7400: 20 61 6c 6f 6e 67 20 6e 69 63 65 6c 79 20 77 69 along nicely wi
7410: 74 68 20 74 68 6f 73 65 20 77 65 20 64 6f 20 70 th those we do p
7420: 72 6f 76 69 64 65 2c 0a 73 75 63 68 20 61 73 20 rovide,.such as
7430: 60 66 65 6f 66 28 29 60 20 6f 72 20 60 66 73 65 `feof()` or `fse
7440: 65 6b 28 29 60 2e 20 20 4b 65 65 70 20 69 6e 20 ek()`. Keep in
7450: 6d 69 6e 64 20 74 68 61 74 20 74 68 65 20 6c 69 mind that the li
7460: 62 72 61 72 79 20 69 73 0a 63 75 72 72 65 6e 74 brary is.current
7470: 6c 79 20 72 65 73 74 72 69 63 74 65 64 20 74 6f ly restricted to
7480: 20 5b 61 20 73 69 6e 67 6c 65 20 34 26 6e 62 73 [a single 4&nbs
7490: 70 3b 6b 57 6f 72 64 20 66 69 65 6c 64 5d 28 23 p;kWord field](#
74a0: 6d 65 6d 6f 72 79 29 2c 20 61 6e 64 20 77 65 0a memory), and we.
74b0: 64 6f 6e e2 80 99 74 20 77 61 6e 74 20 74 6f 20 don’t want to
74c0: 6c 69 66 74 20 74 68 61 74 20 72 65 73 74 72 69 lift that restri
74d0: 63 74 69 6f 6e 2e 20 53 69 6e 63 65 20 74 68 65 ction. Since the
74e0: 20 63 75 72 72 65 6e 74 20 69 6d 70 6c 65 6d 65 current impleme
74f0: 6e 74 61 74 69 6f 6e 0a 6e 65 61 72 6c 79 20 66 ntation.nearly f
7500: 69 6c 6c 73 20 74 68 61 74 20 73 70 61 63 65 2c ills that space,
7510: 20 69 74 20 69 73 20 75 6e 6c 69 6b 65 6c 79 20 it is unlikely
7520: 74 68 61 74 20 77 65 e2 80 99 6c 6c 20 61 64 64 that we’ll add
7530: 20 6d 75 63 68 20 6d 6f 72 65 0a 66 75 6e 63 74 much more.funct
7540: 69 6f 6e 61 6c 69 74 79 20 62 65 79 6f 6e 64 20 ionality beyond
7550: 74 68 65 20 63 75 72 72 65 6e 74 6c 79 20 70 72 the currently pr
7560: 6f 76 69 64 65 64 20 33 33 20 4c 49 42 43 20 66 ovided 33 LIBC f
7570: 75 6e 63 74 69 6f 6e 73 20 70 6c 75 73 20 5b 74 unctions plus [t
7580: 68 65 0a 39 20 61 64 64 69 74 69 6f 6e 61 6c 20 he.9 additional
7590: 66 75 6e 63 74 69 6f 6e 73 5d 28 23 61 64 64 66 functions](#addf
75a0: 6e 29 2e 20 49 66 20 77 65 20 65 76 65 72 20 66 n). If we ever f
75b0: 69 78 20 61 6e 79 20 6f 66 20 74 68 65 20 6c 69 ix any of the li
75c0: 6d 69 74 61 74 69 6f 6e 73 0a 77 65 e2 80 99 76 mitations.we’v
75d0: 65 20 69 64 65 6e 74 69 66 69 65 64 20 62 65 6c e identified bel
75e0: 6f 77 2c 20 63 6f 6e 73 69 64 65 72 20 69 74 20 ow, consider it
75f0: e2 80 9c 67 72 61 76 79 e2 80 9d 20 72 61 74 68 “gravy” rath
7600: 65 72 20 74 68 61 6e 20 61 6e 79 20 6b 69 6e 64 er than any kind
7610: 20 6f 66 0a 6f 62 6c 69 67 61 74 69 6f 6e 20 66 of.obligation f
7620: 75 6c 66 69 6c 6c 65 64 2e 0a 0a 53 6f 6d 65 20 ulfilled...Some
7630: 6f 66 20 74 68 65 73 65 20 6d 69 73 73 69 6e 67 of these missing
7640: 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20 6c functions are l
7650: 65 73 73 20 75 73 65 66 75 6c 20 69 6e 20 74 68 ess useful in th
7660: 65 20 43 43 38 20 77 6f 72 6c 64 20 74 68 61 6e e CC8 world than
7670: 20 69 6e 0a 6d 6f 72 65 20 6d 6f 64 65 72 6e 20 in.more modern
7680: 43 20 65 6e 76 69 72 6f 6e 6d 65 6e 74 73 2e 20 C environments.
7690: 54 68 65 20 6c 6f 77 2d 6d 65 6d 6f 72 79 20 6e The low-memory n
76a0: 61 74 75 72 65 20 6f 66 20 74 68 69 73 20 77 6f ature of this wo
76b0: 72 6c 64 0a 65 6e 63 6f 75 72 61 67 65 73 20 77 rld.encourages w
76c0: 72 69 74 69 6e 67 20 6c 6f 6f 70 73 20 6f 76 65 riting loops ove
76d0: 72 20 5b 77 6f 72 64 20 73 74 72 69 6e 67 73 5d r [word strings]
76e0: 28 23 77 6f 72 64 73 74 72 29 20 69 6e 20 74 65 (#wordstr) in te
76f0: 72 6d 73 20 6f 66 0a 70 6f 69 6e 74 65 72 20 61 rms of.pointer a
7700: 72 69 74 68 6d 65 74 69 63 20 61 6e 64 20 69 6d rithmetic and im
7710: 70 6c 69 63 69 74 20 7a 65 72 6f 20 74 65 73 74 plicit zero test
7720: 69 6e 67 20 28 65 2e 67 2e 20 60 77 68 69 6c 65 ing (e.g. `while
7730: 20 28 2a 70 2b 2b 29 20 7b 20 2f 2a 0a 75 73 65 (*p++) { /*.use
7740: 20 70 20 2a 2f 20 7d 60 29 20 72 61 74 68 65 72 p */ }`) rather
7750: 20 74 68 61 6e 20 6d 61 6b 65 20 65 78 70 65 6e than make expen
7760: 73 69 76 65 20 63 61 6c 6c 73 20 74 6f 20 60 73 sive calls to `s
7770: 74 72 6c 65 6e 28 29 60 2c 20 73 6f 20 74 68 61 trlen()`, so tha
7780: 74 0a 66 75 6e 63 74 69 6f 6e 20 69 73 6e e2 80 t.function isn
7790: 99 74 20 70 72 6f 76 69 64 65 64 2e 0a 0a 44 6f t provided...Do
77a0: 20 6e 6f 74 20 62 72 69 6e 67 20 79 6f 75 72 20 not bring your
77b0: 6d 6f 64 65 72 6e 20 43 20 65 6e 76 69 72 6f 6e modern C environ
77c0: 6d 65 6e 74 20 65 78 70 65 63 74 61 74 69 6f 6e ment expectation
77d0: 73 20 74 6f 20 43 43 38 21 0a 0a 0a 23 23 20 3c s to CC8!...## <
77e0: 61 20 69 64 3d 22 6c 69 62 72 65 66 22 3e 3c 2f a id="libref"></
77f0: 61 3e 54 68 65 20 43 43 38 20 43 20 4c 69 62 72 a>The CC8 C Libr
7800: 61 72 79 3a 20 52 65 66 65 72 65 6e 63 65 0a 0a ary: Reference..
7810: 43 43 38 20 6f 66 66 65 72 73 20 61 20 76 65 72 CC8 offers a ver
7820: 79 20 6c 69 6d 69 74 65 64 20 73 74 61 6e 64 61 y limited standa
7830: 72 64 20 6c 69 62 72 61 72 79 2c 20 77 68 69 63 rd library, whic
7840: 68 20 69 73 20 73 68 61 72 65 64 20 62 65 74 77 h is shared betw
7850: 65 65 6e 20 74 68 65 0a 6e 61 74 69 76 65 20 61 een the.native a
7860: 6e 64 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 nd cross-compile
7870: 72 73 2e 20 57 68 69 6c 65 20 73 6f 6d 65 20 6f rs. While some o
7880: 66 20 69 74 73 20 66 75 6e 63 74 69 6f 6e 20 6e f its function n
7890: 61 6d 65 73 20 61 72 65 20 74 68 65 0a 73 61 6d ames are the.sam
78a0: 65 20 61 73 20 66 75 6e 63 74 69 6f 6e 73 20 64 e as functions d
78b0: 65 66 69 6e 65 64 20 62 79 20 53 74 61 6e 64 61 efined by Standa
78c0: 72 64 20 43 2c 20 74 68 65 73 65 20 66 75 6e 63 rd C, these func
78d0: 74 69 6f 6e 73 20 67 65 6e 65 72 61 6c 6c 79 20 tions generally
78e0: 64 6f 0a 6e 6f 74 20 63 6f 6e 66 6f 72 6d 20 63 do.not conform c
78f0: 6f 6d 70 6c 65 74 65 6c 79 20 74 6f 20 61 6e 79 ompletely to any
7900: 20 67 69 76 65 6e 20 73 74 61 6e 64 61 72 64 20 given standard
7910: 64 75 65 20 74 6f 20 74 68 65 20 73 65 76 65 72 due to the sever
7920: 65 20 72 65 73 6f 75 72 63 65 0a 63 6f 6e 73 74 e resource.const
7930: 72 61 69 6e 74 73 20 69 6d 70 6f 73 65 64 20 62 raints imposed b
7940: 79 20 74 68 65 20 50 44 50 2d 38 20 61 72 63 68 y the PDP-8 arch
7950: 69 74 65 63 74 75 72 65 2e 20 54 68 69 73 20 73 itecture. This s
7960: 65 63 74 69 6f 6e 20 6f 66 20 74 68 65 0a 6d 61 ection of the.ma
7970: 6e 75 61 6c 20 64 6f 63 75 6d 65 6e 74 73 20 74 nual documents t
7980: 68 65 20 6b 6e 6f 77 6e 20 6c 69 6d 69 74 61 74 he known limitat
7990: 69 6f 6e 73 20 6f 66 20 74 68 65 73 65 20 66 75 ions of these fu
79a0: 6e 63 74 69 6f 6e 73 20 72 65 6c 61 74 69 76 65 nctions relative
79b0: 20 74 6f 0a 5b 74 68 65 20 63 75 72 72 65 6e 74 to.[the current
79c0: 20 43 20 73 74 61 6e 64 61 72 64 20 61 73 20 69 C standard as i
79d0: 6e 74 65 72 70 72 65 74 65 64 20 62 79 20 60 63 nterpreted by `c
79e0: 70 70 72 65 66 65 72 65 6e 63 65 2e 63 6f 6d 60 ppreference.com`
79f0: 5d 5b 63 70 70 72 5d 2c 20 62 75 74 0a 69 74 20 ][cppr], but.it
7a00: 69 73 20 6c 69 6b 65 6c 79 20 74 68 61 74 20 77 is likely that w
7a10: 65 20 68 61 76 65 20 6f 76 65 72 6c 6f 6f 6b 65 e have overlooke
7a20: 64 20 63 6f 72 6e 65 72 20 63 61 73 65 73 20 74 d corner cases t
7a30: 68 61 74 20 6f 75 72 20 6c 69 62 72 61 72 79 20 hat our library
7a40: 64 6f 65 73 0a 6e 6f 74 20 79 65 74 20 69 6d 70 does.not yet imp
7a50: 6c 65 6d 65 6e 74 2e 20 20 57 68 65 6e 20 69 6e lement. When in
7a60: 20 64 6f 75 62 74 2c 20 5b 72 65 61 64 20 74 68 doubt, [read th
7a70: 65 20 73 6f 75 72 63 65 5d 5b 6c 69 62 63 73 72 e source][libcsr
7a80: 63 5d 2e 0a 0a 5b 54 68 65 20 4c 49 42 43 20 69 c]...[The LIBC i
7a90: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 5d 5b 6c mplementation][l
7aa0: 69 62 63 73 72 63 5d 20 69 73 20 63 75 72 72 65 ibcsrc] is curre
7ab0: 6e 74 6c 79 20 73 74 6f 72 65 64 20 69 6e 20 74 ntly stored in t
7ac0: 68 65 20 73 61 6d 65 0a 73 6f 75 72 63 65 20 74 he same.source t
7ad0: 72 65 65 20 64 69 72 65 63 74 6f 72 79 20 61 73 ree directory as
7ae0: 20 74 68 65 20 6e 61 74 69 76 65 20 63 6f 6d 70 the native comp
7af0: 69 6c 65 72 2c 20 65 76 65 6e 20 74 68 6f 75 67 iler, even thoug
7b00: 68 20 69 74 e2 80 99 73 20 73 68 61 72 65 64 0a h it’s shared.
7b10: 62 65 74 77 65 65 6e 20 74 68 65 20 74 77 6f 20 between the two
7b20: 63 6f 6d 70 69 6c 65 72 73 2e 20 54 68 69 73 20 compilers. This
7b30: 69 73 20 62 65 63 61 75 73 65 20 74 68 65 20 74 is because the t
7b40: 77 6f 20 63 6f 6d 70 69 6c 65 72 73 20 64 69 66 wo compilers dif
7b50: 66 65 72 20 6f 6e 6c 79 0a 66 72 6f 6d 20 74 68 fer only.from th
7b60: 65 20 63 6f 64 65 20 67 65 6e 65 72 61 74 69 6f e code generatio
7b70: 6e 20 6c 61 79 65 72 20 75 70 3a 20 69 66 20 79 n layer up: if y
7b80: 6f 75 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 ou cross-compile
7b90: 20 61 20 43 20 70 72 6f 67 72 61 6d 20 77 69 74 a C program wit
7ba0: 68 0a 60 62 69 6e 2f 63 63 38 60 2c 20 79 6f 75 h.`bin/cc8`, you
7bb0: 20 6d 75 73 74 20 73 74 69 6c 6c 20 2a 61 73 73 must still *ass
7bc0: 65 6d 62 6c 65 20 61 6e 64 20 6c 69 6e 6b 2a 20 emble and link*
7bd0: 69 74 20 75 6e 64 65 72 20 4f 53 2f 38 2c 20 77 it under OS/8, w
7be0: 68 69 63 68 20 6d 65 61 6e 73 0a 75 73 69 6e 67 hich means.using
7bf0: 20 74 68 65 20 60 4c 49 42 43 2e 52 4c 60 20 62 the `LIBC.RL` b
7c00: 69 6e 61 72 79 20 70 72 6f 64 75 63 65 64 20 66 inary produced f
7c10: 6f 72 20 75 73 65 20 62 79 20 74 68 65 20 6e 61 or use by the na
7c20: 74 69 76 65 20 63 6f 6d 70 69 6c 65 72 2e 0a 0a tive compiler...
7c30: 43 6f 6e 74 72 61 73 74 20 5b 74 68 65 20 60 6c Contrast [the `l
7c40: 69 62 63 2e 68 60 20 66 69 6c 65 5d 5b 6c 69 62 ibc.h` file][lib
7c50: 63 68 5d 20 77 68 69 63 68 20 69 73 20 73 79 6d ch] which is sym
7c60: 6c 69 6e 6b 65 64 20 6f 72 20 63 6f 70 69 65 64 linked or copied
7c70: 0a 65 76 65 72 79 77 68 65 72 65 20 69 74 20 6e .everywhere it n
7c80: 65 65 64 73 20 74 6f 20 62 65 2e 20 54 68 69 73 eeds to be. This
7c90: 20 69 73 20 62 65 63 61 75 73 65 20 6e 65 69 74 is because neit
7ca0: 68 65 72 20 76 65 72 73 69 6f 6e 20 6f 66 20 43 her version of C
7cb0: 43 38 20 68 61 73 0a 74 68 65 20 6e 6f 74 69 6f C8 has.the notio
7cc0: 6e 20 6f 66 20 61 6e 20 69 6e 63 6c 75 64 65 20 n of an include
7cd0: 70 61 74 68 2e 20 54 68 69 73 20 66 69 6c 65 20 path. This file
7ce0: 6d 75 73 74 20 74 68 65 72 65 66 6f 72 65 20 62 must therefore b
7cf0: 65 20 61 76 61 69 6c 61 62 6c 65 20 69 6e 0a 74 e available in.t
7d00: 68 65 20 73 61 6d 65 20 64 69 72 65 63 74 6f 72 he same director
7d10: 79 20 61 73 20 65 61 63 68 20 43 20 66 69 6c 65 y as each C file
7d20: 20 74 68 61 74 20 75 73 65 73 20 69 74 2e 0a 0a that uses it...
7d30: 49 6e 20 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 In the following
7d40: 20 74 65 78 74 2c 20 77 65 20 75 73 65 20 4f 53 text, we use OS
7d50: 2f 38 20 64 65 76 69 63 65 20 6e 61 6d 65 73 20 /8 device names
7d60: 61 73 20 61 20 68 61 6e 64 77 61 76 79 20 6b 69 as a handwavy ki
7d70: 6e 64 20 6f 66 0a 73 68 6f 72 74 68 61 6e 64 2c nd of.shorthand,
7d80: 20 65 76 65 6e 20 77 68 65 6e 20 74 68 65 20 63 even when the c
7d90: 6f 64 65 20 77 6f 75 6c 64 20 6f 74 68 65 72 77 ode would otherw
7da0: 69 73 65 20 72 75 6e 20 6f 6e 20 61 6e 79 20 50 ise run on any P
7db0: 44 50 2d 38 20 69 6e 0a 61 62 73 65 6e 63 65 20 DP-8 in.absence
7dc0: 6f 66 20 4f 53 2f 38 2e 20 57 68 65 72 65 20 77 of OS/8. Where w
7dd0: 65 20 75 73 65 20 e2 80 9c 60 54 54 59 3a 60 e2 e use “`TTY:`
7de0: 80 9d 2c 20 66 6f 72 20 65 78 61 6d 70 6c 65 2c , for example,
7df0: 20 77 65 e2 80 99 64 20 62 65 20 6d 6f 72 65 0a we’d be more.
7e00: 70 72 65 63 69 73 65 20 74 6f 20 73 61 79 20 69 precise to say i
7e10: 6e 73 74 65 61 64 20 e2 80 9c 74 68 65 20 63 6f nstead “the co
7e20: 6e 73 6f 6c 65 20 74 65 6c 65 70 72 69 6e 74 65 nsole teleprinte
7e30: 72 2c 20 62 65 69 6e 67 20 74 68 65 20 6f 6e 65 r, being the one
7e40: 20 74 68 61 74 0a 72 65 73 70 6f 6e 64 73 20 74 that.responds t
7e50: 6f 20 5b 49 4f 54 20 64 65 76 69 63 65 20 63 6f o [IOT device co
7e60: 64 65 5d 5b 69 6f 74 5d 20 33 20 66 6f 72 20 69 de][iot] 3 for i
7e70: 6e 70 75 74 20 61 6e 64 20 74 6f 20 64 65 76 69 nput and to devi
7e80: 63 65 20 63 6f 64 65 20 34 20 66 6f 72 0a 6f 75 ce code 4 for.ou
7e90: 74 70 75 74 2e e2 80 9d 20 57 65 e2 80 99 64 20 tput.” We’d
7ea0: 72 61 74 68 65 72 20 6e 6f 74 20 77 72 69 74 65 rather not write
7eb0: 20 61 6c 6c 20 6f 66 20 74 68 61 74 20 66 6f 72 all of that for
7ec0: 20 65 76 65 72 79 20 73 74 64 69 6f 20 66 75 6e every stdio fun
7ed0: 63 74 69 6f 6e 0a 62 65 6c 6f 77 2c 20 73 6f 20 ction.below, so
7ee0: 77 65 20 75 73 65 20 74 68 69 73 20 73 68 6f 72 we use this shor
7ef0: 74 68 61 6e 64 2e 0a 0a 5b 63 70 70 72 5d 3a 20 thand...[cppr]:
7f00: 20 20 20 68 74 74 70 73 3a 2f 2f 65 6e 2e 63 70 https://en.cp
7f10: 70 72 65 66 65 72 65 6e 63 65 2e 63 6f 6d 2f 77 preference.com/w
7f20: 2f 63 0a 5b 69 6f 74 5d 3a 20 20 20 20 20 2f 77 /c.[iot]: /w
7f30: 69 6b 69 3f 6e 61 6d 65 3d 49 4f 54 2b 44 65 76 iki?name=IOT+Dev
7f40: 69 63 65 2b 41 73 73 69 67 6e 6d 65 6e 74 73 0a ice+Assignments.
7f50: 5b 6c 69 62 63 68 5d 3a 20 20 20 2f 64 6f 63 2f [libch]: /doc/
7f60: 74 72 75 6e 6b 2f 73 72 63 2f 63 63 38 2f 69 6e trunk/src/cc8/in
7f70: 63 6c 75 64 65 2f 6c 69 62 63 2e 68 0a 5b 6c 69 clude/libc.h.[li
7f80: 62 63 73 72 63 5d 3a 20 2f 64 6f 63 2f 74 72 75 bcsrc]: /doc/tru
7f90: 6e 6b 2f 73 72 63 2f 63 63 38 2f 6f 73 38 2f 6c nk/src/cc8/os8/l
7fa0: 69 62 63 2e 63 0a 0a 0a 23 23 23 20 3c 61 20 69 ibc.c...### <a i
7fb0: 64 3d 22 61 74 6f 69 22 3e 3c 2f 61 3e 60 69 6e d="atoi"></a>`in
7fc0: 74 20 61 74 6f 69 28 73 2c 20 2a 72 65 73 75 6c t atoi(s, *resul
7fd0: 74 29 60 0a 0a 54 61 6b 65 73 20 61 20 6e 75 6c t)`..Takes a nul
7fe0: 6c 2d 74 65 72 6d 69 6e 61 74 65 64 20 41 53 43 l-terminated ASC
7ff0: 49 49 20 63 68 61 72 61 63 74 65 72 20 73 74 72 II character str
8000: 69 6e 67 20 70 6f 69 6e 74 65 72 20 60 73 60 20 ing pointer `s`
8010: 61 6e 64 20 74 72 69 65 73 20 74 6f 0a 69 6e 74 and tries to.int
8020: 65 72 70 72 65 74 20 69 74 20 61 73 20 61 20 31 erpret it as a 1
8030: 32 2d 62 69 74 20 50 44 50 2d 38 20 74 77 6f e2 2-bit PDP-8 two
8040: 80 99 73 20 63 6f 6d 70 6c 65 6d 65 6e 74 20 73 s complement s
8050: 69 67 6e 65 64 20 69 6e 74 65 67 65 72 2c 20 73 igned integer, s
8060: 74 6f 72 69 6e 67 0a 74 68 65 20 76 61 6c 75 65 toring.the value
8070: 20 69 6e 20 60 2a 72 65 73 75 6c 74 60 20 61 6e in `*result` an
8080: 64 20 72 65 74 75 72 6e 69 6e 67 20 74 68 65 20 d returning the
8090: 6e 75 6d 62 65 72 20 6f 66 20 62 79 74 65 73 20 number of bytes
80a0: 69 6e 20 60 73 60 0a 63 6f 6e 73 75 6d 65 64 2e in `s`.consumed.
80b0: 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 69 6f ..**Standard Vio
80c0: 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 lations:**..*
80d0: 49 6e 73 74 65 61 64 20 6f 66 20 72 65 74 75 72 Instead of retur
80e0: 6e 69 6e 67 20 74 68 65 20 63 6f 6e 76 65 72 74 ning the convert
80f0: 65 64 20 69 6e 74 65 67 65 72 2c 20 74 68 69 73 ed integer, this
8100: 20 66 75 6e 63 74 69 6f 6e 20 73 74 6f 72 65 73 function stores
8110: 0a 20 20 20 20 74 68 61 74 20 76 61 6c 75 65 20 . that value
8120: 69 6e 20 60 2a 72 65 73 75 6c 74 60 2e 0a 0a 2a in `*result`...*
8130: 20 20 20 57 68 65 72 65 61 73 20 60 61 74 6f 69 Whereas `atoi
8140: 28 29 60 20 69 6e 20 53 74 61 6e 64 61 72 64 20 ()` in Standard
8150: 43 20 72 65 74 75 72 6e 73 20 74 68 65 20 63 6f C returns the co
8160: 6e 76 65 72 74 65 64 20 76 61 6c 75 65 2c 20 69 nverted value, i
8170: 6e 20 74 68 69 73 0a 20 20 20 20 66 75 6e 63 74 n this. funct
8180: 69 6f 6e 2c 20 60 73 5b 72 65 74 76 61 6c 5d 60 ion, `s[retval]`
8190: 20 69 73 20 74 68 65 20 66 69 72 73 74 20 69 6e is the first in
81a0: 76 61 6c 69 64 20 e2 80 94 20 6e 6f 6e 2d 73 69 valid — non-si
81b0: 67 6e 2c 20 6e 6f 6e 2d 64 69 67 69 74 2c 0a 20 gn, non-digit,.
81c0: 20 20 20 6e 6f 6e 2d 73 70 61 63 65 20 e2 80 94 non-space —
81d0: 20 63 68 61 72 61 63 74 65 72 20 69 6e 20 74 68 character in th
81e0: 65 20 73 74 72 69 6e 67 2c 20 77 68 65 72 65 20 e string, where
81f0: 60 72 65 74 76 61 6c 60 20 69 73 20 74 68 65 20 `retval` is the
8200: 72 65 74 75 72 6e 0a 20 20 20 20 76 61 6c 75 65 return. value
8210: 2e 0a 0a 2a 20 20 20 53 6b 69 70 73 20 6c 65 61 ...* Skips lea
8220: 64 69 6e 67 20 41 53 43 49 49 20 33 32 20 28 73 ding ASCII 32 (s
8230: 70 61 63 65 29 20 63 68 61 72 61 63 74 65 72 73 pace) characters
8240: 20 6f 6e 6c 79 2c 20 6e 6f 74 20 74 68 6f 73 65 only, not those
8250: 20 6d 61 74 63 68 65 64 20 62 79 0a 20 20 20 20 matched by.
8260: 5b 60 69 73 73 70 61 63 65 28 29 60 5d 28 23 69 [`isspace()`](#i
8270: 73 73 70 61 63 65 29 2c 20 61 73 20 74 68 65 20 sspace), as the
8280: 53 74 61 6e 64 61 72 64 20 72 65 71 75 69 72 65 Standard require
8290: 73 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 s....### <a id="
82a0: 63 75 70 70 65 72 22 3e 3c 2f 61 3e 60 63 75 70 cupper"></a>`cup
82b0: 70 65 72 28 70 29 60 0a 0a 49 6d 70 6c 65 6d 65 per(p)`..Impleme
82c0: 6e 74 73 20 74 68 69 73 20 6c 6f 6f 70 20 6d 6f nts this loop mo
82d0: 72 65 20 65 66 66 69 63 69 65 6e 74 6c 79 3a 0a re efficiently:.
82e0: 0a 20 20 20 20 63 68 61 72 2a 20 74 6d 70 20 3d . char* tmp =
82f0: 20 70 3b 0a 20 20 20 20 77 68 69 6c 65 20 28 2a p;. while (*
8300: 74 6d 70 29 20 7b 0a 20 20 20 20 20 20 20 20 2a tmp) {. *
8310: 74 6d 70 20 3d 20 74 6f 75 70 70 65 72 28 2a 74 tmp = toupper(*t
8320: 6d 70 29 3b 0a 20 20 20 20 20 20 20 20 2b 2b 74 mp);. ++t
8330: 6d 70 3b 0a 20 20 20 20 7d 0a 0a 54 68 61 74 20 mp;. }..That
8340: 69 73 2c 20 69 74 20 64 6f 65 73 20 61 6e 20 69 is, it does an i
8350: 6e 2d 70 6c 61 63 65 20 63 6f 6e 76 65 72 73 69 n-place conversi
8360: 6f 6e 20 6f 66 20 74 68 65 20 70 61 73 73 65 64 on of the passed
8370: 20 5b 30 2d 74 65 72 6d 69 6e 61 74 65 64 20 77 [0-terminated w
8380: 6f 72 64 0a 73 74 72 69 6e 67 5d 28 23 77 6f 72 ord.string](#wor
8390: 64 73 74 72 29 20 74 6f 20 61 6c 6c 2d 75 70 70 dstr) to all-upp
83a0: 65 72 63 61 73 65 2e 0a 0a 54 68 69 73 20 66 75 ercase...This fu
83b0: 6e 63 74 69 6f 6e 20 65 78 69 73 74 73 20 69 6e nction exists in
83c0: 20 4c 49 42 43 20 62 65 63 61 75 73 65 20 69 74 LIBC because it
83d0: 20 69 73 20 75 73 65 66 75 6c 20 66 6f 72 20 65 is useful for e
83e0: 6e 73 75 72 69 6e 67 20 74 68 61 74 20 66 69 6c nsuring that fil
83f0: 65 0a 6e 61 6d 65 73 20 61 72 65 20 75 70 70 65 e.names are uppe
8400: 72 63 61 73 65 2c 20 61 73 20 4f 53 2f 38 20 72 rcase, as OS/8 r
8410: 65 71 75 69 72 65 73 2e 20 57 69 74 68 20 74 68 equires. With th
8420: 65 20 63 75 72 72 65 6e 74 20 43 43 38 20 63 6f e current CC8 co
8430: 6d 70 69 6c 65 72 0a 69 6d 70 6c 65 6d 65 6e 74 mpiler.implement
8440: 61 74 69 6f 6e 2c 20 74 68 65 20 65 71 75 69 76 ation, the equiv
8450: 61 6c 65 6e 74 20 63 6f 64 65 20 61 62 6f 76 65 alent code above
8460: 20 72 65 71 75 69 72 65 73 20 32 34 20 6d 6f 72 requires 24 mor
8470: 65 20 69 6e 73 74 72 75 63 74 69 6f 6e 73 0a 74 e instructions.t
8480: 68 61 6e 20 63 61 6c 6c 69 6e 67 20 60 63 75 70 han calling `cup
8490: 70 65 72 28 29 60 20 69 6e 73 74 65 61 64 2c 20 per()` instead,
84a0: 62 65 73 74 2d 63 61 73 65 21 20 54 68 61 74 20 best-case! That
84b0: 6d 65 61 6e 73 20 61 20 73 69 6e 67 6c 65 20 63 means a single c
84c0: 61 6c 6c 0a 63 6f 6e 76 65 72 74 65 64 20 66 72 all.converted fr
84d0: 6f 6d 20 61 20 6c 6f 6f 70 20 61 72 6f 75 6e 64 om a loop around
84e0: 20 5b 60 74 6f 75 70 70 65 72 28 29 60 5d 28 23 [`toupper()`](#
84f0: 74 6f 75 70 70 65 72 29 20 74 6f 20 61 20 60 63 toupper) to a `c
8500: 75 70 70 65 72 28 29 60 0a 63 61 6c 6c 20 6d 6f upper()`.call mo
8510: 72 65 20 74 68 61 6e 20 70 61 79 73 20 66 6f 72 re than pays for
8520: 20 74 68 65 20 32 31 20 69 6e 73 74 72 75 63 74 the 21 instruct
8530: 69 6f 6e 73 20 61 6e 64 20 6f 6e 65 20 65 78 74 ions and one ext
8540: 72 61 20 6a 75 6d 70 20 74 61 62 6c 65 0a 73 6c ra jump table.sl
8550: 6f 74 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e ot this function
8560: 20 72 65 71 75 69 72 65 73 20 69 6e 20 4c 49 42 requires in LIB
8570: 43 2e 0a 0a 44 6f 20 6e 6f 74 20 64 65 70 65 6e C...Do not depen
8580: 64 20 6f 6e 20 74 68 65 20 72 65 74 75 72 6e 20 d on the return
8590: 76 61 6c 75 65 2e 20 54 68 65 72 65 20 69 73 20 value. There is
85a0: 61 20 70 72 65 64 69 63 74 61 62 6c 65 20 6d 61 a predictable ma
85b0: 70 70 69 6e 67 2c 20 62 75 74 0a 69 74 20 68 61 pping, but.it ha
85c0: 73 20 6e 6f 20 69 6e 68 65 72 65 6e 74 20 6d 65 s no inherent me
85d0: 61 6e 69 6e 67 2c 20 73 6f 20 77 65 20 61 72 65 aning, so we are
85e0: 20 6e 6f 74 20 64 6f 63 75 6d 65 6e 74 69 6e 67 not documenting
85f0: 20 74 68 61 74 20 6d 61 70 70 69 6e 67 20 68 65 that mapping he
8600: 72 65 2e 0a 49 66 20 43 43 38 20 68 61 64 20 61 re..If CC8 had a
8610: 20 e2 80 9c 60 76 6f 69 64 60 e2 80 9d 20 72 65 “`void`” re
8620: 74 75 72 6e 20 74 79 70 65 20 66 65 61 74 75 72 turn type featur
8630: 65 2c 20 77 65 e2 80 99 64 20 62 65 20 75 73 69 e, we’d be usi
8640: 6e 67 20 74 68 61 74 20 68 65 72 65 2e 0a 0a 2a ng that here...*
8650: 2a 4e 6f 6e 73 74 61 6e 64 61 72 64 2e 2a 2a 20 *Nonstandard.**
8660: 4e 6f 20 6b 6e 6f 77 6e 20 61 6e 61 6c 6f 67 20 No known analog
8670: 69 6e 20 61 6e 79 20 6f 74 68 65 72 20 43 20 6c in any other C l
8680: 69 62 72 61 72 79 2e 0a 0a 0a 23 23 23 20 3c 61 ibrary....### <a
8690: 20 69 64 3d 22 64 69 73 70 78 79 22 3e 3c 2f 61 id="dispxy"></a
86a0: 3e 60 64 69 73 70 78 79 28 78 2c 79 29 60 0a 0a >`dispxy(x,y)`..
86b0: 50 6c 6f 74 20 61 20 70 6f 69 6e 74 20 61 74 20 Plot a point at
86c0: 63 6f 6f 72 64 69 6e 61 74 65 20 28 78 2c 79 29 coordinate (x,y)
86d0: 20 6f 6e 20 61 20 5b 56 43 38 45 20 70 6f 69 6e on a [VC8E poin
86e0: 74 2d 70 6c 6f 74 20 64 69 73 70 6c 61 79 5d 5b t-plot display][
86f0: 76 63 38 65 5d 2e 0a 0a 54 68 69 73 20 69 73 20 vc8e]...This is
8700: 74 68 65 20 64 69 73 70 6c 61 79 20 74 79 70 65 the display type
8710: 20 61 73 73 75 6d 65 64 20 62 79 20 74 68 65 20 assumed by the
8720: 50 69 44 50 2d 38 2f 49 20 53 70 61 63 65 77 61 PiDP-8/I Spacewa
8730: 72 21 0a 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f r!.implementatio
8740: 6e 2e 20 54 68 65 72 65 20 77 65 72 65 20 6d 61 n. There were ma
8750: 6e 79 20 6f 74 68 65 72 20 64 69 73 70 6c 61 79 ny other display
8760: 20 74 79 70 65 73 20 64 65 73 69 67 6e 65 64 20 types designed
8770: 66 6f 72 20 61 6e 64 0a 73 6f 6c 64 20 77 69 74 for and.sold wit
8780: 68 20 50 44 50 2d 38 20 66 61 6d 69 6c 79 20 63 h PDP-8 family c
8790: 6f 6d 70 75 74 65 72 73 2c 20 77 68 69 63 68 20 omputers, which
87a0: 67 65 6e 65 72 61 6c 6c 79 20 75 73 65 64 20 64 generally used d
87b0: 69 66 66 65 72 65 6e 74 20 49 4f 54 0a 63 6f 64 ifferent IOT.cod
87c0: 65 73 2e 20 49 66 20 79 6f 75 e2 80 99 72 65 20 es. If you’re
87d0: 74 72 79 69 6e 67 20 74 6f 20 63 6f 6e 74 72 6f trying to contro
87e0: 6c 20 73 6f 6d 65 74 68 69 6e 67 20 6f 74 68 65 l something othe
87f0: 72 20 74 68 61 6e 20 61 20 56 43 38 45 2c 20 79 r than a VC8E, y
8800: 6f 75 0a 6d 69 67 68 74 20 77 61 6e 74 20 74 6f ou.might want to
8810: 20 72 65 70 6c 61 63 65 20 74 68 69 73 20 72 6f replace this ro
8820: 75 74 69 6e 65 e2 80 99 73 20 69 6e 74 65 72 6e utine’s intern
8830: 61 6c 73 20 72 61 74 68 65 72 20 74 68 61 6e 20 als rather than
8840: 63 6f 64 65 20 61 0a 73 65 70 61 72 61 74 65 20 code a.separate
8850: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2c 20 implementation,
8860: 6c 65 61 64 69 6e 67 20 74 6f 20 77 61 73 74 65 leading to waste
8870: 64 20 73 70 61 63 65 20 69 6e 20 79 6f 75 72 20 d space in your
8880: 4c 49 42 43 2e 0a 0a 2a 2a 4e 6f 6e 73 74 61 6e LIBC...**Nonstan
8890: 64 61 72 64 2e 2a 2a 0a 0a 5b 64 69 78 79 5d 3a dard.**..[dixy]:
88a0: 20 68 74 74 70 3a 2f 2f 68 6f 6d 65 70 61 67 65 http://homepage
88b0: 2e 64 69 76 6d 73 2e 75 69 6f 77 61 2e 65 64 75 .divms.uiowa.edu
88c0: 2f 7e 6a 6f 6e 65 73 2f 70 64 70 38 2f 6d 61 6e /~jones/pdp8/man
88d0: 2f 76 63 38 65 2e 68 74 6d 6c 0a 5b 76 63 38 65 /vc8e.html.[vc8e
88e0: 5d 3a 20 68 74 74 70 73 3a 2f 2f 68 6f 6d 65 70 ]: https://homep
88f0: 61 67 65 2e 64 69 76 6d 73 2e 75 69 6f 77 61 2e age.divms.uiowa.
8900: 65 64 75 2f 7e 6a 6f 6e 65 73 2f 70 64 70 38 2f edu/~jones/pdp8/
8910: 6d 61 6e 2f 76 63 38 65 2e 68 74 6d 6c 0a 0a 0a man/vc8e.html...
8920: 23 23 23 20 3c 61 20 69 64 3d 22 65 78 69 74 22 ### <a id="exit"
8930: 3e 3c 2f 61 3e 60 65 78 69 74 28 72 65 74 29 60 ></a>`exit(ret)`
8940: 0a 0a 45 78 69 74 73 20 74 68 65 20 70 72 6f 67 ..Exits the prog
8950: 72 61 6d 2e 0a 0a 54 68 69 73 20 66 75 6e 63 74 ram...This funct
8960: 69 6f 6e 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 ion is implement
8970: 65 64 20 69 6e 20 74 65 72 6d 73 20 6f 66 20 74 ed in terms of t
8980: 68 65 20 5b 46 4f 52 54 52 41 4e 20 49 49 20 6c he [FORTRAN II l
8990: 69 62 72 61 72 79 0a 73 75 62 72 6f 75 74 69 6e ibrary.subroutin
89a0: 65 20 60 45 58 49 54 60 5d 5b 66 32 65 78 69 74 e `EXIT`][f2exit
89b0: 5d 2c 20 77 68 69 63 68 20 69 6e 20 74 68 65 20 ], which in the
89c0: 4f 53 2f 38 20 69 6d 70 6c 65 6d 65 6e 74 61 74 OS/8 implementat
89d0: 69 6f 6e 20 73 69 6d 70 6c 79 0a 72 65 74 75 72 ion simply.retur
89e0: 6e 73 20 63 6f 6e 74 72 6f 6c 20 74 6f 20 74 68 ns control to th
89f0: 65 20 4f 53 2f 38 20 6b 65 79 62 6f 61 72 64 20 e OS/8 keyboard
8a00: 6d 6f 6e 69 74 6f 72 2e 0a 0a 49 66 20 60 45 58 monitor...If `EX
8a10: 49 54 60 20 72 65 74 75 72 6e 73 20 66 6f 72 20 IT` returns for
8a20: 61 6e 79 20 72 65 61 73 6f 6e 2c 20 4c 49 42 43 any reason, LIBC
8a30: 20 68 61 6c 74 73 20 74 68 65 20 70 72 6f 63 65 halts the proce
8a40: 73 73 6f 72 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 ssor...**Standar
8a50: 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a d Violations:**.
8a60: 0a 2a 20 20 20 54 68 65 20 70 61 73 73 65 64 20 .* The passed
8a70: 72 65 74 75 72 6e 20 63 6f 64 65 20 69 73 20 69 return code is i
8a80: 67 6e 6f 72 65 64 2c 20 74 68 65 72 65 20 62 65 gnored, there be
8a90: 69 6e 67 20 6e 6f 20 73 75 63 68 20 74 68 69 6e ing no such thin
8aa0: 67 20 61 73 20 61 0a 20 20 20 20 70 72 6f 67 72 g as a. progr
8ab0: 61 6d e2 80 99 73 20 e2 80 9c 73 74 61 74 75 73 am’s “status
8ac0: 20 63 6f 64 65 e2 80 9d 20 69 6e 20 4f 53 2f 38 code” in OS/8
8ad0: 2e 0a 0a 2a 20 20 20 54 68 65 72 65 20 69 73 20 ...* There is
8ae0: 6e 6f 20 60 61 74 65 78 69 74 28 29 60 20 6d 65 no `atexit()` me
8af0: 63 68 61 6e 69 73 6d 20 69 6e 20 74 68 65 20 43 chanism in the C
8b00: 43 38 20 4c 49 42 43 2e 0a 0a 5b 66 32 65 78 69 C8 LIBC...[f2exi
8b10: 74 5d 3a 20 68 74 74 70 73 3a 2f 2f 61 72 63 68 t]: https://arch
8b20: 69 76 65 2e 6f 72 67 2f 64 65 74 61 69 6c 73 2f ive.org/details/
8b30: 62 69 74 73 61 76 65 72 73 5f 64 65 63 70 64 70 bitsavers_decpdp
8b40: 38 6f 73 38 5f 33 39 34 31 34 37 39 32 2f 70 61 8os8_39414792/pa
8b50: 67 65 2f 6e 37 30 32 0a 0a 0a 23 23 23 20 3c 61 ge/n702...### <a
8b60: 20 69 64 3d 22 66 63 6c 6f 73 65 22 3e 3c 2f 61 id="fclose"></a
8b70: 3e 60 66 63 6c 6f 73 65 28 29 60 0a 0a 43 6c 6f >`fclose()`..Clo
8b80: 73 65 73 20 74 68 65 20 63 75 72 72 65 6e 74 6c ses the currentl
8b90: 79 2d 6f 70 65 6e 65 64 20 6f 75 74 70 75 74 20 y-opened output
8ba0: 66 69 6c 65 2e 0a 0a 54 68 69 73 20 66 75 6e 63 file...This func
8bb0: 74 69 6f 6e 20 73 69 6d 70 6c 79 20 63 61 6c 6c tion simply call
8bc0: 73 20 74 68 65 20 4f 53 2f 38 20 46 4f 52 54 52 s the OS/8 FORTR
8bd0: 41 4e 20 49 49 20 6c 69 62 72 61 72 79 20 73 75 AN II library su
8be0: 62 72 6f 75 74 69 6e 65 0a 5b 60 4f 43 4c 4f 53 broutine.[`OCLOS
8bf0: 45 60 5d 5b 66 32 66 69 6f 5d 2e 0a 0a 2a 2a 53 E`][f2fio]...**S
8c00: 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 69 6f tandard Violatio
8c10: 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 44 6f 65 73 20 ns:**..* Does
8c20: 6e 6f 74 20 74 61 6b 65 20 61 20 60 46 49 4c 45 not take a `FILE
8c30: 2a 60 20 61 72 67 75 6d 65 6e 74 2e 20 20 28 53 *` argument. (S
8c40: 65 65 20 5b 60 66 6f 70 65 6e 28 29 60 5d 28 23 ee [`fopen()`](#
8c50: 66 6f 70 65 6e 29 20 66 6f 72 0a 20 20 20 20 6a fopen) for. j
8c60: 75 73 74 69 66 69 63 61 74 69 6f 6e 2e 29 0a 0a ustification.)..
8c70: 2a 20 20 20 41 6c 77 61 79 73 20 63 6c 6f 73 65 * Always close
8c80: 73 20 74 68 65 20 6c 61 73 74 2d 6f 70 65 6e 65 s the last-opene
8c90: 64 20 2a 6f 75 74 70 75 74 2a 20 66 69 6c 65 2c d *output* file,
8ca0: 20 6f 6e 6c 79 2c 20 74 68 65 72 65 20 62 65 69 only, there bei
8cb0: 6e 67 0a 20 20 20 20 5b 6e 6f 20 70 6f 69 6e 74 ng. [no point
8cc0: 5d 28 23 66 69 6f 6c 69 6d 29 20 69 6e 20 65 78 ](#fiolim) in ex
8cd0: 70 6c 69 63 69 74 6c 79 20 63 6c 6f 73 69 6e 67 plicitly closing
8ce0: 20 69 6e 70 75 74 20 66 69 6c 65 73 20 69 6e 20 input files in
8cf0: 74 68 69 73 0a 20 20 20 20 69 6d 70 6c 65 6d 65 this. impleme
8d00: 6e 74 61 74 69 6f 6e 2e 0a 0a 5b 66 32 66 69 6f ntation...[f2fio
8d10: 5d 3a 20 68 74 74 70 73 3a 2f 2f 61 72 63 68 69 ]: https://archi
8d20: 76 65 2e 6f 72 67 2f 64 65 74 61 69 6c 73 2f 62 ve.org/details/b
8d30: 69 74 73 61 76 65 72 73 5f 64 65 63 70 64 70 38 itsavers_decpdp8
8d40: 6f 73 38 5f 33 39 34 31 34 37 39 32 2f 70 61 67 os8_39414792/pag
8d50: 65 2f 6e 37 30 30 0a 0a 0a 23 23 23 20 3c 61 20 e/n700...### <a
8d60: 69 64 3d 22 66 67 65 74 73 22 3e 3c 2f 61 3e 60 id="fgets"></a>`
8d70: 66 67 65 74 73 28 73 29 60 0a 0a 52 65 61 64 73 fgets(s)`..Reads
8d80: 20 61 20 73 74 72 69 6e 67 20 6f 66 20 41 53 43 a string of ASC
8d90: 49 49 20 63 68 61 72 61 63 74 65 72 73 20 66 72 II characters fr
8da0: 6f 6d 20 74 68 65 20 6c 61 73 74 20 66 69 6c 65 om the last file
8db0: 20 6f 70 65 6e 65 64 20 66 6f 72 20 69 6e 70 75 opened for inpu
8dc0: 74 0a 62 79 20 5b 60 66 6f 70 65 6e 28 29 60 5d t.by [`fopen()`]
8dd0: 28 23 66 6f 70 65 6e 29 2c 20 73 74 6f 72 69 6e (#fopen), storin
8de0: 67 20 69 74 20 61 74 20 63 6f 72 65 20 6d 65 6d g it at core mem
8df0: 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 20 60 73 60 ory location `s`
8e00: 2e 20 49 74 20 72 65 61 64 73 0a 75 6e 74 69 6c . It reads.until
8e10: 20 69 74 20 65 6e 63 6f 75 6e 74 65 72 73 20 61 it encounters a
8e20: 6e 20 4c 46 20 63 68 61 72 61 63 74 65 72 2c 20 n LF character,
8e30: 73 74 6f 72 69 6e 67 20 74 68 61 74 20 61 6e 64 storing that and
8e40: 20 61 20 74 72 61 69 6c 69 6e 67 20 4e 55 4c 0a a trailing NUL.
8e50: 62 65 66 6f 72 65 20 72 65 74 75 72 6e 69 6e 67 before returning
8e60: 2c 20 62 65 63 61 75 73 65 20 69 74 20 61 73 73 , because it ass
8e70: 75 6d 65 73 20 74 68 65 20 4f 53 2f 38 20 63 6f umes the OS/8 co
8e80: 6e 76 65 6e 74 69 6f 6e 20 6f 66 20 43 52 2b 4c nvention of CR+L
8e90: 46 0a 74 65 72 6d 69 6e 61 74 65 64 20 74 65 78 F.terminated tex
8ea0: 74 20 66 69 6c 65 73 2e 0a 0a 4f 53 2f 38 20 74 t files...OS/8 t
8eb0: 65 78 74 20 66 69 6c 65 73 20 66 72 65 71 75 65 ext files freque
8ec0: 6e 74 6c 79 20 69 6e 63 6c 75 64 65 20 66 6f 72 ntly include for
8ed0: 6d 20 66 65 65 64 20 63 68 61 72 61 63 74 65 72 m feed character
8ee0: 73 20 e2 80 94 20 41 53 43 49 49 20 31 32 20 e2 s — ASCII 12
8ef0: 80 94 0a 6f 77 69 6e 67 20 74 6f 20 74 68 65 20 .owing to the
8f00: 50 44 50 2d 38 e2 80 99 73 20 63 6c 6f 73 65 20 PDP-8’s close
8f10: 61 73 73 6f 63 69 61 74 69 6f 6e 20 77 69 74 68 association with
8f20: 20 74 65 6c 65 70 72 69 6e 74 65 72 73 2e 20 60 teleprinters. `
8f30: 66 67 65 74 73 28 29 60 20 64 6f 65 73 0a 6e 6f fgets()` does.no
8f40: 74 20 64 6f 20 61 6e 79 74 68 69 6e 67 20 77 69 t do anything wi
8f50: 74 68 20 74 68 65 73 65 20 6f 74 68 65 72 20 74 th these other t
8f60: 68 61 6e 20 67 69 76 65 20 74 68 65 6d 20 74 6f han give them to
8f70: 20 74 68 65 20 70 72 6f 67 72 61 6d 0a 6c 69 74 the program.lit
8f80: 65 72 61 6c 6c 79 2e 20 54 68 65 73 65 20 73 68 erally. These sh
8f90: 6f 75 6c 64 20 74 79 70 69 63 61 6c 6c 79 20 62 ould typically b
8fa0: 65 20 72 65 6d 6f 76 65 64 20 66 72 6f 6d 20 69 e removed from i
8fb0: 6e 70 75 74 20 6f 72 20 72 65 70 6c 61 63 65 64 nput or replaced
8fc0: 20 77 69 74 68 0a 61 6e 20 41 53 43 49 49 20 73 with.an ASCII s
8fd0: 70 61 63 65 20 63 68 61 72 61 63 74 65 72 2c 20 pace character,
8fe0: 33 32 2e 0a 0a 52 65 74 75 72 6e 73 20 30 20 6f 32...Returns 0 o
8ff0: 6e 20 45 4f 46 2c 20 61 73 20 53 74 61 6e 64 61 n EOF, as Standa
9000: 72 64 20 43 20 72 65 71 75 69 72 65 73 2e 0a 0a rd C requires...
9010: 2a 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 **Standard Viola
9020: 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 52 65 tions:**..* Re
9030: 74 75 72 6e 73 20 74 68 65 20 6e 75 6d 62 65 72 turns the number
9040: 20 6f 66 20 63 68 61 72 61 63 74 65 72 73 20 72 of characters r
9050: 65 61 64 20 6f 6e 20 73 75 63 63 65 73 73 2c 20 ead on success,
9060: 72 61 74 68 65 72 20 74 68 61 6e 20 60 73 60 20 rather than `s`
9070: 61 73 0a 20 20 20 20 53 74 61 6e 64 61 72 64 20 as. Standard
9080: 43 20 72 65 71 75 69 72 65 73 2e 0a 0a 2a 20 20 C requires...*
9090: 20 53 69 6e 63 65 20 45 4f 46 20 69 73 20 74 68 Since EOF is th
90a0: 65 20 6f 6e 6c 79 20 65 72 72 6f 72 20 65 78 69 e only error exi
90b0: 74 20 63 61 73 65 20 66 72 6f 6d 20 74 68 69 73 t case from this
90c0: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
90d0: 6f 66 0a 20 20 20 20 60 66 67 65 74 73 28 29 60 of. `fgets()`
90e0: 2c 20 74 68 69 73 20 4c 49 42 43 20 64 6f 65 73 , this LIBC does
90f0: 20 6e 6f 74 20 70 72 6f 76 69 64 65 20 60 66 65 not provide `fe
9100: 6f 66 28 29 60 2e 0a 0a 0a 23 23 23 20 3c 61 20 of()`....### <a
9110: 69 64 3d 22 66 6f 70 65 6e 22 3e 3c 2f 61 3e 60 id="fopen"></a>`
9120: 66 6f 70 65 6e 28 6e 61 6d 65 2c 20 6d 6f 64 65 fopen(name, mode
9130: 29 60 0a 0a 4f 70 65 6e 73 20 4f 53 2f 38 20 66 )`..Opens OS/8 f
9140: 69 6c 65 20 60 44 53 4b 3a 4e 41 2e 4d 45 60 2e ile `DSK:NA.ME`.
9150: 0a 0a 54 68 65 20 60 6e 61 6d 65 60 20 70 61 72 ..The `name` par
9160: 61 6d 65 74 65 72 20 6d 75 73 74 20 70 6f 69 6e ameter must poin
9170: 74 20 74 6f 20 61 74 20 6d 6f 73 74 20 73 69 78 t to at most six
9180: 20 30 2d 74 65 72 6d 69 6e 61 74 65 64 20 63 68 0-terminated ch
9190: 61 72 61 63 74 65 72 73 2c 0a 5b 6f 6e 65 20 63 aracters,.[one c
91a0: 68 61 72 61 63 74 65 72 20 70 65 72 20 77 6f 72 haracter per wor
91b0: 64 5d 28 23 77 6f 72 64 73 74 72 29 2c 20 70 6c d](#wordstr), pl
91c0: 75 73 20 61 20 32 2d 6c 65 74 74 65 72 20 66 69 us a 2-letter fi
91d0: 6c 65 20 6e 61 6d 65 20 65 78 74 65 6e 73 69 6f le name extensio
91e0: 6e 2c 0a 61 6c 6c 20 69 6e 20 75 70 70 65 72 20 n,.all in upper
91f0: 63 61 73 65 2e 20 20 28 53 65 65 20 5b 60 63 75 case. (See [`cu
9200: 70 70 65 72 28 29 60 5d 28 23 63 75 70 70 65 72 pper()`](#cupper
9210: 29 2e 29 0a 0a 54 68 65 20 66 69 6c 65 20 69 73 ).)..The file is
9220: 20 6f 70 65 6e 65 64 20 66 6f 72 20 72 65 61 64 opened for read
9230: 69 6e 67 20 69 66 20 60 6d 6f 64 65 60 20 70 6f ing if `mode` po
9240: 69 6e 74 73 20 74 6f 20 61 6e 20 e2 80 9d 60 72 ints to an ”`r
9250: 60 e2 80 9d 20 63 68 61 72 61 63 74 65 72 2c 0a `” character,.
9260: 61 6e 64 20 69 74 20 69 73 20 6f 70 65 6e 65 64 and it is opened
9270: 20 66 6f 72 20 77 72 69 74 69 6e 67 20 69 66 20 for writing if
9280: 60 6d 6f 64 65 60 20 70 6f 69 6e 74 73 20 74 6f `mode` points to
9290: 20 61 20 e2 80 9c 60 77 60 e2 80 9d 20 63 68 61 a “`w`” cha
92a0: 72 61 63 74 65 72 2e 20 54 68 69 73 0a 6e 65 65 racter. This.nee
92b0: 64 20 6f 6e 6c 79 20 70 6f 69 6e 74 20 74 6f 20 d only point to
92c0: 61 20 73 69 6e 67 6c 65 20 63 68 61 72 61 63 74 a single charact
92d0: 65 72 2c 20 73 69 6e 63 65 20 6f 6e 6c 79 20 74 er, since only t
92e0: 68 61 74 20 6f 6e 65 20 6d 65 6d 6f 72 79 0a 6c hat one memory.l
92f0: 6f 63 61 74 69 6f 6e 20 69 73 20 65 76 65 72 20 ocation is ever
9300: 72 65 66 65 72 65 6e 63 65 64 2e 20 4e 6f 20 74 referenced. No t
9310: 65 72 6d 69 6e 61 74 6f 72 20 69 73 20 72 65 71 erminator is req
9320: 75 69 72 65 64 2e 0a 0a 54 68 65 20 4f 53 2f 38 uired...The OS/8
9330: 20 64 65 76 69 63 65 20 6e 61 6d 65 20 69 73 20 device name is
9340: 68 61 72 64 2d 63 6f 64 65 64 2c 20 64 65 73 70 hard-coded, desp
9350: 69 74 65 20 74 68 65 20 66 61 63 74 20 74 68 61 ite the fact tha
9360: 74 20 74 68 65 20 4f 53 2f 38 0a 46 4f 52 54 52 t the OS/8.FORTR
9370: 41 4e 20 49 49 20 5b 60 49 4f 50 45 4e 60 20 61 AN II [`IOPEN` a
9380: 6e 64 20 60 4f 4f 50 45 4e 60 5d 5b 66 32 66 69 nd `OOPEN`][f2fi
9390: 6f 5d 20 73 75 62 72 6f 75 74 69 6e 65 73 20 74 o] subroutines t
93a0: 68 61 74 20 60 66 6f 70 65 6e 28 29 60 20 69 73 hat `fopen()` is
93b0: 0a 69 6d 70 6c 65 6d 65 6e 74 65 64 20 69 6e 20 .implemented in
93c0: 74 65 72 6d 73 20 6f 66 20 61 63 63 65 70 74 20 terms of accept
93d0: 61 20 64 65 76 69 63 65 20 6e 61 6d 65 20 70 61 a device name pa
93e0: 72 61 6d 65 74 65 72 2e 20 54 68 69 73 20 6d 65 rameter. This me
93f0: 61 6e 73 20 74 68 65 72 65 0a 69 73 20 63 75 72 ans there.is cur
9400: 72 65 6e 74 6c 79 20 6e 6f 20 77 61 79 20 74 6f rently no way to
9410: 20 75 73 65 20 74 68 69 73 20 60 73 74 64 69 6f use this `stdio
9420: 60 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e ` implementation
9430: 20 74 6f 20 72 65 61 64 20 66 72 6f 6d 20 6f 72 to read from or
9440: 0a 77 72 69 74 65 20 74 6f 20 66 69 6c 65 73 20 .write to files
9450: 6f 6e 20 4f 53 2f 38 20 64 65 76 69 63 65 73 20 on OS/8 devices
9460: 6f 74 68 65 72 20 74 68 61 6e 20 60 44 53 4b 3a other than `DSK:
9470: 60 2e 0a 0a 54 68 65 20 75 6e 64 65 72 6c 79 69 `...The underlyi
9480: 6e 67 20 46 4f 52 54 52 41 4e 20 49 49 20 72 6f ng FORTRAN II ro
9490: 75 74 69 6e 65 73 20 61 72 65 20 64 6f 63 75 6d utines are docum
94a0: 65 6e 74 65 64 20 61 73 20 68 61 72 64 2d 63 6f ented as hard-co
94b0: 64 69 6e 67 20 74 68 65 0a 66 69 6c 65 20 6e 61 ding the.file na
94c0: 6d 65 20 65 78 74 65 6e 73 69 6f 6e 20 74 6f 20 me extension to
94d0: 60 44 41 60 2c 20 62 75 74 20 69 6e 73 70 65 63 `DA`, but inspec
94e0: 74 69 6f 6e 20 6f 66 20 74 68 65 20 63 6f 64 65 tion of the code
94f0: 20 72 65 76 65 61 6c 73 20 74 68 61 74 0a 74 68 reveals that.th
9500: 69 73 20 4c 49 42 43 20 64 6f 65 73 20 73 6f 6d is LIBC does som
9510: 65 20 68 61 63 6b 65 72 79 20 74 6f 20 6f 76 65 e hackery to ove
9520: 72 77 72 69 74 65 20 74 68 61 74 2c 20 61 6c 6c rwrite that, all
9530: 6f 77 69 6e 67 20 61 72 69 62 74 72 61 72 79 0a owing aribtrary.
9540: 65 78 74 65 6e 73 69 6f 6e 73 2e 20 20 2a 2a 54 extensions. **T
9550: 4f 44 4f 3a 2a 2a 20 56 65 72 69 66 79 20 74 68 ODO:** Verify th
9560: 69 73 20 66 6f 72 20 62 6f 74 68 20 72 65 61 64 is for both read
9570: 20 61 6e 64 20 77 72 69 74 65 2e 0a 0a 0a 2a 2a and write....**
9580: 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 69 Standard Violati
9590: 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 44 6f 65 73 ons:**..* Does
95a0: 20 6e 6f 74 20 72 65 74 75 72 6e 20 61 20 60 46 not return a `F
95b0: 49 4c 45 2a 60 2e 20 46 75 6e 63 74 69 6f 6e 73 ILE*`. Functions
95c0: 20 77 68 69 63 68 2c 20 69 6e 20 53 74 61 6e 64 which, in Stand
95d0: 61 72 64 20 43 2c 20 74 61 6b 65 20 61 0a 20 20 ard C, take a.
95e0: 20 20 60 46 49 4c 45 2a 60 20 61 72 67 75 6d 65 `FILE*` argume
95f0: 6e 74 20 64 6f 20 6e 6f 74 20 64 6f 20 73 6f 20 nt do not do so
9600: 69 6e 20 74 68 65 20 43 43 38 20 4c 49 42 43 2c in the CC8 LIBC,
9610: 20 62 65 63 61 75 73 65 20 74 68 65 72 65 20 63 because there c
9620: 61 6e 20 62 65 0a 20 20 20 20 6f 6e 6c 79 20 6f an be. only o
9630: 6e 65 20 6f 70 65 6e 65 64 20 69 6e 70 75 74 20 ne opened input
9640: 66 69 6c 65 20 61 6e 64 20 6f 6e 65 20 6f 70 65 file and one ope
9650: 6e 65 64 20 6f 75 74 70 75 74 20 66 69 6c 65 20 ned output file
9660: 61 74 20 61 20 74 69 6d 65 2c 20 73 6f 0a 20 20 at a time, so.
9670: 20 20 74 68 65 20 66 69 6c 65 20 74 68 61 74 20 the file that
9680: 69 73 20 6d 65 61 6e 74 20 69 73 20 69 6d 70 6c is meant is impl
9690: 69 63 69 74 20 69 6e 20 74 68 65 20 63 61 6c 6c icit in the call
96a0: 2e 0a 0a 20 20 20 20 54 68 69 73 20 61 6c 73 6f ... This also
96b0: 20 6d 65 61 6e 73 20 60 66 6f 70 65 6e 28 29 60 means `fopen()`
96c0: 20 68 61 73 20 6e 6f 20 77 61 79 20 74 6f 20 73 has no way to s
96d0: 69 67 6e 61 6c 20 61 20 66 61 69 6c 75 72 65 20 ignal a failure
96e0: 74 6f 20 6f 70 65 6e 20 74 68 65 0a 20 20 20 20 to open the.
96f0: 72 65 71 75 65 73 74 65 64 20 66 69 6c 65 20 6e requested file n
9700: 61 6d 65 21 20 20 2e 2e 2e 57 68 69 63 68 20 69 ame! ...Which i
9710: 73 20 6a 75 73 74 20 61 73 20 77 65 6c 6c 2c 20 s just as well,
9720: 73 69 6e 63 65 20 74 68 65 72 65 20 69 73 20 61 since there is a
9730: 6c 73 6f 0a 20 20 20 20 6e 6f 20 60 66 65 72 72 lso. no `ferr
9740: 6f 72 28 29 60 20 6f 72 20 60 65 72 72 6e 6f 60 or()` or `errno`
9750: 20 69 6e 20 6f 75 72 20 4c 49 42 43 2e 0a 0a 20 in our LIBC...
9760: 20 20 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e This function
9770: 20 77 69 6c 6c 20 72 65 74 75 72 6e 20 2d 31 20 will return -1
9780: 69 66 20 6e 6f 20 66 69 6c 65 20 6e 61 6d 65 20 if no file name
9790: 65 78 74 65 6e 73 69 6f 6e 20 69 73 20 67 69 76 extension is giv
97a0: 65 6e 2c 0a 20 20 20 20 77 68 69 63 68 20 69 73 en,. which is
97b0: 20 67 6f 6f 64 20 69 6e 20 74 68 61 74 20 69 74 good in that it
97c0: 20 6d 65 61 6e 73 20 74 68 69 73 20 66 75 6e 63 means this func
97d0: 74 69 6f 6e 20 64 6f 65 73 20 68 61 76 65 20 2a tion does have *
97e0: 73 6f 6d 65 2a 20 65 72 72 6f 72 0a 20 20 20 20 some* error.
97f0: 63 68 65 63 6b 69 6e 67 2c 20 69 74 e2 80 99 73 checking, it’s
9800: 20 61 20 6e 6f 6e 73 74 61 6e 64 61 72 64 20 77 a nonstandard w
9810: 61 79 20 74 6f 20 73 69 67 6e 61 6c 20 69 74 2e ay to signal it.
9820: 0a 0a 2a 20 20 20 44 6f 65 73 20 6e 6f 74 20 61 ..* Does not a
9830: 63 63 65 70 74 20 74 68 65 20 73 74 61 6e 64 61 ccept the standa
9840: 72 64 20 6d 6f 64 65 20 60 61 60 2c 20 66 6f 72 rd mode `a`, for
9850: 20 61 70 70 65 6e 64 2e 20 20 53 69 6e 63 65 20 append. Since
9860: 74 68 65 72 65 20 69 73 0a 20 20 20 20 61 6c 73 there is. als
9870: 6f 20 6e 6f 20 60 66 73 65 65 6b 28 29 60 20 69 o no `fseek()` i
9880: 6e 20 43 43 38 e2 80 99 73 20 4c 49 42 43 2c 20 n CC8’s LIBC,
9890: 61 20 70 72 65 65 78 69 73 74 69 6e 67 20 66 69 a preexisting fi
98a0: 6c 65 20 6e 61 6d 65 64 20 66 6f 72 0a 20 20 20 le named for.
98b0: 20 77 72 69 74 69 6e 67 20 69 73 20 61 6c 77 61 writing is alwa
98c0: 79 73 20 6f 76 65 72 77 72 69 74 74 65 6e 2e 0a ys overwritten..
98d0: 0a 2a 20 20 20 44 6f 65 73 20 6e 6f 74 20 61 63 .* Does not ac
98e0: 63 65 70 74 20 74 68 65 20 73 74 61 6e 64 61 72 cept the standar
98f0: 64 20 60 2b 60 20 6d 6f 64 69 66 69 65 72 20 74 d `+` modifier t
9900: 6f 20 63 6f 6d 62 69 6e 65 20 72 65 61 64 2f 77 o combine read/w
9910: 72 69 74 65 0a 20 20 20 20 6d 6f 64 65 73 3a 20 rite. modes:
9920: 66 69 6c 65 73 20 61 72 65 20 6f 6e 6c 79 20 72 files are only r
9930: 65 61 64 61 62 6c 65 20 6f 72 20 6f 6e 6c 79 20 eadable or only
9940: 77 72 69 74 65 61 62 6c 65 20 75 6e 64 65 72 20 writeable under
9950: 74 68 69 73 0a 20 20 20 20 69 6d 70 6c 65 6d 65 this. impleme
9960: 6e 74 61 74 69 6f 6e 2e 20 20 4e 65 69 74 68 65 ntation. Neithe
9970: 72 20 69 73 20 69 74 20 70 6f 73 73 69 62 6c 65 r is it possible
9980: 20 74 6f 20 67 69 76 65 20 e2 80 9c 60 72 77 60 to give “`rw`
9990: e2 80 9d 2c 20 74 68 65 0a 20 20 20 20 6e 6f 6e ”, the. non
99a0: 73 74 61 6e 64 61 72 64 20 62 75 74 20 77 69 64 standard but wid
99b0: 65 6c 79 20 73 75 70 70 6f 72 74 65 64 20 77 61 ely supported wa
99c0: 79 20 74 6f 20 73 70 65 63 69 66 79 20 e2 80 9c y to specify “
99d0: 6f 70 65 6e 20 66 6f 72 0a 20 20 20 20 72 65 61 open for. rea
99e0: 64 2f 77 72 69 74 65 e2 80 9d 2e 0a 0a 2a 20 20 d/write”...*
99f0: 20 44 6f 65 73 20 6e 6f 74 20 73 75 70 70 6f 72 Does not suppor
9a00: 74 20 74 68 65 20 60 62 60 20 6d 6f 64 69 66 69 t the `b` modifi
9a10: 65 72 20 66 6f 72 20 62 69 6e 61 72 79 20 49 2f er for binary I/
9a20: 4f 3a 20 66 69 6c 65 73 20 61 72 65 20 61 73 73 O: files are ass
9a30: 75 6d 65 64 0a 20 20 20 20 74 6f 20 63 6f 6e 74 umed. to cont
9a40: 61 69 6e 20 41 53 43 49 49 20 74 65 78 74 20 6f ain ASCII text o
9a50: 6e 6c 79 2e 0a 0a 2a 20 20 20 44 6f 65 73 20 6e nly...* Does n
9a60: 6f 74 20 64 69 61 67 6e 6f 73 65 20 6e 75 6c 6c ot diagnose null
9a70: 20 70 6f 69 6e 74 65 72 73 20 61 73 20 72 65 71 pointers as req
9a80: 75 69 72 65 64 20 62 79 20 74 68 65 20 53 74 61 uired by the Sta
9a90: 6e 64 61 72 64 3a 20 69 74 20 77 69 6c 6c 0a 20 ndard: it will.
9aa0: 20 20 20 70 72 6f 62 61 62 6c 79 20 64 6f 20 73 probably do s
9ab0: 6f 6d 65 74 68 69 6e 67 20 73 69 6c 6c 79 20 6c omething silly l
9ac0: 69 6b 65 20 72 65 66 65 72 65 6e 63 65 20 5b 63 ike reference [c
9ad0: 6f 72 65 20 6d 65 6d 6f 72 79 20 6c 6f 63 61 74 ore memory locat
9ae0: 69 6f 6e 20 30 0a 20 20 20 20 69 6e 20 74 68 65 ion 0. in the
9af0: 20 75 73 65 72 20 64 61 74 61 20 66 69 65 6c 64 user data field
9b00: 5d 28 23 75 64 66 29 2c 20 74 68 65 6e 20 72 65 ](#udf), then re
9b10: 74 75 72 6e 20 77 69 74 68 6f 75 74 20 68 61 76 turn without hav
9b20: 69 6e 67 20 64 6f 6e 65 0a 20 20 20 20 61 6e 79 ing done. any
9b30: 74 68 69 6e 67 20 75 73 65 66 75 6c 2c 20 63 61 thing useful, ca
9b40: 75 73 69 6e 67 20 74 68 65 20 73 75 62 73 65 71 using the subseq
9b50: 75 65 6e 74 20 49 2f 4f 20 63 61 6c 6c 73 20 6f uent I/O calls o
9b60: 6e 20 74 68 61 74 20 66 69 6c 65 20 74 6f 0a 20 n that file to.
9b70: 20 20 20 66 61 69 6c 2e 0a 0a 2a 20 20 20 54 68 fail...* Th
9b80: 65 72 65 20 61 70 70 65 61 72 73 20 74 6f 20 62 ere appears to b
9b90: 65 20 61 20 62 75 67 20 69 6e 20 74 68 65 20 63 e a bug in the c
9ba0: 75 72 72 65 6e 74 20 69 6d 70 6c 65 6d 65 6e 74 urrent implement
9bb0: 61 74 69 6f 6e 20 74 68 61 74 0a 20 20 20 20 72 ation that. r
9bc0: 65 71 75 69 72 65 73 20 79 6f 75 20 74 6f 20 6f equires you to o
9bd0: 70 65 6e 20 74 68 65 20 69 6e 70 75 74 20 66 69 pen the input fi
9be0: 6c 65 20 62 65 66 6f 72 65 20 6f 70 65 6e 69 6e le before openin
9bf0: 67 20 61 6e 20 6f 75 74 70 75 74 20 66 69 6c 65 g an output file
9c00: 0a 20 20 20 20 77 68 65 6e 20 79 6f 75 20 6e 65 . when you ne
9c10: 65 64 20 62 6f 74 68 2e 20 20 49 74 20 6d 61 79 ed both. It may
9c20: 20 6e 6f 74 20 62 65 20 70 6f 73 73 69 62 6c 65 not be possible
9c30: 20 74 6f 20 66 69 78 20 74 68 69 73 20 77 69 74 to fix this wit
9c40: 68 69 6e 20 74 68 65 0a 20 20 20 20 63 75 72 72 hin the. curr
9c50: 65 6e 74 20 6c 69 6d 69 74 61 74 69 6f 6e 73 20 ent limitations
9c60: 6f 6e 20 74 68 65 20 6c 69 62 72 61 72 79 2c 20 on the library,
9c70: 62 75 74 20 69 66 20 79 6f 75 20 63 6f 6d 65 20 but if you come
9c80: 75 70 20 77 69 74 68 0a 20 20 20 20 73 6f 6d 65 up with. some
9c90: 74 68 69 6e 67 2c 20 5b 77 65 20 61 63 63 65 70 thing, [we accep
9ca0: 74 20 70 61 74 63 68 65 73 5d 5b 68 61 6b 70 5d t patches][hakp]
9cb0: 2e 0a 0a 5b 68 61 6b 70 5d 3a 20 2f 64 6f 63 2f ...[hakp]: /doc/
9cc0: 74 72 75 6e 6b 2f 43 4f 4e 54 52 49 42 55 54 49 trunk/CONTRIBUTI
9cd0: 4e 47 2e 6d 64 23 70 61 74 63 68 65 73 0a 0a 0a NG.md#patches...
9ce0: 23 23 23 20 3c 61 20 69 64 3d 22 66 70 72 69 6e ### <a id="fprin
9cf0: 74 66 22 3e 3c 2f 61 3e 60 66 70 72 69 6e 74 66 tf"></a>`fprintf
9d00: 28 66 6d 74 2c 20 61 72 67 73 2e 2e 2e 29 60 0a (fmt, args...)`.
9d10: 0a 57 72 69 74 65 73 20 69 74 73 20 61 72 67 75 .Writes its argu
9d20: 6d 65 6e 74 73 20 28 60 61 72 67 73 60 2e 2e 2e ments (`args`...
9d30: 29 20 74 6f 20 74 68 65 20 63 75 72 72 65 6e 74 ) to the current
9d40: 6c 79 2d 6f 70 65 6e 65 64 20 6f 75 74 70 75 74 ly-opened output
9d50: 20 66 69 6c 65 0a 61 63 63 6f 72 64 69 6e 67 20 file.according
9d60: 74 6f 20 66 6f 72 6d 61 74 20 73 74 72 69 6e 67 to format string
9d70: 20 60 66 6d 74 60 2e 0a 0a 52 65 74 75 72 6e 73 `fmt`...Returns
9d80: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 63 the number of c
9d90: 68 61 72 61 63 74 65 72 73 20 77 72 69 74 74 65 haracters writte
9da0: 6e 20 74 6f 20 74 68 65 20 6f 75 74 70 75 74 20 n to the output
9db0: 66 69 6c 65 2e 0a 0a 54 68 69 73 20 66 75 6e 63 file...This func
9dc0: 74 69 6f 6e 20 69 73 20 6a 75 73 74 20 61 20 73 tion is just a s
9dd0: 69 6d 70 6c 65 20 77 72 61 70 70 65 72 20 61 72 imple wrapper ar
9de0: 6f 75 6e 64 20 5b 60 70 72 69 6e 74 66 28 29 60 ound [`printf()`
9df0: 5d 28 23 70 72 69 6e 74 66 29 0a 77 68 69 63 68 ](#printf).which
9e00: 20 73 65 74 73 20 61 20 66 6c 61 67 20 74 68 61 sets a flag tha
9e10: 74 20 63 61 75 73 65 73 20 60 70 72 69 6e 74 66 t causes `printf
9e20: 28 29 60 20 74 6f 20 77 72 69 74 65 20 74 68 65 ()` to write the
9e30: 20 66 6f 72 6d 61 74 74 65 64 20 73 74 72 69 6e formatted strin
9e40: 67 0a 74 6f 20 74 68 65 20 63 75 72 72 65 6e 74 g.to the current
9e50: 20 6f 75 74 70 75 74 20 66 69 6c 65 20 75 73 69 output file usi
9e60: 6e 67 20 5b 60 66 70 75 74 73 28 29 60 5d 28 23 ng [`fputs()`](#
9e70: 66 70 75 74 73 29 20 69 6e 73 74 65 61 64 20 6f fputs) instead o
9e80: 66 20 74 6f 0a 60 54 54 59 3a 60 2c 20 73 6f 20 f to.`TTY:`, so
9e90: 79 6f 75 20 6d 75 73 74 20 72 65 61 64 20 74 68 you must read th
9ea0: 6f 73 65 20 74 77 6f 20 66 75 6e 63 74 69 6f 6e ose two function
9eb0: 73 e2 80 99 20 64 6f 63 75 6d 65 6e 74 61 74 69 s’ documentati
9ec0: 6f 6e 20 74 6f 20 66 75 6c 6c 79 0a 75 6e 64 65 on to fully.unde
9ed0: 72 73 74 61 6e 64 20 60 66 70 72 69 6e 74 66 28 rstand `fprintf(
9ee0: 29 60 2e 20 53 69 6e 63 65 20 60 70 72 69 6e 74 )`. Since `print
9ef0: 66 28 29 60 20 69 73 20 69 6e 20 74 75 72 6e 20 f()` is in turn
9f00: 62 61 73 65 64 20 6f 6e 0a 5b 60 73 70 72 69 6e based on.[`sprin
9f10: 74 66 28 29 60 5d 28 23 73 70 72 69 6e 74 66 29 tf()`](#sprintf)
9f20: 2c 20 79 6f 75 20 6d 75 73 74 20 72 65 61 64 20 , you must read
9f30: 74 68 61 74 20 66 75 6e 63 74 69 6f 6e e2 80 99 that function’
9f40: 73 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e 20 s documentation
9f50: 61 73 0a 77 65 6c 6c 2e 0a 0a 2a 2a 53 74 61 6e as.well...**Stan
9f60: 64 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a dard Violations:
9f70: 2a 2a 0a 0a 2a 20 20 20 60 66 70 72 69 6e 74 66 **..* `fprintf
9f80: 60 20 64 6f 65 73 20 6e 6f 74 20 74 61 6b 65 20 ` does not take
9f90: 61 20 60 46 49 4c 45 2a 60 20 70 6f 69 6e 74 65 a `FILE*` pointe
9fa0: 72 20 61 73 20 69 74 73 20 66 69 72 73 74 20 61 r as its first a
9fb0: 72 67 75 6d 65 6e 74 2e 20 49 74 0a 20 20 20 20 rgument. It.
9fc0: 73 69 6d 70 6c 79 20 77 72 69 74 65 73 20 74 6f simply writes to
9fd0: 20 74 68 65 20 6f 6e 65 20 61 6e 64 20 6f 6e 6c the one and onl
9fe0: 79 20 6f 75 74 70 75 74 20 66 69 6c 65 20 74 68 y output file th
9ff0: 61 74 20 63 61 6e 20 62 65 20 6f 70 65 6e 65 64 at can be opened
a000: 20 61 74 0a 20 20 20 20 61 20 74 69 6d 65 20 62 at. a time b
a010: 79 20 5b 60 66 6f 70 65 6e 28 29 60 5d 28 23 66 y [`fopen()`](#f
a020: 6f 70 65 6e 29 2e 0a 0a 2a 20 20 20 46 69 6c 65 open)...* File
a030: 20 49 2f 4f 20 65 72 72 6f 72 73 20 61 72 65 20 I/O errors are
a040: 6e 6f 74 20 64 69 61 67 6e 6f 73 65 64 2e 0a 0a not diagnosed...
a050: 0a 23 23 23 20 3c 61 20 69 64 3d 22 67 65 74 63 .### <a id="getc
a060: 22 20 6e 61 6d 65 3d 22 66 67 65 74 63 22 3e 3c " name="fgetc"><
a070: 2f 61 3e 60 67 65 74 63 28 29 60 2c 20 60 66 67 /a>`getc()`, `fg
a080: 65 74 63 28 29 60 0a 0a 52 65 61 64 73 20 61 20 etc()`..Reads a
a090: 73 69 6e 67 6c 65 20 41 53 43 49 49 20 63 68 61 single ASCII cha
a0a0: 72 61 63 74 65 72 20 66 72 6f 6d 20 60 54 54 59 racter from `TTY
a0b0: 3a 60 20 6f 72 20 66 72 6f 6d 20 74 68 65 20 6c :` or from the l
a0c0: 61 73 74 20 66 69 6c 65 20 6f 70 65 6e 65 64 0a ast file opened.
a0d0: 66 6f 72 20 69 6e 70 75 74 20 62 79 20 5b 60 66 for input by [`f
a0e0: 6f 70 65 6e 28 29 60 5d 28 23 66 6f 70 65 6e 29 open()`](#fopen)
a0f0: 2c 20 72 65 73 70 65 63 74 69 76 65 6c 79 2e 0a , respectively..
a100: 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c .**Standard Viol
a110: 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 52 ations:**..* R
a120: 65 74 75 72 6e 73 20 41 53 43 49 49 20 4e 55 4c eturns ASCII NUL
a130: 20 28 30 29 20 74 6f 20 73 69 67 6e 61 6c 20 45 (0) to signal E
a140: 4f 46 2c 20 6e 6f 74 20 61 6e 20 69 6d 70 6c 65 OF, not an imple
a150: 6d 65 6e 74 61 74 69 6f 6e 2d 64 65 66 69 6e 65 mentation-define
a160: 64 0a 20 20 20 20 6f 75 74 2d 6f 66 2d 72 61 6e d. out-of-ran
a170: 67 65 20 45 4f 46 20 63 6f 6e 73 74 61 6e 74 2e ge EOF constant.
a180: 20 20 28 4d 6f 73 74 20 63 6f 6d 6d 6f 6e 6c 79 (Most commonly
a190: 20 2d 31 20 69 6e 20 6f 74 68 65 72 20 43 20 6c -1 in other C l
a1a0: 69 62 72 61 72 79 0a 20 20 20 20 69 6d 70 6c 65 ibrary. imple
a1b0: 6d 65 6e 74 61 74 69 6f 6e 73 2e 29 20 20 53 69 mentations.) Si
a1c0: 6e 63 65 20 74 68 65 72 65 20 69 73 20 6e 6f 20 nce there is no
a1d0: 60 66 65 6f 66 28 29 60 20 66 75 6e 63 74 69 6f `feof()` functio
a1e0: 6e 20 69 6e 20 43 43 38 20 4c 49 42 43 0a 20 20 n in CC8 LIBC.
a1f0: 20 20 74 6f 20 64 69 73 61 6d 62 69 67 75 61 74 to disambiguat
a200: 65 20 74 68 65 20 63 61 73 65 73 2c 20 74 68 69 e the cases, thi
a210: 73 20 66 75 6e 63 74 69 6f 6e 20 63 61 6e 6e 6f s function canno
a220: 74 20 73 61 66 65 6c 79 20 62 65 20 63 61 6c 6c t safely be call
a230: 65 64 20 66 6f 72 0a 20 20 20 20 66 69 6c 65 73 ed for. files
a240: 20 74 68 61 74 20 63 6f 75 6c 64 20 63 6f 6e 74 that could cont
a250: 61 69 6e 20 61 20 30 20 62 79 74 65 2c 20 73 69 ain a 0 byte, si
a260: 6e 63 65 20 69 74 20 77 69 6c 6c 20 72 65 73 75 nce it will resu
a270: 6c 74 20 69 6e 20 61 20 66 61 6c 73 65 0a 20 20 lt in a false.
a280: 20 20 74 72 75 6e 63 61 74 69 6f 6e 2e 0a 0a 0a truncation....
a290: 23 23 23 20 3c 61 20 69 64 3d 22 67 65 74 73 22 ### <a id="gets"
a2a0: 3e 3c 2f 61 3e 60 67 65 74 73 28 73 29 60 0a 0a ></a>`gets(s)`..
a2b0: 52 65 61 64 73 20 61 20 73 74 72 69 6e 67 20 6f Reads a string o
a2c0: 66 20 41 53 43 49 49 20 63 68 61 72 61 63 74 65 f ASCII characte
a2d0: 72 73 20 66 72 6f 6d 20 60 54 54 59 3a 60 2c 20 rs from `TTY:`,
a2e0: 75 70 20 74 6f 20 61 6e 64 20 69 6e 63 6c 75 64 up to and includ
a2f0: 69 6e 67 20 74 68 65 0a 74 65 72 6d 69 6e 61 74 ing the.terminat
a300: 69 6e 67 20 43 52 20 63 68 61 72 61 63 74 65 72 ing CR character
a310: 2c 20 73 74 6f 72 69 6e 67 20 69 74 20 61 74 20 , storing it at
a320: 63 6f 72 65 20 6d 65 6d 6f 72 79 20 6c 6f 63 61 core memory loca
a330: 74 69 6f 6e 20 60 73 60 2c 20 61 6e 64 0a 66 6f tion `s`, and.fo
a340: 6c 6c 6f 77 69 6e 67 20 74 68 65 20 74 65 72 6d llowing the term
a350: 69 6e 61 74 69 6e 67 20 43 52 20 77 69 74 68 20 inating CR with
a360: 61 20 4e 55 4c 20 63 68 61 72 61 63 74 65 72 2e a NUL character.
a370: 0a 0a 42 61 63 6b 73 70 61 63 65 20 63 68 61 72 ..Backspace char
a380: 61 63 74 65 72 73 20 66 72 6f 6d 20 74 68 65 20 acters from the
a390: 74 65 72 6d 69 6e 61 6c 20 72 65 6d 6f 76 65 20 terminal remove
a3a0: 74 68 65 20 6c 61 73 74 20 63 68 61 72 61 63 74 the last charact
a3b0: 65 72 20 66 72 6f 6d 0a 74 68 65 20 73 74 72 69 er from.the stri
a3c0: 6e 67 2e 0a 0a 52 65 74 75 72 6e 73 20 74 68 65 ng...Returns the
a3d0: 20 70 61 73 73 65 64 20 73 74 72 69 6e 67 20 70 passed string p
a3e0: 6f 69 6e 74 65 72 20 6f 6e 20 73 75 63 63 65 73 ointer on succes
a3f0: 73 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 s...**Standard V
a400: 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 iolations:**..*
a410: 20 20 43 61 6e 6e 6f 74 20 72 65 74 75 72 6e 20 Cannot return
a420: 30 20 66 6f 72 20 e2 80 9c 6e 6f 20 69 6e 70 75 0 for “no inpu
a430: 74 e2 80 9d 20 61 73 20 53 74 61 6e 64 61 72 64 t” as Standard
a440: 20 43 20 72 65 71 75 69 72 65 73 3a 20 61 6c 77 C requires: alw
a450: 61 79 73 0a 20 20 20 20 73 75 63 63 65 65 64 73 ays. succeeds
a460: 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 69 ....### <a id="i
a470: 73 61 6c 6e 75 6d 22 3e 3c 2f 61 3e 60 69 73 61 salnum"></a>`isa
a480: 6c 6e 75 6d 28 63 29 60 0a 0a 52 65 74 75 72 6e lnum(c)`..Return
a490: 73 20 6e 6f 6e 7a 65 72 6f 20 69 66 20 65 69 74 s nonzero if eit
a4a0: 68 65 72 20 5b 60 69 73 64 69 67 69 74 28 29 60 her [`isdigit()`
a4b0: 5d 28 23 69 73 64 69 67 69 74 29 20 6f 72 0a 5b ](#isdigit) or.[
a4c0: 60 69 73 61 6c 70 68 61 28 29 60 5d 28 23 69 73 `isalpha()`](#is
a4d0: 61 6c 70 68 61 29 20 72 65 74 75 72 6e 73 20 6e alpha) returns n
a4e0: 6f 6e 7a 65 72 6f 20 66 6f 72 20 60 63 60 2e 0a onzero for `c`..
a4f0: 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c .**Standard Viol
a500: 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 44 ations:**..* D
a510: 6f 65 73 20 6e 6f 74 20 6b 6e 6f 77 20 61 6e 79 oes not know any
a520: 74 68 69 6e 67 20 61 62 6f 75 74 20 6c 6f 63 61 thing about loca
a530: 6c 65 73 3b 20 61 73 73 75 6d 65 73 20 55 53 2d les; assumes US-
a540: 41 53 43 49 49 20 69 6e 70 75 74 2e 0a 0a 0a 23 ASCII input....#
a550: 23 23 20 3c 61 20 69 64 3d 22 69 73 61 6c 70 68 ## <a id="isalph
a560: 61 22 3e 3c 2f 61 3e 60 69 73 61 6c 70 68 61 28 a"></a>`isalpha(
a570: 63 29 60 0a 0a 52 65 74 75 72 6e 73 20 6e 6f 6e c)`..Returns non
a580: 7a 65 72 6f 20 69 66 20 74 68 65 20 70 61 73 73 zero if the pass
a590: 65 64 20 63 68 61 72 61 63 74 65 72 20 60 63 60 ed character `c`
a5a0: 20 69 73 20 65 69 74 68 65 72 20 62 65 74 77 65 is either betwe
a5b0: 65 6e 20 36 35 20 61 6e 64 20 39 30 0a 6f 72 20 en 65 and 90.or
a5c0: 62 65 74 77 65 65 6e 20 39 37 20 61 6e 64 20 31 between 97 and 1
a5d0: 32 32 20 69 6e 63 6c 75 73 69 76 65 2c 20 62 65 22 inclusive, be
a5e0: 69 6e 67 20 74 68 65 20 41 53 43 49 49 20 61 6c ing the ASCII al
a5f0: 70 68 61 62 65 74 69 63 20 63 68 61 72 61 63 74 phabetic charact
a600: 65 72 73 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 ers...**Standard
a610: 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a Violations:**..
a620: 2a 20 20 20 44 6f 65 73 20 6e 6f 74 20 6b 6e 6f * Does not kno
a630: 77 20 61 6e 79 74 68 69 6e 67 20 61 62 6f 75 74 w anything about
a640: 20 6c 6f 63 61 6c 65 73 3b 20 61 73 73 75 6d 65 locales; assume
a650: 73 20 55 53 2d 41 53 43 49 49 20 69 6e 70 75 74 s US-ASCII input
a660: 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 69 ....### <a id="i
a670: 73 64 69 67 69 74 22 20 6e 61 6d 65 3d 22 69 73 sdigit" name="is
a680: 6e 75 6d 22 3e 3c 2f 61 3e 60 69 73 64 69 67 69 num"></a>`isdigi
a690: 74 28 63 29 60 2c 20 60 69 73 6e 75 6d 28 63 29 t(c)`, `isnum(c)
a6a0: 60 0a 0a 52 65 74 75 72 6e 73 20 6e 6f 6e 7a 65 `..Returns nonze
a6b0: 72 6f 20 69 66 20 74 68 65 20 70 61 73 73 65 64 ro if the passed
a6c0: 20 63 68 61 72 61 63 74 65 72 20 60 63 60 20 69 character `c` i
a6d0: 73 20 62 65 74 77 65 65 6e 20 34 38 20 61 6e 20 s between 48 an
a6e0: 35 37 2c 0a 69 6e 63 6c 75 73 69 76 65 2c 20 62 57,.inclusive, b
a6f0: 65 69 6e 67 20 74 68 65 20 41 53 43 49 49 20 64 eing the ASCII d
a700: 65 63 69 6d 61 6c 20 64 69 67 69 74 20 63 68 61 ecimal digit cha
a710: 72 61 63 74 65 72 73 2e 0a 0a 2a 2a 53 74 61 6e racters...**Stan
a720: 64 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a dard Violations:
a730: 2a 2a 0a 0a 2a 20 20 20 60 69 73 6e 75 6d 60 20 **..* `isnum`
a740: 69 73 20 61 20 6e 6f 6e 73 74 61 6e 64 61 72 64 is a nonstandard
a750: 20 61 6c 69 61 73 20 66 6f 72 20 60 69 73 64 69 alias for `isdi
a760: 67 69 74 60 20 63 6f 6e 66 6f 72 6d 69 6e 67 20 git` conforming
a770: 74 6f 20 6e 6f 20 6f 74 68 65 72 0a 20 20 20 20 to no other.
a780: 6b 6e 6f 77 6e 20 43 20 6c 69 62 72 61 72 79 20 known C library
a790: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 20 implementation.
a7a0: 20 42 6f 74 68 20 61 72 65 20 69 6d 70 6c 65 6d Both are implem
a7b0: 65 6e 74 65 64 20 77 69 74 68 20 74 68 65 20 73 ented with the s
a7c0: 61 6d 65 0a 20 20 20 20 4c 49 42 43 20 63 6f 64 ame. LIBC cod
a7d0: 65 2e 0a 0a 2a 20 20 20 44 6f 65 73 20 6e 6f 74 e...* Does not
a7e0: 20 6b 6e 6f 77 20 61 6e 79 74 68 69 6e 67 20 61 know anything a
a7f0: 62 6f 75 74 20 6c 6f 63 61 6c 65 73 3b 20 61 73 bout locales; as
a800: 73 75 6d 65 73 20 55 53 2d 41 53 43 49 49 20 69 sumes US-ASCII i
a810: 6e 70 75 74 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 nput....### <a i
a820: 64 3d 22 69 73 73 70 61 63 65 22 3e 3c 2f 61 3e d="isspace"></a>
a830: 60 69 73 73 70 61 63 65 28 63 29 60 0a 0a 52 65 `isspace(c)`..Re
a840: 74 75 72 6e 73 20 6e 6f 6e 7a 65 72 6f 20 69 66 turns nonzero if
a850: 20 74 68 65 20 70 61 73 73 65 64 20 63 68 61 72 the passed char
a860: 61 63 74 65 72 20 60 63 60 20 69 73 20 63 6f 6e acter `c` is con
a870: 73 69 64 65 72 65 64 20 61 20 e2 80 9c 77 68 69 sidered a “whi
a880: 74 65 73 70 61 63 65 e2 80 9d 0a 63 68 61 72 61 tespace”.chara
a890: 63 74 65 72 2e 0a 0a 54 68 69 73 20 66 75 6e 63 cter...This func
a8a0: 74 69 6f 6e 20 69 73 20 6e 6f 74 20 75 73 65 64 tion is not used
a8b0: 20 62 79 20 60 61 74 6f 69 60 3a 20 69 74 73 20 by `atoi`: its
a8c0: 77 68 69 74 65 73 70 61 63 65 20 6d 61 74 63 68 whitespace match
a8d0: 69 6e 67 20 69 73 0a 68 61 72 64 2d 63 6f 64 65 ing is.hard-code
a8e0: 64 20 69 6e 74 65 72 6e 61 6c 6c 79 2e 0a 0a 2a d internally...*
a8f0: 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 *Standard Violat
a900: 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 57 68 69 ions:**..* Whi
a910: 74 65 73 70 61 63 65 20 69 73 20 63 75 72 72 65 tespace is curre
a920: 6e 74 6c 79 20 64 65 66 69 6e 65 64 20 61 73 20 ntly defined as
a930: 41 53 43 49 49 20 31 20 74 68 72 6f 75 67 68 20 ASCII 1 through
a940: 33 32 2c 20 69 6e 63 6c 75 73 69 76 65 2e 0a 20 32, inclusive..
a950: 20 20 20 59 65 73 2c 20 74 68 69 73 20 69 73 20 Yes, this is
a960: 61 20 2a 76 61 73 74 2a 20 6f 76 65 72 72 65 61 a *vast* overrea
a970: 63 68 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d ch....### <a id=
a980: 22 69 74 6f 61 22 3e 3c 2f 61 3e 60 69 74 6f 61 "itoa"></a>`itoa
a990: 28 6e 75 6d 2c 20 73 74 72 2c 20 72 61 64 69 78 (num, str, radix
a9a0: 29 60 0a 0a 43 6f 6e 76 65 72 74 20 61 20 31 32 )`..Convert a 12
a9b0: 2d 62 69 74 20 50 44 50 2d 38 20 69 6e 74 65 67 -bit PDP-8 integ
a9c0: 65 72 20 60 6e 75 6d 60 20 74 6f 20 61 6e 20 5b er `num` to an [
a9d0: 41 53 43 49 49 20 77 6f 72 64 20 73 74 72 69 6e ASCII word strin
a9e0: 67 5d 28 23 77 6f 72 64 73 74 72 29 0a 65 78 70 g](#wordstr).exp
a9f0: 72 65 73 73 69 6e 67 20 74 68 61 74 20 6e 75 6d ressing that num
aa00: 62 65 72 20 69 6e 20 74 68 65 20 67 69 76 65 6e ber in the given
aa10: 20 60 72 61 64 69 78 60 2c 20 73 74 6f 72 65 64 `radix`, stored
aa20: 20 69 6e 20 6d 65 6d 6f 72 79 20 70 6f 69 6e 74 in memory point
aa30: 65 64 20 74 6f 0a 62 79 20 60 73 74 72 60 2e 0a ed to.by `str`..
aa40: 0a 49 66 20 60 72 61 64 69 78 60 20 69 73 20 31 .If `radix` is 1
aa50: 30 2c 20 60 6e 75 6d 60 20 69 73 20 74 72 65 61 0, `num` is trea
aa60: 74 65 64 20 61 73 20 61 20 74 77 6f e2 80 99 73 ted as a two’s
aa70: 20 63 6f 6d 70 6c 65 6d 65 6e 74 20 69 6e 74 65 complement inte
aa80: 67 65 72 2c 20 73 6f 0a 74 68 61 74 20 60 73 74 ger, so.that `st
aa90: 72 5b 30 5d 20 3d 3d 20 27 2d 27 60 20 66 6f 72 r[0] == '-'` for
aaa0: 20 6e 65 67 61 74 69 76 65 20 6e 75 6d 62 65 72 negative number
aab0: 73 2e 0a 0a 46 6f 72 20 6f 74 68 65 72 20 72 61 s...For other ra
aac0: 64 69 63 65 73 2c 20 60 6e 75 6d 60 20 69 73 20 dices, `num` is
aad0: 74 72 65 61 74 65 64 20 61 73 20 61 6e 20 75 6e treated as an un
aae0: 73 69 67 6e 65 64 20 76 61 6c 75 65 2e 0a 0a 52 signed value...R
aaf0: 61 64 69 63 65 73 20 62 65 79 6f 6e 64 20 31 30 adices beyond 10
ab00: 20 75 73 65 20 41 53 43 49 49 20 63 68 61 72 61 use ASCII chara
ab10: 63 74 65 72 73 20 69 6e 20 74 68 65 20 72 61 6e cters in the ran
ab20: 67 65 20 e2 80 9c 60 61 60 e2 80 9d 20 75 70 77 ge “`a`” upw
ab30: 61 72 64 20 66 6f 72 0a 64 69 67 69 74 73 2c 20 ard for.digits,
ab40: 67 69 76 69 6e 67 20 61 20 70 72 61 63 74 69 63 giving a practic
ab50: 61 6c 20 6c 69 6d 69 74 20 6f 66 20 62 61 73 65 al limit of base
ab60: 20 33 36 2c 20 74 68 6f 75 67 68 20 74 68 69 73 36, though this
ab70: 20 69 73 20 6e 6f 74 20 63 68 65 63 6b 65 64 0a is not checked.
ab80: 69 6e 20 74 68 65 20 63 6f 64 65 2e 20 20 57 65 in the code. We
ab90: 20 63 68 6f 73 65 20 74 6f 20 75 73 65 20 6c 6f chose to use lo
aba0: 77 65 72 63 61 73 65 20 6c 65 74 74 65 72 73 20 wercase letters
abb0: 62 65 63 61 75 73 65 20 63 6f 6e 76 65 72 73 69 because conversi
abc0: 6f 6e 20 74 6f 0a 75 70 70 65 72 63 61 73 65 20 on to.uppercase
abd0: 69 73 20 65 61 73 69 6c 79 20 64 6f 6e 65 20 77 is easily done w
abe0: 69 74 68 20 74 68 65 20 65 78 69 73 74 69 6e 67 ith the existing
abf0: 20 5b 60 63 75 70 70 65 72 28 29 60 5d 28 23 63 [`cupper()`](#c
ac00: 75 70 70 65 72 29 0a 66 75 6e 63 74 69 6f 6e 2c upper).function,
ac10: 20 77 68 69 63 68 20 77 65 20 6e 65 65 64 20 61 which we need a
ac20: 6e 79 77 61 79 2c 20 77 68 65 72 65 61 73 20 74 nyway, whereas t
ac30: 68 65 20 72 65 76 65 72 73 65 20 63 6f 6e 76 65 he reverse conve
ac40: 72 73 69 6f 6e 20 77 6f 75 6c 64 0a 68 61 76 65 rsion would.have
ac50: 20 72 65 71 75 69 72 65 64 20 65 78 74 72 61 20 required extra
ac60: 63 6f 64 65 20 73 70 61 63 65 2c 20 61 20 70 72 code space, a pr
ac70: 65 63 69 6f 75 73 20 63 6f 6d 6d 6f 64 69 74 79 ecious commodity
ac80: 20 69 6e 20 74 68 65 20 50 44 50 2d 38 2e 0a 0a in the PDP-8...
ac90: 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 64 6f This function do
aca0: 65 73 20 6e 6f 74 20 63 68 65 63 6b 20 66 6f 72 es not check for
acb0: 20 73 75 66 66 69 63 69 65 6e 74 20 62 75 66 66 sufficient buff
acc0: 65 72 20 73 70 61 63 65 20 62 65 66 6f 72 65 0a er space before.
acd0: 62 65 67 69 6e 6e 69 6e 67 20 77 6f 72 6b 2e 20 beginning work.
ace0: 46 6f 72 20 72 61 64 69 78 20 31 30 2c 20 69 66 For radix 10, if
acf0: 20 74 68 65 20 62 6f 75 6e 64 73 20 6f 6e 20 60 the bounds on `
ad00: 6e 75 6d 60 20 61 72 65 20 6e 6f 74 20 6b 6e 6f num` are not kno
ad10: 77 6e 20 69 6e 0a 61 64 76 61 6e 63 65 2c 20 60 wn in.advance, `
ad20: 73 74 72 60 20 73 68 6f 75 6c 64 20 70 6f 69 6e str` should poin
ad30: 74 20 74 6f 20 36 20 77 6f 72 64 73 20 6f 66 20 t to 6 words of
ad40: 6d 65 6d 6f 72 79 20 74 6f 20 63 6f 76 65 72 20 memory to cover
ad50: 74 68 65 20 77 6f 72 73 74 2d 63 61 73 65 0a 63 the worst-case.c
ad60: 6f 6e 64 69 74 69 6f 6e 2c 20 65 2e 67 2e 20 22 ondition, e.g. "
ad70: 2d 31 32 33 34 5c 5c 30 22 2e 20 4c 6f 77 65 72 -1234\\0". Lower
ad80: 20 72 61 64 69 63 65 73 20 67 65 6e 65 72 61 6c radices general
ad90: 6c 79 20 72 65 71 75 69 72 65 20 6d 6f 72 65 0a ly require more.
ada0: 73 74 6f 72 61 67 65 20 73 70 61 63 65 2e 0a 0a storage space...
adb0: 54 68 65 72 65 20 69 73 20 6e 6f 20 74 68 6f 75 There is no thou
adc0: 73 61 6e 64 73 20 73 65 70 61 72 61 74 6f 72 20 sands separator
add0: 69 6e 20 74 68 65 20 6f 75 74 70 75 74 20 73 74 in the output st
ade0: 72 69 6e 67 2e 0a 0a 2a 2a 4e 6f 6e 73 74 61 6e ring...**Nonstan
adf0: 64 61 72 64 2e 2a 2a 20 45 6d 75 6c 61 74 65 73 dard.** Emulates
ae00: 20 74 68 65 20 60 69 74 6f 61 28 29 60 20 66 75 the `itoa()` fu
ae10: 6e 63 74 69 6f 6e 20 61 73 20 64 65 66 69 6e 65 nction as define
ae20: 64 20 69 6e 20 74 68 65 0a 5b 56 69 73 75 61 6c d in the.[Visual
ae30: 20 43 2b 2b 5d 5b 69 74 6f 61 6d 5d 20 61 6e 64 C++][itoam] and
ae40: 20 5b 45 6d 62 61 72 63 61 64 65 72 6f 20 43 2b [Embarcadero C+
ae50: 2b 5d 5b 69 74 6f 61 65 5d 20 72 65 66 65 72 65 +][itoae] refere
ae60: 6e 63 65 20 6d 61 6e 75 61 6c 73 2e 0a 0a 5b 69 nce manuals...[i
ae70: 74 6f 61 65 5d 3a 20 68 74 74 70 3a 2f 2f 64 6f toae]: http://do
ae80: 63 73 2e 65 6d 62 61 72 63 61 64 65 72 6f 2e 63 cs.embarcadero.c
ae90: 6f 6d 2f 70 72 6f 64 75 63 74 73 2f 72 61 64 5f om/products/rad_
aea0: 73 74 75 64 69 6f 2f 72 61 64 73 74 75 64 69 6f studio/radstudio
aeb0: 32 30 30 37 2f 52 53 32 30 30 37 5f 68 65 6c 70 2007/RS2007_help
aec0: 75 70 64 61 74 65 73 2f 48 55 70 64 61 74 65 34 updates/HUpdate4
aed0: 2f 45 4e 2f 68 74 6d 6c 2f 64 65 76 77 69 6e 33 /EN/html/devwin3
aee0: 32 2f 69 74 6f 61 5f 78 6d 6c 2e 68 74 6d 6c 0a 2/itoa_xml.html.
aef0: 5b 69 74 6f 61 6d 5d 3a 20 68 74 74 70 73 3a 2f [itoam]: https:/
af00: 2f 64 6f 63 73 2e 6d 69 63 72 6f 73 6f 66 74 2e /docs.microsoft.
af10: 63 6f 6d 2f 63 70 70 2f 63 2d 72 75 6e 74 69 6d com/cpp/c-runtim
af20: 65 2d 6c 69 62 72 61 72 79 2f 72 65 66 65 72 65 e-library/refere
af30: 6e 63 65 2f 69 74 6f 61 2d 69 74 6f 77 0a 0a 0a nce/itoa-itow...
af40: 23 23 23 20 3c 61 20 69 64 3d 22 6b 62 68 69 74 ### <a id="kbhit
af50: 22 3e 3c 2f 61 3e 60 6b 62 68 69 74 28 29 60 0a "></a>`kbhit()`.
af60: 0a 52 65 74 75 72 6e 73 20 6e 6f 6e 7a 65 72 6f .Returns nonzero
af70: 20 69 66 20 60 54 54 59 3a 60 20 68 61 73 20 73 if `TTY:` has s
af80: 65 6e 74 20 61 6e 20 69 6e 70 75 74 20 63 68 61 ent an input cha
af90: 72 61 63 74 65 72 20 74 68 61 74 20 68 61 73 20 racter that has
afa0: 6e 6f 74 20 79 65 74 0a 62 65 65 6e 20 72 65 61 not yet.been rea
afb0: 64 2c 20 77 68 69 63 68 20 6d 61 79 20 74 68 65 d, which may the
afc0: 6e 20 62 65 20 72 65 61 64 20 62 79 20 61 20 73 n be read by a s
afd0: 75 62 73 65 71 75 65 6e 74 20 63 61 6c 6c 20 74 ubsequent call t
afe0: 6f 0a 5b 60 67 65 74 63 28 29 60 5d 28 28 23 67 o.[`getc()`]((#g
aff0: 65 74 63 29 2e 20 52 65 74 75 72 6e 73 20 30 20 etc). Returns 0
b000: 6f 74 68 65 72 77 69 73 65 2e 0a 0a 54 68 69 73 otherwise...This
b010: 20 66 75 6e 63 74 69 6f 6e e2 80 99 73 20 69 6e function’s in
b020: 74 65 6e 64 65 64 20 70 75 72 70 6f 73 65 20 69 tended purpose i
b030: 73 20 74 6f 20 6c 65 74 20 74 68 65 20 70 72 6f s to let the pro
b040: 67 72 61 6d 20 64 6f 20 77 6f 72 6b 20 77 68 69 gram do work whi
b050: 6c 65 0a 77 61 69 74 69 6e 67 20 66 6f 72 20 6b le.waiting for k
b060: 65 79 62 6f 61 72 64 2c 20 73 69 6e 63 65 20 63 eyboard, since c
b070: 61 6c 6c 69 6e 67 20 60 67 65 74 63 28 29 60 20 alling `getc()`
b080: 62 65 66 6f 72 65 20 69 6e 70 75 74 20 69 73 20 before input is
b090: 61 76 61 69 6c 61 62 6c 65 0a 77 6f 75 6c 64 20 available.would
b0a0: 62 6c 6f 63 6b 20 74 68 65 20 70 72 6f 67 72 61 block the progra
b0b0: 6d 2e 0a 0a 2a 2a 4e 6f 6e 73 74 61 6e 64 61 72 m...**Nonstandar
b0c0: 64 2e 2a 2a 20 45 6d 75 6c 61 74 65 73 20 61 20 d.** Emulates a
b0d0: 66 75 6e 63 74 69 6f 6e 20 63 6f 6d 6d 6f 6e 20 function common
b0e0: 69 6e 20 44 4f 53 20 43 20 6c 69 62 72 61 72 69 in DOS C librari
b0f0: 65 73 20 6f 72 20 74 68 6f 73 65 0a 64 65 73 63 es or those.desc
b100: 65 6e 64 65 64 20 66 72 6f 6d 20 74 68 65 6d 2c ended from them,
b110: 20 73 75 63 68 20 61 73 20 5b 45 6d 62 61 72 63 such as [Embarc
b120: 61 64 65 72 6f 20 43 2b 2b 5d 5b 6b 62 68 69 74 adero C++][kbhit
b130: 65 5d 20 61 6e 64 20 5b 56 69 73 75 61 6c 0a 43 e] and [Visual.C
b140: 2b 2b 5d 5b 6b 62 68 69 74 6d 5d 2e 0a 0a 5b 6b ++][kbhitm]...[k
b150: 62 68 69 74 65 5d 3a 20 68 74 74 70 3a 2f 2f 64 bhite]: http://d
b160: 6f 63 73 2e 65 6d 62 61 72 63 61 64 65 72 6f 2e ocs.embarcadero.
b170: 63 6f 6d 2f 70 72 6f 64 75 63 74 73 2f 72 61 64 com/products/rad
b180: 5f 73 74 75 64 69 6f 2f 72 61 64 73 74 75 64 69 _studio/radstudi
b190: 6f 32 30 30 37 2f 52 53 32 30 30 37 5f 68 65 6c o2007/RS2007_hel
b1a0: 70 75 70 64 61 74 65 73 2f 48 55 70 64 61 74 65 pupdates/HUpdate
b1b0: 34 2f 45 4e 2f 68 74 6d 6c 2f 64 65 76 77 69 6e 4/EN/html/devwin
b1c0: 33 32 2f 6b 62 68 69 74 5f 78 6d 6c 2e 68 74 6d 32/kbhit_xml.htm
b1d0: 6c 0a 5b 6b 62 68 69 74 6d 5d 3a 20 68 74 74 70 l.[kbhitm]: http
b1e0: 73 3a 2f 2f 64 6f 63 73 2e 6d 69 63 72 6f 73 6f s://docs.microso
b1f0: 66 74 2e 63 6f 6d 2f 63 70 70 2f 63 2d 72 75 6e ft.com/cpp/c-run
b200: 74 69 6d 65 2d 6c 69 62 72 61 72 79 2f 72 65 66 time-library/ref
b210: 65 72 65 6e 63 65 2f 6b 62 68 69 74 0a 0a 0a 23 erence/kbhit...#
b220: 23 23 20 3c 61 20 69 64 3d 22 6d 65 6d 63 70 79 ## <a id="memcpy
b230: 22 3e 3c 2f 61 3e 60 6d 65 6d 63 70 79 28 64 73 "></a>`memcpy(ds
b240: 74 2c 20 73 72 63 2c 20 6e 29 60 0a 0a 43 6f 70 t, src, n)`..Cop
b250: 69 65 73 20 60 6e 60 20 77 6f 72 64 73 20 66 72 ies `n` words fr
b260: 6f 6d 20 63 6f 72 65 20 6d 65 6d 6f 72 79 20 6c om core memory l
b270: 6f 63 61 74 69 6f 6e 20 60 73 72 63 60 20 74 6f ocation `src` to
b280: 20 60 64 73 74 60 20 69 6e 20 74 68 65 20 5b 75 `dst` in the [u
b290: 73 65 72 0a 64 61 74 61 20 66 69 65 6c 64 5d 28 ser.data field](
b2a0: 23 6d 65 6d 6f 72 79 29 2e 0a 0a 42 65 77 61 72 #memory)...Bewar
b2b0: 65 20 74 68 61 74 20 74 68 65 20 63 6f 70 79 20 e that the copy
b2c0: 77 69 6c 6c 20 5b 77 72 61 70 20 61 72 6f 75 6e will [wrap aroun
b2d0: 64 5d 28 23 70 74 72 77 72 61 70 29 20 74 6f 20 d](#ptrwrap) to
b2e0: 74 68 65 20 62 65 67 69 6e 6e 69 6e 67 20 6f 66 the beginning of
b2f0: 0a 74 68 65 20 66 69 65 6c 64 20 69 66 20 65 69 .the field if ei
b300: 74 68 65 72 20 60 73 72 63 2b 6e 60 20 6f 72 20 ther `src+n` or
b310: 60 64 73 74 2b 6e 60 20 26 67 65 3b 20 34 30 39 `dst+n` ≥ 409
b320: 36 2e 0a 0a 54 68 65 20 60 64 73 74 60 20 62 75 6...The `dst` bu
b330: 66 66 65 72 20 63 61 6e 20 73 61 66 65 6c 79 20 ffer can safely
b340: 6f 76 65 72 6c 61 70 20 74 68 65 20 60 73 72 63 overlap the `src
b350: 60 20 62 75 66 66 65 72 20 6f 6e 6c 79 20 69 66 ` buffer only if
b360: 20 69 74 20 69 73 20 61 74 20 61 0a 6c 6f 77 65 it is at a.lowe
b370: 72 20 61 64 64 72 65 73 73 20 69 6e 20 6d 65 6d r address in mem
b380: 6f 72 79 2e 20 28 4e 6f 74 65 20 74 68 61 74 20 ory. (Note that
b390: 74 68 65 72 65 20 69 73 20 6e 6f 20 60 6d 65 6d there is no `mem
b3a0: 6d 6f 76 65 28 29 60 20 69 6e 20 74 68 69 73 0a move()` in this.
b3b0: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 29 implementation.)
b3c0: 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 69 6f ..**Standard Vio
b3d0: 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 lations:**..*
b3e0: 52 65 74 75 72 6e 73 20 30 20 69 6e 73 74 65 61 Returns 0 instea
b3f0: 64 20 6f 66 20 74 68 65 20 60 64 73 74 60 20 70 d of the `dst` p
b400: 6f 69 6e 74 65 72 20 61 73 20 72 65 71 75 69 72 ointer as requir
b410: 65 64 20 62 79 20 74 68 65 20 53 74 61 6e 64 61 ed by the Standa
b420: 72 64 2e 0a 20 20 20 20 41 20 4e 55 4c 4c 20 72 rd.. A NULL r
b430: 65 74 75 72 6e 20 69 73 20 73 70 65 63 69 66 69 eturn is specifi
b440: 65 64 20 61 73 20 61 20 66 61 69 6c 75 72 65 20 ed as a failure
b450: 63 6f 6e 64 69 74 69 6f 6e 20 62 79 20 74 68 65 condition by the
b460: 20 53 74 61 6e 64 61 72 64 2e 0a 0a 20 20 20 20 Standard...
b470: 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 68 61 This function ha
b480: 73 20 6e 6f 20 69 6e 74 65 72 6e 61 6c 6c 79 2d s no internally-
b490: 64 65 74 65 63 74 65 64 20 66 61 69 6c 75 72 65 detected failure
b4a0: 20 63 61 73 65 73 2c 20 73 6f 20 74 68 65 72 65 cases, so there
b4b0: 20 69 73 0a 20 20 20 20 6e 6f 20 61 6d 62 69 67 is. no ambig
b4c0: 75 69 74 79 20 69 6e 20 74 68 65 20 6d 65 61 6e uity in the mean
b4d0: 69 6e 67 20 6f 66 20 74 68 65 20 72 65 74 75 72 ing of the retur
b4e0: 6e 20 76 61 6c 75 65 2e 0a 0a 0a 23 23 23 20 3c n value....### <
b4f0: 61 20 69 64 3d 22 6d 65 6d 73 65 74 22 3e 3c 2f a id="memset"></
b500: 61 3e 60 6d 65 6d 73 65 74 28 64 73 74 2c 20 63 a>`memset(dst, c
b510: 2c 20 6c 65 6e 29 60 0a 0a 53 65 74 73 20 61 20 , len)`..Sets a
b520: 72 75 6e 20 6f 66 20 60 6c 65 6e 60 20 63 6f 72 run of `len` cor
b530: 65 20 6d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f e memory locatio
b540: 6e 73 20 73 74 61 72 74 69 6e 67 20 61 74 20 60 ns starting at `
b550: 64 73 74 60 20 74 6f 20 60 63 60 2e 0a 0a 42 65 dst` to `c`...Be
b560: 77 61 72 65 20 74 68 61 74 20 74 68 69 73 20 66 ware that this f
b570: 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 5b 77 72 unction will [wr
b580: 61 70 20 61 72 6f 75 6e 64 5d 28 23 70 74 72 77 ap around](#ptrw
b590: 72 61 70 29 20 69 66 20 60 64 73 74 2b 6c 65 6e rap) if `dst+len
b5a0: 2d 31 60 0a 26 67 65 3b 20 34 30 39 36 2e 0a 0a -1`.≥ 4096...
b5b0: 2a 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 **Standard Viola
b5c0: 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 52 65 tions:**..* Re
b5d0: 74 75 72 6e 73 20 30 20 69 6e 73 74 65 61 64 20 turns 0 instead
b5e0: 6f 66 20 74 68 65 20 60 64 73 74 60 20 70 6f 69 of the `dst` poi
b5f0: 6e 74 65 72 20 61 73 20 72 65 71 75 69 72 65 64 nter as required
b600: 20 62 79 20 74 68 65 20 53 74 61 6e 64 61 72 64 by the Standard
b610: 2e 0a 0a 2a 20 20 20 54 68 69 73 20 66 75 6e 63 ...* This func
b620: 74 69 6f 6e 20 68 61 73 20 6e 6f 20 69 6e 74 65 tion has no inte
b630: 72 6e 61 6c 6c 79 2d 64 65 74 65 63 74 65 64 20 rnally-detected
b640: 66 61 69 6c 75 72 65 20 63 61 73 65 73 2c 20 73 failure cases, s
b650: 6f 20 74 68 65 0a 20 20 20 20 53 74 61 6e 64 61 o the. Standa
b660: 72 64 e2 80 99 73 20 72 65 71 75 69 72 65 6d 65 rd’s requireme
b670: 6e 74 20 74 68 61 74 20 74 68 69 73 20 66 75 6e nt that this fun
b680: 63 74 69 6f 6e 20 72 65 74 75 72 6e 20 30 20 69 ction return 0 i
b690: 6e 20 65 72 72 6f 72 20 63 61 73 65 73 0a 20 20 n error cases.
b6a0: 20 20 6d 65 61 6e 73 20 74 68 65 72 65 20 69 73 means there is
b6b0: 20 6e 6f 20 61 6d 62 69 67 75 69 74 79 20 69 6e no ambiguity in
b6c0: 20 74 68 65 20 6d 65 61 6e 69 6e 67 20 6f 66 20 the meaning of
b6d0: 74 68 65 20 72 65 74 75 72 6e 20 76 61 6c 75 65 the return value
b6e0: 2e 0a 0a 20 20 20 20 49 66 20 77 65 20 65 76 65 ... If we eve
b6f0: 72 20 66 69 78 20 74 68 65 20 70 72 69 6f 72 20 r fix the prior
b700: 76 69 6f 6c 61 74 69 6f 6e 2c 20 74 68 65 72 65 violation, there
b710: 20 77 69 6c 6c 20 73 74 69 6c 6c 20 62 65 20 6e will still be n
b720: 6f 20 61 6d 62 69 67 75 69 74 79 0a 20 20 20 20 o ambiguity.
b730: 77 69 74 68 20 74 68 65 20 65 72 72 6f 72 20 63 with the error c
b740: 61 73 65 20 73 69 6e 63 65 20 5b 61 20 76 61 6c ase since [a val
b750: 69 64 20 70 6f 69 6e 74 65 72 20 69 6e 20 43 43 id pointer in CC
b760: 38 20 63 61 6e 6e 6f 74 20 62 65 0a 20 20 20 20 8 cannot be.
b770: 7a 65 72 6f 5d 28 23 6d 65 6d 6f 72 79 29 2e 0a zero](#memory)..
b780: 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 70 72 69 ..### <a id="pri
b790: 6e 74 66 22 3e 3c 2f 61 3e 60 70 72 69 6e 74 66 ntf"></a>`printf
b7a0: 28 66 6d 74 2c 20 61 72 67 73 2e 2e 2e 29 60 0a (fmt, args...)`.
b7b0: 0a 57 72 69 74 65 73 20 69 74 73 20 61 72 67 75 .Writes its argu
b7c0: 6d 65 6e 74 73 20 28 60 61 72 67 73 60 29 20 66 ments (`args`) f
b7d0: 6f 72 6d 61 74 74 65 64 20 61 63 63 6f 72 64 69 ormatted accordi
b7e0: 6e 67 20 74 6f 20 66 6f 72 6d 61 74 20 73 74 72 ng to format str
b7f0: 69 6e 67 20 60 66 6d 74 60 0a 74 6f 20 60 54 54 ing `fmt`.to `TT
b800: 59 3a 60 2e 0a 0a 54 68 69 73 20 66 75 6e 63 74 Y:`...This funct
b810: 69 6f 6e 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 ion is implement
b820: 65 64 20 69 6e 20 74 65 72 6d 73 20 6f 66 20 5b ed in terms of [
b830: 60 73 70 72 69 6e 74 66 28 29 60 5d 28 23 73 70 `sprintf()`](#sp
b840: 72 69 6e 74 66 29 2c 20 73 6f 20 73 65 65 0a 69 rintf), so see.i
b850: 74 73 20 64 6f 63 75 6d 65 6e 74 61 74 69 6f 6e ts documentation
b860: 20 66 6f 72 20 64 65 74 61 69 6c 73 20 6f 6e 20 for details on
b870: 73 74 72 69 6e 67 20 66 6f 72 6d 61 74 74 69 6e string formattin
b880: 67 2e 0a 0a 54 68 69 73 20 66 75 6e 63 74 69 6f g...This functio
b890: 6e 20 63 61 6c 6c 73 20 5b 60 70 75 74 73 28 29 n calls [`puts()
b8a0: 60 5d 28 23 70 75 74 73 29 20 61 66 74 65 72 20 `](#puts) after
b8b0: 66 6f 72 6d 61 74 74 69 6e 67 20 74 68 65 20 6f formatting the o
b8c0: 75 74 70 75 74 0a 73 74 72 69 6e 67 2c 20 73 6f utput.string, so
b8d0: 20 73 65 65 20 69 74 73 20 64 6f 63 75 6d 65 6e see its documen
b8e0: 74 61 74 69 6f 6e 20 66 6f 72 20 69 6e 66 6f 72 tation for infor
b8f0: 6d 61 74 69 6f 6e 20 6f 6e 20 68 6f 77 20 4c 49 mation on how LI
b900: 42 43 20 77 72 69 74 65 73 20 72 61 77 0a 63 68 BC writes raw.ch
b910: 61 72 61 63 74 65 72 20 73 74 72 69 6e 67 73 2e aracter strings.
b920: 0a 0a 2a 2a 57 41 52 4e 49 4e 47 3a 2a 2a 20 42 ..**WARNING:** B
b930: 65 63 61 75 73 65 20 60 70 72 69 6e 74 66 28 29 ecause `printf()
b940: 60 20 69 73 20 69 6d 70 6c 65 6d 65 6e 74 65 64 ` is implemented
b950: 20 69 6e 20 74 65 72 6d 73 20 6f 66 20 60 73 70 in terms of `sp
b960: 72 69 6e 74 66 28 29 60 0a 61 6e 64 20 69 74 20 rintf()`.and it
b970: 70 6f 69 6e 74 73 20 61 74 20 5b 61 20 73 74 61 points at [a sta
b980: 74 69 63 20 62 75 66 66 65 72 20 69 6e 20 74 68 tic buffer in th
b990: 65 20 75 73 65 72 20 64 61 74 61 20 66 69 65 6c e user data fiel
b9a0: 64 5d 28 23 6d 65 6d 6f 72 79 29 2c 20 79 6f 75 d](#memory), you
b9b0: 0a 63 61 6e 20 6f 6e 6c 79 20 73 61 66 65 6c 79 .can only safely
b9c0: 20 70 72 69 6e 74 20 75 70 20 74 6f 20 2a 31 31 print up to *11
b9d0: 32 2a 20 63 68 61 72 61 63 74 65 72 73 20 61 74 2* characters at
b9e0: 20 61 20 74 69 6d 65 20 77 69 74 68 20 60 70 72 a time with `pr
b9f0: 69 6e 74 66 28 29 60 2e 0a 50 72 69 6e 74 69 6e intf()`..Printin
ba00: 67 20 6d 6f 72 65 20 77 69 6c 6c 20 63 6f 72 72 g more will corr
ba10: 75 70 74 20 70 72 6f 67 72 61 6d 20 64 61 74 61 upt program data
ba20: 20 61 6e 64 20 6d 6f 73 74 20 6c 69 6b 65 6c 79 and most likely
ba30: 20 63 72 61 73 68 20 74 68 65 0a 70 72 6f 67 72 crash the.progr
ba40: 61 6d 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d am....### <a id=
ba50: 22 70 75 74 63 22 20 6e 61 6d 65 3d 22 66 70 75 "putc" name="fpu
ba60: 74 63 22 3e 3c 2f 61 3e 60 70 75 74 63 28 63 29 tc"></a>`putc(c)
ba70: 60 2c 20 60 66 70 75 74 63 28 63 29 60 0a 0a 57 `, `fputc(c)`..W
ba80: 72 69 74 65 73 20 61 20 63 68 61 72 61 63 74 65 rites a characte
ba90: 72 20 60 63 60 20 65 69 74 68 65 72 20 74 6f 20 r `c` either to
baa0: 60 54 54 59 3a 60 20 6f 72 20 74 6f 20 74 68 65 `TTY:` or to the
bab0: 20 63 75 72 72 65 6e 74 6c 79 2d 6f 70 65 6e 65 currently-opene
bac0: 64 0a 6f 75 74 70 75 74 20 66 69 6c 65 2e 0a 0a d.output file...
bad0: 54 68 65 20 63 68 61 72 61 63 74 65 72 73 20 70 The characters p
bae0: 6f 69 6e 74 65 64 20 74 6f 20 61 72 65 20 65 78 ointed to are ex
baf0: 70 65 63 74 65 64 20 74 6f 20 62 65 20 37 2d 62 pected to be 7-b
bb00: 69 74 20 41 53 43 49 49 20 62 79 74 65 73 20 73 it ASCII bytes s
bb10: 74 6f 72 65 64 0a 77 69 74 68 69 6e 20 65 61 63 tored.within eac
bb20: 68 20 50 44 50 2d 38 20 77 6f 72 64 2c 20 77 69 h PDP-8 word, wi
bb30: 74 68 20 74 68 65 20 74 6f 70 20 35 20 62 69 74 th the top 5 bit
bb40: 73 20 75 6e 73 65 74 2c 20 62 75 74 20 6e 6f 20 s unset, but no
bb50: 61 74 74 65 6d 70 74 20 69 73 0a 63 75 72 72 65 attempt is.curre
bb60: 6e 74 6c 79 20 6d 61 64 65 20 74 6f 20 65 6e 66 ntly made to enf
bb70: 6f 72 63 65 20 74 68 69 73 2e 0a 0a 42 6f 74 68 orce this...Both
bb80: 20 66 75 6e 63 74 69 6f 6e 73 20 72 65 74 75 72 functions retur
bb90: 6e 20 74 68 65 20 77 72 69 74 74 65 6e 20 63 68 n the written ch
bba0: 61 72 61 63 74 65 72 2e 0a 0a 2a 2a 53 74 61 6e aracter...**Stan
bbb0: 64 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a dard Violations:
bbc0: 2a 2a 0a 0a 2a 20 20 20 4e 65 69 74 68 65 72 20 **..* Neither
bbd0: 66 75 6e 63 74 69 6f 6e 20 63 61 6e 20 66 61 69 function can fai
bbe0: 6c 20 77 69 74 68 6f 75 74 20 6c 6f 63 6b 69 6e l without lockin
bbf0: 67 20 75 70 20 74 68 65 20 63 6f 6d 70 75 74 65 g up the compute
bc00: 72 20 6f 72 0a 20 20 20 20 63 72 61 73 68 69 6e r or. crashin
bc10: 67 20 74 68 65 20 70 72 6f 67 72 61 6d 2c 20 73 g the program, s
bc20: 6f 20 61 6e 20 45 4f 46 20 72 65 74 75 72 6e 20 o an EOF return
bc30: 63 61 6e 20 6e 65 76 65 72 20 68 61 70 70 65 6e can never happen
bc40: 2e 0a 0a 2a 20 20 20 4e 65 69 74 68 65 72 20 66 ...* Neither f
bc50: 75 6e 63 74 69 6f 6e 20 74 61 6b 65 20 61 20 60 unction take a `
bc60: 46 49 4c 45 2a 60 20 61 73 20 74 68 65 69 72 20 FILE*` as their
bc70: 73 65 63 6f 6e 64 20 70 61 72 61 6d 65 74 65 72 second parameter
bc80: 2e 20 60 70 75 74 63 28 29 60 0a 20 20 20 20 61 . `putc()`. a
bc90: 6c 77 61 79 73 20 77 72 69 74 65 73 20 74 6f 20 lways writes to
bca0: 60 54 54 59 3a 60 2c 20 61 6e 64 20 60 66 70 75 `TTY:`, and `fpu
bcb0: 74 63 28 29 60 20 61 6c 77 61 79 73 20 77 72 69 tc()` always wri
bcc0: 74 65 73 20 74 6f 20 74 68 65 0a 20 20 20 20 63 tes to the. c
bcd0: 75 72 72 65 6e 74 6c 79 2d 6f 70 65 6e 65 64 20 urrently-opened
bce0: 6f 75 74 70 75 74 20 66 69 6c 65 2e 0a 0a 0a 23 output file....#
bcf0: 23 23 20 3c 61 20 69 64 3d 22 70 75 74 73 22 20 ## <a id="puts"
bd00: 6e 61 6d 65 3d 22 66 70 75 74 73 22 3e 3c 2f 61 name="fputs"></a
bd10: 3e 60 70 75 74 73 28 73 29 60 2c 20 60 66 70 75 >`puts(s)`, `fpu
bd20: 74 73 28 73 29 60 0a 0a 57 72 69 74 65 73 20 61 ts(s)`..Writes a
bd30: 20 6e 75 6c 6c 2d 74 65 72 6d 69 6e 61 74 65 64 null-terminated
bd40: 20 63 68 61 72 61 63 74 65 72 20 73 74 72 69 6e character strin
bd50: 67 20 60 73 60 20 65 69 74 68 65 72 20 74 6f 20 g `s` either to
bd60: 60 54 54 59 3a 60 20 6f 72 20 74 6f 20 74 68 65 `TTY:` or to the
bd70: 0a 63 75 72 72 65 6e 74 6c 79 2d 6f 70 65 6e 65 .currently-opene
bd80: 64 20 6f 75 74 70 75 74 20 66 69 6c 65 2e 0a 0a d output file...
bd90: 54 68 65 20 63 68 61 72 61 63 74 65 72 73 20 70 The characters p
bda0: 6f 69 6e 74 65 64 20 74 6f 20 61 72 65 20 65 78 ointed to are ex
bdb0: 70 65 63 74 65 64 20 74 6f 20 62 65 20 37 2d 62 pected to be 7-b
bdc0: 69 74 20 41 53 43 49 49 20 62 79 74 65 73 20 73 it ASCII bytes s
bdd0: 74 6f 72 65 64 0a 77 69 74 68 69 6e 20 65 61 63 tored.within eac
bde0: 68 20 50 44 50 2d 38 20 77 6f 72 64 2c 20 77 69 h PDP-8 word, wi
bdf0: 74 68 20 74 68 65 20 74 6f 70 20 35 20 62 69 74 th the top 5 bit
be00: 73 20 75 6e 73 65 74 2e 0a 0a 2a 2a 53 74 61 6e s unset...**Stan
be10: 64 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a dard Violations:
be20: 2a 2a 0a 0a 2a 20 20 20 54 68 65 20 60 70 75 74 **..* The `put
be30: 73 28 29 60 20 69 6d 70 6c 65 6d 65 6e 74 61 74 s()` implementat
be40: 69 6f 6e 20 64 6f 65 73 20 6e 6f 74 20 77 72 69 ion does not wri
be50: 74 65 20 61 20 6e 65 77 6c 69 6e 65 20 61 66 74 te a newline aft
be60: 65 72 20 74 68 65 0a 20 20 20 20 70 61 73 73 65 er the. passe
be70: 64 20 73 74 72 69 6e 67 2e 0a 0a 20 20 20 20 28 d string... (
be80: 4e 65 69 74 68 65 72 20 64 6f 65 73 20 6f 75 72 Neither does our
be90: 20 60 66 70 75 74 73 28 29 60 2c 20 62 75 74 20 `fputs()`, but
bea0: 74 68 61 74 e2 80 99 73 20 61 63 74 75 61 6c 6c that’s actuall
beb0: 79 20 53 74 61 6e 64 61 72 64 20 62 65 68 61 76 y Standard behav
bec0: 69 6f 72 2e 29 0a 0a 2a 20 20 20 42 6f 74 68 20 ior.)..* Both
bed0: 60 70 75 74 73 28 29 60 20 61 6e 64 20 60 66 70 `puts()` and `fp
bee0: 75 74 73 28 29 60 20 61 72 65 20 73 75 70 70 6f uts()` are suppo
bef0: 73 65 64 20 74 6f 20 72 65 74 75 72 6e 20 6e 6f sed to return no
bf00: 6e 7a 65 72 6f 20 6f 6e 0a 20 20 20 20 73 75 63 nzero on. suc
bf10: 63 65 73 73 2c 20 62 75 74 20 74 68 69 73 20 69 cess, but this i
bf20: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 72 65 mplementation re
bf30: 74 75 72 6e 73 20 30 2e 0a 20 20 20 20 0a 20 20 turns 0.. .
bf40: 20 20 54 65 63 68 6e 69 63 61 6c 6c 79 2c 20 74 Technically, t
bf50: 68 65 73 65 20 66 75 6e 63 74 69 6f 6e 73 20 61 hese functions a
bf60: 72 65 6e e2 80 99 74 20 65 78 70 6c 69 63 69 74 ren’t explicit
bf70: 6c 79 20 e2 80 9c 72 65 74 75 72 6e 69 6e 67 e2 ly “returning
bf80: 80 9d 20 61 6e 79 74 68 69 6e 67 2c 0a 20 20 20 anything,.
bf90: 20 74 68 65 79 e2 80 99 72 65 20 6a 75 73 74 20 they’re just
bfa0: 6c 65 61 76 69 6e 67 20 30 20 69 6e 20 41 43 2c leaving 0 in AC,
bfb0: 20 74 68 61 74 20 62 65 69 6e 67 20 74 68 65 20 that being the
bfc0: 41 53 43 49 49 20 4e 55 4c 20 63 68 61 72 61 63 ASCII NUL charac
bfd0: 74 65 72 0a 20 20 20 20 74 68 61 74 20 74 65 72 ter. that ter
bfe0: 6d 69 6e 61 74 65 64 20 74 68 65 20 6c 6f 6f 70 minated the loop
bff0: 20 69 6e 73 69 64 65 20 65 61 63 68 20 66 75 6e inside each fun
c000: 63 74 69 6f 6e e2 80 99 73 20 69 6d 70 6c 65 6d ction’s implem
c010: 65 6e 74 61 74 69 6f 6e 2e 0a 0a 2a 20 20 20 60 entation...* `
c020: 66 70 75 74 73 28 29 60 20 64 65 74 65 63 74 73 fputs()` detects
c030: 20 6e 6f 20 49 2f 4f 20 65 72 72 6f 72 20 63 6f no I/O error co
c040: 6e 64 69 74 69 6f 6e 73 2c 20 61 6e 64 20 74 68 nditions, and th
c050: 75 73 20 63 61 6e 6e 6f 74 20 72 65 74 75 72 6e us cannot return
c060: 0a 20 20 20 20 45 4f 46 20 74 6f 20 73 69 67 6e . EOF to sign
c070: 61 6c 20 61 6e 20 65 72 72 6f 72 2e 20 49 74 20 al an error. It
c080: 61 6c 77 61 79 73 20 72 65 74 75 72 6e 73 20 30 always returns 0
c090: 2c 20 77 68 65 74 68 65 72 20 61 6e 20 65 72 72 , whether an err
c0a0: 6f 72 0a 20 20 20 20 6f 63 63 75 72 72 65 64 20 or. occurred
c0b0: 6f 72 20 6e 6f 74 2e 0a 0a 2a 20 20 20 60 66 70 or not...* `fp
c0c0: 75 74 73 28 29 60 20 64 6f 65 73 20 6e 6f 74 20 uts()` does not
c0d0: 74 61 6b 65 20 61 20 60 46 49 4c 45 2a 60 20 61 take a `FILE*` a
c0e0: 73 20 69 74 73 20 66 69 72 73 74 20 70 61 72 61 s its first para
c0f0: 6d 65 74 65 72 20 64 75 65 20 74 6f 20 74 68 65 meter due to the
c100: 0a 20 20 20 20 5b 69 6d 70 6c 69 63 69 74 20 73 . [implicit s
c110: 69 6e 67 6c 65 20 6f 75 74 70 75 74 20 66 69 6c ingle output fil
c120: 65 5d 28 23 66 69 6f 6c 69 6d 29 2e 0a 0a 0a 23 e](#fiolim)....#
c130: 23 23 20 3c 61 20 69 64 3d 22 72 65 76 63 70 79 ## <a id="revcpy
c140: 22 3e 3c 2f 61 3e 60 72 65 76 63 70 79 28 64 73 "></a>`revcpy(ds
c150: 74 2c 20 73 72 63 2c 20 6e 29 60 0a 0a 46 6f 72 t, src, n)`..For
c160: 20 6e 6f 6e 2d 6f 76 65 72 6c 61 70 70 69 6e 67 non-overlapping
c170: 20 62 75 66 66 65 72 73 2c 20 68 61 73 20 74 68 buffers, has th
c180: 65 20 73 61 6d 65 20 65 66 66 65 63 74 20 61 73 e same effect as
c190: 0a 5b 60 6d 65 6d 63 70 79 28 29 60 5d 28 23 6d .[`memcpy()`](#m
c1a0: 65 6d 63 70 79 29 2c 20 75 73 69 6e 67 20 6c 65 emcpy), using le
c1b0: 73 73 20 65 66 66 69 63 69 65 6e 74 20 63 6f 64 ss efficient cod
c1c0: 65 2e 0a 0a 42 65 63 61 75 73 65 20 69 74 20 63 e...Because it c
c1d0: 6f 70 69 65 73 20 77 6f 72 64 73 20 69 6e 20 74 opies words in t
c1e0: 68 65 20 6f 70 70 6f 73 69 74 65 20 6f 72 64 65 he opposite orde
c1f0: 72 20 66 72 6f 6d 20 60 6d 65 6d 63 70 79 28 29 r from `memcpy()
c200: 60 2c 20 79 6f 75 20 6d 61 79 0a 62 65 20 77 69 `, you may.be wi
c210: 6c 6c 69 6e 67 20 74 6f 20 70 61 79 20 69 74 73 lling to pay its
c220: 20 65 66 66 69 63 69 65 6e 63 79 20 68 69 74 20 efficiency hit
c230: 77 68 65 6e 20 63 6f 70 79 69 6e 67 20 62 65 74 when copying bet
c240: 77 65 65 6e 20 6f 76 65 72 6c 61 70 70 69 6e 67 ween overlapping
c250: 0a 62 75 66 66 65 72 73 20 77 68 65 6e 20 74 68 .buffers when th
c260: 65 20 64 65 73 74 69 6e 61 74 69 6f 6e 20 66 6f e destination fo
c270: 6c 6c 6f 77 73 20 74 68 65 20 73 6f 75 72 63 65 llows the source
c280: 2e 0a 0a 2a 2a 4e 6f 6e 73 74 61 6e 64 61 72 64 ...**Nonstandard
c290: 2e 2a 2a 20 43 6f 6e 66 6f 72 6d 73 20 74 6f 20 .** Conforms to
c2a0: 6e 6f 20 6b 6e 6f 77 6e 20 43 20 6c 69 62 72 61 no known C libra
c2b0: 72 79 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f ry implementatio
c2c0: 6e 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 n....### <a id="
c2d0: 73 70 72 69 6e 74 66 22 3e 3c 2f 61 3e 60 73 70 sprintf"></a>`sp
c2e0: 72 69 6e 74 66 28 6f 75 74 73 74 72 2c 20 66 6d rintf(outstr, fm
c2f0: 74 2c 20 61 72 67 73 2e 2e 2e 29 60 0a 0a 46 6f t, args...)`..Fo
c300: 72 6d 61 74 73 20 69 74 73 20 61 72 67 75 6d 65 rmats its argume
c310: 6e 74 73 20 28 60 61 72 67 73 60 29 20 66 6f 72 nts (`args`) for
c320: 20 6f 75 74 70 75 74 20 74 6f 20 60 6f 75 74 73 output to `outs
c330: 74 72 60 20 62 61 73 65 64 20 6f 6e 20 66 6f 72 tr` based on for
c340: 6d 61 74 0a 73 74 72 69 6e 67 20 60 66 6d 74 60 mat.string `fmt`
c350: 2e 0a 0a 54 68 65 20 61 6c 6c 6f 77 65 64 20 73 ...The allowed s
c360: 74 61 6e 64 61 72 64 20 63 6f 6e 76 65 72 73 69 tandard conversi
c370: 6f 6e 20 73 70 65 63 69 66 69 65 72 73 20 61 72 on specifiers ar
c380: 65 20 60 25 60 2c 20 60 63 60 2c 20 60 64 60 2c e `%`, `c`, `d`,
c390: 20 60 6f 60 2c 20 60 73 60 2c 0a 60 75 60 2c 20 `o`, `s`,.`u`,
c3a0: 60 78 60 2c 20 61 6e 64 20 60 58 60 2e 20 20 53 `x`, and `X`. S
c3b0: 65 65 20 79 6f 75 72 20 66 61 76 6f 72 69 74 65 ee your favorite
c3c0: 20 43 20 6d 61 6e 75 61 6c 20 66 6f 72 20 74 68 C manual for th
c3d0: 65 69 72 20 6d 65 61 6e 69 6e 67 2e 0a 0a 54 68 eir meaning...Th
c3e0: 65 20 43 43 38 20 4c 49 42 43 20 64 6f 65 73 20 e CC8 LIBC does
c3f0: 73 75 70 70 6f 72 74 20 6f 6e 65 20 6e 6f 6e 73 support one nons
c400: 74 61 6e 64 61 72 64 20 63 6f 6e 76 65 72 73 69 tandard conversi
c410: 6f 6e 20 73 70 65 63 69 66 69 65 72 2c 20 60 62 on specifier, `b
c420: 60 2c 0a 6d 65 61 6e 69 6e 67 20 62 69 6e 61 72 `,.meaning binar
c430: 79 20 6f 75 74 70 75 74 2e 20 54 68 69 6e 6b 20 y output. Think
c440: 6f 66 20 69 74 20 6c 69 6b 65 20 60 78 60 2c 20 of it like `x`,
c450: 62 75 74 20 69 6e 20 62 61 73 65 20 32 2e 0a 0a but in base 2...
c460: 54 68 65 20 60 62 60 2c 20 60 64 60 2c 20 60 6f The `b`, `d`, `o
c470: 60 2c 20 60 75 60 2c 20 60 78 60 2c 20 61 6e 64 `, `u`, `x`, and
c480: 20 60 58 60 20 73 70 65 63 69 66 69 65 72 73 20 `X` specifiers
c490: 61 72 65 20 69 6d 70 6c 65 6d 65 6e 74 65 64 20 are implemented
c4a0: 69 6e 20 74 65 72 6d 73 0a 6f 66 20 5b 60 69 74 in terms.of [`it
c4b0: 6f 61 28 29 60 5d 28 23 69 74 6f 61 29 2e 20 4f oa()`](#itoa). O
c4c0: 75 72 20 60 25 58 60 20 74 68 65 72 65 66 6f 72 ur `%X` therefor
c4d0: 65 20 69 6e 76 6f 6c 76 65 73 20 61 20 63 61 6c e involves a cal
c4e0: 6c 20 74 6f 0a 5b 60 63 75 70 70 65 72 28 29 60 l to.[`cupper()`
c4f0: 5d 28 23 63 75 70 70 65 72 29 20 61 66 74 65 72 ](#cupper) after
c500: 20 60 69 74 6f 61 28 29 60 2c 20 6d 61 6b 69 6e `itoa()`, makin
c510: 67 20 60 25 78 60 20 74 68 65 20 6d 6f 72 65 20 g `%x` the more
c520: 65 66 66 69 63 69 65 6e 74 0a 6f 70 74 69 6f 6e efficient.option
c530: 2e 0a 0a 4c 65 66 74 20 61 6e 64 20 72 69 67 68 ...Left and righ
c540: 74 2d 6a 75 73 74 69 66 69 65 64 20 70 61 64 64 t-justified padd
c550: 69 6e 67 20 69 73 20 73 75 70 70 6f 72 74 65 64 ing is supported
c560: 2e 20 53 70 61 63 65 20 61 6e 64 20 7a 65 72 6f . Space and zero
c570: 2d 70 61 64 64 69 6e 67 0a 69 73 20 73 75 70 70 -padding.is supp
c580: 6f 72 74 65 64 2e 0a 0a 57 69 64 74 68 20 70 72 orted...Width pr
c590: 65 66 69 78 65 73 20 61 72 65 20 6f 62 65 79 65 efixes are obeye
c5a0: 64 2e 0a 0a 50 72 65 63 69 73 69 6f 6e 20 73 70 d...Precision sp
c5b0: 65 63 69 66 69 65 72 73 20 61 72 65 20 70 61 72 ecifiers are par
c5c0: 73 65 64 20 62 75 74 20 68 61 76 65 20 6e 6f 20 sed but have no
c5d0: 65 66 66 65 63 74 20 6f 6e 20 74 68 65 20 6f 75 effect on the ou
c5e0: 74 70 75 74 2e 0a 2a 2a 54 4f 44 4f 2a 2a 3a 20 tput..**TODO**:
c5f0: 43 6c 61 69 6d 20 62 61 73 65 64 20 6f 6e 20 63 Claim based on c
c600: 6f 64 65 20 69 6e 73 70 65 63 74 69 6f 6e 3b 20 ode inspection;
c610: 76 65 72 69 66 79 20 77 69 74 68 20 74 65 73 74 verify with test
c620: 73 2e 0a 0a 4f 6e 20 73 75 63 63 65 73 73 2c 20 s...On success,
c630: 69 74 20 72 65 74 75 72 6e 73 20 74 68 65 20 6e it returns the n
c640: 75 6d 62 65 72 20 6f 66 20 63 68 61 72 61 63 74 umber of charact
c650: 65 72 73 20 77 72 69 74 74 65 6e 20 74 6f 20 74 ers written to t
c660: 68 65 20 6f 75 74 70 75 74 0a 73 74 72 65 61 6d he output.stream
c670: 2c 20 6e 6f 74 20 69 6e 63 6c 75 64 69 6e 67 20 , not including
c680: 74 68 65 20 74 72 61 69 6c 69 6e 67 20 4e 55 4c the trailing NUL
c690: 20 63 68 61 72 61 63 74 65 72 2e 20 49 66 20 69 character. If i
c6a0: 74 20 65 6e 63 6f 75 6e 74 65 72 73 20 61 6e 0a t encounters an.
c6b0: 75 6e 6b 6e 6f 77 6e 20 66 6f 72 6d 61 74 20 73 unknown format s
c6c0: 70 65 63 69 66 69 65 72 2c 20 69 74 20 74 65 72 pecifier, it ter
c6d0: 6d 69 6e 61 74 65 73 20 74 68 65 20 6f 75 74 70 minates the outp
c6e0: 75 74 20 73 74 72 69 6e 67 20 77 69 74 68 20 61 ut string with a
c6f0: 20 4e 55 4c 20 61 6e 64 0a 72 65 74 75 72 6e 73 NUL and.returns
c700: 20 2d 31 2e 0a 0a 2a 2a 57 41 52 4e 49 4e 47 3a -1...**WARNING:
c710: 2a 2a 20 54 68 69 73 20 66 75 6e 63 74 69 6f 6e ** This function
c720: 20 64 6f 65 73 20 6e 6f 74 20 63 68 65 63 6b 20 does not check
c730: 69 74 73 20 62 75 66 66 65 72 20 70 6f 69 6e 74 its buffer point
c740: 65 72 20 66 6f 72 0a 65 6e 64 2d 6f 66 2d 66 69 er for.end-of-fi
c750: 65 6c 64 2c 20 73 6f 20 69 66 20 79 6f 75 20 63 eld, so if you c
c760: 61 75 73 65 20 69 74 20 74 6f 20 70 72 69 6e 74 ause it to print
c770: 20 6d 6f 72 65 20 74 68 61 6e 20 63 61 6e 20 62 more than can b
c780: 65 20 73 74 6f 72 65 64 20 61 74 20 74 68 65 0a e stored at the.
c790: 65 6e 64 20 6f 66 20 61 20 66 69 65 6c 64 2c 20 end of a field,
c7a0: 69 74 20 77 69 6c 6c 20 77 72 61 70 20 61 72 6f it will wrap aro
c7b0: 75 6e 64 20 61 6e 64 20 62 65 67 69 6e 20 77 72 und and begin wr
c7c0: 69 74 69 6e 67 20 61 74 20 74 68 65 20 62 65 67 iting at the beg
c7d0: 69 6e 6e 69 6e 67 0a 6f 66 20 74 68 65 20 73 61 inning.of the sa
c7e0: 6d 65 20 66 69 65 6c 64 2e 20 54 68 69 73 20 61 me field. This a
c7f0: 6c 73 6f 20 68 61 73 20 65 66 66 65 63 74 73 20 lso has effects
c800: 6f 6e 20 74 68 65 20 62 65 68 61 76 69 6f 72 20 on the behavior
c810: 6f 66 0a 5b 60 70 72 69 6e 74 66 28 29 60 5d 28 of.[`printf()`](
c820: 23 70 72 69 6e 74 66 29 20 61 6e 64 20 5b 60 66 #printf) and [`f
c830: 70 72 69 6e 74 66 28 29 60 5d 28 23 66 70 72 69 printf()`](#fpri
c840: 6e 74 66 29 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 ntf)...**Standar
c850: 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a d Violations:**.
c860: 0a 2a 20 20 20 41 73 20 6c 6f 6e 67 20 61 73 20 .* As long as
c870: 43 43 38 20 68 61 73 20 6e 6f 20 66 6c 6f 61 74 CC8 has no float
c880: 69 6e 67 2d 70 6f 69 6e 74 20 73 75 70 70 6f 72 ing-point suppor
c890: 74 2c 20 74 68 65 20 60 61 60 2c 20 60 65 60 2c t, the `a`, `e`,
c8a0: 20 60 66 60 2c 20 61 6e 64 0a 20 20 20 20 60 67 `f`, and. `g
c8b0: 60 20 66 6f 72 6d 61 74 20 73 70 65 63 69 66 69 ` format specifi
c8c0: 65 72 73 20 28 61 6e 64 20 74 68 65 69 72 20 63 ers (and their c
c8d0: 61 70 69 74 61 6c 69 7a 65 64 20 76 61 72 69 61 apitalized varia
c8e0: 6e 74 73 29 20 63 61 6e 6e 6f 74 20 62 65 0a 20 nts) cannot be.
c8f0: 20 20 20 73 75 70 70 6f 72 74 65 64 2e 0a 0a 2a supported...*
c900: 20 20 20 53 69 6e 63 65 20 43 43 38 20 64 6f 65 Since CC8 doe
c910: 73 20 6e 6f 74 20 73 75 70 70 6f 72 74 20 74 68 s not support th
c920: 65 20 60 6c 6f 6e 67 60 20 69 6e 74 65 67 65 72 e `long` integer
c930: 20 74 79 70 65 20 71 75 61 6c 69 66 69 65 72 2c type qualifier,
c940: 20 74 68 69 73 0a 20 20 20 20 66 75 6e 63 74 69 this. functi
c950: 6f 6e 20 64 6f 65 73 20 6e 6f 74 20 73 75 70 70 on does not supp
c960: 6f 72 74 20 74 68 65 20 60 6c 60 20 66 6f 72 6d ort the `l` form
c970: 61 74 20 73 70 65 63 69 66 69 65 72 2e 0a 0a 2a at specifier...*
c980: 20 20 20 54 68 65 20 73 74 61 6e 64 61 72 64 20 The standard
c990: 60 6e 60 20 61 6e 64 20 60 70 60 20 66 6f 72 6d `n` and `p` form
c9a0: 61 74 20 73 70 65 63 69 66 69 65 72 73 20 63 6f at specifiers co
c9b0: 75 6c 64 20 62 65 20 73 75 70 70 6f 72 74 65 64 uld be supported
c9c0: 2c 20 62 75 74 0a 20 20 20 20 63 75 72 72 65 6e , but. curren
c9d0: 74 6c 79 20 61 72 65 20 6e 6f 74 2e 0a 0a 2a 20 tly are not...*
c9e0: 20 20 54 68 65 20 60 69 60 20 61 6c 69 61 73 20 The `i` alias
c9f0: 66 6f 72 20 74 68 65 20 6d 6f 72 65 20 63 6f 6d for the more com
ca00: 6d 6f 6e 20 60 64 60 20 73 70 65 63 69 66 69 65 mon `d` specifie
ca10: 72 20 69 73 20 6e 6f 74 20 73 75 70 70 6f 72 74 r is not support
ca20: 65 64 2e 0a 0a 2a 20 20 20 55 6e 73 75 70 70 6f ed...* Unsuppo
ca30: 72 74 65 64 20 69 6e 70 75 74 20 73 70 65 63 69 rted input speci
ca40: 66 69 65 72 73 20 63 61 75 73 65 20 74 68 65 20 fiers cause the
ca50: 66 75 6e 63 74 69 6f 6e 20 74 6f 20 72 65 74 75 function to retu
ca60: 72 6e 20 74 68 65 20 6e 75 6d 62 65 72 0a 20 20 rn the number.
ca70: 20 20 6f 66 20 63 68 61 72 61 63 74 65 72 73 20 of characters
ca80: 77 72 69 74 74 65 6e 20 73 6f 20 66 61 72 2c 20 written so far,
ca90: 6e 6f 74 20 61 20 6e 65 67 61 74 69 76 65 20 76 not a negative v
caa0: 61 6c 75 65 20 61 73 20 74 68 65 20 53 74 61 6e alue as the Stan
cab0: 64 61 72 64 0a 20 20 20 20 72 65 71 75 69 72 65 dard. require
cac0: 73 2e 20 20 49 6e 20 74 68 65 20 63 61 73 65 20 s. In the case
cad0: 6f 66 20 60 73 70 72 69 6e 74 66 28 29 60 2c 20 of `sprintf()`,
cae0: 74 68 69 73 20 6d 65 61 6e 73 20 74 68 65 20 74 this means the t
caf0: 72 61 69 6c 69 6e 67 20 4e 55 4c 0a 20 20 20 20 railing NUL.
cb00: 63 68 61 72 61 63 74 65 72 20 77 69 6c 6c 20 6e character will n
cb10: 6f 74 20 62 65 20 77 72 69 74 74 65 6e 21 0a 0a ot be written!..
cb20: 2a 20 20 20 54 68 65 72 65 20 69 73 20 6e 6f 20 * There is no
cb30: 60 73 6e 70 72 69 6e 74 66 28 29 60 2c 20 60 76 `snprintf()`, `v
cb40: 70 72 69 6e 74 66 28 29 60 2c 20 65 74 63 2e 0a printf()`, etc..
cb50: 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 73 63 61 ..### <a id="sca
cb60: 6e 66 22 20 6e 61 6d 65 3d 22 66 73 63 61 6e 66 nf" name="fscanf
cb70: 22 3e 3c 2f 61 3e 60 66 73 63 61 6e 66 60 2c 20 "></a>`fscanf`,
cb80: 60 73 63 61 6e 66 60 2c 20 60 73 73 63 61 6e 66 `scanf`, `sscanf
cb90: 60 0a 0a 50 61 72 73 65 20 73 74 72 69 6e 67 73 `..Parse strings
cba0: 20 61 63 63 6f 72 64 69 6e 67 20 74 6f 20 61 20 according to a
cbb0: 60 70 72 69 6e 74 66 60 2d 6c 69 6b 65 20 66 6f `printf`-like fo
cbc0: 72 6d 61 74 20 73 70 65 63 69 66 69 63 61 74 69 rmat specificati
cbd0: 6f 6e 2e 20 60 73 63 61 6e 66 60 0a 67 65 74 73 on. `scanf`.gets
cbe0: 20 74 68 65 20 73 74 72 69 6e 67 20 66 72 6f 6d the string from
cbf0: 20 74 68 65 20 69 6e 74 65 72 61 63 74 69 76 65 the interactive
cc00: 20 74 65 72 6d 69 6e 61 6c 2c 20 60 66 73 63 61 terminal, `fsca
cc10: 6e 66 60 20 67 65 74 73 20 69 74 20 66 72 6f 6d nf` gets it from
cc20: 20 61 0a 66 69 6c 65 20 6f 70 65 6e 65 64 20 77 a.file opened w
cc30: 69 74 68 20 5b 60 66 6f 70 65 6e 28 29 60 5d 28 ith [`fopen()`](
cc40: 23 66 6f 70 65 6e 29 2c 20 61 6e 64 20 60 73 73 #fopen), and `ss
cc50: 63 61 6e 66 60 20 67 65 74 73 20 69 74 20 66 72 canf` gets it fr
cc60: 6f 6d 20 61 0a 4e 55 4c 2d 74 65 72 6d 69 6e 61 om a.NUL-termina
cc70: 74 65 64 20 43 20 73 74 72 69 6e 67 20 61 6c 72 ted C string alr
cc80: 65 61 64 79 20 69 6e 20 63 6f 72 65 2e 0a 0a 2a eady in core...*
cc90: 2a 44 4f 43 55 4d 45 4e 54 41 54 49 4f 4e 20 49 *DOCUMENTATION I
cca0: 4e 43 4f 4d 50 4c 45 54 45 2a 2a 0a 0a 0a 23 23 NCOMPLETE**...##
ccb0: 23 20 3c 61 20 69 64 3d 22 73 74 72 63 61 74 22 # <a id="strcat"
ccc0: 3e 3c 2f 61 3e 60 73 74 72 63 61 74 28 64 73 74 ></a>`strcat(dst
ccd0: 2c 20 73 72 63 29 60 0a 0a 43 6f 6e 63 61 74 65 , src)`..Concate
cce0: 6e 61 74 65 73 20 6f 6e 65 20 5b 30 2d 74 65 72 nates one [0-ter
ccf0: 6d 69 6e 61 74 65 64 20 77 6f 72 64 20 73 74 72 minated word str
cd00: 69 6e 67 5d 28 23 77 6f 72 64 73 74 72 29 20 74 ing](#wordstr) t
cd10: 6f 20 74 68 65 20 65 6e 64 20 6f 66 0a 61 6e 6f o the end of.ano
cd20: 74 68 65 72 20 69 6e 20 74 68 65 20 5b 75 73 65 ther in the [use
cd30: 72 20 64 61 74 61 20 66 69 65 6c 64 5d 28 23 75 r data field](#u
cd40: 64 66 29 2e 0a 0a 54 68 69 73 20 66 75 6e 63 74 df)...This funct
cd50: 69 6f 6e 20 77 69 6c 6c 20 6e 6f 74 20 63 6f 70 ion will not cop
cd60: 79 20 64 61 74 61 20 62 65 74 77 65 65 6e 20 66 y data between f
cd70: 69 65 6c 64 73 2e 0a 0a 49 66 20 74 68 65 20 74 ields...If the t
cd80: 65 72 6d 69 6e 61 74 69 6e 67 20 30 20 77 6f 72 erminating 0 wor
cd90: 64 20 69 73 20 6e 6f 74 20 66 6f 75 6e 64 20 69 d is not found i
cda0: 6e 20 60 64 73 74 60 20 62 79 20 74 68 65 20 65 n `dst` by the e
cdb0: 6e 64 20 6f 66 20 74 68 65 0a 63 75 72 72 65 6e nd of the.curren
cdc0: 74 20 66 69 65 6c 64 2c 20 69 74 20 77 69 6c 6c t field, it will
cdd0: 20 77 72 61 70 20 61 72 6f 75 6e 64 20 74 6f 20 wrap around to
cde0: 74 68 65 20 73 74 61 72 74 20 6f 66 20 74 68 65 the start of the
cdf0: 20 66 69 65 6c 64 20 61 6e 64 20 72 65 73 75 6d field and resum
ce00: 65 0a 73 65 61 72 63 68 69 6e 67 20 74 68 65 72 e.searching ther
ce10: 65 3b 20 74 68 65 20 63 6f 6e 63 61 74 65 6e 61 e; the concatena
ce20: 74 69 6f 6e 20 77 69 6c 6c 20 6f 63 63 75 72 20 tion will occur
ce30: 77 68 65 72 65 76 65 72 20 69 74 20 64 6f 65 73 wherever it does
ce40: 20 66 69 6e 64 20 61 20 30 0a 77 6f 72 64 2e 20 find a 0.word.
ce50: 49 66 20 74 68 65 72 65 20 68 61 70 70 65 6e 20 If there happen
ce60: 74 6f 20 62 65 20 6e 6f 20 30 20 77 6f 72 64 73 to be no 0 words
ce70: 20 69 6e 20 74 68 65 20 66 69 65 6c 64 2c 20 69 in the field, i
ce80: 74 20 77 69 6c 6c 20 69 74 65 72 61 74 65 0a 66 t will iterate.f
ce90: 6f 72 65 76 65 72 21 0a 0a 42 65 77 61 72 65 20 orever!..Beware
cea0: 74 68 61 74 20 74 68 69 73 20 66 75 6e 63 74 69 that this functi
ceb0: 6f 6e 20 77 69 6c 6c 20 5b 77 72 61 70 20 61 72 on will [wrap ar
cec0: 6f 75 6e 64 5d 28 23 70 74 72 77 72 61 70 29 20 ound](#ptrwrap)
ced0: 69 66 0a 60 64 73 74 20 2b 20 73 74 72 6c 65 6e if.`dst + strlen
cee0: 28 64 73 74 29 20 2b 20 73 74 72 6c 65 6e 28 73 (dst) + strlen(s
cef0: 72 63 29 60 20 26 67 65 3b 20 34 30 39 36 20 61 rc)` ≥ 4096 a
cf00: 6e 64 20 73 74 6f 6d 70 20 6f 6e 20 77 68 61 74 nd stomp on what
cf10: 65 76 65 72 e2 80 99 73 0a 61 74 20 74 68 65 20 ever’s.at the
cf20: 73 74 61 72 74 20 6f 66 20 74 68 65 20 66 69 65 start of the fie
cf30: 6c 64 2e 0a 0a 54 68 65 73 65 20 61 72 65 20 6e ld...These are n
cf40: 6f 74 20 74 65 63 68 6e 69 63 61 6c 6c 79 20 76 ot technically v
cf50: 69 6f 6c 61 74 69 6f 6e 73 20 6f 66 20 53 74 61 iolations of Sta
cf60: 6e 64 61 72 64 20 43 20 61 73 20 69 74 20 6c 65 ndard C as it le
cf70: 61 76 65 73 20 73 75 63 68 0a 6d 61 74 74 65 72 aves such.matter
cf80: 73 20 5b 75 6e 64 65 66 69 6e 65 64 5d 5b 75 62 s [undefined][ub
cf90: 5d 2e 0a 0a 52 65 74 75 72 6e 73 20 61 20 63 6f ]...Returns a co
cfa0: 70 79 20 6f 66 20 60 64 73 74 60 2e 0a 0a 2a 2a py of `dst`...**
cfb0: 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 69 Standard Violati
cfc0: 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 4e 6f 6e 65 ons:**..* None
cfd0: 20 6b 6e 6f 77 6e 2e 0a 0a 0a 23 23 23 20 3c 61 known....### <a
cfe0: 20 69 64 3d 22 73 74 72 63 70 79 22 3e 3c 2f 61 id="strcpy"></a
cff0: 3e 60 73 74 72 63 70 79 28 64 73 74 2c 20 73 72 >`strcpy(dst, sr
d000: 63 29 60 0a 0a 43 6f 70 69 65 73 20 6f 6e 65 20 c)`..Copies one
d010: 5b 30 2d 74 65 72 6d 69 6e 61 74 65 64 20 77 6f [0-terminated wo
d020: 72 64 20 73 74 72 69 6e 67 5d 28 23 77 6f 72 64 rd string](#word
d030: 73 74 72 29 20 74 6f 20 61 6e 6f 74 68 65 72 20 str) to another
d040: 6d 65 6d 6f 72 79 0a 6c 6f 63 61 74 69 6f 6e 20 memory.location
d050: 69 6e 20 74 68 65 20 5b 75 73 65 72 20 64 61 74 in the [user dat
d060: 61 20 66 69 65 6c 64 5d 28 23 75 64 66 29 2e 0a a field](#udf)..
d070: 0a 54 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 77 .This function w
d080: 69 6c 6c 20 6e 6f 74 20 63 6f 70 79 20 64 61 74 ill not copy dat
d090: 61 20 62 65 74 77 65 65 6e 20 66 69 65 6c 64 73 a between fields
d0a0: 2e 0a 0a 42 65 77 61 72 65 20 74 68 61 74 20 74 ...Beware that t
d0b0: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c his function wil
d0c0: 6c 20 5b 77 72 61 70 20 61 72 6f 75 6e 64 5d 28 l [wrap around](
d0d0: 23 70 74 72 77 72 61 70 29 20 69 66 20 65 69 74 #ptrwrap) if eit
d0e0: 68 65 72 0a 60 73 72 63 2b 73 74 72 6c 65 6e 28 her.`src+strlen(
d0f0: 73 72 63 29 60 20 6f 72 20 60 64 73 74 2b 73 74 src)` or `dst+st
d100: 72 6c 65 6e 28 64 73 74 29 60 20 26 67 65 3b 20 rlen(dst)` ≥
d110: 34 30 39 36 2e 0a 0a 54 68 65 20 60 64 73 74 60 4096...The `dst`
d120: 20 62 75 66 66 65 72 20 63 61 6e 20 73 61 66 65 buffer can safe
d130: 6c 79 20 6f 76 65 72 6c 61 70 20 74 68 65 20 60 ly overlap the `
d140: 73 72 63 60 20 62 75 66 66 65 72 20 6f 6e 6c 79 src` buffer only
d150: 20 69 66 20 69 74 20 69 73 20 61 74 20 61 0a 6c if it is at a.l
d160: 6f 77 65 72 20 61 64 64 72 65 73 73 20 69 6e 20 ower address in
d170: 6d 65 6d 6f 72 79 2e 0a 0a 2a 2a 53 74 61 6e 64 memory...**Stand
d180: 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a ard Violations:*
d190: 2a 0a 0a 2a 20 20 20 52 65 74 75 72 6e 73 20 30 *..* Returns 0
d1a0: 2c 20 6e 6f 74 20 61 20 63 6f 70 79 20 6f 66 20 , not a copy of
d1b0: 60 64 73 74 60 20 61 73 20 74 68 65 20 53 74 61 `dst` as the Sta
d1c0: 6e 64 61 72 64 20 72 65 71 75 69 72 65 73 2e 0a ndard requires..
d1d0: 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 73 74 72 ..### <a id="str
d1e0: 73 74 72 22 3e 3c 2f 61 3e 60 73 74 72 73 74 72 str"></a>`strstr
d1f0: 28 68 61 79 73 74 61 63 6b 2c 20 6e 65 65 64 6c (haystack, needl
d200: 65 29 60 0a 0a 41 74 74 65 6d 70 74 73 20 74 6f e)`..Attempts to
d210: 20 66 69 6e 64 20 74 68 65 20 66 69 72 73 74 20 find the first
d220: 69 6e 73 74 61 6e 63 65 20 6f 66 20 60 6e 65 65 instance of `nee
d230: 64 6c 65 60 20 77 69 74 68 69 6e 20 60 68 61 79 dle` within `hay
d240: 73 74 61 63 6b 60 2c 20 77 68 69 63 68 0a 61 72 stack`, which.ar
d250: 65 20 5b 30 2d 74 65 72 6d 69 6e 61 74 65 64 20 e [0-terminated
d260: 77 6f 72 64 20 73 74 72 69 6e 67 73 5d 28 23 77 word strings](#w
d270: 6f 72 64 73 74 72 29 2e 20 54 68 69 73 20 66 75 ordstr). This fu
d280: 6e 63 74 69 6f 6e e2 80 99 73 20 62 65 68 61 76 nction’s behav
d290: 69 6f 72 20 69 73 0a 5b 75 6e 64 65 66 69 6e 65 ior is.[undefine
d2a0: 64 5d 5b 75 62 5d 20 69 66 20 65 69 74 68 65 72 d][ub] if either
d2b0: 20 62 75 66 66 65 72 20 69 73 20 6e 6f 74 20 30 buffer is not 0
d2c0: 2d 74 65 72 6d 69 6e 61 74 65 64 2e 0a 0a 54 68 -terminated...Th
d2d0: 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e e implementation
d2e0: 20 75 73 65 73 20 74 68 65 20 5b 6e 61 c3 af 76 uses the [naïv
d2f0: 65 20 73 74 72 69 6e 67 20 73 65 61 72 63 68 20 e string search
d300: 61 6c 67 6f 72 69 74 68 6d 5d 5b 6e 73 73 61 5d algorithm][nssa]
d310: 2c 20 73 6f 0a 74 68 65 20 74 79 70 69 63 61 6c , so.the typical
d320: 20 65 78 65 63 75 74 69 6f 6e 20 74 69 6d 65 20 execution time
d330: 69 73 20 4f 28 6e 2b 6d 29 2c 20 62 75 74 20 74 is O(n+m), but t
d340: 68 65 20 77 6f 72 73 74 20 63 61 73 65 20 74 69 he worst case ti
d350: 6d 65 20 69 73 0a 26 54 68 65 74 61 28 6e 6d 29 me is.&Theta(nm)
d360: 2e 20 44 6f 6e e2 80 99 74 20 67 6f 20 65 78 70 . Don’t go exp
d370: 65 63 74 69 6e 67 20 75 73 20 74 6f 20 62 75 79 ecting us to buy
d380: 20 65 78 65 63 75 74 69 6f 6e 20 73 70 65 65 64 execution speed
d390: 20 77 69 74 68 0a 70 72 65 70 72 6f 63 65 73 73 with.preprocess
d3a0: 69 6e 67 20 73 74 65 70 73 20 61 73 20 77 69 74 ing steps as wit
d3b0: 68 20 5b 42 4d 48 5d 5b 62 6d 68 5d 20 6f 72 20 h [BMH][bmh] or
d3c0: 5b 4b 4d 50 5d 5b 6b 6d 70 5d 21 0a 0a 42 6f 74 [KMP][kmp]!..Bot
d3d0: 68 20 74 68 65 20 60 68 61 79 73 74 61 63 6b 60 h the `haystack`
d3e0: 20 61 6e 64 20 60 6e 65 65 64 6c 65 60 20 62 75 and `needle` bu
d3f0: 66 66 65 72 20 70 6f 69 6e 74 65 72 73 20 61 72 ffer pointers ar
d400: 65 20 6f 66 66 73 65 74 73 20 77 69 74 68 69 6e e offsets within
d410: 20 74 68 65 0a 5b 75 73 65 72 20 64 61 74 61 20 the.[user data
d420: 66 69 65 6c 64 5d 28 23 75 64 66 29 2e 0a 0a 42 field](#udf)...B
d430: 65 77 61 72 65 20 74 68 61 74 20 74 68 69 73 20 eware that this
d440: 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 5b 77 function will [w
d450: 72 61 70 20 61 72 6f 75 6e 64 5d 28 23 70 74 72 rap around](#ptr
d460: 77 72 61 70 29 20 69 66 20 65 69 74 68 65 72 0a wrap) if either.
d470: 60 68 61 79 73 74 61 63 6b 2b 73 74 72 6c 65 6e `haystack+strlen
d480: 28 68 61 79 73 74 61 63 6b 29 60 20 6f 72 20 60 (haystack)` or `
d490: 6e 65 65 64 6c 65 2b 73 74 72 6c 65 6e 28 6e 65 needle+strlen(ne
d4a0: 65 64 6c 65 29 60 20 26 67 65 3b 20 34 30 39 36 edle)` ≥ 4096
d4b0: 2c 0a 63 6f 6e 74 69 6e 75 69 6e 67 20 74 68 65 ,.continuing the
d4c0: 20 73 65 61 72 63 68 20 6f 72 20 6d 61 74 63 68 search or match
d4d0: 20 28 72 65 73 70 65 63 74 69 76 65 6c 79 29 20 (respectively)
d4e0: 66 72 6f 6d 20 74 68 61 74 20 70 6f 69 6e 74 2e from that point.
d4f0: 0a 0a 2a 2a 52 65 74 75 72 6e 73 3a 2a 2a 0a 0a ..**Returns:**..
d500: 2a 20 20 20 2a 61 20 70 6f 69 6e 74 65 72 20 74 * *a pointer t
d510: 6f 20 74 68 65 20 66 69 72 73 74 20 6e 65 65 64 o the first need
d520: 6c 65 2a 2c 20 69 66 20 6f 6e 65 20 69 73 20 66 le*, if one is f
d530: 6f 75 6e 64 20 77 69 74 68 69 6e 20 74 68 65 20 ound within the
d540: 68 61 79 73 74 61 63 6b 0a 0a 2a 20 20 20 2a 7a haystack..* *z
d550: 65 72 6f 2a 20 69 66 20 65 69 74 68 65 72 20 6e ero* if either n
d560: 6f 20 6e 65 65 64 6c 65 20 69 73 20 69 6e 20 74 o needle is in t
d570: 68 65 20 68 61 79 73 74 61 63 6b 2c 20 2a 6f 72 he haystack, *or
d580: 2a 20 74 68 65 20 68 61 79 73 74 61 63 6b 20 69 * the haystack i
d590: 73 0a 20 20 20 20 7a 65 72 6f 2d 6c 65 6e 67 74 s. zero-lengt
d5a0: 68 20 28 69 2e 65 2e 20 60 2a 68 61 79 73 74 61 h (i.e. `*haysta
d5b0: 63 6b 20 3d 3d 20 27 5c 30 27 60 29 2c 20 2a 6f ck == '\0'`), *o
d5c0: 72 2a 20 74 68 65 20 6e 65 65 64 6c 65 20 69 73 r* the needle is
d5d0: 20 62 69 67 67 65 72 0a 20 20 20 20 74 68 61 6e bigger. than
d5e0: 20 74 68 65 20 68 61 79 73 74 61 63 6b 0a 0a 2a the haystack..*
d5f0: 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 *Standard Violat
d600: 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 4e 6f 6e ions:**..* Non
d610: 65 20 6b 6e 6f 77 6e 2e 0a 0a 5b 62 6d 68 5d 3a e known...[bmh]:
d620: 20 20 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b https://en.wik
d630: 69 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f ipedia.org/wiki/
d640: 42 6f 79 65 72 25 45 32 25 38 30 25 39 33 4d 6f Boyer%E2%80%93Mo
d650: 6f 72 65 25 45 32 25 38 30 25 39 33 48 6f 72 73 ore%E2%80%93Hors
d660: 70 6f 6f 6c 5f 61 6c 67 6f 72 69 74 68 6d 0a 5b pool_algorithm.[
d670: 6b 6d 70 5d 3a 20 20 68 74 74 70 73 3a 2f 2f 65 kmp]: https://e
d680: 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f n.wikipedia.org/
d690: 77 69 6b 69 2f 4b 6e 75 74 68 25 45 32 25 38 30 wiki/Knuth%E2%80
d6a0: 25 39 33 4d 6f 72 72 69 73 25 45 32 25 38 30 25 %93Morris%E2%80%
d6b0: 39 33 50 72 61 74 74 5f 61 6c 67 6f 72 69 74 68 93Pratt_algorith
d6c0: 6d 0a 5b 6e 73 73 61 5d 3a 20 68 74 74 70 73 3a m.[nssa]: https:
d6d0: 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f //en.wikipedia.o
d6e0: 72 67 2f 77 69 6b 69 2f 53 74 72 69 6e 67 2d 73 rg/wiki/String-s
d6f0: 65 61 72 63 68 69 6e 67 5f 61 6c 67 6f 72 69 74 earching_algorit
d700: 68 6d 23 4e 61 25 43 33 25 41 46 76 65 5f 73 74 hm#Na%C3%AFve_st
d710: 72 69 6e 67 5f 73 65 61 72 63 68 0a 0a 0a 23 23 ring_search...##
d720: 23 20 3c 61 20 69 64 3d 22 74 6f 75 70 70 65 72 # <a id="toupper
d730: 22 3e 3c 2f 61 3e 60 74 6f 75 70 70 65 72 28 63 "></a>`toupper(c
d740: 29 60 0a 0a 52 65 74 75 72 6e 73 20 74 68 65 20 )`..Returns the
d750: 75 70 70 65 72 63 61 73 65 20 66 6f 72 6d 20 6f uppercase form o
d760: 66 20 41 53 43 49 49 20 63 68 61 72 61 63 74 65 f ASCII characte
d770: 72 20 60 63 60 20 69 66 20 69 74 20 69 73 20 6c r `c` if it is l
d780: 6f 77 65 72 63 61 73 65 2c 0a 4f 74 68 65 72 77 owercase,.Otherw
d790: 69 73 65 2c 20 72 65 74 75 72 6e 73 20 60 63 60 ise, returns `c`
d7a0: 20 75 6e 63 68 61 6e 67 65 64 2e 0a 0a 2a 2a 53 unchanged...**S
d7b0: 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 69 6f tandard Violatio
d7c0: 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 54 68 65 72 65 ns:**..* There
d7d0: 20 69 73 20 6e 6f 20 60 74 6f 6c 6f 77 65 72 28 is no `tolower(
d7e0: 29 60 20 69 6e 20 74 68 65 20 43 43 38 20 4c 49 )` in the CC8 LI
d7f0: 42 43 2e 0a 0a 2a 20 20 20 44 6f 65 73 20 6e 6f BC...* Does no
d800: 74 20 6b 6e 6f 77 20 61 6e 79 74 68 69 6e 67 20 t know anything
d810: 61 62 6f 75 74 20 6c 6f 63 61 6c 65 73 3b 20 61 about locales; a
d820: 73 73 75 6d 65 73 20 55 53 2d 41 53 43 49 49 20 ssumes US-ASCII
d830: 69 6e 70 75 74 2e 0a 0a 0a 23 23 23 20 3c 61 20 input....### <a
d840: 69 64 3d 22 78 69 6e 69 74 22 3e 3c 2f 61 3e 60 id="xinit"></a>`
d850: 78 69 6e 69 74 28 29 60 0a 0a 50 72 69 6e 74 73 xinit()`..Prints
d860: 20 74 68 65 20 43 43 38 20 63 6f 6d 70 69 6c 65 the CC8 compile
d870: 72 e2 80 99 73 20 62 61 6e 6e 65 72 20 6d 65 73 r’s banner mes
d880: 73 61 67 65 2e 20 54 68 69 73 20 69 73 20 69 6e sage. This is in
d890: 20 4c 49 42 43 20 6f 6e 6c 79 20 62 65 63 61 75 LIBC only becau
d8a0: 73 65 0a 69 74 e2 80 99 73 20 63 61 6c 6c 65 64 se.it’s called
d8b0: 20 66 72 6f 6d 20 73 65 76 65 72 61 6c 20 70 6c from several pl
d8c0: 61 63 65 73 20 77 69 74 68 69 6e 20 43 43 38 20 aces within CC8
d8d0: 69 74 73 65 6c 66 2e 0a 0a 2a 2a 4e 6f 6e 73 74 itself...**Nonst
d8e0: 61 6e 64 61 72 64 2e 2a 2a 0a 0a 0a 23 23 20 3c andard.**...## <
d8f0: 61 20 69 64 3d 22 61 64 64 66 6e 22 3e 3c 2f 61 a id="addfn"></a
d900: 3e 41 64 64 69 74 69 6f 6e 61 6c 20 55 74 69 6c >Additional Util
d910: 69 74 79 20 52 6f 75 74 69 6e 65 73 0a 0a 54 68 ity Routines..Th
d920: 65 20 66 75 6e 63 74 69 6f 6e 73 20 74 68 61 74 e functions that
d930: 20 43 43 38 20 75 73 65 73 20 74 6f 20 6d 61 6e CC8 uses to man
d940: 69 70 75 6c 61 74 65 20 74 68 65 20 73 6f 66 74 ipulate the soft
d950: 77 61 72 65 20 73 74 61 63 6b 20 61 72 65 20 61 ware stack are a
d960: 6c 73 6f 0a 61 76 61 69 6c 61 62 6c 65 20 74 6f lso.available to
d970: 20 62 65 20 63 61 6c 6c 65 64 20 62 79 20 65 6e be called by en
d980: 64 2d 75 73 65 72 20 70 72 6f 67 72 61 6d 73 3a d-user programs:
d990: 20 60 50 55 53 48 60 2c 20 60 50 4f 50 60 2c 20 `PUSH`, `POP`,
d9a0: 60 50 55 54 53 54 4b 60 2c 0a 60 50 4f 50 52 45 `PUTSTK`,.`POPRE
d9b0: 54 60 2c 20 61 6e 64 20 60 50 43 41 4c 4c 60 2e T`, and `PCALL`.
d9c0: 20 54 68 65 20 70 61 67 65 20 7a 65 72 6f 20 70 The page zero p
d9d0: 6f 69 6e 74 65 72 73 20 66 6f 72 20 74 68 69 73 ointers for this
d9e0: 20 73 74 61 63 6b 20 61 72 65 0a 69 6e 69 74 69 stack are.initi
d9f0: 61 6c 69 7a 65 64 20 62 79 20 63 6f 64 65 20 69 alized by code i
da00: 6e 20 60 68 65 61 64 65 72 2e 73 62 60 2c 20 77 n `header.sb`, w
da10: 68 69 63 68 20 69 73 20 69 6e 6a 65 63 74 65 64 hich is injected
da20: 20 69 6e 74 6f 20 79 6f 75 72 0a 70 72 6f 67 72 into your.progr
da30: 61 6d e2 80 99 73 20 73 74 61 72 74 75 70 20 73 am’s startup s
da40: 65 71 75 65 6e 63 65 20 64 75 72 69 6e 67 20 63 equence during c
da50: 6f 6d 70 69 6c 61 74 69 6f 6e 2e 0a 0a 49 6e 20 ompilation...In
da60: 61 64 64 69 74 69 6f 6e 2c 20 74 68 65 72 65 20 addition, there
da70: 61 72 65 20 61 20 73 65 74 20 6f 66 20 66 75 6e are a set of fun
da80: 63 74 69 6f 6e 73 20 74 68 61 74 20 6d 61 79 20 ctions that may
da90: 62 65 20 75 73 65 64 20 74 6f 20 70 72 6f 76 69 be used to provi
daa0: 64 65 0a 74 65 6d 70 6f 72 61 72 79 20 73 74 6f de.temporary sto
dab0: 72 61 67 65 20 69 6e 20 66 69 65 6c 64 20 34 2c rage in field 4,
dac0: 20 61 63 74 69 6e 67 20 6c 69 6b 65 20 61 20 74 acting like a t
dad0: 65 6d 70 6f 72 61 72 79 20 62 69 6e 61 72 79 20 emporary binary
dae0: 66 69 6c 65 3a 0a 0a 60 76 6f 69 64 20 69 69 6e file:..`void iin
daf0: 69 74 28 69 6e 74 20 61 64 64 72 65 73 73 29 60 it(int address)`
db00: 3a 20 52 65 73 65 74 20 74 68 65 20 66 69 6c 65 : Reset the file
db10: 20 70 6f 69 6e 74 65 72 20 74 6f 20 61 6e 20 61 pointer to an a
db20: 72 62 69 74 72 61 72 79 0a 61 64 64 72 65 73 73 rbitrary.address
db30: 20 72 61 6e 67 65 20 30 2d 34 30 39 35 2e 0a 0a range 0-4095...
db40: 60 76 6f 69 64 20 73 74 72 69 28 69 6e 74 20 76 `void stri(int v
db50: 61 6c 75 65 29 60 3a 20 53 74 6f 72 65 20 e2 80 alue)`: Store
db60: 98 76 61 6c 75 65 e2 80 99 20 61 74 20 74 68 65 value’ at the
db70: 20 63 75 72 72 65 6e 74 20 61 64 64 72 65 73 73 current address
db80: 2c 20 61 6e 64 0a 69 6e 63 72 65 6d 65 6e 74 20 , and.increment
db90: 74 68 65 20 61 64 64 72 65 73 73 20 70 6f 69 6e the address poin
dba0: 74 65 72 2e 0a 0a 60 69 6e 74 20 73 74 72 6c 28 ter...`int strl(
dbb0: 29 60 3a 20 52 65 61 64 20 74 68 65 20 77 6f 72 )`: Read the wor
dbc0: 64 20 61 74 20 74 68 65 20 63 75 72 72 65 6e 74 d at the current
dbd0: 20 61 64 64 72 65 73 73 2c 20 61 6e 64 20 64 6f address, and do
dbe0: 20 6e 6f 74 20 69 6e 63 72 65 6d 65 6e 74 0a 74 not increment.t
dbf0: 68 65 20 61 64 64 72 65 73 73 2e 0a 0a 60 69 6e he address...`in
dc00: 74 20 73 74 72 64 28 29 60 3a 20 52 65 61 64 20 t strd()`: Read
dc10: 74 68 65 20 77 6f 72 64 20 61 74 20 74 68 65 20 the word at the
dc20: 63 75 72 72 65 6e 74 20 61 64 64 72 65 73 73 2c current address,
dc30: 20 61 6e 64 20 69 6e 63 72 65 6d 65 6e 74 20 74 and increment t
dc40: 68 65 0a 61 64 64 72 65 73 73 2e 0a 0a 41 73 20 he.address...As
dc50: 66 69 65 6c 64 20 34 20 69 73 20 6e 6f 74 20 75 field 4 is not u
dc60: 73 65 64 20 62 79 20 4f 53 2f 38 2c 20 79 6f 75 sed by OS/8, you
dc70: 72 20 70 72 6f 67 72 61 6d 20 6d 61 79 20 75 73 r program may us
dc80: 65 20 74 68 65 20 65 6e 74 69 72 65 20 66 69 65 e the entire fie
dc90: 6c 64 2e 0a 54 68 69 73 20 6c 69 62 72 61 72 79 ld..This library
dca0: 20 63 6f 64 65 20 64 6f 65 73 20 6e 6f 74 20 63 code does not c
dcb0: 68 65 63 6b 20 66 6f 72 20 6f 76 65 72 66 6c 6f heck for overflo
dcc0: 77 3a 20 67 6f 69 6e 67 20 62 65 79 6f 6e 64 20 w: going beyond
dcd0: 61 64 64 72 65 73 73 20 34 30 39 35 0a 77 69 6c address 4095.wil
dce0: 6c 20 73 69 6d 70 6c 79 20 77 72 61 70 20 74 6f l simply wrap to
dcf0: 20 61 64 64 72 65 73 73 20 30 2e 0a 0a 0a 0a 3c address 0.....<
dd00: 61 20 69 64 3d 22 65 78 61 6d 70 6c 65 73 22 3e a id="examples">
dd10: 3c 2f 61 3e 0a 23 23 20 54 72 79 69 6e 67 20 74 </a>.## Trying t
dd20: 68 65 20 45 78 61 6d 70 6c 65 73 0a 0a 54 68 65 he Examples..The
dd30: 20 73 74 61 6e 64 61 72 64 20 50 69 44 50 2d 38 standard PiDP-8
dd40: 2f 49 20 4f 53 2f 38 20 52 4b 30 35 20 62 6f 6f /I OS/8 RK05 boo
dd50: 74 20 64 69 73 6b 20 63 6f 6e 74 61 69 6e 73 20 t disk contains
dd60: 73 65 76 65 72 61 6c 20 65 78 61 6d 70 6c 65 0a several example.
dd70: 43 20 70 72 6f 67 72 61 6d 73 20 74 68 61 74 20 C programs that
dd80: 74 68 65 20 4f 53 2f 38 20 76 65 72 73 69 6f 6e the OS/8 version
dd90: 20 6f 66 20 43 43 38 20 69 73 20 61 62 6c 65 20 of CC8 is able
dda0: 74 6f 20 63 6f 6d 70 69 6c 65 2e 0a 0a 54 6f 20 to compile...To
ddb0: 74 72 79 20 74 68 65 20 4f 53 2f 38 20 76 65 72 try the OS/8 ver
ddc0: 73 69 6f 6e 20 6f 66 20 43 43 38 20 6f 75 74 2c sion of CC8 out,
ddd0: 20 62 6f 6f 74 20 4f 53 2f 38 20 77 69 74 68 69 boot OS/8 withi
dde0: 6e 20 74 68 65 20 50 69 44 50 2d 38 2f 49 0a 65 n the PiDP-8/I.e
ddf0: 6e 76 69 72 6f 6e 6d 65 6e 74 20 61 73 20 79 6f nvironment as yo
de00: 75 20 6e 6f 72 6d 61 6c 6c 79 20 77 6f 75 6c 64 u normally would
de10: 2c 20 74 68 65 6e 20 74 72 79 20 62 75 69 6c 64 , then try build
de20: 69 6e 67 20 6f 6e 65 20 6f 66 20 74 68 65 0a 65 ing one of the.e
de30: 78 61 6d 70 6c 65 73 3a 0a 0a 20 20 20 20 2e 45 xamples:.. .E
de40: 58 45 20 43 43 52 20 20 20 e2 87 a0 20 42 41 54 XE CCR ⇠ BAT
de50: 43 48 20 77 72 61 70 70 65 72 20 61 72 6f 75 6e CH wrapper aroun
de60: 64 20 43 43 3f 2e 53 56 3a 20 22 43 6f 6d 70 69 d CC?.SV: "Compi
de70: 6c 65 20 43 20 61 6e 64 20 52 75 6e 22 0a 20 20 le C and Run".
de80: 20 20 3e 70 73 2e 63 20 20 20 20 20 20 e2 87 a0 >ps.c ⇠
de90: 20 74 61 6b 65 73 20 6e 61 6d 65 20 6f 66 20 43 takes name of C
dea0: 20 70 72 6f 67 72 61 6d 2c 20 62 75 69 6c 64 73 program, builds
deb0: 2c 20 6c 69 6e 6b 73 2c 20 61 6e 64 20 72 75 6e , links, and run
dec0: 73 20 69 74 0a 0a 54 68 69 73 20 65 78 61 6d 70 s it..This examp
ded0: 6c 65 20 69 73 20 70 61 72 74 69 63 75 6c 61 72 le is particular
dee0: 6c 79 20 69 6e 74 65 72 65 73 74 69 6e 67 2e 20 ly interesting.
def0: 49 74 20 67 65 6e 65 72 61 74 65 73 0a 50 61 73 It generates.Pas
df00: 63 61 6c e2 80 99 73 20 74 72 69 61 6e 67 6c 65 cal’s triangle
df10: 20 77 69 74 68 6f 75 74 20 75 73 69 6e 67 20 66 without using f
df20: 61 63 74 6f 72 69 61 6c 73 2c 20 77 68 69 63 68 actorials, which
df30: 20 61 72 65 20 61 20 62 69 74 20 6f 75 74 20 6f are a bit out o
df40: 66 0a 72 61 6e 67 65 20 66 6f 72 20 31 32 20 62 f.range for 12 b
df50: 69 74 73 21 0a 0a 54 68 65 20 6f 74 68 65 72 20 its!..The other
df60: 65 78 61 6d 70 6c 65 73 20 70 72 65 69 6e 73 74 examples preinst
df70: 61 6c 6c 65 64 20 61 72 65 3a 0a 0a 2a 20 20 20 alled are:..*
df80: 2a 2a 3c 63 6f 64 65 3e 63 61 6c 63 2e 63 3c 2f **<code>calc.c</
df90: 63 6f 64 65 3e 2a 2a 20 2d 20 41 20 73 69 6d 70 code>** - A simp
dfa0: 6c 65 20 34 2d 66 75 6e 63 74 69 6f 6e 20 63 61 le 4-function ca
dfb0: 6c 63 75 6c 61 74 6f 72 20 70 72 6f 67 72 61 6d lculator program
dfc0: 2e 0a 0a 2a 20 20 20 2a 2a 3c 63 6f 64 65 3e 70 ...* **<code>p
dfd0: 64 2e 63 3c 2f 63 6f 64 65 3e 2a 2a 20 2d 20 53 d.c</code>** - S
dfe0: 68 6f 77 73 20 6d 65 74 68 6f 64 73 20 66 6f 72 hows methods for
dff0: 20 64 6f 69 6e 67 20 64 6f 75 62 6c 65 2d 70 72 doing double-pr
e000: 65 63 69 73 69 6f 6e 0a 20 20 20 20 28 69 2e 65 ecision. (i.e
e010: 2e 20 32 34 2d 62 69 74 29 20 69 6e 74 65 67 65 . 24-bit) intege
e020: 72 20 63 61 6c 63 75 6c 61 74 69 6f 6e 73 2e 0a r calculations..
e030: 0a 2a 20 20 20 2a 2a 3c 63 6f 64 65 3e 68 6c 62 .* **<code>hlb
e040: 2e 63 3c 2f 63 6f 64 65 3e 2a 2a 20 2d 20 47 65 .c</code>** - Ge
e050: 6e 65 72 61 74 65 73 20 5b 48 69 6c 62 65 72 74 nerates [Hilbert
e060: 20 63 75 72 76 65 73 5d 5b 68 63 5d 20 6f 6e 20 curves][hc] on
e070: 61 20 54 65 6b 34 30 31 30 0a 20 20 20 20 73 65 a Tek4010. se
e080: 72 69 65 73 20 64 69 73 70 6c 61 79 20 75 73 69 ries display usi
e090: 6e 67 20 72 61 77 20 74 65 72 6d 69 6e 61 6c 20 ng raw terminal
e0a0: 63 6f 64 65 73 2e 20 54 68 65 72 65 66 6f 72 65 codes. Therefore
e0b0: 2c 20 79 6f 75 20 6d 75 73 74 20 62 65 0a 20 20 , you must be.
e0c0: 20 20 72 75 6e 6e 69 6e 67 20 61 20 54 65 6b 34 running a Tek4
e0d0: 30 31 30 20 65 6d 75 6c 61 74 6f 72 20 77 68 65 010 emulator whe
e0e0: 6e 20 72 75 6e 6e 69 6e 67 20 74 68 69 73 20 70 n running this p
e0f0: 72 6f 67 72 61 6d 2c 20 65 6c 73 65 20 79 6f 75 rogram, else you
e100: 20 77 69 6c 6c 0a 20 20 20 20 67 65 74 20 67 61 will. get ga
e110: 72 62 61 67 65 20 6f 6e 20 74 68 65 20 64 69 73 rbage on the dis
e120: 70 6c 61 79 21 0a 0a 2a 20 20 20 2a 2a 3c 63 6f play!..* **<co
e130: 64 65 3e 66 69 62 2e 63 3c 2f 63 6f 64 65 3e 2a de>fib.c</code>*
e140: 2a 20 2d 20 43 61 6c 63 75 6c 61 74 65 73 20 74 * - Calculates t
e150: 68 65 20 66 69 72 73 74 20 31 30 20 46 69 62 6f he first 10 Fibo
e160: 6e 61 63 63 69 20 6e 75 6d 62 65 72 73 2e 0a 20 nacci numbers..
e170: 20 20 20 54 68 69 73 20 69 6d 70 6c 69 63 69 74 This implicit
e180: 6c 79 20 64 65 6d 6f 6e 73 74 72 61 74 65 73 20 ly demonstrates
e190: 43 43 38 27 73 20 61 62 69 6c 69 74 79 20 74 6f CC8's ability to
e1a0: 20 68 61 6e 64 6c 65 20 72 65 63 75 72 73 69 76 handle recursiv
e1b0: 65 0a 20 20 20 20 66 75 6e 63 74 69 6f 6e 20 63 e. function c
e1c0: 61 6c 6c 73 2e 0a 0a 2a 20 20 20 2a 2a 3c 63 6f alls...* **<co
e1d0: 64 65 3e 62 61 73 69 63 2e 63 3c 2f 63 6f 64 65 de>basic.c</code
e1e0: 3e 2a 2a 20 2d 20 41 20 73 69 6d 70 6c 65 20 42 >** - A simple B
e1f0: 61 73 69 63 20 69 6e 74 65 72 70 72 65 74 65 72 asic interpreter
e200: 20 75 73 65 64 20 74 6f 20 74 65 73 74 0a 20 20 used to test.
e210: 20 20 61 20 73 69 6d 70 6c 65 20 72 65 63 75 72 a simple recur
e220: 73 69 76 65 20 65 78 70 72 65 73 73 69 6f 6e 20 sive expression
e230: 70 72 6f 63 65 73 73 6f 72 2e 0a 0a 2a 20 20 20 processor...*
e240: 2a 2a 3c 63 6f 64 65 3e 66 6f 72 74 68 2e 63 3c **<code>forth.c<
e250: 2f 63 6f 64 65 3e 2a 2a 20 2d 20 41 20 73 69 6d /code>** - A sim
e260: 70 6c 65 20 46 6f 72 74 68 20 69 6e 74 65 72 70 ple Forth interp
e270: 72 65 74 65 72 20 75 73 65 64 20 74 6f 20 74 65 reter used to te
e280: 73 74 0a 20 20 20 20 73 77 69 74 63 68 20 73 74 st. switch st
e290: 61 74 65 6d 6d 65 6e 74 73 20 65 74 63 2e 0a 0a atemments etc...
e2a0: 54 68 65 20 74 77 6f 20 69 6e 74 65 72 70 65 74 The two interpet
e2b0: 65 72 73 20 61 72 65 20 71 75 69 74 65 20 63 6f ers are quite co
e2c0: 6d 70 6c 65 78 2c 20 70 61 72 74 69 63 75 6c 61 mplex, particula
e2d0: 72 6c 79 20 74 68 65 20 46 6f 72 74 68 0a 69 6e rly the Forth.in
e2e0: 74 65 72 70 72 65 74 65 72 2c 20 77 68 69 63 68 terpreter, which
e2f0: 20 63 6f 6e 74 61 69 6e 73 20 33 30 30 20 6c 69 contains 300 li
e300: 6e 65 73 20 6f 66 20 63 6f 64 65 20 61 6e 64 20 nes of code and
e310: 69 6d 70 6c 65 6d 65 6e 74 73 20 61 20 6e 75 6d implements a num
e320: 62 65 72 20 6f 66 0a 62 61 73 69 63 20 46 6f 72 ber of.basic For
e330: 74 68 20 66 75 6e 63 74 69 6f 6e 73 2e 20 54 68 th functions. Th
e340: 69 73 20 65 78 61 6d 70 6c 65 20 69 73 20 69 6e is example is in
e350: 74 65 6e 64 65 64 20 74 6f 20 73 68 6f 77 20 77 tended to show w
e360: 68 61 74 20 63 61 6e 20 62 65 0a 63 72 61 6d 6d hat can be.cramm
e370: 65 64 20 69 6e 74 6f 20 34 6b 20 6f 66 20 63 6f ed into 4k of co
e380: 72 65 2e 0a 0a 0a 41 6e 6f 74 68 65 72 20 73 65 re....Another se
e390: 74 20 6f 66 20 65 78 61 6d 70 6c 65 73 20 6e 6f t of examples no
e3a0: 74 20 70 72 65 69 6e 73 74 61 6c 6c 65 64 20 6f t preinstalled o
e3b0: 6e 20 74 68 65 20 4f 53 2f 38 20 64 69 73 6b 20 n the OS/8 disk
e3c0: 61 72 65 0a 60 65 78 61 6d 70 6c 65 73 2f 70 65 are.`examples/pe
e3d0: 70 30 30 31 2d 2a 2e 63 60 2c 20 77 68 69 63 68 p001-*.c`, which
e3e0: 20 61 72 65 20 64 65 73 63 72 69 62 65 64 20 5b are described [
e3f0: 65 6c 73 65 77 68 65 72 65 5d 5b 70 63 65 5d 2e elsewhere][pce].
e400: 0a 0a 5b 68 63 5d 3a 20 20 68 74 74 70 73 3a 2f ..[hc]: https:/
e410: 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 /en.wikipedia.or
e420: 67 2f 77 69 6b 69 2f 48 69 6c 62 65 72 74 5f 63 g/wiki/Hilbert_c
e430: 75 72 76 65 0a 5b 70 63 65 5d 3a 20 2f 77 69 6b urve.[pce]: /wik
e440: 69 3f 6e 61 6d 65 3d 50 45 50 30 30 31 2e 43 0a i?name=PEP001.C.
e450: 0a 0a 23 23 20 3c 61 20 69 64 3d 22 65 78 65 73 ..## <a id="exes
e460: 22 3e 3c 2f 61 3e 4d 61 6b 69 6e 67 20 45 78 65 "></a>Making Exe
e470: 63 75 74 61 62 6c 65 73 20 0a 0a 45 78 65 63 75 cutables ..Execu
e480: 74 69 6e 67 20 60 43 43 52 2e 42 49 60 20 6c 6f ting `CCR.BI` lo
e490: 61 64 73 2c 20 6c 69 6e 6b 73 2c 20 61 6e 64 20 ads, links, and
e4a0: 72 75 6e 73 20 79 6f 75 72 20 43 20 70 72 6f 67 runs your C prog
e4b0: 72 61 6d 20 77 69 74 68 6f 75 74 0a 70 72 6f 64 ram without.prod
e4c0: 75 63 69 6e 67 20 61 6e 20 65 78 65 63 75 74 61 ucing an executa
e4d0: 62 6c 65 20 66 69 6c 65 20 6f 6e 20 64 69 73 6b ble file on disk
e4e0: 2e 20 20 59 6f 75 20 6e 65 65 64 20 6f 6e 6c 79 . You need only
e4f0: 20 61 20 73 6d 61 6c 6c 20 76 61 72 69 61 74 69 a small variati
e500: 6f 6e 0a 6f 6e 20 74 68 69 73 20 42 41 54 43 48 on.on this BATCH
e510: 20 66 69 6c 65 27 73 20 63 6f 6e 74 65 6e 74 73 file's contents
e520: 20 74 6f 20 67 65 74 20 61 6e 20 65 78 65 63 75 to get an execu
e530: 74 61 62 6c 65 20 63 6f 72 65 20 69 6d 61 67 65 table core image
e540: 20 74 68 61 74 0a 79 6f 75 20 63 61 6e 20 72 75 that.you can ru
e550: 6e 20 77 69 74 68 20 74 68 65 20 4f 53 2f 38 20 n with the OS/8
e560: 60 52 60 20 63 6f 6d 6d 61 6e 64 3a 0a 0a 20 20 `R` command:..
e570: 20 20 2e 52 20 43 43 20 20 20 20 20 20 20 20 20 .R CC
e580: 20 20 20 20 20 20 20 20 20 20 e2 87 a0 20 6b 69 ⇠ ki
e590: 6e 64 61 20 6c 69 6b 65 20 55 6e 69 78 20 63 63 nda like Unix cc
e5a0: 28 31 29 0a 20 20 20 20 3e 6d 79 70 72 6f 67 2e (1). >myprog.
e5b0: 63 0a 20 20 20 20 2e 43 4f 4d 50 20 43 43 2e 53 c. .COMP CC.S
e5c0: 42 0a 20 20 20 20 2e 52 20 4c 4f 41 44 45 52 0a B. .R LOADER.
e5d0: 20 20 20 20 2a 43 43 2c 4c 49 42 43 2f 49 2f 4f *CC,LIBC/I/O
e5e0: 24 20 20 20 20 20 20 20 20 20 20 20 e2 87 a0 20 $ ⇠
e5f0: 24 20 3d 20 45 73 63 61 70 65 0a 20 20 20 20 2e $ = Escape. .
e600: 53 41 56 45 20 53 59 53 3a 4d 59 50 52 4f 47 0a SAVE SYS:MYPROG.
e610: 0a 49 66 20 79 6f 75 27 76 65 20 6a 75 73 74 20 .If you've just
e620: 72 75 6e 20 60 45 58 45 20 43 43 52 60 20 6f 6e run `EXE CCR` on
e630: 20 60 6d 79 70 72 6f 67 2e 63 60 2c 20 79 6f 75 `myprog.c`, you
e640: 20 63 61 6e 20 73 6b 69 70 20 74 68 65 20 60 43 can skip the `C
e650: 43 60 20 61 6e 64 0a 60 43 4f 4d 50 60 20 73 74 C` and.`COMP` st
e660: 65 70 73 20 61 62 6f 76 65 2c 20 72 65 75 73 69 eps above, reusi
e670: 6e 67 20 74 68 65 20 60 43 43 2e 52 4c 60 20 66 ng the `CC.RL` f
e680: 69 6c 65 20 74 68 61 74 20 77 61 73 20 6c 65 66 ile that was lef
e690: 74 20 62 65 68 69 6e 64 2e 0a 0a 42 61 73 69 63 t behind...Basic
e6a0: 61 6c 6c 79 2c 20 77 65 20 6c 65 61 76 65 20 74 ally, we leave t
e6b0: 68 65 20 60 2f 47 60 20 22 67 6f 22 20 73 77 69 he `/G` "go" swi
e6c0: 74 63 68 20 6f 66 66 20 6f 66 20 74 68 65 20 63 tch off of the c
e6d0: 6f 6d 6d 61 6e 64 20 74 6f 20 4c 4f 41 44 45 52 ommand to LOADER
e6e0: 0a 73 6f 20 74 68 61 74 20 74 68 65 20 70 72 6f .so that the pro
e6f0: 67 72 61 6d 20 69 73 20 6c 65 66 74 20 69 6e 20 gram is left in
e700: 69 74 73 20 70 72 65 2d 72 75 6e 20 73 74 61 74 its pre-run stat
e710: 65 20 69 6e 20 63 6f 72 65 20 73 6f 20 74 68 61 e in core so tha
e720: 74 0a 60 53 41 56 45 60 20 63 61 6e 20 63 61 70 t.`SAVE` can cap
e730: 74 75 72 65 20 69 74 20 74 6f 20 64 69 73 6b 2e ture it to disk.
e740: 0a 0a 0a 23 23 20 3c 61 20 69 64 3d 22 6d 65 6d ...## <a id="mem
e750: 6f 72 79 22 3e 3c 2f 61 3e 4d 65 6d 6f 72 79 20 ory"></a>Memory
e760: 4d 6f 64 65 6c 0a 0a 54 68 65 20 4f 53 2f 38 20 Model..The OS/8
e770: 46 4f 52 54 52 41 4e 20 49 49 20 6c 69 6e 6b 69 FORTRAN II linki
e780: 6e 67 20 6c 6f 61 64 65 72 20 28 60 4c 4f 41 44 ng loader (`LOAD
e790: 45 52 2e 53 56 60 29 20 64 65 74 65 72 6d 69 6e ER.SV`) determin
e7a0: 65 73 20 74 68 65 20 63 6f 72 65 0a 6d 65 6d 6f es the core.memo
e7b0: 72 79 20 6c 61 79 6f 75 74 20 66 6f 72 20 74 68 ry layout for th
e7c0: 65 20 62 75 69 6c 74 20 70 72 6f 67 72 61 6d 73 e built programs
e7d0: 2e 20 49 74 20 69 73 20 66 72 65 65 20 74 6f 20 . It is free to
e7e0: 70 6c 61 63 65 20 63 6f 64 65 20 61 6e 64 20 64 place code and d
e7f0: 61 74 61 0a 77 68 65 72 65 76 65 72 20 69 74 20 ata.wherever it
e800: 6c 69 6b 65 73 2c 20 62 75 74 20 74 68 65 20 66 likes, but the f
e810: 6f 6c 6c 6f 77 69 6e 67 20 69 73 20 61 20 70 6c ollowing is a pl
e820: 61 75 73 69 62 6c 65 20 6c 61 79 6f 75 74 20 69 ausible layout i
e830: 74 20 63 6f 75 6c 64 0a 63 68 6f 6f 73 65 3a 0a t could.choose:.
e840: 0a 2a 2a 46 69 65 6c 64 20 30 3a 2a 2a 20 46 4f .**Field 0:** FO
e850: 52 54 52 41 4e 20 6c 69 62 72 61 72 79 20 75 74 RTRAN library ut
e860: 69 6c 69 74 79 20 66 75 6e 63 74 69 6f 6e 73 20 ility functions
e870: 61 6e 64 20 4f 53 2f 38 20 49 2f 4f 20 73 79 73 and OS/8 I/O sys
e880: 74 65 6d 0a 0a 2a 2a 46 69 65 6c 64 20 31 3a 2a tem..**Field 1:*
e890: 2a 20 54 68 65 20 75 73 65 72 20 64 61 74 61 20 * The user data
e8a0: 66 69 65 6c 64 20 28 55 44 46 29 3a 20 67 6c 6f field (UDF): glo
e8b0: 62 61 6c 73 2c 20 6c 69 74 65 72 61 6c 73 2c 20 bals, literals,
e8c0: 61 6e 64 20 73 74 61 63 6b 0a 0a 2a 2a 46 69 65 and stack..**Fie
e8d0: 6c 64 20 32 3a 2a 2a 20 54 68 65 20 70 72 6f 67 ld 2:** The prog
e8e0: 72 61 6d 27 73 20 65 78 65 63 75 74 61 62 6c 65 ram's executable
e8f0: 20 63 6f 64 65 0a 0a 2a 2a 46 69 65 6c 64 20 33 code..**Field 3
e900: 3a 2a 2a 20 54 68 65 20 4c 49 42 43 20 6c 69 62 :** The LIBC lib
e910: 72 61 72 79 20 63 6f 64 65 0a 0a 2a 2a 46 69 65 rary code..**Fie
e920: 6c 64 20 34 3a 2a 2a 20 28 4f 70 74 69 6f 6e 61 ld 4:** (Optiona
e930: 6c 29 20 73 65 65 20 74 68 65 20 62 69 6e 61 72 l) see the binar
e940: 79 20 75 74 69 6c 69 74 69 65 73 20 61 62 6f 76 y utilities abov
e950: 65 20 28 73 74 72 69 2e 2e 2e 29 2e 0a 0a 23 23 e (stri...)...##
e960: 23 20 3c 61 20 69 64 3d 22 6f 73 38 72 65 73 22 # <a id="os8res"
e970: 3e 3c 2f 61 3e 4f 53 2f 38 20 52 65 73 65 72 76 ></a>OS/8 Reserv
e980: 61 74 69 6f 6e 73 0a 0a 54 68 65 20 75 70 70 65 ations..The uppe
e990: 72 6d 6f 73 74 20 70 61 67 65 20 6f 66 20 66 69 rmost page of fi
e9a0: 65 6c 64 73 20 30 20 74 68 72 75 20 32 20 68 6f elds 0 thru 2 ho
e9b0: 6c 64 20 74 68 65 0a 5b 72 65 73 69 64 65 6e 74 ld the.[resident
e9c0: 20 70 6f 72 74 69 6f 6e 20 6f 66 20 4f 53 2f 38 portion of OS/8
e9d0: 5d 5b 6f 73 38 72 65 73 5d 20 61 6e 64 20 74 68 ][os8res] and th
e9e0: 65 72 65 66 6f 72 65 20 6d 75 73 74 20 6e 6f 74 erefore must not
e9f0: 20 62 65 20 74 6f 75 63 68 65 64 20 62 79 0a 61 be touched by.a
ea00: 20 70 72 6f 67 72 61 6d 20 62 75 69 6c 74 20 77 program built w
ea10: 69 74 68 20 43 43 38 20 77 68 69 6c 65 20 72 75 ith CC8 while ru
ea20: 6e 6e 69 6e 67 20 75 6e 64 65 72 20 4f 53 2f 38 nning under OS/8
ea30: 2e 20 46 6f 72 20 65 78 61 6d 70 6c 65 2c 20 74 . For example, t
ea40: 68 65 0a 5b 4f 53 2f 38 20 6b 65 79 62 6f 61 72 he.[OS/8 keyboar
ea50: 64 20 6d 6f 6e 69 74 6f 72 5d 5b 6f 73 38 6b 62 d monitor][os8kb
ea60: 64 5d 20 72 65 2d 65 6e 74 72 79 20 70 6f 69 6e d] re-entry poin
ea70: 74 20 69 73 20 61 74 20 30 37 36 30 30 e2 82 88 t is at 07600₈
ea80: 2c 20 5b 74 68 65 20 6f 75 74 70 75 74 0a 66 69 , [the output.fi
ea90: 6c 65 20 74 61 62 6c 65 5d 5b 6f 73 38 6f 66 74 le table][os8oft
eaa0: 5d 20 69 73 20 61 74 20 31 37 36 30 30 e2 82 88 ] is at 17600₈
eab0: 2c 20 61 6e 64 20 5b 74 68 65 20 55 53 52 5d 5b , and [the USR][
eac0: 6f 73 38 75 73 72 5d 20 69 73 20 61 74 20 31 37 os8usr] is at 17
ead0: 37 30 30 e2 82 88 2e 0a 54 68 65 20 72 65 73 69 700₈..The resi
eae0: 64 65 6e 74 20 70 61 72 74 73 20 6f 66 20 64 65 dent parts of de
eaf0: 76 69 63 65 20 64 72 69 76 65 72 73 20 61 6c 73 vice drivers als
eb00: 6f 20 6c 69 76 65 20 75 70 20 68 65 72 65 2e 0a o live up here..
eb10: 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 7a 65 72 ..### <a id="zer
eb20: 6f 70 67 22 3e 3c 2f 61 3e 5a 65 72 6f 20 50 61 opg"></a>Zero Pa
eb30: 67 65 20 55 73 61 67 65 0a 0a 54 68 65 20 66 69 ge Usage..The fi
eb40: 72 73 74 20 74 68 69 6e 67 20 74 6f 20 67 65 74 rst thing to get
eb50: 20 63 6c 65 61 72 20 69 6e 20 79 6f 75 72 20 6d clear in your m
eb60: 69 6e 64 20 69 73 20 74 68 61 74 20 74 68 65 72 ind is that ther
eb70: 65 20 61 72 65 20 61 74 20 6c 65 61 73 74 0a 2a e are at least.*
eb80: 74 68 72 65 65 2a 20 7a 65 72 6f 20 70 61 67 65 three* zero page
eb90: 73 20 69 6e 76 6f 6c 76 65 64 20 68 65 72 65 2c s involved here,
eba0: 20 61 6e 64 20 70 6f 73 73 69 62 6c 79 20 66 6f and possibly fo
ebb0: 75 72 2c 20 64 65 70 65 6e 64 69 6e 67 20 6f 6e ur, depending on
ebc0: 20 68 6f 77 0a 60 4c 4f 41 44 45 52 2e 53 56 60 how.`LOADER.SV`
ebd0: 20 63 68 6f 6f 73 65 73 20 74 6f 20 61 72 72 61 chooses to arra
ebe0: 6e 67 65 20 79 6f 75 72 20 70 72 6f 67 72 61 6d nge your program
ebf0: 20 69 6e 20 6d 65 6d 6f 72 79 2e 20 28 57 65 20 in memory. (We
ec00: 67 65 74 20 69 6e 74 6f 20 74 68 65 0a 6e 69 74 get into the.nit
ec10: 74 79 20 67 72 69 74 74 79 20 6f 66 20 74 68 61 ty gritty of tha
ec20: 74 20 5b 62 65 6c 6f 77 5d 28 23 66 6c 61 79 6f t [below](#flayo
ec30: 75 74 29 2e 29 20 54 68 65 72 65 20 61 72 65 20 ut).) There are
ec40: 64 69 66 66 65 72 65 6e 74 20 72 75 6c 65 73 20 different rules
ec50: 66 6f 72 0a 65 61 63 68 20 66 69 65 6c 64 2e 0a for.each field..
ec60: 0a 54 68 65 20 66 69 65 6c 64 20 63 6f 6e 74 61 .The field conta
ec70: 69 6e 69 6e 67 20 74 68 65 20 75 73 65 72 e2 80 ining the user
ec80: 99 73 20 65 78 65 63 75 74 61 62 6c 65 20 63 6f s executable co
ec90: 64 65 20 63 61 6e 20 61 6c 73 6f 20 68 61 76 65 de can also have
eca0: 20 63 6f 64 65 20 66 72 6f 6d 0a 74 68 65 20 46 code from.the F
ecb0: 4f 52 54 52 41 4e 20 49 49 20 72 75 6e 20 74 69 ORTRAN II run ti
ecc0: 6d 65 20 6c 69 62 72 61 72 79 20 69 6e 20 69 74 me library in it
ecd0: 2c 20 65 73 70 65 63 69 61 6c 6c 79 20 77 68 65 , especially whe
ece0: 6e 20 74 68 65 20 75 73 65 72 e2 80 99 73 0a 70 n the user’s.p
ecf0: 72 6f 67 72 61 6d 20 69 73 20 73 6d 61 6c 6c 20 rogram is small
ed00: 61 6e 64 20 69 74 73 20 75 73 65 20 6f 66 20 46 and its use of F
ed10: 4f 52 54 52 41 4e 20 49 49 20 62 61 73 65 64 20 ORTRAN II based
ed20: 6c 69 62 72 61 72 79 20 72 6f 75 74 69 6e 65 73 library routines
ed30: 20 69 73 0a 6d 6f 64 65 73 74 2e 20 28 57 65 20 is.modest. (We
ed40: 67 69 76 65 20 61 6e 20 65 78 61 6d 70 6c 65 20 give an example
ed50: 6f 66 20 74 68 69 73 20 5b 62 65 6c 6f 77 5d 28 of this [below](
ed60: 23 66 6c 61 79 6f 75 74 29 2e 29 20 49 6e 20 73 #flayout).) In s
ed70: 75 63 68 20 66 69 65 6c 64 73 2c 0a 4c 4f 41 44 uch fields,.LOAD
ed80: 45 52 20 70 6c 61 63 65 73 20 61 20 73 6d 61 6c ER places a smal
ed90: 6c 20 6c 69 62 72 61 72 79 20 6f 66 20 72 6f 75 l library of rou
eda0: 74 69 6e 65 73 2c 20 77 68 69 63 68 20 74 6f 20 tines, which to
edb0: 61 20 66 69 72 73 74 0a 61 70 70 72 6f 78 69 6d a first.approxim
edc0: 61 74 69 6f 6e 20 6d 65 61 6e 73 20 75 73 65 72 ation means user
edd0: 20 63 6f 64 65 20 73 68 6f 75 6c 64 20 6e 6f 74 code should not
ede0: 20 75 73 65 20 74 68 65 20 7a 65 72 6f 20 70 61 use the zero pa
edf0: 67 65 2e 0a 0a 53 6f 6d 65 20 6f 66 20 74 68 65 ge...Some of the
ee00: 20 73 70 61 63 65 20 69 6e 20 74 68 65 20 75 73 space in the us
ee10: 65 72 20 63 6f 64 65 20 66 69 65 6c 64 e2 80 99 er code field’
ee20: 73 20 7a 65 72 6f 20 70 61 67 65 20 69 73 20 6c s zero page is l
ee30: 65 66 74 20 75 6e 75 73 65 64 20 62 79 0a 4c 4f eft unused by.LO
ee40: 41 44 45 52 2c 20 73 6f 20 77 65 20 75 73 65 20 ADER, so we use
ee50: 69 74 20 66 6f 72 20 61 20 73 6d 61 6c 6c 20 6e it for a small n
ee60: 75 6d 62 65 72 20 6f 66 20 69 6e 74 65 72 6e 61 umber of interna
ee70: 6c 20 67 6c 6f 62 61 6c 73 20 6d 61 69 6e 74 61 l globals mainta
ee80: 69 6e 65 64 0a 62 79 20 74 68 65 20 43 43 38 20 ined.by the CC8
ee90: 70 72 6f 67 72 61 6d 20 69 6e 69 74 69 61 6c 69 program initiali
eea0: 7a 61 74 69 6f 6e 20 63 6f 64 65 3a 20 60 69 6e zation code: `in
eeb0: 69 74 2e 68 60 20 66 6f 72 20 74 68 65 20 63 72 it.h` for the cr
eec0: 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 2c 0a 61 6e oss-compiler,.an
eed0: 64 20 60 68 65 61 64 65 72 2e 73 62 60 20 66 6f d `header.sb` fo
eee0: 72 20 74 68 65 20 6e 61 74 69 76 65 20 63 6f 6d r the native com
eef0: 70 69 6c 65 72 2c 20 77 68 69 63 68 20 77 65 e2 piler, which we
ef00: 80 99 6c 6c 20 72 65 66 65 72 20 74 6f 0a 67 65 ll refer to.ge
ef10: 6e 65 72 69 63 61 6c 6c 79 20 61 73 20 e2 80 9c nerically as “
ef20: 49 4e 49 54 e2 80 9d 20 66 72 6f 6d 20 68 65 72 INIT” from her
ef30: 65 20 6f 6e 2e 0a 0a 49 74 20 69 73 20 6e 6f 74 e on...It is not
ef40: 20 63 75 72 72 65 6e 74 6c 79 20 63 6c 65 61 72 currently clear
ef50: 20 74 6f 20 75 73 20 69 66 2c 20 62 65 74 77 65 to us if, betwe
ef60: 65 6e 20 4c 4f 41 44 45 52 20 61 6e 64 20 49 4e en LOADER and IN
ef70: 49 54 2c 20 69 66 20 74 68 65 72 65 20 69 73 0a IT, if there is.
ef80: 61 6e 79 20 73 70 61 63 65 20 61 74 20 61 6c 6c any space at all
ef90: 20 6c 65 66 74 20 6f 76 65 72 20 69 6e 20 74 68 left over in th
efa0: 65 20 75 73 65 72 20 63 6f 64 65 20 66 69 65 6c e user code fiel
efb0: 64 2e 20 57 65 e2 80 99 6c 6c 20 6e 65 65 64 20 d. We’ll need
efc0: 74 6f 0a 75 6e 64 65 72 74 61 6b 65 20 61 20 6d to.undertake a m
efd0: 61 70 70 69 6e 67 20 71 75 65 73 74 20 74 6f 20 apping quest to
efe0: 77 6f 72 6b 20 74 68 69 73 20 6f 75 74 2e 20 57 work this out. W
eff0: 65 e2 80 99 6c 6c 20 72 65 70 6f 72 74 20 74 68 e’ll report th
f000: 65 20 72 65 73 75 6c 74 73 0a 68 65 72 65 20 69 e results.here i
f010: 66 20 6f 75 72 20 71 75 65 73 74 20 70 61 72 74 f our quest part
f020: 79 20 6d 61 6e 61 67 65 73 20 74 6f 20 72 65 74 y manages to ret
f030: 75 72 6e 20 61 6c 69 76 65 2e 20 3a 29 0a 0a 4e urn alive. :)..N
f040: 6f 6e 65 20 6f 66 20 74 68 69 73 20 61 70 70 6c one of this appl
f050: 69 65 73 20 74 6f 20 74 68 65 20 66 69 65 6c 64 ies to the field
f060: 20 63 6f 6e 74 61 69 6e 69 6e 67 20 4c 49 42 43 containing LIBC
f070: 20 62 65 63 61 75 73 65 20 69 74 20 63 6f 6e 74 because it cont
f080: 61 69 6e 73 20 6e 6f 0a 46 4f 52 54 52 41 4e 20 ains no.FORTRAN
f090: 49 49 20 63 6f 64 65 2c 20 68 65 6e 63 65 20 6e II code, hence n
f0a0: 6f 20 4c 4f 41 44 45 52 20 69 6e 74 65 72 6e 61 o LOADER interna
f0b0: 6c 20 68 65 6c 70 65 72 20 72 6f 75 74 69 6e 65 l helper routine
f0c0: 73 20 6f 72 20 74 68 65 20 67 6c 6f 62 61 6c 73 s or the globals
f0d0: 0a 66 6f 72 20 74 68 6f 73 65 20 72 6f 75 74 69 .for those routi
f0e0: 6e 65 73 2e 20 4c 49 42 43 20 74 68 65 72 65 66 nes. LIBC theref
f0f0: 6f 72 65 20 75 73 65 73 20 74 68 65 20 7a 65 72 ore uses the zer
f100: 6f 20 70 61 67 65 20 69 6e 20 69 74 73 20 66 69 o page in its fi
f110: 65 6c 64 20 66 6f 72 0a 65 6e 74 69 72 65 6c 79 eld for.entirely
f120: 20 64 69 66 66 65 72 65 6e 74 20 70 75 72 70 6f different purpo
f130: 73 65 73 2c 20 77 68 69 63 68 20 77 65 20 64 6f ses, which we do
f140: 20 6e 6f 74 20 64 6f 63 75 6d 65 6e 74 20 68 65 not document he
f150: 72 65 20 62 65 63 61 75 73 65 20 69 74 0a 6e 65 re because it.ne
f160: 76 65 72 20 63 6f 6e 66 6c 69 63 74 73 20 77 69 ver conflicts wi
f170: 74 68 20 74 68 65 20 65 6e 64 20 75 73 65 72 20 th the end user
f180: 63 6f 64 65 20 61 6e 64 20 64 61 74 61 20 66 69 code and data fi
f190: 65 6c 64 73 2e 20 49 66 20 79 6f 75 20 77 61 6e elds. If you wan
f1a0: 74 20 74 6f 0a 6b 6e 6f 77 20 68 6f 77 20 4c 49 t to.know how LI
f1b0: 42 43 20 75 73 65 73 20 69 74 73 20 66 69 65 6c BC uses its fiel
f1c0: 64 e2 80 99 73 20 7a 65 72 6f 20 70 61 67 65 2c d’s zero page,
f1d0: 20 73 65 65 20 60 73 72 63 2f 63 63 38 2f 6f 73 see `src/cc8/os
f1e0: 38 2f 6c 69 62 63 2e 63 60 2e 0a 0a 54 68 65 20 8/libc.c`...The
f1f0: 5b 75 73 65 72 20 64 61 74 61 20 66 69 65 6c 64 [user data field
f200: 5d 28 23 75 64 66 29 20 61 6c 73 6f 20 72 75 6e ](#udf) also run
f210: 73 20 6f 6e 20 65 6e 74 69 72 65 6c 79 20 64 69 s on entirely di
f220: 66 66 65 72 65 6e 74 20 72 75 6c 65 73 20 66 72 fferent rules fr
f230: 6f 6d 0a 74 68 65 20 61 62 6f 76 65 2c 20 73 69 om.the above, si
f240: 6e 63 65 20 69 74 20 63 6f 6e 74 61 69 6e 73 20 nce it contains
f250: 6e 6f 20 65 78 65 63 75 74 61 62 6c 65 20 63 6f no executable co
f260: 64 65 20 61 74 20 61 6c 6c 2c 20 68 65 6e 63 65 de at all, hence
f270: 20 6e 6f 20 70 72 69 6f 72 0a 72 65 73 65 72 76 no prior.reserv
f280: 61 74 69 6f 6e 73 20 62 79 20 4c 4f 41 44 45 52 ations by LOADER
f290: 20 6f 72 20 4c 49 42 43 2e 20 53 65 65 20 74 68 or LIBC. See th
f2a0: 65 20 6e 65 78 74 20 73 65 63 74 69 6f 6e 20 66 e next section f
f2b0: 6f 72 20 68 6f 77 20 74 68 65 20 55 44 46 0a 75 or how the UDF.u
f2c0: 73 65 73 20 69 74 73 20 7a 65 72 6f 20 70 61 67 ses its zero pag
f2d0: 65 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 e....### <a id="
f2e0: 75 64 66 22 3e 3c 2f 61 3e 54 68 65 20 55 73 65 udf"></a>The Use
f2f0: 72 20 44 61 74 61 20 46 69 65 6c 64 0a 0a 54 68 r Data Field..Th
f300: 65 20 75 73 65 72 20 64 61 74 61 20 66 69 65 6c e user data fiel
f310: 64 20 69 73 20 61 6c 77 61 79 73 20 66 69 65 6c d is always fiel
f320: 64 20 31 2e 20 49 74 73 20 6c 61 79 6f 75 74 20 d 1. Its layout
f330: 62 72 65 61 6b 73 20 64 6f 77 6e 20 6c 69 6b 65 breaks down like
f340: 20 74 68 69 73 3a 0a 0a 7c 20 72 61 6e 67 65 20 this:..| range
f350: 20 20 20 20 20 20 20 20 7c 20 75 73 65 20 7c 0a | use |.
f360: 7c 20 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 2d 20 | -------------
f370: 7c 20 2d 2d 2d 20 7c 0a 7c 20 60 31 30 30 30 30 | --- |.| `10000
f380: 2d 31 30 30 30 31 60 20 7c 20 50 44 50 2d 38 20 -10001` | PDP-8
f390: 69 6e 74 65 72 72 75 70 74 20 68 61 6e 64 6c 69 interrupt handli
f3a0: 6e 67 3b 20 73 65 65 20 53 6d 61 6c 6c 20 43 6f ng; see Small Co
f3b0: 6d 70 75 74 65 72 20 48 61 6e 64 62 6f 6f 6b 20 mputer Handbook
f3c0: 7c 0a 7c 20 60 31 30 30 30 32 2d 31 30 30 30 37 |.| `10002-10007
f3d0: 60 20 7c 20 72 65 73 65 72 76 65 64 20 66 6f 72 ` | reserved for
f3e0: 20 66 75 74 75 72 65 20 4c 49 42 43 20 75 73 65 future LIBC use
f3f0: 20 7c 0a 7c 20 60 31 30 30 31 30 2d 31 30 30 31 |.| `10010-1001
f400: 37 60 20 7c 20 50 44 50 2d 38 20 61 75 74 6f 2d 7` | PDP-8 auto-
f410: 69 6e 64 65 78 20 72 65 67 69 73 74 65 72 73 3b index registers;
f420: 20 73 65 65 20 53 6d 61 6c 6c 20 43 6f 6d 70 75 see Small Compu
f430: 74 65 72 20 48 61 6e 64 62 6f 6f 6b 20 7c 0a 7c ter Handbook |.|
f440: 20 60 31 30 30 32 30 2d 31 30 31 37 37 60 20 7c `10020-10177` |
f450: 20 73 74 61 74 69 63 20 6f 75 74 70 75 74 20 62 static output b
f460: 75 66 66 65 72 20 75 73 65 64 20 62 79 20 5b 60 uffer used by [`
f470: 5b 66 5d 70 72 69 6e 74 66 28 29 60 5d 28 23 70 [f]printf()`](#p
f480: 72 69 6e 74 66 29 20 69 6e 20 5b 60 73 70 72 69 rintf) in [`spri
f490: 6e 74 66 28 29 60 5d 28 23 73 70 72 69 6e 74 66 ntf()`](#sprintf
f4a0: 29 20 63 61 6c 6c 20 7c 0a 7c 20 60 31 30 32 30 ) call |.| `1020
f4b0: 30 2d 31 78 78 78 78 60 20 7c 20 67 6c 6f 62 61 0-1xxxx` | globa
f4c0: 6c 73 20 66 69 72 73 74 2c 20 74 68 65 6e 20 6c ls first, then l
f4d0: 69 74 65 72 61 6c 73 20 70 61 63 6b 65 64 20 74 iterals packed t
f4e0: 6f 67 65 74 68 65 72 20 61 74 20 74 68 65 20 62 ogether at the b
f4f0: 6f 74 74 6f 6d 20 7c 0a 7c 20 60 31 78 78 78 78 ottom |.| `1xxxx
f500: 2d 31 37 35 37 37 60 20 7c 20 75 73 65 72 20 73 -17577` | user s
f510: 74 61 63 6b 2c 20 67 72 6f 77 73 20 75 70 77 61 tack, grows upwa
f520: 72 64 20 66 72 6f 6d 20 65 6e 64 20 6f 66 20 6c rd from end of l
f530: 69 74 65 72 61 6c 73 20 7c 0a 7c 20 60 31 37 36 iterals |.| `176
f540: 30 30 2d 31 37 37 37 37 60 20 7c 20 6c 61 73 74 00-17777` | last
f550: 20 70 61 67 65 20 6f 66 20 55 44 46 20 72 65 73 page of UDF res
f560: 65 72 76 65 64 20 62 79 20 4f 53 2f 38 20 28 5b erved by OS/8 ([
f570: 73 65 65 20 61 62 6f 76 65 5d 28 23 6f 73 38 72 see above](#os8r
f580: 65 73 29 29 20 7c 0a 0a 54 68 65 20 6d 61 78 69 es)) |..The maxi
f590: 6d 75 6d 20 73 69 7a 65 20 6f 66 20 67 6c 6f 62 mum size of glob
f5a0: 61 6c 73 20 2b 20 6c 69 74 65 72 61 6c 73 20 2b als + literals +
f5b0: 20 73 74 61 63 6b 20 69 6e 20 61 20 43 43 38 20 stack in a CC8
f5c0: 70 72 6f 67 72 61 6d 20 69 73 0a 74 68 65 72 65 program is.there
f5d0: 66 6f 72 65 20 37 34 30 30 e2 82 88 20 77 6f 72 fore 7400₈ wor
f5e0: 64 73 2e 20 28 33 38 34 30 20 64 65 63 69 6d 61 ds. (3840 decima
f5f0: 6c 2e 29 0a 0a 0a 23 23 23 23 20 3c 61 20 69 64 l.)...#### <a id
f600: 3d 22 6e 75 6c 70 74 72 22 3e 3c 2f 61 3e 43 20 ="nulptr"></a>C
f610: 4e 55 4c 4c 20 50 6f 69 6e 74 65 72 73 0a 0a 42 NULL Pointers..B
f620: 65 63 61 75 73 65 20 74 68 65 20 50 44 50 2d 38 ecause the PDP-8
f630: 20 69 6e 74 65 72 72 75 70 74 20 73 79 73 74 65 interrupt syste
f640: 6d 20 73 65 74 73 20 61 73 69 64 65 20 74 68 65 m sets aside the
f650: 20 66 69 72 73 74 20 74 77 6f 20 6c 6f 63 61 74 first two locat
f660: 69 6f 6e 73 20 6f 66 0a 65 61 63 68 20 66 69 65 ions of.each fie
f670: 6c 64 20 66 6f 72 20 69 74 73 65 6c 66 2c 20 61 ld for itself, a
f680: 6e 64 20 43 43 38 20 70 6c 61 79 73 20 61 6c 6f nd CC8 plays alo
f690: 6e 67 2c 20 61 20 76 61 6c 69 64 20 43 20 70 6f ng, a valid C po
f6a0: 69 6e 74 65 72 20 63 61 6e 20 6e 65 76 65 72 0a inter can never.
f6b0: 68 61 76 65 20 76 61 6c 75 65 20 30 2c 20 70 72 have value 0, pr
f6c0: 65 73 65 72 76 69 6e 67 20 74 68 65 20 65 78 70 eserving the exp
f6d0: 65 63 74 65 64 20 66 61 6c 73 79 20 6e 61 74 75 ected falsy natu
f6e0: 72 65 20 6f 66 20 61 20 43 20 4e 55 4c 4c 20 70 re of a C NULL p
f6f0: 6f 69 6e 74 65 72 2e 0a 54 68 69 73 20 68 61 73 ointer..This has
f700: 20 70 72 61 63 74 69 63 61 6c 20 70 6f 73 69 74 practical posit
f710: 69 76 65 20 63 6f 6e 73 65 71 75 65 6e 63 65 73 ive consequences
f720: 20 73 75 63 68 20 61 73 20 74 68 65 20 66 61 63 such as the fac
f730: 74 20 74 68 61 74 20 79 6f 75 20 63 61 6e 0a 64 t that you can.d
f740: 65 70 65 6e 64 20 6f 6e 20 61 20 63 61 6c 6c 20 epend on a call
f750: 74 6f 20 5b 60 67 65 74 73 28 29 60 5d 28 23 67 to [`gets()`](#g
f760: 65 74 73 29 20 74 6f 20 61 6c 77 61 79 73 20 72 ets) to always r
f770: 65 74 75 72 6e 20 61 20 74 72 75 74 68 79 20 76 eturn a truthy v
f780: 61 6c 75 65 20 6f 6e 0a 73 75 63 63 65 73 73 2c alue on.success,
f790: 20 70 72 6f 76 69 64 65 64 20 79 6f 75 e2 80 99 provided you’
f7a0: 76 65 20 70 61 73 73 65 64 20 69 74 20 61 20 6e ve passed it a n
f7b0: 6f 72 6d 61 6c 20 43 20 70 6f 69 6e 74 65 72 2e ormal C pointer.
f7c0: 0a 0a 43 20 67 69 76 65 73 20 79 6f 75 20 70 6c ..C gives you pl
f7d0: 65 6e 74 79 20 6f 66 20 70 6f 77 65 72 20 74 6f enty of power to
f7e0: 20 63 72 65 61 74 65 20 61 20 70 6f 69 6e 74 65 create a pointe
f7f0: 72 20 65 71 75 61 6c 20 74 6f 20 30 20 61 6e 64 r equal to 0 and
f800: 0a 64 65 72 65 66 65 72 65 6e 63 65 20 69 74 2c .dereference it,
f810: 20 62 75 74 20 79 6f 75 e2 80 99 64 20 62 65 20 but you’d be
f820: 6f 75 74 20 69 6e 20 5b 75 6e 64 65 66 69 6e 65 out in [undefine
f830: 64 20 62 65 68 61 76 69 6f 72 5d 5b 75 62 5d 20 d behavior][ub]
f840: 74 65 72 72 69 74 6f 72 79 0a 62 79 20 74 68 61 territory.by tha
f850: 74 20 70 6f 69 6e 74 2c 20 73 6f 20 6f 6e 20 79 t point, so on y
f860: 6f 75 72 20 68 65 61 64 20 62 65 20 74 68 65 20 our head be the
f870: 63 6f 6e 73 65 71 75 65 6e 63 65 73 21 0a 0a 0a consequences!...
f880: 23 23 23 20 3c 61 20 69 64 3d 22 70 74 72 77 72 ### <a id="ptrwr
f890: 61 70 22 3e 3c 2f 61 3e 50 6f 69 6e 74 65 72 73 ap"></a>Pointers
f8a0: 20 57 72 61 70 20 41 72 6f 75 6e 64 0a 0a 50 6f Wrap Around..Po
f8b0: 69 6e 74 65 72 73 20 69 6e 20 74 68 69 73 20 43 inters in this C
f8c0: 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 implementation
f8d0: 61 72 65 20 67 65 6e 65 72 61 6c 6c 79 20 63 6f are generally co
f8e0: 6e 66 69 6e 65 64 20 74 6f 20 5b 74 68 65 20 75 nfined to [the u
f8f0: 73 65 72 0a 64 61 74 61 20 66 69 65 6c 64 5d 28 ser.data field](
f900: 23 75 64 66 29 2e 20 54 68 61 74 20 69 73 20 74 #udf). That is t
f910: 6f 20 73 61 79 2c 20 74 68 65 20 63 6f 64 65 20 o say, the code
f920: 67 65 6e 65 72 61 74 65 64 20 62 79 20 43 43 38 generated by CC8
f930: 20 64 6f 65 73 20 6e 6f 74 0a 75 73 65 20 31 35 does not.use 15
f940: 2d 62 69 74 20 65 78 74 65 6e 64 65 64 20 61 64 -bit extended ad
f950: 64 72 65 73 73 65 73 3b 20 69 74 20 6a 75 73 74 dresses; it just
f960: 20 66 6c 69 70 73 20 62 65 74 77 65 65 6e 20 70 flips between p
f970: 61 67 65 73 20 64 65 70 65 6e 64 69 6e 67 20 6f ages depending o
f980: 6e 0a 77 68 61 74 20 74 79 70 65 20 6f 66 20 64 n.what type of d
f990: 61 74 61 20 6f 72 20 63 6f 64 65 20 69 74 e2 80 ata or code it
f9a0: 99 73 20 74 72 79 69 6e 67 20 74 6f 20 61 63 63 s trying to acc
f9b0: 65 73 73 2e 0a 0a 54 68 69 73 20 6d 65 61 6e 73 ess...This means
f9c0: 20 69 74 20 69 73 20 70 6f 73 73 69 62 6c 65 20 it is possible
f9d0: 74 6f 20 69 74 65 72 61 74 65 20 61 20 70 6f 69 to iterate a poi
f9e0: 6e 74 65 72 20 70 61 73 74 20 74 68 65 20 65 6e nter past the en
f9f0: 64 20 6f 66 20 61 20 34 30 39 36 0a 77 6f 72 64 d of a 4096.word
fa00: 20 63 6f 72 65 20 6d 65 6d 6f 72 79 20 66 69 65 core memory fie
fa10: 6c 64 2c 20 63 61 75 73 69 6e 67 20 69 74 20 74 ld, causing it t
fa20: 6f 20 77 72 61 70 20 61 72 6f 75 6e 64 20 74 6f o wrap around to
fa30: 20 30 20 61 6e 64 20 63 6f 6e 74 69 6e 75 65 0a 0 and continue.
fa40: 62 6c 69 74 68 65 6c 79 20 61 6c 6f 6e 67 2e 20 blithely along.
fa50: 20 53 69 6e 63 65 20 74 68 65 20 6c 61 73 74 20 Since the last
fa60: 70 61 67 65 20 6f 66 20 74 68 65 20 75 73 65 72 page of the user
fa70: 20 64 61 74 61 20 66 69 65 6c 64 20 5b 69 73 20 data field [is
fa80: 72 65 73 65 72 76 65 64 0a 66 6f 72 20 75 73 65 reserved.for use
fa90: 20 62 79 20 4f 53 2f 38 5d 28 23 6f 73 38 72 65 by OS/8](#os8re
faa0: 73 29 20 61 6e 64 20 74 68 65 20 66 69 72 73 74 s) and the first
fab0: 20 70 61 67 65 20 6f 66 20 74 68 65 20 55 44 46 page of the UDF
fac0: 20 68 61 73 20 5b 73 65 76 65 72 61 6c 0a 73 70 has [several.sp
fad0: 65 63 69 61 6c 20 75 73 65 73 5d 28 23 75 64 66 ecial uses](#udf
fae0: 29 2c 20 70 72 6f 67 72 61 6d 73 20 74 68 61 74 ), programs that
faf0: 20 64 6f 20 74 68 69 73 20 77 69 6c 6c 20 6d 6f do this will mo
fb00: 73 74 20 6c 69 6b 65 6c 79 20 63 72 61 73 68 20 st likely crash
fb10: 61 6e 64 0a 6d 61 79 20 65 76 65 6e 20 64 65 73 and.may even des
fb20: 74 72 6f 79 20 64 61 74 61 2e 20 4f 75 72 20 5b troy data. Our [
fb30: 4c 49 42 43 20 69 6d 70 6c 65 6d 65 6e 74 61 74 LIBC implementat
fb40: 69 6f 6e 5d 28 23 6c 69 62 63 29 20 67 65 6e 65 ion](#libc) gene
fb50: 72 61 6c 6c 79 20 64 6f 65 73 0a 6e 6f 74 20 74 rally does.not t
fb60: 72 79 20 74 6f 20 63 68 65 63 6b 20 66 6f 72 20 ry to check for
fb70: 73 75 63 68 20 77 72 61 70 61 72 6f 75 6e 64 20 such wraparound
fb80: 70 72 6f 62 6c 65 6d 73 2c 20 6d 75 63 68 20 6c problems, much l
fb90: 65 73 73 20 73 69 67 6e 61 6c 20 65 72 72 6f 72 ess signal error
fba0: 73 0a 77 68 65 6e 20 69 74 20 68 61 70 70 65 6e s.when it happen
fbb0: 73 2e 20 54 68 65 20 70 72 6f 67 72 61 6d 6d 65 s. The programme
fbc0: 72 20 69 73 20 65 78 70 65 63 74 65 64 20 74 6f r is expected to
fbd0: 20 61 76 6f 69 64 20 64 6f 69 6e 67 20 74 68 69 avoid doing thi
fbe0: 73 2e 0a 0a 43 6f 64 65 20 74 68 61 74 20 6f 70 s...Code that op
fbf0: 65 72 61 74 65 73 20 6f 6e 20 70 6f 69 6e 74 65 erates on pointe
fc00: 72 73 20 77 69 6c 6c 20 67 65 6e 65 72 61 6c 6c rs will generall
fc10: 79 20 6f 6e 6c 79 20 64 6f 20 69 74 73 20 77 6f y only do its wo
fc20: 72 6b 20 77 69 74 68 69 6e 0a 74 68 65 20 75 73 rk within.the us
fc30: 65 72 20 64 61 74 61 20 66 69 65 6c 64 2e 20 59 er data field. Y
fc40: 6f 75 20 77 69 6c 6c 20 6c 69 6b 65 6c 79 20 6e ou will likely n
fc50: 65 65 64 20 74 6f 20 72 65 73 6f 72 74 20 74 6f eed to resort to
fc60: 20 5b 69 6e 6c 69 6e 65 0a 61 73 73 65 6d 62 6c [inline.assembl
fc70: 79 5d 28 23 61 73 6d 29 20 61 6e 64 20 60 43 49 y](#asm) and `CI
fc80: 46 60 2f 60 43 44 46 60 20 69 6e 73 74 72 75 63 F`/`CDF` instruc
fc90: 74 69 6f 6e 73 20 74 6f 20 65 73 63 61 70 65 20 tions to escape
fca0: 74 68 61 74 20 66 69 65 6c 64 2e 0a 47 65 74 74 that field..Gett
fcb0: 69 6e 67 20 6f 75 72 20 5b 4c 49 42 43 5d 28 23 ing our [LIBC](#
fcc0: 6c 69 62 63 29 20 74 6f 20 6f 70 65 72 61 74 65 libc) to operate
fcd0: 20 6f 6e 20 6f 74 68 65 72 20 66 69 65 6c 64 73 on other fields
fce0: 20 6d 61 79 20 62 65 20 74 72 69 63 6b 79 20 6f may be tricky o
fcf0: 72 0a 65 76 65 6e 20 6d 6f 72 65 20 64 69 66 66 r.even more diff
fd00: 69 63 75 6c 74 20 74 68 61 6e 20 69 74 e2 80 99 icult than it’
fd10: 73 20 77 6f 72 74 68 2e 0a 0a 4f 6e 20 74 68 65 s worth...On the
fd20: 20 62 72 69 67 68 74 20 73 69 64 65 2c 20 70 6f bright side, po
fd30: 69 6e 74 65 72 73 20 61 72 65 20 61 6c 77 61 79 inters are alway
fd40: 73 20 31 32 2d 62 69 74 20 76 61 6c 75 65 73 2c s 12-bit values,
fd50: 20 61 63 63 65 73 73 65 64 20 77 69 74 68 0a 69 accessed with.i
fd60: 6e 64 69 72 65 63 74 20 61 64 64 72 65 73 73 69 ndirect addressi
fd70: 6e 67 2c 20 72 61 74 68 65 72 20 74 68 61 6e 20 ng, rather than
fd80: 70 61 67 65 2d 72 65 6c 61 74 69 76 65 20 37 2d page-relative 7-
fd90: 62 69 74 20 61 64 64 72 65 73 73 65 73 2c 20 73 bit addresses, s
fda0: 6f 20 74 68 61 74 0a 70 72 6f 67 72 61 6d 73 20 o that.programs
fdb0: 62 75 69 6c 74 20 77 69 74 68 20 43 43 38 20 6e built with CC8 n
fdc0: 65 65 64 20 6e 6f 74 20 63 6f 6e 63 65 72 6e 20 eed not concern
fdd0: 74 68 65 6d 73 65 6c 76 65 73 20 77 69 74 68 20 themselves with
fde0: 5b 70 61 67 65 0a 62 6f 75 6e 64 61 72 69 65 73 [page.boundaries
fdf0: 5d 5b 6d 65 6d 61 64 64 5d 2e 0a 0a 0a 23 23 23 ][memadd]....###
fe00: 20 3c 61 20 69 64 3d 22 68 65 61 70 22 3e 3c 2f <a id="heap"></
fe10: 61 3e 54 68 65 72 65 20 49 73 20 4e 6f 20 48 65 a>There Is No He
fe20: 61 70 0a 0a 54 68 65 72 65 20 69 73 20 6e 6f 20 ap..There is no
fe30: 60 6d 61 6c 6c 6f 63 28 29 60 20 69 6e 20 74 68 `malloc()` in th
fe40: 69 73 20 43 20 6c 69 62 72 61 72 79 20 61 6e 64 is C library and
fe50: 20 6e 6f 20 73 70 61 63 65 20 72 65 73 65 72 76 no space reserv
fe60: 65 64 20 66 6f 72 20 69 74 73 0a 68 65 61 70 20 ed for its.heap
fe70: 69 6e 20 5b 74 68 65 20 75 73 65 72 20 64 61 74 in [the user dat
fe80: 61 20 66 69 65 6c 64 5d 28 23 75 64 66 29 2e 20 a field](#udf).
fe90: 45 76 65 72 79 74 68 69 6e 67 20 69 6e 20 61 20 Everything in a
fea0: 43 43 38 20 70 72 6f 67 72 61 6d 20 69 73 0a 73 CC8 program is.s
feb0: 74 61 74 69 63 61 6c 6c 79 2d 61 6c 6c 6f 63 61 tatically-alloca
fec0: 74 65 64 2c 20 69 66 20 79 6f 75 e2 80 99 72 65 ted, if you’re
fed0: 20 75 73 69 6e 67 20 73 74 6f 63 6b 20 43 2d 6c using stock C-l
fee0: 65 76 65 6c 20 6d 65 63 68 61 6e 69 73 6d 73 2e evel mechanisms.
fef0: 20 49 66 20 79 6f 75 72 0a 70 72 6f 67 72 61 6d If your.program
ff00: 20 6e 65 65 64 73 20 61 64 64 69 74 69 6f 6e 61 needs additiona
ff10: 6c 20 64 79 6e 61 6d 69 63 61 6c 6c 79 2d 61 6c l dynamically-al
ff20: 6c 6f 63 61 74 65 64 20 6d 65 6d 6f 72 79 2c 20 located memory,
ff30: 79 6f 75 e2 80 99 6c 6c 20 6e 65 65 64 20 74 6f you’ll need to
ff40: 0a 61 72 72 61 6e 67 65 20 61 63 63 65 73 73 20 .arrange access
ff50: 74 6f 20 69 74 20 73 6f 6d 65 20 6f 74 68 65 72 to it some other
ff60: 20 77 61 79 2c 20 73 75 63 68 20 61 73 20 5b 76 way, such as [v
ff70: 69 61 20 69 6e 6c 69 6e 65 0a 61 73 73 65 6d 62 ia inline.assemb
ff80: 6c 79 5d 28 23 61 73 6d 29 2e 0a 0a 0a 23 23 23 ly](#asm)....###
ff90: 23 20 46 75 6e 20 54 72 69 76 69 61 3a 20 54 68 # Fun Trivia: Th
ffa0: 65 20 48 69 73 74 6f 72 79 20 6f 66 20 60 6d 61 e History of `ma
ffb0: 6c 6c 6f 63 28 29 60 0a 0a 54 68 65 72 65 20 69 lloc()`..There i
ffc0: 73 20 6e 6f 20 e2 80 9c 60 6d 61 6c 6c 6f 63 28 s no “`malloc(
ffd0: 29 60 e2 80 9d 20 69 6e 20 4b 26 52 20 43 2c 20 )`” in K&R C,
ffe0: 65 69 74 68 65 72 2c 20 61 74 20 6c 65 61 73 74 either, at least
fff0: 20 61 73 20 66 61 72 20 61 73 20 74 68 65 20 66 as far as the f
10000 69 72 73 74 0a 65 64 69 74 69 6f 6e 20 6f 66 20 irst.edition of
10010 e2 80 9c 5b 54 68 65 20 43 20 50 72 6f 67 72 61 “[The C Progra
10020 6d 6d 69 6e 67 20 4c 61 6e 67 75 61 67 65 e2 80 mming Language
10030 9d 5d 5b 6b 72 63 5d 20 67 6f 65 73 2e 20 41 62 ][krc] goes. Ab
10040 6f 75 74 20 68 61 6c 66 77 61 79 20 69 6e 74 6f out halfway into
10050 0a 74 68 65 20 62 6f 6f 6b 20 74 68 65 79 20 67 .the book they g
10060 69 76 65 20 61 20 73 69 6d 70 6c 65 20 66 75 6e ive a simple fun
10070 63 74 69 6f 6e 20 63 61 6c 6c 65 64 20 60 61 6c ction called `al
10080 6c 6f 63 28 29 60 20 74 68 61 74 20 6a 75 73 74 loc()` that just
10090 0a 64 65 74 65 72 6d 69 6e 65 64 20 77 68 65 74 .determined whet
100a0 68 65 72 20 74 68 65 20 72 65 71 75 65 73 74 65 her the requeste
100b0 64 20 61 6d 6f 75 6e 74 20 6f 66 20 73 70 61 63 d amount of spac
100c0 65 20 77 61 73 20 61 76 61 69 6c 61 62 6c 65 20 e was available
100d0 77 69 74 68 69 6e 20 61 0a 6c 61 72 67 65 20 73 within a.large s
100e0 74 61 74 69 63 20 60 63 68 61 72 5b 5d 60 20 61 tatic `char[]` a
100f0 72 72 61 79 20 69 74 20 6d 61 6e 61 67 65 64 20 rray it managed
10100 66 6f 72 20 69 74 73 20 63 61 6c 6c 65 72 73 2e for its callers.
10110 20 49 66 20 73 6f 2c 20 69 74 0a 61 64 76 61 6e If so, it.advan
10120 63 65 64 20 74 68 65 20 70 6f 69 6e 74 65 72 20 ced the pointer
10130 74 68 61 74 20 6d 75 63 68 20 66 61 72 74 68 65 that much farthe
10140 72 20 69 6e 74 6f 20 74 68 65 20 62 75 66 66 65 r into the buffe
10150 72 20 61 6e 64 20 72 65 74 75 72 6e 65 64 20 74 r and returned t
10160 68 61 74 0a 70 6f 69 6e 74 65 72 2e 20 54 68 65 hat.pointer. The
10170 20 63 6f 72 72 65 73 70 6f 6e 64 69 6e 67 20 60 corresponding `
10180 66 72 65 65 28 29 60 20 69 6d 70 6c 65 6d 65 6e free()` implemen
10190 74 61 74 69 6f 6e 20 6a 75 73 74 20 63 68 6f 70 tation just chop
101a0 70 65 64 20 74 68 65 0a 67 6c 6f 62 61 6c 6c 79 ped the.globally
101b0 2d 61 6c 6c 6f 63 61 74 65 64 20 73 70 61 63 65 -allocated space
101c0 20 6f 66 66 20 61 67 61 69 6e 2c 20 73 6f 20 69 off again, so i
101d0 66 20 79 6f 75 20 63 61 6c 6c 65 64 20 74 68 61 f you called tha
101e0 74 20 60 61 6c 6c 6f 63 28 29 60 0a 74 77 69 63 t `alloc()`.twic
101f0 65 20 61 6e 64 20 66 72 65 65 64 20 74 68 65 20 e and freed the
10200 66 69 72 73 74 20 70 6f 69 6e 74 65 72 2c 20 74 first pointer, t
10210 68 65 20 73 65 63 6f 6e 64 20 77 6f 75 6c 64 20 he second would
10220 62 65 20 69 6e 76 61 6c 69 64 2c 20 74 6f 6f 21 be invalid, too!
10230 0a 0a 54 68 65 6e 20 69 6e 20 41 70 70 65 6e 64 ..Then in Append
10240 69 78 20 41 2c 20 4b 65 72 6e 69 67 68 61 6e 20 ix A, Kernighan
10250 26 20 52 69 74 63 68 69 65 20 67 69 76 65 20 61 & Ritchie give a
10260 20 6d 75 63 68 20 73 6d 61 72 74 65 72 20 61 6c much smarter al
10270 74 65 72 6e 61 74 69 76 65 0a 62 61 73 65 64 20 ternative.based
10280 6f 6e 20 74 68 65 20 6f 6c 64 20 55 6e 69 78 20 on the old Unix
10290 73 79 73 63 61 6c 6c 20 5b 60 73 62 72 6b 28 32 syscall [`sbrk(2
102a0 29 60 5d 5b 73 62 72 6b 5d 2e 20 54 68 65 20 69 )`][sbrk]. The i
102b0 6d 70 72 65 73 73 69 6f 6e 20 67 69 76 65 6e 20 mpression given
102c0 69 73 0a 74 68 61 74 20 6d 65 6d 6f 72 79 20 61 is.that memory a
102d0 6c 6c 6f 63 61 74 69 6f 6e 20 69 73 6e e2 80 99 llocation isn’
102e0 74 20 70 61 72 74 20 6f 66 20 74 68 65 20 6c 61 t part of the la
102f0 6e 67 75 61 67 65 2c 20 69 74 e2 80 99 73 20 70 nguage, it’s p
10300 61 72 74 20 6f 66 20 74 68 65 0a 6f 70 65 72 61 art of the.opera
10310 74 69 6e 67 20 73 79 73 74 65 6d 2c 20 61 6e 64 ting system, and
10320 20 64 69 66 66 65 72 65 6e 74 20 69 6d 70 6c 65 different imple
10330 6d 65 6e 74 61 74 69 6f 6e 73 20 6f 66 20 43 20 mentations of C
10340 77 65 72 65 20 65 78 70 65 63 74 65 64 20 74 6f were expected to
10350 0a 70 72 6f 76 69 64 65 20 74 68 69 73 20 66 61 .provide this fa
10360 63 69 6c 69 74 79 20 69 6e 20 6c 6f 63 61 6c 20 cility in local
10370 77 61 79 73 2e 0a 0a 5b 56 36 20 55 4e 49 58 5d ways...[V6 UNIX]
10380 5b 76 36 75 78 5d 20 70 72 65 63 65 64 65 64 20 [v6ux] preceded
10390 4b 26 52 20 43 20 62 79 20 73 65 76 65 72 61 6c K&R C by several
103a0 20 79 65 61 72 73 2c 20 61 6e 64 20 74 68 65 72 years, and ther
103b0 65 20 69 73 20 6e 6f 0a 60 6d 61 6c 6c 6f 63 28 e is no.`malloc(
103c0 29 60 20 74 68 65 72 65 2c 20 65 69 74 68 65 72 )` there, either
103d0 2e 20 54 68 65 72 65 e2 80 99 73 20 61 6e 20 60 . There’s an `
103e0 61 6c 6c 6f 63 28 29 60 20 69 6d 70 6c 65 6d 65 alloc()` impleme
103f0 6e 74 61 74 69 6f 6e 20 69 6e 20 69 74 73 0a 60 ntation in its.`
10400 6c 69 62 63 60 20 74 68 61 74 e2 80 99 73 20 73 libc` that’s s
10410 63 61 72 63 65 6c 79 20 6d 6f 72 65 20 63 6f 6d carcely more com
10420 70 6c 69 63 61 74 65 64 20 74 68 61 6e 20 74 68 plicated than th
10430 65 20 60 63 68 61 72 5b 5d 60 20 62 61 73 65 64 e `char[]` based
10440 20 6f 6e 65 0a 66 69 72 73 74 20 70 72 65 73 65 one.first prese
10450 6e 74 65 64 20 69 6e 20 4b 26 52 2e 20 54 68 65 nted in K&R. The
10460 72 65 20 69 73 20 6e 6f 20 60 66 72 65 65 28 29 re is no `free()
10470 60 20 69 6e 20 56 36 3a 20 6e 65 77 20 61 6c 6c ` in V6: new all
10480 6f 63 61 74 69 6f 6e 73 20 6a 75 73 74 0a 6b 65 ocations just.ke
10490 65 70 20 65 78 74 65 6e 64 69 6e 67 20 74 68 65 ep extending the
104a0 20 61 6d 6f 75 6e 74 20 6f 66 20 63 6f 72 65 20 amount of core
104b0 72 65 71 75 65 73 74 65 64 2e 0a 0a 60 6d 61 6c requested...`mal
104c0 6c 6f 63 28 29 60 20 61 70 70 61 72 65 6e 74 6c loc()` apparentl
104d0 79 20 66 69 72 73 74 20 61 70 70 65 61 72 65 64 y first appeared
104e0 20 61 62 6f 75 74 20 61 20 79 65 61 72 20 61 66 about a year af
104f0 74 65 72 20 4b 26 52 20 77 61 73 0a 70 75 62 6c ter K&R was.publ
10500 69 73 68 65 64 2c 20 69 6e 20 5b 56 37 20 55 4e ished, in [V7 UN
10510 49 58 5d 5b 76 37 75 78 5d 2e 20 49 74 20 61 6e IX][v7ux]. It an
10520 64 20 69 74 73 20 63 6f 72 72 65 73 70 6f 6e 64 d its correspond
10530 69 6e 67 20 60 66 72 65 65 28 29 60 20 63 61 6c ing `free()` cal
10540 6c 0a 61 72 65 20 62 61 73 65 64 20 6f 6e 20 73 l.are based on s
10550 69 6d 69 6c 61 72 20 74 65 63 68 6e 69 71 75 65 imilar technique
10560 73 20 74 6f 20 74 68 65 20 60 73 62 72 6b 28 29 s to the `sbrk()
10570 60 2d 62 61 73 65 64 20 60 61 6c 6c 6f 63 28 29 `-based `alloc()
10580 60 20 61 6e 64 0a 60 66 72 65 65 28 29 60 20 70 ` and.`free()` p
10590 75 62 6c 69 73 68 65 64 20 69 6e 20 4b 26 52 20 ublished in K&R
105a0 41 70 70 65 6e 64 69 78 20 41 2c 20 74 68 6f 75 Appendix A, thou
105b0 67 68 20 63 6c 65 61 72 6c 79 20 77 69 74 68 20 gh clearly with
105c0 71 75 69 74 65 20 61 20 6c 6f 74 20 6f 66 0a 65 quite a lot of.e
105d0 76 6f 6c 75 74 69 6f 6e 20 62 65 74 77 65 65 6e volution between
105e0 20 74 68 65 20 74 77 6f 2e 0a 0a 5b 73 62 72 6b the two...[sbrk
105f0 5d 3a 20 68 74 74 70 73 3a 2f 2f 70 75 62 73 2e ]: https://pubs.
10600 6f 70 65 6e 67 72 6f 75 70 2e 6f 72 67 2f 6f 6e opengroup.org/on
10610 6c 69 6e 65 70 75 62 73 2f 37 39 30 38 37 39 39 linepubs/7908799
10620 2f 78 73 68 2f 62 72 6b 2e 68 74 6d 6c 0a 5b 76 /xsh/brk.html.[v
10630 36 75 78 5d 3a 20 68 74 74 70 73 3a 2f 2f 65 6e 6ux]: https://en
10640 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f 77 .wikipedia.org/w
10650 69 6b 69 2f 56 65 72 73 69 6f 6e 5f 36 5f 55 6e iki/Version_6_Un
10660 69 78 0a 5b 76 37 75 78 5d 3a 20 68 74 74 70 73 ix.[v7ux]: https
10670 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e ://en.wikipedia.
10680 6f 72 67 2f 77 69 6b 69 2f 56 65 72 73 69 6f 6e org/wiki/Version
10690 5f 37 5f 55 6e 69 78 0a 0a 0a 23 23 23 20 3c 61 _7_Unix...### <a
106a0 20 69 64 3d 22 76 6f 6e 6e 22 3e 3c 2f 61 3e 54 id="vonn"></a>T
106b0 68 65 72 65 20 41 72 65 20 4e 6f 20 53 74 6f 72 here Are No Stor
106c0 61 67 65 20 54 79 70 65 20 44 69 73 74 69 6e 63 age Type Distinc
106d0 74 69 6f 6e 73 0a 0a 4c 69 74 65 72 61 6c 73 20 tions..Literals
106e0 61 72 65 20 70 6c 61 63 65 64 20 69 6e 20 74 68 are placed in th
106f0 65 20 73 61 6d 65 20 66 69 65 6c 64 20 61 73 20 e same field as
10700 67 6c 6f 62 61 6c 73 20 61 6e 64 20 74 68 65 20 globals and the
10710 63 61 6c 6c 20 73 74 61 63 6b 2c 0a 72 61 74 68 call stack,.rath
10720 65 72 20 74 68 61 74 20 69 6e 6c 69 6e 65 20 77 er that inline w
10730 69 74 68 69 6e 20 74 68 65 20 67 65 6e 65 72 61 ithin the genera
10740 74 65 64 20 65 78 65 63 75 74 61 62 6c 65 20 63 ted executable c
10750 6f 64 65 2e 20 54 68 69 73 20 6d 61 79 20 63 61 ode. This may ca
10760 75 73 65 0a 73 75 72 70 72 69 73 65 20 73 69 7a use.surprise siz
10770 65 20 6c 69 6d 69 74 61 74 69 6f 6e 73 20 6f 66 e limitations of
10780 20 74 68 65 20 75 73 65 72 20 70 72 6f 67 72 61 the user progra
10790 6d 73 2e 0a 0a 43 43 38 20 64 6f 65 73 20 69 74 ms...CC8 does it
107a0 20 74 68 69 73 20 77 61 79 20 62 65 63 61 75 73 this way becaus
107b0 65 20 74 68 65 20 46 4f 52 54 52 41 4e 20 49 49 e the FORTRAN II
107c0 20 2f 20 53 41 42 52 20 73 79 73 74 65 6d 20 64 / SABR system d
107d0 6f 65 73 20 61 6c 6c 6f 77 20 61 6e 79 0a 69 6e oes allow any.in
107e0 69 74 69 61 6c 69 73 61 74 69 6f 6e 20 6f 66 20 itialisation of
107f0 43 4f 4d 4d 4f 4e 20 73 74 6f 72 61 67 65 20 69 COMMON storage i
10800 6e 20 66 69 65 6c 64 20 31 2c 20 73 6f 20 74 68 n field 1, so th
10810 65 20 6c 69 74 65 72 61 6c 73 20 68 61 76 65 20 e literals have
10820 74 6f 20 62 65 0a 73 74 6f 72 65 64 20 69 6e 20 to be.stored in
10830 74 68 65 20 75 73 65 72 20 70 72 6f 67 72 61 6d the user program
10840 20 70 61 67 65 20 61 6e 64 20 74 68 65 6e 20 62 page and then b
10850 65 20 63 6f 70 69 65 64 20 69 6e 74 6f 20 66 69 e copied into fi
10860 65 6c 64 20 31 20 61 74 0a 70 72 6f 67 72 61 6d eld 1 at.program
10870 20 69 6e 69 74 69 61 6c 69 7a 61 74 69 6f 6e 20 initialization
10880 74 69 6d 65 2e 20 20 56 61 72 69 6f 75 73 20 70 time. Various p
10890 6f 69 6e 74 65 72 73 20 74 6f 20 74 68 65 73 65 ointers to these
108a0 20 72 65 67 69 6f 6e 73 20 61 72 65 0a 6d 61 69 regions are.mai
108b0 6e 61 74 69 6e 65 64 20 62 79 20 74 68 65 20 63 natined by the c
108c0 6f 6d 70 69 6c 65 72 2e 0a 0a 0a 23 23 23 20 3c ompiler....### <
108d0 61 20 69 64 3d 22 73 6f 76 65 72 22 3e 3c 2f 61 a id="sover"></a
108e0 3e 53 74 61 63 6b 20 4f 76 65 72 66 6c 6f 77 0a >Stack Overflow.
108f0 0a 53 69 6e 63 65 20 43 43 38 20 70 6c 61 63 65 .Since CC8 place
10900 73 20 74 68 65 20 63 61 6c 6c 20 73 74 61 63 6b s the call stack
10910 20 69 6d 6d 65 64 69 61 74 65 6c 79 20 61 66 74 immediately aft
10920 65 72 20 74 68 65 20 6c 61 73 74 20 6c 69 74 65 er the last lite
10930 72 61 6c 0a 73 74 6f 72 65 64 20 69 6e 20 63 6f ral.stored in co
10940 72 65 2c 20 61 20 70 72 6f 67 72 61 6d 20 77 69 re, a program wi
10950 74 68 20 6d 61 6e 79 20 67 6c 6f 62 61 6c 73 20 th many globals
10960 61 6e 64 2f 6f 72 20 6c 69 74 65 72 61 6c 73 20 and/or literals
10970 77 69 6c 6c 20 68 61 76 65 0a 6c 65 73 73 20 75 will have.less u
10980 73 61 62 6c 65 20 73 74 61 63 6b 20 73 70 61 63 sable stack spac
10990 65 20 74 68 61 6e 20 61 20 70 72 6f 67 72 61 6d e than a program
109a0 20 77 69 74 68 20 66 65 77 65 72 20 6f 66 20 65 with fewer of e
109b0 61 63 68 2e 0a 0a 4e 65 69 74 68 65 72 20 76 65 ach...Neither ve
109c0 72 73 69 6f 6e 20 6f 66 20 43 43 38 20 67 65 6e rsion of CC8 gen
109d0 65 72 61 74 65 73 20 63 6f 64 65 20 74 6f 20 64 erates code to d
109e0 65 74 65 63 74 20 73 74 61 63 6b 20 6f 76 65 72 etect stack over
109f0 66 6c 6f 77 2e 20 49 66 20 79 6f 75 0a 74 72 79 flow. If you.try
10a00 20 74 6f 20 70 75 73 68 20 74 6f 6f 20 6d 75 63 to push too muc
10a10 68 20 6f 6e 74 6f 20 74 68 65 20 73 74 61 63 6b h onto the stack
10a20 2c 20 69 74 20 77 69 6c 6c 20 73 69 6d 70 6c 79 , it will simply
10a30 20 62 65 67 69 6e 20 6f 76 65 72 77 72 69 74 69 begin overwriti
10a40 6e 67 0a 74 68 65 20 70 61 67 65 20 4f 53 2f 38 ng.the page OS/8
10a50 20 69 73 20 75 73 69 6e 67 20 61 74 20 74 68 65 is using at the
10a60 20 74 6f 70 20 6f 66 20 66 69 65 6c 64 20 31 2e top of field 1.
10a70 20 49 66 20 79 6f 75 20 6d 61 6e 61 67 65 20 74 If you manage t
10a80 6f 20 62 6c 6f 77 20 74 68 65 0a 73 74 61 63 6b o blow the.stack
10a90 20 62 79 20 6d 6f 72 65 20 74 68 61 6e 20 61 20 by more than a
10aa0 70 61 67 65 20 77 69 74 68 6f 75 74 20 63 72 61 page without cra
10ab0 73 68 69 6e 67 20 74 68 65 20 70 72 6f 67 72 61 shing the progra
10ac0 6d 20 6f 72 20 74 68 65 20 63 6f 6d 70 75 74 65 m or the compute
10ad0 72 0a 66 69 72 73 74 2c 20 74 68 65 20 5b 73 74 r.first, the [st
10ae0 61 63 6b 20 70 6f 69 6e 74 65 72 20 77 69 6c 6c ack pointer will
10af0 20 77 72 61 70 20 61 72 6f 75 6e 64 5d 28 23 70 wrap around](#p
10b00 74 72 77 72 61 70 29 20 61 6e 64 20 74 68 65 20 trwrap) and the
10b10 73 74 61 63 6b 20 77 69 6c 6c 0a 62 65 67 69 6e stack will.begin
10b20 20 6f 76 65 72 77 72 69 74 69 6e 67 20 74 68 65 overwriting the
10b30 20 66 69 72 73 74 20 70 61 67 65 20 6f 66 20 66 first page of f
10b40 69 65 6c 64 20 31 2e 0a 0a 0a 23 23 23 20 3c 61 ield 1....### <a
10b50 20 69 64 3d 22 66 6c 61 79 6f 75 74 22 3e 3c 2f id="flayout"></
10b60 61 3e 46 69 65 6c 64 20 4c 61 79 6f 75 74 2c 20 a>Field Layout,
10b70 43 6f 6e 63 72 65 74 65 20 45 78 61 6d 70 6c 65 Concrete Example
10b80 0a 0a 54 68 65 20 66 69 65 6c 64 20 6c 61 79 6f ..The field layo
10b90 75 74 20 67 69 76 65 6e 20 5b 61 74 20 74 68 65 ut given [at the
10ba0 20 73 74 61 72 74 20 6f 66 20 74 68 69 73 20 73 start of this s
10bb0 65 63 74 69 6f 6e 5d 28 23 6d 65 6d 6f 72 79 29 ection](#memory)
10bc0 20 69 73 20 6e 6f 74 0a 66 69 78 65 64 2e 20 54 is not.fixed. T
10bd0 68 65 20 6c 69 6e 6b 69 6e 67 20 6c 6f 61 64 65 he linking loade
10be0 72 20 69 73 20 66 72 65 65 20 74 6f 20 75 73 65 r is free to use
10bf0 20 61 6e 79 20 6c 61 79 6f 75 74 20 69 74 20 6c any layout it l
10c00 69 6b 65 73 2c 20 63 6f 6e 73 69 73 74 65 6e 74 ikes, consistent
10c10 0a 77 69 74 68 20 61 6e 79 20 63 6f 6e 73 74 72 .with any constr
10c20 61 69 6e 74 73 20 69 6e 20 74 68 65 20 69 6e 70 aints in the inp
10c30 75 74 20 62 69 6e 61 72 69 65 73 2e 20 59 6f 75 ut binaries. You
10c40 20 63 61 6e 20 75 73 65 20 74 68 65 20 60 2f 4d can use the `/M
10c50 60 20 6f 70 74 69 6f 6e 0a 77 69 74 68 20 60 4c ` option.with `L
10c60 4f 41 44 45 52 2e 53 56 60 20 74 6f 20 67 65 74 OADER.SV` to get
10c70 20 61 20 63 6f 72 65 20 6d 65 6d 6f 72 79 20 6d a core memory m
10c80 61 70 20 66 6f 72 20 61 20 67 69 76 65 6e 20 6f ap for a given o
10c90 75 74 70 75 74 2e 20 4c 65 74 e2 80 99 73 20 77 utput. Let’s w
10ca0 6f 72 6b 0a 61 6e 20 65 78 61 6d 70 6c 65 20 75 ork.an example u
10cb0 73 69 6e 67 20 74 68 65 20 60 70 73 2e 63 60 20 sing the `ps.c`
10cc0 65 78 61 6d 70 6c 65 20 70 72 6f 67 72 61 6d 3a example program:
10cd0 0a 0a 20 20 20 20 2e 52 20 43 43 0a 20 20 20 20 .. .R CC.
10ce0 3e 70 73 2e 63 0a 20 20 20 20 2e 43 4f 4d 50 20 >ps.c. .COMP
10cf0 43 43 2e 53 42 0a 20 20 20 20 2e 52 20 4c 4f 41 CC.SB. .R LOA
10d00 44 45 52 0a 20 20 20 20 2a 43 43 2c 4c 49 42 43 DER. *CC,LIBC
10d10 2f 49 2f 4f 2f 4d 0a 20 20 20 20 56 20 34 41 0a /I/O/M. V 4A.
10d20 20 20 20 20 4d 41 49 4e 20 20 20 20 30 31 30 30 MAIN 0100
10d30 30 0a 20 20 20 20 4c 49 42 43 20 20 20 20 32 30 0. LIBC 20
10d40 32 30 34 0a 20 20 20 20 4f 50 45 4e 20 20 20 20 204. OPEN
10d50 30 30 30 30 30 20 55 0a 20 20 20 20 45 58 49 54 00000 U. EXIT
10d60 20 20 20 20 30 30 30 30 30 20 55 0a 20 20 20 20 00000 U.
10d70 2e 2e 2e 0a 0a 54 68 65 20 60 4d 41 49 4e 60 20 .....The `MAIN`
10d80 6c 69 6e 65 20 74 65 6c 6c 73 20 75 73 20 74 68 line tells us th
10d90 61 74 20 60 4c 4f 41 44 45 52 2e 53 56 60 20 68 at `LOADER.SV` h
10da0 61 73 20 63 68 6f 73 65 6e 20 74 6f 20 70 6c 61 as chosen to pla
10db0 63 65 20 6f 75 72 20 43 0a 70 72 6f 67 72 61 6d ce our C.program
10dc0 20 69 6e 20 66 69 65 6c 64 20 30 2c 20 6e 6f 74 in field 0, not
10dd0 20 66 69 65 6c 64 20 32 20 61 73 20 73 75 67 67 field 2 as sugg
10de0 65 73 74 65 64 20 61 62 6f 76 65 2e 0a 0a 28 54 ested above...(T
10df0 68 69 73 20 69 73 20 6e 6f 74 20 74 6f 20 62 65 his is not to be
10e00 20 63 6f 6e 66 75 73 65 64 20 77 69 74 68 20 74 confused with t
10e10 68 65 20 43 20 60 6d 61 69 6e 28 29 60 20 2a 66 he C `main()` *f
10e20 75 6e 63 74 69 6f 6e 2a 3a 20 77 65 e2 80 99 72 unction*: we’r
10e30 65 0a 76 69 65 77 69 6e 67 20 74 68 69 6e 67 73 e.viewing things
10e40 20 66 72 6f 6d 20 74 68 65 20 46 4f 52 54 52 41 from the FORTRA
10e50 4e 20 49 49 20 6c 65 76 65 6c 20 68 65 72 65 2c N II level here,
10e60 20 6e 6f 74 20 74 68 65 20 43 20 6c 65 76 65 6c not the C level
10e70 2e 20 60 4d 41 49 4e 60 0a 69 73 20 74 68 65 20 . `MAIN`.is the
10e80 6e 61 6d 65 20 6f 66 20 74 68 65 20 77 68 6f 6c name of the whol
10e90 65 20 6d 6f 64 75 6c 65 20 61 73 20 66 61 72 20 e module as far
10ea0 61 73 20 60 4c 4f 41 44 45 52 2e 53 56 60 20 69 as `LOADER.SV` i
10eb0 73 20 63 6f 6e 63 65 72 6e 65 64 2e 29 0a 0a 54 s concerned.)..T
10ec0 68 65 20 6c 6f 61 64 65 72 20 64 6f 75 62 74 6c he loader doubtl
10ed0 65 73 73 20 64 69 64 20 74 68 69 73 20 62 65 63 ess did this bec
10ee0 61 75 73 65 20 60 70 73 2e 63 60 20 69 73 20 73 ause `ps.c` is s
10ef0 6d 61 6c 6c 2c 20 73 6f 20 74 68 65 72 65 20 77 mall, so there w
10f00 61 73 20 6d 6f 72 65 0a 74 68 61 6e 20 65 6e 6f as more.than eno
10f10 75 67 68 20 73 70 61 63 65 20 69 6e 20 66 69 65 ugh space in fie
10f20 6c 64 20 30 20 74 6f 20 68 6f 6c 64 20 6f 75 72 ld 0 to hold our
10f30 20 60 4d 41 49 4e 60 20 6d 6f 64 75 6c 65 20 61 `MAIN` module a
10f40 6e 64 20 61 6c 6c 20 6f 66 20 74 68 65 0a 46 4f nd all of the.FO
10f50 52 54 52 41 4e 20 49 49 20 6c 69 62 72 61 72 79 RTRAN II library
10f60 20 72 6f 75 74 69 6e 65 73 20 69 74 20 6e 65 65 routines it nee
10f70 64 73 2e 20 57 65 e2 80 99 6c 6c 20 73 65 65 20 ds. We’ll see
10f80 68 6f 77 20 6d 75 63 68 20 6d 6f 72 65 20 62 65 how much more be
10f90 6c 6f 77 2e 0a 0a 54 68 65 20 6d 61 70 20 74 68 low...The map th
10fa0 65 6e 20 74 65 6c 6c 73 20 75 73 20 74 68 61 74 en tells us that
10fb0 20 4c 49 42 43 20 69 73 20 69 6e 20 66 69 65 6c LIBC is in fiel
10fc0 64 20 32 2c 20 6e 6f 74 20 33 20 61 73 20 73 75 d 2, not 3 as su
10fd0 67 67 65 73 74 65 64 20 61 62 6f 76 65 2e 0a 54 ggested above..T
10fe0 68 69 73 20 69 73 20 61 67 61 69 6e 20 61 20 63 his is again a c
10ff0 6f 6e 73 65 71 75 65 6e 63 65 20 6f 66 20 6e 6f onsequence of no
11000 74 20 6e 65 65 64 69 6e 67 20 74 77 6f 20 73 65 t needing two se
11010 70 61 72 61 74 65 20 66 69 65 6c 64 73 20 66 6f parate fields fo
11020 72 20 74 68 65 0a 46 4f 52 54 52 41 4e 20 49 49 r the.FORTRAN II
11030 20 6c 69 62 72 61 72 79 20 61 6e 64 20 74 68 65 library and the
11040 20 60 4d 41 49 4e 60 20 6d 6f 64 75 6c 65 2e 0a `MAIN` module..
11050 0a 54 68 65 20 e2 80 9c 30 30 30 30 30 20 55 e2 .The “00000 U
11060 80 9d 20 6c 69 6e 65 73 20 6f 6e 20 65 61 63 68 lines on each
11070 20 6f 66 20 74 68 65 20 46 4f 52 54 52 41 4e 20 of the FORTRAN
11080 49 49 20 6c 69 62 72 61 72 79 20 72 6f 75 74 69 II library routi
11090 6e 65 20 6c 6f 63 61 74 69 6f 6e 73 0a 74 65 6c ne locations.tel
110a0 6c 20 75 73 20 74 68 61 74 20 74 68 6f 73 65 20 l us that those
110b0 6c 6f 63 61 74 69 6f 6e 73 20 68 61 64 6e e2 80 locations hadn
110c0 99 74 20 79 65 74 20 62 65 65 6e 20 64 65 74 65 t yet been dete
110d0 72 6d 69 6e 65 64 20 61 74 20 74 68 65 20 74 69 rmined at the ti
110e0 6d 65 20 69 74 0a 77 61 73 20 74 6f 6c 64 20 74 me it.was told t
110f0 6f 20 70 72 6f 64 75 63 65 20 74 68 65 20 63 6f o produce the co
11100 72 65 20 6d 61 70 2e 20 28 55 20 3d 20 e2 80 9c re map. (U = “
11110 75 6e 64 65 66 69 6e 65 64 2e e2 80 9d 29 0a 0a undefined.”)..
11120 49 66 20 77 65 20 77 61 6e 74 20 74 6f 20 70 69 If we want to pi
11130 6e 20 64 6f 77 6e 20 74 68 65 20 6c 6f 63 61 74 n down the locat
11140 69 6f 6e 20 6f 66 20 74 68 6f 73 65 20 46 4f 52 ion of those FOR
11150 54 52 41 4e 20 49 49 20 72 6f 75 74 69 6e 65 73 TRAN II routines
11160 2c 20 77 65 20 63 61 6e 0a 61 73 6b 20 74 68 65 , we can.ask the
11170 20 6c 6f 61 64 65 72 20 74 6f 20 67 69 76 65 20 loader to give
11180 75 73 20 74 68 65 20 6d 61 70 20 2a 61 66 74 65 us the map *afte
11190 72 2a 20 69 74 e2 80 99 73 20 66 69 6e 61 6c 69 r* it’s finali
111a0 7a 65 64 20 65 76 65 72 79 74 68 69 6e 67 20 62 zed everything b
111b0 79 0a 74 65 6c 6c 69 6e 67 20 69 74 20 74 6f 20 y.telling it to
111c0 72 75 6e 20 74 68 65 20 70 72 6f 67 72 61 6d 20 run the program
111d0 28 60 2f 47 60 29 2c 20 74 68 65 6e 20 67 69 76 (`/G`), then giv
111e0 65 20 75 73 20 74 68 65 20 6d 61 70 3a 0a 0a 20 e us the map:..
111f0 20 20 20 2a 43 43 2c 4c 49 42 43 2f 49 2f 4f 2f *CC,LIBC/I/O/
11200 47 2f 4d 0a 20 20 20 20 56 20 34 41 0a 20 20 20 G/M. V 4A.
11210 20 4d 41 49 4e 20 20 20 20 30 32 34 30 30 0a 20 MAIN 02400.
11220 20 20 20 4c 49 42 43 20 20 20 20 32 30 32 30 34 LIBC 20204
11230 0a 20 20 20 20 4f 50 45 4e 20 20 20 20 30 33 36 . OPEN 036
11240 33 33 0a 20 20 20 20 45 58 49 54 20 20 20 20 30 33. EXIT 0
11250 34 31 33 33 0a 20 20 20 20 4d 50 59 20 20 20 20 4133. MPY
11260 20 30 34 32 30 36 0a 20 20 20 20 43 48 52 49 4f 04206. CHRIO
11270 20 20 20 32 30 34 37 30 0a 20 20 20 20 47 45 4e 20470. GEN
11280 49 4f 20 20 20 30 33 34 30 33 0a 20 20 20 20 4f IO 03403. O
11290 4f 50 45 4e 20 20 20 30 34 36 32 35 0a 20 20 20 OPEN 04625.
112a0 20 49 4f 50 45 4e 20 20 20 30 34 36 30 32 0a 20 IOPEN 04602.
112b0 20 20 20 4f 43 4c 4f 53 20 20 20 30 34 36 34 37 OCLOS 04647
112c0 0a 20 20 20 20 44 49 56 20 20 20 20 20 30 34 32 . DIV 042
112d0 35 31 0a 20 20 20 20 49 52 45 4d 20 20 20 20 30 51. IREM 0
112e0 34 33 35 35 0a 20 20 20 20 45 52 52 4f 52 20 20 4355. ERROR
112f0 20 30 34 30 31 33 0a 20 20 20 20 43 4b 49 4f 20 04013. CKIO
11300 20 20 20 30 34 31 34 31 0a 20 20 20 20 43 4c 45 04141. CLE
11310 41 52 20 20 20 30 34 34 33 37 0a 20 20 20 20 49 AR 04437. I
11320 41 42 53 20 20 20 20 30 34 34 30 30 0a 20 20 20 ABS 04400.
11330 20 49 52 44 53 57 20 20 20 30 34 34 32 31 0a 20 IRDSW 04421.
11340 20 20 20 53 55 42 53 43 20 20 20 30 34 34 36 32 SUBSC 04462
11350 0a 20 20 20 20 43 48 41 49 4e 20 20 20 30 34 37 . CHAIN 047
11360 33 33 0a 20 20 20 20 30 30 31 33 0a 20 20 20 20 33. 0013.
11370 30 30 30 30 0a 20 20 20 20 30 30 30 30 0a 20 20 0000. 0000.
11380 20 20 30 30 33 36 0a 20 20 20 20 30 30 33 36 0a 0036. 0036.
11390 20 20 20 20 30 30 33 36 0a 20 20 20 20 30 30 33 0036. 003
113a0 36 0a 20 20 20 20 30 30 33 36 0a 0a 4e 6f 77 20 6. 0036..Now
113b0 77 65 20 63 61 6e 20 73 65 65 20 74 68 61 74 2c we can see that,
113c0 20 69 6e 64 65 65 64 2c 20 61 6c 6c 20 6f 66 20 indeed, all of
113d0 74 68 65 20 46 4f 52 54 52 41 4e 20 49 49 20 6c the FORTRAN II l
113e0 69 62 72 61 72 79 20 72 6f 75 74 69 6e 65 73 20 ibrary routines
113f0 64 69 64 0a 69 6e 20 66 61 63 74 20 6c 61 6e 64 did.in fact land
11400 20 69 6e 20 66 69 65 6c 64 20 30 2e 0a 0a 54 68 in field 0...Th
11410 65 20 74 61 69 6c 20 65 6e 64 20 6f 66 20 74 68 e tail end of th
11420 65 20 6d 61 70 20 66 69 6c 65 20 69 73 20 61 6c e map file is al
11430 73 6f 20 68 65 6c 70 66 75 6c 2e 20 54 68 65 72 so helpful. Ther
11440 65 20 61 72 65 20 38 20 6c 69 6e 65 73 20 61 74 e are 8 lines at
11450 20 74 68 65 0a 65 6e 64 20 66 6f 72 20 61 20 33 the.end for a 3
11460 32 26 6e 62 73 70 3b 6b 57 6f 72 64 20 6d 61 63 2 kWord mac
11470 68 69 6e 65 2c 20 6f 6e 65 20 66 6f 72 20 65 61 hine, one for ea
11480 63 68 20 66 69 65 6c 64 2e 20 54 68 65 20 76 61 ch field. The va
11490 6c 75 65 20 69 73 20 74 68 65 0a 6e 75 6d 62 65 lue is the.numbe
114a0 72 20 6f 66 20 63 6f 72 65 20 6d 65 6d 6f 72 79 r of core memory
114b0 20 70 61 67 65 73 20 6c 65 66 74 20 66 72 65 65 pages left free
114c0 2c 20 69 6e 20 6f 63 74 61 6c 2c 20 61 66 74 65 , in octal, afte
114d0 72 20 6c 6f 61 64 69 6e 67 20 74 68 65 0a 70 72 r loading the.pr
114e0 6f 67 72 61 6d 2e 0a 0a 54 68 69 73 20 74 65 6c ogram...This tel
114f0 6c 73 20 75 73 20 74 68 61 74 20 66 69 65 6c 64 ls us that field
11500 20 30 20 68 61 73 20 31 33 e2 82 88 20 70 61 67 0 has 13₈ pag
11510 65 73 20 66 72 65 65 2c 20 67 69 76 69 6e 67 20 es free, giving
11520 75 73 20 61 74 20 6c 65 61 73 74 20 32 36 30 30 us at least 2600
11530 e2 82 88 0a 77 6f 72 64 73 20 6f 66 20 73 70 61 ₈.words of spa
11540 63 65 20 74 6f 20 75 73 65 20 77 69 74 68 20 43 ce to use with C
11550 20 63 6f 64 65 20 61 6e 64 20 46 4f 52 54 52 41 code and FORTRA
11560 4e 20 49 49 20 6c 69 62 72 61 72 79 20 72 65 66 N II library ref
11570 65 72 65 6e 63 65 73 0a 62 65 66 6f 72 65 20 74 erences.before t
11580 68 65 20 6c 6f 61 64 65 72 20 77 69 6c 6c 20 62 he loader will b
11590 65 20 66 6f 72 63 65 64 20 74 6f 20 70 75 74 20 e forced to put
115a0 60 4d 41 49 4e 60 20 69 6e 20 61 20 73 65 70 61 `MAIN` in a sepa
115b0 72 61 74 65 20 66 69 65 6c 64 2e 0a 0a 46 69 65 rate field...Fie
115c0 6c 64 73 20 31 20 61 6e 64 20 32 20 61 72 65 20 lds 1 and 2 are
115d0 6d 61 72 6b 65 64 20 61 73 20 77 68 6f 6c 6c 79 marked as wholly
115e0 20 75 73 65 64 20 75 70 2e 20 54 68 69 73 20 69 used up. This i
115f0 73 20 61 6e 6f 74 68 65 72 20 67 6f 6f 64 20 63 s another good c
11600 6c 75 65 0a 74 68 61 74 20 74 68 69 73 20 69 73 lue.that this is
11610 20 74 68 65 20 55 44 46 20 69 73 20 69 6e 20 66 the UDF is in f
11620 69 65 6c 64 20 31 20 69 6e 20 74 68 69 73 20 70 ield 1 in this p
11630 72 6f 67 72 61 6d 2c 20 73 69 6e 63 65 20 77 65 rogram, since we
11640 20 6b 6e 6f 77 20 4c 49 42 43 0a 69 73 20 69 6e know LIBC.is in
11650 20 66 69 65 6c 64 20 32 2e 20 45 76 65 72 79 20 field 2. Every
11660 6c 61 73 74 20 77 6f 72 64 20 6f 66 20 74 68 65 last word of the
11670 73 65 20 70 61 67 65 73 20 69 73 6e e2 80 99 74 se pages isn’t
11680 20 61 63 74 75 61 6c 6c 79 20 69 6e 20 75 73 65 actually in use
11690 2c 20 62 75 74 0a 74 68 65 20 4c 4f 41 44 45 52 , but.the LOADER
116a0 20 63 6f 6e 73 69 64 65 72 73 20 74 68 65 73 65 considers these
116b0 20 73 70 61 63 65 73 20 68 61 6e 64 73 2d 6f 66 spaces hands-of
116c0 66 20 61 73 20 66 61 72 20 61 73 20 6c 6f 61 64 f as far as load
116d0 69 6e 67 20 6f 74 68 65 72 0a 63 6f 64 65 2e 0a ing other.code..
116e0 0a 54 68 65 20 76 61 6c 75 65 20 33 36 e2 82 88 .The value 36₈
116f0 20 69 6e 20 74 68 65 20 72 65 6d 61 69 6e 69 6e in the remainin
11700 67 20 6c 69 6e 65 73 20 72 65 66 6c 65 63 74 73 g lines reflects
11710 20 74 68 65 20 77 61 79 20 74 68 65 20 6c 6f 61 the way the loa
11720 64 65 72 20 77 6f 72 6b 73 2e 0a 54 68 65 20 73 der works..The s
11730 69 7a 65 20 6f 66 20 61 20 63 6f 72 65 20 6d 65 ize of a core me
11740 6d 6f 72 79 20 66 69 65 6c 64 20 69 6e 20 74 68 mory field in th
11750 65 20 50 44 50 2d 38 20 69 73 20 34 30 e2 82 88 e PDP-8 is 40₈
11760 20 70 61 67 65 73 2e 20 54 68 65 20 6c 6f 77 65 pages. The lowe
11770 73 74 0a 70 61 67 65 20 69 73 20 5b 73 65 74 20 st.page is [set
11780 61 73 69 64 65 20 66 6f 72 20 75 73 65 20 62 79 aside for use by
11790 20 4c 4f 41 44 45 52 20 69 74 73 65 6c 66 5d 28 LOADER itself](
117a0 23 6c 64 72 74 73 29 2e 20 54 68 65 20 72 65 6d #ldrts). The rem
117b0 61 69 6e 69 6e 67 20 33 0a 70 61 67 65 73 20 70 aining 3.pages p
117c0 65 72 20 66 69 65 6c 64 20 61 72 65 20 64 75 65 er field are due
117d0 20 74 6f 20 6f 75 72 20 75 73 65 20 6f 66 20 64 to our use of d
117e0 65 76 69 63 65 2d 69 6e 64 65 70 65 6e 64 65 6e evice-independen
117f0 74 20 49 2f 4f 2c 20 72 65 71 75 65 73 74 65 64 t I/O, requested
11800 0a 66 72 6f 6d 20 4c 4f 41 44 45 52 20 77 69 74 .from LOADER wit
11810 68 20 74 68 65 20 60 2f 49 2f 4f 60 20 66 6c 61 h the `/I/O` fla
11820 67 73 2e 20 50 72 6f 67 72 61 6d 73 20 6e 6f 74 gs. Programs not
11830 20 6e 65 65 64 69 6e 67 20 74 68 61 74 20 63 61 needing that ca
11840 6e 20 73 61 76 65 0a 62 65 74 77 65 65 6e 20 31 n save.between 1
11850 20 61 6e 64 20 33 20 6f 66 20 74 68 65 73 65 20 and 3 of these
11860 70 61 67 65 73 20 70 65 72 20 66 69 65 6c 64 2e pages per field.
11870 0a 0a 46 6f 72 20 6d 6f 72 65 20 6f 6e 20 74 68 ..For more on th
11880 69 73 20 74 6f 70 69 63 2c 20 73 65 65 20 74 68 is topic, see th
11890 65 20 63 6f 6d 70 61 6e 69 6f 6e 20 61 72 74 69 e companion arti
118a0 63 6c 65 20 5b 50 44 50 2d 38 20 4d 65 6d 6f 72 cle [PDP-8 Memor
118b0 79 0a 41 64 64 72 65 73 73 69 6e 67 5d 5b 6d 65 y.Addressing][me
118c0 6d 61 64 64 5d 2e 0a 0a 0a 5b 6d 65 6d 61 64 64 madd]....[memadd
118d0 5d 3a 20 2f 77 69 6b 69 3f 6e 61 6d 65 3d 50 44 ]: /wiki?name=PD
118e0 50 2d 38 2b 4d 65 6d 6f 72 79 2b 41 64 64 72 65 P-8+Memory+Addre
118f0 73 73 69 6e 67 0a 5b 6f 73 38 6b 62 64 5d 3a 20 ssing.[os8kbd]:
11900 68 74 74 70 73 3a 2f 2f 61 72 63 68 69 76 65 2e https://archive.
11910 6f 72 67 2f 64 65 74 61 69 6c 73 2f 62 69 74 73 org/details/bits
11920 61 76 65 72 73 5f 64 65 63 70 64 70 38 6f 73 38 avers_decpdp8os8
11930 75 70 5f 35 35 36 36 34 39 35 2f 70 61 67 65 2f up_5566495/page/
11940 6e 39 0a 5b 6f 73 38 6f 66 74 5d 3a 20 68 74 74 n9.[os8oft]: htt
11950 70 73 3a 2f 2f 61 72 63 68 69 76 65 2e 6f 72 67 ps://archive.org
11960 2f 64 65 74 61 69 6c 73 2f 62 69 74 73 61 76 65 /details/bitsave
11970 72 73 5f 64 65 63 70 64 70 38 6f 73 38 75 70 5f rs_decpdp8os8up_
11980 35 35 36 36 34 39 35 2f 70 61 67 65 2f 6e 33 35 5566495/page/n35
11990 0a 5b 6f 73 38 72 65 73 5d 3a 20 68 74 74 70 73 .[os8res]: https
119a0 3a 2f 2f 61 72 63 68 69 76 65 2e 6f 72 67 2f 64 ://archive.org/d
119b0 65 74 61 69 6c 73 2f 62 69 74 73 61 76 65 72 73 etails/bitsavers
119c0 5f 64 65 63 70 64 70 38 6f 73 38 75 70 5f 35 35 _decpdp8os8up_55
119d0 36 36 34 39 35 2f 70 61 67 65 2f 6e 36 39 0a 5b 66495/page/n69.[
119e0 6f 73 38 75 73 72 5d 3a 20 68 74 74 70 73 3a 2f os8usr]: https:/
119f0 2f 61 72 63 68 69 76 65 2e 6f 72 67 2f 64 65 74 /archive.org/det
11a00 61 69 6c 73 2f 62 69 74 73 61 76 65 72 73 5f 64 ails/bitsavers_d
11a10 65 63 70 64 70 38 6f 73 38 75 70 5f 35 35 36 36 ecpdp8os8up_5566
11a20 34 39 35 2f 70 61 67 65 2f 6e 31 37 0a 5b 75 62 495/page/n17.[ub
11a30 5d 3a 20 20 20 20 20 68 74 74 70 73 3a 2f 2f 65 ]: https://e
11a40 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f n.wikipedia.org/
11a50 77 69 6b 69 2f 55 6e 64 65 66 69 6e 65 64 5f 62 wiki/Undefined_b
11a60 65 68 61 76 69 6f 72 0a 5b 7a 70 5d 3a 20 20 20 ehavior.[zp]:
11a70 20 20 68 74 74 70 73 3a 2f 2f 68 6f 6d 65 70 61 https://homepa
11a80 67 65 2e 64 69 76 6d 73 2e 75 69 6f 77 61 2e 65 ge.divms.uiowa.e
11a90 64 75 2f 7e 6a 6f 6e 65 73 2f 70 64 70 38 2f 6d du/~jones/pdp8/m
11aa0 61 6e 2f 6d 72 69 2e 68 74 6d 6c 23 70 61 67 65 an/mri.html#page
11ab0 7a 65 72 6f 0a 0a 0a 3c 61 20 69 64 3d 22 61 73 zero...<a id="as
11ac0 6d 22 3e 3c 2f 61 3e 0a 23 23 20 49 6e 6c 69 6e m"></a>.## Inlin
11ad0 65 20 41 73 73 65 6d 62 6c 79 20 43 6f 64 65 0a e Assembly Code.
11ae0 0a 42 6f 74 68 20 74 68 65 20 5b 63 72 6f 73 73 .Both the [cross
11af0 2d 63 6f 6d 70 69 6c 65 72 5d 28 23 63 72 6f 73 -compiler](#cros
11b00 73 29 20 61 6e 64 20 74 68 65 20 5b 6e 61 74 69 s) and the [nati
11b10 76 65 20 63 6f 6d 70 69 6c 65 72 5d 28 23 6e 61 ve compiler](#na
11b20 74 69 76 65 29 0a 61 6c 6c 6f 77 20 69 6e 6c 69 tive).allow inli
11b30 6e 65 20 5b 53 41 42 52 5d 5b 73 61 62 72 5d 20 ne [SABR][sabr]
11b40 61 73 73 65 6d 62 6c 79 20 63 6f 64 65 20 62 65 assembly code be
11b50 74 77 65 65 6e 20 60 23 61 73 6d 60 20 61 6e 64 tween `#asm` and
11b60 20 60 23 65 6e 64 61 73 6d 60 0a 6d 61 72 6b 65 `#endasm`.marke
11b70 72 73 20 69 6e 20 74 68 65 20 43 20 73 6f 75 72 rs in the C sour
11b80 63 65 20 63 6f 64 65 3a 0a 0a 20 20 20 20 23 61 ce code:.. #a
11b90 73 6d 0a 20 20 20 20 20 20 20 20 54 41 44 20 28 sm. TAD (
11ba0 34 32 20 20 20 20 20 20 2f 20 61 64 64 20 34 32 42 / add 42
11bb0 20 74 6f 20 41 43 0a 20 20 20 20 23 65 6e 64 61 to AC. #enda
11bc0 73 6d 0a 0a 53 75 63 68 20 63 6f 64 65 20 69 73 sm..Such code is
11bd0 20 63 6f 70 69 65 64 20 6c 69 74 65 72 61 6c 6c copied literall
11be0 79 20 66 72 6f 6d 20 74 68 65 20 69 6e 70 75 74 y from the input
11bf0 20 43 20 73 6f 75 72 63 65 20 66 69 6c 65 20 69 C source file i
11c00 6e 74 6f 20 74 68 65 0a 63 6f 6d 70 69 6c 65 72 nto the.compiler
11c10 e2 80 99 73 20 53 41 42 52 20 6f 75 74 70 75 74 ’s SABR output
11c20 20 66 69 6c 65 2c 20 73 6f 20 69 74 20 6d 75 73 file, so it mus
11c30 74 20 62 65 20 77 72 69 74 74 65 6e 20 77 69 74 t be written wit
11c40 68 20 74 68 61 74 20 63 6f 6e 74 65 78 74 20 69 h that context i
11c50 6e 0a 6d 69 6e 64 2e 0a 0a 0a 23 23 23 20 3c 61 n.mind....### <a
11c60 20 69 64 3d 22 63 61 6c 6c 69 6e 67 22 3e 3c 2f id="calling"></
11c70 61 3e 54 68 65 20 43 43 38 20 43 61 6c 6c 69 6e a>The CC8 Callin
11c80 67 20 43 6f 6e 76 65 6e 74 69 6f 6e 0a 0a 59 6f g Convention..Yo
11c90 75 20 63 61 6e 20 77 72 69 74 65 20 77 68 6f 6c u can write whol
11ca0 65 20 66 75 6e 63 74 69 6f 6e 73 20 69 6e 20 69 e functions in i
11cb0 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c 79 2c 20 nline assembly,
11cc0 74 68 6f 75 67 68 20 66 6f 72 20 73 69 6d 70 6c though for simpl
11cd0 69 63 69 74 79 2c 0a 77 65 20 72 65 63 6f 6d 6d icity,.we recomm
11ce0 65 6e 64 20 74 68 61 74 20 79 6f 75 20 77 72 69 end that you wri
11cf0 74 65 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 te the function
11d00 77 72 61 70 70 65 72 20 69 6e 20 43 20 73 79 6e wrapper in C syn
11d10 74 61 78 2c 20 77 69 74 68 20 74 68 65 0a 62 6f tax, with the.bo
11d20 64 79 20 69 6e 20 61 73 73 65 6d 62 6c 79 3a 0a dy in assembly:.
11d30 0a 20 20 20 20 61 64 64 34 38 28 61 29 0a 20 20 . add48(a).
11d40 20 20 69 6e 74 20 61 0a 20 20 20 20 7b 0a 20 20 int a. {.
11d50 20 20 20 20 20 20 61 3b 20 20 20 20 20 20 20 20 a;
11d60 20 20 2f 2a 20 6c 6f 61 64 20 27 61 27 20 69 6e /* load 'a' in
11d70 74 6f 20 41 43 3b 20 65 78 70 6c 61 69 6e 65 64 to AC; explained
11d80 20 62 65 6c 6f 77 20 2a 2f 0a 20 20 20 20 23 61 below */. #a
11d90 73 6d 0a 20 20 20 20 20 20 20 20 54 41 44 20 28 sm. TAD (
11da0 44 34 38 0a 20 20 20 20 23 65 6e 64 61 73 6d 0a D48. #endasm.
11db0 20 20 20 20 7d 0a 0a 44 6f 69 6e 67 20 69 74 20 }..Doing it
11dc0 74 68 69 73 20 77 61 79 20 73 61 76 65 73 20 79 this way saves y
11dd0 6f 75 20 66 72 6f 6d 20 68 61 76 69 6e 67 20 74 ou from having t
11de0 6f 20 75 6e 64 65 72 73 74 61 6e 64 20 74 68 65 o understand the
11df0 20 77 61 79 20 74 68 65 20 43 43 38 0a 73 6f 66 way the CC8.sof
11e00 74 77 61 72 65 20 73 74 61 63 6b 20 77 6f 72 6b tware stack work
11e10 73 2c 20 77 68 69 63 68 20 77 65 e2 80 99 76 65 s, which we’ve
11e20 20 63 68 6f 73 65 6e 20 6e 6f 74 20 74 6f 20 64 chosen not to d
11e30 6f 63 75 6d 65 6e 74 20 68 65 72 65 20 79 65 74 ocument here yet
11e40 2c 20 61 70 61 72 74 0a 66 72 6f 6d 20 5b 69 74 , apart.from [it
11e50 73 20 61 70 70 72 6f 78 69 6d 61 74 65 20 6c 6f s approximate lo
11e60 63 61 74 69 6f 6e 20 69 6e 20 63 6f 72 65 20 6d cation in core m
11e70 65 6d 6f 72 79 5d 28 23 6d 65 6d 6f 72 79 29 2e emory](#memory).
11e80 20 41 6c 6c 20 79 6f 75 20 6e 65 65 64 20 74 6f All you need to
11e90 0a 6b 6e 6f 77 20 69 73 20 74 68 61 74 20 70 61 .know is that pa
11ea0 72 61 6d 65 74 65 72 73 20 61 72 65 20 70 61 73 rameters are pas
11eb0 73 65 64 20 6f 6e 20 74 68 65 20 73 74 61 63 6b sed on the stack
11ec0 20 61 6e 64 20 2a 73 6f 6d 65 68 6f 77 2a 20 65 and *somehow* e
11ed0 78 74 72 61 63 74 65 64 0a 77 68 65 6e 20 74 68 xtracted.when th
11ee0 65 79 e2 80 99 72 65 20 72 65 66 65 72 65 6e 63 ey’re referenc
11ef0 65 64 20 69 6e 20 43 20 63 6f 64 65 2e 0a 0a 43 ed in C code...C
11f00 43 38 20 72 65 74 75 72 6e 73 20 76 61 6c 75 65 C8 returns value
11f10 73 20 66 72 6f 6d 20 66 75 6e 63 74 69 6f 6e 73 s from functions
11f20 20 69 6e 20 41 43 2c 20 73 6f 20 6f 75 72 20 65 in AC, so our e
11f30 78 61 6d 70 6c 65 20 64 6f 65 73 20 6e 6f 74 20 xample does not
11f40 72 65 71 75 69 72 65 0a 61 6e 20 65 78 70 6c 69 require.an expli
11f50 63 69 74 20 e2 80 9c 60 72 65 74 75 72 6e 60 e2 cit “`return`
11f60 80 9d 20 73 74 61 74 65 6d 65 6e 74 3a 20 77 65 statement: we
11f70 e2 80 99 76 65 20 61 72 72 61 6e 67 65 64 20 66 ’ve arranged f
11f80 6f 72 20 6f 75 72 20 69 6e 74 65 6e 64 65 64 20 or our intended
11f90 72 65 74 75 72 6e 0a 76 61 6c 75 65 20 74 6f 20 return.value to
11fa0 62 65 20 69 6e 20 41 43 20 61 74 20 74 68 65 20 be in AC at the
11fb0 65 6e 64 20 6f 66 20 74 68 65 20 66 75 6e 63 74 end of the funct
11fc0 69 6f 6e 20 62 6f 64 79 2c 20 73 6f 20 74 68 65 ion body, so the
11fd0 20 69 6d 70 6c 69 63 69 74 0a 72 65 74 75 72 6e implicit.return
11fe0 20 64 6f 65 73 20 77 68 61 74 20 77 65 20 77 61 does what we wa
11ff0 6e 74 20 68 65 72 65 2e 0a 0a 54 68 65 20 61 62 nt here...The ab
12000 6f 76 65 20 73 6e 69 70 70 65 74 20 74 68 65 72 ove snippet ther
12010 65 66 6f 72 65 20 64 65 63 6c 61 72 65 73 20 61 efore declares a
12020 20 66 75 6e 63 74 69 6f 6e 20 60 61 64 64 34 38 function `add48
12030 60 20 74 61 6b 69 6e 67 20 61 20 73 69 6e 67 6c ` taking a singl
12040 65 0a 70 61 72 61 6d 65 74 65 72 20 e2 80 9c 60 e.parameter “`
12050 61 60 e2 80 9d 20 61 6e 64 20 72 65 74 75 72 6e a`” and return
12060 69 6e 67 20 60 61 2b 34 38 60 2e 0a 0a 4b 65 65 ing `a+48`...Kee
12070 70 20 69 6e 20 6d 69 6e 64 20 77 68 65 6e 20 72 p in mind when r
12080 65 61 64 69 6e 67 20 73 75 63 68 20 63 6f 64 65 eading such code
12090 20 74 68 61 74 20 43 43 38 20 69 73 20 5b 65 73 that CC8 is [es
120a0 73 65 6e 74 69 61 6c 6c 79 0a 74 79 70 65 6c 65 sentially.typele
120b0 73 73 5d 28 23 74 79 70 65 6c 65 73 73 29 3a 20 ss](#typeless):
120c0 69 74 e2 80 99 73 20 74 65 6d 70 74 69 6e 67 20 it’s tempting
120d0 74 6f 20 74 68 69 6e 6b 20 6f 66 20 74 68 65 20 to think of the
120e0 61 62 6f 76 65 20 63 6f 64 65 20 61 73 20 74 61 above code as ta
120f0 6b 69 6e 67 0a 61 6e 20 69 6e 74 65 67 65 72 20 king.an integer
12100 61 6e 64 20 72 65 74 75 72 6e 69 6e 67 20 61 6e and returning an
12110 20 69 6e 74 65 67 65 72 2c 20 62 75 74 20 79 6f integer, but yo
12120 75 20 63 61 6e 20 65 71 75 61 6c 6c 79 20 63 6f u can equally co
12130 72 72 65 63 74 6c 79 20 74 68 69 6e 6b 0a 6f 66 rrectly think.of
12140 20 69 74 20 61 73 20 74 61 6b 69 6e 67 20 61 20 it as taking a
12150 63 68 61 72 61 63 74 65 72 20 61 6e 64 20 72 65 character and re
12160 74 75 72 6e 69 6e 67 20 61 20 63 68 61 72 61 63 turning a charac
12170 74 65 72 2e 20 49 6e 64 65 65 64 2c 20 74 68 61 ter. Indeed, tha
12180 74 0a 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 t.function will
12190 74 61 6b 65 20 61 20 76 61 6c 75 65 20 69 6e 20 take a value in
121a0 74 68 65 20 72 61 6e 67 65 20 30 20 74 68 72 75 the range 0 thru
121b0 20 39 20 61 6e 64 20 72 65 74 75 72 6e 20 74 68 9 and return th
121c0 65 0a 65 71 75 69 76 61 6c 65 6e 74 20 41 53 43 e.equivalent ASC
121d0 49 49 20 64 69 67 69 74 21 20 43 43 38 e2 80 99 II digit! CC8’
121e0 73 20 74 79 70 65 6c 65 73 73 20 6e 61 74 75 72 s typeless natur
121f0 65 20 6d 61 74 65 73 20 77 65 6c 6c 20 77 69 74 e mates well wit
12200 68 20 4b 26 52 20 43 e2 80 99 73 0a 69 6e 64 69 h K&R C’s.indi
12210 66 66 65 72 65 6e 63 65 20 74 6f 77 61 72 64 20 fference toward
12220 72 65 74 75 72 6e 20 74 79 70 65 20 64 65 63 6c return type decl
12230 61 72 61 74 69 6f 6e 2e 0a 0a 0a 23 23 23 20 45 aration....### E
12240 71 75 69 76 61 6c 65 6e 63 65 20 74 6f 20 53 74 quivalence to St
12250 61 74 65 6d 65 6e 74 73 0a 0a 41 20 62 6c 6f 63 atements..A bloc
12260 6b 20 6f 66 20 69 6e 6c 69 6e 65 20 61 73 73 65 k of inline asse
12270 6d 62 6c 79 20 66 75 6e 63 74 69 6f 6e 73 20 61 mbly functions a
12280 73 20 73 69 6e 67 6c 65 20 73 74 61 74 65 6d 65 s single stateme
12290 6e 74 20 69 6e 20 74 68 65 20 43 0a 70 72 6f 67 nt in the C.prog
122a0 72 61 6d 2c 20 66 72 6f 6d 20 61 20 73 79 6e 74 ram, from a synt
122b0 61 63 74 69 63 20 70 6f 69 6e 74 20 6f 66 20 76 actic point of v
122c0 69 65 77 2e 20 43 6f 6e 73 69 64 65 72 20 74 68 iew. Consider th
122d0 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e e implementation
122e0 20 6f 66 0a 74 68 65 20 53 74 61 6e 64 61 72 64 of.the Standard
122f0 20 43 20 66 75 6e 63 74 69 6f 6e 20 60 70 75 74 C function `put
12300 73 60 20 66 72 6f 6d 20 74 68 65 20 43 43 38 20 s` from the CC8
12310 4c 49 42 43 3a 0a 0a 20 20 20 20 70 75 74 73 28 LIBC:.. puts(
12320 70 29 0a 20 20 20 20 63 68 61 72 20 2a 70 3b 0a p). char *p;.
12330 20 20 20 20 20 20 20 20 7b 0a 20 20 20 20 20 20 {.
12340 20 20 20 20 20 20 77 68 69 6c 65 20 28 2a 70 2b while (*p+
12350 2b 29 20 0a 20 20 20 20 23 61 73 6d 0a 20 20 20 +) . #asm.
12360 20 20 20 20 20 20 20 20 20 54 4c 53 0a 20 20 20 TLS.
12370 20 58 43 31 2c 20 20 20 20 54 53 46 0a 20 20 20 XC1, TSF.
12380 20 20 20 20 20 20 20 20 20 4a 4d 50 20 58 43 31 JMP XC1
12390 0a 20 20 20 20 23 65 6e 64 61 73 6d 0a 20 20 20 . #endasm.
123a0 20 20 20 20 20 7d 0a 0a 4e 6f 74 69 63 65 20 74 }..Notice t
123b0 68 61 74 20 74 68 65 72 65 20 69 73 20 6e 6f 20 hat there is no
123c0 6f 70 65 6e 69 6e 67 20 63 75 72 6c 79 20 62 72 opening curly br
123d0 61 63 65 20 6f 6e 20 74 68 65 20 60 77 68 69 6c ace on the `whil
123e0 65 60 20 6c 6f 6f 70 3a 20 77 68 65 6e 0a 74 68 e` loop: when.th
123f0 65 20 60 54 53 46 60 20 6f 70 2d 63 6f 64 65 20 e `TSF` op-code
12400 63 61 75 73 65 73 20 74 68 65 20 60 4a 4d 50 60 causes the `JMP`
12410 20 69 6e 73 74 72 75 63 74 69 6f 6e 20 74 6f 20 instruction to
12420 62 65 20 73 6b 69 70 70 65 64 20 e2 80 94 20 6d be skipped — m
12430 65 61 6e 69 6e 67 0a 74 68 65 20 63 6f 6e 73 6f eaning.the conso
12440 6c 65 20 74 65 72 6d 69 6e 61 6c 20 69 73 20 72 le terminal is r
12450 65 61 64 79 20 66 6f 72 20 61 6e 6f 74 68 65 72 eady for another
12460 20 6f 75 74 70 75 74 20 63 68 61 72 61 63 74 65 output characte
12470 72 20 e2 80 94 20 63 6f 6e 74 72 6f 6c 0a 67 6f r — control.go
12480 65 73 20 62 61 63 6b 20 74 6f 20 74 68 65 20 74 es back to the t
12490 6f 70 20 6f 66 20 74 68 65 20 60 77 68 69 6c 65 op of the `while
124a0 60 20 6c 6f 6f 70 2e 20 54 68 61 74 20 69 73 2c ` loop. That is,
124b0 20 74 68 65 73 65 20 74 68 72 65 65 0a 69 6e 73 these three.ins
124c0 74 72 75 63 74 69 6f 6e 73 20 62 65 68 61 76 65 tructions behave
124d0 20 61 73 20 69 66 20 74 68 65 79 20 77 65 72 65 as if they were
124e0 20 61 20 73 69 6e 67 6c 65 20 43 20 73 74 61 74 a single C stat
124f0 65 6d 65 6e 74 20 61 6e 64 20 74 68 75 73 0a 63 ement and thus.c
12500 6f 6e 73 74 69 74 75 74 65 20 74 68 65 20 77 68 onstitute the wh
12510 6f 6c 65 20 62 6f 64 79 20 6f 66 20 74 68 65 20 ole body of the
12520 60 77 68 69 6c 65 60 20 6c 6f 6f 70 2e 0a 0a 0a `while` loop....
12530 23 23 23 20 4f 70 74 69 6d 69 7a 61 74 69 6f 6e ### Optimization
12540 0a 0a 54 68 65 72 65 20 61 72 65 20 73 65 76 65 ..There are seve
12550 72 61 6c 20 63 6c 65 76 65 72 20 6f 70 74 69 6d ral clever optim
12560 69 7a 61 74 69 6f 6e 73 20 74 68 61 74 20 79 6f izations that yo
12570 75 20 6d 69 67 68 74 20 77 61 6e 74 20 74 6f 20 u might want to
12580 75 73 65 20 69 6e 0a 79 6f 75 72 20 6f 77 6e 20 use in.your own
12590 70 72 6f 67 72 61 6d 73 2c 20 73 6f 6d 65 20 6f programs, some o
125a0 66 20 77 68 69 63 68 20 61 72 65 20 73 68 6f 77 f which are show
125b0 6e 20 69 6e 20 74 68 65 20 65 78 61 6d 70 6c 65 n in the example
125c0 73 20 61 62 6f 76 65 3a 0a 0a 2a 20 20 20 49 6e s above:..* In
125d0 20 74 68 65 20 60 61 64 64 34 38 60 20 65 78 61 the `add48` exa
125e0 6d 70 6c 65 20 74 68 65 20 6c 69 6e 65 20 e2 80 mple the line
125f0 9c 60 61 3b 60 e2 80 9d 20 6d 65 61 6e 73 20 e2 `a;`” means
12600 80 9c 6c 6f 61 64 20 60 61 60 20 69 6e 74 6f 20 load `a` into
12610 41 43 e2 80 9d 2e 20 49 6e 0a 20 20 20 20 61 20 AC”. In. a
12620 53 74 61 6e 64 61 72 64 20 43 20 63 6f 6d 70 69 Standard C compi
12630 6c 65 72 2c 20 74 68 69 73 20 77 6f 75 6c 64 20 ler, this would
12640 62 65 20 63 6f 6e 73 69 64 65 72 65 64 20 75 73 be considered us
12650 65 20 6f 66 20 61 20 76 61 72 69 61 62 6c 65 20 e of a variable
12660 69 6e 0a 20 20 20 20 60 76 6f 69 64 60 20 63 6f in. `void` co
12670 6e 74 65 78 74 20 61 6e 64 20 74 68 75 73 20 62 ntext and thus b
12680 65 20 6f 70 74 69 6d 69 7a 65 64 20 6f 75 74 2c e optimized out,
12690 20 62 75 74 20 4b 26 52 20 43 20 68 61 73 20 6e but K&R C has n
126a0 6f 20 73 75 63 68 0a 20 20 20 20 6e 6f 74 69 6f o such. notio
126b0 6e 2c 20 73 6f 20 69 74 20 68 61 73 20 74 68 69 n, so it has thi
126c0 73 20 6e 6f 6e 73 74 61 6e 64 61 72 64 20 6d 65 s nonstandard me
126d0 61 6e 69 6e 67 20 69 6e 20 43 43 38 2e 20 20 54 aning in CC8. T
126e0 68 69 73 20 74 65 63 68 6e 69 71 75 65 0a 20 20 his technique.
126f0 20 20 69 73 20 75 73 65 64 20 71 75 69 74 65 20 is used quite
12700 61 20 6c 6f 74 20 69 6e 20 6f 75 72 20 5b 4c 49 a lot in our [LI
12710 42 43 5d 28 23 6c 69 62 63 29 2c 20 73 6f 20 79 BC](#libc), so y
12720 6f 75 20 63 61 6e 20 62 65 20 73 75 72 65 20 74 ou can be sure t
12730 68 65 0a 20 20 20 20 62 65 68 61 76 69 6f 72 20 he. behavior
12740 77 6f 6e e2 80 99 74 20 62 65 20 67 6f 69 6e 67 won’t be going
12750 20 61 77 61 79 2e 0a 0a 2a 20 20 20 49 6e 20 74 away...* In t
12760 68 65 20 60 70 75 74 73 60 20 65 78 61 6d 70 6c he `puts` exampl
12770 65 2c 20 74 68 65 20 73 74 61 74 65 6d 65 6e 74 e, the statement
12780 20 60 2a 70 2b 2b 60 20 69 6d 70 6c 69 63 69 74 `*p++` implicit
12790 6c 79 20 73 74 6f 72 65 73 20 74 68 65 0a 20 20 ly stores the.
127a0 20 20 76 61 6c 75 65 20 61 74 20 74 68 65 20 63 value at the c
127b0 6f 72 65 20 6d 65 6d 6f 72 79 20 6c 6f 63 61 74 ore memory locat
127c0 69 6f 6e 20 72 65 66 65 72 72 65 64 20 74 6f 20 ion referred to
127d0 62 79 20 60 70 60 20 69 6e 20 41 43 2c 20 73 6f by `p` in AC, so
127e0 20 77 65 0a 20 20 20 20 63 61 6e 20 75 73 65 20 we. can use
127f0 69 74 20 77 69 74 68 69 6e 20 74 68 65 20 61 73 it within the as
12800 73 65 6d 62 6c 79 20 62 6f 64 79 20 6f 66 20 74 sembly body of t
12810 68 61 74 20 6c 6f 6f 70 20 77 69 74 68 6f 75 74 hat loop without
12820 20 65 76 65 72 0a 20 20 20 20 65 78 70 6c 69 63 ever. explic
12830 69 74 6c 79 20 72 65 66 65 72 72 69 6e 67 20 74 itly referring t
12840 6f 20 60 70 60 2e 0a 0a 2a 20 20 20 4b 6e 6f 77 o `p`...* Know
12850 69 6e 67 20 74 68 61 74 20 66 75 6e 63 74 69 6f ing that functio
12860 6e 73 20 72 65 74 75 72 6e 20 74 68 65 69 72 20 ns return their
12870 76 61 6c 75 65 20 69 6e 20 41 43 2c 20 79 6f 75 value in AC, you
12880 20 63 61 6e 20 63 61 6c 6c 0a 20 20 20 20 61 6e can call. an
12890 6f 74 68 65 72 20 43 20 66 75 6e 63 74 69 6f 6e other C function
128a0 20 66 72 6f 6d 20 74 68 65 20 6d 69 64 64 6c 65 from the middle
128b0 20 6f 66 20 61 20 62 6c 6f 63 6b 20 6f 66 20 61 of a block of a
128c0 73 73 65 6d 62 6c 79 20 63 6f 64 65 20 62 75 74 ssembly code but
128d0 0a 20 20 20 20 6e 65 76 65 72 20 73 74 6f 72 65 . never store
128e0 20 69 74 73 20 72 65 74 75 72 6e 20 76 61 6c 75 its return valu
128f0 65 20 65 78 70 6c 69 63 69 74 6c 79 3a 20 6a 75 e explicitly: ju
12900 73 74 20 75 73 65 20 69 74 73 20 72 65 74 75 72 st use its retur
12910 6e 20 76 61 6c 75 65 0a 20 20 20 20 64 69 72 65 n value. dire
12920 63 74 6c 79 20 66 72 6f 6d 20 41 43 20 74 6f 20 ctly from AC to
12930 73 61 76 65 20 73 70 61 63 65 20 6f 6e 20 74 68 save space on th
12940 65 20 73 74 61 63 6b 2e 0a 0a 42 65 77 61 72 65 e stack...Beware
12950 20 74 68 61 74 20 43 43 38 20 69 73 6e e2 80 99 that CC8 isn’
12960 74 20 61 20 70 61 72 74 69 63 75 6c 61 72 6c 79 t a particularly
12970 20 73 6d 61 72 74 20 63 6f 6d 70 69 6c 65 72 2e smart compiler.
12980 20 49 74 20 70 65 72 66 6f 72 6d 73 20 66 65 77 It performs few
12990 20 6f 66 0a 74 68 65 20 61 75 74 6f 6d 61 74 69 of.the automati
129a0 63 20 74 72 69 63 6b 73 20 79 6f 75 e2 80 99 64 c tricks you’d
129b0 20 65 78 70 65 63 74 20 66 72 6f 6d 20 61 20 6d expect from a m
129c0 6f 64 65 72 6e 20 43 20 63 6f 6d 70 69 6c 65 72 odern C compiler
129d0 2c 20 6e 6f 74 20 65 76 65 6e 0a 68 61 6e 64 6c , not even.handl
129e0 69 6e 67 20 73 69 6d 70 6c 65 20 74 68 69 6e 67 ing simple thing
129f0 73 20 6c 69 6b 65 20 63 6f 6e 73 74 61 6e 74 20 s like constant
12a00 65 78 70 72 65 73 73 69 6f 6e 20 72 65 64 75 63 expression reduc
12a10 74 69 6f 6e 3a 0a 0a 20 20 20 20 63 68 61 72 20 tion:.. char
12a20 63 20 3d 20 27 61 27 20 2d 20 31 30 3b 20 20 20 c = 'a' - 10;
12a30 20 20 20 2f 2a 20 73 61 76 65 20 41 53 43 49 49 /* save ASCII
12a40 20 63 68 61 72 61 63 74 65 72 20 31 30 20 62 61 character 10 ba
12a50 63 6b 20 66 72 6f 6d 20 e2 80 9c 61 e2 80 9d 20 ck from “a”
12a60 2a 2f 0a 20 20 20 20 63 68 61 72 20 63 20 3d 20 */. char c =
12a70 38 37 3b 20 20 20 20 20 20 20 20 20 20 20 20 2f 87; /
12a80 2a 20 73 61 6d 65 20 65 66 66 65 63 74 2c 20 62 * same effect, b
12a90 75 74 20 67 69 76 65 73 20 73 68 6f 72 74 65 72 ut gives shorter
12aa0 20 6f 75 74 70 75 74 21 20 2a 2f 0a 0a 54 68 61 output! */..Tha
12ab0 74 20 65 78 61 6d 70 6c 65 20 69 73 20 62 61 73 t example is bas
12ac0 65 64 20 6f 6e 20 72 65 61 6c 20 63 6f 64 65 2c ed on real code,
12ad0 20 74 68 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74 the implementat
12ae0 69 6f 6e 20 6f 66 0a 5b 60 69 74 6f 61 28 29 60 ion of.[`itoa()`
12af0 5d 28 23 69 74 6f 61 29 20 66 6f 72 20 72 61 64 ](#itoa) for rad
12b00 69 63 65 73 20 62 65 79 6f 6e 64 20 31 30 3a 20 ices beyond 10:
12b10 77 65 20 74 72 69 65 64 20 69 74 20 62 6f 74 68 we tried it both
12b20 20 77 61 79 73 20 61 6e 64 20 65 6e 64 65 64 0a ways and ended.
12b30 75 70 20 64 6f 69 6e 67 20 69 74 20 74 68 65 20 up doing it the
12b40 6f 62 73 63 75 72 65 20 77 61 79 20 74 6f 20 73 obscure way to s
12b50 61 76 65 20 63 6f 64 65 20 73 70 61 63 65 20 69 ave code space i
12b60 6e 20 4c 49 42 43 2e 0a 0a 46 6f 72 20 74 68 65 n LIBC...For the
12b70 20 6d 6f 73 74 20 70 61 72 74 2c 20 43 43 38 20 most part, CC8
12b80 63 75 72 72 65 6e 74 6c 79 20 6c 65 61 76 65 73 currently leaves
12b90 20 74 68 65 20 74 61 73 6b 20 6f 66 20 6f 70 74 the task of opt
12ba0 69 6d 69 7a 61 74 69 6f 6e 20 74 6f 20 74 68 65 imization to the
12bb0 0a 65 6e 64 20 75 73 65 72 2e 0a 0a 0a 23 23 23 .end user....###
12bc0 20 3c 61 20 69 64 3d 22 61 73 6d 6f 63 74 22 3e <a id="asmoct">
12bd0 3c 2f 61 3e 49 6e 6c 69 6e 65 20 41 73 73 65 6d </a>Inline Assem
12be0 62 6c 79 20 69 73 20 69 6e 20 4f 63 74 61 6c 0a bly is in Octal.
12bf0 0a 4c 69 6b 65 20 74 68 65 20 4f 53 2f 38 20 46 .Like the OS/8 F
12c00 4f 52 54 52 41 4e 20 49 49 20 63 6f 6d 70 69 6c ORTRAN II compil
12c10 65 72 2c 20 74 68 65 20 43 43 38 20 63 6f 6d 70 er, the CC8 comp
12c20 69 6c 65 72 73 20 6c 65 61 76 65 20 53 41 42 52 ilers leave SABR
12c30 20 69 6e 20 69 74 73 0a 64 65 66 61 75 6c 74 20 in its.default
12c40 6f 63 74 61 6c 20 6d 6f 64 65 2e 20 41 6c 6c 20 octal mode. All
12c50 69 6e 74 65 67 65 72 20 63 6f 6e 73 74 61 6e 74 integer constant
12c60 73 20 65 6d 69 74 65 64 20 62 79 20 62 6f 74 68 s emited by both
12c70 20 63 6f 6d 70 69 6c 65 72 73 20 61 72 65 0a 69 compilers are.i
12c80 6e 20 6f 63 74 61 6c 2e 20 20 28 45 76 65 6e 20 n octal. (Even
12c90 74 68 6f 73 65 20 69 6e 20 67 65 6e 65 72 61 74 those in generat
12ca0 65 64 20 6c 61 62 65 6c 73 20 61 6e 64 20 69 6e ed labels and in
12cb0 20 65 72 72 6f 72 20 6f 75 74 70 75 74 0a 6d 65 error output.me
12cc0 73 73 61 67 65 73 21 29 20 54 68 69 73 20 6d 65 ssages!) This me
12cd0 61 6e 73 20 69 6e 74 65 67 65 72 20 63 6f 6e 73 ans integer cons
12ce0 74 61 6e 74 73 20 69 6e 20 79 6f 75 72 20 69 6e tants in your in
12cf0 6c 69 6e 65 20 61 73 73 65 6d 62 6c 79 20 61 6c line assembly al
12d00 73 6f 20 67 65 74 0a 69 6e 74 65 72 70 72 65 74 so get.interpret
12d10 65 64 20 61 73 20 6f 63 74 61 6c 2c 20 62 79 20 ed as octal, by
12d20 64 65 66 61 75 6c 74 2e 0a 0a 49 66 20 79 6f 75 default...If you
12d30 20 75 73 65 20 74 68 65 20 60 44 45 43 49 4d 60 use the `DECIM`
12d40 20 53 41 42 52 20 70 73 65 75 64 6f 2d 6f 70 20 SABR pseudo-op
12d50 74 6f 20 67 65 74 20 61 72 6f 75 6e 64 20 74 68 to get around th
12d60 69 73 2c 20 79 6f 75 20 6d 75 73 74 20 62 65 0a is, you must be.
12d70 63 61 72 65 66 75 6c 20 74 6f 20 61 64 64 20 61 careful to add a
12d80 6e 20 60 4f 43 54 41 4c 60 20 6f 70 20 62 65 66 n `OCTAL` op bef
12d90 6f 72 65 20 74 68 65 20 62 6c 6f 63 6b 20 65 6e ore the block en
12da0 64 73 20 74 6f 20 73 68 69 66 74 20 74 68 65 20 ds to shift the
12db0 6d 6f 64 65 0a 62 61 63 6b 2e 20 54 68 65 20 63 mode.back. The c
12dc0 6f 6d 70 69 6c 65 72 20 64 6f 65 73 6e e2 80 99 ompiler doesn’
12dd0 74 20 64 65 74 65 63 74 20 75 73 65 20 6f 66 20 t detect use of
12de0 60 44 45 43 49 4d 60 2c 20 61 6e 64 20 69 74 20 `DECIM`, and it
12df0 64 6f 65 73 6e e2 80 99 74 20 62 6c 69 6e 64 6c doesn’t blindl
12e00 79 0a 69 6e 6a 65 63 74 20 60 4f 43 54 41 4c 60 y.inject `OCTAL`
12e10 20 6f 70 73 20 61 66 74 65 72 20 65 76 65 72 79 ops after every
12e20 20 69 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c 79 inline assembly
12e30 20 62 6c 6f 63 6b 20 74 6f 20 66 6f 72 63 65 20 block to force
12e40 74 68 65 20 6d 6f 64 65 0a 62 61 63 6b 20 6f 6e the mode.back on
12e50 20 74 68 65 20 6f 66 66 20 63 68 61 6e 63 65 20 the off chance
12e60 74 68 61 74 20 74 68 65 20 75 73 65 72 20 68 61 that the user ha
12e70 64 20 73 68 69 66 74 65 64 20 74 68 65 20 61 73 d shifted the as
12e80 73 65 6d 62 6c 65 72 20 69 6e 74 6f 0a 64 65 63 sembler into.dec
12e90 69 6d 61 6c 20 6d 6f 64 65 2e 20 49 66 20 79 6f imal mode. If yo
12ea0 75 20 6c 65 61 76 65 20 74 68 65 20 61 73 73 65 u leave the asse
12eb0 6d 62 6c 65 72 20 69 6e 20 60 44 45 43 49 4d 60 mbler in `DECIM`
12ec0 20 6d 6f 64 65 20 61 74 20 74 68 65 20 65 6e 64 mode at the end
12ed0 20 6f 66 0a 61 6e 20 69 6e 6c 69 6e 65 20 61 73 of.an inline as
12ee0 73 65 6d 62 6c 79 20 62 6c 6f 63 6b 2c 20 74 68 sembly block, th
12ef0 65 20 72 65 73 75 6c 74 69 6e 67 20 53 41 42 52 e resulting SABR
12f00 20 6f 75 74 70 75 74 20 77 69 6c 6c 20 70 72 6f output will pro
12f10 62 61 62 6c 79 0a 61 73 73 65 6d 62 6c 65 20 62 bably.assemble b
12f20 75 74 20 77 6f 6e e2 80 99 74 20 72 75 6e 20 63 ut won’t run c
12f30 6f 72 72 65 63 74 6c 79 20 62 65 63 61 75 73 65 orrectly because
12f40 20 61 6c 6c 20 69 6e 74 65 67 65 72 20 63 6f 6e all integer con
12f50 73 74 61 6e 74 73 20 66 72 6f 6d 20 74 68 61 74 stants from that
12f60 0a 70 6f 69 6e 74 20 6f 6e 20 77 69 6c 6c 20 62 .point on will b
12f70 65 20 6d 69 73 69 6e 74 65 72 70 72 65 74 65 64 e misinterpreted
12f80 2e 0a 0a 49 74 e2 80 99 73 20 73 61 66 65 72 2c ...It’s safer,
12f90 20 69 66 20 79 6f 75 20 77 61 6e 20 61 20 67 69 if you wan a gi
12fa0 76 65 6e 20 63 6f 6e 73 74 61 6e 74 20 74 6f 20 ven constant to
12fb0 62 65 20 69 6e 74 65 72 70 72 65 74 65 64 20 61 be interpreted a
12fc0 73 20 64 65 63 69 6d 61 6c 2c 20 74 6f 0a 70 72 s decimal, to.pr
12fd0 65 66 69 78 20 69 74 20 77 69 74 68 20 61 20 60 efix it with a `
12fe0 44 60 2e 20 53 65 65 20 74 68 65 20 53 41 42 52 D`. See the SABR
12ff0 20 6d 61 6e 75 61 6c 20 66 6f 72 20 6d 6f 72 65 manual for more
13000 20 64 65 74 61 69 6c 73 20 6f 6e 20 74 68 69 73 details on this
13010 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 6c ....### <a id="l
13020 69 6e 6b 61 67 65 22 20 6e 61 6d 65 3d 22 76 61 inkage" name="va
13030 72 61 72 67 73 22 3e 3c 2f 61 3e 4c 69 62 72 61 rargs"></a>Libra
13040 72 79 20 4c 69 6e 6b 61 67 65 20 61 6e 64 20 56 ry Linkage and V
13050 61 72 61 72 67 73 0a 0a 43 43 38 20 68 61 73 20 arargs..CC8 has
13060 73 6f 6d 65 20 6e 6f 6e 2d 73 74 61 6e 64 61 72 some non-standar
13070 64 20 66 65 61 74 75 72 65 73 20 74 6f 20 65 6e d features to en
13080 61 62 6c 65 20 74 68 65 20 69 6e 74 65 72 66 61 able the interfa
13090 63 65 20 62 65 74 77 65 65 6e 20 74 68 65 0a 6d ce between the.m
130a0 61 69 6e 20 70 72 6f 67 72 61 6d 20 61 6e 64 20 ain program and
130b0 74 68 65 20 43 20 6c 69 62 72 61 72 79 2e 20 54 the C library. T
130c0 68 69 73 20 63 6f 6e 73 74 69 74 75 74 65 73 20 his constitutes
130d0 61 20 63 6f 6d 70 69 6c 65 20 74 69 6d 65 20 6c a compile time l
130e0 69 6e 6b 61 67 65 0a 73 79 73 74 65 6d 20 74 6f inkage.system to
130f0 20 61 6c 6c 6f 77 20 66 6f 72 20 73 74 61 6e 64 allow for stand
13100 61 72 64 20 61 6e 64 20 76 61 72 61 72 67 20 66 ard and vararg f
13110 75 6e 63 74 69 6f 6e 73 20 74 6f 20 62 65 20 63 unctions to be c
13120 61 6c 6c 65 64 20 69 6e 20 74 68 65 0a 6c 69 62 alled in the.lib
13130 72 61 72 79 2e 0a 0a 2a 2a 54 4f 44 4f 3a 2a 2a rary...**TODO:**
13140 20 45 78 70 6c 61 69 6e 20 74 68 69 73 2e 0a 0a Explain this...
13150 0a 23 23 23 20 3c 61 20 69 64 3d 22 6f 73 38 61 .### <a id="os8a
13160 73 6d 22 3e 3c 2f 61 3e 49 6e 6c 69 6e 65 20 41 sm"></a>Inline A
13170 73 73 65 6d 62 6c 79 20 4c 69 6d 69 74 61 74 69 ssembly Limitati
13180 6f 6e 73 20 69 6e 20 74 68 65 20 4e 61 74 69 76 ons in the Nativ
13190 65 20 43 43 38 20 43 6f 6d 70 69 6c 65 72 0a 0a e CC8 Compiler..
131a0 54 68 65 20 6e 61 74 69 76 65 20 63 6f 6d 70 69 The native compi
131b0 6c 65 72 20 68 61 73 20 73 6f 6d 65 20 73 69 67 ler has some sig
131c0 6e 69 66 69 63 61 6e 74 20 6c 69 6d 69 74 61 74 nificant limitat
131d0 69 6f 6e 73 20 69 6e 20 74 68 65 20 77 61 79 20 ions in the way
131e0 69 74 0a 68 61 6e 64 6c 65 73 20 69 6e 6c 69 6e it.handles inlin
131f0 65 20 61 73 73 65 6d 62 6c 79 2e 0a 0a 54 68 65 e assembly...The
13200 20 70 72 69 6d 61 72 79 20 6f 6e 65 20 69 73 20 primary one is
13210 74 68 61 74 20 73 6e 69 70 70 65 74 73 20 6f 66 that snippets of
13220 20 69 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c 79 inline assembly
13230 20 61 72 65 20 67 61 74 68 65 72 65 64 20 62 79 are gathered by
13240 20 74 68 65 0a 5b 66 69 72 73 74 20 70 61 73 73 the.[first pass
13250 5d 28 23 6e 63 70 61 73 73 29 20 6f 66 20 74 68 ](#ncpass) of th
13260 65 20 63 6f 6d 70 69 6c 65 72 20 69 6e 20 61 20 e compiler in a
13270 63 6f 72 65 20 6d 65 6d 6f 72 79 20 62 75 66 66 core memory buff
13280 65 72 20 74 68 61 74 e2 80 99 73 0a 6f 6e 6c 79 er that’s.only
13290 20 31 30 32 34 20 63 68 61 72 61 63 74 65 72 73 1024 characters
132a0 20 69 6e 20 73 69 7a 65 2e 20 49 66 20 74 68 65 in size. If the
132b0 20 74 6f 74 61 6c 20 61 6d 6f 75 6e 74 20 6f 66 total amount of
132c0 20 69 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c 79 inline assembly
132d0 20 69 6e 0a 79 6f 75 72 20 70 72 6f 67 72 61 6d in.your program
132e0 20 65 78 63 65 65 64 73 20 74 68 69 73 20 61 6d exceeds this am
132f0 6f 75 6e 74 2c 20 60 43 43 2e 53 56 60 20 77 69 ount, `CC.SV` wi
13300 6c 6c 20 6f 76 65 72 72 75 6e 20 74 68 69 73 20 ll overrun this
13310 62 75 66 66 65 72 20 61 6e 64 0a 70 72 6f 64 75 buffer and.produ
13320 63 65 20 63 6f 72 72 75 70 74 20 6f 75 74 70 75 ce corrupt outpu
13330 74 2e 0a 0a 49 74 e2 80 99 73 20 64 69 66 66 69 t...It’s diffi
13340 63 75 6c 74 20 74 6f 20 6a 75 73 74 69 66 79 20 cult to justify
13350 69 6e 63 72 65 61 73 69 6e 67 20 74 68 65 20 73 increasing the s
13360 69 7a 65 20 6f 66 20 74 68 61 74 20 62 75 66 66 ize of that buff
13370 65 72 2c 20 62 65 63 61 75 73 65 0a 69 74 e2 80 er, because.it
13380 99 73 20 61 6c 72 65 61 64 79 20 6f 76 65 72 20 s already over
13390 5b 26 66 72 61 63 31 34 3b 20 74 68 65 20 73 70 [¼ the sp
133a0 61 63 65 20 67 69 76 65 6e 5d 28 23 75 64 66 29 ace given](#udf)
133b0 20 69 6e 20 43 43 38 20 74 6f 20 67 6c 6f 62 61 in CC8 to globa
133c0 6c 0a 76 61 72 69 61 62 6c 65 73 2e 0a 0a 49 74 l.variables...It
133d0 20 61 6c 6c 20 68 61 73 20 74 6f 20 62 65 20 67 all has to be g
133e0 61 74 68 65 72 65 64 20 69 6e 20 6f 6e 65 20 70 athered in one p
133f0 61 73 73 2c 20 62 65 63 61 75 73 65 20 74 68 69 ass, because thi
13400 73 20 31 26 6e 62 73 70 3b 6b 57 6f 72 64 20 62 s 1 kWord b
13410 75 66 66 65 72 0a 69 73 20 77 72 69 74 74 65 6e uffer.is written
13420 20 74 6f 20 61 20 74 65 78 74 20 66 69 6c 65 20 to a text file
13430 28 60 43 41 53 4d 2e 54 58 60 29 20 61 74 20 74 (`CASM.TX`) at t
13440 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20 5b 66 he end of the [f
13450 69 72 73 74 20 63 6f 6d 70 69 6c 65 72 0a 70 61 irst compiler.pa
13460 73 73 5d 28 23 6e 63 70 61 73 73 29 2c 20 77 68 ss](#ncpass), wh
13470 65 72 65 20 69 74 20 77 61 69 74 73 20 66 6f 72 ere it waits for
13480 20 74 68 65 20 66 69 6e 61 6c 20 63 6f 6d 70 69 the final compi
13490 6c 65 72 20 70 61 73 73 20 74 6f 20 72 65 61 64 ler pass to read
134a0 20 69 74 0a 62 61 63 6b 20 69 6e 20 74 6f 20 62 it.back in to b
134b0 65 20 69 6e 73 65 72 74 65 64 20 69 6e 74 6f 20 e inserted into
134c0 74 68 65 20 6f 75 74 70 75 74 20 53 41 42 52 20 the output SABR
134d0 63 6f 64 65 2e 20 20 53 69 6e 63 65 20 4c 49 42 code. Since LIB
134e0 43 e2 80 99 73 0a 5b 60 66 6f 70 65 6e 28 29 60 C’s.[`fopen()`
134f0 5d 28 23 66 6f 70 65 6e 29 20 69 73 20 6c 69 6d ](#fopen) is lim
13500 69 74 65 64 20 74 6f 20 61 20 5b 73 69 6e 67 6c ited to a [singl
13510 65 20 6f 75 74 70 75 74 20 66 69 6c 65 20 61 74 e output file at
13520 20 61 0a 74 69 6d 65 5d 28 23 66 69 6f 6c 69 6d a.time](#fiolim
13530 29 20 61 6e 64 20 69 74 20 63 61 6e 6e 6f 74 20 ) and it cannot
13540 61 70 70 65 6e 64 20 74 6f 20 61 6e 20 65 78 69 append to an exi
13550 73 74 69 6e 67 20 66 69 6c 65 2c 20 69 74 e2 80 sting file, it
13560 99 73 20 67 6f 74 20 6f 6e 65 0a 73 68 6f 74 20 s got one.shot
13570 74 6f 20 77 72 69 74 65 20 65 76 65 72 79 74 68 to write everyth
13580 69 6e 67 20 69 74 20 63 6f 6c 6c 65 63 74 65 64 ing it collected
13590 2e 0a 0a 54 68 69 73 20 69 73 20 6f 6e 65 20 72 ...This is one r
135a0 65 61 73 6f 6e 20 74 68 65 20 43 43 38 20 4c 49 eason the CC8 LI
135b0 42 43 20 68 61 73 20 74 6f 20 62 65 20 63 72 6f BC has to be cro
135c0 73 73 2d 63 6f 6d 70 69 6c 65 64 3a 20 69 74 73 ss-compiled: its
135d0 20 69 6e 6c 69 6e 65 0a 61 73 73 65 6d 62 6c 79 inline.assembly
135e0 20 69 73 20 6f 76 65 72 20 36 26 74 69 6d 65 73 is over 6×
135f0 3b 20 74 68 65 20 73 69 7a 65 20 6f 66 20 74 68 ; the size of th
13600 69 73 20 62 75 66 66 65 72 2e 0a 0a 41 6e 6f 74 is buffer...Anot
13610 68 65 72 20 70 72 6f 62 6c 65 6d 20 74 6f 20 77 her problem to w
13620 61 74 63 68 20 6f 75 74 20 66 6f 72 20 69 73 20 atch out for is
13630 74 68 61 74 20 74 68 69 73 20 69 6e 6c 69 6e 65 that this inline
13640 20 61 73 73 65 6d 62 6c 79 20 62 75 66 66 65 72 assembly buffer
13650 20 69 73 0a 62 72 6f 6b 65 6e 20 69 6e 74 6f 20 is.broken into
13660 73 65 63 74 69 6f 6e 73 20 77 69 74 68 20 60 21 sections with `!
13670 60 20 61 6e 64 20 60 24 60 20 63 68 61 72 61 63 ` and `$` charac
13680 74 65 72 73 20 73 6f 20 74 68 61 74 20 74 68 65 ters so that the
13690 20 66 69 6e 61 6c 20 70 61 73 73 0a 6f 66 20 74 final pass.of t
136a0 68 65 20 63 6f 6d 70 69 6c 65 72 20 63 61 6e 20 he compiler can
136b0 62 72 65 61 6b 20 74 68 65 20 60 43 41 53 4d 2e break the `CASM.
136c0 54 58 60 20 66 69 6c 65 20 75 70 20 69 6e 74 6f TX` file up into
136d0 20 73 65 63 74 69 6f 6e 73 20 66 6f 72 0a 69 6e sections for.in
136e0 73 65 72 74 69 6f 6e 20 69 6e 74 6f 20 74 68 65 sertion into the
136f0 20 53 41 42 52 20 6f 75 74 70 75 74 2e 20 49 74 SABR output. It
13700 20 69 73 20 74 68 65 72 65 66 6f 72 65 20 75 6e is therefore un
13710 73 61 66 65 20 74 6f 20 75 73 65 20 74 68 65 73 safe to use thes
13720 65 0a 63 68 61 72 61 63 74 65 72 73 20 69 6e 20 e.characters in
13730 79 6f 75 72 20 69 6e 6c 69 6e 65 20 61 73 73 65 your inline asse
13740 6d 62 6c 79 2c 20 6c 65 73 74 20 74 68 65 79 20 mbly, lest they
13750 62 65 20 73 65 65 6e 20 61 73 20 73 65 70 61 72 be seen as separ
13760 61 74 6f 72 73 2c 0a 63 61 75 73 69 6e 67 20 69 ators,.causing i
13770 6e 63 6f 72 72 65 63 74 20 6f 75 74 70 75 74 2e ncorrect output.
13780 20 20 54 68 69 73 20 69 73 20 65 73 70 65 63 69 This is especi
13790 61 6c 6c 79 20 65 61 73 79 20 74 6f 20 64 6f 20 ally easy to do
137a0 69 6e 20 63 6f 6d 6d 65 6e 74 73 3b 0a 77 61 74 in comments;.wat
137b0 63 68 20 6f 75 74 21 20 28 53 65 65 20 68 6f 77 ch out! (See how
137c0 20 65 61 73 79 20 69 74 20 69 73 20 74 6f 20 75 easy it is to u
137d0 73 65 20 61 6e 20 65 78 63 6c 61 6d 61 74 69 6f se an exclamatio
137e0 6e 20 70 6f 69 6e 74 20 77 68 65 6e 20 6d 61 6b n point when mak
137f0 69 6e 67 0a 63 6f 6d 6d 65 6e 74 73 3f 29 0a 0a ing.comments?)..
13800 0a 23 23 23 20 3c 61 20 69 64 3d 22 6f 70 64 65 .### <a id="opde
13810 66 22 3e 3c 2f 61 3e 50 72 65 64 65 66 69 6e 65 f"></a>Predefine
13820 64 20 4f 50 44 45 46 73 0a 0a 49 6e 20 61 64 64 d OPDEFs..In add
13830 69 74 69 6f 6e 20 74 6f 20 74 68 65 20 6f 70 2d ition to the op-
13840 63 6f 64 65 73 20 70 72 65 64 65 66 69 6e 65 64 codes predefined
13850 20 66 6f 72 20 53 41 42 52 20 e2 80 94 20 77 68 for SABR — wh
13860 69 63 68 20 79 6f 75 20 63 61 6e 20 66 69 6e 64 ich you can find
13870 20 69 6e 0a 5b 41 70 70 65 6e 64 69 78 20 43 20 in.[Appendix C
13880 6f 66 20 74 68 65 20 4f 53 2f 38 20 48 61 6e 64 of the OS/8 Hand
13890 62 6f 6f 6b 2c 20 31 39 37 34 20 65 64 69 74 69 book, 1974 editi
138a0 6f 6e 5d 5b 6f 73 38 68 61 63 5d 20 e2 80 94 20 on][os8hac] —
138b0 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a 60 4f the following.`O
138c0 50 44 45 46 60 20 64 69 72 65 63 74 69 76 65 73 PDEF` directives
138d0 20 61 72 65 20 69 6e 73 65 72 74 65 64 20 61 74 are inserted at
138e0 20 74 68 65 20 74 6f 70 20 6f 66 20 65 76 65 72 the top of ever
138f0 79 20 53 41 42 52 20 66 69 6c 65 20 6f 75 74 70 y SABR file outp
13900 75 74 0a 66 72 6f 6d 20 43 43 38 2c 20 61 6c 6c ut.from CC8, all
13910 6f 77 69 6e 67 20 79 6f 75 72 20 53 41 42 52 20 owing your SABR
13920 63 6f 64 65 20 74 6f 20 75 73 65 20 74 68 65 73 code to use thes
13930 65 20 61 73 20 77 65 6c 6c 3a 0a 0a 7c 6f 70 2d e as well:..|op-
13940 63 6f 64 65 7c 76 61 6c 75 65 7c 6d 65 61 6e 69 code|value|meani
13950 6e 67 7c 0a 7c 2d 2d 2d 2d 2d 2d 2d 7c 2d 2d 2d ng|.|-------|---
13960 2d 2d 7c 2d 2d 2d 2d 2d 2d 2d 7c 0a 7c 60 41 4e --|-------|.|`AN
13970 44 49 60 20 7c 30 34 30 30 20 7c 73 61 6d 65 20 DI` |0400 |same
13980 61 73 20 60 41 4e 44 20 49 60 20 69 6e 20 50 41 as `AND I` in PA
13990 4c 38 7c 0a 7c 60 54 41 44 49 60 20 7c 31 34 30 L8|.|`TADI` |140
139a0 30 20 7c 73 61 6d 65 20 61 73 20 60 54 41 44 20 0 |same as `TAD
139b0 49 60 20 69 6e 20 50 41 4c 38 7c 0a 7c 60 49 53 I` in PAL8|.|`IS
139c0 5a 49 60 20 7c 32 34 30 30 20 7c 73 61 6d 65 20 ZI` |2400 |same
139d0 61 73 20 60 49 53 5a 20 49 60 20 69 6e 20 50 41 as `ISZ I` in PA
139e0 4c 38 7c 0a 7c 60 44 43 41 49 60 20 7c 33 34 30 L8|.|`DCAI` |340
139f0 30 20 7c 73 61 6d 65 20 61 73 20 60 44 43 41 20 0 |same as `DCA
13a00 49 60 20 69 6e 20 50 41 4c 38 7c 0a 7c 60 4a 4d I` in PAL8|.|`JM
13a10 53 49 60 20 7c 34 34 30 30 20 7c 73 61 6d 65 20 SI` |4400 |same
13a20 61 73 20 60 4a 4d 53 20 49 60 20 69 6e 20 50 41 as `JMS I` in PA
13a30 4c 38 7c 0a 7c 60 4a 4d 50 49 60 20 7c 35 34 30 L8|.|`JMPI` |540
13a40 30 20 7c 73 61 6d 65 20 61 73 20 60 4a 4d 50 20 0 |same as `JMP
13a50 49 60 20 69 6e 20 50 41 4c 38 7c 0a 7c 60 4d 51 I` in PAL8|.|`MQ
13a60 4c 60 20 20 7c 37 34 32 31 20 7c 6c 6f 61 64 20 L` |7421 |load
13a70 4d 51 20 66 72 6f 6d 20 41 43 2c 20 63 6c 65 61 MQ from AC, clea
13a80 72 20 41 43 7c 0a 7c 60 41 43 4c 60 20 20 7c 37 r AC|.|`ACL` |7
13a90 37 30 31 20 7c 6c 6f 61 64 20 41 43 20 66 72 6f 701 |load AC fro
13aa0 6d 20 4d 51 20 28 75 73 65 20 60 43 4c 41 20 53 m MQ (use `CLA S
13ab0 57 50 60 20 74 6f 20 67 69 76 65 20 69 6e 76 65 WP` to give inve
13ac0 72 73 65 20 6f 66 20 60 4d 51 4c 60 29 7c 0a 7c rse of `MQL`)|.|
13ad0 60 4d 51 41 60 20 20 7c 37 35 30 31 20 7c 4f 52 `MQA` |7501 |OR
13ae0 20 4d 51 20 77 69 74 68 20 41 43 2c 20 72 65 73 MQ with AC, res
13af0 75 6c 74 20 69 6e 20 4d 51 7c 0a 7c 60 53 57 50 ult in MQ|.|`SWP
13b00 60 20 20 7c 37 35 32 31 20 7c 73 77 61 70 20 41 ` |7521 |swap A
13b10 43 20 61 6e 64 20 4d 51 7c 0a 7c 60 44 49 4c 58 C and MQ|.|`DILX
13b20 60 20 7c 36 30 35 33 20 7c 73 65 74 20 56 43 38 ` |6053 |set VC8
13b30 45 20 58 20 63 6f 6f 72 64 69 6e 61 74 65 20 28 E X coordinate (
13b40 75 73 65 64 20 62 79 20 5b 60 64 69 73 70 78 79 used by [`dispxy
13b50 28 29 60 5d 28 23 64 69 73 70 78 79 29 29 7c 0a ()`](#dispxy))|.
13b60 7c 60 44 49 4c 59 60 20 7c 36 30 35 34 20 7c 73 |`DILY` |6054 |s
13b70 65 74 20 56 43 38 45 20 59 20 63 6f 6f 72 64 69 et VC8E Y coordi
13b80 6e 61 74 65 7c 0a 7c 60 44 49 58 59 60 20 7c 36 nate|.|`DIXY` |6
13b90 30 35 34 20 7c 70 75 6c 73 65 20 56 43 38 45 20 054 |pulse VC8E
13ba0 61 74 20 28 58 2c 59 29 20 73 65 74 20 62 79 20 at (X,Y) set by
13bb0 60 44 49 58 59 60 2c 60 44 49 4c 59 60 7c 0a 7c `DIXY`,`DILY`|.|
13bc0 60 43 44 46 30 60 20 7c 36 32 30 31 20 7c 63 68 `CDF0` |6201 |ch
13bd0 61 6e 67 65 20 44 46 20 74 6f 20 66 69 65 6c 64 ange DF to field
13be0 20 30 7c 0a 7c 60 43 44 46 31 60 20 7c 36 32 31 0|.|`CDF1` |621
13bf0 31 20 7c 63 68 61 6e 67 65 20 44 46 20 74 6f 20 1 |change DF to
13c00 66 69 65 6c 64 20 31 7c 0a 7c 60 43 41 46 30 60 field 1|.|`CAF0`
13c10 20 7c 36 32 30 33 20 7c 63 68 61 6e 67 65 20 62 |6203 |change b
13c20 6f 74 68 20 49 46 20 61 6e 64 20 44 46 20 74 6f oth IF and DF to
13c30 20 66 69 65 6c 64 20 30 7c 0a 7c 60 52 49 46 60 field 0|.|`RIF`
13c40 20 20 7c 36 32 32 34 20 7c 72 65 61 64 20 69 6e |6224 |read in
13c50 73 74 72 75 63 74 69 6f 6e 20 66 69 65 6c 64 3a struction field:
13c60 20 4f 52 20 49 46 20 77 69 74 68 20 62 69 74 73 OR IF with bits
13c70 20 36 2d 38 20 6f 66 20 41 43 7c 0a 7c 60 42 53 6-8 of AC|.|`BS
13c80 57 60 20 20 7c 37 30 30 32 20 7c 65 78 63 68 61 W` |7002 |excha
13c90 6e 67 65 20 74 68 65 20 68 69 67 68 20 61 6e 64 nge the high and
13ca0 20 6c 6f 77 20 36 20 62 69 74 73 20 6f 66 20 41 low 6 bits of A
13cb0 43 7c 0a 7c 60 43 41 4d 60 20 20 7c 37 36 32 31 C|.|`CAM` |7621
13cc0 20 7c 63 6c 65 61 72 20 41 43 20 61 6e 64 20 4d |clear AC and M
13cd0 51 7c 0a 0a 54 68 65 20 66 69 72 73 74 20 73 69 Q|..The first si
13ce0 78 20 6f 70 65 72 61 74 69 6f 6e 73 20 72 65 71 x operations req
13cf0 75 69 72 65 20 73 6f 6d 65 20 65 78 70 6c 61 6e uire some explan
13d00 61 74 69 6f 6e 2e 20 53 41 42 52 20 74 72 69 65 ation. SABR trie
13d10 73 20 74 6f 20 70 72 65 73 65 6e 74 0a 61 20 66 s to present.a f
13d20 6c 61 74 20 6d 65 6d 6f 72 79 20 6d 6f 64 65 6c lat memory model
13d30 20 74 6f 20 74 68 65 20 75 73 65 72 2c 20 77 68 to the user, wh
13d40 69 63 68 20 6d 65 61 6e 73 20 74 68 61 74 20 69 ich means that i
13d50 66 20 79 6f 75 20 77 72 69 74 65 20 73 6f 6d 65 f you write some
13d60 74 68 69 6e 67 0a 6c 69 6b 65 20 60 54 41 44 20 thing.like `TAD
13d70 49 20 56 41 4c 60 20 69 74 20 64 6f 65 73 6e e2 I VAL` it doesn
13d80 80 99 74 20 65 6d 69 74 20 61 20 73 69 6e 67 6c t emit a singl
13d90 65 20 69 6e 73 74 72 75 63 74 69 6f 6e 20 6c 69 e instruction li
13da0 6b 65 20 73 69 6d 70 6c 65 72 20 50 44 50 2d 38 ke simpler PDP-8
13db0 0a 61 73 73 65 6d 62 6c 65 72 73 20 77 69 6c 6c .assemblers will
13dc0 2e 20 54 68 65 73 65 20 50 41 4c 38 20 65 6d 75 . These PAL8 emu
13dd0 6c 61 74 69 6e 67 20 6f 70 2d 63 6f 64 65 73 20 lating op-codes
13de0 61 6c 6c 6f 77 20 74 68 65 20 70 72 6f 67 72 61 allow the progra
13df0 6d 6d 65 72 20 74 6f 0a 62 79 70 61 73 73 20 74 mmer to.bypass t
13e00 68 69 73 20 62 65 68 61 76 69 6f 72 20 6f 66 20 his behavior of
13e10 53 41 42 52 20 77 68 65 6e 20 69 74 20 69 73 6e SABR when it isn
13e20 e2 80 99 74 20 68 65 6c 70 66 75 6c 2e 20 53 65 ’t helpful. Se
13e30 65 20 74 68 65 0a 64 6f 63 75 6d 65 6e 74 61 74 e the.documentat
13e40 69 6f 6e 20 6f 6e 20 53 41 42 52 20 6c 69 6e 6b ion on SABR link
13e50 20 67 65 6e 65 72 61 74 69 6f 6e 20 69 6e 20 74 generation in t
13e60 68 65 20 4f 53 2f 38 20 48 61 6e 64 62 6f 6f 6b he OS/8 Handbook
13e70 2e 0a 0a 5b 6f 73 38 68 61 63 5d 3a 20 68 74 74 ...[os8hac]: htt
13e80 70 73 3a 2f 2f 61 72 63 68 69 76 65 2e 6f 72 67 ps://archive.org
13e90 2f 64 65 74 61 69 6c 73 2f 62 69 74 73 61 76 65 /details/bitsave
13ea0 72 73 5f 64 65 63 70 64 70 38 6f 73 38 5f 33 39 rs_decpdp8os8_39
13eb0 34 31 34 37 39 32 2f 70 61 67 65 2f 6e 38 37 35 414792/page/n875
13ec0 0a 0a 0a 23 23 20 43 6f 6e 63 6c 75 73 69 6f 6e ...## Conclusion
13ed0 0a 0a 54 68 69 73 20 69 73 20 61 20 73 6f 6d 65 ..This is a some
13ee0 77 68 61 74 20 6c 69 6d 69 74 65 64 20 6d 61 6e what limited man
13ef0 75 61 6c 20 77 68 69 63 68 20 61 74 74 65 6d 70 ual which attemp
13f00 74 73 20 74 6f 20 67 69 76 65 20 61 6e 20 6f 75 ts to give an ou
13f10 74 6c 69 6e 65 20 6f 66 20 61 0a 76 65 72 79 20 tline of a.very
13f20 73 69 6d 70 6c 65 20 63 6f 6d 70 69 6c 65 72 20 simple compiler
13f30 66 6f 72 20 77 68 69 63 68 20 77 65 20 61 70 6f for which we apo
13f40 6c 6f 67 69 73 65 20 61 73 20 74 68 65 20 73 6f logise as the so
13f50 75 72 63 65 20 63 6f 64 65 20 69 73 0a 6f 62 73 urce code is.obs
13f60 63 75 72 65 20 61 6e 64 20 62 61 64 6c 79 20 63 cure and badly c
13f70 6f 6d 6d 65 6e 74 65 64 2e 20 48 6f 77 65 76 65 ommented. Howeve
13f80 72 2c 20 74 68 65 20 6e 61 74 69 76 65 20 4f 53 r, the native OS
13f90 2f 38 20 63 6f 6d 70 69 6c 65 72 2f 74 6f 6b 65 /8 compiler/toke
13fa0 6e 69 73 65 72 0a 28 60 6e 38 2e 63 60 29 20 69 niser.(`n8.c`) i
13fb0 73 20 6f 6e 6c 79 20 36 30 30 20 6c 69 6e 65 73 s only 600 lines
13fc0 20 77 68 69 63 68 20 69 73 20 61 20 6e 6f 74 68 which is a noth
13fd0 69 6e 67 20 69 6e 20 74 68 65 20 73 63 61 6c 65 ing in the scale
13fe0 20 6f 66 20 74 68 69 6e 67 73 0a 74 68 65 73 65 of things.these
13ff0 20 64 61 79 73 2e 20 20 48 6f 77 65 76 65 72 2c days. However,
14000 20 77 65 20 68 6f 70 65 20 74 68 69 73 20 70 72 we hope this pr
14010 6f 6a 65 63 74 20 67 69 76 65 73 20 73 6f 6d 65 oject gives some
14020 20 69 6e 73 69 67 68 74 20 69 6e 74 6f 0a 63 6f insight into.co
14030 6d 70 69 6c 65 72 20 64 65 73 69 67 6e 20 61 6e mpiler design an
14040 64 20 63 6f 64 65 20 67 65 6e 65 72 61 74 69 6f d code generatio
14050 6e 20 73 74 72 61 74 65 67 69 65 73 20 74 6f 20 n strategies to
14060 74 61 72 67 65 74 20 61 20 6d 6f 73 74 0a 72 65 target a most.re
14070 6d 61 72 6b 61 62 6c 65 20 63 6f 6d 70 75 74 65 markable compute
14080 72 2e 20 57 65 20 77 6f 75 6c 64 20 61 6c 73 6f r. We would also
14090 20 6c 69 6b 65 20 74 6f 20 67 69 76 65 20 63 72 like to give cr
140a0 65 64 69 74 20 74 6f 20 74 68 65 20 62 75 69 6c edit to the buil
140b0 64 65 72 73 0a 6f 66 20 4f 53 2f 38 20 61 6e 64 ders.of OS/8 and
140c0 20 69 6e 20 70 61 72 74 69 63 75 6c 61 72 20 74 in particular t
140d0 68 65 20 46 4f 52 54 52 41 4e 20 49 49 20 73 79 he FORTRAN II sy
140e0 73 74 65 6d 20 77 68 69 63 68 20 77 61 73 20 6e stem which was n
140f0 65 76 65 72 20 64 65 73 69 67 6e 65 64 0a 74 6f ever designed.to
14100 20 73 75 72 76 69 76 65 20 74 68 65 20 6f 6e 73 survive the ons
14110 6c 61 75 67 68 74 20 6f 66 20 74 68 69 73 20 6b laught of this k
14120 69 6e 64 20 6f 66 20 6d 6f 64 65 72 6e 20 73 6f ind of modern so
14130 66 74 77 61 72 65 2e 0a 0a 44 6f 6e e2 80 99 74 ftware...Don’t
14140 20 65 78 70 65 63 74 20 74 6f 6f 20 6d 75 63 68 expect too much
14150 21 20 54 68 69 73 20 63 6f 6d 70 69 6c 65 72 20 ! This compiler
14160 77 69 6c 6c 20 6e 6f 74 20 62 75 69 6c 64 20 74 will not build t
14170 68 69 73 20 77 65 65 6b e2 80 99 73 20 62 6c 65 his week’s ble
14180 65 64 69 6e 67 0a 65 64 67 65 20 6b 65 72 6e 65 eding.edge kerne
14190 6c 2e 20 42 75 74 2c 20 69 74 20 6d 61 79 20 62 l. But, it may b
141a0 65 20 75 73 65 64 20 74 6f 20 62 75 69 6c 64 20 e used to build
141b0 61 6e 79 20 6e 75 6d 62 65 72 20 6f 66 20 75 73 any number of us
141c0 65 66 75 6c 20 75 74 69 6c 69 74 79 0a 70 72 6f eful utility.pro
141d0 67 72 61 6d 73 20 66 6f 72 20 4f 53 2f 38 2e 0a grams for OS/8..
141e0 0a 0a 23 23 20 4c 69 63 65 6e 73 65 0a 0a 54 68 ..## License..Th
141f0 69 73 20 64 6f 63 75 6d 65 6e 74 20 69 73 20 75 is document is u
14200 6e 64 65 72 20 74 68 65 20 5b 47 4e 55 20 47 50 nder the [GNU GP
14210 4c 76 33 20 4c 69 63 65 6e 73 65 5d 5b 67 70 6c Lv3 License][gpl
14220 5d 2c 20 63 6f 70 79 72 69 67 68 74 20 c2 a9 20 ], copyright ©
14230 4d 61 79 2c 0a 4a 75 6e 65 2c 20 61 6e 64 20 4e May,.June, and N
14240 6f 76 65 6d 62 65 72 20 32 30 31 37 20 62 79 20 ovember 2017 by
14250 5b 49 61 6e 20 53 63 68 6f 66 69 65 6c 64 5d 5b [Ian Schofield][
14260 69 61 6e 5d 2c 20 77 69 74 68 20 6c 61 74 65 72 ian], with later
14270 20 69 6d 70 72 6f 76 65 6d 65 6e 74 73 0a 62 79 improvements.by
14280 20 5b 57 61 72 72 65 6e 20 59 6f 75 6e 67 5d 5b [Warren Young][
14290 77 79 5d 20 69 6e 20 32 30 31 37 20 61 6e 64 20 wy] in 2017 and
142a0 32 30 31 39 2e 0a 0a 5b 67 70 6c 5d 3a 20 68 74 2019...[gpl]: ht
142b0 74 70 73 3a 2f 2f 77 77 77 2e 67 6e 75 2e 6f 72 tps://www.gnu.or
142c0 67 2f 6c 69 63 65 6e 73 65 73 2f 67 70 6c 2e 68 g/licenses/gpl.h
142d0 74 6d 6c 0a 5b 69 61 6e 5d 3a 20 6d 61 69 6c 74 tml.[ian]: mailt
142e0 6f 3a 49 73 79 73 78 70 40 67 6d 61 69 6c 2e 63 o:Isysxp@gmail.c
142f0 6f 6d 0a 5b 77 79 5d 3a 20 20 68 74 74 70 73 3a om.[wy]: https:
14300 2f 2f 74 61 6e 67 65 6e 74 73 6f 66 74 2e 63 6f //tangentsoft.co
14310 6d 2f 0a m/.