PiDP-8/I Software

Hex Artifact Content
Log In

Artifact 9fe63e83cc026c04d1f2af2fd70d1100e7386dd16f890368dd38cde4da283125:


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 68 74 74 70 3a 2f 2f  .[gti]:  http://
1fa0: 6c 6f 63 61 6c 68 6f 73 74 3a 38 30 38 30 2f 77  localhost:8080/w
1fb0: 69 6b 69 3f 6e 61 6d 65 3d 47 65 74 74 69 6e 67  iki?name=Getting
1fc0: 2b 54 65 78 74 2b 49 6e 0a 5b 6b 72 63 5d 3a 20  +Text+In.[krc]: 
1fd0: 20 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b 69   https://en.wiki
1fe0: 70 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 54  pedia.org/wiki/T
1ff0: 68 65 5f 43 5f 50 72 6f 67 72 61 6d 6d 69 6e 67  he_C_Programming
2000: 5f 4c 61 6e 67 75 61 67 65 0a 5b 73 61 62 72 5d  _Language.[sabr]
2010: 3a 20 2f 77 69 6b 69 3f 6e 61 6d 65 3d 41 2b 46  : /wiki?name=A+F
2020: 69 65 6c 64 2b 47 75 69 64 65 2b 74 6f 2b 50 44  ield+Guide+to+PD
2030: 50 2d 38 2b 41 73 73 65 6d 62 6c 65 72 73 23 73  P-8+Assemblers#s
2040: 61 62 72 0a 5b 73 63 38 30 5d 3a 20 68 74 74 70  abr.[sc80]: http
2050: 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61  s://en.wikipedia
2060: 2e 6f 72 67 2f 77 69 6b 69 2f 53 6d 61 6c 6c 2d  .org/wiki/Small-
2070: 43 0a 5b 73 63 38 35 5d 3a 20 68 74 74 70 73 3a  C.[sc85]: https:
2080: 2f 2f 67 69 74 68 75 62 2e 63 6f 6d 2f 6e 63 62  //github.com/ncb
2090: 38 35 2f 53 6d 61 6c 6c 43 2d 38 35 0a 0a 0a 3c  85/SmallC-85...<
20a0: 61 20 69 64 3d 22 63 70 70 22 3e 3c 2f 61 3e 0a  a id="cpp"></a>.
20b0: 23 23 23 20 54 68 65 20 43 72 6f 73 73 2d 43 6f  ### The Cross-Co
20c0: 6d 70 69 6c 65 72 e2 80 99 73 20 50 72 65 70 72  mpiler’s Prepr
20d0: 6f 63 65 73 73 6f 72 20 46 65 61 74 75 72 65 73  ocessor Features
20e0: 0a 0a 54 68 65 20 63 72 6f 73 73 2d 63 6f 6d 70  ..The cross-comp
20f0: 69 6c 65 72 20 68 61 73 20 72 75 64 69 6d 65 6e  iler has rudimen
2100: 74 61 72 79 20 43 20 70 72 65 70 72 6f 63 65 73  tary C preproces
2110: 73 6f 72 20 66 65 61 74 75 72 65 73 3a 0a 0a 2a  sor features:..*
2120: 20 20 20 4c 69 74 65 72 61 6c 20 60 23 64 65 66     Literal `#def
2130: 69 6e 65 60 20 6f 6e 6c 79 2e 20 20 59 6f 75 20  ine` only.  You 
2140: 63 61 6e 6e 6f 74 20 64 65 66 69 6e 65 20 70 61  cannot define pa
2150: 72 61 6d 65 74 65 72 69 7a 65 64 20 6d 61 63 72  rameterized macr
2160: 6f 73 2e 0a 0a 2a 20 20 20 54 68 65 72 65 20 61  os...*   There a
2170: 72 65 20 6e 6f 20 74 6f 6b 65 6e 20 70 61 73 74  re no token past
2180: 69 6e 67 20 28 60 23 23 60 29 2c 20 73 74 72 69  ing (`##`), stri
2190: 6e 67 69 7a 61 74 69 6f 6e 20 28 60 23 60 29 2c  ngization (`#`),
21a0: 20 6f 72 0a 20 20 20 20 63 68 61 72 69 7a 61 74   or.    charizat
21b0: 69 6f 6e 20 28 60 23 40 60 29 20 66 65 61 74 75  ion (`#@`) featu
21c0: 72 65 73 2c 20 74 68 65 72 65 20 62 65 69 6e 67  res, there being
21d0: 20 6c 69 74 74 6c 65 20 70 6f 69 6e 74 20 74 6f   little point to
21e0: 20 74 68 65 73 65 0a 20 20 20 20 66 65 61 74 75   these.    featu
21f0: 65 72 73 20 6f 66 20 74 68 65 20 43 20 70 72 65  ers of the C pre
2200: 70 72 6f 63 65 73 73 6f 72 20 77 69 74 68 6f 75  processor withou
2210: 74 20 70 61 72 61 6d 65 74 65 72 69 7a 65 64 20  t parameterized 
2220: 6d 61 63 72 6f 73 2e 0a 0a 2a 20 20 20 60 23 75  macros...*   `#u
2230: 6e 64 65 66 60 20 72 65 6d 6f 76 65 73 20 61 20  ndef` removes a 
2240: 73 79 6d 62 6f 6c 20 70 72 65 76 69 6f 75 73 6c  symbol previousl
2250: 79 20 64 65 66 69 6e 65 64 20 77 69 74 68 20 60  y defined with `
2260: 23 64 65 66 69 6e 65 60 0a 0a 2a 20 20 20 54 68  #define`..*   Th
2270: 65 72 65 20 61 72 65 20 6e 6f 20 60 2d 44 60 20  ere are no `-D` 
2280: 6f 72 20 60 2d 55 60 20 66 6c 61 67 73 20 74 6f  or `-U` flags to
2290: 20 64 65 66 69 6e 65 20 61 6e 64 20 75 6e 64 65   define and unde
22a0: 66 69 6e 65 20 6d 61 63 72 6f 73 20 66 72 6f 6d  fine macros from
22b0: 0a 20 20 20 20 74 68 65 20 63 6f 6d 6d 61 6e 64  .    the command
22c0: 20 6c 69 6e 65 2e 0a 0a 2a 20 20 20 60 23 69 6e   line...*   `#in
22d0: 63 6c 75 64 65 60 2c 20 62 75 74 20 6f 6e 6c 79  clude`, but only
22e0: 20 66 6f 72 20 66 69 6c 65 73 20 69 6e 20 74 68   for files in th
22f0: 65 20 63 75 72 72 65 6e 74 20 64 69 72 65 63 74  e current direct
2300: 6f 72 79 2e 20 20 54 68 65 72 65 20 69 73 0a 20  ory.  There is. 
2310: 20 20 20 6e 6f 20 69 6e 63 6c 75 64 65 20 70 61     no include pa
2320: 74 68 2c 20 65 69 74 68 65 72 20 68 61 72 64 2d  th, either hard-
2330: 63 6f 64 65 64 20 77 69 74 68 69 6e 20 74 68 65  coded within the
2340: 20 63 6f 6d 70 69 6c 65 72 20 6f 72 20 6d 6f 64   compiler or mod
2350: 69 66 69 61 62 6c 65 0a 20 20 20 20 76 69 61 20  ifiable.    via 
2360: 74 68 65 20 74 72 61 64 69 74 69 6f 6e 61 6c 20  the traditional 
2370: 60 2d 49 60 20 63 6f 6d 70 69 6c 65 72 20 66 6c  `-I` compiler fl
2380: 61 67 2e 20 49 74 20 69 73 20 6c 65 67 61 6c 20  ag. It is legal 
2390: 74 6f 20 6e 65 73 74 20 60 23 69 6e 63 6c 75 64  to nest `#includ
23a0: 65 60 0a 20 20 20 20 73 74 61 74 65 6d 65 6e 74  e`.    statement
23b0: 73 2c 20 62 75 74 20 74 68 65 20 64 65 70 74 68  s, but the depth
23c0: 20 69 73 20 63 75 72 72 65 6e 74 6c 79 20 6c 69   is currently li
23d0: 6d 69 74 65 64 20 74 6f 20 33 20 6c 65 76 65 6c  mited to 3 level
23e0: 73 2c 20 6d 61 78 69 6d 75 6d 2e 0a 0a 2a 20 20  s, maximum...*  
23f0: 20 5b 49 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c   [Inline assembl
2400: 79 5d 28 23 61 73 6d 29 20 76 69 61 20 60 23 61  y](#asm) via `#a
2410: 73 6d 60 2e 0a 0a 2a 20 20 20 60 23 69 66 64 65  sm`...*   `#ifde
2420: 66 60 2c 20 60 23 69 66 6e 64 65 66 60 2c 20 60  f`, `#ifndef`, `
2430: 23 65 6c 73 65 60 20 61 6e 64 20 60 23 65 6e 64  #else` and `#end
2440: 69 66 60 20 77 6f 72 6b 20 61 73 20 65 78 70 65  if` work as expe
2450: 63 74 65 64 2c 20 77 69 74 68 69 6e 0a 20 20 20  cted, within.   
2460: 20 74 68 65 20 6c 69 6d 69 74 61 74 69 6f 6e 73   the limitations
2470: 20 6f 6e 20 6d 61 63 72 6f 73 20 67 69 76 65 6e   on macros given
2480: 20 61 62 6f 76 65 2e 0a 0a 2a 20 20 20 54 68 65   above...*   The
2490: 72 65 20 69 73 20 6e 6f 20 73 75 70 70 6f 72 74  re is no support
24a0: 20 66 6f 72 20 60 23 69 66 60 2c 20 6e 6f 74 20   for `#if`, not 
24b0: 65 76 65 6e 20 66 6f 72 20 73 69 6d 70 6c 65 20  even for simple 
24c0: 74 68 69 6e 67 73 20 6c 69 6b 65 20 60 23 69 66  things like `#if
24d0: 0a 20 20 20 20 30 60 2c 20 6d 75 63 68 20 6c 65  .    0`, much le
24e0: 73 73 20 66 6f 72 20 65 78 70 72 65 73 73 69 6f  ss for expressio
24f0: 6e 73 20 73 75 63 68 20 61 73 20 60 23 69 66 20  ns such as `#if 
2500: 64 65 66 69 6e 65 64 28 58 58 58 29 20 26 26 0a  defined(XXX) &&.
2510: 20 20 20 20 21 64 65 66 69 6e 65 64 28 59 59 59      !defined(YYY
2520: 29 60 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22  )`...### <a id="
2530: 6e 68 65 61 64 22 3e 3c 2f 61 3e 4e 65 63 65 73  nhead"></a>Neces
2540: 73 61 72 79 20 48 65 61 64 65 72 73 0a 0a 54 68  sary Headers..Th
2550: 65 72 65 20 61 72 65 20 74 77 6f 20 68 65 61 64  ere are two head
2560: 65 72 20 66 69 6c 65 73 2c 20 66 6f 72 20 75 73  er files, for us
2570: 65 20 77 69 74 68 20 74 68 65 20 63 72 6f 73 73  e with the cross
2580: 2d 63 6f 6d 70 69 6c 65 72 20 6f 6e 6c 79 3a 0a  -compiler only:.
2590: 0a 2a 20 20 20 60 6c 69 62 63 2e 68 60 20 e2 80  .*   `libc.h` 
25a0: 94 20 44 65 63 6c 61 72 65 73 20 74 68 65 20 65   Declares the e
25b0: 6e 74 72 79 20 70 6f 69 6e 74 73 20 75 73 65 64  ntry points used
25c0: 20 62 79 20 5b 4c 49 42 43 5d 28 23 6c 69 62 63   by [LIBC](#libc
25d0: 29 20 75 73 69 6e 67 0a 20 20 20 20 43 43 38 20  ) using.    CC8 
25e0: 5b 6c 69 62 72 61 72 79 20 6c 69 6e 6b 61 67 65  [library linkage
25f0: 20 64 69 72 65 63 74 69 76 65 73 5d 28 23 6c 69   directives](#li
2600: 6e 6b 61 67 65 29 2e 20 49 66 20 79 6f 75 72 20  nkage). If your 
2610: 70 72 6f 67 72 61 6d 20 6d 61 6b 65 73 0a 20 20  program makes.  
2620: 20 20 75 73 65 20 6f 66 20 61 6e 79 20 6c 69 62    use of any lib
2630: 72 61 72 79 20 66 75 6e 63 74 69 6f 6e 73 2c 20  rary functions, 
2640: 79 6f 75 20 6d 75 73 74 20 60 23 69 6e 63 6c 75  you must `#inclu
2650: 64 65 60 20 74 68 69 73 20 61 74 20 74 68 65 20  de` this at the 
2660: 74 6f 70 20 6f 66 0a 20 20 20 20 79 6f 75 72 20  top of.    your 
2670: 70 72 6f 67 72 61 6d 2e 0a 0a 2a 20 20 20 60 69  program...*   `i
2680: 6e 69 74 2e 68 60 20 e2 80 94 20 49 6e 73 65 72  nit.h` — Inser
2690: 74 73 20 61 20 62 6c 6f 63 6b 20 6f 66 20 5b 69  ts a block of [i
26a0: 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c 79 5d 28  nline assembly](
26b0: 23 61 73 6d 29 20 73 74 61 72 74 75 70 20 63 6f  #asm) startup co
26c0: 64 65 0a 20 20 20 20 69 6e 74 6f 20 79 6f 75 72  de.    into your
26d0: 20 70 72 6f 67 72 61 6d 2c 20 77 68 69 63 68 20   program, which 
26e0: 69 6e 69 74 69 61 6c 69 7a 65 73 20 74 68 65 20  initializes the 
26f0: 70 72 6f 67 72 61 6d 20 65 6e 76 69 72 6f 6e 6d  program environm
2700: 65 6e 74 2c 20 73 65 74 73 0a 20 20 20 20 75 70  ent, sets.    up
2710: 20 4c 49 42 43 2c 20 61 6e 64 20 64 65 66 69 6e   LIBC, and defin
2720: 65 73 20 61 20 66 65 77 20 6c 6f 77 2d 6c 65 76  es a few low-lev
2730: 65 6c 20 72 6f 75 74 69 6e 65 73 2e 20 55 6e 6c  el routines. Unl
2740: 65 73 73 20 79 6f 75 20 6b 6e 6f 77 20 74 68 69  ess you know thi
2750: 73 0a 20 20 20 20 66 69 6c 65 e2 80 99 73 20 63  s.    file’s c
2760: 6f 6e 74 65 6e 74 73 20 61 6e 64 20 68 61 76 65  ontents and have
2770: 20 64 65 74 65 72 6d 69 6e 65 64 20 74 68 61 74   determined that
2780: 20 79 6f 75 20 64 6f 20 6e 6f 74 20 6e 65 65 64   you do not need
2790: 20 61 6e 79 20 6f 66 20 77 68 61 74 0a 20 20 20   any of what.   
27a0: 20 69 74 20 64 6f 65 73 20 66 6f 72 20 79 6f 75   it does for you
27b0: 2c 20 79 6f 75 20 70 72 6f 62 61 62 6c 79 20 63  , you probably c
27c0: 61 6e 6e 6f 74 20 77 72 69 74 65 20 61 20 76 61  annot write a va
27d0: 6c 69 64 20 43 43 38 20 70 72 6f 67 72 61 6d 20  lid CC8 program 
27e0: 74 68 61 74 0a 20 20 20 20 64 6f 65 73 20 6e 6f  that.    does no
27f0: 74 20 60 23 69 6e 63 6c 75 64 65 60 20 74 68 69  t `#include` thi
2800: 73 20 68 65 61 64 65 72 2e 0a 0a 42 65 63 61 75  s header...Becau
2810: 73 65 20 74 68 65 20 63 72 6f 73 73 2d 63 6f 6d  se the cross-com
2820: 70 69 6c 65 72 20 6c 61 63 6b 73 20 61 6e 20 69  piler lacks an i
2830: 6e 63 6c 75 64 65 20 70 61 74 68 20 66 65 61 74  nclude path feat
2840: 75 72 65 2c 20 79 6f 75 20 67 65 6e 65 72 61 6c  ure, you general
2850: 6c 79 0a 77 61 6e 74 20 74 6f 20 73 79 6d 6c 69  ly.want to symli
2860: 6e 6b 20 74 68 65 73 65 20 66 69 6c 65 73 20 74  nk these files t
2870: 6f 20 74 68 65 20 64 69 72 65 63 74 6f 72 79 20  o the directory 
2880: 77 68 65 72 65 20 79 6f 75 72 20 73 6f 75 72 63  where your sourc
2890: 65 20 66 69 6c 65 73 0a 61 72 65 2e 20 54 68 69  e files.are. Thi
28a0: 73 20 69 73 20 61 6c 72 65 61 64 79 20 64 6f 6e  s is already don
28b0: 65 20 66 6f 72 20 74 68 65 20 43 43 38 20 65 78  e for the CC8 ex
28c0: 61 6d 70 6c 65 73 20 61 6e 64 20 73 75 63 68 2e  amples and such.
28d0: 0a 0a 49 66 20 79 6f 75 20 63 6f 6d 70 61 72 65  ..If you compare
28e0: 20 74 68 65 20 65 78 61 6d 70 6c 65 73 20 69 6e   the examples in
28f0: 20 74 68 65 20 73 6f 75 72 63 65 20 74 72 65 65   the source tree
2900: 20 28 60 73 72 63 2f 63 63 38 2f 65 78 61 6d 70   (`src/cc8/examp
2910: 6c 65 73 60 29 20 74 6f 0a 74 68 6f 73 65 20 77  les`) to.those w
2920: 69 74 68 20 75 70 70 65 72 63 61 73 65 64 20 76  ith uppercased v
2930: 65 72 73 69 6f 6e 73 20 6f 66 20 74 68 6f 73 65  ersions of those
2940: 20 73 61 6d 65 20 6e 61 6d 65 73 20 6f 6e 20 74   same names on t
2950: 68 65 20 4f 53 2f 38 20 60 44 53 4b 3a 60 0a 76  he OS/8 `DSK:`.v
2960: 6f 6c 75 6d 65 2c 20 79 6f 75 e2 80 99 6c 6c 20  olume, you’ll 
2970: 6e 6f 74 69 63 65 20 74 68 61 74 20 74 68 65 73  notice that thes
2980: 65 20 60 23 69 6e 63 6c 75 64 65 60 20 73 74 61  e `#include` sta
2990: 74 65 6d 65 6e 74 73 20 77 65 72 65 20 73 74 72  tements were str
29a0: 69 70 70 65 64 20 6f 75 74 0a 61 73 20 70 61 72  ipped out.as par
29b0: 74 20 6f 66 20 74 68 65 20 64 69 73 6b 20 70 61  t of the disk pa
29c0: 63 6b 20 62 75 69 6c 64 20 70 72 6f 63 65 73 73  ck build process
29d0: 2e 20 54 68 69 73 20 69 73 20 5b 6e 65 63 65 73  . This is [neces
29e0: 73 61 72 79 5d 28 23 6f 73 38 70 70 29 3b 20 74  sary](#os8pp); t
29f0: 68 65 0a 6c 69 6e 6b 65 64 20 64 6f 63 75 6d 65  he.linked docume
2a00: 6e 74 61 74 69 6f 6e 20 74 65 6c 6c 73 20 79 6f  ntation tells yo
2a10: 75 20 77 68 79 20 61 6e 64 20 68 6f 77 20 74 68  u why and how th
2a20: 65 20 4f 53 2f 38 20 76 65 72 73 69 6f 6e 20 6f  e OS/8 version o
2a30: 66 20 43 43 38 20 67 65 74 73 0a 61 77 61 79 20  f CC8 gets.away 
2a40: 77 69 74 68 6f 75 74 20 61 20 60 23 69 6e 63 6c  without a `#incl
2a50: 75 64 65 60 20 66 65 61 74 75 72 65 2e 0a 0a 49  ude` feature...I
2a60: 66 20 79 6f 75 20 6e 65 65 64 20 74 6f 20 77 72  f you need to wr
2a70: 69 74 65 20 43 20 70 72 6f 67 72 61 6d 73 20 74  ite C programs t
2a80: 68 61 74 20 62 75 69 6c 64 20 77 69 74 68 20 62  hat build with b
2a90: 6f 74 68 20 63 6f 6d 70 69 6c 65 72 73 2c 20 79  oth compilers, y
2aa0: 6f 75 20 63 61 6e 0a 63 6f 6e 76 65 72 74 20 74  ou can.convert t
2ab0: 68 65 20 66 69 6c 65 73 20 6c 69 6b 65 20 73 6f  he files like so
2ac0: 3a 0a 0a 20 20 20 20 73 65 64 20 27 2f 5e 23 69  :..    sed '/^#i
2ad0: 6e 63 6c 75 64 65 2f 64 27 20 3c 20 6d 79 2d 70  nclude/d' < my-p
2ae0: 72 6f 67 72 61 6d 2d 63 72 6f 73 73 2e 63 20 3e  rogram-cross.c >
2af0: 20 4d 59 50 52 4f 47 2e 43 0a 0a 0a 3c 61 20 69   MYPROG.C...<a i
2b00: 64 3d 22 6e 61 74 69 76 65 22 20 6e 61 6d 65 3d  d="native" name=
2b10: 22 6f 73 38 22 3e 3c 2f 61 3e 0a 23 23 20 54 68  "os8"></a>.## Th
2b20: 65 20 4e 61 74 69 76 65 20 4f 53 2f 38 20 43 6f  e Native OS/8 Co
2b30: 6d 70 69 6c 65 72 0a 0a 57 68 65 72 65 61 73 20  mpiler..Whereas 
2b40: 74 68 65 20 5b 43 43 38 20 63 72 6f 73 73 2d 63  the [CC8 cross-c
2b50: 6f 6d 70 69 6c 65 72 5d 28 23 63 72 6f 73 73 29  ompiler](#cross)
2b60: 20 69 73 20 62 61 73 69 63 61 6c 6c 79 20 6a 75   is basically ju
2b70: 73 74 20 61 20 50 44 50 2d 38 20 63 6f 64 65 0a  st a PDP-8 code.
2b80: 67 65 6e 65 72 61 74 6f 72 20 73 74 72 61 70 70  generator strapp
2b90: 65 64 20 74 6f 20 74 68 65 20 70 72 65 65 78 69  ed to the preexi
2ba0: 73 74 69 6e 67 20 53 6d 61 6c 6c 2d 43 20 63 6f  sting Small-C co
2bb0: 6d 70 69 6c 65 72 2c 20 74 68 65 20 6e 61 74 69  mpiler, the nati
2bc0: 76 65 20 4f 53 2f 38 0a 43 43 38 20 63 6f 6d 70  ve OS/8.CC8 comp
2bd0: 69 6c 65 72 20 77 61 73 20 77 72 69 74 74 65 6e  iler was written
2be0: 20 66 72 6f 6d 20 73 63 72 61 74 63 68 20 62 79   from scratch by
2bf0: 20 49 61 6e 20 53 63 68 6f 66 69 65 6c 64 2e 20   Ian Schofield. 
2c00: 49 74 20 67 65 74 73 0a 63 72 6f 73 73 2d 63 6f  It gets.cross-co
2c10: 6d 70 69 6c 65 64 2c 20 61 73 73 65 6d 62 6c 65  mpiled, assemble
2c20: 64 2c 20 6c 69 6e 6b 65 64 2c 20 61 6e 64 20 73  d, linked, and s
2c30: 61 76 65 64 20 74 6f 20 74 68 65 20 4f 53 2f 38  aved to the OS/8
2c40: 20 64 69 73 6b 20 70 61 63 6b 73 20 61 73 0a 70   disk packs as.p
2c50: 61 72 74 20 6f 66 20 74 68 65 20 50 69 44 50 2d  art of the PiDP-
2c60: 38 2f 49 20 73 6f 66 74 77 61 72 65 20 62 75 69  8/I software bui
2c70: 6c 64 20 70 72 6f 63 65 73 73 2e 20 54 68 65 72  ld process. Ther
2c80: 65 61 66 74 65 72 2c 20 69 74 20 69 73 20 61 0a  eafter, it is a.
2c90: 73 74 61 6e 64 61 6c 6f 6e 65 20 73 79 73 74 65  standalone syste
2ca0: 6d 20 75 73 69 6e 67 20 6f 6e 6c 79 20 4f 53 2f  m using only OS/
2cb0: 38 20 72 65 73 6f 75 72 63 65 73 2e 0a 0a 42 65  8 resources...Be
2cc0: 63 61 75 73 65 20 74 68 69 73 20 63 6f 6d 70 69  cause this compi
2cd0: 6c 65 72 20 6d 75 73 74 20 77 6f 72 6b 20 65 6e  ler must work en
2ce0: 74 69 72 65 6c 79 20 77 69 74 68 69 6e 20 74 68  tirely within th
2cf0: 65 20 73 74 72 69 6e 67 65 6e 74 20 6c 69 6d 69  e stringent limi
2d00: 74 73 20 6f 66 0a 74 68 65 20 50 44 50 2d 38 20  ts of.the PDP-8 
2d10: 63 6f 6d 70 75 74 65 72 20 61 72 63 68 69 74 65  computer archite
2d20: 63 74 75 72 65 20 61 6e 64 20 69 74 73 20 4f 53  cture and its OS
2d30: 2f 38 20 6f 70 65 72 61 74 69 6e 67 20 73 79 73  /8 operating sys
2d40: 74 65 6d 2c 20 69 74 20 73 70 65 61 6b 73 0a 61  tem, it speaks.a
2d50: 20 5b 6d 75 63 68 20 73 69 6d 70 6c 65 72 20 64   [much simpler d
2d60: 69 61 6c 65 63 74 20 6f 66 20 43 5d 28 23 6e 66  ialect of C](#nf
2d70: 65 61 74 29 20 74 68 61 6e 20 74 68 65 20 63 72  eat) than the cr
2d80: 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 2c 20 77 68  oss-compiler, wh
2d90: 69 63 68 0a 67 65 74 73 20 74 6f 20 75 73 65 20  ich.gets to use 
2da0: 79 6f 75 72 20 68 6f 73 74 e2 80 99 73 20 6d 75  your host’s mu
2db0: 63 68 20 67 72 65 61 74 65 72 20 72 65 73 6f 75  ch greater resou
2dc0: 72 63 65 73 2e 0a 0a 55 6e 6c 69 6b 65 20 77 69  rces...Unlike wi
2dd0: 74 68 20 74 68 65 20 6f 72 69 67 69 6e 61 6c 20  th the original 
2de0: 43 43 38 20 73 6f 66 74 77 61 72 65 20 64 69 73  CC8 software dis
2df0: 74 72 69 62 75 74 69 6f 6e 2c 20 74 68 65 20 50  tribution, the P
2e00: 69 44 50 2d 38 2f 49 0a 73 6f 66 74 77 61 72 65  iDP-8/I.software
2e10: 20 70 72 6f 6a 65 63 74 20 64 6f 65 73 20 6e 6f   project does no
2e20: 74 20 73 68 69 70 20 61 6e 79 20 70 72 65 2d 62  t ship any pre-b
2e30: 75 69 6c 74 20 43 43 38 20 62 69 6e 61 72 69 65  uilt CC8 binarie
2e40: 73 2e 20 20 49 6e 73 74 65 61 64 2c 20 77 65 0a  s.  Instead, we.
2e50: 62 6f 6f 74 73 74 72 61 70 20 43 43 38 20 62 69  bootstrap CC8 bi
2e60: 6e 61 72 69 65 73 20 66 72 6f 6d 20 73 6f 75 72  naries from sour
2e70: 63 65 20 63 6f 64 65 20 77 69 74 68 20 74 68 65  ce code with the
2e80: 20 70 6f 77 65 72 66 75 6c 0a 5b 60 6f 73 38 2d   powerful.[`os8-
2e90: 72 75 6e 60 5d 5b 6f 73 38 72 5d 20 73 63 72 69  run`][os8r] scri
2ea0: 70 74 69 6e 67 20 6c 61 6e 67 75 61 67 65 20 69  pting language i
2eb0: 6e 74 65 72 70 72 65 74 65 72 20 61 6e 64 20 74  nterpreter and t
2ec0: 68 65 20 50 69 44 50 2d 38 2f 49 0a 73 6f 66 74  he PiDP-8/I.soft
2ed0: 77 61 72 65 20 62 75 69 6c 64 20 73 79 73 74 65  ware build syste
2ee0: 6d 2e 20 20 28 59 6f 75 20 63 61 6e 20 73 75 70  m.  (You can sup
2ef0: 70 72 65 73 73 20 74 68 69 73 20 62 79 20 70 61  press this by pa
2f00: 73 73 69 6e 67 20 74 68 65 0a 60 2d 2d 64 69 73  ssing the.`--dis
2f10: 61 62 6c 65 2d 6f 73 38 2d 63 63 38 60 20 6f 70  able-os8-cc8` op
2f20: 74 69 6f 6e 20 74 6f 20 74 68 65 20 60 63 6f 6e  tion to the `con
2f30: 66 69 67 75 72 65 60 20 73 63 72 69 70 74 2e 29  figure` script.)
2f40: 20 54 68 69 73 20 70 72 6f 63 65 73 73 20 69 73   This process is
2f50: 0a 63 6f 6e 74 72 6f 6c 6c 65 64 20 62 79 20 74  .controlled by t
2f60: 68 65 20 5b 60 63 63 38 2d 74 75 35 36 2e 6f 73  he [`cc8-tu56.os
2f70: 38 60 5d 5b 63 63 74 75 5d 20 73 63 72 69 70 74  8`][cctu] script
2f80: 2c 20 77 68 69 63 68 20 79 6f 75 20 6d 61 79 20  , which you may 
2f90: 77 61 6e 74 20 74 6f 0a 65 78 61 6d 69 6e 65 20  want to.examine 
2fa0: 61 6c 6f 6e 67 20 77 69 74 68 20 74 68 65 20 60  along with the `
2fb0: 6f 73 38 2d 72 75 6e 60 20 64 6f 63 75 6d 65 6e  os8-run` documen
2fc0: 74 61 74 69 6f 6e 20 74 6f 20 75 6e 64 65 72 73  tation to unders
2fd0: 74 61 6e 64 20 74 68 69 73 0a 70 72 6f 63 65 73  tand this.proces
2fe0: 73 20 62 65 74 74 65 72 2e 0a 0a 49 66 20 79 6f  s better...If yo
2ff0: 75 20 63 68 61 6e 67 65 20 74 68 65 20 4f 53 2f  u change the OS/
3000: 38 20 43 43 38 20 73 6f 75 72 63 65 20 63 6f 64  8 CC8 source cod
3010: 65 2c 20 73 61 79 69 6e 67 20 60 6d 61 6b 65 60  e, saying `make`
3020: 20 61 74 20 74 68 65 20 50 69 44 50 2d 38 2f 49   at the PiDP-8/I
3030: 0a 62 75 69 6c 64 20 72 6f 6f 74 20 77 69 6c 6c  .build root will
3040: 20 75 70 64 61 74 65 20 60 62 69 6e 2f 76 33 64   update `bin/v3d
3050: 2e 72 6b 30 35 60 20 77 69 74 68 20 6e 65 77 20  .rk05` with new 
3060: 62 69 6e 61 72 69 65 73 20 61 75 74 6f 6d 61 74  binaries automat
3070: 69 63 61 6c 6c 79 2e 0a 0a 42 65 63 61 75 73 65  ically...Because
3080: 20 74 68 65 20 43 43 38 20 6e 61 74 69 76 65 20   the CC8 native 
3090: 63 6f 6d 70 69 6c 65 72 20 69 73 20 63 6f 6d 70  compiler is comp
30a0: 69 6c 65 64 20 62 79 20 74 68 65 20 43 43 38 20  iled by the CC8 
30b0: 2a 63 72 6f 73 73 2a 2d 63 6f 6d 70 69 6c 65 72  *cross*-compiler
30c0: 2c 0a 74 68 65 20 5b 73 74 61 6e 64 61 72 64 20  ,.the [standard 
30d0: 6d 65 6d 6f 72 79 20 6c 61 79 6f 75 74 5d 28 23  memory layout](#
30e0: 6d 65 6d 6f 72 79 29 20 61 70 70 6c 69 65 73 20  memory) applies 
30f0: 74 6f 20 62 6f 74 68 2e 20 20 41 6d 6f 6e 67 20  to both.  Among 
3100: 6f 74 68 65 72 0a 74 68 69 6e 67 73 2c 20 74 68  other.things, th
3110: 69 73 20 6d 65 61 6e 73 20 65 61 63 68 20 70 61  is means each pa
3120: 73 73 20 6f 66 20 74 68 65 20 6e 61 74 69 76 65  ss of the native
3130: 20 63 6f 6d 70 69 6c 65 72 20 72 65 71 75 69 72   compiler requir
3140: 65 73 0a 61 70 70 72 6f 78 69 6d 61 74 65 6c 79  es.approximately
3150: 20 32 30 26 6e 62 73 70 3b 6b 57 6f 72 64 73 20   20&nbsp;kWords 
3160: 6f 66 20 63 6f 72 65 2e 0a 0a 54 68 65 20 6e 61  of core...The na
3170: 74 69 76 65 20 4f 53 2f 38 20 43 43 38 20 63 6f  tive OS/8 CC8 co
3180: 6d 70 69 6c 65 72 e2 80 99 73 20 73 6f 75 72 63  mpiler’s sourc
3190: 65 20 63 6f 64 65 20 69 73 20 69 6e 20 74 68 65  e code is in the
31a0: 20 60 73 72 63 2f 63 63 38 2f 6f 73 38 60 0a 73   `src/cc8/os8`.s
31b0: 75 62 64 69 72 65 63 74 6f 72 79 20 6f 66 20 74  ubdirectory of t
31c0: 68 65 20 50 69 44 50 2d 38 2f 49 20 73 6f 66 74  he PiDP-8/I soft
31d0: 77 61 72 65 20 64 69 73 74 72 69 62 75 74 69 6f  ware distributio
31e0: 6e 2e 0a 0a 3c 61 20 69 64 3d 22 6e 63 70 61 73  n...<a id="ncpas
31f0: 73 22 3e 3c 2f 61 3e 54 68 65 20 63 6f 6d 70 69  s"></a>The compi
3200: 6c 65 72 20 70 61 73 73 65 73 20 61 72 65 3a 0a  ler passes are:.
3210: 0a 31 2e 20 20 60 63 38 2e 63 60 20 26 72 61 72  .1.  `c8.c` &rar
3220: 72 3b 20 60 63 38 2e 73 62 60 20 26 72 61 72 72  r; `c8.sb` &rarr
3230: 3b 20 60 43 43 2e 53 56 60 3a 20 54 68 65 20 63  ; `CC.SV`: The c
3240: 6f 6d 70 69 6c 65 72 20 64 72 69 76 65 72 3a 20  ompiler driver: 
3250: 61 63 63 65 70 74 73 0a 20 20 20 20 74 68 65 20  accepts.    the 
3260: 69 6e 70 75 74 20 66 69 6c 65 20 6e 61 6d 65 20  input file name 
3270: 66 72 6f 6d 20 74 68 65 20 75 73 65 72 2c 20 64  from the user, d
3280: 6f 65 73 20 73 6f 6d 65 20 5b 72 75 64 69 6d 65  oes some [rudime
3290: 6e 74 61 72 79 0a 20 20 20 20 70 72 65 70 72 6f  ntary.    prepro
32a0: 63 65 73 73 69 6e 67 5d 28 23 6f 73 38 70 70 29  cessing](#os8pp)
32b0: 20 6f 6e 20 69 74 2c 20 61 6e 64 20 63 61 6c 6c   on it, and call
32c0: 73 20 74 68 65 20 66 69 72 73 74 20 70 72 6f 70  s the first prop
32d0: 65 72 20 63 6f 6d 70 69 6c 65 72 0a 20 20 20 20  er compiler.    
32e0: 70 61 73 73 2c 20 60 43 43 31 60 2e 0a 0a 32 2e  pass, `CC1`...2.
32f0: 20 20 60 6e 38 2e 63 60 20 26 72 61 72 72 3b 20    `n8.c` &rarr; 
3300: 60 6e 38 2e 73 62 60 20 26 72 61 72 72 3b 20 60  `n8.sb` &rarr; `
3310: 43 43 31 2e 53 56 60 3a 20 54 68 65 20 70 61 72  CC1.SV`: The par
3320: 73 65 72 2f 74 6f 6b 65 6e 69 73 65 72 20 73 65  ser/tokeniser se
3330: 63 74 69 6f 6e 0a 20 20 20 20 6f 66 20 74 68 65  ction.    of the
3340: 20 63 6f 6d 70 69 6c 65 72 2e 0a 0a 33 2e 20 20   compiler...3.  
3350: 60 70 38 2e 63 60 20 26 72 61 72 72 3b 20 60 70  `p8.c` &rarr; `p
3360: 38 2e 73 62 60 20 26 72 61 72 72 3b 20 60 43 43  8.sb` &rarr; `CC
3370: 32 2e 53 56 60 3a 20 54 68 65 20 74 6f 6b 65 6e  2.SV`: The token
3380: 20 74 6f 20 53 41 42 52 20 63 6f 64 65 0a 20 20   to SABR code.  
3390: 20 20 63 6f 6e 76 65 72 74 65 72 20 73 65 63 74    converter sect
33a0: 69 6f 6e 20 6f 66 20 74 68 65 20 63 6f 6d 70 69  ion of the compi
33b0: 6c 65 72 2e 0a 0a 54 68 65 72 65 20 69 73 20 61  ler...There is a
33c0: 6c 73 6f 20 60 6c 69 62 63 2e 63 60 20 26 72 61  lso `libc.c` &ra
33d0: 72 72 3b 20 60 6c 69 62 63 2e 73 62 60 20 26 72  rr; `libc.sb` &r
33e0: 61 72 72 3b 20 60 4c 49 42 43 2e 52 4c 60 2c 20  arr; `LIBC.RL`, 
33f0: 74 68 65 20 5b 43 0a 6c 69 62 72 61 72 79 5d 28  the [C.library](
3400: 23 6c 69 62 63 29 20 6c 69 6e 6b 65 64 20 74 6f  #libc) linked to
3410: 20 61 6e 79 20 70 72 6f 67 72 61 6d 20 62 75 69   any program bui
3420: 6c 74 20 77 69 74 68 20 43 43 38 2c 20 69 6e 63  lt with CC8, inc
3430: 6c 75 64 69 6e 67 20 74 68 65 0a 70 61 73 73 65  luding the.passe
3440: 73 20 61 62 6f 76 65 2c 20 62 75 74 20 61 6c 73  s above, but als
3450: 6f 20 74 6f 20 79 6f 75 72 20 6f 77 6e 20 70 72  o to your own pr
3460: 6f 67 72 61 6d 73 2e 0a 0a 41 6c 6c 20 6f 66 20  ograms...All of 
3470: 74 68 65 73 65 20 62 69 6e 61 72 69 65 73 20 65  these binaries e
3480: 6e 64 20 75 70 20 6f 6e 20 74 68 65 20 61 75 74  nd up on the aut
3490: 6f 6d 61 74 69 63 61 6c 6c 79 2d 62 75 69 6c 74  omatically-built
34a0: 20 4f 53 2f 38 20 62 6f 6f 74 20 64 69 73 6b 3a   OS/8 boot disk:
34b0: 0a 60 43 43 3f 2e 53 56 60 20 6f 6e 20 60 53 59  .`CC?.SV` on `SY
34c0: 53 3a 60 2c 20 61 6e 64 20 65 76 65 72 79 74 68  S:`, and everyth
34d0: 69 6e 67 20 65 6c 73 65 20 6f 6e 20 60 44 53 4b  ing else on `DSK
34e0: 3a 60 2c 20 62 61 73 65 64 20 6f 6e 20 74 68 65  :`, based on the
34f0: 20 64 65 66 61 75 6c 74 73 0a 6f 75 72 20 4f 53   defaults.our OS
3500: 2f 38 20 64 69 73 74 72 69 62 75 74 69 6f 6e 20  /8 distribution 
3510: 69 73 20 63 6f 6e 66 69 67 75 72 65 64 20 74 6f  is configured to
3520: 20 75 73 65 20 77 68 65 6e 20 73 65 65 6b 69 6e   use when seekin
3530: 67 20 6f 75 74 20 66 69 6c 65 73 2e 0a 0a 49 6e  g out files...In
3540: 70 75 74 20 70 72 6f 67 72 61 6d 73 20 73 68 6f  put programs sho
3550: 75 6c 64 20 67 6f 20 6f 6e 20 60 44 53 4b 3a 60  uld go on `DSK:`
3560: 2e 20 43 6f 6d 70 69 6c 65 72 20 6f 75 74 70 75  . Compiler outpu
3570: 74 73 20 61 72 65 20 61 6c 73 6f 20 70 6c 61 63  ts are also plac
3580: 65 64 20 6f 6e 0a 60 44 53 4b 3a 60 2e 0a 0a 5b  ed on.`DSK:`...[
3590: 63 63 74 75 5d 3a 20 2f 66 69 6c 65 3f 66 6e 3d  cctu]: /file?fn=
35a0: 6d 65 64 69 61 2f 6f 73 38 2f 73 63 72 69 70 74  media/os8/script
35b0: 73 2f 63 63 38 2d 74 75 35 36 2e 6f 73 38 0a 5b  s/cc8-tu56.os8.[
35c0: 6f 73 38 72 5d 3a 20 2e 2f 6f 73 38 2d 72 75 6e  os8r]: ./os8-run
35d0: 2e 6d 64 0a 0a 0a 3c 61 20 69 64 3d 22 6e 66 65  .md...<a id="nfe
35e0: 61 74 22 20 6e 61 6d 65 3d 22 66 65 61 74 75 72  at" name="featur
35f0: 65 73 22 3e 3c 2f 61 3e 0a 23 23 23 20 46 65 61  es"></a>.### Fea
3600: 74 75 72 65 73 20 6f 66 20 74 68 65 20 4e 61 74  tures of the Nat
3610: 69 76 65 20 4f 53 2f 38 20 43 6f 6d 70 69 6c 65  ive OS/8 Compile
3620: 72 0a 0a 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67  r..The following
3630: 20 69 73 20 74 68 65 20 73 75 62 73 65 74 20 6f   is the subset o
3640: 66 20 43 20 6b 6e 6f 77 6e 20 74 6f 20 62 65 20  f C known to be 
3650: 75 6e 64 65 72 73 74 6f 6f 64 20 62 79 20 74 68  understood by th
3660: 65 20 6e 61 74 69 76 65 0a 4f 53 2f 38 20 43 43  e native.OS/8 CC
3670: 38 20 63 6f 6d 70 69 6c 65 72 3a 0a 0a 31 2e 20  8 compiler:..1. 
3680: 20 2a 2a 4c 6f 63 61 6c 20 61 6e 64 20 67 6c 6f   **Local and glo
3690: 62 61 6c 20 76 61 72 69 61 62 6c 65 73 2a 2a 0a  bal variables**.
36a0: 0a 31 2e 20 20 2a 2a 50 6f 69 6e 74 65 72 73 2c  .1.  **Pointers,
36b0: 2a 2a 20 77 69 74 68 69 6e 20 6c 69 6d 69 74 61  ** within limita
36c0: 74 69 6f 6e 73 20 67 69 76 65 6e 20 62 65 6c 6f  tions given belo
36d0: 77 2e 0a 0a 31 2e 20 20 2a 2a 46 75 6e 63 74 69  w...1.  **Functi
36e0: 6f 6e 73 3a 2a 2a 20 50 61 72 61 6d 65 74 65 72  ons:** Parameter
36f0: 20 6c 69 73 74 73 20 6d 75 73 74 20 62 65 20 64   lists must be d
3700: 65 63 6c 61 72 65 64 20 69 6e 20 4b 26 52 20 66  eclared in K&R f
3710: 6f 72 6d 3a 0a 0a 20 20 20 20 20 20 20 20 69 6e  orm:..        in
3720: 74 20 66 6f 6f 20 28 61 2c 20 62 29 0a 20 20 20  t foo (a, b).   
3730: 20 20 20 20 20 69 6e 74 20 61 2c 20 62 3b 0a 20       int a, b;. 
3740: 20 20 20 20 20 20 20 7b 0a 20 20 20 20 20 20 20         {.       
3750: 20 20 20 20 20 2e 2e 2e 0a 20 20 20 20 20 20 20       ....       
3760: 20 7d 0a 0a 31 2e 20 20 2a 2a 52 65 63 75 72 73   }..1.  **Recurs
3770: 69 6f 6e 3a 2a 2a 20 53 65 65 20 5b 60 46 49 42  ion:** See [`FIB
3780: 2e 43 60 5d 5b 66 69 62 5d 20 66 6f 72 20 61 6e  .C`][fib] for an
3790: 20 65 78 61 6d 70 6c 65 20 6f 66 20 74 68 69 73   example of this
37a0: 2e 0a 0a 31 2e 20 20 2a 2a 53 69 6d 70 6c 65 20  ...1.  **Simple 
37b0: 61 72 69 74 68 6d 65 74 69 63 20 6f 70 65 72 61  arithmetic opera
37c0: 74 6f 72 73 3a 2a 2a 20 60 2b 60 2c 20 60 2d 60  tors:** `+`, `-`
37d0: 2c 20 60 2a 60 2c 20 60 2f 60 2c 20 65 74 63 2e  , `*`, `/`, etc.
37e0: 0a 0a 31 2e 20 20 2a 2a 42 69 74 77 69 73 65 20  ..1.  **Bitwise 
37f0: 6f 70 65 72 61 74 6f 72 73 3a 2a 2a 20 60 26 60  operators:** `&`
3800: 2c 20 60 7c 60 2c 20 60 7e 60 20 61 6e 64 20 60  , `|`, `~` and `
3810: 21 60 0a 0a 31 2e 20 20 2a 2a 53 69 6d 70 6c 65  !`..1.  **Simple
3820: 20 63 6f 6d 70 61 72 69 73 6f 6e 20 6f 70 65 72   comparison oper
3830: 61 74 6f 72 73 3a 2a 2a 20 46 61 6c 73 65 20 65  ators:** False e
3840: 78 70 72 65 73 73 69 6f 6e 73 20 65 76 61 6c 75  xpressions evalu
3850: 61 74 65 20 61 73 20 30 20 61 6e 64 0a 20 20 20  ate as 0 and.   
3860: 20 74 72 75 65 20 61 73 20 2d 31 20 69 6e 20 74   true as -1 in t
3870: 77 6f e2 80 99 73 20 63 6f 6d 70 6c 65 6d 65 6e  wo’s complemen
3880: 74 20 66 6f 72 6d 2c 20 6d 65 61 6e 69 6e 67 20  t form, meaning 
3890: 61 6c 6c 20 31 27 73 20 69 6e 20 62 69 6e 61 72  all 1's in binar
38a0: 79 20 66 6f 72 6d 2e 0a 20 20 20 20 53 65 65 20  y form..    See 
38b0: 74 68 65 20 6c 69 73 74 20 6f 66 20 6c 69 6d 69  the list of limi
38c0: 74 61 74 69 6f 6e 73 20 62 65 6c 6f 77 20 66 6f  tations below fo
38d0: 72 20 74 68 65 20 6f 70 65 72 61 74 6f 72 73 20  r the operators 
38e0: 65 78 63 6c 75 64 65 64 20 62 79 20 6f 75 72 0a  excluded by our.
38f0: 20 20 20 20 22 73 69 6d 70 6c 65 22 20 71 75 61      "simple" qua
3900: 6c 69 66 69 65 72 2e 0a 0a 31 2e 20 20 2a 2a 32  lifier...1.  **2
3910: 2d 63 68 61 72 61 63 74 65 72 20 6f 70 65 72 61  -character opera
3920: 74 6f 72 73 3a 2a 2a 20 60 2b 2b 60 2c 20 60 2d  tors:** `++`, `-
3930: 2d 60 2c 20 60 3d 3d 60 2c 20 60 21 3d 60 2c 60  -`, `==`, `!=`,`
3940: 3e 3d 60 2c 20 60 3c 3d 60 2c 20 60 26 26 60 2c  >=`, `<=`, `&&`,
3950: 0a 20 20 20 20 61 6e 64 20 60 7c 7c 60 2e 20 4e  .    and `||`. N
3960: 6f 74 65 20 74 68 61 74 20 60 2b 2b 60 20 61 6e  ote that `++` an
3970: 64 20 60 2d 2d 60 20 61 72 65 20 70 6f 73 74 66  d `--` are postf
3980: 69 78 20 6f 6e 6c 79 2c 20 61 6e 64 0a 20 20 20  ix only, and.   
3990: 20 74 68 61 74 20 60 26 26 60 20 61 6e 64 20 60   that `&&` and `
39a0: 7c 7c 60 20 61 72 65 20 5b 69 6d 70 6c 65 6d 65  ||` are [impleme
39b0: 6e 74 65 64 20 61 73 20 60 26 60 20 61 6e 64 20  nted as `&` and 
39c0: 60 7c 60 5d 28 23 32 63 62 6f 29 2e 0a 0a 31 2e  `|`](#2cbo)...1.
39d0: 20 20 2a 2a 54 65 72 6e 61 72 79 20 6f 70 65 72    **Ternary oper
39e0: 61 74 6f 72 3a 2a 2a 20 54 68 65 20 60 3f 3a 60  ator:** The `?:`
39f0: 20 6f 70 65 72 61 74 6f 72 20 77 6f 72 6b 73 20   operator works 
3a00: 61 73 20 6f 66 20 4d 61 79 20 32 30 32 30 3b 20  as of May 2020; 
3a10: 69 74 20 6d 61 79 0a 20 20 20 20 62 65 20 6e 65  it may.    be ne
3a20: 73 74 65 64 2e 0a 0a 31 2e 20 20 2a 2a 4c 69 6d  sted...1.  **Lim
3a30: 69 74 65 64 20 6c 69 62 72 61 72 79 3a 2a 2a 20  ited library:** 
3a40: 53 65 65 20 5b 62 65 6c 6f 77 5d 28 23 6c 69 62  See [below](#lib
3a50: 63 29 20 66 6f 72 20 61 20 6c 69 73 74 20 6f 66  c) for a list of
3a60: 20 6c 69 62 72 61 72 79 0a 20 20 20 20 66 75 6e   library.    fun
3a70: 63 74 69 6f 6e 73 20 70 72 6f 76 69 64 65 64 2c  ctions provided,
3a80: 20 69 6e 63 6c 75 64 69 6e 67 20 74 68 65 69 72   including their
3a90: 20 6b 6e 6f 77 6e 20 6c 69 6d 69 74 61 74 69 6f   known limitatio
3aa0: 6e 73 20 72 65 6c 61 74 69 76 65 20 74 6f 0a 20  ns relative to. 
3ab0: 20 20 20 53 74 61 6e 64 61 72 64 20 43 2e 0a 0a     Standard C...
3ac0: 20 20 20 20 54 68 65 72 65 20 61 72 65 20 6d 61      There are ma
3ad0: 6e 79 20 6c 69 6d 69 74 61 74 69 6f 6e 73 20 69  ny limitations i
3ae0: 6e 20 74 68 69 73 20 6c 69 62 72 61 72 79 20 72  n this library r
3af0: 65 6c 61 74 69 76 65 20 74 6f 20 53 74 61 6e 64  elative to Stand
3b00: 61 72 64 20 43 20 6f 72 0a 20 20 20 20 65 76 65  ard C or.    eve
3b10: 6e 20 4b 26 52 20 43 2c 20 77 68 69 63 68 20 61  n K&R C, which a
3b20: 72 65 20 64 6f 63 75 6d 65 6e 74 65 64 20 62 65  re documented be
3b30: 6c 6f 77 2e 0a 0a 31 2e 20 20 2a 2a 4c 69 6d 69  low...1.  **Limi
3b40: 74 65 64 20 73 74 72 75 63 74 75 72 69 6e 67 20  ted structuring 
3b50: 63 6f 6e 73 74 72 75 63 74 73 3a 2a 2a 20 60 69  constructs:** `i
3b60: 66 60 2c 20 60 77 68 69 6c 65 60 2c 20 60 66 6f  f`, `while`, `fo
3b70: 72 60 2c 20 65 74 63 2e 20 61 72 65 0a 20 20 20  r`, etc. are.   
3b80: 20 73 75 70 70 6f 72 74 65 64 2e 20 54 68 65 72   supported. Ther
3b90: 65 20 69 73 20 61 20 6e 65 73 74 69 6e 67 20 6c  e is a nesting l
3ba0: 69 6d 69 74 20 6f 66 20 31 30 20 77 68 69 63 68  imit of 10 which
3bb0: 20 69 73 20 72 61 72 65 6c 79 20 65 78 63 65 65   is rarely excee
3bc0: 64 65 64 20 69 6e 20 0a 20 20 20 20 6d 6f 73 74  ded in .    most
3bd0: 20 61 70 70 6c 69 63 61 74 69 6f 6e 73 2e 20 49   applications. I
3be0: 6e 20 61 64 64 69 74 69 6f 6e 2c 20 60 73 77 69  n addition, `swi
3bf0: 74 63 68 60 20 73 74 61 74 65 6d 65 6e 74 73 20  tch` statements 
3c00: 61 72 65 20 6e 6f 77 20 73 75 70 70 6f 72 74 65  are now supporte
3c10: 64 0a 20 20 20 20 76 69 61 20 61 20 63 6f 64 65  d.    via a code
3c20: 20 72 65 2d 77 72 69 74 65 20 69 6e 20 74 68 65   re-write in the
3c30: 20 43 20 70 72 65 2d 70 72 6f 63 65 73 73 6f 72   C pre-processor
3c40: 20 28 63 63 2e 73 76 29 2e 20 53 65 65 20 20 5b   (cc.sv). See  [
3c50: 60 46 4f 52 54 48 2e 43 60 5d 5b 66 6f 72 74 68  `FORTH.C`][forth
3c60: 5d 0a 20 20 20 20 66 6f 72 20 61 6e 20 65 78 61  ].    for an exa
3c70: 6d 70 6c 65 2e 0a 0a 5b 66 69 62 5d 3a 20 20 20  mple...[fib]:   
3c80: 2f 64 6f 63 2f 74 72 75 6e 6b 2f 73 72 63 2f 6f  /doc/trunk/src/o
3c90: 73 38 2f 65 78 61 6d 70 6c 65 73 2f 66 69 62 2e  s8/examples/fib.
3ca0: 63 0a 5b 66 6f 72 74 68 5d 3a 20 2f 64 6f 63 2f  c.[forth]: /doc/
3cb0: 74 72 75 6e 6b 2f 73 72 63 2f 6f 73 38 2f 65 78  trunk/src/os8/ex
3cc0: 61 6d 70 6c 65 73 2f 66 6f 72 74 68 2e 63 0a 0a  amples/forth.c..
3cd0: 3c 61 20 69 64 3d 22 6e 6c 69 6d 22 20 6e 61 6d  <a id="nlim" nam
3ce0: 65 3d 22 6c 69 6d 69 74 61 74 69 6f 6e 73 22 3e  e="limitations">
3cf0: 3c 2f 61 3e 0a 23 23 23 20 4b 6e 6f 77 6e 20 4c  </a>.### Known L
3d00: 69 6d 69 74 61 74 69 6f 6e 73 20 6f 66 20 74 68  imitations of th
3d10: 65 20 4f 53 2f 38 20 43 43 38 20 43 6f 6d 70 69  e OS/8 CC8 Compi
3d20: 6c 65 72 0a 0a 54 68 65 20 4f 53 2f 38 20 76 65  ler..The OS/8 ve
3d30: 72 73 69 6f 6e 20 6f 66 20 43 43 38 20 73 75 70  rsion of CC8 sup
3d40: 70 6f 72 74 73 20 61 20 73 75 62 73 65 74 20 6f  ports a subset o
3d50: 66 20 74 68 65 20 43 20 64 69 61 6c 65 63 74 20  f the C dialect 
3d60: 75 6e 64 65 72 73 74 6f 6f 64 20 62 79 0a 5b 74  understood by.[t
3d70: 68 65 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65  he cross-compile
3d80: 72 5d 28 23 63 72 6f 73 73 29 2c 20 61 6e 64 20  r](#cross), and 
3d90: 74 68 75 73 20 6f 66 20 4b 26 52 20 43 3a 0a 0a  thus of K&R C:..
3da0: 31 2e 20 20 3c 61 20 69 64 3d 22 74 79 70 65 6c  1.  <a id="typel
3db0: 65 73 73 22 3e 3c 2f 61 3e 54 68 65 20 6c 61 6e  ess"></a>The lan
3dc0: 67 75 61 67 65 20 69 73 20 74 79 70 65 6c 65 73  guage is typeles
3dd0: 73 20 69 6e 20 74 68 61 74 20 65 76 65 72 79 74  s in that everyt
3de0: 68 69 6e 67 20 69 73 0a 20 20 20 20 61 20 31 32  hing is.    a 12
3df0: 20 62 69 74 20 69 6e 74 65 67 65 72 2c 20 61 6e   bit integer, an
3e00: 64 20 61 6e 79 20 76 61 72 69 61 62 6c 65 2f 61  d any variable/a
3e10: 72 72 61 79 20 63 61 6e 20 69 6e 74 65 72 70 72  rray can interpr
3e20: 65 74 65 64 20 61 73 20 60 69 6e 74 60 2c 0a 20  eted as `int`,. 
3e30: 20 20 20 60 63 68 61 72 60 20 6f 72 20 70 6f 69     `char` or poi
3e40: 6e 74 65 72 2e 20 20 41 6c 6c 20 76 61 72 69 61  nter.  All varia
3e50: 62 6c 65 73 20 61 6e 64 20 61 72 72 61 79 73 20  bles and arrays 
3e60: 6d 75 73 74 20 62 65 20 64 65 63 6c 61 72 65 64  must be declared
3e70: 20 61 73 0a 20 20 20 20 60 69 6e 74 60 2e 20 41   as.    `int`. A
3e80: 73 20 77 69 74 68 20 4b 26 52 20 43 2c 20 74 68  s with K&R C, th
3e90: 65 20 72 65 74 75 72 6e 20 74 79 70 65 20 6d 61  e return type ma
3ea0: 79 20 62 65 20 6c 65 66 74 20 6f 66 66 20 6f 66  y be left off of
3eb0: 20 61 0a 20 20 20 20 66 75 6e 63 74 69 6f 6e 27   a.    function'
3ec0: 73 20 64 65 66 69 6e 69 74 69 6f 6e 3b 20 69 74  s definition; it
3ed0: 20 69 73 20 69 6d 70 6c 69 63 69 74 6c 79 20 60   is implicitly `
3ee0: 69 6e 74 60 20 69 6e 20 61 6c 6c 20 63 61 73 65  int` in all case
3ef0: 73 2e 0a 0a 20 20 20 20 49 74 20 69 73 20 6e 6f  s...    It is no
3f00: 74 20 6e 65 63 65 73 73 61 72 79 20 74 6f 20 67  t necessary to g
3f10: 69 76 65 20 61 72 67 75 6d 65 6e 74 20 74 79 70  ive argument typ
3f20: 65 73 20 77 68 65 6e 20 64 65 63 6c 61 72 69 6e  es when declarin
3f30: 67 20 66 75 6e 63 74 69 6f 6e 0a 20 20 20 20 61  g function.    a
3f40: 72 67 75 6d 65 6e 74 73 2c 20 62 75 74 20 79 6f  rguments, but yo
3f50: 75 20 6d 75 73 74 20 64 65 63 6c 61 72 65 20 61  u must declare a
3f60: 20 72 65 74 75 72 6e 20 74 79 70 65 20 77 69 74   return type wit
3f70: 68 20 74 68 65 20 4f 53 2f 38 20 43 43 38 0a 20  h the OS/8 CC8. 
3f80: 20 20 20 63 6f 6d 70 69 6c 65 72 3a 0a 0a 20 20     compiler:..  
3f90: 20 20 20 20 20 20 69 6e 74 20 6d 79 66 6e 28 6e        int myfn(n
3fa0: 29 20 7b 20 2f 2a 20 64 6f 20 73 6f 6d 65 74 68  ) { /* do someth
3fb0: 69 6e 67 20 77 69 74 68 20 6e 20 2a 2f 20 7d 0a  ing with n */ }.
3fc0: 0a 20 20 20 20 54 68 69 73 20 64 65 63 6c 61 72  .    This declar
3fd0: 65 73 20 61 20 66 75 6e 63 74 69 6f 6e 20 74 61  es a function ta
3fe0: 6b 69 6e 67 20 61 6e 20 60 69 6e 74 60 20 63 61  king an `int` ca
3ff0: 6c 6c 65 64 20 60 6e 60 20 61 6e 64 20 72 65 74  lled `n` and ret
4000: 75 72 6e 69 6e 67 0a 20 20 20 20 61 6e 20 60 69  urning.    an `i
4010: 6e 74 60 2e 0a 20 20 20 20 0a 20 20 20 20 43 6f  nt`..    .    Co
4020: 6e 74 72 61 73 74 20 74 68 65 20 43 43 38 20 63  ntrast the CC8 c
4030: 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 2c 20 77  ross-compiler, w
4040: 68 69 63 68 20 72 65 71 75 69 72 65 73 20 66 75  hich requires fu
4050: 6e 63 74 69 6f 6e 20 61 72 67 75 6d 65 6e 74 0a  nction argument.
4060: 20 20 20 20 74 79 70 65 73 20 74 6f 20 62 65 20      types to be 
4070: 64 65 63 6c 61 72 65 64 20 62 75 74 20 6e 6f 74  declared but not
4080: 20 74 68 65 20 72 65 74 75 72 6e 20 74 79 70 65   the return type
4090: 2c 20 70 65 72 20 4b 26 52 20 43 20 72 75 6c 65  , per K&R C rule
40a0: 73 3a 0a 0a 20 20 20 20 20 20 20 20 69 6e 74 20  s:..        int 
40b0: 6d 79 66 6e 28 6e 29 0a 20 20 20 20 20 20 20 20  myfn(n).        
40c0: 69 6e 74 20 6e 3b 0a 20 20 20 20 20 20 20 20 7b  int n;.        {
40d0: 0a 20 20 20 20 20 20 20 20 20 20 20 20 2f 2a 20  .            /* 
40e0: 64 6f 20 73 6f 6d 65 74 68 69 6e 67 20 77 69 74  do something wit
40f0: 68 20 6e 2c 20 74 68 65 6e 20 5f 6d 61 79 62 65  h n, then _maybe
4100: 5f 20 72 65 74 75 72 6e 20 73 6f 6d 65 74 68 69  _ return somethi
4110: 6e 67 20 2a 2f 0a 20 20 20 20 20 20 20 20 7d 0a  ng */.        }.
4120: 0a 20 20 20 20 54 68 65 20 74 79 70 65 20 69 6e  .    The type in
4130: 74 20 69 73 20 6d 61 6e 64 61 74 6f 72 79 20 66  t is mandatory f
4140: 6f 72 20 61 6c 6c 20 66 75 6e 63 74 69 6f 6e 73  or all functions
4150: 2e 0a 0a 20 20 20 20 54 68 65 20 63 72 6f 73 73  ...    The cross
4160: 2d 63 6f 6d 70 69 6c 65 72 20 73 75 70 70 6f 72  -compiler suppor
4170: 74 73 20 60 76 6f 69 64 60 20 61 73 20 61 6e 20  ts `void` as an 
4180: 65 78 74 65 6e 73 69 6f 6e 20 74 6f 20 4b 26 52  extension to K&R
4190: 20 43 2e 20 54 68 69 73 20 74 79 70 65 0a 20 20   C. This type.  
41a0: 20 20 69 73 20 63 6f 6e 76 65 72 74 65 64 20 74    is converted t
41b0: 6f 20 60 69 6e 74 60 20 69 6e 20 74 68 65 20 70  o `int` in the p
41c0: 72 65 2d 70 72 6f 63 65 73 73 6f 72 2e 20 53 69  re-processor. Si
41d0: 6d 69 6c 61 72 6c 79 2c 20 74 68 65 20 74 79 70  milarly, the typ
41e0: 65 20 60 63 68 61 72 60 20 69 73 0a 20 20 20 20  e `char` is.    
41f0: 63 6f 6e 76 65 72 74 65 64 2e 20 54 68 65 73 65  converted. These
4200: 20 74 79 70 65 20 6d 61 79 20 62 65 20 75 73 65   type may be use
4210: 64 20 66 6f 72 20 72 65 61 64 61 62 69 6c 69 74  d for readabilit
4220: 79 20 70 75 72 70 6f 73 65 73 2e 0a 0a 32 2e 20  y purposes...2. 
4230: 20 54 68 65 72 65 20 6d 75 73 74 20 62 65 20 61   There must be a
4240: 6e 20 60 69 6e 74 20 6d 61 69 6e 28 29 60 2c 20  n `int main()`, 
4250: 61 6e 64 20 69 74 20 6d 75 73 74 20 62 65 20 74  and it must be t
4260: 68 65 20 6c 61 73 74 20 66 75 6e 63 74 69 6f 6e  he last function
4270: 0a 20 20 20 20 69 6e 20 74 68 65 20 73 69 6e 67  .    in the sing
4280: 6c 65 20 69 6e 70 75 74 20 43 20 66 69 6c 65 2e  le input C file.
4290: 0a 0a 20 20 20 20 53 69 6e 63 65 20 4f 53 2f 38  ..    Since OS/8
42a0: 20 68 61 73 20 6e 6f 20 77 61 79 20 74 6f 20 70   has no way to p
42b0: 61 73 73 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65  ass command line
42c0: 20 61 72 67 75 6d 65 6e 74 73 20 74 6f 20 61 20   arguments to a 
42d0: 70 72 6f 67 72 61 6d 0a 20 20 20 20 e2 80 94 20  program.    — 
42e0: 61 74 20 6c 65 61 73 74 2c 20 6e 6f 74 20 69 6e  at least, not in
42f0: 20 61 20 77 61 79 20 74 68 61 74 20 69 73 20 63   a way that is c
4300: 6f 6d 70 61 74 69 62 6c 65 20 77 69 74 68 20 74  ompatible with t
4310: 68 65 20 55 6e 69 78 20 73 74 79 6c 65 0a 20 20  he Unix style.  
4320: 20 20 63 6f 6d 6d 61 6e 64 20 6c 69 6e 65 73 20    command lines 
4330: 65 78 70 65 63 74 65 64 20 62 79 20 43 20 e2 80  expected by C 
4340: 94 20 74 68 65 20 60 6d 61 69 6e 28 29 60 20 66   the `main()` f
4350: 75 6e 63 74 69 6f 6e 20 69 73 20 6e 65 76 65 72  unction is never
4360: 0a 20 20 20 20 64 65 63 6c 61 72 65 64 20 74 6f  .    declared to
4370: 20 74 61 6b 65 20 61 72 67 75 6d 65 6e 74 73 2e   take arguments.
4380: 0a 0a 33 2e 20 20 57 65 20 64 6f 20 6e 6f 74 20  ..3.  We do not 
4390: 79 65 74 20 73 75 70 70 6f 72 74 20 73 65 70 61  yet support sepa
43a0: 72 61 74 65 20 63 6f 6d 70 69 6c 61 74 69 6f 6e  rate compilation
43b0: 20 6f 66 20 6d 75 6c 74 69 70 6c 65 20 43 20 6d   of multiple C m
43c0: 6f 64 75 6c 65 73 0a 20 20 20 20 74 68 61 74 20  odules.    that 
43d0: 67 65 74 20 6c 69 6e 6b 65 64 20 74 6f 67 65 74  get linked toget
43e0: 68 65 72 2e 20 20 59 6f 75 20 63 61 6e 20 70 72  her.  You can pr
43f0: 6f 64 75 63 65 20 72 65 6c 6f 63 61 74 61 62 6c  oduce relocatabl
4400: 65 20 6c 69 62 72 61 72 69 65 73 20 69 6e 0a 20  e libraries in. 
4410: 20 20 20 4f 53 2f 38 20 60 2a 2e 52 4c 60 20 66     OS/8 `*.RL` f
4420: 6f 72 6d 61 74 20 61 6e 64 20 6c 69 6e 6b 20 74  ormat and link t
4430: 68 65 6d 20 77 69 74 68 20 74 68 65 20 4f 53 2f  hem with the OS/
4440: 38 20 4c 4f 41 44 45 52 2c 20 62 75 74 20 62 65  8 LOADER, but be
4450: 63 61 75 73 65 0a 20 20 20 20 6f 66 20 74 68 65  cause.    of the
4460: 20 70 72 65 76 69 6f 75 73 20 6c 69 6d 69 74 61   previous limita
4470: 74 69 6f 6e 2c 20 6f 6e 6c 79 20 6f 6e 65 20 6f  tion, only one o
4480: 66 20 74 68 65 73 65 20 63 61 6e 20 62 65 20 77  f these can be w
4490: 72 69 74 74 65 6e 20 69 6e 20 43 2e 0a 0a 34 2e  ritten in C...4.
44a0: 20 20 3c 61 20 69 64 3d 22 6f 73 38 70 70 22 3e    <a id="os8pp">
44b0: 3c 2f 61 3e 54 68 65 20 4f 53 2f 38 20 63 6f 6d  </a>The OS/8 com
44c0: 70 69 6c 65 72 20 68 61 73 20 65 78 74 72 65 6d  piler has extrem
44d0: 65 6c 79 20 72 75 64 69 6d 65 6e 74 61 72 79 0a  ely rudimentary.
44e0: 20 20 20 20 73 75 70 70 6f 72 74 20 66 6f 72 20      support for 
44f0: 70 72 65 70 72 6f 63 65 73 73 6f 72 20 64 69 72  preprocessor dir
4500: 65 63 74 69 76 65 73 2e 0a 0a 20 20 20 20 2a 20  ectives...    * 
4510: 20 20 4c 69 74 65 72 61 6c 20 60 23 64 65 66 69    Literal `#defi
4520: 6e 65 60 20 6f 6e 6c 79 3a 20 6e 6f 20 70 61 72  ne` only: no par
4530: 61 6d 65 74 65 72 69 7a 65 64 20 6d 61 63 72 6f  ameterized macro
4540: 73 2c 20 61 6e 64 20 6e 6f 20 60 23 75 6e 64 65  s, and no `#unde
4550: 66 60 2e 0a 0a 20 20 20 20 2a 20 20 20 60 23 69  f`...    *   `#i
4560: 6e 63 6c 75 64 65 60 20 69 73 20 6e 6f 74 20 73  nclude` is not s
4570: 75 70 70 6f 72 74 65 64 20 61 6e 64 20 6d 75 73  upported and mus
4580: 74 20 6e 6f 74 20 61 70 70 65 61 72 20 69 6e 20  t not appear in 
4590: 74 68 65 20 43 20 73 6f 75 72 63 65 0a 20 20 20  the C source.   
45a0: 20 20 20 20 20 63 6f 64 65 20 66 65 64 20 74 6f       code fed to
45b0: 20 74 68 65 20 4e 61 74 69 76 65 20 4f 53 2f 38   the Native OS/8
45c0: 20 43 6f 6d 70 69 6c 65 72 2e 0a 0a 20 20 20 20   Compiler...    
45d0: 20 20 20 20 54 68 69 73 20 6d 65 61 6e 73 20 79      This means y
45e0: 6f 75 20 63 61 6e 6e 6f 74 20 75 73 65 20 60 23  ou cannot use `#
45f0: 69 6e 63 6c 75 64 65 60 20 64 69 72 65 63 74 69  include` directi
4600: 76 65 73 20 74 6f 20 73 74 72 69 6e 67 0a 20 20  ves to string.  
4610: 20 20 20 20 20 20 6d 75 6c 74 69 70 6c 65 20 43        multiple C
4620: 20 6d 6f 64 75 6c 65 73 20 69 6e 74 6f 20 61 20   modules into a 
4630: 73 69 6e 67 6c 65 20 70 72 6f 67 72 61 6d 2e 0a  single program..
4640: 0a 20 20 20 20 20 20 20 20 49 74 20 61 6c 73 6f  .        It also
4650: 20 6d 65 61 6e 73 20 74 68 61 74 20 69 66 20 79   means that if y
4660: 6f 75 20 74 61 6b 65 20 61 20 70 72 6f 67 72 61  ou take a progra
4670: 6d 20 74 68 61 74 20 74 68 65 20 63 72 6f 73 73  m that the cross
4680: 2d 63 6f 6d 70 69 6c 65 72 0a 20 20 20 20 20 20  -compiler.      
4690: 20 20 68 61 6e 64 6c 65 73 20 63 6f 72 72 65 63    handles correc
46a0: 74 6c 79 20 61 6e 64 20 6a 75 73 74 20 63 6f 70  tly and just cop
46b0: 79 20 69 74 20 73 74 72 61 69 67 68 74 20 69 6e  y it straight in
46c0: 74 6f 20 4f 53 2f 38 20 61 6e 64 20 74 72 79 20  to OS/8 and try 
46d0: 74 6f 0a 20 20 20 20 20 20 20 20 63 6f 6d 70 69  to.        compi
46e0: 6c 65 20 69 74 2c 20 69 74 20 70 72 6f 62 61 62  le it, it probab
46f0: 6c 79 20 73 74 69 6c 6c 20 68 61 73 20 74 68 65  ly still has the
4700: 20 60 23 69 6e 63 6c 75 64 65 20 3c 6c 69 62 63   `#include <libc
4710: 2e 68 3e 60 20 6c 69 6e 65 20 61 6e 64 0a 20 20  .h>` line and.  
4720: 20 20 20 20 20 20 70 6f 73 73 69 62 6c 79 20 6f        possibly o
4730: 6e 65 20 66 6f 72 20 60 69 6e 69 74 2e 68 60 20  ne for `init.h` 
4740: 61 73 20 77 65 6c 6c 2e 20 2a 53 75 63 68 20 63  as well. *Such c
4750: 6f 64 65 20 77 69 6c 6c 20 66 61 69 6c 20 74 6f  ode will fail to
4760: 20 63 6f 6d 70 69 6c 65 2e 2a 0a 20 20 20 20 20   compile.*.     
4770: 20 20 20 59 6f 75 20 6d 75 73 74 20 73 74 72 69     You must stri
4780: 70 20 73 75 63 68 20 6c 69 6e 65 73 20 6f 75 74  p such lines out
4790: 20 77 68 65 6e 20 63 6f 70 79 69 6e 67 20 43 20   when copying C 
47a0: 66 69 6c 65 73 20 69 6e 74 6f 20 4f 53 2f 38 2e  files into OS/8.
47b0: 0a 0a 20 20 20 20 20 20 20 20 28 54 68 65 20 6e  ..        (The n
47c0: 61 74 69 76 65 20 63 6f 6d 70 69 6c 65 72 20 65  ative compiler e
47d0: 6d 69 74 73 20 73 74 61 72 74 75 70 20 63 6f 64  mits startup cod
47e0: 65 20 61 75 74 6f 6d 61 74 69 63 61 6c 6c 79 2c  e automatically,
47f0: 20 61 6e 64 20 69 74 0a 20 20 20 20 20 20 20 20   and it.        
4800: 68 61 72 64 2d 63 6f 64 65 73 20 74 68 65 20 4c  hard-codes the L
4810: 49 42 43 20 63 61 6c 6c 20 74 61 62 6c 65 20 69  IBC call table i
4820: 6e 20 74 68 65 20 5b 66 69 6e 61 6c 20 63 6f 6d  n the [final com
4830: 70 69 6c 65 72 0a 20 20 20 20 20 20 20 20 70 61  piler.        pa
4840: 73 73 5d 28 23 6e 63 70 61 73 73 29 2c 20 69 6d  ss](#ncpass), im
4850: 70 6c 65 6d 65 6e 74 65 64 20 69 6e 20 60 70 38  plemented in `p8
4860: 2e 63 60 2c 20 73 6f 20 69 74 20 64 6f 65 73 6e  .c`, so it doesn
4870: e2 80 99 74 20 6e 65 65 64 0a 20 20 20 20 20 20  ’t need.      
4880: 20 20 60 23 69 6e 63 6c 75 64 65 60 20 74 6f 20    `#include` to 
4890: 6d 61 6b 65 20 74 68 65 73 65 20 74 68 69 6e 67  make these thing
48a0: 73 20 77 6f 72 6b 2e 29 0a 0a 20 20 20 20 2a 20  s work.)..    * 
48b0: 20 20 4e 6f 20 63 6f 6e 64 69 74 69 6f 6e 61 6c    No conditional
48c0: 20 63 6f 6d 70 69 6c 61 74 69 6f 6e 3a 20 60 23   compilation: `#
48d0: 69 66 60 2c 20 60 23 69 66 64 65 66 60 2c 20 60  if`, `#ifdef`, `
48e0: 23 65 6c 73 65 60 2c 20 65 74 63 2e 0a 0a 20 20  #else`, etc...  
48f0: 20 20 2a 20 20 20 5b 49 6e 6c 69 6e 65 20 61 73    *   [Inline as
4900: 73 6d 65 6d 62 6c 79 5d 28 23 61 73 6d 29 20 76  smembly](#asm) v
4910: 69 61 20 60 23 61 73 6d 60 20 2f 20 60 23 65 6e  ia `#asm` / `#en
4920: 64 61 73 6d 60 2e 20 53 65 65 0a 20 20 20 20 20  dasm`. See.     
4930: 20 20 20 5b 60 46 49 42 2e 43 60 5d 5b 66 69 62     [`FIB.C`][fib
4940: 5d 20 66 6f 72 20 61 6e 20 65 78 61 6d 70 6c 65  ] for an example
4950: 0a 0a 35 2e 20 20 56 61 72 69 61 62 6c 65 73 20  ..5.  Variables 
4960: 61 72 65 20 69 6d 70 6c 69 63 69 74 6c 79 20 60  are implicitly `
4970: 73 74 61 74 69 63 60 2c 20 65 76 65 6e 20 77 68  static`, even wh
4980: 65 6e 20 6c 6f 63 61 6c 2e 0a 0a 36 2e 20 20 41  en local...6.  A
4990: 72 72 61 79 73 20 6d 61 79 20 6f 6e 6c 79 20 62  rrays may only b
49a0: 65 20 73 69 6e 67 6c 65 20 69 6e 64 65 78 65 64  e single indexed
49b0: 2e 20 53 65 65 20 60 50 53 2e 43 60 20 66 6f 72  . See `PS.C` for
49c0: 20 61 6e 20 65 78 61 6d 70 6c 65 2e 0a 0a 37 2e   an example...7.
49d0: 20 20 54 68 65 20 63 6f 6d 70 69 6c 65 72 20 64    The compiler d
49e0: 6f 65 73 20 6e 6f 74 20 79 65 74 20 75 6e 64 65  oes not yet unde
49f0: 72 73 74 61 6e 64 20 68 6f 77 20 74 6f 20 61 73  rstand how to as
4a00: 73 69 67 6e 20 61 20 76 61 72 69 61 62 6c 65 27  sign a variable'
4a10: 73 0a 20 20 20 20 69 6e 69 74 69 61 6c 20 76 61  s.    initial va
4a20: 6c 75 65 20 61 73 20 70 61 72 74 20 6f 66 20 69  lue as part of i
4a30: 74 73 20 64 65 63 6c 61 72 61 74 69 6f 6e 2e 20  ts declaration. 
4a40: 54 68 69 73 3a 0a 0a 20 20 20 20 20 20 20 20 69  This:..        i
4a50: 6e 74 20 69 20 3d 20 35 3b 0a 0a 20 20 20 20 6d  nt i = 5;..    m
4a60: 75 73 74 20 69 6e 73 74 65 61 64 20 62 65 3a 0a  ust instead be:.
4a70: 0a 20 20 20 20 20 20 20 20 69 6e 74 20 69 3b 0a  .        int i;.
4a80: 20 20 20 20 20 20 20 20 69 20 3d 20 35 3b 0a 0a          i = 5;..
4a90: 38 2e 20 20 3c 61 20 6e 61 6d 65 3d 22 32 63 62  8.  <a name="2cb
4aa0: 6f 22 3e 3c 2f 61 3e 60 26 26 60 20 61 6e 64 20  o"></a>`&&` and 
4ab0: 60 7c 7c 60 20 77 6f 72 6b 2c 20 62 75 74 20 62  `||` work, but b
4ac0: 65 63 61 75 73 65 20 74 68 65 79 0a 20 20 20 20  ecause they.    
4ad0: 61 72 65 20 69 6e 74 65 72 6e 61 6c 6c 79 20 63  are internally c
4ae0: 6f 6e 76 65 72 74 65 64 20 74 6f 20 60 26 60 20  onverted to `&` 
4af0: 61 6e 64 20 60 7c 60 2c 20 74 68 65 69 72 20 70  and `|`, their p
4b00: 72 65 63 65 64 65 6e 63 65 20 68 61 73 0a 20 20  recedence has.  
4b10: 20 20 63 68 61 6e 67 65 64 2c 20 61 6e 64 20 74    changed, and t
4b20: 68 65 79 20 64 6f 20 6e 6f 74 20 73 68 6f 72 74  hey do not short
4b30: 2d 63 69 72 63 75 69 74 20 61 73 20 69 6e 20 61  -circuit as in a
4b40: 20 63 6f 6e 66 6f 72 6d 69 6e 67 20 43 0a 20 20   conforming C.  
4b50: 20 20 63 6f 6d 70 69 6c 65 72 2e 0a 0a 20 20 20    compiler...   
4b60: 20 59 6f 75 20 63 61 6e 20 77 6f 72 6b 20 61 72   You can work ar
4b70: 6f 75 6e 64 20 73 75 63 68 20 64 69 66 66 65 72  ound such differ
4b80: 65 6e 63 65 73 20 77 69 74 68 20 63 6c 65 76 65  ences with cleve
4b90: 72 20 63 6f 64 69 6e 67 2e 20 46 6f 72 0a 20 20  r coding. For.  
4ba0: 20 20 65 78 61 6d 70 6c 65 2c 20 74 68 69 73 20    example, this 
4bb0: 63 6f 64 65 20 66 6f 72 20 61 20 63 6f 6e 66 6f  code for a confo
4bc0: 72 6d 69 6e 67 20 43 20 63 6f 6d 70 69 6c 65 72  rming C compiler
4bd0: 3a 0a 0a 20 20 20 20 20 20 20 20 69 66 20 28 69  :..        if (i
4be0: 20 21 3d 20 30 20 7c 7c 20 6a 20 3d 3d 20 35 29   != 0 || j == 5)
4bf0: 0a 0a 20 20 20 20 73 68 6f 75 6c 64 20 62 65 20  ..    should be 
4c00: 72 65 77 72 69 74 74 65 6e 20 66 6f 72 20 43 43  rewritten for CC
4c10: 38 20 74 6f 20 61 76 6f 69 64 20 74 68 65 20 70  8 to avoid the p
4c20: 72 65 63 65 64 65 6e 63 65 20 63 68 61 6e 67 65  recedence change
4c30: 73 20 61 73 3a 0a 0a 20 20 20 20 20 20 20 20 69  s as:..        i
4c40: 66 20 28 21 28 69 20 3d 3d 20 30 29 20 7c 7c 20  f (!(i == 0) || 
4c50: 28 6a 20 3d 3d 20 35 29 29 0a 0a 20 20 20 20 62  (j == 5))..    b
4c60: 65 63 61 75 73 65 20 61 20 74 72 75 65 20 72 65  ecause a true re
4c70: 73 75 6c 74 20 69 6e 20 65 61 63 68 20 73 75 62  sult in each sub
4c80: 65 78 70 72 65 73 73 69 6f 6e 20 79 69 65 6c 64  expression yield
4c90: 73 20 2d 31 20 70 65 72 20 74 68 65 0a 20 20 20  s -1 per the.   
4ca0: 20 70 72 65 76 69 6f 75 73 20 70 6f 69 6e 74 2c   previous point,
4cb0: 20 77 68 69 63 68 20 77 68 65 6e 20 62 69 74 77   which when bitw
4cc0: 69 73 65 20 4f 52 27 64 20 74 6f 67 65 74 68 65  ise OR'd togethe
4cd0: 72 20 6d 65 61 6e 73 20 79 6f 75 20 67 65 74 20  r means you get 
4ce0: 2d 31 20 69 66 0a 20 20 20 20 65 69 74 68 65 72  -1 if.    either
4cf0: 20 73 75 62 65 78 70 72 65 73 73 69 6f 6e 20 69   subexpression i
4d00: 73 20 74 72 75 65 2c 20 77 68 69 63 68 20 6d 65  s true, which me
4d10: 61 6e 73 20 74 68 65 20 77 68 6f 6c 65 20 65 78  ans the whole ex
4d20: 70 72 65 73 73 69 6f 6e 0a 20 20 20 20 65 76 61  pression.    eva
4d30: 6c 75 61 74 65 73 20 74 6f 20 74 72 75 65 20 69  luates to true i
4d40: 66 20 65 69 74 68 65 72 20 73 75 62 65 78 70 72  f either subexpr
4d50: 65 73 73 69 6f 6e 20 69 73 20 74 72 75 65 2e 0a  ession is true..
4d60: 0a 20 20 20 20 49 66 20 74 68 65 20 63 6f 64 65  .    If the code
4d70: 20 79 6f 75 20 77 65 72 65 20 67 6f 69 6e 67 20   you were going 
4d80: 74 6f 20 77 72 69 74 65 20 77 61 73 20 69 6e 73  to write was ins
4d90: 74 65 61 64 3a 0a 0a 20 20 20 20 20 20 20 20 69  tead:..        i
4da0: 66 20 28 69 20 21 3d 20 30 20 7c 7c 20 6a 20 21  f (i != 0 || j !
4db0: 3d 20 35 29 0a 0a 20 20 20 20 74 68 65 6e 20 74  = 5)..    then t
4dc0: 68 65 20 72 65 77 72 69 74 65 20 69 73 20 65 76  he rewrite is ev
4dd0: 65 6e 20 73 69 6d 70 6c 65 72 20 6f 77 69 6e 67  en simpler owing
4de0: 20 74 6f 20 74 68 65 20 72 75 6c 65 73 20 6f 66   to the rules of
4df0: 20 5b 42 6f 6f 6c 65 61 6e 0a 20 20 20 20 61 6c   [Boolean.    al
4e00: 67 65 62 72 61 5d 28 68 74 74 70 73 3a 2f 2f 65  gebra](https://e
4e10: 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f  n.wikipedia.org/
4e20: 77 69 6b 69 2f 42 6f 6f 6c 65 61 6e 5f 61 6c 67  wiki/Boolean_alg
4e30: 65 62 72 61 29 3a 0a 0a 20 20 20 20 20 20 20 20  ebra):..        
4e40: 69 66 20 28 21 28 69 20 3d 3d 20 30 20 26 20 6a  if (!(i == 0 & j
4e50: 20 3d 3d 20 35 29 29 0a 0a 20 20 20 20 54 68 65   == 5))..    The
4e60: 73 65 20 72 75 6c 65 73 20 6d 65 61 6e 20 74 68  se rules mean th
4e70: 61 74 20 69 66 20 77 65 20 6e 65 67 61 74 65 20  at if we negate 
4e80: 74 68 65 20 65 6e 74 69 72 65 20 65 78 70 72 65  the entire expre
4e90: 73 73 69 6f 6e 2c 20 77 65 20 67 65 74 20 74 68  ssion, we get th
4ea0: 65 0a 20 20 20 20 73 61 6d 65 20 74 72 75 74 68  e.    same truth
4eb0: 20 74 61 62 6c 65 20 69 66 20 77 65 20 66 6c 69   table if we fli
4ec0: 70 20 74 68 65 20 6f 70 65 72 61 74 6f 72 73 20  p the operators 
4ed0: 61 72 6f 75 6e 64 20 61 6e 64 20 73 77 61 70 20  around and swap 
4ee0: 74 68 65 0a 20 20 20 20 6c 6f 67 69 63 61 6c 20  the.    logical 
4ef0: 74 65 73 74 20 66 72 6f 6d 20 4f 52 20 74 6f 20  test from OR to 
4f00: 41 4e 44 2c 20 77 68 69 63 68 20 69 6e 20 74 68  AND, which in th
4f10: 69 73 20 63 61 73 65 20 63 6f 6e 76 65 72 74 73  is case converts
4f20: 20 74 68 65 0a 20 20 20 20 65 78 70 72 65 73 73   the.    express
4f30: 69 6f 6e 20 74 6f 20 61 20 66 6f 72 6d 20 74 68  ion to a form th
4f40: 61 74 20 69 73 20 6e 6f 77 20 6c 65 67 61 6c 20  at is now legal 
4f50: 69 6e 20 6f 75 72 20 6c 69 6d 69 74 65 64 20 43  in our limited C
4f60: 20 64 69 61 6c 65 63 74 2e 20 41 6c 6c 0a 20 20   dialect. All.  
4f70: 20 20 6f 66 20 74 68 69 73 20 63 6f 6d 65 73 20    of this comes 
4f80: 66 72 6f 6d 20 74 68 65 20 4c 61 77 73 20 73 65  from the Laws se
4f90: 63 74 69 6f 6e 20 6f 66 20 74 68 65 20 6c 69 6e  ction of the lin
4fa0: 6b 65 64 20 57 69 6b 69 70 65 64 69 61 20 61 72  ked Wikipedia ar
4fb0: 74 69 63 6c 65 3b 0a 20 20 20 20 69 66 20 79 6f  ticle;.    if yo
4fc0: 75 20 6c 65 61 72 6e 20 6e 6f 74 68 69 6e 67 20  u learn nothing 
4fd0: 65 6c 73 65 20 61 62 6f 75 74 20 42 6f 6f 6c 65  else about Boole
4fe0: 61 6e 20 61 6c 67 65 62 72 61 2c 20 79 6f 75 20  an algebra, you 
4ff0: 77 6f 75 6c 64 20 62 65 20 77 65 6c 6c 0a 20 20  would be well.  
5000: 20 20 73 65 72 76 65 64 20 74 6f 20 6d 65 6d 6f    served to memo
5010: 72 69 7a 65 20 74 68 6f 73 65 20 72 75 6c 65 73  rize those rules
5020: 2e 0a 0a 39 2e 20 44 65 72 65 66 65 72 65 6e 63  ...9. Dereferenc
5030: 69 6e 67 20 70 61 72 65 6e 74 68 65 73 69 7a 65  ing parenthesize
5040: 64 20 65 78 70 72 65 73 73 69 6f 6e 73 20 64 6f  d expressions do
5050: 65 73 20 6e 6f 74 20 77 6f 72 6b 3a 20 60 2a 28  es not work: `*(
5060: 3c 65 78 70 72 3e 29 60 0a 0a 31 30 2e 20 54 68  <expr>)`..10. Th
5070: 65 72 65 20 69 73 20 6e 6f 20 61 72 67 75 6d 65  ere is no argume
5080: 6e 74 20 6c 69 73 74 20 63 68 65 63 6b 69 6e 67  nt list checking
5090: 2c 20 6e 6f 74 20 65 76 65 6e 20 66 6f 72 20 66  , not even for f
50a0: 75 6e 63 74 69 6f 6e 73 0a 20 20 20 20 70 72 65  unctions.    pre
50b0: 76 69 6f 75 73 6c 79 20 64 65 63 6c 61 72 65 64  viously declared
50c0: 20 69 6e 20 74 68 65 20 73 61 6d 65 20 43 20 66   in the same C f
50d0: 69 6c 65 2e 20 49 66 20 77 65 20 64 69 64 20 66  ile. If we did f
50e0: 69 78 20 74 68 69 73 2c 20 74 68 65 0a 20 20 20  ix this, the.   
50f0: 20 70 72 6f 62 6c 65 6d 20 77 6f 75 6c 64 20 73   problem would s
5100: 74 69 6c 6c 20 65 78 69 73 74 20 66 6f 72 20 66  till exist for f
5110: 75 6e 63 74 69 6f 6e 73 20 69 6e 20 6f 74 68 65  unctions in othe
5120: 72 20 6d 6f 64 75 6c 65 73 2c 20 73 75 63 68 20  r modules, such 
5130: 61 73 0a 20 20 20 20 5b 60 4c 49 42 43 60 5d 28  as.    [`LIBC`](
5140: 23 6c 69 62 63 29 2c 20 73 69 6e 63 65 20 4b 26  #libc), since K&
5150: 52 20 43 20 64 6f 65 73 6e e2 80 99 74 20 68 61  R C doesn’t ha
5160: 76 65 20 70 72 6f 74 6f 74 79 70 65 73 3b 20 41  ve prototypes; A
5170: 4e 53 49 20 61 64 64 65 64 0a 20 20 20 20 74 68  NSI added.    th
5180: 61 74 20 66 65 61 74 75 72 65 20 74 6f 20 43 2e  at feature to C.
5190: 0a 0a 31 31 2e 20 60 64 6f 2f 77 68 69 6c 65 60  ..11. `do/while`
51a0: 20 6c 6f 6f 70 73 20 61 72 65 20 70 61 72 73 65   loops are parse
51b0: 64 2c 20 62 75 74 20 74 68 65 20 63 6f 64 65 20  d, but the code 
51c0: 69 73 20 6e 6f 74 20 70 72 6f 70 65 72 6c 79 20  is not properly 
51d0: 67 65 6e 65 72 61 74 65 64 2e 0a 20 20 20 20 52  generated..    R
51e0: 65 67 75 6c 61 72 20 60 77 68 69 6c 65 60 20 6c  egular `while` l
51f0: 6f 6f 70 73 20 77 6f 72 6b 2c 20 61 73 20 64 6f  oops work, as do
5200: 65 73 20 60 62 72 65 61 6b 60 2c 20 73 6f 20 6f  es `break`, so o
5210: 6e 65 20 77 6f 72 6b 61 72 6f 75 6e 64 20 66 6f  ne workaround fo
5220: 72 20 61 0a 20 20 20 20 6c 61 63 6b 20 6f 66 20  r a.    lack of 
5230: 60 64 6f 2f 77 68 69 6c 65 60 20 69 73 3a 0a 0a  `do/while` is:..
5240: 20 20 20 20 20 20 20 20 77 68 69 6c 65 20 28 31          while (1
5250: 29 20 7b 20 2f 2a 20 64 6f 20 73 6f 6d 65 74 68  ) { /* do someth
5260: 69 6e 67 20 75 73 65 66 75 6c 20 2a 2f 3b 20 69  ing useful */; i
5270: 66 20 28 63 6f 6e 64 29 20 62 72 65 61 6b 3b 20  f (cond) break; 
5280: 7d 0a 0a 20 20 20 20 57 65 20 68 61 76 65 20 6e  }..    We have n
5290: 6f 20 69 6e 74 65 6e 74 69 6f 6e 20 74 6f 20 66  o intention to f
52a0: 69 78 20 74 68 69 73 2e 0a 0a 31 32 2e 20 41 73  ix this...12. As
52b0: 20 6f 66 20 4d 61 79 20 32 30 32 30 2c 20 60 73   of May 2020, `s
52c0: 77 69 74 63 68 60 20 69 73 20 69 6d 70 6c 65 6d  witch` is implem
52d0: 65 6e 74 65 64 20 76 69 61 20 72 65 2d 77 72 69  ented via re-wri
52e0: 74 65 20 74 6f 20 63 61 73 63 61 64 69 6e 67 0a  te to cascading.
52f0: 20 20 20 20 60 69 66 60 2f 60 74 68 65 6e 60 20      `if`/`then` 
5300: 73 74 61 74 65 6d 65 6e 74 73 2e 20 54 68 65 72  statements. Ther
5310: 65 20 61 72 65 20 61 20 6e 75 6d 62 65 72 20 6f  e are a number o
5320: 66 20 6c 69 6d 69 74 61 74 69 6f 6e 73 20 74 6f  f limitations to
5330: 20 74 68 69 73 0a 20 20 20 20 61 70 70 72 6f 61   this.    approa
5340: 63 68 20 74 68 61 74 20 61 20 43 43 38 20 75 73  ch that a CC8 us
5350: 65 72 20 73 68 6f 75 6c 64 20 62 65 20 61 77 61  er should be awa
5360: 72 65 20 6f 66 2e 0a 0a 20 20 20 20 54 68 65 20  re of...    The 
5370: 70 72 69 6d 61 72 79 20 6f 6e 65 20 74 6f 20 6b  primary one to k
5380: 65 65 70 20 69 6e 20 6d 69 6e 64 20 69 73 20 74  eep in mind is t
5390: 68 61 74 20 74 68 61 74 20 69 66 20 79 6f 75 20  hat that if you 
53a0: 75 73 65 20 61 0a 20 20 20 20 6d 65 6d 6f 72 79  use a.    memory
53b0: 2d 6d 75 74 61 74 69 6e 67 20 65 78 70 72 65 73  -mutating expres
53c0: 73 69 6f 6e 20 69 6e 20 74 68 65 20 60 73 77 69  sion in the `swi
53d0: 74 63 68 60 20 63 6c 61 75 73 65 20 77 69 74 68  tch` clause with
53e0: 20 61 20 63 6f 6e 66 6f 72 6d 69 6e 67 0a 20 20   a conforming.  
53f0: 20 20 43 20 63 6f 6d 70 69 6c 65 72 2c 20 69 74    C compiler, it
5400: 20 69 73 20 65 76 61 6c 75 61 74 65 64 20 6a 75   is evaluated ju
5410: 73 74 20 6f 6e 63 65 20 61 74 20 74 68 65 20 73  st once at the s
5420: 74 61 72 74 20 6f 66 20 74 68 65 20 62 6c 6f 63  tart of the bloc
5430: 6b 2c 20 62 75 74 0a 20 20 20 20 69 6e 20 43 43  k, but.    in CC
5440: 38 2c 20 69 74 20 69 73 20 65 76 61 6c 75 61 74  8, it is evaluat
5450: 65 64 20 6f 6e 63 65 20 66 6f 72 20 65 61 63 68  ed once for each
5460: 20 67 65 6e 65 72 61 74 65 64 20 60 69 66 60 20   generated `if` 
5470: 73 75 62 2d 65 78 70 72 65 73 73 69 6f 6e 0a 20  sub-expression. 
5480: 20 20 20 74 68 61 74 20 74 68 65 20 63 6f 64 65     that the code
5490: 20 76 69 73 69 74 73 2e 20 54 68 61 74 20 69 73   visits. That is
54a0: 2c 20 79 6f 75 20 73 68 6f 75 6c 64 20 6e 6f 74  , you should not
54b0: 20 73 61 79 20 74 68 69 6e 67 73 20 6c 69 6b 65   say things like
54c0: 20 74 68 69 73 0a 20 20 20 20 69 6e 20 63 6f 64   this.    in cod
54d0: 65 20 6d 65 61 6e 74 20 74 6f 20 62 65 20 63 6f  e meant to be co
54e0: 6d 70 69 6c 65 64 20 77 69 74 68 20 74 68 65 20  mpiled with the 
54f0: 43 43 38 20 6e 61 74 69 76 65 20 63 6f 6d 70 69  CC8 native compi
5500: 6c 65 72 3a 0a 0a 20 20 20 20 20 20 20 20 73 77  ler:..        sw
5510: 69 74 63 68 20 28 2a 70 2b 2b 29 20 7b 2e 2e 2e  itch (*p++) {...
5520: 7d 0a 0a 20 20 20 20 53 61 79 20 69 6e 73 74 65  }..    Say inste
5530: 61 64 3a 0a 0a 20 20 20 20 20 20 20 20 69 6e 74  ad:..        int
5540: 20 74 65 6d 70 20 3d 20 2a 70 2b 2b 3b 0a 20 20   temp = *p++;.  
5550: 20 20 20 20 20 20 73 77 69 74 63 68 20 28 74 65        switch (te
5560: 6d 70 29 20 7b 2e 2e 2e 2e 7d 0a 0a 20 20 20 20  mp) {....}..    
5570: 41 6c 73 6f 2c 20 74 68 65 72 65 20 2a 2a 6d 75  Also, there **mu
5580: 73 74 2a 2a 20 62 65 20 61 20 60 64 65 66 61 75  st** be a `defau
5590: 6c 74 60 20 63 61 73 65 2c 20 61 6e 64 20 63 61  lt` case, and ca
55a0: 73 65 73 20 28 69 6e 63 6c 75 64 69 6e 67 20 74  ses (including t
55b0: 68 65 0a 20 20 20 20 64 65 66 61 75 6c 74 20 63  he.    default c
55c0: 61 73 65 29 20 6d 75 73 74 20 62 65 20 74 65 72  ase) must be ter
55d0: 6d 69 6e 61 74 65 64 20 77 69 74 68 20 61 20 60  minated with a `
55e0: 62 72 65 61 6b 60 2e 20 43 43 38 20 64 6f 65 73  break`. CC8 does
55f0: 20 6e 6f 74 20 61 6c 6c 6f 77 0a 20 20 20 20 66   not allow.    f
5600: 6f 72 20 63 61 73 65 73 20 74 68 61 74 20 66 61  or cases that fa
5610: 6c 6c 20 74 68 72 6f 75 67 68 20 74 6f 20 74 68  ll through to th
5620: 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 63 61 73 65  e following case
5630: 2e 20 54 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 0a  . The following.
5640: 20 20 20 20 63 6f 64 65 20 68 61 73 20 61 74 20      code has at 
5650: 6c 65 61 73 74 20 74 68 72 65 65 20 73 79 6e 74  least three synt
5660: 61 78 20 65 72 72 6f 72 73 3a 0a 0a 20 20 20 20  ax errors:..    
5670: 20 20 20 20 73 77 69 74 63 68 20 28 78 29 20 7b      switch (x) {
5680: 0a 20 20 20 20 20 20 20 20 20 20 20 20 63 61 73  .            cas
5690: 65 20 31 3a 20 20 66 6f 6f 28 29 3b 0a 20 20 20  e 1:  foo();.   
56a0: 20 20 20 20 20 20 20 20 20 63 61 73 65 20 32 3a           case 2:
56b0: 20 20 62 61 72 28 29 3b 0a 20 20 20 20 20 20 20    bar();.       
56c0: 20 20 20 20 20 64 65 66 61 75 6c 74 3a 20 71 75       default: qu
56d0: 78 28 29 3b 0a 20 20 20 20 20 20 20 20 7d 0a 0a  x();.        }..
56e0: 31 33 2e 20 60 73 69 7a 65 6f 66 28 29 60 20 69  13. `sizeof()` i
56f0: 73 20 6e 6f 74 20 69 6d 70 6c 65 6d 65 6e 74 65  s not implemente
5700: 64 2e 0a 0a 0a 0a 3c 61 20 69 64 3d 22 77 61 72  d.....<a id="war
5710: 6e 69 6e 67 22 3e 3c 2f 61 3e 0a 23 23 23 23 20  ning"></a>.#### 
5720: 47 4f 56 45 52 4e 4d 45 4e 54 20 48 45 41 4c 54  GOVERNMENT HEALT
5730: 48 20 57 41 52 4e 49 4e 47 0a 0a 2a 2a 59 6f 75  H WARNING..**You
5740: 20 61 72 65 20 68 65 72 65 62 79 20 77 61 72 6e   are hereby warn
5750: 65 64 2a 2a 3a 20 54 68 65 20 6e 61 74 69 76 65  ed**: The native
5760: 20 4f 53 2f 38 20 63 6f 6d 70 69 6c 65 72 20 64   OS/8 compiler d
5770: 6f 65 73 20 6e 6f 74 20 63 6f 6e 74 61 69 6e 20  oes not contain 
5780: 61 6e 79 0a 65 72 72 6f 72 20 63 68 65 63 6b 69  any.error checki
5790: 6e 67 20 77 68 61 74 73 6f 65 76 65 72 2e 20 49  ng whatsoever. I
57a0: 66 20 74 68 65 20 73 6f 75 72 63 65 20 66 69 6c  f the source fil
57b0: 65 73 20 63 6f 6e 74 61 69 6e 20 61 6e 20 65 72  es contain an er
57c0: 72 6f 72 20 6f 72 20 79 6f 75 0a 6d 69 73 74 79  ror or you.misty
57d0: 70 65 20 61 20 62 75 69 6c 64 20 63 6f 6d 6d 61  pe a build comma
57e0: 6e 64 2c 20 79 6f 75 20 6d 61 79 20 67 65 74 3a  nd, you may get:
57f0: 0a 0a 2a 20 20 20 41 20 72 75 6e 74 69 6d 65 20  ..*   A runtime 
5800: 63 72 61 73 68 20 69 6e 20 74 68 65 20 63 6f 6d  crash in the com
5810: 70 69 6c 65 72 0a 2a 20 20 20 53 41 42 52 20 61  piler.*   SABR a
5820: 73 73 65 6d 62 6c 79 20 6f 75 74 70 75 74 20 74  ssembly output t
5830: 68 61 74 20 77 6f 6e 27 74 20 61 73 73 65 6d 62  hat won't assemb
5840: 6c 65 0a 2a 20 20 20 4f 75 74 70 75 74 20 74 68  le.*   Output th
5850: 61 74 20 61 73 73 65 6d 62 6c 65 73 20 62 75 74  at assembles but
5860: 20 77 6f 6e 27 74 20 72 75 6e 20 63 6f 72 72 65   won't run corre
5870: 63 74 6c 79 0a 0a 52 61 72 65 6c 79 20 77 69 6c  ctly..Rarely wil
5880: 6c 20 61 6e 79 20 6f 66 20 74 68 65 73 65 20 66  l any of these f
5890: 61 69 6c 75 72 65 20 6d 6f 64 65 73 20 67 69 76  ailure modes giv
58a0: 65 20 61 6e 79 20 6b 69 6e 64 20 6f 66 20 73 65  e any kind of se
58b0: 6e 73 69 62 6c 65 20 68 69 6e 74 20 61 73 0a 74  nsible hint as.t
58c0: 6f 20 74 68 65 20 63 61 75 73 65 2e 20 4f 53 2f  o the cause. OS/
58d0: 38 20 43 43 38 20 63 61 6e 6e 6f 74 20 61 66 66  8 CC8 cannot aff
58e0: 6f 72 64 20 74 68 65 20 68 75 6e 64 72 65 64 73  ord the hundreds
58f0: 20 6f 66 20 6b 69 6c 6f 62 79 74 65 73 20 6f 66   of kilobytes of
5900: 20 65 72 72 6f 72 0a 63 68 65 63 6b 69 6e 67 20   error.checking 
5910: 61 6e 64 20 74 65 78 74 20 72 65 70 6f 72 74 69  and text reporti
5920: 6e 67 20 74 68 61 74 20 79 6f 75 20 67 65 74 20  ng that you get 
5930: 69 6e 20 61 20 6d 6f 64 65 72 6e 20 63 6f 6d 70  in a modern comp
5940: 69 6c 65 72 20 6c 69 6b 65 20 47 43 43 0a 6f 72  iler like GCC.or
5950: 20 43 6c 61 6e 67 2e 20 54 68 61 74 20 77 6f 75   Clang. That wou
5960: 6c 64 20 68 61 76 65 20 72 65 71 75 69 72 65 64  ld have required
5970: 20 61 20 72 6f 6f 6d 66 75 6c 20 6f 66 20 63 6f   a roomful of co
5980: 72 65 20 6d 65 6d 6f 72 79 20 74 6f 20 61 63 68  re memory to ach
5990: 69 65 76 65 0a 6f 6e 20 61 20 72 65 61 6c 20 50  ieve.on a real P
59a0: 44 50 2d 38 2e 20 53 69 6e 63 65 20 77 65 27 72  DP-8. Since we'r
59b0: 65 20 77 6f 72 6b 69 6e 67 20 77 69 74 68 69 6e  e working within
59c0: 20 74 68 65 20 63 6f 6e 73 74 72 61 69 6e 74 73   the constraints
59d0: 20 6f 66 20 74 68 65 20 6f 6c 64 0a 50 44 50 2d   of the old.PDP-
59e0: 38 20 61 72 63 68 69 74 65 63 74 75 72 65 2c 20  8 architecture, 
59f0: 77 65 20 6f 6e 6c 79 20 68 61 76 65 20 61 62 6f  we only have abo
5a00: 75 74 20 33 26 6e 62 73 70 3b 6b 57 6f 72 64 73  ut 3&nbsp;kWords
5a10: 20 74 6f 20 63 6f 6e 73 74 72 75 63 74 20 74 68   to construct th
5a20: 65 20 70 61 72 73 65 0a 72 65 73 75 6c 74 2c 20  e parse.result, 
5a30: 66 6f 72 20 65 78 61 6d 70 6c 65 2e 0a 0a 49 6e  for example...In
5a40: 20 61 64 64 69 74 69 6f 6e 2c 20 74 68 65 20 6e   addition, the n
5a50: 61 74 69 76 65 20 4f 53 2f 38 20 63 6f 6d 70 69  ative OS/8 compi
5a60: 6c 65 72 20 69 73 20 73 65 76 65 72 65 6c 79 20  ler is severely 
5a70: 6c 69 6d 69 74 65 64 20 69 6e 20 63 6f 64 65 20  limited in code 
5a80: 73 70 61 63 65 2c 0a 73 6f 20 69 74 20 64 6f 65  space,.so it doe
5a90: 73 20 6e 6f 74 20 75 6e 64 65 72 73 74 61 6e 64  s not understand
5aa0: 20 74 68 65 20 66 75 6c 6c 20 43 20 6c 61 6e 67   the full C lang
5ab0: 75 61 67 65 2e 20 49 74 20 69 73 20 6c 65 73 73  uage. It is less
5ac0: 20 66 75 6e 63 74 69 6f 6e 61 6c 0a 74 68 61 6e   functional.than
5ad0: 20 4b 26 52 20 43 20 31 39 37 38 3b 20 77 65 20   K&R C 1978; we 
5ae0: 64 6f 20 6e 6f 74 20 68 61 76 65 20 61 20 67 6f  do not have a go
5af0: 6f 64 20 62 65 6e 63 68 6d 61 72 6b 20 66 6f 72  od benchmark for
5b00: 20 77 68 61 74 20 69 74 20 63 6f 6d 70 61 72 65   what it compare
5b10: 73 20 74 6f 0a 69 6e 20 74 65 72 6d 73 20 6f 66  s to.in terms of
5b20: 20 6f 74 68 65 72 20 65 61 72 6c 79 20 43 20 64   other early C d
5b30: 69 61 6c 65 63 74 73 2c 20 62 75 74 20 77 65 20  ialects, but we 
5b40: 63 61 6e 20 73 75 6d 20 69 74 20 75 70 20 69 6e  can sum it up in
5b50: 20 61 20 73 69 6e 67 6c 65 0a 77 6f 72 64 3a 20   a single.word: 
5b60: 70 72 69 6d 69 74 69 76 65 2e 0a 0a 4e 6f 6e 65  primitive...None
5b70: 74 68 65 6c 65 73 73 2c 20 6f 75 72 20 68 69 67  theless, our hig
5b80: 68 6c 79 20 6c 69 6d 69 74 65 64 20 43 20 64 69  hly limited C di
5b90: 61 6c 65 63 74 20 69 73 20 54 75 72 69 6e 67 20  alect is Turing 
5ba0: 63 6f 6d 70 6c 65 74 65 2e 20 49 74 20 6d 69 67  complete. It mig
5bb0: 68 74 0a 62 65 20 62 65 74 74 65 72 20 74 6f 20  ht.be better to 
5bc0: 74 68 69 6e 6b 20 6f 66 20 69 74 20 61 73 20 61  think of it as a
5bd0: 20 68 69 67 68 2d 6c 65 76 65 6c 20 61 73 73 65   high-level asse
5be0: 6d 62 6c 79 20 6c 61 6e 67 75 61 67 65 20 74 68  mbly language th
5bf0: 61 74 0a 72 65 73 65 6d 62 6c 65 73 20 43 20 72  at.resembles C r
5c00: 61 74 68 65 72 20 74 68 61 6e 20 61 73 20 22 43  ather than as "C
5c10: 22 20 70 72 6f 70 65 72 2e 0a 0a 0a 23 23 20 3c  " proper....## <
5c20: 61 20 69 64 3d 22 6c 69 62 63 22 3e 3c 2f 61 3e  a id="libc"></a>
5c30: 54 68 65 20 43 43 38 20 43 20 4c 69 62 72 61 72  The CC8 C Librar
5c40: 79 3a 20 44 6f 63 75 6d 65 6e 74 61 74 69 6f 6e  y: Documentation
5c50: 0a 0a 49 6e 20 74 68 69 73 20 73 65 63 74 69 6f  ..In this sectio
5c60: 6e 2c 20 77 65 20 77 69 6c 6c 20 65 78 70 6c 61  n, we will expla
5c70: 69 6e 20 73 6f 6d 65 20 68 69 67 68 2d 6c 65 76  in some high-lev
5c80: 65 6c 20 6d 61 74 74 65 72 73 20 74 68 61 74 20  el matters that 
5c90: 63 75 74 20 61 63 72 6f 73 73 0a 6d 75 6c 74 69  cut across.multi
5ca0: 70 6c 65 20 66 75 6e 63 74 69 6f 6e 73 20 69 6e  ple functions in
5cb0: 20 74 68 65 20 43 20 6c 69 62 72 61 72 79 2e 20   the C library. 
5cc0: 54 68 69 73 20 6d 61 74 65 72 69 61 6c 20 69 73  This material is
5cd0: 20 74 68 65 72 65 66 6f 72 65 20 6e 6f 74 0a 61   therefore not.a
5ce0: 70 70 72 6f 70 72 69 61 74 65 20 74 6f 20 72 65  ppropriate to re
5cf0: 70 65 61 74 20 62 65 6c 6f 77 2c 20 69 6e 20 74  peat below, in t
5d00: 68 65 20 5b 43 20 6c 69 62 72 61 72 79 20 66 75  he [C library fu
5d10: 6e 63 74 69 6f 6e 0a 72 65 66 65 72 65 6e 63 65  nction.reference
5d20: 5d 28 23 6c 69 62 72 65 66 29 2e 0a 0a 0a 23 23  ](#libref)....##
5d30: 23 20 3c 61 20 69 64 3d 22 63 74 79 70 65 22 3e  # <a id="ctype">
5d40: 3c 2f 61 3e 63 74 79 70 65 0a 0a 54 68 65 20 49  </a>ctype..The I
5d50: 53 4f 20 43 20 53 74 61 6e 64 61 72 64 20 64 6f  SO C Standard do
5d60: 65 73 20 6e 6f 74 20 64 65 66 69 6e 65 20 77 68  es not define wh
5d70: 61 74 20 74 68 65 20 60 69 73 2a 28 29 60 20 66  at the `is*()` f
5d80: 75 6e 63 74 69 6f 6e 73 20 64 6f 20 77 68 65 6e  unctions do when
5d90: 0a 74 68 65 20 70 61 73 73 65 64 20 63 68 61 72  .the passed char
5da0: 61 63 74 65 72 20 69 73 20 6e 6f 74 20 72 65 70  acter is not rep
5db0: 72 65 73 65 6e 74 61 62 6c 65 20 61 73 20 60 75  resentable as `u
5dc0: 6e 73 69 67 6e 65 64 20 63 68 61 72 60 2e 20 53  nsigned char`. S
5dd0: 69 6e 63 65 20 74 68 69 73 0a 43 20 63 6f 6d 70  ince this.C comp
5de0: 69 6c 65 72 20 5b 64 6f 65 73 20 6e 6f 74 20 64  iler [does not d
5df0: 69 73 74 69 6e 67 75 69 73 68 20 74 79 70 65 73  istinguish types
5e00: 5d 28 23 74 79 70 65 6c 65 73 73 29 2c 20 6f 75  ](#typeless), ou
5e10: 72 20 60 69 73 2a 28 29 60 0a 66 75 6e 63 74 69  r `is*()`.functi
5e20: 6f 6e 73 20 72 65 74 75 72 6e 20 66 61 6c 73 65  ons return false
5e30: 20 66 6f 72 20 61 6e 79 20 76 61 6c 75 65 20 6f   for any value o
5e40: 75 74 73 69 64 65 20 6f 66 20 74 68 65 20 41 53  utside of the AS
5e50: 43 49 49 20 72 61 6e 67 65 2c 20 30 2d 31 32 37  CII range, 0-127
5e60: 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 63  ....### <a id="c
5e70: 73 65 74 22 3e 3c 2f 61 3e 43 68 61 72 61 63 74  set"></a>Charact
5e80: 65 72 20 53 65 74 0a 0a 54 68 65 20 73 74 64 69  er Set..The stdi
5e90: 6f 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e  o implementation
5ea0: 20 63 75 72 72 65 6e 74 6c 79 20 61 73 73 75 6d   currently assum
5eb0: 65 73 20 55 53 2d 41 53 43 49 49 20 37 2d 62 69  es US-ASCII 7-bi
5ec0: 74 20 74 65 78 74 20 49 2f 4f 2e 0a 0a 49 6e 70  t text I/O...Inp
5ed0: 75 74 20 63 68 61 72 61 63 74 65 72 73 20 68 61  ut characters ha
5ee0: 76 65 20 74 68 65 69 72 20 75 70 70 65 72 20 35  ve their upper 5
5ef0: 20 62 69 74 73 20 6d 61 73 6b 65 64 20 6f 66 66   bits masked off
5f00: 20 73 6f 20 74 68 61 74 20 6f 6e 6c 79 20 74 68   so that only th
5f10: 65 0a 6c 6f 77 65 72 20 37 20 62 69 74 73 20 61  e.lower 7 bits a
5f20: 72 65 20 76 61 6c 69 64 20 69 6e 20 74 68 65 20  re valid in the 
5f30: 72 65 74 75 72 6e 65 64 20 31 32 20 62 69 74 20  returned 12 bit 
5f40: 50 44 50 2d 38 20 77 6f 72 64 2e 20 43 6f 64 65  PDP-8 word. Code
5f50: 20 75 73 69 6e 67 0a 5b 60 66 67 65 74 63 60 5d   using.[`fgetc`]
5f60: 28 23 66 67 65 74 63 29 20 63 61 6e 6e 6f 74 20  (#fgetc) cannot 
5f70: 62 65 20 75 73 65 64 20 6f 6e 20 61 72 62 69 74  be used on arbit
5f80: 72 61 72 79 20 62 69 6e 61 72 79 20 64 61 74 61  rary binary data
5f90: 20 62 65 63 61 75 73 65 20 69 74 73 0a e2 80 9c   because its.“
5fa0: 65 6e 64 20 6f 66 20 66 69 6c 65 e2 80 9d 20 72  end of file” r
5fb0: 65 74 75 72 6e 20 63 61 73 65 20 69 73 20 69 6e  eturn case is in
5fc0: 64 69 73 74 69 6e 67 75 69 73 68 61 62 6c 65 20  distinguishable 
5fd0: 66 72 6f 6d 20 72 65 61 64 69 6e 67 20 61 20 30  from reading a 0
5fe0: 20 62 79 74 65 2e 0a 0a 54 68 65 20 6f 75 74 70   byte...The outp
5ff0: 75 74 20 66 75 6e 63 74 69 6f 6e 73 20 77 69 6c  ut functions wil
6000: 6c 20 61 74 74 65 6d 70 74 20 74 6f 20 73 74 6f  l attempt to sto
6010: 72 65 20 38 2d 62 69 74 20 64 61 74 61 2c 20 62  re 8-bit data, b
6020: 75 74 20 73 69 6e 63 65 20 79 6f 75 0a 63 61 6e  ut since you.can
6030: e2 80 99 74 20 72 65 61 64 20 69 74 20 62 61 63  ’t read it bac
6040: 6b 20 69 6e 20 73 61 66 65 6c 79 20 77 69 74 68  k in safely with
6050: 20 74 68 69 73 20 63 75 72 72 65 6e 74 20 69 6d   this current im
6060: 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2c 20 70 65  plementation, pe
6070: 72 0a 61 62 6f 76 65 2c 20 79 6f 75 20 73 68 6f  r.above, you sho
6080: 75 6c 64 20 6f 6e 6c 79 20 77 72 69 74 65 20 41  uld only write A
6090: 53 43 49 49 20 74 65 78 74 20 74 6f 20 6f 75 74  SCII text to out
60a0: 70 75 74 20 66 69 6c 65 73 20 77 69 74 68 20 74  put files with t
60b0: 68 69 73 0a 69 6d 70 6c 65 6d 65 6e 74 61 74 69  his.implementati
60c0: 6f 6e 2e 20 45 76 65 6e 20 69 66 20 79 6f 75 20  on. Even if you 
60d0: 61 72 65 20 72 65 61 64 69 6e 67 20 79 6f 75 72  are reading your
60e0: 20 66 69 6c 65 73 20 77 69 74 68 20 73 6f 6d 65   files with some
60f0: 20 6f 74 68 65 72 20 63 6f 64 65 0a 77 68 69 63   other code.whic
6100: 68 20 69 73 20 63 61 70 61 62 6c 65 20 6f 66 20  h is capable of 
6110: 68 61 6e 64 6c 69 6e 67 20 38 2d 62 69 74 20 64  handling 8-bit d
6120: 61 74 61 2c 20 74 68 65 72 65 20 61 72 65 20 66  ata, there are f
6130: 75 72 74 68 65 72 20 64 69 66 66 69 63 75 6c 74  urther difficult
6140: 69 65 73 0a 73 75 63 68 20 61 73 20 61 20 6c 61  ies.such as a la
6150: 63 6b 20 6f 66 20 66 75 6e 63 74 69 6f 6e 73 20  ck of functions 
6160: 74 61 6b 69 6e 67 20 61 6e 20 65 78 70 6c 69 63  taking an explic
6170: 69 74 20 6c 65 6e 67 74 68 2c 20 6c 69 6b 65 20  it length, like 
6180: 60 66 77 72 69 74 65 28 29 60 2c 0a 77 68 69 63  `fwrite()`,.whic
6190: 68 20 6d 61 6b 65 73 20 64 65 61 6c 69 6e 67 20  h makes dealing 
61a0: 77 69 74 68 20 41 53 43 49 49 20 4e 55 4c 20 64  with ASCII NUL d
61b0: 69 66 66 69 63 75 6c 74 2e 20 59 6f 75 20 63 6f  ifficult. You co
61c0: 75 6c 64 20 77 72 69 74 65 20 61 20 4e 55 4c 20  uld write a NUL 
61d0: 74 6f 0a 61 6e 20 6f 75 74 70 75 74 20 66 69 6c  to.an output fil
61e0: 65 20 77 69 74 68 20 60 66 70 75 74 63 28 29 60  e with `fputc()`
61f0: 2c 20 62 75 74 20 6e 6f 74 20 77 69 74 68 20 60  , but not with `
6200: 66 70 75 74 73 28 29 60 2c 20 73 69 6e 63 65 20  fputs()`, since 
6210: 4e 55 4c 0a 74 65 72 6d 69 6e 61 74 65 73 20 74  NUL.terminates t
6220: 68 65 20 6f 75 74 70 75 74 20 73 74 72 69 6e 67  he output string
6230: 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 77  ....### <a id="w
6240: 6f 72 64 73 74 72 22 3e 3c 2f 61 3e 53 74 72 69  ordstr"></a>Stri
6250: 6e 67 73 20 61 72 65 20 6f 66 20 57 6f 72 64 73  ngs are of Words
6260: 2c 20 4e 6f 74 20 6f 66 20 42 79 74 65 73 20 6f  , Not of Bytes o
6270: 72 20 43 68 61 72 61 63 74 65 72 73 0a 0a 49 6e  r Characters..In
6280: 20 73 65 76 65 72 61 6c 20 70 6c 61 63 65 73 2c   several places,
6290: 20 74 68 65 20 53 74 61 6e 64 61 72 64 20 73 61   the Standard sa
62a0: 79 73 20 61 20 63 6f 6e 66 6f 72 6d 69 6e 67 20  ys a conforming 
62b0: 43 20 6c 69 62 72 61 72 79 20 69 73 20 73 75 70  C library is sup
62c0: 70 6f 73 65 64 0a 74 6f 20 6f 70 65 72 61 74 65  posed.to operate
62d0: 20 6f 6e 20 e2 80 9c 62 79 74 65 73 e2 80 9d 20   on “bytes” 
62e0: 6f 72 20 e2 80 9c 63 68 61 72 61 63 74 65 72 73  or “characters
62f0: 2c e2 80 9d 20 61 74 20 6c 65 61 73 74 20 61 63  ,” at least ac
6300: 63 6f 72 64 69 6e 67 20 74 6f 20 5b 6f 75 72 20  cording to [our 
6310: 63 68 6f 73 65 6e 0a 69 6e 74 65 72 70 72 65 74  chosen.interpret
6320: 61 74 69 6f 6e 5d 5b 63 70 70 72 5d 2e 20 45 78  ation][cppr]. Ex
6330: 63 65 70 74 20 66 6f 72 20 74 68 65 20 74 65 78  cept for the tex
6340: 74 20 49 2f 4f 20 72 65 73 74 72 69 63 74 69 6f  t I/O restrictio
6350: 6e 73 20 63 61 6c 6c 65 64 20 6f 75 74 0a 5b 61  ns called out.[a
6360: 62 6f 76 65 5d 28 23 63 73 65 74 29 2c 20 4c 49  bove](#cset), LI
6370: 42 43 20 6f 70 65 72 61 74 65 73 20 6f 6e 20 73  BC operates on s
6380: 74 72 69 6e 67 73 20 6f 66 20 50 44 50 2d 38 20  trings of PDP-8 
6390: 77 6f 72 64 73 2c 20 6e 6f 74 20 6f 6e 20 74 68  words, not on th
63a0: 65 73 65 0a 6d 6f 64 65 72 6e 20 6e 6f 74 69 6f  ese.modern notio
63b0: 6e 73 20 6f 66 20 66 69 78 65 64 20 38 2d 62 69  ns of fixed 8-bi
63c0: 74 20 62 79 74 65 73 20 6f 72 20 74 68 65 20 65  t bytes or the e
63d0: 76 65 72 2d 6e 65 62 75 6c 6f 75 73 20 e2 80 9c  ver-nebulous “
63e0: 63 68 61 72 61 63 74 65 72 73 2e e2 80 9d 0a 0a  characters.”..
63f0: 42 65 63 61 75 73 65 20 79 6f 75 20 6d 61 79 20  Because you may 
6400: 62 65 20 75 73 65 64 20 74 6f 20 74 68 65 20 69  be used to the i
6410: 64 65 61 20 74 68 61 74 20 73 74 72 69 6e 67 20  dea that string 
6420: 61 6e 64 20 6d 65 6d 6f 72 79 20 66 75 6e 63 74  and memory funct
6430: 69 6f 6e 73 0a 6c 69 6b 65 20 5b 60 6d 65 6d 63  ions.like [`memc
6440: 70 79 28 29 60 5d 28 23 6d 65 6d 63 70 79 29 20  py()`](#memcpy) 
6450: 61 6e 64 20 5b 60 73 74 72 63 61 74 28 29 60 5d  and [`strcat()`]
6460: 28 23 73 74 72 63 61 74 29 20 77 69 6c 6c 20 6f  (#strcat) will o
6470: 70 65 72 61 74 65 20 6f 6e 0a 62 79 74 65 73 2c  perate on.bytes,
6480: 20 77 65 e2 80 99 76 65 20 6d 61 72 6b 65 64 20   we’ve marked 
6490: 61 6c 6c 20 6f 66 20 74 68 65 73 65 20 63 61 73  all of these cas
64a0: 65 73 20 77 69 74 68 20 61 20 72 65 66 65 72 65  es with a refere
64b0: 6e 63 65 20 62 61 63 6b 20 74 6f 20 74 68 69 73  nce back to this
64c0: 0a 73 65 63 74 69 6f 6e 2e 0a 0a 42 79 20 74 68  .section...By th
64d0: 65 20 73 61 6d 65 20 74 6f 6b 65 6e 2c 20 6d 6f  e same token, mo
64e0: 73 74 20 66 75 6e 63 74 69 6f 6e 73 20 74 68 61  st functions tha
64f0: 74 20 6f 70 65 72 61 74 65 20 6f 6e 20 4e 55 4c  t operate on NUL
6500: 2d 74 65 72 6d 69 6e 61 74 65 64 20 73 74 72 69  -terminated stri
6510: 6e 67 0a 62 75 66 66 65 72 73 20 69 6e 20 61 20  ng.buffers in a 
6520: 63 6f 6e 66 6f 72 6d 69 6e 67 20 43 20 6c 69 62  conforming C lib
6530: 72 61 72 79 20 69 6d 70 6c 65 6d 65 6e 74 61 74  rary implementat
6540: 69 6f 6e 20 61 63 74 75 61 6c 6c 79 20 63 68 65  ion actually che
6550: 63 6b 20 66 6f 72 20 61 0a 77 6f 72 64 20 65 71  ck for a.word eq
6560: 75 61 6c 20 74 6f 20 30 30 30 30 e2 82 88 20 69  ual to 0000₈ i
6570: 6e 20 74 68 69 73 20 69 6d 70 6c 65 6d 65 6e 74  n this implement
6580: 61 74 69 6f 6e 2e 20 54 68 65 20 6b 65 79 20 74  ation. The key t
6590: 68 69 6e 67 20 74 6f 20 75 6e 64 65 72 73 74 61  hing to understa
65a0: 6e 64 0a 69 73 20 74 68 61 74 20 74 68 65 73 65  nd.is that these
65b0: 20 72 6f 75 74 69 6e 65 73 20 61 72 65 20 6e 6f   routines are no
65c0: 74 20 63 61 72 65 66 75 6c 6c 79 20 6d 61 73 6b  t carefully mask
65d0: 69 6e 67 20 6f 66 66 20 74 68 65 20 74 6f 70 20  ing off the top 
65e0: 34 20 6f 72 20 35 20 62 69 74 73 0a 74 6f 20 63  4 or 5 bits.to c
65f0: 68 65 63 6b 20 2a 6f 6e 6c 79 2a 20 61 67 61 69  heck *only* agai
6600: 6e 73 74 20 61 20 37 2d 20 6f 72 20 38 2d 62 69  nst a 7- or 8-bi
6610: 74 20 4e 55 4c 20 63 68 61 72 61 63 74 65 72 2e  t NUL character.
6620: 0a 0a 54 68 69 73 20 69 73 20 61 6e 6f 74 68 65  ..This is anothe
6630: 72 20 6d 61 6e 69 66 65 73 74 61 74 69 6f 6e 20  r manifestation 
6640: 6f 66 20 5b 43 43 38 e2 80 99 73 20 74 79 70 65  of [CC8’s type
6650: 6c 65 73 73 20 6e 61 74 75 72 65 5d 28 23 74 79  less nature](#ty
6660: 70 65 6c 65 73 73 29 2e 0a 0a 0a 23 23 23 20 3c  peless)....### <
6670: 61 20 69 64 3d 22 66 69 6f 6c 69 6d 22 3e 3c 2f  a id="fiolim"></
6680: 61 3e 46 69 6c 65 20 49 2f 4f 20 4c 69 6d 69 74  a>File I/O Limit
6690: 61 74 69 6f 6e 73 0a 0a 42 65 63 61 75 73 65 20  ations..Because 
66a0: 4c 49 42 43 e2 80 99 73 20 73 74 64 69 6f 20 69  LIBC’s stdio i
66b0: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 69 73  mplementation is
66c0: 20 62 75 69 6c 74 20 61 74 6f 70 20 74 68 65 20   built atop the 
66d0: 4f 53 2f 38 20 46 4f 52 54 52 41 4e 20 49 49 0a  OS/8 FORTRAN II.
66e0: 6c 69 62 72 61 72 79 2c 20 69 74 20 6f 6e 6c 79  library, it only
66f0: 20 61 6c 6c 6f 77 73 20 6f 6e 65 20 66 69 6c 65   allows one file
6700: 20 74 6f 20 62 65 20 6f 70 65 6e 20 61 74 20 61   to be open at a
6710: 20 74 69 6d 65 20 66 6f 72 20 72 65 61 64 69 6e   time for readin
6720: 67 20 61 6e 64 0a 6f 6e 65 20 66 6f 72 20 77 72  g and.one for wr
6730: 69 74 69 6e 67 2e 20 4f 53 2f 38 e2 80 99 73 20  iting. OS/8’s 
6740: 75 6e 64 65 72 6c 79 69 6e 67 20 6c 69 6d 69 74  underlying limit
6750: 20 69 73 20 35 20 6f 75 74 70 75 74 20 66 69 6c   is 5 output fil
6760: 65 73 20 61 6e 64 20 39 20 69 6e 70 75 74 0a 66  es and 9 input.f
6770: 69 6c 65 73 2c 20 77 68 69 63 68 20 61 70 70 65  iles, which appe
6780: 61 72 73 20 74 6f 20 62 65 20 61 6e 20 61 63 63  ars to be an acc
6790: 6f 6d 6d 6f 64 61 74 69 6f 6e 20 73 70 65 63 69  ommodation speci
67a0: 66 69 63 61 6c 6c 79 20 66 6f 72 20 69 74 73 20  fically for its 
67b0: 46 4f 52 54 52 41 4e 0a 49 56 20 69 6d 70 6c 65  FORTRAN.IV imple
67c0: 6d 65 6e 74 61 74 69 6f 6e 2c 20 73 6f 20 69 74  mentation, so it
67d0: 20 69 73 20 70 6f 73 73 69 62 6c 65 20 74 68 61   is possible tha
67e0: 74 20 61 20 66 75 74 75 72 65 20 43 43 38 20 77  t a future CC8 w
67f0: 6f 75 6c 64 20 62 65 0a 72 65 74 61 72 67 65 74  ould be.retarget
6800: 65 64 20 61 74 20 46 4f 52 54 52 41 4e 20 49 56  ed at FORTRAN IV
6810: 20 74 6f 20 6c 69 66 74 20 74 68 69 73 20 6c 69   to lift this li
6820: 6d 69 74 61 74 69 6f 6e 2c 20 62 75 74 20 69 74  mitation, but it
6830: 20 77 6f 75 6c 64 20 62 65 20 61 0a 6e 6f 6e 74   would be a.nont
6840: 72 69 76 69 61 6c 20 61 6d 6f 75 6e 74 20 6f 66  rivial amount of
6850: 20 77 6f 72 6b 2e 0a 0a 4d 65 61 6e 77 68 69 6c   work...Meanwhil
6860: 65 2c 20 77 65 20 67 65 6e 65 72 61 6c 6c 79 20  e, we generally 
6870: 64 65 66 65 72 20 74 6f 20 74 68 65 20 4f 53 2f  defer to the OS/
6880: 38 20 46 4f 52 54 52 41 4e 20 49 49 20 6d 61 6e  8 FORTRAN II man
6890: 75 61 6c 20 77 68 65 72 65 20 69 74 0a 63 6f 6d  ual where it.com
68a0: 65 73 20 74 6f 20 64 6f 63 75 6d 65 6e 74 61 74  es to documentat
68b0: 69 6f 6e 20 6f 66 20 74 68 65 73 65 20 66 75 6e  ion of these fun
68c0: 63 74 69 6f 6e 73 20 62 65 68 61 76 69 6f 72 2e  ctions behavior.
68d0: 20 20 54 68 65 20 6f 6e 6c 79 20 74 69 6d 65 20    The only time 
68e0: 77 65 0a 62 72 69 6e 67 20 69 74 20 75 70 20 69  we.bring it up i
68f0: 6e 20 74 68 69 73 20 6d 61 6e 75 61 6c 20 69 73  n this manual is
6900: 20 77 68 65 6e 20 74 68 65 72 65 20 69 73 20 65   when there is e
6910: 69 74 68 65 72 20 61 20 6d 69 73 6d 61 74 63 68  ither a mismatch
6920: 20 62 65 74 77 65 65 6e 0a 65 78 70 65 63 74 65   between.expecte
6930: 64 20 43 20 62 65 68 61 76 69 6f 72 20 61 6e 64  d C behavior and
6940: 20 61 63 74 75 61 6c 20 46 4f 52 54 52 41 4e 20   actual FORTRAN 
6950: 49 49 20 62 65 68 61 76 69 6f 72 20 6f 72 20 62  II behavior or b
6960: 65 74 77 65 65 6e 20 74 68 65 20 77 61 79 0a 4f  etween the way.O
6970: 53 2f 38 20 46 4f 52 54 52 41 4e 20 49 49 20 69  S/8 FORTRAN II i
6980: 73 20 64 6f 63 75 6d 65 6e 74 65 64 20 61 6e 64  s documented and
6990: 20 74 68 65 20 77 61 79 20 74 68 69 6e 67 73 20   the way things 
69a0: 61 63 74 75 61 6c 6c 79 20 77 6f 72 6b 20 77 68  actually work wh
69b0: 65 6e 20 69 74 e2 80 99 73 0a 62 65 69 6e 67 20  en it’s.being 
69c0: 64 72 69 76 65 6e 20 62 79 20 43 43 38 2e 0a 0a  driven by CC8...
69d0: 54 68 69 73 20 75 6e 64 65 72 6c 79 69 6e 67 20  This underlying 
69e0: 62 61 73 65 20 68 61 73 20 61 6e 20 69 6d 70 6f  base has an impo
69f0: 72 74 61 6e 74 20 69 6d 70 6c 69 63 61 74 69 6f  rtant implicatio
6a00: 6e 3a 20 70 72 6f 67 72 61 6d 73 20 62 75 69 6c  n: programs buil
6a10: 74 20 77 69 74 68 0a 43 43 38 20 77 68 69 63 68  t with.CC8 which
6a20: 20 75 73 65 20 69 74 73 20 66 69 6c 65 20 49 2f   use its file I/
6a30: 4f 20 66 75 6e 63 74 69 6f 6e 73 20 61 72 65 20  O functions are 
6a40: 64 65 70 65 6e 64 65 6e 74 20 75 70 6f 6e 20 4f  dependent upon O
6a50: 53 2f 38 2e 20 20 54 68 61 74 0a 75 6e 64 65 72  S/8.  That.under
6a60: 6c 79 69 6e 67 20 62 61 73 65 20 64 65 74 65 72  lying base deter
6a70: 6d 69 6e 65 73 20 68 6f 77 20 66 69 6c 65 20 6e  mines how file n
6a80: 61 6d 65 73 20 61 72 65 20 69 6e 74 65 72 70 72  ames are interpr
6a90: 65 74 65 64 2c 20 77 68 61 74 20 64 65 76 69 63  eted, what devic
6aa0: 65 73 0a 67 65 74 20 75 73 65 64 2c 20 65 74 63  es.get used, etc
6ab0: 2e 0a 0a 42 65 63 61 75 73 65 20 6f 66 20 74 68  ...Because of th
6ac0: 69 73 20 73 69 6e 67 6c 65 2d 66 69 6c 65 20 6c  is single-file l
6ad0: 69 6d 69 74 61 74 69 6f 6e 2c 20 74 68 65 20 73  imitation, the s
6ae0: 74 64 69 6f 20 66 75 6e 63 74 69 6f 6e 73 20 6f  tdio functions o
6af0: 70 65 72 61 74 69 6e 67 20 6f 6e 0a 66 69 6c 65  perating on.file
6b00: 73 20 64 6f 20 6e 6f 74 20 74 61 6b 65 20 61 20  s do not take a 
6b10: 60 46 49 4c 45 2a 60 20 61 72 67 75 6d 65 6e 74  `FILE*` argument
6b20: 20 61 73 20 69 6e 20 53 74 61 6e 64 61 72 64 20   as in Standard 
6b30: 43 2c 20 74 68 65 72 65 20 62 65 69 6e 67 20 6e  C, there being n
6b40: 6f 0a 6e 65 65 64 20 74 6f 20 73 70 65 63 69 66  o.need to specif
6b50: 79 20 77 68 69 63 68 20 66 69 6c 65 20 69 73 20  y which file is 
6b60: 6d 65 61 6e 74 2e 20 4f 75 74 70 75 74 20 66 75  meant. Output fu
6b70: 6e 63 74 69 6f 6e 73 20 75 73 65 20 74 68 65 20  nctions use the 
6b80: 6f 6e 65 20 61 6e 64 0a 6f 6e 6c 79 20 6f 75 74  one and.only out
6b90: 70 75 74 20 66 69 6c 65 2c 20 61 6e 64 20 69 6e  put file, and in
6ba0: 70 75 74 20 66 75 6e 63 74 69 6f 6e 73 20 75 73  put functions us
6bb0: 65 20 74 68 65 20 6f 6e 65 20 61 6e 64 20 6f 6e  e the one and on
6bc0: 6c 79 20 69 6e 70 75 74 20 66 69 6c 65 2e 0a 4f  ly input file..O
6bd0: 75 72 20 5b 60 66 6f 70 65 6e 28 29 60 5d 28 23  ur [`fopen()`](#
6be0: 66 6f 70 65 6e 29 20 64 6f 65 73 6e e2 80 99 74  fopen) doesn’t
6bf0: 20 72 65 74 75 72 6e 20 61 20 60 46 49 4c 45 2a   return a `FILE*
6c00: 60 20 62 65 63 61 75 73 65 20 74 68 65 20 63 61  ` because the ca
6c10: 6c 6c 65 72 0a 64 6f 65 73 6e e2 80 99 74 20 6e  ller.doesn’t n
6c20: 65 65 64 20 6f 6e 65 20 74 6f 20 70 61 73 73 20  eed one to pass 
6c30: 74 6f 20 61 6e 79 20 6f 66 20 74 68 65 20 6f 74  to any of the ot
6c40: 68 65 72 20 66 75 6e 63 74 69 6f 6e 73 2e 20 54  her functions. T
6c50: 68 61 74 20 6c 65 61 76 65 73 20 6f 6e 6c 79 0a  hat leaves only.
6c60: 5b 60 66 63 6c 6f 73 65 28 29 60 5d 28 23 66 63  [`fclose()`](#fc
6c70: 6c 6f 73 65 29 2c 20 77 68 69 63 68 20 77 6f 75  lose), which wou
6c80: 6c 64 20 62 65 20 61 6e 20 61 6d 62 69 67 75 6f  ld be an ambiguo
6c90: 75 73 20 63 61 6c 6c 20 77 69 74 68 6f 75 74 20  us call without 
6ca0: 61 0a 60 46 49 4c 45 2a 60 20 61 72 67 75 6d 65  a.`FILE*` argume
6cb0: 6e 74 20 69 66 20 69 74 20 77 61 73 6e e2 80 99  nt if it wasn’
6cc0: 74 20 66 6f 72 20 74 68 65 20 66 61 63 74 20 74  t for the fact t
6cd0: 68 61 74 20 4f 53 2f 38 20 46 4f 52 54 52 41 4e  hat OS/8 FORTRAN
6ce0: 20 49 49 20 64 6f 65 73 6e e2 80 99 74 0a 68 61   II doesn’t.ha
6cf0: 76 65 20 61 6e 20 60 49 43 4c 4f 53 45 60 20 6c  ve an `ICLOSE` l
6d00: 69 62 72 61 72 79 20 66 75 6e 63 74 69 6f 6e 2c  ibrary function,
6d10: 20 74 68 65 72 65 20 61 70 70 61 72 65 6e 74 6c   there apparentl
6d20: 79 20 62 65 69 6e 67 20 6e 6f 20 72 65 73 6f 75  y being no resou
6d30: 72 63 65 73 0a 74 6f 20 66 72 65 65 20 6f 6e 20  rces.to free on 
6d40: 63 6c 6f 73 69 6e 67 20 61 6e 20 69 6e 70 75 74  closing an input
6d50: 20 66 69 6c 65 2e 0a 0a 41 6c 6c 20 6f 66 20 74   file...All of t
6d60: 68 69 73 20 6d 65 61 6e 73 20 74 68 61 74 20 74  his means that t
6d70: 6f 20 6f 70 65 6e 20 6d 75 6c 74 69 70 6c 65 20  o open multiple 
6d80: 6f 75 74 70 75 74 20 66 69 6c 65 73 2c 20 79 6f  output files, yo
6d90: 75 20 68 61 76 65 20 74 6f 0a 60 66 63 6c 6f 73  u have to.`fclos
6da0: 65 60 20 65 61 63 68 20 66 69 6c 65 20 62 65 66  e` each file bef
6db0: 6f 72 65 20 63 61 6c 6c 69 6e 67 20 5b 60 66 6f  ore calling [`fo
6dc0: 70 65 6e 28 22 46 49 4c 45 4e 41 2e 4d 45 22 2c  pen("FILENA.ME",
6dd0: 20 22 77 22 29 60 5d 28 23 66 6f 70 65 6e 29 20   "w")`](#fopen) 
6de0: 74 6f 0a 6f 70 65 6e 20 74 68 65 20 6e 65 78 74  to.open the next
6df0: 2e 20 20 54 6f 20 6f 70 65 6e 20 6d 75 6c 74 69  .  To open multi
6e00: 70 6c 65 20 69 6e 70 75 74 20 66 69 6c 65 73 2c  ple input files,
6e10: 20 73 69 6d 70 6c 79 20 63 61 6c 6c 20 60 66 6f   simply call `fo
6e20: 70 65 6e 28 29 60 20 74 6f 0a 6f 70 65 6e 20 65  pen()` to.open e
6e30: 61 63 68 20 73 75 62 73 65 71 75 65 6e 74 20 66  ach subsequent f
6e40: 69 6c 65 2c 20 69 6d 70 6c 69 63 69 74 6c 79 20  ile, implicitly 
6e50: 63 6c 6f 73 69 6e 67 20 74 68 65 20 70 72 69 6f  closing the prio
6e60: 72 20 69 6e 70 75 74 20 66 69 6c 65 2e 0a 0a 0a  r input file....
6e70: 23 23 23 20 3c 61 20 69 64 3d 22 63 72 6c 66 22  ### <a id="crlf"
6e80: 3e 3c 2f 61 3e 43 52 2b 4c 46 20 48 61 6e 64 6c  ></a>CR+LF Handl
6e90: 69 6e 67 0a 0a 42 65 63 61 75 73 65 20 74 68 65  ing..Because the
6ea0: 20 50 44 50 2d 38 20 73 74 61 72 74 65 64 20 6c   PDP-8 started l
6eb0: 69 66 65 20 69 6e 20 61 20 77 6f 72 6c 64 20 77  ife in a world w
6ec0: 68 65 72 65 20 e2 80 9c 74 65 72 6d 69 6e 61 6c  here “terminal
6ed0: e2 80 9d 20 77 61 73 0a 73 79 6e 6f 6e 79 6d 6f  ” was.synonymo
6ee0: 75 73 20 77 69 74 68 20 e2 80 9c 54 65 6c 65 74  us with “Telet
6ef0: 79 70 65 2c e2 80 9d 20 4f 53 2f 38 20 75 73 65  ype,” OS/8 use
6f00: 73 20 43 52 2b 4c 46 20 6c 69 6e 65 20 65 6e 64  s CR+LF line end
6f10: 69 6e 67 73 2c 20 61 6e 64 20 69 74 73 0a 46 4f  ings, and its.FO
6f20: 52 54 52 41 4e 20 49 49 20 69 6d 70 6c 65 6d 65  RTRAN II impleme
6f30: 6e 74 61 74 69 6f 6e 20 64 6f 65 73 20 6e 6f 74  ntation does not
6f40: 20 74 72 61 6e 73 6c 61 74 65 20 62 61 72 65 20   translate bare 
6f50: 4c 46 20 74 6f 20 43 52 2b 4c 46 20 6f 6e 20 6f  LF to CR+LF on o
6f60: 75 74 70 75 74 2e 0a 54 68 69 73 20 6d 65 61 6e  utput..This mean
6f70: 73 20 74 68 61 74 20 69 6e 20 6f 72 64 65 72 20  s that in order 
6f80: 74 6f 20 70 72 6f 70 65 72 6c 79 20 77 72 69 74  to properly writ
6f90: 65 20 74 65 78 74 20 66 69 6c 65 73 2c 20 79 6f  e text files, yo
6fa0: 75 20 6d 75 73 74 20 75 73 65 20 61 6e 0a 65 78  u must use an.ex
6fb0: 70 6c 69 63 69 74 20 e2 80 9c 60 5c 72 5c 6e 60  plicit “`\r\n`
6fc0: e2 80 9d 20 73 65 71 75 65 6e 63 65 20 69 6e 20  ” sequence in 
6fd0: 70 72 6f 67 72 61 6d 73 20 63 6f 6d 70 69 6c 65  programs compile
6fe0: 64 20 77 69 74 68 20 43 43 38 2e 0a 0a 57 65 e2  d with CC8...We
6ff0: 80 99 76 65 20 74 72 69 65 64 20 66 69 78 69 6e  ve tried fixin
7000: 67 20 69 74 2c 20 61 6e 64 20 69 74 e2 80 99 73  g it, and it’s
7010: 20 6d 65 73 73 79 20 74 6f 20 64 6f 20 61 20 63   messy to do a c
7020: 6f 6d 70 6c 65 74 65 20 6a 6f 62 20 6f 66 20 69  omplete job of i
7030: 74 20 67 69 76 65 6e 0a 74 68 65 20 63 6f 6e 73  t given.the cons
7040: 74 72 61 69 6e 74 73 20 69 6e 76 6f 6c 76 65 64  traints involved
7050: 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 63  ....### <a id="c
7060: 74 72 6c 63 22 3e 3c 2f 61 3e 43 74 72 6c 2d 43  trlc"></a>Ctrl-C
7070: 20 48 61 6e 64 6c 69 6e 67 0a 0a 55 6e 6c 69 6b   Handling..Unlik
7080: 65 20 6f 6e 20 6d 6f 64 65 72 6e 20 6f 70 65 72  e on modern oper
7090: 61 74 69 6e 67 20 73 79 73 74 65 6d 73 2c 20 74  ating systems, t
70a0: 68 65 72 65 20 69 73 20 6e 6f 74 68 69 6e 67 20  here is nothing 
70b0: 6c 69 6b 65 20 60 53 49 47 49 4e 54 60 20 69 6e  like `SIGINT` in
70c0: 0a 4f 53 2f 38 2c 20 77 68 69 63 68 20 6d 65 61  .OS/8, which mea
70d0: 6e 73 20 43 74 72 6c 2d 43 20 6f 6e 6c 79 20 6b  ns Ctrl-C only k
70e0: 69 6c 6c 73 20 70 72 6f 67 72 61 6d 73 20 74 68  ills programs th
70f0: 61 74 20 65 78 70 6c 69 63 69 74 6c 79 20 63 68  at explicitly ch
7100: 65 63 6b 20 66 6f 72 0a 69 74 2e 20 20 54 68 65  eck for.it.  The
7110: 20 6b 65 79 62 6f 61 72 64 20 69 6e 70 75 74 20   keyboard input 
7120: 6c 6f 6f 70 20 69 6e 20 74 68 65 20 43 43 38 20  loop in the CC8 
7130: 4c 49 42 43 20 73 74 61 6e 64 61 72 64 20 6c 69  LIBC standard li
7140: 62 72 61 72 79 20 64 6f 65 73 20 64 6f 0a 74 68  brary does do.th
7150: 69 73 2e 0a 0a 54 68 65 20 74 68 69 6e 67 20 74  is...The thing t
7160: 6f 20 62 65 20 61 77 61 72 65 20 6f 66 20 69 73  o be aware of is
7170: 2c 20 74 68 69 73 20 77 6f 6e e2 80 99 74 20 68  , this won’t h
7180: 61 70 70 65 6e 20 77 68 69 6c 65 20 61 20 70 72  appen while a pr
7190: 6f 67 72 61 6d 20 69 73 20 73 74 75 63 6b 0a 69  ogram is stuck.i
71a0: 6e 20 61 6e 20 69 6e 66 69 6e 69 74 65 20 6c 6f  n an infinite lo
71b0: 6f 70 20 6f 72 20 73 69 6d 69 6c 61 72 2e 20 54  op or similar. T
71c0: 68 65 20 6f 6e 6c 79 20 77 61 79 20 74 6f 20 67  he only way to g
71d0: 65 74 20 6f 75 74 20 6f 66 20 73 75 63 68 20 61  et out of such a
71e0: 0a 70 72 6f 67 72 61 6d 20 69 73 20 74 6f 20 65  .program is to e
71f0: 69 74 68 65 72 20 72 65 73 74 61 72 74 20 4f 53  ither restart OS
7200: 2f 38 20 e2 80 94 20 61 73 73 75 6d 69 6e 67 20  /8 — assuming 
7210: 74 68 65 20 62 72 6f 6b 65 6e 20 70 72 6f 67 72  the broken progr
7220: 61 6d 20 68 61 73 6e e2 80 99 74 0a 63 6f 72 72  am hasn’t.corr
7230: 75 70 74 65 64 20 74 68 65 20 4f 53 e2 80 99 73  upted the OS’s
7240: 20 72 65 73 69 64 65 6e 74 20 70 61 72 74 73 20   resident parts 
7250: e2 80 94 20 6f 72 20 72 65 73 74 61 72 74 20 74  — or restart t
7260: 68 65 20 50 44 50 2d 38 2e 0a 0a 28 59 6f 75 20  he PDP-8...(You 
7270: 63 61 6e 20 72 65 73 74 61 72 74 20 4f 53 2f 38  can restart OS/8
7280: 20 62 79 20 63 61 75 73 69 6e 67 20 61 20 6a 75   by causing a ju
7290: 6d 70 20 74 6f 20 63 6f 72 65 20 6d 65 6d 6f 72  mp to core memor
72a0: 79 20 6c 6f 63 61 74 69 6f 6e 20 30 37 36 30 30  y location 07600
72b0: 2e 0a 57 69 74 68 69 6e 20 74 68 65 20 60 70 69  ..Within the `pi
72c0: 64 70 38 69 60 20 65 6e 76 69 72 6f 6e 6d 65 6e  dp8i` environmen
72d0: 74 2c 20 79 6f 75 20 63 61 6e 20 68 69 74 20 43  t, you can hit C
72e0: 74 72 6c 2d 45 2c 20 74 68 65 6e 20 73 61 79 20  trl-E, then say 
72f0: e2 80 9c 60 67 6f 0a 37 36 30 30 60 e2 80 9d 2e  “`go.7600`”.
7300: 20 20 46 72 6f 6d 20 74 68 65 20 66 72 6f 6e 74    From the front
7310: 20 70 61 6e 65 6c 2c 20 70 72 65 73 73 20 74 68   panel, press th
7320: 65 20 53 74 6f 70 20 6b 65 79 2c 20 74 6f 67 67  e Stop key, togg
7330: 6c 65 20 37 36 30 30 20 69 6e 74 6f 20 74 68 65  le 7600 into the
7340: 0a 73 77 69 74 63 68 20 72 65 67 69 73 74 65 72  .switch register
7350: 2c 20 70 72 65 73 73 20 74 68 65 20 4c 6f 61 64  , press the Load
7360: 20 41 64 64 20 6b 65 79 2c 20 74 68 65 6e 20 70   Add key, then p
7370: 72 65 73 73 20 74 68 65 20 53 74 61 72 74 20 6b  ress the Start k
7380: 65 79 2e 29 0a 0a 0a 23 23 23 20 3c 61 20 69 64  ey.)...### <a id
7390: 3d 22 6d 69 73 73 69 6e 67 22 3e 3c 2f 61 3e 4d  ="missing"></a>M
73a0: 69 73 73 69 6e 67 20 46 75 6e 63 74 69 6f 6e 73  issing Functions
73b0: 0a 0a 54 68 65 20 62 75 6c 6b 20 6f 66 20 74 68  ..The bulk of th
73c0: 65 20 53 74 61 6e 64 61 72 64 20 43 20 4c 69 62  e Standard C Lib
73d0: 72 61 72 79 20 69 73 20 6e 6f 74 20 70 72 6f 76  rary is not prov
73e0: 69 64 65 64 2c 20 69 6e 63 6c 75 64 69 6e 67 20  ided, including 
73f0: 73 6f 6d 65 0a 66 75 6e 63 74 69 6f 6e 73 20 79  some.functions y
7400: 6f 75 e2 80 99 64 20 74 68 69 6e 6b 20 77 6f 75  ou’d think wou
7410: 6c 64 20 67 6f 20 61 6c 6f 6e 67 20 6e 69 63 65  ld go along nice
7420: 6c 79 20 77 69 74 68 20 74 68 6f 73 65 20 77 65  ly with those we
7430: 20 64 6f 20 70 72 6f 76 69 64 65 2c 0a 73 75 63   do provide,.suc
7440: 68 20 61 73 20 60 66 65 6f 66 28 29 60 20 6f 72  h as `feof()` or
7450: 20 60 66 73 65 65 6b 28 29 60 2e 20 20 4b 65 65   `fseek()`.  Kee
7460: 70 20 69 6e 20 6d 69 6e 64 20 74 68 61 74 20 74  p in mind that t
7470: 68 65 20 6c 69 62 72 61 72 79 20 69 73 0a 63 75  he library is.cu
7480: 72 72 65 6e 74 6c 79 20 72 65 73 74 72 69 63 74  rrently restrict
7490: 65 64 20 74 6f 20 5b 61 20 73 69 6e 67 6c 65 20  ed to [a single 
74a0: 34 26 6e 62 73 70 3b 6b 57 6f 72 64 20 66 69 65  4&nbsp;kWord fie
74b0: 6c 64 5d 28 23 6d 65 6d 6f 72 79 29 2c 20 61 6e  ld](#memory), an
74c0: 64 20 77 65 0a 64 6f 6e e2 80 99 74 20 77 61 6e  d we.don’t wan
74d0: 74 20 74 6f 20 6c 69 66 74 20 74 68 61 74 20 72  t to lift that r
74e0: 65 73 74 72 69 63 74 69 6f 6e 2e 20 53 69 6e 63  estriction. Sinc
74f0: 65 20 74 68 65 20 63 75 72 72 65 6e 74 20 69 6d  e the current im
7500: 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 0a 6e 65 61  plementation.nea
7510: 72 6c 79 20 66 69 6c 6c 73 20 74 68 61 74 20 73  rly fills that s
7520: 70 61 63 65 2c 20 69 74 20 69 73 20 75 6e 6c 69  pace, it is unli
7530: 6b 65 6c 79 20 74 68 61 74 20 77 65 e2 80 99 6c  kely that we’l
7540: 6c 20 61 64 64 20 6d 75 63 68 20 6d 6f 72 65 0a  l add much more.
7550: 66 75 6e 63 74 69 6f 6e 61 6c 69 74 79 20 62 65  functionality be
7560: 79 6f 6e 64 20 74 68 65 20 63 75 72 72 65 6e 74  yond the current
7570: 6c 79 20 70 72 6f 76 69 64 65 64 20 33 33 20 4c  ly provided 33 L
7580: 49 42 43 20 66 75 6e 63 74 69 6f 6e 73 20 70 6c  IBC functions pl
7590: 75 73 20 5b 74 68 65 0a 39 20 61 64 64 69 74 69  us [the.9 additi
75a0: 6f 6e 61 6c 20 66 75 6e 63 74 69 6f 6e 73 5d 28  onal functions](
75b0: 23 61 64 64 66 6e 29 2e 20 49 66 20 77 65 20 65  #addfn). If we e
75c0: 76 65 72 20 66 69 78 20 61 6e 79 20 6f 66 20 74  ver fix any of t
75d0: 68 65 20 6c 69 6d 69 74 61 74 69 6f 6e 73 0a 77  he limitations.w
75e0: 65 e2 80 99 76 65 20 69 64 65 6e 74 69 66 69 65  e’ve identifie
75f0: 64 20 62 65 6c 6f 77 2c 20 63 6f 6e 73 69 64 65  d below, conside
7600: 72 20 69 74 20 e2 80 9c 67 72 61 76 79 e2 80 9d  r it “gravy”
7610: 20 72 61 74 68 65 72 20 74 68 61 6e 20 61 6e 79   rather than any
7620: 20 6b 69 6e 64 20 6f 66 0a 6f 62 6c 69 67 61 74   kind of.obligat
7630: 69 6f 6e 20 66 75 6c 66 69 6c 6c 65 64 2e 0a 0a  ion fulfilled...
7640: 53 6f 6d 65 20 6f 66 20 74 68 65 73 65 20 6d 69  Some of these mi
7650: 73 73 69 6e 67 20 66 75 6e 63 74 69 6f 6e 73 20  ssing functions 
7660: 61 72 65 20 6c 65 73 73 20 75 73 65 66 75 6c 20  are less useful 
7670: 69 6e 20 74 68 65 20 43 43 38 20 77 6f 72 6c 64  in the CC8 world
7680: 20 74 68 61 6e 20 69 6e 0a 6d 6f 72 65 20 6d 6f   than in.more mo
7690: 64 65 72 6e 20 43 20 65 6e 76 69 72 6f 6e 6d 65  dern C environme
76a0: 6e 74 73 2e 20 54 68 65 20 6c 6f 77 2d 6d 65 6d  nts. The low-mem
76b0: 6f 72 79 20 6e 61 74 75 72 65 20 6f 66 20 74 68  ory nature of th
76c0: 69 73 20 77 6f 72 6c 64 0a 65 6e 63 6f 75 72 61  is world.encoura
76d0: 67 65 73 20 77 72 69 74 69 6e 67 20 6c 6f 6f 70  ges writing loop
76e0: 73 20 6f 76 65 72 20 5b 77 6f 72 64 20 73 74 72  s over [word str
76f0: 69 6e 67 73 5d 28 23 77 6f 72 64 73 74 72 29 20  ings](#wordstr) 
7700: 69 6e 20 74 65 72 6d 73 20 6f 66 0a 70 6f 69 6e  in terms of.poin
7710: 74 65 72 20 61 72 69 74 68 6d 65 74 69 63 20 61  ter arithmetic a
7720: 6e 64 20 69 6d 70 6c 69 63 69 74 20 7a 65 72 6f  nd implicit zero
7730: 20 74 65 73 74 69 6e 67 20 28 65 2e 67 2e 20 60   testing (e.g. `
7740: 77 68 69 6c 65 20 28 2a 70 2b 2b 29 20 7b 20 2f  while (*p++) { /
7750: 2a 0a 75 73 65 20 70 20 2a 2f 20 7d 60 29 20 72  *.use p */ }`) r
7760: 61 74 68 65 72 20 74 68 61 6e 20 6d 61 6b 65 20  ather than make 
7770: 65 78 70 65 6e 73 69 76 65 20 63 61 6c 6c 73 20  expensive calls 
7780: 74 6f 20 60 73 74 72 6c 65 6e 28 29 60 2c 20 73  to `strlen()`, s
7790: 6f 20 74 68 61 74 0a 66 75 6e 63 74 69 6f 6e 20  o that.function 
77a0: 69 73 6e e2 80 99 74 20 70 72 6f 76 69 64 65 64  isn’t provided
77b0: 2e 0a 0a 44 6f 20 6e 6f 74 20 62 72 69 6e 67 20  ...Do not bring 
77c0: 79 6f 75 72 20 6d 6f 64 65 72 6e 20 43 20 65 6e  your modern C en
77d0: 76 69 72 6f 6e 6d 65 6e 74 20 65 78 70 65 63 74  vironment expect
77e0: 61 74 69 6f 6e 73 20 74 6f 20 43 43 38 21 0a 0a  ations to CC8!..
77f0: 0a 23 23 20 3c 61 20 69 64 3d 22 6c 69 62 72 65  .## <a id="libre
7800: 66 22 3e 3c 2f 61 3e 54 68 65 20 43 43 38 20 43  f"></a>The CC8 C
7810: 20 4c 69 62 72 61 72 79 3a 20 52 65 66 65 72 65   Library: Refere
7820: 6e 63 65 0a 0a 43 43 38 20 6f 66 66 65 72 73 20  nce..CC8 offers 
7830: 61 20 76 65 72 79 20 6c 69 6d 69 74 65 64 20 73  a very limited s
7840: 74 61 6e 64 61 72 64 20 6c 69 62 72 61 72 79 2c  tandard library,
7850: 20 77 68 69 63 68 20 69 73 20 73 68 61 72 65 64   which is shared
7860: 20 62 65 74 77 65 65 6e 20 74 68 65 0a 6e 61 74   between the.nat
7870: 69 76 65 20 61 6e 64 20 63 72 6f 73 73 2d 63 6f  ive and cross-co
7880: 6d 70 69 6c 65 72 73 2e 20 57 68 69 6c 65 20 73  mpilers. While s
7890: 6f 6d 65 20 6f 66 20 69 74 73 20 66 75 6e 63 74  ome of its funct
78a0: 69 6f 6e 20 6e 61 6d 65 73 20 61 72 65 20 74 68  ion names are th
78b0: 65 0a 73 61 6d 65 20 61 73 20 66 75 6e 63 74 69  e.same as functi
78c0: 6f 6e 73 20 64 65 66 69 6e 65 64 20 62 79 20 53  ons defined by S
78d0: 74 61 6e 64 61 72 64 20 43 2c 20 74 68 65 73 65  tandard C, these
78e0: 20 66 75 6e 63 74 69 6f 6e 73 20 67 65 6e 65 72   functions gener
78f0: 61 6c 6c 79 20 64 6f 0a 6e 6f 74 20 63 6f 6e 66  ally do.not conf
7900: 6f 72 6d 20 63 6f 6d 70 6c 65 74 65 6c 79 20 74  orm completely t
7910: 6f 20 61 6e 79 20 67 69 76 65 6e 20 73 74 61 6e  o any given stan
7920: 64 61 72 64 20 64 75 65 20 74 6f 20 74 68 65 20  dard due to the 
7930: 73 65 76 65 72 65 20 72 65 73 6f 75 72 63 65 0a  severe resource.
7940: 63 6f 6e 73 74 72 61 69 6e 74 73 20 69 6d 70 6f  constraints impo
7950: 73 65 64 20 62 79 20 74 68 65 20 50 44 50 2d 38  sed by the PDP-8
7960: 20 61 72 63 68 69 74 65 63 74 75 72 65 2e 20 54   architecture. T
7970: 68 69 73 20 73 65 63 74 69 6f 6e 20 6f 66 20 74  his section of t
7980: 68 65 0a 6d 61 6e 75 61 6c 20 64 6f 63 75 6d 65  he.manual docume
7990: 6e 74 73 20 74 68 65 20 6b 6e 6f 77 6e 20 6c 69  nts the known li
79a0: 6d 69 74 61 74 69 6f 6e 73 20 6f 66 20 74 68 65  mitations of the
79b0: 73 65 20 66 75 6e 63 74 69 6f 6e 73 20 72 65 6c  se functions rel
79c0: 61 74 69 76 65 20 74 6f 0a 5b 74 68 65 20 63 75  ative to.[the cu
79d0: 72 72 65 6e 74 20 43 20 73 74 61 6e 64 61 72 64  rrent C standard
79e0: 20 61 73 20 69 6e 74 65 72 70 72 65 74 65 64 20   as interpreted 
79f0: 62 79 20 60 63 70 70 72 65 66 65 72 65 6e 63 65  by `cppreference
7a00: 2e 63 6f 6d 60 5d 5b 63 70 70 72 5d 2c 20 62 75  .com`][cppr], bu
7a10: 74 0a 69 74 20 69 73 20 6c 69 6b 65 6c 79 20 74  t.it is likely t
7a20: 68 61 74 20 77 65 20 68 61 76 65 20 6f 76 65 72  hat we have over
7a30: 6c 6f 6f 6b 65 64 20 63 6f 72 6e 65 72 20 63 61  looked corner ca
7a40: 73 65 73 20 74 68 61 74 20 6f 75 72 20 6c 69 62  ses that our lib
7a50: 72 61 72 79 20 64 6f 65 73 0a 6e 6f 74 20 79 65  rary does.not ye
7a60: 74 20 69 6d 70 6c 65 6d 65 6e 74 2e 20 20 57 68  t implement.  Wh
7a70: 65 6e 20 69 6e 20 64 6f 75 62 74 2c 20 5b 72 65  en in doubt, [re
7a80: 61 64 20 74 68 65 20 73 6f 75 72 63 65 5d 5b 6c  ad the source][l
7a90: 69 62 63 73 72 63 5d 2e 0a 0a 5b 54 68 65 20 4c  ibcsrc]...[The L
7aa0: 49 42 43 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69  IBC implementati
7ab0: 6f 6e 5d 5b 6c 69 62 63 73 72 63 5d 20 69 73 20  on][libcsrc] is 
7ac0: 63 75 72 72 65 6e 74 6c 79 20 73 74 6f 72 65 64  currently stored
7ad0: 20 69 6e 20 74 68 65 20 73 61 6d 65 0a 73 6f 75   in the same.sou
7ae0: 72 63 65 20 74 72 65 65 20 64 69 72 65 63 74 6f  rce tree directo
7af0: 72 79 20 61 73 20 74 68 65 20 6e 61 74 69 76 65  ry as the native
7b00: 20 63 6f 6d 70 69 6c 65 72 2c 20 65 76 65 6e 20   compiler, even 
7b10: 74 68 6f 75 67 68 20 69 74 e2 80 99 73 20 73 68  though it’s sh
7b20: 61 72 65 64 0a 62 65 74 77 65 65 6e 20 74 68 65  ared.between the
7b30: 20 74 77 6f 20 63 6f 6d 70 69 6c 65 72 73 2e 20   two compilers. 
7b40: 54 68 69 73 20 69 73 20 62 65 63 61 75 73 65 20  This is because 
7b50: 74 68 65 20 74 77 6f 20 63 6f 6d 70 69 6c 65 72  the two compiler
7b60: 73 20 64 69 66 66 65 72 20 6f 6e 6c 79 0a 66 72  s differ only.fr
7b70: 6f 6d 20 74 68 65 20 63 6f 64 65 20 67 65 6e 65  om the code gene
7b80: 72 61 74 69 6f 6e 20 6c 61 79 65 72 20 75 70 3a  ration layer up:
7b90: 20 69 66 20 79 6f 75 20 63 72 6f 73 73 2d 63 6f   if you cross-co
7ba0: 6d 70 69 6c 65 20 61 20 43 20 70 72 6f 67 72 61  mpile a C progra
7bb0: 6d 20 77 69 74 68 0a 60 62 69 6e 2f 63 63 38 60  m with.`bin/cc8`
7bc0: 2c 20 79 6f 75 20 6d 75 73 74 20 73 74 69 6c 6c  , you must still
7bd0: 20 2a 61 73 73 65 6d 62 6c 65 20 61 6e 64 20 6c   *assemble and l
7be0: 69 6e 6b 2a 20 69 74 20 75 6e 64 65 72 20 4f 53  ink* it under OS
7bf0: 2f 38 2c 20 77 68 69 63 68 20 6d 65 61 6e 73 0a  /8, which means.
7c00: 75 73 69 6e 67 20 74 68 65 20 60 4c 49 42 43 2e  using the `LIBC.
7c10: 52 4c 60 20 62 69 6e 61 72 79 20 70 72 6f 64 75  RL` binary produ
7c20: 63 65 64 20 66 6f 72 20 75 73 65 20 62 79 20 74  ced for use by t
7c30: 68 65 20 6e 61 74 69 76 65 20 63 6f 6d 70 69 6c  he native compil
7c40: 65 72 2e 0a 0a 43 6f 6e 74 72 61 73 74 20 5b 74  er...Contrast [t
7c50: 68 65 20 60 6c 69 62 63 2e 68 60 20 66 69 6c 65  he `libc.h` file
7c60: 5d 5b 6c 69 62 63 68 5d 20 77 68 69 63 68 20 69  ][libch] which i
7c70: 73 20 73 79 6d 6c 69 6e 6b 65 64 20 6f 72 20 63  s symlinked or c
7c80: 6f 70 69 65 64 0a 65 76 65 72 79 77 68 65 72 65  opied.everywhere
7c90: 20 69 74 20 6e 65 65 64 73 20 74 6f 20 62 65 2e   it needs to be.
7ca0: 20 54 68 69 73 20 69 73 20 62 65 63 61 75 73 65   This is because
7cb0: 20 6e 65 69 74 68 65 72 20 76 65 72 73 69 6f 6e   neither version
7cc0: 20 6f 66 20 43 43 38 20 68 61 73 0a 74 68 65 20   of CC8 has.the 
7cd0: 6e 6f 74 69 6f 6e 20 6f 66 20 61 6e 20 69 6e 63  notion of an inc
7ce0: 6c 75 64 65 20 70 61 74 68 2e 20 54 68 69 73 20  lude path. This 
7cf0: 66 69 6c 65 20 6d 75 73 74 20 74 68 65 72 65 66  file must theref
7d00: 6f 72 65 20 62 65 20 61 76 61 69 6c 61 62 6c 65  ore be available
7d10: 20 69 6e 0a 74 68 65 20 73 61 6d 65 20 64 69 72   in.the same dir
7d20: 65 63 74 6f 72 79 20 61 73 20 65 61 63 68 20 43  ectory as each C
7d30: 20 66 69 6c 65 20 74 68 61 74 20 75 73 65 73 20   file that uses 
7d40: 69 74 2e 0a 0a 49 6e 20 74 68 65 20 66 6f 6c 6c  it...In the foll
7d50: 6f 77 69 6e 67 20 74 65 78 74 2c 20 77 65 20 75  owing text, we u
7d60: 73 65 20 4f 53 2f 38 20 64 65 76 69 63 65 20 6e  se OS/8 device n
7d70: 61 6d 65 73 20 61 73 20 61 20 68 61 6e 64 77 61  ames as a handwa
7d80: 76 79 20 6b 69 6e 64 20 6f 66 0a 73 68 6f 72 74  vy kind of.short
7d90: 68 61 6e 64 2c 20 65 76 65 6e 20 77 68 65 6e 20  hand, even when 
7da0: 74 68 65 20 63 6f 64 65 20 77 6f 75 6c 64 20 6f  the code would o
7db0: 74 68 65 72 77 69 73 65 20 72 75 6e 20 6f 6e 20  therwise run on 
7dc0: 61 6e 79 20 50 44 50 2d 38 20 69 6e 0a 61 62 73  any PDP-8 in.abs
7dd0: 65 6e 63 65 20 6f 66 20 4f 53 2f 38 2e 20 57 68  ence of OS/8. Wh
7de0: 65 72 65 20 77 65 20 75 73 65 20 e2 80 9c 60 54  ere we use “`T
7df0: 54 59 3a 60 e2 80 9d 2c 20 66 6f 72 20 65 78 61  TY:`”, for exa
7e00: 6d 70 6c 65 2c 20 77 65 e2 80 99 64 20 62 65 20  mple, we’d be 
7e10: 6d 6f 72 65 0a 70 72 65 63 69 73 65 20 74 6f 20  more.precise to 
7e20: 73 61 79 20 69 6e 73 74 65 61 64 20 e2 80 9c 74  say instead “t
7e30: 68 65 20 63 6f 6e 73 6f 6c 65 20 74 65 6c 65 70  he console telep
7e40: 72 69 6e 74 65 72 2c 20 62 65 69 6e 67 20 74 68  rinter, being th
7e50: 65 20 6f 6e 65 20 74 68 61 74 0a 72 65 73 70 6f  e one that.respo
7e60: 6e 64 73 20 74 6f 20 5b 49 4f 54 20 64 65 76 69  nds to [IOT devi
7e70: 63 65 20 63 6f 64 65 5d 5b 69 6f 74 5d 20 33 20  ce code][iot] 3 
7e80: 66 6f 72 20 69 6e 70 75 74 20 61 6e 64 20 74 6f  for input and to
7e90: 20 64 65 76 69 63 65 20 63 6f 64 65 20 34 20 66   device code 4 f
7ea0: 6f 72 0a 6f 75 74 70 75 74 2e e2 80 9d 20 57 65  or.output.” We
7eb0: e2 80 99 64 20 72 61 74 68 65 72 20 6e 6f 74 20  ’d rather not 
7ec0: 77 72 69 74 65 20 61 6c 6c 20 6f 66 20 74 68 61  write all of tha
7ed0: 74 20 66 6f 72 20 65 76 65 72 79 20 73 74 64 69  t for every stdi
7ee0: 6f 20 66 75 6e 63 74 69 6f 6e 0a 62 65 6c 6f 77  o function.below
7ef0: 2c 20 73 6f 20 77 65 20 75 73 65 20 74 68 69 73  , so we use this
7f00: 20 73 68 6f 72 74 68 61 6e 64 2e 0a 0a 5b 63 70   shorthand...[cp
7f10: 70 72 5d 3a 20 20 20 20 68 74 74 70 73 3a 2f 2f  pr]:    https://
7f20: 65 6e 2e 63 70 70 72 65 66 65 72 65 6e 63 65 2e  en.cppreference.
7f30: 63 6f 6d 2f 77 2f 63 0a 5b 69 6f 74 5d 3a 20 20  com/w/c.[iot]:  
7f40: 20 20 20 2f 77 69 6b 69 3f 6e 61 6d 65 3d 49 4f     /wiki?name=IO
7f50: 54 2b 44 65 76 69 63 65 2b 41 73 73 69 67 6e 6d  T+Device+Assignm
7f60: 65 6e 74 73 0a 5b 6c 69 62 63 68 5d 3a 20 20 20  ents.[libch]:   
7f70: 2f 64 6f 63 2f 74 72 75 6e 6b 2f 73 72 63 2f 63  /doc/trunk/src/c
7f80: 63 38 2f 69 6e 63 6c 75 64 65 2f 6c 69 62 63 2e  c8/include/libc.
7f90: 68 0a 5b 6c 69 62 63 73 72 63 5d 3a 20 2f 64 6f  h.[libcsrc]: /do
7fa0: 63 2f 74 72 75 6e 6b 2f 73 72 63 2f 63 63 38 2f  c/trunk/src/cc8/
7fb0: 6f 73 38 2f 6c 69 62 63 2e 63 0a 0a 0a 23 23 23  os8/libc.c...###
7fc0: 20 3c 61 20 69 64 3d 22 61 74 6f 69 22 3e 3c 2f   <a id="atoi"></
7fd0: 61 3e 60 69 6e 74 20 61 74 6f 69 28 73 2c 20 2a  a>`int atoi(s, *
7fe0: 72 65 73 75 6c 74 29 60 0a 0a 54 61 6b 65 73 20  result)`..Takes 
7ff0: 61 20 6e 75 6c 6c 2d 74 65 72 6d 69 6e 61 74 65  a null-terminate
8000: 64 20 41 53 43 49 49 20 63 68 61 72 61 63 74 65  d ASCII characte
8010: 72 20 73 74 72 69 6e 67 20 70 6f 69 6e 74 65 72  r string pointer
8020: 20 60 73 60 20 61 6e 64 20 74 72 69 65 73 20 74   `s` and tries t
8030: 6f 0a 69 6e 74 65 72 70 72 65 74 20 69 74 20 61  o.interpret it a
8040: 73 20 61 20 31 32 2d 62 69 74 20 50 44 50 2d 38  s a 12-bit PDP-8
8050: 20 74 77 6f e2 80 99 73 20 63 6f 6d 70 6c 65 6d   two’s complem
8060: 65 6e 74 20 73 69 67 6e 65 64 20 69 6e 74 65 67  ent signed integ
8070: 65 72 2c 20 73 74 6f 72 69 6e 67 0a 74 68 65 20  er, storing.the 
8080: 76 61 6c 75 65 20 69 6e 20 60 2a 72 65 73 75 6c  value in `*resul
8090: 74 60 20 61 6e 64 20 72 65 74 75 72 6e 69 6e 67  t` and returning
80a0: 20 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 62   the number of b
80b0: 79 74 65 73 20 69 6e 20 60 73 60 0a 63 6f 6e 73  ytes in `s`.cons
80c0: 75 6d 65 64 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72  umed...**Standar
80d0: 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a  d Violations:**.
80e0: 0a 2a 20 20 20 49 6e 73 74 65 61 64 20 6f 66 20  .*   Instead of 
80f0: 72 65 74 75 72 6e 69 6e 67 20 74 68 65 20 63 6f  returning the co
8100: 6e 76 65 72 74 65 64 20 69 6e 74 65 67 65 72 2c  nverted integer,
8110: 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 73   this function s
8120: 74 6f 72 65 73 0a 20 20 20 20 74 68 61 74 20 76  tores.    that v
8130: 61 6c 75 65 20 69 6e 20 60 2a 72 65 73 75 6c 74  alue in `*result
8140: 60 2e 0a 0a 2a 20 20 20 57 68 65 72 65 61 73 20  `...*   Whereas 
8150: 60 61 74 6f 69 28 29 60 20 69 6e 20 53 74 61 6e  `atoi()` in Stan
8160: 64 61 72 64 20 43 20 72 65 74 75 72 6e 73 20 74  dard C returns t
8170: 68 65 20 63 6f 6e 76 65 72 74 65 64 20 76 61 6c  he converted val
8180: 75 65 2c 20 69 6e 20 74 68 69 73 0a 20 20 20 20  ue, in this.    
8190: 66 75 6e 63 74 69 6f 6e 2c 20 60 73 5b 72 65 74  function, `s[ret
81a0: 76 61 6c 5d 60 20 69 73 20 74 68 65 20 66 69 72  val]` is the fir
81b0: 73 74 20 69 6e 76 61 6c 69 64 20 e2 80 94 20 6e  st invalid — n
81c0: 6f 6e 2d 73 69 67 6e 2c 20 6e 6f 6e 2d 64 69 67  on-sign, non-dig
81d0: 69 74 2c 0a 20 20 20 20 6e 6f 6e 2d 73 70 61 63  it,.    non-spac
81e0: 65 20 e2 80 94 20 63 68 61 72 61 63 74 65 72 20  e — character 
81f0: 69 6e 20 74 68 65 20 73 74 72 69 6e 67 2c 20 77  in the string, w
8200: 68 65 72 65 20 60 72 65 74 76 61 6c 60 20 69 73  here `retval` is
8210: 20 74 68 65 20 72 65 74 75 72 6e 0a 20 20 20 20   the return.    
8220: 76 61 6c 75 65 2e 0a 0a 2a 20 20 20 53 6b 69 70  value...*   Skip
8230: 73 20 6c 65 61 64 69 6e 67 20 41 53 43 49 49 20  s leading ASCII 
8240: 33 32 20 28 73 70 61 63 65 29 20 63 68 61 72 61  32 (space) chara
8250: 63 74 65 72 73 20 6f 6e 6c 79 2c 20 6e 6f 74 20  cters only, not 
8260: 74 68 6f 73 65 20 6d 61 74 63 68 65 64 20 62 79  those matched by
8270: 0a 20 20 20 20 5b 60 69 73 73 70 61 63 65 28 29  .    [`isspace()
8280: 60 5d 28 23 69 73 73 70 61 63 65 29 2c 20 61 73  `](#isspace), as
8290: 20 74 68 65 20 53 74 61 6e 64 61 72 64 20 72 65   the Standard re
82a0: 71 75 69 72 65 73 2e 0a 0a 0a 23 23 23 20 3c 61  quires....### <a
82b0: 20 69 64 3d 22 63 75 70 70 65 72 22 3e 3c 2f 61   id="cupper"></a
82c0: 3e 60 63 75 70 70 65 72 28 70 29 60 0a 0a 49 6d  >`cupper(p)`..Im
82d0: 70 6c 65 6d 65 6e 74 73 20 74 68 69 73 20 6c 6f  plements this lo
82e0: 6f 70 20 6d 6f 72 65 20 65 66 66 69 63 69 65 6e  op more efficien
82f0: 74 6c 79 3a 0a 0a 20 20 20 20 63 68 61 72 2a 20  tly:..    char* 
8300: 74 6d 70 20 3d 20 70 3b 0a 20 20 20 20 77 68 69  tmp = p;.    whi
8310: 6c 65 20 28 2a 74 6d 70 29 20 7b 0a 20 20 20 20  le (*tmp) {.    
8320: 20 20 20 20 2a 74 6d 70 20 3d 20 74 6f 75 70 70      *tmp = toupp
8330: 65 72 28 2a 74 6d 70 29 3b 0a 20 20 20 20 20 20  er(*tmp);.      
8340: 20 20 2b 2b 74 6d 70 3b 0a 20 20 20 20 7d 0a 0a    ++tmp;.    }..
8350: 54 68 61 74 20 69 73 2c 20 69 74 20 64 6f 65 73  That is, it does
8360: 20 61 6e 20 69 6e 2d 70 6c 61 63 65 20 63 6f 6e   an in-place con
8370: 76 65 72 73 69 6f 6e 20 6f 66 20 74 68 65 20 70  version of the p
8380: 61 73 73 65 64 20 5b 30 2d 74 65 72 6d 69 6e 61  assed [0-termina
8390: 74 65 64 20 77 6f 72 64 0a 73 74 72 69 6e 67 5d  ted word.string]
83a0: 28 23 77 6f 72 64 73 74 72 29 20 74 6f 20 61 6c  (#wordstr) to al
83b0: 6c 2d 75 70 70 65 72 63 61 73 65 2e 0a 0a 54 68  l-uppercase...Th
83c0: 69 73 20 66 75 6e 63 74 69 6f 6e 20 65 78 69 73  is function exis
83d0: 74 73 20 69 6e 20 4c 49 42 43 20 62 65 63 61 75  ts in LIBC becau
83e0: 73 65 20 69 74 20 69 73 20 75 73 65 66 75 6c 20  se it is useful 
83f0: 66 6f 72 20 65 6e 73 75 72 69 6e 67 20 74 68 61  for ensuring tha
8400: 74 20 66 69 6c 65 0a 6e 61 6d 65 73 20 61 72 65  t file.names are
8410: 20 75 70 70 65 72 63 61 73 65 2c 20 61 73 20 4f   uppercase, as O
8420: 53 2f 38 20 72 65 71 75 69 72 65 73 2e 20 57 69  S/8 requires. Wi
8430: 74 68 20 74 68 65 20 63 75 72 72 65 6e 74 20 43  th the current C
8440: 43 38 20 63 6f 6d 70 69 6c 65 72 0a 69 6d 70 6c  C8 compiler.impl
8450: 65 6d 65 6e 74 61 74 69 6f 6e 2c 20 74 68 65 20  ementation, the 
8460: 65 71 75 69 76 61 6c 65 6e 74 20 63 6f 64 65 20  equivalent code 
8470: 61 62 6f 76 65 20 72 65 71 75 69 72 65 73 20 32  above requires 2
8480: 34 20 6d 6f 72 65 20 69 6e 73 74 72 75 63 74 69  4 more instructi
8490: 6f 6e 73 0a 74 68 61 6e 20 63 61 6c 6c 69 6e 67  ons.than calling
84a0: 20 60 63 75 70 70 65 72 28 29 60 20 69 6e 73 74   `cupper()` inst
84b0: 65 61 64 2c 20 62 65 73 74 2d 63 61 73 65 21 20  ead, best-case! 
84c0: 54 68 61 74 20 6d 65 61 6e 73 20 61 20 73 69 6e  That means a sin
84d0: 67 6c 65 20 63 61 6c 6c 0a 63 6f 6e 76 65 72 74  gle call.convert
84e0: 65 64 20 66 72 6f 6d 20 61 20 6c 6f 6f 70 20 61  ed from a loop a
84f0: 72 6f 75 6e 64 20 5b 60 74 6f 75 70 70 65 72 28  round [`toupper(
8500: 29 60 5d 28 23 74 6f 75 70 70 65 72 29 20 74 6f  )`](#toupper) to
8510: 20 61 20 60 63 75 70 70 65 72 28 29 60 0a 63 61   a `cupper()`.ca
8520: 6c 6c 20 6d 6f 72 65 20 74 68 61 6e 20 70 61 79  ll more than pay
8530: 73 20 66 6f 72 20 74 68 65 20 32 31 20 69 6e 73  s for the 21 ins
8540: 74 72 75 63 74 69 6f 6e 73 20 61 6e 64 20 6f 6e  tructions and on
8550: 65 20 65 78 74 72 61 20 6a 75 6d 70 20 74 61 62  e extra jump tab
8560: 6c 65 0a 73 6c 6f 74 20 74 68 69 73 20 66 75 6e  le.slot this fun
8570: 63 74 69 6f 6e 20 72 65 71 75 69 72 65 73 20 69  ction requires i
8580: 6e 20 4c 49 42 43 2e 0a 0a 44 6f 20 6e 6f 74 20  n LIBC...Do not 
8590: 64 65 70 65 6e 64 20 6f 6e 20 74 68 65 20 72 65  depend on the re
85a0: 74 75 72 6e 20 76 61 6c 75 65 2e 20 54 68 65 72  turn value. Ther
85b0: 65 20 69 73 20 61 20 70 72 65 64 69 63 74 61 62  e is a predictab
85c0: 6c 65 20 6d 61 70 70 69 6e 67 2c 20 62 75 74 0a  le mapping, but.
85d0: 69 74 20 68 61 73 20 6e 6f 20 69 6e 68 65 72 65  it has no inhere
85e0: 6e 74 20 6d 65 61 6e 69 6e 67 2c 20 73 6f 20 77  nt meaning, so w
85f0: 65 20 61 72 65 20 6e 6f 74 20 64 6f 63 75 6d 65  e are not docume
8600: 6e 74 69 6e 67 20 74 68 61 74 20 6d 61 70 70 69  nting that mappi
8610: 6e 67 20 68 65 72 65 2e 0a 49 66 20 43 43 38 20  ng here..If CC8 
8620: 68 61 64 20 61 20 e2 80 9c 60 76 6f 69 64 60 e2  had a “`void`
8630: 80 9d 20 72 65 74 75 72 6e 20 74 79 70 65 20 66   return type f
8640: 65 61 74 75 72 65 2c 20 77 65 e2 80 99 64 20 62  eature, we’d b
8650: 65 20 75 73 69 6e 67 20 74 68 61 74 20 68 65 72  e using that her
8660: 65 2e 0a 0a 2a 2a 4e 6f 6e 73 74 61 6e 64 61 72  e...**Nonstandar
8670: 64 2e 2a 2a 20 4e 6f 20 6b 6e 6f 77 6e 20 61 6e  d.** No known an
8680: 61 6c 6f 67 20 69 6e 20 61 6e 79 20 6f 74 68 65  alog in any othe
8690: 72 20 43 20 6c 69 62 72 61 72 79 2e 0a 0a 0a 23  r C library....#
86a0: 23 23 20 3c 61 20 69 64 3d 22 64 69 73 70 78 79  ## <a id="dispxy
86b0: 22 3e 3c 2f 61 3e 60 64 69 73 70 78 79 28 78 2c  "></a>`dispxy(x,
86c0: 79 29 60 0a 0a 50 6c 6f 74 20 61 20 70 6f 69 6e  y)`..Plot a poin
86d0: 74 20 61 74 20 63 6f 6f 72 64 69 6e 61 74 65 20  t at coordinate 
86e0: 28 78 2c 79 29 20 6f 6e 20 61 20 5b 56 43 38 45  (x,y) on a [VC8E
86f0: 20 70 6f 69 6e 74 2d 70 6c 6f 74 20 64 69 73 70   point-plot disp
8700: 6c 61 79 5d 5b 76 63 38 65 5d 2e 0a 0a 54 68 69  lay][vc8e]...Thi
8710: 73 20 69 73 20 74 68 65 20 64 69 73 70 6c 61 79  s is the display
8720: 20 74 79 70 65 20 61 73 73 75 6d 65 64 20 62 79   type assumed by
8730: 20 74 68 65 20 50 69 44 50 2d 38 2f 49 20 53 70   the PiDP-8/I Sp
8740: 61 63 65 77 61 72 21 0a 69 6d 70 6c 65 6d 65 6e  acewar!.implemen
8750: 74 61 74 69 6f 6e 2e 20 54 68 65 72 65 20 77 65  tation. There we
8760: 72 65 20 6d 61 6e 79 20 6f 74 68 65 72 20 64 69  re many other di
8770: 73 70 6c 61 79 20 74 79 70 65 73 20 64 65 73 69  splay types desi
8780: 67 6e 65 64 20 66 6f 72 20 61 6e 64 0a 73 6f 6c  gned for and.sol
8790: 64 20 77 69 74 68 20 50 44 50 2d 38 20 66 61 6d  d with PDP-8 fam
87a0: 69 6c 79 20 63 6f 6d 70 75 74 65 72 73 2c 20 77  ily computers, w
87b0: 68 69 63 68 20 67 65 6e 65 72 61 6c 6c 79 20 75  hich generally u
87c0: 73 65 64 20 64 69 66 66 65 72 65 6e 74 20 49 4f  sed different IO
87d0: 54 0a 63 6f 64 65 73 2e 20 49 66 20 79 6f 75 e2  T.codes. If you
87e0: 80 99 72 65 20 74 72 79 69 6e 67 20 74 6f 20 63  re trying to c
87f0: 6f 6e 74 72 6f 6c 20 73 6f 6d 65 74 68 69 6e 67  ontrol something
8800: 20 6f 74 68 65 72 20 74 68 61 6e 20 61 20 56 43   other than a VC
8810: 38 45 2c 20 79 6f 75 0a 6d 69 67 68 74 20 77 61  8E, you.might wa
8820: 6e 74 20 74 6f 20 72 65 70 6c 61 63 65 20 74 68  nt to replace th
8830: 69 73 20 72 6f 75 74 69 6e 65 e2 80 99 73 20 69  is routine’s i
8840: 6e 74 65 72 6e 61 6c 73 20 72 61 74 68 65 72 20  nternals rather 
8850: 74 68 61 6e 20 63 6f 64 65 20 61 0a 73 65 70 61  than code a.sepa
8860: 72 61 74 65 20 69 6d 70 6c 65 6d 65 6e 74 61 74  rate implementat
8870: 69 6f 6e 2c 20 6c 65 61 64 69 6e 67 20 74 6f 20  ion, leading to 
8880: 77 61 73 74 65 64 20 73 70 61 63 65 20 69 6e 20  wasted space in 
8890: 79 6f 75 72 20 4c 49 42 43 2e 0a 0a 2a 2a 4e 6f  your LIBC...**No
88a0: 6e 73 74 61 6e 64 61 72 64 2e 2a 2a 0a 0a 5b 64  nstandard.**..[d
88b0: 69 78 79 5d 3a 20 68 74 74 70 3a 2f 2f 68 6f 6d  ixy]: http://hom
88c0: 65 70 61 67 65 2e 64 69 76 6d 73 2e 75 69 6f 77  epage.divms.uiow
88d0: 61 2e 65 64 75 2f 7e 6a 6f 6e 65 73 2f 70 64 70  a.edu/~jones/pdp
88e0: 38 2f 6d 61 6e 2f 76 63 38 65 2e 68 74 6d 6c 0a  8/man/vc8e.html.
88f0: 5b 76 63 38 65 5d 3a 20 68 74 74 70 73 3a 2f 2f  [vc8e]: https://
8900: 68 6f 6d 65 70 61 67 65 2e 64 69 76 6d 73 2e 75  homepage.divms.u
8910: 69 6f 77 61 2e 65 64 75 2f 7e 6a 6f 6e 65 73 2f  iowa.edu/~jones/
8920: 70 64 70 38 2f 6d 61 6e 2f 76 63 38 65 2e 68 74  pdp8/man/vc8e.ht
8930: 6d 6c 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22  ml...### <a id="
8940: 65 78 69 74 22 3e 3c 2f 61 3e 60 65 78 69 74 28  exit"></a>`exit(
8950: 72 65 74 29 60 0a 0a 45 78 69 74 73 20 74 68 65  ret)`..Exits the
8960: 20 70 72 6f 67 72 61 6d 2e 0a 0a 54 68 69 73 20   program...This 
8970: 66 75 6e 63 74 69 6f 6e 20 69 73 20 69 6d 70 6c  function is impl
8980: 65 6d 65 6e 74 65 64 20 69 6e 20 74 65 72 6d 73  emented in terms
8990: 20 6f 66 20 74 68 65 20 5b 46 4f 52 54 52 41 4e   of the [FORTRAN
89a0: 20 49 49 20 6c 69 62 72 61 72 79 0a 73 75 62 72   II library.subr
89b0: 6f 75 74 69 6e 65 20 60 45 58 49 54 60 5d 5b 66  outine `EXIT`][f
89c0: 32 65 78 69 74 5d 2c 20 77 68 69 63 68 20 69 6e  2exit], which in
89d0: 20 74 68 65 20 4f 53 2f 38 20 69 6d 70 6c 65 6d   the OS/8 implem
89e0: 65 6e 74 61 74 69 6f 6e 20 73 69 6d 70 6c 79 0a  entation simply.
89f0: 72 65 74 75 72 6e 73 20 63 6f 6e 74 72 6f 6c 20  returns control 
8a00: 74 6f 20 74 68 65 20 4f 53 2f 38 20 6b 65 79 62  to the OS/8 keyb
8a10: 6f 61 72 64 20 6d 6f 6e 69 74 6f 72 2e 0a 0a 49  oard monitor...I
8a20: 66 20 60 45 58 49 54 60 20 72 65 74 75 72 6e 73  f `EXIT` returns
8a30: 20 66 6f 72 20 61 6e 79 20 72 65 61 73 6f 6e 2c   for any reason,
8a40: 20 4c 49 42 43 20 68 61 6c 74 73 20 74 68 65 20   LIBC halts the 
8a50: 70 72 6f 63 65 73 73 6f 72 2e 0a 0a 2a 2a 53 74  processor...**St
8a60: 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e  andard Violation
8a70: 73 3a 2a 2a 0a 0a 2a 20 20 20 54 68 65 20 70 61  s:**..*   The pa
8a80: 73 73 65 64 20 72 65 74 75 72 6e 20 63 6f 64 65  ssed return code
8a90: 20 69 73 20 69 67 6e 6f 72 65 64 2c 20 74 68 65   is ignored, the
8aa0: 72 65 20 62 65 69 6e 67 20 6e 6f 20 73 75 63 68  re being no such
8ab0: 20 74 68 69 6e 67 20 61 73 20 61 0a 20 20 20 20   thing as a.    
8ac0: 70 72 6f 67 72 61 6d e2 80 99 73 20 e2 80 9c 73  program’s “s
8ad0: 74 61 74 75 73 20 63 6f 64 65 e2 80 9d 20 69 6e  tatus code” in
8ae0: 20 4f 53 2f 38 2e 0a 0a 2a 20 20 20 54 68 65 72   OS/8...*   Ther
8af0: 65 20 69 73 20 6e 6f 20 60 61 74 65 78 69 74 28  e is no `atexit(
8b00: 29 60 20 6d 65 63 68 61 6e 69 73 6d 20 69 6e 20  )` mechanism in 
8b10: 74 68 65 20 43 43 38 20 4c 49 42 43 2e 0a 0a 5b  the CC8 LIBC...[
8b20: 66 32 65 78 69 74 5d 3a 20 68 74 74 70 73 3a 2f  f2exit]: https:/
8b30: 2f 61 72 63 68 69 76 65 2e 6f 72 67 2f 64 65 74  /archive.org/det
8b40: 61 69 6c 73 2f 62 69 74 73 61 76 65 72 73 5f 64  ails/bitsavers_d
8b50: 65 63 70 64 70 38 6f 73 38 5f 33 39 34 31 34 37  ecpdp8os8_394147
8b60: 39 32 2f 70 61 67 65 2f 6e 37 30 32 0a 0a 0a 23  92/page/n702...#
8b70: 23 23 20 3c 61 20 69 64 3d 22 66 63 6c 6f 73 65  ## <a id="fclose
8b80: 22 3e 3c 2f 61 3e 60 66 63 6c 6f 73 65 28 29 60  "></a>`fclose()`
8b90: 0a 0a 43 6c 6f 73 65 73 20 74 68 65 20 63 75 72  ..Closes the cur
8ba0: 72 65 6e 74 6c 79 2d 6f 70 65 6e 65 64 20 6f 75  rently-opened ou
8bb0: 74 70 75 74 20 66 69 6c 65 2e 0a 0a 54 68 69 73  tput file...This
8bc0: 20 66 75 6e 63 74 69 6f 6e 20 73 69 6d 70 6c 79   function simply
8bd0: 20 63 61 6c 6c 73 20 74 68 65 20 4f 53 2f 38 20   calls the OS/8 
8be0: 46 4f 52 54 52 41 4e 20 49 49 20 6c 69 62 72 61  FORTRAN II libra
8bf0: 72 79 20 73 75 62 72 6f 75 74 69 6e 65 0a 5b 60  ry subroutine.[`
8c00: 4f 43 4c 4f 53 45 60 5d 5b 66 32 66 69 6f 5d 2e  OCLOSE`][f2fio].
8c10: 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 69 6f  ..**Standard Vio
8c20: 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20  lations:**..*   
8c30: 44 6f 65 73 20 6e 6f 74 20 74 61 6b 65 20 61 20  Does not take a 
8c40: 60 46 49 4c 45 2a 60 20 61 72 67 75 6d 65 6e 74  `FILE*` argument
8c50: 2e 20 20 28 53 65 65 20 5b 60 66 6f 70 65 6e 28  .  (See [`fopen(
8c60: 29 60 5d 28 23 66 6f 70 65 6e 29 20 66 6f 72 0a  )`](#fopen) for.
8c70: 20 20 20 20 6a 75 73 74 69 66 69 63 61 74 69 6f      justificatio
8c80: 6e 2e 29 0a 0a 2a 20 20 20 41 6c 77 61 79 73 20  n.)..*   Always 
8c90: 63 6c 6f 73 65 73 20 74 68 65 20 6c 61 73 74 2d  closes the last-
8ca0: 6f 70 65 6e 65 64 20 2a 6f 75 74 70 75 74 2a 20  opened *output* 
8cb0: 66 69 6c 65 2c 20 6f 6e 6c 79 2c 20 74 68 65 72  file, only, ther
8cc0: 65 20 62 65 69 6e 67 0a 20 20 20 20 5b 6e 6f 20  e being.    [no 
8cd0: 70 6f 69 6e 74 5d 28 23 66 69 6f 6c 69 6d 29 20  point](#fiolim) 
8ce0: 69 6e 20 65 78 70 6c 69 63 69 74 6c 79 20 63 6c  in explicitly cl
8cf0: 6f 73 69 6e 67 20 69 6e 70 75 74 20 66 69 6c 65  osing input file
8d00: 73 20 69 6e 20 74 68 69 73 0a 20 20 20 20 69 6d  s in this.    im
8d10: 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 0a 0a 5b  plementation...[
8d20: 66 32 66 69 6f 5d 3a 20 68 74 74 70 73 3a 2f 2f  f2fio]: https://
8d30: 61 72 63 68 69 76 65 2e 6f 72 67 2f 64 65 74 61  archive.org/deta
8d40: 69 6c 73 2f 62 69 74 73 61 76 65 72 73 5f 64 65  ils/bitsavers_de
8d50: 63 70 64 70 38 6f 73 38 5f 33 39 34 31 34 37 39  cpdp8os8_3941479
8d60: 32 2f 70 61 67 65 2f 6e 37 30 30 0a 0a 0a 23 23  2/page/n700...##
8d70: 23 20 3c 61 20 69 64 3d 22 66 67 65 74 73 22 3e  # <a id="fgets">
8d80: 3c 2f 61 3e 60 66 67 65 74 73 28 73 29 60 0a 0a  </a>`fgets(s)`..
8d90: 52 65 61 64 73 20 61 20 73 74 72 69 6e 67 20 6f  Reads a string o
8da0: 66 20 41 53 43 49 49 20 63 68 61 72 61 63 74 65  f ASCII characte
8db0: 72 73 20 66 72 6f 6d 20 74 68 65 20 6c 61 73 74  rs from the last
8dc0: 20 66 69 6c 65 20 6f 70 65 6e 65 64 20 66 6f 72   file opened for
8dd0: 20 69 6e 70 75 74 0a 62 79 20 5b 60 66 6f 70 65   input.by [`fope
8de0: 6e 28 29 60 5d 28 23 66 6f 70 65 6e 29 2c 20 73  n()`](#fopen), s
8df0: 74 6f 72 69 6e 67 20 69 74 20 61 74 20 63 6f 72  toring it at cor
8e00: 65 20 6d 65 6d 6f 72 79 20 6c 6f 63 61 74 69 6f  e memory locatio
8e10: 6e 20 60 73 60 2e 20 49 74 20 72 65 61 64 73 0a  n `s`. It reads.
8e20: 75 6e 74 69 6c 20 69 74 20 65 6e 63 6f 75 6e 74  until it encount
8e30: 65 72 73 20 61 6e 20 4c 46 20 63 68 61 72 61 63  ers an LF charac
8e40: 74 65 72 2c 20 73 74 6f 72 69 6e 67 20 74 68 61  ter, storing tha
8e50: 74 20 61 6e 64 20 61 20 74 72 61 69 6c 69 6e 67  t and a trailing
8e60: 20 4e 55 4c 0a 62 65 66 6f 72 65 20 72 65 74 75   NUL.before retu
8e70: 72 6e 69 6e 67 2c 20 62 65 63 61 75 73 65 20 69  rning, because i
8e80: 74 20 61 73 73 75 6d 65 73 20 74 68 65 20 4f 53  t assumes the OS
8e90: 2f 38 20 63 6f 6e 76 65 6e 74 69 6f 6e 20 6f 66  /8 convention of
8ea0: 20 43 52 2b 4c 46 0a 74 65 72 6d 69 6e 61 74 65   CR+LF.terminate
8eb0: 64 20 74 65 78 74 20 66 69 6c 65 73 2e 0a 0a 4f  d text files...O
8ec0: 53 2f 38 20 74 65 78 74 20 66 69 6c 65 73 20 66  S/8 text files f
8ed0: 72 65 71 75 65 6e 74 6c 79 20 69 6e 63 6c 75 64  requently includ
8ee0: 65 20 66 6f 72 6d 20 66 65 65 64 20 63 68 61 72  e form feed char
8ef0: 61 63 74 65 72 73 20 e2 80 94 20 41 53 43 49 49  acters — ASCII
8f00: 20 31 32 20 e2 80 94 0a 6f 77 69 6e 67 20 74 6f   12 —.owing to
8f10: 20 74 68 65 20 50 44 50 2d 38 e2 80 99 73 20 63   the PDP-8’s c
8f20: 6c 6f 73 65 20 61 73 73 6f 63 69 61 74 69 6f 6e  lose association
8f30: 20 77 69 74 68 20 74 65 6c 65 70 72 69 6e 74 65   with teleprinte
8f40: 72 73 2e 20 60 66 67 65 74 73 28 29 60 20 64 6f  rs. `fgets()` do
8f50: 65 73 0a 6e 6f 74 20 64 6f 20 61 6e 79 74 68 69  es.not do anythi
8f60: 6e 67 20 77 69 74 68 20 74 68 65 73 65 20 6f 74  ng with these ot
8f70: 68 65 72 20 74 68 61 6e 20 67 69 76 65 20 74 68  her than give th
8f80: 65 6d 20 74 6f 20 74 68 65 20 70 72 6f 67 72 61  em to the progra
8f90: 6d 0a 6c 69 74 65 72 61 6c 6c 79 2e 20 54 68 65  m.literally. The
8fa0: 73 65 20 73 68 6f 75 6c 64 20 74 79 70 69 63 61  se should typica
8fb0: 6c 6c 79 20 62 65 20 72 65 6d 6f 76 65 64 20 66  lly be removed f
8fc0: 72 6f 6d 20 69 6e 70 75 74 20 6f 72 20 72 65 70  rom input or rep
8fd0: 6c 61 63 65 64 20 77 69 74 68 0a 61 6e 20 41 53  laced with.an AS
8fe0: 43 49 49 20 73 70 61 63 65 20 63 68 61 72 61 63  CII space charac
8ff0: 74 65 72 2c 20 33 32 2e 0a 0a 52 65 74 75 72 6e  ter, 32...Return
9000: 73 20 30 20 6f 6e 20 45 4f 46 2c 20 61 73 20 53  s 0 on EOF, as S
9010: 74 61 6e 64 61 72 64 20 43 20 72 65 71 75 69 72  tandard C requir
9020: 65 73 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20  es...**Standard 
9030: 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a  Violations:**..*
9040: 20 20 20 52 65 74 75 72 6e 73 20 74 68 65 20 6e     Returns the n
9050: 75 6d 62 65 72 20 6f 66 20 63 68 61 72 61 63 74  umber of charact
9060: 65 72 73 20 72 65 61 64 20 6f 6e 20 73 75 63 63  ers read on succ
9070: 65 73 73 2c 20 72 61 74 68 65 72 20 74 68 61 6e  ess, rather than
9080: 20 60 73 60 20 61 73 0a 20 20 20 20 53 74 61 6e   `s` as.    Stan
9090: 64 61 72 64 20 43 20 72 65 71 75 69 72 65 73 2e  dard C requires.
90a0: 0a 0a 2a 20 20 20 53 69 6e 63 65 20 45 4f 46 20  ..*   Since EOF 
90b0: 69 73 20 74 68 65 20 6f 6e 6c 79 20 65 72 72 6f  is the only erro
90c0: 72 20 65 78 69 74 20 63 61 73 65 20 66 72 6f 6d  r exit case from
90d0: 20 74 68 69 73 20 69 6d 70 6c 65 6d 65 6e 74 61   this implementa
90e0: 74 69 6f 6e 20 6f 66 0a 20 20 20 20 60 66 67 65  tion of.    `fge
90f0: 74 73 28 29 60 2c 20 74 68 69 73 20 4c 49 42 43  ts()`, this LIBC
9100: 20 64 6f 65 73 20 6e 6f 74 20 70 72 6f 76 69 64   does not provid
9110: 65 20 60 66 65 6f 66 28 29 60 2e 0a 0a 0a 23 23  e `feof()`....##
9120: 23 20 3c 61 20 69 64 3d 22 66 6f 70 65 6e 22 3e  # <a id="fopen">
9130: 3c 2f 61 3e 60 66 6f 70 65 6e 28 6e 61 6d 65 2c  </a>`fopen(name,
9140: 20 6d 6f 64 65 29 60 0a 0a 4f 70 65 6e 73 20 4f   mode)`..Opens O
9150: 53 2f 38 20 66 69 6c 65 20 60 44 53 4b 3a 4e 41  S/8 file `DSK:NA
9160: 2e 4d 45 60 2e 0a 0a 54 68 65 20 60 6e 61 6d 65  .ME`...The `name
9170: 60 20 70 61 72 61 6d 65 74 65 72 20 6d 75 73 74  ` parameter must
9180: 20 70 6f 69 6e 74 20 74 6f 20 61 74 20 6d 6f 73   point to at mos
9190: 74 20 73 69 78 20 30 2d 74 65 72 6d 69 6e 61 74  t six 0-terminat
91a0: 65 64 20 63 68 61 72 61 63 74 65 72 73 2c 0a 5b  ed characters,.[
91b0: 6f 6e 65 20 63 68 61 72 61 63 74 65 72 20 70 65  one character pe
91c0: 72 20 77 6f 72 64 5d 28 23 77 6f 72 64 73 74 72  r word](#wordstr
91d0: 29 2c 20 70 6c 75 73 20 61 20 32 2d 6c 65 74 74  ), plus a 2-lett
91e0: 65 72 20 66 69 6c 65 20 6e 61 6d 65 20 65 78 74  er file name ext
91f0: 65 6e 73 69 6f 6e 2c 0a 61 6c 6c 20 69 6e 20 75  ension,.all in u
9200: 70 70 65 72 20 63 61 73 65 2e 20 20 28 53 65 65  pper case.  (See
9210: 20 5b 60 63 75 70 70 65 72 28 29 60 5d 28 23 63   [`cupper()`](#c
9220: 75 70 70 65 72 29 2e 29 0a 0a 54 68 65 20 66 69  upper).)..The fi
9230: 6c 65 20 69 73 20 6f 70 65 6e 65 64 20 66 6f 72  le is opened for
9240: 20 72 65 61 64 69 6e 67 20 69 66 20 60 6d 6f 64   reading if `mod
9250: 65 60 20 70 6f 69 6e 74 73 20 74 6f 20 61 6e 20  e` points to an 
9260: e2 80 9d 60 72 60 e2 80 9d 20 63 68 61 72 61 63  ”`r`” charac
9270: 74 65 72 2c 0a 61 6e 64 20 69 74 20 69 73 20 6f  ter,.and it is o
9280: 70 65 6e 65 64 20 66 6f 72 20 77 72 69 74 69 6e  pened for writin
9290: 67 20 69 66 20 60 6d 6f 64 65 60 20 70 6f 69 6e  g if `mode` poin
92a0: 74 73 20 74 6f 20 61 20 e2 80 9c 60 77 60 e2 80  ts to a “`w`
92b0: 9d 20 63 68 61 72 61 63 74 65 72 2e 20 54 68 69   character. Thi
92c0: 73 0a 6e 65 65 64 20 6f 6e 6c 79 20 70 6f 69 6e  s.need only poin
92d0: 74 20 74 6f 20 61 20 73 69 6e 67 6c 65 20 63 68  t to a single ch
92e0: 61 72 61 63 74 65 72 2c 20 73 69 6e 63 65 20 6f  aracter, since o
92f0: 6e 6c 79 20 74 68 61 74 20 6f 6e 65 20 6d 65 6d  nly that one mem
9300: 6f 72 79 0a 6c 6f 63 61 74 69 6f 6e 20 69 73 20  ory.location is 
9310: 65 76 65 72 20 72 65 66 65 72 65 6e 63 65 64 2e  ever referenced.
9320: 20 4e 6f 20 74 65 72 6d 69 6e 61 74 6f 72 20 69   No terminator i
9330: 73 20 72 65 71 75 69 72 65 64 2e 0a 0a 54 68 65  s required...The
9340: 20 4f 53 2f 38 20 64 65 76 69 63 65 20 6e 61 6d   OS/8 device nam
9350: 65 20 69 73 20 68 61 72 64 2d 63 6f 64 65 64 2c  e is hard-coded,
9360: 20 64 65 73 70 69 74 65 20 74 68 65 20 66 61 63   despite the fac
9370: 74 20 74 68 61 74 20 74 68 65 20 4f 53 2f 38 0a  t that the OS/8.
9380: 46 4f 52 54 52 41 4e 20 49 49 20 5b 60 49 4f 50  FORTRAN II [`IOP
9390: 45 4e 60 20 61 6e 64 20 60 4f 4f 50 45 4e 60 5d  EN` and `OOPEN`]
93a0: 5b 66 32 66 69 6f 5d 20 73 75 62 72 6f 75 74 69  [f2fio] subrouti
93b0: 6e 65 73 20 74 68 61 74 20 60 66 6f 70 65 6e 28  nes that `fopen(
93c0: 29 60 20 69 73 0a 69 6d 70 6c 65 6d 65 6e 74 65  )` is.implemente
93d0: 64 20 69 6e 20 74 65 72 6d 73 20 6f 66 20 61 63  d in terms of ac
93e0: 63 65 70 74 20 61 20 64 65 76 69 63 65 20 6e 61  cept a device na
93f0: 6d 65 20 70 61 72 61 6d 65 74 65 72 2e 20 54 68  me parameter. Th
9400: 69 73 20 6d 65 61 6e 73 20 74 68 65 72 65 0a 69  is means there.i
9410: 73 20 63 75 72 72 65 6e 74 6c 79 20 6e 6f 20 77  s currently no w
9420: 61 79 20 74 6f 20 75 73 65 20 74 68 69 73 20 60  ay to use this `
9430: 73 74 64 69 6f 60 20 69 6d 70 6c 65 6d 65 6e 74  stdio` implement
9440: 61 74 69 6f 6e 20 74 6f 20 72 65 61 64 20 66 72  ation to read fr
9450: 6f 6d 20 6f 72 0a 77 72 69 74 65 20 74 6f 20 66  om or.write to f
9460: 69 6c 65 73 20 6f 6e 20 4f 53 2f 38 20 64 65 76  iles on OS/8 dev
9470: 69 63 65 73 20 6f 74 68 65 72 20 74 68 61 6e 20  ices other than 
9480: 60 44 53 4b 3a 60 2e 0a 0a 54 68 65 20 75 6e 64  `DSK:`...The und
9490: 65 72 6c 79 69 6e 67 20 46 4f 52 54 52 41 4e 20  erlying FORTRAN 
94a0: 49 49 20 72 6f 75 74 69 6e 65 73 20 61 72 65 20  II routines are 
94b0: 64 6f 63 75 6d 65 6e 74 65 64 20 61 73 20 68 61  documented as ha
94c0: 72 64 2d 63 6f 64 69 6e 67 20 74 68 65 0a 66 69  rd-coding the.fi
94d0: 6c 65 20 6e 61 6d 65 20 65 78 74 65 6e 73 69 6f  le name extensio
94e0: 6e 20 74 6f 20 60 44 41 60 2c 20 62 75 74 20 69  n to `DA`, but i
94f0: 6e 73 70 65 63 74 69 6f 6e 20 6f 66 20 74 68 65  nspection of the
9500: 20 63 6f 64 65 20 72 65 76 65 61 6c 73 20 74 68   code reveals th
9510: 61 74 0a 74 68 69 73 20 4c 49 42 43 20 64 6f 65  at.this LIBC doe
9520: 73 20 73 6f 6d 65 20 68 61 63 6b 65 72 79 20 74  s some hackery t
9530: 6f 20 6f 76 65 72 77 72 69 74 65 20 74 68 61 74  o overwrite that
9540: 2c 20 61 6c 6c 6f 77 69 6e 67 20 61 72 69 62 74  , allowing aribt
9550: 72 61 72 79 0a 65 78 74 65 6e 73 69 6f 6e 73 2e  rary.extensions.
9560: 20 20 2a 2a 54 4f 44 4f 3a 2a 2a 20 56 65 72 69    **TODO:** Veri
9570: 66 79 20 74 68 69 73 20 66 6f 72 20 62 6f 74 68  fy this for both
9580: 20 72 65 61 64 20 61 6e 64 20 77 72 69 74 65 2e   read and write.
9590: 0a 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 69  ...**Standard Vi
95a0: 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20  olations:**..*  
95b0: 20 44 6f 65 73 20 6e 6f 74 20 72 65 74 75 72 6e   Does not return
95c0: 20 61 20 60 46 49 4c 45 2a 60 2e 20 46 75 6e 63   a `FILE*`. Func
95d0: 74 69 6f 6e 73 20 77 68 69 63 68 2c 20 69 6e 20  tions which, in 
95e0: 53 74 61 6e 64 61 72 64 20 43 2c 20 74 61 6b 65  Standard C, take
95f0: 20 61 0a 20 20 20 20 60 46 49 4c 45 2a 60 20 61   a.    `FILE*` a
9600: 72 67 75 6d 65 6e 74 20 64 6f 20 6e 6f 74 20 64  rgument do not d
9610: 6f 20 73 6f 20 69 6e 20 74 68 65 20 43 43 38 20  o so in the CC8 
9620: 4c 49 42 43 2c 20 62 65 63 61 75 73 65 20 74 68  LIBC, because th
9630: 65 72 65 20 63 61 6e 20 62 65 0a 20 20 20 20 6f  ere can be.    o
9640: 6e 6c 79 20 6f 6e 65 20 6f 70 65 6e 65 64 20 69  nly one opened i
9650: 6e 70 75 74 20 66 69 6c 65 20 61 6e 64 20 6f 6e  nput file and on
9660: 65 20 6f 70 65 6e 65 64 20 6f 75 74 70 75 74 20  e opened output 
9670: 66 69 6c 65 20 61 74 20 61 20 74 69 6d 65 2c 20  file at a time, 
9680: 73 6f 0a 20 20 20 20 74 68 65 20 66 69 6c 65 20  so.    the file 
9690: 74 68 61 74 20 69 73 20 6d 65 61 6e 74 20 69 73  that is meant is
96a0: 20 69 6d 70 6c 69 63 69 74 20 69 6e 20 74 68 65   implicit in the
96b0: 20 63 61 6c 6c 2e 0a 0a 20 20 20 20 54 68 69 73   call...    This
96c0: 20 61 6c 73 6f 20 6d 65 61 6e 73 20 60 66 6f 70   also means `fop
96d0: 65 6e 28 29 60 20 68 61 73 20 6e 6f 20 77 61 79  en()` has no way
96e0: 20 74 6f 20 73 69 67 6e 61 6c 20 61 20 66 61 69   to signal a fai
96f0: 6c 75 72 65 20 74 6f 20 6f 70 65 6e 20 74 68 65  lure to open the
9700: 0a 20 20 20 20 72 65 71 75 65 73 74 65 64 20 66  .    requested f
9710: 69 6c 65 20 6e 61 6d 65 21 20 20 2e 2e 2e 57 68  ile name!  ...Wh
9720: 69 63 68 20 69 73 20 6a 75 73 74 20 61 73 20 77  ich is just as w
9730: 65 6c 6c 2c 20 73 69 6e 63 65 20 74 68 65 72 65  ell, since there
9740: 20 69 73 20 61 6c 73 6f 0a 20 20 20 20 6e 6f 20   is also.    no 
9750: 60 66 65 72 72 6f 72 28 29 60 20 6f 72 20 60 65  `ferror()` or `e
9760: 72 72 6e 6f 60 20 69 6e 20 6f 75 72 20 4c 49 42  rrno` in our LIB
9770: 43 2e 0a 0a 20 20 20 20 54 68 69 73 20 66 75 6e  C...    This fun
9780: 63 74 69 6f 6e 20 77 69 6c 6c 20 72 65 74 75 72  ction will retur
9790: 6e 20 2d 31 20 69 66 20 6e 6f 20 66 69 6c 65 20  n -1 if no file 
97a0: 6e 61 6d 65 20 65 78 74 65 6e 73 69 6f 6e 20 69  name extension i
97b0: 73 20 67 69 76 65 6e 2c 0a 20 20 20 20 77 68 69  s given,.    whi
97c0: 63 68 20 69 73 20 67 6f 6f 64 20 69 6e 20 74 68  ch is good in th
97d0: 61 74 20 69 74 20 6d 65 61 6e 73 20 74 68 69 73  at it means this
97e0: 20 66 75 6e 63 74 69 6f 6e 20 64 6f 65 73 20 68   function does h
97f0: 61 76 65 20 2a 73 6f 6d 65 2a 20 65 72 72 6f 72  ave *some* error
9800: 0a 20 20 20 20 63 68 65 63 6b 69 6e 67 2c 20 69  .    checking, i
9810: 74 e2 80 99 73 20 61 20 6e 6f 6e 73 74 61 6e 64  t’s a nonstand
9820: 61 72 64 20 77 61 79 20 74 6f 20 73 69 67 6e 61  ard way to signa
9830: 6c 20 69 74 2e 0a 0a 2a 20 20 20 44 6f 65 73 20  l it...*   Does 
9840: 6e 6f 74 20 61 63 63 65 70 74 20 74 68 65 20 73  not accept the s
9850: 74 61 6e 64 61 72 64 20 6d 6f 64 65 20 60 61 60  tandard mode `a`
9860: 2c 20 66 6f 72 20 61 70 70 65 6e 64 2e 20 20 53  , for append.  S
9870: 69 6e 63 65 20 74 68 65 72 65 20 69 73 0a 20 20  ince there is.  
9880: 20 20 61 6c 73 6f 20 6e 6f 20 60 66 73 65 65 6b    also no `fseek
9890: 28 29 60 20 69 6e 20 43 43 38 e2 80 99 73 20 4c  ()` in CC8’s L
98a0: 49 42 43 2c 20 61 20 70 72 65 65 78 69 73 74 69  IBC, a preexisti
98b0: 6e 67 20 66 69 6c 65 20 6e 61 6d 65 64 20 66 6f  ng file named fo
98c0: 72 0a 20 20 20 20 77 72 69 74 69 6e 67 20 69 73  r.    writing is
98d0: 20 61 6c 77 61 79 73 20 6f 76 65 72 77 72 69 74   always overwrit
98e0: 74 65 6e 2e 0a 0a 2a 20 20 20 44 6f 65 73 20 6e  ten...*   Does n
98f0: 6f 74 20 61 63 63 65 70 74 20 74 68 65 20 73 74  ot accept the st
9900: 61 6e 64 61 72 64 20 60 2b 60 20 6d 6f 64 69 66  andard `+` modif
9910: 69 65 72 20 74 6f 20 63 6f 6d 62 69 6e 65 20 72  ier to combine r
9920: 65 61 64 2f 77 72 69 74 65 0a 20 20 20 20 6d 6f  ead/write.    mo
9930: 64 65 73 3a 20 66 69 6c 65 73 20 61 72 65 20 6f  des: files are o
9940: 6e 6c 79 20 72 65 61 64 61 62 6c 65 20 6f 72 20  nly readable or 
9950: 6f 6e 6c 79 20 77 72 69 74 65 61 62 6c 65 20 75  only writeable u
9960: 6e 64 65 72 20 74 68 69 73 0a 20 20 20 20 69 6d  nder this.    im
9970: 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 20 20 4e  plementation.  N
9980: 65 69 74 68 65 72 20 69 73 20 69 74 20 70 6f 73  either is it pos
9990: 73 69 62 6c 65 20 74 6f 20 67 69 76 65 20 e2 80  sible to give 
99a0: 9c 60 72 77 60 e2 80 9d 2c 20 74 68 65 0a 20 20  `rw`”, the.  
99b0: 20 20 6e 6f 6e 73 74 61 6e 64 61 72 64 20 62 75    nonstandard bu
99c0: 74 20 77 69 64 65 6c 79 20 73 75 70 70 6f 72 74  t widely support
99d0: 65 64 20 77 61 79 20 74 6f 20 73 70 65 63 69 66  ed way to specif
99e0: 79 20 e2 80 9c 6f 70 65 6e 20 66 6f 72 0a 20 20  y “open for.  
99f0: 20 20 72 65 61 64 2f 77 72 69 74 65 e2 80 9d 2e    read/write”.
9a00: 0a 0a 2a 20 20 20 44 6f 65 73 20 6e 6f 74 20 73  ..*   Does not s
9a10: 75 70 70 6f 72 74 20 74 68 65 20 60 62 60 20 6d  upport the `b` m
9a20: 6f 64 69 66 69 65 72 20 66 6f 72 20 62 69 6e 61  odifier for bina
9a30: 72 79 20 49 2f 4f 3a 20 66 69 6c 65 73 20 61 72  ry I/O: files ar
9a40: 65 20 61 73 73 75 6d 65 64 0a 20 20 20 20 74 6f  e assumed.    to
9a50: 20 63 6f 6e 74 61 69 6e 20 41 53 43 49 49 20 74   contain ASCII t
9a60: 65 78 74 20 6f 6e 6c 79 2e 0a 0a 2a 20 20 20 44  ext only...*   D
9a70: 6f 65 73 20 6e 6f 74 20 64 69 61 67 6e 6f 73 65  oes not diagnose
9a80: 20 6e 75 6c 6c 20 70 6f 69 6e 74 65 72 73 20 61   null pointers a
9a90: 73 20 72 65 71 75 69 72 65 64 20 62 79 20 74 68  s required by th
9aa0: 65 20 53 74 61 6e 64 61 72 64 3a 20 69 74 20 77  e Standard: it w
9ab0: 69 6c 6c 0a 20 20 20 20 70 72 6f 62 61 62 6c 79  ill.    probably
9ac0: 20 64 6f 20 73 6f 6d 65 74 68 69 6e 67 20 73 69   do something si
9ad0: 6c 6c 79 20 6c 69 6b 65 20 72 65 66 65 72 65 6e  lly like referen
9ae0: 63 65 20 5b 63 6f 72 65 20 6d 65 6d 6f 72 79 20  ce [core memory 
9af0: 6c 6f 63 61 74 69 6f 6e 20 30 0a 20 20 20 20 69  location 0.    i
9b00: 6e 20 74 68 65 20 75 73 65 72 20 64 61 74 61 20  n the user data 
9b10: 66 69 65 6c 64 5d 28 23 75 64 66 29 2c 20 74 68  field](#udf), th
9b20: 65 6e 20 72 65 74 75 72 6e 20 77 69 74 68 6f 75  en return withou
9b30: 74 20 68 61 76 69 6e 67 20 64 6f 6e 65 0a 20 20  t having done.  
9b40: 20 20 61 6e 79 74 68 69 6e 67 20 75 73 65 66 75    anything usefu
9b50: 6c 2c 20 63 61 75 73 69 6e 67 20 74 68 65 20 73  l, causing the s
9b60: 75 62 73 65 71 75 65 6e 74 20 49 2f 4f 20 63 61  ubsequent I/O ca
9b70: 6c 6c 73 20 6f 6e 20 74 68 61 74 20 66 69 6c 65  lls on that file
9b80: 20 74 6f 0a 20 20 20 20 66 61 69 6c 2e 0a 0a 2a   to.    fail...*
9b90: 20 20 20 54 68 65 72 65 20 61 70 70 65 61 72 73     There appears
9ba0: 20 74 6f 20 62 65 20 61 20 62 75 67 20 69 6e 20   to be a bug in 
9bb0: 74 68 65 20 63 75 72 72 65 6e 74 20 69 6d 70 6c  the current impl
9bc0: 65 6d 65 6e 74 61 74 69 6f 6e 20 74 68 61 74 0a  ementation that.
9bd0: 20 20 20 20 72 65 71 75 69 72 65 73 20 79 6f 75      requires you
9be0: 20 74 6f 20 6f 70 65 6e 20 74 68 65 20 69 6e 70   to open the inp
9bf0: 75 74 20 66 69 6c 65 20 62 65 66 6f 72 65 20 6f  ut file before o
9c00: 70 65 6e 69 6e 67 20 61 6e 20 6f 75 74 70 75 74  pening an output
9c10: 20 66 69 6c 65 0a 20 20 20 20 77 68 65 6e 20 79   file.    when y
9c20: 6f 75 20 6e 65 65 64 20 62 6f 74 68 2e 20 20 49  ou need both.  I
9c30: 74 20 6d 61 79 20 6e 6f 74 20 62 65 20 70 6f 73  t may not be pos
9c40: 73 69 62 6c 65 20 74 6f 20 66 69 78 20 74 68 69  sible to fix thi
9c50: 73 20 77 69 74 68 69 6e 20 74 68 65 0a 20 20 20  s within the.   
9c60: 20 63 75 72 72 65 6e 74 20 6c 69 6d 69 74 61 74   current limitat
9c70: 69 6f 6e 73 20 6f 6e 20 74 68 65 20 6c 69 62 72  ions on the libr
9c80: 61 72 79 2c 20 62 75 74 20 69 66 20 79 6f 75 20  ary, but if you 
9c90: 63 6f 6d 65 20 75 70 20 77 69 74 68 0a 20 20 20  come up with.   
9ca0: 20 73 6f 6d 65 74 68 69 6e 67 2c 20 5b 77 65 20   something, [we 
9cb0: 61 63 63 65 70 74 20 70 61 74 63 68 65 73 5d 5b  accept patches][
9cc0: 68 61 6b 70 5d 2e 0a 0a 5b 68 61 6b 70 5d 3a 20  hakp]...[hakp]: 
9cd0: 2f 64 6f 63 2f 74 72 75 6e 6b 2f 43 4f 4e 54 52  /doc/trunk/CONTR
9ce0: 49 42 55 54 49 4e 47 2e 6d 64 23 70 61 74 63 68  IBUTING.md#patch
9cf0: 65 73 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22  es...### <a id="
9d00: 66 70 72 69 6e 74 66 22 3e 3c 2f 61 3e 60 66 70  fprintf"></a>`fp
9d10: 72 69 6e 74 66 28 66 6d 74 2c 20 61 72 67 73 2e  rintf(fmt, args.
9d20: 2e 2e 29 60 0a 0a 57 72 69 74 65 73 20 69 74 73  ..)`..Writes its
9d30: 20 61 72 67 75 6d 65 6e 74 73 20 28 60 61 72 67   arguments (`arg
9d40: 73 60 2e 2e 2e 29 20 74 6f 20 74 68 65 20 63 75  s`...) to the cu
9d50: 72 72 65 6e 74 6c 79 2d 6f 70 65 6e 65 64 20 6f  rrently-opened o
9d60: 75 74 70 75 74 20 66 69 6c 65 0a 61 63 63 6f 72  utput file.accor
9d70: 64 69 6e 67 20 74 6f 20 66 6f 72 6d 61 74 20 73  ding to format s
9d80: 74 72 69 6e 67 20 60 66 6d 74 60 2e 0a 0a 52 65  tring `fmt`...Re
9d90: 74 75 72 6e 73 20 74 68 65 20 6e 75 6d 62 65 72  turns the number
9da0: 20 6f 66 20 63 68 61 72 61 63 74 65 72 73 20 77   of characters w
9db0: 72 69 74 74 65 6e 20 74 6f 20 74 68 65 20 6f 75  ritten to the ou
9dc0: 74 70 75 74 20 66 69 6c 65 2e 0a 0a 54 68 69 73  tput file...This
9dd0: 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 6a 75 73   function is jus
9de0: 74 20 61 20 73 69 6d 70 6c 65 20 77 72 61 70 70  t a simple wrapp
9df0: 65 72 20 61 72 6f 75 6e 64 20 5b 60 70 72 69 6e  er around [`prin
9e00: 74 66 28 29 60 5d 28 23 70 72 69 6e 74 66 29 0a  tf()`](#printf).
9e10: 77 68 69 63 68 20 73 65 74 73 20 61 20 66 6c 61  which sets a fla
9e20: 67 20 74 68 61 74 20 63 61 75 73 65 73 20 60 70  g that causes `p
9e30: 72 69 6e 74 66 28 29 60 20 74 6f 20 77 72 69 74  rintf()` to writ
9e40: 65 20 74 68 65 20 66 6f 72 6d 61 74 74 65 64 20  e the formatted 
9e50: 73 74 72 69 6e 67 0a 74 6f 20 74 68 65 20 63 75  string.to the cu
9e60: 72 72 65 6e 74 20 6f 75 74 70 75 74 20 66 69 6c  rrent output fil
9e70: 65 20 75 73 69 6e 67 20 5b 60 66 70 75 74 73 28  e using [`fputs(
9e80: 29 60 5d 28 23 66 70 75 74 73 29 20 69 6e 73 74  )`](#fputs) inst
9e90: 65 61 64 20 6f 66 20 74 6f 0a 60 54 54 59 3a 60  ead of to.`TTY:`
9ea0: 2c 20 73 6f 20 79 6f 75 20 6d 75 73 74 20 72 65  , so you must re
9eb0: 61 64 20 74 68 6f 73 65 20 74 77 6f 20 66 75 6e  ad those two fun
9ec0: 63 74 69 6f 6e 73 e2 80 99 20 64 6f 63 75 6d 65  ctions’ docume
9ed0: 6e 74 61 74 69 6f 6e 20 74 6f 20 66 75 6c 6c 79  ntation to fully
9ee0: 0a 75 6e 64 65 72 73 74 61 6e 64 20 60 66 70 72  .understand `fpr
9ef0: 69 6e 74 66 28 29 60 2e 20 53 69 6e 63 65 20 60  intf()`. Since `
9f00: 70 72 69 6e 74 66 28 29 60 20 69 73 20 69 6e 20  printf()` is in 
9f10: 74 75 72 6e 20 62 61 73 65 64 20 6f 6e 0a 5b 60  turn based on.[`
9f20: 73 70 72 69 6e 74 66 28 29 60 5d 28 23 73 70 72  sprintf()`](#spr
9f30: 69 6e 74 66 29 2c 20 79 6f 75 20 6d 75 73 74 20  intf), you must 
9f40: 72 65 61 64 20 74 68 61 74 20 66 75 6e 63 74 69  read that functi
9f50: 6f 6e e2 80 99 73 20 64 6f 63 75 6d 65 6e 74 61  on’s documenta
9f60: 74 69 6f 6e 20 61 73 0a 77 65 6c 6c 2e 0a 0a 2a  tion as.well...*
9f70: 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74  *Standard Violat
9f80: 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 60 66 70  ions:**..*   `fp
9f90: 72 69 6e 74 66 60 20 64 6f 65 73 20 6e 6f 74 20  rintf` does not 
9fa0: 74 61 6b 65 20 61 20 60 46 49 4c 45 2a 60 20 70  take a `FILE*` p
9fb0: 6f 69 6e 74 65 72 20 61 73 20 69 74 73 20 66 69  ointer as its fi
9fc0: 72 73 74 20 61 72 67 75 6d 65 6e 74 2e 20 49 74  rst argument. It
9fd0: 0a 20 20 20 20 73 69 6d 70 6c 79 20 77 72 69 74  .    simply writ
9fe0: 65 73 20 74 6f 20 74 68 65 20 6f 6e 65 20 61 6e  es to the one an
9ff0: 64 20 6f 6e 6c 79 20 6f 75 74 70 75 74 20 66 69  d only output fi
a000: 6c 65 20 74 68 61 74 20 63 61 6e 20 62 65 20 6f  le that can be o
a010: 70 65 6e 65 64 20 61 74 0a 20 20 20 20 61 20 74  pened at.    a t
a020: 69 6d 65 20 62 79 20 5b 60 66 6f 70 65 6e 28 29  ime by [`fopen()
a030: 60 5d 28 23 66 6f 70 65 6e 29 2e 0a 0a 2a 20 20  `](#fopen)...*  
a040: 20 46 69 6c 65 20 49 2f 4f 20 65 72 72 6f 72 73   File I/O errors
a050: 20 61 72 65 20 6e 6f 74 20 64 69 61 67 6e 6f 73   are not diagnos
a060: 65 64 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d  ed....### <a id=
a070: 22 67 65 74 63 22 20 6e 61 6d 65 3d 22 66 67 65  "getc" name="fge
a080: 74 63 22 3e 3c 2f 61 3e 60 67 65 74 63 28 29 60  tc"></a>`getc()`
a090: 2c 20 60 66 67 65 74 63 28 29 60 0a 0a 52 65 61  , `fgetc()`..Rea
a0a0: 64 73 20 61 20 73 69 6e 67 6c 65 20 41 53 43 49  ds a single ASCI
a0b0: 49 20 63 68 61 72 61 63 74 65 72 20 66 72 6f 6d  I character from
a0c0: 20 60 54 54 59 3a 60 20 6f 72 20 66 72 6f 6d 20   `TTY:` or from 
a0d0: 74 68 65 20 6c 61 73 74 20 66 69 6c 65 20 6f 70  the last file op
a0e0: 65 6e 65 64 0a 66 6f 72 20 69 6e 70 75 74 20 62  ened.for input b
a0f0: 79 20 5b 60 66 6f 70 65 6e 28 29 60 5d 28 23 66  y [`fopen()`](#f
a100: 6f 70 65 6e 29 2c 20 72 65 73 70 65 63 74 69 76  open), respectiv
a110: 65 6c 79 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 64  ely...**Standard
a120: 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a   Violations:**..
a130: 2a 20 20 20 52 65 74 75 72 6e 73 20 41 53 43 49  *   Returns ASCI
a140: 49 20 4e 55 4c 20 28 30 29 20 74 6f 20 73 69 67  I NUL (0) to sig
a150: 6e 61 6c 20 45 4f 46 2c 20 6e 6f 74 20 61 6e 20  nal EOF, not an 
a160: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2d 64  implementation-d
a170: 65 66 69 6e 65 64 0a 20 20 20 20 6f 75 74 2d 6f  efined.    out-o
a180: 66 2d 72 61 6e 67 65 20 45 4f 46 20 63 6f 6e 73  f-range EOF cons
a190: 74 61 6e 74 2e 20 20 28 4d 6f 73 74 20 63 6f 6d  tant.  (Most com
a1a0: 6d 6f 6e 6c 79 20 2d 31 20 69 6e 20 6f 74 68 65  monly -1 in othe
a1b0: 72 20 43 20 6c 69 62 72 61 72 79 0a 20 20 20 20  r C library.    
a1c0: 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 73 2e  implementations.
a1d0: 29 20 20 53 69 6e 63 65 20 74 68 65 72 65 20 69  )  Since there i
a1e0: 73 20 6e 6f 20 60 66 65 6f 66 28 29 60 20 66 75  s no `feof()` fu
a1f0: 6e 63 74 69 6f 6e 20 69 6e 20 43 43 38 20 4c 49  nction in CC8 LI
a200: 42 43 0a 20 20 20 20 74 6f 20 64 69 73 61 6d 62  BC.    to disamb
a210: 69 67 75 61 74 65 20 74 68 65 20 63 61 73 65 73  iguate the cases
a220: 2c 20 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20  , this function 
a230: 63 61 6e 6e 6f 74 20 73 61 66 65 6c 79 20 62 65  cannot safely be
a240: 20 63 61 6c 6c 65 64 20 66 6f 72 0a 20 20 20 20   called for.    
a250: 66 69 6c 65 73 20 74 68 61 74 20 63 6f 75 6c 64  files that could
a260: 20 63 6f 6e 74 61 69 6e 20 61 20 30 20 62 79 74   contain a 0 byt
a270: 65 2c 20 73 69 6e 63 65 20 69 74 20 77 69 6c 6c  e, since it will
a280: 20 72 65 73 75 6c 74 20 69 6e 20 61 20 66 61 6c   result in a fal
a290: 73 65 0a 20 20 20 20 74 72 75 6e 63 61 74 69 6f  se.    truncatio
a2a0: 6e 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22  n....### <a id="
a2b0: 67 65 74 73 22 3e 3c 2f 61 3e 60 67 65 74 73 28  gets"></a>`gets(
a2c0: 73 29 60 0a 0a 52 65 61 64 73 20 61 20 73 74 72  s)`..Reads a str
a2d0: 69 6e 67 20 6f 66 20 41 53 43 49 49 20 63 68 61  ing of ASCII cha
a2e0: 72 61 63 74 65 72 73 20 66 72 6f 6d 20 60 54 54  racters from `TT
a2f0: 59 3a 60 2c 20 75 70 20 74 6f 20 61 6e 64 20 69  Y:`, up to and i
a300: 6e 63 6c 75 64 69 6e 67 20 74 68 65 0a 74 65 72  ncluding the.ter
a310: 6d 69 6e 61 74 69 6e 67 20 43 52 20 63 68 61 72  minating CR char
a320: 61 63 74 65 72 2c 20 73 74 6f 72 69 6e 67 20 69  acter, storing i
a330: 74 20 61 74 20 63 6f 72 65 20 6d 65 6d 6f 72 79  t at core memory
a340: 20 6c 6f 63 61 74 69 6f 6e 20 60 73 60 2c 20 61   location `s`, a
a350: 6e 64 0a 66 6f 6c 6c 6f 77 69 6e 67 20 74 68 65  nd.following the
a360: 20 74 65 72 6d 69 6e 61 74 69 6e 67 20 43 52 20   terminating CR 
a370: 77 69 74 68 20 61 20 4e 55 4c 20 63 68 61 72 61  with a NUL chara
a380: 63 74 65 72 2e 0a 0a 42 61 63 6b 73 70 61 63 65  cter...Backspace
a390: 20 63 68 61 72 61 63 74 65 72 73 20 66 72 6f 6d   characters from
a3a0: 20 74 68 65 20 74 65 72 6d 69 6e 61 6c 20 72 65   the terminal re
a3b0: 6d 6f 76 65 20 74 68 65 20 6c 61 73 74 20 63 68  move the last ch
a3c0: 61 72 61 63 74 65 72 20 66 72 6f 6d 0a 74 68 65  aracter from.the
a3d0: 20 73 74 72 69 6e 67 2e 0a 0a 52 65 74 75 72 6e   string...Return
a3e0: 73 20 74 68 65 20 70 61 73 73 65 64 20 73 74 72  s the passed str
a3f0: 69 6e 67 20 70 6f 69 6e 74 65 72 20 6f 6e 20 73  ing pointer on s
a400: 75 63 63 65 73 73 2e 0a 0a 2a 2a 53 74 61 6e 64  uccess...**Stand
a410: 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a  ard Violations:*
a420: 2a 0a 0a 2a 20 20 20 43 61 6e 6e 6f 74 20 72 65  *..*   Cannot re
a430: 74 75 72 6e 20 30 20 66 6f 72 20 e2 80 9c 6e 6f  turn 0 for “no
a440: 20 69 6e 70 75 74 e2 80 9d 20 61 73 20 53 74 61   input” as Sta
a450: 6e 64 61 72 64 20 43 20 72 65 71 75 69 72 65 73  ndard C requires
a460: 3a 20 61 6c 77 61 79 73 0a 20 20 20 20 73 75 63  : always.    suc
a470: 63 65 65 64 73 2e 0a 0a 0a 23 23 23 20 3c 61 20  ceeds....### <a 
a480: 69 64 3d 22 69 73 61 6c 6e 75 6d 22 3e 3c 2f 61  id="isalnum"></a
a490: 3e 60 69 73 61 6c 6e 75 6d 28 63 29 60 0a 0a 52  >`isalnum(c)`..R
a4a0: 65 74 75 72 6e 73 20 6e 6f 6e 7a 65 72 6f 20 69  eturns nonzero i
a4b0: 66 20 65 69 74 68 65 72 20 5b 60 69 73 64 69 67  f either [`isdig
a4c0: 69 74 28 29 60 5d 28 23 69 73 64 69 67 69 74 29  it()`](#isdigit)
a4d0: 20 6f 72 0a 5b 60 69 73 61 6c 70 68 61 28 29 60   or.[`isalpha()`
a4e0: 5d 28 23 69 73 61 6c 70 68 61 29 20 72 65 74 75  ](#isalpha) retu
a4f0: 72 6e 73 20 6e 6f 6e 7a 65 72 6f 20 66 6f 72 20  rns nonzero for 
a500: 60 63 60 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 64  `c`...**Standard
a510: 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a   Violations:**..
a520: 2a 20 20 20 44 6f 65 73 20 6e 6f 74 20 6b 6e 6f  *   Does not kno
a530: 77 20 61 6e 79 74 68 69 6e 67 20 61 62 6f 75 74  w anything about
a540: 20 6c 6f 63 61 6c 65 73 3b 20 61 73 73 75 6d 65   locales; assume
a550: 73 20 55 53 2d 41 53 43 49 49 20 69 6e 70 75 74  s US-ASCII input
a560: 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 69  ....### <a id="i
a570: 73 61 6c 70 68 61 22 3e 3c 2f 61 3e 60 69 73 61  salpha"></a>`isa
a580: 6c 70 68 61 28 63 29 60 0a 0a 52 65 74 75 72 6e  lpha(c)`..Return
a590: 73 20 6e 6f 6e 7a 65 72 6f 20 69 66 20 74 68 65  s nonzero if the
a5a0: 20 70 61 73 73 65 64 20 63 68 61 72 61 63 74 65   passed characte
a5b0: 72 20 60 63 60 20 69 73 20 65 69 74 68 65 72 20  r `c` is either 
a5c0: 62 65 74 77 65 65 6e 20 36 35 20 61 6e 64 20 39  between 65 and 9
a5d0: 30 0a 6f 72 20 62 65 74 77 65 65 6e 20 39 37 20  0.or between 97 
a5e0: 61 6e 64 20 31 32 32 20 69 6e 63 6c 75 73 69 76  and 122 inclusiv
a5f0: 65 2c 20 62 65 69 6e 67 20 74 68 65 20 41 53 43  e, being the ASC
a600: 49 49 20 61 6c 70 68 61 62 65 74 69 63 20 63 68  II alphabetic ch
a610: 61 72 61 63 74 65 72 73 2e 0a 0a 2a 2a 53 74 61  aracters...**Sta
a620: 6e 64 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e 73  ndard Violations
a630: 3a 2a 2a 0a 0a 2a 20 20 20 44 6f 65 73 20 6e 6f  :**..*   Does no
a640: 74 20 6b 6e 6f 77 20 61 6e 79 74 68 69 6e 67 20  t know anything 
a650: 61 62 6f 75 74 20 6c 6f 63 61 6c 65 73 3b 20 61  about locales; a
a660: 73 73 75 6d 65 73 20 55 53 2d 41 53 43 49 49 20  ssumes US-ASCII 
a670: 69 6e 70 75 74 2e 0a 0a 0a 23 23 23 20 3c 61 20  input....### <a 
a680: 69 64 3d 22 69 73 64 69 67 69 74 22 20 6e 61 6d  id="isdigit" nam
a690: 65 3d 22 69 73 6e 75 6d 22 3e 3c 2f 61 3e 60 69  e="isnum"></a>`i
a6a0: 73 64 69 67 69 74 28 63 29 60 2c 20 60 69 73 6e  sdigit(c)`, `isn
a6b0: 75 6d 28 63 29 60 0a 0a 52 65 74 75 72 6e 73 20  um(c)`..Returns 
a6c0: 6e 6f 6e 7a 65 72 6f 20 69 66 20 74 68 65 20 70  nonzero if the p
a6d0: 61 73 73 65 64 20 63 68 61 72 61 63 74 65 72 20  assed character 
a6e0: 60 63 60 20 69 73 20 62 65 74 77 65 65 6e 20 34  `c` is between 4
a6f0: 38 20 61 6e 20 35 37 2c 0a 69 6e 63 6c 75 73 69  8 an 57,.inclusi
a700: 76 65 2c 20 62 65 69 6e 67 20 74 68 65 20 41 53  ve, being the AS
a710: 43 49 49 20 64 65 63 69 6d 61 6c 20 64 69 67 69  CII decimal digi
a720: 74 20 63 68 61 72 61 63 74 65 72 73 2e 0a 0a 2a  t characters...*
a730: 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74  *Standard Violat
a740: 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 60 69 73  ions:**..*   `is
a750: 6e 75 6d 60 20 69 73 20 61 20 6e 6f 6e 73 74 61  num` is a nonsta
a760: 6e 64 61 72 64 20 61 6c 69 61 73 20 66 6f 72 20  ndard alias for 
a770: 60 69 73 64 69 67 69 74 60 20 63 6f 6e 66 6f 72  `isdigit` confor
a780: 6d 69 6e 67 20 74 6f 20 6e 6f 20 6f 74 68 65 72  ming to no other
a790: 0a 20 20 20 20 6b 6e 6f 77 6e 20 43 20 6c 69 62  .    known C lib
a7a0: 72 61 72 79 20 69 6d 70 6c 65 6d 65 6e 74 61 74  rary implementat
a7b0: 69 6f 6e 2e 20 20 42 6f 74 68 20 61 72 65 20 69  ion.  Both are i
a7c0: 6d 70 6c 65 6d 65 6e 74 65 64 20 77 69 74 68 20  mplemented with 
a7d0: 74 68 65 20 73 61 6d 65 0a 20 20 20 20 4c 49 42  the same.    LIB
a7e0: 43 20 63 6f 64 65 2e 0a 0a 2a 20 20 20 44 6f 65  C code...*   Doe
a7f0: 73 20 6e 6f 74 20 6b 6e 6f 77 20 61 6e 79 74 68  s not know anyth
a800: 69 6e 67 20 61 62 6f 75 74 20 6c 6f 63 61 6c 65  ing about locale
a810: 73 3b 20 61 73 73 75 6d 65 73 20 55 53 2d 41 53  s; assumes US-AS
a820: 43 49 49 20 69 6e 70 75 74 2e 0a 0a 0a 23 23 23  CII input....###
a830: 20 3c 61 20 69 64 3d 22 69 73 73 70 61 63 65 22   <a id="isspace"
a840: 3e 3c 2f 61 3e 60 69 73 73 70 61 63 65 28 63 29  ></a>`isspace(c)
a850: 60 0a 0a 52 65 74 75 72 6e 73 20 6e 6f 6e 7a 65  `..Returns nonze
a860: 72 6f 20 69 66 20 74 68 65 20 70 61 73 73 65 64  ro if the passed
a870: 20 63 68 61 72 61 63 74 65 72 20 60 63 60 20 69   character `c` i
a880: 73 20 63 6f 6e 73 69 64 65 72 65 64 20 61 20 e2  s considered a 
a890: 80 9c 77 68 69 74 65 73 70 61 63 65 e2 80 9d 0a  whitespace”.
a8a0: 63 68 61 72 61 63 74 65 72 2e 0a 0a 54 68 69 73  character...This
a8b0: 20 66 75 6e 63 74 69 6f 6e 20 69 73 20 6e 6f 74   function is not
a8c0: 20 75 73 65 64 20 62 79 20 60 61 74 6f 69 60 3a   used by `atoi`:
a8d0: 20 69 74 73 20 77 68 69 74 65 73 70 61 63 65 20   its whitespace 
a8e0: 6d 61 74 63 68 69 6e 67 20 69 73 0a 68 61 72 64  matching is.hard
a8f0: 2d 63 6f 64 65 64 20 69 6e 74 65 72 6e 61 6c 6c  -coded internall
a900: 79 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56  y...**Standard V
a910: 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20  iolations:**..* 
a920: 20 20 57 68 69 74 65 73 70 61 63 65 20 69 73 20    Whitespace is 
a930: 63 75 72 72 65 6e 74 6c 79 20 64 65 66 69 6e 65  currently define
a940: 64 20 61 73 20 41 53 43 49 49 20 31 20 74 68 72  d as ASCII 1 thr
a950: 6f 75 67 68 20 33 32 2c 20 69 6e 63 6c 75 73 69  ough 32, inclusi
a960: 76 65 2e 0a 20 20 20 20 59 65 73 2c 20 74 68 69  ve..    Yes, thi
a970: 73 20 69 73 20 61 20 2a 76 61 73 74 2a 20 6f 76  s is a *vast* ov
a980: 65 72 72 65 61 63 68 2e 0a 0a 0a 23 23 23 20 3c  erreach....### <
a990: 61 20 69 64 3d 22 69 74 6f 61 22 3e 3c 2f 61 3e  a id="itoa"></a>
a9a0: 60 69 74 6f 61 28 6e 75 6d 2c 20 73 74 72 2c 20  `itoa(num, str, 
a9b0: 72 61 64 69 78 29 60 0a 0a 43 6f 6e 76 65 72 74  radix)`..Convert
a9c0: 20 61 20 31 32 2d 62 69 74 20 50 44 50 2d 38 20   a 12-bit PDP-8 
a9d0: 69 6e 74 65 67 65 72 20 60 6e 75 6d 60 20 74 6f  integer `num` to
a9e0: 20 61 6e 20 5b 41 53 43 49 49 20 77 6f 72 64 20   an [ASCII word 
a9f0: 73 74 72 69 6e 67 5d 28 23 77 6f 72 64 73 74 72  string](#wordstr
aa00: 29 0a 65 78 70 72 65 73 73 69 6e 67 20 74 68 61  ).expressing tha
aa10: 74 20 6e 75 6d 62 65 72 20 69 6e 20 74 68 65 20  t number in the 
aa20: 67 69 76 65 6e 20 60 72 61 64 69 78 60 2c 20 73  given `radix`, s
aa30: 74 6f 72 65 64 20 69 6e 20 6d 65 6d 6f 72 79 20  tored in memory 
aa40: 70 6f 69 6e 74 65 64 20 74 6f 0a 62 79 20 60 73  pointed to.by `s
aa50: 74 72 60 2e 0a 0a 49 66 20 60 72 61 64 69 78 60  tr`...If `radix`
aa60: 20 69 73 20 31 30 2c 20 60 6e 75 6d 60 20 69 73   is 10, `num` is
aa70: 20 74 72 65 61 74 65 64 20 61 73 20 61 20 74 77   treated as a tw
aa80: 6f e2 80 99 73 20 63 6f 6d 70 6c 65 6d 65 6e 74  o’s complement
aa90: 20 69 6e 74 65 67 65 72 2c 20 73 6f 0a 74 68 61   integer, so.tha
aaa0: 74 20 60 73 74 72 5b 30 5d 20 3d 3d 20 27 2d 27  t `str[0] == '-'
aab0: 60 20 66 6f 72 20 6e 65 67 61 74 69 76 65 20 6e  ` for negative n
aac0: 75 6d 62 65 72 73 2e 0a 0a 46 6f 72 20 6f 74 68  umbers...For oth
aad0: 65 72 20 72 61 64 69 63 65 73 2c 20 60 6e 75 6d  er radices, `num
aae0: 60 20 69 73 20 74 72 65 61 74 65 64 20 61 73 20  ` is treated as 
aaf0: 61 6e 20 75 6e 73 69 67 6e 65 64 20 76 61 6c 75  an unsigned valu
ab00: 65 2e 0a 0a 52 61 64 69 63 65 73 20 62 65 79 6f  e...Radices beyo
ab10: 6e 64 20 31 30 20 75 73 65 20 41 53 43 49 49 20  nd 10 use ASCII 
ab20: 63 68 61 72 61 63 74 65 72 73 20 69 6e 20 74 68  characters in th
ab30: 65 20 72 61 6e 67 65 20 e2 80 9c 60 61 60 e2 80  e range “`a`
ab40: 9d 20 75 70 77 61 72 64 20 66 6f 72 0a 64 69 67   upward for.dig
ab50: 69 74 73 2c 20 67 69 76 69 6e 67 20 61 20 70 72  its, giving a pr
ab60: 61 63 74 69 63 61 6c 20 6c 69 6d 69 74 20 6f 66  actical limit of
ab70: 20 62 61 73 65 20 33 36 2c 20 74 68 6f 75 67 68   base 36, though
ab80: 20 74 68 69 73 20 69 73 20 6e 6f 74 20 63 68 65   this is not che
ab90: 63 6b 65 64 0a 69 6e 20 74 68 65 20 63 6f 64 65  cked.in the code
aba0: 2e 20 20 57 65 20 63 68 6f 73 65 20 74 6f 20 75  .  We chose to u
abb0: 73 65 20 6c 6f 77 65 72 63 61 73 65 20 6c 65 74  se lowercase let
abc0: 74 65 72 73 20 62 65 63 61 75 73 65 20 63 6f 6e  ters because con
abd0: 76 65 72 73 69 6f 6e 20 74 6f 0a 75 70 70 65 72  version to.upper
abe0: 63 61 73 65 20 69 73 20 65 61 73 69 6c 79 20 64  case is easily d
abf0: 6f 6e 65 20 77 69 74 68 20 74 68 65 20 65 78 69  one with the exi
ac00: 73 74 69 6e 67 20 5b 60 63 75 70 70 65 72 28 29  sting [`cupper()
ac10: 60 5d 28 23 63 75 70 70 65 72 29 0a 66 75 6e 63  `](#cupper).func
ac20: 74 69 6f 6e 2c 20 77 68 69 63 68 20 77 65 20 6e  tion, which we n
ac30: 65 65 64 20 61 6e 79 77 61 79 2c 20 77 68 65 72  eed anyway, wher
ac40: 65 61 73 20 74 68 65 20 72 65 76 65 72 73 65 20  eas the reverse 
ac50: 63 6f 6e 76 65 72 73 69 6f 6e 20 77 6f 75 6c 64  conversion would
ac60: 0a 68 61 76 65 20 72 65 71 75 69 72 65 64 20 65  .have required e
ac70: 78 74 72 61 20 63 6f 64 65 20 73 70 61 63 65 2c  xtra code space,
ac80: 20 61 20 70 72 65 63 69 6f 75 73 20 63 6f 6d 6d   a precious comm
ac90: 6f 64 69 74 79 20 69 6e 20 74 68 65 20 50 44 50  odity in the PDP
aca0: 2d 38 2e 0a 0a 54 68 69 73 20 66 75 6e 63 74 69  -8...This functi
acb0: 6f 6e 20 64 6f 65 73 20 6e 6f 74 20 63 68 65 63  on does not chec
acc0: 6b 20 66 6f 72 20 73 75 66 66 69 63 69 65 6e 74  k for sufficient
acd0: 20 62 75 66 66 65 72 20 73 70 61 63 65 20 62 65   buffer space be
ace0: 66 6f 72 65 0a 62 65 67 69 6e 6e 69 6e 67 20 77  fore.beginning w
acf0: 6f 72 6b 2e 20 46 6f 72 20 72 61 64 69 78 20 31  ork. For radix 1
ad00: 30 2c 20 69 66 20 74 68 65 20 62 6f 75 6e 64 73  0, if the bounds
ad10: 20 6f 6e 20 60 6e 75 6d 60 20 61 72 65 20 6e 6f   on `num` are no
ad20: 74 20 6b 6e 6f 77 6e 20 69 6e 0a 61 64 76 61 6e  t known in.advan
ad30: 63 65 2c 20 60 73 74 72 60 20 73 68 6f 75 6c 64  ce, `str` should
ad40: 20 70 6f 69 6e 74 20 74 6f 20 36 20 77 6f 72 64   point to 6 word
ad50: 73 20 6f 66 20 6d 65 6d 6f 72 79 20 74 6f 20 63  s of memory to c
ad60: 6f 76 65 72 20 74 68 65 20 77 6f 72 73 74 2d 63  over the worst-c
ad70: 61 73 65 0a 63 6f 6e 64 69 74 69 6f 6e 2c 20 65  ase.condition, e
ad80: 2e 67 2e 20 22 2d 31 32 33 34 5c 5c 30 22 2e 20  .g. "-1234\\0". 
ad90: 4c 6f 77 65 72 20 72 61 64 69 63 65 73 20 67 65  Lower radices ge
ada0: 6e 65 72 61 6c 6c 79 20 72 65 71 75 69 72 65 20  nerally require 
adb0: 6d 6f 72 65 0a 73 74 6f 72 61 67 65 20 73 70 61  more.storage spa
adc0: 63 65 2e 0a 0a 54 68 65 72 65 20 69 73 20 6e 6f  ce...There is no
add0: 20 74 68 6f 75 73 61 6e 64 73 20 73 65 70 61 72   thousands separ
ade0: 61 74 6f 72 20 69 6e 20 74 68 65 20 6f 75 74 70  ator in the outp
adf0: 75 74 20 73 74 72 69 6e 67 2e 0a 0a 2a 2a 4e 6f  ut string...**No
ae00: 6e 73 74 61 6e 64 61 72 64 2e 2a 2a 20 45 6d 75  nstandard.** Emu
ae10: 6c 61 74 65 73 20 74 68 65 20 60 69 74 6f 61 28  lates the `itoa(
ae20: 29 60 20 66 75 6e 63 74 69 6f 6e 20 61 73 20 64  )` function as d
ae30: 65 66 69 6e 65 64 20 69 6e 20 74 68 65 0a 5b 56  efined in the.[V
ae40: 69 73 75 61 6c 20 43 2b 2b 5d 5b 69 74 6f 61 6d  isual C++][itoam
ae50: 5d 20 61 6e 64 20 5b 45 6d 62 61 72 63 61 64 65  ] and [Embarcade
ae60: 72 6f 20 43 2b 2b 5d 5b 69 74 6f 61 65 5d 20 72  ro C++][itoae] r
ae70: 65 66 65 72 65 6e 63 65 20 6d 61 6e 75 61 6c 73  eference manuals
ae80: 2e 0a 0a 5b 69 74 6f 61 65 5d 3a 20 68 74 74 70  ...[itoae]: http
ae90: 3a 2f 2f 64 6f 63 73 2e 65 6d 62 61 72 63 61 64  ://docs.embarcad
aea0: 65 72 6f 2e 63 6f 6d 2f 70 72 6f 64 75 63 74 73  ero.com/products
aeb0: 2f 72 61 64 5f 73 74 75 64 69 6f 2f 72 61 64 73  /rad_studio/rads
aec0: 74 75 64 69 6f 32 30 30 37 2f 52 53 32 30 30 37  tudio2007/RS2007
aed0: 5f 68 65 6c 70 75 70 64 61 74 65 73 2f 48 55 70  _helpupdates/HUp
aee0: 64 61 74 65 34 2f 45 4e 2f 68 74 6d 6c 2f 64 65  date4/EN/html/de
aef0: 76 77 69 6e 33 32 2f 69 74 6f 61 5f 78 6d 6c 2e  vwin32/itoa_xml.
af00: 68 74 6d 6c 0a 5b 69 74 6f 61 6d 5d 3a 20 68 74  html.[itoam]: ht
af10: 74 70 73 3a 2f 2f 64 6f 63 73 2e 6d 69 63 72 6f  tps://docs.micro
af20: 73 6f 66 74 2e 63 6f 6d 2f 63 70 70 2f 63 2d 72  soft.com/cpp/c-r
af30: 75 6e 74 69 6d 65 2d 6c 69 62 72 61 72 79 2f 72  untime-library/r
af40: 65 66 65 72 65 6e 63 65 2f 69 74 6f 61 2d 69 74  eference/itoa-it
af50: 6f 77 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22  ow...### <a id="
af60: 6b 62 68 69 74 22 3e 3c 2f 61 3e 60 6b 62 68 69  kbhit"></a>`kbhi
af70: 74 28 29 60 0a 0a 52 65 74 75 72 6e 73 20 6e 6f  t()`..Returns no
af80: 6e 7a 65 72 6f 20 69 66 20 60 54 54 59 3a 60 20  nzero if `TTY:` 
af90: 68 61 73 20 73 65 6e 74 20 61 6e 20 69 6e 70 75  has sent an inpu
afa0: 74 20 63 68 61 72 61 63 74 65 72 20 74 68 61 74  t character that
afb0: 20 68 61 73 20 6e 6f 74 20 79 65 74 0a 62 65 65   has not yet.bee
afc0: 6e 20 72 65 61 64 2c 20 77 68 69 63 68 20 6d 61  n read, which ma
afd0: 79 20 74 68 65 6e 20 62 65 20 72 65 61 64 20 62  y then be read b
afe0: 79 20 61 20 73 75 62 73 65 71 75 65 6e 74 20 63  y a subsequent c
aff0: 61 6c 6c 20 74 6f 0a 5b 60 67 65 74 63 28 29 60  all to.[`getc()`
b000: 5d 28 28 23 67 65 74 63 29 2e 20 52 65 74 75 72  ]((#getc). Retur
b010: 6e 73 20 30 20 6f 74 68 65 72 77 69 73 65 2e 0a  ns 0 otherwise..
b020: 0a 54 68 69 73 20 66 75 6e 63 74 69 6f 6e e2 80  .This function
b030: 99 73 20 69 6e 74 65 6e 64 65 64 20 70 75 72 70  s intended purp
b040: 6f 73 65 20 69 73 20 74 6f 20 6c 65 74 20 74 68  ose is to let th
b050: 65 20 70 72 6f 67 72 61 6d 20 64 6f 20 77 6f 72  e program do wor
b060: 6b 20 77 68 69 6c 65 0a 77 61 69 74 69 6e 67 20  k while.waiting 
b070: 66 6f 72 20 6b 65 79 62 6f 61 72 64 2c 20 73 69  for keyboard, si
b080: 6e 63 65 20 63 61 6c 6c 69 6e 67 20 60 67 65 74  nce calling `get
b090: 63 28 29 60 20 62 65 66 6f 72 65 20 69 6e 70 75  c()` before inpu
b0a0: 74 20 69 73 20 61 76 61 69 6c 61 62 6c 65 0a 77  t is available.w
b0b0: 6f 75 6c 64 20 62 6c 6f 63 6b 20 74 68 65 20 70  ould block the p
b0c0: 72 6f 67 72 61 6d 2e 0a 0a 2a 2a 4e 6f 6e 73 74  rogram...**Nonst
b0d0: 61 6e 64 61 72 64 2e 2a 2a 20 45 6d 75 6c 61 74  andard.** Emulat
b0e0: 65 73 20 61 20 66 75 6e 63 74 69 6f 6e 20 63 6f  es a function co
b0f0: 6d 6d 6f 6e 20 69 6e 20 44 4f 53 20 43 20 6c 69  mmon in DOS C li
b100: 62 72 61 72 69 65 73 20 6f 72 20 74 68 6f 73 65  braries or those
b110: 0a 64 65 73 63 65 6e 64 65 64 20 66 72 6f 6d 20  .descended from 
b120: 74 68 65 6d 2c 20 73 75 63 68 20 61 73 20 5b 45  them, such as [E
b130: 6d 62 61 72 63 61 64 65 72 6f 20 43 2b 2b 5d 5b  mbarcadero C++][
b140: 6b 62 68 69 74 65 5d 20 61 6e 64 20 5b 56 69 73  kbhite] and [Vis
b150: 75 61 6c 0a 43 2b 2b 5d 5b 6b 62 68 69 74 6d 5d  ual.C++][kbhitm]
b160: 2e 0a 0a 5b 6b 62 68 69 74 65 5d 3a 20 68 74 74  ...[kbhite]: htt
b170: 70 3a 2f 2f 64 6f 63 73 2e 65 6d 62 61 72 63 61  p://docs.embarca
b180: 64 65 72 6f 2e 63 6f 6d 2f 70 72 6f 64 75 63 74  dero.com/product
b190: 73 2f 72 61 64 5f 73 74 75 64 69 6f 2f 72 61 64  s/rad_studio/rad
b1a0: 73 74 75 64 69 6f 32 30 30 37 2f 52 53 32 30 30  studio2007/RS200
b1b0: 37 5f 68 65 6c 70 75 70 64 61 74 65 73 2f 48 55  7_helpupdates/HU
b1c0: 70 64 61 74 65 34 2f 45 4e 2f 68 74 6d 6c 2f 64  pdate4/EN/html/d
b1d0: 65 76 77 69 6e 33 32 2f 6b 62 68 69 74 5f 78 6d  evwin32/kbhit_xm
b1e0: 6c 2e 68 74 6d 6c 0a 5b 6b 62 68 69 74 6d 5d 3a  l.html.[kbhitm]:
b1f0: 20 68 74 74 70 73 3a 2f 2f 64 6f 63 73 2e 6d 69   https://docs.mi
b200: 63 72 6f 73 6f 66 74 2e 63 6f 6d 2f 63 70 70 2f  crosoft.com/cpp/
b210: 63 2d 72 75 6e 74 69 6d 65 2d 6c 69 62 72 61 72  c-runtime-librar
b220: 79 2f 72 65 66 65 72 65 6e 63 65 2f 6b 62 68 69  y/reference/kbhi
b230: 74 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 6d  t...### <a id="m
b240: 65 6d 63 70 79 22 3e 3c 2f 61 3e 60 6d 65 6d 63  emcpy"></a>`memc
b250: 70 79 28 64 73 74 2c 20 73 72 63 2c 20 6e 29 60  py(dst, src, n)`
b260: 0a 0a 43 6f 70 69 65 73 20 60 6e 60 20 77 6f 72  ..Copies `n` wor
b270: 64 73 20 66 72 6f 6d 20 63 6f 72 65 20 6d 65 6d  ds from core mem
b280: 6f 72 79 20 6c 6f 63 61 74 69 6f 6e 20 60 73 72  ory location `sr
b290: 63 60 20 74 6f 20 60 64 73 74 60 20 69 6e 20 74  c` to `dst` in t
b2a0: 68 65 20 5b 75 73 65 72 0a 64 61 74 61 20 66 69  he [user.data fi
b2b0: 65 6c 64 5d 28 23 6d 65 6d 6f 72 79 29 2e 0a 0a  eld](#memory)...
b2c0: 42 65 77 61 72 65 20 74 68 61 74 20 74 68 65 20  Beware that the 
b2d0: 63 6f 70 79 20 77 69 6c 6c 20 5b 77 72 61 70 20  copy will [wrap 
b2e0: 61 72 6f 75 6e 64 5d 28 23 70 74 72 77 72 61 70  around](#ptrwrap
b2f0: 29 20 74 6f 20 74 68 65 20 62 65 67 69 6e 6e 69  ) to the beginni
b300: 6e 67 20 6f 66 0a 74 68 65 20 66 69 65 6c 64 20  ng of.the field 
b310: 69 66 20 65 69 74 68 65 72 20 60 73 72 63 2b 6e  if either `src+n
b320: 60 20 6f 72 20 60 64 73 74 2b 6e 60 20 26 67 65  ` or `dst+n` &ge
b330: 3b 20 34 30 39 36 2e 0a 0a 54 68 65 20 60 64 73  ; 4096...The `ds
b340: 74 60 20 62 75 66 66 65 72 20 63 61 6e 20 73 61  t` buffer can sa
b350: 66 65 6c 79 20 6f 76 65 72 6c 61 70 20 74 68 65  fely overlap the
b360: 20 60 73 72 63 60 20 62 75 66 66 65 72 20 6f 6e   `src` buffer on
b370: 6c 79 20 69 66 20 69 74 20 69 73 20 61 74 20 61  ly if it is at a
b380: 0a 6c 6f 77 65 72 20 61 64 64 72 65 73 73 20 69  .lower address i
b390: 6e 20 6d 65 6d 6f 72 79 2e 20 28 4e 6f 74 65 20  n memory. (Note 
b3a0: 74 68 61 74 20 74 68 65 72 65 20 69 73 20 6e 6f  that there is no
b3b0: 20 60 6d 65 6d 6d 6f 76 65 28 29 60 20 69 6e 20   `memmove()` in 
b3c0: 74 68 69 73 0a 69 6d 70 6c 65 6d 65 6e 74 61 74  this.implementat
b3d0: 69 6f 6e 2e 29 0a 0a 2a 2a 53 74 61 6e 64 61 72  ion.)..**Standar
b3e0: 64 20 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a  d Violations:**.
b3f0: 0a 2a 20 20 20 52 65 74 75 72 6e 73 20 30 20 69  .*   Returns 0 i
b400: 6e 73 74 65 61 64 20 6f 66 20 74 68 65 20 60 64  nstead of the `d
b410: 73 74 60 20 70 6f 69 6e 74 65 72 20 61 73 20 72  st` pointer as r
b420: 65 71 75 69 72 65 64 20 62 79 20 74 68 65 20 53  equired by the S
b430: 74 61 6e 64 61 72 64 2e 0a 20 20 20 20 41 20 4e  tandard..    A N
b440: 55 4c 4c 20 72 65 74 75 72 6e 20 69 73 20 73 70  ULL return is sp
b450: 65 63 69 66 69 65 64 20 61 73 20 61 20 66 61 69  ecified as a fai
b460: 6c 75 72 65 20 63 6f 6e 64 69 74 69 6f 6e 20 62  lure condition b
b470: 79 20 74 68 65 20 53 74 61 6e 64 61 72 64 2e 0a  y the Standard..
b480: 0a 20 20 20 20 54 68 69 73 20 66 75 6e 63 74 69  .    This functi
b490: 6f 6e 20 68 61 73 20 6e 6f 20 69 6e 74 65 72 6e  on has no intern
b4a0: 61 6c 6c 79 2d 64 65 74 65 63 74 65 64 20 66 61  ally-detected fa
b4b0: 69 6c 75 72 65 20 63 61 73 65 73 2c 20 73 6f 20  ilure cases, so 
b4c0: 74 68 65 72 65 20 69 73 0a 20 20 20 20 6e 6f 20  there is.    no 
b4d0: 61 6d 62 69 67 75 69 74 79 20 69 6e 20 74 68 65  ambiguity in the
b4e0: 20 6d 65 61 6e 69 6e 67 20 6f 66 20 74 68 65 20   meaning of the 
b4f0: 72 65 74 75 72 6e 20 76 61 6c 75 65 2e 0a 0a 0a  return value....
b500: 23 23 23 20 3c 61 20 69 64 3d 22 6d 65 6d 73 65  ### <a id="memse
b510: 74 22 3e 3c 2f 61 3e 60 6d 65 6d 73 65 74 28 64  t"></a>`memset(d
b520: 73 74 2c 20 63 2c 20 6c 65 6e 29 60 0a 0a 53 65  st, c, len)`..Se
b530: 74 73 20 61 20 72 75 6e 20 6f 66 20 60 6c 65 6e  ts a run of `len
b540: 60 20 63 6f 72 65 20 6d 65 6d 6f 72 79 20 6c 6f  ` core memory lo
b550: 63 61 74 69 6f 6e 73 20 73 74 61 72 74 69 6e 67  cations starting
b560: 20 61 74 20 60 64 73 74 60 20 74 6f 20 60 63 60   at `dst` to `c`
b570: 2e 0a 0a 42 65 77 61 72 65 20 74 68 61 74 20 74  ...Beware that t
b580: 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 77 69 6c  his function wil
b590: 6c 20 5b 77 72 61 70 20 61 72 6f 75 6e 64 5d 28  l [wrap around](
b5a0: 23 70 74 72 77 72 61 70 29 20 69 66 20 60 64 73  #ptrwrap) if `ds
b5b0: 74 2b 6c 65 6e 2d 31 60 0a 26 67 65 3b 20 34 30  t+len-1`.&ge; 40
b5c0: 39 36 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20  96...**Standard 
b5d0: 56 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a  Violations:**..*
b5e0: 20 20 20 52 65 74 75 72 6e 73 20 30 20 69 6e 73     Returns 0 ins
b5f0: 74 65 61 64 20 6f 66 20 74 68 65 20 60 64 73 74  tead of the `dst
b600: 60 20 70 6f 69 6e 74 65 72 20 61 73 20 72 65 71  ` pointer as req
b610: 75 69 72 65 64 20 62 79 20 74 68 65 20 53 74 61  uired by the Sta
b620: 6e 64 61 72 64 2e 0a 0a 2a 20 20 20 54 68 69 73  ndard...*   This
b630: 20 66 75 6e 63 74 69 6f 6e 20 68 61 73 20 6e 6f   function has no
b640: 20 69 6e 74 65 72 6e 61 6c 6c 79 2d 64 65 74 65   internally-dete
b650: 63 74 65 64 20 66 61 69 6c 75 72 65 20 63 61 73  cted failure cas
b660: 65 73 2c 20 73 6f 20 74 68 65 0a 20 20 20 20 53  es, so the.    S
b670: 74 61 6e 64 61 72 64 e2 80 99 73 20 72 65 71 75  tandard’s requ
b680: 69 72 65 6d 65 6e 74 20 74 68 61 74 20 74 68 69  irement that thi
b690: 73 20 66 75 6e 63 74 69 6f 6e 20 72 65 74 75 72  s function retur
b6a0: 6e 20 30 20 69 6e 20 65 72 72 6f 72 20 63 61 73  n 0 in error cas
b6b0: 65 73 0a 20 20 20 20 6d 65 61 6e 73 20 74 68 65  es.    means the
b6c0: 72 65 20 69 73 20 6e 6f 20 61 6d 62 69 67 75 69  re is no ambigui
b6d0: 74 79 20 69 6e 20 74 68 65 20 6d 65 61 6e 69 6e  ty in the meanin
b6e0: 67 20 6f 66 20 74 68 65 20 72 65 74 75 72 6e 20  g of the return 
b6f0: 76 61 6c 75 65 2e 0a 0a 20 20 20 20 49 66 20 77  value...    If w
b700: 65 20 65 76 65 72 20 66 69 78 20 74 68 65 20 70  e ever fix the p
b710: 72 69 6f 72 20 76 69 6f 6c 61 74 69 6f 6e 2c 20  rior violation, 
b720: 74 68 65 72 65 20 77 69 6c 6c 20 73 74 69 6c 6c  there will still
b730: 20 62 65 20 6e 6f 20 61 6d 62 69 67 75 69 74 79   be no ambiguity
b740: 0a 20 20 20 20 77 69 74 68 20 74 68 65 20 65 72  .    with the er
b750: 72 6f 72 20 63 61 73 65 20 73 69 6e 63 65 20 5b  ror case since [
b760: 61 20 76 61 6c 69 64 20 70 6f 69 6e 74 65 72 20  a valid pointer 
b770: 69 6e 20 43 43 38 20 63 61 6e 6e 6f 74 20 62 65  in CC8 cannot be
b780: 0a 20 20 20 20 7a 65 72 6f 5d 28 23 6d 65 6d 6f  .    zero](#memo
b790: 72 79 29 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64  ry)....### <a id
b7a0: 3d 22 70 72 69 6e 74 66 22 3e 3c 2f 61 3e 60 70  ="printf"></a>`p
b7b0: 72 69 6e 74 66 28 66 6d 74 2c 20 61 72 67 73 2e  rintf(fmt, args.
b7c0: 2e 2e 29 60 0a 0a 57 72 69 74 65 73 20 69 74 73  ..)`..Writes its
b7d0: 20 61 72 67 75 6d 65 6e 74 73 20 28 60 61 72 67   arguments (`arg
b7e0: 73 60 29 20 66 6f 72 6d 61 74 74 65 64 20 61 63  s`) formatted ac
b7f0: 63 6f 72 64 69 6e 67 20 74 6f 20 66 6f 72 6d 61  cording to forma
b800: 74 20 73 74 72 69 6e 67 20 60 66 6d 74 60 0a 74  t string `fmt`.t
b810: 6f 20 60 54 54 59 3a 60 2e 0a 0a 54 68 69 73 20  o `TTY:`...This 
b820: 66 75 6e 63 74 69 6f 6e 20 69 73 20 69 6d 70 6c  function is impl
b830: 65 6d 65 6e 74 65 64 20 69 6e 20 74 65 72 6d 73  emented in terms
b840: 20 6f 66 20 5b 60 73 70 72 69 6e 74 66 28 29 60   of [`sprintf()`
b850: 5d 28 23 73 70 72 69 6e 74 66 29 2c 20 73 6f 20  ](#sprintf), so 
b860: 73 65 65 0a 69 74 73 20 64 6f 63 75 6d 65 6e 74  see.its document
b870: 61 74 69 6f 6e 20 66 6f 72 20 64 65 74 61 69 6c  ation for detail
b880: 73 20 6f 6e 20 73 74 72 69 6e 67 20 66 6f 72 6d  s on string form
b890: 61 74 74 69 6e 67 2e 0a 0a 54 68 69 73 20 66 75  atting...This fu
b8a0: 6e 63 74 69 6f 6e 20 63 61 6c 6c 73 20 5b 60 70  nction calls [`p
b8b0: 75 74 73 28 29 60 5d 28 23 70 75 74 73 29 20 61  uts()`](#puts) a
b8c0: 66 74 65 72 20 66 6f 72 6d 61 74 74 69 6e 67 20  fter formatting 
b8d0: 74 68 65 20 6f 75 74 70 75 74 0a 73 74 72 69 6e  the output.strin
b8e0: 67 2c 20 73 6f 20 73 65 65 20 69 74 73 20 64 6f  g, so see its do
b8f0: 63 75 6d 65 6e 74 61 74 69 6f 6e 20 66 6f 72 20  cumentation for 
b900: 69 6e 66 6f 72 6d 61 74 69 6f 6e 20 6f 6e 20 68  information on h
b910: 6f 77 20 4c 49 42 43 20 77 72 69 74 65 73 20 72  ow LIBC writes r
b920: 61 77 0a 63 68 61 72 61 63 74 65 72 20 73 74 72  aw.character str
b930: 69 6e 67 73 2e 0a 0a 2a 2a 57 41 52 4e 49 4e 47  ings...**WARNING
b940: 3a 2a 2a 20 42 65 63 61 75 73 65 20 60 70 72 69  :** Because `pri
b950: 6e 74 66 28 29 60 20 69 73 20 69 6d 70 6c 65 6d  ntf()` is implem
b960: 65 6e 74 65 64 20 69 6e 20 74 65 72 6d 73 20 6f  ented in terms o
b970: 66 20 60 73 70 72 69 6e 74 66 28 29 60 0a 61 6e  f `sprintf()`.an
b980: 64 20 69 74 20 70 6f 69 6e 74 73 20 61 74 20 5b  d it points at [
b990: 61 20 73 74 61 74 69 63 20 62 75 66 66 65 72 20  a static buffer 
b9a0: 69 6e 20 74 68 65 20 75 73 65 72 20 64 61 74 61  in the user data
b9b0: 20 66 69 65 6c 64 5d 28 23 6d 65 6d 6f 72 79 29   field](#memory)
b9c0: 2c 20 79 6f 75 0a 63 61 6e 20 6f 6e 6c 79 20 73  , you.can only s
b9d0: 61 66 65 6c 79 20 70 72 69 6e 74 20 75 70 20 74  afely print up t
b9e0: 6f 20 2a 31 31 32 2a 20 63 68 61 72 61 63 74 65  o *112* characte
b9f0: 72 73 20 61 74 20 61 20 74 69 6d 65 20 77 69 74  rs at a time wit
ba00: 68 20 60 70 72 69 6e 74 66 28 29 60 2e 0a 50 72  h `printf()`..Pr
ba10: 69 6e 74 69 6e 67 20 6d 6f 72 65 20 77 69 6c 6c  inting more will
ba20: 20 63 6f 72 72 75 70 74 20 70 72 6f 67 72 61 6d   corrupt program
ba30: 20 64 61 74 61 20 61 6e 64 20 6d 6f 73 74 20 6c   data and most l
ba40: 69 6b 65 6c 79 20 63 72 61 73 68 20 74 68 65 0a  ikely crash the.
ba50: 70 72 6f 67 72 61 6d 2e 0a 0a 0a 23 23 23 20 3c  program....### <
ba60: 61 20 69 64 3d 22 70 75 74 63 22 20 6e 61 6d 65  a id="putc" name
ba70: 3d 22 66 70 75 74 63 22 3e 3c 2f 61 3e 60 70 75  ="fputc"></a>`pu
ba80: 74 63 28 63 29 60 2c 20 60 66 70 75 74 63 28 63  tc(c)`, `fputc(c
ba90: 29 60 0a 0a 57 72 69 74 65 73 20 61 20 63 68 61  )`..Writes a cha
baa0: 72 61 63 74 65 72 20 60 63 60 20 65 69 74 68 65  racter `c` eithe
bab0: 72 20 74 6f 20 60 54 54 59 3a 60 20 6f 72 20 74  r to `TTY:` or t
bac0: 6f 20 74 68 65 20 63 75 72 72 65 6e 74 6c 79 2d  o the currently-
bad0: 6f 70 65 6e 65 64 0a 6f 75 74 70 75 74 20 66 69  opened.output fi
bae0: 6c 65 2e 0a 0a 54 68 65 20 63 68 61 72 61 63 74  le...The charact
baf0: 65 72 73 20 70 6f 69 6e 74 65 64 20 74 6f 20 61  ers pointed to a
bb00: 72 65 20 65 78 70 65 63 74 65 64 20 74 6f 20 62  re expected to b
bb10: 65 20 37 2d 62 69 74 20 41 53 43 49 49 20 62 79  e 7-bit ASCII by
bb20: 74 65 73 20 73 74 6f 72 65 64 0a 77 69 74 68 69  tes stored.withi
bb30: 6e 20 65 61 63 68 20 50 44 50 2d 38 20 77 6f 72  n each PDP-8 wor
bb40: 64 2c 20 77 69 74 68 20 74 68 65 20 74 6f 70 20  d, with the top 
bb50: 35 20 62 69 74 73 20 75 6e 73 65 74 2c 20 62 75  5 bits unset, bu
bb60: 74 20 6e 6f 20 61 74 74 65 6d 70 74 20 69 73 0a  t no attempt is.
bb70: 63 75 72 72 65 6e 74 6c 79 20 6d 61 64 65 20 74  currently made t
bb80: 6f 20 65 6e 66 6f 72 63 65 20 74 68 69 73 2e 0a  o enforce this..
bb90: 0a 42 6f 74 68 20 66 75 6e 63 74 69 6f 6e 73 20  .Both functions 
bba0: 72 65 74 75 72 6e 20 74 68 65 20 77 72 69 74 74  return the writt
bbb0: 65 6e 20 63 68 61 72 61 63 74 65 72 2e 0a 0a 2a  en character...*
bbc0: 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74  *Standard Violat
bbd0: 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 4e 65 69  ions:**..*   Nei
bbe0: 74 68 65 72 20 66 75 6e 63 74 69 6f 6e 20 63 61  ther function ca
bbf0: 6e 20 66 61 69 6c 20 77 69 74 68 6f 75 74 20 6c  n fail without l
bc00: 6f 63 6b 69 6e 67 20 75 70 20 74 68 65 20 63 6f  ocking up the co
bc10: 6d 70 75 74 65 72 20 6f 72 0a 20 20 20 20 63 72  mputer or.    cr
bc20: 61 73 68 69 6e 67 20 74 68 65 20 70 72 6f 67 72  ashing the progr
bc30: 61 6d 2c 20 73 6f 20 61 6e 20 45 4f 46 20 72 65  am, so an EOF re
bc40: 74 75 72 6e 20 63 61 6e 20 6e 65 76 65 72 20 68  turn can never h
bc50: 61 70 70 65 6e 2e 0a 0a 2a 20 20 20 4e 65 69 74  appen...*   Neit
bc60: 68 65 72 20 66 75 6e 63 74 69 6f 6e 20 74 61 6b  her function tak
bc70: 65 20 61 20 60 46 49 4c 45 2a 60 20 61 73 20 74  e a `FILE*` as t
bc80: 68 65 69 72 20 73 65 63 6f 6e 64 20 70 61 72 61  heir second para
bc90: 6d 65 74 65 72 2e 20 60 70 75 74 63 28 29 60 0a  meter. `putc()`.
bca0: 20 20 20 20 61 6c 77 61 79 73 20 77 72 69 74 65      always write
bcb0: 73 20 74 6f 20 60 54 54 59 3a 60 2c 20 61 6e 64  s to `TTY:`, and
bcc0: 20 60 66 70 75 74 63 28 29 60 20 61 6c 77 61 79   `fputc()` alway
bcd0: 73 20 77 72 69 74 65 73 20 74 6f 20 74 68 65 0a  s writes to the.
bce0: 20 20 20 20 63 75 72 72 65 6e 74 6c 79 2d 6f 70      currently-op
bcf0: 65 6e 65 64 20 6f 75 74 70 75 74 20 66 69 6c 65  ened output file
bd00: 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 70  ....### <a id="p
bd10: 75 74 73 22 20 6e 61 6d 65 3d 22 66 70 75 74 73  uts" name="fputs
bd20: 22 3e 3c 2f 61 3e 60 70 75 74 73 28 73 29 60 2c  "></a>`puts(s)`,
bd30: 20 60 66 70 75 74 73 28 73 29 60 0a 0a 57 72 69   `fputs(s)`..Wri
bd40: 74 65 73 20 61 20 6e 75 6c 6c 2d 74 65 72 6d 69  tes a null-termi
bd50: 6e 61 74 65 64 20 63 68 61 72 61 63 74 65 72 20  nated character 
bd60: 73 74 72 69 6e 67 20 60 73 60 20 65 69 74 68 65  string `s` eithe
bd70: 72 20 74 6f 20 60 54 54 59 3a 60 20 6f 72 20 74  r to `TTY:` or t
bd80: 6f 20 74 68 65 0a 63 75 72 72 65 6e 74 6c 79 2d  o the.currently-
bd90: 6f 70 65 6e 65 64 20 6f 75 74 70 75 74 20 66 69  opened output fi
bda0: 6c 65 2e 0a 0a 54 68 65 20 63 68 61 72 61 63 74  le...The charact
bdb0: 65 72 73 20 70 6f 69 6e 74 65 64 20 74 6f 20 61  ers pointed to a
bdc0: 72 65 20 65 78 70 65 63 74 65 64 20 74 6f 20 62  re expected to b
bdd0: 65 20 37 2d 62 69 74 20 41 53 43 49 49 20 62 79  e 7-bit ASCII by
bde0: 74 65 73 20 73 74 6f 72 65 64 0a 77 69 74 68 69  tes stored.withi
bdf0: 6e 20 65 61 63 68 20 50 44 50 2d 38 20 77 6f 72  n each PDP-8 wor
be00: 64 2c 20 77 69 74 68 20 74 68 65 20 74 6f 70 20  d, with the top 
be10: 35 20 62 69 74 73 20 75 6e 73 65 74 2e 0a 0a 2a  5 bits unset...*
be20: 2a 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74  *Standard Violat
be30: 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 54 68 65  ions:**..*   The
be40: 20 60 70 75 74 73 28 29 60 20 69 6d 70 6c 65 6d   `puts()` implem
be50: 65 6e 74 61 74 69 6f 6e 20 64 6f 65 73 20 6e 6f  entation does no
be60: 74 20 77 72 69 74 65 20 61 20 6e 65 77 6c 69 6e  t write a newlin
be70: 65 20 61 66 74 65 72 20 74 68 65 0a 20 20 20 20  e after the.    
be80: 70 61 73 73 65 64 20 73 74 72 69 6e 67 2e 0a 0a  passed string...
be90: 20 20 20 20 28 4e 65 69 74 68 65 72 20 64 6f 65      (Neither doe
bea0: 73 20 6f 75 72 20 60 66 70 75 74 73 28 29 60 2c  s our `fputs()`,
beb0: 20 62 75 74 20 74 68 61 74 e2 80 99 73 20 61 63   but that’s ac
bec0: 74 75 61 6c 6c 79 20 53 74 61 6e 64 61 72 64 20  tually Standard 
bed0: 62 65 68 61 76 69 6f 72 2e 29 0a 0a 2a 20 20 20  behavior.)..*   
bee0: 42 6f 74 68 20 60 70 75 74 73 28 29 60 20 61 6e  Both `puts()` an
bef0: 64 20 60 66 70 75 74 73 28 29 60 20 61 72 65 20  d `fputs()` are 
bf00: 73 75 70 70 6f 73 65 64 20 74 6f 20 72 65 74 75  supposed to retu
bf10: 72 6e 20 6e 6f 6e 7a 65 72 6f 20 6f 6e 0a 20 20  rn nonzero on.  
bf20: 20 20 73 75 63 63 65 73 73 2c 20 62 75 74 20 74    success, but t
bf30: 68 69 73 20 69 6d 70 6c 65 6d 65 6e 74 61 74 69  his implementati
bf40: 6f 6e 20 72 65 74 75 72 6e 73 20 30 2e 0a 20 20  on returns 0..  
bf50: 20 20 0a 20 20 20 20 54 65 63 68 6e 69 63 61 6c    .    Technical
bf60: 6c 79 2c 20 74 68 65 73 65 20 66 75 6e 63 74 69  ly, these functi
bf70: 6f 6e 73 20 61 72 65 6e e2 80 99 74 20 65 78 70  ons aren’t exp
bf80: 6c 69 63 69 74 6c 79 20 e2 80 9c 72 65 74 75 72  licitly “retur
bf90: 6e 69 6e 67 e2 80 9d 20 61 6e 79 74 68 69 6e 67  ning” anything
bfa0: 2c 0a 20 20 20 20 74 68 65 79 e2 80 99 72 65 20  ,.    they’re 
bfb0: 6a 75 73 74 20 6c 65 61 76 69 6e 67 20 30 20 69  just leaving 0 i
bfc0: 6e 20 41 43 2c 20 74 68 61 74 20 62 65 69 6e 67  n AC, that being
bfd0: 20 74 68 65 20 41 53 43 49 49 20 4e 55 4c 20 63   the ASCII NUL c
bfe0: 68 61 72 61 63 74 65 72 0a 20 20 20 20 74 68 61  haracter.    tha
bff0: 74 20 74 65 72 6d 69 6e 61 74 65 64 20 74 68 65  t terminated the
c000: 20 6c 6f 6f 70 20 69 6e 73 69 64 65 20 65 61 63   loop inside eac
c010: 68 20 66 75 6e 63 74 69 6f 6e e2 80 99 73 20 69  h function’s i
c020: 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 2e 0a 0a  mplementation...
c030: 2a 20 20 20 60 66 70 75 74 73 28 29 60 20 64 65  *   `fputs()` de
c040: 74 65 63 74 73 20 6e 6f 20 49 2f 4f 20 65 72 72  tects no I/O err
c050: 6f 72 20 63 6f 6e 64 69 74 69 6f 6e 73 2c 20 61  or conditions, a
c060: 6e 64 20 74 68 75 73 20 63 61 6e 6e 6f 74 20 72  nd thus cannot r
c070: 65 74 75 72 6e 0a 20 20 20 20 45 4f 46 20 74 6f  eturn.    EOF to
c080: 20 73 69 67 6e 61 6c 20 61 6e 20 65 72 72 6f 72   signal an error
c090: 2e 20 49 74 20 61 6c 77 61 79 73 20 72 65 74 75  . It always retu
c0a0: 72 6e 73 20 30 2c 20 77 68 65 74 68 65 72 20 61  rns 0, whether a
c0b0: 6e 20 65 72 72 6f 72 0a 20 20 20 20 6f 63 63 75  n error.    occu
c0c0: 72 72 65 64 20 6f 72 20 6e 6f 74 2e 0a 0a 2a 20  rred or not...* 
c0d0: 20 20 60 66 70 75 74 73 28 29 60 20 64 6f 65 73    `fputs()` does
c0e0: 20 6e 6f 74 20 74 61 6b 65 20 61 20 60 46 49 4c   not take a `FIL
c0f0: 45 2a 60 20 61 73 20 69 74 73 20 66 69 72 73 74  E*` as its first
c100: 20 70 61 72 61 6d 65 74 65 72 20 64 75 65 20 74   parameter due t
c110: 6f 20 74 68 65 0a 20 20 20 20 5b 69 6d 70 6c 69  o the.    [impli
c120: 63 69 74 20 73 69 6e 67 6c 65 20 6f 75 74 70 75  cit single outpu
c130: 74 20 66 69 6c 65 5d 28 23 66 69 6f 6c 69 6d 29  t file](#fiolim)
c140: 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 72  ....### <a id="r
c150: 65 76 63 70 79 22 3e 3c 2f 61 3e 60 72 65 76 63  evcpy"></a>`revc
c160: 70 79 28 64 73 74 2c 20 73 72 63 2c 20 6e 29 60  py(dst, src, n)`
c170: 0a 0a 46 6f 72 20 6e 6f 6e 2d 6f 76 65 72 6c 61  ..For non-overla
c180: 70 70 69 6e 67 20 62 75 66 66 65 72 73 2c 20 68  pping buffers, h
c190: 61 73 20 74 68 65 20 73 61 6d 65 20 65 66 66 65  as the same effe
c1a0: 63 74 20 61 73 0a 5b 60 6d 65 6d 63 70 79 28 29  ct as.[`memcpy()
c1b0: 60 5d 28 23 6d 65 6d 63 70 79 29 2c 20 75 73 69  `](#memcpy), usi
c1c0: 6e 67 20 6c 65 73 73 20 65 66 66 69 63 69 65 6e  ng less efficien
c1d0: 74 20 63 6f 64 65 2e 0a 0a 42 65 63 61 75 73 65  t code...Because
c1e0: 20 69 74 20 63 6f 70 69 65 73 20 77 6f 72 64 73   it copies words
c1f0: 20 69 6e 20 74 68 65 20 6f 70 70 6f 73 69 74 65   in the opposite
c200: 20 6f 72 64 65 72 20 66 72 6f 6d 20 60 6d 65 6d   order from `mem
c210: 63 70 79 28 29 60 2c 20 79 6f 75 20 6d 61 79 0a  cpy()`, you may.
c220: 62 65 20 77 69 6c 6c 69 6e 67 20 74 6f 20 70 61  be willing to pa
c230: 79 20 69 74 73 20 65 66 66 69 63 69 65 6e 63 79  y its efficiency
c240: 20 68 69 74 20 77 68 65 6e 20 63 6f 70 79 69 6e   hit when copyin
c250: 67 20 62 65 74 77 65 65 6e 20 6f 76 65 72 6c 61  g between overla
c260: 70 70 69 6e 67 0a 62 75 66 66 65 72 73 20 77 68  pping.buffers wh
c270: 65 6e 20 74 68 65 20 64 65 73 74 69 6e 61 74 69  en the destinati
c280: 6f 6e 20 66 6f 6c 6c 6f 77 73 20 74 68 65 20 73  on follows the s
c290: 6f 75 72 63 65 2e 0a 0a 2a 2a 4e 6f 6e 73 74 61  ource...**Nonsta
c2a0: 6e 64 61 72 64 2e 2a 2a 20 43 6f 6e 66 6f 72 6d  ndard.** Conform
c2b0: 73 20 74 6f 20 6e 6f 20 6b 6e 6f 77 6e 20 43 20  s to no known C 
c2c0: 6c 69 62 72 61 72 79 20 69 6d 70 6c 65 6d 65 6e  library implemen
c2d0: 74 61 74 69 6f 6e 2e 0a 0a 0a 23 23 23 20 3c 61  tation....### <a
c2e0: 20 69 64 3d 22 73 70 72 69 6e 74 66 22 3e 3c 2f   id="sprintf"></
c2f0: 61 3e 60 73 70 72 69 6e 74 66 28 6f 75 74 73 74  a>`sprintf(outst
c300: 72 2c 20 66 6d 74 2c 20 61 72 67 73 2e 2e 2e 29  r, fmt, args...)
c310: 60 0a 0a 46 6f 72 6d 61 74 73 20 69 74 73 20 61  `..Formats its a
c320: 72 67 75 6d 65 6e 74 73 20 28 60 61 72 67 73 60  rguments (`args`
c330: 29 20 66 6f 72 20 6f 75 74 70 75 74 20 74 6f 20  ) for output to 
c340: 60 6f 75 74 73 74 72 60 20 62 61 73 65 64 20 6f  `outstr` based o
c350: 6e 20 66 6f 72 6d 61 74 0a 73 74 72 69 6e 67 20  n format.string 
c360: 60 66 6d 74 60 2e 0a 0a 54 68 65 20 61 6c 6c 6f  `fmt`...The allo
c370: 77 65 64 20 73 74 61 6e 64 61 72 64 20 63 6f 6e  wed standard con
c380: 76 65 72 73 69 6f 6e 20 73 70 65 63 69 66 69 65  version specifie
c390: 72 73 20 61 72 65 20 60 25 60 2c 20 60 63 60 2c  rs are `%`, `c`,
c3a0: 20 60 64 60 2c 20 60 6f 60 2c 20 60 73 60 2c 0a   `d`, `o`, `s`,.
c3b0: 60 75 60 2c 20 60 78 60 2c 20 61 6e 64 20 60 58  `u`, `x`, and `X
c3c0: 60 2e 20 20 53 65 65 20 79 6f 75 72 20 66 61 76  `.  See your fav
c3d0: 6f 72 69 74 65 20 43 20 6d 61 6e 75 61 6c 20 66  orite C manual f
c3e0: 6f 72 20 74 68 65 69 72 20 6d 65 61 6e 69 6e 67  or their meaning
c3f0: 2e 0a 0a 54 68 65 20 43 43 38 20 4c 49 42 43 20  ...The CC8 LIBC 
c400: 64 6f 65 73 20 73 75 70 70 6f 72 74 20 6f 6e 65  does support one
c410: 20 6e 6f 6e 73 74 61 6e 64 61 72 64 20 63 6f 6e   nonstandard con
c420: 76 65 72 73 69 6f 6e 20 73 70 65 63 69 66 69 65  version specifie
c430: 72 2c 20 60 62 60 2c 0a 6d 65 61 6e 69 6e 67 20  r, `b`,.meaning 
c440: 62 69 6e 61 72 79 20 6f 75 74 70 75 74 2e 20 54  binary output. T
c450: 68 69 6e 6b 20 6f 66 20 69 74 20 6c 69 6b 65 20  hink of it like 
c460: 60 78 60 2c 20 62 75 74 20 69 6e 20 62 61 73 65  `x`, but in base
c470: 20 32 2e 0a 0a 54 68 65 20 60 62 60 2c 20 60 64   2...The `b`, `d
c480: 60 2c 20 60 6f 60 2c 20 60 75 60 2c 20 60 78 60  `, `o`, `u`, `x`
c490: 2c 20 61 6e 64 20 60 58 60 20 73 70 65 63 69 66  , and `X` specif
c4a0: 69 65 72 73 20 61 72 65 20 69 6d 70 6c 65 6d 65  iers are impleme
c4b0: 6e 74 65 64 20 69 6e 20 74 65 72 6d 73 0a 6f 66  nted in terms.of
c4c0: 20 5b 60 69 74 6f 61 28 29 60 5d 28 23 69 74 6f   [`itoa()`](#ito
c4d0: 61 29 2e 20 4f 75 72 20 60 25 58 60 20 74 68 65  a). Our `%X` the
c4e0: 72 65 66 6f 72 65 20 69 6e 76 6f 6c 76 65 73 20  refore involves 
c4f0: 61 20 63 61 6c 6c 20 74 6f 0a 5b 60 63 75 70 70  a call to.[`cupp
c500: 65 72 28 29 60 5d 28 23 63 75 70 70 65 72 29 20  er()`](#cupper) 
c510: 61 66 74 65 72 20 60 69 74 6f 61 28 29 60 2c 20  after `itoa()`, 
c520: 6d 61 6b 69 6e 67 20 60 25 78 60 20 74 68 65 20  making `%x` the 
c530: 6d 6f 72 65 20 65 66 66 69 63 69 65 6e 74 0a 6f  more efficient.o
c540: 70 74 69 6f 6e 2e 0a 0a 4c 65 66 74 20 61 6e 64  ption...Left and
c550: 20 72 69 67 68 74 2d 6a 75 73 74 69 66 69 65 64   right-justified
c560: 20 70 61 64 64 69 6e 67 20 69 73 20 73 75 70 70   padding is supp
c570: 6f 72 74 65 64 2e 20 53 70 61 63 65 20 61 6e 64  orted. Space and
c580: 20 7a 65 72 6f 2d 70 61 64 64 69 6e 67 0a 69 73   zero-padding.is
c590: 20 73 75 70 70 6f 72 74 65 64 2e 0a 0a 57 69 64   supported...Wid
c5a0: 74 68 20 70 72 65 66 69 78 65 73 20 61 72 65 20  th prefixes are 
c5b0: 6f 62 65 79 65 64 2e 0a 0a 50 72 65 63 69 73 69  obeyed...Precisi
c5c0: 6f 6e 20 73 70 65 63 69 66 69 65 72 73 20 61 72  on specifiers ar
c5d0: 65 20 70 61 72 73 65 64 20 62 75 74 20 68 61 76  e parsed but hav
c5e0: 65 20 6e 6f 20 65 66 66 65 63 74 20 6f 6e 20 74  e no effect on t
c5f0: 68 65 20 6f 75 74 70 75 74 2e 0a 2a 2a 54 4f 44  he output..**TOD
c600: 4f 2a 2a 3a 20 43 6c 61 69 6d 20 62 61 73 65 64  O**: Claim based
c610: 20 6f 6e 20 63 6f 64 65 20 69 6e 73 70 65 63 74   on code inspect
c620: 69 6f 6e 3b 20 76 65 72 69 66 79 20 77 69 74 68  ion; verify with
c630: 20 74 65 73 74 73 2e 0a 0a 4f 6e 20 73 75 63 63   tests...On succ
c640: 65 73 73 2c 20 69 74 20 72 65 74 75 72 6e 73 20  ess, it returns 
c650: 74 68 65 20 6e 75 6d 62 65 72 20 6f 66 20 63 68  the number of ch
c660: 61 72 61 63 74 65 72 73 20 77 72 69 74 74 65 6e  aracters written
c670: 20 74 6f 20 74 68 65 20 6f 75 74 70 75 74 0a 73   to the output.s
c680: 74 72 65 61 6d 2c 20 6e 6f 74 20 69 6e 63 6c 75  tream, not inclu
c690: 64 69 6e 67 20 74 68 65 20 74 72 61 69 6c 69 6e  ding the trailin
c6a0: 67 20 4e 55 4c 20 63 68 61 72 61 63 74 65 72 2e  g NUL character.
c6b0: 20 49 66 20 69 74 20 65 6e 63 6f 75 6e 74 65 72   If it encounter
c6c0: 73 20 61 6e 0a 75 6e 6b 6e 6f 77 6e 20 66 6f 72  s an.unknown for
c6d0: 6d 61 74 20 73 70 65 63 69 66 69 65 72 2c 20 69  mat specifier, i
c6e0: 74 20 74 65 72 6d 69 6e 61 74 65 73 20 74 68 65  t terminates the
c6f0: 20 6f 75 74 70 75 74 20 73 74 72 69 6e 67 20 77   output string w
c700: 69 74 68 20 61 20 4e 55 4c 20 61 6e 64 0a 72 65  ith a NUL and.re
c710: 74 75 72 6e 73 20 2d 31 2e 0a 0a 2a 2a 57 41 52  turns -1...**WAR
c720: 4e 49 4e 47 3a 2a 2a 20 54 68 69 73 20 66 75 6e  NING:** This fun
c730: 63 74 69 6f 6e 20 64 6f 65 73 20 6e 6f 74 20 63  ction does not c
c740: 68 65 63 6b 20 69 74 73 20 62 75 66 66 65 72 20  heck its buffer 
c750: 70 6f 69 6e 74 65 72 20 66 6f 72 0a 65 6e 64 2d  pointer for.end-
c760: 6f 66 2d 66 69 65 6c 64 2c 20 73 6f 20 69 66 20  of-field, so if 
c770: 79 6f 75 20 63 61 75 73 65 20 69 74 20 74 6f 20  you cause it to 
c780: 70 72 69 6e 74 20 6d 6f 72 65 20 74 68 61 6e 20  print more than 
c790: 63 61 6e 20 62 65 20 73 74 6f 72 65 64 20 61 74  can be stored at
c7a0: 20 74 68 65 0a 65 6e 64 20 6f 66 20 61 20 66 69   the.end of a fi
c7b0: 65 6c 64 2c 20 69 74 20 77 69 6c 6c 20 77 72 61  eld, it will wra
c7c0: 70 20 61 72 6f 75 6e 64 20 61 6e 64 20 62 65 67  p around and beg
c7d0: 69 6e 20 77 72 69 74 69 6e 67 20 61 74 20 74 68  in writing at th
c7e0: 65 20 62 65 67 69 6e 6e 69 6e 67 0a 6f 66 20 74  e beginning.of t
c7f0: 68 65 20 73 61 6d 65 20 66 69 65 6c 64 2e 20 54  he same field. T
c800: 68 69 73 20 61 6c 73 6f 20 68 61 73 20 65 66 66  his also has eff
c810: 65 63 74 73 20 6f 6e 20 74 68 65 20 62 65 68 61  ects on the beha
c820: 76 69 6f 72 20 6f 66 0a 5b 60 70 72 69 6e 74 66  vior of.[`printf
c830: 28 29 60 5d 28 23 70 72 69 6e 74 66 29 20 61 6e  ()`](#printf) an
c840: 64 20 5b 60 66 70 72 69 6e 74 66 28 29 60 5d 28  d [`fprintf()`](
c850: 23 66 70 72 69 6e 74 66 29 2e 0a 0a 2a 2a 53 74  #fprintf)...**St
c860: 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 69 6f 6e  andard Violation
c870: 73 3a 2a 2a 0a 0a 2a 20 20 20 41 73 20 6c 6f 6e  s:**..*   As lon
c880: 67 20 61 73 20 43 43 38 20 68 61 73 20 6e 6f 20  g as CC8 has no 
c890: 66 6c 6f 61 74 69 6e 67 2d 70 6f 69 6e 74 20 73  floating-point s
c8a0: 75 70 70 6f 72 74 2c 20 74 68 65 20 60 61 60 2c  upport, the `a`,
c8b0: 20 60 65 60 2c 20 60 66 60 2c 20 61 6e 64 0a 20   `e`, `f`, and. 
c8c0: 20 20 20 60 67 60 20 66 6f 72 6d 61 74 20 73 70     `g` format sp
c8d0: 65 63 69 66 69 65 72 73 20 28 61 6e 64 20 74 68  ecifiers (and th
c8e0: 65 69 72 20 63 61 70 69 74 61 6c 69 7a 65 64 20  eir capitalized 
c8f0: 76 61 72 69 61 6e 74 73 29 20 63 61 6e 6e 6f 74  variants) cannot
c900: 20 62 65 0a 20 20 20 20 73 75 70 70 6f 72 74 65   be.    supporte
c910: 64 2e 0a 0a 2a 20 20 20 53 69 6e 63 65 20 43 43  d...*   Since CC
c920: 38 20 64 6f 65 73 20 6e 6f 74 20 73 75 70 70 6f  8 does not suppo
c930: 72 74 20 74 68 65 20 60 6c 6f 6e 67 60 20 69 6e  rt the `long` in
c940: 74 65 67 65 72 20 74 79 70 65 20 71 75 61 6c 69  teger type quali
c950: 66 69 65 72 2c 20 74 68 69 73 0a 20 20 20 20 66  fier, this.    f
c960: 75 6e 63 74 69 6f 6e 20 64 6f 65 73 20 6e 6f 74  unction does not
c970: 20 73 75 70 70 6f 72 74 20 74 68 65 20 60 6c 60   support the `l`
c980: 20 66 6f 72 6d 61 74 20 73 70 65 63 69 66 69 65   format specifie
c990: 72 2e 0a 0a 2a 20 20 20 54 68 65 20 73 74 61 6e  r...*   The stan
c9a0: 64 61 72 64 20 60 6e 60 20 61 6e 64 20 60 70 60  dard `n` and `p`
c9b0: 20 66 6f 72 6d 61 74 20 73 70 65 63 69 66 69 65   format specifie
c9c0: 72 73 20 63 6f 75 6c 64 20 62 65 20 73 75 70 70  rs could be supp
c9d0: 6f 72 74 65 64 2c 20 62 75 74 0a 20 20 20 20 63  orted, but.    c
c9e0: 75 72 72 65 6e 74 6c 79 20 61 72 65 20 6e 6f 74  urrently are not
c9f0: 2e 0a 0a 2a 20 20 20 54 68 65 20 60 69 60 20 61  ...*   The `i` a
ca00: 6c 69 61 73 20 66 6f 72 20 74 68 65 20 6d 6f 72  lias for the mor
ca10: 65 20 63 6f 6d 6d 6f 6e 20 60 64 60 20 73 70 65  e common `d` spe
ca20: 63 69 66 69 65 72 20 69 73 20 6e 6f 74 20 73 75  cifier is not su
ca30: 70 70 6f 72 74 65 64 2e 0a 0a 2a 20 20 20 55 6e  pported...*   Un
ca40: 73 75 70 70 6f 72 74 65 64 20 69 6e 70 75 74 20  supported input 
ca50: 73 70 65 63 69 66 69 65 72 73 20 63 61 75 73 65  specifiers cause
ca60: 20 74 68 65 20 66 75 6e 63 74 69 6f 6e 20 74 6f   the function to
ca70: 20 72 65 74 75 72 6e 20 74 68 65 20 6e 75 6d 62   return the numb
ca80: 65 72 0a 20 20 20 20 6f 66 20 63 68 61 72 61 63  er.    of charac
ca90: 74 65 72 73 20 77 72 69 74 74 65 6e 20 73 6f 20  ters written so 
caa0: 66 61 72 2c 20 6e 6f 74 20 61 20 6e 65 67 61 74  far, not a negat
cab0: 69 76 65 20 76 61 6c 75 65 20 61 73 20 74 68 65  ive value as the
cac0: 20 53 74 61 6e 64 61 72 64 0a 20 20 20 20 72 65   Standard.    re
cad0: 71 75 69 72 65 73 2e 20 20 49 6e 20 74 68 65 20  quires.  In the 
cae0: 63 61 73 65 20 6f 66 20 60 73 70 72 69 6e 74 66  case of `sprintf
caf0: 28 29 60 2c 20 74 68 69 73 20 6d 65 61 6e 73 20  ()`, this means 
cb00: 74 68 65 20 74 72 61 69 6c 69 6e 67 20 4e 55 4c  the trailing NUL
cb10: 0a 20 20 20 20 63 68 61 72 61 63 74 65 72 20 77  .    character w
cb20: 69 6c 6c 20 6e 6f 74 20 62 65 20 77 72 69 74 74  ill not be writt
cb30: 65 6e 21 0a 0a 2a 20 20 20 54 68 65 72 65 20 69  en!..*   There i
cb40: 73 20 6e 6f 20 60 73 6e 70 72 69 6e 74 66 28 29  s no `snprintf()
cb50: 60 2c 20 60 76 70 72 69 6e 74 66 28 29 60 2c 20  `, `vprintf()`, 
cb60: 65 74 63 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64  etc....### <a id
cb70: 3d 22 73 63 61 6e 66 22 20 6e 61 6d 65 3d 22 66  ="scanf" name="f
cb80: 73 63 61 6e 66 22 3e 3c 2f 61 3e 60 66 73 63 61  scanf"></a>`fsca
cb90: 6e 66 60 2c 20 60 73 63 61 6e 66 60 2c 20 60 73  nf`, `scanf`, `s
cba0: 73 63 61 6e 66 60 0a 0a 50 61 72 73 65 20 73 74  scanf`..Parse st
cbb0: 72 69 6e 67 73 20 61 63 63 6f 72 64 69 6e 67 20  rings according 
cbc0: 74 6f 20 61 20 60 70 72 69 6e 74 66 60 2d 6c 69  to a `printf`-li
cbd0: 6b 65 20 66 6f 72 6d 61 74 20 73 70 65 63 69 66  ke format specif
cbe0: 69 63 61 74 69 6f 6e 2e 20 60 73 63 61 6e 66 60  ication. `scanf`
cbf0: 0a 67 65 74 73 20 74 68 65 20 73 74 72 69 6e 67  .gets the string
cc00: 20 66 72 6f 6d 20 74 68 65 20 69 6e 74 65 72 61   from the intera
cc10: 63 74 69 76 65 20 74 65 72 6d 69 6e 61 6c 2c 20  ctive terminal, 
cc20: 60 66 73 63 61 6e 66 60 20 67 65 74 73 20 69 74  `fscanf` gets it
cc30: 20 66 72 6f 6d 20 61 0a 66 69 6c 65 20 6f 70 65   from a.file ope
cc40: 6e 65 64 20 77 69 74 68 20 5b 60 66 6f 70 65 6e  ned with [`fopen
cc50: 28 29 60 5d 28 23 66 6f 70 65 6e 29 2c 20 61 6e  ()`](#fopen), an
cc60: 64 20 60 73 73 63 61 6e 66 60 20 67 65 74 73 20  d `sscanf` gets 
cc70: 69 74 20 66 72 6f 6d 20 61 0a 4e 55 4c 2d 74 65  it from a.NUL-te
cc80: 72 6d 69 6e 61 74 65 64 20 43 20 73 74 72 69 6e  rminated C strin
cc90: 67 20 61 6c 72 65 61 64 79 20 69 6e 20 63 6f 72  g already in cor
cca0: 65 2e 0a 0a 2a 2a 44 4f 43 55 4d 45 4e 54 41 54  e...**DOCUMENTAT
ccb0: 49 4f 4e 20 49 4e 43 4f 4d 50 4c 45 54 45 2a 2a  ION INCOMPLETE**
ccc0: 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 73 74  ...### <a id="st
ccd0: 72 63 61 74 22 3e 3c 2f 61 3e 60 73 74 72 63 61  rcat"></a>`strca
cce0: 74 28 64 73 74 2c 20 73 72 63 29 60 0a 0a 43 6f  t(dst, src)`..Co
ccf0: 6e 63 61 74 65 6e 61 74 65 73 20 6f 6e 65 20 5b  ncatenates one [
cd00: 30 2d 74 65 72 6d 69 6e 61 74 65 64 20 77 6f 72  0-terminated wor
cd10: 64 20 73 74 72 69 6e 67 5d 28 23 77 6f 72 64 73  d string](#words
cd20: 74 72 29 20 74 6f 20 74 68 65 20 65 6e 64 20 6f  tr) to the end o
cd30: 66 0a 61 6e 6f 74 68 65 72 20 69 6e 20 74 68 65  f.another in the
cd40: 20 5b 75 73 65 72 20 64 61 74 61 20 66 69 65 6c   [user data fiel
cd50: 64 5d 28 23 75 64 66 29 2e 0a 0a 54 68 69 73 20  d](#udf)...This 
cd60: 66 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 6e 6f  function will no
cd70: 74 20 63 6f 70 79 20 64 61 74 61 20 62 65 74 77  t copy data betw
cd80: 65 65 6e 20 66 69 65 6c 64 73 2e 0a 0a 49 66 20  een fields...If 
cd90: 74 68 65 20 74 65 72 6d 69 6e 61 74 69 6e 67 20  the terminating 
cda0: 30 20 77 6f 72 64 20 69 73 20 6e 6f 74 20 66 6f  0 word is not fo
cdb0: 75 6e 64 20 69 6e 20 60 64 73 74 60 20 62 79 20  und in `dst` by 
cdc0: 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 0a 63  the end of the.c
cdd0: 75 72 72 65 6e 74 20 66 69 65 6c 64 2c 20 69 74  urrent field, it
cde0: 20 77 69 6c 6c 20 77 72 61 70 20 61 72 6f 75 6e   will wrap aroun
cdf0: 64 20 74 6f 20 74 68 65 20 73 74 61 72 74 20 6f  d to the start o
ce00: 66 20 74 68 65 20 66 69 65 6c 64 20 61 6e 64 20  f the field and 
ce10: 72 65 73 75 6d 65 0a 73 65 61 72 63 68 69 6e 67  resume.searching
ce20: 20 74 68 65 72 65 3b 20 74 68 65 20 63 6f 6e 63   there; the conc
ce30: 61 74 65 6e 61 74 69 6f 6e 20 77 69 6c 6c 20 6f  atenation will o
ce40: 63 63 75 72 20 77 68 65 72 65 76 65 72 20 69 74  ccur wherever it
ce50: 20 64 6f 65 73 20 66 69 6e 64 20 61 20 30 0a 77   does find a 0.w
ce60: 6f 72 64 2e 20 49 66 20 74 68 65 72 65 20 68 61  ord. If there ha
ce70: 70 70 65 6e 20 74 6f 20 62 65 20 6e 6f 20 30 20  ppen to be no 0 
ce80: 77 6f 72 64 73 20 69 6e 20 74 68 65 20 66 69 65  words in the fie
ce90: 6c 64 2c 20 69 74 20 77 69 6c 6c 20 69 74 65 72  ld, it will iter
cea0: 61 74 65 0a 66 6f 72 65 76 65 72 21 0a 0a 42 65  ate.forever!..Be
ceb0: 77 61 72 65 20 74 68 61 74 20 74 68 69 73 20 66  ware that this f
cec0: 75 6e 63 74 69 6f 6e 20 77 69 6c 6c 20 5b 77 72  unction will [wr
ced0: 61 70 20 61 72 6f 75 6e 64 5d 28 23 70 74 72 77  ap around](#ptrw
cee0: 72 61 70 29 20 69 66 0a 60 64 73 74 20 2b 20 73  rap) if.`dst + s
cef0: 74 72 6c 65 6e 28 64 73 74 29 20 2b 20 73 74 72  trlen(dst) + str
cf00: 6c 65 6e 28 73 72 63 29 60 20 26 67 65 3b 20 34  len(src)` &ge; 4
cf10: 30 39 36 20 61 6e 64 20 73 74 6f 6d 70 20 6f 6e  096 and stomp on
cf20: 20 77 68 61 74 65 76 65 72 e2 80 99 73 0a 61 74   whatever’s.at
cf30: 20 74 68 65 20 73 74 61 72 74 20 6f 66 20 74 68   the start of th
cf40: 65 20 66 69 65 6c 64 2e 0a 0a 54 68 65 73 65 20  e field...These 
cf50: 61 72 65 20 6e 6f 74 20 74 65 63 68 6e 69 63 61  are not technica
cf60: 6c 6c 79 20 76 69 6f 6c 61 74 69 6f 6e 73 20 6f  lly violations o
cf70: 66 20 53 74 61 6e 64 61 72 64 20 43 20 61 73 20  f Standard C as 
cf80: 69 74 20 6c 65 61 76 65 73 20 73 75 63 68 0a 6d  it leaves such.m
cf90: 61 74 74 65 72 73 20 5b 75 6e 64 65 66 69 6e 65  atters [undefine
cfa0: 64 5d 5b 75 62 5d 2e 0a 0a 52 65 74 75 72 6e 73  d][ub]...Returns
cfb0: 20 61 20 63 6f 70 79 20 6f 66 20 60 64 73 74 60   a copy of `dst`
cfc0: 2e 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 69  ...**Standard Vi
cfd0: 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20  olations:**..*  
cfe0: 20 4e 6f 6e 65 20 6b 6e 6f 77 6e 2e 0a 0a 0a 23   None known....#
cff0: 23 23 20 3c 61 20 69 64 3d 22 73 74 72 63 70 79  ## <a id="strcpy
d000: 22 3e 3c 2f 61 3e 60 73 74 72 63 70 79 28 64 73  "></a>`strcpy(ds
d010: 74 2c 20 73 72 63 29 60 0a 0a 43 6f 70 69 65 73  t, src)`..Copies
d020: 20 6f 6e 65 20 5b 30 2d 74 65 72 6d 69 6e 61 74   one [0-terminat
d030: 65 64 20 77 6f 72 64 20 73 74 72 69 6e 67 5d 28  ed word string](
d040: 23 77 6f 72 64 73 74 72 29 20 74 6f 20 61 6e 6f  #wordstr) to ano
d050: 74 68 65 72 20 6d 65 6d 6f 72 79 0a 6c 6f 63 61  ther memory.loca
d060: 74 69 6f 6e 20 69 6e 20 74 68 65 20 5b 75 73 65  tion in the [use
d070: 72 20 64 61 74 61 20 66 69 65 6c 64 5d 28 23 75  r data field](#u
d080: 64 66 29 2e 0a 0a 54 68 69 73 20 66 75 6e 63 74  df)...This funct
d090: 69 6f 6e 20 77 69 6c 6c 20 6e 6f 74 20 63 6f 70  ion will not cop
d0a0: 79 20 64 61 74 61 20 62 65 74 77 65 65 6e 20 66  y data between f
d0b0: 69 65 6c 64 73 2e 0a 0a 42 65 77 61 72 65 20 74  ields...Beware t
d0c0: 68 61 74 20 74 68 69 73 20 66 75 6e 63 74 69 6f  hat this functio
d0d0: 6e 20 77 69 6c 6c 20 5b 77 72 61 70 20 61 72 6f  n will [wrap aro
d0e0: 75 6e 64 5d 28 23 70 74 72 77 72 61 70 29 20 69  und](#ptrwrap) i
d0f0: 66 20 65 69 74 68 65 72 0a 60 73 72 63 2b 73 74  f either.`src+st
d100: 72 6c 65 6e 28 73 72 63 29 60 20 6f 72 20 60 64  rlen(src)` or `d
d110: 73 74 2b 73 74 72 6c 65 6e 28 64 73 74 29 60 20  st+strlen(dst)` 
d120: 26 67 65 3b 20 34 30 39 36 2e 0a 0a 54 68 65 20  &ge; 4096...The 
d130: 60 64 73 74 60 20 62 75 66 66 65 72 20 63 61 6e  `dst` buffer can
d140: 20 73 61 66 65 6c 79 20 6f 76 65 72 6c 61 70 20   safely overlap 
d150: 74 68 65 20 60 73 72 63 60 20 62 75 66 66 65 72  the `src` buffer
d160: 20 6f 6e 6c 79 20 69 66 20 69 74 20 69 73 20 61   only if it is a
d170: 74 20 61 0a 6c 6f 77 65 72 20 61 64 64 72 65 73  t a.lower addres
d180: 73 20 69 6e 20 6d 65 6d 6f 72 79 2e 0a 0a 2a 2a  s in memory...**
d190: 53 74 61 6e 64 61 72 64 20 56 69 6f 6c 61 74 69  Standard Violati
d1a0: 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20 52 65 74 75  ons:**..*   Retu
d1b0: 72 6e 73 20 30 2c 20 6e 6f 74 20 61 20 63 6f 70  rns 0, not a cop
d1c0: 79 20 6f 66 20 60 64 73 74 60 20 61 73 20 74 68  y of `dst` as th
d1d0: 65 20 53 74 61 6e 64 61 72 64 20 72 65 71 75 69  e Standard requi
d1e0: 72 65 73 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64  res....### <a id
d1f0: 3d 22 73 74 72 73 74 72 22 3e 3c 2f 61 3e 60 73  ="strstr"></a>`s
d200: 74 72 73 74 72 28 68 61 79 73 74 61 63 6b 2c 20  trstr(haystack, 
d210: 6e 65 65 64 6c 65 29 60 0a 0a 41 74 74 65 6d 70  needle)`..Attemp
d220: 74 73 20 74 6f 20 66 69 6e 64 20 74 68 65 20 66  ts to find the f
d230: 69 72 73 74 20 69 6e 73 74 61 6e 63 65 20 6f 66  irst instance of
d240: 20 60 6e 65 65 64 6c 65 60 20 77 69 74 68 69 6e   `needle` within
d250: 20 60 68 61 79 73 74 61 63 6b 60 2c 20 77 68 69   `haystack`, whi
d260: 63 68 0a 61 72 65 20 5b 30 2d 74 65 72 6d 69 6e  ch.are [0-termin
d270: 61 74 65 64 20 77 6f 72 64 20 73 74 72 69 6e 67  ated word string
d280: 73 5d 28 23 77 6f 72 64 73 74 72 29 2e 20 54 68  s](#wordstr). Th
d290: 69 73 20 66 75 6e 63 74 69 6f 6e e2 80 99 73 20  is function’s 
d2a0: 62 65 68 61 76 69 6f 72 20 69 73 0a 5b 75 6e 64  behavior is.[und
d2b0: 65 66 69 6e 65 64 5d 5b 75 62 5d 20 69 66 20 65  efined][ub] if e
d2c0: 69 74 68 65 72 20 62 75 66 66 65 72 20 69 73 20  ither buffer is 
d2d0: 6e 6f 74 20 30 2d 74 65 72 6d 69 6e 61 74 65 64  not 0-terminated
d2e0: 2e 0a 0a 54 68 65 20 69 6d 70 6c 65 6d 65 6e 74  ...The implement
d2f0: 61 74 69 6f 6e 20 75 73 65 73 20 74 68 65 20 5b  ation uses the [
d300: 6e 61 c3 af 76 65 20 73 74 72 69 6e 67 20 73 65  naïve string se
d310: 61 72 63 68 20 61 6c 67 6f 72 69 74 68 6d 5d 5b  arch algorithm][
d320: 6e 73 73 61 5d 2c 20 73 6f 0a 74 68 65 20 74 79  nssa], so.the ty
d330: 70 69 63 61 6c 20 65 78 65 63 75 74 69 6f 6e 20  pical execution 
d340: 74 69 6d 65 20 69 73 20 4f 28 6e 2b 6d 29 2c 20  time is O(n+m), 
d350: 62 75 74 20 74 68 65 20 77 6f 72 73 74 20 63 61  but the worst ca
d360: 73 65 20 74 69 6d 65 20 69 73 0a 26 54 68 65 74  se time is.&Thet
d370: 61 28 6e 6d 29 2e 20 44 6f 6e e2 80 99 74 20 67  a(nm). Don’t g
d380: 6f 20 65 78 70 65 63 74 69 6e 67 20 75 73 20 74  o expecting us t
d390: 6f 20 62 75 79 20 65 78 65 63 75 74 69 6f 6e 20  o buy execution 
d3a0: 73 70 65 65 64 20 77 69 74 68 0a 70 72 65 70 72  speed with.prepr
d3b0: 6f 63 65 73 73 69 6e 67 20 73 74 65 70 73 20 61  ocessing steps a
d3c0: 73 20 77 69 74 68 20 5b 42 4d 48 5d 5b 62 6d 68  s with [BMH][bmh
d3d0: 5d 20 6f 72 20 5b 4b 4d 50 5d 5b 6b 6d 70 5d 21  ] or [KMP][kmp]!
d3e0: 0a 0a 42 6f 74 68 20 74 68 65 20 60 68 61 79 73  ..Both the `hays
d3f0: 74 61 63 6b 60 20 61 6e 64 20 60 6e 65 65 64 6c  tack` and `needl
d400: 65 60 20 62 75 66 66 65 72 20 70 6f 69 6e 74 65  e` buffer pointe
d410: 72 73 20 61 72 65 20 6f 66 66 73 65 74 73 20 77  rs are offsets w
d420: 69 74 68 69 6e 20 74 68 65 0a 5b 75 73 65 72 20  ithin the.[user 
d430: 64 61 74 61 20 66 69 65 6c 64 5d 28 23 75 64 66  data field](#udf
d440: 29 2e 0a 0a 42 65 77 61 72 65 20 74 68 61 74 20  )...Beware that 
d450: 74 68 69 73 20 66 75 6e 63 74 69 6f 6e 20 77 69  this function wi
d460: 6c 6c 20 5b 77 72 61 70 20 61 72 6f 75 6e 64 5d  ll [wrap around]
d470: 28 23 70 74 72 77 72 61 70 29 20 69 66 20 65 69  (#ptrwrap) if ei
d480: 74 68 65 72 0a 60 68 61 79 73 74 61 63 6b 2b 73  ther.`haystack+s
d490: 74 72 6c 65 6e 28 68 61 79 73 74 61 63 6b 29 60  trlen(haystack)`
d4a0: 20 6f 72 20 60 6e 65 65 64 6c 65 2b 73 74 72 6c   or `needle+strl
d4b0: 65 6e 28 6e 65 65 64 6c 65 29 60 20 26 67 65 3b  en(needle)` &ge;
d4c0: 20 34 30 39 36 2c 0a 63 6f 6e 74 69 6e 75 69 6e   4096,.continuin
d4d0: 67 20 74 68 65 20 73 65 61 72 63 68 20 6f 72 20  g the search or 
d4e0: 6d 61 74 63 68 20 28 72 65 73 70 65 63 74 69 76  match (respectiv
d4f0: 65 6c 79 29 20 66 72 6f 6d 20 74 68 61 74 20 70  ely) from that p
d500: 6f 69 6e 74 2e 0a 0a 2a 2a 52 65 74 75 72 6e 73  oint...**Returns
d510: 3a 2a 2a 0a 0a 2a 20 20 20 2a 61 20 70 6f 69 6e  :**..*   *a poin
d520: 74 65 72 20 74 6f 20 74 68 65 20 66 69 72 73 74  ter to the first
d530: 20 6e 65 65 64 6c 65 2a 2c 20 69 66 20 6f 6e 65   needle*, if one
d540: 20 69 73 20 66 6f 75 6e 64 20 77 69 74 68 69 6e   is found within
d550: 20 74 68 65 20 68 61 79 73 74 61 63 6b 0a 0a 2a   the haystack..*
d560: 20 20 20 2a 7a 65 72 6f 2a 20 69 66 20 65 69 74     *zero* if eit
d570: 68 65 72 20 6e 6f 20 6e 65 65 64 6c 65 20 69 73  her no needle is
d580: 20 69 6e 20 74 68 65 20 68 61 79 73 74 61 63 6b   in the haystack
d590: 2c 20 2a 6f 72 2a 20 74 68 65 20 68 61 79 73 74  , *or* the hayst
d5a0: 61 63 6b 20 69 73 0a 20 20 20 20 7a 65 72 6f 2d  ack is.    zero-
d5b0: 6c 65 6e 67 74 68 20 28 69 2e 65 2e 20 60 2a 68  length (i.e. `*h
d5c0: 61 79 73 74 61 63 6b 20 3d 3d 20 27 5c 30 27 60  aystack == '\0'`
d5d0: 29 2c 20 2a 6f 72 2a 20 74 68 65 20 6e 65 65 64  ), *or* the need
d5e0: 6c 65 20 69 73 20 62 69 67 67 65 72 0a 20 20 20  le is bigger.   
d5f0: 20 74 68 61 6e 20 74 68 65 20 68 61 79 73 74 61   than the haysta
d600: 63 6b 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56  ck..**Standard V
d610: 69 6f 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20  iolations:**..* 
d620: 20 20 4e 6f 6e 65 20 6b 6e 6f 77 6e 2e 0a 0a 5b    None known...[
d630: 62 6d 68 5d 3a 20 20 68 74 74 70 73 3a 2f 2f 65  bmh]:  https://e
d640: 6e 2e 77 69 6b 69 70 65 64 69 61 2e 6f 72 67 2f  n.wikipedia.org/
d650: 77 69 6b 69 2f 42 6f 79 65 72 25 45 32 25 38 30  wiki/Boyer%E2%80
d660: 25 39 33 4d 6f 6f 72 65 25 45 32 25 38 30 25 39  %93Moore%E2%80%9
d670: 33 48 6f 72 73 70 6f 6f 6c 5f 61 6c 67 6f 72 69  3Horspool_algori
d680: 74 68 6d 0a 5b 6b 6d 70 5d 3a 20 20 68 74 74 70  thm.[kmp]:  http
d690: 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61  s://en.wikipedia
d6a0: 2e 6f 72 67 2f 77 69 6b 69 2f 4b 6e 75 74 68 25  .org/wiki/Knuth%
d6b0: 45 32 25 38 30 25 39 33 4d 6f 72 72 69 73 25 45  E2%80%93Morris%E
d6c0: 32 25 38 30 25 39 33 50 72 61 74 74 5f 61 6c 67  2%80%93Pratt_alg
d6d0: 6f 72 69 74 68 6d 0a 5b 6e 73 73 61 5d 3a 20 68  orithm.[nssa]: h
d6e0: 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65  ttps://en.wikipe
d6f0: 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 53 74 72  dia.org/wiki/Str
d700: 69 6e 67 2d 73 65 61 72 63 68 69 6e 67 5f 61 6c  ing-searching_al
d710: 67 6f 72 69 74 68 6d 23 4e 61 25 43 33 25 41 46  gorithm#Na%C3%AF
d720: 76 65 5f 73 74 72 69 6e 67 5f 73 65 61 72 63 68  ve_string_search
d730: 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 74 6f  ...### <a id="to
d740: 75 70 70 65 72 22 3e 3c 2f 61 3e 60 74 6f 75 70  upper"></a>`toup
d750: 70 65 72 28 63 29 60 0a 0a 52 65 74 75 72 6e 73  per(c)`..Returns
d760: 20 74 68 65 20 75 70 70 65 72 63 61 73 65 20 66   the uppercase f
d770: 6f 72 6d 20 6f 66 20 41 53 43 49 49 20 63 68 61  orm of ASCII cha
d780: 72 61 63 74 65 72 20 60 63 60 20 69 66 20 69 74  racter `c` if it
d790: 20 69 73 20 6c 6f 77 65 72 63 61 73 65 2c 0a 4f   is lowercase,.O
d7a0: 74 68 65 72 77 69 73 65 2c 20 72 65 74 75 72 6e  therwise, return
d7b0: 73 20 60 63 60 20 75 6e 63 68 61 6e 67 65 64 2e  s `c` unchanged.
d7c0: 0a 0a 2a 2a 53 74 61 6e 64 61 72 64 20 56 69 6f  ..**Standard Vio
d7d0: 6c 61 74 69 6f 6e 73 3a 2a 2a 0a 0a 2a 20 20 20  lations:**..*   
d7e0: 54 68 65 72 65 20 69 73 20 6e 6f 20 60 74 6f 6c  There is no `tol
d7f0: 6f 77 65 72 28 29 60 20 69 6e 20 74 68 65 20 43  ower()` in the C
d800: 43 38 20 4c 49 42 43 2e 0a 0a 2a 20 20 20 44 6f  C8 LIBC...*   Do
d810: 65 73 20 6e 6f 74 20 6b 6e 6f 77 20 61 6e 79 74  es not know anyt
d820: 68 69 6e 67 20 61 62 6f 75 74 20 6c 6f 63 61 6c  hing about local
d830: 65 73 3b 20 61 73 73 75 6d 65 73 20 55 53 2d 41  es; assumes US-A
d840: 53 43 49 49 20 69 6e 70 75 74 2e 0a 0a 0a 23 23  SCII input....##
d850: 23 20 3c 61 20 69 64 3d 22 78 69 6e 69 74 22 3e  # <a id="xinit">
d860: 3c 2f 61 3e 60 78 69 6e 69 74 28 29 60 0a 0a 50  </a>`xinit()`..P
d870: 72 69 6e 74 73 20 74 68 65 20 43 43 38 20 63 6f  rints the CC8 co
d880: 6d 70 69 6c 65 72 e2 80 99 73 20 62 61 6e 6e 65  mpiler’s banne
d890: 72 20 6d 65 73 73 61 67 65 2e 20 54 68 69 73 20  r message. This 
d8a0: 69 73 20 69 6e 20 4c 49 42 43 20 6f 6e 6c 79 20  is in LIBC only 
d8b0: 62 65 63 61 75 73 65 0a 69 74 e2 80 99 73 20 63  because.it’s c
d8c0: 61 6c 6c 65 64 20 66 72 6f 6d 20 73 65 76 65 72  alled from sever
d8d0: 61 6c 20 70 6c 61 63 65 73 20 77 69 74 68 69 6e  al places within
d8e0: 20 43 43 38 20 69 74 73 65 6c 66 2e 0a 0a 2a 2a   CC8 itself...**
d8f0: 4e 6f 6e 73 74 61 6e 64 61 72 64 2e 2a 2a 0a 0a  Nonstandard.**..
d900: 0a 23 23 20 3c 61 20 69 64 3d 22 61 64 64 66 6e  .## <a id="addfn
d910: 22 3e 3c 2f 61 3e 41 64 64 69 74 69 6f 6e 61 6c  "></a>Additional
d920: 20 55 74 69 6c 69 74 79 20 52 6f 75 74 69 6e 65   Utility Routine
d930: 73 0a 0a 54 68 65 20 66 75 6e 63 74 69 6f 6e 73  s..The functions
d940: 20 74 68 61 74 20 43 43 38 20 75 73 65 73 20 74   that CC8 uses t
d950: 6f 20 6d 61 6e 69 70 75 6c 61 74 65 20 74 68 65  o manipulate the
d960: 20 73 6f 66 74 77 61 72 65 20 73 74 61 63 6b 20   software stack 
d970: 61 72 65 20 61 6c 73 6f 0a 61 76 61 69 6c 61 62  are also.availab
d980: 6c 65 20 74 6f 20 62 65 20 63 61 6c 6c 65 64 20  le to be called 
d990: 62 79 20 65 6e 64 2d 75 73 65 72 20 70 72 6f 67  by end-user prog
d9a0: 72 61 6d 73 3a 20 60 50 55 53 48 60 2c 20 60 50  rams: `PUSH`, `P
d9b0: 4f 50 60 2c 20 60 50 55 54 53 54 4b 60 2c 0a 60  OP`, `PUTSTK`,.`
d9c0: 50 4f 50 52 45 54 60 2c 20 61 6e 64 20 60 50 43  POPRET`, and `PC
d9d0: 41 4c 4c 60 2e 20 54 68 65 20 70 61 67 65 20 7a  ALL`. The page z
d9e0: 65 72 6f 20 70 6f 69 6e 74 65 72 73 20 66 6f 72  ero pointers for
d9f0: 20 74 68 69 73 20 73 74 61 63 6b 20 61 72 65 0a   this stack are.
da00: 69 6e 69 74 69 61 6c 69 7a 65 64 20 62 79 20 63  initialized by c
da10: 6f 64 65 20 69 6e 20 60 68 65 61 64 65 72 2e 73  ode in `header.s
da20: 62 60 2c 20 77 68 69 63 68 20 69 73 20 69 6e 6a  b`, which is inj
da30: 65 63 74 65 64 20 69 6e 74 6f 20 79 6f 75 72 0a  ected into your.
da40: 70 72 6f 67 72 61 6d e2 80 99 73 20 73 74 61 72  program’s star
da50: 74 75 70 20 73 65 71 75 65 6e 63 65 20 64 75 72  tup sequence dur
da60: 69 6e 67 20 63 6f 6d 70 69 6c 61 74 69 6f 6e 2e  ing compilation.
da70: 0a 0a 49 6e 20 61 64 64 69 74 69 6f 6e 2c 20 74  ..In addition, t
da80: 68 65 72 65 20 61 72 65 20 61 20 73 65 74 20 6f  here are a set o
da90: 66 20 66 75 6e 63 74 69 6f 6e 73 20 74 68 61 74  f functions that
daa0: 20 6d 61 79 20 62 65 20 75 73 65 64 20 74 6f 20   may be used to 
dab0: 70 72 6f 76 69 64 65 0a 74 65 6d 70 6f 72 61 72  provide.temporar
dac0: 79 20 73 74 6f 72 61 67 65 20 69 6e 20 66 69 65  y storage in fie
dad0: 6c 64 20 34 2c 20 61 63 74 69 6e 67 20 6c 69 6b  ld 4, acting lik
dae0: 65 20 61 20 74 65 6d 70 6f 72 61 72 79 20 62 69  e a temporary bi
daf0: 6e 61 72 79 20 66 69 6c 65 3a 0a 0a 60 76 6f 69  nary file:..`voi
db00: 64 20 69 69 6e 69 74 28 69 6e 74 20 61 64 64 72  d iinit(int addr
db10: 65 73 73 29 60 3a 20 52 65 73 65 74 20 74 68 65  ess)`: Reset the
db20: 20 66 69 6c 65 20 70 6f 69 6e 74 65 72 20 74 6f   file pointer to
db30: 20 61 6e 20 61 72 62 69 74 72 61 72 79 0a 61 64   an arbitrary.ad
db40: 64 72 65 73 73 20 72 61 6e 67 65 20 30 2d 34 30  dress range 0-40
db50: 39 35 2e 0a 0a 60 76 6f 69 64 20 73 74 72 69 28  95...`void stri(
db60: 69 6e 74 20 76 61 6c 75 65 29 60 3a 20 53 74 6f  int value)`: Sto
db70: 72 65 20 e2 80 98 76 61 6c 75 65 e2 80 99 20 61  re ‘value’ a
db80: 74 20 74 68 65 20 63 75 72 72 65 6e 74 20 61 64  t the current ad
db90: 64 72 65 73 73 2c 20 61 6e 64 0a 69 6e 63 72 65  dress, and.incre
dba0: 6d 65 6e 74 20 74 68 65 20 61 64 64 72 65 73 73  ment the address
dbb0: 20 70 6f 69 6e 74 65 72 2e 0a 0a 60 69 6e 74 20   pointer...`int 
dbc0: 73 74 72 6c 28 29 60 3a 20 52 65 61 64 20 74 68  strl()`: Read th
dbd0: 65 20 77 6f 72 64 20 61 74 20 74 68 65 20 63 75  e word at the cu
dbe0: 72 72 65 6e 74 20 61 64 64 72 65 73 73 2c 20 61  rrent address, a
dbf0: 6e 64 20 64 6f 20 6e 6f 74 20 69 6e 63 72 65 6d  nd do not increm
dc00: 65 6e 74 0a 74 68 65 20 61 64 64 72 65 73 73 2e  ent.the address.
dc10: 0a 0a 60 69 6e 74 20 73 74 72 64 28 29 60 3a 20  ..`int strd()`: 
dc20: 52 65 61 64 20 74 68 65 20 77 6f 72 64 20 61 74  Read the word at
dc30: 20 74 68 65 20 63 75 72 72 65 6e 74 20 61 64 64   the current add
dc40: 72 65 73 73 2c 20 61 6e 64 20 69 6e 63 72 65 6d  ress, and increm
dc50: 65 6e 74 20 74 68 65 0a 61 64 64 72 65 73 73 2e  ent the.address.
dc60: 0a 0a 41 73 20 66 69 65 6c 64 20 34 20 69 73 20  ..As field 4 is 
dc70: 6e 6f 74 20 75 73 65 64 20 62 79 20 4f 53 2f 38  not used by OS/8
dc80: 2c 20 79 6f 75 72 20 70 72 6f 67 72 61 6d 20 6d  , your program m
dc90: 61 79 20 75 73 65 20 74 68 65 20 65 6e 74 69 72  ay use the entir
dca0: 65 20 66 69 65 6c 64 2e 0a 54 68 69 73 20 6c 69  e field..This li
dcb0: 62 72 61 72 79 20 63 6f 64 65 20 64 6f 65 73 20  brary code does 
dcc0: 6e 6f 74 20 63 68 65 63 6b 20 66 6f 72 20 6f 76  not check for ov
dcd0: 65 72 66 6c 6f 77 3a 20 67 6f 69 6e 67 20 62 65  erflow: going be
dce0: 79 6f 6e 64 20 61 64 64 72 65 73 73 20 34 30 39  yond address 409
dcf0: 35 0a 77 69 6c 6c 20 73 69 6d 70 6c 79 20 77 72  5.will simply wr
dd00: 61 70 20 74 6f 20 61 64 64 72 65 73 73 20 30 2e  ap to address 0.
dd10: 0a 0a 0a 0a 3c 61 20 69 64 3d 22 65 78 61 6d 70  ....<a id="examp
dd20: 6c 65 73 22 3e 3c 2f 61 3e 0a 23 23 20 54 72 79  les"></a>.## Try
dd30: 69 6e 67 20 74 68 65 20 45 78 61 6d 70 6c 65 73  ing the Examples
dd40: 0a 0a 54 68 65 20 73 74 61 6e 64 61 72 64 20 50  ..The standard P
dd50: 69 44 50 2d 38 2f 49 20 4f 53 2f 38 20 52 4b 30  iDP-8/I OS/8 RK0
dd60: 35 20 62 6f 6f 74 20 64 69 73 6b 20 63 6f 6e 74  5 boot disk cont
dd70: 61 69 6e 73 20 73 65 76 65 72 61 6c 20 65 78 61  ains several exa
dd80: 6d 70 6c 65 0a 43 20 70 72 6f 67 72 61 6d 73 20  mple.C programs 
dd90: 74 68 61 74 20 74 68 65 20 4f 53 2f 38 20 76 65  that the OS/8 ve
dda0: 72 73 69 6f 6e 20 6f 66 20 43 43 38 20 69 73 20  rsion of CC8 is 
ddb0: 61 62 6c 65 20 74 6f 20 63 6f 6d 70 69 6c 65 2e  able to compile.
ddc0: 0a 0a 54 6f 20 74 72 79 20 74 68 65 20 4f 53 2f  ..To try the OS/
ddd0: 38 20 76 65 72 73 69 6f 6e 20 6f 66 20 43 43 38  8 version of CC8
dde0: 20 6f 75 74 2c 20 62 6f 6f 74 20 4f 53 2f 38 20   out, boot OS/8 
ddf0: 77 69 74 68 69 6e 20 74 68 65 20 50 69 44 50 2d  within the PiDP-
de00: 38 2f 49 0a 65 6e 76 69 72 6f 6e 6d 65 6e 74 20  8/I.environment 
de10: 61 73 20 79 6f 75 20 6e 6f 72 6d 61 6c 6c 79 20  as you normally 
de20: 77 6f 75 6c 64 2c 20 74 68 65 6e 20 74 72 79 20  would, then try 
de30: 62 75 69 6c 64 69 6e 67 20 6f 6e 65 20 6f 66 20  building one of 
de40: 74 68 65 0a 65 78 61 6d 70 6c 65 73 3a 0a 0a 20  the.examples:.. 
de50: 20 20 20 2e 45 58 45 20 43 43 52 20 20 20 e2 87     .EXE CCR   
de60: a0 20 42 41 54 43 48 20 77 72 61 70 70 65 72 20   BATCH wrapper 
de70: 61 72 6f 75 6e 64 20 43 43 3f 2e 53 56 3a 20 22  around CC?.SV: "
de80: 43 6f 6d 70 69 6c 65 20 43 20 61 6e 64 20 52 75  Compile C and Ru
de90: 6e 22 0a 20 20 20 20 3e 70 73 2e 63 20 20 20 20  n".    >ps.c    
dea0: 20 20 e2 87 a0 20 74 61 6b 65 73 20 6e 61 6d 65    ⇠ takes name
deb0: 20 6f 66 20 43 20 70 72 6f 67 72 61 6d 2c 20 62   of C program, b
dec0: 75 69 6c 64 73 2c 20 6c 69 6e 6b 73 2c 20 61 6e  uilds, links, an
ded0: 64 20 72 75 6e 73 20 69 74 0a 0a 54 68 69 73 20  d runs it..This 
dee0: 65 78 61 6d 70 6c 65 20 69 73 20 70 61 72 74 69  example is parti
def0: 63 75 6c 61 72 6c 79 20 69 6e 74 65 72 65 73 74  cularly interest
df00: 69 6e 67 2e 20 49 74 20 67 65 6e 65 72 61 74 65  ing. It generate
df10: 73 0a 50 61 73 63 61 6c e2 80 99 73 20 74 72 69  s.Pascal’s tri
df20: 61 6e 67 6c 65 20 77 69 74 68 6f 75 74 20 75 73  angle without us
df30: 69 6e 67 20 66 61 63 74 6f 72 69 61 6c 73 2c 20  ing factorials, 
df40: 77 68 69 63 68 20 61 72 65 20 61 20 62 69 74 20  which are a bit 
df50: 6f 75 74 20 6f 66 0a 72 61 6e 67 65 20 66 6f 72  out of.range for
df60: 20 31 32 20 62 69 74 73 21 0a 0a 54 68 65 20 6f   12 bits!..The o
df70: 74 68 65 72 20 65 78 61 6d 70 6c 65 73 20 70 72  ther examples pr
df80: 65 69 6e 73 74 61 6c 6c 65 64 20 61 72 65 3a 0a  einstalled are:.
df90: 0a 2a 20 20 20 2a 2a 3c 63 6f 64 65 3e 63 61 6c  .*   **<code>cal
dfa0: 63 2e 63 3c 2f 63 6f 64 65 3e 2a 2a 20 2d 20 41  c.c</code>** - A
dfb0: 20 73 69 6d 70 6c 65 20 34 2d 66 75 6e 63 74 69   simple 4-functi
dfc0: 6f 6e 20 63 61 6c 63 75 6c 61 74 6f 72 20 70 72  on calculator pr
dfd0: 6f 67 72 61 6d 2e 0a 0a 2a 20 20 20 2a 2a 3c 63  ogram...*   **<c
dfe0: 6f 64 65 3e 70 64 2e 63 3c 2f 63 6f 64 65 3e 2a  ode>pd.c</code>*
dff0: 2a 20 2d 20 53 68 6f 77 73 20 6d 65 74 68 6f 64  * - Shows method
e000: 73 20 66 6f 72 20 64 6f 69 6e 67 20 64 6f 75 62  s for doing doub
e010: 6c 65 2d 70 72 65 63 69 73 69 6f 6e 0a 20 20 20  le-precision.   
e020: 20 28 69 2e 65 2e 20 32 34 2d 62 69 74 29 20 69   (i.e. 24-bit) i
e030: 6e 74 65 67 65 72 20 63 61 6c 63 75 6c 61 74 69  nteger calculati
e040: 6f 6e 73 2e 0a 0a 2a 20 20 20 2a 2a 3c 63 6f 64  ons...*   **<cod
e050: 65 3e 68 6c 62 2e 63 3c 2f 63 6f 64 65 3e 2a 2a  e>hlb.c</code>**
e060: 20 2d 20 47 65 6e 65 72 61 74 65 73 20 5b 48 69   - Generates [Hi
e070: 6c 62 65 72 74 20 63 75 72 76 65 73 5d 5b 68 63  lbert curves][hc
e080: 5d 20 6f 6e 20 61 20 54 65 6b 34 30 31 30 0a 20  ] on a Tek4010. 
e090: 20 20 20 73 65 72 69 65 73 20 64 69 73 70 6c 61     series displa
e0a0: 79 20 75 73 69 6e 67 20 72 61 77 20 74 65 72 6d  y using raw term
e0b0: 69 6e 61 6c 20 63 6f 64 65 73 2e 20 54 68 65 72  inal codes. Ther
e0c0: 65 66 6f 72 65 2c 20 79 6f 75 20 6d 75 73 74 20  efore, you must 
e0d0: 62 65 0a 20 20 20 20 72 75 6e 6e 69 6e 67 20 61  be.    running a
e0e0: 20 54 65 6b 34 30 31 30 20 65 6d 75 6c 61 74 6f   Tek4010 emulato
e0f0: 72 20 77 68 65 6e 20 72 75 6e 6e 69 6e 67 20 74  r when running t
e100: 68 69 73 20 70 72 6f 67 72 61 6d 2c 20 65 6c 73  his program, els
e110: 65 20 79 6f 75 20 77 69 6c 6c 0a 20 20 20 20 67  e you will.    g
e120: 65 74 20 67 61 72 62 61 67 65 20 6f 6e 20 74 68  et garbage on th
e130: 65 20 64 69 73 70 6c 61 79 21 0a 0a 2a 20 20 20  e display!..*   
e140: 2a 2a 3c 63 6f 64 65 3e 66 69 62 2e 63 3c 2f 63  **<code>fib.c</c
e150: 6f 64 65 3e 2a 2a 20 2d 20 43 61 6c 63 75 6c 61  ode>** - Calcula
e160: 74 65 73 20 74 68 65 20 66 69 72 73 74 20 31 30  tes the first 10
e170: 20 46 69 62 6f 6e 61 63 63 69 20 6e 75 6d 62 65   Fibonacci numbe
e180: 72 73 2e 0a 20 20 20 20 54 68 69 73 20 69 6d 70  rs..    This imp
e190: 6c 69 63 69 74 6c 79 20 64 65 6d 6f 6e 73 74 72  licitly demonstr
e1a0: 61 74 65 73 20 43 43 38 27 73 20 61 62 69 6c 69  ates CC8's abili
e1b0: 74 79 20 74 6f 20 68 61 6e 64 6c 65 20 72 65 63  ty to handle rec
e1c0: 75 72 73 69 76 65 0a 20 20 20 20 66 75 6e 63 74  ursive.    funct
e1d0: 69 6f 6e 20 63 61 6c 6c 73 2e 0a 0a 2a 20 20 20  ion calls...*   
e1e0: 2a 2a 3c 63 6f 64 65 3e 62 61 73 69 63 2e 63 3c  **<code>basic.c<
e1f0: 2f 63 6f 64 65 3e 2a 2a 20 2d 20 41 20 73 69 6d  /code>** - A sim
e200: 70 6c 65 20 42 61 73 69 63 20 69 6e 74 65 72 70  ple Basic interp
e210: 72 65 74 65 72 20 75 73 65 64 20 74 6f 20 74 65  reter used to te
e220: 73 74 0a 20 20 20 20 61 20 73 69 6d 70 6c 65 20  st.    a simple 
e230: 72 65 63 75 72 73 69 76 65 20 65 78 70 72 65 73  recursive expres
e240: 73 69 6f 6e 20 70 72 6f 63 65 73 73 6f 72 2e 0a  sion processor..
e250: 0a 2a 20 20 20 2a 2a 3c 63 6f 64 65 3e 66 6f 72  .*   **<code>for
e260: 74 68 2e 63 3c 2f 63 6f 64 65 3e 2a 2a 20 2d 20  th.c</code>** - 
e270: 41 20 73 69 6d 70 6c 65 20 46 6f 72 74 68 20 69  A simple Forth i
e280: 6e 74 65 72 70 72 65 74 65 72 20 75 73 65 64 20  nterpreter used 
e290: 74 6f 20 74 65 73 74 0a 20 20 20 20 73 77 69 74  to test.    swit
e2a0: 63 68 20 73 74 61 74 65 6d 6d 65 6e 74 73 20 65  ch statemments e
e2b0: 74 63 2e 0a 0a 54 68 65 20 74 77 6f 20 69 6e 74  tc...The two int
e2c0: 65 72 70 65 74 65 72 73 20 61 72 65 20 71 75 69  erpeters are qui
e2d0: 74 65 20 63 6f 6d 70 6c 65 78 2c 20 70 61 72 74  te complex, part
e2e0: 69 63 75 6c 61 72 6c 79 20 74 68 65 20 46 6f 72  icularly the For
e2f0: 74 68 0a 69 6e 74 65 72 70 72 65 74 65 72 2c 20  th.interpreter, 
e300: 77 68 69 63 68 20 63 6f 6e 74 61 69 6e 73 20 33  which contains 3
e310: 30 30 20 6c 69 6e 65 73 20 6f 66 20 63 6f 64 65  00 lines of code
e320: 20 61 6e 64 20 69 6d 70 6c 65 6d 65 6e 74 73 20   and implements 
e330: 61 20 6e 75 6d 62 65 72 20 6f 66 0a 62 61 73 69  a number of.basi
e340: 63 20 46 6f 72 74 68 20 66 75 6e 63 74 69 6f 6e  c Forth function
e350: 73 2e 20 54 68 69 73 20 65 78 61 6d 70 6c 65 20  s. This example 
e360: 69 73 20 69 6e 74 65 6e 64 65 64 20 74 6f 20 73  is intended to s
e370: 68 6f 77 20 77 68 61 74 20 63 61 6e 20 62 65 0a  how what can be.
e380: 63 72 61 6d 6d 65 64 20 69 6e 74 6f 20 34 6b 20  crammed into 4k 
e390: 6f 66 20 63 6f 72 65 2e 0a 0a 0a 41 6e 6f 74 68  of core....Anoth
e3a0: 65 72 20 73 65 74 20 6f 66 20 65 78 61 6d 70 6c  er set of exampl
e3b0: 65 73 20 6e 6f 74 20 70 72 65 69 6e 73 74 61 6c  es not preinstal
e3c0: 6c 65 64 20 6f 6e 20 74 68 65 20 4f 53 2f 38 20  led on the OS/8 
e3d0: 64 69 73 6b 20 61 72 65 0a 60 65 78 61 6d 70 6c  disk are.`exampl
e3e0: 65 73 2f 70 65 70 30 30 31 2d 2a 2e 63 60 2c 20  es/pep001-*.c`, 
e3f0: 77 68 69 63 68 20 61 72 65 20 64 65 73 63 72 69  which are descri
e400: 62 65 64 20 5b 65 6c 73 65 77 68 65 72 65 5d 5b  bed [elsewhere][
e410: 70 63 65 5d 2e 0a 0a 5b 68 63 5d 3a 20 20 68 74  pce]...[hc]:  ht
e420: 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64  tps://en.wikiped
e430: 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 48 69 6c 62  ia.org/wiki/Hilb
e440: 65 72 74 5f 63 75 72 76 65 0a 5b 70 63 65 5d 3a  ert_curve.[pce]:
e450: 20 2f 77 69 6b 69 3f 6e 61 6d 65 3d 50 45 50 30   /wiki?name=PEP0
e460: 30 31 2e 43 0a 0a 0a 23 23 20 3c 61 20 69 64 3d  01.C...## <a id=
e470: 22 65 78 65 73 22 3e 3c 2f 61 3e 4d 61 6b 69 6e  "exes"></a>Makin
e480: 67 20 45 78 65 63 75 74 61 62 6c 65 73 20 0a 0a  g Executables ..
e490: 45 78 65 63 75 74 69 6e 67 20 60 43 43 52 2e 42  Executing `CCR.B
e4a0: 49 60 20 6c 6f 61 64 73 2c 20 6c 69 6e 6b 73 2c  I` loads, links,
e4b0: 20 61 6e 64 20 72 75 6e 73 20 79 6f 75 72 20 43   and runs your C
e4c0: 20 70 72 6f 67 72 61 6d 20 77 69 74 68 6f 75 74   program without
e4d0: 0a 70 72 6f 64 75 63 69 6e 67 20 61 6e 20 65 78  .producing an ex
e4e0: 65 63 75 74 61 62 6c 65 20 66 69 6c 65 20 6f 6e  ecutable file on
e4f0: 20 64 69 73 6b 2e 20 20 59 6f 75 20 6e 65 65 64   disk.  You need
e500: 20 6f 6e 6c 79 20 61 20 73 6d 61 6c 6c 20 76 61   only a small va
e510: 72 69 61 74 69 6f 6e 0a 6f 6e 20 74 68 69 73 20  riation.on this 
e520: 42 41 54 43 48 20 66 69 6c 65 27 73 20 63 6f 6e  BATCH file's con
e530: 74 65 6e 74 73 20 74 6f 20 67 65 74 20 61 6e 20  tents to get an 
e540: 65 78 65 63 75 74 61 62 6c 65 20 63 6f 72 65 20  executable core 
e550: 69 6d 61 67 65 20 74 68 61 74 0a 79 6f 75 20 63  image that.you c
e560: 61 6e 20 72 75 6e 20 77 69 74 68 20 74 68 65 20  an run with the 
e570: 4f 53 2f 38 20 60 52 60 20 63 6f 6d 6d 61 6e 64  OS/8 `R` command
e580: 3a 0a 0a 20 20 20 20 2e 52 20 43 43 20 20 20 20  :..    .R CC    
e590: 20 20 20 20 20 20 20 20 20 20 20 20 20 20 20 e2                 
e5a0: 87 a0 20 6b 69 6e 64 61 20 6c 69 6b 65 20 55 6e   kinda like Un
e5b0: 69 78 20 63 63 28 31 29 0a 20 20 20 20 3e 6d 79  ix cc(1).    >my
e5c0: 70 72 6f 67 2e 63 0a 20 20 20 20 2e 43 4f 4d 50  prog.c.    .COMP
e5d0: 20 43 43 2e 53 42 0a 20 20 20 20 2e 52 20 4c 4f   CC.SB.    .R LO
e5e0: 41 44 45 52 0a 20 20 20 20 2a 43 43 2c 4c 49 42  ADER.    *CC,LIB
e5f0: 43 2f 49 2f 4f 24 20 20 20 20 20 20 20 20 20 20  C/I/O$          
e600: 20 e2 87 a0 20 24 20 3d 20 45 73 63 61 70 65 0a   ⇠ $ = Escape.
e610: 20 20 20 20 2e 53 41 56 45 20 53 59 53 3a 4d 59      .SAVE SYS:MY
e620: 50 52 4f 47 0a 0a 49 66 20 79 6f 75 27 76 65 20  PROG..If you've 
e630: 6a 75 73 74 20 72 75 6e 20 60 45 58 45 20 43 43  just run `EXE CC
e640: 52 60 20 6f 6e 20 60 6d 79 70 72 6f 67 2e 63 60  R` on `myprog.c`
e650: 2c 20 79 6f 75 20 63 61 6e 20 73 6b 69 70 20 74  , you can skip t
e660: 68 65 20 60 43 43 60 20 61 6e 64 0a 60 43 4f 4d  he `CC` and.`COM
e670: 50 60 20 73 74 65 70 73 20 61 62 6f 76 65 2c 20  P` steps above, 
e680: 72 65 75 73 69 6e 67 20 74 68 65 20 60 43 43 2e  reusing the `CC.
e690: 52 4c 60 20 66 69 6c 65 20 74 68 61 74 20 77 61  RL` file that wa
e6a0: 73 20 6c 65 66 74 20 62 65 68 69 6e 64 2e 0a 0a  s left behind...
e6b0: 42 61 73 69 63 61 6c 6c 79 2c 20 77 65 20 6c 65  Basically, we le
e6c0: 61 76 65 20 74 68 65 20 60 2f 47 60 20 22 67 6f  ave the `/G` "go
e6d0: 22 20 73 77 69 74 63 68 20 6f 66 66 20 6f 66 20  " switch off of 
e6e0: 74 68 65 20 63 6f 6d 6d 61 6e 64 20 74 6f 20 4c  the command to L
e6f0: 4f 41 44 45 52 0a 73 6f 20 74 68 61 74 20 74 68  OADER.so that th
e700: 65 20 70 72 6f 67 72 61 6d 20 69 73 20 6c 65 66  e program is lef
e710: 74 20 69 6e 20 69 74 73 20 70 72 65 2d 72 75 6e  t in its pre-run
e720: 20 73 74 61 74 65 20 69 6e 20 63 6f 72 65 20 73   state in core s
e730: 6f 20 74 68 61 74 0a 60 53 41 56 45 60 20 63 61  o that.`SAVE` ca
e740: 6e 20 63 61 70 74 75 72 65 20 69 74 20 74 6f 20  n capture it to 
e750: 64 69 73 6b 2e 0a 0a 0a 23 23 20 3c 61 20 69 64  disk....## <a id
e760: 3d 22 6d 65 6d 6f 72 79 22 3e 3c 2f 61 3e 4d 65  ="memory"></a>Me
e770: 6d 6f 72 79 20 4d 6f 64 65 6c 0a 0a 54 68 65 20  mory Model..The 
e780: 4f 53 2f 38 20 46 4f 52 54 52 41 4e 20 49 49 20  OS/8 FORTRAN II 
e790: 6c 69 6e 6b 69 6e 67 20 6c 6f 61 64 65 72 20 28  linking loader (
e7a0: 60 4c 4f 41 44 45 52 2e 53 56 60 29 20 64 65 74  `LOADER.SV`) det
e7b0: 65 72 6d 69 6e 65 73 20 74 68 65 20 63 6f 72 65  ermines the core
e7c0: 0a 6d 65 6d 6f 72 79 20 6c 61 79 6f 75 74 20 66  .memory layout f
e7d0: 6f 72 20 74 68 65 20 62 75 69 6c 74 20 70 72 6f  or the built pro
e7e0: 67 72 61 6d 73 2e 20 49 74 20 69 73 20 66 72 65  grams. It is fre
e7f0: 65 20 74 6f 20 70 6c 61 63 65 20 63 6f 64 65 20  e to place code 
e800: 61 6e 64 20 64 61 74 61 0a 77 68 65 72 65 76 65  and data.whereve
e810: 72 20 69 74 20 6c 69 6b 65 73 2c 20 62 75 74 20  r it likes, but 
e820: 74 68 65 20 66 6f 6c 6c 6f 77 69 6e 67 20 69 73  the following is
e830: 20 61 20 70 6c 61 75 73 69 62 6c 65 20 6c 61 79   a plausible lay
e840: 6f 75 74 20 69 74 20 63 6f 75 6c 64 0a 63 68 6f  out it could.cho
e850: 6f 73 65 3a 0a 0a 2a 2a 46 69 65 6c 64 20 30 3a  ose:..**Field 0:
e860: 2a 2a 20 46 4f 52 54 52 41 4e 20 6c 69 62 72 61  ** FORTRAN libra
e870: 72 79 20 75 74 69 6c 69 74 79 20 66 75 6e 63 74  ry utility funct
e880: 69 6f 6e 73 20 61 6e 64 20 4f 53 2f 38 20 49 2f  ions and OS/8 I/
e890: 4f 20 73 79 73 74 65 6d 0a 0a 2a 2a 46 69 65 6c  O system..**Fiel
e8a0: 64 20 31 3a 2a 2a 20 54 68 65 20 75 73 65 72 20  d 1:** The user 
e8b0: 64 61 74 61 20 66 69 65 6c 64 20 28 55 44 46 29  data field (UDF)
e8c0: 3a 20 67 6c 6f 62 61 6c 73 2c 20 6c 69 74 65 72  : globals, liter
e8d0: 61 6c 73 2c 20 61 6e 64 20 73 74 61 63 6b 0a 0a  als, and stack..
e8e0: 2a 2a 46 69 65 6c 64 20 32 3a 2a 2a 20 54 68 65  **Field 2:** The
e8f0: 20 70 72 6f 67 72 61 6d 27 73 20 65 78 65 63 75   program's execu
e900: 74 61 62 6c 65 20 63 6f 64 65 0a 0a 2a 2a 46 69  table code..**Fi
e910: 65 6c 64 20 33 3a 2a 2a 20 54 68 65 20 4c 49 42  eld 3:** The LIB
e920: 43 20 6c 69 62 72 61 72 79 20 63 6f 64 65 0a 0a  C library code..
e930: 2a 2a 46 69 65 6c 64 20 34 3a 2a 2a 20 28 4f 70  **Field 4:** (Op
e940: 74 69 6f 6e 61 6c 29 20 73 65 65 20 74 68 65 20  tional) see the 
e950: 62 69 6e 61 72 79 20 75 74 69 6c 69 74 69 65 73  binary utilities
e960: 20 61 62 6f 76 65 20 28 73 74 72 69 2e 2e 2e 29   above (stri...)
e970: 2e 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 6f 73  ...### <a id="os
e980: 38 72 65 73 22 3e 3c 2f 61 3e 4f 53 2f 38 20 52  8res"></a>OS/8 R
e990: 65 73 65 72 76 61 74 69 6f 6e 73 0a 0a 54 68 65  eservations..The
e9a0: 20 75 70 70 65 72 6d 6f 73 74 20 70 61 67 65 20   uppermost page 
e9b0: 6f 66 20 66 69 65 6c 64 73 20 30 20 74 68 72 75  of fields 0 thru
e9c0: 20 32 20 68 6f 6c 64 20 74 68 65 0a 5b 72 65 73   2 hold the.[res
e9d0: 69 64 65 6e 74 20 70 6f 72 74 69 6f 6e 20 6f 66  ident portion of
e9e0: 20 4f 53 2f 38 5d 5b 6f 73 38 72 65 73 5d 20 61   OS/8][os8res] a
e9f0: 6e 64 20 74 68 65 72 65 66 6f 72 65 20 6d 75 73  nd therefore mus
ea00: 74 20 6e 6f 74 20 62 65 20 74 6f 75 63 68 65 64  t not be touched
ea10: 20 62 79 0a 61 20 70 72 6f 67 72 61 6d 20 62 75   by.a program bu
ea20: 69 6c 74 20 77 69 74 68 20 43 43 38 20 77 68 69  ilt with CC8 whi
ea30: 6c 65 20 72 75 6e 6e 69 6e 67 20 75 6e 64 65 72  le running under
ea40: 20 4f 53 2f 38 2e 20 46 6f 72 20 65 78 61 6d 70   OS/8. For examp
ea50: 6c 65 2c 20 74 68 65 0a 5b 4f 53 2f 38 20 6b 65  le, the.[OS/8 ke
ea60: 79 62 6f 61 72 64 20 6d 6f 6e 69 74 6f 72 5d 5b  yboard monitor][
ea70: 6f 73 38 6b 62 64 5d 20 72 65 2d 65 6e 74 72 79  os8kbd] re-entry
ea80: 20 70 6f 69 6e 74 20 69 73 20 61 74 20 30 37 36   point is at 076
ea90: 30 30 e2 82 88 2c 20 5b 74 68 65 20 6f 75 74 70  00₈, [the outp
eaa0: 75 74 0a 66 69 6c 65 20 74 61 62 6c 65 5d 5b 6f  ut.file table][o
eab0: 73 38 6f 66 74 5d 20 69 73 20 61 74 20 31 37 36  s8oft] is at 176
eac0: 30 30 e2 82 88 2c 20 61 6e 64 20 5b 74 68 65 20  00₈, and [the 
ead0: 55 53 52 5d 5b 6f 73 38 75 73 72 5d 20 69 73 20  USR][os8usr] is 
eae0: 61 74 20 31 37 37 30 30 e2 82 88 2e 0a 54 68 65  at 17700₈..The
eaf0: 20 72 65 73 69 64 65 6e 74 20 70 61 72 74 73 20   resident parts 
eb00: 6f 66 20 64 65 76 69 63 65 20 64 72 69 76 65 72  of device driver
eb10: 73 20 61 6c 73 6f 20 6c 69 76 65 20 75 70 20 68  s also live up h
eb20: 65 72 65 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64  ere....### <a id
eb30: 3d 22 7a 65 72 6f 70 67 22 3e 3c 2f 61 3e 5a 65  ="zeropg"></a>Ze
eb40: 72 6f 20 50 61 67 65 20 55 73 61 67 65 0a 0a 54  ro Page Usage..T
eb50: 68 65 20 66 69 72 73 74 20 74 68 69 6e 67 20 74  he first thing t
eb60: 6f 20 67 65 74 20 63 6c 65 61 72 20 69 6e 20 79  o get clear in y
eb70: 6f 75 72 20 6d 69 6e 64 20 69 73 20 74 68 61 74  our mind is that
eb80: 20 74 68 65 72 65 20 61 72 65 20 61 74 20 6c 65   there are at le
eb90: 61 73 74 0a 2a 74 68 72 65 65 2a 20 7a 65 72 6f  ast.*three* zero
eba0: 20 70 61 67 65 73 20 69 6e 76 6f 6c 76 65 64 20   pages involved 
ebb0: 68 65 72 65 2c 20 61 6e 64 20 70 6f 73 73 69 62  here, and possib
ebc0: 6c 79 20 66 6f 75 72 2c 20 64 65 70 65 6e 64 69  ly four, dependi
ebd0: 6e 67 20 6f 6e 20 68 6f 77 0a 60 4c 4f 41 44 45  ng on how.`LOADE
ebe0: 52 2e 53 56 60 20 63 68 6f 6f 73 65 73 20 74 6f  R.SV` chooses to
ebf0: 20 61 72 72 61 6e 67 65 20 79 6f 75 72 20 70 72   arrange your pr
ec00: 6f 67 72 61 6d 20 69 6e 20 6d 65 6d 6f 72 79 2e  ogram in memory.
ec10: 20 28 57 65 20 67 65 74 20 69 6e 74 6f 20 74 68   (We get into th
ec20: 65 0a 6e 69 74 74 79 20 67 72 69 74 74 79 20 6f  e.nitty gritty o
ec30: 66 20 74 68 61 74 20 5b 62 65 6c 6f 77 5d 28 23  f that [below](#
ec40: 66 6c 61 79 6f 75 74 29 2e 29 20 54 68 65 72 65  flayout).) There
ec50: 20 61 72 65 20 64 69 66 66 65 72 65 6e 74 20 72   are different r
ec60: 75 6c 65 73 20 66 6f 72 0a 65 61 63 68 20 66 69  ules for.each fi
ec70: 65 6c 64 2e 0a 0a 54 68 65 20 66 69 65 6c 64 20  eld...The field 
ec80: 63 6f 6e 74 61 69 6e 69 6e 67 20 74 68 65 20 75  containing the u
ec90: 73 65 72 e2 80 99 73 20 65 78 65 63 75 74 61 62  ser’s executab
eca0: 6c 65 20 63 6f 64 65 20 63 61 6e 20 61 6c 73 6f  le code can also
ecb0: 20 68 61 76 65 20 63 6f 64 65 20 66 72 6f 6d 0a   have code from.
ecc0: 74 68 65 20 46 4f 52 54 52 41 4e 20 49 49 20 72  the FORTRAN II r
ecd0: 75 6e 20 74 69 6d 65 20 6c 69 62 72 61 72 79 20  un time library 
ece0: 69 6e 20 69 74 2c 20 65 73 70 65 63 69 61 6c 6c  in it, especiall
ecf0: 79 20 77 68 65 6e 20 74 68 65 20 75 73 65 72 e2  y when the user
ed00: 80 99 73 0a 70 72 6f 67 72 61 6d 20 69 73 20 73  s.program is s
ed10: 6d 61 6c 6c 20 61 6e 64 20 69 74 73 20 75 73 65  mall and its use
ed20: 20 6f 66 20 46 4f 52 54 52 41 4e 20 49 49 20 62   of FORTRAN II b
ed30: 61 73 65 64 20 6c 69 62 72 61 72 79 20 72 6f 75  ased library rou
ed40: 74 69 6e 65 73 20 69 73 0a 6d 6f 64 65 73 74 2e  tines is.modest.
ed50: 20 28 57 65 20 67 69 76 65 20 61 6e 20 65 78 61   (We give an exa
ed60: 6d 70 6c 65 20 6f 66 20 74 68 69 73 20 5b 62 65  mple of this [be
ed70: 6c 6f 77 5d 28 23 66 6c 61 79 6f 75 74 29 2e 29  low](#flayout).)
ed80: 20 49 6e 20 73 75 63 68 20 66 69 65 6c 64 73 2c   In such fields,
ed90: 0a 4c 4f 41 44 45 52 20 70 6c 61 63 65 73 20 61  .LOADER places a
eda0: 20 73 6d 61 6c 6c 20 6c 69 62 72 61 72 79 20 6f   small library o
edb0: 66 20 72 6f 75 74 69 6e 65 73 2c 20 77 68 69 63  f routines, whic
edc0: 68 20 74 6f 20 61 20 66 69 72 73 74 0a 61 70 70  h to a first.app
edd0: 72 6f 78 69 6d 61 74 69 6f 6e 20 6d 65 61 6e 73  roximation means
ede0: 20 75 73 65 72 20 63 6f 64 65 20 73 68 6f 75 6c   user code shoul
edf0: 64 20 6e 6f 74 20 75 73 65 20 74 68 65 20 7a 65  d not use the ze
ee00: 72 6f 20 70 61 67 65 2e 0a 0a 53 6f 6d 65 20 6f  ro page...Some o
ee10: 66 20 74 68 65 20 73 70 61 63 65 20 69 6e 20 74  f the space in t
ee20: 68 65 20 75 73 65 72 20 63 6f 64 65 20 66 69 65  he user code fie
ee30: 6c 64 e2 80 99 73 20 7a 65 72 6f 20 70 61 67 65  ld’s zero page
ee40: 20 69 73 20 6c 65 66 74 20 75 6e 75 73 65 64 20   is left unused 
ee50: 62 79 0a 4c 4f 41 44 45 52 2c 20 73 6f 20 77 65  by.LOADER, so we
ee60: 20 75 73 65 20 69 74 20 66 6f 72 20 61 20 73 6d   use it for a sm
ee70: 61 6c 6c 20 6e 75 6d 62 65 72 20 6f 66 20 69 6e  all number of in
ee80: 74 65 72 6e 61 6c 20 67 6c 6f 62 61 6c 73 20 6d  ternal globals m
ee90: 61 69 6e 74 61 69 6e 65 64 0a 62 79 20 74 68 65  aintained.by the
eea0: 20 43 43 38 20 70 72 6f 67 72 61 6d 20 69 6e 69   CC8 program ini
eeb0: 74 69 61 6c 69 7a 61 74 69 6f 6e 20 63 6f 64 65  tialization code
eec0: 3a 20 60 69 6e 69 74 2e 68 60 20 66 6f 72 20 74  : `init.h` for t
eed0: 68 65 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65  he cross-compile
eee0: 72 2c 0a 61 6e 64 20 60 68 65 61 64 65 72 2e 73  r,.and `header.s
eef0: 62 60 20 66 6f 72 20 74 68 65 20 6e 61 74 69 76  b` for the nativ
ef00: 65 20 63 6f 6d 70 69 6c 65 72 2c 20 77 68 69 63  e compiler, whic
ef10: 68 20 77 65 e2 80 99 6c 6c 20 72 65 66 65 72 20  h we’ll refer 
ef20: 74 6f 0a 67 65 6e 65 72 69 63 61 6c 6c 79 20 61  to.generically a
ef30: 73 20 e2 80 9c 49 4e 49 54 e2 80 9d 20 66 72 6f  s “INIT” fro
ef40: 6d 20 68 65 72 65 20 6f 6e 2e 0a 0a 49 74 20 69  m here on...It i
ef50: 73 20 6e 6f 74 20 63 75 72 72 65 6e 74 6c 79 20  s not currently 
ef60: 63 6c 65 61 72 20 74 6f 20 75 73 20 69 66 2c 20  clear to us if, 
ef70: 62 65 74 77 65 65 6e 20 4c 4f 41 44 45 52 20 61  between LOADER a
ef80: 6e 64 20 49 4e 49 54 2c 20 69 66 20 74 68 65 72  nd INIT, if ther
ef90: 65 20 69 73 0a 61 6e 79 20 73 70 61 63 65 20 61  e is.any space a
efa0: 74 20 61 6c 6c 20 6c 65 66 74 20 6f 76 65 72 20  t all left over 
efb0: 69 6e 20 74 68 65 20 75 73 65 72 20 63 6f 64 65  in the user code
efc0: 20 66 69 65 6c 64 2e 20 57 65 e2 80 99 6c 6c 20   field. We’ll 
efd0: 6e 65 65 64 20 74 6f 0a 75 6e 64 65 72 74 61 6b  need to.undertak
efe0: 65 20 61 20 6d 61 70 70 69 6e 67 20 71 75 65 73  e a mapping ques
eff0: 74 20 74 6f 20 77 6f 72 6b 20 74 68 69 73 20 6f  t to work this o
f000: 75 74 2e 20 57 65 e2 80 99 6c 6c 20 72 65 70 6f  ut. We’ll repo
f010: 72 74 20 74 68 65 20 72 65 73 75 6c 74 73 0a 68  rt the results.h
f020: 65 72 65 20 69 66 20 6f 75 72 20 71 75 65 73 74  ere if our quest
f030: 20 70 61 72 74 79 20 6d 61 6e 61 67 65 73 20 74   party manages t
f040: 6f 20 72 65 74 75 72 6e 20 61 6c 69 76 65 2e 20  o return alive. 
f050: 3a 29 0a 0a 4e 6f 6e 65 20 6f 66 20 74 68 69 73  :)..None of this
f060: 20 61 70 70 6c 69 65 73 20 74 6f 20 74 68 65 20   applies to the 
f070: 66 69 65 6c 64 20 63 6f 6e 74 61 69 6e 69 6e 67  field containing
f080: 20 4c 49 42 43 20 62 65 63 61 75 73 65 20 69 74   LIBC because it
f090: 20 63 6f 6e 74 61 69 6e 73 20 6e 6f 0a 46 4f 52   contains no.FOR
f0a0: 54 52 41 4e 20 49 49 20 63 6f 64 65 2c 20 68 65  TRAN II code, he
f0b0: 6e 63 65 20 6e 6f 20 4c 4f 41 44 45 52 20 69 6e  nce no LOADER in
f0c0: 74 65 72 6e 61 6c 20 68 65 6c 70 65 72 20 72 6f  ternal helper ro
f0d0: 75 74 69 6e 65 73 20 6f 72 20 74 68 65 20 67 6c  utines or the gl
f0e0: 6f 62 61 6c 73 0a 66 6f 72 20 74 68 6f 73 65 20  obals.for those 
f0f0: 72 6f 75 74 69 6e 65 73 2e 20 4c 49 42 43 20 74  routines. LIBC t
f100: 68 65 72 65 66 6f 72 65 20 75 73 65 73 20 74 68  herefore uses th
f110: 65 20 7a 65 72 6f 20 70 61 67 65 20 69 6e 20 69  e zero page in i
f120: 74 73 20 66 69 65 6c 64 20 66 6f 72 0a 65 6e 74  ts field for.ent
f130: 69 72 65 6c 79 20 64 69 66 66 65 72 65 6e 74 20  irely different 
f140: 70 75 72 70 6f 73 65 73 2c 20 77 68 69 63 68 20  purposes, which 
f150: 77 65 20 64 6f 20 6e 6f 74 20 64 6f 63 75 6d 65  we do not docume
f160: 6e 74 20 68 65 72 65 20 62 65 63 61 75 73 65 20  nt here because 
f170: 69 74 0a 6e 65 76 65 72 20 63 6f 6e 66 6c 69 63  it.never conflic
f180: 74 73 20 77 69 74 68 20 74 68 65 20 65 6e 64 20  ts with the end 
f190: 75 73 65 72 20 63 6f 64 65 20 61 6e 64 20 64 61  user code and da
f1a0: 74 61 20 66 69 65 6c 64 73 2e 20 49 66 20 79 6f  ta fields. If yo
f1b0: 75 20 77 61 6e 74 20 74 6f 0a 6b 6e 6f 77 20 68  u want to.know h
f1c0: 6f 77 20 4c 49 42 43 20 75 73 65 73 20 69 74 73  ow LIBC uses its
f1d0: 20 66 69 65 6c 64 e2 80 99 73 20 7a 65 72 6f 20   field’s zero 
f1e0: 70 61 67 65 2c 20 73 65 65 20 60 73 72 63 2f 63  page, see `src/c
f1f0: 63 38 2f 6f 73 38 2f 6c 69 62 63 2e 63 60 2e 0a  c8/os8/libc.c`..
f200: 0a 54 68 65 20 5b 75 73 65 72 20 64 61 74 61 20  .The [user data 
f210: 66 69 65 6c 64 5d 28 23 75 64 66 29 20 61 6c 73  field](#udf) als
f220: 6f 20 72 75 6e 73 20 6f 6e 20 65 6e 74 69 72 65  o runs on entire
f230: 6c 79 20 64 69 66 66 65 72 65 6e 74 20 72 75 6c  ly different rul
f240: 65 73 20 66 72 6f 6d 0a 74 68 65 20 61 62 6f 76  es from.the abov
f250: 65 2c 20 73 69 6e 63 65 20 69 74 20 63 6f 6e 74  e, since it cont
f260: 61 69 6e 73 20 6e 6f 20 65 78 65 63 75 74 61 62  ains no executab
f270: 6c 65 20 63 6f 64 65 20 61 74 20 61 6c 6c 2c 20  le code at all, 
f280: 68 65 6e 63 65 20 6e 6f 20 70 72 69 6f 72 0a 72  hence no prior.r
f290: 65 73 65 72 76 61 74 69 6f 6e 73 20 62 79 20 4c  eservations by L
f2a0: 4f 41 44 45 52 20 6f 72 20 4c 49 42 43 2e 20 53  OADER or LIBC. S
f2b0: 65 65 20 74 68 65 20 6e 65 78 74 20 73 65 63 74  ee the next sect
f2c0: 69 6f 6e 20 66 6f 72 20 68 6f 77 20 74 68 65 20  ion for how the 
f2d0: 55 44 46 0a 75 73 65 73 20 69 74 73 20 7a 65 72  UDF.uses its zer
f2e0: 6f 20 70 61 67 65 2e 0a 0a 0a 23 23 23 20 3c 61  o page....### <a
f2f0: 20 69 64 3d 22 75 64 66 22 3e 3c 2f 61 3e 54 68   id="udf"></a>Th
f300: 65 20 55 73 65 72 20 44 61 74 61 20 46 69 65 6c  e User Data Fiel
f310: 64 0a 0a 54 68 65 20 75 73 65 72 20 64 61 74 61  d..The user data
f320: 20 66 69 65 6c 64 20 69 73 20 61 6c 77 61 79 73   field is always
f330: 20 66 69 65 6c 64 20 31 2e 20 49 74 73 20 6c 61   field 1. Its la
f340: 79 6f 75 74 20 62 72 65 61 6b 73 20 64 6f 77 6e  yout breaks down
f350: 20 6c 69 6b 65 20 74 68 69 73 3a 0a 0a 7c 20 72   like this:..| r
f360: 61 6e 67 65 20 20 20 20 20 20 20 20 20 7c 20 75  ange         | u
f370: 73 65 20 7c 0a 7c 20 2d 2d 2d 2d 2d 2d 2d 2d 2d  se |.| ---------
f380: 2d 2d 2d 2d 20 7c 20 2d 2d 2d 20 7c 0a 7c 20 60  ---- | --- |.| `
f390: 31 30 30 30 30 2d 31 30 30 30 31 60 20 7c 20 50  10000-10001` | P
f3a0: 44 50 2d 38 20 69 6e 74 65 72 72 75 70 74 20 68  DP-8 interrupt h
f3b0: 61 6e 64 6c 69 6e 67 3b 20 73 65 65 20 53 6d 61  andling; see Sma
f3c0: 6c 6c 20 43 6f 6d 70 75 74 65 72 20 48 61 6e 64  ll Computer Hand
f3d0: 62 6f 6f 6b 20 7c 0a 7c 20 60 31 30 30 30 32 2d  book |.| `10002-
f3e0: 31 30 30 30 37 60 20 7c 20 72 65 73 65 72 76 65  10007` | reserve
f3f0: 64 20 66 6f 72 20 66 75 74 75 72 65 20 4c 49 42  d for future LIB
f400: 43 20 75 73 65 20 7c 0a 7c 20 60 31 30 30 31 30  C use |.| `10010
f410: 2d 31 30 30 31 37 60 20 7c 20 50 44 50 2d 38 20  -10017` | PDP-8 
f420: 61 75 74 6f 2d 69 6e 64 65 78 20 72 65 67 69 73  auto-index regis
f430: 74 65 72 73 3b 20 73 65 65 20 53 6d 61 6c 6c 20  ters; see Small 
f440: 43 6f 6d 70 75 74 65 72 20 48 61 6e 64 62 6f 6f  Computer Handboo
f450: 6b 20 7c 0a 7c 20 60 31 30 30 32 30 2d 31 30 31  k |.| `10020-101
f460: 37 37 60 20 7c 20 73 74 61 74 69 63 20 6f 75 74  77` | static out
f470: 70 75 74 20 62 75 66 66 65 72 20 75 73 65 64 20  put buffer used 
f480: 62 79 20 5b 60 5b 66 5d 70 72 69 6e 74 66 28 29  by [`[f]printf()
f490: 60 5d 28 23 70 72 69 6e 74 66 29 20 69 6e 20 5b  `](#printf) in [
f4a0: 60 73 70 72 69 6e 74 66 28 29 60 5d 28 23 73 70  `sprintf()`](#sp
f4b0: 72 69 6e 74 66 29 20 63 61 6c 6c 20 7c 0a 7c 20  rintf) call |.| 
f4c0: 60 31 30 32 30 30 2d 31 78 78 78 78 60 20 7c 20  `10200-1xxxx` | 
f4d0: 67 6c 6f 62 61 6c 73 20 66 69 72 73 74 2c 20 74  globals first, t
f4e0: 68 65 6e 20 6c 69 74 65 72 61 6c 73 20 70 61 63  hen literals pac
f4f0: 6b 65 64 20 74 6f 67 65 74 68 65 72 20 61 74 20  ked together at 
f500: 74 68 65 20 62 6f 74 74 6f 6d 20 7c 0a 7c 20 60  the bottom |.| `
f510: 31 78 78 78 78 2d 31 37 35 37 37 60 20 7c 20 75  1xxxx-17577` | u
f520: 73 65 72 20 73 74 61 63 6b 2c 20 67 72 6f 77 73  ser stack, grows
f530: 20 75 70 77 61 72 64 20 66 72 6f 6d 20 65 6e 64   upward from end
f540: 20 6f 66 20 6c 69 74 65 72 61 6c 73 20 7c 0a 7c   of literals |.|
f550: 20 60 31 37 36 30 30 2d 31 37 37 37 37 60 20 7c   `17600-17777` |
f560: 20 6c 61 73 74 20 70 61 67 65 20 6f 66 20 55 44   last page of UD
f570: 46 20 72 65 73 65 72 76 65 64 20 62 79 20 4f 53  F reserved by OS
f580: 2f 38 20 28 5b 73 65 65 20 61 62 6f 76 65 5d 28  /8 ([see above](
f590: 23 6f 73 38 72 65 73 29 29 20 7c 0a 0a 54 68 65  #os8res)) |..The
f5a0: 20 6d 61 78 69 6d 75 6d 20 73 69 7a 65 20 6f 66   maximum size of
f5b0: 20 67 6c 6f 62 61 6c 73 20 2b 20 6c 69 74 65 72   globals + liter
f5c0: 61 6c 73 20 2b 20 73 74 61 63 6b 20 69 6e 20 61  als + stack in a
f5d0: 20 43 43 38 20 70 72 6f 67 72 61 6d 20 69 73 0a   CC8 program is.
f5e0: 74 68 65 72 65 66 6f 72 65 20 37 34 30 30 e2 82  therefore 7400
f5f0: 88 20 77 6f 72 64 73 2e 20 28 33 38 34 30 20 64   words. (3840 d
f600: 65 63 69 6d 61 6c 2e 29 0a 0a 0a 23 23 23 23 20  ecimal.)...#### 
f610: 3c 61 20 69 64 3d 22 6e 75 6c 70 74 72 22 3e 3c  <a id="nulptr"><
f620: 2f 61 3e 43 20 4e 55 4c 4c 20 50 6f 69 6e 74 65  /a>C NULL Pointe
f630: 72 73 0a 0a 42 65 63 61 75 73 65 20 74 68 65 20  rs..Because the 
f640: 50 44 50 2d 38 20 69 6e 74 65 72 72 75 70 74 20  PDP-8 interrupt 
f650: 73 79 73 74 65 6d 20 73 65 74 73 20 61 73 69 64  system sets asid
f660: 65 20 74 68 65 20 66 69 72 73 74 20 74 77 6f 20  e the first two 
f670: 6c 6f 63 61 74 69 6f 6e 73 20 6f 66 0a 65 61 63  locations of.eac
f680: 68 20 66 69 65 6c 64 20 66 6f 72 20 69 74 73 65  h field for itse
f690: 6c 66 2c 20 61 6e 64 20 43 43 38 20 70 6c 61 79  lf, and CC8 play
f6a0: 73 20 61 6c 6f 6e 67 2c 20 61 20 76 61 6c 69 64  s along, a valid
f6b0: 20 43 20 70 6f 69 6e 74 65 72 20 63 61 6e 20 6e   C pointer can n
f6c0: 65 76 65 72 0a 68 61 76 65 20 76 61 6c 75 65 20  ever.have value 
f6d0: 30 2c 20 70 72 65 73 65 72 76 69 6e 67 20 74 68  0, preserving th
f6e0: 65 20 65 78 70 65 63 74 65 64 20 66 61 6c 73 79  e expected falsy
f6f0: 20 6e 61 74 75 72 65 20 6f 66 20 61 20 43 20 4e   nature of a C N
f700: 55 4c 4c 20 70 6f 69 6e 74 65 72 2e 0a 54 68 69  ULL pointer..Thi
f710: 73 20 68 61 73 20 70 72 61 63 74 69 63 61 6c 20  s has practical 
f720: 70 6f 73 69 74 69 76 65 20 63 6f 6e 73 65 71 75  positive consequ
f730: 65 6e 63 65 73 20 73 75 63 68 20 61 73 20 74 68  ences such as th
f740: 65 20 66 61 63 74 20 74 68 61 74 20 79 6f 75 20  e fact that you 
f750: 63 61 6e 0a 64 65 70 65 6e 64 20 6f 6e 20 61 20  can.depend on a 
f760: 63 61 6c 6c 20 74 6f 20 5b 60 67 65 74 73 28 29  call to [`gets()
f770: 60 5d 28 23 67 65 74 73 29 20 74 6f 20 61 6c 77  `](#gets) to alw
f780: 61 79 73 20 72 65 74 75 72 6e 20 61 20 74 72 75  ays return a tru
f790: 74 68 79 20 76 61 6c 75 65 20 6f 6e 0a 73 75 63  thy value on.suc
f7a0: 63 65 73 73 2c 20 70 72 6f 76 69 64 65 64 20 79  cess, provided y
f7b0: 6f 75 e2 80 99 76 65 20 70 61 73 73 65 64 20 69  ou’ve passed i
f7c0: 74 20 61 20 6e 6f 72 6d 61 6c 20 43 20 70 6f 69  t a normal C poi
f7d0: 6e 74 65 72 2e 0a 0a 43 20 67 69 76 65 73 20 79  nter...C gives y
f7e0: 6f 75 20 70 6c 65 6e 74 79 20 6f 66 20 70 6f 77  ou plenty of pow
f7f0: 65 72 20 74 6f 20 63 72 65 61 74 65 20 61 20 70  er to create a p
f800: 6f 69 6e 74 65 72 20 65 71 75 61 6c 20 74 6f 20  ointer equal to 
f810: 30 20 61 6e 64 0a 64 65 72 65 66 65 72 65 6e 63  0 and.dereferenc
f820: 65 20 69 74 2c 20 62 75 74 20 79 6f 75 e2 80 99  e it, but you’
f830: 64 20 62 65 20 6f 75 74 20 69 6e 20 5b 75 6e 64  d be out in [und
f840: 65 66 69 6e 65 64 20 62 65 68 61 76 69 6f 72 5d  efined behavior]
f850: 5b 75 62 5d 20 74 65 72 72 69 74 6f 72 79 0a 62  [ub] territory.b
f860: 79 20 74 68 61 74 20 70 6f 69 6e 74 2c 20 73 6f  y that point, so
f870: 20 6f 6e 20 79 6f 75 72 20 68 65 61 64 20 62 65   on your head be
f880: 20 74 68 65 20 63 6f 6e 73 65 71 75 65 6e 63 65   the consequence
f890: 73 21 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22  s!...### <a id="
f8a0: 70 74 72 77 72 61 70 22 3e 3c 2f 61 3e 50 6f 69  ptrwrap"></a>Poi
f8b0: 6e 74 65 72 73 20 57 72 61 70 20 41 72 6f 75 6e  nters Wrap Aroun
f8c0: 64 0a 0a 50 6f 69 6e 74 65 72 73 20 69 6e 20 74  d..Pointers in t
f8d0: 68 69 73 20 43 20 69 6d 70 6c 65 6d 65 6e 74 61  his C implementa
f8e0: 74 69 6f 6e 20 61 72 65 20 67 65 6e 65 72 61 6c  tion are general
f8f0: 6c 79 20 63 6f 6e 66 69 6e 65 64 20 74 6f 20 5b  ly confined to [
f900: 74 68 65 20 75 73 65 72 0a 64 61 74 61 20 66 69  the user.data fi
f910: 65 6c 64 5d 28 23 75 64 66 29 2e 20 54 68 61 74  eld](#udf). That
f920: 20 69 73 20 74 6f 20 73 61 79 2c 20 74 68 65 20   is to say, the 
f930: 63 6f 64 65 20 67 65 6e 65 72 61 74 65 64 20 62  code generated b
f940: 79 20 43 43 38 20 64 6f 65 73 20 6e 6f 74 0a 75  y CC8 does not.u
f950: 73 65 20 31 35 2d 62 69 74 20 65 78 74 65 6e 64  se 15-bit extend
f960: 65 64 20 61 64 64 72 65 73 73 65 73 3b 20 69 74  ed addresses; it
f970: 20 6a 75 73 74 20 66 6c 69 70 73 20 62 65 74 77   just flips betw
f980: 65 65 6e 20 70 61 67 65 73 20 64 65 70 65 6e 64  een pages depend
f990: 69 6e 67 20 6f 6e 0a 77 68 61 74 20 74 79 70 65  ing on.what type
f9a0: 20 6f 66 20 64 61 74 61 20 6f 72 20 63 6f 64 65   of data or code
f9b0: 20 69 74 e2 80 99 73 20 74 72 79 69 6e 67 20 74   it’s trying t
f9c0: 6f 20 61 63 63 65 73 73 2e 0a 0a 54 68 69 73 20  o access...This 
f9d0: 6d 65 61 6e 73 20 69 74 20 69 73 20 70 6f 73 73  means it is poss
f9e0: 69 62 6c 65 20 74 6f 20 69 74 65 72 61 74 65 20  ible to iterate 
f9f0: 61 20 70 6f 69 6e 74 65 72 20 70 61 73 74 20 74  a pointer past t
fa00: 68 65 20 65 6e 64 20 6f 66 20 61 20 34 30 39 36  he end of a 4096
fa10: 0a 77 6f 72 64 20 63 6f 72 65 20 6d 65 6d 6f 72  .word core memor
fa20: 79 20 66 69 65 6c 64 2c 20 63 61 75 73 69 6e 67  y field, causing
fa30: 20 69 74 20 74 6f 20 77 72 61 70 20 61 72 6f 75   it to wrap arou
fa40: 6e 64 20 74 6f 20 30 20 61 6e 64 20 63 6f 6e 74  nd to 0 and cont
fa50: 69 6e 75 65 0a 62 6c 69 74 68 65 6c 79 20 61 6c  inue.blithely al
fa60: 6f 6e 67 2e 20 20 53 69 6e 63 65 20 74 68 65 20  ong.  Since the 
fa70: 6c 61 73 74 20 70 61 67 65 20 6f 66 20 74 68 65  last page of the
fa80: 20 75 73 65 72 20 64 61 74 61 20 66 69 65 6c 64   user data field
fa90: 20 5b 69 73 20 72 65 73 65 72 76 65 64 0a 66 6f   [is reserved.fo
faa0: 72 20 75 73 65 20 62 79 20 4f 53 2f 38 5d 28 23  r use by OS/8](#
fab0: 6f 73 38 72 65 73 29 20 61 6e 64 20 74 68 65 20  os8res) and the 
fac0: 66 69 72 73 74 20 70 61 67 65 20 6f 66 20 74 68  first page of th
fad0: 65 20 55 44 46 20 68 61 73 20 5b 73 65 76 65 72  e UDF has [sever
fae0: 61 6c 0a 73 70 65 63 69 61 6c 20 75 73 65 73 5d  al.special uses]
faf0: 28 23 75 64 66 29 2c 20 70 72 6f 67 72 61 6d 73  (#udf), programs
fb00: 20 74 68 61 74 20 64 6f 20 74 68 69 73 20 77 69   that do this wi
fb10: 6c 6c 20 6d 6f 73 74 20 6c 69 6b 65 6c 79 20 63  ll most likely c
fb20: 72 61 73 68 20 61 6e 64 0a 6d 61 79 20 65 76 65  rash and.may eve
fb30: 6e 20 64 65 73 74 72 6f 79 20 64 61 74 61 2e 20  n destroy data. 
fb40: 4f 75 72 20 5b 4c 49 42 43 20 69 6d 70 6c 65 6d  Our [LIBC implem
fb50: 65 6e 74 61 74 69 6f 6e 5d 28 23 6c 69 62 63 29  entation](#libc)
fb60: 20 67 65 6e 65 72 61 6c 6c 79 20 64 6f 65 73 0a   generally does.
fb70: 6e 6f 74 20 74 72 79 20 74 6f 20 63 68 65 63 6b  not try to check
fb80: 20 66 6f 72 20 73 75 63 68 20 77 72 61 70 61 72   for such wrapar
fb90: 6f 75 6e 64 20 70 72 6f 62 6c 65 6d 73 2c 20 6d  ound problems, m
fba0: 75 63 68 20 6c 65 73 73 20 73 69 67 6e 61 6c 20  uch less signal 
fbb0: 65 72 72 6f 72 73 0a 77 68 65 6e 20 69 74 20 68  errors.when it h
fbc0: 61 70 70 65 6e 73 2e 20 54 68 65 20 70 72 6f 67  appens. The prog
fbd0: 72 61 6d 6d 65 72 20 69 73 20 65 78 70 65 63 74  rammer is expect
fbe0: 65 64 20 74 6f 20 61 76 6f 69 64 20 64 6f 69 6e  ed to avoid doin
fbf0: 67 20 74 68 69 73 2e 0a 0a 43 6f 64 65 20 74 68  g this...Code th
fc00: 61 74 20 6f 70 65 72 61 74 65 73 20 6f 6e 20 70  at operates on p
fc10: 6f 69 6e 74 65 72 73 20 77 69 6c 6c 20 67 65 6e  ointers will gen
fc20: 65 72 61 6c 6c 79 20 6f 6e 6c 79 20 64 6f 20 69  erally only do i
fc30: 74 73 20 77 6f 72 6b 20 77 69 74 68 69 6e 0a 74  ts work within.t
fc40: 68 65 20 75 73 65 72 20 64 61 74 61 20 66 69 65  he user data fie
fc50: 6c 64 2e 20 59 6f 75 20 77 69 6c 6c 20 6c 69 6b  ld. You will lik
fc60: 65 6c 79 20 6e 65 65 64 20 74 6f 20 72 65 73 6f  ely need to reso
fc70: 72 74 20 74 6f 20 5b 69 6e 6c 69 6e 65 0a 61 73  rt to [inline.as
fc80: 73 65 6d 62 6c 79 5d 28 23 61 73 6d 29 20 61 6e  sembly](#asm) an
fc90: 64 20 60 43 49 46 60 2f 60 43 44 46 60 20 69 6e  d `CIF`/`CDF` in
fca0: 73 74 72 75 63 74 69 6f 6e 73 20 74 6f 20 65 73  structions to es
fcb0: 63 61 70 65 20 74 68 61 74 20 66 69 65 6c 64 2e  cape that field.
fcc0: 0a 47 65 74 74 69 6e 67 20 6f 75 72 20 5b 4c 49  .Getting our [LI
fcd0: 42 43 5d 28 23 6c 69 62 63 29 20 74 6f 20 6f 70  BC](#libc) to op
fce0: 65 72 61 74 65 20 6f 6e 20 6f 74 68 65 72 20 66  erate on other f
fcf0: 69 65 6c 64 73 20 6d 61 79 20 62 65 20 74 72 69  ields may be tri
fd00: 63 6b 79 20 6f 72 0a 65 76 65 6e 20 6d 6f 72 65  cky or.even more
fd10: 20 64 69 66 66 69 63 75 6c 74 20 74 68 61 6e 20   difficult than 
fd20: 69 74 e2 80 99 73 20 77 6f 72 74 68 2e 0a 0a 4f  it’s worth...O
fd30: 6e 20 74 68 65 20 62 72 69 67 68 74 20 73 69 64  n the bright sid
fd40: 65 2c 20 70 6f 69 6e 74 65 72 73 20 61 72 65 20  e, pointers are 
fd50: 61 6c 77 61 79 73 20 31 32 2d 62 69 74 20 76 61  always 12-bit va
fd60: 6c 75 65 73 2c 20 61 63 63 65 73 73 65 64 20 77  lues, accessed w
fd70: 69 74 68 0a 69 6e 64 69 72 65 63 74 20 61 64 64  ith.indirect add
fd80: 72 65 73 73 69 6e 67 2c 20 72 61 74 68 65 72 20  ressing, rather 
fd90: 74 68 61 6e 20 70 61 67 65 2d 72 65 6c 61 74 69  than page-relati
fda0: 76 65 20 37 2d 62 69 74 20 61 64 64 72 65 73 73  ve 7-bit address
fdb0: 65 73 2c 20 73 6f 20 74 68 61 74 0a 70 72 6f 67  es, so that.prog
fdc0: 72 61 6d 73 20 62 75 69 6c 74 20 77 69 74 68 20  rams built with 
fdd0: 43 43 38 20 6e 65 65 64 20 6e 6f 74 20 63 6f 6e  CC8 need not con
fde0: 63 65 72 6e 20 74 68 65 6d 73 65 6c 76 65 73 20  cern themselves 
fdf0: 77 69 74 68 20 5b 70 61 67 65 0a 62 6f 75 6e 64  with [page.bound
fe00: 61 72 69 65 73 5d 5b 6d 65 6d 61 64 64 5d 2e 0a  aries][memadd]..
fe10: 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 68 65 61  ..### <a id="hea
fe20: 70 22 3e 3c 2f 61 3e 54 68 65 72 65 20 49 73 20  p"></a>There Is 
fe30: 4e 6f 20 48 65 61 70 0a 0a 54 68 65 72 65 20 69  No Heap..There i
fe40: 73 20 6e 6f 20 60 6d 61 6c 6c 6f 63 28 29 60 20  s no `malloc()` 
fe50: 69 6e 20 74 68 69 73 20 43 20 6c 69 62 72 61 72  in this C librar
fe60: 79 20 61 6e 64 20 6e 6f 20 73 70 61 63 65 20 72  y and no space r
fe70: 65 73 65 72 76 65 64 20 66 6f 72 20 69 74 73 0a  eserved for its.
fe80: 68 65 61 70 20 69 6e 20 5b 74 68 65 20 75 73 65  heap in [the use
fe90: 72 20 64 61 74 61 20 66 69 65 6c 64 5d 28 23 75  r data field](#u
fea0: 64 66 29 2e 20 45 76 65 72 79 74 68 69 6e 67 20  df). Everything 
feb0: 69 6e 20 61 20 43 43 38 20 70 72 6f 67 72 61 6d  in a CC8 program
fec0: 20 69 73 0a 73 74 61 74 69 63 61 6c 6c 79 2d 61   is.statically-a
fed0: 6c 6c 6f 63 61 74 65 64 2c 20 69 66 20 79 6f 75  llocated, if you
fee0: e2 80 99 72 65 20 75 73 69 6e 67 20 73 74 6f 63  ’re using stoc
fef0: 6b 20 43 2d 6c 65 76 65 6c 20 6d 65 63 68 61 6e  k C-level mechan
ff00: 69 73 6d 73 2e 20 49 66 20 79 6f 75 72 0a 70 72  isms. If your.pr
ff10: 6f 67 72 61 6d 20 6e 65 65 64 73 20 61 64 64 69  ogram needs addi
ff20: 74 69 6f 6e 61 6c 20 64 79 6e 61 6d 69 63 61 6c  tional dynamical
ff30: 6c 79 2d 61 6c 6c 6f 63 61 74 65 64 20 6d 65 6d  ly-allocated mem
ff40: 6f 72 79 2c 20 79 6f 75 e2 80 99 6c 6c 20 6e 65  ory, you’ll ne
ff50: 65 64 20 74 6f 0a 61 72 72 61 6e 67 65 20 61 63  ed to.arrange ac
ff60: 63 65 73 73 20 74 6f 20 69 74 20 73 6f 6d 65 20  cess to it some 
ff70: 6f 74 68 65 72 20 77 61 79 2c 20 73 75 63 68 20  other way, such 
ff80: 61 73 20 5b 76 69 61 20 69 6e 6c 69 6e 65 0a 61  as [via inline.a
ff90: 73 73 65 6d 62 6c 79 5d 28 23 61 73 6d 29 2e 0a  ssembly](#asm)..
ffa0: 0a 0a 23 23 23 23 20 46 75 6e 20 54 72 69 76 69  ..#### Fun Trivi
ffb0: 61 3a 20 54 68 65 20 48 69 73 74 6f 72 79 20 6f  a: The History o
ffc0: 66 20 60 6d 61 6c 6c 6f 63 28 29 60 0a 0a 54 68  f `malloc()`..Th
ffd0: 65 72 65 20 69 73 20 6e 6f 20 e2 80 9c 60 6d 61  ere is no “`ma
ffe0: 6c 6c 6f 63 28 29 60 e2 80 9d 20 69 6e 20 4b 26  lloc()`” in K&
fff0: 52 20 43 2c 20 65 69 74 68 65 72 2c 20 61 74 20  R C, either, at 
10000 6c 65 61 73 74 20 61 73 20 66 61 72 20 61 73 20  least as far as 
10010 74 68 65 20 66 69 72 73 74 0a 65 64 69 74 69 6f  the first.editio
10020 6e 20 6f 66 20 e2 80 9c 5b 54 68 65 20 43 20 50  n of “[The C P
10030 72 6f 67 72 61 6d 6d 69 6e 67 20 4c 61 6e 67 75  rogramming Langu
10040 61 67 65 e2 80 9d 5d 5b 6b 72 63 5d 20 67 6f 65  age”][krc] goe
10050 73 2e 20 41 62 6f 75 74 20 68 61 6c 66 77 61 79  s. About halfway
10060 20 69 6e 74 6f 0a 74 68 65 20 62 6f 6f 6b 20 74   into.the book t
10070 68 65 79 20 67 69 76 65 20 61 20 73 69 6d 70 6c  hey give a simpl
10080 65 20 66 75 6e 63 74 69 6f 6e 20 63 61 6c 6c 65  e function calle
10090 64 20 60 61 6c 6c 6f 63 28 29 60 20 74 68 61 74  d `alloc()` that
100a0 20 6a 75 73 74 0a 64 65 74 65 72 6d 69 6e 65 64   just.determined
100b0 20 77 68 65 74 68 65 72 20 74 68 65 20 72 65 71   whether the req
100c0 75 65 73 74 65 64 20 61 6d 6f 75 6e 74 20 6f 66  uested amount of
100d0 20 73 70 61 63 65 20 77 61 73 20 61 76 61 69 6c   space was avail
100e0 61 62 6c 65 20 77 69 74 68 69 6e 20 61 0a 6c 61  able within a.la
100f0 72 67 65 20 73 74 61 74 69 63 20 60 63 68 61 72  rge static `char
10100 5b 5d 60 20 61 72 72 61 79 20 69 74 20 6d 61 6e  []` array it man
10110 61 67 65 64 20 66 6f 72 20 69 74 73 20 63 61 6c  aged for its cal
10120 6c 65 72 73 2e 20 49 66 20 73 6f 2c 20 69 74 0a  lers. If so, it.
10130 61 64 76 61 6e 63 65 64 20 74 68 65 20 70 6f 69  advanced the poi
10140 6e 74 65 72 20 74 68 61 74 20 6d 75 63 68 20 66  nter that much f
10150 61 72 74 68 65 72 20 69 6e 74 6f 20 74 68 65 20  arther into the 
10160 62 75 66 66 65 72 20 61 6e 64 20 72 65 74 75 72  buffer and retur
10170 6e 65 64 20 74 68 61 74 0a 70 6f 69 6e 74 65 72  ned that.pointer
10180 2e 20 54 68 65 20 63 6f 72 72 65 73 70 6f 6e 64  . The correspond
10190 69 6e 67 20 60 66 72 65 65 28 29 60 20 69 6d 70  ing `free()` imp
101a0 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 6a 75 73 74  lementation just
101b0 20 63 68 6f 70 70 65 64 20 74 68 65 0a 67 6c 6f   chopped the.glo
101c0 62 61 6c 6c 79 2d 61 6c 6c 6f 63 61 74 65 64 20  bally-allocated 
101d0 73 70 61 63 65 20 6f 66 66 20 61 67 61 69 6e 2c  space off again,
101e0 20 73 6f 20 69 66 20 79 6f 75 20 63 61 6c 6c 65   so if you calle
101f0 64 20 74 68 61 74 20 60 61 6c 6c 6f 63 28 29 60  d that `alloc()`
10200 0a 74 77 69 63 65 20 61 6e 64 20 66 72 65 65 64  .twice and freed
10210 20 74 68 65 20 66 69 72 73 74 20 70 6f 69 6e 74   the first point
10220 65 72 2c 20 74 68 65 20 73 65 63 6f 6e 64 20 77  er, the second w
10230 6f 75 6c 64 20 62 65 20 69 6e 76 61 6c 69 64 2c  ould be invalid,
10240 20 74 6f 6f 21 0a 0a 54 68 65 6e 20 69 6e 20 41   too!..Then in A
10250 70 70 65 6e 64 69 78 20 41 2c 20 4b 65 72 6e 69  ppendix A, Kerni
10260 67 68 61 6e 20 26 20 52 69 74 63 68 69 65 20 67  ghan & Ritchie g
10270 69 76 65 20 61 20 6d 75 63 68 20 73 6d 61 72 74  ive a much smart
10280 65 72 20 61 6c 74 65 72 6e 61 74 69 76 65 0a 62  er alternative.b
10290 61 73 65 64 20 6f 6e 20 74 68 65 20 6f 6c 64 20  ased on the old 
102a0 55 6e 69 78 20 73 79 73 63 61 6c 6c 20 5b 60 73  Unix syscall [`s
102b0 62 72 6b 28 32 29 60 5d 5b 73 62 72 6b 5d 2e 20  brk(2)`][sbrk]. 
102c0 54 68 65 20 69 6d 70 72 65 73 73 69 6f 6e 20 67  The impression g
102d0 69 76 65 6e 20 69 73 0a 74 68 61 74 20 6d 65 6d  iven is.that mem
102e0 6f 72 79 20 61 6c 6c 6f 63 61 74 69 6f 6e 20 69  ory allocation i
102f0 73 6e e2 80 99 74 20 70 61 72 74 20 6f 66 20 74  sn’t part of t
10300 68 65 20 6c 61 6e 67 75 61 67 65 2c 20 69 74 e2  he language, it
10310 80 99 73 20 70 61 72 74 20 6f 66 20 74 68 65 0a  s part of the.
10320 6f 70 65 72 61 74 69 6e 67 20 73 79 73 74 65 6d  operating system
10330 2c 20 61 6e 64 20 64 69 66 66 65 72 65 6e 74 20  , and different 
10340 69 6d 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 73 20  implementations 
10350 6f 66 20 43 20 77 65 72 65 20 65 78 70 65 63 74  of C were expect
10360 65 64 20 74 6f 0a 70 72 6f 76 69 64 65 20 74 68  ed to.provide th
10370 69 73 20 66 61 63 69 6c 69 74 79 20 69 6e 20 6c  is facility in l
10380 6f 63 61 6c 20 77 61 79 73 2e 0a 0a 5b 56 36 20  ocal ways...[V6 
10390 55 4e 49 58 5d 5b 76 36 75 78 5d 20 70 72 65 63  UNIX][v6ux] prec
103a0 65 64 65 64 20 4b 26 52 20 43 20 62 79 20 73 65  eded K&R C by se
103b0 76 65 72 61 6c 20 79 65 61 72 73 2c 20 61 6e 64  veral years, and
103c0 20 74 68 65 72 65 20 69 73 20 6e 6f 0a 60 6d 61   there is no.`ma
103d0 6c 6c 6f 63 28 29 60 20 74 68 65 72 65 2c 20 65  lloc()` there, e
103e0 69 74 68 65 72 2e 20 54 68 65 72 65 e2 80 99 73  ither. There’s
103f0 20 61 6e 20 60 61 6c 6c 6f 63 28 29 60 20 69 6d   an `alloc()` im
10400 70 6c 65 6d 65 6e 74 61 74 69 6f 6e 20 69 6e 20  plementation in 
10410 69 74 73 0a 60 6c 69 62 63 60 20 74 68 61 74 e2  its.`libc` that
10420 80 99 73 20 73 63 61 72 63 65 6c 79 20 6d 6f 72  s scarcely mor
10430 65 20 63 6f 6d 70 6c 69 63 61 74 65 64 20 74 68  e complicated th
10440 61 6e 20 74 68 65 20 60 63 68 61 72 5b 5d 60 20  an the `char[]` 
10450 62 61 73 65 64 20 6f 6e 65 0a 66 69 72 73 74 20  based one.first 
10460 70 72 65 73 65 6e 74 65 64 20 69 6e 20 4b 26 52  presented in K&R
10470 2e 20 54 68 65 72 65 20 69 73 20 6e 6f 20 60 66  . There is no `f
10480 72 65 65 28 29 60 20 69 6e 20 56 36 3a 20 6e 65  ree()` in V6: ne
10490 77 20 61 6c 6c 6f 63 61 74 69 6f 6e 73 20 6a 75  w allocations ju
104a0 73 74 0a 6b 65 65 70 20 65 78 74 65 6e 64 69 6e  st.keep extendin
104b0 67 20 74 68 65 20 61 6d 6f 75 6e 74 20 6f 66 20  g the amount of 
104c0 63 6f 72 65 20 72 65 71 75 65 73 74 65 64 2e 0a  core requested..
104d0 0a 60 6d 61 6c 6c 6f 63 28 29 60 20 61 70 70 61  .`malloc()` appa
104e0 72 65 6e 74 6c 79 20 66 69 72 73 74 20 61 70 70  rently first app
104f0 65 61 72 65 64 20 61 62 6f 75 74 20 61 20 79 65  eared about a ye
10500 61 72 20 61 66 74 65 72 20 4b 26 52 20 77 61 73  ar after K&R was
10510 0a 70 75 62 6c 69 73 68 65 64 2c 20 69 6e 20 5b  .published, in [
10520 56 37 20 55 4e 49 58 5d 5b 76 37 75 78 5d 2e 20  V7 UNIX][v7ux]. 
10530 49 74 20 61 6e 64 20 69 74 73 20 63 6f 72 72 65  It and its corre
10540 73 70 6f 6e 64 69 6e 67 20 60 66 72 65 65 28 29  sponding `free()
10550 60 20 63 61 6c 6c 0a 61 72 65 20 62 61 73 65 64  ` call.are based
10560 20 6f 6e 20 73 69 6d 69 6c 61 72 20 74 65 63 68   on similar tech
10570 6e 69 71 75 65 73 20 74 6f 20 74 68 65 20 60 73  niques to the `s
10580 62 72 6b 28 29 60 2d 62 61 73 65 64 20 60 61 6c  brk()`-based `al
10590 6c 6f 63 28 29 60 20 61 6e 64 0a 60 66 72 65 65  loc()` and.`free
105a0 28 29 60 20 70 75 62 6c 69 73 68 65 64 20 69 6e  ()` published in
105b0 20 4b 26 52 20 41 70 70 65 6e 64 69 78 20 41 2c   K&R Appendix A,
105c0 20 74 68 6f 75 67 68 20 63 6c 65 61 72 6c 79 20   though clearly 
105d0 77 69 74 68 20 71 75 69 74 65 20 61 20 6c 6f 74  with quite a lot
105e0 20 6f 66 0a 65 76 6f 6c 75 74 69 6f 6e 20 62 65   of.evolution be
105f0 74 77 65 65 6e 20 74 68 65 20 74 77 6f 2e 0a 0a  tween the two...
10600 5b 73 62 72 6b 5d 3a 20 68 74 74 70 73 3a 2f 2f  [sbrk]: https://
10610 70 75 62 73 2e 6f 70 65 6e 67 72 6f 75 70 2e 6f  pubs.opengroup.o
10620 72 67 2f 6f 6e 6c 69 6e 65 70 75 62 73 2f 37 39  rg/onlinepubs/79
10630 30 38 37 39 39 2f 78 73 68 2f 62 72 6b 2e 68 74  08799/xsh/brk.ht
10640 6d 6c 0a 5b 76 36 75 78 5d 3a 20 68 74 74 70 73  ml.[v6ux]: https
10650 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61 2e  ://en.wikipedia.
10660 6f 72 67 2f 77 69 6b 69 2f 56 65 72 73 69 6f 6e  org/wiki/Version
10670 5f 36 5f 55 6e 69 78 0a 5b 76 37 75 78 5d 3a 20  _6_Unix.[v7ux]: 
10680 68 74 74 70 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70  https://en.wikip
10690 65 64 69 61 2e 6f 72 67 2f 77 69 6b 69 2f 56 65  edia.org/wiki/Ve
106a0 72 73 69 6f 6e 5f 37 5f 55 6e 69 78 0a 0a 0a 23  rsion_7_Unix...#
106b0 23 23 20 3c 61 20 69 64 3d 22 76 6f 6e 6e 22 3e  ## <a id="vonn">
106c0 3c 2f 61 3e 54 68 65 72 65 20 41 72 65 20 4e 6f  </a>There Are No
106d0 20 53 74 6f 72 61 67 65 20 54 79 70 65 20 44 69   Storage Type Di
106e0 73 74 69 6e 63 74 69 6f 6e 73 0a 0a 4c 69 74 65  stinctions..Lite
106f0 72 61 6c 73 20 61 72 65 20 70 6c 61 63 65 64 20  rals are placed 
10700 69 6e 20 74 68 65 20 73 61 6d 65 20 66 69 65 6c  in the same fiel
10710 64 20 61 73 20 67 6c 6f 62 61 6c 73 20 61 6e 64  d as globals and
10720 20 74 68 65 20 63 61 6c 6c 20 73 74 61 63 6b 2c   the call stack,
10730 0a 72 61 74 68 65 72 20 74 68 61 74 20 69 6e 6c  .rather that inl
10740 69 6e 65 20 77 69 74 68 69 6e 20 74 68 65 20 67  ine within the g
10750 65 6e 65 72 61 74 65 64 20 65 78 65 63 75 74 61  enerated executa
10760 62 6c 65 20 63 6f 64 65 2e 20 54 68 69 73 20 6d  ble code. This m
10770 61 79 20 63 61 75 73 65 0a 73 75 72 70 72 69 73  ay cause.surpris
10780 65 20 73 69 7a 65 20 6c 69 6d 69 74 61 74 69 6f  e size limitatio
10790 6e 73 20 6f 66 20 74 68 65 20 75 73 65 72 20 70  ns of the user p
107a0 72 6f 67 72 61 6d 73 2e 0a 0a 43 43 38 20 64 6f  rograms...CC8 do
107b0 65 73 20 69 74 20 74 68 69 73 20 77 61 79 20 62  es it this way b
107c0 65 63 61 75 73 65 20 74 68 65 20 46 4f 52 54 52  ecause the FORTR
107d0 41 4e 20 49 49 20 2f 20 53 41 42 52 20 73 79 73  AN II / SABR sys
107e0 74 65 6d 20 64 6f 65 73 20 61 6c 6c 6f 77 20 61  tem does allow a
107f0 6e 79 0a 69 6e 69 74 69 61 6c 69 73 61 74 69 6f  ny.initialisatio
10800 6e 20 6f 66 20 43 4f 4d 4d 4f 4e 20 73 74 6f 72  n of COMMON stor
10810 61 67 65 20 69 6e 20 66 69 65 6c 64 20 31 2c 20  age in field 1, 
10820 73 6f 20 74 68 65 20 6c 69 74 65 72 61 6c 73 20  so the literals 
10830 68 61 76 65 20 74 6f 20 62 65 0a 73 74 6f 72 65  have to be.store
10840 64 20 69 6e 20 74 68 65 20 75 73 65 72 20 70 72  d in the user pr
10850 6f 67 72 61 6d 20 70 61 67 65 20 61 6e 64 20 74  ogram page and t
10860 68 65 6e 20 62 65 20 63 6f 70 69 65 64 20 69 6e  hen be copied in
10870 74 6f 20 66 69 65 6c 64 20 31 20 61 74 0a 70 72  to field 1 at.pr
10880 6f 67 72 61 6d 20 69 6e 69 74 69 61 6c 69 7a 61  ogram initializa
10890 74 69 6f 6e 20 74 69 6d 65 2e 20 20 56 61 72 69  tion time.  Vari
108a0 6f 75 73 20 70 6f 69 6e 74 65 72 73 20 74 6f 20  ous pointers to 
108b0 74 68 65 73 65 20 72 65 67 69 6f 6e 73 20 61 72  these regions ar
108c0 65 0a 6d 61 69 6e 61 74 69 6e 65 64 20 62 79 20  e.mainatined by 
108d0 74 68 65 20 63 6f 6d 70 69 6c 65 72 2e 0a 0a 0a  the compiler....
108e0 23 23 23 20 3c 61 20 69 64 3d 22 73 6f 76 65 72  ### <a id="sover
108f0 22 3e 3c 2f 61 3e 53 74 61 63 6b 20 4f 76 65 72  "></a>Stack Over
10900 66 6c 6f 77 0a 0a 53 69 6e 63 65 20 43 43 38 20  flow..Since CC8 
10910 70 6c 61 63 65 73 20 74 68 65 20 63 61 6c 6c 20  places the call 
10920 73 74 61 63 6b 20 69 6d 6d 65 64 69 61 74 65 6c  stack immediatel
10930 79 20 61 66 74 65 72 20 74 68 65 20 6c 61 73 74  y after the last
10940 20 6c 69 74 65 72 61 6c 0a 73 74 6f 72 65 64 20   literal.stored 
10950 69 6e 20 63 6f 72 65 2c 20 61 20 70 72 6f 67 72  in core, a progr
10960 61 6d 20 77 69 74 68 20 6d 61 6e 79 20 67 6c 6f  am with many glo
10970 62 61 6c 73 20 61 6e 64 2f 6f 72 20 6c 69 74 65  bals and/or lite
10980 72 61 6c 73 20 77 69 6c 6c 20 68 61 76 65 0a 6c  rals will have.l
10990 65 73 73 20 75 73 61 62 6c 65 20 73 74 61 63 6b  ess usable stack
109a0 20 73 70 61 63 65 20 74 68 61 6e 20 61 20 70 72   space than a pr
109b0 6f 67 72 61 6d 20 77 69 74 68 20 66 65 77 65 72  ogram with fewer
109c0 20 6f 66 20 65 61 63 68 2e 0a 0a 4e 65 69 74 68   of each...Neith
109d0 65 72 20 76 65 72 73 69 6f 6e 20 6f 66 20 43 43  er version of CC
109e0 38 20 67 65 6e 65 72 61 74 65 73 20 63 6f 64 65  8 generates code
109f0 20 74 6f 20 64 65 74 65 63 74 20 73 74 61 63 6b   to detect stack
10a00 20 6f 76 65 72 66 6c 6f 77 2e 20 49 66 20 79 6f   overflow. If yo
10a10 75 0a 74 72 79 20 74 6f 20 70 75 73 68 20 74 6f  u.try to push to
10a20 6f 20 6d 75 63 68 20 6f 6e 74 6f 20 74 68 65 20  o much onto the 
10a30 73 74 61 63 6b 2c 20 69 74 20 77 69 6c 6c 20 73  stack, it will s
10a40 69 6d 70 6c 79 20 62 65 67 69 6e 20 6f 76 65 72  imply begin over
10a50 77 72 69 74 69 6e 67 0a 74 68 65 20 70 61 67 65  writing.the page
10a60 20 4f 53 2f 38 20 69 73 20 75 73 69 6e 67 20 61   OS/8 is using a
10a70 74 20 74 68 65 20 74 6f 70 20 6f 66 20 66 69 65  t the top of fie
10a80 6c 64 20 31 2e 20 49 66 20 79 6f 75 20 6d 61 6e  ld 1. If you man
10a90 61 67 65 20 74 6f 20 62 6c 6f 77 20 74 68 65 0a  age to blow the.
10aa0 73 74 61 63 6b 20 62 79 20 6d 6f 72 65 20 74 68  stack by more th
10ab0 61 6e 20 61 20 70 61 67 65 20 77 69 74 68 6f 75  an a page withou
10ac0 74 20 63 72 61 73 68 69 6e 67 20 74 68 65 20 70  t crashing the p
10ad0 72 6f 67 72 61 6d 20 6f 72 20 74 68 65 20 63 6f  rogram or the co
10ae0 6d 70 75 74 65 72 0a 66 69 72 73 74 2c 20 74 68  mputer.first, th
10af0 65 20 5b 73 74 61 63 6b 20 70 6f 69 6e 74 65 72  e [stack pointer
10b00 20 77 69 6c 6c 20 77 72 61 70 20 61 72 6f 75 6e   will wrap aroun
10b10 64 5d 28 23 70 74 72 77 72 61 70 29 20 61 6e 64  d](#ptrwrap) and
10b20 20 74 68 65 20 73 74 61 63 6b 20 77 69 6c 6c 0a   the stack will.
10b30 62 65 67 69 6e 20 6f 76 65 72 77 72 69 74 69 6e  begin overwritin
10b40 67 20 74 68 65 20 66 69 72 73 74 20 70 61 67 65  g the first page
10b50 20 6f 66 20 66 69 65 6c 64 20 31 2e 0a 0a 0a 23   of field 1....#
10b60 23 23 20 3c 61 20 69 64 3d 22 66 6c 61 79 6f 75  ## <a id="flayou
10b70 74 22 3e 3c 2f 61 3e 46 69 65 6c 64 20 4c 61 79  t"></a>Field Lay
10b80 6f 75 74 2c 20 43 6f 6e 63 72 65 74 65 20 45 78  out, Concrete Ex
10b90 61 6d 70 6c 65 0a 0a 54 68 65 20 66 69 65 6c 64  ample..The field
10ba0 20 6c 61 79 6f 75 74 20 67 69 76 65 6e 20 5b 61   layout given [a
10bb0 74 20 74 68 65 20 73 74 61 72 74 20 6f 66 20 74  t the start of t
10bc0 68 69 73 20 73 65 63 74 69 6f 6e 5d 28 23 6d 65  his section](#me
10bd0 6d 6f 72 79 29 20 69 73 20 6e 6f 74 0a 66 69 78  mory) is not.fix
10be0 65 64 2e 20 54 68 65 20 6c 69 6e 6b 69 6e 67 20  ed. The linking 
10bf0 6c 6f 61 64 65 72 20 69 73 20 66 72 65 65 20 74  loader is free t
10c00 6f 20 75 73 65 20 61 6e 79 20 6c 61 79 6f 75 74  o use any layout
10c10 20 69 74 20 6c 69 6b 65 73 2c 20 63 6f 6e 73 69   it likes, consi
10c20 73 74 65 6e 74 0a 77 69 74 68 20 61 6e 79 20 63  stent.with any c
10c30 6f 6e 73 74 72 61 69 6e 74 73 20 69 6e 20 74 68  onstraints in th
10c40 65 20 69 6e 70 75 74 20 62 69 6e 61 72 69 65 73  e input binaries
10c50 2e 20 59 6f 75 20 63 61 6e 20 75 73 65 20 74 68  . You can use th
10c60 65 20 60 2f 4d 60 20 6f 70 74 69 6f 6e 0a 77 69  e `/M` option.wi
10c70 74 68 20 60 4c 4f 41 44 45 52 2e 53 56 60 20 74  th `LOADER.SV` t
10c80 6f 20 67 65 74 20 61 20 63 6f 72 65 20 6d 65 6d  o get a core mem
10c90 6f 72 79 20 6d 61 70 20 66 6f 72 20 61 20 67 69  ory map for a gi
10ca0 76 65 6e 20 6f 75 74 70 75 74 2e 20 4c 65 74 e2  ven output. Let
10cb0 80 99 73 20 77 6f 72 6b 0a 61 6e 20 65 78 61 6d  s work.an exam
10cc0 70 6c 65 20 75 73 69 6e 67 20 74 68 65 20 60 70  ple using the `p
10cd0 73 2e 63 60 20 65 78 61 6d 70 6c 65 20 70 72 6f  s.c` example pro
10ce0 67 72 61 6d 3a 0a 0a 20 20 20 20 2e 52 20 43 43  gram:..    .R CC
10cf0 0a 20 20 20 20 3e 70 73 2e 63 0a 20 20 20 20 2e  .    >ps.c.    .
10d00 43 4f 4d 50 20 43 43 2e 53 42 0a 20 20 20 20 2e  COMP CC.SB.    .
10d10 52 20 4c 4f 41 44 45 52 0a 20 20 20 20 2a 43 43  R LOADER.    *CC
10d20 2c 4c 49 42 43 2f 49 2f 4f 2f 4d 0a 20 20 20 20  ,LIBC/I/O/M.    
10d30 56 20 34 41 0a 20 20 20 20 4d 41 49 4e 20 20 20  V 4A.    MAIN   
10d40 20 30 31 30 30 30 0a 20 20 20 20 4c 49 42 43 20   01000.    LIBC 
10d50 20 20 20 32 30 32 30 34 0a 20 20 20 20 4f 50 45     20204.    OPE
10d60 4e 20 20 20 20 30 30 30 30 30 20 55 0a 20 20 20  N    00000 U.   
10d70 20 45 58 49 54 20 20 20 20 30 30 30 30 30 20 55   EXIT    00000 U
10d80 0a 20 20 20 20 2e 2e 2e 0a 0a 54 68 65 20 60 4d  .    .....The `M
10d90 41 49 4e 60 20 6c 69 6e 65 20 74 65 6c 6c 73 20  AIN` line tells 
10da0 75 73 20 74 68 61 74 20 60 4c 4f 41 44 45 52 2e  us that `LOADER.
10db0 53 56 60 20 68 61 73 20 63 68 6f 73 65 6e 20 74  SV` has chosen t
10dc0 6f 20 70 6c 61 63 65 20 6f 75 72 20 43 0a 70 72  o place our C.pr
10dd0 6f 67 72 61 6d 20 69 6e 20 66 69 65 6c 64 20 30  ogram in field 0
10de0 2c 20 6e 6f 74 20 66 69 65 6c 64 20 32 20 61 73  , not field 2 as
10df0 20 73 75 67 67 65 73 74 65 64 20 61 62 6f 76 65   suggested above
10e00 2e 0a 0a 28 54 68 69 73 20 69 73 20 6e 6f 74 20  ...(This is not 
10e10 74 6f 20 62 65 20 63 6f 6e 66 75 73 65 64 20 77  to be confused w
10e20 69 74 68 20 74 68 65 20 43 20 60 6d 61 69 6e 28  ith the C `main(
10e30 29 60 20 2a 66 75 6e 63 74 69 6f 6e 2a 3a 20 77  )` *function*: w
10e40 65 e2 80 99 72 65 0a 76 69 65 77 69 6e 67 20 74  e’re.viewing t
10e50 68 69 6e 67 73 20 66 72 6f 6d 20 74 68 65 20 46  hings from the F
10e60 4f 52 54 52 41 4e 20 49 49 20 6c 65 76 65 6c 20  ORTRAN II level 
10e70 68 65 72 65 2c 20 6e 6f 74 20 74 68 65 20 43 20  here, not the C 
10e80 6c 65 76 65 6c 2e 20 60 4d 41 49 4e 60 0a 69 73  level. `MAIN`.is
10e90 20 74 68 65 20 6e 61 6d 65 20 6f 66 20 74 68 65   the name of the
10ea0 20 77 68 6f 6c 65 20 6d 6f 64 75 6c 65 20 61 73   whole module as
10eb0 20 66 61 72 20 61 73 20 60 4c 4f 41 44 45 52 2e   far as `LOADER.
10ec0 53 56 60 20 69 73 20 63 6f 6e 63 65 72 6e 65 64  SV` is concerned
10ed0 2e 29 0a 0a 54 68 65 20 6c 6f 61 64 65 72 20 64  .)..The loader d
10ee0 6f 75 62 74 6c 65 73 73 20 64 69 64 20 74 68 69  oubtless did thi
10ef0 73 20 62 65 63 61 75 73 65 20 60 70 73 2e 63 60  s because `ps.c`
10f00 20 69 73 20 73 6d 61 6c 6c 2c 20 73 6f 20 74 68   is small, so th
10f10 65 72 65 20 77 61 73 20 6d 6f 72 65 0a 74 68 61  ere was more.tha
10f20 6e 20 65 6e 6f 75 67 68 20 73 70 61 63 65 20 69  n enough space i
10f30 6e 20 66 69 65 6c 64 20 30 20 74 6f 20 68 6f 6c  n field 0 to hol
10f40 64 20 6f 75 72 20 60 4d 41 49 4e 60 20 6d 6f 64  d our `MAIN` mod
10f50 75 6c 65 20 61 6e 64 20 61 6c 6c 20 6f 66 20 74  ule and all of t
10f60 68 65 0a 46 4f 52 54 52 41 4e 20 49 49 20 6c 69  he.FORTRAN II li
10f70 62 72 61 72 79 20 72 6f 75 74 69 6e 65 73 20 69  brary routines i
10f80 74 20 6e 65 65 64 73 2e 20 57 65 e2 80 99 6c 6c  t needs. We’ll
10f90 20 73 65 65 20 68 6f 77 20 6d 75 63 68 20 6d 6f   see how much mo
10fa0 72 65 20 62 65 6c 6f 77 2e 0a 0a 54 68 65 20 6d  re below...The m
10fb0 61 70 20 74 68 65 6e 20 74 65 6c 6c 73 20 75 73  ap then tells us
10fc0 20 74 68 61 74 20 4c 49 42 43 20 69 73 20 69 6e   that LIBC is in
10fd0 20 66 69 65 6c 64 20 32 2c 20 6e 6f 74 20 33 20   field 2, not 3 
10fe0 61 73 20 73 75 67 67 65 73 74 65 64 20 61 62 6f  as suggested abo
10ff0 76 65 2e 0a 54 68 69 73 20 69 73 20 61 67 61 69  ve..This is agai
11000 6e 20 61 20 63 6f 6e 73 65 71 75 65 6e 63 65 20  n a consequence 
11010 6f 66 20 6e 6f 74 20 6e 65 65 64 69 6e 67 20 74  of not needing t
11020 77 6f 20 73 65 70 61 72 61 74 65 20 66 69 65 6c  wo separate fiel
11030 64 73 20 66 6f 72 20 74 68 65 0a 46 4f 52 54 52  ds for the.FORTR
11040 41 4e 20 49 49 20 6c 69 62 72 61 72 79 20 61 6e  AN II library an
11050 64 20 74 68 65 20 60 4d 41 49 4e 60 20 6d 6f 64  d the `MAIN` mod
11060 75 6c 65 2e 0a 0a 54 68 65 20 e2 80 9c 30 30 30  ule...The “000
11070 30 30 20 55 e2 80 9d 20 6c 69 6e 65 73 20 6f 6e  00 U” lines on
11080 20 65 61 63 68 20 6f 66 20 74 68 65 20 46 4f 52   each of the FOR
11090 54 52 41 4e 20 49 49 20 6c 69 62 72 61 72 79 20  TRAN II library 
110a0 72 6f 75 74 69 6e 65 20 6c 6f 63 61 74 69 6f 6e  routine location
110b0 73 0a 74 65 6c 6c 20 75 73 20 74 68 61 74 20 74  s.tell us that t
110c0 68 6f 73 65 20 6c 6f 63 61 74 69 6f 6e 73 20 68  hose locations h
110d0 61 64 6e e2 80 99 74 20 79 65 74 20 62 65 65 6e  adn’t yet been
110e0 20 64 65 74 65 72 6d 69 6e 65 64 20 61 74 20 74   determined at t
110f0 68 65 20 74 69 6d 65 20 69 74 0a 77 61 73 20 74  he time it.was t
11100 6f 6c 64 20 74 6f 20 70 72 6f 64 75 63 65 20 74  old to produce t
11110 68 65 20 63 6f 72 65 20 6d 61 70 2e 20 28 55 20  he core map. (U 
11120 3d 20 e2 80 9c 75 6e 64 65 66 69 6e 65 64 2e e2  = “undefined.
11130 80 9d 29 0a 0a 49 66 20 77 65 20 77 61 6e 74 20  )..If we want 
11140 74 6f 20 70 69 6e 20 64 6f 77 6e 20 74 68 65 20  to pin down the 
11150 6c 6f 63 61 74 69 6f 6e 20 6f 66 20 74 68 6f 73  location of thos
11160 65 20 46 4f 52 54 52 41 4e 20 49 49 20 72 6f 75  e FORTRAN II rou
11170 74 69 6e 65 73 2c 20 77 65 20 63 61 6e 0a 61 73  tines, we can.as
11180 6b 20 74 68 65 20 6c 6f 61 64 65 72 20 74 6f 20  k the loader to 
11190 67 69 76 65 20 75 73 20 74 68 65 20 6d 61 70 20  give us the map 
111a0 2a 61 66 74 65 72 2a 20 69 74 e2 80 99 73 20 66  *after* it’s f
111b0 69 6e 61 6c 69 7a 65 64 20 65 76 65 72 79 74 68  inalized everyth
111c0 69 6e 67 20 62 79 0a 74 65 6c 6c 69 6e 67 20 69  ing by.telling i
111d0 74 20 74 6f 20 72 75 6e 20 74 68 65 20 70 72 6f  t to run the pro
111e0 67 72 61 6d 20 28 60 2f 47 60 29 2c 20 74 68 65  gram (`/G`), the
111f0 6e 20 67 69 76 65 20 75 73 20 74 68 65 20 6d 61  n give us the ma
11200 70 3a 0a 0a 20 20 20 20 2a 43 43 2c 4c 49 42 43  p:..    *CC,LIBC
11210 2f 49 2f 4f 2f 47 2f 4d 0a 20 20 20 20 56 20 34  /I/O/G/M.    V 4
11220 41 0a 20 20 20 20 4d 41 49 4e 20 20 20 20 30 32  A.    MAIN    02
11230 34 30 30 0a 20 20 20 20 4c 49 42 43 20 20 20 20  400.    LIBC    
11240 32 30 32 30 34 0a 20 20 20 20 4f 50 45 4e 20 20  20204.    OPEN  
11250 20 20 30 33 36 33 33 0a 20 20 20 20 45 58 49 54    03633.    EXIT
11260 20 20 20 20 30 34 31 33 33 0a 20 20 20 20 4d 50      04133.    MP
11270 59 20 20 20 20 20 30 34 32 30 36 0a 20 20 20 20  Y     04206.    
11280 43 48 52 49 4f 20 20 20 32 30 34 37 30 0a 20 20  CHRIO   20470.  
11290 20 20 47 45 4e 49 4f 20 20 20 30 33 34 30 33 0a    GENIO   03403.
112a0 20 20 20 20 4f 4f 50 45 4e 20 20 20 30 34 36 32      OOPEN   0462
112b0 35 0a 20 20 20 20 49 4f 50 45 4e 20 20 20 30 34  5.    IOPEN   04
112c0 36 30 32 0a 20 20 20 20 4f 43 4c 4f 53 20 20 20  602.    OCLOS   
112d0 30 34 36 34 37 0a 20 20 20 20 44 49 56 20 20 20  04647.    DIV   
112e0 20 20 30 34 32 35 31 0a 20 20 20 20 49 52 45 4d    04251.    IREM
112f0 20 20 20 20 30 34 33 35 35 0a 20 20 20 20 45 52      04355.    ER
11300 52 4f 52 20 20 20 30 34 30 31 33 0a 20 20 20 20  ROR   04013.    
11310 43 4b 49 4f 20 20 20 20 30 34 31 34 31 0a 20 20  CKIO    04141.  
11320 20 20 43 4c 45 41 52 20 20 20 30 34 34 33 37 0a    CLEAR   04437.
11330 20 20 20 20 49 41 42 53 20 20 20 20 30 34 34 30      IABS    0440
11340 30 0a 20 20 20 20 49 52 44 53 57 20 20 20 30 34  0.    IRDSW   04
11350 34 32 31 0a 20 20 20 20 53 55 42 53 43 20 20 20  421.    SUBSC   
11360 30 34 34 36 32 0a 20 20 20 20 43 48 41 49 4e 20  04462.    CHAIN 
11370 20 20 30 34 37 33 33 0a 20 20 20 20 30 30 31 33    04733.    0013
11380 0a 20 20 20 20 30 30 30 30 0a 20 20 20 20 30 30  .    0000.    00
11390 30 30 0a 20 20 20 20 30 30 33 36 0a 20 20 20 20  00.    0036.    
113a0 30 30 33 36 0a 20 20 20 20 30 30 33 36 0a 20 20  0036.    0036.  
113b0 20 20 30 30 33 36 0a 20 20 20 20 30 30 33 36 0a    0036.    0036.
113c0 0a 4e 6f 77 20 77 65 20 63 61 6e 20 73 65 65 20  .Now we can see 
113d0 74 68 61 74 2c 20 69 6e 64 65 65 64 2c 20 61 6c  that, indeed, al
113e0 6c 20 6f 66 20 74 68 65 20 46 4f 52 54 52 41 4e  l of the FORTRAN
113f0 20 49 49 20 6c 69 62 72 61 72 79 20 72 6f 75 74   II library rout
11400 69 6e 65 73 20 64 69 64 0a 69 6e 20 66 61 63 74  ines did.in fact
11410 20 6c 61 6e 64 20 69 6e 20 66 69 65 6c 64 20 30   land in field 0
11420 2e 0a 0a 54 68 65 20 74 61 69 6c 20 65 6e 64 20  ...The tail end 
11430 6f 66 20 74 68 65 20 6d 61 70 20 66 69 6c 65 20  of the map file 
11440 69 73 20 61 6c 73 6f 20 68 65 6c 70 66 75 6c 2e  is also helpful.
11450 20 54 68 65 72 65 20 61 72 65 20 38 20 6c 69 6e   There are 8 lin
11460 65 73 20 61 74 20 74 68 65 0a 65 6e 64 20 66 6f  es at the.end fo
11470 72 20 61 20 33 32 26 6e 62 73 70 3b 6b 57 6f 72  r a 32&nbsp;kWor
11480 64 20 6d 61 63 68 69 6e 65 2c 20 6f 6e 65 20 66  d machine, one f
11490 6f 72 20 65 61 63 68 20 66 69 65 6c 64 2e 20 54  or each field. T
114a0 68 65 20 76 61 6c 75 65 20 69 73 20 74 68 65 0a  he value is the.
114b0 6e 75 6d 62 65 72 20 6f 66 20 63 6f 72 65 20 6d  number of core m
114c0 65 6d 6f 72 79 20 70 61 67 65 73 20 6c 65 66 74  emory pages left
114d0 20 66 72 65 65 2c 20 69 6e 20 6f 63 74 61 6c 2c   free, in octal,
114e0 20 61 66 74 65 72 20 6c 6f 61 64 69 6e 67 20 74   after loading t
114f0 68 65 0a 70 72 6f 67 72 61 6d 2e 0a 0a 54 68 69  he.program...Thi
11500 73 20 74 65 6c 6c 73 20 75 73 20 74 68 61 74 20  s tells us that 
11510 66 69 65 6c 64 20 30 20 68 61 73 20 31 33 e2 82  field 0 has 13
11520 88 20 70 61 67 65 73 20 66 72 65 65 2c 20 67 69   pages free, gi
11530 76 69 6e 67 20 75 73 20 61 74 20 6c 65 61 73 74  ving us at least
11540 20 32 36 30 30 e2 82 88 0a 77 6f 72 64 73 20 6f   2600₈.words o
11550 66 20 73 70 61 63 65 20 74 6f 20 75 73 65 20 77  f space to use w
11560 69 74 68 20 43 20 63 6f 64 65 20 61 6e 64 20 46  ith C code and F
11570 4f 52 54 52 41 4e 20 49 49 20 6c 69 62 72 61 72  ORTRAN II librar
11580 79 20 72 65 66 65 72 65 6e 63 65 73 0a 62 65 66  y references.bef
11590 6f 72 65 20 74 68 65 20 6c 6f 61 64 65 72 20 77  ore the loader w
115a0 69 6c 6c 20 62 65 20 66 6f 72 63 65 64 20 74 6f  ill be forced to
115b0 20 70 75 74 20 60 4d 41 49 4e 60 20 69 6e 20 61   put `MAIN` in a
115c0 20 73 65 70 61 72 61 74 65 20 66 69 65 6c 64 2e   separate field.
115d0 0a 0a 46 69 65 6c 64 73 20 31 20 61 6e 64 20 32  ..Fields 1 and 2
115e0 20 61 72 65 20 6d 61 72 6b 65 64 20 61 73 20 77   are marked as w
115f0 68 6f 6c 6c 79 20 75 73 65 64 20 75 70 2e 20 54  holly used up. T
11600 68 69 73 20 69 73 20 61 6e 6f 74 68 65 72 20 67  his is another g
11610 6f 6f 64 20 63 6c 75 65 0a 74 68 61 74 20 74 68  ood clue.that th
11620 69 73 20 69 73 20 74 68 65 20 55 44 46 20 69 73  is is the UDF is
11630 20 69 6e 20 66 69 65 6c 64 20 31 20 69 6e 20 74   in field 1 in t
11640 68 69 73 20 70 72 6f 67 72 61 6d 2c 20 73 69 6e  his program, sin
11650 63 65 20 77 65 20 6b 6e 6f 77 20 4c 49 42 43 0a  ce we know LIBC.
11660 69 73 20 69 6e 20 66 69 65 6c 64 20 32 2e 20 45  is in field 2. E
11670 76 65 72 79 20 6c 61 73 74 20 77 6f 72 64 20 6f  very last word o
11680 66 20 74 68 65 73 65 20 70 61 67 65 73 20 69 73  f these pages is
11690 6e e2 80 99 74 20 61 63 74 75 61 6c 6c 79 20 69  n’t actually i
116a0 6e 20 75 73 65 2c 20 62 75 74 0a 74 68 65 20 4c  n use, but.the L
116b0 4f 41 44 45 52 20 63 6f 6e 73 69 64 65 72 73 20  OADER considers 
116c0 74 68 65 73 65 20 73 70 61 63 65 73 20 68 61 6e  these spaces han
116d0 64 73 2d 6f 66 66 20 61 73 20 66 61 72 20 61 73  ds-off as far as
116e0 20 6c 6f 61 64 69 6e 67 20 6f 74 68 65 72 0a 63   loading other.c
116f0 6f 64 65 2e 0a 0a 54 68 65 20 76 61 6c 75 65 20  ode...The value 
11700 33 36 e2 82 88 20 69 6e 20 74 68 65 20 72 65 6d  36₈ in the rem
11710 61 69 6e 69 6e 67 20 6c 69 6e 65 73 20 72 65 66  aining lines ref
11720 6c 65 63 74 73 20 74 68 65 20 77 61 79 20 74 68  lects the way th
11730 65 20 6c 6f 61 64 65 72 20 77 6f 72 6b 73 2e 0a  e loader works..
11740 54 68 65 20 73 69 7a 65 20 6f 66 20 61 20 63 6f  The size of a co
11750 72 65 20 6d 65 6d 6f 72 79 20 66 69 65 6c 64 20  re memory field 
11760 69 6e 20 74 68 65 20 50 44 50 2d 38 20 69 73 20  in the PDP-8 is 
11770 34 30 e2 82 88 20 70 61 67 65 73 2e 20 54 68 65  40₈ pages. The
11780 20 6c 6f 77 65 73 74 0a 70 61 67 65 20 69 73 20   lowest.page is 
11790 5b 73 65 74 20 61 73 69 64 65 20 66 6f 72 20 75  [set aside for u
117a0 73 65 20 62 79 20 4c 4f 41 44 45 52 20 69 74 73  se by LOADER its
117b0 65 6c 66 5d 28 23 6c 64 72 74 73 29 2e 20 54 68  elf](#ldrts). Th
117c0 65 20 72 65 6d 61 69 6e 69 6e 67 20 33 0a 70 61  e remaining 3.pa
117d0 67 65 73 20 70 65 72 20 66 69 65 6c 64 20 61 72  ges per field ar
117e0 65 20 64 75 65 20 74 6f 20 6f 75 72 20 75 73 65  e due to our use
117f0 20 6f 66 20 64 65 76 69 63 65 2d 69 6e 64 65 70   of device-indep
11800 65 6e 64 65 6e 74 20 49 2f 4f 2c 20 72 65 71 75  endent I/O, requ
11810 65 73 74 65 64 0a 66 72 6f 6d 20 4c 4f 41 44 45  ested.from LOADE
11820 52 20 77 69 74 68 20 74 68 65 20 60 2f 49 2f 4f  R with the `/I/O
11830 60 20 66 6c 61 67 73 2e 20 50 72 6f 67 72 61 6d  ` flags. Program
11840 73 20 6e 6f 74 20 6e 65 65 64 69 6e 67 20 74 68  s not needing th
11850 61 74 20 63 61 6e 20 73 61 76 65 0a 62 65 74 77  at can save.betw
11860 65 65 6e 20 31 20 61 6e 64 20 33 20 6f 66 20 74  een 1 and 3 of t
11870 68 65 73 65 20 70 61 67 65 73 20 70 65 72 20 66  hese pages per f
11880 69 65 6c 64 2e 0a 0a 46 6f 72 20 6d 6f 72 65 20  ield...For more 
11890 6f 6e 20 74 68 69 73 20 74 6f 70 69 63 2c 20 73  on this topic, s
118a0 65 65 20 74 68 65 20 63 6f 6d 70 61 6e 69 6f 6e  ee the companion
118b0 20 61 72 74 69 63 6c 65 20 5b 50 44 50 2d 38 20   article [PDP-8 
118c0 4d 65 6d 6f 72 79 0a 41 64 64 72 65 73 73 69 6e  Memory.Addressin
118d0 67 5d 5b 6d 65 6d 61 64 64 5d 2e 0a 0a 0a 5b 6d  g][memadd]....[m
118e0 65 6d 61 64 64 5d 3a 20 2f 77 69 6b 69 3f 6e 61  emadd]: /wiki?na
118f0 6d 65 3d 50 44 50 2d 38 2b 4d 65 6d 6f 72 79 2b  me=PDP-8+Memory+
11900 41 64 64 72 65 73 73 69 6e 67 0a 5b 6f 73 38 6b  Addressing.[os8k
11910 62 64 5d 3a 20 68 74 74 70 73 3a 2f 2f 61 72 63  bd]: https://arc
11920 68 69 76 65 2e 6f 72 67 2f 64 65 74 61 69 6c 73  hive.org/details
11930 2f 62 69 74 73 61 76 65 72 73 5f 64 65 63 70 64  /bitsavers_decpd
11940 70 38 6f 73 38 75 70 5f 35 35 36 36 34 39 35 2f  p8os8up_5566495/
11950 70 61 67 65 2f 6e 39 0a 5b 6f 73 38 6f 66 74 5d  page/n9.[os8oft]
11960 3a 20 68 74 74 70 73 3a 2f 2f 61 72 63 68 69 76  : https://archiv
11970 65 2e 6f 72 67 2f 64 65 74 61 69 6c 73 2f 62 69  e.org/details/bi
11980 74 73 61 76 65 72 73 5f 64 65 63 70 64 70 38 6f  tsavers_decpdp8o
11990 73 38 75 70 5f 35 35 36 36 34 39 35 2f 70 61 67  s8up_5566495/pag
119a0 65 2f 6e 33 35 0a 5b 6f 73 38 72 65 73 5d 3a 20  e/n35.[os8res]: 
119b0 68 74 74 70 73 3a 2f 2f 61 72 63 68 69 76 65 2e  https://archive.
119c0 6f 72 67 2f 64 65 74 61 69 6c 73 2f 62 69 74 73  org/details/bits
119d0 61 76 65 72 73 5f 64 65 63 70 64 70 38 6f 73 38  avers_decpdp8os8
119e0 75 70 5f 35 35 36 36 34 39 35 2f 70 61 67 65 2f  up_5566495/page/
119f0 6e 36 39 0a 5b 6f 73 38 75 73 72 5d 3a 20 68 74  n69.[os8usr]: ht
11a00 74 70 73 3a 2f 2f 61 72 63 68 69 76 65 2e 6f 72  tps://archive.or
11a10 67 2f 64 65 74 61 69 6c 73 2f 62 69 74 73 61 76  g/details/bitsav
11a20 65 72 73 5f 64 65 63 70 64 70 38 6f 73 38 75 70  ers_decpdp8os8up
11a30 5f 35 35 36 36 34 39 35 2f 70 61 67 65 2f 6e 31  _5566495/page/n1
11a40 37 0a 5b 75 62 5d 3a 20 20 20 20 20 68 74 74 70  7.[ub]:     http
11a50 73 3a 2f 2f 65 6e 2e 77 69 6b 69 70 65 64 69 61  s://en.wikipedia
11a60 2e 6f 72 67 2f 77 69 6b 69 2f 55 6e 64 65 66 69  .org/wiki/Undefi
11a70 6e 65 64 5f 62 65 68 61 76 69 6f 72 0a 5b 7a 70  ned_behavior.[zp
11a80 5d 3a 20 20 20 20 20 68 74 74 70 73 3a 2f 2f 68  ]:     https://h
11a90 6f 6d 65 70 61 67 65 2e 64 69 76 6d 73 2e 75 69  omepage.divms.ui
11aa0 6f 77 61 2e 65 64 75 2f 7e 6a 6f 6e 65 73 2f 70  owa.edu/~jones/p
11ab0 64 70 38 2f 6d 61 6e 2f 6d 72 69 2e 68 74 6d 6c  dp8/man/mri.html
11ac0 23 70 61 67 65 7a 65 72 6f 0a 0a 0a 3c 61 20 69  #pagezero...<a i
11ad0 64 3d 22 61 73 6d 22 3e 3c 2f 61 3e 0a 23 23 20  d="asm"></a>.## 
11ae0 49 6e 6c 69 6e 65 20 41 73 73 65 6d 62 6c 79 20  Inline Assembly 
11af0 43 6f 64 65 0a 0a 42 6f 74 68 20 74 68 65 20 5b  Code..Both the [
11b00 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 72 5d 28  cross-compiler](
11b10 23 63 72 6f 73 73 29 20 61 6e 64 20 74 68 65 20  #cross) and the 
11b20 5b 6e 61 74 69 76 65 20 63 6f 6d 70 69 6c 65 72  [native compiler
11b30 5d 28 23 6e 61 74 69 76 65 29 0a 61 6c 6c 6f 77  ](#native).allow
11b40 20 69 6e 6c 69 6e 65 20 5b 53 41 42 52 5d 5b 73   inline [SABR][s
11b50 61 62 72 5d 20 61 73 73 65 6d 62 6c 79 20 63 6f  abr] assembly co
11b60 64 65 20 62 65 74 77 65 65 6e 20 60 23 61 73 6d  de between `#asm
11b70 60 20 61 6e 64 20 60 23 65 6e 64 61 73 6d 60 0a  ` and `#endasm`.
11b80 6d 61 72 6b 65 72 73 20 69 6e 20 74 68 65 20 43  markers in the C
11b90 20 73 6f 75 72 63 65 20 63 6f 64 65 3a 0a 0a 20   source code:.. 
11ba0 20 20 20 23 61 73 6d 0a 20 20 20 20 20 20 20 20     #asm.        
11bb0 54 41 44 20 28 34 32 20 20 20 20 20 20 2f 20 61  TAD (42      / a
11bc0 64 64 20 34 32 20 74 6f 20 41 43 0a 20 20 20 20  dd 42 to AC.    
11bd0 23 65 6e 64 61 73 6d 0a 0a 53 75 63 68 20 63 6f  #endasm..Such co
11be0 64 65 20 69 73 20 63 6f 70 69 65 64 20 6c 69 74  de is copied lit
11bf0 65 72 61 6c 6c 79 20 66 72 6f 6d 20 74 68 65 20  erally from the 
11c00 69 6e 70 75 74 20 43 20 73 6f 75 72 63 65 20 66  input C source f
11c10 69 6c 65 20 69 6e 74 6f 20 74 68 65 0a 63 6f 6d  ile into the.com
11c20 70 69 6c 65 72 e2 80 99 73 20 53 41 42 52 20 6f  piler’s SABR o
11c30 75 74 70 75 74 20 66 69 6c 65 2c 20 73 6f 20 69  utput file, so i
11c40 74 20 6d 75 73 74 20 62 65 20 77 72 69 74 74 65  t must be writte
11c50 6e 20 77 69 74 68 20 74 68 61 74 20 63 6f 6e 74  n with that cont
11c60 65 78 74 20 69 6e 0a 6d 69 6e 64 2e 0a 0a 0a 23  ext in.mind....#
11c70 23 23 20 3c 61 20 69 64 3d 22 63 61 6c 6c 69 6e  ## <a id="callin
11c80 67 22 3e 3c 2f 61 3e 54 68 65 20 43 43 38 20 43  g"></a>The CC8 C
11c90 61 6c 6c 69 6e 67 20 43 6f 6e 76 65 6e 74 69 6f  alling Conventio
11ca0 6e 0a 0a 59 6f 75 20 63 61 6e 20 77 72 69 74 65  n..You can write
11cb0 20 77 68 6f 6c 65 20 66 75 6e 63 74 69 6f 6e 73   whole functions
11cc0 20 69 6e 20 69 6e 6c 69 6e 65 20 61 73 73 65 6d   in inline assem
11cd0 62 6c 79 2c 20 74 68 6f 75 67 68 20 66 6f 72 20  bly, though for 
11ce0 73 69 6d 70 6c 69 63 69 74 79 2c 0a 77 65 20 72  simplicity,.we r
11cf0 65 63 6f 6d 6d 65 6e 64 20 74 68 61 74 20 79 6f  ecommend that yo
11d00 75 20 77 72 69 74 65 20 74 68 65 20 66 75 6e 63  u write the func
11d10 74 69 6f 6e 20 77 72 61 70 70 65 72 20 69 6e 20  tion wrapper in 
11d20 43 20 73 79 6e 74 61 78 2c 20 77 69 74 68 20 74  C syntax, with t
11d30 68 65 0a 62 6f 64 79 20 69 6e 20 61 73 73 65 6d  he.body in assem
11d40 62 6c 79 3a 0a 0a 20 20 20 20 61 64 64 34 38 28  bly:..    add48(
11d50 61 29 0a 20 20 20 20 69 6e 74 20 61 0a 20 20 20  a).    int a.   
11d60 20 7b 0a 20 20 20 20 20 20 20 20 61 3b 20 20 20   {.        a;   
11d70 20 20 20 20 20 20 20 2f 2a 20 6c 6f 61 64 20 27         /* load '
11d80 61 27 20 69 6e 74 6f 20 41 43 3b 20 65 78 70 6c  a' into AC; expl
11d90 61 69 6e 65 64 20 62 65 6c 6f 77 20 2a 2f 0a 20  ained below */. 
11da0 20 20 20 23 61 73 6d 0a 20 20 20 20 20 20 20 20     #asm.        
11db0 54 41 44 20 28 44 34 38 0a 20 20 20 20 23 65 6e  TAD (D48.    #en
11dc0 64 61 73 6d 0a 20 20 20 20 7d 0a 0a 44 6f 69 6e  dasm.    }..Doin
11dd0 67 20 69 74 20 74 68 69 73 20 77 61 79 20 73 61  g it this way sa
11de0 76 65 73 20 79 6f 75 20 66 72 6f 6d 20 68 61 76  ves you from hav
11df0 69 6e 67 20 74 6f 20 75 6e 64 65 72 73 74 61 6e  ing to understan
11e00 64 20 74 68 65 20 77 61 79 20 74 68 65 20 43 43  d the way the CC
11e10 38 0a 73 6f 66 74 77 61 72 65 20 73 74 61 63 6b  8.software stack
11e20 20 77 6f 72 6b 73 2c 20 77 68 69 63 68 20 77 65   works, which we
11e30 e2 80 99 76 65 20 63 68 6f 73 65 6e 20 6e 6f 74  ’ve chosen not
11e40 20 74 6f 20 64 6f 63 75 6d 65 6e 74 20 68 65 72   to document her
11e50 65 20 79 65 74 2c 20 61 70 61 72 74 0a 66 72 6f  e yet, apart.fro
11e60 6d 20 5b 69 74 73 20 61 70 70 72 6f 78 69 6d 61  m [its approxima
11e70 74 65 20 6c 6f 63 61 74 69 6f 6e 20 69 6e 20 63  te location in c
11e80 6f 72 65 20 6d 65 6d 6f 72 79 5d 28 23 6d 65 6d  ore memory](#mem
11e90 6f 72 79 29 2e 20 41 6c 6c 20 79 6f 75 20 6e 65  ory). All you ne
11ea0 65 64 20 74 6f 0a 6b 6e 6f 77 20 69 73 20 74 68  ed to.know is th
11eb0 61 74 20 70 61 72 61 6d 65 74 65 72 73 20 61 72  at parameters ar
11ec0 65 20 70 61 73 73 65 64 20 6f 6e 20 74 68 65 20  e passed on the 
11ed0 73 74 61 63 6b 20 61 6e 64 20 2a 73 6f 6d 65 68  stack and *someh
11ee0 6f 77 2a 20 65 78 74 72 61 63 74 65 64 0a 77 68  ow* extracted.wh
11ef0 65 6e 20 74 68 65 79 e2 80 99 72 65 20 72 65 66  en they’re ref
11f00 65 72 65 6e 63 65 64 20 69 6e 20 43 20 63 6f 64  erenced in C cod
11f10 65 2e 0a 0a 43 43 38 20 72 65 74 75 72 6e 73 20  e...CC8 returns 
11f20 76 61 6c 75 65 73 20 66 72 6f 6d 20 66 75 6e 63  values from func
11f30 74 69 6f 6e 73 20 69 6e 20 41 43 2c 20 73 6f 20  tions in AC, so 
11f40 6f 75 72 20 65 78 61 6d 70 6c 65 20 64 6f 65 73  our example does
11f50 20 6e 6f 74 20 72 65 71 75 69 72 65 0a 61 6e 20   not require.an 
11f60 65 78 70 6c 69 63 69 74 20 e2 80 9c 60 72 65 74  explicit “`ret
11f70 75 72 6e 60 e2 80 9d 20 73 74 61 74 65 6d 65 6e  urn`” statemen
11f80 74 3a 20 77 65 e2 80 99 76 65 20 61 72 72 61 6e  t: we’ve arran
11f90 67 65 64 20 66 6f 72 20 6f 75 72 20 69 6e 74 65  ged for our inte
11fa0 6e 64 65 64 20 72 65 74 75 72 6e 0a 76 61 6c 75  nded return.valu
11fb0 65 20 74 6f 20 62 65 20 69 6e 20 41 43 20 61 74  e to be in AC at
11fc0 20 74 68 65 20 65 6e 64 20 6f 66 20 74 68 65 20   the end of the 
11fd0 66 75 6e 63 74 69 6f 6e 20 62 6f 64 79 2c 20 73  function body, s
11fe0 6f 20 74 68 65 20 69 6d 70 6c 69 63 69 74 0a 72  o the implicit.r
11ff0 65 74 75 72 6e 20 64 6f 65 73 20 77 68 61 74 20  eturn does what 
12000 77 65 20 77 61 6e 74 20 68 65 72 65 2e 0a 0a 54  we want here...T
12010 68 65 20 61 62 6f 76 65 20 73 6e 69 70 70 65 74  he above snippet
12020 20 74 68 65 72 65 66 6f 72 65 20 64 65 63 6c 61   therefore decla
12030 72 65 73 20 61 20 66 75 6e 63 74 69 6f 6e 20 60  res a function `
12040 61 64 64 34 38 60 20 74 61 6b 69 6e 67 20 61 20  add48` taking a 
12050 73 69 6e 67 6c 65 0a 70 61 72 61 6d 65 74 65 72  single.parameter
12060 20 e2 80 9c 60 61 60 e2 80 9d 20 61 6e 64 20 72   “`a`” and r
12070 65 74 75 72 6e 69 6e 67 20 60 61 2b 34 38 60 2e  eturning `a+48`.
12080 0a 0a 4b 65 65 70 20 69 6e 20 6d 69 6e 64 20 77  ..Keep in mind w
12090 68 65 6e 20 72 65 61 64 69 6e 67 20 73 75 63 68  hen reading such
120a0 20 63 6f 64 65 20 74 68 61 74 20 43 43 38 20 69   code that CC8 i
120b0 73 20 5b 65 73 73 65 6e 74 69 61 6c 6c 79 0a 74  s [essentially.t
120c0 79 70 65 6c 65 73 73 5d 28 23 74 79 70 65 6c 65  ypeless](#typele
120d0 73 73 29 3a 20 69 74 e2 80 99 73 20 74 65 6d 70  ss): it’s temp
120e0 74 69 6e 67 20 74 6f 20 74 68 69 6e 6b 20 6f 66  ting to think of
120f0 20 74 68 65 20 61 62 6f 76 65 20 63 6f 64 65 20   the above code 
12100 61 73 20 74 61 6b 69 6e 67 0a 61 6e 20 69 6e 74  as taking.an int
12110 65 67 65 72 20 61 6e 64 20 72 65 74 75 72 6e 69  eger and returni
12120 6e 67 20 61 6e 20 69 6e 74 65 67 65 72 2c 20 62  ng an integer, b
12130 75 74 20 79 6f 75 20 63 61 6e 20 65 71 75 61 6c  ut you can equal
12140 6c 79 20 63 6f 72 72 65 63 74 6c 79 20 74 68 69  ly correctly thi
12150 6e 6b 0a 6f 66 20 69 74 20 61 73 20 74 61 6b 69  nk.of it as taki
12160 6e 67 20 61 20 63 68 61 72 61 63 74 65 72 20 61  ng a character a
12170 6e 64 20 72 65 74 75 72 6e 69 6e 67 20 61 20 63  nd returning a c
12180 68 61 72 61 63 74 65 72 2e 20 49 6e 64 65 65 64  haracter. Indeed
12190 2c 20 74 68 61 74 0a 66 75 6e 63 74 69 6f 6e 20  , that.function 
121a0 77 69 6c 6c 20 74 61 6b 65 20 61 20 76 61 6c 75  will take a valu
121b0 65 20 69 6e 20 74 68 65 20 72 61 6e 67 65 20 30  e in the range 0
121c0 20 74 68 72 75 20 39 20 61 6e 64 20 72 65 74 75   thru 9 and retu
121d0 72 6e 20 74 68 65 0a 65 71 75 69 76 61 6c 65 6e  rn the.equivalen
121e0 74 20 41 53 43 49 49 20 64 69 67 69 74 21 20 43  t ASCII digit! C
121f0 43 38 e2 80 99 73 20 74 79 70 65 6c 65 73 73 20  C8’s typeless 
12200 6e 61 74 75 72 65 20 6d 61 74 65 73 20 77 65 6c  nature mates wel
12210 6c 20 77 69 74 68 20 4b 26 52 20 43 e2 80 99 73  l with K&R C’s
12220 0a 69 6e 64 69 66 66 65 72 65 6e 63 65 20 74 6f  .indifference to
12230 77 61 72 64 20 72 65 74 75 72 6e 20 74 79 70 65  ward return type
12240 20 64 65 63 6c 61 72 61 74 69 6f 6e 2e 0a 0a 0a   declaration....
12250 23 23 23 20 45 71 75 69 76 61 6c 65 6e 63 65 20  ### Equivalence 
12260 74 6f 20 53 74 61 74 65 6d 65 6e 74 73 0a 0a 41  to Statements..A
12270 20 62 6c 6f 63 6b 20 6f 66 20 69 6e 6c 69 6e 65   block of inline
12280 20 61 73 73 65 6d 62 6c 79 20 66 75 6e 63 74 69   assembly functi
12290 6f 6e 73 20 61 73 20 73 69 6e 67 6c 65 20 73 74  ons as single st
122a0 61 74 65 6d 65 6e 74 20 69 6e 20 74 68 65 20 43  atement in the C
122b0 0a 70 72 6f 67 72 61 6d 2c 20 66 72 6f 6d 20 61  .program, from a
122c0 20 73 79 6e 74 61 63 74 69 63 20 70 6f 69 6e 74   syntactic point
122d0 20 6f 66 20 76 69 65 77 2e 20 43 6f 6e 73 69 64   of view. Consid
122e0 65 72 20 74 68 65 20 69 6d 70 6c 65 6d 65 6e 74  er the implement
122f0 61 74 69 6f 6e 20 6f 66 0a 74 68 65 20 53 74 61  ation of.the Sta
12300 6e 64 61 72 64 20 43 20 66 75 6e 63 74 69 6f 6e  ndard C function
12310 20 60 70 75 74 73 60 20 66 72 6f 6d 20 74 68 65   `puts` from the
12320 20 43 43 38 20 4c 49 42 43 3a 0a 0a 20 20 20 20   CC8 LIBC:..    
12330 70 75 74 73 28 70 29 0a 20 20 20 20 63 68 61 72  puts(p).    char
12340 20 2a 70 3b 0a 20 20 20 20 20 20 20 20 7b 0a 20   *p;.        {. 
12350 20 20 20 20 20 20 20 20 20 20 20 77 68 69 6c 65             while
12360 20 28 2a 70 2b 2b 29 20 0a 20 20 20 20 23 61 73   (*p++) .    #as
12370 6d 0a 20 20 20 20 20 20 20 20 20 20 20 20 54 4c  m.            TL
12380 53 0a 20 20 20 20 58 43 31 2c 20 20 20 20 54 53  S.    XC1,    TS
12390 46 0a 20 20 20 20 20 20 20 20 20 20 20 20 4a 4d  F.            JM
123a0 50 20 58 43 31 0a 20 20 20 20 23 65 6e 64 61 73  P XC1.    #endas
123b0 6d 0a 20 20 20 20 20 20 20 20 7d 0a 0a 4e 6f 74  m.        }..Not
123c0 69 63 65 20 74 68 61 74 20 74 68 65 72 65 20 69  ice that there i
123d0 73 20 6e 6f 20 6f 70 65 6e 69 6e 67 20 63 75 72  s no opening cur
123e0 6c 79 20 62 72 61 63 65 20 6f 6e 20 74 68 65 20  ly brace on the 
123f0 60 77 68 69 6c 65 60 20 6c 6f 6f 70 3a 20 77 68  `while` loop: wh
12400 65 6e 0a 74 68 65 20 60 54 53 46 60 20 6f 70 2d  en.the `TSF` op-
12410 63 6f 64 65 20 63 61 75 73 65 73 20 74 68 65 20  code causes the 
12420 60 4a 4d 50 60 20 69 6e 73 74 72 75 63 74 69 6f  `JMP` instructio
12430 6e 20 74 6f 20 62 65 20 73 6b 69 70 70 65 64 20  n to be skipped 
12440 e2 80 94 20 6d 65 61 6e 69 6e 67 0a 74 68 65 20  — meaning.the 
12450 63 6f 6e 73 6f 6c 65 20 74 65 72 6d 69 6e 61 6c  console terminal
12460 20 69 73 20 72 65 61 64 79 20 66 6f 72 20 61 6e   is ready for an
12470 6f 74 68 65 72 20 6f 75 74 70 75 74 20 63 68 61  other output cha
12480 72 61 63 74 65 72 20 e2 80 94 20 63 6f 6e 74 72  racter — contr
12490 6f 6c 0a 67 6f 65 73 20 62 61 63 6b 20 74 6f 20  ol.goes back to 
124a0 74 68 65 20 74 6f 70 20 6f 66 20 74 68 65 20 60  the top of the `
124b0 77 68 69 6c 65 60 20 6c 6f 6f 70 2e 20 54 68 61  while` loop. Tha
124c0 74 20 69 73 2c 20 74 68 65 73 65 20 74 68 72 65  t is, these thre
124d0 65 0a 69 6e 73 74 72 75 63 74 69 6f 6e 73 20 62  e.instructions b
124e0 65 68 61 76 65 20 61 73 20 69 66 20 74 68 65 79  ehave as if they
124f0 20 77 65 72 65 20 61 20 73 69 6e 67 6c 65 20 43   were a single C
12500 20 73 74 61 74 65 6d 65 6e 74 20 61 6e 64 20 74   statement and t
12510 68 75 73 0a 63 6f 6e 73 74 69 74 75 74 65 20 74  hus.constitute t
12520 68 65 20 77 68 6f 6c 65 20 62 6f 64 79 20 6f 66  he whole body of
12530 20 74 68 65 20 60 77 68 69 6c 65 60 20 6c 6f 6f   the `while` loo
12540 70 2e 0a 0a 0a 23 23 23 20 4f 70 74 69 6d 69 7a  p....### Optimiz
12550 61 74 69 6f 6e 0a 0a 54 68 65 72 65 20 61 72 65  ation..There are
12560 20 73 65 76 65 72 61 6c 20 63 6c 65 76 65 72 20   several clever 
12570 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 73 20 74 68  optimizations th
12580 61 74 20 79 6f 75 20 6d 69 67 68 74 20 77 61 6e  at you might wan
12590 74 20 74 6f 20 75 73 65 20 69 6e 0a 79 6f 75 72  t to use in.your
125a0 20 6f 77 6e 20 70 72 6f 67 72 61 6d 73 2c 20 73   own programs, s
125b0 6f 6d 65 20 6f 66 20 77 68 69 63 68 20 61 72 65  ome of which are
125c0 20 73 68 6f 77 6e 20 69 6e 20 74 68 65 20 65 78   shown in the ex
125d0 61 6d 70 6c 65 73 20 61 62 6f 76 65 3a 0a 0a 2a  amples above:..*
125e0 20 20 20 49 6e 20 74 68 65 20 60 61 64 64 34 38     In the `add48
125f0 60 20 65 78 61 6d 70 6c 65 20 74 68 65 20 6c 69  ` example the li
12600 6e 65 20 e2 80 9c 60 61 3b 60 e2 80 9d 20 6d 65  ne “`a;`” me
12610 61 6e 73 20 e2 80 9c 6c 6f 61 64 20 60 61 60 20  ans “load `a` 
12620 69 6e 74 6f 20 41 43 e2 80 9d 2e 20 49 6e 0a 20  into AC”. In. 
12630 20 20 20 61 20 53 74 61 6e 64 61 72 64 20 43 20     a Standard C 
12640 63 6f 6d 70 69 6c 65 72 2c 20 74 68 69 73 20 77  compiler, this w
12650 6f 75 6c 64 20 62 65 20 63 6f 6e 73 69 64 65 72  ould be consider
12660 65 64 20 75 73 65 20 6f 66 20 61 20 76 61 72 69  ed use of a vari
12670 61 62 6c 65 20 69 6e 0a 20 20 20 20 60 76 6f 69  able in.    `voi
12680 64 60 20 63 6f 6e 74 65 78 74 20 61 6e 64 20 74  d` context and t
12690 68 75 73 20 62 65 20 6f 70 74 69 6d 69 7a 65 64  hus be optimized
126a0 20 6f 75 74 2c 20 62 75 74 20 4b 26 52 20 43 20   out, but K&R C 
126b0 68 61 73 20 6e 6f 20 73 75 63 68 0a 20 20 20 20  has no such.    
126c0 6e 6f 74 69 6f 6e 2c 20 73 6f 20 69 74 20 68 61  notion, so it ha
126d0 73 20 74 68 69 73 20 6e 6f 6e 73 74 61 6e 64 61  s this nonstanda
126e0 72 64 20 6d 65 61 6e 69 6e 67 20 69 6e 20 43 43  rd meaning in CC
126f0 38 2e 20 20 54 68 69 73 20 74 65 63 68 6e 69 71  8.  This techniq
12700 75 65 0a 20 20 20 20 69 73 20 75 73 65 64 20 71  ue.    is used q
12710 75 69 74 65 20 61 20 6c 6f 74 20 69 6e 20 6f 75  uite a lot in ou
12720 72 20 5b 4c 49 42 43 5d 28 23 6c 69 62 63 29 2c  r [LIBC](#libc),
12730 20 73 6f 20 79 6f 75 20 63 61 6e 20 62 65 20 73   so you can be s
12740 75 72 65 20 74 68 65 0a 20 20 20 20 62 65 68 61  ure the.    beha
12750 76 69 6f 72 20 77 6f 6e e2 80 99 74 20 62 65 20  vior won’t be 
12760 67 6f 69 6e 67 20 61 77 61 79 2e 0a 0a 2a 20 20  going away...*  
12770 20 49 6e 20 74 68 65 20 60 70 75 74 73 60 20 65   In the `puts` e
12780 78 61 6d 70 6c 65 2c 20 74 68 65 20 73 74 61 74  xample, the stat
12790 65 6d 65 6e 74 20 60 2a 70 2b 2b 60 20 69 6d 70  ement `*p++` imp
127a0 6c 69 63 69 74 6c 79 20 73 74 6f 72 65 73 20 74  licitly stores t
127b0 68 65 0a 20 20 20 20 76 61 6c 75 65 20 61 74 20  he.    value at 
127c0 74 68 65 20 63 6f 72 65 20 6d 65 6d 6f 72 79 20  the core memory 
127d0 6c 6f 63 61 74 69 6f 6e 20 72 65 66 65 72 72 65  location referre
127e0 64 20 74 6f 20 62 79 20 60 70 60 20 69 6e 20 41  d to by `p` in A
127f0 43 2c 20 73 6f 20 77 65 0a 20 20 20 20 63 61 6e  C, so we.    can
12800 20 75 73 65 20 69 74 20 77 69 74 68 69 6e 20 74   use it within t
12810 68 65 20 61 73 73 65 6d 62 6c 79 20 62 6f 64 79  he assembly body
12820 20 6f 66 20 74 68 61 74 20 6c 6f 6f 70 20 77 69   of that loop wi
12830 74 68 6f 75 74 20 65 76 65 72 0a 20 20 20 20 65  thout ever.    e
12840 78 70 6c 69 63 69 74 6c 79 20 72 65 66 65 72 72  xplicitly referr
12850 69 6e 67 20 74 6f 20 60 70 60 2e 0a 0a 2a 20 20  ing to `p`...*  
12860 20 4b 6e 6f 77 69 6e 67 20 74 68 61 74 20 66 75   Knowing that fu
12870 6e 63 74 69 6f 6e 73 20 72 65 74 75 72 6e 20 74  nctions return t
12880 68 65 69 72 20 76 61 6c 75 65 20 69 6e 20 41 43  heir value in AC
12890 2c 20 79 6f 75 20 63 61 6e 20 63 61 6c 6c 0a 20  , you can call. 
128a0 20 20 20 61 6e 6f 74 68 65 72 20 43 20 66 75 6e     another C fun
128b0 63 74 69 6f 6e 20 66 72 6f 6d 20 74 68 65 20 6d  ction from the m
128c0 69 64 64 6c 65 20 6f 66 20 61 20 62 6c 6f 63 6b  iddle of a block
128d0 20 6f 66 20 61 73 73 65 6d 62 6c 79 20 63 6f 64   of assembly cod
128e0 65 20 62 75 74 0a 20 20 20 20 6e 65 76 65 72 20  e but.    never 
128f0 73 74 6f 72 65 20 69 74 73 20 72 65 74 75 72 6e  store its return
12900 20 76 61 6c 75 65 20 65 78 70 6c 69 63 69 74 6c   value explicitl
12910 79 3a 20 6a 75 73 74 20 75 73 65 20 69 74 73 20  y: just use its 
12920 72 65 74 75 72 6e 20 76 61 6c 75 65 0a 20 20 20  return value.   
12930 20 64 69 72 65 63 74 6c 79 20 66 72 6f 6d 20 41   directly from A
12940 43 20 74 6f 20 73 61 76 65 20 73 70 61 63 65 20  C to save space 
12950 6f 6e 20 74 68 65 20 73 74 61 63 6b 2e 0a 0a 42  on the stack...B
12960 65 77 61 72 65 20 74 68 61 74 20 43 43 38 20 69  eware that CC8 i
12970 73 6e e2 80 99 74 20 61 20 70 61 72 74 69 63 75  sn’t a particu
12980 6c 61 72 6c 79 20 73 6d 61 72 74 20 63 6f 6d 70  larly smart comp
12990 69 6c 65 72 2e 20 49 74 20 70 65 72 66 6f 72 6d  iler. It perform
129a0 73 20 66 65 77 20 6f 66 0a 74 68 65 20 61 75 74  s few of.the aut
129b0 6f 6d 61 74 69 63 20 74 72 69 63 6b 73 20 79 6f  omatic tricks yo
129c0 75 e2 80 99 64 20 65 78 70 65 63 74 20 66 72 6f  u’d expect fro
129d0 6d 20 61 20 6d 6f 64 65 72 6e 20 43 20 63 6f 6d  m a modern C com
129e0 70 69 6c 65 72 2c 20 6e 6f 74 20 65 76 65 6e 0a  piler, not even.
129f0 68 61 6e 64 6c 69 6e 67 20 73 69 6d 70 6c 65 20  handling simple 
12a00 74 68 69 6e 67 73 20 6c 69 6b 65 20 63 6f 6e 73  things like cons
12a10 74 61 6e 74 20 65 78 70 72 65 73 73 69 6f 6e 20  tant expression 
12a20 72 65 64 75 63 74 69 6f 6e 3a 0a 0a 20 20 20 20  reduction:..    
12a30 63 68 61 72 20 63 20 3d 20 27 61 27 20 2d 20 31  char c = 'a' - 1
12a40 30 3b 20 20 20 20 20 20 2f 2a 20 73 61 76 65 20  0;      /* save 
12a50 41 53 43 49 49 20 63 68 61 72 61 63 74 65 72 20  ASCII character 
12a60 31 30 20 62 61 63 6b 20 66 72 6f 6d 20 e2 80 9c  10 back from “
12a70 61 e2 80 9d 20 2a 2f 0a 20 20 20 20 63 68 61 72  a” */.    char
12a80 20 63 20 3d 20 38 37 3b 20 20 20 20 20 20 20 20   c = 87;        
12a90 20 20 20 20 2f 2a 20 73 61 6d 65 20 65 66 66 65      /* same effe
12aa0 63 74 2c 20 62 75 74 20 67 69 76 65 73 20 73 68  ct, but gives sh
12ab0 6f 72 74 65 72 20 6f 75 74 70 75 74 21 20 2a 2f  orter output! */
12ac0 0a 0a 54 68 61 74 20 65 78 61 6d 70 6c 65 20 69  ..That example i
12ad0 73 20 62 61 73 65 64 20 6f 6e 20 72 65 61 6c 20  s based on real 
12ae0 63 6f 64 65 2c 20 74 68 65 20 69 6d 70 6c 65 6d  code, the implem
12af0 65 6e 74 61 74 69 6f 6e 20 6f 66 0a 5b 60 69 74  entation of.[`it
12b00 6f 61 28 29 60 5d 28 23 69 74 6f 61 29 20 66 6f  oa()`](#itoa) fo
12b10 72 20 72 61 64 69 63 65 73 20 62 65 79 6f 6e 64  r radices beyond
12b20 20 31 30 3a 20 77 65 20 74 72 69 65 64 20 69 74   10: we tried it
12b30 20 62 6f 74 68 20 77 61 79 73 20 61 6e 64 20 65   both ways and e
12b40 6e 64 65 64 0a 75 70 20 64 6f 69 6e 67 20 69 74  nded.up doing it
12b50 20 74 68 65 20 6f 62 73 63 75 72 65 20 77 61 79   the obscure way
12b60 20 74 6f 20 73 61 76 65 20 63 6f 64 65 20 73 70   to save code sp
12b70 61 63 65 20 69 6e 20 4c 49 42 43 2e 0a 0a 46 6f  ace in LIBC...Fo
12b80 72 20 74 68 65 20 6d 6f 73 74 20 70 61 72 74 2c  r the most part,
12b90 20 43 43 38 20 63 75 72 72 65 6e 74 6c 79 20 6c   CC8 currently l
12ba0 65 61 76 65 73 20 74 68 65 20 74 61 73 6b 20 6f  eaves the task o
12bb0 66 20 6f 70 74 69 6d 69 7a 61 74 69 6f 6e 20 74  f optimization t
12bc0 6f 20 74 68 65 0a 65 6e 64 20 75 73 65 72 2e 0a  o the.end user..
12bd0 0a 0a 23 23 23 20 3c 61 20 69 64 3d 22 61 73 6d  ..### <a id="asm
12be0 6f 63 74 22 3e 3c 2f 61 3e 49 6e 6c 69 6e 65 20  oct"></a>Inline 
12bf0 41 73 73 65 6d 62 6c 79 20 69 73 20 69 6e 20 4f  Assembly is in O
12c00 63 74 61 6c 0a 0a 4c 69 6b 65 20 74 68 65 20 4f  ctal..Like the O
12c10 53 2f 38 20 46 4f 52 54 52 41 4e 20 49 49 20 63  S/8 FORTRAN II c
12c20 6f 6d 70 69 6c 65 72 2c 20 74 68 65 20 43 43 38  ompiler, the CC8
12c30 20 63 6f 6d 70 69 6c 65 72 73 20 6c 65 61 76 65   compilers leave
12c40 20 53 41 42 52 20 69 6e 20 69 74 73 0a 64 65 66   SABR in its.def
12c50 61 75 6c 74 20 6f 63 74 61 6c 20 6d 6f 64 65 2e  ault octal mode.
12c60 20 41 6c 6c 20 69 6e 74 65 67 65 72 20 63 6f 6e   All integer con
12c70 73 74 61 6e 74 73 20 65 6d 69 74 65 64 20 62 79  stants emited by
12c80 20 62 6f 74 68 20 63 6f 6d 70 69 6c 65 72 73 20   both compilers 
12c90 61 72 65 0a 69 6e 20 6f 63 74 61 6c 2e 20 20 28  are.in octal.  (
12ca0 45 76 65 6e 20 74 68 6f 73 65 20 69 6e 20 67 65  Even those in ge
12cb0 6e 65 72 61 74 65 64 20 6c 61 62 65 6c 73 20 61  nerated labels a
12cc0 6e 64 20 69 6e 20 65 72 72 6f 72 20 6f 75 74 70  nd in error outp
12cd0 75 74 0a 6d 65 73 73 61 67 65 73 21 29 20 54 68  ut.messages!) Th
12ce0 69 73 20 6d 65 61 6e 73 20 69 6e 74 65 67 65 72  is means integer
12cf0 20 63 6f 6e 73 74 61 6e 74 73 20 69 6e 20 79 6f   constants in yo
12d00 75 72 20 69 6e 6c 69 6e 65 20 61 73 73 65 6d 62  ur inline assemb
12d10 6c 79 20 61 6c 73 6f 20 67 65 74 0a 69 6e 74 65  ly also get.inte
12d20 72 70 72 65 74 65 64 20 61 73 20 6f 63 74 61 6c  rpreted as octal
12d30 2c 20 62 79 20 64 65 66 61 75 6c 74 2e 0a 0a 49  , by default...I
12d40 66 20 79 6f 75 20 75 73 65 20 74 68 65 20 60 44  f you use the `D
12d50 45 43 49 4d 60 20 53 41 42 52 20 70 73 65 75 64  ECIM` SABR pseud
12d60 6f 2d 6f 70 20 74 6f 20 67 65 74 20 61 72 6f 75  o-op to get arou
12d70 6e 64 20 74 68 69 73 2c 20 79 6f 75 20 6d 75 73  nd this, you mus
12d80 74 20 62 65 0a 63 61 72 65 66 75 6c 20 74 6f 20  t be.careful to 
12d90 61 64 64 20 61 6e 20 60 4f 43 54 41 4c 60 20 6f  add an `OCTAL` o
12da0 70 20 62 65 66 6f 72 65 20 74 68 65 20 62 6c 6f  p before the blo
12db0 63 6b 20 65 6e 64 73 20 74 6f 20 73 68 69 66 74  ck ends to shift
12dc0 20 74 68 65 20 6d 6f 64 65 0a 62 61 63 6b 2e 20   the mode.back. 
12dd0 54 68 65 20 63 6f 6d 70 69 6c 65 72 20 64 6f 65  The compiler doe
12de0 73 6e e2 80 99 74 20 64 65 74 65 63 74 20 75 73  sn’t detect us
12df0 65 20 6f 66 20 60 44 45 43 49 4d 60 2c 20 61 6e  e of `DECIM`, an
12e00 64 20 69 74 20 64 6f 65 73 6e e2 80 99 74 20 62  d it doesn’t b
12e10 6c 69 6e 64 6c 79 0a 69 6e 6a 65 63 74 20 60 4f  lindly.inject `O
12e20 43 54 41 4c 60 20 6f 70 73 20 61 66 74 65 72 20  CTAL` ops after 
12e30 65 76 65 72 79 20 69 6e 6c 69 6e 65 20 61 73 73  every inline ass
12e40 65 6d 62 6c 79 20 62 6c 6f 63 6b 20 74 6f 20 66  embly block to f
12e50 6f 72 63 65 20 74 68 65 20 6d 6f 64 65 0a 62 61  orce the mode.ba
12e60 63 6b 20 6f 6e 20 74 68 65 20 6f 66 66 20 63 68  ck on the off ch
12e70 61 6e 63 65 20 74 68 61 74 20 74 68 65 20 75 73  ance that the us
12e80 65 72 20 68 61 64 20 73 68 69 66 74 65 64 20 74  er had shifted t
12e90 68 65 20 61 73 73 65 6d 62 6c 65 72 20 69 6e 74  he assembler int
12ea0 6f 0a 64 65 63 69 6d 61 6c 20 6d 6f 64 65 2e 20  o.decimal mode. 
12eb0 49 66 20 79 6f 75 20 6c 65 61 76 65 20 74 68 65  If you leave the
12ec0 20 61 73 73 65 6d 62 6c 65 72 20 69 6e 20 60 44   assembler in `D
12ed0 45 43 49 4d 60 20 6d 6f 64 65 20 61 74 20 74 68  ECIM` mode at th
12ee0 65 20 65 6e 64 20 6f 66 0a 61 6e 20 69 6e 6c 69  e end of.an inli
12ef0 6e 65 20 61 73 73 65 6d 62 6c 79 20 62 6c 6f 63  ne assembly bloc
12f00 6b 2c 20 74 68 65 20 72 65 73 75 6c 74 69 6e 67  k, the resulting
12f10 20 53 41 42 52 20 6f 75 74 70 75 74 20 77 69 6c   SABR output wil
12f20 6c 20 70 72 6f 62 61 62 6c 79 0a 61 73 73 65 6d  l probably.assem
12f30 62 6c 65 20 62 75 74 20 77 6f 6e e2 80 99 74 20  ble but won’t 
12f40 72 75 6e 20 63 6f 72 72 65 63 74 6c 79 20 62 65  run correctly be
12f50 63 61 75 73 65 20 61 6c 6c 20 69 6e 74 65 67 65  cause all intege
12f60 72 20 63 6f 6e 73 74 61 6e 74 73 20 66 72 6f 6d  r constants from
12f70 20 74 68 61 74 0a 70 6f 69 6e 74 20 6f 6e 20 77   that.point on w
12f80 69 6c 6c 20 62 65 20 6d 69 73 69 6e 74 65 72 70  ill be misinterp
12f90 72 65 74 65 64 2e 0a 0a 49 74 e2 80 99 73 20 73  reted...It’s s
12fa0 61 66 65 72 2c 20 69 66 20 79 6f 75 20 77 61 6e  afer, if you wan
12fb0 20 61 20 67 69 76 65 6e 20 63 6f 6e 73 74 61 6e   a given constan
12fc0 74 20 74 6f 20 62 65 20 69 6e 74 65 72 70 72 65  t to be interpre
12fd0 74 65 64 20 61 73 20 64 65 63 69 6d 61 6c 2c 20  ted as decimal, 
12fe0 74 6f 0a 70 72 65 66 69 78 20 69 74 20 77 69 74  to.prefix it wit
12ff0 68 20 61 20 60 44 60 2e 20 53 65 65 20 74 68 65  h a `D`. See the
13000 20 53 41 42 52 20 6d 61 6e 75 61 6c 20 66 6f 72   SABR manual for
13010 20 6d 6f 72 65 20 64 65 74 61 69 6c 73 20 6f 6e   more details on
13020 20 74 68 69 73 2e 0a 0a 0a 23 23 23 20 3c 61 20   this....### <a 
13030 69 64 3d 22 6c 69 6e 6b 61 67 65 22 20 6e 61 6d  id="linkage" nam
13040 65 3d 22 76 61 72 61 72 67 73 22 3e 3c 2f 61 3e  e="varargs"></a>
13050 4c 69 62 72 61 72 79 20 4c 69 6e 6b 61 67 65 20  Library Linkage 
13060 61 6e 64 20 56 61 72 61 72 67 73 0a 0a 43 43 38  and Varargs..CC8
13070 20 68 61 73 20 73 6f 6d 65 20 6e 6f 6e 2d 73 74   has some non-st
13080 61 6e 64 61 72 64 20 66 65 61 74 75 72 65 73 20  andard features 
13090 74 6f 20 65 6e 61 62 6c 65 20 74 68 65 20 69 6e  to enable the in
130a0 74 65 72 66 61 63 65 20 62 65 74 77 65 65 6e 20  terface between 
130b0 74 68 65 0a 6d 61 69 6e 20 70 72 6f 67 72 61 6d  the.main program
130c0 20 61 6e 64 20 74 68 65 20 43 20 6c 69 62 72 61   and the C libra
130d0 72 79 2e 20 54 68 69 73 20 63 6f 6e 73 74 69 74  ry. This constit
130e0 75 74 65 73 20 61 20 63 6f 6d 70 69 6c 65 20 74  utes a compile t
130f0 69 6d 65 20 6c 69 6e 6b 61 67 65 0a 73 79 73 74  ime linkage.syst
13100 65 6d 20 74 6f 20 61 6c 6c 6f 77 20 66 6f 72 20  em to allow for 
13110 73 74 61 6e 64 61 72 64 20 61 6e 64 20 76 61 72  standard and var
13120 61 72 67 20 66 75 6e 63 74 69 6f 6e 73 20 74 6f  arg functions to
13130 20 62 65 20 63 61 6c 6c 65 64 20 69 6e 20 74 68   be called in th
13140 65 0a 6c 69 62 72 61 72 79 2e 0a 0a 2a 2a 54 4f  e.library...**TO
13150 44 4f 3a 2a 2a 20 45 78 70 6c 61 69 6e 20 74 68  DO:** Explain th
13160 69 73 2e 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d  is....### <a id=
13170 22 6f 73 38 61 73 6d 22 3e 3c 2f 61 3e 49 6e 6c  "os8asm"></a>Inl
13180 69 6e 65 20 41 73 73 65 6d 62 6c 79 20 4c 69 6d  ine Assembly Lim
13190 69 74 61 74 69 6f 6e 73 20 69 6e 20 74 68 65 20  itations in the 
131a0 4e 61 74 69 76 65 20 43 43 38 20 43 6f 6d 70 69  Native CC8 Compi
131b0 6c 65 72 0a 0a 54 68 65 20 6e 61 74 69 76 65 20  ler..The native 
131c0 63 6f 6d 70 69 6c 65 72 20 68 61 73 20 73 6f 6d  compiler has som
131d0 65 20 73 69 67 6e 69 66 69 63 61 6e 74 20 6c 69  e significant li
131e0 6d 69 74 61 74 69 6f 6e 73 20 69 6e 20 74 68 65  mitations in the
131f0 20 77 61 79 20 69 74 0a 68 61 6e 64 6c 65 73 20   way it.handles 
13200 69 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c 79 2e  inline assembly.
13210 0a 0a 54 68 65 20 70 72 69 6d 61 72 79 20 6f 6e  ..The primary on
13220 65 20 69 73 20 74 68 61 74 20 73 6e 69 70 70 65  e is that snippe
13230 74 73 20 6f 66 20 69 6e 6c 69 6e 65 20 61 73 73  ts of inline ass
13240 65 6d 62 6c 79 20 61 72 65 20 67 61 74 68 65 72  embly are gather
13250 65 64 20 62 79 20 74 68 65 0a 5b 66 69 72 73 74  ed by the.[first
13260 20 70 61 73 73 5d 28 23 6e 63 70 61 73 73 29 20   pass](#ncpass) 
13270 6f 66 20 74 68 65 20 63 6f 6d 70 69 6c 65 72 20  of the compiler 
13280 69 6e 20 61 20 63 6f 72 65 20 6d 65 6d 6f 72 79  in a core memory
13290 20 62 75 66 66 65 72 20 74 68 61 74 e2 80 99 73   buffer that’s
132a0 0a 6f 6e 6c 79 20 31 30 32 34 20 63 68 61 72 61  .only 1024 chara
132b0 63 74 65 72 73 20 69 6e 20 73 69 7a 65 2e 20 49  cters in size. I
132c0 66 20 74 68 65 20 74 6f 74 61 6c 20 61 6d 6f 75  f the total amou
132d0 6e 74 20 6f 66 20 69 6e 6c 69 6e 65 20 61 73 73  nt of inline ass
132e0 65 6d 62 6c 79 20 69 6e 0a 79 6f 75 72 20 70 72  embly in.your pr
132f0 6f 67 72 61 6d 20 65 78 63 65 65 64 73 20 74 68  ogram exceeds th
13300 69 73 20 61 6d 6f 75 6e 74 2c 20 60 43 43 2e 53  is amount, `CC.S
13310 56 60 20 77 69 6c 6c 20 6f 76 65 72 72 75 6e 20  V` will overrun 
13320 74 68 69 73 20 62 75 66 66 65 72 20 61 6e 64 0a  this buffer and.
13330 70 72 6f 64 75 63 65 20 63 6f 72 72 75 70 74 20  produce corrupt 
13340 6f 75 74 70 75 74 2e 0a 0a 49 74 e2 80 99 73 20  output...It’s 
13350 64 69 66 66 69 63 75 6c 74 20 74 6f 20 6a 75 73  difficult to jus
13360 74 69 66 79 20 69 6e 63 72 65 61 73 69 6e 67 20  tify increasing 
13370 74 68 65 20 73 69 7a 65 20 6f 66 20 74 68 61 74  the size of that
13380 20 62 75 66 66 65 72 2c 20 62 65 63 61 75 73 65   buffer, because
13390 0a 69 74 e2 80 99 73 20 61 6c 72 65 61 64 79 20  .it’s already 
133a0 6f 76 65 72 20 5b 26 66 72 61 63 31 34 3b 20 74  over [&frac14; t
133b0 68 65 20 73 70 61 63 65 20 67 69 76 65 6e 5d 28  he space given](
133c0 23 75 64 66 29 20 69 6e 20 43 43 38 20 74 6f 20  #udf) in CC8 to 
133d0 67 6c 6f 62 61 6c 0a 76 61 72 69 61 62 6c 65 73  global.variables
133e0 2e 0a 0a 49 74 20 61 6c 6c 20 68 61 73 20 74 6f  ...It all has to
133f0 20 62 65 20 67 61 74 68 65 72 65 64 20 69 6e 20   be gathered in 
13400 6f 6e 65 20 70 61 73 73 2c 20 62 65 63 61 75 73  one pass, becaus
13410 65 20 74 68 69 73 20 31 26 6e 62 73 70 3b 6b 57  e this 1&nbsp;kW
13420 6f 72 64 20 62 75 66 66 65 72 0a 69 73 20 77 72  ord buffer.is wr
13430 69 74 74 65 6e 20 74 6f 20 61 20 74 65 78 74 20  itten to a text 
13440 66 69 6c 65 20 28 60 43 41 53 4d 2e 54 58 60 29  file (`CASM.TX`)
13450 20 61 74 20 74 68 65 20 65 6e 64 20 6f 66 20 74   at the end of t
13460 68 65 20 5b 66 69 72 73 74 20 63 6f 6d 70 69 6c  he [first compil
13470 65 72 0a 70 61 73 73 5d 28 23 6e 63 70 61 73 73  er.pass](#ncpass
13480 29 2c 20 77 68 65 72 65 20 69 74 20 77 61 69 74  ), where it wait
13490 73 20 66 6f 72 20 74 68 65 20 66 69 6e 61 6c 20  s for the final 
134a0 63 6f 6d 70 69 6c 65 72 20 70 61 73 73 20 74 6f  compiler pass to
134b0 20 72 65 61 64 20 69 74 0a 62 61 63 6b 20 69 6e   read it.back in
134c0 20 74 6f 20 62 65 20 69 6e 73 65 72 74 65 64 20   to be inserted 
134d0 69 6e 74 6f 20 74 68 65 20 6f 75 74 70 75 74 20  into the output 
134e0 53 41 42 52 20 63 6f 64 65 2e 20 20 53 69 6e 63  SABR code.  Sinc
134f0 65 20 4c 49 42 43 e2 80 99 73 0a 5b 60 66 6f 70  e LIBC’s.[`fop
13500 65 6e 28 29 60 5d 28 23 66 6f 70 65 6e 29 20 69  en()`](#fopen) i
13510 73 20 6c 69 6d 69 74 65 64 20 74 6f 20 61 20 5b  s limited to a [
13520 73 69 6e 67 6c 65 20 6f 75 74 70 75 74 20 66 69  single output fi
13530 6c 65 20 61 74 20 61 0a 74 69 6d 65 5d 28 23 66  le at a.time](#f
13540 69 6f 6c 69 6d 29 20 61 6e 64 20 69 74 20 63 61  iolim) and it ca
13550 6e 6e 6f 74 20 61 70 70 65 6e 64 20 74 6f 20 61  nnot append to a
13560 6e 20 65 78 69 73 74 69 6e 67 20 66 69 6c 65 2c  n existing file,
13570 20 69 74 e2 80 99 73 20 67 6f 74 20 6f 6e 65 0a   it’s got one.
13580 73 68 6f 74 20 74 6f 20 77 72 69 74 65 20 65 76  shot to write ev
13590 65 72 79 74 68 69 6e 67 20 69 74 20 63 6f 6c 6c  erything it coll
135a0 65 63 74 65 64 2e 0a 0a 54 68 69 73 20 69 73 20  ected...This is 
135b0 6f 6e 65 20 72 65 61 73 6f 6e 20 74 68 65 20 43  one reason the C
135c0 43 38 20 4c 49 42 43 20 68 61 73 20 74 6f 20 62  C8 LIBC has to b
135d0 65 20 63 72 6f 73 73 2d 63 6f 6d 70 69 6c 65 64  e cross-compiled
135e0 3a 20 69 74 73 20 69 6e 6c 69 6e 65 0a 61 73 73  : its inline.ass
135f0 65 6d 62 6c 79 20 69 73 20 6f 76 65 72 20 36 26  embly is over 6&
13600 74 69 6d 65 73 3b 20 74 68 65 20 73 69 7a 65 20  times; the size 
13610 6f 66 20 74 68 69 73 20 62 75 66 66 65 72 2e 0a  of this buffer..
13620 0a 41 6e 6f 74 68 65 72 20 70 72 6f 62 6c 65 6d  .Another problem
13630 20 74 6f 20 77 61 74 63 68 20 6f 75 74 20 66 6f   to watch out fo
13640 72 20 69 73 20 74 68 61 74 20 74 68 69 73 20 69  r is that this i
13650 6e 6c 69 6e 65 20 61 73 73 65 6d 62 6c 79 20 62  nline assembly b
13660 75 66 66 65 72 20 69 73 0a 62 72 6f 6b 65 6e 20  uffer is.broken 
13670 69 6e 74 6f 20 73 65 63 74 69 6f 6e 73 20 77 69  into sections wi
13680 74 68 20 60 21 60 20 61 6e 64 20 60 24 60 20 63  th `!` and `$` c
13690 68 61 72 61 63 74 65 72 73 20 73 6f 20 74 68 61  haracters so tha
136a0 74 20 74 68 65 20 66 69 6e 61 6c 20 70 61 73 73  t the final pass
136b0 0a 6f 66 20 74 68 65 20 63 6f 6d 70 69 6c 65 72  .of the compiler
136c0 20 63 61 6e 20 62 72 65 61 6b 20 74 68 65 20 60   can break the `
136d0 43 41 53 4d 2e 54 58 60 20 66 69 6c 65 20 75 70  CASM.TX` file up
136e0 20 69 6e 74 6f 20 73 65 63 74 69 6f 6e 73 20 66   into sections f
136f0 6f 72 0a 69 6e 73 65 72 74 69 6f 6e 20 69 6e 74  or.insertion int
13700 6f 20 74 68 65 20 53 41 42 52 20 6f 75 74 70 75  o the SABR outpu
13710 74 2e 20 49 74 20 69 73 20 74 68 65 72 65 66 6f  t. It is therefo
13720 72 65 20 75 6e 73 61 66 65 20 74 6f 20 75 73 65  re unsafe to use
13730 20 74 68 65 73 65 0a 63 68 61 72 61 63 74 65 72   these.character
13740 73 20 69 6e 20 79 6f 75 72 20 69 6e 6c 69 6e 65  s in your inline
13750 20 61 73 73 65 6d 62 6c 79 2c 20 6c 65 73 74 20   assembly, lest 
13760 74 68 65 79 20 62 65 20 73 65 65 6e 20 61 73 20  they be seen as 
13770 73 65 70 61 72 61 74 6f 72 73 2c 0a 63 61 75 73  separators,.caus
13780 69 6e 67 20 69 6e 63 6f 72 72 65 63 74 20 6f 75  ing incorrect ou
13790 74 70 75 74 2e 20 20 54 68 69 73 20 69 73 20 65  tput.  This is e
137a0 73 70 65 63 69 61 6c 6c 79 20 65 61 73 79 20 74  specially easy t
137b0 6f 20 64 6f 20 69 6e 20 63 6f 6d 6d 65 6e 74 73  o do in comments
137c0 3b 0a 77 61 74 63 68 20 6f 75 74 21 20 28 53 65  ;.watch out! (Se
137d0 65 20 68 6f 77 20 65 61 73 79 20 69 74 20 69 73  e how easy it is
137e0 20 74 6f 20 75 73 65 20 61 6e 20 65 78 63 6c 61   to use an excla
137f0 6d 61 74 69 6f 6e 20 70 6f 69 6e 74 20 77 68 65  mation point whe
13800 6e 20 6d 61 6b 69 6e 67 0a 63 6f 6d 6d 65 6e 74  n making.comment
13810 73 3f 29 0a 0a 0a 23 23 23 20 3c 61 20 69 64 3d  s?)...### <a id=
13820 22 6f 70 64 65 66 22 3e 3c 2f 61 3e 50 72 65 64  "opdef"></a>Pred
13830 65 66 69 6e 65 64 20 4f 50 44 45 46 73 0a 0a 49  efined OPDEFs..I
13840 6e 20 61 64 64 69 74 69 6f 6e 20 74 6f 20 74 68  n addition to th
13850 65 20 6f 70 2d 63 6f 64 65 73 20 70 72 65 64 65  e op-codes prede
13860 66 69 6e 65 64 20 66 6f 72 20 53 41 42 52 20 e2  fined for SABR 
13870 80 94 20 77 68 69 63 68 20 79 6f 75 20 63 61 6e   which you can
13880 20 66 69 6e 64 20 69 6e 0a 5b 41 70 70 65 6e 64   find in.[Append
13890 69 78 20 43 20 6f 66 20 74 68 65 20 4f 53 2f 38  ix C of the OS/8
138a0 20 48 61 6e 64 62 6f 6f 6b 2c 20 31 39 37 34 20   Handbook, 1974 
138b0 65 64 69 74 69 6f 6e 5d 5b 6f 73 38 68 61 63 5d  edition][os8hac]
138c0 20 e2 80 94 20 74 68 65 20 66 6f 6c 6c 6f 77 69   — the followi
138d0 6e 67 0a 60 4f 50 44 45 46 60 20 64 69 72 65 63  ng.`OPDEF` direc
138e0 74 69 76 65 73 20 61 72 65 20 69 6e 73 65 72 74  tives are insert
138f0 65 64 20 61 74 20 74 68 65 20 74 6f 70 20 6f 66  ed at the top of
13900 20 65 76 65 72 79 20 53 41 42 52 20 66 69 6c 65   every SABR file
13910 20 6f 75 74 70 75 74 0a 66 72 6f 6d 20 43 43 38   output.from CC8
13920 2c 20 61 6c 6c 6f 77 69 6e 67 20 79 6f 75 72 20  , allowing your 
13930 53 41 42 52 20 63 6f 64 65 20 74 6f 20 75 73 65  SABR code to use
13940 20 74 68 65 73 65 20 61 73 20 77 65 6c 6c 3a 0a   these as well:.
13950 0a 7c 6f 70 2d 63 6f 64 65 7c 76 61 6c 75 65 7c  .|op-code|value|
13960 6d 65 61 6e 69 6e 67 7c 0a 7c 2d 2d 2d 2d 2d 2d  meaning|.|------
13970 2d 7c 2d 2d 2d 2d 2d 7c 2d 2d 2d 2d 2d 2d 2d 7c  -|-----|-------|
13980 0a 7c 60 41 4e 44 49 60 20 7c 30 34 30 30 20 7c  .|`ANDI` |0400 |
13990 73 61 6d 65 20 61 73 20 60 41 4e 44 20 49 60 20  same as `AND I` 
139a0 69 6e 20 50 41 4c 38 7c 0a 7c 60 54 41 44 49 60  in PAL8|.|`TADI`
139b0 20 7c 31 34 30 30 20 7c 73 61 6d 65 20 61 73 20   |1400 |same as 
139c0 60 54 41 44 20 49 60 20 69 6e 20 50 41 4c 38 7c  `TAD I` in PAL8|
139d0 0a 7c 60 49 53 5a 49 60 20 7c 32 34 30 30 20 7c  .|`ISZI` |2400 |
139e0 73 61 6d 65 20 61 73 20 60 49 53 5a 20 49 60 20  same as `ISZ I` 
139f0 69 6e 20 50 41 4c 38 7c 0a 7c 60 44 43 41 49 60  in PAL8|.|`DCAI`
13a00 20 7c 33 34 30 30 20 7c 73 61 6d 65 20 61 73 20   |3400 |same as 
13a10 60 44 43 41 20 49 60 20 69 6e 20 50 41 4c 38 7c  `DCA I` in PAL8|
13a20 0a 7c 60 4a 4d 53 49 60 20 7c 34 34 30 30 20 7c  .|`JMSI` |4400 |
13a30 73 61 6d 65 20 61 73 20 60 4a 4d 53 20 49 60 20  same as `JMS I` 
13a40 69 6e 20 50 41 4c 38 7c 0a 7c 60 4a 4d 50 49 60  in PAL8|.|`JMPI`
13a50 20 7c 35 34 30 30 20 7c 73 61 6d 65 20 61 73 20   |5400 |same as 
13a60 60 4a 4d 50 20 49 60 20 69 6e 20 50 41 4c 38 7c  `JMP I` in PAL8|
13a70 0a 7c 60 4d 51 4c 60 20 20 7c 37 34 32 31 20 7c  .|`MQL`  |7421 |
13a80 6c 6f 61 64 20 4d 51 20 66 72 6f 6d 20 41 43 2c  load MQ from AC,
13a90 20 63 6c 65 61 72 20 41 43 7c 0a 7c 60 41 43 4c   clear AC|.|`ACL
13aa0 60 20 20 7c 37 37 30 31 20 7c 6c 6f 61 64 20 41  `  |7701 |load A
13ab0 43 20 66 72 6f 6d 20 4d 51 20 28 75 73 65 20 60  C from MQ (use `
13ac0 43 4c 41 20 53 57 50 60 20 74 6f 20 67 69 76 65  CLA SWP` to give
13ad0 20 69 6e 76 65 72 73 65 20 6f 66 20 60 4d 51 4c   inverse of `MQL
13ae0 60 29 7c 0a 7c 60 4d 51 41 60 20 20 7c 37 35 30  `)|.|`MQA`  |750
13af0 31 20 7c 4f 52 20 4d 51 20 77 69 74 68 20 41 43  1 |OR MQ with AC
13b00 2c 20 72 65 73 75 6c 74 20 69 6e 20 4d 51 7c 0a  , result in MQ|.
13b10 7c 60 53 57 50 60 20 20 7c 37 35 32 31 20 7c 73  |`SWP`  |7521 |s
13b20 77 61 70 20 41 43 20 61 6e 64 20 4d 51 7c 0a 7c  wap AC and MQ|.|
13b30 60 44 49 4c 58 60 20 7c 36 30 35 33 20 7c 73 65  `DILX` |6053 |se
13b40 74 20 56 43 38 45 20 58 20 63 6f 6f 72 64 69 6e  t VC8E X coordin
13b50 61 74 65 20 28 75 73 65 64 20 62 79 20 5b 60 64  ate (used by [`d
13b60 69 73 70 78 79 28 29 60 5d 28 23 64 69 73 70 78  ispxy()`](#dispx
13b70 79 29 29 7c 0a 7c 60 44 49 4c 59 60 20 7c 36 30  y))|.|`DILY` |60
13b80 35 34 20 7c 73 65 74 20 56 43 38 45 20 59 20 63  54 |set VC8E Y c
13b90 6f 6f 72 64 69 6e 61 74 65 7c 0a 7c 60 44 49 58  oordinate|.|`DIX
13ba0 59 60 20 7c 36 30 35 34 20 7c 70 75 6c 73 65 20  Y` |6054 |pulse 
13bb0 56 43 38 45 20 61 74 20 28 58 2c 59 29 20 73 65  VC8E at (X,Y) se
13bc0 74 20 62 79 20 60 44 49 58 59 60 2c 60 44 49 4c  t by `DIXY`,`DIL
13bd0 59 60 7c 0a 7c 60 43 44 46 30 60 20 7c 36 32 30  Y`|.|`CDF0` |620
13be0 31 20 7c 63 68 61 6e 67 65 20 44 46 20 74 6f 20  1 |change DF to 
13bf0 66 69 65 6c 64 20 30 7c 0a 7c 60 43 44 46 31 60  field 0|.|`CDF1`
13c00 20 7c 36 32 31 31 20 7c 63 68 61 6e 67 65 20 44   |6211 |change D
13c10 46 20 74 6f 20 66 69 65 6c 64 20 31 7c 0a 7c 60  F to field 1|.|`
13c20 43 41 46 30 60 20 7c 36 32 30 33 20 7c 63 68 61  CAF0` |6203 |cha
13c30 6e 67 65 20 62 6f 74 68 20 49 46 20 61 6e 64 20  nge both IF and 
13c40 44 46 20 74 6f 20 66 69 65 6c 64 20 30 7c 0a 7c  DF to field 0|.|
13c50 60 52 49 46 60 20 20 7c 36 32 32 34 20 7c 72 65  `RIF`  |6224 |re
13c60 61 64 20 69 6e 73 74 72 75 63 74 69 6f 6e 20 66  ad instruction f
13c70 69 65 6c 64 3a 20 4f 52 20 49 46 20 77 69 74 68  ield: OR IF with
13c80 20 62 69 74 73 20 36 2d 38 20 6f 66 20 41 43 7c   bits 6-8 of AC|
13c90 0a 7c 60 42 53 57 60 20 20 7c 37 30 30 32 20 7c  .|`BSW`  |7002 |
13ca0 65 78 63 68 61 6e 67 65 20 74 68 65 20 68 69 67  exchange the hig
13cb0 68 20 61 6e 64 20 6c 6f 77 20 36 20 62 69 74 73  h and low 6 bits
13cc0 20 6f 66 20 41 43 7c 0a 7c 60 43 41 4d 60 20 20   of AC|.|`CAM`  
13cd0 7c 37 36 32 31 20 7c 63 6c 65 61 72 20 41 43 20  |7621 |clear AC 
13ce0 61 6e 64 20 4d 51 7c 0a 0a 54 68 65 20 66 69 72  and MQ|..The fir
13cf0 73 74 20 73 69 78 20 6f 70 65 72 61 74 69 6f 6e  st six operation
13d00 73 20 72 65 71 75 69 72 65 20 73 6f 6d 65 20 65  s require some e
13d10 78 70 6c 61 6e 61 74 69 6f 6e 2e 20 53 41 42 52  xplanation. SABR
13d20 20 74 72 69 65 73 20 74 6f 20 70 72 65 73 65 6e   tries to presen
13d30 74 0a 61 20 66 6c 61 74 20 6d 65 6d 6f 72 79 20  t.a flat memory 
13d40 6d 6f 64 65 6c 20 74 6f 20 74 68 65 20 75 73 65  model to the use
13d50 72 2c 20 77 68 69 63 68 20 6d 65 61 6e 73 20 74  r, which means t
13d60 68 61 74 20 69 66 20 79 6f 75 20 77 72 69 74 65  hat if you write
13d70 20 73 6f 6d 65 74 68 69 6e 67 0a 6c 69 6b 65 20   something.like 
13d80 60 54 41 44 20 49 20 56 41 4c 60 20 69 74 20 64  `TAD I VAL` it d
13d90 6f 65 73 6e e2 80 99 74 20 65 6d 69 74 20 61 20  oesn’t emit a 
13da0 73 69 6e 67 6c 65 20 69 6e 73 74 72 75 63 74 69  single instructi
13db0 6f 6e 20 6c 69 6b 65 20 73 69 6d 70 6c 65 72 20  on like simpler 
13dc0 50 44 50 2d 38 0a 61 73 73 65 6d 62 6c 65 72 73  PDP-8.assemblers
13dd0 20 77 69 6c 6c 2e 20 54 68 65 73 65 20 50 41 4c   will. These PAL
13de0 38 20 65 6d 75 6c 61 74 69 6e 67 20 6f 70 2d 63  8 emulating op-c
13df0 6f 64 65 73 20 61 6c 6c 6f 77 20 74 68 65 20 70  odes allow the p
13e00 72 6f 67 72 61 6d 6d 65 72 20 74 6f 0a 62 79 70  rogrammer to.byp
13e10 61 73 73 20 74 68 69 73 20 62 65 68 61 76 69 6f  ass this behavio
13e20 72 20 6f 66 20 53 41 42 52 20 77 68 65 6e 20 69  r of SABR when i
13e30 74 20 69 73 6e e2 80 99 74 20 68 65 6c 70 66 75  t isn’t helpfu
13e40 6c 2e 20 53 65 65 20 74 68 65 0a 64 6f 63 75 6d  l. See the.docum
13e50 65 6e 74 61 74 69 6f 6e 20 6f 6e 20 53 41 42 52  entation on SABR
13e60 20 6c 69 6e 6b 20 67 65 6e 65 72 61 74 69 6f 6e   link generation
13e70 20 69 6e 20 74 68 65 20 4f 53 2f 38 20 48 61 6e   in the OS/8 Han
13e80 64 62 6f 6f 6b 2e 0a 0a 5b 6f 73 38 68 61 63 5d  dbook...[os8hac]
13e90 3a 20 68 74 74 70 73 3a 2f 2f 61 72 63 68 69 76  : https://archiv
13ea0 65 2e 6f 72 67 2f 64 65 74 61 69 6c 73 2f 62 69  e.org/details/bi
13eb0 74 73 61 76 65 72 73 5f 64 65 63 70 64 70 38 6f  tsavers_decpdp8o
13ec0 73 38 5f 33 39 34 31 34 37 39 32 2f 70 61 67 65  s8_39414792/page
13ed0 2f 6e 38 37 35 0a 0a 0a 23 23 20 43 6f 6e 63 6c  /n875...## Concl
13ee0 75 73 69 6f 6e 0a 0a 54 68 69 73 20 69 73 20 61  usion..This is a
13ef0 20 73 6f 6d 65 77 68 61 74 20 6c 69 6d 69 74 65   somewhat limite
13f00 64 20 6d 61 6e 75 61 6c 20 77 68 69 63 68 20 61  d manual which a
13f10 74 74 65 6d 70 74 73 20 74 6f 20 67 69 76 65 20  ttempts to give 
13f20 61 6e 20 6f 75 74 6c 69 6e 65 20 6f 66 20 61 0a  an outline of a.
13f30 76 65 72 79 20 73 69 6d 70 6c 65 20 63 6f 6d 70  very simple comp
13f40 69 6c 65 72 20 66 6f 72 20 77 68 69 63 68 20 77  iler for which w
13f50 65 20 61 70 6f 6c 6f 67 69 73 65 20 61 73 20 74  e apologise as t
13f60 68 65 20 73 6f 75 72 63 65 20 63 6f 64 65 20 69  he source code i
13f70 73 0a 6f 62 73 63 75 72 65 20 61 6e 64 20 62 61  s.obscure and ba
13f80 64 6c 79 20 63 6f 6d 6d 65 6e 74 65 64 2e 20 48  dly commented. H
13f90 6f 77 65 76 65 72 2c 20 74 68 65 20 6e 61 74 69  owever, the nati
13fa0 76 65 20 4f 53 2f 38 20 63 6f 6d 70 69 6c 65 72  ve OS/8 compiler
13fb0 2f 74 6f 6b 65 6e 69 73 65 72 0a 28 60 6e 38 2e  /tokeniser.(`n8.
13fc0 63 60 29 20 69 73 20 6f 6e 6c 79 20 36 30 30 20  c`) is only 600 
13fd0 6c 69 6e 65 73 20 77 68 69 63 68 20 69 73 20 61  lines which is a
13fe0 20 6e 6f 74 68 69 6e 67 20 69 6e 20 74 68 65 20   nothing in the 
13ff0 73 63 61 6c 65 20 6f 66 20 74 68 69 6e 67 73 0a  scale of things.
14000 74 68 65 73 65 20 64 61 79 73 2e 20 20 48 6f 77  these days.  How
14010 65 76 65 72 2c 20 77 65 20 68 6f 70 65 20 74 68  ever, we hope th
14020 69 73 20 70 72 6f 6a 65 63 74 20 67 69 76 65 73  is project gives
14030 20 73 6f 6d 65 20 69 6e 73 69 67 68 74 20 69 6e   some insight in
14040 74 6f 0a 63 6f 6d 70 69 6c 65 72 20 64 65 73 69  to.compiler desi
14050 67 6e 20 61 6e 64 20 63 6f 64 65 20 67 65 6e 65  gn and code gene
14060 72 61 74 69 6f 6e 20 73 74 72 61 74 65 67 69 65  ration strategie
14070 73 20 74 6f 20 74 61 72 67 65 74 20 61 20 6d 6f  s to target a mo
14080 73 74 0a 72 65 6d 61 72 6b 61 62 6c 65 20 63 6f  st.remarkable co
14090 6d 70 75 74 65 72 2e 20 57 65 20 77 6f 75 6c 64  mputer. We would
140a0 20 61 6c 73 6f 20 6c 69 6b 65 20 74 6f 20 67 69   also like to gi
140b0 76 65 20 63 72 65 64 69 74 20 74 6f 20 74 68 65  ve credit to the
140c0 20 62 75 69 6c 64 65 72 73 0a 6f 66 20 4f 53 2f   builders.of OS/
140d0 38 20 61 6e 64 20 69 6e 20 70 61 72 74 69 63 75  8 and in particu
140e0 6c 61 72 20 74 68 65 20 46 4f 52 54 52 41 4e 20  lar the FORTRAN 
140f0 49 49 20 73 79 73 74 65 6d 20 77 68 69 63 68 20  II system which 
14100 77 61 73 20 6e 65 76 65 72 20 64 65 73 69 67 6e  was never design
14110 65 64 0a 74 6f 20 73 75 72 76 69 76 65 20 74 68  ed.to survive th
14120 65 20 6f 6e 73 6c 61 75 67 68 74 20 6f 66 20 74  e onslaught of t
14130 68 69 73 20 6b 69 6e 64 20 6f 66 20 6d 6f 64 65  his kind of mode
14140 72 6e 20 73 6f 66 74 77 61 72 65 2e 0a 0a 44 6f  rn software...Do
14150 6e e2 80 99 74 20 65 78 70 65 63 74 20 74 6f 6f  n’t expect too
14160 20 6d 75 63 68 21 20 54 68 69 73 20 63 6f 6d 70   much! This comp
14170 69 6c 65 72 20 77 69 6c 6c 20 6e 6f 74 20 62 75  iler will not bu
14180 69 6c 64 20 74 68 69 73 20 77 65 65 6b e2 80 99  ild this week’
14190 73 20 62 6c 65 65 64 69 6e 67 0a 65 64 67 65 20  s bleeding.edge 
141a0 6b 65 72 6e 65 6c 2e 20 42 75 74 2c 20 69 74 20  kernel. But, it 
141b0 6d 61 79 20 62 65 20 75 73 65 64 20 74 6f 20 62  may be used to b
141c0 75 69 6c 64 20 61 6e 79 20 6e 75 6d 62 65 72 20  uild any number 
141d0 6f 66 20 75 73 65 66 75 6c 20 75 74 69 6c 69 74  of useful utilit
141e0 79 0a 70 72 6f 67 72 61 6d 73 20 66 6f 72 20 4f  y.programs for O
141f0 53 2f 38 2e 0a 0a 0a 23 23 20 4c 69 63 65 6e 73  S/8....## Licens
14200 65 0a 0a 54 68 69 73 20 64 6f 63 75 6d 65 6e 74  e..This document
14210 20 69 73 20 75 6e 64 65 72 20 74 68 65 20 5b 47   is under the [G
14220 4e 55 20 47 50 4c 76 33 20 4c 69 63 65 6e 73 65  NU GPLv3 License
14230 5d 5b 67 70 6c 5d 2c 20 63 6f 70 79 72 69 67 68  ][gpl], copyrigh
14240 74 20 c2 a9 20 4d 61 79 2c 0a 4a 75 6e 65 2c 20  t © May,.June, 
14250 61 6e 64 20 4e 6f 76 65 6d 62 65 72 20 32 30 31  and November 201
14260 37 20 62 79 20 5b 49 61 6e 20 53 63 68 6f 66 69  7 by [Ian Schofi
14270 65 6c 64 5d 5b 69 61 6e 5d 2c 20 77 69 74 68 20  eld][ian], with 
14280 6c 61 74 65 72 20 69 6d 70 72 6f 76 65 6d 65 6e  later improvemen
14290 74 73 0a 62 79 20 5b 57 61 72 72 65 6e 20 59 6f  ts.by [Warren Yo
142a0 75 6e 67 5d 5b 77 79 5d 20 69 6e 20 32 30 31 37  ung][wy] in 2017
142b0 20 61 6e 64 20 32 30 31 39 2e 0a 0a 5b 67 70 6c   and 2019...[gpl
142c0 5d 3a 20 68 74 74 70 73 3a 2f 2f 77 77 77 2e 67  ]: https://www.g
142d0 6e 75 2e 6f 72 67 2f 6c 69 63 65 6e 73 65 73 2f  nu.org/licenses/
142e0 67 70 6c 2e 68 74 6d 6c 0a 5b 69 61 6e 5d 3a 20  gpl.html.[ian]: 
142f0 6d 61 69 6c 74 6f 3a 49 73 79 73 78 70 40 67 6d  mailto:Isysxp@gm
14300 61 69 6c 2e 63 6f 6d 0a 5b 77 79 5d 3a 20 20 68  ail.com.[wy]:  h
14310 74 74 70 73 3a 2f 2f 74 61 6e 67 65 6e 74 73 6f  ttps://tangentso
14320 66 74 2e 63 6f 6d 2f 0a                          ft.com/.