Dr.  Dobb’s  Journal 

For  Users  of  Small  Computer  Systems  / 


Dr.  Dobbs  journal 

For  Users  of  Small  Computer  Systems 


\£)lume  Six 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems  / 


A  Reference  Journal  for  Users  of  Home  Computers 


\Wme  Six 


The  People’s  Computer  Company  Series 


as 

HAYDEN  BOOK  COMPANY  INC. 


Hasbrouck  Heights,  New  Jersey 


Acknowledgments 


Many  thanks  to  all  authors  and  readers  who  have  contributed  articles,  ideas  and 
illumination  to  the  pages  of  Dr.  Dobb’s  Journal.  Many  of  the  items  found  in  these  pages 
would  have  been  inaccessible  to  the  microcomputer  hobbyist,  or  available  only  at  great 
expense,  has  their  creators  not  felt  that  immersion  in  the  critical  cauldron  of  the  computing 
community  were  more  important  than  financial  compensation. 

Much  gratitude  also  goes  to  the  Friends  of  PCC.  They  are  a  large  and  loose-knit  band 
united  by  such  ephemeral  and  fleeting  moments  as  potluck  dinners,  spontaneous  music  in 
the  parks,  coffeehouse  synergisms,  and  occasional  moments  of  genius.  These  friends  keep 
us  sane,  and  make  microcomputing  human. 


Editor:  MARLIN  OUVERSON 

Book  production:  JANE  A.  MCKEAN 

Production  assistant:  ALANA  HUNTER 

Index:  POLLY  KOCH,  SUE  ELDREDGE 

Printed  and  bound  by:  MALLOY  LITHOGRAPHING,  INC. 


Cover:  Linocut  of  griffin  by  Wendy  Palmer.  The  mythological  griffin,  half 
lion  and  half  eagle,  has  long  stood  as  an  enemy  of  ignorance. 


Copyright  ®  1983  by  People’s  Computer  Company.  All  rights  reserved.  No 
part  of  this  book  may  be  reprinted,  or  reproduced,  or  utilized  in  any  form  or 
by  any  electronic,  mechanical,  or  other  means,  now  known  or  hereafter 
invented,  including  photocopying  and  recording,  or  in  any  information 
storage  and  retrieval  system,  without  permission  in  writing  from  the 
Publisher. 

Printed  in  the  United  States  of  America 

23456789  PRINTING 


84  85  86  87  88  89  90  91 


YEAR 


Editors  Preface 


Editor’s  Preface 

Since  1976,  Dr.  Dobb’s  Journal  had  been  serving  the  microcomputing  world  —  a  small, 
almost  cloistered  group  of  hackers  and  left-wing  professionals  who  believed  in  the  concept  of 
personal  computing.  But  the  movement  gained  momentum.  A  nose  for  profits  lured  big  com¬ 
panies  into  the  arena.  Even  Hewlett-Packard,  after  throwing  away  the  Apple,  joined  the  fray. 
Publishers  like  McGraw-Hill  and,  later,  Ziff-Davis  took  up  the  scent. 

It  became  obvious  that  more  and  more  people  were  developing  their  microcomputer  exper¬ 
tise.  More  people  were  graduating  to  the  next  stage  of  understanding,  entering  systems  work 
instead  of  simply  using  or  writing  applications.  In  other  words,  the  potential  audience  for  DDJ 
was  growing  rapidly. 

Beginning  at  about  this  tim e,Dr.  Dobb’s  Journal  began  accepting  limited  amounts  of  adver¬ 
tising.  The  editor  was  charged  with  the  responsibility  of  not  allowing  any  such  source  of  income 
bias  the  textual  content  of  the  magazine.  Readers  of  this  bound  volume  will  note  that  certain 
page  numbers  are  missing;  this  is  because  the  advertisements  were  not  reproduced  here.  All  text 
is,  however,  included.  Despite  the  inclusion  of  some  advertising,  and  a  new  cover  designed  to 
work  well  for  newsstand  sales,  the  articles  continued  in  the  time -honored,  reader -defended 
tradition.  Utilities,  algorithms,  compiler  design,  operating  systems,  and  lots  of  useful  public- 
domain  software  remain  the  focus  of  the  magazine  to  this  day.  By  remaining  free  of  corporate 
publishing  interests,  we  have  retained  the  freedom  to  publish  what  is  important,  not  what  will 
simply  create  the  mass  market  sale. 

It  is  our  conviction  that  the  same  level  of  computing  power  and  ease  should  be  available  to 
individuals  and  small  organizations  as  rests  at  the  fingertips  of  governments  and  corporations. 
What  is  at  the  disposal  of  politicians  and  financiers  should  also  be  used  by  and  for  just  plain 
people.  In  the  beginning  days  of  personal  computing,  there  was  a  strong  awareness  of  the  fact 
that  whoever  has  control  of  these  machines  has  control  of  information  and  computing  utilities 
that  directly  influence  the  daily  lives  of  members  of  entire  civilizations.  Micro  enthusiasts  were 
banded  together  to  improve  personal  computing  power  by  sharing  public-domain  software, 
home -brewing  better  machines,  and  working  with  the  physically  handicapped. 

It  will  be  interesting  to  note  whether  the  descent  of  microcomputers  into  the  mainstream 
of  industrial  nations  will  dilute  or  eradicate  that  revolutionary  spirit.  Will  the  programmer  who 
now  can  readily  sell  games  or  utilities  to  a  receptive  public  still  take  the  time  to  tinker  with 
software  and  hardware  controls  for  a  paraplegic’s  “smart”  wheelchair,  or  fight  to  integrate  the 
communication  protocols  for  the  deaf  into  the  standard  which  has  evolved  for  the  non-hearing- 
impaired  ? 

At  the  end  of  this  decade ,  we  must  hope  to  find  that  we  have  heeded  the  call  to  conscience 
presented  to  us  by  the  microcomputing  revolution.  Perhaps  we  should  remember  that  this 
phenomenon  truly  did  begin  as  a  revolution.  Whether  or  not  the  powerful  tools  we  have  created 
will  help  to  transform  this  world  into  an  even  better  one  will  depend  on  the  people  involved 
and  on  their  priorities.  It  is  still  unclear  whether  our  ideals  or  our  bank  accounts  will  prevail. 

Either  way ,  Dr.  Dobb ’s  Journal  is  providing  the  tools  for  advanced  computer  users.  Use 
them  in  good  health. 


Marlin  Ouverson 
Editor 


About  People’s  Computer  Company 


People’s  Computer  Company,  the  publisher  of  Dr.  Dobb ’s  Journal,  was  founded  in  1972  as 
a  non-profit  source  of  education  and  information  about  computers.  It  grew  from  the  same  roots 
as  the  Whole  Earth  Catalog.  Both  companies  were  offshoots  of  the  Portola  Institute  of  Menlo 
Park,  California,  an  organization  investigating  and  promoting  the  idea  of  alternative  technology. 
For  the  founders  of  PCC,  this  meant  learning  to  use  computers  as  a  liberating  force  in  society. 

To  make  these  ideas  manifest,  it  has  been  necessary  to  think  far  ahead,  to  be  creative  and 
innovative.  PCC  published  the  first  personal  computing  periodical  in  1972,  a  time  when  the 
technical  community  at  large  found  the  thought  of  “personal”  computers  preposterous. 

PCC  has  initiated  a  number  of  successful  service -oriented  projects  in  order  to  empower 
people  to  take  a  more  active  part  in  a  society  in  which  computers  are  a  significant  factor.  It  has 
published  a  newspaper,  three  magazines,  and  several  books  on  home/personal  computing.  It  has 
also  operated  a  neighborhood  computer  center,  a  mail-order  bookstore,  a  computer  van,  and 
has  sponsored  telecommunications  research  (PCNET). 

The  main  emphasis  of  the  company  has  been  small,  personal  computers  —  the  kind  anyone 
can  learn  to  use  and  many  families  can  afford.  ComputerTown,  USA!  is  a  major  project  begun 
with  financial  assistance  from  the  National  Science  Foundation.  It  provides  a  model  of  how  to 
make  everyone  in  a  small-  to  medium-size  community  “computer  literate.”  It  shows  how  to 
use  local  resources  —  public  libraries  and  museums,  schools,  community  centers,  local  businesses, 
and  donations  of  hardware  and  volunteer  time  —  to  give  children  and  adults  direct,  hands-on 
experience  with  computers.  ComputerTown  shares  its  experience  and  resources  in  a  newsletter, 
in  the  ComputerTown  Books  series,  in  the  ComputerTown  Guidebooks,  and  through  classes 
and  membership  services.  Affiliates  exist  in  the  United  Kingdom,  Europe,  Australia,  and  across 
the  United  States. 

Dr.  Dobb ’s  Journal  was  PCC’s  second  publication.  The  first  issue  was  published  in  1976  in 
order  to  provide  short-term  distribution  of  the  newly  written  Tiny  BASIC  language.  Reader 
response  was  so  strong  that  it  went  immediately  into  monthly  production.  It  has  led  the  way 
since  then  by  focusing  on  important  advances,  printing  public  domain  software,  and  fostering 
vital  reader  interaction  on  technical  matters.  Most  readers  describe  their  experience  with  com¬ 
puters  as  intermediate  to  extensive.  About  ten  percent  of  them  live  outside  the  United  States. 
Volumes  One  through  Six  include  the  first  six  years  of  DDJ’s  publication,  and  are  available  in 
matching,  bound  volumes  from  Hayden  Book  Company. 

The  PCC  staff  members  have  a  wide  variety  of  personal  and  professional  interests  and 
experiences.  Their  work  stems  from  a  conviction  that  the  personal  computing  revolution  is  of 
tremendous  significance,  and  that  familiarity  with  computers  fosters  confidence  and  greater 
control  over  one’s  life. 

Bob  Albrecht,  one  of  the  company’s  founders,  explained  the  inspiration  for  the  company 
in  the  first  issue  of  the  PCC  Newspaper  : 

“Computers  are  mostly  used  against  people  instead  of  for  people,  used  to  control  people 
instead  of  free  them.  It’s  time  to  change  all  that.  We  need  a  People’s  Computer  Company.” 

People’s  Computer  Company 
P.O.  Box  E 

Menlo  Park,  C A  94025 


Contents 


VOLUME  6,  NUMBER  51,  1981 


2  Editorial 

3  Letters 

5  Dobb’s  Ex  Machina 

6  What  FORTH  Is?  H.  T.  GORDON 

14  Of  Interest 

15  Z-80  File  Comparator  Donald  E.  Faulkner 

16  Z-80  Video  Drivers  Anthony  Skjellum 
36  Software  Review 

“8080/Z-80  Editor,  Assembler,  Disassembler”  J.  N.  DEMAS 

41  Book  Reviews 

42  Intext  —  An  Input  Routine  for  Text  Editors  Greg  Smith 
45  Turing  Machine  Simulation  J.  L.  Lawrence 


VOLUME  6,  NUMBER  52,  1981 


50  Editorial 

5 1  Letters 

54  Parfor —  A  Theoretical,  Parametrized,  FORTH-like  HLL  H.  T.  Gordon 
60  Sinclair’s  ZX80  John  B.  Palmer 

62  POKE  and  PEEK  to  Your  Heart’s  Content  T.  J.  Van  Iderstine 

63  PAN  —  One  Activity  of  the  PCNET  Project  Dave  Caulkins  and 

David  C.  Harris 

64  DECONCAT  —  A  De-Bugging  Tool  for  Concatenated  Programs  Greg  Smith 

66  Small-C  —  An  Implementor’s  Notes  and  a  Bug  Corrected  P  L.  WOODS 

69  Z-80  Memory  Test  Ray  Duncan 

80  Software  Reviews 

“ DB.BAS  —  General  File  Maintenance”  MICHAEL  FAVITTA 

“ ZDM  for  CPIM  Users”  Gene  Head 

82  Dobb’s  Ex  Machina 

84  Of  Interest 

86  Book  Reviews 

88  Radio  Shack  Pocket  Computer  Dick  Greenlaw 


VOLUME  6,  NUMBER  53,  1981 


90  Editorial 

91  Letters 


95  Computer-Based  High  Speed  Reading  Dave  Caulkins 

96  Analysis  of  the  Use  of  the  6502’s  Opcodes  Howard  W.  Whitlock,  Jr. 

99  Book  Reviews 

100  ERGO:  A  “Thinking  Program”  Sheldon  Softky  and  Sylvan  RUBIN 

102  Using  Word-Master  with  the  Compal-80  Anthony  Skjellum 

103  Byte  Manipulation  and  Byte  Pointers  Edwin  E.  Freed 

104  Small-C:  Current  Status  R  L.  WOODS 

122  Software  Reviews 

"CLOAD  Magazine,  Inc.’’  JOHN  HATFIELD 
‘  ‘MON  3' '  Steven  Wexler 

“Disk  Keyplus”  MARCIA  KALISH 
124  DOSMOVER  for  the  North  Star  THOMAS  W.  CAGE 

126  Video  Underline  Modification  Dannie  E.  Davis 

127  TRS-80  Voice  Synthesizer  on  Other  Microcomputers  MICHAEL  Hightower 

and  Peter  B.  Maggs 
131  Of  Interest 


VOLUME  6,  NUMBER  54,  1981 


136 

Editorial 

137 

Letters 

140 

Z-80  Floppy  Disk  Test 

Ray  Duncan 

146 

Polynomial  Evaluation  in 

BASIC  R.  A. 

Hoffman 

148 

Algorithms  in  FORTH 

S.  B.  Bassett 

149 

A  SLIC  Label  Program 

Robert  Hallem 

150 

A  Cassette  I/O  Routine  for  BASIC  Arrays 

Arne  Rohde 

174 

Of  Interest 

177 

Important  Features  of  the  PCNET  Protocol 

David  C.  Harris 

178 

Software  Review 

“MINCE:  Not  Just  Another  Editor’’  Barry  A.  Dobyns 


VOLUME  6,  NUMBER  55,  1981 


184 

Editorial 

185 

Letters 

187 

Using  (and  Misusing)  the  Z-80  Microprocessor 

Ray  Duncan 

189 

A  Smart  2716  EPROM  Programmer  ERIC  M. 

Miller 

191 

Of  Interest 

194 

What  to  Do  With  Those  Extra  Function  Keys 

John  B.  Palmer 

197 

CAD  for  Time  Delay  Circuits  Hal  KN1PPENBERG 

198 

Book  Reviews 

200 

Dr.  Dobb’s  Clinic  Dave  CORTESI 

202 

Santa  Barbara  Tiny  BASIC  for  6809’s  JAMES  A.  HINDS 

220 

Software  Review 

“SCRIBE  IX’ '  Gene  Head 

VOLUME  6,  NUMBER  56,  1981 


226  Editorial 

227  Letters 

230  Cross  Assembler  for  8080  or  Z-80  Jonathan  Mills 

235  COMAL-80  —  A  New  Language?  SUSAN  SONDERSTRUP  and  MOGENS  Pelle 

237  Guest  Essay 

“Re-thinking  Program  Editors’’  William  B.  Brogden 

239  H8  Text  Editor  to  CP/M  File  Conversion  Jim  SCOTT 

240  A  Tiny  File  System  William  A.  Gale 
268  Book  Reviews 

270  Installing  a  Printer  Toggle  in  North  Star  DOS  5.2  Bert  Smart 

271  Dr.  Dobb’s  Clinic  Dave  CORTESI 
273  Of  Interest 


VOLUME  6,  NUMBER  57,  1981 


276 

Editorial 

277 

Letters 

282 

Pidgin  —  A  Systems  Programming  Language 

William  A.  Gale 

287 

Time  on  the  Horizon  D.  J.  Yates 

291 

BASIC  Rubik’s  —  A  Cube  Simulator 

J.  W. 

Pehoushek 

310 

Of  Interest 

312 

Dr.  Dobb’s  Clinic  Dave  CORTESI 

315 

Book  Reviews 

VOLUME  6,  NUMBER  58,  1981 


3 1 8  Editorial 

319  Letters 

321  Write  Your  Own  Compiler  William  A.  Gale 

330  Some  Useful  C  Time  Functions  Bill  Bolton 

354  Dr.  Dobb’s  Clinic  Dave  CORTESI 

357  Of  Interest 


VOLUME  6,  NUMBER  59,  1981 


362  Editorial 

363  The  FORTH  Philosophy  Kim  Harris 

369  A  FORTH  Assembler  for  the  6502  William  F.  Ragsdale 

381  Sallying  FORTH  to  Battle  R.  G.  Loeliger 

383  Screen-Oriented  Editor  in  FORTH  Henry  laxen 

398  Elements  of  a  FORTH  Data  Base  Design  Glen  B.  Haydon 

403  FORTH  Decompiler  Ray  Duncan 

408  Of  Interest 

41 1  The  FORTH  Alternative  MITCHELL  E.  Timin 
414  Dr.  Dobb’s  Clinic  Dave  CORTESI 


VOLUME  6,  NUMBER  60,  1981 


418  Editorial 

419  Letters 

422  Dr.  Dobb’s  Clinic  Dave  CORTESI 

423  TEK4010  —  A  Tektronix  4010  Simulator  Anthony  SKJELLUM 
427  BASIC-FORTH  —  A  Poor  Man’s  FORTH  Computer  C.  H.  Ting 
429  The  Conference  Tree  —  Computer  Conferencing  John  S.  James 
460  Of  Interest 


I 


VOLUME  6,  NUMBER  61,  1981 


464 

Editorial 

465 

Letters 

466 

Of  Interest 

468 

ADVEN-80  —  An  Advanced  Adventure  Development  System 

Peter  D.  Scargill 

487 

Terminal  Programs  for  North  Star  Richard  Blessing 

492 

Small  VM  - —  Portable  Software  Development  Environment 

J.  E.  Hendrix 

504 

Small-C  Grows  Up 

Richard  Roth 

510 

Essay  on  Hacking 

Gandalf 

515 

Dr.  Dobb’s  Clinic 

Dave  Cortesi 

VOLUME  6,  NUMBER  62,  1981 


518  Editorial 

519  Letters 

520  Dr.  Dobb’s  Clinic  Dave  Cortesi 

522  Of  Interest 

526  Actors,  Property  Lists,  and  LISP  RONALD  L.  Nicol 

533  Marching  the  8080  —  A  Simple  Memory  Chip  Tester  JAMES  LAURINO 

535  For  CP/M  BIOS  —  An  Improved  MX-80  Printer  Driver  GARY  R  NOVOSIELSKI 

545  Connect  A  Parallel  Printer  to  North  Star  (More  on  the  MX-80)  ALAN  BOMBERGER 

547  Small-C  Expression  Analyzer  —  Patching  the  Address  Arithmetic  J.  E.  HENDRIX 

551  Auto.  Loading  of  Assembly  Language  Subroutines  John  B.  Palmer 


Dr.  Dobbs  Journal 

For  Users  of  Small  Computer  Systems 


\klume  Six 


m 


$2.50 

DTT^^  *W"  In  Canada  $3.00 

R.  DOBB  S  lOURNALof 

COMPUTER 

(Calisthenics  ^  Orthodontia 

Running  Light  Without  Overbyte 


OBB’S  lOURNALof 


Number  51 


January  1981 


Volume  6,  Issue  1 


A  REFERENCE  JOURNAL  FOR  USERS  OF 
SMALL  COMPUTERS 


What  FORTH  Is? 

H.  T.  Gordon 

Z-80  File  Comparator 
Donald  E.  Faulkner 

Z-80  Video  Drivers 
Anthony  Skjellum 

Intext:  An  Input  Routine  for  Text  Editors 
Greg  Smith 

Turing  Machine  Simulation 

J.  L.  Lawrence 

and  much,  much  more  .  .  . 


Re 


P.  0.  Box  E 
Menlo  Park 
CA  94025 


Dr.  Dobb's  Journal  of 

COMPUTER  Calisthenics  6  Orthodontia 


Volume  6,  Issue  1 
Number  51 
January  1981 


Contents 

Articles 


Departments 


What  FORTH  Is? .  8 

by  H.  T.  Gordon 

Z- 80  File  Comparator . 19 

by  Donald  E.  Faulkner 

Z-80  Video  Drivers . 20 

by  Anthony  Skjellum 

Intext:  An  Input  Routine  for  Text  Editors . 46 

by  Greg  Smith 

Turing  Machine  Simulation . 49 

by  J.  L.  Lawrence 


Publisher 

Art  Director 

Marketing  Director 

Ann  Merchberger 

Clifford  West 

Gavin  W.  Cullen 

Editor 

Artists 

Advertising  Director 

Marlin  Ouverson 

Barbara  Ruzgerian 

Michael  Madaj 

Contributing  Editors 

Greg  Gordon 

Circulation  Manager 

Dennis  Allison 

Jeannie  Barroga 

Peter  Clark 

Dave  Caulkins 

Typesetter 

Circulation  Assistant 

Dave  Cortesi 

Renny  Wiggins 

Leah  Dansby 

Editorial 

c 

^^^'hange  has  been  called  the  essence  of  manifestation. 
DDJ  is  growing  continually,  and  is  under  the  guidance  of  a 
new  editor.  The  position  carries  with  it  a  keen  responsibility 
not  only  to  the  readers,  but  to  the  ideals  of  the  publisher. 
These  are  of  such  broad  impact  and  general  importance  that 
the  commitment  to  them  can  only  be  met  by  calling  together 
many  voices  to  speak  within  the  pages  of  this  publication. 

Among  this  issue’s  letters  to  the  editor  is  one  which  ex¬ 
presses  dissatisfaction  with  the  direction  followed  by  DDJ. 
The  new  subscriber  is  shocked  that  the  “.  .  .  founding  fathers 
have  abandoned  ship  . . .  and  in  their  place  a  girl  journalism 
student . . .  [who  cannot]  pretend  to  any  technical  compe¬ 
tence 

With  the  most  recent  change  of  editors,  the  issues  of 
feminism  and  journalism  became  merely  rhetorical.  It  is, 
however,  vital  for  each  of  us  to  realize  that  the  technical  ex¬ 
cellence  of  this  journal  derives  from  many  sources.  The 
founding  fathers  have  not  abandoned  ship  in  any  sense  of 
the  expression.  Each  of  them  contributes  directly  and  in¬ 
directly  with  articles,  advice,  overall  guidance  and  specific, 
critical  comments.  Additionally,  the  staff  relies  upon  a  grow¬ 


Letters .  4 

Dobb ’s  Ex  Machina .  7 

Of  Interest .  17 

Software  Review . 40 

Club  News . 44 

Book  Reviews . 45 


©1981  by  People’s  Computer  Company.  All  rights  reserved. 

Dr.  Dobb 's  Journal  (USPS  307690)  is  published  twelve  times  per  year 
by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real,  Menlo 
Park,  California  94025.  Second  class  postage  paid  at  Menlo  Park, 
California  94025  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  9402  5. 

Subscription  Rates:  $2  5  per  year  within  the  United  States;  $44  for 
first  class  to  Canada  and  Mexico;  $62  for  airmail  to  other  countries. 
Payment  must  be  in  U.S.  dollars,  drawn  on  a  U.S.  bank. 

Writer’s  Guidelines:  All  items  should  be  typed,  double-spaced  on  white 
paper.  Listings  should  be  produced  by  the  computer,  using  a  fresh 
dark  ribbon  on  continuous  white  paper.  Please  avoid  printing  on  per¬ 
forations.  Payment  is  in  contributor’s  copies.  Requests  to  review 
galleys  must  accompany  the  manuscript  when  it  is  first  submitted. 
Authors  may  receive  a  copy  of  the  complete  writer’s  guidelines  by 
sending  a  self-addressed,  stamped  envelope. 


ing  number  of  technical  advisors.  It  would  not  be  appropriate 
for  any  of  these  fine  people  to  quit  their  own  endeavors  to 
become  journalists,  for  it  would  mean  fewer  experts  at  work 
on  new  developments  in  the  field.  As  H.T.  Gordon  states  in 
this  issue,  “Most  experts  are  doers,  not  teachers.” 

Most  important  of  all  to  the  realization  of  DDJ' s  ideals 
are  its  readers.  The  entire  philosophy  of  the  publisher  hinges 
upon  the  demystification  and  proliferation  of  computer 
expertise.  Our  contributors  are  exemplars  of  this  outlook. 
While  each  of  us  benefits  from  the  volatile  exchange  of 
information,  there  is  also  within  each  of  us  at  least  a  half- 
kindled  spark  of  altruism.  It  is  that  which  moves  us  to  give, 
to  share  a  discovery  or  to  provide  a  new  way  of  looking  at  an 
aspect  of  personal  microprocessing. 

We  are  engaged  in  a  concerted  effort,  in  which  each  of  us 
has  an  important  role.  Your  letters,  thoughts  and  articles  are 
always  welcome. 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 
2 


Letters 


Dr.  Dobb’s  Journal  welcomes  letters  to 
the  editor  as  a  forum  for  ideas,  innova¬ 
tions,  irascibility  and  even  idiosyncrasies. 
Some  letters  may  be  edited  for  clarity 
and  brevity.  The  Doctor  likes  hearing 
from  you  -  keep  on  writing! 

Note  on  Multiple  File  Transfer 

Dear  DDJ: 

I  am  a  new  CP/M  user,  presently  with 
a  single  drive  system  (Thinker  Toys 
double  density),  so  the  MFT  -  Multiple 
File  Transfer  Utility  in  the  October  issue 
of  DDJ  -  came  along  at  just  the  right 
time  for  me.  However,  I  found  two  minor 
problems  with  the  way  it  was  written. 

First,  when  the  copy  function  is 
completed  it  re- boots  immediately  with 
whatever  disk  is  currently  in  the  drive.  If 
it  doesn’t  have  a  copy  of  CP/M  on  it,  or 
has  a  different  version  of  CP/M  (a  differ¬ 
ent  memory  location,  for  example)  it 
goes  wild.  This  is  easily  corrected  by 
adding  one  more  message: 

MSGF  DB  ‘Mount  System  disk, 
press  any  key’,0 

and  replacing  the  JMP  0  instruction  at 
label  MFTG  with  the  following  routine. 

MFTG  LXIH.MSGF 

CALL  WASC  ;print  message 

CALL  RACC  ;wait  for  key¬ 

board  input 
JMP  0  ;now  re- boot 

This  gives  you  the  opportunity  to  swap 
disks  again  before  it  re- boots. 

Second,  I  had  some  problems  when 
trying  to  copy  from  single  density  disks. 
Adding  a  CALL  RESET  instruction  be¬ 
tween  the  CALL  WEOLC  and  LDA 
IBFLG  instructions  in  the  MFT1  routine 
(top  of  page  26)  corrects  this. 

I  hope  these  modifications  will  help 
others;  this  program  works  great.  (And 
it  saved  me  from  trying  to  write  the  same 
thing  from  scratch!) 

Larry  Hudson 
2232  Alameda  Ave. 

Ventura,  CA  93003 


One -Byte  Opcodes 

Dear  Dr.  Dobb’s: 

H.T.  Gordon  comes  very  close  to  an¬ 
swering  how  to  create  a  large  number  of 
one-byte  opcodes  in  DDJ  #49.  “Opcode 
Design :  9  or  1 6  bits”  in  several  places  was 
on  the  brink  of  suggesting  a  microproces¬ 
sor  with  a  “language  register.”  The  con¬ 
tents  of  this  register  would  specify  the 
machine  language  currently  being  exe¬ 
cuted. 


Some  of  the  CPU’s  languages  could 
be  optimized  for  string  manipulation, 
floating  point  math,  input/output,  sort¬ 
ing,  file  handling,  process  control,  Pascal, 
BASIC,  etc.  Other  languages  might  emu¬ 
late  a  6502,  8080,  6800,  etc.  The  assem¬ 
bly  language  of  this  multi- lingual  micro¬ 
processor  would  include  commands  to 
read  and  write  a  language  register.  The 
actual  opcodes  generated  by  these  com¬ 
mands  would  of  course  depend  on  which 
language  was  in  use. 

Steps  in  a  similar  direction  have  been 
taken  by  circuit  board  designers. 
Godbout  Electronics  offers  a  Dual  Pro¬ 
cessor  Board  with  an  8085  and  an  8088. 
Microsoft  has  a  Z80  card  to  plug  in  with 
the  Apple’s  6502.  Ohio  Scientific  has 
offered  several  co-resident  processors,  in¬ 
cluding  the  Z80,  6502,  6100,  and  6800. 
But  these  merely  offer  the  choice  of  one 
of  several  compromises  —  each  chip  is  de¬ 
signed  to  do  everything.  A  single  micro¬ 
processor  implementing  several  languages, 
each  of  which  was  designed  to  do  one 
thing  well,  would  provide  the  “quantum 
leap  in  performance”  H.T.  Gordon  men¬ 
tions. 

Sincerely, 

Charles  Floto,  Editor 

BUSS 

325  Pennsylvania  Avenue,  S.E. 

Washington,  DC  20003 

H.  T.  Gordon  responds: 

Dear  Mr.  Floto, 

Thanks  for  sending  me  a  copy  of 
your  DDJ  letter  re  my  9-  vs.  16 -bit  arti¬ 
cle.  I  wrote  that  in  a  few,  hypermanic 
hours,  without  the  usual  long  reflection 
and  rewriting  such  things  ought  to  get. 
Only  later  did  I  wonder  whether  a  single 
status  bit  gives  designers  enough  of  a 
“handle”  on  the  circuitry  to  provide  two 
distinct  and  meaningful  interpretations  of 
a  set  of  8 -bit  opcodes.  That  may  be  why 
8 -bit  leading  bytes  are  used  to  “com¬ 
pletely  redefine”  an  opcode.  Your  con¬ 
cept  goes  very  far  beyond  what  I  had  in 
mind  at  the  time  (enlarging  a  set  with 
minimal  loss  of  speed  and  code  efficien¬ 
cy),  and  would  not  be  invalidated  even  if 
several  status  bits  were  needed  for  a  total 
reinterpretation.  It  is  possible  that,  even 
though  I  didn’t  see  it,  some  CPU  design¬ 
ers  (especially  the  2650!)  did,  but  de¬ 
cided  the  circuit  complexity  would  be 
too  formidable  in  the  then  state-of-the- 
art.  Who  knows,  the  6809  designers  may 
have  mused  about  it  but  been  told  not  to 
get  too  wild!  That  possibility  certainly 


crossed  my  mind! 

Your  idea  is  powerful  and  may  now 
even  be  feasible,  though  doing  it  might 
drive  designers  up  the  wall.  Still,  it  might 
be  worth  sacrificing  a  few  geniuses  to  the 
gods  (though  I’d  rather  sacrifice  a  few 
hundred  executives)  to  get  a  chip  that 
could  acquire  magical  powers  in  a  few 
microseconds.  It  would  be  a  quantum 
leap,  though  the  distinction  between  “co¬ 
resident  processors”  and  opcode- 
extension  of  one  super- processor  is  a 
subtle  one.  Some  operations,  like  read / 
write  of  memory,  might  well  be  identical 
for  all  the  “processor  sets.”  My  impres¬ 
sion  (that  will  be  developed  in  forth¬ 
coming  articles  on  FORTH -like  HLLs)  is 
that  designers  are  now  thinking  hard 
about  optimizing  microprocessor  in¬ 
struction  sets  to  “run”  the  intermediate- 
code  of  various  HLLs.  Perhaps  your  “9+ 
opcode”  concept  would  be  useful  there. 
Sincerely, 

H.  T.  Gordon 

College  of  Natural  Resources 
University  of  California 
Berkeley,  CA  94720 


A  Mote  Point . . , 

Dear  DDJ: 

As  a  tech  writer  for  a  PR  agency, 
with  primarily  high-technology  clients,  I 
read  most  of  the  computer  and  electron¬ 
ics  magazines,  and  I  come  across  occa¬ 
sional  gems  of  technical  prose,  which  I’d 
like  to  share  with  you  and  your  readers. 

Herewith  please  find  my  submission 
to  Dr.  Dobb’s  Compendium  of  Self- 
Referential  Phraseology : 

“. .  .  clear,  concise,  industrial  grade 
speech.” 

It  is  from  a  Texas  Instruments 
TM990/36  ad. 

Referentially, 

S.  B.  Bassett 

c/o  151  University  Avenue 
Palo  Alto,  C A  94301 


Captured  by  the  Capitalists? 

Dear  Editor, 

In  the  October  issue  you  requested 
suggestions  and  comments.  I  have  a  few 
for  you.  I  am  a  new  subscriber  (starting 
June  this  year)  but  my  readership  dates 
back  considerably  farther.  Your  magazine 
came  highly  recommended  from  several 
articles  and  books  and  early  this  year 
when  the  Hayden  Book  Company  offered 


4 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 

3 


Letters 


a  1 5  day  trial  on  the  first  three  volumes  I 
took  the  chance.  I  expected  to  be  disap¬ 
pointed.  The  very  concept  of  the  People’s 
Computer  Company  seems  doubtful  to 
me,  since  I  am  convinced  that  the  capital¬ 
ist  system  is  the  only  currently  viable 
one.  So  I  expected  that  shared  software 
would  be  cast-offs,  half-baked  schemes 
etc.  Instead  there  were  indeed  useful  list¬ 
ings,  interpreter- writing  aids,  and  other 
sytems  software  level  tips.  I  find  those 
first  three  volumes  a  valuable  reference. 
So  I  subscribed  in  June.  Imagine  my 
shock.  The  founding  fathers  have  aban¬ 
doned  the  ship  (contributing  editors?) 
and  in  their  place  a  girl  journalism 
student  whose  first  suggestion  was  to 
have  more  business  oriented  practical  arti¬ 
cles  (in  a  systems  software  journal?). 
Neither  Suzanne  nor  yourself  can  pretend 
to  any  technical  competence  in  microsys¬ 
tems  software.  And  that  seems  to  me  to 
be  a  mistake.  Sure,  a  generalist  can  edit 
any  text,  but  in  order  to  publish  a  journal 
which  was  intended  to  be  an  exchange 
point  for  systems  software  it  seems  to  me 
that  you  need  to  understand  the  technical 
details  in  depth. 

What  I  am  trying  to  say  is  that,  for 
me  at  least,  your  journal  is  slowly  becom¬ 
ing  useless.  There  are  plenty  of  magazines 
for  non-technical  beginners  in  higher- 
level  languages  already.  I  am  looking  for 
details  on  writing  systems  utilities  such  as 
spoolers,  designing  compilers,  text- 
editors  and  so  on.  Maybe  a  tutorial  on 
CP/M  concepts  is  useful,  but  PASCAL? 
My  suggestion?  You’ve  been  captured  by 
the  capitalists.  Give  up  the  ads  and  at¬ 
tempted  slick  format.  Go  back  to  being  a 
systems  software  journal.  Give  us  more 
lowdowns  on  others’  problems  with  new 
systems.  Give  up  being  an  expensive  imi¬ 
tation  of  BYTE  and  Kilobaud.  Go  and 
reread  those  first  issues  and  get  back  to 
the  basics.  Get  someone  who’s  compe¬ 
tent  in  the  field  to  (co-)edit. 

I’d  also  like  to  respond  to  a  letter  in 
that  October  issue,  in  which  Prentice - 
Hall  was  criticized  for  their  15 -day  trial 
program.  Since  I  don’t  live  in  a  big  city 
(or  California),  I  have  had  to  use  these 
free  trials  to  review  the  (usually  oversold) 
new  publications.  I  have  had  excellent 
success  with  both  Prentice- Hall  and 
Hayden  Publishing  Companies.  It  has 
never  required  more  than  one  letter  to 
correct  any  misunderstandings.  There  is  a 
cost,  however.  If  you  keep  the  book  you 
end  up  paying  the  usual  postage  and 
handling  fees  and  if  you  send  it  back  you 
pay  for  the  postage  (usually  around  a  dol¬ 


lar).  Of  course,  there  is  no  free  lunch. 
Since  the  book  is  mailed  fourth  class  and 
the  bill  first,  it  should  come  as  no  sur¬ 
prise  that  you  might  get  the  bill  first.  I 
have  never  had  a  publisher  question  the 
length  of  the  trial.  They  know  the  mails 
are  slow. 

I  hope  you  can  use  this. 

Very  truly  yours, 

Siebert  Ickler 
3709  Bentwood 
Corpus  Christi,  TX  78415 
Editor’s  note:  Please  refer  to  this  month's 
editorial  on  page  3.  Thank  you  for  airing 
your  views  .  .  .  but  really,  DDJ  an  “ ex¬ 
pensive  imitation?"  DDJ  was  the  first, 
and  still  remains  on  the  cutting  edge  of 
innovation,  thanks  to  its  contributors, 
its  technical  advisors  and  the  founding 
fathers. 


Pascal  Postscript 

Dear  DDJ. 


I  recently  perused  DDJ  #48,  in 
which  Mr.  John  Culleton  discusses  (in 
the  Letters  column)  the  “upside  down” 
nature  of  Pascal.  While  I  personally  agree 
with  this  characterization,  my  recent  ex¬ 
perience  modifying  a  Pascal  compiler  (to 
operate  on  the  M68000)  has  given  me  a 
clear  appreciation  of  the  problems  which 
lead  to  this  order.  I  offer  the  following 
not  as  an  apology,  but  as  an  explanation. 

In  passing,  I  would  like  to  clarify  one 
of  the  diagrams  in  Mr.  Culleton’s  letter. 
He  refers  to  a  program  with  main  routine 
000,  calling  100,  200,  and  300,  which  in 
turn  call  110,  120,  etc.  His  diagram  of  the 
order  “required”  by  Pascal  is  correct,  but 
not  actually  required;  it  appears  on  the 
left,  and  a  truly  “required”  order  appears 
on  the  right. 


900 

910 

920 


110 

120 

130 

210 

220 

310 

320 

330 

340 

410 


100 

200 

300 

400 


000 


900 

910 

920 


100 


200 


300 


400 


(utilities) 


110 

120 

130 

210 

220 

310 

320 

330 

340 

410 


000 


As  can  be  seen,  the  lower  level  routines 
need  not  all  be  defined  first;  in  fact,  if 
they  are  called  only  from  their  associated 
higher  level  routine,  they  should  not  be. 
Therein  lies  the  problem. 

The  definition  of  group  (200,  210, 
220)  seems  to  indicate  that  the  subrou¬ 
tines  are  defined  before  the  higher  rou¬ 
tine.  This  is  not  quite  the  case.  The  order 
is  more  like  this: 

200’s  definition; 

200’s  variables; 

210’s  definition; 

210’s  variables; 

210’s  text; 

220’s  definition; 

220’s  variables; 

220’s  text; 

200’s  text 

I  support  the  view  that  this  puts  the 
“Mainline”  text,  which  is  what  most 
people  read  when  they  peruse  a  program, 
in  a  strange  order.  However,  the  defini¬ 
tion  of  the  routine  and  its  variables  ap¬ 
pears  before  the  subroutines,  which  is 
required  by  the  Pascal- defined  “scope 
of  identifiers.” 

Routines  210  and  220  can  refer  to 
200’s  variables,  and  in  fact  if  they  do  not 
specifically  define  their  own  variables 
with  the  same  names,  they  can  refer  to 
000’s  as  well.  200  cannot  refer  to  210’s 
variables,  since  they  are  at  a  different 
level  (they  have  a  definition  in  the  way). 
More  importantly,  since  Pascal  is  a  stack 
oriented  system,  210’s  “variables”  are 
really  just  offsets  into  a  stack  frame 
which  is  allocated  when  210  is  called  and 
de- allocated  when  210  finishes.  They 
therefore  do  not  exist  when  200  is  in 
control.  Since  200’s  frame  is  underneath 
210’s,  the  “upward”  reference  is  possible. 
(Similarly,  000’s  frame  is  further  down 
yet  and  is  thus  always  accessible.) 

Languages  like  COBOL  and  FOR¬ 
TRAN  differ  from  Pascal  in  that  their 
variables  are  allocated  at  the  beginning  of 
time  and  stay  in  the  same  place  forever. 
FORTRAN  does  not  allow  any  referenc¬ 
ing  of  variables  not  explicitly  defined  in 
the  current  routine  or  function ;  COBOL 
does  not  have  subroutines  (for  the  most 
part;  PERFORM  is  not  a  proper  sub¬ 
routine  call).  It  may  be  noted  that  PL/1, 
a  recursive  dynamic -allocation  language, 
has  the  same  definition  structure  for 
embedded  routines. 

I  have  used  FORTRAN  compilers 
which  required  the  routines  to  be  entered 
in  lowest-reference  (i.e.,  upside-down) 
order;  I  have  also  used  an  assembler 
(continued  on  page  16) 


6 

4 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


DOBB  S  Ex  Machina 


Occasionally,  a  reader  of  Dr.  Dobb’s 
Journal  will  experience  poor  product 
performance  or  what  he  considers  to  be  a 
company's  failure  to  provide  the  quality 
of  service  they  advertise.  If  his  own 
honest  attempts  to  resolve  the  situation 
fail,  he  may  then  take  recourse  to  the 
impartial  (if  not  heavenly)  mediation  of 
Dobb 's  Ex  Machina . 

When  writing  a  complaint  to  us, 
please  send  backup  data  (e.g.,  carbons  or 
photocopies  of  letters  you  have  sent  to 
the  company  in  question,  replies  received, 
copies  of  registered  receipts).  It  is  not 
possible  to  cover  all  complaints  received, 
but  we  will  publish  a  representative  sam¬ 
ple.  DDJ  has  no  particular  ax  to  grind 
with  any  seller  or  manufacturer,  but  we 
will  pay  close  attention  to  those  compa¬ 
nies  about  which  we  receive  numerous 
and  consistent  complaints. 


Dear  Editor, 

You’ve  had  quite  a  few  letters  about 
mail  order  problems,  but  let  me  tell  you 
what  can  happen  in  playing  safe  and 
ordering  from  a  local  store. 

Toward  the  end  of  last  year  I 
planned  to  upgrade  a  system  used  for  self- 
funded  research  into  methods  of  im¬ 
proving  children’s  medical  care,  ba¬ 
sically  substituting  a  CRT  terminal  for 
the  old  faithful  V DM- 1. 

I  decided  to  play  it  safe  and  ordered 
a  well-known  name  from  a  local  store, 
rather  than  ordering  one  of  the  newer 
brands  from  a  mail  order  discounter.  It 
seemed  likely  that  paying  a  good  bit  more 
initially  would  pay  off  eventually  in 
better  service  and  support. 

However  I  made  two  mistakes.  I 
ordered  a  Hazeltine  1520  from  a  local 
Computerland. 

The  terminal  didn’t  work  properly 
when  unpacked.  Computerland  not  only 
couldn’t  find  the  problem,  they  weren’t 
sure  whether  or  not  one  existed.  The 
Hazeltine  service  agency,  TRW,  did  find  a 
problem  and  fixed  it,  but  when  the  unit 
was  brought  home  a  different  problem 
was  evident,  so  back  again.  (The  TRW 
technician  said  he  was  not  responsible  for 
general  fitness  of  the  terminal,  but  only 
for  the  present  problem.) 

In  all,  the  Hazeltine  failed  six  times 
within  90  days.  Five  times  it  was  taken  to 
TRW  on  an  80  mile  round  trip  and  re¬ 
turned  for  another  80  miles.  I  kept  think¬ 
ing  that  this  time  would  see  it  fixed  for 
good,  but  at  the  sixth  time  I  couldn’t 
face  another  160  miles  of  traveling, 


particularly  when  the  terminal  had  never 
worked  long  enough  to  do  anything  use¬ 
ful.  I  wrote  a  restrained  letter  to  Hazel¬ 
tine  asking  for  a  refund. 

Hazeltine’s  response  has  consisted  of 
pointing  out  that  they  guarantee  only  to 
fix  faults,  not  that  they  will  stay  fixed, 
and  accusing  my  system  of  being  at  fault. 
(This  system  worked  well  with  a  DEC- 
WRITER  for  years  and  the  televideo  ter¬ 
minal,  in  use  now,  has  been  flawless  for 
many  months.) 

Having  a  bit  more  of  a  conscience 
myself  I  can’t  recover  part  of  the  nearly 
$2000  by  unloading  it  on  some  other 
sucker.  I  can’t  afford  to  write  this  kind  of 
money  off  to  experience.  It  shot  a  big 
hole  in  my  research  budget,  but  what  can 
one  individual  do  against  a  large  corpo¬ 
ration?  Try  to  warn  others  I  guess. 

Yours, 

Jim  Callas 

650  N.  San  Pedro  Rd. 

San  Rafael,  CA  94903 
8/11/80 


Dear  Editor, 

Thank  you  for  allowing  Hazeltine 
Corporation  the  opportunity  to  respond 
to  Dr.  Callas’  letter.  Given  that  Dr.  Callas 
represents  a  unique  group  of  consumers  it 
is  important  that  your  readers  understand 
the  chronology  of  events  and  perhaps 
gain  additional  insight  into  the  potential 
pitfalls  that  can  plague  an  unsuspecting 
consumer  as  they  relate  to  purchasing 
computer  peripheral  products. 

To  begin  with,  let’s  review  the  events 
as  they  took  place: 

1 )  Dr.  Callas  purchased  a  Hazeltine 
1520  from  our  customer,  Computerland, 
in  November  of  1979.  We  were  not  ad¬ 
vised  of  a  problem  until  we  received  a 
letter  on  March  3,  1980. 

2)  Personal  contact  with  Dr.  Callas 
was  made  on  March  6,  1980,  at  that  time 
we  requested  additional  information, 
such  as  the  serial  number  for  investigation 
of  his  problem. 

3)  On  March  27,  Dr.  Callas’  attorney 
called  Hazeltine  requesting  a  refund.  All 
communications  since  then  have  been 
through  his  attorney.  To  date  we  have  yet 
to  discuss  with  Dr.  Callas  the  actual 
conditions  the  unit  was  expected  to 
operate  under. 

4)  Through  his  attorney  we  have 
learned  that  he  was  trying  to  run  a  tele¬ 
type  off  the  Hazeltine  1520  using  a  “pro¬ 
prietary”  circuit.  The  design  of  that  cir¬ 
cuit  may  not  be  compatible  to  our  unit 


causing  the  many  failures  he  has  experi¬ 
enced.  There  is  no  way  Hazeltine  or 
Computerland  can  diagnose  and  find  the 
problem  in  such  circumstances. 

5)  Hazeltine’s  1500  Series  carries  an 
“On-site”  warranty  for  commercial  cus¬ 
tomers.  Dr.  Callas’  unit  is  in  his  home. 
T.R.W.  cannot  service  units  in  private 
dwellings.  If  Computerland  was  closer  to 
Dr.  Callas’  home  than  the  T.R.W.  repair 
center,  arrangements  might  have  been 
made  to  do  warranty  service  at  Comput¬ 
erland. 

6)  T.R.W.  responded  correctly  to  Dr. 
Callas.  They  are  not  responsible  for 
general  fitness  of  our  terminal.  That  is, 
they  are  not  responsible  for  whether  a 
particular  Hazeltine  terminal  will  operate 
in  an  environment  which  is  unique  to  a 
particular  customer.  Hazeltine  cannot 
warrant  that  our  unit  will  perform  with 
any  particular  system,  because  we  do  not 
have  control  over  the  systems  to  which  a 
customer  connects  our  terminal. 

As  one  might  assume,  Hazeltine  has 
incurred  substantial  warranty  costs  in  an 
unsuccessful  effort  to  make  the  HI 520 
work  on  Dr.  Callas’  system.  But  that  is 
not  the  issue.  The  point  to  be  made  here 
is  that  there  is  an  abundance  of  terminals 
available  “off  the  shelf”  from  distribu¬ 
tors  or  retail  computer  stores.  Compati¬ 
bility  can  never  be  assumed.  Incompati¬ 
bility  and  poor  product  performance  are 
truly  two  distinct  issues;  one  is  a  function 
of  a  product’s  technical  specifications, 
the  latter  is  simply  a  quality  problem. 
T.R.W.  stands  ready  to  make  repairs 
should  the  customer  experience  a  prob¬ 
lem  due  to  a  failure  of  quality  control. 
There  is  a  specific  burden  of  risk  placed 
on  the  buyer  when  he  purchases  from 
distributors  or  retail  computer  stores  that 
the  product  will  be  compatible  with  the 
buyer’s  system.  The  store  may  assume 
that  the  buyer  knows  what  he  needs  and 
what  technical  specifications  are  correct 
for  his  system.  As  a  point  of  information, 
Hazeltine  employs  a  direct  salesforce, 
an  Engineering  Department,  a  Customer 
Service  Department  and  a  Technical  Sup¬ 
port  Department,  all  of  which  are  at  our 
customer’s  disposal.  Had  Dr.  Callas  first 
confirmed  the  compatibility  of  his  system 
with  the  H1520,  we  suspect  his  decision 
to  purchase  the  HI 520  would  have  been 
affected. 

It  is  our  opinion  that  Dr.  Callas  re¬ 
ceived  good  service  and  the  best  possible 
support  under  these  circumstances.  We 

/ continued  on  page  48) 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


7 

5 


What 

FORTH 

Is? 

by  H.T.  Gordon 


M 

-A.  T  -M*y  brief  critique  of  FORTH  ( DDJ  #48,  p.  19) 
elicited  several  positive  responses  from  the  FIG  (Forth  Interest 
Group).  The  one  that  sparked  this  note  was  a  call  from  Daniel 
Conde,  a  UCB  student,  telling  me  that  some  FORTH  literature 
had  been  given  to  our  Computer  Science  reference  library  by 
Jim  Flournoy.  On  browsing  through '  this,  I  was  pleasantly 
surprised  to  find  a  copy  of  an  unpublished  article :  The  FOR  TH 
language  ...  a  detailed  study  of  U.C.S.D.  's  version  of  FORTH, 
by  Bruce  Airy,  who  is  or  was  a  student  at  the  U.C.  San  Diego 
campus.  He  seems  to  have  implemented  FORTH  on  an  antique 
NOVA  computer  (he  has  many  wry  comments  on  its  weak¬ 
nesses).  This  odd  experience,  plus  an  awareness  of  how  to 
communicate  with  novices  that  is  rare  in  computer  science, 
makes  his  writing  the  clearest  introduction  to  FORTH  I  have  so 
far  read.  Because  its  NOVA  orientation  makes  it  unsuitable  for 
DDJ,  I  decided  to  write  a  shorter  and  more  generalized  presen¬ 
tation  (the  “?”  in  my  title  acknowledges  its  non- expert  charac¬ 
ter). 

It  may  be  argued  that  the  recent  expert  articles  on  FORTH 
published  in  BYTE  (Aug.  1980)  are  pre-emptive.  Excellent 
though  they  are,  my  own  impression  is  that  they  probe  less 
deeply  into  the  working  of  FORTH  than  Airy’s  version.  Ex¬ 
pertise  in  the  cryptics  of  FORTH  code  seems  to  inspire  the  same 
aversion  to  human- oriented  documentation  that  is  so  common 
among  assembly-language  programmers  (you’re  telling  the 
machine  what  to  do,  so  who  cares  about  dimwitted  people!). 
At  the  human  level,  the  way  to  dispel  subconscious  fear  of 
something  new  and  strange  is  to  lay  stress  on  its  similarity  to 
what  is  well-known  and  understood.  That’s  the  secret  of  one  of 
the  rare  human  achievements:  good  teaching.  Most  experts  are 
doers,  not  teachers. 

A 

-A.  jk.  n  impressionist  overview  of  FORTH.  As  I  now  see  it, 
FORTH  is  what  a  simple  command -language  will  evolve  into  if 
(1)  its  creator  is  unable  to  resist  internal  or  external  compul¬ 
sion  to  enhance  it  endlessly,  and  (2)  it  proves  so  useful  that  he  is 
driven  to  adapt  it  to  more  than  one  kind  of  machine.  The  first 
I  know  from  personal  experience  to  be  an  irresistible  tempta¬ 
tion.  The  urge  to  invent  new  commands  in  my  EDITHA  pro¬ 
gram  ( DDJ  #25)  was  halted  by  lack  of  memory  in  the  KIM- 1. 
In  my  DISPAG  program  ( DDJ  #48)  the  brake  was  mental 
fatigue.  In  both  cases,  the  driving  force  was  the  need  to  enhance 
performance  far  beyond  the  limits  of  the  ROM  monitor  com¬ 
mands.  In  his  BYTE  article,  Charles  Moore  (the  inventor  of 
FORTH)  says  that  he  developed  this  “unusual”  HLL  in  order  to 
write  complex  programs  at  a  higher  rate  than  that  possible  with 
other  HLLs. 

A  “command”  is  generated  by  pressing  a  key  (or  a  sequence 
of  keys),  to  send  a  bit- pattern  to  an  interpreter  program.  The 
interpreter  “decodes”  it  to  the  address  of  a  block  of  machine- 
language  code,  that  is  jumped  to,  executed,  and  terminated  by 
a  return  to  interpreter  controL  The  simplest  possible  command- 
language  would  consist  only  of  addresses,  but  no  such  language 
exists  because  our  minds  are  not  that  numerical!  Human  evolu- 

H.  T.  Gordon,  College  of  Natural  Resources,  University  of 
California,  Berkeley,  CA  94720. 


8 

6 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


tion  has  programmed  us  to  communicate  with  our  own  kind, 
first  with  sounds  and  gestures,  then  with  written  visual  equiva¬ 
lents,  then  (when  machines  entered  the  picture)  via  ASCII 
equivalents.  So  our  commands  to  a  machine  must  originate  in 
our  minds  as  sounds  or  pictures,  with  mnemonic  values  that 
guide  our  fingers  to  the  keys  of  the  correct  command -code. 

Most  commands  require  prior  entry  of  parameters  that  will 
be  used  by  the  command -execution  code.  This  entry  is  often 
done  under  control  of  implied  commands  within  the  interpreter. 
Bruce  Airy  perceived  that  commands  are  analogous  to  the  built- 
in  operation  codes  of  a  CPU,  and  that  parameters  are  akin  to  the 
machine-language  “operands.”  Some  commands  may  have  im¬ 
plied  parameters  (existing  within  the  execution-code),  and  (like 
complex  opcodes  such  as  INC)  also  imply  operation  of  more 
primitive  (i.e.,  simpler)  commands. 

The  great  creative  idea  in  FORTH  is  its  enhancement  of 
interpreter  logic  to  make  possible  the  construction  not  only  of 
new  “primitives,”  but  of  commands  that  consist  of  sequences  of 
such  primitives,  that  (like  a  machine- language  program)  can  be 
run  without  interruption.  Freeing  a  command- language  from 
the  restriction  of  single-step  execution  profoundly  influences 
its  development.  The  opcode -like  primitives  must  be  designed 
to  interact  in  sequence,  since  they  are  the  instruction  set  of  a  “vir¬ 
tual”  machine  that  is  being  emulated  on  a  simpler,  real  machine. 
The  program-like  complex  commands  require  the  high-level 
equivalent  of  a  CPU  program -counter,  and  also  branching  primi¬ 
tives  to  make  possible  loops  and  conditional  jumps. 

w 

T  T  hat  —  and  where  —  are  the  FORTH  primitives?  There 
is  a  universal  tendency  for  innovations  to  develop  a  special  jar¬ 
gon  either  of  neologisms  or  of  pre-existing  words  whose  meaning 
can  be  stretched  to  include  something  rather  different.  Since  a 
command-code  consists  of  one  or  more  ASCII  characters  (not 
including,  but  delimited  by,  spaces)  it  is,  in  some  sense,  a 
“word.”  The  command-set  is  therefore  like  a  vocabulary.  The 
list  in  which  the  command-codes  are  stored,  with  their  defini¬ 
tions,  has  some  nebulous  kinship  to  a  dictionary.  In  reality,  it  is 
a  unitary  file,  organized  as  a  linked  list  so  that  it  can  be  searched 
through.  The  basic  primitives  are  in  its  lower  region,  and  it  is 
extensible  at  its  high  end,  new  user- defined  commands  being 
appended  in  chronological  order.  The  structure  of  each  entry  in 
the  list  consists  of  a  uniform  “head,”  followed  by  a  “body” 
(definition)  determined  by  the  logic  of  the  “defining  word” 
primitive  used  to  construct  it.  The  body  of  every  primitive 
command  is  a  program  written  in  the  machine-code  of  the  CPU 
being  used  by  the  FORTH  system,  terminated  by  a  return  to 
whatever  control  program  in  the  “kernel”  happens  to  be  in 
charge.  The  kernel  machine- code  programs,  located  below  the 
dictionary  in  memory,  control  all  FORTH  operations. 

To  know  what  a  primitive  is,  one  must  know  the  dynamics 
of  its  construction.  New-command  construction  is  controlled 
by  the  text  (outer)  interpreter  program,  working  with  one  of 
the  defining-word  primitives.  The  command-code  for  building 
a  new  primitive  is  CODE  (followed  by  a  space  delimiter).  Con¬ 
trol  shifts  to  the  head- constructing  routine,  which  has  access  to 
two  16-bit  variables  in  the  kernel:  HEAD  and  DP,  the  addresses 
of  the  first  and  last  bytes  of  the  previous  entry.  The  routine 
expects  one  or  more  ASCII  characters  to  be  keyed,  to  be  the 
unique  name  (command- code)  of  the  new  command.  The  se¬ 


quence  is  stored  in  the  dictionary,  starting  at  location  DP+2. 
Keying  a  space  stops  the  routine.  The  number  (n)  of  characters 
is  stored  at  DP+1  (the  first  byte  of  the  new  head).  To  save 
space,  the  number  of  name- characters  is  truncated  to  only  the 
first  4.  I  suspect  that  some  versions  compress  these  into  2  hex 
bytes,  both  to  save  space  and  to  accelerate  a  dictionary -search. 
The  next  2  bytes  are  used  to  store  the  address  of  the  previous 
entry,  to  serve  as  a  link  during  a  dictionary-search.  The  search 
routine  always  starts  at  the  address  of  the  highest  (last)  entry 
(saved  in  HEAD),  and  if  the  value  of  n  does  not  match  that  of 
the  command- code  being  sought  it  uses  the  link  address  to  find 
and  test  the  next  lower  entry.  If  the  n  values  do  match,  the 
character- strings  are  compared.  This  means  that  names  such  as 
TEST1  and  TEST2  are  not  unique,  since  both  are  encoded  as 
5  TEST. 

In  Airy’s  NOVA  version,  the  byte  that  follows  the  4 
“name”  characters  stores  the  “precedence”  of  the  command  in 
its  2  low- order  bits  (the  other  6  presumably  set  to  zero).  So 
there  are  4  possible  precedence  states  (0,  1,  2,  or  3),  and  most 
commands  have  a  precedence  of  zero.  Within  the  kernel  is  a 
control  variable,  STATE.  A  command  will  be  executed  only  if 
its  precedence  is  equal  to  or  greater  than  STATE.  In  the  com¬ 
piler  mode,  STATE  is  set  to  2,  blocking  execution  of  commands 
with  a  lower  precedence  so  that  the  compiler  can  fetch  their 
execution- address  (required  for  the  construction  of  “program- 
like”  commands). 

Bruce  Airy’s  presentation  sometimes  falters,  forcing  me  to 
fall  back  on  personal  interpretation.  He  ignores  the  case  of  a 
single -character  name,  storable  in  a  single  byte.  I  see  no  reason 
not  to  do  this,  since  the  naming- routine  has  the  value  of  n  (in 
this  case,  1).  If  n  is  less  than  4,  it  can  calculate  the  storage  loca¬ 
tion  for  the  link  address  as  DP+3+n,  otherwise  as  DP+7.  A  more 
puzzling  element  in  Airy’s  version  of  the  head-construction  is 
his  storing  of  the  execution- address  in  the  2  bytes  following  the 
storing  of  the  link-address.  This  address  is  that  of  the  first  byte 
of  the  “body”  that  immediately  follows  it  and  contains  the 
logic  to  execute  the  command.  I  see  no  reason  why  this  logic 
should  not  immediately  follow  the  link -address,  since  its 
address  is  calculable  by  just  adding  2  to  the  algorithm  for 
calculating  the  location  of  the  link- address. 

The  construction  of  the  machine-language  body  of  the 
primitive  normally  requires  that  an  assembler  program  have 
been  temporarily  loaded  (unless  it’s  in  a  ROM).  I’ve  never  used 
an  assembler  (the  6502  instruction  set  being  being  so  simple). 
Were  I  to  adopt  FORTH,  I  would  probably  prefer  a  variant  of 
CODE  that  would  just  accept  a  sequence  of  hex  bytes.  The  pro¬ 
gram  executed  by  a  FORTH  primitive  ought  to  be  a  relatively  sim¬ 
ple  one  -  complexity  being  attained  by  weaving  primitives  to¬ 
gether  “in  FORTH.”  That,  after  all,  is  why  HLLs  were  invented. 

T 

he  role  of  the  “variables”  stack.  I  see  no  reason  why  the 
program  that  executes  a  primitive  should  not  make  use  of 
storage  locations  within  itself  (or  with  6800/6502  systems, 
zero- page  locations)  but  one  of  the  major  FORTH  conventions 
is  that  the  passing  of  parameters  between  primitives,  or  their 
initialization  by  user  keying-in,  always  involve  pushing  them 
onto  or  pulling  them  from  a  LIFO  (last  in,  first  out)  stack.  Most 
of  the  primitives  (cf.  the  Glossary,  Aug.  1980  BYTE,  p.  186) 
involve  stack-manipulations,  and  the  user  must  at  all  times  be 


9 

7 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


“The  simplest  possible  command 
language  would  consist  only  of 
addresses,  but  no  such  language 
exists  because  our  minds  are  not 
that  numerical!” 


aware  of  what  is  on  the  stack.  That’s  the  psychological  reason 
why  no  one  primitive  either  pushes  or  pulls  a  large  number  of 
variables!  The  FIG  version  of  FORTH  has  primitives  that  play 
with  as  many  as  the  3  most  recent  stack  entries. 

If  a  program  plays  with  a  variable  in  a  complex,  erratic  way, 
it  becomes  difficult  to  ensure  that  it  will  appear  on  TOS  (the 
acronym  for  top-of-stack)  exactly  at  the  right  moment.  This 
problem  is  solved  by  giving  it  a  name  (declaring,  i.e.,  creating, 
a  unique  storage  location  for  it),  using  the  defining- word 
VARIABLE.  Like  all  defining- words,  this  expects  keying-in 
of  a  unique  ASCII  name  and  creates  a  new  dictionary- entry 
with  the  standard  head.  The  body,  however,  causes  execution  of 
machine-code  (within  the  VARIABLE  primitive)  whose  func¬ 
tion  is  to  put  the  address  of  a  2-byte  storage  location  within 
the  body  of  the  new  entry  onto  the  stack.  That’s  what  keying  in 
the  new  name  (say  XVAL)  will  cause.  To  initialize  the  XVAL 
storage- location,  one  must  key  in  a  sequence  of  3  commands, 
e.g.,  17  XVAL  !  The  17  (or  any  other  number)  will  be  inter¬ 
preted  as  a  command  to  push  it  on  the  stack.  XVAL  pushes  its 
storage- address  on  the  stack.  The  !  primitive  causes  17  to  be 
stored  in  the  XVAL  location,  and  clears  both  address  and  num¬ 
ber  from  the  stack.  To  push  the  number  currently  stored  back 
on  the  stack,  one  keys  in  XVAL  @.  The  @  primitive  fetches  the 
number  located  at  the  address  that  XVAL  has  put  on  the  stack, 
and  replaces  the  address  on  the  stack  by  that  number. 

Some  readers  will  wonder  (as  I  did)  how  any  number 
implies  a  command  to  push  it  on  the  stack.  The  FORTH  inter¬ 
preter  doesn’t  “know”  that  a  sequence  of  ASCII  numerical 
characters  is  a  number.  It  first  searches  through  the  dictionary 
to  see  if  it’s  a  command- code,  but  it’s  not  (or  ought  not  to  be). 
When  the  search  is  exhausted,  control  shifts  to  the  NUMBER 
program  in  the  kernel,  which  tests  to  see  if  it’s  a  valid  number  in 
whatever  BASE  (decimal,  hex,  or  what  have  you)  has  been  de¬ 
clared.  If  it  is,  it’s  pushed  on  the  stack  (otherwise,  error- 
message).  Sometimes,  the  same  number  will  be  needed  repeated¬ 
ly  in  a  program,  so  to  ease  the  burden  on  human  memory  it  is 
given  a  name,  by  using  the  defining-word  CONSTANT.  The 
sequence  73518  CONSTANT  FACTOR  will  create  a  new  dic¬ 
tionary  entry,  differing  from  VARIABLE  in  that  the  execution 
logic  will  push  the  number  73518  on  the  stack  whenever  the 
command  FACTOR  is  keyed-in.  Unless  this  number  has  been 
carefully  chosen  because  it  is  a  valid  address  of  a  RAM  storage 
location  (it  usually  isn’t,  but  could  be),  primitives  like  @  and  ! 
will  only  wreck  the  operation  -  certainly  they  can’t  alter  the 
numerical  value  stored  in  the  body  of  FACTOR.  Still,  using  a 
constant  to  push  a  base-address  onto  the  stack  would  allow 
adding  a  number  to  it  to  provide  something  like  indexable 
access  to  a  table  in  memory. 

I  shall  not  discuss  the  operation  of  the  long  list  of  primi¬ 
tives,  or  the  deeper  question:  are  these  now  an  optimal  macro- 
instruction  set?  That  needs  a  lot  of  thought.  My  critique  of 
the  instruction  sets  of  several  microprocessors  ( Microcomput¬ 
ing,  #39  and  #40,  1980)  was  based  on  two  years  of  study, 
while  this  note  is  only  a  preliminary,  superficial  exploration  of 
FORTH. 


r 

y  onstruction  and  execution  of  program-like  commands. 
The  great  creative  idea  in  FORTH  is  its  design  of  high-level 


10 

8 


commands  that  can,  without  interruption,  run  a  sequence  of 
(ultimately)  primitive  commands.  The  :  defining-word  (colon 
command)  controls  the  construction  process.  It  expects  a  new 
ASCII  name  and  creates  a  dictionary-entry  head  in  the  usual 
way,  but  the  body  is  utterly  different.  Not  machine- code, 
but  primarily  a  sequence  of  addresses  of  commands  that  exist  in 
the  dictionary.  This  is  not  what  the  user  is  keying- in  at  all, 
but  a  compilation  of  the  source- code  that  is  being  keyed- in. 
This  code  is  human-level  (or  as  close  as  FORTH  ever  gets  to  it!) 
and  consists  of  a  sequence  of  command-names  and  numbers, 
delimited  by  spaces.  During  compilation  the  STATE  variable 
is  reset  (to  2  in  the  Airy  version)  in  order  to  block  execution  of 
most  of  the  keyed-in  commands,  except  for  a  handful  of  “com¬ 
piler  imperative”  primitives  that  have  a  precedence  of  2  or  3. 
The  first  element  in  the  body  is  the  address  of  the  :  primitive, 
that  will  (when  STATE  =  0,  allowing  the  high-level  command  to 
run  when  its  name  is  keyed-in)  cause  the  address  (inner)  inter¬ 
preter  in  the  kernel  to  control  execution.  When  the  user  has 
keyed-in  the  first  “word,”  the  space  delimiter  causes  the 
compiler  to  search  the  dictionary  to  see  if  it’s  a  known  com¬ 
mand.  If  it  is,  and  its  precedence  is  less  than  2,  the  compiler 
adds  its  execution-address  to  the  body  of  the  new  entry.  If  it’s 
not,  but  it  is  a  valid  number,  the  compiler  adds  the  address  of 
the  LIT  primitive  to  the  sequence,  and  then  adds  the  numerical 
value  to  the  sequence.  When  LIT  logic  is  eventually  executed,  it 
will  push  the  numerical  value  that  follows  it  in  the  sequence 
onto  the  stack,  and  increment  the  “command-counter”  of  the 
address- interpreter  so  that  the  numerical  value  will  be  skipped. 
Construction  of  the  high-level  command  is  terminated  by 
keying-in  the  ;  primitive.  This  semi-colon  command  is  a 
compiler-imperative.  Its  execution  first  adds  the  ;  execution- 
address  to  the  new  body  (in  the  run  state,  it  will  act  as  a  termi¬ 
nator  of  the  address-interpreter  operation)  and  returns  control 
to  the  text- interpreter. 

FORTH  has  a  great  variety  of  primitives  which,  when  in¬ 
serted  in  its  colon- programs,  are  the  equivalent  of  branch  or 
jump  instructions  in  assembly  languages.  Some  are  conditional, 
so  the  equivalent  of  a  status  register  might  be  expected.  To  my 
surprise,  this  proved  to  be  rudimentary  when  compared  to  the 
status  register  of  microprocessors.  Status  can  only  be  false 
(zero)  or  true  (non- zero),  and  these  numerical  values  must  be 
on  TOS  when  the  conditional-branch  primitive  is  executed. 
Perhaps  this  reflects  the  somewhat  infantile  state  of  the  CPUs 
and  HLLs  existing  at  the  time  FORTH  was  invented.  To  my 
mind,  it  does  not  justify  the  belief  of  Charles  Moore  (in  his 
BYTE  article)  that  FORTH  is  now  so  close  to  perfection  that  it 
can  be  standardized. 

There  are  4  types  of  repetitive -looping  constructs.  Two  of 
them  are  somewhat  like  FORTRAN  DO-loops.  Both  are  initi¬ 
ated  by  the  DO  primitive,  whose  function  is  to  store  3  items  of 
information  for  eventual  use  by  a  matching  LOOP  or  +LOOP 
later  in  the  sequence.  The  first  2  are  indexing- range  numbers, 
integers  that  I  think  of  as  Endex  and  Index,  that  normally  im¬ 
mediately  precede  the  DO  (e.g.,  Endex  Index  DO)  and  will 
therefore  be  pushed  onto  the  stack  by  LIT  primitives.  The  third 
is  the  return-address  of  the  DO,  available  in  the  command- 
counter  (the  equivalent  of  a  CPU  program -counter)  at  the 
execution- time  of  the  t)0.  In  principle,  this  could  be  “remem¬ 
bered”  by  also  pushing  it  onto  the  variables  stack,  since  the 
logic  of  the  repeating- sequence  ought  to  keep  this  balanced  to 
prevent  an  excess  of  pushes  or  pulls  from  “blowing  up”  the 
stack.  However,  FORTH  creates  a  specialized  return-stack  for 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


“The  program  executed  by  a 
FORTH  primitive  ought  to  be  a 
relatively  simple  one  -  complexity 
being  attained  by  weaving  primi¬ 
tives  together . . 


the  parameters  used  by  its  control  primitives.  Execution  of  the 
DO  pulls  Index  from  the  variables  stack  and  pushes  it  onto  the 
return-stack,  then  pulls  Endex  and  puts  it  on  the  return-stack, 
and  finally  pushes  the  DO  return- address  onto  the  return- stack. 
When  the  matching  LOOP  primitive  is  executed,  its  logic  incre¬ 
ments  Index  and  compares  it  with  Endex.  If  Endex  is  greater,  it 
resets  the  command -counter  to  the  DO  return- address.  Since 
the  counter  auto-increments,  execution  of  the  sequence  im¬ 
mediately  following  the  DO  is  repeated.  If  Endex  is  not  greater, 
the  information  on  the  return-stack  is  no  longer  needed,  so  it  is 
cleared  (I  presume  by  resetting  the  return-stack  pointer)  and 
the  command-counter  auto- increments  to  execute  the  sequence 
following  LOOP.  The  +LOOP  primitive  expects  to  find  an  inte¬ 
ger  (2  or  higher)  on  TOS,  pulls  it  and  adds  it  to  Index,  then 
works  like  LOOP. 

An  inner  LOOP  can  be  nested  within  an  outer  one,  but  its 
DO  requires  its  own  matching  LOOP  as  well  as  its  own  index- 
range  parameters.  This  ensures  that  the  inner  LOOP  will  be  com¬ 
pleted,  and  its  information  cleared  from  the  return-stack,  be¬ 
fore  the  outer  LOOP  is  reached. 

A  special  primitive,  I,  when  inserted  in  the  within-loop  se¬ 
quence,  causes  the  current  value  of  Index  to  be  read  and  pushed 
on  the  stack.  The  return- stack  differs  from  the  variables  stack 
in  that  information  on  it  is  much  more  often  read  than  sub¬ 
jected  to  the  flux  of  pushes  and  pulls  characteristic  of  the  varia¬ 
bles  stack.  The  FIG  version  of  FORTH  has  primitives  that  allow 
the  programmer  to  push,  pull,  or  copy  information  using  the 
return-stack  —  but  wisely  advises  caution  since  unbalancing  it 
spells  disaster!  This  suggests  that  memory-management  can  be  a 
problem.  The  FORTH  environment  defines  3  storage- areas  in 
memory:  the  2  stacks  (which  must  be  kept  more-or-less 
balanced),  and  the  so-far-unused  area  at  the  high  end  of  the  dic¬ 
tionary.  I  suspect  that  primitives  will  in  time  be  created  to  ex¬ 
ploit  the  last  —  simpler  than  creating  one  more  storage  area  for 
the  programmer  to  keep  in  mind. 

There  are  also  two  types  of  “indefinite”  loops.  Escape 
from  these  requires  that  a  generator- logic  sequence  terminate 
by  pushing  a  true  (non- zero)  status  onto  the  variables  stack. 
Both  are  initiated  by  the  BEGIN  compiler- imperative,  that 
causes  the  compiler  to  push  the  return- address  (current  address 
in  the  sequence  being  compiled)  onto  the  variables  stack.  Since 
the  execution-address  of  an  imperative  is  not  itself  compiled 
(i.e.,  added  to  the  sequence),  the  return-address  will  actually  be 
that  of  the  next  program  word  after  BEGIN,  the  BEGIN  causing 
no  increment  of  the  command- counter  and  so  “vanishing”  from 
the  program.  In  the  simpler  version  of  this  type  of  loop,  there 
must  be  a  matching  END  (re-named  UNTIL  by  the  FIG)  that 
will  decide  to  repeat  or  escape  from  the  loop.  END  is  also  an 
imperative.  It  first  compiles  the  execution- address  of  the  SKIP? 
primitive,  then  pulls  the  return- address  from  the  stack  and  com¬ 
piles  it.  During  execution,  the  SKIP?  pulls  the  “status”  left  on 
TOS  by  the  preceding  decision- generating  logic.  If  it  is  zero 
(false),  it  resets  the  command -counter  to  the  return  address 
that  follows  it  in  the  sequence.  If  non-zero  (true),  it  causes  the 
command- counter  to  skip  the  return-address  and  move  on  to 
the  post-END  sequence. 

The  more  complex  loop  is  required  when  the  decision- logic 
must  (if  false)  be  followed  by  error- correction  logic,  that  must 
always  return  to  the  decision  logic  sequence  to  see  if  the  correc¬ 
tion  has  worked.  If  it  has  (status  becomes  true),  the  correction 
logic  must  be  by-passed  in  escaping  from  the  loop.  The  BEGIN 


works  as  before,  leaving  the  address  of  the  start  of  the  decision 
logic  on  the  stack.  At  the  point  where  the  true- or- false  status  is 
pushed  on  the  stack,  an  IF  (renamed  WHILE  by  the  FIG)  is  in¬ 
serted.  This  imperative  compiles  a  SKIP?,  but  unlike  END  it 
does  not  pull  the  BEGIN  return- address.  Instead,  it  pushes  its 
own  current  address  on  the  variables  stack,  and  causes  the  com¬ 
piler  to  leave  the  address-location  following  the  SKIP?  vacant. 
The  correction  logic  is  then  written,  and  terminated  by  an 
AGAIN  (REPEAT  in  FIG).  This  imperative  compiles  the  SKIP 
unconditional-jump.  It  uses  the  address  left  on  the  stack  by  the 
IF  to  store  the  correct  SKIP?  jump- address  (that  of  the  start 
of  the  post -AGAIN  logic  to  be  run  where  escape  from  the  loop 
occurs).  It  then  pulls  the  BEGIN  return-address  and  compiles  it 
following  its  SKIP.  Like  the  indexed  DO  loops,  the  indefinite 
loops  can  be  nested,  but  each  BEGIN  needs  its  own  END  (or 
WHILE .  . .  REPEAT)  to  allow  escape  from  an  inner  loop 
before  re-entry  into  an  outer  one. 

The  . . .  IF  .  .  .  ELSE  .  . .  THEN  (ENDIF  in  FIG)  construct 
allows  non-loop  branching.  If  the  pre-IF  decision  logic  is  true, 
the  post-IF  sequence  is  run.  The  ELSE  is  optional,  required 
only  if  the  false  condition  needs  special  execution  logic,  but 
every  IF  must  have  its  own  THEN.  As  before,  the  IF  compiles 
the  SKIP?  address,  creates  a  vacancy  for  the  as-yet-unknown 
jump-address,  and  pushes  its  own  address  on  the  stack  so  that 
a  subsequent  imperative  will  be  able  to  fill  it.  If  that  is  an  ELSE, 
the  correct  SKIP?  address  is  that  of  the  post-ELSE,  false  logic. 
The  ELSE  inserts  this,  using  the  address  left  on  the  stack  by  the 
IF.  ELSE  then  compiles  a  SKIP,  but  leaves  the  jump  address 
vacant,  pushing  its  own  address  on  the  stack  for  use  by  the  (in¬ 
evitable)  THEN.  All  that  the  THEN  has  to  do  is  fill  the  vacant 
location  with  the  address  of  the  post-THEN  logic,  leaving  no 
other  trace  of  its  passage.  If  there  was  no  ELSE,  its  operation 
will  fill  the  still-vacant  jump-address  of  the  SKIP?  compiled  by 
the  IF.  Like  the  BEGIN,  the  THEN  exists  only  in  the  source 
code,  not  the  program,  since  the  only  function  is  to  provide 
address-information  during  compilation. 

These  constructs  are  extraordinarily  simple  when  compared 
with  the  intricacy  of  branching  possible  with  assembly  langauge. 
Their  rigidity  is  the  reason  why  FORTHians  can  point  with 
pride  to  the  structured  programming  quality  of  FORTH,  with¬ 
out  saying  what  is  being  traded-off  for  it.  But  the  user- 
extensibility  would  allow  a  programmer  to  do  some  interesting 
destructuring! 

A 

X  _*Ln  elementary  —  but  complexly  motivated  —  example. 

The  generation  of  the  Fibonacci  number  sequence  is  a  very  sim¬ 
ple  task.  The  first  two  numbers  are  both  ones,  and  each  successive 
number  is  the  sum  of  the  preceding  two  numbers.  It’s  one  of 
many  algorithms  useful  to  reveal  how  different  HLLs  work.  My 
reason  for  writing  it  in  FORTH  is  historic.  While  I  was  talking 
to  a  friend  who  had  acquired  FORTH  and  was  demonstrating  it 
on  his  PET,  a  bystander  asked  him  to  generate  the  first  10 
Fibonacci  numbers,  saying  it  was  easy  to  do  in  BASIC.  It  can’t 
be  difficult  in  any  HLL!  Yet  my  friend’s  coding  of  it  failed  to 
give  the  correct  sequence.  I  now  realize  that  he  had  not  yet 
mastered  the  visualization  of  the  stack  parameters  that  is  the 
sine  qua  non  for  writing  FORTH. 

In  the  listings  is  my  “easy”  program  -  untested  since  I 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


11 

9 


“To  my  mind,  [this]  does  not 
justify  the  belief . . .  that  FORTH 
is  now  so  close  to  perfection  that 
it  can  be  standardized.’’ 


do  not  have  a  FORTH  system.  The  first  line  has  it  in  typical 
FORTHian,  uncommented  format.  It  ought  to  be  somewhat 
intelligible  if  my  earlier  explanantions  were  instructive. 
However,  the  listing  then  reiterates  it  in  something  like  an 
assembler  format,  with  comments,  anything  within  parentheses 
being  ignored  by  the  FORTH  interpreter.  This  is  followed  by 
program -execution  and  output. 

My  commented  version  illustrates  why  FORTHians  tend  to 
avoid  comment.  Note  that  I  have  three  “multiple-words”  that  I 
see  as  complex -commands  with  an  inherent  unity,  described  in 
the  parenthetic  statement  to  the  right.  Some  words  are  also  pro¬ 
vided  with  location-identifiers  at  the  left.  All  this  is  very  tenta¬ 
tive!  Of  greater  interest  are  novel  conventions  to  identify  stack 
locations  and  operations.  S0  is  the  first  “free”  location,  and  a 
push  into  it  is  -*  S0.  Sj  is  the  location  above  S0,  S2  above  Sj, 
etc.  The  operation  -*■  S0  causes  what  was  the  So  location  to 
become  Sj  (and  so  automatically  alters  the  numbering  of  the 
absolute  locations  that  were  previously  S1;  S2,  etc.).  When  one 
or  more  filled  stack  locations  are  pulled,  this  is  denoted  by 
brackets.  The  primitive  DROP,  that  just  pulls  the  TOS  without 
using  it,  would  be  commented  as  ( [  S 2  ]  ),  causing  the  previous 
Sj  location  to  become  the  new  S0,  with  corresponding  altera¬ 
tion  of  the  previous  S2  to  S x ,  etc.  Note  the  more  complex  effect 
of  the  +  primitive  in  the  FIBO  program.  This  kind  of  stack  nota¬ 
tion  may  be  more  helpful  in  keeping  track  of  the  status  than 
that  used  in  FIG  FORTH.  For  example,  their  comment  of  the 
OVER  primitive  is  (nj  n2  -*■  nj  n2  n,)  instead  of  my  (S2  -*•  S0), 
and  DUP  is  (n  n  n)  instead  of  my  (Sj  -»•  S0).  Note  also  that 
I  simplify  the  comment  of  the  immediately -interacting  pair 
DUP.  to  its  overall  effect  (print  S  x ),  to  avoid  the  confusion  of 
(S,  ->  S0,  print  [S,  ]  ). 

FORTHians  may  object  to  the  space-wasting  complexity  of 
such  a  commented  format,  and  anti-FORTHians  may  still  claim 
that  it’s  not  intelligible  enough.  All  I  can  say  is  that,  since 
FORTH  is  a  kind  of  high-level  assembly -language,  that  may  be 
as  intelligible  as  it  can  ever  get. 

As  to  space- wasting,  look  at  the  output!  Perhaps  an  expert 
could  use  the  primitives  to  write  FIBO  so  as  to  format  more 
efficiently.  Of  course,  one  could  create  a  new  type  of  output 
command  to  do  anything  one  likes.  But  then,  the  beautiful 
simplicity  begins  to  erode!  Something  like  this  seems  to  be 
transmogrifying,  the  (relatively)  simple  C  language  little-by¬ 
little  into  a  more  powerful  (but  less  easy)  D. 

Something  more  fundamental  comes  to  mind  if  we  note  the 
similarity  between  DUP  (Sj  -*■  S0)  and  OVER  (S2  -*■  S0).  There 
may  be  (and  surely  could  be)  similarities  in  the  machine  code  of 
these  primitives,  that  might  be  generalized  to  cases  like  (S3  -*■ 
S0),  (S4  -*■  S0),  and  perhaps  even  to  (S3  -*■  Si).  Analogously, 
exchanges  of  the  SWAP  type  might  be  generalized  to  include 
operations  such  as  (S3  <-»  St).  Conservative  counterarguments 
to  this  might  be  (1)  these  operations  are  not  useful,  (2)  if  ever 
needed,  they  can  be  emulated  by  sequences  of  existing  primi¬ 
tives,  (3)  they  would  strain  the  memory  of  programmers,  and 
(4)  their  addition  would  strain  the  memory  of  the  FORTH 
dictionary.  Similar  arguments  exist  for  limiting  the  complexity 
of  microprocessor  instruction  sets.  Since  these  get  larger  in  suc¬ 
cessive  generations,  the  validity  of  the  small-is-beautiful  argu¬ 
ments  is  open  to  question! 

As  to  (1),  some  operations  are  more  often  used,  and  some 
may  be  more  useful  than  others,  but  I  doubt  that  any  are 
useless.  (2)  It’s  nice  to  kill  several  birds  with  one  stone.  (3)  Re¬ 
member  and  use  only  the  subset  you  prefer,  as  the  users  of  a 


complex  assembly -language  often  do.  (4)  Not  necessarily. 
Complexity  can  be  achieved  in  three  ways:  by  accretions,  which 
lead  to  elephantine  bulk,  by  innovative  combinations,  or  by 
metamorphoses  to  a  higher  level  of  deep  structure  and  under¬ 
standing.  Examples  of  all  these  could  be  drawn  from  the  evolu¬ 
tion  of  many  HLLs,  as  well  as  of  microprocessors  (e.g.,  the  6502 
set  is  smaller  and  came  much  later  than  the  8080,  but  is  not  less 
powerful).  However,  I  shall  explore  the  possibilites  in  FORTH. 

To  implement  a  generalized  operation  of  the  type  (S„  -> 
S0)  means  replacing  two  primitives  (DUP  and  OVER)  by  a 
single  SPUSH,  that  requires  the  value  of  n  to  locate  Sn.  A  more 
general  form  like  (Sn  -*■  Sm)  would  need  2  parameters,  and 
perhaps  more  complex  logic.  The  simpler  version  (implying  that 
m  =  0)  might  expect  n  on  TOS  (St)  at  execution,  pulling  it  to 
use  as  an  index  for  its  logic.  So  the  price  for  its  power  to  do 
many  operations  is  that  each  would  be  a  sequence  of  n  SPUSH 
—  two  commands  and  a  longer,  slower-running  program.  The 
gains  would  be  a  minimizing  of  dictionary  primitives,  probably 
some  coding  economy,  possibly  some  reduction  in  strain  on  pro¬ 
grammer  memory.  That’s  the  “combinations”  concept,  not  too 
unlike  the  DO. 

M 

.X.  ▼  M  etamorphic  changes  in  information -transfer  by  con¬ 
catenations  of  characters.  The  word  metamorphosis  means  a  dras¬ 
tic  change  to  a  higher  level  of  complexity.  It  can  occur  anywhere. 
Although  it  is  relatively  rare,  many  books  have  been  written 
about  specific  instances  of  it,  and  even  a  few  on  the  phenome¬ 
non  in  general.  The  instance  I  hope  to  develop  in  this  section  is 
the  class  of  picture-symbols  we  call  characters.  Like  all  symbols, 
they  are  an  arbitrary  representation  of  a  packet  of  information 
that  will  be  transferred  from  a  generator -transmitter  system 
to  a  receptor-interpreter  system.  Chinese  characters  represent 
a  word,  itself  a  symbol.  So  do  many  of  our  characters  (like  +  or 
=),  while  others  signify  sounds  (e,  z).  Where  we  differ  from  the 
Chinese  is  our  use  of  concatenations  of  a  small  character-set  to 
create  complex  symbols,  while  they  have  expanded  their 
character-set  to  immense  size  and  complexity. 

There  has  been  a  tendency  (Zipfs  “law”)  for  often-used 
words  to  become  relatively  short  (monosyllabic),  and  so  they 
can  be  written  as  a  string  of  a  few  characters.  Otherwise,  the 
human  brain  seems  to  have  been  unconcerned  about  the  ef- 
fiency  of  information-transfer.  Possible  words  (like  “gevi”  or 
“miro”)  go  unused  in  English.  There  are  some  gestures  toward 
economy,  like  the  plural  suffix  “s”  or  the  occasional  use  of  the 
negator  Latin  prefix  “un”  (though  we  prefer  “bad”  to 
“ungood,”  and  “not  bad”  is  not  the  semantic  equal  of  “good,” 
while  “untrue,”  “not  true”  and  “false”  have  much  the  same 
meaning).  Tolerance  of  linguistic  inefficiency  and  inconsistency 
is  the  sign  of  a  very  complex  interpreter.  No  interpreting 
machine  can  be  so  powerful  (that’s  why  I  believe  that  artificial 
intelligence  must  differ  from  human  intelligence). 

The  dilemma  of  every  HLL  is  that  it  must  be  comprehen¬ 
sible  to  both  human  and  a  machine  interpreter,  a  bridging  com¬ 
promise  between  extremely  different  systems.  Hex  or  octal 
notations  are  close  to  the  machine,  while  assembly  language  gets 
nearer  the  human  level.  All  HLLs  are  at  a  higher  level  of  sym¬ 
bolic  complexity.  Some  (LISP,  or  FORTH)  rise  little  above  the 
assembly -language  level,  though  modifications  (SNOBOL4,  and 
perhaps  STOIC)  may  improve  intelligibility.  Others  (BASIC,  or 
Pascal)  make  greater  concessions  to  the  human  interpreter. 


12 

10 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


“Increasing  power  —  with  retention 
of  compatability  and  human- 
intelligibility,  and  without  expo¬ 
nential  rises  in  interpreter  size  and 
complexity  -  demands  nothing  less 
than  genius.” 


The  price  of  this  trade-off  is  high.  First,  these  require  a  more  com¬ 
plex  machine  interpreter,  over  which  the  user  has  no  control. 
Only  experts  can  enhance  it.  Increasing  power  -  with  retention 
of  compatibility  and  human -intelligibility,  and  without  expo¬ 
nential  rises  in  interpreter  size  and  complexity  —  demands 
nothing  less  than  genius.  Second,  and  the  consequence  of  the 
first,  as  they  approach  immutability,  there  will  be  a  tendency  to 
assume  that  nothing  better  is  possible  or  needed.  Limitations 
will  not  be  seen,  or  if  seen  will  be  thought  of  as  insuperables  (as 
we  now  see  the  limiting  velocity  of  light).  Third,  the  great  com¬ 
plexity  and  specialization  will  lower  the  probability  of  meta- 
morphic  change. 

All  this  pleading  for  retaining  machine-interpreter  simpli¬ 
city  has  been  a  prologue  for  a  possibly  metamorphic  change  in 
the  FORTH  command -coding.  Bruce  Airy  did  not  push  his 
analogy  with  CPU  structure  down  to  the  bit-level.  However, 
‘if  a  FORTH  command-code  is  the  analog  of  an  opcode,  each 
character  of  the  code  is  the  analog  of  a  bit.  The  genii  who  de¬ 
sign  CPUs  have  learned  how  to  cause  a  very  small  number  of  bits 
to  control  very  complex  operations.  Since  this  complexity  is  not 
in  the  opcode  bit -pattern,  it  has  to  be  created  by  intricate  (but 
highly  efficient!)  switching  networks  in  the  interpreting  control- 
unit.  The  information  in  the  opcode  bit-pattern  is  used  with  an 
inhumanly-optimal  efficiency.  Can  something  like  this  be 
approximated  for  the  information  in  a  command -code? 

The  execution -logic  requires  parameters.  Some  are  trans¬ 
ferred  to  it  (via  the  stack)  by  previous  commands.  Others  are 
implied,  residing  in  the  logic  itself.  Thus,  the  OVER  command 
has  no  indication  within  its  4  characters  of  the  parameters  used 
to  execute  (S2  So).  Why  not?  Consider  the  possible 
command-code  ?S20,  where  ?  is  intended  to  signal  an  unusual 
operation  to  the  FORTH  interpreter,  S  acts  as  a  human- 
mnemonic  of  a  stack  operation,  and  the  numbers  specify  stack 
locations  to  be  used  by  the  S  execution-logic.  This  code 
structure  —  if  it  can  be  rightly  machine-interpreted  —  allows 
great  generality.  DUP  would  be  replaced  by  ?S  1 0,  and  presently 
non-existant  analogs  such  as  ?S30,  ?S70,  etc.,  will  work. 
Furthermore,  the  execution  logic  could  recognize  that  a 
non-zero  value  for  the  second  parameter  means  an  exchange 
instead  of  a  copy  into  S0.  The  existing  SWAP  would  become 
?S21.  Or,  going  deeper  into  complexity,  ?S21  could  be  executed 
as  (S2  -*•  Si),  while  ?S  1 2  would  command  a  SWAP  (S2  «-►  S2). 
The  goal  is  to  maximize  the  information  content  in  the 
command -code.  Since  one  can  play  with  stack  locations  from 
S0  to  S9 ,  a  very  large  number  of  distinct  (though  similar) 
operations  become  possible. 

Since  existing  interpreter  logic  would  see  all  these  variants 
as  completely  different  words,  it  would  have  to  be  taught  that 
commands  of  the  type  ?SXY  (where  X  and  Y  are  different  deci¬ 
mal  digits)  require  special  handling!  In  fact,  one  can  imagine  a 
whole  class  of  codes  starting  with  a  ?  but  with  characters  other 
than  the  S  to  cause  execution  of  quite  different  logic  to  use  X 
and  Y,  even  using  XY  as  a  2 -digit  number  if  only  one  parameter 
(but  a  greater  range)  is  needed.  Existing  FORTH  suggests  that 
implementation  is  feasible,  since  its  compiler-imperatives  don’t 
work  like  other  commands.  I  am  not  concerned  here  with  imple¬ 
mentation  detail,  but  with  the  concept  of  making  command- 
codes  as  information-rich  as  opcodes.  Complexity  is  ultimately 
essential.  Existing  FORTH  puts  it  in  its  dictionary  and  its  pro¬ 
grams.  Why  not  put  whatever  you  can  in  a  more  powerful 
kernel? 

While  the  above  change  begins  to  break  the  ice  of  the  now- 


frozen  command -coding,  true  metamorphosis  means  exploiting 
an  innovation  all  the  way  to  its  extreme  limits.  What  would  the 
seemingly  senseless  command  ?S11  signify?  Why  not  the  exist¬ 
ing  DROP,  that  in  my  new  notation  is  ([Si])?  By  extension, 
?S22  would  be  a  DROP  of  S2,  etc.,  reorganizing  the  stack  to 
erase  any  one  of  the  9  specifiable  locations.  This  still  leaves 
structures  like  ?S02,  that  might  be  interpreted  as  a  DROP  of 
(1S2,S,  ]),  i.e.,  more  than  one  location.  The  meaningless  ?S00 
could  be  interpreted  like  the  existing  R  command,  copying  the 
top  of  the  return-stack  into  S0.  However,  the  details  of  inter¬ 
pretation  cannot  be  made  specific  at  the  germinal-idea  stage. 
The  machine -code  of  the  parametrized  ?SXY  primitive  would 
be  a  complex,  optimizable  stack-manipulation.  Its  realistic 
limits  would  be  revealed  only  during  its  creation,  and  act  as  a 
guide  to  optimal  XY  interpretations.  Equally  important  would 
be  the  views  of  the  designer  concerning  the  options  likely  to  be 
most  frequently  needed,  influenced  by  the  potential  mnemonic 
value  to  the  user. 

During  compilation,  a  ?SXY  would  first  put  the  execution- 
address  of  the  machine-code  in  the  sequence,  then  the  numeri¬ 
cal  XY  perhaps  compressed  into  a  single  byte,  in  any  event  not 
needing  more  than  one  location  (like  the  IF,  ELSE,  and  LOOP). 
This  is  a  significant  compression  by  comparison  with  the 
combinations  approach,  which  would  have  to  compile  2  LITs 
and  their  numerics,  then  the  address  of  S  stack-manipulation 
code,  that  would  be  more  complex  since  it  would  have  to  pull 
the  parameters  from  the  stack. 

We  are  not  yet  at  the  metamorphic  limit!  What  of  the  infor¬ 
mation  content  in  the  S  character?  It’s  true  that  a  minimum  of 
one  character  is  needed  to  find  the  execution-address  of  the 
stack -manipulation  machine-code.  But  we  have  so  far  ignored 
the  stack -rotation  FORTH  primitive,  ROT,  that  in  my  notation 
is  (S3  -*•  S]  -*•  S2  -*■  S3 )  linearly  representing  a  “circular”  move. 
Note  that  “counter-rotation”  like  (Si  -*■  S3  -*•  S2  -*■  Si)  is  also 
conceivable,  though  it  has  no  primitive  in  existing  FORTH,  and 
that  the  concept  is  extensible  to  more  than  three  contiguous 
locations.  It  is  impossible  to  decide  a  priori  to  what  extent  the 
machine-logic  could  be  shared  with  that  of  the  ?SXY  opera¬ 
tions.  In  any  case,  the  limits  of  existing  FORTH  command¬ 
naming  seem  to  demand  a  separate  dictionary  entry.  If  this 
were  ?RXY,  the  ASCII  numeric  equivalent  of  R  is  52,  and  of  S 
53.  The  R  logic  might  enter  the  S  logic  with  the  low-nibble  2 
“in  its  teeth”  to  modify  interpretation  to  a  rotation.  E.g.,  ?R3 1 
would  replace  the  existing  ROT,  ?R13  would  signify  its  reversed 
version,  etc.  Needs  much  thought!  Complexity  is  being  shifted 
into  the  machine-logic  of  fewer  (but  more  information-rich) 
commands,  lowering  the  requirement  for  complex  sequences  of 
a  larger  number  of  simple  commands.  The  ROT  must  have  been 
created  for  that  very  reason. 

FORTH-like  languages  are  still  far  below  their  potential 
evolutionary  peak.  Like  other  HLLs,  FORTH  came  to  life  with¬ 
in  one  highly  creative  mind.  Although  he  asserts  that  it  “has 
been  honed  against  the  rock  of  experience,”  it  has  not  yet  been 
tempered  in  the  fire  of  other  creative  minds.  One  sign  that  they 
are  interested  is  the  article  by  the  Motorola  designers  Ritter  and 
Walker  on  “threaded -code”  ( BYTE  Sept.  1980  p.  206),  recog¬ 
nizing  how  HLLs  may  become  similar  at  the  intermediate -code 
level  and  that  it’s  there  one  might  optimize  a  microprocessor  to 
serve  more  than  one  HLL.  I  also  expect  a  major  impact  on  HLLs 
by  the  Japanese,  with  their  utterly  different  spoken  and  written 
language.  The  non-Englishy  quality  of  FORTH  may  prove  to  be 
an  advantage  at  the  international  level. 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


13 

ii 


“I  am  . . .  concerned  .  . .  with  the 
concept  of  making  command -codes 
as  information -rich  as  opcodes.” 


FORTH  ready  for  widespread  usage?  I  start  by  conceding 
that  the  preceding  remarks  are  amateurish.  A  few  weeks  of 
study  do  not  suffice  to  make  anyone  an  authority  on  a  subject 
so  complex!  Perceptive  readers  will  have  noticed  that  my  views 
underwent  subtle  change  as  my  understanding  gradually 
improved.  My  present  feeling  is  that  existing  FORTH  is  not 
ready  for  use  by  novices.  Charles  Moore  concedes  ( BYTE  Aug. 
1980  p.  76)  that  it  is  more  “sensitive  to  the  quality  of  the  pro¬ 
grammer”  than  are  BASIC  and  FORTRAN,  and  that  it  is  possi¬ 
ble  (I  would  say  easy)  to  write  “very  bad  FORTH  code.”  Even  a 
program  as  simple  as  my  FIBO  example  (that  I  hope  is  good 
FORTH  code!)  lays  considerable  stress  on  the  intelligence  of  the 
programmer.  Stack -manipulation  is  trickier  than  using  the 
fixed -location  registers  of  a  CPU  (especially  a  simple  one  like 
the  6502).  The  action  caused  by  a  command-code  primitive  is 
less  intelligible  than  that  of  most  assembler  mnemonics.  The 
development  of  richer  commenting  conventions  may  help  cor¬ 
rect  this,  but  I  feel  that  greater  utilization  of  the  information¬ 
carrying  capacity  of  the  codes  (hinted  at  in  my  ?  type  struc¬ 
tures)  may  prove  even  more  effective.  Having  in  mind  a  clear 
image  of  the  architecture  of  a  CPU  is  invaluable  in  the  writing 
of  assembly-language  programs,  so  I  have  tried  —  following  in 
the  footsteps  of  Bruce  Airy  —  to  construct  one.  It  may  be  possi¬ 
ble  to  enhance  FORTH  at  its  very  core,  where  complexity  and 
power  might  be  maximized  while  the  user-level  constructs 
become  fewer  and  easier-to-grasp  (I  cannot  help  thinking  of 
this  as  the  8080  -+  6502  transformation). 

Nevertheless,  even  the  most  enhanced  version  of  FORTH 
will  have  become  a  superior  high-level  assembly-language  — 
machine -oriented,  though  independent  of  real-world  machines 
to  the  extent  that  an  HLL  can  be.  Even  if  it  has  resisted  the 
temptation  of  primitive-proliferation  (the  8080  -*  Z80  direc¬ 
tion),  it  will  retain  the  error- proneness  (all  things  are  possible, 
most  of  them  wrong)  that  the  computer  elite  thinks  is  inherent 
in  assembly-language.  I  shall  quote  some  trenchant  comments 
by  G.  J.  Myers  of  the  IBM  Research  Center  in  his  book  Soft¬ 
ware  Reliability  (1976,  John  Wiley  &  Sons,  N.Y.): 

.  . .  in  general,  the  “ higher  the  level  of  language,  the  fewer 
the  errors  .  ...  If  a  programmer  is  using  a  machine  language,  he 
spends  most  of  his  time  not  problem-solving  but  fumbling  with 
the  details  of  the  machine  ....  P~o grams  in  high  level  languages 
are  more  understandable,  easier  to  change,  somewhat  self- 
documenting,  and  enhance  the  compatibility  and  portability  of 
programs ....  The  biggest  advantage  of  high  level  languages  is 
their  ability  to  express  and  manipulate  complex  data- structures 
.  .  .  manipulation  of  data  is  what  programming  is  all  about . .  . 
efficiency  is  achieved  through  the  intelligent  selection  of  algo¬ 
rithms  and  data -structures ...  structured  programming  is  the 
attitude  of  writing  code  with  the  intent  of  communicating  with 
people  instead  of  machines. . . 

These  reflections  must  be  based  on  a  lot  of  bitter  ex¬ 
perience  and  ought  to  be  kept  in  mind  in  any  FORTH  en¬ 
hancement.  In  fairness  to  Dr.  Myers,  he  is  no  less  aware  of  the 
problems  of  HLLs  that  make  the  machine  invisible  to  the  pro¬ 
grammer,  especially  IBM’s  baby,  PL-I. 

The  following  issue  of  DDJ  will  feature  Mr.  Gordon's  theoretical 
extension  of  the  “parametrized  command”  concept.  It  will 
introduce  new  considerations  and  further  develop  some  aspects 
presented  in  this  article. 


Table  of  Architectural  Analogies 

between  FORTH  and  a  CPU 

(modified  from  original  idea  of  Bruce  Airy  of  UCSD) 

bit  (only  0  or  1 ) 

ASCII  character-set 

opcode  byte,  8 -bit 

command-code  (word), 

variable  length 

instruction  set 

command-set  (vocabulary) 

(non-expansible) 

primitives  (expansible  by  user) 

working  registers 

variables- stack  (number  indefi- 

(fixed  number) 

nite,  no  definite  accumulator) 

index  registers 

temporary  return-stack  locations 

(fixed  number) 

(may  use  evanescent  -*•  S0) 

stack  pointer 

return -stack  pointer  (kernel) 

program  counter 

command  counter  (kernel) 

program 

sequence  of  execution-addresses 

of  command-codes,  and 
numeric  operands 

working  memory 

mostly  within  dictionary 

control  unit 

control  CPU- code  programs 

(kernel) 

status  register 

only  evanescent  zero  or 

(many  specific  bits) 

non -zero  -*■  S0 

JSR  and  RTS 

:  and  ;  primitives 

load  -#im  mediate 

LIT  primitive 

JZ  and  JMP  absolute 

SKIP?  and  SKIP  primitives, 

followed  by  address  numeric 

DDJ’s  responsive  readership 
can  give  you  invaluable  feedback 
on  your  ideas  and  innovations. 

Find  out  how  you  can  reach  them 

by  contacting  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


14 

12 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


“We  are  not  yet  at  the 
metamorphic  limit!” 


FORTH  program  to  generate  and  print  first  10  Fibonacci  numbers. 

:  FIBO  0  1  1 1  1  DO  CR  DUP  .  SWAP  OVER  +  LOOP  ; 

(commented  version,  cf.  text) 

(execution  and  output) 

(FIBO)  :  FIBO 

(compile  new  program  name) 

FIBO  (run  new  command  name) 

0 

(#0  -+  S0,  S,  =0) 

1- 

1 

■j 

1 

(#1  -*>S0,S,  =  l.S,  =0) 

11  1  DO 

(set  up  loop,  I  =  1  to  10) 

3 

(LP-1)  CR 

(CRLF  to  start  next  print  line) 

5 

DUP. 

(print  St) 

8 

SWAP 

(S,  S2) 

13 

OVER 

(S2  -»S0) 

21 

34 

+ 

LOOP 
(STOP)  ; 

«S,  +S,1  -S0) 

(1*1+1,  if  #11  return  to  LP-1) 

(end  compilation) 

55 

(continued  from  page  6) 

which  ran  faster  and  smaller  if  the  vari¬ 
ables  were  defined  near  the  top  of  the 
program  (with  a  jump  around  them,  of 
course).  Any  such  program  must  keep 
track  of  forward  references  for  later 
fixup,  and  that  takes  space  and  time. 
Furthermore,  it  is  presumed  that  defining 
things  first  makes  the  programmer  think 
about  his  data  structures  and  get  organ¬ 
ized  before  coding. 

I  feel  that  Pascal  has  certain  severe 
problems,  including  the  non-obvious 
order  of  its  writing  and  reading,  and  I 
deplore  the  fact  that  it  was  picked  up  by 
many  as  a  panacea.  Structured  program¬ 
ming  is  a  state  of  mind,  not  a  set  of  rules. 
However,  the  stack  orientation  is  one  of 
the  nicer  parts  of  Pascal;  smaller  memory 
use  and  recursion  are  obtained  for  free, 
and  a  careful  ordering  of  routines  can  cut 


memory  use  significantly.  1  think  that  the 
matter  is  still  open  to  discussion. 

Truly  yours, 

Harlan  A.  Rosenthal 
Nicolet  Scientific  Corp. 

245  Livingston  St. 

Northvale,  NJ  07647 

Dear  Editor: 

Number  43  has  just  hit  Yap  by  slow 
boat.  Without  wishing  to  suggest  that 
DDT s  usual  offerings  are  not  high  quali¬ 
ty,  nevertheless  Dr.  Knuth’s  article  was 
filet  mignon  when  one  had  expected 
ground  round! 

We  linguists,  you  see,  are  another 
group  that  is  constantly  plagued  with 
both  text-formatting  and  font-design  and 
-use  problems,  perhaps  more  so  even  than 
mathematicians.  The  center  of  my  at¬ 
tention  is  dictionaries  in  foreign  lan¬ 
guages,  and  I  have  nearly  despaired  of 


writing  programs  to  adequately  handle 
my  own  data- management  problems. 
Nevertheless,  Dr.  Knuth’s  books  are  my 
thread  of  hope,  and  his  mention  of  a 
book  on  TEX  is  a  ray  of  light  in  the 
darkness. 

Yours  truly, 

John  Thayer  Jensen 
P.O.  Box  358 
Yap,  TT  96943 

Correction  to  DDJ  # 50 ,  page  52:  Marilyn 
Darling’s  letter  mentioned  that  Digital 
Research  is  compiling  a  list  of  CP/M- 
compatible  software  vendors  for  distribu¬ 
tion  to  interested  persons  who  contact 
them.  A  DDJ  production  error  confused 
the  last  sentence,  which  should  have  let 
readers  know  that  questions  about  this 
Digital  Research  project  may  be  directed 
to  Curt  Geske  at  (408)  649-3896.  ■■ 


16 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 

13 


Of  Interest 


Cassette  Pascal  For  the  Apple  II 

A  cassette-based  Pascal  for  the  Apple 
II  is  now  available  from  Dynasoft  Sys¬ 
tems.  It  is  a  compact  p-code  implementa¬ 
tion  of  a  Pascal  subset  which  has  been 
available  for  6800  and  6809  microproces¬ 
sors  since  the  beginning  of  1980.  It  is 
intended  for  systems  which  cannot  sup¬ 
port  full-scale  implementations  such  as 
UCSD  Pascal. 

The  package  sells  for  $50,  which 
includes  a  user’s  manual  and  airmail 
postage.  It  is  comparable  in  speed  with 
Apple  Integer  BASIC  and  the  system,  in¬ 
cluding  the  compiler,  interpreter  and  a 
line- oriented  editor,  occupies  approxi¬ 
mately  8K  bytes.  For  further  informa¬ 
tion,  contact  Dr.  Allen  Jost  at  Dynasoft 
Systems  Ltd.,  P.O.  Box  5 1 ,  Windsor  Junc¬ 
tion,  Nova  Scotia,  Canada,  BON  2V0. 

SI 99  Computer 

RCA  Microboard  Products  has  added 
to  its  line  a  “complete  computer  system” 
on  a  4.5  x  7.5  inch  card.  It  contains  a< 
CDP1802  CMOS  Microprocessor,  a 
2-MHz  crystal-controlled  clock,  512 
bytes  of  read -write  memory,  parallel  I/O 
ports,  power-on  reset,  an  interface  ex¬ 
pansion  area  and  a  socket  for  1  or  2  kilo¬ 
bytes  of  user-selected  ROM.  The 
CDP18S604  has  the  inherent  advantages 
of  low-power  static  CMOS  and  the 
COSMAC  microprocessor  architecture. 
Powered  from  a  5 -volt  supply,  it  requires 
only  4  milliamperes  when  populated  with 
a  CMOS  ROM  and  is  designed  for  a  vari¬ 
ety  of  low-cost  computer  applications.  It 
is  expandable  by  use  of  the  44-pin 
COSMAC  Microboard  Universal  Back- 
plate.  Information  may  be  obtained  from 
RCA  Solid  State  Division,  Box  3200, 
Somerville,  NJ  08876. 


RCA's  "complete  computer"  for  $199. 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 
14 


RCA  has  also  introduced  the  indus¬ 
try’s  first  10V  CMOS  4K  RAM.  Its 
features  include  silicon-on-sapphire 
CMOS  technology,  low  standby  and  oper¬ 
ating  power,  extended  temperature  range 
(-40°C  to  +85°C),  wide  operating  voltage 
range  (4  to  10.5  volts)  and  industry 
standard  1024x4  pinouts. 

Further  information,  and  a  copy  of 
the  CDP1825  data  sheet,  file  #  1247, 
may  be  obtained  by  writing  to  the  RCA 
address  listed  above. 

RCA  has  reduced  prices  on  a  number 
of  other  products.  Their  CDP18S601 
Microboard  Computer  (4-kilobyte  RAM; 
sockets  for  4/8 -kilobyte  ROM/PROM) 
has  been  reduced  from  $549  to  $349. 
Also,  their  CDP18S623  Microboard  (8- 
kilobyte  RAM),  that  now  sells  for  $495, 
was  previously  $650. 

CP/M  -86  Operating  System 

Digital  Research  has  introduced 
CP/M -86  for  Intel  8086/8088 -based 
microcomputers.  This  is  the  first  of  Digi¬ 
tal  Research’s  sixteen-bit  products,  a 
high-performance,  single-user  operating 
system  designed  to  take  advantage  of  the 
8086’s  address  space  and  speed  while  ex¬ 
panding  upon  the  facilities  of  standard 
CP/M.  The  file  format  of  CP/M,  release  2, 
has  been  retained  for  compatibility. 
CP/M-86  can  also  serve  as  a  slave  node  in 
a  CP/NET  network. 

As  with  previous  versions,  logical  and 
hardware-dependent  portions  are  modu¬ 
larized  for  ease  in  configuration.  For  de¬ 
tails,  contact  Harold  Elgie  at  (408)  649- 
3896. 

PET  Users  Magazine 

PET  users  may  find  of  interest  the 
British  publication,  PRINTOUT.  It  is  a 
slick -format  magazine,  published  ten 
times  a  year.  It  is  devoted  to  consumer  re¬ 
ports  of  hardware  and  peripherals,  un¬ 
biased  software  reviews,  applications,  and 
software  problems.  Subscriptions  are  $33 
per  year  from  P.O.  Box  48,  Newbury, 
Berkshire  RG16  0BD,  England. 

IEEE-696  Prototype  Card 

A  nine-inch  deep,  S-100  wire-wrap 
prototyping  card  is  available  from  the 
Inner  Access  Corporation  for  the  IEEE- 
696  bus  standard,  compliance  H.  The 
company  expects  compliance  H  to 
become  the  preferred  board  size  for  both 
industrial  and  commercial  S-100  users 
since  it  nearly  doubles  the  area  previously 
available  to  the  designer  (potential  users 
should  inquire  how  to  fit  one  onto  an 


older  mainframe).  It  will  accommodate 
over  one  hundred  sixteen -pin  wire -wrap 
sockets  or  other  wire-wrap  sockets  on 

O. 3"  or  0.6"  centers. 

The  board  comes  complete  with  on¬ 
board  regulators  which  provide  5  volts  at 
3  amps  and  ±12  volts  at  1  amp.  Twenty- 
six  0.1  ufd  decoupling  capacitors  are  dis¬ 
tributed  at  either  end  of  the  board.  Here¬ 
tofore,  no  H-size  prototyping  boards 
have  been  available.  The  board  costs  $98 
singly,  from  Inner  Access  Corporation, 

P. O.  Box  888,  Belmont,  CA  94002. 

Word  Processing  Report 

“Word  Processing  on  Personal  Com¬ 
puters”  is  the  first  in  a  series  of  evalua¬ 
tion  reports  published  by  the  Small  Sys¬ 
tems  Group.  This  report  introduces  per¬ 
sonal  computer  word  processing  with  sec¬ 
tions  on  software,  hardware  and  applica¬ 
tions.  It  compares  Auto  Scribe,  Electric 
Pencil,  Magic  Wand  and  Wordstar  in  terms 
of  quality  of  documentation,  ease  of 
learning,  editing  power  and  formatting 
power.  To  do  so,  159  features  were  ana¬ 
lyzed,  and  the  final  section  tabulates  and 
discusses  these  in  detail. 

Single  copies  are  available  in  North 
America  for  $10  and  for  $12  elsewhere. 
They  may  be  ordered  from  the  Small  Sys¬ 
tems  Group,  Box  5429,  Santa  Monica, 
CA  90405. 


H-size  prototyping  board  for  the  S-100. 


17 


Z~80  File  Comparator 


M 

A-  T  ^M^any  times  in  the  last  few 
years,  I’ve  found  myself  in  need  of  a 
routine  permitting  a  byte-by-byte  compar¬ 
ison  between  two  files  in  memory.  Such 
comparisons  between  old  and  newly  pur¬ 
chased  “improved”  versions  of  programs 
can  quickly  point  to  the  locations  of  any 
modifications  which  may  have  been 
made.  Then,  when  the  addresses  have 
been  ferreted  out,  the  disassembler  gen¬ 
erally  makes  quick  work  of  disclosing  the 
nature  of  such  program  changes.  The  rou¬ 
tine  is  very  handy  also  for  validating  the 
source  code  generated  by  disassemblers. 
Often,  portions  of  disassembled  object 
code  turn  out  to  be  data  tables,  ASCII 
strings,  etc.,  rather  than  valid  instruc¬ 
tions.  After  correcting  the  new  source 
listings  to  properly  recreate  the  tables  and 
strings,  the  code  can  be  validated  by  re¬ 
assembling  into  object  code  and  com¬ 
paring  with  the  original  machine  code. 

In  the  past,  these  comparisons  were 
handled  on  my  system  by  a  routine  writ¬ 
ten  in  BASIC.  Although  the  BASIC  pro¬ 
gram  was  slow,  its  foot-dragging  pace 
didn’t  really  become  obvious  on  files  con¬ 
taining  many  dissimilarities.  The  venera¬ 
ble  teletype,  as  it  listed  the  addresses  of 
discrepancies,  masked  the  slowness  of  the 
actual  comparisons  with  its  own  slow- 
motion  gyrations.  When  two  long,  virtual¬ 
ly  identical  files  were  compared,  however, 
the  interpreter’s  slowness  became  more 
evident.  With  no  dissimilar  address  being 
listed,  one  could  really  begin  to  appreci¬ 
ate  just  how  slowly  the  wheels  of  progress 
ground  inside  the  computer  cabinet. 

It  was  partly  this  which  caused  me  to 
write  the  accompanying  program.  Actual¬ 
ly,  the  bulk  of  the  stimulation  to  do  so 
resulted  from  my  own  housekeeping 
problems;  I  lost  the  BASIC  routine. 

This  program  is  written  to  run  on  a 
Z-80  CPU.  My  own  system  is  a  Digital 
Group  Z-80  with  50K  of  RAM  using  digi¬ 
tal  tape  storage  running  under  the 
PHIMON  operating  system.  The  video  dis¬ 
play  uses  a  64  character  by  1 6  line  screen 
format.  For  convenience,  several  of  the 
PHIMON  operating  system’s  subroutines 


by  Donald  E.  Faulkner 


Donald  E.  Faulkner,  1245  Springdale 
Drive,  Jackson,  Mississippi  39211. 

Dr.  Dobb’s  Journal,  Number  51,  January  1981 


have  been  used.  However,  these  have  been 
accessed  through  a  series  of  “equates”  at 
the  beginning  of  the  program  to  make 
adapting  it  to  another  system  somewhat 
easier. 

In  operation,  the  routine  requests  be¬ 
ginning  and  ending  addresses  of  the  first 
file  in  RAM  and  the  beginning  address  of 
the  second  file  to  which  it  is  to  be  com¬ 
pared.  The  printer  routine  may  be  acti¬ 
vated  by  preceding  the  entry  of  these  ad¬ 
dresses  with  a  CONTROL/P.  CONTROL/ 
O  may  later  be  used  at  this  same  point  to 
“turn  off’  the  printer.  The  addresss 
entries  must  be  followed  by  a  carriage  re¬ 
turn  to  initiate  the  comparison  process. 
(Entry  errors  may  be  corrected  with  the 
usual  RUB-OUT.)  The  routine  lists  the 
split-octal  addresses,  if  any,  within  the 
first  file  at  which  dissimilar  bytes  have 
been  located.  The  last  split-octal  address 
listed  is  followed  by  the  message 
“Term.  .”  indicating  that  the  comparison 
is  complete. 

After  listing  a  block  of  fourteen  lines 
of  eight  addresses  each,  the  routine 
pauses.  Pressing  the  spacebar  clears  the 
screen  and  causes  the  listing  to  resume; 
pressing  ESCAPE  terminates  the  listing 
and  exits  to  the  operating  system.  Other 
keystrokes  are  ignored.  When  the  listing 
of  addresses  is  complete,  the  operator 
may  repeat  the  process,  selecting  new 
addresses,  by  pressing  the  spacebar.  ES¬ 
CAPE  will,  instead,  exit  to  the  operating 
system. 

Now,  looking  at  the  subroutines 
called  from  the  PHIMON  operating  sys¬ 
tem: 

OPRSYS  Must  be  the  entry  point  of 
the  computer’s  own  operating 
system. 

KEYBDO  Is  the  address  of  a  keyboard 
entry  subroutine  which,  when 
called,  accepts  a  character 
from  the  keyboard  and  re¬ 
turns  it  in  the  A-register. 


TV  Is  a  subroutine  which,  when 

called,  outputs  the  character 
in  the  A-register  to  the 
screen.  The  A-register  then 
returns  a  null. 

ERASE  Must  clear  the  screen  and  ar¬ 
range  for  the  next  character 
to  be  at  the  screen’s  upper 
left  (i.e.,  “Home”  the  cursor). 


LINBUF  Is  the  address  of  any  32-byte- 
long  area  in  RAM  which  may 
be  used  as  a  command  buffer. 

DELAY  Is  a  subroutine  which  causes 
a  time  delay,  when  called, 
which  is  proportional  to  the 
constant  pre-loaded  into  the 
A-register.  If  you  have  no 
time  delay  routine  in  your 
system,  a  simple  delaying  sub¬ 
routine  is  given  in  listing  two. 

TVEDT  Outputs  to  the  screen  the 
ASCII  character  pointed  to 
by  the  HL  register  pair.  It 
then  increments  HL  and  re¬ 
peats  the  process  until  a  null 
byte  is  encountered.  At  this 
point  it  returns  to  the  calling 
routine.  ASCII  characters 
must  have  most-significant- 
bits  set.  Bytes  with  msb’s 
not  set  are  interpreted  as 
multiple  spaces.  (An  octal 
101  produces  65  spaces, 
while  an  octal  301  prints  the 
character  “A”.)  A  subroutine 
which  does  this  is  given  in 
listing  three. 

If  you’re  not  running  a  Digital  Group 
system,  replace  the  TOGGLE  subroutine 
in  the  program  with  one  which  will  toggle 
the  cursor  position  back  20  spaces  on 
your  screen.  If  you  don’t  have  this 
backward  -  cursor-  movement  capability , 
remove  the  subroutine  (lines  440-520) 
and  enter  a  data  byte  of  054  octal  be¬ 
tween  lines  1970  and  1980  of  the  source 
code.  This  modification  will  allow  the  ad¬ 
dresses  entered  to  fall  below  the  format - 
prompting  string  on  the  screen  rather 
than  overwriting  it.  Finally,  if  your 
printer  doesn’t  automatically  generate  a 
line-feed  with  each  carriage -return  it  re¬ 
ceives,  then  load  the  A-register  with  octal 
212  and  call  HCOPY  between  lines  1500 
and  1 5 1 0  of  the  source  code. 

If  you  don’t  already  have  a  compari¬ 
son  utility  on  your  system,  now  is  the 
time  to  add  one.  I  hope  that  you’ll  find 
it  as  useful  as  I  have,  perhaps  even  taking 
its  place  right  alongside  your  search 
utility  as  an  indispensable  software  tool. 


(LISTING  ON  PAGE  37) 

19 

15 


Z~80  Video  Drivers 


Abstract 

Memory-mapped  video  displays  are 
widely  used  in  microcomputer  systems. 
They  afford  considerable  output  flexibili¬ 
ty  and  are  generally  less  expensive  than  a 
standard  CRT  unit.  The  major  advantage 
of  the  memory- mapped  display  is  the 
fact  that  the  contents  of  the  display  may 
be  accessed  like  any  other  memory  in 
the  microprocessor.  This  capability  is 
lacking  in  CRT’s.  However,  standard 
terminal  functions  must  be  provided  for 
by  software.  This  software  has  to  be 
designed  carefully  and  with  the  desired 
application  in  mind,  in  order  to  provide 
maximum  capability  and  efficiency. 

In  this  article  several  video  drivers  are 
included  in  their  complete  form.  First 
a  basic  implementation  is  presented  to 
exemplify  the  general  concepts  behind 
the  design  of  such  a  driver.  Then,  a  full 
implementation  is  presented  along  with 
discussion  of  the  features  and  approaches 
used  to  implement  them.  As  part  of  the 
discussion,  a  special  purpose  driver  is 
included  that  handles  cursor  positioning 
in  a  Life  simulation  program. 

Introduction 

Memory- mapped  video  displays  are  a 
common  element  to  many  microcompu¬ 
ter  systems.  This  variety  of  display  de¬ 
vices  offers  significant  versatility  in  the 
presentation  of  information  and  still  re¬ 
mains  a  low-cost  alternative  to  CRT  dis¬ 
plays.  However,  unlike  CRT’s,  memory- 
mapped  displays  require  non-trivial  soft¬ 
ware  drivers  to  provide  the  normal  dis¬ 
play  functions  such  as  scrolling,  back¬ 
spacing  and  cursor  positioning.  Many  fac¬ 
tors  must  be  considered  in  the  design 
stage  in  order  to  provide  a  useful  and  ef¬ 
ficient  video  driver.  Among  these  design 
considerations  are  display  speed  limita¬ 
tions,  output  formatting  and  the  scope 
of  included  features. 

Strategy  in  Design 

The  drivers  presented  in  this  article 
utilize  a  main  routine  that  also  serves  as 
the  entry  point  for  calling  routines.  The 
main  routine  provides  common  informa¬ 
tion  about  the  cursor  position  to  each 
subroutine,  which  is  used  to  execute  the 


by  Anthony  Skjellum 

Copyright  ©  1980  by  Anthony  Skjellum, 
1695  Shenandoah  Road,  San  Marino,  CA 
91108. 


display  features.  It  is  responsible  for  de¬ 
coding  commands,  for  executing  appro¬ 
priate  subroutines  and  for  handling  nor¬ 
mal  character  output  and  scrolling  or 
paging.  As  well,  it  handles  removal  and  re¬ 
placement  of  the  cursor  character  on  the 
screen.  The  subprograms  change  the  cur¬ 
sor  address  and  manipulate  the  video 
memory  in  various  ways.  They  are  re¬ 
quired  to  follow  a  set  convention  for 
parameter  passing.  The  only  parameter 
passed  is  the  cursor  address.  In  Figure  1, 
the  layout  of  the  video  drivers  is  outlined. 
Each  utilizes  the  same  essential  structure 
including  a  main  loop  and  support  rou¬ 
tines. 

A  First  Attempt 

A  design  specification  is  useful  in  pro¬ 
ducing  drivers  of  any  kind.  It  is  wise  to 
outline  the  functions  to  be  included  in 
the  primary  implementation.  Additional 
features  may  be  included  once  the  basic 
driver  is  fully  functional.  Table  la  lists 
a  set  of  minimal  functions  for  a  first 
implementation.  These  functions  will  be 
required  to  handle  normal  TTY  emula¬ 
tion. 

Example  I  is  a  listing  for  a  minimum 
driver  called  MNDRIVR.  It  supports  the 
features  enumerated  in  Table  la  as  well  as 
those  of  Table  lb.  As  it  stands,  this  driver 
is  very  useful.  Its  main  virtue  is  speed. 
MNDRIVR  was  intended  to  be  an  exam¬ 
ple  of  a  first  implementation.  Expandabil¬ 
ity  and  maximum  throughput  were  con¬ 
sidered  equally  important  in  its  design. 

In  order  to  make  MNDRIVR  as  effi¬ 
cient  as  possible,  the  parameter  passing 
conventions  were  made  simple.  The  HL 
register  contains  the  cursor  address  on 
entry  to  the  support  routines;  they  are 
expected  to  update  this  value  in  a  mean¬ 
ingful  way.  Because  the  other  registers 
may  be  modified  at  will,  there  is  no  need 
for  cumbersome  push-pop  sequences  at 
the  beginning  and  end  of  support  rou¬ 
tines.  This  makes  interfacing  support  rou¬ 
tines  much  more  straightforward  and 
avoids  the  additional  overhead  that  would 
otherwise  be  required. 

Scrolling 

Scrolling  is  the  rate  dependent  step  in 
text  display,  therefore  extra  attention  has 
been  put  toward  minimizing  the  execu¬ 
tion  time  of  SCRL  and  to  decoding  the 
linefeed  character  (i.e.,  by  looking  for  it 
first).  If  scrolling  could  be  removed,  the 
display  speed  would  be  much  faster.  This 
can  be  done  readily.  Instead  of  scrolling, 
the  cursor  is  made  to  home.  No  display 


memory  need  be  moved.  The  only  dis¬ 
advantage  is  a  slight  loss  in  readability 
which  I  feel  is  made  up  for  by  the  gain  in 
throughput.  Through  conditional  assem¬ 
bly,  the  paging  option  may  be  selected  in 
MNDRIVR. 

For  a  first  attempt  at  a  video  driver, 
MNDRIVR  has  provided  the  essential 
functions  necessary  for  emulating  TTY 
operation  and  has  also  addressed  a  design 
tradeoff  between  scrolling  and  display 
speed. 

A  General  Purpose  Driver 

Because  of  MNDRIVR’s  modular  con¬ 
struction,  additional  features  can  be 
added  in  a  logical  way  while  the  efficient 
inner  loop  is  maintained.  Many  useful 
functions  may  be  added  with  little  addi¬ 
tional  overhead.  In  the  next  sections, 
several  specific  features  are  discussed  in¬ 
cluding  negative  scrolling  (and  negative 
linefeeds),  line  insert-delete,  cursor  ad¬ 
dressing  as  well  as  “linefeed  collection,”  a 
process  by  which  scrolling  is  made  more 
efficient.  All  of  these  features  are  in¬ 
cluded  in  the  comprehensive  program, 
GPDRIVR,  in  Example  II.  It  is  not  in¬ 
tended  that  all  of  these  features  be  in¬ 
corporated  in  all  applications.  Therefore, 
desired  options  are  selectable  via  condi¬ 
tional  assembly  toggles. 

Cursor  Motion  Functions 

It  is  often  necessary  to  move  the  cur¬ 
sor  around  on  the  display.  This  is  facili¬ 
tated  by  four- directional  cursor  motion. 
The  standard  linefeed  function  provides 
the  down  motion;  up,  left  and  right  are 
trivial  to  implement  as  well. 

For  special  purpose  drivers,  it  may  be 
useful  to  move  the  cursor  diagonally  as 
well.  Take,  for  example,  a  program  that 
performs  a  Life  simulation.  Such  a 
program  could  allow  the  user  to  place 
“cells”  on  the  display  by  moving  the  cur¬ 
sor  and  pressing  a  key.  Such  a  driver  is 
included  in  Example  III.  It  allows  the  cur¬ 
sor  to  be  moved  in  any  of  eight  direc¬ 
tions. 

Reverse  Scrolling 

Reverse  scrolling  provides  a  logical 
way  to  handle  negative  linefeeding,  back¬ 
spacing  or  cursor  positioning,  which 
causes  the  cursor  to  move  above  the 
home  position  and  off  the  screen.  In 
MNDRIVR  this  condition  is  handled  by 
placing  the  cursor  at  the  home  position. 
In  GPDRIVR,  either  reverse  scrolling  or 
homing  can  be  selected  by  conditional 
assembly. 


20 

16 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


TABLE  la 

I. 

Carriage  return 

II. 

Linefeed 

III. 

Backspacing 

IV. 

Scrolling 

V. 

Top  of  page  detection 

TABLE  lb 

I. 

Clear  screen 

II. 

Home  cursor 

III. 

Scrolling  or  paging  option 

Linefeed  Collection 

In  normal  text  output  there  are  occa¬ 
sions  that  require  multiple  carriage 
return-linefeed  sequences  without  inter¬ 
vening  characters.  In  such  a  case  it  is 
possible  to  “save  up”  the  scrolling  and 
perform  it  all  at  once.  Each  scroll  requires 
that  960  bytes  of  memory  be  moved  and 
that  the  bottom  line  be  filled  with  blanks. 
A  multi- line  scroll  moves  fewer  charac¬ 
ters  and  correspondingly  fills  more  lines. 
Linefeed  collection  (or  “scroll-control” 
as  it  is  called  in  GPDRIVR)  provides  this 
feature.  This  feature  is  not  available  when 
the  paging  option  is  selected.  Further¬ 
more,  linefeed  collection  only  occurs 
when  the  cursor  is  at  the  bottom  left  cor¬ 
ner  of  the  display. 

Other  Special  Functions 

For  sophisticated  text  display,  there 
are  several  other  key  features  that  need  to 
be  included.  They  include  delete  to  end- 
of-line,  delete  to  end-of-screen,  cursor 
addressing,  line  insert  and  line  delete. 
These  features  require  a  greater  overhead 
than  some  of  the  more  conventional  func¬ 
tions  including  a  GPDRIVR.  Therefore, 
an  “escape  sequence”  is  necessary  to 
access  these  functions.  An  escape  charac¬ 
ter  (ESC)  is  sent  prior  to  the  command 
character.  By  using  this  technique,  the 
main  routine  need  not  decode  these  addi¬ 
tional  commands  but  instead  controls  a 
smaller  overhead  for  the  escape  mode. 

Summary 

In  this  article,  many  aspects  of  CRT 
emulation  for  memory -mapped  displays 
have  been  explored.  Other  sophisticated 
features,  such  as  display  windows  and 
the  like,  were  considered  beyond  the 


scope  of  a  routine  that  was  to  be  driven 
via  character- by- character  input.  Fea¬ 
tures  such  as  point  and  line  plotting  could 
be  included  as  part  of  the  escape  se¬ 
quence  functions  in  GPDRIVR.  Such  an 
undertaking  is  quite  feasible  but  was  con¬ 
sidered  too  specific  for  inclusion  here. 

Implementation  Notes 

MNDRIVR  and  GPDRIVR  were  both 


assembled  under  MAC.  They  utilize  the 
standard  Z80  library  (Z80.LIB).  They 
also  require  SUPPORT.LIB,  which  is  pre¬ 
sented  in  Listing  I.  The  macro  TEST  is  a 
short  test  program  that  echoes  console  in¬ 
put  to  the  video  driver  for  test  purposes. 
In  a  normal  application,  this  would  be 
eliminated. 

CRT  in  Example  III  was  written  for 
the  TDL  MACRO  ASSEMBLER.  ■  ■ 


FIGURE  1. 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


21 

17 


Z-80  Video  Drivers 


ui  co 

Ui  Ui 

OC  3 


'  •  ®  •  Q  •  (J  •  X  • 

^  G-  Q.  a-  a. 

I  *5  *5  *  5 

X“)  O'  ->  a:  => 

«  «  «  « 

.*  XX  XX  XX  XX 

Ui  U  UI  U  UJ  O  u  t_j  UJ 


o  o  to  o 

QC  CL  O  O 

O  U  h  o  *- 

CO  CO  o 


»  ft.  ft.*-  ft.  •.  ft.  •. 

o  x  o  xo  xo  3K  O 

w  *-•  CO  H  CO  •— l  CO  H  O) 

u.  co  u.  co  u.  to  u_  co  u. 


<  it  M 

ft  u  a. 

U  LI  UJ  Z 

**UJD 
1  (J  CO  -) 


X  H-  X  Ui 
Uft  AO 


-J  -J  CJ  Ui  X 

UI  UJ  X  _J  X 

AO  (J  U  CJ 


fic  ft.  ot  ft.  oc  ft.  ae  cl  «  g.  , 

kO  1  CJ  "I  CJ  “)  o  “)  (j  -)  jj 


m  rs.  wo  o 

CO  UJ  00  UJ 

CM  U.  CM  u. 


ro  o  ^ 

CD  UJ  00 

CM  U.  CM 


o  o  ▼  rs 

o  o  o  o- 

n  n  u  u  ao  uj  «- 

rv  cm  rs  u.  n  u.  o 


o  cm  ♦  >o  co  <r  cj 

rs  rs  rs.  rs.  rs  rs  n 


•  oc 

*  =► 

*  M 


o  o  o  O  O  d  O 

CJ  —  MJ  uiOu-rooxj  — 

moo  ooooomu. 

—  «  —  O^csiQ®UJ«P0D 
rorsi«—  —  cm(Jcju.cj(J  — 

♦  ♦♦♦♦♦♦♦♦♦♦♦ 

oro'Oo*«QontN«u 

OOOOOO*-  —  —  —  — 


22 

18 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


SOFTUARE  DRIVER  FOR  VECTOR  GRAPHIC'S  * 

FLASHURITER  16X64  DISPLAY.  *  jp  SCROL  .  SCROLLING  OPTION 


Dr.  Dobb’s  Journal,  Number  5 1,  January  1981 


23 

19 


X 

o 


S- 


OX  —  J  «  U.QCO 

X  I  _l  UJ  O.  X  U_  CJ  H-l 

UOUOUIHO(0> 

—  ocoi\»=>oo<roo 
oo  —  oooo  —  — 
ooooooooo 


0> 


XU  -JO 

—1  co  a.  juj  z  ouj 

u  ui  o  a.t  h  aa 

xiiujwo<iuh 
UUOOQXHCOO 

o®in(No«-oii.u 
—  —  —  OOUOU-iO 
OOOOO  —  —  u_  — 
OOOOOOOU.O 


s 

X 

>- 

CO 


£  tn  x  o  uj 

a  O  0  (A  (D 


u  u  o  o  o  : 


05  I 


---OOOflBIMh 
0  —  00  —  —  — 
oooooooo 


§ 


o  a.  x  o  cj  i 

uj  o  ■«  x  <r  i 

xxxoe  ja.u.Ka.< 

®UOUQU.JQC0 

9VOBQO0<UJO 


OOOOOOOOOO 


CM  CM  O 
CM  ^  CM 

u  u  u 

o  o  o 


CM 

m 

MNO 


oo  c  aa 

U  L)  U 


(O  K  OC 
_j  u_  <r  ►-  _j 
U  JUJ  JO. 
U  X  X  _J  Ui  05 

at  u  u  u  q  uj 


o  'O  u  ®  03  o  ▼ 
OOOOQOOOU-Ouu 
0O«=>  —  —  o  u-  o  — 
OOOOOQOU.OO 


M  O  «  » 
Ik  O  Oft 


24 

20 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


I 


—  O  O  T-  o  O  — 

o  O  O  o  ©  ©  o 

u  »-  *«  uj  O  u.  m  o  u  <- 

moo  ooAOQmu. 

-«r-CMNQ®UJ<iacD 

ro«N-*-NUOu.uu»- 
♦  ♦♦♦♦♦♦♦♦♦♦ 
on<oo><Qo(MtN« 


o  o  o  o  o  o 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


25 

21 


M  X  •  (/)  ■  0)  • 

I  Z  H-  QC  H-  «  h- 

03  «  x  =3  x  3  x 

X  =>  X  OX  OX 

3  0  UJ  +  Ui  l  X 

O  ♦  I 

a  a  a  a 

Sa  z  ox  ox 

<r  <r  a  <r  a  <r 


<X  ••  K  X  Ui 

H-  O  U  U  K  U. 

CO  Z|j\  M 

-  M  f  W 

o  Ui  u  3  ui 

t-  co  z  o 

<c  koilz 

£■  a.  o  z  x  x 

Z  UJ  J  Ll  UJ  X 

m  ii  -j  £  Ui  Z 

O  ••  m  Ui  Q  UI  O 

a.  a  u.  i  a  a)  u 


QC  Ui  Ui 
<5  x  => 
*—  uj  ■« 
03  a  03 


QC  A  O 

Ui  « 

§5  ui  z 


a.  o 


QC  S 

X  Ui 

X  O  UJ 
Ui  QC  QC 
X  O  \ 

o  x  !$! 


3  ¥  ~ 
QC  Ui  Ui 

UOQ 
J  Ui  Z 
U  Q  4 


a 
♦ 
i  t 

a 

a 

♦ 

CM 

X 

X 

Z  X 

UJ 

X  X 

03  cn 

a  x  u  z  — 

8s 

a 

z  X 

O  03 

03  a  CM 

X 

X 

cn 

x  a  cj 

CJ 

?  c 

X  O 

03  C 

aT  a  *T  z  ix*  a  o 

I 

!$j  x  z  o  z 

a  «  x  z 

•*  X 

x  a  a 

zz  8 

H-  O 

6  ? 

(9  O 

X  O 

x  I 


o  O 

03  CO 


O  OC 

X  ►- 

8  5 


►1  a  X  X  X  X  X 

X  C  Ui  X  Ui  U  Ui 

«J  a  fiC  •  H  QC  •-  o  oc 


*-•  H>K>ft.XOHt- 
XXOXOXXXXUJ 
jj*Mru-)Ui_i* 


o«Oujxoox 

a.oa.£_jxri-. 


3  U  Ui  X  U_ 

«•*  r  o  x 


i  o  -  cm  po  ♦  m 

i  o  o  o  o  u  u 


<X  CO 

Ui  o 

X  Ui 

o  a 


03  r- 

X  «J  >- 

0  03  1  O 

X  CD  U 

o  <r  z 

co  j  oc  UJ 

u.  o  => 

O  U.  XI 

ui  ►—  S  :> 

Ui  Ui  Ui  Ui 

Z  03  0.  QC 


% 

X 

O  •  -J  • 

4  •  UJ  • 

a  •  a  • 

«£ 

X  Z  I  z 

O  UJ  O  UJ 

X  X 

X  X  ♦-  H- 

2.2. 
28  58 

03  li.  03  U. 


x  OC 

o  *»• 

UJ  Z  X 

X  UI  03 

XI  ui  Ui 

ax  o 


H  <  £  «  * 
uj  3  a 
3  QC  "3  X  3 
ui  <r  <c 
-J  X  z  X  z 
O  Ui  U  Ui 
a  z  z 

55^5*" 

o  a.  •>  u.  » 
wxof  o 


X  X 
X  X  03 

X  03  UI 

03  UI  3 

uj  o  a 

a  o  uj 

O  UJ  QC 

UJ  X 


Q.  •  u.  •  co 

a  •  uj  •  x 

•  —I  •  QC 
Z  &.  X 

<r  z  <r  z  <X 

QC  “3  X  -3  X 

«  « 

X  X  X  z  X 

o  Uj  o  uj  o  i 

X  X  X  X  X 

3  3a 

a.  -  a.  -  a_ 


UJXOZO  zoxoz 

03  x»  co  x*  cn  h  0)  h  in  xi 

U  CO  U.  O)  U.  03u.03u.03l 


UJ  03 

X  >-  O 

<x  u.  5_ 

U  •  H 

03  •  x  03 

Ui  •  z  « 

Q.  UJ 


03  -J 

03  X 

2  0 

UJ 


X  (J 
UJ  W 


>-  QC 

-J  « 

x  x 

o  o 


X  »-  1—03  z 

«  3  -  QC  XI  «  XI 

CJ  a.  x  O 


U 

03 

2  £ 

J— 

X  X  « 

8  8. 


O  CO  X  UI 
(J  -I  X  Z  I 
UJ  U  UJ  X 


X  UJ  X  X  o 

3  x  -j  x  X 

X  X  Z  UJ  X 

(_>  X  CJ  X  o 


O  uj 
z  CJ  a  OD 

O  CO  O  CN  X  QC 

03  uj  o  —  x  a 

Ui  X  O  *•  U  x 

8i  u  x  <r  uj  => 


3  a  <r  <c  n  a  i 

ox  a  x  x  o 

z  uj  •  *  x  o  CJ  •«  x  I 


H  N  h  N  X  PM  X  fst  x  I 
XXXXX  XXXXXi 
>X  u  1  U  “>  ••(J  “3  U  “3  O 


X  XX 

O  X  X  X 

■*  Q_  •-  X  o  “> 


X  CN 

CN  UJ 

«  CN  ^  CD 

n  «  u  rs 

«  <  Pv  <t 

00  00  00  00 


oo  x  x  a 

o  ♦  rv  ^ 

UJ  00  X  00 

X  CM  X  CN 

♦  ♦ 
a  ax  ~> 
a  a  a  o* 


a  NON  CM 

—  oaro  o 

x  o  x  cn  a  o 

X  CN  1*3  M  ^  N 


26 

22 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


o 

cc 

o 

CO 

* 

M 

V 


CL¬ 

UJ 


^  o 
oc  z 
u 

(/)  O 
« 
_ I 

•«  o 

S" 

O  UJ 

z  cc 


£2  J 

oc 

li.  o  u 

»-«  A  co 


i* 


CC  H- 

u  z 

CO  i-t 


^  CO  ac  CO 

M  id  UJ  _J 

Z  h-  -J 

UJ  M  u.  o 

•  3  _l  «  CC 

•  cc  CJ  •- 

•  UJ  OC  CO  CSJ 

UJ  CO  A  •  O  * 

CO  UJCUU.ll 

*-■*  K  3  U  O  -J 

3  0.  Z  «  UJ  Z 

a  t-  m 

ui  h  u  o  «  II  •-  ■-  •- 

sc  Oh  'O  CM  *■ 

h-  3«UJQ-UJ_l^-00»-r0'O 

o  C(J)N3(DX*t«»« 


UJ 

ID 

« 

=1 

UJ 

2 


CO 
CO  CO 
CO  UJ 
UJ  A 

cc  o 

Q  A 

a  <r 

CO  « 

CO  UJ 
UJ  H  U 
cc  co  as 

QUJ3 
A  A  O 

<r  co 

UI  •—  o 
0(0  11 


co  a: 

ai 

(j 

co 


£ 

O 


^  •— t  •— •  o 

Z  u.  u.  a. 


O  • 
QC  X 
o  <t 
CO  z 


! 

B 

c 

c 

o 

T3 

.C 

c 

c 

o 


8 


_r«5: 


UJ 

UJ 

CJ 

CM 

z 

o_ 

•« 

UJ 

— J 

CO 

a. 

CD 

cc 

_j 

A 

CO 

u 

z  •« 

CJ 

A 

»— 

•>  a. 

CO 

z  >o 

Z 

A 

CJ 

z  z 

<r  uj 

z 

Z  A 

CJ 

8 


w  “)  h  •»&.  r  x  cn  t  o 


CD 

*-<  z  i 

X  CJ 


S  55 


O  *-«  Z  *-«  o_  ►— 

DOZOQ.OC  X  O  UJ 

- — j  a.  a: 


CJ 

co 

* 


U-CM'OO'O'O-O^O-O-A  — 
i«W«NNNMNf»fMUN 


►  <  «  U  U.  -  N 


«r  m  -o  rv  od 

U-U.U.U.U- 
o  o  o  o  o 


o  w  ▼  in  rv.  oo  «  «  u  o  u_  —  «r 

ooo  ooooooo  o  »-  «- 

CM  CM  CM  CM  CM  CM  CM  CM  CM  CM 

OOO  ooooooo 


o>  o 
u.  u 

o  *—  «—  O' 
CM  CM  U  U 
■1 

m 

o  »-  *-  *- 

CM  CM  CM  CM 


*©  O- 

CM  CM 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


27 

23 


28 

24 


Di.  Dobb’s  Journal,  Number  51,  January  1981 


IF  8KE6SC  ;  IF  NE6ATIVE  SCROLL 
0230  CD4A02  CALL  NSCRL 


o«  ro 
—  ro 
O  CM  o* 
n  n  u 


—  o  wo 

OU-'00'0'0'0'0-0'-«U_'00'0' 

rO'OCMCMCMCMCMCMCMIO»n*-*-CJ 


u  o  ujo  cm  ^  is.  oo  «uPu.o-(Nn»inooo-«#u 

CD  CD  CD  O'  O'  O'  O'  O' 

CM  CM  CM  CM  CM  CM  CM  CM  CMCMCMCMCMCMCMCMCMCMCMCMCMCM 


ro 

o 

CM 


U.  CM  O' 
«  M  O 


U.  O  -  ♦  N  OO 

m  -o  -o  -o  'O  >o 


O' 

>o 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


29 

25 


co  • 
co  _| 

UJ  X  « 

CL  A  m 

oana: 

SC  CL  CD 
o  cn 
=>  OC  CL.  CL 

uo  3 

CO  Ui  o 
ZKZ 

o  ix: 

M  U  -J  UJ 

£  Ui  _l  S 
W  >  J  u 
O  <1  H  UJ 

a.  cn  u.  oc 


o  u. 


Q 


CO 

UJ 

g 

a 

<r 


co  g 

n  co  a 

h-  co  <c 

H«nSSg 

UJ  UJ  a  h  o 

n  u  Q  K  w 

uj  c  «  qc  gc 

3  U)  QC  a.  u  • 

o 

fc  X  CO  UJ  Ui  • 

x  h-  i  ^ 

3  3  m  ^  M 

03U  JhX 
o  cn  uj 


3  X  X  t-  _J 
UJ  UJ  J-  «  M  3  M 

Oco  inztLiu. 


:> 

<t 

cn 


H  uj  % 
U.  CL  <z 


a 

a 

a 


3s 

<C  3 
^  CJ 

UJ  »• 

<r  ui 
co  a 


Z  CD 

cn  x 
a  u 
a.  x 


UJ 

CL 


UJ 

a 


o 

CO 


o 

A 


N 


—  CM 
O  © 


o  n  a  — 

U  UJ  U  UJ  u 
CM  Irt  'O  O*  « 

a  a  a  a  a 

CM  CM  CM  CM  CM 


m  cm  m 

a<ONUJONUJOQ-»> 

Nujvroo-voujuuju 

auuju.-NMin'Oo-« 
OOAAMUUOUUUU 
CM  CM  CM  CM  CM  CM  CM  CM  CM  CM 


—  ©  CM  m  CM 

o  o  ©  a  © 

ro  ©  u.  ©  *■ 

a  <  o  u  o 

ama~-o*a«-a 

UUJUJCM-OCMU 

»UJU.Ort^N« 

cjuuaaaao 

CMCMCMNNMCMM 


30 

26 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


O  LU  UJ  (N  OC  H 

_j  ac  O  _J  — i  zuj  j  at  h  j 

_j  o  x  o  o_  -j  •  u-  oc  a  z  o 
ccuicjtnwHx^jzijHuy) 
uSuuuju.Hczo(o>aitt 

u.aNwoiO'roo  louii.o 

♦  »roOOO«OOau-(N<tU.O 
NfMMM<r(NO^»-U.N*-U.O 
OOOOOOOOOU.OOU.O 


X  A  rg  a  _J 

h  ju.t-  jujwa  cc  (_) 

_io.ocj.jxuiou.zaoc 


ziu«ujwwWHgii.(flifcHHUjw 

acjocjoaaujuiu-i-JZOix^M® 

ao-oo-«caujOCNorv'OCp<roro*-CNO 

oooooaof\o»noaooa<rcNQ 

0o0^0*-OM«N’--NO’--fM0 

ooooooaooooooooooo 


_j  o  uj  uj  o  uj  *—  ac  j  k  o  at  o 

i  i  y  h  O  UJ  (A  J  O  OC  X  UJ  A  OC 

»-«0XCMZ-J«00-l  co  o  cd  a  a  o 

u.iXJOUja,wwHju.j(AMM«w 

M0U0000UJUJU.XJSZaC>>'0 

NNIOn'4WO'OLkV4C<N  -O  OJ  O  CO  U_ 
ca_oA«-rvoaDmmoouj*’omo*u. 
*-00*-<M00<MCMf>J00— -CM«—  —  OJU. 
OOOOOOOOOOOOOOOOOU. 


j_jcno_ 

MOUI3H- 
U_  X  X  X  *  I 

A  o  o  o  o 


lOOJOKjins  <=> 
•-«<rO_l-«U-XUJOO_'«X 
_JO_CO»-«0-UJ-«IOOO>- 


S-OMinU.tNOf-MCD^O<IOQOli. 

...MOUQOomou^rrsurooDu. 

»-OC>or,ooroocJNO»-o*-i,OM(Nu. 

Ooooooaoooooooooou. 


ac  cn  x  x  o  uj  a.  o  ac 
ooojtouiojoeuj 
«rujacoacoooo_j 


A  X  UJ  X 

_J  O  _J  o  o 

x  o  x  <r  a  co 


<jxxx_j:DuJot/>3— J>-«oo_a-<EUj 

MOOOOOOUIUJUJU.MCXOU)Xttl 

OD'foruflDOAAr^om^ou.O'OPOu. 

0*-^^ONO«'OMOO-<hUJNWU. 

SOOONfO»-NCMfOOJOO*-^JOMU. 

oooooooooooooooou. 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


31 

27 


Z-80  Video  Drivers 

Example  III 


32 

28 


Di.  Dobb’s  Journal,  Number  51,  January  1981 


CURLF:  OCX  D 

JhP  CRM 


oc  ►—  ►—  X  X 

ocn  oc  oe  oc  —  cm  —  ro  ^  ^ 

3  to  o c  aocauuxK  »—  »—  —cm 

to  *-3  w  *  *w  ►  flt  oc  oc  -  - 

z  «  a  a.  ouoa.3sa.xnouxxKuu  z  _i  z 


i  c  u  a.  «  s  z 


XZXZ  AX  N  a  X 

to  CO  CD  c/3  *-«_iA<o<r^a_»— <•— •a.r^txxxxro-  to  => 

3  D  3  D  XX-XOAOOXXXOCXXX^X  =90 

cl  a.  i  a.  _j_jAa__/xa._j-_io— j— •— •-  a.  x 


m  >  u  o.  a.  d.  a  i 

i  OC  O  A  O  O  o  O  I 

x  x  to  a.  a.  a.  a.  • 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


33 

29 


U  OK 
O  QC 


Of 

a  r 
fli  ♦» 

iff 

5  8 
•*« 
-*»  V 

o» 

*-  *0 
o 

?  = 

Of  A 

u 

(D  •*« 

r  ■** 
19 
C 
c  o 

1 1 

3  <0 

♦* 

0»  Of 

^  4* 

A 

01  3 
•o  cr 
O  Of 

u 

♦* 

Z2 
■-•  ♦» 
c 


♦»  v  • 

ff  <9  ~ 


01 

%- 

o 

Iff 

01 

Of 

f- 


n 

s 


* 

* 

5 

$ 


X 

Iff 

— J 

♦ 

Of  u J 

A 

* 

A  -J 

f— 

♦ 

1— 

♦> 

QC 

* 

♦»  oc 

O 

* 

Iff  0 

V- 

1 

• 

CD 

i . 

0 

■ 

* 

UJ 

* 

►— 

£ 

X 

« 

<c 

01  ♦> 

♦> 

* 

3 

u 

cn 

* 

at 

Of  T? 

c 

• 

UJ 

S  S 

Of 

* 

* 

• 

•  e>  •• 

•*11  ••*  • 

# 

♦ 

X 

* 

UJ 

♦ 

-J 

• 

* 

oc 

* 

ee  «* 

0 

5 

o 

8 


C 

S 

iff 

•** 

s 


Of 

01 

t- 

i 

Of 

t- 


01 
». 
>*  19 
19  *■< 


£>  0.  o» 

«  iff  ^ 
CL  *4  TJ 

iff  T? 


Of  S  ♦* 
91  W  o 
A  fc- 
O.  O  -*» 

‘UI 

o»  u  - 

>  O  (. 


a. 

o»  <-  *-  • 
o»  Z  e 

Iff  iff  o 
U  Of  <0 
Of  U  *0 
£  Of  V  Of 
♦»  c  Of 
O  t-  e 
01  o 

t-  m  v-  »* 

O  •**  19 

%-  A  O  C 


•n  £t  X 

.0  ♦  o  X  X  X 

Mio»n*-o»-noin  +  N  o  *•  o  • 

O-0'0(N«^’«fc00  o 

feO  111  ♦  ♦  ♦  M  '  OOO  O' 


.||  M  II  H  II  M  II  M  II  M  II  M  M  N  II  M  IIM 

M  Ul  UJ  OC  Ul 

O  OC  O  CD  O  Cfl  (/) 

(X  *  <r  «x  __J  <c  —I  <r  <t 

3  A. 

0)  U3D3£tt  j  J-H»IO^inu  WOO 


34 

30 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


Exchanges  the  contents  of  be  and  hi  (be  <->  hi) 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


35 

31 


36 

32 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


* 

* 


■P  -P  T  ~ 

i )i  :  •  «  ft  m 

3>  Ol  «-  c  at 

l/i  C  4  flL  x  *- 

■h£  IflH  •  I 

W  CJ  x  «-  <1 

J  C  T?  TJ  U  O  ~ 

H  I-  III  t-  +J 
)  <P  IQ  -P  I/I  (D  H  tfl 

J  ™  O  3  1.  0-0  J 

:  i-  £  i  n  £  oi  n 

a  Ol  Jl  -P  Ol  31  X 

-  a  &  3  x  U  :>  Ol 

J  O  2  O  U  2  »-  Q 


1  h  U  A  Ol  £  i 

fi  ID  Ol  ♦>  U  i 

)  W  C 

■  IV'H  OiM 

1  3  Ol 

C£  t  •  JZ  i 

-  h  ai  t-  ■**  i 

>  W  C  JQ  IB  O 

)  •  -H  i  £  C  I 

j  jq  :  u  it  1 

.  Ol  c 

j  V  0  -P  -P 

3  C  C  -P  D  a. 

.  ID  ro  C  0.  Oi 
>  -H  ♦»  u 
:  T)  t  3  u  > 

3  <  a.  o  «  i 


:  o  cm  cm  ro  in  o  x 
j  o  >o  o  v  ro  x  o 
•  o  h  n  n  n  cm  cm 
i  o  n  n  m  -o  m  oi 


:  cn  o  u. 

J  >-  Ci  Id  3  K  >■ 

.  cn  aj  uiSiuc 

)  CC  >■  4ZU  J 

a.  ui  :>  q:  x  3>  u 

io^kuj  jt-ai 


r-  o  20 

2  'C  U  W 

3  x  Cl  «  W 

O  ‘UIDhldh 
U  ^  W  J  ID  t  Q 
-  Ui 

j  i  cc  a  a.  j  z> 
I  vuiccwih 


3  U.  W  2  >IO  >-  x 

CC|  2  U.  >  *-1  2  a.  <1  CL  x 

20  o  o  in  «  K  *-•  o  ro  Cl  £L  o  ro 

x  Q  t—  h-  2-  2  13  >-  2  U  -  3  3  2  U  - 

_j  as  uc  2  a.  ~  o  u  o.  m  i  ~  _j  _i  x  x  ~ 

►  voa.NQ.no  JtnuMs  o  >-  >-  -_j 

jlki  ►  x  -  n  ►  i  h  -  rv  ►  ju^u  j  jzoojiij  jjz 

ZZNNNNNNvNNMNZZhZZZvilfl'ZjlZZ'' 

-1  _4  _J  I  -J  -J  I 

-i  O-j-jin  j  j  cl  cn 

a<iaaaaaacacca4:2<i<ia3CQ<i<roa3CiCi 
JUU1UTUTJUTU1HUUT4.  j  jooaoa  J  J 


ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo 

oxCMro4in'Orsco(*ox(Mro<rinx)rvCDOoxCNro4inxirxcocNOxcMroarin>ot'soo(*oxCMroarin'orscoO'OxCMro4inx)rNCD(VOxCMro4in'<>r'CDO>oxCN 

Mrt„H«xxxxxf4f4r4nr4r4r4nr4r4nnnnnnnnnn^^T»^»»«r»vininininininimninin<i'0'0'0'0'0'0'0'0'ONNNNNNNNNNCDCDCD 

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooooo 


00  .£ 
AS 

N  — i 


oi  ro  «  m  x ro 

o  o-oooo- 

o  ro  o  o  o  ro 

N  O  ro  CM  N  CM  O 

n  -O  O  f  4  N  N  h 

ro  x  cm  ro  ro  ro  cm 

x  x>  in  in  x  x  io 

4  >0  x  x  «0  4 

o  o  ro  ro  o  o  ro 


o  ro  o  rororotMCM  ro 

o-o-  o-  oo-ooo  o 

roro  ro  oroooo  o 

incMoroN'Oio©  in  in  rv  N  o  cm  x>  o  in  cm  cm  r\  o  x 

rox)CMrox4»oo  h  ono  ooro  ©  x>  cm  cm  x  o  x 

iohnohono  cm  o  ro  ro  o  cm  ro  o  ro  ro  ro  ro  o  ro 

xin'Oo-oO'ONN'OO'OonminoifiH’flininxoinx-o 
TxMfiNnNx-oNnMno-x^rov  V'oxxonoo-o 
ororooroororo^roorooororoorooorororoorooo 


ooooooooooooooooooooooooooooromoM'O-tttttt-oorominninoroinN-nnoHioinNHiNinoNro'OOiO'ONHNin 

OOOOOOOOOOOOOOOOOOOOOOOOOOOOOO-HHfiNNNNNNNMrOIOrOIOIOttttinifilll'O'O'O'O-ONNNOOOOHHrtHNNN 

OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOxxxxxxxxxxx 


'O 

be 

<3 

cl 

O 

cl 

O 

c 

0 

"CJ 

* 

4  4  4 

4 

'Ll 

♦  +  ♦  0- 

4 

4  4 

4 

4 

4 

4 

4 

4 

4 

4 

4 

c 

4- 

4 

4 

4 

m 

c 

4- 

* 

4 

4 

4 

m 

0 

■4 

Ol 

4 

* 

4 

Ol 

4- 

jC 

4 

4 

4 

x-> 

u 

4- 

« 

4 

4 

>- 

jZ 

m 

Ol 

T3 

X- 

C 

4 

4 

4 

ru 

00 

c. 

C 

c 

4 

4 

4 

H 

»o 

•*x 

•X 

S 

m 

4- 

u» 

4 

4 

4 

o. 

L- 

0 

0 

Q.  -4 

F-X 

♦ 

■X 

4 

4 

4 

in 

a> 

Hi 

3 

0 

4- 

£ 

4 

4 

4 

in  ^ 

*- 

Ol 

0 

4- 

4 

4 

4 

ai  -o 

*• 

m 

a 

a 

in 

m 

in 

(D 

VT 

■4 

4 

4 

4 

c 

T3 

(- 

iX 

rX 

u 

01 

0 

c 

(. 

u 

<- 

4- 

4 

4 

4 

»x  Oi 

t= 

0 

3 

Ol 

Ol 

3 

X 

F  4 

•fX 

3 

10 

m 

x- 

4 

4 

4 

■-x  ^ 

u 

u 

T? 

u 

u 

u 

|X 

UI 

£ 

z 

4- 

"C 

4 

4 

4 

3 

u 

u 

4- 

ff 

4 

4 

4 

i- 

-a-» 

c 

aa 

aa 

aa 

aa 

aa 

aa 

aa 

aa 

4- 

(O 

4 

4 

4 

0- 

ai  c 

m 

Oi 

u 

s- 

L- 

c- 

t- 

s- 

s- 

t- 

xP 

Or 

Ol 

C 

4 

4 

4 

v-  c 

o 

t- 

<- 

Oi 

10 

m 

10 

CO 

CO 

m 

CO 

in 

4- 

c 

73 

4- 

c 

4 

4 

4 

o  o 

CO 

■O 

c- 

£ 

2= 

jZ 

£ 

2= 

2Z 

£ 

£: 

Ol 

01 

0 

O 

4- 

o 

4 

4 

4 

•x:  in 

2: 

Ol  Oi 

u 

U 

u 

u 

u 

u 

U 

U 

u 

u 

i-X 

u 

jZ 

C 

4- 

4 

4 

4 

•— «  rX 

t-  Ol 

Cr.  Or 

in 

in 

CO 

4- 

4 

4 

4 

1-0  cc 

rXJ  c 

CO  0- 

cc 

tn 

r- 

ZD 

3- 

3 

X 

>- 

c- 

Q. 

u 

Ol 

4- 

s 

4 

4 

4 

U  ui 

2:  -»x 

Oi 

•«H 

u 

«- 

0 

in 

0 

0. 

4- 

4 

4 

4 

•X  IX 

UI  r-X 

<-  Ol 

<n 

XX 

X 

^x 

»x 

X 

X 

^x 

F-X 

vn 

»o 

m 

4- 

— > 

4 

4 

4 

CT.  rri 

10 

U  tz 

l-X 

Oi 

t- 

l_ 

i- 

J- 

*- 

U 

t- 

c. 

t- 

u 

u 

U 

4- 

s 

4 

4 

4 

O  o 

•o-  -o 

CL 

fO  rX 

Oi 

X 

x-> 

x-> 

-a-> 

■aJ 

x-> 

•a-* 

■P 

-a-> 

3 

m 

3 

to 

4- 

4 

4 

4 

r-X  i-X 

■o  — 

in 

UI 

-O 

u 

UI 

UI 

UI 

UI 

UI 

ui 

UI 

UI 

UI 

2i 

U 

Ol 

4- 

a» 

4 

4 

4 

4- 

4» 

4 

4 

4 

a  a>  a  a. 

a  a. 

4- 

UI 

4 

4 

4 

4- 

ai 

4 

4 

4 

4- 

Cl 

4 

4 

4 

Z 

4- 

4 

C_ 

*- 

4 

Lu 

4- 

a* 

4 

•© 

T? 

4 

4 

Lu 

4- 

4 

7? 

T? 

4 

4 

Lu 

uT 

4- 

>► 

4 

CO 

rtJ 

4 

Lu 

4-  >0 

CNI 

ro  O 

4- 

OO 

O' 

0 

CM 

ro 

4- 

10 

CM 

rM 

4 

u 

T3 

4 

4- 

<►-• 

4 

4 

O  O 

>o  — 

ro 

rv 

'O 

X- 

a— 

CM 

CM 

CM 

cx 

CM 

CM 

«— 

00 

m 

rx 

■4 

m 

■•X 

4 

4 

4 

4* 

t- 

, — i 

4 

4 

IT 

4 

4 

23 

c* 

4 

4 

Ol 

4 

4- 

> 

4 

O 

4 

■*-> 

4 

4- 

^x 

4 

t- 

c 

4 

4  U 

£ 

4 

UI 

T? 

4 

3 

4 

3  3 

3  3 

8- 

3  3 

3 

3 

3 

3 

3 

3 

3 

3 

3 

3 

3 

3 

3 

3 

4-  a. 

O 

4» 

4 

CD 

t-  c 

4 

cr 

4 

CT  CT 

er  cr 

cr  cr 

cr 

cr 

cr 

W 

cr 

cr 

Cr 

cr 

cr 

cr 

cr 

cr 

cr 

cr 

4-  C 

ao 

o 

4 

C 

— 5  Ol  •  ' 

UJ 

4 

a*.  •>.  Ol  Ol 

•  -  «L  oi  •- 

•  u  .a  Dl 

Oi  Oi 

Ol 

«i 

ai 

Ol 

Ol 

Oi 

m 

Ol 

Ol 

Oi 

Oi 

Ol 

Ol 

Ol  •  -  -- 

4  — > 

r^i 

23 

4  •  - 

4 

4 

4- 

4 

4 

4 

4- 

4 

4 

4 

x-» 

rx 

e= 

4 

4 

4 

4 

Ol 

m 

2: 

m 

X 

c 

0 

a 1 

t— 

x-» 

Oi 

UI 

4- 

4 

u 

4 

4 

3  ^x 

UI 

^x 

cr. 

0 

O 

Ol 

X 

Cl 

"O 

4- 

c 

in 

4- 

4 

Cl 

4 

4 

4- 

X  X 

CO 

UI 

u 

ft! 

Oi 

3 

UI 

UI 

O 

iO 

2= 

m 

4 

4 

4 

4  4  4 

4 

V-  C 

IO  IT> 

Ol 

(■  4- 

Ol 

2= 

-IT 

2: 

2T 

2= 

2T 

2: 

2: 

2= 

Mi 

2: 

A 

4-444 
•  l»  14  •• 

4 

>  a*. 

4  4 

•  4  •• 

4 

— 3 

c  o 

r  c 

in 

U  rX 

T? 

U 

u 

u 

U 

U 

U 

U 

U 

u 

U 

A 

U 

u 

Di.  Dobb’s  Journal,  Number  51,  January  1981 


37 

33 


O  i  O  h 

C  3  3  «*-  -O 

•h  **  O 

t-  Ol  -*-> 

C  •*>  W  ♦»  X 

o  m  *  at 

H  t.  +»  JO  C 

h  %.  m  j>  a. 

w  h  u  3 

o  t-  X?  (0 

a.  o  c  ^ 


v  m  o  tj 
I'D  1/1  Qj  c 

-h  in  c  f» 

II  OlV  o 
U  Cj  o  H  w 
Ol  V  Ol 
u  c  m  (-  u 
Oi  ♦>  o  i 
a.  31  h  a.  u 


~  O  «  I-  t~  ~  ^ 

-j  a:  o  a:  a:  _i  _j  o 

x  a:  _i  o  :>  x  x  5 

—  uj  <x  z 

“■  ►  JNO  ►  JO  »UJ  »  i  in 

«<NUI2U(3IUIiJfi  SliJ4«MaaN  uj  i  (j 

-J  -1 

u  _j  cj  _i  k  oc  a  u  i-  <i  <i  <i  cj 
JOTUHTUJH(JJLJCtJJXJCOQ£C(2(2i2JHT 


<1  UJ  Uh  Q  >-  UJ 

Z  OltQOCN 

O  <X  -  UJ  ro  _J  U- 

•h  CC  _l  3>  -  UJ  3 

01  UJZK4QCB 


o  >-  a. 
<r  A.  oi 
«  cm  o  »- 
»  »  a  3  _j 
cd  <x  x  t-  r 


-1  _J  Z  I- 

oo««tuj 

J  JUUmCC 


O  O  O  o  o  o  < 
•OMB^Onr 
OOOO^^i- 
NNNNNNt 


2?$oooooooc,000°ooooooooo 

a30'0^r^n^in>orsa3i>‘0’-«r>jr*i^,in>or^QOO'0^ 

l/HJl'fl’O'fl'O'fl'O'O'O'O'CNNNNNNNNNMDUl 

N  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM 


O  CM  r 4  * 

^  -A  CM  CM 

cm  w  n  r*i  o 


i/i'OinotcjpjM 
roncMncMooo 
_ ooo 


\  O  O  CM 

o  >0  o  o 

ONON 


o  o  in  o  in  ri  O  CM  CM  CM  OOO  M 

£  £  —  S  5  «  !2  2  H  ■orv-O’-incMinrsnuirsn^'O'Orv^'omuiorvrvrv.rsno 

N'OinNtOHfjtHninHomnNt'OOHfujrjntn 

ocMOOonnnroniooon  »-«CMOCMor*in»-iof,,i»-irof'ioocM»Hr»icMonooo»HOO 


ncjn  in  ^ 
o  o 

won  wo 

WCCO-OhO 

»r  n  n  o  v 

cj  h  cj  o  n  n 


oorj-o 
*00-0 
cm  ©  cm  t*i 

n  -o  in  in  o  h 
o  n  *h  •-<  rj 
O  M  M  O  M 


X  S  ~  ^  ~  2  ^  n  ^  0,4  ^  (V|  ^  ^  ^  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  fN  pj  CN  f 

ftftftSftSftrtSftSS2S2S222222222000000000000ooooooooooooooooooooooooooo 

000O0000000000000000000000000000QQQQ0OOOO0QQQQQQ00Q0000^^^000o00(, 


H  Oi  vvu:  HI  O  •'Oh  h 

I  >  3  VUJ  iMI  h  m  3  W  ♦> 

uiHj033Hin  *i  mu  c. 

•h  ♦>  AO  L  I  U  Oi  C  •  n 

3  0  3  _JT3(-  »  fc  .*  -H  «.  ♦* 

a  c  I  '  t  «-  3  *■<  oim 

C  H  O  4TJ  •*>  3  •  Ol  A. 

ot-«t-c  <•  x  w  oi  ♦>  uj  cm  ♦ 

*•  *  I  V  H  3  H  Jh#  > 

*-  ♦>  o  *  m  inw^joi/iai** 

C  0  •  •  •  C  CK-  N-H* 
in  H  U  b  I  -H  U  H  V  H 


•  •  •  ♦»  h  m  si  h 

-CMC  -  CC  C  XI  3 

*  •  O  in  t  h  O 

ai  ii  'H  m  i  ii  m  m  in 

OJ  *  «  HflLW 

•H  -H  o  k  U  Ol  U  Ol  QJ 

V  V  O  3  IJ  t  f T>  ♦>  u 

«-  3  oi  oi  m 

«  «  ♦>  I'D  m  •  _j 

O  O  A  C  0  W 

«-  U  3  »  3  C3  U  C  3 

vmi  ii  c  in  hc 

»H  *  -H  V-  C  H 

ll  ll  3  I  U  O  h 

♦>•*>  A  m  t-  i»  (»X 


3  •  •  V  ~ 

«-  (•  U  o  4» 

Oi  Oi  Ol  Oi  UJ 

■**  £t  ■*»  ♦»  t-  _J 

C  C  C  H  IH  • 


I  3  3  u  31  U 

UJ  O  CO  O  CO  O 

1  H3  H  u 

m  a.  co  a. 

oi  v  m  in  3i 

h  o  h  v  h  n 

v-  3  0  3-1 

H  ♦>  0. 

-o  «-  u  ♦»  u  in 

o  co  o  u  O  H 

&  0.  V  0  V  3 


I  3  31  l-  3  «- 
UJ  3  CO  3  <0  0 

CO  •— l  "0  'H  . 

in  ol  at  a.  xn 

oi  v  m  in  3>  c 

H  o  H  4-  H  CD  H 

%_  3  0  U  H4) 

•h  a.  ■*»  • 

3  i-  i-  Ji  I  t 

OCOOC-OneO) 

•  e  j.  v  io  v  3  <•  «j 

a.  o  c 


o.  in  i-i  cc 

in  xn  ^  ai  \ 

H  c  H  ro  u  o 

v  H  V  CO 


c  xn  in  in  xn  oi  c 

H  c  H  H  H  in  -H 

v  ‘H  *h  m  oi  u 
■p  •  c  3  x  a.  • 

COU  H  i.  n  v  ♦)  u 

6  oi  co  o  h  m  *oi 

u  +»  -  «  i.  ol  ro  v  -h  -P 

o  c  Mi  u  m  oimh  c 


U  <Z  _J  K  C/3  01 


o  CM  ->•*->  — 


A.  Z  AC  a  Z  CC 
UI3HQUJHX  uj 
in  _J  _J  <t  3  _l  I  Q 
<t  _j  -  r  o  -  '  <t 

AC  O  — J  C/l  __J  _J  -  O 


a i  UJ_J-Q~  XQ  QX 

-  -  I—  -  '  <1  “  OZ  ^ 

ujjuij  *ouj  cj  <r  »  » 


it  u  j  ui  j  j  »o  u  j  j  in  j  »  o  u 

ujax«viuj4«iiviujo 

JJ  j  j  _i 

_l  _l  _J  -J  CC  CJ  CJ  _J 

«<IO«QQQ<tOQflQZQQQ«Q 
CJ  CJ  _J  U  JJ  JUX  JlflH  J  J  JOJ 


axu-^u  z  i-h  u.  uj  Ci  «<t  <t<icn  (j  ~  o  ^  <r 

w  ^  *  -  t-  U.  X  K  UJ  Q  h  ill  h  CJ  UOKai-CJh  ‘JIN  JU 

*■  *  N  _J  _J  _J  cn  N  J  »  j  U  O  >-  U.  UJ  *■  cj  •.  U  •.  ui‘  *U»U  ‘JUJJJI  »»I  ‘J 

caaziiiv^izjiNiau  cdo  am  «  o«  o  4  aai«io<ro«rciXX^N«^NX 

_ ^  A.  CJ  (J  I  w  J'  J  W  d^JA-WU  a  JO. 

C,Cl.5^?C^(±IQOa-9SQ-O0c220c  3QQ«ra«Q  IfiCCuOQOODQUJaaZOO 

JJMUt  J0JX010(LTmh3  Ci _ I  JUJU  J  I.  J  J  U  J  U  JU  O.  0.  JQ  1  J  4  UO. 

in 


_J  _J  _J  X  _J 

uj  -j-  -j  uj  _j  _j  _ju.cn  u  a  j  a. 
3A  C  4D  4  Q  3Qfi4fi4M403CUJ[CQZ40 
LJ  JUJU  J  I.J  JUJU  JULA.  JQ1J4UL 


OZ  cj  r  Kil^  ^ 

o  o  o  «  ^ 

»»**u  z 

2222?«?2?22229?2?20?20000$000000000000000000000oooooooooooooooooooooooooo 
SJScS~52:rr^2'4M^in'or'ooc>'0'Mr'4n,'tn'ors,:D(>s0'Mr’4n^',f>,<)rs®c>k0^c'')M,»'|^'Ors®l>'0’H^w^-in'Orso^r-jn^in'Ors(DO‘0^rjn<rin'Or». 
2255555i2^2^^^l>'(>'<>'(>“<>‘000c>000000,H^^^^’H^,^’^^tN‘r-4C'4C,'4r'4(Vir'4r'ir'4r'IMMnMMr^f^  nn 
00000000000000000  —  ^«-<^->— 


O  0£ 
00  .£ 

I  tn 

N  2 


n  T4  MJ  (M  C4  O  T4 

▼  O  «r  O  O  *  O 

w  o  n  o  o  n  o 


CM  *0  CM  n 

o  *■  on 

o  w  o  f*l 


nrjinonininN  rnr4  min^Nn 

tcjnnum/iH  nmnnM 

cjwm  cjnncjfj  ~  n  n  cj  cj  -< 

inm»HincM"i«oinP'»ininmcM»H'Cinin 
-.<r«r^^mmunM-T5r^^un 
MMO  MOOOMCMnnOOOOMM 

J(MIOOn'OHt'(lHfJ>OOH»N«^C 
loot  ttmmin-O'O'ONNNNOO* 
■<  ^  ^  hhhhhhhhhhhhCJCMC 


cj  in  in 

<r  n  n 

C4  M  r*l 


^  H  CJ<0 

rv  n  oo 

^h  *-»  o  n 


jMCjN^oinnonno  inwr-Jinoin'C  u 

iin*-inr‘*-rs<rin«rcMn  cj  o  n  -  n  h  n  r 

ioocjnocjmoooo  ro-^^n^no  r 

CJM'ONOCJMT'ONOCJCJNCJCJMtinOH^CMC 
(MCJCjcjnncinnMvw^v^Ttvininin^i 
CM  CM  CM  CM  CM  CM  CM  CJ  CM  CM  CN  CM  CN  CN  CN  CJ  CJ  CJ  CM  CJ  CJ  CJ  CJ  C 

OOOOOOOOOOOOOOOOOOOOOOOC 

OOOOOOOOOOOOOOOOOOOOOOOC 


)  O  >0  >0  ^ 

)  U1  rv  5T  T 

»  O  O  CJ  M  M 

)  NrtM 
)  >ONN  NN 
J  CN  CN  C“J  f J  fsl 


38 

34 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


MOhNONMOK) 

M-ocM*,*CM**'cn 

CMO*«CMr)*«CMtMM 

M^t^^NCMCMCM 

m-oooooooo 

noooooooo 


uiZu.u)UHUjau) 
WHO  JNOIQOO. 
«o»-*hu.oj<o:uj 
auz«3ujoo;h 
uj  sa.L.  cor  juu 


ooooooooooooooooooooooo 
r^ntin-ONCDO-OHNrotbT'flMiiO'O-cjnv 
CDCDCDCDCOCDCDCD&'O'thO'&'O'O'O'O'O'OOOOO 
N  N  N  fKJ  N  N  N  N  M  N  N  N  (N  N  N  M  N  M  M  M  M  M 


NHNMtNtOnO 

ooomcMrxrxmno 

(MCM^CMnn-HCMMO 

nidrtHHHtNn^n 

▼^oooooooo 

wmoooooooo 


40NH(ALMill 

JI-I-ZWhZJO 

>ua:ohuzoou 
hao.zii.tinu  ji 


CMOoorxm^ncMrx 
'0-<*-.-*oinrx*-cMrx 
^  (NONnn  n 

IODhhhhNNNN 
*■*•©©©©0000 
nnoooooooo 

O  CC  I-  Z  1-0. 
QhZCHHJCCDk: 

nQHnaz«>Ju 

>-u>-r_jujh-z_j<i 

UlMilOOZUOOh 

zt-zuxuoozcn 


innrorown^rxooooooooooo© 
>MMwnr)nnM000000000000 
iNNNNNiNNNMnnMnnMnnnnn 
>000000000000000000  00 
>00000000000000000000 


ro  ro  o  o  o  o  o  < 
ft  w  u.  u  z  t-  oe  c 

ft  V3  JHUUKNt 
S.  in  a  O  h  O'  N  ID  < 
Kzozzjun 

T  Cl  H  o  O  «  M  Ui  C 

V# J  O  JhUUItt1 


I  H  •  M  (I 

u  U  ■*»  U 

I  •••HU 

:  h  ♦>  t-  D  Cl 

-  «  C  *  •  « 

)  JC  •*  £ 

•  (JOU  )l 
I  «L  -< 

-  +>  *>  c  m 

c  •  x  o  ♦> 

!T  g  g  i,  Z 

)  t  •  I  • 

i  >  31  TO  C 

«  T>  fc  -h  • 

►  «  h-  O  O 


r3  Is 

OO 


OOOOOOOOO 
NKlt  n<N®>0 
«h  —1  —«  — (  *H  «H  •—«  CM 

OOOOOOOOO 


~  o  o  ••  «  < 

••  O  *  N  Jl- 

««N(NU<ZZ»I 


K  -I  -JO 

QKuia.«a  «zit  ( 

JOIZUDOUH"). 


>ooooooooooo< 

>-NWfin>oN«o-OH( 

>ooooooooooo< 


o 

a 1  ai  z 

»  ♦>  ^  v 
(1  COVN 

:  •*  ®  oro 

)  U  £  jQ 

1  1  Cl  £ 

«  X)  ♦> 

-VI  C  -H 

D  H  ro  3 

l  31  e 

I  k  n  c*> 

)  ID  rH  0  -H 

t  a.  a.  o 
re  ui  xn 

-  flL  H  ♦»  C 
)  X5  3'H 

a  0  -< 

jo®  -< 

:  n  c  * 

II  H  ll  It  V 

r-i  &  ® 

o  L  n 
CCIl  u 


U  U  U  U 

ro  ft  ft  m  ' 

OLflLflLflL  — 
Ui  Ui  Ui  III  Z 

D 

NN  N  Nh 
CM  CM  CM  CM  Z 
-*  ^  UJ 


ui  _j  <r  _j 
x  x  _i  <x  o 

U-  IUiZ 


vrjoo- 
u  n  -  <r  m 
*  CM  N  CM  Z 


NNN-O  O 
NNNNU 
O  h  h  h  O  ' 


_J  tJJh 

«  a  o  «  <  u 

U  _J  0.  UU  CC 


OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO 

GOO'O^CMr)*-uT-oivco&>o-iCMr)^in'OrsGOO'0-iCMr)<rin'Or^oo(>.o-icNr)*-in'OrxcDCho^cMr)<r 

^•«rjoininininininifiiniOMJ'0'0'0'0'0'0'0'0>orvrsNrsrsNrsrsrvfsooaDooQDOocDa)03cooDO‘0'C>-«>>0' 


000000 
o  ^  cm  n  ft- 10 
000000 

CM  CM  CM  CM  M  CM 


)  rx  rx  rx  n  rx  cm 

>00000^ 

uonn  nnn 


h  h  (M  CM  fi  f 

r)  m  r)  r)  r)  r 


(MinwoinO'OMH^n 

o«riii^'rfOorm^>o 

nnnMfiMnnionnn 

ll^HVMMl)OOTHr<) 

«r'0i/)^ovM’ru''0O'0 
nrtnnnror)  cm  c\i  nnr) 

^■N-OHn-oorjincjoin 

'OinoO'Oin’f 

h  000  nronmmr)  cm  r)r*)m  cm  r)  c 

1  «r  v  o  r« 

0  •OVOOlilH'OyT^rtM^o, 

in^<r^-<r«r*r<rin<t<r-oin 
1  rj  ruj  n  n  ♦  in  n  fi  n  n  n  n  cj  m  n  n  n  m  cj  i> 

sfxrxrxrxrxrxrx  f. 

ofonMMnnmooriincKJOOH^yj^mc 

'C’T-ociT'CUT-otn^rinr 

^oooooooncMnrorororirjnnnncMC 
>0000000  < 


o  rj  orxtxrx-o  r) 

o  o  rx  IX  ix  cm 

o  in-ooHHHO  r* 

ft-  io  m 

rtonocMHCjn^m-on 

cm  cm  nmrjMMr) 

H  T-OH  HHrt  HHf) 

CM  CM  CM  If)  CM  CM  CM  CM  CM  CM  O 
ooncMOOoooor) 

00  000000 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


Software  Review 

8080/Z-80  Editor,  Assembler, 


you  have  had  your  North  Star 
floppy  disc  system  for  a  while,  you  are 
beginning  to  recognize  that  there  are  a  lot 
of  things  which  can  be  done  either  much 
faster  or  only  in  machine  code.  You  may 
have  tried  entering  machine  language 
programs  in  hexadecimal  through  the 
monitor;  this  effort  probably  lasted  only 
20  or  30  minutes  — unless  you  were  truly 
desperate.  Now  that  you  are  ready  to 
select  one  of  the  many  disc- based  assem¬ 
blers,  the  following  thoughts  should  be 
kept  in  mind. 

First,  like  good  books  and  fine  wine, 
no  piece  of  software  is  suitable  for 
everyone.  Further,  no  piece  of  software 
will  do  exactly  what  you  want,  in  exactly 
the  way  you  want  it  done.  I  describe  here 
what  I  consider  to  be  a  delightful  disc- 
based  assembly  language  software  devel¬ 
opment  package  from  XL  Computer 
Products  (P.O.  Box  805,  Mesa,  AZ 
85202).  The  package  consists  of  an 
EDITOR,  ASSEMBLER,  and  DISAS¬ 
SEMBLER.  I  describe  the  strengths, 
weaknesses,  and  overall  operating  charac¬ 
teristics  of  the  system  so  that  you  can 
determine  whether  this  package  satisfies 
your  needs. 

The  XL  package  is  available  in  an  8080 
and  Z-80  based  version.  By  software 
standards  the  cost  is  modest:  $39.95  for 
the  8080  version  and  $59.95  for  the  Z-80 
one.  Updated  versions  such  as  the  current 
multi-disc  drive  version  can  be  purchased 
by  owners  of  the  earlier  releases  for  the 
reasonable  copying  fee  of  $9.95  and 
$14.95,  respectively.  In  view  of  its 
performance,  I  rate  the  XL  package  as  an 
excellent  buy.  Indeed,  I  am  adopt¬ 
ing  it  to  use  in  teaching  the  software 
portion  of  an  interfacing  course  for 
chemists. 

The  XL  package  is  not  a  general 
purpose  DOS;  it  is  oriented  only  toward 
assembly  language  program  development. 
The  EDITOR  is  for  creating  or  modifying 
assembly  language  source  files;  the 
ASSEMBLER  is  for  generating  machine 
executable  code  files,  and  the  DISAS¬ 
SEMBLER  converts  raw  machine  code 
into  assemblable  assembly  language  files. 
The  power  of  the  system  is  shown  by  the 


by  J.N.Demas 

Copyright  ©  1980  by  J.  N.  Demos,  Chemistry 
Department,  Univeristy  of  Virginia,  Charlottes¬ 
ville,  VA  22901. 


following  example.  Using  a  single  density 
North  Star  disc  drive  (~  84K/disc)  and  a 
24K  RAM  system,  I  disassembled  a  9K 
machine  code  program  to  generate 
80K  of  linked  assembly  language  source 
disk  files.  I  then  edited  the  source  files 
and  reassembled  the  entire  9K  object 
code  program  in  a  single  pass.  This  could 
have  been  done  somewhat  more  tediously 
using  only  16K  of  RAM.  With  one 
double  density  disc  system,  an  object 
code  program  of  about  20K  could  be 
disassembled,  edited,  and  reassembled  in 
a  single  pass.  Machine  language  programs 
this  large  are  more  than  adequate  for  all 
but  the  most  dedicated  (or  inefficient) 
programmers. 

If  you  need,  or  like,  the  incredible 
range  of  commands  of  CP/M  with  the 
ability  to  submit  chains  of  commands,  to 
change  file  names,  copy  one  file  into 
another,  etc.,  then  the  XL  package  may 
not  be  the  one  for  you.  An  exception  to 
this  may  be  if  you  find  that  you  do  not 
have  a  large  enough  disc  system  to  handle 
your  programs  in  the  context  of  a  CP/M 
operating  system. 

Overview 

The  EDITOR,  ASSEMBLER,  and 
DISASSEMBLER  are  all  transient  pro¬ 
grams  that  overlay  with  no  more  than  one 
resident  in  RAM  at  any  one  time.  The 
EDITOR  uses  meaningful  four  character 
mnemonics  for  commands  in  the  tradi¬ 
tion  of  Processor  Technology  (indeed, 
most  are  the  same)  and  is  trivial  to  learn 
to  use.  The  programs  are  all  very  chatty, 
giving  the  operator  good  cues  rather  than 
cryptic  ones.  The  entire  package  is  easy 
to  learn  to  use  if  you  know  assembly 
language;  you  should  be  using  the  system 
adequately  in  one  or  two  hours  and 
proficiently  in  a  day.  Most  of  my  prob¬ 
lems  arose  because  I  just  scanned  rather 
than  read  through  the  manual. 

All  disc  and  input/output  operations 
are  performed  through  the  North  Star 
DOS  so  that  if  you  have  a  functional 
North  Star  DOS,  there  are  no  bothersome 
patches  to  make  to  bring  the  XL  programs 
up.  Also,  if  you  have  a  single  density 
or  double  density  disc  controller  the  same 
software  will  work  with  both.  The  XL 
package  is  supplied  in  single  density  for¬ 
mat,  which  you  can  easily  convert  to  dou¬ 
ble  density  if  you  wish.  The  EDITOR, 
which  also  functions  a  monitor,  is  used  for 
creating  files  and  saving  them  on  disc  and 
for  fetching  and  editing  existing  disc  files. 

An  interesting  and  unadvertised  fea¬ 
ture  of  the  Z-80  package  is  that  it  is 


written  entirely  in  8080  machine  code. 
This  means  that  the  XL  programs  will  run 
on  either  a  Z-80  or  an  8080  develop¬ 
mental  system.  While  this  feature  may 
incense  the  purist,  I  am  delighted  with  it 
since  I  have  a  great  deal  of  money  in 
8080A  based  SOL  and  MITS  computers 
and  want  to  develop  software  for  Z-80 
single  board  systems  without  having 
to  set  up  a  complete  Z-80  developmental 
system.  The  XL  package  permits  me  to 
do  this  without  a  major  new  expendi¬ 
ture.  The  only  penalties  are  that  the  XL 
software  has  somewhat  larger  memory 
requirements  and  executes  more  slowly 
than  if  it  had  been  done  in  optimized 
Z-80  code.  I  have  talked  with  Robert 
Walden  at  XL  and  both  versions  will  also 
run  on  a  Z-80  system. 

The  EDITOR  created  source  files  can 
be  no  larger  than  the  RAM  space  follow¬ 
ing  the  EDITOR,  which  is ~17K  fora  24K 
system  starting  at  2000H  (2000H/ 

7FFFH).  The  ASSEMBLER  is  a  standard 
two  pass  assembler  that  operates  on  disc 
source  files  rather  than  RAM  stored  files. 
The  ASSEMBLER  works  on  the  disc  file 
piecemeal,  and  it  never  has  more  than  a 
small  portion  of  the  source  in  RAM  at 
any  one  time.  Thus,  the  only  RAM 
required  during  assembly  is  for  the  DOS, 
the  ASSEMBLER,  1280  bytes  of  disc 
buffer,  and  the  complete  symbol  table.  In 
a  16K  system  this  limits  you  to  about 
1000  symbols  — a  number  which  I  find 
inconceivably  large  — my  disassembled  9K 
object  code  file  yielded  only  about  600 
labels.  Programs  that  are  longer  than  the 
RAM  file  space  may  be  assembled  by 
linking  several  source  files  together  at 
assembly  time;  I  will  return  to  this 
feature  later. 

From  raw  object  code  the  DISAS¬ 
SEMBLER  generates  either  a  simple 
assembly  language  listing  or  assembly 
language  source  disc  files.  Unlike  many 
popular  but  inferior  disassemblers,  the 
XL  automatically  generates  labels  for  all 
referenced  lines.  The  generated  assembly 
language  files  are  thus  immediately  ready 
for  reassembly.  As  with  other  disassem¬ 
blers  this  one  generates  improper  code  on 
ASCII  strings  and  jump  tables,  so  these 
do  have  to  be  picked  over  manually. 

EDITOR 

The  EDITOR  is  a  combination  moni¬ 
tor-  and  line-oriented  editor;  line  num¬ 
bers  are  used  to  maintain  proper  order, 
and  to  list  or  modify  lines.  The  EDITOR 
commands  are  listed  in  Table  I.  In  case 
you  forget  the  commands,  COMS  lists  all 


40 

36 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


Disassembler 


valid  ones.  The  DUMP  and  ENTR  are 
standard  monitor  commands  for  display¬ 


FIGURE  1. 

Commands  recognized  by  the  XL  EDI¬ 
TOR.  These  are  printed  out  on  typing 

COMS. 

ENTR 

DUMP 

JUMP 

FILE 

LOAD 

SAVE 

ASEQ 

RSEQ 

LIST 

SCAN 

DELT 

APND 

EXIT 

MOVE 

CONV 

ASSM 

ing  memory  contents  in  hexadecimal  or 
for  entering  data  into  memory.  Argu¬ 
ments  may  be  in  hexadecimal  (hex), 
octal,  or  decimal.  Hex  numbers  must  be 
followed  by  an  H,  octal  by  a  Q,  and 
decimal  by  nothing  or  a  D.  Since  my  SOL 
monitor  assumes  hex  arguments  with  no 
suffix  H,  I  am  always  inadvertently 
entering  decimal  values. 

An  important  feature  of  this  XL 
program,  which  should  be  emulated  by 
others,  is  that  you  cannot  enter  data  into 
the  ASSEMBLER,  the  DOS,  or  the  file 
area.  Programmers,  especially  new  ones, 
find  this  to  be  a  serious  error  source  and 
this  simple  human- designed  feature  will 
save  innumerable  hours  of  retyping  a 
destroyed  file. 

The  FILE  command  is  used  to  name 
the  current  file  (only  one  can  be  in 
memory  at  a  time)  or  to  display  the  file 
parameters  (start  and  end  RAM  addresses, 
the  number  of  disc  blocks  required  to 
store  it,  and  the  last  line  number).  The 
command  LOAD  namel,  will  load  the 
named  file  and  make  it  the  current  file; 
this  overwrites  any  file  in  memory.  SAVE 
and  SAVE  name2,  save  the  current  file  on 
disc  either  under  the  current  name  or 
name2.  If  a  file  with  the  same  name 
exists,  it  is  overwritten.  If  no  file  of  that 
name  is  available  then  a  new  one  is 
created  with  that  name. 

The  command  APND  name2  appends 
the  file  name2  to  the  end  of  the  current 
file  and  updates  the  file  information.  If 
you  have  misfigured  and  the  composite 
file  consisting  of  namel  plus  name2 
exceeds  the  memory  available  to  the 
EDITOR,  a  memory  overflow  error 
message  is  issued  and  the  original  file 
is  kept  intact.  Thus  an  APND  can  almost 
never  lose  an  existing  file.  The  APNDed 
file  is  always  placed  at  the  end  even  if  its 
current  line  numbers  would  imply  em¬ 
bedding  it  in  the  middle  of  the  current 
file.  The  line  numbers  are  just  updated,  if 
required,  to  reflect  their  current  posi¬ 
tion.  The  only  time  I  have  destroyed  a 
file  in  RAM  is  when  I  APNDed  a  file  that 


was  so  long  it  overwrote  my  MONITOR’S 
scratchpad  RAM,  which  is  at  high  mem¬ 
ory.  Any  reasonable  attention  paid  to  file 
and  RAM  size  would  avoid  this  problem. 

RSEQ  argl,  arg2  renumbers  the  entire 
file  from  the  beginning.  Argl  is  the 
desired  starting  number.  Arg2  is  optional 
and  is  the  step  size.  ASEQ  argl,  arg2  is 
the  autoline  number  sequence  that 
automatically  inserts  line  numbers  while 
entering  programs.  Argl  is  the  start  value 
and  arg2  is  the  step  size.  By  use  of  RSEQ 
and  ASEQ  new  typed  material  is  easily 
added  to  the  interior  of  an  existing  file. 
Unlike  the  Processor  Technology  assem¬ 
bler,  line  numbers  are  not  limited  to  9999 
but  can  be  as  large  as  65535  (16  bits). 

CONV  argl,  arg2  takes  the  difference 
of  argl  and  arg2  and  displays  the  result  in 
hex,  decimal,  and  octal.  If  arg2  is  omit¬ 
ted,  it  is  treated  as  0.  This  function  is 
invaluable  for  calculating  addresses  for 
the  assembler  or  just  as  a  hex,  octal, 
decimal  calculator.  For  someone  with  as 
poor  an  arithmetic  sense  as  I  have,  this 
function  has  avoided  countless  program¬ 
ming  errors. 

The  most  delightful  feature  of  the 
EDITOR,  however,  is  SCAN.  This  is  the 
search  and  search/replace  command.  For 
example  SCAN“NAME”  would  list  all 
lines  on  which  the  string  NAME  occurred. 
SCAN  “LABEL”  “NEWLABL”  will 
search  for  and  replace  every  occurrence 
of  LABEL  with  NEWLABL  and  print  out 
every  line  as  it  appears  after  it  has  been 
changed.  The  old  and  new  label  may  be 
shorter,  longer,  or  the  same  length  as  the 
old  label.  SCAN  is  invaluable  for  re¬ 
placing  disassembly  “L”  labels  with 
meaningful  ones  and  for  modifying 
labels  in  subroutines  so  that  label  con¬ 
flicts  are  eliminated  when  building  up 
programs  from  a  set  of  libraries. 

The  line  editor  uses  most  of  the  same 
commands  as  the  North  Star  BASIC  line 
editor.  Therefore,  for  those  proficient 
with  the  North  Star,  editing  will  be  easy. 
DELT  argl,  arg2  is  the  standard  line 
delete  command.  MOVE  argl,  arg2  copies 
a  256  byte  block  of  memory  from 
address  arg2  to  address  argl.  Again  you 
cannot  overwrite  or  damage  your  DOS, 
EDITOR,  or  file  with  a  MOVE  command 
as  the  EDITOR  senses  this  impending 
disaster  and  refuses  to  do  it. 

ASSM  or  ASSM  file2  loads  the  AS¬ 
SEMBLER  and  begins  assembly  of  either 
the  currently  named  file  or  of  file2.  All 
assembly  is  done  on  disc  files,  and  the 
current  file  in  RAM  is  destroyed.  The 
EDITOR,  however,  protects  you  from 


loading  a  file,  spending  an  hour  editing 
and  then  destroying  it  by  an  ASSM.  If 
you  change  the  file,  the  EDITOR  will  not 
permit  assembling  it  until  you  SAVE  it. 

ASSEMBLER 

The  ASSEMBLER  can  be  entered 
either  as  a  GO  program  using  the  DOS 
command  or  from  the  EDITOR.  If 
entered  from  the  DOS,  the  ASSEMBLER 
asks  you  the  file  name  to  be  assembled. 
The  ASSEMBLER  is  chatty  and  asks  very 
specifically  for  what  it  wants.  If  you  read 
the  cues,  you  are  hard  pressed  to  err. 
Assembly  time  options  include  generat¬ 
ing:  (1)  object  code  disc  file,  (2)  com¬ 
plete  assembled  listing,  (3)  assembly  error 
listing  only,  and  (4)  object  code  stored  in 
memory.  The  object  code  stored  in 
memory  is  not  very  useful  since  it  is 
stored  in  the  ASSEMBLER  file  area  and 
this  has,  in  general,  no  relationship  to  the 
actual  assembly  location. 

Being  exclusively  a  disc-based  system, 
the  disc  activity  is  nearly  continuous 
during  assembly.  For  those  whose  only 
experience  is  with  assemblers  that  work 
entirely  on  RAM  files  such  as  ALS8,  the 
enormous  reduction  in  speed  necessitated 
by  the  disc  activity  will  be  a  surprise.  A 
16K  source  file  (about  2K  of  object  code) 
without  comments,  requires  about  90 
seconds  to  assemble.  This  appears  to  be 
comparable  to,  or  faster  than,  the  CP/M 
assembler. 

One  of  the  most  significant  features  of 
this  assembler  is  the  inclusion  of  the  new 
pseudo  op  LNK  “name.”  This  is  the  link 
disc  files  command.  When  encountered  in 
a  file  during  assembly,  the  pseudo  op 
LNK  NEXTFIL  instructs  the  assembler  to 
continue  the  assembly  process  on  the 
next  disc  file  (NEXTFIL  in  this  case). 
Any  number  of  disc  files  may  be  linked 
or  chained  together  by  inserting  the  LNK 
command  at  the  end  of  each  piece. 
Forward  and  backward  references  to 
labels  in  other  disc  files  are  all  properly 
handled.  The  only  limitation  is  that 
all  files  must  be  on  accessible  disc  space 
at  any  one  time;  in  a  multidisc  drive 
system,  the  link  can  be  specified  to  a  file 
on  any  of  the  available  drives.  Irritating, 
but  not  fatal,  operator  errors  are  to  forget 
that  any  source  code  in  a  file  following 
the  LNK  is  ignored  and  LNKing  a  chain 
of  files  back  on  itself— the  snake  devour¬ 
ing  itself  problem. 

Another  unusual  feature  of  the  AS¬ 
SEMBLER  is  that  symbolic  labels  can  be 
up  to  10  characters  long  and  are  unique 
to  10  characters.  Thus,  ANOTHERNM1 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


41 

37 


Software  Review 


and  AN0THERNM2  are  different.  With 
10  characters,  meaningful  labels  can 
profitably  be  used  to  make  a  program 
largely  self- documenting. 

The  ASSEMBLER  has  the  equivalent 
of  an  ALS8  ASC  statement,  which 
permits  embedding  ASCII  text  strings  in 
the  program.  This  is  done  merely  by 
putting  quotes  around  the  string.  For 
example,  “PLEASE  PUSH  BUTTON  #1” 
will  embed  the  enclosed  20  character 
ASCII  string  in  the  machine  code.  Com¬ 
ments  are,  of  course,  permitted  in  the 
source  listings. 

Multiple  statements  per  source  line  are 
permitted.  For  example: 

1000  LOOP  INRA/INX  H/ MOV 
M/  JNZ  LOOP 

would  replace  four  lines  of  source  code  in 
many  other  assemblers.  The  “/”  func¬ 
tions  as  a  delimiter  between  op  codes. 
The  only  limitation  is  that  no  labels  are 
permitted  except  at  the  beginning  of  a 
line.  Thus, 

1000  INR  A  /  LOOP  MOV  M,A  / 

INX  H  /  JNZ  LOOP 

is  not  permissible,  because  the  assembler 
tries  to  interpret  LOOP  as  an  op  code 
rather  than  a  label. 

The  file  structure  is  interesting.  It  is 
similar  to,  but  more  efficient  than, 
Processor  Technology’s  Software  Package 
1  or  ALS8.  In  the  XL  files,  the  form  is: 


The  end  of  file  marker  is  a  01,  and  the 
line  byte  counter  is  the  total  number  of 
bytes  in  the  line  including  the  counter 
and  the  CR  just  as  in  ALS8.  The  XL  line 
number  is  always  stored  as  a  two-byte 
pure  binary  number  and  is  converted  to 
decimal  when  printed.  In  ALS8  the  line 
number  is  always  a  four  digit  ASCII  num¬ 
ber  (9999  maximum  line  number)  stored 
in  four  bytes.  Thus,  the  XL  format  saves 
two  bytes  per  line  over  ALS8  and  permits 
lines  numbered  to  65535.  The  XL  format 
of  multiple  statements  per  line  adds 
further  memory  savings  since  one  byte 
counter,  one  line  number,  and  a  CR  serve 
in  several  statements.  Thus,  substantially 
more  program  can  be  stored  in  XL  format 


than  in  ALS8  format  (perhaps  20-50% 
more).  The  XL  format  is  close  enough  to 
ALS8  format,  however,  that  conversion 
between  the  two  is  straight  forward. 
Thus,  if  you  have  reams  of  ALS8  or 
Software  Package  I  programs,  conversion 
to  XL  format  is  easy  (I  will  describe  such 
a  program  elsewhere). 

DISASSEMBLER 

A  disassembler  is  an  essential  element 
of  any  software  development  system.  In 
many  cases  machine  language  software 
suppliers  do  not  give  adequate  informa¬ 
tion  to  modify  their  software  to  ac¬ 
commodate  your  own  special  needs  such 
as  I/O  drivers.  In  other  cases,  as  has 
unfortunately  happened  to  me,  the  single 
assembly  language  source  has  been  lost 
and  only  the  functioning  machine  lan¬ 
guage  code  is  available.  In  both  cases, 
a  disassembler  is  invaluable  to  properly 
modify  or  recover  the  software.  A  word 
of  warning  is  in  order,  however.  The  new¬ 
comer  who  thinks  that  he  is  going  to  go 
out  and  promptly  tear  down  and  correct 
or  modify  someone  else’s  undocumented 
machine  code  is  in  for  a  rude  awakening. 
For  all  but  the  most  trivial  programs, 
determining  how  someone  else’s  software 
works  and  modifying  it  is  a  long  and 
tedious  process  —although  if  done  on 
good  software,  it  is  an  excellent  way  to 
learn  good  programming. 

The  DISASSEMBLER  disassembles 
type  1  GO  disc  files.  The  GO  address  is 
treated  as  the  origin.  Simple  disassembly 
with  listing  and/or  generation  of  a  source 
disc  file  are  permitted.  Figure  2  is  a 
printed  portion  of  an  original  source  and 
a  sample  disassembly  of  this  program. 
The  lines  “ASCII  »  . . . «”  are  the 
ASCII  equivalent  of  the  above  block  of 
code;  this  ASCII  listing  is  not  put  into  the 
disc  file  (I  rather  wish  that  it  had  been 
since  it  would  be  easy  to  edit  out),  but  is 
useful  for  locating  jump  tables  and 
messages.  A  careful  study  of  a  listing 
reveals  the  interesting  trade-offs  that  the 
authors  made.  Overall  I  think  that  they 
made  excellent  choices,  but  intelligent 
study  of  the  listing  is  always  essential. 

First,  note  the  problems  that  the  DIS¬ 
ASSEMBLER  has  with  the  ASCII  string; 
it  generates  functionally  meaningless  code 
that,  if  reassembled  at  the  same  origin, 
would  regenerate  the  original  machine 
code.  If  the  program  were  relocated 
results  could  be  disastrous  although  not 
in  the  current  case.  Note  also  that  all 
jumps  and  calls  are  given  symbolic  labels 
even  though  the  reference  addresses  are 


outside  the  disassembled  region.  An 
attempt  to  reassemble  this  source  yields 
undefined  label  errors  for  the  call  to  the 
monitor  routine  in  line  1  and  28;  these 
are  easily  corrected  using  an  EQU  state¬ 
ment.  The  advantage  of  this  procedure  is 
that  it  aids  program  relocation  at  a  new 
address.  All  internal  labels  are  handled 
properly.  Further,  note  that  the  LXI  H, 

.  .  ,’s  end  up  with  a  symbolic  label  on  the 
loaded  word  since  the  16  bit  addresses 
loaded  into  HL  are  within  the  disassem¬ 
bled  region.  In  the  sample  shown  this  is 
correct  since  HL  is  used  as  a  memory 
pointer;  you  want  HL  to  be  loaded  using 
a  symbolic  address  in  case  you  want  to  re¬ 
locate  the  program.  In  many  cases, 
however,  double  register  pairs  are  loaded 
with  pure  numbers.  In  those  cases  when 
an  “L”  label  is  assigned  (e.g.,  using  an 
LXI  D,0  to  zero  D  and  E),  reassembly  at 
another  region  of  memory  would  reassign 
the  numeric  value  — with  disastrous  results 
to  the  program  function.  It  is  thus 
essential  to  go  through  and  determine  by 
following  program  function  which  LXI 
rp,  LXXXX  value  should  have  the  “L” 
removed.  The  SCAN  function  searching 
for  the  string  “,L”  will  turn  up  all  of 
these  quickly  and  efficiently. 

Another  fine  feature  is  the  way  the 
disassembler  works  when  the  generated 
source  files  are  too  big  to  fit  in  the  disc 
file  set  aside  for  it.  After  filling  the  first 
disc  file,  the  disassembler  stops  and  asks 
the  name  of  the  next  disc  file  to  be  filled 
during  disassembly.  After  you  give  it  the 
new  name  “file2,”  the  disassembler 
inserts  at  the  end  of  the  first  disc  file  the 
necessary  LNK  file2  line  and  continues 
the  disassembly  on  to  disc  file  “file2.” 
This  process  is  repeated  until  the  disas¬ 
sembly  is  complete.  Thus,  even  when 
more  than  one  source  file  is  generated  by 
a  disassembly,  the  files  are  already  linked 
for  the  assembly  process.  In  the  8080 
version  you  must  precreate  these  files 
using  the  DOS.  The  Z-80  version  does  it 
right  and  will  create  the  files  automatical¬ 
ly. 

System  Disadvantages 

The  disc- based  nature  is  a  speed 
disadvantage.  In  disassembly  about  5 
minutes  are  required  for  a  9K  object  code 
file  that  yields  about  70-80K  of  source 
code.  In  assembly  about  4-5  minutes  are 
required  for  four  LNKed  source  files  of 
about  70K  total  length  to  yield  9K  of 
object  code. 

Although  the  North  Star  DOS  sup¬ 
ports  up  to  8  I/O  devices  the  XL  assem- 


42 

38 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


bier  recognizes  only  two:  the  console 
and  the  serial  printer.  These  can  be 
changed  manually  during  listing  by  the 
operator  who  can  watch  his  video  termi¬ 
nal,  and  change  over  to  the  printer  in 
regions  of  interest.  The  two  I/O  device 
restriction  makes  writing  custom  input  or 
output  drivers  harder. 

Since  the  XL  software  uses  the  North 
Star  DOS,  all  the  limitations  of  the  North 
Star  DOS  are  carried  over  to  the  XL 
software.  The  DOS  can  only  append  new 


files  to  the  free  space  at  the  end  of  the 
disc  even  if  several  big  holes  exist  in 
lower  disc  space.  Thus,  you  could  run  out 
of  room  on  a  nearly  empty  disc.  This 
space  can  be  regained  by  using  the  North 
Star  compact  utility,  but  this  destroys  the 
current  run. 

The  SCAN  and  replace  is  strictly  a 
local  rather  than  global  function.  Only 
the  file  in  RAM  is  affected.  For  changes 
that  span  linked  files,  it  is  necessary  to 
read  in  and  change  each  piece.  A  batch 


SUBMIT  function  as  in  CP/M  would  be 
useful  for  circumventing  this  problem. 

The  formatting  of  source  listing  is 
nonexistent  — exactly  the  way  you  type  it 
in.  The  assembled  listing  is  better  with 
proper  indentation. 

Short  of  printing  an  entire  assembly, 
there  is  no  quick  way  to  go  back  and  look 
at  a  piece  of  the  assembly.  Unlike  CP/M 
the  XL  software  cannot  generate  a  print 
disc  file  of  the  assembly  process  for  later 
inspection. 

(continued  on  next  page) 


FIGURE  2. 

Facsimile  of  printed  portion  of  an  original  source  showing  how  it  will  be  assembled  (A)  and  the  disassembly  (B)  of  the 
result  and  machine  code.  In  the  disassembly,  addresses  37H  to  3CH  are  not  part  of  the  actual  program  and  would  be 


ignored. 

(A) 

(B) 

0000 

CD 

IF 

CO 

10  INLOOP  CALL  SYSTEMINP 

0000 

CD 

IF 

CO 

1  L0000 

CALL 

LC01F 

0()03 

CA 

00 

00 

1 1  JZ  INLOOP 

0003 

CA 

00 

00 

2 

JZ 

L0000 

0006 

FE 

45 

12  CPI  “E” 

0006 

FE 

45 

3 

CPI 

45H 

0008 

CA 

04 

CO 

13  JZ  ENDOFRUN 

0008 

CA 

04 

CO 

4 

JZ 

LC004 

000 B 

FE 

4D 

14  CPI  “M” 

000B 

FE 

4D 

5 

CPI 

4DH 

000D  C2 

19 

00 

15  JNZWHAT 

000D  C2 

19 

00 

6 

JNZ 

LOO  19 

0010 

21 

28 

00 

16  LXI  H.OKMESSAGE 

0010 

21 

28 

00 

7 

LXI 

H.L0028 

0013 

CD 

2F 

00 

17  CALLMESSOUT 

0013 

CD 

2F 

00 

8 

CALL 

L002F 

0016 

C3 

00 

00 

18  JMP  INLOOP 

0016 

C3 

00 

00 

9 

JMP 

L0000 

0019 

21 

22 

00 

19  WHAT  LXI  H.WHATMESSAG 

0019 

21 

22 

00 

10  LOO 19 

LXI 

H,L0022 

00 1C 

CD 

2F 

00 

20  CALLMESSOUT 

001C 

CD 

2F 

00 

11 

CALL 

L002F 

00  IF 

C3 

00 

00 

21  JMP  INLOOP 

ASCII » 

E 

M  !  < 

/ 

!  ”  /  « 

0022 

57 

48 

41 

22  WHATMESSAG  “WHAT?” 

001F 

C3 

00 

00 

12 

JMP 

L0000 

0027 

00 

22  DB0 

0022 

57 

13  L0022 

MOV 

D,A 

0028 

41 

4E 

20 

23  OKMESSAGE  “AN  M!  !” 

0023 

48 

14 

MOV 

C,B 

002E 

00 

23  DB0 

0024 

41 

15 

MOV 

B.C 

002F 

7E 

24  MESSOUT  MOV  A,M 

0025 

54 

16 

MOV 

D,H 

0030 

AF 

24  XRA  A 

0026 

3F 

17 

CMC 

0031 

C8 

24  RZ 

0027 

00 

18 

NOP 

0032 

47 

25  MOV  B,A 

0028 

41 

19  L0028 

MOV 

B,C 

0033 

CD 

19 

CO 

26  CALL  SYSOUTPUT 

0029 

4E 

20 

MOV 

C,M 

0036 

C9 

27  RET 

002A 

20 

21 

DB 

20H 

0037 

28  SYSTEMINP  EQU0C01FH 

002B 

4D 

22 

MOV 

C.L 

0037 

29  SYSOUTPUT  EQU0C019H 

002C 

21 

21 

00 

23 

LXI 

H.L0021 

0037 

30  ENDOFRUN  EQU  0C004H 

002F 

7E 

24  L002F 

MOV 

A,M 

0030 

AF 

25 

XRA 

A 

0031 

C8 

26 

RZ 

0032 

47 

27 

MOV 

B,A 

0033 

CD 

19 

CO 

28 

CALL 

LC019 

0036 

C9 

29 

RET 

0037 

00 

30 

NOP 

0038 

7E 

31 

MOV 

A,M 

0039 

AF 

32 

XRA 

A 

003A 

C8 

33 

RZ 

003B 

47 

34 

MOV 

B,A 

003C 

CD 

19 

CO 

35 

CALL 

LC019 

ASCII »  WHAT?  AN  M!  !  G  G  « 
003F  C9  36  RET 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


43 

39 


Software  Review 


Club  News 


The  ASSEMBLER  supports  addition 
and  subtraction,  but  not  multiplication, 
division,  byte  and  word  shifting,  nor 
upper-lower  byte  conversions  of  an 
address.  Particularly  in  large,  frequently 
relocated  programs  these  features  are  very 
bothersome,  although  not  insurmount¬ 
able,  problems.  Conditional  assembly  is 
also  not  supported. 

The  chatty  nature  of  the  ASSEM¬ 
BLER  and  DISASSEMBLER  is  conven¬ 
ient  and  useful  with  a  video  display.  If 
you  use  a  printer,  however,  the  time  and 
paper  wasted  printing  the  instructions 
every  time  would  become  bothersome.  I 
see  no  obvious  way  to  defeat  this  feature. 

Finally,  after  using  the  ALS8  and  the 
ELECTRIC  PENCIL  editors  (superb 
memory -mapped  video  ones),  I  find  the 
strictly  line-oriented  North  Star  editor 
cumbersome  and  slow.  I  have  now 
written  programs  to  interconvert  ALS8, 
XL,  and  ELECTRIC  PENCIL  I  files,  but 
more  on  that  elsewhere.  Also,  the  XL 
package  is  not  designed  as  a  stand  alone 
package.  None  of  the  system’s  utilities, 
such  as  in  ALS8,  are  available  for  the 
user  nor  can  custom  commands  be  set  up. 
Great  flexibility  in  printout  is  lacking 
also;  for  example,  there  is  not  “list  on” 
and  “list  off’  commands  that  can  be 
embedded  in  a  program  for  unattended 
printing  out  of  segments  of  the  program 
during  assembly.  A  simulator  or  debug¬ 
ging  package  is  not  included  and  would 
be  a  quite  valuable  addition;  I  use  the 
ALS8  simulator  for  this  stage  of  devel¬ 
opment. 

Summary 

Overall  I  find  the  XL  package  power¬ 
ful,  easy  to  use  and  versatile.  I  wish  I’d 
had  it  two  years  ago;  it  would  have  saved 
countless  hours.  I  am  currently  convert¬ 
ing  all  my  ALS8  programs  over  to  XL 
files.  The  APND  and  SCAN  and  replace 
make  building  up  and  using  a  software 
library  trivial  since  perhaps  80%  of  a 
machine  language  project  can  consist  of 
routines  you  have  had  to  write  before.  If 
you  have  these  routines  as  XL  disc  files, 
you  can  just  APND  them  together  to 
build  the  final  program  -  after  using  the 
SCAN  and  replace  if  common  labels 
had  occurred  between  modules.  For 
really  big  programs  where  the  entire 
source  program  cannot  fit  in  RAM  at 
once,  the  LNK  command  can  be  used. 
While  this  approach  is  not  as  powerful  as 
an  assembler  that  generates  relocatable 
load  modules,  and  uses  a  linking  loader  to 
build  the  final  program,  it  is  easier  to 


learn  to  use  and  will  probably  satisfy  all 
but  the  most  avid  programmers. 

Although  not  described  by  XL, 
another  valuable  use  of  the  SCAN  and 
replace  is  a  pseudo- macro  capability.  For 
example  during  the  writing  of  a  program, 
you  might  want  to  save  by  PUSHing  and 
then  later  restore  by  POPing  in  the 
inverse  order  all  of  the  registers.  A 
common  programming  error  is  to  restore 
them  in  a  different  order;  the  hours  spent 
tracking  down  this  trivial  error  are 
countless.  To  simplify  this  task  every 
time  you  want  to  save  all  registers  you 
type  in  the  line  SAVEALL  and  every 
time  you  want  to  restore  them  you  type 
in  the  line  RESTORALL.  Then  before 
you  assemble  just  type  in  the  two  lines: 

SCAN  “SAVEALL”  “PUSH  H/PUSH 
D/PUSH  B/PUSH  PSW” 

SCAN  “RESTORALL”  “POP 
PSW/POP  B/POP  D/POP  H” 

Then  every  occurrence  is  correctly 
changed. 

Finally,  I  will  conclude  with  a  few 
examples  of  how  I  am  using  the  XL 
package.  We  are  currently  using  SOL-20’s 
and,  while  the  ROM  based  monitor  is 
excellent,  many  of  the  built-in  functions 
are  not  used  by  us.  Processor  Technology 
supplied  the  documented  source  printout. 

I  have  disassembled  the  monitor,  replaced 
all  of  the  “L”  labels  with  the  Processor 
Technology  ones,  and  we  are  now  throw¬ 
ing  out  the  parts  we  do  not  want  and 
adding  features  that  we  need.  When  we 
are  finished  we  will  burn  a  new  set  of 
PROM’s  that  do  just  what  we  want.  In 
another  area,  my  copy  of  the  ELECTRIC 
PENCIL  I  has  a  number  of  small  but 
irksome  bugs.  I  have  disassembled  it  and 
am  slowly  locating  and  correcting  them  as 
well  as  adding  new  features.  We  also  have 
Processor  Technology’s  powerful,  com¬ 
pact  PROMable  Software  Package  I 
assembler  object  code  and  the  40  page 
source  listing.  Rather  than  try  to  type  in 
the  source  listing,  I  have  disassembled  the 
object  code  and  we  are  changing  the 
labels  with  SCAN  to  agree  with  the 
original  source.  Then  we  will  add  new 
functions,  relocate  it  in  memory  so  that  it 
does  not  interfere  with  any  of  our  other 
system  software,  and  PROM  it  so  that  we 
can  have  a  permanent  resident  assembler 
in  non-disc  based  systems.  Try  some  of 
these  projects  on  limited  money,  limited 
memory,  limited  disc  space  or  limited 
time.  I  think  that  you  will  then  agree  that 
the  XL  package  is  indeed  a  real  bargain 
which  will  pay  for  itself  almost  immed¬ 
iately.  ■  ■ 


Eastern  Iowa  Computer  Club 

The  EICC  has  been  active  by  reach¬ 
ing  out  to  the  local  community.  They  re¬ 
cently  offered  hands-on  North  Star  ex¬ 
perience,  IMSAI  synthesized  music  and 
club  information  on  SWTP.  Their  March 
meeting  is  scheduled  to  be  on  the  subject 
of  displays.  For  information,  call  club 
president  Sam  Dillon  (319)  377-0889. 

Portland  Computer  Society 

PCS  is  steadily  progressing  towards 
incorporation  as  a  non-profit  corpora¬ 
tion.  Contributing  members  ($25  per 
year)  help  them  to  pool  and  spread  public 
information  about  microcomputers.  Sub¬ 
scribers  to  the  PCS  newsletter  ($10  per 
year)  receive  the  latest  club  news  and  a 
full  calendar  of  events.  PCS  may  be  con¬ 
tacted  at  P.O.  Box  17371,  Portland,  OR 
97217. 

Northwest  PET  Users  Group 

The  new  address  for  the  NWPUG  is 
c/o  Richard  Ball,  2565  Dexter  N.,  #203, 
Seattle,  WA  98109.  They  now  meet  on 
the  second  Tuesday  of  each  month,  7:30 
p.m.  at  the  University  of  Washington’s 
Academic  Computer  Center,  3737  Brook¬ 
lyn,  Seattle,  WA. 

New  England  Computer  Society 

Like  many  local  clubs,  NECS  offers 
special  interest  groups  and  “microses¬ 
sions.”  Some  of  their  users  groups  focus 
on  CP/M,  6502,  TRS-80,  6800,  PET, 
APPLE  and  Z-80.  They  have  about  200 
paid  members  who  sponsor  semi-annual 
swap-shops,  computer  and  electronic  flea 
markets.  For  information,  write  to  NECS, 
P.O.  Box  198,  Bedford,  MA  01730.  ■■ 


Donating  Subscribers 

Contributing  Subscriber:  $50/yeai  ($25  tax  de¬ 
ductible).  Retaining  Subscriber:  $75/year  ($50 
tax  deductible).  Sustaining  Subscriber:  $100/ 
year  ($75  tax  deductible).  Lifetime  Subscriber: 
$1000  ($800  tax  deductible).  Corporate  Sub¬ 
scriber:  $500/year  ($400  tax  deductible,  re¬ 
ceives  five  one-year  subscriptions). 

Contributing  Subscribers:  Robert  L.  Edens, 
Eric  P.  Hanson,  J.  G.  Zeratsky,  Mervin  E. 
Frank,  Edward  W.  Carr,  Steven  Fisher,  Thomas 
H.  Grohne,  Richard  Washburn,  Les  Hancock, 
G.  V.  Elkins,  C.  A.  Forsberg,  Daniel  R. 
Lunsford,  J.  D.  Griffith,  Michael  Slade,  Thomas 
M.  Schaefges,  General  Electric,  Louis  L.  Odette, 
Robert  M.  Connors,  William  J.  McEown, 
Robert  C.  Luckey,  Kim  Leary,  Robert  N. 
Stabler,  Dewitt  S.  Brown,  John  B.  Palmer. 
Retaining  Subscribers:  Mike  Faithful  and 
Osamu  Shimizu. 

Sustaining  Subscribers:  Gordon  Eubanks,  Jr. 
and  Robert  C.  Birss,  Ph.D. 


44 

40 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


Book  Reviews 


A  PRIMER  ON  STRUCTURED  DESIGN 

By  Richardson,  Butler,  Tomlinson 

Published  by  PBI-Petrocelli 

232  pages,  $17.50 

Reviewed  by  Charles  K.  Ballinger 

Anyone  interested  in  the  “what  is 
it?,  why?,  and  how?”  of  structured 
program  design  should  read  this  book. 
Having  just  completed  a  week-long 
structured  design  class  in  July,  I  can  only 
say  that  far  more  would  have  been 
assimilated  if  this  book  had  been  the  text 
for  the  course. 

The  three  authors  are  to  be  com¬ 
mended  for  their  writing  clarity  and  ease 
of  getting  the  subject  matter  across  to  the 
reader  without  the  introduction  of  several 
hundred  new  buzzwords.  While  there  is 
some  new  terminology,  it  is  set  forth  in 
an  easy-to-understand  manner,  and  a 
complete  glossary  of  terms  is  provided  as 
backup. 

The  book  covers  structured  design 
from  its  early  background  through  the 
evolution  of  various  design  methodologies 
from  top-down  design  to  current  design 
techniques,  while  maintaining  an  excel¬ 
lent  mixture  of  text  and  examples  to  rein¬ 
force  the  subject  matter.  One  area  not 
many  home  users  may  use,  but  none  the 
less  very  important  to  the  professional 
programmer,  is  the  information  in  Chap¬ 
ter  6  dealing  with  the  use  and  philosophy 
of  Pseudo-code.  Although  the  examples 
are  in  FORTRAN,  COBOL  and  PL/1,  any 
language  can  be  substituted  to  some  de¬ 
gree,  even  BASIC! 

Even  if  structured  design  does  not 
yet  strike  your  fancy,  Chapter  7  on  pro¬ 
gram  style  and  debugging  makes  the  book 
an  excellent  source  for  the  budding  pro¬ 
grammer  or  the  seasoned  veteran.  I  do, 
however,  take  exception  to  the  comment 
on  page  143,  “Readability  is  more  im¬ 
portant  than  efficiency.  (10%  of  the 
codes  typically  consumes  50%  or  more  of 
the  execution  time.)”  I  say  more  like  10% 
of  the  code  executes  90%  of  the  time, 
and  certain  trade-offs  must  be  made  be¬ 
tween  efficiency  and  readability. 

Each  chapter  has  a  summary  and  re¬ 
view  questions  along  with  the  notes  and 
references  used,  so  further  study  or  re¬ 
ference  material  may  be  obtained  if  a 
particular  topic  is  of  special  interest  to 
the  reader. 

Two  additional  chapters  of  great  in¬ 
terest  are  Chapter  8  on  Database  Con¬ 
siderations,  and  Chapter  9  on  Managing 
the  Programming  Process.  Since  these 
two  areas  have  significant  impact  on 


program  design,  it  is  most  useful  to  see 
how  a  database  environment  affects 
program  design,  and  why  managers  in¬ 
herently  get  nervous  when  both  this  week 
and  last  week  you  reported  your  program 
to  be  90%  complete.  Knowing  both  sides 
of  the  fence  makes  one  keenly  aware  why 
you  do  or  don’t  want  to  stay  on  your  side 
of  it! 

In  summary,  this  book  covers  not 
only  structured  program  design,  but  all 
the  facets  involved  in  the  “structured” 
concept.  Even  if  you  are  not  yet  into 
structured  anything,  you  should  consider 
it  on  its  own  merit,  since  industry  appears 
to  be  heading  down  the  structured  road 
to  new  horizons.  This  book  is  an  excel¬ 
lent  reference  guide,  a  valuable  learning 
tool,  and  is  well  worth  the  price.  It 
should  occupy  a  prominent  spot  in  your 
library,  to  be  read  and  used  wherever  pos¬ 
sible. 

THE  CP/M  HANDBOOK  WITH  MP/M 

By  Rodney  Zaks 

Published  by  Sybex 

321  pages,  $13.95  paperbound 

Reviewed  by  George  Reeves 

CP/M  has  become  the  de  facto  stan¬ 
dard  operating  system  for  a  substantial 
portion  of  the  microcomputer  systems  in 
existence  today  —  those  systems  utilizing 
the  8080  and  its  successors.  Rodney 
Zaks,  in  this  handbook,  intends  to  teach 
the  user  how  to  use  the  CP/M  system  and 
its  resources.  No  prior  knowledge  of  com¬ 
puters  is  assumed  (though  it  is  assumed 
that  the  reader  has  access  to  a  computer 
system  equipped  with  CP/M).  This  re¬ 
viewer,  in  reading  the  handbook,  had  the 
knowledge  but  not  the  CP/M  system. 
While  it  would  be  nice  to  have,  it  is  not 
necessary  for  a  good  understanding  of 
CP/M. 

The  first  chapter  is  an  introduction 
to  CP/M  and  MP/M.  It  gives  basic  defini¬ 
tions  of  computer  systems  and  compares 
CP/M  to  some  of  its  look-alikes,  such  as 
Cromemco’s  CDOS.  This  chapter  shows 
the  reader  how  to  bring  up  CP/M  and  to 
use  its  built-in  transient  commands. 

Chapter  2  goes  into  much  more  de¬ 
tail  about  the  CP/M  commands  and  the 
control  characters  recognized  by  the  sys¬ 
tem. 

The  PIP  command  is  briefly  intro¬ 
duced  in  Chapter  1,  and  Chapter  3  de¬ 
tails  its  capabilities,  such  as  how  to  con¬ 
catenate  files,  how  to  print  a  group  of 
files  with  just  one  command,  and  how  to 
read  a  file  up  to  a  specific  word,  without 


using  the  assembler. 

The  CP/M  editor,  ED,  is  explained  in 
Chapter  4.  It  tells  in  general  terms  how  an 
editor  operates,  what  it  can  do,  and,  in 
specific  terms,  how  this  relates  to  ED. 

For  system  programmers,  Chapter  5 
describes  the  internal  operation  of  CP/M. 
You  will  want  to  read  the  chapter  if  you 
wish  to  know  how  an  operating  system 
works,  or  if  you  intend  to  modify  or  use 
some  of  CP/M’s  routines. 

Chapter  6  is  a  good  reference  guide 
to  CP/M  and  MP/M  commands  and  pro¬ 
grams.  It  specifies  which  commands  are 
available  in  the  two  versions  of  CP/M  and 
version  1.0  of  MP/M,  and  how  each  oper¬ 
ates. 

Chapter  7  is  a  compilation  of  practi¬ 
cal  hints  in  using  CP/M  or  MP/M,  and 
Chapter  8  is  a  short  discussion  of  their 
future. 

The  last  30  pages  of  the  book  consist 
of  15  appendices  intended  for  reference 
use.  Some  are  helpful  (the  reference  guide 
to  the  commands  of  ED,  PIP,  and  CP/M); 
others  are  duplications  of  what  you 
probably  have  elsewhere  (hexadecimal 
and  ASCII  conversion  tables);  and  others 
are  useful  depending  upon  your  experi¬ 
ence  (checklist  of  supplies). 

There  are  the  usual  number  of  typo¬ 
graphical  errors,  but  these  are  minor  and 
fairly  evident.  There  is  a  point  of  confu¬ 
sion  as  to  what  will  happen  if,  in  copying 
files  from  disk  A  to  disk  B,  there  is  al¬ 
ready  a  file  of  the  same  name  on  B:  on 
page  37  it  says  the  copy  operation  will 
stop,  while  on  page  38  it  says  the  file  will 
be  deleted.  Such  a  condition  would  be 
easy  to  check  out. 

For  those  who  intend  to  read  this 
handbook  from  cover  to  cover,  it  is  help¬ 
ful,  though  repetitious  in  places;  but  for 
those  users  of  CP/M  1 .4  or  2.2  and  MP/M, 
it  is  an  excellent  reference  guide  and  I 
heartily  recommend  it.  ■  ■ 


Good  News ! 

Dr.  Dobb's  Journal  is  now  published 
twelve  times  each  year!  Subscribers  will 
still  receive  the  number  of  issues  original¬ 
ly  requested.  Watch  your  mailing  label  for 
the  new  expiration  date. 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


45 

41 


Intext 

An  Input  Routine  for  Text  Editors 


A 

X  .^L.nyone  who  has  attempted  to 
write  a  text  editor  in  North  Star  BASIC  is 
almost  certain  to  have  come  across  the 
problem  of  generating  a  Line  Length 
Error  when  inputting  text.  The  following 
passage  shows  how  I  overcame  this  prob¬ 
lem  using  North  Star  BASIC  Release  4. 

The  problem  begins  with  the  maxi¬ 
mum  line  length  allowed  in  North  Star 
BASIC  (normally  132  characters).  If 
more  than  132  characters  are  input  from 
the  terminal  in  succession,  without  being 
interrupted  by  a  carriage  return,  a  Line 
Length  Error  is  generated  and  the  pro¬ 
gram  will  crash.  A  typical  input  sequence 
which  will  cause  a  Line  Length  Error  is 
given  in  Listing  1 . 

This  error  can  now  be  avoided  by 
utilizing  the  INCHARS  function,  avail¬ 
able  in  Release  4  BASIC.  This  function 
waits  for  a  character  to  be  input  from  the 
terminal  and  then  returns  that  character 
as  a  single  character  string.  In  effect 
INCHARS  is  the  same  as  INPUT  except: 

1)  Only  one  character  is  returned. 

2)  No  carriage  return  is  necessary. 

3)  The  character  is  not  “echoed”  to 
the  terminal. 

Therefore  it  can  be  seen  that 
INCHARS  overcomes  the  problem  of 
Line  Length  Error,  since  only  one  charac¬ 
ter  at  a  time  is  input.  This  is  not  to  say 

by  Greg  Smith 

Greg  Smith,  Commonwealth  Department 
of  Transportation,  Ground  Facilities 
Division,  P.O.  Box  367,  Canberra  2601, 
Australia. 


that  our  problems  are  over,  for  INCHARS 
generates  some  headaches  of  its  own: 

1)  Since  the  input  character  is  not 
echoed  to  the  terminal  you  cannot  see 
what  you  are  typing. 

2)  As  only  one  character  is  input  at  a 
time,  the  BASIC  Line  Editor  cannot  be 
used  to  backspace  over  typing  errors. 

3)  Any  character  typed  on  the  ter¬ 
minal  (except  Control  C)  will  be  accepted 
as  a  legitimate  character.  This  may  cause 
problems  if  a  non- printing  character  is 
accidently  typed  and  added  to  the  text 
string,  as  it  may  disrupt  printout. 

The  first  problem  can  be  overcome 
simply  by  printing  the  single  character 
string  into  which  the  INCHARS  func¬ 
tion  has  placed  the  input  character  (List¬ 
ing  2). 

The  problem  of  editing  the  text  as  it 
is  input  is  slightly  more  difficult  to  over¬ 
come  and  involves  detecting  a  backspace 
character  before  it  is  entered  into  the 
string.  This  can  be  done  by  utilizing  the 
ASC  function.  This  function  returns  the 
ASCII  value  of  the  designated  string. 
Therefore,  if  the  ASCII  value  of  each 
character  is  examined  as  it  is  input,  then 
a  backspace  character  can  be  intercepted 
before  it  is  added  to  the  text  string.  It 
is  then  a  simple  matter  to  reduce  the 
length  of  the  text  string  by  one  charac¬ 
ter  for  each  backspace  received  from  the 
terminal.  At  the  same  time  it  is  possible 
to  print  a  backspace  on  the  terminal. 
Since  some  terminals  will  not  accept  a 
backspace,  the  user  may  select  the  charac¬ 
ter  he  wishes  to  print  for  a  backspace  and 
insert  the  ASCII  value  for  this  character 
in  line  50  (Listing  3). 

There  is  one  minor  problem  which 
arises  when  a  backspace  is  printed.  The 


operating  system  treats  a  backspace  as  a 
“normal”  character  and  does  not  reduce 
the  character  count  for  the  line.  Conse¬ 
quently,  the  operating  system  provides  a 
carriage  return  before  the  line  is  com¬ 
plete,  i.e.,  before  the  line  is  “full.”  The 
only  real  problem  with  this  is  that  it 
looks  untidy.  The  solution  is  to  provide 
a  character  counter  and  line  feed/carriage 
return  within  the  routine.  This  mechan- 
sim  has  been  incorporated  in  INTEXT. 
The  number  of  characters  allowed  per 
line  may  be  varied  to  suit  your  require¬ 
ments  by  changing  the  value  of  B  in  line 
20  (Listing  3). 

Examining  the  ASCII  values  of  the 
input  characters  is  also  the  solution  of  the 
third  problem  outlined  above.  Since  the 
ASCII  values  of  the  “printing”  characters 
lie  between  32  and  126  inclusive,  it  is  a 
simple  matter  to  eliminate  spurious 
characters  before  they  reach  the  text 
string.  INTEXT  also  detects  carriage 
returns  and  will  print  them  at  the  termi¬ 
nal  but  will  not  add  them  to  the  text 
string.  If  two  carriage  returns  are  per¬ 
formed  in  succession,  the  routine  termi¬ 
nates.  The  resulting  text  is  contained  in 
the  string  A$. 

INTEXT  is  not  a  particularly  com¬ 
plex  routine  (refer  to  flowchart  Figure  1 
on  page  48).  For  this  reason  it  is  relative¬ 
ly  fast,  and  consequently  the  time  it  takes 
from  when  a  character  is  input  until  the 
next  character  can  be  input  is  quite  short. 
The  program  has  sufficient  speed  to  keep 
pace  with  a  normal  typing  rate. 

Additional  Feature 

When  you  incorporate  INTEXT  into 
your  text  editor,  you  may  wish  to  utilize 
another  capability  it  possesses.  As  pre- 


LOAD  LIST1 

LOAD  LIST2 

READY 

READY 

LIST 

LIST 

10  REM  ,  , , ,  .LISTING  1 _ 

20  REM  IF  MORE  THAN  132  CHARACTERS  ARE 

10  REM . LISTING  2 . 

30  REM  INPUT  IN  SUCCESSION,  A  LINE  LENGTH 

20  LINE  64 

40  REM  ERROR  WILL  OCCUR  IN  LINE  80 

30  DIM  AS  (2000) 

50  LINE  132 

40  A$=“” 

60  DIM  AS  (2000) 

50  T$=INCHAR$(0) 

70  A$=“” 

60  ITS 

80  INPUT  “”,T$ 

70  A$=A$+T$ 

90  A$=A$+T$ 

80  IF  LEN(A$)=2000  THEN  100 

100  IF  LEN(A$)>=2000-25  THEN  120 

90  GOTO  50 

110  GOTO  80 

100  !“STRING  FULL” 

120  !“STRING  FULL” 

110  END 

130  END 

READY 

READY 

46 

42 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


48 

44 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


Turing  Machine  Simulation 


An  Introduction 
to  a  Universal 
Language 

T 

~M~here  is  a  tendency  among  pro¬ 
grammers,  especially  beginners,  to  want 
to  learn  only  one  or  two  programming 
languages  and  force  all  problems  to  fit 
into  the  framework  provided  by  the 
language  used.  I  suppose  this  attitude  is 
justifiable  in  part  if  the  programmer  con¬ 
stantly  works  on  only  one  class  of  prob¬ 
lems  such  as  business  or  scientific  prob¬ 
lems.  With  the  advent  of  microcomputers, 
BASIC  has  become  sort  of  a  standard  for 
small  machines  and  users  may  be  left 
wondering  why  software  vendors  are 
beginning  to  promote  languages  such  as 
Pascal,  FORTRAN,  and  FORTH.  This 
article  is  an  attempt  to  illustrate  one 
reason  for  this  desire  for  multilingual 
micros  and  to  provide  a  very  brief  intro¬ 
duction  to  the  purpose  and  study  of  pro¬ 
gramming  languages. 

Someone  once  stated,  “If  a  computer 
can  do  it,  I  can  write  it  in  FORTRAN.” 
This  statement,  stated  in  different  words, 
was  actually  discussed  by  mathematicians 
and  logicians  before  computers  were  ever 
invented.  The  research  done  in  the  early 
1930’s  produced  some  very  interesting 
results.  Several  computational  models 
were  proposed  and  all  were  shown  to  be 
equivalent.  These  proposed  models  are  in¬ 
teresting  only  from  a  theoretical  point  of 
view  but  they  do  show  that  very  little 
hardware  is  actually  required  to  build  a 
computer  and  that  the  languages  current¬ 
ly  in  use  (i.e.,  FORTRAN,  COBOL,  LISP, 
etc.)  are  universal  languages.  What  this 
means  is  that  a  program  written  in  one 
'anguage  can  also  be  written  in  any  other 


by  J.L.  Lawrence 


J.  L.  Lawrence,  Mathematics  &  Computer 
Science  Department,  Western  Kentucky 
University,  Bowling  Green,  Kentucky 
42101. 


language,  including  the  computational 
models  proposed  in  the  1930’s!  Hence, 
any  program  that  can  be  written  for  a 
computer  can  be  written  in  FORTRAN 
(or  BASIC,  or  COBOL,  etc.)  but  it  may 
be  painful  or  costly  to  do  so.  Painful  pro¬ 
gramming  will  be  illustrated  below.  One 
reason  for  the  proliferation  of  program¬ 
ming  languages  and  the  development  of 
new  languages  is  an  attempt  to  match 
specific  languages  to  specific  classes  of 
problems.  FORTRAN,  for  example,  was 
designed  to  be  a  fast  executing  language 
for  scientific  applications  where  com¬ 
putations  tend  to  be  rather  lengthy 
and  very  little  I/O  is  performed.  COBOL 
was  designed  for  business  applications 
with  quite  a  bit  of  I/O  but  very  little 
“number  crunching.”  BASIC  was  de¬ 
signed  to  be  easy  to  teach  and  learn. 

Another  reason  for  continued  re¬ 
search  is  to  improve  existing  languages  by 
extending  their  features.  BASIC  is  an  ex¬ 
cellent  case  in  point.  Other  research  has 
produced  general  purpose  languages,  such 
as  PL/I,  but  usually  at  a  cost  of  requiring 
more  core  and  time  for  compilation. 
Sacrifices  and  tradeoffs  in  design  goals  are 
often  necessary  to  achieve  general  pur¬ 
pose  languages. 

One  of  the  early  computational 
models  proposed  is  the  Turing  machine. 
A  Turing  machine  consists  of  an  infinite 
length  tape  and  a  read/write  head  which 
moves  over  a  stationary  tape.  In  opera¬ 
tion,  the  read/write  head  can  perform 
only  three  operations:  (1)  read  the  char¬ 
acter  under  the  tape  head  and  move  the 
head  right  or  left,  (2)  read  the  character 
under  the  head  and  write  a  new  character, 
and  (3)  terminate.  Keep  in  mind  that  the 
Turing  machine  is  universal  so  that  any 
program  that  can  be  written  for  a  com¬ 
puter  can  be  done  in  only  these  three 
steps!  Input  to  the  machine  consists  of  a 
finite  string  of  symbols  (from  some  alpha¬ 
bet)  written  on  the  tape  and  output  is  a 
finite  string  written  on  the  tape. 

In  moving  the  tape  head  right  and 
left,  if  either  end  of  the  finite  string  is 
reached,  a  blank  is  automatically  written 
at  the  end.  Figure  1  is  a  program  written 
in  BASIC-PLUS  on  a  PDP  1 1/45  to  simu¬ 
late  a  Turing  machine,  but  for  obvious 
implementation  reasons,  the  tape  is  81 
characters  wide.  If  the  left  end  of  the 
tape  is  ever  reached,  an  error  occurs. 

Perhaps  the  best  way  to  visualize  the 
Turing  machine  concept  is  to  visualize  it 
as  a  set  of  rules  for  passing  from  one  state 
to  another.  That  is,  a  program  is  to  be 
a  set  of  quadruples  of  the  form  QqXYQj 


where  Q0  is  the  state  the  machine  is  cur¬ 
rently  in  (0  is  the  initial  state),  X  repre¬ 
sents  the  character  under  the  tape  head, 
Y  represents  the  action  to  take,  and  Q, 
.represents  the  next  state  for  the  machine, 
'if  Y  is  an  R  or  an  L,  the  tape  is  moved  in 
the  proper  direction.  If  Y  is  anything  ex¬ 
cept  R  or  L,  X  is  replaced  by  the  charac¬ 
ter  Y.  Execution  terminates  when  an  un¬ 
defined  state  is  reached.  Beginning  with 
the  initial  state,  the  Turing  machine  takes 
the  action  specified  by  the  quadruple 
corresponding  to  the  current  machine 
state  and  passes  into  the  state  specified 
until  an  undefined  state  is  reached. 

As  an  example,  assume  we  have  a 
string  with  no  imbedded  blanks  which 
contain  only  lowercase  a’s  and  b's  and  we 
wish  to  translate  them  to  uppercase.  The 
approach  to  take  is  obvious.  Starting 
from  the  left  side  of  the  input  string,  read 
a  character,  translate  it,  and  move  the 
read  head  to  the  right.  Since  we  are  as¬ 
suming  no  imbedded  blanks,  only  two 
possibilities  exist  for  characters  in  the  in¬ 
put  string,  namely  a  and  b.  Thus,  only 
two  instructions  are  necessary  to  trans¬ 
late  the  tape:  OaAO  and  ObBO.  Next,  we 
must  move  the  read  head  by  0AR0  and 
0BR0.  Lastly,  we  can  stop  with  O^tyl 
since  a  blank  will  be  at  the  end  of  the 
input  string.  Figure  1  shows  the  entire 
program  and  traces  its  execution  for  the 
string  ababba.  It  is  important  to  realize 
that  each  state  must  consider  every  possi¬ 
ble  character  that  could  be  under  the  tape 
head  in  that  state  or  else  an  error  occurs. 
The  program  (see  Listing)  does  not  con¬ 
cern  itself  with  this  error  but  may  fall 
into  the  next  defined  state  with  unpre¬ 
dictable  results.  If  example  2  could  have 
any  of  the  26  letters  of  the  alphabet,  an 
additional  48  instructions  would  be  re¬ 
quired  for  the  program! 

Figures  2  and  3  are  other  examples 
of  this  “painful”  programming.  The 
program  in  Figure  2  takes  an  input  string 
of  l’s  and  0’s  and  replaces  all  l’s  with 
#’s.  Figure  3  illustrates  a  more  practical 
problem  in  that  it  determines  whether 
there  are  an  even  or  and  odd  number  of 
l’s  in  the  input  string.  Furthermore,  it 
illustrates  the  difficulty  in  producing  text 
output.  The  point,  again,  is  not  that  any¬ 
one  would  actually  do  useful  work  with  a 
Turing  machine  but  rather  that  it  can  be 
done.  ■■ 


(LISTING  ON  PAGE  50) 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


49 

45 


Turing  Machine  Simulation 


w 

06 

3 

O 

NN 

Un 


a  <x 
r  z 

u  O 
r  >i 

UJ  (/) 


ac  <r 

a  ui  oc  a  Ck 

o  aait-  <  j 

kssgg!* 


*-  ui  ui  cc 

K  U|  (J  h  U 

cnu«Mi- 

O  H  w  yt  i  Z 
O  J&H3UI 


o  o 
*-  a 
>■ 
QC  UJ 


a  u. 
z  u 
«  <* 


«  - 

(0 

UJ 

a.  K 


-  z 

C n  Cl 

1; 


UJ  UJ  • 
K  03  ui 

z  3 
UJ  *-  o 
o  r 
a  z 
UJ  z  o 
I  «  K 
CA  U 


uj  a  uj 

Z  Z  u. 

<x  <t  « 


Z  K 
uJ  «  iZ 

Z  I  o 

3  —  u.  ♦  ♦  * 


O  O  O  O  t 

«  cc  a  x  : 

no  «  JQ  a  . 

o  o  o  o  o  ► 

jk.  «k.  (h-  v  (k.  (k.  3 

~  cm  m  ♦  in  ■« 


o  ^ 

3  l 
••  C 

(k.  Ui  « 


C  3  ► 
r  -  - 
o  z  ; 
u  —  » 


QQaaaaaoQQQQa 

UJUJUJUJUJUJUJUJUJUJUJUJUi 

3333333333333 

uuuuuuuuuuuuu 

UJUJUJUJUJUJUJUJUJUJUJUJUJ 

xxxxxxxxxxxxx 

UJUJUJUJUJUJUJUJUJUJUJUJUJ 

22222222222*2 

uuuuuuuuuuuuu 

CCOLOCdCOCOCXXXXm 

►“^'Kh-h-U-KKKH'KKt- 

m  «  w  w  m  «  m  (n  w  o)  oi  unn 

zzzzzzzzzzzzz 

-Cir-innttinn'O’ONN 

zzzzzzzzzzzzz 

ooooooooooooo 

cnc/icncncntAtAtnwtncntnv) 

0000000033000 
kkU.kkU.ix.U.u.u.U.a.u.U.il.  •• 

aaaaaaoaaaaaa«o 

ulUJUiuJUJUJUJUJaJU>UiaJkwa^ 

3ZZXZIIZZli2Z<t« 

a  yi 

<X  o 

U. 

aaaaaaaaaaa*®— 

aaaaaaaaaazaaujQ 

fO  n>  fO 

aaaaaaaaaaaaa^,*. 


-*  a 

i-  JQ 
rt 

z  a 


liiuyuyulUlujUiuJliJ 


UJ  Ui  UJ  Uj  C  ^ 
lIli.iLU.ZZ 

<t  <r  <r  <t  -  ~t 


50 

46 


Dr.  Dobb’s  Journal,  Number  51,  January  1981 


-  3 
*  U 
M  Ul 
z  x 


Z  K 

*1  ui 
(E  Z 


<  ~ 
ac  a 
o  « 
o  t- 
oc  - 
0.  ~ 

oc  - 

«UHA 

»  u>  ~  * 

m  3  •  * 

«  u  *-< 

»  o  •  ~ 

«*  Z  ~  * 

-  o  o 

w  ^  - 

Zt-VA 

O  Z  A  to 


.l1 

:  u.  a 


*-  oc  t-  ~ 

U  CL  -  « 
3  -•  « 


[N  «i  H 


a. « 

<r  ui 

K  I  < 


:  Cl  Z  UIIhi 

J  «  *-  Ul  oc  c 

»-  U  3  U.  ft.  • 

J  •  IH  > 

:  _i  r  < 

j  «  »-  U)  k  r 

►  z  z  z  o  > 

j  *->  >-  _j  *-<  a 

1  U  CC  OC  < 

•  a.  »  cl  —  ► 


g 

a 

7° 

K 
—  U 
Ui  3 

»-  oc 

Ui  H- 
-I  UJ 

85 

"5 

5i? 

m  ui  i 

“«S 

S2S 


y  3 
3  OC  I- 
oc  *-  z 
K  Ul 
U)  Z  OC  < 

z  ft.  c 
m  r 
z  z 

32*' 

ui- 

h  •  r 

Ui  A 
Jl-a 

Ota 

z  o 

*  *-* 

*-<  z  »  ••  -* 


z  •  *- 

*-  o  o 

••  3 

z  ♦  ac 

V  H- 

ZOO  Ul 


:  o  ♦  z  3 

•  »-  «a  m  » 

:  o  m  ac  c 

.  o  en  a.  c 


i  «  z  a 

-  «  *~i  oc  ► 

i  OC  O  0 

:  —  ft.  u.  o 


N  K)  ll 

M  ro  r 

in  in  ti 


>  o  o  o 

>  -c  rv  qo 
i  «  m  in 


o  o  o  < 

0«(Nh 
O  <  -O  x 


>  o  o  o 

)OhN 

)  fv  rs  r-. 


m  a.  <h  ■ 

*•  «  I  H  Z 
t-  OC 
K  Z  3 
Z  CCCC  X  L- 

N  oouiocy 
z  u.  u  z  a.  ac 

o  o  o  o  o  o 
w  ♦  n  -o  n  o 

N  N  N  N  rs  N 


§ 

ir 


OC  Ui  — 
Ui  Z  A 
U)  < 

3  Z  Ui 


0C  U.  0) 

«  I 

O  t-  3 

t-  3  K 

Cl  3  OC 


©  o  m 
o  -h  -< 
OD  00  00 


©  ©  o  © 

N  O  &>  O 

o  o  ©  -« 


Ui  z  u  o 

z  HZ  Ll 

£  oc  m  z 

3  Ui  OC 

OKOZO 
oc  z  u.  *  t- 
^  ui  *-<  *-• 

•  *  •  ^  ♦ 

Z«  H  R  Z 

uiocwt-  *-  •-«  u  oc 

3ZZ  Ul  3  *  3  Z  3  Ul  3 
•  a.UHKOi-«a.uiLKOKa 

zo.ao  ju  zo.zo  juz 

-*-«oa.u.uac-  howuuocuj 

0000©0©00©000©0 

OHNntiiiooHNntin'OO 

ooooooooooooooo 

rM  f\i  rj  rj  ri  rj  rj  Ki  ki  k,  k,  ho  ki  ki  (v 


o-n-oririrition'OtiniiKh'flNNCDCDii- 


ac  cc  i  cc  cc  ccoacccuiccGocaac^ocutcczoc 


o  *-< 

O  Ul 

^  o 

*H  Cl. 


r*l 

S 

§ 

E 


o  ~  o  -  i  o i  uj  a  a  © 


©  ©  o  *«  •*  -*<NNMf*ifnw*'^inin'0'0rLrs3a3 


o 

-A  Ul 

o 


«  ui  a 

hHi.4 
©•Xu 
y  o  *-  x 
<r  - 
—  y  y 

KO  <  < 

©  z  z 

z««» 

u  ^  U.  U. 


<  K  ► 
Z  3  ► 
Z  Cl  ► 

o  z  ; 


o  *-> 
o  ui 
©  o 

Ui  Cl 
U.  - 

CHliiQ 

I-  O  Cl  <t 
^  <X  U 
y  ^  Z 


•-  ©  <X  « 

•-  o  z  z 
z  o  •-«  >-> 
Hoyy 


ui 

o  o 

O  Cl 


©  .. 

©  Z 

o 


fS 

3 

a 

E 


<  t H  *  °  y  y 


u  o  « 

©  ♦  Ul 

©  *  o 

Ui  ©  Cl. 


►-  -<  Cl  <X 
©  <X  u 
y  o  »-  x 


i»-h  -h  y  y 
Z  3  K  I-  O  «  « 

z  ft.  H.  «  O  z  z 

O  Z  Z  Z  M  u 

Uhm  *i  u  u.  U. 


Dt.  Dobb’s  Journal,  Number  51,  January  1981 


51 

47 


.$4.  1*  ' 


S2.50  ($3.00  In  Canada) 


Dr.  Dobb  s  Journal  of 

COMPUTER  Calisthenics  &  Orthodontia 

FOR  USERS  OF  SMALL  COMPUTER  SYSTEMS 

Number  52  February  1981  Volume  6,  Issue  2 


PARFOR:  A  Theoretical,  Parametrized 
FORTH-like  HLL 

H.T.  Gordon 

Sinclair’s  ZX80 

Review  of  a  Very,  Very  Small  Computer 

John  B.  Palmer 

Small-C 

An  Implementor’s  Notes  and  a  Bug  Corrected 

PL.  Woods 

Z-80  Memory  Test 

Ray  Duncan 

PAN:  One  Activity  of  the  PCNET  Project 

Dave  Caulkins  and  David  C.  Harris 


and  more,  even  more. . . 


P.O.  Box  E 

Menlo  Park 

Dr.  Dobb  s  Journal  of 

Volume  6,  Issue  2 
Number  52 

CA  94025 

COMPUTER  Calisthenics  6  Orthodontia 

February  1981 

Contents 


Articles 


PARFOR:  A  Theoretical,  Parametrized, 

FORTH -like  HLL .  8 

by  H.  T.  Gordon 

Sinclair's  ZX80:  Review  of  a  Very, 

Very  Small  Computer .  14 

by  John  B,  Palmer 

POKE  and  PEEK  to  Your  Heart’s  Content . 16 

by  T.  J.  Van  Iderstine 

PAN:  One  Activity  of  the  PCNET  Project . 17 

by  Dave  Caulkins  and  David  C.  Harris 

DECONCAT:  A  De- Bugging  Tool 

for  Concatenated  Programs . 18 

by  Greg  Smith 

Small-C:  An  Implementor’s  Notes 

and  a  Bug  Corrected . 20 

by  P.  L.  Woods 

Z-80  Memory  Test . 22 

by  Ray  Duncan 

The  Electric  Phone  Book . 42 

The  Radio  Shack  Pocket  Computer . 43 

by  Dick  Greenlaw 


Editorial 


Software  piracy  as  an  issue  has  inspired  a  predictable 
shower  of  editorial  comments  and  disclaimers  from  every 
magazine  and  bulletin  on  the  market.  The  tendency,  unfor¬ 
tunately,  appears  to  be  defensive  rather  than  showing  gen¬ 
uine  interest  in  the  problem.  It  is  as  if,  after  publishing  a 
standard  note  of  abhorrence  on  the  subject,  editors  consider 
the  matter  closed. 

Disregarding  any  inherent  emotional  content,  it  remains 
that  our  legal  system  does  permit  commercial  concerns  to 
copyright  software.  It  is  also  true,  however,  that  innovation 
takes  place  more  easily  in  an  unrestrained  environment. 
Another  concern  are  those  non-profit,  non-business  users 
who  find  the  official  and  financial  requirements  for  obtaining 
licenses  and  updates  too  cumbersome  to  encourage  personal 
microprocessing. 

Creators  of  software  obviously  deserve  compensation,  it 
is  simply  that  the  proper  mechanism  for  doing  so  is  not 
presently  understood.  DDJ  and  People’s  Computer  Company 
do  not  condone  theft  of  copyrighted  materials.  Developers 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 
50 


Departments 


Letters .  6 

Software  Reviews . 34 

Dobb’s  Ex  Machina . 36 

Of  Interest . 38 

Book  Reviews . 41 


©1981  by  People’s  Computer  Company.  All  rights  reserved. 

Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per  year 
by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real,  Menlo 
Park,  California  94025.  Second  class  postage  paid  at  Menlo  Park, 
California  9402  5  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  9402  5. 

Subscription  Rates  &  Writer’s  Guidelines  on  page  42. 


Publisher  Art  Director  Marketing  Director 

Ann  Merchbergei  Clifford  West  Gavin  W.  Cullen 

Editor  Artists  Advertising  Director 

Marlin  Ouverson  Barbara  Ruzgerian  Michael  Madaj 

Contributing  Editors  Greg  Gordon  Circulation  Manager 
Dave  Caulkins  Jeannie  Barroga  peter  Clark 

Dave  Cortesi  Typesetter  Circulation  Assistant 

Renny  Wiggins  Leah  Dansby 


and  distributors  have  always  shown  greater  motivation,  and 
have  provided  better  services,  when  their  larders  are  not 
empty.  We  do  encourage  software  libraries,  low-cost  copying 
services  and  non-proprietary  programs.  It  is  most  important 
that  a  large  pool  of  information  exist  in  the  public  domain. 
This  body  of  material  carries  a  germ  of  vitality  which  thrives 
on  active  interchange,  usage,  commentary,  revision  and  free 
implementation  by  many  different  kinds  of  users. 

The  spirit  of  open  participation  pervades  People’s 
Computer  Company  and  its  publications.  We  will  continue  to 
publish  general  software,  utilities,  algorithms  and  theories  for 
the  benefit  of  the  entire  microprocessing  community. 

Marlin  Ouverson 
Editor 


Letters 


Strings  in  FORTH 

Dear  DDJ: 

I  would  like  to  comment  on  the  sub¬ 
ject  of  strings  in  FORTH,  as  discussed  in 
Mr.  Deane’s  recent  article  ( DDJ  #50).  I 
have  worked  on  implementation  of 
strings  in  CONVERS,  a  FORTH-like  lan¬ 
guage,  and  I  have  found  that  it  is  quite 
convenient  to  have  a  string  comparison 
routine  which  does  more  than  determine 
if  two  strings  are  equal.  My  SCOMPARE 
takes  two  string  addresses  from  the  stack 
and  leaves  a  1,  2,  or  3  on  the  stack,  and 
where  2  indicates  the  strings  are  equal,  1 
indicates  that  the  top  string  is  “greater 
than”  the  bottom  string,  and  3  indicates 
the  top  string  is  “less  than”  the  bottom 
string.  This  information  makes  it  very 
easy  to  sort  or  search  string  arrays,  and  of 
course  can  be  used  to  provide  the  string 
equal  function  if  desired. 

:  S=  SCOMPARE  2  =  ; 

It  is  important  to  make  the  compari¬ 
son  give  “greater  than”  and  “less  than” 
results  in  the  sense  of  alphabetical  order. 
The  almost  useless  string  comparisons  in 
CBASIC  serve  as  an  example  of  how  not 
to  do  it. 

I  also  think  that  it  is  better  to  store 
a  string  count  with  the  variable  rather 
than  using  a  null  to  signify  the  last  char¬ 
acter.  In  this  way  it  is  possible  to  use 
strings  for  general  purpose  buffers.  In  my 
implementation,  when  a  string  variable  is 
executed  it  places  the  starting  address  of 
the  data  on  the  stack.  The  first  two  bytes 
of  data  are  the  maximum  string  size,  the 
next  two  are  the  current  count,  followed 
by  the  string  contents.  This  enables 
strings  to  be  as  large  as  available  memory, 
but  in  actual  practice  this  has  not  turned 
out  to  be  very  useful,  so  255  byte  strings 
are  probably  adequate. 

Yours  truly, 

William  B.  Brogden 
Island  Cybernetics 
P.O.  Box  208 
Port  Aransas,  TX  78373 

Dear  DDJ: 

At  MMS,  we  very  much  enjoyed 
reading  Ralph  Deane’s  fine  article  defin¬ 
ing  some  string  routines  for  the  FORTH 
language. 

We  agree  with  his  premise  that  float¬ 
ing  point  numbers  and  string-handling 
words  are  major  missing  features  of  most 
common  FORTH  versions  available  to¬ 
day.  That  is  why  MMSFORTH,  our  own 
version  of  FORTH  for  the  Radio  Shack 
TRS-80  Model  I  and  Model  III,  provides 


string  operators  —  the  ones  described  and 
more  —  as  a  standard  load  option,  and 
provides  floating  point  number  handling 
—  a  more  complete  set  than  that  provided 
by  the  TRS-80  BASIC  ROM  -  as  an  in¬ 
expensive  utility  routine.  MMSFORTH 
is  a  full,  professional  version  of  FORTH 
which  also  provides  double- precision  in¬ 
teger  arithmetic,  various  types  of  arrays, 
sorting  algorithms,  graphics  capabilities, 
and  more.  Our  standard  versions  for  disk 
or  cassette  sell  for  under  $  100,  and  run  in 
as  little  as  16K  RAM. 

Because  MMSFORTH  has  become 
the  standard  professional  FORTH  on  this 
very  popular  microcomputer,  with  its 
own  users  newsletter  and  more  than 
1,000  registered  users,  we  received  con¬ 
siderable  feedback  on  their  own  likes 
and  dislikes.  Your  FORTH  fans  may  be 
interested  in  our  reading  of  that  feed¬ 
back: 

1.  Floating-point  math  is  sought  by 
many  FORTH  neophytes  but  needed 
by  few  advanced  users.  Although  bet¬ 
ter  techniques  often  exist,  beginning 
FORTH  programmers  may  require  FP 
to  get  their  program  up  and  running 
and,  except  for  the  theoretician,  this 
is  the  bottom  line. 

2.  String- handling  is  a  necessity  for  near¬ 
ly  all  types  of  serious  applications  pro¬ 
gramming.  And  once  FORTH  is  ap¬ 
plied  thusly,  it  shines.  MMSFORTH 
string  words  follow  those  in  Level  II 
BASIC  (a  Microsoft  extended  BASIC), 
which  flattens  the  learning  curve  for  its 
users.  Adhering  to  some  standard 
FORTH  string  nomenclature  could 
create  unnecessary  confusion  unless  it 
is  grounded  in  a  similar  common  exist¬ 
ing  word  set. 

3.  As  with  floating-point,  beginners  of¬ 
ten  want  a  full  Z80  Assembler.  MMS 
also  provides  this  option,  but  we  find 
that  our  own  programming  loses  no¬ 
thing  by  building  on  our  full  8080  As¬ 
sembler,  instead.  It’s  nearly  2K-bytes 
smaller  and  at  least  as  fast  —  including 
its  multi-step  routine  for  block  moves. 
Typically,  users  doubt  this  until  they 
get  good  enough  to  compare.  Chacon 
a  son  gout! 

4.  FORTH  users  want  practical  applica¬ 
tions  programs,  ranging  from  real¬ 
time  graphics  games  to  sophisticated 
business  programs.  In  properly  com¬ 
mented  FORTH  all  these  become  cost- 
effective,  easy  to  maintain  and  enjoy¬ 
able  to  program.  MMS  provides  a 
powerful  and  speedy  database  manage¬ 


ment  system,  a  games  package,  a  sig¬ 
nificant  set  of  additional  utilities,  and 
is  developing  a  complete  business  sys¬ 
tem,  a  flexible  communications  pack¬ 
age  and  an  advanced  word-processing 
system.  Custom  programming  is  a 
major  activity  at  MMS,  and  FORTH 
makes  it  affordable. 

FORTH  is  a  programmer’s  dream 
come  true.  Thanks  for  sharing  it  with 
your  readers!  Any  DDJ  reader  wishing  a 
flier  on  MMSFORTH  for  the  TRS-80  is 
invited  to  write  or  call. 

Sincerely, 

A.  Richard  Miller 
Miller  Microcomputer  Services 
61  Lake  Shore  Road 
Natick,  M A  01760 

Dear  DDJ: 

In  my  article  “A  Proposal  on  Strings 
for  FORTH”  I  supplied  a  demonstration 
program  which  computed  the  Soundex 
code  for  an  entered  name.  I  have  since 
discovered  that  while  it  runs  okay  on  a 
6502  FORTH  system,  it  will  not  work  on 
a  FIG  FORTH-based  system.  This  is  due 
to  a  difference  in  the  way  that  DO  LOOP 
parameters  are  stored.  A  fix  for  this  is  as 
follows. 

DDJ  #50,  page  43,  Figure  VII: 
Change  line  5  to: 

:  ITH  DUP  N$  MID$  DROP  C@64-; 
Change  line  10  to: 

:  COMP  N$  LEN  1  +  2  DO  I  ITH  1ST 
IF  KTH  TEST  IF  BLS  THEN 

These  changes  make  the  Soundex 
program  compatible  with  both  6502 
FORTH  and  FIG  FORTH. 

Ralph  Deane 
Box  27 

Little  Fort,  BC  V0E  2C0 
Canada 

Softcost  Software 

Dear  Dr.  Dobb ’s : 

I’ve  implemented  RATFOR,  Mssrs. 
Kemighan  and  Plaugher’s  rational  alterna¬ 
tive  to  FORTRAN,  on  the  Honeywell 
6000  series  machine.  I’d  be  pleased  to 
make  a  Honeywell  tape  of  this  version  for 
anyone  interested  for  the  price  of  repro¬ 
duction  and  return  postage.  Interested 
readers  may  establish  communications 
with  me  by  letter. 

Sincerely, 

Walter  J.  Kirsch  III 
4316  Starr  Jordan  Drive 
Annandale,  VA  22003 


6 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 

51 


bince  1976,  the  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 

Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


r 

YES!  Enter  my  subscription  to  Dr.  Dobb's  Jour¬ 
nal  and  bill  me  later. 

$25 

name 

one  year  subscription 

12  issues 

address 

saves  $5  off  the  newsstand  price 

city  state  zip 

Mail  to:  DDJ,  P.O.  Box  E., 

Menlo  Park,  CA  94025 

Dr.  Dobb’s  Journal 


For  Users  of  Small  Computer  Systems 


B  Tree  ISAM 
Concepts 


CP/M  BOOS 
and  BIOS  Call 
for  C 


y  IBM  PC 
Printing  Graphic  , 


The  Game  of  Life 


and 

much  morel 


N-Logs 

Dear  Editor, 

Here  are  some  comments  on  the  ar¬ 
ticle  “N-Logs”  in  DDJ  #50.  The  article 
contains  a  number  of  inaccuracies. 

On  page  5,  it  says  that  Napier  used 
the  e=2.71. . .  as  his  base  because  it  is 
easy  to  compute.  I  will  quote  loosely 
from  the  reference  1 : 

Napier  had  no  notion  of  the  base  .  .  . 
Briggs,  after  Napier's  death,  published 
tables  of  decadic  logarithms  .  . .  The 
tables  of  natural  logarithms  appeared  al¬ 
most  simultaneously,  but  their  impor¬ 
tance  was  not  recognized  until  the  in¬ 
finitesimal  calculus  was  better  under¬ 
stood. 

The  natural  logarithm  ln(x)=loge(x) 
has  many  unique  properties.  For  ex¬ 
ample: 

ln(-l)=i*7r 

However,  “the  ease  of  the  evaluation”  is 
not  one  of  them.  In  the  equation  above, 
the  “i”  is  imaginary  unit  (i*i=-l)  and  n= 
3.14  ...  is  Pythagoras’  number. 

Also,  the  “mistakes  of  the  Bell  labs” 
discussed  on  page  6  are  open  to  argu¬ 
ment.  Decibel  (one  tenth  of  a  Bel)  is  used 
in  acoustics  to  measure  both  the  intensity 
(i.e.,  power  per  unit  area)  and  pressure 
level  of  sound  (  =  SPL).  As  a  result  of 
that,  when  you  double  your  distance 
from  the  source  of  the  sound,  the  inten¬ 
sity  of  sound  is  decreased  by  about  6dB; 
the  SPL,  which  is  more  common  when 
describing  sound,  would  decrease  by 
about  3dB  if  definition  would  not  be 
modified.  This  confusing  situation  would 
also  exist  when  discussing  gains:  the  same 
amplifier  would  have  gain  6dB  or  3dB  ac¬ 
cording  to  quantity  used  in  calculation. 
That  is  the  reason  why  textbooks  stress 
the  use  of  the  logarithmic  scale  for  the 
power  only. 

Whether  we  respect  this  convention, 
and  also  whether  we  treat  dB  as  a  unit,  is 
certainly  a  matter  of  taste.  The  merit  of 
the  proposal  is  not  affected  by  that. 
There  are,  however,  more  serious  sins 
committed  in  that  article,  sins  of  incon¬ 
sistency. 

If  we  indeed  do  extend  the  use  of 
the  logarithmic  scale  to  all  quantities, 
then  what  the  author  calls  6-log  is  simply 
the  quantity  X  expressed  in  microbels.  It 
is  unconventional,  but  acceptable  to  say 
that  the  speed  of  light  is  5477  mB  (milli- 
bels),  provided  that  the  value  one  meter 
per  second  was  agreed  on  as  the  reference 
value. 

Finally,  the  convention  explained  at 


the  end  is  an  unfortunate  choice.  If  we 
want  to  avoid  the  superscripts,  as  some 
computer  printers  must,  let’s  stick  with 
the  usual: 

5.103  =5.E3=5000 
e3  =exp35»20 

The  EXP  on  some  calculators  is  short 
for  Exponent,  not  for  the  exponential 
function! 

Annotated  references: 

1  D.  J.  Struik:  A  Concise  History  of  Math¬ 
ematics,  pp  95-97.  (This  book  is  one  of 
the  better  ways  of  spending  $3;  to  order, 
ask  Dover  books  for  their  science  catalog, 
180  Varick  Street,  New  York,  NY  10014.) 
2G.  Porges:  Applied  Acoustics,  pp  16-20. 
(This  is  one  of  the  few  books  on  this  sub¬ 
ject  which  combine  a  good  theoretical 
foundation  with  useful  facts.  Published 
by  Edward  Arnold  in  1971.) 

Peter  Mikes 

16641  Cowell  Street 

San  Leandro,  CA  94578 

Dear  DDJ : 

I  had  immediate  use  for  N-Logs 
(DDJ  #50).  I  needed  to  store  a  large  data 
file  of  the  Dow  Jones  Industrial  closings. 
By  using  the  N-Log  logic,  I  stored  the 
data  as  an  integer  array.  The  following 
program  should  illustrate  the  method 
used.  It  is  also  a  useful  program  to  get  a 
“feel”  for  what  is  happening. 

10  INPUT  “UPPER  LIMIT”  ;U 
20  INPUT  “LOWER  LIMIT”;L 
30  IF  L>=U  THEN  STOP  REM  U 
MUST  BE  GREATER  THAN  L 
40  IF  L<1  THEN  STOP  REM  L  MUST 
BE  1  OR  GREATER 
50  B  =  EXP( (LOG(U)- LOG(L) ) / ( 2 + 
LOG(L)) 

60  C= 32767/ LOG(U/B) 

70  INPUT  “DAT A”; A 
80  D=LOG(A/B)*C+.5 
90  IF  D>32767  THEN  D=32767 
100  IF  D<-32767  THEN  D=-32767 
110  D=INT(D) 

120  E=EXP(D/C)*B 
130  PRINT  D,E 
140  GOTO  70 

Line  50  is  a  centering  procedure  to 
produce  an  evenly  distributed  set  of  posi¬ 
tive  and  negative  values  based  on  the 
upper  and  lower  limits.  It  produces  a  log 
which  lies  at  the  midpoint  of  a  linear 
scale  of  logs  from  the  log  of  “U”  to  the 
log  of  “L.” 

Line  60  produces  a  constant  used  to 
spread  out  the  resulting  data  in  a  range  of 
+  or  -32767.  D  =  the  integer  value  to  be 
stored.  E  =  the  returned  value  after  pro¬ 


cessing  from  integer  form. 

I  anticipate  (right  or  wrong)  the  Dow 
Jones  will  remain  between  3,000  and  300 
for  the  next  five  years.  Using  these  as  my 
upper  and  lower  limits,  I  get  the  follow¬ 
ing: 

B=948.684 

C=24861.1 


Dow  Input 

Integer 

Returned 

956.19 

224 

956.18 

956.20 

225 

956.213 

956.23 

225 

956.213 

956.24 

226 

956.247 

2785.58 

30656 

2785.54 

2785.59 

30657 

2785.64 

2785.68 

30657 

2785.64 

2785.69 

30658 

2785.73 

Stock  volume,  which  can  be  dynamic 
at  times,  is  stored  in  the  same  manner 
since  accuracy  is  then  spread  evenly, 
based  on  the  size  of  the  number  entered. 
Regards, 

Mark  E.  Brown 
5  Maynard  La. 

Eastlslip,  NY  11730 

Dear  DDJ : 

This  letter  is  to  announce  the  availa¬ 
bility  of  my  programs  which  previously 
appeared  in  Dr.  Dobb’s  in  a  new  format. 
They  are  now  also  available  on  Micropolis 
disks  as  well  as  the  8-inch  IBM  compati¬ 
ble  disks  on  which  they  have  been  avail¬ 
able,  both  for  CP/M.  These  are  an  im¬ 
proved  version  of  the  LISP  which  ap¬ 
peared  in  the  December  1978  issue,  and 
the  table  driven  assembler  which  ap¬ 
peared  in  February  1980.  The  8-inch 
disks  continue  to  be  available  for  $10 
each.  The  Micropolis  disks  are  now  avail¬ 
able  for  $15  each.  Persons  outside  the 
United  States  and  Canada  should  include 
an  extra  $2. 

Sincerely, 

Darrel  J.  Van  Buer 

1522  Brockton  Avenue,  Apt.  5 

Los  Angeles,  CA  90025 

Small -C  Compiler 

Dear  DDJ: 

While  implementing  a  CP/M  version 
of  the  Small-C  compiler  (DDJ  #45  and 
#48),  I  discovered  an  error  in  the  run¬ 
time  library  routines  for  the  left  and  right 
shift  operators.  The  C  language  defines 
any  shift  from  zero  to  the  length  of  the 
object  as  legal.  The  routines  ccasl  and 
(continued  on  page  37 J 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


7 

53 


PA  R  FOR 


A  Theoretical 
Parametrized, 

FORTH  like  HLL 


by  H.T.  Gordon 


M 

-A-  ▼  JLy  first  step  in  the  chaotic  HLL  area  was  an  attempt 
to  understand  the  operation  of  FORTH  ( DDJ  #51).  My  tenta¬ 
tive  conclusion  was  that  FORTH  now  is  a  high-level  assembly 
language  for  a  virtual  machine  that  ought  to  have  a  much  more 
powerful  core  structure  than  it  has.  It  is  my  belief  that  develop¬ 
ment  of  a  better  virtual  machine  is  not  a  one-man  task.  The 
most  important  quality  of  an  HLL  is  not  speed  or  efficiency, 
but  acceptability  to  a  quite  large  number  of  users.  I  doubt  that 
any  HLL  will  ever  be  truly  acceptable  to  everyone,  even  if  its 
creator  is  a  genius.  I  vaguely  see  that  distinct  types  of  HLL’s  are 
possible.  Within  each  type,  optimizations  are  possible  such  that 
several  different  excellent  designs  could  be  made  to  work 
equally  well.  If  so,  only  one  design  is  needed,  so  that  the  num¬ 
ber  of  exchangeable,  complex  programs  will  be  maximized.  Re¬ 
duction  in  the  number  of  widely- used  HLL’s  would  also  allow 
CPU  designers  to  optimize  “real”  machines  for  one  (perhaps 
even  more  than  one)  virtual  machine.  Minimizing  variations  at 
all  levels  makes  possible  economies  of  scale.  CPU’s,  systems,  and 
complex  programs  would  all  cost  less. 

The  cost  of  development  of  any  innovation  is  minimized  by 
extensive  theoretical  exploration.  1  am  convinced  that  ultimate 
quality  can  be  maximized  by  the  participation  of  many  human 
minds,  including  those  of  amateurs  like  me.  We  cannot  see  as  far 
as  experts  do,  but  we  may  sometimes  see  things  that  their  biases 
cause  them  to  overlook.  Most  of  our  ideas  will  indeed  be  of  no 
value,  long  ago  evaluated  and  rejected  by  the  cognoscenti.  Any 
expert  who  bothers  to  read  what  we  write  will  be  utterly  bored. 
What  interests  them  is  the  work  of  other  experts,  and  the  needs 
of  the  rich  and  powerful  minority  within  our  society.  That’s 
the  IBM  complex  which  dominates  computer  science.  Big  is 
beautiful. 

The  purpose  of  this  note  is  to  offer  a  purely  theoretical  ex¬ 
tension  of  the  “parametrized  command”  concept  that  arose 
from  my  earlier,  casual  study  of  FORTH.  My  hope  is  that  it  will 
be  criticized  (perhaps  enhanced,  perhaps  rejected)  for  sound, 
logical  reasons  by  more  able  minds  than  my  own. 


s 

i  implications  of  parametrized  command  notation.  One  of 
the  human  problems  with  all  languages  is  the  tedious  keying-in 
of  the  source  code.  FORTH  has  a  fair  number  of  single¬ 
character  commands,  trading  off  mnemonic  value  for  less  keying 
effort,  e.g.,  the  period  (.)  character  that  commands  pulling  the 
number  on  TOS  (top  of  variable  stack)  and  printing  it.  My 


8 

54 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


initial  proposal  for  parametrized  commands  was  ?CX  Y,  where  ? 
is  the  identifier  for  this  type,  C  is  some  one  ASCII  character 
that  specifies  the  actual  operation  (e.g.,  S  for  a  stack- 
manipulation),  and  X  and  Y  are  decimal- digit  parameters.  Since 
the  number  of  parametrizable  operations  turns  out  to  be  quite 
large,  a  simpler  approach  would  be  to  reserve  three-character 
command  codes  to  denote  parametrization.  Since  the  number 
( n )  of  characters  becomes  the  first  byte  of  the  dictionary 
“entry,”  the  generalized  form  CXY  would  be  entered  as  3C,  the 
3  acting  as  the  identifier  and  the  C  as  the  operation- code 
expecting  (for  actual  keying-in)  variable  X  and  Y  digital  para¬ 
meters.  Thus,  stack-manipulation  types  would  exist  in  the 
dictionary  as  the  eccentric  entry  3S,  and  keying-in  S10  would 
execute  the  equivalent  of  the  present  DUP  command  code,  S20 
the  present  OVER,  etc.  I  shall  not  reiterate  the  many  variants 
outlined  for  stack -manipulation  in  my  earlier  note.  All  would 
become  three -character  commands,  the  minimal  possible  length. 
Reserved  “words”  exist  in  many  HLL’s.  This  merely  extends  the 
concept  to  reserved  word  lengths.  Parametrization  adds  some 
mnemonic  value,  but  this  is  not  the  forte  of  FORTH!  PARFOR, 
if  it  ever  is  born,  will  be  more  laconic  than  STOIC. 


r 

eneralized  loop- parameters  access.  The  existing  com¬ 
mand  I  causes  the  value  of  the  current  Index  integer  to  be 
copied  from  the  return-stack  to  what  I  term  the  S0  location  of 
the  variables  stack.  In  the  Bruce  Airy  version  of  FORTH  that 
triggered  my  own  thinking,  there  are  analogs  (J,  K,  L,  .  . .)  that 
allow  similar  access  to  the  current  Indices  of  the  successive 
outer  loops  within  which  the  presently-operational  loop  may  be 
nested.  The  type  IX Y  code  would  allow  access  to  anything  de¬ 
sired.  X=0  would  mean  the  operational  loop  within  which  code 
is  now  being  written  or  used.  Its  parameters  were  pushed  on  the 
return-stack  in  the  order:  Index,  Endex,  and  return- address, 
identifiable  by  Y=0,  1,  and  2.  Thus,  100  would  be  equivalent  to 
the  present  I  command,  101  would  copy  the  current  (constant) 
Endex  to  S0,  and  102  would  copy  the  current  return-address  to 
So-  Since  the  parameters  of  the  next  outer  loop  are  similarly 
stacked  just  above  the  current  ones,  110  would  work  like  Airy’s 
J,  120  like  his  K,  etc.,  and  all  other  parameters  would  be  equally 
accessible.  You  lose  the  delightful  brevity  of  I,  but  you  save 
the  limited  supply  of  single -characters  for  possible  powerful, 
parametrized  commands.  You  gain  access  to  things  you  may  not 
want,  but  as  I  have  said  before,  there  is  never  an  obligation  to 
use  all  available  power. 


T 

-M-  he  data -structures  problem  (for  now  just  numerics).  This 
is  the  supreme  problem  in  computer  science,  as  many  important 
books  attest,  as  well  as  the  HLL’s  designed  to  handle  certain 
types  optimally.  I  have  read,  but  not  mastered,  only  M.  C. 
Harrison’s  Data  Structures  and  Programming  (Scott,  Foresman 
&  Co.,  1973).  My  impression  is  that  FORTHians  skip  lightly 
over  this  snakepit,  relying  on  user-extensibility  for  do-it- 


yourselfing  whatever  may  be  required.  Still,  an  HLL,  especially 
in  the  only-a-dream  stage  of  PARFOR,  ought  to  grasp  this 
nettle  and  consider  whether  its  core  structure  can  be  designed  to 
facilitate  variety  and  complexity  of  data-structures.  Nothing  so 
fundamental  should  be  an  afterthought.  CPU  designers  are 
keenly  aware  of  this,  and  what  is  an  HLL  if  not  a  softwarish 
CPU? 

Multidimensional,  complexly  interlinked  structures  are  far 
beyond  me,  as  is  the  user-extensible  BALM  language  described 
in  Harrison’s  book.  Numerics,  being  “linear  data- objects,” 
seem  more  intelligible.  My  impression  is  that  most  versions  of 
FORTH,  even  if  executed  by  an  8-bit  CPU,  operate  on  16-bit 
numbers,  though  FIG  FORTH  has  a  few  commands  that  handle 
8-bit  bytes  and  some  “double- precision”  ones  that  work  on  32- 
bit  numbers.  (Maybe  more  bytes,  since  an  entire  byte  may  be  in 
use  to  store  the  sign  of  the  number?)  Generalization  presents  a 
problem  not  unlike  the  one  I  briefly  noted  for  microprocessors 
( DDJ  #49,  page  22):  should  you  specify  precision  by  using  a 
specialized  opcode  implying  it,  as  in  FIG  FORTH,  or  by  a  one¬ 
time  prefix  opcode  to  modify  only  the  immediately- following 
action,  or  by  a  permanent  (until  negated)  opcode  modifying  all 
subsequent  actions?  This  last  type  is  used  in  the  number- base¬ 
setting  of  FORTH  numerics,  the  base  (binary,  decimal,  or  hex) 
remaining  in  control  until  reset  to  a  different  base.  Of  course,  a 
flexible  base- type  is  possible  using  a  parametrized  primitive 
such  as  BXY.  X  would  be  1  for  binary,  9  for  decimal,  F  for 
hexadecimal  (hex  coding  being  always  implied).  Y  would  be  0 
for  indefinite  duration,  1  for  one-time  operation  (potentially 
extensible  all  the  way  up  to  F  for  up  to  15  re-uses  before  laps¬ 
ing  back  to  the  saved  permanent-base). 

This  is  trivial,  but  the  concept  (as  I  suggested  in  DDJ  #49) 
is  applicable  to  bit- precision  also.  Although  handling  of  4- bit 
nibbles  might  be  of  interest,  perhaps  even  of  single  bits,  the 
precision -setting  primitive  LXY  might  use  X  to  specify  the 
number  of  bytes  to  be  handled  as  a  unit.  L10  would  be 
a  permanent-set  to  single-byte  precision,' L20  to  16-bit,  LF0  to 
120-bit  (15  bytes).  This  last  would  modify  a  stack- manipulation 
like  S]  o  to  copy  the  top  1 5  bytes  of  the  variables  stack  into  the 
next  15  available  locations!  That  would  be  quite  a  large  integer 
(of  the  order  of  10  to  the  36th  power!).  Of  course,  trying  to 
multiply  Si  by  S2  would  blow  up  the  stack,  unless  safeguards 
were  built-in  or  an  automatic  shift  to  exponential  notation  (as 
in  pocket  calculators)  were  caused. 

Who  might  need  such  big  numbers?  Perhaps  no  one,  but  if 
it’s  feasible  why  not  allow  it?  This  is  a  good  time  to  point  out 
the  trade-off  of  endowing  each  command- code  character  with 
control  over  execution:  one  slip  can  spell  disaster!  There  has  to 
be  a  price  for  the  combination  of  power,  generality,  and  con¬ 
ciseness.  Even  those  who  would  never  use  the  power  must  run  a 
greater  risk  of  error. 

Bruce  Airy’s  version  includes  floating-point  operations,  but 
I  see  no  virtue  in  decimal  points.  A  signed  integer  paired  with  a 
signed  integer  exponent  can  approximate  a  wide  range  of  real 
numbers.  How  wide?  Assuming  that  a  15-byte  upper  limit  for 
integers  is  workable,  at  least  one  of  them  is  needed  for  the  num¬ 
ber,  leaving  14  for  the  exponent,  a  value  of  colossal  size  but  in¬ 
finitesimal  precision.  The  other  extreme  would  be  a  14- byte 
numeric  with  a  1-byte  exponent,  sacrificing  range  for  precision, 
but  still  pretty  big.  This  would  be  specified  by  altering  the  inter¬ 
pretation  of  LXY,  making  all  possibilities  permanent-set  (until 
reset).  Y=0  would  mean  an  integer,  and  thus  L20  would  set  the 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


9 

55 


“I  am  convinced  that  ultimate 
quality  can  be  maximized  by  the 
participation  of  many  human 
minds  ...” 


numeric  format  to  16- bit  integers.  L22  would  mean  pairing  of  a 
16-bit  integer  with  a  16-bit  exponent,  etc.  In  principle  one 
could  have  LFF,  but  a  length  of  30  bytes  might  be  hard  on  the 
stack!  The  L  logic  could  be  written  to  reject  values  of  X+Y 
greater  than  15.  Greater  expertise  than  mine  is  needed  for  deci¬ 
sions  of  this  kind.  Nor  do  I  feel  qualified  to  go  into  logarithms, 
though  I  know  their  value,  and  I  feel  that  they  belong  in  a  math 
core.  As  usual,  the  problem  is  what  ought  to  be  in  the  core 
structures  and  what  ought  to  be  left  for  special-purpose  pro¬ 
grams.  Generality  must  dominate  the  core,  combined  (as  far  as 
possible)  with  speed  and  efficiency. 


P 

M  rint  command  —  output  devices  and  formatting.  FIG 

FORTH  has  many  typically  specialized  commands  targeted  on 
what  seems  to  be  a  single  display  terminal.  Proliferation  was 
probably  forced  by  the  rudimentary  character  of  the  decimal- 
point  primitive,  that  just  pulls  S!  from  the  variables  stack  and 
prints  it,  assuming  a  length  of  16  bits.  My  proposed  LXY 
precision-setting  command  ought  to  alter  the  operation  to 
print  whatever  length  it  specifies.  But  what  might  be  done  with 
the  command-type  .XY?  A  program  may  well  need  to  address 
other  output  devices  than  the  user  terminal,  and  X=0  could  be 
used  to  specify  the  terminal.  Other  values  (up  to  15  if  hex- 
coded)  involve  switching  and  interfacing  problems  that 
logic  must  deal  with  in  a  generalized  way,  perhaps  by  jumps  to 
segments  of  a  system-monitor  program  tailored  for  operating 
whatever  devices  are  in  the  system.  What  of  the  information 
in  Y?  There  are  many  possibilities.  The  value  0  could  retain 
the  present  effect  (pull  Sj  and  output  it),  while  1  would  output 
Si  without  pulling  it,  2  would  similarly  output  S2,  etc.  More 
knowledge  of  device-control  than  I  now  have  is  needed  to  opti¬ 
mize  this.  The  FIG  FORTH  specifics  seem  to  provide  a  few  sim¬ 
ple  output  formats,  more  sophisticated  ones  demanding  pro¬ 
grammed  construction. 


13 

ead  operation.  There  is  now  no  single-character  input- 
read  command  code,  though  a  ?  might  be  made  the  equiva¬ 
lent  of  the  output  command.  Again,  FIG  FORTH  has 
many  specific  codes,  presumably  created  in  response  to  frequent 
needs.  Once  more  I  am  at  a  loss  in  defining  an  ?XY  code, 
though  X  could  logically  specify  the  input  device.  What  is  re¬ 
quired  is  a  clear  general  concept  of  the  I/O  in  a  system.  This  is 
an  area  where  only  user-experience  can  suggest  optimal  general 
modes,  a  problem  that  has  often  puzzled  me  at  the  assembly- 
language  level. 


A 

.X.  Arithmetic  operations.  Like  all  other  FORTH  com¬ 
mands,  the  operators  for  add  (+),  subtract  (-),  multiply(*),  and 


divide  (/)  are  very  specifically  defined.  Stack  locations  Si  and 
S2  are  pulled,  S!  is  used  as  the  first  operand,  and  the  result  is 
pushed  on  the  stack  (becoming  Si).  Stack -manipulation  is  re¬ 
quired  to  make  use  of,  or  to  prevent  loss  of,  the  existing  data. 
Pulling  is  clearly  necessary  to  avoid  blowing  up  the  stack, 
especially  in  loop  operations  where  even  a  small  imbalance 
would  accumulate.  Still,  if  you  pull  two  units  and  replace  them 
by  only  one,  or  if  (to  save  them)  you  duplicate  them  and  then 
operate,  you  have  either  shortened  or  lengthened  the  stack. 
The  all- wise  programmer,  of  course,  takes  care  of  that,  and  the 
operator  logic  may  detect  overflow  and  underflow  problems  as 
the  better  pocket  calculators  do.  I  do  not  know  whether  shifts 
to  exponential  notation  are  automatically  done,  calculator- 
style,  though  it  would  be  possible  to  encode  an  alteration  of  the 
(kernel- stored)  notation-control  directly  set  by  LXY.  This 
raises  the  important  question  of  a  PARFOR  status  register, 
which  I  shall  deal  with  later  on.  For  now,  the  question  is 
whether  parametrizing  the  arithmetic  operators  might  be  useful. 

By  analogy  with  the  SXY  stack- manipulation,  +XY  could 
specify  the  stack  locations  to  be  used,  X  being  the  first  operand. 
Thus,  +23  would  denote  (S2  +  S3,  -*  S0),  nothing  being  wiped 
out.  The  programmer  could  “drop”  operands  by  using  S33  or 
S44  or  a  sequence  of  two  S33’s  (the  numeric  change  is  required 
because  the  add  lengthened  the  stack  by  one).  Some  compara¬ 
tive  programming  would  be  needed  to  see  if  there  is  a  gain  or 
loss  of  code  or  timing,  in  general,  sufficient  to  decide.  My  guess 
is  probably  not.  But  there  are  other  possibilities  for  XY  inter¬ 
pretation.  X=0  could  be  a  programmer-command  to  forbid  any 
further  execution  if  either  underflow  or  overflow  occurred; 
X=1  would  allow  only  underflow;  X=2  only  overflow  (with 
retention  of  the  most  significant  digits);  X=3  overflow  (retain¬ 
ing  least  significant  digits);  and  X=4  an  automatic  shift  to  ex¬ 
ponential  notation  limiting  the  integer  precision  to  4  bytes  (and 
analogously  for  5,  6,  etc.).  I  cannot,  offhand,  think  of  a  use  for 
Y  when  X  is  less  than  4,  but  Y  can  be  used  to  set  the  limit  for 
the  exponent,  which,  if  exceeded,  will  stop  operation.  Perhaps 
Y=0  could  signify  permission  to  continue  building  up  the 
integer  length  to  the  limit  value  present  in  X.  The  advantage  is 
that  the  programmer  acquires  some  control  over  the  execution- 
logic  of  the  operator. 


T 

JL.  he  case  for  an  HLL  status-register.  So  far  I  have  only 
argued  for  a  more  information- rich  command-coding  that  does 
not  seriously  alter  the  architecture  of  FORTH.  The  concept  of 
creating  the  high-level  analog  of  a  CPU  status- register  first  arose 
when  I  understood  Bruce  Airy’s  view  of  FORTH  as  the  equiva¬ 
lent  of  a  CPU.  It  had  a  “state”  variable  hidden  in  its  kernel, 
automatically  modified  by  operations,  vaguely  like  the  interrupt 
bits  of  a  CPU.  Program -set  status,  however,  with  its  associated 
branch  commands,  was  a  rather  crude  zero  or  non-zero  tempo¬ 
rarily  pushed  on  the  variables  stack.  The  whole  thing  struck  me 
as  extremely  primitive  (of  course  I  had  only  Airy’s  description), 
reflecting  the  state  of  CPU’s  in  the  pre-1970  era  and  also  the 
gradual  accretionary  evolution  of  FORTH  in  the  mind  of  its 
maker  (like  the  seemingly  inconsistent  branch  constructs  of 
LOOP  and  IF).  When  you’ve  built  something  up  over  a  long 
time,  you’re  reluctant  to  tear  down  the  ancient  structures  and 


10 

56 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


there  is  never  an  obligation 
to  use  all  available  power.” 


rebuild  from  the  ground  up,  preferring  just  to  add  on  new  and 
better  things.  That’s  why  it  is  good  that  we  oldsters  die  out  - 
the  young  feel  free  to  raze  our  rats’  nests  and  start  from 
scratch,  possibly  to  make  something  better! 

There’s  a  plethora  of  statuses  in  any  complex  operation. 
Numeric  or  non- numeric.  Positive,  negative,  equal.  Zero  or  non¬ 
zero.  Integer  or  exponential  notation.  Unit  length  1-bit,  4-bit, 
8 -bit,  etc.  Some  may  be  important  enough  to  base  decisions  on. 
Others  may  have  information  value  for  analysis  and  debugging. 
In  a  microprocessor,  circuitry  sets  a  limit.  In  a  virtual  CPU,  the 
limits  are  more  subtle:  timing  losses,  memory  consumption,  the 
capacity  of  the  human  mind.  These  are  nonetheless  wider  limits, 
and  an  HLL  status  register  can  have  the  dimensions  of  a 
decision- table. 

The  status  registers  of  microprocessors  have  been  often  de¬ 
scribed  (briefly  by  me,  in  Microcomputing,  April  1980,  page 
176).  They  store  information  bits,  some  in  a  continuous  auto¬ 
matic  mode,  at  a  minor  cost  in  circuitry  with  no  timing  penalty. 
Usually  four  of  them  control  branch  or  jump  instructions.  The 
register  is  valuable  in  program  debugging.  In  a  FORTH-like 
HLL,  the  basic  unit  is  the  8-bit  byte,  allowing  256  distinct 
states,  and  the  register  can  be  of  indefinite  length  and  user- 
extensible.  However,  there  is  a  price  both  in  memory  and 
timing.  The  decision  as  to  which  primitives  should  update  which 
status  bytes  automatically,  therefore,  requires  thought. 

The  existing  kernel-stored,  dictionary- status  addresses 
(HEAD,  the  first,  and  LAST,  the  last  byte  of  the  most  recent 
entry)  clearly  belong  in  the  register.  FIG  FORTH  seems  to  have 
other  entry-addresses,  whose  operation  is  not  clear  to  me.  The 
STATE  variable,  determining  execution  or  compilation,  is  a 
status  byte.  There  may  be  merit  in  a  zero/non-zero  status- 
register  byte,  to  remember  a  prior  status  and  allow  its  re-use 
later.  Also  useful  might  be  a  negative- status,  a  positive  (non¬ 
zero)  status,  and  a  set  of  status  bytes  arising  from  a  generalized 
COMPARE  command:  equal/unequal,  less  than/not  less  than, 
greater  than/not  greater  than.  Possibly  the  current  stack -pointer 
addresses  ought  to  be  in  the  register  sequence.  A  print -the- 
status- register  primitive  would  allow  the  programmer  to  view  all 
this  at  once,  whenever  needed.  Perhaps  the  count  of  the  number 
of  loops  created  and  terminated  (even  of  their  BEGINS  and 
ENDs,  and  DOs  and  LOOPs)  would  also  be  useful.  As  always, 
user  experience  will  reveal  whether  other  statuses  are  desirable. 
The  numeric- operation  status  could  include  the  number  of 
bytes  in  the  integer  and  also  the  number  in  the  exponent.  A 
zero  in  the  second  would  mean  a  pure  integer.  A  zero  in  the  first 
might  denote  non-numeric  status.  The  programmer- specified 
controls  that  I  suggested  for  the  +XY  primitive  (also  feasible  for 
the  other  operators)  could  be  saved  in  the  register,  and  also 
things  like  overflow  and  underflow  statuses.  The  list  is  already 
quite  long,  though  not  exhaustive. 


A 

jL.  parametrized  conditional-jump  primitive.  Assuming 

that  a  sequence  of  status- register  bytes  exists  and  is  updated  in 
the  kernel,  the  existing  IF  could  be  replaced  by  FXY.  This 
would  pick  up  the  correct  jump  address  as  now,  but  X  would 
specify  which  status  byte  is  to  control  the  jump,  and  Y  would 
be  either  0  or  1.  If  X=0  specifies  the  zero/non- zero  status  byte, 


F00  would  interpret  as  jump-if-zero,  F01  as  jump-if-non-zero. 
There  would  be  analogous  jump-if-negative,  jump-if-equal, 
jump-if-overflow,  etc.  possibilities,  including  user-defined  flags. 

The  CASE  construct,  allowing  more  than  a  bifurcation,  is 
available  in  principle  as  a  logical  extension  of  the  FXY,  if  the 
programmer  sets  the  value  of  Y  to  a  hex  integer  from  2  to  F  (F 
being  reserved  as  a  terminator).  The  preceding  decision-logic  is 
expected  to  set  the  “case- byte”  in  the  status  register  to  one  of 
the  possible  values.  The  code  FX2  will  compile  the  address  of 
the  F  primitive  logic,  leave  the  jump  address  empty,  and  be  fol¬ 
lowed  by  the  case- 2  execution  logic,  terminated  by  an  FX3. 
This  will  compile  the  address  of  F  again,  but  fill  the  empty  FX2 
address  of  the  FX2  with  its  own  address  (so  that  there  will  be  a 
jump  to  FX3  if  the  case- byte  was  not  2),  and  leave  an  empty 
space  of  the  preceding  FXY  with  its  own  address.  What  of  the 
X  value?  This  can  be  used  to  warn  the  compiler  of  the  number 
of  cases  to  be  encountered.  The  case  status- byte  can  be  used 
during  compilation  to  store  this  number.  An  initial  F42  would 
store  the  number  4.  The  compiler  then  expects  a  sequence:  F33, 
F24,  FI 5,  and  a  terminator  FOF,  and  compel  the  programmer 
to  keep  things  in  order!  This  might  reduce  the  error- proneness 
of  the  CASE  construct. 

The  above  still  leaves  FXF  uninterpreted  for  values  of  X 
from  1  to  F.  Readers  may  have  noted  that  the  FOF  definition  is 
equivalent  to  the  THEN  of  existing  FORTH,  with  all  else  only 
a  playing  on  the  possible  intricacies  of  the  IF.  Also,  moving  the 
status  into  a  kernel-updated  register  means  that  whatever  is  on 
the  stack  no  longer  matters  when  the  F  logic  is  executed.  The 

ELSE  can  therefore  be  the  alternate  IF,  e.g . (decision-logic) 

. .  .  F00  . .  .  (non-zero  status  logic) . .  .  F01  . . .  (zero-status  log¬ 
ic) ..  .  FOF  .  .  .  Note  that  if  no  zero-status  logic  is  needed,  but 
something  ought  to  be  done  if  there  was  an  overflow,  the  F01 
can  be  replaced  by  an  FX1  (where  X  is  the  status  byte  for  over¬ 
flow). 

It  may  be  useful  to  reiterate  the  six  distinct  operations  pos¬ 
sible  in  F  compilations:  (1)  Push  onto  the  variables  stack  the 
current  address  in  the  compiler  command -counter,  and  incre¬ 
ment  the  (normally- zero)  jump-status  byte  in  the  status- 
register.  If  the  command  does  nothing  else,  it  is  a  “pure  initia¬ 
tor”  like  the  FORTH  BEGIN.  This  could  be  the  F1F.  (2)  Pull 
address  previously  stored  on  the  stack,  and  decrement  the  jump- 
status  byte.  This  would  make  no  sense  if  the  jump-status  byte  is 
at  zero,  so  this  would  “inhibit”  step  two.  (3)  Compile  into  the 
program  sequence  the  execution-address  of  the  F  command 
logic,  and  then  the  XY  numerics  that  logic  will  need,  as  with  all 
normal  parametrized  commands.  Since  F  logic  executes  a  jump, 
however,  the  next  space  in  the  program  must  get  filled  by  the 
correct  jump-address,  now  or  later.  (4)  If  the  jump -status  byte 
is  zero,  there  is  no  address  left  on  the  stack.  Therefore,  the 
jump-address  space  is  left  vacant  and  step  one  must  be  done,  so 
that  a  subsequent  command  will  be  able  to  locate  and  fill  the 
vacancy  with  its  own  current  address,  creating  a  forward  jump. 
(5)  If  jump-status  is  non-zero,  a  command  may  do  step  two  and 
use  the  stored  address  to  locate  the  vacancy  and  fill  it  with  its 
own  address.  If  nothing  else  is  done,  this  is  a  terminator  like  the 
FORTH  THEN,  for  which  I  have  already  proposed  the  FOF 
coding.  (6)  If  jump-status  is  non-zero,  and  step  three  is  done,  a 
command  may  do  step  two  and  use  the  stack-stored  address  to 
fill  its  own  jump-address,  creating  a  backward  jump.  An  uncon¬ 
ditional  backward  jump,  like  the  FORTH  END,  could  be  en¬ 
coded  as  FFF,  but  this  creates  an  indeterminate- loop  problem. 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


11 

57 


given  a  task  at  a  certain  level 
of  complexity,  one  ought  to  do 
it  in  the  simplest  possible  way.” 


Types  like  FXO  or  FX1  might  allow  a  conditional  exit,  but  we 
must  first  see  how  these  IF-like  operations  must  normally  work. 
An  initial  F00  is  inhibited  from  doing  step  two  since  the  jump- 
status  is  zero.  It  does  step  four  (a  sequence  of  steps  three  and 
one).  However,  a  subsequent  F01  (working  like  an  ELSE),  finds 
a  jump-status  of  1,  enabling  step  five  (that  includes  step  two, 
and  then  step  four,  so  that  the  address  of  the  F00  is  replaced  on 
the  stack  by  that  of  the  F01,  with  jump-status  reset  to  1). 

Such  chains  have  no  logical  limit,  unless  terminated  by  the 
FOF.  It  is  clear  that  the  sequence  F1F  (BEGIN) .  . .  F00  . . . 
cannot  work  if  the  F1F  does  only  step  one!  The  F00  “sees”  a 
jump-status  of  1  and  will  try  to  fill  a  non-existent  jump  com¬ 
mand  with  its  own  address!  This  can  be  inhibited  if  the  F1F 
pushes  a  zero  onto  the  stack  following  its  own  address.  When 
the  F00  executes  step  two  and  finds  that  it  has  pulled  a  zero 
value,  it  shifts  its  execution  to  step  three  and  step  six,  leaving 
the  jump-status  at  zero  to  signal  termination  and  creating  a 
conditional  backward  jump,  allowing  exit  if  the  zero-status  byte 
eventually  gets  set  to  1 . 

This  type  of  loop  still  does  not  allow  the  equivalent  of  the 
BEGIN  .  .  .  IF  .  .  .  END  construct  of  FORTH,  where  the  IF  al¬ 
lows  conditional  escape  from  the  indeterminate  loop  created  by 
the  unconditional  jump  from  END  back  to  BEGIN.  The  IF  must 
now  ignore  the  BEGIN  address  and  work  as  if  it  were  an  initial 
IF,  doing  only  step  four,  and  the  FFF  (END)  must  fill  its  vacant 
address  with  the  first  address  of  the  post-END  escape  logic. 
What  is  needed  is  a  different  type  of  BEGIN  (perhaps  FEF)  that 
would  push  first  its  own  return  address,  then  FFFF  on  the  stack. 
A  subsequent  F00,  on  executing  step  two  and  finding  this  odd 
address,  would  shift  execution  to  step  four,  leaving  a  jump- 
status  of  2  in  the  register.  The  terminating  FFF  would  then  do 
both  step  five  and  step  six. 


A 

X  pause  for  reflection  on  the  rationale  of  PARFOR. 

Readers  who  have  persisted  to  this  point  in  my  description  of 
the  structure  of  an  imaginary  HLL  must  be  wondering  why  I  am 
maximizing  its  complexity.  A  few  may  recall  my  earlier  paeans 
of  praise  to  the  goddess  of  simplicity!  I  still  worship  her  in  the 
sense  that,  given  a  task  at  a  certain  level  of  complexity,  one 
ought  to  do  it  in  the  simplest  possible  way.  That  way  may  have 
to  be  quite  complex.  Reality  is  complex.  Complexity  is  unavoid¬ 
able.  The  only  question  is  Where  should  it  be? 

The  aim  of  PARFOR  is  to  put  it  in  the  machine  code  of  the 
control  programs  of  the  kernel  and  the  primitives.  It  is  there 
that  the  tiny  elite  of  assembly-language  experts  can  optimize 
operations  for  the  specific  CPU  that  does  the  ultimate  execu¬ 
tion.  Complexity  doesn’t  phase  them\  The  problem  has  long 
been  recognized  at  the  machine-code  level,  in  deciding  whether 
to  encode  a  small  block  of  instructions  in-line  or  as  a  subrou¬ 
tine.  If  it’s  going  to  be  used  often,  subroutining  it  will  trade-off 
speed  of  execution  to  save  memory  (often  done  in  ROM  design 
where  memory  is  at  a  premium).  Another  way  is  to  create  com¬ 
plex,  multi-purpose  subroutines  that  handle  many  parameters. 
That  becomes  even  more  appealing  as  one’s  expertise  in 
machine-language  grows,  since  main  programs  can  become 
simple,  just  controlling  subprograms. 

The  FORTHian  view  is  well -presented  in  a  recent  article  by 


BUI  Ragsdale  of  the  FIG  (BYTE,  October  1980,  page  274). 
Their  design  criteria  for  FORTH  are:  1)  correctness  —  most  im¬ 
portant  to  a  user,  2)  portabUity,  3)  simplicity  of  buUt-in  com¬ 
mands  -  most  important  to  FORTH,  4)  clarity,  5)  generality, 
6)  execution  speed,  7)  memory  compactness,  8)  compUation 
speed,  9)  historical  continuity  (I’m  not  sure  what  that  means), 
10)  pronounceability,  and  1 1)  teachability. 

It’s  at  point  three  that  PARFOR  diverges  from  FORTH. 
That  decision  trades-off  linguistic  simplicity  at  the  price  of  pro¬ 
gram  complexity.  FORTHians  know  that  “a  greater  burden  is 
placed  on  the  programmer,  who  must  create  application-specific 
functions.  This  characteristic  is  tolerated,  even  cherished,  by 
FORTH  programmers:  but  who  better  understands  the  demands 
of  the  application,  the  application  programmer  or  a  distant  com¬ 
piler  writer?” 

To  me,  the  real  question  is  Who  has  the  more  brilliant  mind 
and  the  broadest  and  deepest  knowledge  and  experience?  In  my 
introduction  I  argued  that  amateurs  can  play  a  minor  role,  and 
that  professionals  err  when  they  ignore  us.  However,  star  roles 
and  center-stage  belong  to  the  experts.  As  an  amateur,  I  don’t 
cherish  writing  complex  programs.  I  would  relish  having 
expertly-designed,  bug-proofed  tools  to  use.  That’s  the  ration¬ 
ale  of  operating  systems  like  CP/M  and  other  expert  creations, 
including  all  HLL’s. 

s 

k^ome  concluding  thoughts, and  a  hazy  PARFOR  architec¬ 
ture.  My  first  article  on  FORTH  was  not  easy  to  write,  and  was 
intended  to  do  some  ice-breaking.  This  one  has  tried  to  initiate 
some  building,  an  even  more  fatiguing  task  (no  doubt  for  read¬ 
ers  as  well)!  The  possibilities  of  even  parametrization  are  im¬ 
mense,  and  it  is  only  one  of  many  possible  approaches  to  fuller 
utilization  of  the  information-carrying  capacity  of  the  charac¬ 
ters  in  command -codes. 

As  a  kind  of  last  gasp,  I  shall  try  to  complete  the  interpreta¬ 
tion  of  the  RXY  stack -rotation  command  casually  mentioned 
in  my  earlier  article.  The  existing  ROT  command  of  FORTH, 
that  executes  (S3  -►  Si  -*■  S2  -►  S3),  was  defined  by  R31,  and 
the  corresponding  counter-rotation  by  R13.  The  operation  of  a 
legion  of  analogous  rotations  is  commanded  by  using  other  non¬ 
zero  parameters.  Interpretation  is  also  possible  for  ROY  and 
RXO.  Though  the  S0  location  is  undefined,  it  can  be  momen¬ 
tarily  set  to  zero.  R20  will  cause  (S2  -*  So  -*■  Si  -*■  S2),  a  kind  of 
“left -shift”  in  which  the  previous  S2  is  lost  and  replaced  by  the 
previous  Si ,  while  Si  is  now  zero.  R02  will  cause  an  analogous 
“right-shift,”  with  St  lost.  It  would  be  possible  to  use  a  kernel 
(status-register?)  storage  area  as  the  effective  S0,  so  that  the 
shifted -out  data  would  not  be  lost,  and  in  fact  could  be  shifted - 
in  like  the  carry  bit  in  CPU  rotate-thru-carry  instructions. 

How  useful  might  this  be?  More  generally,  how  far  can  one 
usefully  push  the  analogy  of  an  HLL  to  a  CPU?  FORTH  now 
has  one  Protean  working- register  —  the  variables  stack  —  where 
nearly  everything  is  done.  It  implements  named  dictionary  en¬ 
tries  to  store  16-bit  units,  and  the  !  and  @  commands  to  move 
these  to  and  from  the  stack.  If  my  “unit -length -set”  LXY  is  im¬ 
plemented,  a  storage  capacity  as  large  as  16  bytes  might  be 
needed.  One  might  have  a  parametrized  variable  VXY  in  the  dic¬ 
tionary  with  this  capacity.  Values  of  X  from  0  to  F  would  speci- 


12 

58 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


“The  possibilities  of  even 
parametrization  are  immense  ...” 


fy  one  byte  in  the  sequence.  Y=0  could  be  interpreted  as  a  com¬ 
mand  to  push  that  byte  on  the  stack  (the  S0  location),  and 
other  Y  values  as  a  command  to  store  the  Sy  stack  value  into 
the  Y  storage  location. 

I  do  not  wish  to  stress  any  specific  operation  (needs 
thought!),  only  the  fact  that  this  kind  of  dictionary  variable  is 
beginning  to  look  like  an  auxiliary  working  register  and  perhaps 
belongs  in  the  kernel  together  with  the  status- register.  Readers 
are  aware  that  the  only  parametrized  command  in  existing 
FORTH  is  the  backward -jumping  DO/ LOOP,  defined  for  16-bit 
numerics,  with  one  of  them  an  auto-incrementing  Index.  One 
wonders  if  a  DXY  analog,  whose  Index  could  also  index  some 
parametrized  commands  within  the  loop,  would  be  worth 
having?  Limited  range,  but  greater  power. 

This  is  no  longer  an  alteration  of  detail  but  of  the  very 
architecture  of  FORTH,  bound  to  dismay  FORTHians  much  as 
the  growing-up  of  a  child  can  be  psychically  disturbing  to  its 
parents.  Not  yet  too  much,  since  it’s  hardly  even  an  embryo! 
Without  a  lot  of  expert  design-decisions  and  intense  effort,  it 
will  go  nowhere.  Bill  Ragsdale’s  quote  from  English  expert  C.  A. 
R.  Hoare,  that  the  most  difficult  problem  of  language  design  is 
deciding  what  to  leave  out,  is  not  yet  relevant.  PARFOR  has 
barely  begun  to  collect  all  the  things  that  might  be  put  in.  If 
that  ever  gets  done,  it  will  encounter  the  Noah  Problem:  how 
will  all  these  beasts  interact  inside  the  Ark?  The  real  criterion 
will  be  elegance,  superior  to  sheer  power  and  much  harder  to 
achieve.  Simplicity  is  only  one  of  the  subcriteria  of  elegance. 

The  hypothetical  architecture  of  PARFOR  would  consist 
of  a  kernel  and  many  primitives,  using  the  two  stacks  and  a 
complex  status-register.  Primitives  would  be  mostly  (all?)  para¬ 
metrized,  with  very  complex,  optimized  machine  code,  and 
some  might  function  as  auxiliary  working  registers.  The  low  end 
of  the  status  register  would  consist  of  a  sequence  of  status 
bytes,  some  set  or  reset  automatically  by  certain  primitives  and 
perhaps  by  special  set/reset  command  primitives.  The  latter  kind 
of  intentional  programmer-control  would  be  implemented  for 
other  status  parameters,  such  as  those  defining  the  configuration 
of  the  variables  stack  (e.g.,  the  LXY  set  of  integer- length  and 
exponent-length  of  a  numeric,  where  the  “meaningless”  X=0 
might  allow  an  alphanumeric  of  length  Y)  and  the  numeric  base 
(decimal,  hex  or  whatever).  There  would  also  be  error- checking 
bytes  to  guard  against  imbalance  of  DO’s  and  LOOP’S,  or  im¬ 
balances  of  stack  pulls  and  pushes.  Also,  a  set  of  addresses,  like 
stack  pointers  and  dictionary  entry- points.  Some  unused  space 
should  be  left  to  allow  for  expansion. 

The  options  available  to  the  adventurous  are  the  eternal 
ones:  whether  to  add  improvements  to  an  antiquated  but  time- 
tested  structure  (which  may  be  what  FORTHians  mean  by 
“historical  continuity”),  or  to  try  a  costlier  major  reconstruc¬ 
tion,  or  to  take  the  great  risk  of  creating  something  possibly 
more  grandiose  that  no  one  will  ever  use.  Successive  FOR¬ 
TRAN’S  (I,  II,  etc.)  have  stressed  compatibility  with  the  ances¬ 
tral  form,  making  it  the  most  conservative  of  all  HLL’s  and  com¬ 
pelling  the  creation  of  new  ones.  The  FORTHian  “standard- 
izers”  fear  the  Tower-of-Babel  effect  of  user-extensibility.  If 
they  steer  FORTH  too  firmly,  to  avoid  Scylla,  they  may  be 
heading  for  the  Charybdis  of  an  independent  FORTH-like 
HLL,  probably  far  more  formidable  than  PARFOR!  Who  can 
foresee  the  limits  of  human  creativity?  ■  ■ 


H 


JL  ,T.  Gordon  is  a  long-time  contributor  and 
friend  of  DDJ.  He  acquired  a  KIM-1  in  1976,  and  his  first 
micro  output  was  a  note  in  DDJ  #12.  His  work  since  then 
has  led  many  to  consider  him  expert,  an  honorific  he  dis¬ 
claims,  because  to  his  way  of  thinking  the  trade-off  for 
expertise  is  loss  of  breadth. 

Now  sixty-two  years  of  age  and  a  familiar  denizen  in 
the  academic  towers  of  Harvard  and  Berkeley,  Hal  has 
dabbled  in  several  of  the  sciences  (especially  biology, 
though  he  resists  being  called  a  specialist)  and  in  numer¬ 
ous  non-scientific  fields,  including  history  and  philos¬ 
ophy. 

His  Zen-like  inclinations  tell  him  that  too  much 
knowledge  is  a  dangerous  thing,  and  he  applauds  the 
Delphic  “nothing  too  much.”  On  the  computer  scene, 
he  sees  overemphasis  on  differences  among  CPU’s,  hard¬ 
ware  systems  and  languages  as  an  undermining  of  the 
underlying  unity  which  exists  in  the  world  of  operations 
and  their  algorithms.  Similarities,  even  among  human 
beings,  are  more  vital  than  are  differences.  That  is  one  of 
the  motivations  for  this  current  move  up  to  the  HLL 
level. 

Typifying  Hal’s  outlook  is  a  sentence  from  his  1947 
Harvard  doctoral  thesis  in  neuro- physiology.  “The  mighti¬ 
est  poem,  symphony,  theory,  machine  -  these  are  less  ad¬ 
mirable  than  the  mechanism  that  designed  them:  the 
human  brain."  ■■ 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


13 

59 


Sinclair’s  ZX80 

Review  of  a  Very,  Very  Small  Computer 


A 

X  few  days  ago,  I  received  a  Sin¬ 
clair  ZX80  in  the  mail.  I  took  it  out  of 
the  box  and  got  it  to  work  after  finding  a 
portable  TV  that  would  tolerate  the 
Channel  2  output  of  the  built-in  VHF 
video  modulator.  I  was  pleased  with  the 
ZX80’s  overall  performance,  but  I  was 
disappointed  with  the  quality  of  the 
video  display. 

Before  I  give  a  rundown  of  all  my 
likes  and  dislikes,  let  me  first  review  what 
the  Sinclair  ZX80  is  and  what  it  is  not.  1 
hope  this  will  aid  others  who  may  be 
thinking  about  the  purchase  of  a  personal 
computer  in  the  $200  price  range. 

The  ZX80,  as  you  might  guess,  is 
built  around  a  Z-80  microprocessor.  It 
has  a  built-in  4K  integer  BASIC  and  IK 
of  RAM  for  programs  you  write.  A  very 
tiny  keyboard  is  part  of  the  7  inch  by 
8-1/2  inch  (about  21  mm  by  19  mm) 
plastic  wafer  that  encloses  everything 
except  the  power  supply.  Connections  for 
recorder,  TV  and  power  supply  are  on  the 
backside,  where  the  wafer  thickens  to 
1-1/2  inches  (3-1/2  mm). 

As  I  mentioned  earlier,  the  ZX80 
comes  with  a  VHF  video  modulator  built- 
in  and  preset  to  Channel  2  for  use  in 
North  or  South  America.  (The  ZX80  is 
made  in  England.)  You  also  get  a  nice, 
128  page  operating  manual  that  explains 
how  to  install  the  unit  and  how  to  pro¬ 
gram  in  Sinclair’s  version  of  BASIC. 

The  9 -volt,  external  power  supply 
has  a  long  cord  and  looks  very  much  like 
the  units  you  often  see  with  calculators 
and  transistor  radios.  Of  course,  the  unit  I 
received  was  for  use  on  120  volt,  60  Hz., 
and  it  has  a  “UL”  label  on  it. 

Now  here  are  some  things  you  do  not 
get  for  $200.  You  do  not  get  a  TV  set  nor 
any  kind  of  display  that  would  allow  you 
to  use  the  ZX80  without  a  TV  set. 
Neither  do  you  get  a  cassette  recorder.  I 
tried  it  on  a  well-used  Hitachi  portable 
TV  and  a  worn  out  Sony  cassette.  Both 
seem  to  work  satisfactorily. 

Sinclair  does  not  include  any  cassette 
programs  with  the  unit.  They  say  they 
will  provide  such  in  the  future.  For  now, 
the  user  must  do  his  own  programming. 
There  are  no  built-in  games  or  pictures, 


by  John  B.  Palmer 


Video  display 
Keyboard 
Expandability 
Price 

Recorder  interface 

Graphics 

CPU 

BASIC 

Editor 


only  primitive,  low-resolution  graphics. 

An  expansion  interface  is  provided 
by  a  nearly  standard  edge  connector.  A 
50-pin,  flat  cable  card  edge  connector, 
like  the  ones  that  fit  a  Shugart  8 -inch 
drive,  can  be  made  to  fit  the  Sinclair 
ZX80  after  some  minor  surgery  with  a 
sharp  knife.  Sinclair  says  they  will  sell 
additional  memory  in  the  future.  There  is 
no  provision  for  the  user  to  add  memory 
himself.  There  is  not  even  a  wire  diagram 
for  the  unit. 

Now  let’s  get  to  the  details.  Overall,  I 
like  the  ZX80,  but  it  has  some  real  weak 
spots.  I  will  give  my  harsh  comments  first 
and  save  the  praise  for  last.  Here  is  how  I 
rate  Sinclair’s  ZX80,  using  the  following 
scale: 

Give  it  a  1 ,  Very  poor 
Give  it  a  2,  Weak 
Give  it  a  2,  Weak 
Give  it  a  3,  Good 
Give  it  a  3,  Good 
Give  it  a  3,  Good 
Give  it  a  4,  Very  good 
Give  it  a  4,  Very  good 
Give  it  a  5,  Excellent 

Video  Display:  why  did  I  give  it  such 
a  low  score?  Because  I  really  had  a  hard 
time  getting  a  picture  I  could  read.  Sin¬ 
clair  warns  you  on  page  eleven  of  the 
manual  that  you  have  to  try  tuning  the 
TV  set  and  adjusting  the  contrast  and 
brightness  controls.  When  I  first  got  the 
unit  I  was  in  Silicon  Valley,  where  the 
airways  are  full  of  all  kinds  of  VHF  activi¬ 
ty.  I  just  could  not  keep  out  interference. 

Either  the  ZX80  does  not  have 
enough  output  or  else  it  can  not  reject 
common  mode  signals  that  come  via  the 
power  supply.  I  found  that  the  display 
would  improve  when  I  used  a  long  exten¬ 
sion  cord  for  the  power  supply.  There 
was  no  provision  for  using  an  alternate 
UHF  or  VHF  channel,  so  I  dug  into  the 
little  tin  box  inside  of  the  ZX80. 1  found 
the  air-wound  coil  and  spread  it  open  un¬ 
til  I  could  tune  in  the  display  on  Channel 
3.  That  did  help,  but  not  enough.  We 
have  a  cable  system  here  and  every 
channel  in  the  low  VHF  is  used. 

Even  if  Sinclair  would  provide  a 
VHF/UHF  option,  I  suspect  there  would 
still  be  trouble  with  the  display.  The 
bandwidth  of  the  modulator  seems  to  be 
too  wide  for  the  low-cost,  black-and- 
white  TV  set  that  I  wish  to  use.  If  I  try  to 
tune  to  the  very  edge  of  the  channel  to 
increase  the  high  frequency  detail,  I  get 
a  lot  of  trash  that  appears  to  come  from 
the  ZX80.  I  can  not  see  buying  a  better 


TV  set  just  to  correct  this  problem.  Per¬ 
haps  a  bandwidth  compromise  could 
help.  (Take  a  look  at  Lancaster’s  TV 
Cookbook.) 

Now  about  the  keyboard:  it  is  too 
small.  I  can  not  get  four  fingers  of  my  left 
hand  over  the  A,  S,  D,  and  F  keys.  The 
forty  keys  are  not  keys  at  all.  A  flat  sur¬ 
face  with  the  keypads  marked  in  blue,  it 
is  impossible  to  develop  a  touch  for  the 
keys.  You  have  to  revert  to  typing  with 
one  finger.  (One  good  thing,  the  BASIC 
allows  single-key  entries.)  And  the  inter¬ 
nal  code  is  not  ASCII  (it  is  a  6-bit  alpha¬ 
numeric  code  that  may  be  converted  to 
a  subset  of  ASCII).  This  means  you  can 
not  use  another  keyboard,  or  a  printer, 
without  quite  a  bit  of  work.  Most  of  the 
raw  information  about  the  internal  code 
is  documented  in  the  user’s  manual.  What 
is  needed  now  are  some  good,  detailed 
examples  of  how  to  enjoy  the  ZX80 
without  tearing  it  apart  (which  is  fun!). 

The  ZX80  has  an  attractive  price.  To 
my  knowledge  it  is  the  lowest  cost, 
assembled  and  tested  unit  that  provides 
a  TV  display  and  BASIC  programming. 
Here  in  the  United  States,  there  are  few 
kits  under  two  hundred  dollars  that 
promise  as  much  as  the  Sinclair.  Personal¬ 
ly,  I  strongly  recommend  that  any  novice 
not  try  to  build  such  kits  unless  the  kit- 
building  is  the  objective.  Will  the  price  of 
the  ZX80  come  down?  I  believe  that  Sin¬ 
clair  will  be  able  to  lower  the  price  of  the 
present  ZX80  to  about  $150  and  then 
introduce  a  better  model  for  about  $250 
sometime  in  1981. 

The  cassette  interface  seems  to  work 
quite  well.  The  operating  manual  says 
that  your  recorder  must  provide  4  volts, 
peak  to  peak,  to  fully  drive  the  input 
during  playback.  Recording  is  not  much 
of  a  problem,  just  read  the  instructions. 
During  playback  of  your  program,  you 
must  adjust  the  volume  control  until  you 
find  the  best  setting.  This  may  take  a  few 
tries.  Once  you  find  the  right  setting, 
leave  it. 

My  old  Sony  worked  alright  on  the 
second  try.  I  believe  that  is  very  remark¬ 
able.  It  took  me  a  week  to  get  my  APPLE 
cassette  going,  and  I  have  heard  of  some 
TRS-80  owners  who  are  still  trying  to 
adjust  the  playback  volume!  With  the 
ZX80  it  is  quite  simple.  Turn  it  up  as 
loud  as  it  will  go  and  then  back  off  just 
a  bit.  The  video  display  gives  some  idea  of 
what  is  going  on.  If  the  display  remains 
blank  after  playing  the  tape  beyond  the 
area  where  you  recorded  data,  just  rewind 


14 

60 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


and  try  again  with  more  volume. 

If  you  get  a  ZX80,  do  not  expect  it 
to  work  with  tapes  made  by  a  friend  who 
has  a  different  personal  computer.  In 
fact,  you  may  find  that  your  ZX80  can 
not  read  tapes  made  by  another  ZX80. 
This  is  true  of  most  personal  computers 
and  is  not  a  problem  unique  to  the  ZX80. 
Quite  a  while  ago,  many  users  got  to¬ 
gether  in  Kansas  City  and  came  up  with  a 
reliable  tape  system.  But  the  most  popu¬ 
lar  brands  of  small  computers  ignore  the 
standard.  This  makes  me  mad!  Why  can  I 
not  trade  tapes  with  my  friends  just  be¬ 
cause  they  have  brands  X  and  Y,  and  I 
have  Z? 

The  graphics  are  good.  In  fact,  they 
are  better  than  some  more  costly  systems. 
Any  letter  or  symbol  on  the  keyboard 
can  be  displayed  in  reverse  video  by 
means  of  the  CHR$  function.  And  there 
are  twenty  additional  shapes  that  are  to 
be  used  in  making  bar  graphs,  squares  or 
highlights.  The  low -resolution  graphics 
are  satisfactory.  Too  bad  the  letters  were 
not  better. 

The  Z-80  CPU  is  possibly  the  most 
popular  among  hobbyists.  Sinclair’s  BAS¬ 
IC  allows  you  to  write  machine  code 
using  POKE.  The  USR  function  allows 
BASIC  to  call  the  machine  code.  A  para¬ 
meter  is  sent  and  returned  in  the  HL 
register  pair.  The  PEEK  function  allows 
access  to  special  system  variables  or  any 
part  of  memory.  The  IK  RAM  is  from 
16384  thru  17407.  All  notation  must  be 
in  decimal  in  the  BASIC  text.  (The  ZX80 
could  be  used  to  learn  about  Z-80  code, 
but  it  does  not  have  a  system  monitor 
other  than  the  BASIC  interpreter.  You 
could  write  your  own  and  save  it  on  cas¬ 
sette.) 

The  CPU  does  the  whole  show.  There 
is  no  video  display  chip.  While  the  CPU 
is  waiting  for  the  user  to  enter  something 
on  the  keyboard,  it  is  updating  the  tele¬ 
vision  screen  60  times  a  second  (or  50 
times  a  second  in  Europe).  This  is  the 
secret  of  how  Sinclair  can  offer  so  much 
in  a  small  package.  Perhaps  you  may 
sense  that  I  am  partial  to  the  Z-80.  I 
think  that  Sinclair  has  done  a  good  job  of 
using  the  advantages  of  the  Z-80  CPU. 

Sinclair  BASIC  is  very  good.  It  re¬ 
minds  me  of  Tiny  BASIC,  but  has  many 
more  features  that  make  the  ZX80  an 
enjoyable  personal  computer.  All  of  the 
standard  GOTO,  GOSUB,  IF  THEN,  FOR 
NEXT,  PRINT,  and  other  BASIC  com¬ 
mands  are  present.  To  save  space  in  the 
IK  RAM  area  and  to  reduce  the  program¬ 


mer’s  work,  all  principle  BASIC  keywords 
are  entered  with  a  single  keystroke.  Many 
of  the  single-stroke  keywords  appear  on 
the  same  keypads  as  do  the  letters  and 
numerals.  How  does  BASIC  know  if  you 
want  to  type  in  a  keyword  or  something 
else?  It  is  automatic.  Some  other  BASIC 
words  are  known  as  “tokens”  rather 
than“keywords.”  These  are  entered  with 
a  shift.  There  are  eight  lesser-used  func¬ 
tions  that  must  be  given  letter  by  letter. 

This  BASIC  is  not  for  any  operation 
that  requires  decimal-point  arithmetic. 
Sinclair’s  BASIC  will  seldom  give  the 
right  answer  to  a  division  problem.  There 
is  a  good  explanation  for  this  in  the 
operating  manual,  and  a  program  listing 
that  shows  how  to  correct  the  problem.  It 
would  have  been  nice  if  the  remainder 
from  division  had  been  stored  into  a  spe¬ 
cial  variable. 

Strings  may  be  tested  and  altered 
with  some  novel  functions.  On  pages  76 
and  77  is  a  table  showing  all  the  codes  for 
ZX80-BASIC.  Page  77  explains  the  use  of 
CHR$(  ),  CODE$(  )  and  TL$(  ).  With  this 
information,  you  can  have  many  enjoy¬ 
able  hours  making  up  nonsensical  pro¬ 
grams  that  display  cryptic  messages.  This 
is  far  more  important  than  decimal  point 
arithmetic.  After  all,  the  real  reasons  any¬ 
one  would  buy  a  low-cost  personal  com¬ 
puter  should  not  include  anything  very 
serious.  I  work  all  day  doing  serious 
things.  With  my  new  pastime,  I  can  hide 
away  and  write  programs  that  serve  the 
noble  task  of  bringing  me  pleasure  and 
relaxation. 

What  makes  this  BASIC  outstanding 
is  the  operating  manual.  Not  too  big.  Not 
too  little.  Just  right  to  go  with  a  comput¬ 
er  you  can  carry  in  your  lunch  pail  with 
room  left  for  a  sandwich  and  a  banana! 
There  is  enough  information  that  a  novice 
could  learn  to  program  using  the  operat¬ 
ing  manual  and  his  Sinclair.  For  the  more 
advanced,  there  is  enough  detail  about 
how  the  system  works  to  allow  you  to  try 
some  fancy  tricks.  There  is  a  program 
example  of  how  to  use  the  frame  refresh 
to  measure  reaction  time  in  milliseconds! 
(No,  they  do  not  give  ROM  source 
code  —  sigh.) 

Now  the  best  part:  the  text  editor.  I 
did  not  expect  a  low-cost  personal  com¬ 
puter,  with  the  features  already  de¬ 
scribed,  to  have  a  text  editor.  Without 
bothering  to  read  the  operating  manual 
all  the  way  through  (which  is  perfectly  all 
right,  if  you  at  least  browse  through  it),  I 
noticed  four  little  arrows  at  the  top  of 


the  keyboard.  I  tried  one  and  found,  to 
my  surprise,  that  what  happened  was  per¬ 
fectly  natural.  The  back  arrow  allows  me 
to  go  back  and  insert  more  text.  The  for¬ 
ward  arrow  allows  me  to  move  forward  in 
the  text.  The  rubout  will  rubout  the  char¬ 
acter  to  the  right  of  the  cursor. 

Compare  the  above  with  some  of  the 
very  popular  word  processor  hardware 
and  software.  I  used  a  very  expensive, 
professional  Data  Entry  Terminal  to  write 
this  review.  Over  half  of  the  special  keys 
do  not  work  in  a  logical  manner.  My  big 
terminal  also  has  four  cursor  controls. 
Only  one  works  almost  right.  You  have  to 
learn  a  bunch  of  control  codes  just  to  do 
something  logical.  At  work,  I  spend 
several  hours  working  on  another  system 
that  is  alien  to  the  one  I  use  at  home. 
And  I  have  to  spend  some  time  each  day 
explaining  the  text  editors  to  newer  em¬ 
ployees. 

A  simple  and  natural  cursor  move¬ 
ment  text  editor  in  the  Sinclair  was  far 
beyond  expectations.  Now,  I  do  not 
mean  to  say  that  is  is  a  full  text  editor.  I 
mean  that  it  is  beyond  what  is  often  seen 
in  personal  computers  up  to  the  one 
thousand  dollar  price  range. 

The  line  currently  being  written  or 
edited  is  at  the  bottom  of  the  display. 
When  you  get  to  the  end  of  the  line,  you 
just  hit  the  key  called  “newline.”  It  is  not 
called  “return.”  It  is  not  called  “enter.” 
It  is  called  “newline,”  Hit  it  and  your 
line  finds  its  place  in  the  BASIC  list,  in 
the  upper  part  of  the  video  display.  The 
cursor  goes  to  the  left  of  the  now  clear 
bottom  line  and  displays  an  inverted  “K” 
to  let  you  know  that  the  BASIC  parser 
now  expects  a  single-stroke  keyword.  Hit 
a  single -letter  keyword,  it  appears  in¬ 
stantly,  and  the  cursor  changes  to  an  in¬ 
verted  “L”  to  let  you  know  that  the 
parser  now  expects  an  argument  to  the 
keyword.  If  you  enter  an  invalid  argu¬ 
ment,  the  cursor  changes  to  an  inverted 
“S”  to  tell  you  that  your  syntax  is  not 
correct  at  this  point.  Move  the  cursor 
back,  and  it  becomes  an  inverted  “L”  as 
soon  as  you  pass  to  the  right  of  the 
character  that  caused  the  syntax  error.  In 
some  cases,  the  “S”  will  appear  until  you 
have  fully  formed  an  expression.  There  is 
no  way  you  will  forget  the  final,  left 
parenthesis! 

What  about  lines  you  have  already 
entered?  Any  line  you  have  already  en¬ 
tered  does  not  have  any  syntax  errors. 
The  editor  will  not  allow  you  to  hit  the 
(continued  on  page  43) 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


15 

61 


POKE  and  PEEK 
to  Your  Hearts  Content 


An  enhancement  to  Microsoft 
BASIC  Version  3.2  (8K  version)  to 
enable  PEEK  and  POKE  to  any 
location  in  memory. 


F 

M  or  four  years  now  I  have  been 
running  MITS  ALTAIR  BASIC  Version 
3.2  (Microsoft  8K  version)  with  no  major 
complaints.  However,  I  recently  expand¬ 
ed  my  ALTAIR  8800’s  memory  beyond 
the  32K  point  which  created  a  problem 
with  the  PEEK  and  POKE  functions. 

In  this  early  version  of  Microsoft 
BASIC,  which  many  of  us  are  still  using, 
these  two  functions  work  only  with 
addresses  of  less  than  32768  (32K).  Call¬ 
ing  these  functions  with  arguments  great¬ 
er  than  32767  or  with  negative  arguments 
(the  convention  for  larger  versions  of 
BASIC)  results  in  a  FC  (Function  Call) 
error.  I  found  myself  unable  to  relocate 
my  Polymorphics  VTI  screen  memory 
address  at  the  new  Top  of  Memory  so  as 
to  give  BASIC  access  to  the  expanded 
memory  and  still  be  able  to  update 
points  on  the  screen  directly  from  BASIC 
using  PEEK  and  POKE. 

Two  long  days  of  running  BASIC 
under  a  simulator  allowed  me  to  locate 
and  analyze  the  subroutines  which  con¬ 
trol  the  behavior  of  PEEK  and  POKE. 
Another  day  with  the  simulator  and  I  had 
the  patches  described  here  developed, 
tested  and  installed  in  BASIC  allowing 
PEEK  and  POKE  to  all  memory. 

To  implement  this  enhancement,  an 
eleven- byte  subroutine  must  be  added 
to  BASIC  and  two  Calls  must  be  altered 
within  it.  I  added  the  required  subroutine 
immediately  following  the  trig  functions. 
Using  this  location  will  necessitate  the  al¬ 
teration  of  BASIC’s  initialization  routine 
to  set  the  start  of  program  memory  after 
the  subroutine  and  to  eliminate  the  start¬ 
up  option  to  delete  the  trig  functions. 
An  alternative  would  be  to  locate  the  sub¬ 
routine  elsewhere,  near  the  Top  of  Mem¬ 
ory. 


by  T.  J.  Van  Iderstine 


T.  J.  Van  Iderstine,  Box  5407,  Kreole 
Station,  Moss  Point,  MS  39563. 


Table  I  presents  the  new  subroutine 
and  the  patched  subroutine  Calls  as  well 
as  the  reentry  point  and  the  bypassed 
subroutines.  The  addresses  given  are  from 
my  Paper  Tape  version  of  BASIC.  Other 
versions  may  have  these  subroutines  at 
different  addresses,  but  my  experience 
has  shown  that  the  variation  will  likely  be 
less  than  IK.  The  full  subroutines  are 
given  to  allow  you  to  find  them  easily  in 
your  version. 

With  these  changes  installed,  you  will 
be  able  to  POKE  or  PEEK  anywhere 
within  the  direct  addressing  area,  using 
either  positive  or  negative  addresses  up  to 


65535.  That  is  to  say,  you  may  use  either 
convention  to  address  any  location,  -5 
will  point  to  the  same  location  as  65531 
and  +5  will  point  to  the  same  location  as 
-65531. 

So  patch  it  in  and  POKE  and  PEEK 
to  your  heart’s  content! 


TABLE  I 

0FF7 

PEEK 

CALL 

SR01+3  ;Changed  from  L0638 

OF  FA 

LDAX 

D 

OFFB 

JMP 

L0CB9 

OFFE 

POKE 

CALL 

SR01  .Changed  from  L0635 

1001 

PUSH 

D 

1002 

RST 

1 

1003 

DB 

2CH  ,’ 

1004 

CALL 

L0FCD 

1007 

POP 

D 

1008 

1009 

STAX 

RET 

D 

0634 

L0634 

RST 

2 

0635 

L0635 

CALL 

L0960  ;  Bypassed  in  POKE 

0638 

L0638 

RST 

5  ;Bypassed  in  PEEK  &  POKE 

0639 

JM 

L064F  ; 

063C 

L063C 

LDA 

L0242  ; 

063F 

CPI 

90H  ; 

0641 

JC 

LI 301  ; Reentry  from  new  subroutine 

0644 

LXI 

B.9080H 

0647 

LXI 

D.0000H 

064A 

CALL 

L12D6 

064D 

064E 

MOV 

RZ 

D,C 

064F 

L064F 

MVI 

E,08H 

0651 

JMP 

L02C6 

16C8 

SR01 

CALL 

L0960  ;New  Subroutine  to  enable 

16CB 

LDA 

L0242  ;POKE  and  PEEK  to  all 

16CE 

CPI 

9 1 H  ;  directly  addressable  memory. 

16D0 

JMP 

L9641 

END 

16 

62 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


PAN 

One  Activity  of  the  PCNET  Project 


T 

_A_he  Personal  Computer  NETwork 
had  its  inception  at  the  First  West  Coast 
Computer  Faire.  It  marked  the  beginning 
of  today's  international  movement 
toward  computer  networks.  PCNET  is  the 
frontrunner  in  a  field  still  largely  domi¬ 
nated  by  Computer  Bulletin  Boards  and 
other  relatively  simple  systems. 

The  PCNET  Project  is  conducting 
three  principal  activities.  The  most  sig¬ 
nificant  is  the  Personal  Computer  NET¬ 
work  (PCNET)  “protocol,”  a  method  by 
which  any  personal  computer  can  tele¬ 
phone  a  text  message  to  any  other  per¬ 
sonal  computer  automatically,  detecting 
and  correcting  any  errors  that  might  oc¬ 
cur  because  of  the  noisiness  of  the  tele¬ 
phone  system.  We  are  designing  and  pro¬ 
gramming  one  or  more  “model”  imple¬ 
mentations,  and  we  will  conduct  a  large 
workshop  in  which  users  of  various 
personal  computers  will  recode  a  model 
version  into  a  useful  language  for  their 
own  particular  hardware.  The  model  and 
all  versions  from  the  workshop  will  be 
distributed  without  copyright,  so  that 
anyone  will  be  able  to  use  the  PCNET 
protocol  directly  or  as  the  basis  for  other 
programs  which  need  reliable  communica¬ 
tion.  This  activity  is  now  being  coordi¬ 
nated  by  David  Harris. 

The  second  activity,  coordinated  by 
Pat  Cleland,  is  the  “Electric  Phone 
Book,”  a  list  of  Bulletin  Board  Systems 
believed  to  be  in  operation.  There  sys¬ 
tems' are  computers  programmed  to  re¬ 
ceive  phone  calls  and  manage  the  reading 
and  leaving  of  text  messages  for  other 
people.  Like  a  public  bulletin  board,  any¬ 
one  can  read  most  of  the  messages 
posted,  and  anyone  can  post  them.  To 
encourage  use  by  as  many  people  as  pos¬ 
sible,  the  PCNET  Committee  is  arranging 
to  have  these  systems’  phone  numbers 
published  in  Recreational  Computing.  In¬ 
cidentally,  the  PCNET  Committee  itself 
operates  a  Bulletin  Board  System,  on  an 
Apple  computer. 


by  Dave  Caulkins 
and  David  C.  Harris 


The  third  activity  of  the  PCNET 
Project  is  the  PAN  electronic  mail  system, 
which  we  started  distributing  in  early 
1980.  PAN  lacks  the  power  of  the  full 
PCNET  protocol  in  terms  of  error  control 
and  data  transparency,  but  is  quite  suit¬ 
able  for  short,  natural  language  messages. 
A  more  detailed  description  of  PAN  can 
be  found  in  the  June/July  ’80  issue  of 
DDJ. 

We  and  the  TNW  Corporation  (our 
associate  in  developing  PAN)  have 
decided  that  licenses  for  the  PET  version 
of  PAN  will  no  longer  be  necessary.  We 
plan  to  put  a  complete  listing  of  PET 
PAN  into  an  upcoming  issue  of  DDJ. 

We’re  making  some  changes  in  PAN 
for  a  number  of  reasons  as  described  be¬ 
low.  If  you  have  a  PAN  system  and  wish 
to  be  able  to  conform  to  the  PAN  stan¬ 
dard  for  communication  with  present  and 
future  versions  of  PAN,  please  make  the 
indicated  changes. 

1)  To  make  PAN  conform  to  the  PCNET 
standard  serial  character  format  (1 
start  bit,  8  data  bits,  1  stop  bit  and  no 
parity): 

change  CHR$(145)  to  CHR$(154) 
in  line  1030 

2)  If  you  have  purchased  a  TNW488 
modem  recently,  it  may  be  set  up  for 
device  numbers  16  and  17.  If  this  is 
the  case,  change  line  1028  to  read  as 
follows: 

1028  OPEN R,1 6,0 :OPENS,l  7,0: 

OPENT,16,l  :OPENU,17,l 

3)  Some  computers  for  which  PAN  is  be¬ 
ing  implemented  dedicate  the  <-  char¬ 
acter  to  special  purposes.  For  this  rea¬ 
son  the  PAN  end-of-message  character 
is  being  changed  from  «-  to  t.  Make 
changes  as  follows: 

In  line  300 1  change  «-  to  t . 

Change  line  31 16  to  read: 

3116  IFA$=“t”THENXl=-l 
Change  95  to  94  in  line  3247  (1 
place),  in  line  3248  (2  places),  and 
in  line  3250  ( 1  place). 

4)  Some  computers  for  which  PAN  is  be¬ 
ing  implemented  require  longer  delays 
for  some  of  their  operations.  To  ac¬ 
commodate  these  machines  some  PAN 
timeouts  have  been  lengthened. 
Change  lines  7740  and  8000  as  fol¬ 
lows: 

7704  1FTI- V<  1 80000T07702 
8000  V=TI+ 1800:1=1 


5)  PAN  version  numbers  are  of  the  form 
ANN  where  the  A  is  a  single  alphabetic 
character;  present  assignments  are  P 
for  PET,  A  for  Apple  and  X  for  experi¬ 
mental  version.  Change  line  9467  to 
the  new  version  number  as  follows: 

9467  L$=“@@@P10” 

6)  The  previous  version  of  PAN  (P09)  did 
not  handle  the  cursor  properly  during 
message  entry  on  PETs  with  new 
ROMs.  Change  line  13000  to  read  as 
follows: 

13000  A=224  +  PEEK(50003)*-28 
Add  new  line  13001: 

13001  CP=PEEK(A)+PEEK(A+1)* 
256+PEEK(A+2) 

The  present  version  of  PAN  has  one 
outstanding  defect:  the  receiving  PAN 
does  not  acknowledge  receipt  of  a  com¬ 
plete  message.  We  intend  to  change  the 
PAN  protocol  to  provide  the  sending 
PAN  with  a  positive  acknowledgement 
from  the  receiving  PAN  that  the  entire 
message  has  been  accepted.  This  change 
will  be  documented  in  an  upcoming  issue 
of  DDJ. 

Robert  Maas  pointed  out  that  the 
PAN  protocol  that  appeared  in  the  June/ 
July  issue  of  DDJ  was  not  as  detailed  as  it 
should  have  been.  The  following  revised 
version  should  be  better.  Note  that  a  PAN 
message  can  be  sent  manually  with  only  a 
terminal  and  modem,  because  the  proto¬ 
col  is  so  simple. 

A 

_^.t  the  hardware  level,  PAN  con¬ 
forms  to  the  Bell  103A  standard  operat¬ 
ing  at  300  baud.  The  serial  character  for¬ 
mat  is  1  start  bit,  8  data  bits  and  1  stop 
bit.  PAN  does  not  use  parity;  it  is  desir¬ 
able  but  not  required  for  the  transmit¬ 
ting  PAN  to  set  the  parity  bit  to  the  mark 
state.  PAN  is  designed  for  use  with  upper 
case  characters.  Some  PAN  versions  will 
accept  lower  case  characters,  but  some 
will  not;  unless  the  capabilities  of  the  tar¬ 
get  PAN  are  known,  it  is  safer  to  use 
upper  case  characters  only.  The  UP 
ARROW  character  (t)  is  reserved  for  use 
as  the  end-of-message  character  and 
should  not  be  used  as  part  of  the  message 
text. 

(continued  on  page  37) 


Dr.  Dobb’s  Journal,  Number  52,  February  1 981 


17 

63 


DECONCAT 

A  De~Bugging  Tool  for  Concatenated  Programs 


n  order  to  save  precious  bytes  and 
running  time,  program  statements  in  sev¬ 
eral  BASIC’s  can  be  concatenated  onto 
one  line.  In  North  Star  BASIC,  state¬ 
ments  on  the  same  line  are  separated  by  a 
backslash  (\). 

For  example: 

10  FILL  10466, 3\IF  Z=  3  THEN  20 
\END 

There  are  programs  on  the  market 
such  as  DOC  (from  Mini  Business  Sys¬ 
tems)  which  concatenate  BASIC  pro¬ 
grams.  Figure  1  is  the  listing  of  a  sample 


by  Greg  Smith 


GREG  SMITH,  Commonwealth  Depart¬ 
ment  of  Transport,  Ground  Facilities 
Division,  P.O.  Box  367,  Canberra  2601, 
Australia. 


program  after  it  has  been  concatenated 
by  DOC. 

One  disadvantage  of  having  concate¬ 
nated  programs  is  trying  to  debug  or 
make  changes.  This  is  the  reason  that 
DECONCAT  was  written.  DECONCAT  is 
a  program  which  will  split  concatenated 
program  lines  into  their  component  state¬ 
ments,  making  each  statement  a  separate 
line. 

There  are  three  simple  steps  to  fol¬ 
low  when  using  DECONCAT: 

1 )  Renumber  the  original  program. 

2)  Create  a  file  into  which  the  new  (de- 
concatenated)  program  can  be  written. 

3)  Run  the  program,  supplying  the  name 
of  the  program  to  be  deconcatenated 
and  the  name  of  the  new  program  file. 

Figure  2  is  the  listing  of  the  sample 
program  after  it  has  been  run  through 
DECONCAT.  DECONCAT  also  checks  to 
ensure  there  is  a  blank  between  the  line 
number  and  the  first  character  in  the 
statement,  which  makes  the  program 
much  easier  to  read  (Figure  3). 


How  it  works. 

A  North  Star  BASIC  program  line  is 
written  onto  file  in  the  form : 

A,B,C,STATEMENT,<CR> 

A  is  the  byte  containing  the  number 
of  bytes  in  the  line,  while  B  and  C  are  the 
bytes  which  contain  the  line  number  in 
the  form: 

LINE  NUMBER=Cx256+B 
When  a  line  is  concatenated,  it  is  re¬ 
presented  by: 

A,B,C,STATEMENT\STATEMENT\ 

.  . .  etc _ \<CR> 

DECONCAT  operates  by  reading  a 
program  line  and  searching  for  a  back¬ 
slash.  If  no  backslash  is  found  then 
the  line  remains  unchanged.  When  a  back¬ 
slash  is  found  the  line  is  split.  The  first 
part  of  the  line  retains  the  original  line 
number  (thus  preserving  GOTO’s,  etc.) 
and  the  remainder  of  the  line  is  assigned 
a  line  number  one  greater  than  the  origi¬ 
nal  line  (hence  the  need  to  renumber  the 
original  program  before  attempting  to  de- 
concatenate  it).  ■  ■ 


Listing 


LISTING 

LOAD  DECONCAT 

READY 

LIST  10,490 


10  REM . DECONCAT . 

20  REM . 7/10/79 

30  REM . (C)  G.  L.  SMITH 

40  REM .  4  WILLCOTT  STREET 

50  REM .  GEEBUNG, 

60  REM .  BRISBANE, 

70  REM .  QUEENSLAND,  4034 

80  REM .  AUSTRALIA 


90  DIMA9  (300) 

100  INPUT“SOURCE  FILE  NAME  ?  ”,W$ 

110  INPUT“FILE  TYPE  ?  ”,W 

120  INPUT“TARGET  FILE  NAME  ?",W1$ 

130  INPUT“FILE  TYPE  ?  ”,W1 
140  ! 

150  !“OLD  LINE  NEWLINE” 

160  OPEN#0%W,W$ 

170  OPEN#l%Wl,Wl$ 

180  REM.  .  READ  LINE  LENGTH  (A)  AND  LINE  NO.  BYTES  (B,C) 

190  READ#0,&A,&B  ,&C 

200  IF  A=1  THEN  300 

210  REM.  .  .CALCULATE  LINE  NO.  (E) 

220  E=C*256+B 
230  !E  , 


240  REM.  .  READ  LINE 
250  FOR  1=1  TO  A-3 
260  READ#0,&A9(I) 

270  NEXTI 
280  GOTO  340 

290  REM  .  END  OF  PROGRAM 

300  WRITE#  1,&A 

310  CLOSE#  1 

320  CLOSE#0 

330  END 

340  M=0 

350  D=1 

360  Q=1 

370  REM.  .  .CHECK  FOR  LINE  NUMBERS  IN  STATEMENTS  (154) 

380  FOR  L=D  TO  A-3 

390  IF  A9(L)=154  THEN  L=L+2  ELSE  420 

400  NEXTL 

410  REM  .  CHECK  FOR  INVERTED  COMMAS  (34) 

420  IF  A9(L)<>34  THEN  450 
430  IF  S=1  THEN  S=0  ELSE  S=1 

440  REM.  .  CHECK  FOR  END  OF  INVERTED  COMMAS 

450  IF  S=1  THEN  480 

460  REM  .  .CHECK  FOR  BACKSLASH  (92) 

470  IF  A9(L)=92  THEN  GOSUB  550 
480  NEXTL 
490  L=L-1 
READY 


18 

64 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


LIST  500, 

FIGURE  2 

500  IF  M=1  THEN  A=L-Q+4 

510  Z=1 

520  GOSUB  600 

10  REM  EXAMPLE  PROGRAM 

530  Z=0 

1 1  [“DECONCAT  EXAMPLE  PROGRAM” 

540  GOTO  190 

50  !“DECONCAT  WILL  NOT  MISTAKE  A  BACKSLASH  (\),  IN  A  PRINT” 

550  M=1 

90  ! “STATEMENT  SUCH  AS  THIS,  FOR  A  NEW  STATEMENT  \\\\\\\\” 

560  A9(L)=13 

130  REM  INPUT  PHASE 

570  REM.  .  CALCULATE  STATEMENT  LENGTH  (A) 

131  OPEN#  1  “DATA” 

580  A=L-Q+4 

132  READ#  1 , J,  K 

590  REM.  .  .INSERT  SPACE  (32)  AFTER  LINE  NO. 

170  FOR  J=1  TOK 

600  IF  A9(Q)=32  THEN  630  ELSE  A=A+1 

171  IF  J=23  THEN  (“FOUND”  ELSE  250 

610  WRITE#  1,&A,&B  ,AC  .&32.NOENDMARK 

210  IF  J=45  (“LOST  IT” 

620  GOTO  640 

211  NEXT J 

630  WRITE# l,&A,AB,4C,NOENDMARK 

250  REM  END  OF  SEARCH 

640  FOR  F=Q  TO  L 

25 1  IF  J<>23  THEN  (“THE  END”  ELSE  290 

650  WRITE#  l,4A9(F),NOENDMARK 

252  GOTO  330 

660  NEXTF 

290  !“J=  ”,J 

670  !TAB(10),E 

330  END 

680  IF  Z=1  THEN  RETURN 

370  REM . 

690  REM.  .  .CALCULATE  NEW  LINE  NO.  BYTES  (B,C) 

410  REM  DECONCAT  WILL  HANDLE  ANY  NUMBER  OF  STATEMENTS 

700  E=E+1 

IN  THE  ONE  LINE  e.g. 

710  C=INT(E/256) 

450  REM 

720  B=INT((E/256-C)*256+.  1 ) 

451  REM 

730  Q=L+1 

452  REM 

740  RETURN 

453  REM 

READY 

454  REM 

455  REM 

456  REM 

457  REM 

end 

458  REM 

459  REM 

460  REM 

461  REM 

462  REM 

463  REM 

464  REM 

FIGURE  1 

465  REM 

466  REM 

10  REM  EXAMPLE  PROGRAM\!“DECONCAT  EXAMPLE  PROGRAM” 

467  REM 

50  !“DECONCAT  WILL  NOT  MISTAKE  A  BACKSLASH  (\),  IN  A  PRINT” 

468  REM 

90  ("STATEMENT  SUCH  AS  THIS,  FOR  A  NEW  STATEMENT  \\\\\\\\” 

469  REM 

130  REM  INPUT  PHASE\OPEN#  1,“DATA”\READ#  1,  J,K 

470  REM 

170  FOR  J=1  TO  K\IF  J=23  THEN  (“FOUND”  ELSE  250 

471  REM 

210  IF  J=45  !“LOST  IT”  \NEXTJ 

472  REM 

250  REM  END  OF  SEARCH\IF  J<>23  THEN  !“THE  END”  ELSE  290\ 

473  REM 

GOTO  330 

474  REM 

290  !“J=  ”,J 

475  REM 

330  END 

476  REM 

370  REM . 

477  REM 

410  REM  DECONCAT  WILL  HANDLE  ANY  NUMBER  OF  STATEMENTS 

478  REM 

IN  THE  ONE  LINE  e  g. 

479  REM 

450  REM\REM\REM\REM\REM\REM\REM\REM\REM\REM\REM\ 

480  REM 

REM\REM\REM\REM\REM\REM\REM\REM\REM\REM\REM\ 

481  REM 

REM\REM\REM\REM\REM\REM\REM\REM\REM\REM 

490  REM . 

490  REM . 

530  REM  DECONCAT  IS  NOT  CONFUSED  BY  NUMBERS  IN 

530  REM  DECONCAT  IS  NOT  CONFUSED  BY  NUMBERS  IN 

STATEMENTS 

STATEMENTS 

570  REM  HAVING  THE  SAVE  VALUE  AS  THE  ASCII  CHARACTER 

570  REM  HAVING  THE  SAVE  VALUE  AS  THE  ASCII  CHARACTER 

VALUES 

VALUES 

610  REM  FOR  WHICH  IT  SEARCHES  e  g. 

610  REM  FOR  WHICH  IT  SEARCHES  e  g. 

650  (34/92*154 

650  !34/92*154\GOTO  32 

651  GOTO  32 

690  ON  D  GOTO  92,154,34,92,32 

690  ON  D  GOTO  92,154,34,92,32 

Dr.  Dobb’s  Journal,  Number  52,  February  1981  19 

65 


Small~C 

An  Implementor's  Notes  and  a  Bug  Corrected 

Abstract  piler  in  its  entirety2 ,  to  be  followed  a  would  be  better  than  nothing,  for  I  could 

The  author  describes  his  experience  short  time  later  by  the  run  time  system  then  feed  small  C  (written  in  small  C) 

of  implementing  the  small  C  compiler2  in  f°r  his  program3 .  I  had  read  The  C  Pro -  into  my  cross  compiler  and  get  an  8080- 

FORTRAN  as  a  cross-compiler  running  gramming  Language* ,  which  is  the  defini-  executable  version.  I  would  still  be  faced 
on  a  large  minicomputer,  and  describes  a  five  document  for  the  full  language,  and  with  the  problem  of  typing  the  assembler 
bug  detected  during  the  implementation,  also  for  tiny-cs .  A  comparison  between  version  of  small  C  into  my  home  comput- 
The  bug  permits  an  incorrect  interaction  the  facilities  proposed  for  my  sub-  er,  but  at  least  I  would  not  have  the 
between  a  function  argument  list  and  the  FORTRAN  compiler  and  those  imple-  daunting  prospect  of  hand  coding  the 
type  declarations  for  those  arguments,  re-  mented  by  Mr.  Cain  showed  that,  if  any-  compiler.  In  the  meantime,  I  could  cross¬ 
suiting  in  incorrect  code  being  generated  thing,  his  compiler  was  more  extensive  compile  short  small  C  programs  and  take 

for  references  to  function  arguments,  than  mine  would  have  been.  This,  to-  them  home  to  test  them. 

Corrective  code  is  presented.  gether  with  the  fact  that  his  program  was 

a  finished  product  while  mine  was  still  at  Implementation  Difficulties 
Introduction  the  design  stage,  led  to  only  one  conclu-  The  actual  building  of  the  cross- 

The  May  1980  issue  of  Dr.  Dobb’s  sion.  terminate  work  on  the  FORTRAN  compiler  went  very  smoothly,  with  few 
Journal  could  have  been  written  just  for  project  and  set  about  implementing  the  problems.  These  mainly  concerned  C  and 
me.  I  have  built  a  home-brewed,  Z-80  small  C  compiler.  FORTRAN  incompatibilities.  In  C,  the 

based  computer  system,  and  am  now  first  element  of  an  array  is  number  [0], 

looking  for  reasonably  priced  software  to  while  in  FORTRAN  it  is  [  1  ] .  This  was 

run  on  it.  After  about  a  year  of  hand  as-  Compiling  the  Compiler  solved  by  simply  adding  1  to  each  array 

sembling  programs,  and  then  loading  The  first  step  to  implement  the  small  reference  where  it  occurred, 
hexadecimal  numbers  directly  into  C  compiler  would  be  to  create  a  machine-  Also,  as  FORTRAN  does  not  have 

memory  via  a  VDU,  I  came  across  a  local  readable  copy  of  the  source  code.  That  is  a  pointer  type,  all  pointers  had  to  be 
supplier  of  a  Z-80  assembler.  This  greatly  easily  solved,  and  would  merely  require  a  changed  to  either  array  indices  or  array 

eased  the  programming  burden,  but  as  I  lot  of  typing  and  careful  checking  on  my  elements,  depending  on  the  context.  De- 

have  tried  Pascal  and  currently  use  FOR-  part.  But  that  would  have  left  me  with  a  ciding  which,  and  then  which  array  to 

TRAN  professionally,  I  knew  that  some-  small  C  compiler  written  in  a  language  for  subscript,  was  sometimes  a  little  difficult, 

thing  was  lacking,  namely  a  high  level  lan-  which  I  did  not  yet  have  a  compiler:  Although  FORTRAN  is  strong  on  its 

guage  on  my  micro.  namely  small  C!  I  do  not  have  access  to  a  scientific  variable  types  (DOUBLE  PRE- 

Pascal  seems  widely  available,  and  a  C  compiler,  so  I  started  to  look  for  other  CISION  and  COMPLEX),  it  is  lacking  in 
compiler  for  a  subset  of  this  has  been  ways  of  compiling  the  compiler.  the  area  of  a  character  variable  type. 

published1 ,  but  my  earlier  experiences  There  are  two  solutions  to  this  class  Thus,  all  character  types  had  to  be  con- 
with  this  language  had  convinced  me  that  of  problem.  One  is  to  hand-code  the  pro-  verted  to  integers  and  this  unfortunately 
while  it  achieves  its  design  aims,  as  a  prac-  gram  into  assembly  language.  This  is  im-  meant  that  certain  C  constants  such  as  *[’ 
tical  language  capable  of  supporting  port-  practical  and  defeats  the  object  of  become  meaningless  numbers  like  9 1 .  Be- 
able  programs  it  leaves  much  to  be  the  exercise.  The  other  solution  is  to  cause  of  difficulties  with  the  character 
desired.  So  I  decided  against  Pascal.  translate  the  troublesome  program  into  a  set,  I  also  decided  that  the  FORTRAN 

FORTRAN  was  a  possibility,  but  is  language  for  which  one  does  have  a  com-  version  of  the  compiler  would  accept 
not  readily  available  on  a  home  system,  piler,  and  ensure  that  the  translation  is  so  upper-case  reserved  words  only  (“IF”  in- 

This  language  has  many  critics,  but  these  easy  that  it  may  be  performed  without  stead  of  “if’),  even  though  the  preferred 

are  more  than  outweighed  by  the  number  much  mental  effort  (I  am  lazy).  I  in-  style  is  to  use  lower  case, 
of  successful  compilers  for  the  language,  spected  the  small  C  compiler  for  possible  Another  problem  was  the  FOR- 

and  the  wealth  of  available  programs,  snags,  and  found  a  further  restriction.  TRAN  programmers’  usual  nightmare  of 
Further,  once  written,  a  compiler  for  a  The  chosen  language  must  support  re-  what  to  do  with  string  (Hollerith)  con- 
subset  of  the  language  would  be  useful  to  entrant  functions;  that  is,  functions  must  stants.  One  solution  would  have  been  to 
those  in  situations  much  the  same  as  be  able  to  call  themselves.  have  changed  all  strings  to  integer  arrays 

mine,  and  those  prepared  to  make  do  J  did,  however,  have  access  to  a  com-  set  by  DATA  statements  filled  in  the 

with  the  inadequacies  of  the  language  in  puter  which  had  a  FORTRAN  compiler  same  format  the  compiler  maintains  in  its 
exchange  for  something  widely  available,  and  while  FORTRAN  is  normally  regard-  own  internally  generated  strings.  This 
I  thus  started  to  consider  the  design  of  a  ed  as  not  permitting  recursive  subrou-  does,  however,  lack  clarity,  so  I  chose  to 
FORTRAN  compiler  to  generate  relocata-  tines,  the  author  of  this  particular  prod-  leave  the  strings  alone  and  accept  the 
ble  machine  code  for  a  Z-80  processor,  uct  had  been  especially  liberal-minded,  overhead  of  unpacking  and  repacking 
and  coded  some  initial  routines.  and  had  added  this  feature  as  an  option  strings  into  integer  arrays  with  subroutine 

That  was  until  I  came  across  Ron  to  his  compiler.  My  problem  was  solved.  I  calls.  In  certain  cases  (e.g.,  “astreq”),  this 
Cain’s  article  presenting  a  small  C  com-  would  translate  the  small  C  compiler  to  meant  that  I  had  to  have  two  versions  of 

FORTRAN  and  then  compile,  using  the  the  function,  depending  on  the  origin  of 
re-entrant  code  option.  the  arguments  —  Hollerith  string  or  sym- 

This  meant  I  would  effectively  end  bol  table  entry, 
up  with  a  cross-compiler  for  small  C,  The  final  incompatibility  was  that 

P.  L.  WOODS,  78  Dukes  Avenue,  Muswell  a  program  which  runs  on  one  computer  some  of  the  function  names  in  small 
Hill,  London  N 10  2QA,  England.  and  produces  code  for  a  second.  That  C  looked  very  much  like  FORTRAN  key- 


by  RL.  Woods 


20 

66 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


words.  Although  the  function  CALL 
should  have  been  safe  enough,  the  same 
could  not  have  been  said  of  MOD  and 
AND,  so  these  and  other  similar  names 
were  changed  by  appending  a  Z. 

The  last  problem  encountered  was 
that  the  liberal-minded  author  of  the  com¬ 
piler  had  not  been  as  generous  as  it  had 
first  appeared.  While  his  FORTRAN  com¬ 
piler  would  indeed  generate  re-entrant 
code,  this  was  only  true  for  subroutines, 
not  for  functions.  Thus,  all  the  small  C 
functions  that  returned  a  value  had  to  be 
rewritten  as  subroutines.  This  proved 
not  too  onerous  a  task,  and  merely  in¬ 
volved  changing  function  declaration 
statements  to  subroutine  declarations, 
and  modifying  the  statements  that  re¬ 
turned  the  function  values  to  do  this  via 
a  subroutine  argument. 

Moral 

There  is  a  moral  to  this  part  of  the 
story.  It  is  that  if  you  see  something  in 
Dr.  Dobb’s  Journal  which  you  like,  but  it 
is  written  in  a  language  that  your  comput¬ 
er  will  not  accept,  do  not  give  up  hope! 
Instead,  ask  around  to  find  someone  who 
has  a  processor  for  that  language  which 
you  might  use,  or  consider  rewriting  the 
program  in  a  language  which  your  com¬ 
puter  will  accept.  That  will  be  far  less 
work  than  re-inventing  the  silicon  chip. 

A  Bug  Discovered  . . . 

My  selected,  course  of  implementing 
small  C  led  me  to  carefully  check  the  sort 
of  code  being  produced  for  various  small 
C  source  statements.  Due  to  my  poor 
typing,  this  soon  revealed  a  problem.  At 
one  point,  I  had  written  in  a  test  routine: 

testsetup  (pone,  ptwo) 

int  ptwo,  pone; 

( 

/*  and  so  on  . . .  */ 

The  code  generated  did  not  work. 
My  test  source  code  looked  all  right,  but 
to  make  sure,  I  inspected  the  source  code 
in  the  original  article  to  see  if  I  could  find 
any  instance  of  what  1  was  trying  to  do. 
(If  it  worked  before,  it  should  work  for 
me.)  Then  I  noticed  that  Mr.  Cain  had 
always  been  careful  to  declare  the  types 
of  his  function  parameters  in  exactly  the 
same  order  as  they  appeared  on  the  func¬ 
tion  header  statement.  This  is  certainly  a 
good  style  to  adopt,  but  in  my  test  pro¬ 
gram  I  had  declared  the  types  of  the  para¬ 
meters  in  the  reverse  order.  This,  I 
thought,  should  make  no  difference,  and 


is  certainly  the  case  in  all  other  computer 
languages  I  have  come  across.  Neverthe¬ 
less,  I  started  to  check  what  the  compiler 
was  doing  while  it  was  reading  function 
header  lines  and  then  setting  the  types  of 
the  parameters. 

As  an  aid  to  this,  I  wrote  and  com¬ 
piled  a  pair  of  test  functions  and  obtained 
the  output  shown  in  Listing  I.  The  only 
difference  between  these  functions  is  the 
order  in  which  the  parameters  are  typed, 
but  the  code  generated  is  clearly  different 
as  to  the  values  loaded  into  the  HL  regis¬ 
ter  pair,  and  in  the  second  case  is  wrong. 
The  reason  for  the  use  of  upper  case  is 
due  to  the  technical  difficulties  encoun¬ 
tered  with  the  FORTRAN  version  of  the 
small  C  compiler  mentioned  above. 

My  attention  was  soon  centered 
upon  “newfunc”  and  “getarg”  and  the 
bug  was  revealed.  The  small  C  compiler  as 
published2 ,  uses  the  function  header  line 
only  to  determine  the  number  of  argu¬ 
ments.  Their  addresses  on  the  stack  are 
set  by  their  order  of  declaration  in  the 
following  “int”  or  “char”  statements,  not 
by  their  order  of  appearance  on  the  head¬ 
er  line. 

.  .  .  and  a  Bug  Corrected 

This  was  a  definite  bug  in  the  com¬ 
piler,  so  I  set  forth  to  fix  the  error.  The 
approach  was  clear.  Entries  for  dummy 
arguments  must  be  inserted  into  the  local 
symbol  table  when  the  parameter  list  is 
being  read,  rather  than  during  the  pro¬ 
cessing  of  the  type  declarations.  However, 
only  part  of  the  symbol  table  entry  is 
known  for  the  variable  at  that  point  (its 
name  and  relative  address),  so  that  the 
rest  of  the  information  (“int”  or  “char”, 
pointer  or  not),  must  be  patched  in  at  a 
later  date  when  the  “int”  or  “char”  state¬ 
ments  are  read. 

This  called  for  a  complete  rewrite  of 
the  “getarg”  function,  but  only  minor 
changes  to  “newfunc”.  A  side  effect  of 
the  changes  in  “newfunc”  was  that  some 
code  to  clear  the  local  variable  list  had  to 
be  moved  around,  as  the  original  code 
cleared  this  array  after  reading  the  para¬ 
meter  list,  rather  than  before  as  required 
by  my  modifications.  Complete  listings 
of  both  “newfunc”  and  “getarg”  are  pre¬ 
sented  in  Listing  II. 

As  a  test  of  my  correction,  I  reran 
my  trial  functions  from  Listing  I.  The  re¬ 
sults  are  shown  in  Listing  III,  and  it  is 
clear  that  the  code  is  now  correct.  Final¬ 
ly,  I  retried  “testsetup”,  and  that  worked 
too. 


Conclusion 

The  result  of  this  work  is  that  I  now 
have  a  cross-compiler  available  for  my 
home-brewed  Z-80  based  home  comput¬ 
er  system,  a  prospect  that  seemed  rather 
distant  before  I  came  across  the  recent 
editions  of  Dr.  Dobb’s  Journal.  I  will 
shortly  have  the  compiler  up  and  running 
on  my  own  machine,  freeing  myself  from 
assembly  language  programming  at  home. 

Corrective  code  for  a  nasty  little  bug 
is  presented  here.  I  hope  I  have  saved 
someone  from  sleepless  nights  while  try¬ 
ing  to  work  out  why  his  legal  program 
does  not  work. 

References 

1  The  BYTE  Book  of  Pascal.  B.  W.  Liffick 
(ed.),  Byte  Publications,  1980. 

2 A  Small  C  Compiler  for  the  8080's.  Ron 
Cain,  Dr.  Dobb’s  Journal,  #45  (May 
1980),  pp.  5-19. 

3 A  Run  Time  Library  for  the  Small  C 
Compiler.  Ron  Cain,  Dr.  Dobb’s 
Journal,  #48  (September  1980), 
pp.  4-15. 

4  The  C  Programming  Language.  B.  W. 
Kernighan  &  D.  M.  Ritchie,  Prentice 
Hall,  1978. 

s  The  tiny-c  Owner’s  Manual.  T.  Gibson 
&  S.  Guthery.  tiny-c  associates,  1978. 


(LISTING  ON  PAGE  32) 


A  Very  Special 
THANK  YOU 

Readers  who  responded  to  DDJ’s  re¬ 
cent  survey  have  greatly  assisted  us  to 
understand  the  growing  number  of  ways 
we  can  serve  you. 

Five  of  those  surveyed  were  selected 
at  random  to  receive  a  small  gift  of 
thanks.  The  first  three  compiled  volumes 
of  Dr.  Dobb’s  Journal  have  been  sent  to 
these  individuals: 

D.  W.  Daetwyler 
Ken  Data 
Ned  Freed 
Steve  Patchen 
Fred  W.  Pluebell 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


21 

67 


t?mce  1976,  the  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 

Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


r 

YES!  Enter  my  subscription  to  Dr.  Dobb's  Jour¬ 
nal  and  bill  me  later. 

$25 

name 

one  year  subscription 

12  issues 

address 

saves  $5  off  the  newsstand  price 

city  state  zip 

Mail  to:  DDJ,  P.O.  Box  E., 

Menlo  Park,  CA  94025 

Z~80  Memory  Test 


Figure  1. 

Memory  Address 

In  Listing  As 

Significance 

0103 

00 

Address  of  terminal  status  port 

0104 

01 

Address  of  terminal  data  port 

0105 

40 

Data  ready  flag  (RDA) 

0106 

80 

Transmit  buffer  empty  flag  (TBE) 

General  Description 

This  Z-80  Memory  Test  for  CP/M- 
based  systems  is  modeled  after  the  ex¬ 
haustive  diagnostic  programs  used  by 
minicomputer  memory  add-on  manufac¬ 
turers.  Mode  and  area  of  memory  tested 
are  controlled  from  the  keyboard.*  Fail¬ 
ing  locations  are  isolated  to  the  bit  level 
and  audited  on  the  console.  Errors  in 
mapping  the  logical  address  space  to  the 
physical  memory  are  trapped  by  calcu¬ 
lating  and  writing  the  entire  data  pattern 
before  reading  any  locations. 

Configuring  test  for  your  computer 

All  console  input  and  output  is  done 
by  a  set  of  subroutines  which  access  the 
four  configuration  bytes  at  0103H- 
0106H.  You  may  easily  customize  the 
test  for  a  different  serial  I/O  board  by 
reading  in  the  HEX  or  COM  file  with 
DDT  or  DEBUG,  modifying  these  four 
bytes,  and  SAVEing  a  new  COM  file  (see 
Fig.  1). 

It  is  recommended  that  you  do  NOT 
modify  the  actual  input  and  output  rou¬ 
tines  “Ci,”  “Ciw,”  and  “Co.” 

Using  the  test  program 

After  booting  up  your  system,  type: 

A>Z80MT 

The  test  program  will  load  into  memory 
and  print  the  title  and  version  number: 

Laboratory  Microsystems 
Z-80  Memory  Test  version  2.3 
The  program  will  then  request  the  test 
mode: 

I = itemize  errors,  T= print  error  total 
only,  E=exit  test 
> 

You  must  select  I,  T,  or  E.  Selections 
have  the  following  consequences: 

I  =  normal  mode  of  memory  test,  all 
memory  errors  found  are  itemized. 
This  mode  should  be  used  when  soft 
or  intermittent  errors  are  suspected. 

T  =  print  total  errors  per  pass  only,  do 
not  itemize  individual  errors.  This 
mode  may  be  used  to  avoid  long 
printouts  when  you  have  a  known 
failing  location. 


by  Ray  Duncan 


Ray  Duncan,  Laboratory  Microsystems, 
4147  Beethoven  Street,  Los  Angeles, 
CA  90066. 


*  Because  the  memory  test  may  destroy  the 
CP/M  monitor,  console  I/O  is  done  directly. 


E  =  exit  test  —  if  the  test  program  deter¬ 
mines  that  the  operating  system  was 
not  destroyed  during  the  testing  pro¬ 
cess,  a  “warm  boot”  is  executed. 
Otherwise,  the  test  prints  a  warning 
message  and  loops  waiting  for  manu¬ 
al  restart  of  the  computer  system. 

The  program  will  now  request  that 
you  specify  the  area  of  memory  to  be 
tested : 

Enter  address  of  the  first  byte  of 
memory  to  test: 

> 

Enter  address  of  the  last  byte  of 
memory  to  test : 

> 

The  addresses  you  enter  must  be  four 
hexadecimal  digits.  For  example,  legal 
entries  would  be  1000,  2FFF,  8000, 


CAAA.  The  test  program  protects  itself 
from  destruction;  if  you  enter  an  address 
that  falls  within  the  boundary  of  the  test 
program,  it  will  reset  that  address  to  the 
end  of  the  program  and  print  a  warning 
message. 

After  acceptance  of  the  last  byte  ad¬ 
dress  to  test,  the  program  automatically 
begins  executing.  You  can  interrupt 
execution  of  the  test  at  any  time  by  de¬ 
pressing  any  key,  however  response  may 
take  several  seconds  when  testing  large 
areas  of  memory. 

For  each  error  detected,  an  audit  is 
printed  on  the  console  in  the  form  (all 
numbers  are  in  hexadecimal,  see  Fig.  2). 

(continued  on  page  35) 

Listing  begins  on  page  24 


Figure  2. 

Address=xxxx 

Pattem=xx  Contents=xx  Xor=xx  Type=xx 

Address: 

Memory  address  where  error  detected 

Pattern: 

Data  that  was  written  to  that  location  in  memory 

Contents: 

Data  that  was  read  back  from  that  location  in  memory 

Xor: 

Logical  exclusive  OR  of  pattern  and  contents,  isolates  the  failing 
bits(s) 

Type: 

Test  makes  best  guess  of  whether  error  detected  is  hard  (write) 
or  soft  (read) 

Figure  3. 

Pass=xxxx 

Errors=xxxx  Cum.  errors=xxxx  And  =  xxxx  Or=xxxx 

Pass: 

Number  of  passes  executed  since  test  began 

Errors: 

Total  errors  this  pass 

Cum.  errors 

Total  errors  since  test  began 

And: 

Logical  AND  of  all  failing  memory  addresses  since  test  began 
(i.e.,  gives  bits  in  common  to  the  addresses  of  all  failing 
locations) 

Or: 

Logical  inclusive  OR  of  addresses  of  all  failing  memory  locations 
(i.e.,  gives  the  union  of  all  bits  in  the  addresses  of  failing 
locations) 

22 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 

69 


E  o 

a 

«  L  ' o 

•  a  C 

L  o  •  ■ 

a  L 

a.  O  - 

C  Q.  4* 

a  I  c 

L  3  •«  4» 

n  -»«c  ■> 

o  .  4* 

(-  Jl  -H  4» 

a  oi« 

• 

c  a  < 

■*«  m  - 

■c  ^  II  a 

4*  <  • 

-«  80  «*-  L 

9  li.  -  • 


5  •  £  h 


~  C 

•h  •  > 

ICh(. 


_  *-  •  “*  a  I  (-  a.  a  <  4*  4* 

<  •  fc  A  L  a  l  m  L  L  I 

«  u  3  .  a  a  u  tj  j  a  a 

-J  •  *  «-  •  u  .«a  >  > 

£  Oo  -<4»acaic  c 
•••■*»  C-^VOO 

>  a  -«  a  a  <  ^  -o  m  i  u  u 

•  5  •  a  t  c  aou  , 

cn  u  e  *  l  u.  a.  a  a  c  m 

-  -  ~  2  -  -  -  -»  «.  -  -  n  ** 

«  §  a  ;  i. 

E  r  £  *£  *  £  * 

si5S*5: 


1  C  9  (.  *•* 
i  -*  t.  a 

■  4»  (- 

•  a  a  a-  l 

*-  u 


i  O  ■*«  4* 

U  1C 
I  ■« 
last. 

>  a  *.  a  o.  i 

4*  a  4*  i 

i  a  a.  a  .  i 

9  a  9^  i 


o»0  o»  o 
c  CL 


a  a  a  - 

i>  a  (•  a 
ala 
a  3  a  a 
o  ->  o  a 


5  hs^sih  ss  «S  5  3 


■a  a  o  c 

JOQ.H 


2§25oSS8S2=22222^2tS2a§2222SR8saS5SSfiRfiS5!?555^ 

OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO 


N  CO  lh  O  -«  CM  _  _  . 
OOOOOOOOOOO 


a  a 

Em  c 

a 

•  -  -  -  E 

IPltfi'ON 

iDnnAn 


-55  -o  mtnn  o  n  n 

s  III  !  §§§§  sL«  58* 

S  8  *  g  ^  i<  «  n  b  n  n  0  amm 

ui  ui  u.  m  o  01  3  n  S  8  uj  ui  o  £  3  n  uj  uj  F3  8  2 

SiSfciSe  8  S2£g!fc?;:g!$$$g!?*2 

^4  H  W  H  H  H  HHHHHHHHHHHHHH  H 

ooooo  o  ooooooooooooooo 


Oonoo  o* 

&  2  S  1  2  5  cm 

a  5  a  q  a)  n  r> 

HHDQHQnnQ  N  Q 

OCMOUJCMOUJUJUJ  CQ  Ui 

tBOBiLni)<0N  au 
<<<<<00  0(0  mm 

ooooooooo  oo 


CM 

J  8 

m 

o 

B 

O  cm  m 

N  Q 

©  -*  O 

it 

CM 

m  uj 

n  cm  o 

n 

m  o 

uj  o  n 

<j 

N 

m  m 

moo 

o 

o 

*H  H 

v4 

•4 

o  o 

o  o  o 

o 

o 

<  Q  o  ^ 

O  O  Q  Q 
O  O  O  O 


*  E 

-*  a  4»  o 

4*  a  *0 

4*  a  a  o 

a.  9  (.  O 

a  9  a  4>  a- 

in  -q  o  cn 

i-  « 
**  O  u  C  O 

O  •*«  a 

_  *  r  >  . 

n  •<  o  a 
c  9  x:  a 

CM  4»  a  i-  4»  ~ 

x  u  o  a  a 

c  w  c  4*  a  9 
o  ■•«  d  a  m  c 

M  L  Q  L  < 

a  9  on 

(-  o.  9m  a*  a 

a  o  a  a  ^  o 

>  UIJ<J 


o  t>  a 

a  l  j - 

■p  o.  o  6 

a  a 

a  a  c  4* 

L  a 


tj  (. 

a  o  a  a  i 

a  E  4*  . 
».  a  o  j 
a.  a  a  0.4 

pH  f 

9  a.  x)  O  « 

a  o  a  u  ( 

E  u  TJ 

a  a  i 

l  «*-  a  •*  . 

a  o  (-  x:  < 

a 

a  »-  a  4*  i 

-c  a  c  l  i 

U  DH  o 
»-  E  -C  CL  I 

3  3  u  a  i 

o.  c  a  3  i 

E  a  4 
a  9  ( 

jc  c  c  o  : 

H  a  o  4*  l 


L  h  a 
04*4  | 

a  (.  a 

O  9 

a  a.  tj  j. 

3  a  a 

4»  a  a  a- 
a  4»  (-  a. 

4*  a  3 
a  a  a  a 


an  c 

at  cl 

i-l  o 


^  »  O  o  *<  • 


La  -•  -•  E  L 

lc  aa  o  o4*i 

a  •*<  a  a  i>  o.  f_  i 

u  -•  4*  4*  a.  o  i 

c  c  a  o.  I 

m  m  a  a  l  3 

3  3  a  4*  a  i 

oo  o'o*  4*  a  4*  4 

0)  CD  a  a  c  4*  a  > 

:  <  «  aa  a  a-oi 


4*  a 
a  4* 

E  4*  a  a 

a  *  tj  tj  . 

E  LHITI 


333333333 

o'o’o'cfa'or’a’o'o* 


*  4*  a 

u  a  4*  4*  4* 

BE4>aaau  cc 

4*0.  *  T)  TJ  X  a  c_«i-  U  U 

.(noHi-iEi-iiJo  J  --q:3 


4*  a 

a  4>  a  a 


a  -o  l  4* 

.  a  a  a  a 


ItCMIMDO-OHncntBO 

'OOOOOO*-*-^^*-*^^^ 

!8§§888§§8§oo8 


MD(hOHfCP)<ftCINO(hOHNn<«>ONOO'OHN 

-i^^fMCMCMCMfMCMfMCMfMCMnnnnnnnnnn*** 

88888888888888888888888888 


O  Of 

X  .5 

Ji  2 

N  j 


OOOhOOOQC 

0000^0-00 

•400000000 

ooooooooo 


0-^00 
O  O  <  CD 


n  m  o 
o  o  o  o 


24 

70 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


9  c 
4 


C  -O 

■*«  c 

*0  4*  m  4 

(•  -H  ft  ft  - 

•  ft  •  C  4>  J 

o  3  4*  4  C  •< 

<0  ft  3 

»  (-  V  *>  O 

ft  ft  0.4*  U  4 

4*  -»  4*  3  ft 

ft  u  4  o.  ft  I 

•  ft  *-  ft 

4*  U  4  ft  ft  4* 

•  ft  4*  >  •*« 

Of  4=  C  ft  4 

4*  u  u  *4  ft  3 


I* 

0-0-0  4* 

•  8  C  ft  ft 

I  ft  ft  4*  9 

f  « 

ft-  ft  4* 

»  ft  •*«  4*  O 

1  u  C 

.  6  M  •  * 

I  ft  u  4>  o. 

.  >  •  o 

D  £  O  O 


•  4*  M  4  ft 

4*  4*  ft  I.  •*«  O  *-i 

o  h  a  •  h  1.  c 

c  4  >  ft  ft  ft 

.  3  ft  O  "H  4*  c  . 

Q.  4*  4*  C  C 

O  4*  ^  O  -*3  C  4 
o  ft  I-  c  CO  O  ft  - 

-*  a»  3  ft  ■**  u  4  4*  « 

%.  4* 
ft 

3  v  S* 

•  C  ft  O  • 


•  -H  -D 

<  ft  ft  c 

B  4*  -O  3  4*  ft 

Il  4  ft 

O  ft  4  ft  C 

ft  4*  4*  O  ft  4*  4 

4  ft  43  4*  ft 

O  9  3*  9  U  4*  4* 

4  -  t-  •  ft  0.4* 

4  O  -**  4  3  ft 

ft  8  ft  4  o. 

ft  -**  4T  4 

o  8  u  u  ft  ft 

ft  ft  4*  > 

ft  ft-  f  ft-  C  ft 

.4  O  u  •*«•*«  ft 


C  0-  • 

C  T>  4*  I 

4  1*  U  I 

f-  ft  ft  ft  I 

ft  4*  4  I 

4*  4*  9  9  4  l 

C  ft  4  4*  4  O 

3  O  O  -*4  O  O  I 

o  8  8  04 

u  ft  ft  ft  ft  «  8^ 

4*  s  >  8  4*  3 

•  3  ft  ft  “*  I 
-o  O  ft  ft  O  O  .4 

ft  f  -  .  ft  ft  - 

ft  O  f  .  ft  ft  ft  I 

4  o  4*  4  •*«  9  : 


j  -J  .x 

IJ  -  M  %  Ml 

-I<UJ2<Q2I 


J  ■**  -MO 

X  O  <  Z  B 


~  no 

£  4  S~- 

4*  <  -  E  J  4 

ft  -  .  -  X  4 

CL  ■  <  B  N  v  U 


ft  4  -4  r> 

11  i  13 

ft  ft 

-  - - -  -  E  E 

Scho^nin^ft'Oi 
n-o-o-O'0'0-0'3- 


MDtho^nntn-oi 

•di-ONNNNNNM 


'COOL- 

INJU"). 


8(hOn| 

NNiffll 


ft  4  4  3 
U  O  ">  CL 


3  ft  ft 
ft  4  E 
•  D 

ft  ft-  4*  E 


'OOOOOOOOOOOOOOOOl 


SS&8S??Sf???^5:?S:§S8SSo§S§S2n22J 


•00000000 


0000000000 


rv  n  -o 

n 

S 

m  n  m  oc  o  ~ 

o 

<0  b(KP)  «  <0  O'  <  00  (J  Q  U.  O  -•  n  ft 

OO  O  lii  L&J  Ul  lii  UJ  UJ  UJ  Ul  lil  UJ  IL  U.  U.  U. 

— *  — H  »<  H  H  H 

00  000  o  o  0000000000 


«o 

n 

01 

O 

o 

o 

a  n 

4 

?  a 

a  n 

N 

c 

>  a 

QNOn 

Q 

MU  (D  g 

9  O  Q 

unnu 

O 

ft-  N  03  r 

UNO 

00  UJ  Ll 

01 

« 

U.  IL  IL  IL  O  O  OOOOOO 
r*  m  ft  rcnnnnn 

o  0000  o  000000 


•  «  ac-  >  4 

3  ft  ft  C  ft 

43  4*  a.  *  ft  f  I 
l  O  U  4*  4 

ft  C  u  -ft  ft  I 

C  ft  4=  I 

ft  -  a.  o  ft  3  3  1 


4*  <3  4* 

-  a  o 

s  ft  il  o  c 

«  4* 

ft  <4  ft 

<  4  o  *  •- 

9  CD  ft  O 

4  li.  ft  •  < 

o  ft  4*  .  m 

EL  9ft  Ia. 

ft  ft  4*  f  > 

8  4*  ft  ft 

C  43  4  4*  ft  4 

4*  ft  ft  ft  ft.-*  3 

ft  -O  a.  a*  C  3  ft 

94*  h  a  •  3  t. 

C  3  C  ->  ft  ft 

3  ■*«  4*  £J> 

0  4  •  *4  ft  O  4*  ft 

Co.  a-><  -h  ft  o  E 


<  *■« 
.  T)  4* 

•  ~  ~  c  8 

J  ft  ft  ft 

!  X  8  K  E 


8  E  8  I  (Eh 

ft  ft  ft  .ft  .  ex 

5  E  5  af  5  5?  S 


H  t  -  &H  - 
.  E  J  ft  4  . 
<  ~  X  O  O  <  I 


43  n  -e 

8  O  C 

•  »  Eft 

E  *-»  4  ft  4- 

.  0.4*  I  <  E  . 

3!oi5<<e^3! 


-I  -I  -I  -J  -J  -I  O 


-i -i -i -i -i -i  o  JJ  juo  JOUOo5?U^( 


4  0-0  -o  ft  ft 

4  x  _J  JUU 


ft  -o  4  Q.  TJ  3 
U  JO*)  JO. 


+  ft1  *  ft* 

8888 


)»OHNn<rn«NO0>QHi 

18888888888888! 


i^NNNNNNNNNNaoamooaSoi 

{8888888888888888888! 


o^wnft,r>«ON®o-p 


o  n 

n-oon 

o  o 

o  o  o  o 

-o  a 

Il  <h  U.  O 

o  (h 

F  fr*  o  a 

<  01  UJ 

.  4  Q 

01  01  N 

n  o  oi  o 

nuiHnnon  ui 

OOhhh^h  h 

H  *4  *4  *4  *4  *4  *4  *4 

0000000  o 


QQUS<h« 

OUNBIi.*4|U 


KSiDs  2S35^3?S 


OOOOOOO  OOOOOOOOOOOOOOO 


OOOOOOOO 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


(continued  on  the  top  of  page  24)  '  (continued  on  the  next  page) 


•*  *-  p  a 

~  A  "4  A 

i  >  A  3  A 

P  O  A 

*  -«  A  A 

*  4»  m  £  O. 

o  a  a 

u  jz  u 

U  P  A  M  -f  * 

•  -H  <  £ 

P  O  A  3  03  P 

•*«  P  P  -JO 

A  A  *  c 

c  o.  c  a  a 

•  *-  cc 

P  A  P  A  O  P 

•  4»  £  P  P  (. 

VP  BP  «  « 

(.  a  •  a  t  • 


a  o  o  a 

U  _i  _J  u 


J  p  -  E 

I  Q  <  w 


o  a  o  **  o 

J  U  J  K  J 


3 

6  o  «*■ 

UJ  A  L-  o 

O  E 


a  p  p  a: 

•  a  c  O  < 

l>  a  i 

o  Pa 

•o  O  c  >  I 

a  a  o  -m  - 

PUP 
w  A  3  • 
C  -«  i 

•*  3  A  U  < 

^  U  3  W 

P  A  ' 
A  A  U 


;SU  SUH, 


3  0  0  0  0  O  t-  3  O  O  O  O  O 

a.  J  J  J  J0.->  L  J  J  J  JL 


£  £  £  £ 

3  3  3  3  0 
(L  0.  0.  0.  X 


ao-o«o 
J  J  O  CL 


£SS2!2S£i!E;S0'o~n,n^in 

nnnnnnnnnnntttttt 

S22C5C5553nnf>finnc) 

ooooooooooooooooo 


2N£D£o^n!n*!£;0£<i)£o^nin*,n>0N<ij(ho-'0in*r>orsa>0'O-«r*no-« 

Srt25SSSSSS222S2CSC555nnnr)t,5nnwnnnnnnnnnnnS 

oooooooooooooooooooooooooooooooooooooooo 


noon 

a-  n  m 

o  ry  o  o 

o  o  o  o 

o 

O  03  oa  o 

a  O  ry  ry 

CM 

<D  *  ^  © 

Q  os  ry  ry 

o 

a  a  ~  q 

-  o  *  cm 

-  n 

U  UJ  CM  O 

cm  o  rt  o  n 

Q  O 

Q  O  t  N 

<  q  o  n  a 

N  CD 

<  <  < 

<  <  03  CQ  03 

03  03 

cm  cm  ry  ry 

ry  ry  ry  cm  ry 

ry  ry 

o  o  o  o 

o  o  o  o  o 

o  o 

a 

p 

a 

a 

c 

o 

c  c 

o 

a  o  o 

a 

a  <*- 

•  ««  (- 

a 

L  O  9  O 

a 

XI  c  c  P  a 

oop  t-  p  C 

p  a  a  a 

•*«  p  * 

o»  P 

O  P  U  90 

C 

3  **  p  ».  a  •*  o 

c  c  c 

P 

C  P 

o 

o  p  a  a  P 

p 

l_  a  p  a. 

c  a  a  •*«  o 

9  O 

.«  ^  ^ 

••  •* 

a 

a 

a  a 

a  n 

^  9. 

o 

o  o 

o  o 

N  Q 

a  uj  o 

cm  a  a  uj 

<r  od 

m  u 

ha  2 

•o  o  o  u 

u  < 

m  uj  ry 

y  a  r  ® 

m 

uj  cm  uj  ry  ~ 

n  m  m  rj  od 

u  — •  o 

^4 

u.  n  cn 

nnu.  h 

u 

nPinnu. 

UQUJlL< 

a  cm  o  u 

03  O  UJ 

^n-oN 

0* 

<  o  u  -*  a 

O-OMBO- 

<  03  UJ 

03  03  03 

a  a  a  a 

o 

U  U  U  Q  Q 

a  q  a  a  a 

QQQ 

UJ 

CM  CM  CM 

ry  cm  cm  cm 

ry 

cm  ru  cm  ry  ry 

CM  CM  CM  CM  CM 

CM  CM  CM 

CM 

o  o  o  o  o  o  o 

o  o  o  o  o  o 

o  o  o  o  o 

O  O  O 

o 

p  C  C  P 

«  o  a 

t  a  o  a  a. 

^  P  A  O  £>  O 

^  p  ■«  a  o 
*-••*«  O  9£  o  H 

^  *  3  u.  U  P  * 

P  P  «  O  0  P 

P  o  E  •  a  a 

a  c  a  c  a  9 

«■  o  C  (. 

p  p  (.  *.  a  a 

a  c  *-  a  p  c 

o  a  u  90 

L  C  -a  L  o 

p  Q.O  a  u  c 

a  .  a  >  a  E  p 

o  o  a  o  p  a  o 

■o  c  »-  a  u  E  c 


P  p  t-  c 

a  p  a  (. 

9  a  p  a 

a.  c  p 

a  3  Pi¬ 
ca  o  a  a 

o  f.  u  a.  > 

o  o  o 

Poo 

p  p  a  a  o 

o  a  a  a  c 

c  *-  c  c  a 


^a-iac 


3-0  3-0  3  0  30  30  3  ' 


*  **  **  ■*  Z  ^  ' 

*  •' 

CM 

n  n 

t- 

E  E 

a  a 

Ul 

E  E 

n 

1 

-J  -  I 

E 

M 

-J  *  M  -  NO 

a 

03  Z 

Z<UJZ<QZOB 

E 

M 

•-* 

U  Q. 

c 

cl  a 

Coa.coo.t-o 

u  o 

Q 

A  C  P  P 

a  a  a  a  a.  p 

U  C  9  o 

C  a-  a  op 

a  o  (-  a  -i  m 

>  u  C  -  o 

o  o  c  0  0  3 

a  c  •*«  oca 


o  <  ^  z  E 


C  o  a  j-  L 
HJU’)’) 


~  p  E  o 

o  o 
o  p  U  O 

p  (.  a 

a  p 

o  p  p  c 

H  P  -H  -rt 

o  a  m  (. 

a-  K  UJ  a 


O  E  E  - 

CM  '  «.  a 


ft  £  M  —  v  -wcc 

r  •  a  a 

r  r  -  -  -  —  . . e  e 

sssSs§aaaSss™ssssass8SPiS?;$;!js?:?$5?58s«ssKS!;ss:S32!2SS5!ss$gs 

gggggoggggggggggggggggggggggggggggggggggggggggggggggggggg 


-o-O'O'O-O'O'OO'O'O'O'O'O'O'O'Offla- 

(h(Dlh(D^(D(hlD(h(Dlhffi^O^(DB(J 


o*  m  © 

o  o  o 

nonou<o-  o 

(MNmniNnniu  ^ 


o  -•  cm  n  a  m  «o  rs  ao  a*  <  ca  u  a  uj  il  o  uj 

cm  cm  cm  cm  cm  cm  cm  cm  cm 
cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  cm  ry  ry  ry  ry  cm  cm  cm  ry 

o o o o o o o o o o o o o o o o o o  oooooooo  o 


03  a  o 

** 

o 

omul 

«  n 
o  o 
o 

o  «  ry 

CM  O  -* 

ry  03 

OCMJOOD 

■0  Ul  CM 

^  Q 

OMlCM-i 

u.  u  o 

CM  o 

o  -  cm  a  o 

non 

ul  ry 

n  n  nn  n 

cn  a 

CM  (M  CM  CM  CM 

ry  ry  cm 

CM  CM 

o  o  o  o  o 

o  o  o 

o  o 

26 

72 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


t-  Ol 

L  *  o 

3  0  ^ 

u  0 

u  m  • 

*»  -a  > 

0*0  0 

t*  0  0  • 


r  x>  : 

<  *  0  cd 

-  J  ■<=  , 

o  i  o  o  : 


<  Ul 

II  <  J 


-  E 
E  ~ 

<  0  -  Q 


<  Ui  < 

«  «  •  ] 

I  I  <  _J  _J 


UJ  %  CL 

<  N  i  Q  i  Q  ! 


L  0  H  u 
1  3  O  0  O  C 
,LJU  Jh 


a.  0 

T3  O  3  *0  T> 

J  ft.  ft.  J  J  • 


0  .  IN 

*0  0 

0  JU 

4>  0  I 
0  (• 

0  n 


:  o  *0  o  *o 

:  _i  -j  _i  _i  i 


100000 

ioqlQ.q.q: 


0  u  u 

CL  CQ  00 

o  «  «  « 

imijlii 


D  T>  TJ  TJ  TJ 
0-  _J  _J  <  < 


1  n  fi  &  fi 

•  00000 


EE  ^  4»  C 

O'  O00  O  4> 

L  O  E  U  QC  4* 

L  0 

Ui 

iwntn-ONfflQ'OHpintft-oNDihOHN 

imNrtrtrtWNfKnnnnnninnnphrtt 

•000000000000000000000 


♦  n  jn  *  n  0*  0-  ft  n  m  n  r>  0  n 

0000  0000  o  00  00  00 

u  CD  ll  <5  ^OO  O  n  n  m  ncp  -o  o-  o 

me  <<  <©q  a  cm  cm  cm  ci  3  o  O' m 

£RE£Pr!P£P£2£!!;:£:X52r^P,24e£<5<*,K®,ou-rtS  cd  o  ( 


ttKUt(KUUUWUfllP(0(QQ0(N<-flN< 

nn<oo‘<QOHnitf)OBuiiOHtf)4M9 


INB-OMa- 


mmnouiooo 


rtn<MKQO»<0(r(DByltOHtft<MP(h<QOHniP)t«'00*  (JQU.CMft'ONOD 

nnnrSnnnn 

00000000000000000000000000000000  00000000 


uionoo 


O'  <  o  u.  0 

SSSS8 

00000 


a  >  •*<  0  < 

CO  r-. 

»-  O  c  E  4> 

4*  4»  (-  0  0  C 

0  0  4*  4>  4>  -*4 

L  0  C  0  0  (.  • 


O0  •  | 

0  C  «*  OTJ  < 

*»-  3  *-  C  C  0 

*•"•  3  *H  -*4  9  | 

s  4*  4*  4*  O  ( 

*  •  0  0  0  1.-. 

U  4*  U  t-  t-  4*  ( 

0  0  *  0  0  0( 

c  7  o  a.  a.  0  1 

u  0  c  o  o  -o  : 

u  ~ 

E  0  o' 

0  E  E 

E  0  E  0  9 

-  E  -  0.  E  *-» 

'  ~  JU  -  a. 

i  <  -  n  I  Q 


0N  »«  0 

»  Em  EE 

0  1  0  0 

E  0  E  E  O 

~  E  ~  ~  CD 

><**04*. 

1  4:  o  j  *.  u  _j  _j 

U  CD  I  U  O  I  I 


-1 

•  ^  Cl - 

^  ^  _ 

I 

CM 

K 

^  -k  n 

« 

Ol 

ft  E 

fs 

ft  E  m 

C 

CM  0 

O 

CM  0  E 

K 

0 

o  E 

i ' 

o.  E  0 

E 

E  L 

E  - 

0 

E  -  E 

0 

*  0U 

0  * 

IJE' 

0  «  « 

E  . 

JUJ£; 

E  -J 

»  «  »  « 

EUJ 

w  ! 

I  m  I  u  < 

-  I 

<  <  M  < 

w  OQ  I 

-I  -J  U  “1  -JO 


J  TJ  0  TJ  TJ  0  T3  TJ  T> 

J  JU  J  JU  J  J< 


0  a.  h 
*0  3  0-00* 
JQ.0.JU. 


*0*0*0  (.  co 

-I  -J  -I  O  1  _l 


-  -  -  - - -  E 

aaaaaa""SSSSSS“SSS""wfi""WNS«8888888888SnnnnSnnnn88888a8Sa 

000000000000000000000000000000000000000000000000000000000 


ft  ft 

o 

ft  n 

CM 

O 

9  ° 

o 

o  o 

9  u. 

o 

O'  o 

ft 

O'  £ 

o 

<o  m 

ft 

5  5 

UJ  < 

^  o 

n 

cm  n 

m  o 

CM  O 

o 

ft  OD 

B  U 

U.  CM 

ft 

♦  ♦ 

♦  <* 

e*  ft 

ft 

(M  CM 

CM  (M 

CM  CM 

CM 

o  o 

O  O 

O  O 

O 

XX  X  o 

00  o  o 

cm  CM0np0r>00 

O  QOOQOOftO 

m  nftomnomo 

0  0UJa!0U.CD0Q 

ftono^ao^aaeo' 

QUJOUJCMOUJCMOUJCMO 

ODO'QUICMftaDOlLCM'OO' 

(MCMCMCMCMCMCMCMCMfMCMCM 

OOOOOOOOOOOO 


o  ft  n 

o  00 

0  jOQ 

ft  000 

NftHHQUJ 

cm  uj  0  cm  0  n 


<  Q  Ul  Ul  CM  ft 
N  N  N  N  GO  CD 
CM  rM  CM  CM  CM  CM 
OOOOOO 


ft  >0 
O  O 

m  0  O'  o 

Oft  -  cm 

CM  <  O  ft  OD  UJ 

n  cm  n  m  cm  n 

N<QUi|LH 

ssssss 

OOOOOO 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


(continued  on  the  top  of  page  26)  I  (continued  on  the  next  page) 


r» 

O 


(-  c 

ft  •*«  ft 

•c  l  4» 


oj 

4»  9 
I-  3  b 
o  a.  m 
c 

3  -*4 

ft  O  x» 


■O  4* 

C  • 

ft  fr. 


ft  3  ft 
•  i  - 

(-'-»- 
■O  (- 
■O  Ol  ft 

ft  c  u 


b  0- 

ft  ai 

^  C 
u  •*« 
f- 


•*«  ft  4» 

£  a.  b 

■m  ft-  *  C  • 

O  ft  3  4» 
■D  .  A  C 

C  -O  ft  . 

ft  C  ft  o  O 

ft  ft  9  C  a. 


ft  ft  *o  « 

-a  oi  ft  C 

ft  ft 

ft  •*«  H-  ft 
*  b  3 
•*«  b  ft  U 

^  ft  C 
ft  v  ft 


■*«  C  "O 

C  ft  c 
•*«  ft  ft 


o- 

b  c 

•  »- 

4»  3 

(-  U  -ft 

ft  ft  ft 

*»  b  b  o- 

C  ft  o* 

3  £  ft  4*  I 

O  u  ■*»  o-O 

U  -*4  ft  tt 


o  (-  .  -4  ft- 

.c  (-  ft  ft  . 

U  ft  ft  ft  ft  o 

I  ft  U  9-*  9  C 


I-  ft 

ft  3 

3  O 

O  •*«  ft 


9 

o  o- 

-« u. 

ft-  i 

b  o 


■o  (0 
ft  <  CD 


8 

i 


s^SsIdS 


3  3 
<L  Q. 


ft 

(J 


SO'  o  oj  n 
r>  -o  >o  -o  o 
nnmnnm 
o  o  o  o  o  o 


ft-  r> 

22 

o  o 


3  c 
a.  m 


n  r> 

O  o 


■o  j. 
-J  “> 


t- 

Q. 


»  ft  O 

a  (0 

4»  <t 
4»  3 


b  4»  4>  (-.Of-  _J 

^  3  U  <  U  U  N  I 

«»-  O  9 


N 

I 


ft*  3? 


H  H  4»  U 

ft  -o  ft  a.  ft  c  b 

U  JUUITh  -> 


O  ft- 

it 


•O  ft 

_J  o 


..........  liJ 


'  t  9 

.  O  .  *4  O  (- 

<  U  U  U  U  U  I 


b  X 

UJ  O 
'  O  < 


Ift-OftftO.ftO.f.C 

lU_JOOUtLU“>« 


cd  a-  o  -  t 

<i  -o  rv  rv  r 
r>  n  r>  n  i 
O  O  O  O  ( 


oooooooooooooooooooooooooooo 


UJ 

UJ 

CD  O'  C 

)^wntr)«0Nm 

Ch  Ch  C 

>00000000 

r>  r>  4 

DO-OO-O-O-O-OO 

o  o  c 

>00000000 

.  .  «  .  UJ  ' 


<<<<->  o 


ch  o  ^  oj  n 

§iisi 


CM  CD 

o  o 
id  in  n  O  ld 

ujQur^HH 


CD  O'  <  00  U  UJ 

n  $  $  $  n  i5 
o  o  o  o  o  o 


n  0 

0  0 

O  Ll  Q 

<0 

u.  0 

Ll 

Q  UJ  Q  UJ  CD  n 

OD 

u  mj  u.  u  n 

— H 

0  n  ^  n  (h  < 

00 

00  00  00  00  00  00 

00 

n  n  n  n  n  n 

n 

000000 

0 

0  n 

0  <i  0 

0  0 

0  00 

0  u 

uiiLt  <ou.q  ^niu. 

-0 

0  it 

HNO^NO  ft^OQ 

UJQUJQQUJQDUJQD'O 

IMMMMD 

Oi  O 

nuouuu.uii.nuj 

r>j  oj  nj  w  n 

O  O 

nmiD<QoruniDN 

(h  <  00  U  Q 

£  ^ 

yyyyy9QQQQ 

Q  Q  Q  Q  Q 

n  r> 

nnnnnnnnnn 

n  n  r>  n  n 

0  0 

0000000000 

00000 

a.  *-«  >  O 

c 

ft  ft  -*4  ft 

Ol  4»  4> 

•*«  ft  c  •  c 

(-•(-•(- 
4J  b  •  f-  ft  A 

E*04»'04»-4  f  -+ 
ft  ft  H  v  H  H  ft  >-H 

UftftftftftUft 


ft  n  o 
ft  -o  (- 
C  • 

o  (-  M 


o  o 
b  b 


''VHiuntnoNDo-o 


c 

(- 


ft 

a. 


■o 


b 

A 

c 

ft 

u 


ft 

o 

b 

u 


sf 

•  o 

—  Hrtn^ftONDO'H 

§5  ftftftftftftftftftft  ~i 

LQ.Q.Q.Q.HIL11Q.IL  < 


ft 

ft 

c 

o 


I  ^  M  < 


X 

Ll 

Ll 

o 

< 


X 


< 


o 

< 


s 

n 

< 


ft  -J 

c 

o  < 


C?  6  c 

4>  ft  ft 

« c  r 

-1  0-  ~  ~ 

<  6  <  < 


4» 

•  J-J-J-J-J-J-J-J-J-l- 

a:“>“>“>">->->->->“>“> 


u  u  u  (.  *o  (-  4* 

■o»-(-Q:oc(-oft- 

jinrtt:K<-)xQ:. 


J  U  K 


T>  ft 

-J  OC 


o' 

UJ 


U  U  U  (.  T3 
T>f-f-(-OC(.f- 

jcca;x<‘)’) 


JK*). 


*4 

O 

ft 

Oi 

n 

ft” 

n 

-0 

ffi 

O' 

O' 

4* 

b 

ft 

4» 

4* 

4* 

4* 

4> 

4* 

4* 

4* 

4* 

ft 

ft 

c 

ft 

ft 

ft 

ft 

ft 

ft 

ft 

ft 

ft 

-  CL 

M 

0 

-  Q. 

■.  OL 

-  0L 

-  CL 

-  OL 

Q. 

-  (L 

-  0. 

(L 

ntD-ONOO‘QHmnt«oMDihOHNP)tinoMDa-OHrtntinoNa)i>OHnir)«ftON®j'OH(nntfiONfflO' 

ft-<ft,ft-ft-ft,ft-^^r>n^r)rntfjr)^)<i<!O~0>0'C'0'0'0NNNrvr^rvrvfvf>vr^(D©a)CDCDCDaDa)QDCD(h(h(h0‘i>a‘^ch(>0' 

ft-ftftft-ft-ft-ft-ft-ftft-ft-ft-ft-ftft-ftft-ftft-ft-ft-ft-ft-ft-ftft-ft-ft-ft-ft-ft-ft-ft-ft-ftft-ft-ft-ftft-ft-ftft’ft-ft-ftftftftft-ft-ft-ftft-ft-ft-ft 

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo 


n  O'  S 

UJ  0  ^ 

ujuju.onu.Q'0~4 

CDCDCDODODDODGDCO 

H  H  *4  H  »i  *4  H  H 

7D 

OF 

OF 

OF 

AC 

E601 

2002 

AF 

C9 

3EFF 

C9 

O  O' 
n  0 

3EAA 

C9 

O  U.  O' 

N  01  0 

r> 

m 

UJ  O' 

n  0 

0331 

0332 

0333 

0335 

0337 

0339 

033B 

033D 

033F 

0341 

0343 

0345 

NOO'<OUUJOHp(t 

nnnnnnnnnnn 

00000000000 

K2 

n  n 

0  0 

0357 

0359 

035A 

035B 

035C 

Q  u. 
«  m 
n  n 
0  0 

h  N  N 
O  UJ  UJ 
au.u.u.O'Oaai 

NOOO<UIMh 


o-ryn^^NO- 

nnnnnnnn 

oooooooo 


m 

m 

0 

0 

0 

r) 

ft-  OJ 

OJ 

n 

O  OJ 

OJ 

0 

QIlO< 

o*  < 

k  n  n 

0  rt 

a  o  Q  u.  im  n 

O  O  O  -0  N  N 

n  h  n  n  n  c*) 
o  o  o  o  o  o 


28 

74 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


(.  +  >  t.  e  u 

o  >  t-  m  4* 

+*  +  m  ft  ft  .c  c  c 

u  *>  i~  4*  u  u  o  m 

m  -i  a.  urn 

*■  -o  m  ^  u-  *•  *> 

■c  (.  *  +  (. 

•  ft  4*  m  ft  £.  m  « 

I  W  £.  4*  3  4* 

T3  ft  3  U  «*-  O  O'  ft 

13  4*  -«  C  ft 

1  ft-  ft  ft  4*  ft  4»  I. 

h  Oft  C4»  C 
-O  o  4*  3  H  V  H  -D 

I’OftftftOKftt.C 

ft^E’ouftoia.ft 


■■* 

n 

•*“*•*»  - 

ft 

n 

1-  CM 

c 

t- 

4*  t- 

(- 

4*  -• 

C  4* 

H  ' 

3 

C  ♦ 

UJ  c 

c-  N  C- 

4* 

UJ  ' 

.  .  u  I  « 

4J  .  -*J 

-  u. 

o  <  .  it. 

c  -  o  c 

(- 

O  ' 

Z  '  U(hOJJUNUJ<uUJ 

.0.0 
<  O  <  O 


TJ  “O  U  4* 

■  a.f.'oCf-'Oftftf.* 


■o  ft  -o  ft  ft 

JUJUK 


iNDDO'O^runftr  • 

>^*«-«cmcmcmcmcmcmc 

!§SSSSSS2Si 


iMD^Onnint  ft^MDO*! 
imoifiinnnnnnnnnn' 

2S22S2;S§S2S;§3; 


CM  Ml 

J  -  CM 

^  ft-  5 

5  ft  o 

CD  UJ  C 

5  uj  m 

n  u.  r 

o  u.  n 

r  it  il  h 

a  n  n  <j 


^nftN>BQitOHOinnN< 

ooooooooooooooo 


-0  *0 

o  o 

Q  U.  <  U. 
ONON 
LJQUQth 

n  o  n  o  o 


uiiinno 
u.  u.  o  o  o 

n  ft  «e  ft  ft 

o  o  o  o  o 


0!  ?  2  £*  P  P  <  Q  p  ft  cm  uj  n  n  ft  n -o  cm  u.  cm  o  ft  ft  n 

OMKNNNCl  >0  OiN  NOD  44NON  O  <l  CM  N  ft  O 

^Ha-nO'QOOCio-n  r>  l  uj  ft«4f>u.(hoaor>Oft  ft 

O'ON'ON-CfCPXNN  O  O  ftl  NOOO-OCMOCMOCMN  N 

ocM(Mi>nr>omQrMBOOO*CMOuiocMOOftM>chftu.n  uj 
ft  N  N  vO  N  >0  CM  ft  ft  N  O  CM  N  O  H  O  O  CM  N  01  O  N  <1  K  N  O  N  O 
<^i^Qu^ftOQou^ftOon°ft^rMftr)onQCMChft^Qr5 
OOOftONCMCMCMO*>CMCM  x  - -  *  ‘  ‘  - - * 


n  ft  n  -o  cm 

O  O  N  O  N 

ft  *i  U.  0-  < 

N'O’O'O'OC 


NCMOftNOM 

CM 


INONNNOOft 


ft  ft 

4*  4*  O- 

c  ^  u. 

3  -O  | 

O  ft 


£  •**  -  I  L- 

•  »  •  (-  O 

■c  •  ft  O  ft  O  4* 

u  C  ^  C  9  ft-  ft  . 


»-  ft 
ft  Ol  (. 

4*  4*  C  ft 

ft-  c*  C  -44  4* 

•*  C  3  4*  ft 

C.  O  »-  •*« 

ft  4*  U  ft  Ol 

ft-  >  ft 

4*  4*  (-  C  f- 

C  £  C  ft  O  4* 

ftf-*ft4*Uft  * 
€  •  f  u  *-  * 
•  4>~4ftft~HOft 
»-  C  ^  »-  t-  ~4  4* 
US-^Uftfift-O 
ft04*ft£4*ftC 
TJCIft-OUftf-ft 


ft  O  I  I  O  '  .J 


U 

iz%i 


3  3  3  C  C  C  -O 
(L  O.  Ql  h  m  h  j 


-o  C  a  (.  T)  -O  TJ  ft 
JQ 


It’OtU'OtTJli 

IOJCJJKJQ 


a  &  o.4> 
u  o  O  O  ft 
“>  0.  Q.  0.  K 


il8llssssssssss§aSSassaSS8i:;!3!8"SS!:5S?;5?3!!??;j5n8sassRs 

>000000000000000000000000000000000000000000000000000 


r*  il 

!!s8S8 


ON  CD  Ch  <  O  U. 

N  N  Is  N  N  N  N 

pi  n  n  n  n  o  n 

o  o  o  o  o  o  o 


S  &S3S8 

nr)M)nnnoch-ouj(pooNB 

UiQU(M(MlM*<NbJltnuuN(M 

ft 

o 

UJNOItMMLLQ 

N 

u. 

o  « 

8  -4  -4  -4  O' 

CM  *-« 

CM  O  Q  UJ  O 

|||888^p8lRfi8 

OOOOOOOOOOOOOOO 

nMDO'<BJUQUJ 

ooooooooo 

y 

o  o 

03A2 

03A4 

03A5 

03A6 

03A7 

Dr.  Dobb’s  Journal,  Number  52,  February  1981 


(continued  on  the  top  of  page  28)  I  (continued  on  the  next  page) 


(- 

o 


4» 

c 


tj  «*-  ~ 

C  -h  O  4* 

•  t-  m 

-'  ft  4* 

MUM  * 

3  U  •  < 

4>  <  i  ~  <  ■ 

n  u  %  * 

c  u  m  <  u  - 

•  H  U 
^  < 

ft 

~  c 

o  m  f-  JZ 

•  3  « 

C  U  4*  3  T3  T3  ' 

O  ft  ft  Q.  _J  _J  . 

U  i.  L 


0 

E 

CM 

n 

O' 

O'  O' 

O' 

O 

0  ,0 

•0 

0 

0  0 

0 

ChOO'ChChOOOOOCOOOOO-'^^-H^^^ 

ooooooooooooooooooooooo 


on^nn  unnonu 

ni-0  >0  NN  -ONOniNW 

n  m3 

K  N  O  h*-  O  O  O  CM  O  O  N 


O  N  N  N  O  O 
OOlftOOO 

cm  n  o  n  cm  cm 


uj  <  n  (h  n  m 
o  n  o  o  n  <o 
N  N  O  f  O  ^ 
N  O  N  N  CM  N 


ssssss  S3Rf!:§ 

nn3S|8S|SS5R  %'*£%$££  3!U3!S!28$3S!}iS 

328£8P?8ES:3S§3S38;i£!lJS85;S8?!!S!£3!i85{?3 


o  o  <r  r> 
'OOINO 
o  m3  n  ^  a 
•O-ONNO 
•  O'  cm  a  u.  lu  o 


a  < 

S  N  CD  O' 
u  to  cm  u 


OMU 
m  r  in  m 
o  o  o  o 
o  o  o  o 


0 

0 

n 

r> 

CD 

CM 

0 

0 

N 

O 

<n  <  u_ 

< 

N  Q  0 

O 

u  n  ^ 

n 

<  w  < 

CM 

Q  LU  -  CM  M3  O  CD  O' 

On<MMMM)  O 

o  o  o  o  o  o  o  o 

ooooooo  o 


TJ  4-  « 

TJ  j*  O  * 

ft  ^  c- 

1  Q  TJ 
ft  4*  z  T5 

4*  ft  <  ft 

9  ft 

OH  a 
ft  t-  ft  C 

4*  ft  U  U  H 

ft  4*  HH 

U-  4»  at  H 

H  O  H  O  ft 

4  4>  h  4. 


xa 

A 

XI 

X 

a 

X 

•0  3  3  xa 

■a 

A 

X 

XJ 

X 

1 

4J  3 

Q 

a 

0 

0 

a 

Q 

Q  Q  Q  Q 

O 

O 

O 

O 

a 

Q 

a 

O  O 

*H 

CM 

n 

<r 

m 

CM 

n 

CM 

M3 

CM 

n 

+ 

T> 

"O 

TJ 

TJ 

TJ 

TJ  ft  «*-  » 

at 

01 

at 

at 

01 

Oft 

“»  Ji 

6 

8 

E 

E 

E 

E  E  E  E 

E 

E 

E 

E 

E 

s 

E 

E  E 

ft 

ft 

ft 

ft 

ft 

ft  ft  ft  ft 

ft 

ft 

ft 

ft 

ft 

ft 

ft 

ft  ft 

E 

E 

E 

E 

E 

E  E  E  E 

E 

E 

E 

E 

E 

E 

E 

E  E 

O' 

O 

*H 

CM 

n 

+ 

«  O  N  QO 

O' 

O 

CM 

n 

* 

M3 

0  n  a)  O' 

m 

in 

n 

m 

m 

M3  m  m  in 

M3 

O 

O 

O 

0 

O 

OOOOO 

O 

*0 

0 

<i 

0 

0 

-00-00 

O 

O 

*0 

O 

0 

O 

OOOOO 

O 

0 

O 

0 

0 

0 

OOOO 

O 

O 

O 

O 

0 

O 

OOOOO 

^non  u.  cm  o  +  <  rto^Hoi  o*n  o  q  o  m  *•  *•  o  <  *■  cm  n  *  M3  m3  cm  *■  *  *  cm  * 

O  h*  O  h*  OOWNn  K  n  CM  >0  N  CM  1^  CM  H  CM  O  (M  (M  ift  H  CM  I"'  CM  O  fv  CM  O  CM  N  CM 

M3  u.  a  o  m  o  «t  *  n *  o  m  o  w  <r  o  cm  o  o  Q  «■  *  o  n  «r  M3  cm  «t  n  o  u.  o  *■  u  *  u.  «* 

o  o  o  o  o  cm  o  CM  h-  o  n  cm  m  o  cm  o  n  cm  n  cm  n  o  cm  cm  cm  k  cm  *  n  cm  *  cm  o  cm  cm  *0  cm  «*■  cm 

OfMOoOM30'*u.n  t  ntoMQMnuj  *t  \l  +  &  oootton  <ou.o<rowcM<*  -«  o  «t  o  o  *  o  u. 

r^CM'ON'ONN'ON  ■ONCMlMh'nCM'O'O  CM  O  CM  N  CM  O  O  CM  CM  CM  N  CMCMOCMCMCMCMf^HCM  «t  CM  CM  CM  CM  CM  O  U. 

N^notQ(MCh^iftQHft^o^iu^ninQ^a)^MQOOO^QtHO'rocM<»toQtMn^oo<^04<QO  uju. 

N'OMMN'ONNN'OOt'OCMlMN'OCM^’OnCMiOCMiftniMOOtMrttM'OnUMCMNntMtM-ONhClItMOnCMninniOO  Ul  ll. 


CM  O  *  CM  o^n 
NHCM'ON  CMf^l^ 
*  o  <*  o  m  o  w  <* 

O  N  CM  I DO  CM  -ON 
tn’roMQ^u.aj 


Q  O  CM  t 
O  Q  Q  Q 


q  o  cm  n 

^  CM  CM  CM 

M3  m  ir>  in 

o  o  00 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


oao-nomcMtunimo'Qnooo'rr-.onfr 

jniiBL.-flDonimii.Nrxnnrio*’ 

n'0'0nno»-Nii(»»*<)n«i<inno< 

ooooooooooooooooooooo 


>  n  > 

5  «  o  8s  z  «  i 

UUUQUIlii 


'OOiLOQn«<oiLiiJtnoNiLNnoO‘H 

o<NfflUjQnou.p53uuHfli^wfi<onio 

Hrt'OnnniHHHfiitttrjnn'Onnno 

ooooooooooooooooooooo 


jtooonnuQoociDiciM-i* 
It-CtEE  E  ttr  EtE£hl-h< 


<  <  <  Q 

CL  CL  CL  H 


•  •  u  o  » 

~  «  >-  m  <J  ~  ~ 

yit  *  *  * . ilui 

CQ  <  <  U  <  (D  <<  M  <  (J  «  ~  I 


CL  4*  0.-0  4* 

0*TJ-0C0CO» 

a.o:JjMQ.<ua: 


*  * 

3  3  W 
CL  CL  J  J  . 


-O  Q.  *»  O  4*  3  T> 

CC  (-  T>  T3  O  3  O  *  O*  c 
*-««  ">  j  ja.oo.ir  UiUJ 


ncD-ouD'ftU'Mionio^HnQcQiDNnoo 

O0‘nu.QrtH<wnt(pQHtta-oNnmDin 

HPMmnp)HHHf(t^4r)ftft<nnnor) 

oooooooooooooooooooooo 

tn 

h-  ^4  «o  on  o  o  tn 

<  m  lurihOQniniDQOo  Jo:>H4)h  o 
K<3Jh-0:£tEEEEEEEEE(-h(-Ua: 
wi~acza:uiUjiuwLiUJUJUJLiUJUJ<<«cnuj 
»UUUlUIUE£EEEEE£CEELa.Q.hN 


3 

O 

-  -  -  o 


MSthO^nn^n'OMDiho^ntntnoNCDiho^nntinoNffliho^n 

oooooooooooooooooooooooooooooooooooo 


n^QQ<(hNno^Nu.nifl9no^rvQnon 

OO'OOOOOOarxOftQOrXOQftXiNOO 

Hn-oonriiHHHNtttnninnnnf)HO 

OOOOOOOOOOOOOOOOOOOOOO 

n 

n  ^  n  n  rx  rx  ^  ^ 

<  -•  ce  cm  O  rx  D  <  Q  II  O  *  O  I>  -4  X3  O'  O  h- 

Q  <  CX  ha:EEEEEEEEEEEHhh<2 
KZ*-«Q:zo:ujiiJUJUJUJUJiiJUJUJiiJUi<<<»-o 
»UUUUIUEEEEEEEEEEELILa.U)3 


o 

2  ° 

o  o 

o 

O'  o 

ft  ©  lL  03 

O  Ui 

n  *o 

0 

03  ft  O' 

O'  o 

O  N  N  h 

o  -• 

o  o 

N 

Ul  O  N 

O  *4 

-*0'<IlQ-4>0UJO 

-  n 

X)  X) 

<  lL  <  N 

Q  O 

CD  <  U.  -4  Q  -•  O' 

o  o 

uunftiuuiuiLU 

n  o 

U  IL 

n  ft  n  ft 

UJ  < 

rx  n  ft  il  uj  o  o 

moao-nftO0 

O'  o 

IL  O 

*4  ft  X)  © 

O'  03 

uujHfxnn-o 

N 

OOONNNNKN 

N  h* 

N  0 

©000 

©  © 

0  0  O'  O'  O'  O'  O' 

O' 

OOOOOOOOO 

O  O 

O  O 

0  0-00 

O  O 

o  o  o  o  o  o  o 

o 

ooooooooo 

o  o 

O  O 

o  o  o  o 

o  o 

o  o  o  o  o  o  o 

o 

xiDOOQn<<<o<Hoonoii.N<a)00 

oaxiOBinosQH<45ori'Ounnt)to 

Hn-oonriOHH^ni^tnnnnnnnoo 

oooooooooooooooooooooo 


**  «*-  c  *» 

9  E  o  m  * 
•o  •  a  L 

*»  m  •  •* 

4*  *  4*  43  «*- 
ft  9  9 
U  ft  jO  CM  ft 

-4  cm 

•4-  C*  4* 

C  ft  4>  -O 
«*-  -*4  (.  ft  ft 

O  4>  •-«  ft  « 

ft  **-  4*  3 

*  L 

ft  ft  *4  ft  E 

•  a.  m  c-  ft 

L  O  3  O  L 

■o  4>  «*-  a» 
TJ  «4-  U  ft  O 

ft  O  ft  43  t- 


ft 

X) 

O  1". 

© 

N 

N 

N  N 

N 

o 

o 

o  o 

o 

o 

o 

o  o 

o 

O' 

•  •  m 

ZEE 

o  -4  rx  n  ft 

X) 

m 

E 

o 

• 

E 

K 

N 

0  0  0  03  0 

© 

© 

0 

O 

o  o  o  o  o 

o 

o 

O 

O 

o  o  o  o  o 

o 

o 

o 

iLin  ft  «  rx  n  nou.u.oo>  o  ft  Q  rx  uj  O'  q  ft  m  q  n  n  r>  w 

O  O  NNNN  N  rx  -0  -O  (X  N  N  fs  O  N  O  N  O  N  O  O  O  O  N  O  CX 

4-  ^  o  ft  rx  ft  u  u  m  o  ft  n  o-  n  m  nihOft  n  O'  n  ft 

•p  £■  O  O  O  N  N  N  N  N  O  O  *0  CX  N  •O-ON'O  N  MX  N  N  O  O  >0 

rx  QQOu.oQiijrxo^ujOQftr)  o  ft  o  ft  nu.oujox3oujir>  o 
ft’O  D'Orx^rxn'ONrX'O'OninNN  n  mx  n  oorxocxorxoo  o 
«t9il5l(J[||yS(,k,f)N^,i-0,R&,,ooll'H^,,,0^M^Hyw^oftQo 
O'OOft'O'OMXn-OONN-Onit'O'OOt'O'ONrX'ON'O'fl'ONMX'OOO 


o  o  rx  n  o  o  ft 

WNNSCX-ON 
ft  o  n  o  ft  o  n 
o  rx  o  rx  o  rx  n 
uj  o  il  q  x)  n  rx 
O  O  O  O  O  N  N 


rx  o  ft  o  ft 

n  rx  n  rx  rx 

ft  n  o  ft  ft 

ONfXN  CX 

ftnunoft 

'ON'OMXW 


o  *>u.rx^n»40‘0'4«ftx30ftox>rx 
O  ft  'ON'ON'O'OCX'O'ON'OnCXOftN 


2 

(X 

o 

©  O' 

< 

rx 

n 

ft 

X) 

O  <0 

N 

X3 

X) 

X) 

X) 

r>  x) 

x> 

o 

o 

o 

o 

o  o 

o 

Dr.  Dobb’s  Journal,  Number  52,  February  1981 


31 

77 


\\ 

«  « 


co 

i* 


u 

•« 

Eh 

CO 

a 

3 

o 

•» 

CO 

X 

Eh 

—  CO 

« 

Z 

Eh 

CO 

CO 

Z 

O 

Z  - 

u 

• 

z 

z 

Z 

M 

•-  Eh  •- 

u 

X 

Z  K 

Eh 

< 

Eh 

X  M  < 

< 

o  • 

<  u  u 

Eh 

<  CO 

X 

X  —  X 

CO  • 

•J 

O 

U  CO 

X 

X  < 

u  o 

<  U 

U  u 

CO 

—  X  ~ 

< 

Eh  O 

U 

<  — 

O  Eh 

Z  3 

X 

O  Eh  b 

Q  CO 

M 

X 

X  U  CO 

O  U 

Eh 

<  o  o 

«  X 

x  a 

•  Eh  —  X 

\  3 

< 

<  oc  O  — 

*  U  — ~*X 

SK  nu 

—  CQ 

U  CO  ~  -Z 
X  Eh  •«*  b  3 


-£! 


U  Z  b  MO 
UDQii  Z 

Q2£~2 
X  <  U  X  * 
U  BUB 

CO  U  —  H  — 
3  CO  < 

o  x  r  os 
h  i  u  <  O 
UHh  w06 


z 
< 
— *  u 
Z  J 

os  u 

3 

H  * 
b3  X 
OS  M 
H  x 

CO  CO 


—  Z  ~ 
OS  O 

—  3  — 


U  U 
<  Eh 
H  < 

w8 
fr>  *J 
U  _J 
CO  < 

u  u 
x  a 


•j 

< 

g 

3 

U 

X 

H 

Z 

M 

X 

X 

H 

z 

u  • 
H 
z  z 

<  u 
X 

CO  3 
Q  O 
Q  X 

<  < 


-3  <  X 

—  Eh 

3 

U  Eh 

Z  X  u 

u  X  - 

Eh 

u 

z 

*  <  M  — 

Eh  X  Eh 

X 

X 

B  J 

o  — 

Z  CO  — 

< 

< 

o 

z  u  u 

u  <  a 

Eh 

•J 

Z  CD 

X  CO  CO 

Z  O  Eh 

CO 

u 

o  z 

«  «  H  J  J 

U  «  z  U 

u 

X  >H 

w— u  u  — 

Eh  OC  ~ 

■ 

Q 

X  CO 

< 

•• 

Eh 

O  X 

a 

CO 

H 

u 

— 

1  X 

J 

u 

•J 

X 

X  o 

< 

M 

CO  J'*' 

u 

u  a  i 

X 

CO 

z  u 

CO 

M  Z 

u 

Eh  < 

X 

• 

3  Z 

• 

a 

CO 

O 

z 

a  - 

u 

X  X  I 

u 

<  X 

X 

U  1 

h 

Eh 

>H 

CO  <  1 

Eh 

-  X 

Eh 

M  U  1 

u  o 

X  1 

X 

Z  X 

Eh 

Eh  X 

s 

<  < 

Z 

O  U 

z  « 

u 

8  X  1 

X 

3 

z 

U 

<  - 

3 

z  u 

X 

u  u 

o 

3  J 

-3 

u 

X 

X  CO  u 

J  - 

H 

U 

•J 

X 

X 

o 

u 

z 

o 

H 

U 

z 


\ 

w 

\ 

« 

«  « 

-* 

B 

"7 

B 

z 

X 

u 

u 

• 

u 

Eh 

CO 

z 

Eh 

—  p 

t-H 

Z 

^  X  u 

o 

u 

—  U  CO 

X 

z 

Eh 

3 

u  z  x 

CO 

u 

Z  M  X 

< 

X 

<03 

-c 

Z  X  Eh 

X 

-3  CO 

X 

u 

J  < 

Eh 

X 

M  J 

z 

o 

Eh  a 

u 

z 

< 

o 

-  a 

o 

CO  X 

K  Q 

z 

H  M  HH  — * 

<  < 

1  X- 

U 

« 

«  CO  — . 

X  « 

u 

Eh 

Z  •' 
Z  M  u 

x  o  a 

D  a  CD 
Eh  < 
U  ■  M 
X  X 
n  < 
—  > 


i  — 


\\\\\' 


-UK 
Q.  N  h 
O  H  CO 
H  CO  O 
o  u  X 
X  Z  <  C 
<  <  —  * 
Z  I  H- 

-•o  z  x 
E->  O  U 
—  HXhJ 
H  H  Z  <  O  M 
—  Z  M  I  x  X 
M  —  U  <  * 

2 

< 

H 

U 

vO 


X  —  U 
Eh  CO 
COX  J 

o  u  u 
X  H 

ss 


U  I 

>  X  —  u 
<  b  H  J 

Z-'MM 


X 

o 


CO 

co 

X 

a 

a 

< 


x 

Eh 


H 

U  v 

CO  V 


O  u"> 


\  -  —'V  •  ffl\ 


X  — 

to  u  — 

X  Eh  —  Eh 

<  Z  CO 

Z  H  U  Q 

X  O  H  Z 

X  X  X  U  — 

to  X  —  X 

<  z  u 

I  —  M  X  E-« 

•— (0  w  H  z 


_2 
u  < 
X  — 
< 


o 

r>  i 

co  • 

•J  U  I  H  x 

M  X  O 

<  <  ~  H 

Eh  Z  Eh  O 

U  Z  —  X 
a  co  co  co  < 

i  a  x 

Z  H  M  X  N 
m  —  E-* 

X  —CO 
Q  Eh  x  CO 
a  X  Eh  u 

<  O  X  X 

X  o  Q 
«  «  <  x  a 
w—  <  < 


CN 

*•  CO 

—  »-co 

H  CO  u 
+  CO  X 
EH  U  O 

u  x  a 
co  a  < 
x  a 

X  <  N 

o 

—  N  — 
X  rH 

Eh  —  ♦ 
X  Eh  Eh 
o  u  u 

X  CO  CO 

<  X  X 

—  X  X 

~o  o 

X  X 

22 

< 


Eh  b 
CO  —  - 
O  — B 
X  —  — 


<  x  «  Z 

t-3  M 

3 

Eh  X 

o  u  \- 

•-3  <—  <  — 

u 

—  1  CO  U 

U  Eh 

K9 

Q  Eh 

•J  < 

U 

K  Z  < 

—  z 

•J 

Eh  U  Z 

CO  —  — 
O 

X  X 

X 

XXX 

M  hH 

t-H 

<  HH  M. 

NNN\\ 


« 


SG 

£ 

CO  z 

Eh  O 
Z  w 
U  Eh 

Z  < 

3 

3  X 

O 

^  "5 

X 

X  3 
<  U 

U 

X  Q 

z 

H 

.  3C  U 
U  3  X 
3  Q  X 

CD  Eh 

o 

X 

-3  O  U 

<  X 

o 

M  CO  Eh 

Eh  CO 

H-t 

Z  CO  X 

C3 

CO  CO  O 

Eh  U 

"a 

oxo 
X  Q  z 

E 

a  m 

<  <  Q 

o 

< 

u 

u  u  u 
Eh  X  X 

X 

<  Eh 

O 

a> 

o  z 

H  CO  O 

i-H 

Eh  CO  m 

t 

CO  Z  Eh 

o 

> 

CO  M  u 

0) 

>  i;  z 

X 

Z  x  3 

c 

MUX 

•— 

u 

Eh 

(1> 

O  u  U 

OS 

<-H 

Eh  O  X 

o 

•H 

Eh 

Z 

a 

U  Eh 

Eh 

e 

J  < 

0 

X  X 

» 

u 

z  z 

U 

< 

z 

u 

X  u 

O 

1 

U  M 

— 

i-H 

i-H 

<TJ 

EH  •• 

E 

CO  M 

to 

«  «  «  « 

*  U  Eh 

\  \  \  \ 

\Eh  CO 

U 

•» 

•-  •«  •*  •- 

•»  •-  Eh 

Eh 

Z 


O  O 

X  -  -XU 
Eh  O  I  CO  U  X 


•  S 


Eh 

Z 


> 


o 

-XU 


i  co  u  a  u 


J  Z  J  J 

^hQ  J(OhQ  JXiJ 
X<<3X<<0< 
3JQUXJOUXU 


Eh  Eh 

z  z  > 

M  t-H  I-H 

U  fN  o  ^  o  o 
z  -  -XU  -XU  u 

OOXC0UXXC0UOU 

Eh 

o 

-g 

O  iJX  J  «-3 

ZVmQJCOmQJXJ 

U 

« 

H  X<<3X<<0< 

X 

u 

UJOUXJQUXU 

z 

Eh  Z 

o 

z  o 

w 

M  — 

« 

fM 

Eh  •• 
CO  CN 
U  Eh 

u 

•%  •«  •%  Eh  •-  •- 


Z 

o 


o 

u 

Eh  Q 
U  Z  Z 
X  M  U 

CO 

-  X 

o 

X 

X 


32 

78 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


ERROR  ("EXPECTING  ARGUMENT  NAME") 


c 

X  o 

o 

z 

•  z  u 

'■C 

O  3  X 

£ 

3  O  >< 

CD  H 

a 

£ 

Du 

JOU 
<  I 

►h  CD  E- 

o 

H  03 

U 

z  co  os 
u  wo 

E-*  U 

o 

O  os  o 

t 

04  o  z 

O  H- 
<  <  Q 

o 

V 

04 

ATE 

THE 

HEA 

CJ  2 
H  WO 

Eh  03  •—» 

WZH 

> 

03  h  CJ 

V 

>  Z  2 

OS 

2  X  3 
m  U  Lu 

>  ht  O  Q 

>  -  x  cj  c j 

)  I  I  (/]  U  Q  U 


03  nr  O  CJ  Q 

2  -  X  CJ  »  X  U  CJ 

OOIUIUIII/IUQU 


1  X  J  J 

JWmQ  Jfl,  J 

:  o  x  -t  <  o  < 

)Q<  JQUbU 


O  JX  J  3 

I\hQ  JMhQ  JO,  J 

H  X<<Z5X<<0< 
UJQU&i  JQU&U 
H  2 
2  O 


2 

03  «.  CD 

Q 

o 

3  ^  < 

___ 

O 

Z  3 

03  Z 

O 

3  04 

<  '-'  X 

z 

cu 

X 

•* 

H  03 

4-* 

O 

X 

• 

•  O4  •  ►H 

■ 

03 

z 

< 

3 

CL 

< 

* 

3  a  03  03  03  3 

z 

Ch 

3 

z 

X 

z 

0  z  z  a  z  as 

03 

as 

z 

c 

Ci3  Z 

0 

CO  — '  <  *-H  <  < 

x 

03  CD  — 

0 

Q 

X  o 

►H 

Z  Z  E-  Z  03 

•  < 

CD  CJ  ••  X 

CJ 

, 

<  *-• 

Xb.  3 

2  X 

z  a  — *  £h 

B 

•  X 

u 

Z  CD 

< 

CD  03  H  3  H  CD 

0 

*-h  <  •  Z  CD 

s 

< 

< 

0  03 

as 

as 

O  <  Z  <  < 

Z  -  •  Z 

CD  w  O 

03  • 

z 

03  Eh 

u 

O  03 

< 

Z  t-i  z  Z  2 

.  03 

cd  eh  .  a  a  .. 

Z  CD 

03 

z 

Eh  z 

• 

H  > 

3  • 

Hhh-h 

Z  Z  CD  Ou 

03  Z  Eh  OO.  <  CN 

<  O 

CO 

0 

03  *-h 

53 

CJ  03 

3  Z  E- 

OOOO 

Z  3  Z  O  03 

2  O 

4—. 

CJ 

3  O 

w 

CD  Q 

03  Z 

X  3  >-  O  >«  < 

*-<  •“•  a 

•"•  0  3  2  0  -  ♦ 

O 

O  O 

03  X 

03  03 

O  — 

Q  Z  CD  >-h  CO  Z 

Eh  H  <  O 

3  CJ  O  H-c  0 

Eh  2 

3 

0 

O 

E 

M  M 

3 

<  H  2 

CJ  CJ  z 

CD  CJ  3  Eh  X 

Z 

3  N  — 

03 

X 

OS  04 

as 

03  —  03  CJ  Z  —  • 

z  z  a  »-i 

O  0  Z  0.  3  -  Eh 

03  3 

O  »  Of- 

CJ  cj 

E-  *-» 

O  03 

0SZ3ZOZ03Z 

3  3  O  CD 

2  0  03  CJ  3  O  CD 

z  a. 

z 

CJ 

0  < 

Im 

o 

H 

3OC03^O>O 

Cl.  Cl.  Cl.  CD 

Eh  O  Z  OS  Z  O 

3 

CD  ^  N 

03 

3  Eh 

o 

03  O 

z  < 

<h<04Hh<h 

2  «  Eh  <  *  as 

0 

*  N 

a. 

Eh  CD 

Z  Z 

0  0 

H  *h  CJ  H  Z  H 

<  -Z  Z 

Eh  •  Z  < 

as 

X 

X 

►-< 

*— 1  t— 1 

«  CJ  X  N  Z  CJ  CJ 

H  03  ■ 

3  Z  «  CD  a  —  — 

<  • 

ZP4S 

03 

<  Eh 

a> 

H 

H  3 

\  Z  <  N  3Z03Z 

CD  Z  OS  — 

•  04  3  \  04  03  Z  N 

z 

03  B 

B 

Eh  03 

•a 

3 

O  < 

3  >  O4  3  2  3 

<  *■<  < 

a  0  z  m  ~  u 

3  O 

a  -  * 

w 

CD  CD 

o  • 

Z  > 

X  «— ^  O4  O4 

cj  a-  a 

03  «  CJ  3  Cl.  Ox 

<  *-< 

<  OS  B 

03 

o 

as  cd 

3  Z 

<  H  <  03 

03  0 

Eh  \  CO  CJ  3  Eh 

O  Eh 

a*  Eh  — 

X 

X 

O  X 

u 

2 

O4  *-h 

N  03  N  CD  < 

z  '  z  as 

2  0  O  O  O  CD 

03  < 

a. 

0 

< 

Eh  X 

CD  O 

—  X  CD  X  M 

wZOJfl! 

»-<  OS  4^03^0  3  QO 

3  CJ 

O  3  Z  OS 

03 

a> 

►h  3 

•»  3  * 

QCuQ-3« 

O.  O  0.  03  • 

O  <  O  z  ^  Z  Q  <  OC 

3  w 

z  +  cj  as 

X 

X  « 

> 

Z  3 

OS  <  \ 

—  —  <&4<H0S\ 

03  W  O  03 

o.  <  Z  z  — -  < 

t-c  O. 

►H  03  Eh 

03 

CQ 

Eh  \ 

H  O 

H  —  CJ 

—*  H  03  0  03  03  03 

Q  H  ~  Z 

Eh  N  Z  *-i 

B  »-H 

CD  Z  < 

X 

O4 

04  O  03 

z  z  as  —  as  CD  z 

CJ  03  O  < 

X  *— «  H  ,  X  O, 

w  Q 

O  »-<  Z 

CJ 

o 

■ 

*  3 

03  3  as  3  Ol  H 

*  2  03  Z 

CJ  Z  3  W  03  - 

O 

3  3^ 

__ 

5 

a> 

03  H 

N  3 

□  <£•<040 

03  S3  CD  N 

<.*t-i^<^H  03 

a  z 

CJ 

>_ 

3 

H  * 

CD  < 

*  N  H-* 

CO  *H  CO  0 

3  0.  N  Z 

Eh  CJ  b  O  Cl.  CD 

0 

Du 

t-  z 

as  z 

4—*  B 

3  ~  •*  *  ■ — « 

CO  a  0 

CD  O  *  —  03  *  *-c  3 

as  o.  — 

f-  Oh 

Eh 

E- 

O  o 

<  2 

03  »-% 

C5  as  \  \  os  \ 

<  «■  03  ^  *-H 

3  \b  3  03 

—  as  0  ~ 

O  03- 

03 

03 

Cj  ^ 

04 

C*9  Z  •» 

QH  a.  h 

H  Z  E-*  ■  Eh 

3  Eh  ^  >. 

03 

Z  X 

a 

CD  ^ 

B  Ol 

►h  ^  a  z 

Z  04  —  CO 

w  H  w  CJ 

<  as  X  £ 

*— •  Q  CD 

Eh 

z 

03  X 

U 

0 

cd  0  as 

►-4  — ' ’ 

Z  03  B  z 

CJ  <  Z  Z  >w- 

Z  X 

O.  CD 

03 

X  Eh 

Z 

z 

03  03  X  3  3 

O4  03  03 

*-«  cn  cn  — »  o 

O  Eh  •*  CJ  < 

03  03  Z 

t-H  — 

CD 

3 

0  H 

Z  Z  as  3  Eh 

X  CD  CD 

3  0.  — 

3  CD  O  Eh  U* 

CD  < 

O  O 

Cl4 

OS  3 

<  <  03  *-h  03 

n  *-  3  3 

HC3QZ  Z 

<  *  —• 

3  «  3 

«  O4 

X 

Eh  X 

O4  O 

z  z  *—  x  as  — ' 

03  03  . — 

OQ<CJEh  — 

OS  N  N  z  \  — 

03  \  CO 

HH  — 

-  < 

< 

•—  z 

as 

Z  Q  Z  Eh  Z 

<  — 

LO  •'  — ' 

O 

Z  X 

Eh 

<  <  h  as  4-. 

••03  05X 

a  0 

z 

03 

CD 

04 

O4  03  z  as  H  ^ 

—  3  H  Eh  03 

O  03 

*-H 

3 

— * 

as 

h  03  2  w  0.  CD 

—  U  O.  CD  3 

CJ  N  3 

cj 

•J 

< 

CD  H  3 

O  O  H 

HH 

u 

< 

Z  X 

Cl. 

«  3«  Cl.  *  D  O  3  «  O  Z  X 

«  X  z 

03 

CJ 

u 

z 

~  CJ 

M 

\OJ\h\OUZ\3<2 

\  CD  2 

2 

«  «  «  «  «  u 

,\W\\2 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


33 

79 


Software  Reviews 


DB.BAS  —  General  File  Maintenance 

(Revised  Version) 

Published  by  Holiday  Software 

4807  Arlene  Street 

San  Diego,  CA  92117 
Price:  $88.95 

Reviewed  by  Michael  Favitta 

DB.BAS  Ver.  2  is  Holiday  Soft¬ 
ware’s  new  release  of  their  general  file 
maintenance  package.  Those  of  you  who 
read  my  review  of  Version  1  in  Dr. 
Dobb’s  #47  know  I  thought  the  idea  was 
good,  but  the  package  was  not  what  1 
considered  complete.  It  also  contained 
some  serious  errors.  Ver.  2  of  DB.BAS 
has  corrected  those  errors  along  with 
adding  capabilities  which  were  lacking 
in  the  earlier  version. 

DB.BAS  is  a  set  of  CBASIC-2  pro¬ 
grams  which  allow  for  the  easy  creation 
and  maintenance  of  indexed  sequential 
files.  These  files  can  be  used  to  hold  the 
data  required  for  any  small  application 
where  random  access  to  data  records  is 
desired.  The  package  also  provides  the 
means  to  write  out  selected  data  records 
in  various  predetermined  or  user- 
specified  formats,  thus  giving  the  user  a 
limited  “query”  capability. 

The  package  requires  a  system  con¬ 
taining  at  least  40K  of  RAM,  one  or  more 
disk  drives,  the  CP/M  operating  system, 
and  CBASIC-2  Ver.  2.06.  The  amount  of 
available  memory  determines  the  maxi¬ 
mum  size  of  the  index  array,  which  in 
turn  limits  the  number  of  records  a  file 
may  contain.  A  40K  system  will  allow  up 
to  250  records  per  file. 

DB.BAS  commands  allow  you  to 
CREATE  files,  ADD  records  to  existing 
files,  CHANGE,  DELETE,  and  FIND  rec¬ 
ords  by  number  or  key,  to  create  secon¬ 
dary  key  INDEX  files,  APPEND  data 
files,  perform  a  USER  written  function, 
and  to  PRINT  all  or  select  groups  of 
records  at  the  console  or  printer.  The 
APPEND,  USER,  and  expanded  PRINT 
commands  are  new  additions  in  Ver.  2. 

The  APPEND  command  merges  some 
or  all  the  records  in  one  file  into  a  second 
file.  The  records  to  be  merged  may  be 
selected  by  matching  data  or  field  names 
in  a  record  with  those  present  in  the  out¬ 
put  file.  The  matching  routines  recognize 
special  characters  that  will  match  any 
digit,  any  alpha,  and  any  character.  If  no 
selection  criteria  is  chosen,  you  can 
blindly  move  records  into  the  output  file. 
This  feature  can  be  used  to  restructure 
your  data  files,  as  the  output  file  record 


34 

80 


description  need  not  match  that  of  the 
input  file.  When  using  selection  with 
matching  data  and  an  empty  output  file, 
you  may  create  files  containing  only  rec¬ 
ords  with  a  common  attribute. 

The  new  PRINT  command  allows 
groups  of  records  which  are  selected  by 
a  mechanism  similar  to  that  of  the 
APPEND  command  to  be  output  in  four 
different  formats.  A  horizontal  table,  a 
vertical  form  like  that  of  an  index  card,  a 
mailing  label,  and  any  form  the  user 
wants  to  provide  himself.  Column  head¬ 
ings  are  generated  automatically  from  rec¬ 
ord  field  names.  When  printing  mailing 
labels,  this  feature  is  suppressed  and  data 
from  fields  defined  as  non- label  at 
CREATE  time  will  not  be  printed.  These 
new  print  features  enhance  the  flexibility 
of  the  package  as  Ver.  1  could  only  dump 
records  in  the  index  card  format. 

Another  improvement  present  in 
Ver.  2  is  the  inclusion  of  a  memo  on  how 
to  get  help  if  you  encounter  a  program 
bug.  Since  Ver.  2  was  not  quite  perfect, 

I  took  Holiday  Software  up  on  their  of¬ 
fer  and  sent  them  documentation  on 
some  minor  bugs.  Their  response  was 
quick  (about  a  week)  and  complete,  pro¬ 
viding  both  an  explanation  and  a  fix  for 
each  problem.  One  should  note  that  even 
though  the  service  was  excellent,  fixing 
a  problem  would  be  quite  a  typing  effort, 
since  only  source  listings  are  available. 

DB.BAS  has  been  designed  to  be  easy 
to  use.  When  the  program  is  loaded,  a 
menu  listing  all  the  commands  is  dis¬ 
played.  Once  a  command  has  been  se¬ 
lected  from  the  main  menu,  the  menu  for 
that  command  is  displayed.  Whenever  a 
menu  isn’t  present,  you  are  guided  by  sys¬ 
tem  prompts.  The  interactive  nature  of 
this  product  is  what  I  consider  to  be  its 
greatest  strength.  A  comprehensive  user’s 
manual  is  also  supplied.  It  is  well- 
organized  and  contains  examples  of  how 
each  command  may  be  used.  All  data  files 
used  in  the  examples  are  provided  so  that 
the  examples  in  the  manual  may  be  used 
as  a  hands-on  tutorial. 

Holiday  Software’s  new  release  of 
DB.BAS  is  definitely  a  step  up  from  Ver. 

1.  New  and  enhanced  commands  round 
out  this  package  into  a  system  capable  of 
handling  data  files  from  creation  to  being 
sources  of  information.  If  the  size  of  your 
application  is  within  the  limits  set  by 
DB.BAS,  then  this  product  could  be  a 
cost-effective  approach  to  solving  your 
data  manipulation  problems. 


ZDM  FOR  CP/M  USERS 
Published  by  RD  Software 
1290  Monument  Street 
Pacific  Palisades,  CA  90272 
(213)454-8270 

Price:  $30.00  for  program  and  manual 
$  3.00  for  manual  alone 
Formats:  8 -inch  IBM  —  Micropolis  disk  — 
Northstar  Disk  —  Tapelib/Tarbell 
Reviewed  by  Gene  Head 

ZDM  is  a  Z-80  debugger  and  moni¬ 
tor  program  very  similar  to  the  debugger 
distributed  with  the  CP/M  operating  sys¬ 
tem,  DDT.  The  only  feature  found  in 
DDT  and  missing  in  ZDM  is  the  in-line  as¬ 
sembly  command  “A.”  Bob  Doolittle  of 
RD  Software  says  future  versions  of  ZDM 
will  have  this  feature.  He  also  noted  that 
the  actual  release  of  future  versions  will 
depend  on  the  response  given  to  this  edi¬ 
tion.  In-line  assembly  is  actually  a  poor 
description  for  the  “A”  command  in 
DDT.  In  reality,  it  is  in-line  patching 
using  mnemonics.  Assembly,  to  me,  im¬ 
plies  just  that,  ASSEMBLY.  When  I 
change  or  insert  a  line  of  source  code  and 
re -assemble  a  source  file,  everything  gets 
moved  and  shifted  appropriately.  With 
the  “A”  command  in  DDT,  I  am  merely 
patching  using  mnemonics.  No  actual  as¬ 
sembly  is  taking  place.  My  conclusion  is 
the  missing  “A”  command  in  ZDM  is  of 
little  serious  consequence. 

The  best  feature  of  ZDM  is  its  Z-80 
capability.  Additionally,  ZDM  surpasses 
DDT  in  the  following  areas: 

1.  Upon  initialization,  the  user  custom¬ 
izes  the  program  to  match  the  termi¬ 
nal’s  specifications. 

2.  Unlike  CP/M’s  DDT,  a  long  file  that 
would  overwrite  (and  crash)  DDT  is 
sensed  by  ZDM  and  an  error  message 
is  issued  while  preserving  ZDM.  This  is 
especially  useful  in  smaller- sized  sys¬ 
tems. 

3.  More  efficient  Z-80  code  reduces  the 
program  size  and  allows  one  more  full 
page  for  the  TPA. 

4.  ZDM  recognizes  both  upper-  and 
lower-case  keyboard  input. 

5.  ZDM  displays  extended  8080  mne¬ 
monics  similar  to  TDL’s. 

6.  Additional  commands  include: 

Display  and  alter  both  sets  of  Z-80 
registers  and  flags. 

Enable  or  disable  interrupts  when  en¬ 
tering  the  target  program. 

Read  from  an  input  port  and  write  to 
an  output  port. 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


HEX-MATH  for  computing  relative 
off-sets,  etc. 

I  utilized  the  ZDM  on  a  North  Star- 
based  Z-80  system.  It  worked  the  first 
time.  Initially,  I  didn’t  even  bother  to 
read  the  manual.  I  like  software  where 
the  user  is  prompted  intelligently,  and 
ZDM  passes  this  test.  After  PIPing  a  copy 
to  a  work  disk  (the  original  will  never 
have  the  write  protect  tab  removed, 
NEVER),  I  typed  ZDM.  It  signed  on  with 
the  request  to  enter  the  width  of  my  ter¬ 
minal  in  hex.  After  that,  the  number  of 
lines  was  requested.  After  these  para¬ 
meters  were  entered,  ZDM  politely  asks, 
“Are  you  sure?”  A  positive  response  to 
this  and  the  final  message  says  “save  19 
ZDM.COM”.  Even  I  could  do  it!  This  is  a 
one-time-only  procedure.  Now  when  I 
execute  ZDM  it  is  set  to  work  with  my 
terminal. 

Exercising  all  the  features,  I  found 
the  program  to  function  as  advertised. 
The  most  noticeable  difference  between 
ZDM  and  DDT  is  in  the  List  command. 
Watching  a  “disassembled”  listing  with¬ 
out  the  familiar  “20  ??”  is  refreshing.  I 
find  the  TDL-like  mnemonics  a  bit  unus¬ 
ual  but  I  suppose  that  comes  down  to 
whatever  you  have  become  accustomed 
to.  The  HEX-MATH  feature  is  nice  when 
computing  relative  off-sets  for  patching. 
Being  able  to  examine  and  alter  the  prime 
register  set  has  uncovered  some  ideas  con¬ 
cerning  their  usefulness  that  I  have  not 
experienced  before. 

There  is  a  very  small  bug  that  has 
been  discovered,  and  an  equally  small 
patch  to  correct  the  problem.  There 
seems  to  be  a  problem  when  tracing 
through  an  EXAF  instruction.  The  solu¬ 
tion  is  to  substitute  a  value  of  9H  at 
memory  location  1 1C0H.  ZDM  can  be 
used  to  modify  itself  as  follows: 

1.  In  CP/M  command  mode  and  the 
ZDM  disk  in  the  logged-in  drive, 
type: 

ZDM  ZDM.COM  (CR) 

2.  After  the  ZDM  prompt  (-)  appears, 
type: 

SI  ICO  (CR) 

9  (CR) 

(CR) 

GO  (CR)  G(zero) 

3.  Back  in  the  command  level,  save  the 
patched  version  by  typing: 

SAVE  19  ZDM.COM  (CR) 

This  will  cure  the  EXAF  tracing  problem. 

I  am  unable  to  compare  ZDM  with 
ZSID  because  I  don’t  have  a  copy  of 


ZSID.  I  have  a  copy  of  SID  but  no  man¬ 
ual.  I  know  ZDM  has  no  symbolic  capa¬ 
bilities,  so  a  comparison  here  would  be 
like  comparing  a  skateboard  to  a  motor¬ 
cycle.  They  both  get  you  where  you  want 
to  go;  one  is  just  a  bit  slower  and  requires 
a  bit  more  energy.  On  the  other  hand,  the 
expense  is  $100  for  ZSID  and  $30  for 
ZDM.  So  before  you  buy,  consider  how 
far  you  travel  and  how  often.  This  should 
help  you  decide.  Being  cheap,  I’d  go  with 
ZDM.  It  more  than  meets  my  require¬ 
ments  for  a  usable  program  development 
tool. 

Command  Summary 

D  —  Display  contents  of  memory  in  Hex 
and  ASCII 

DI  —  Disable  Interrupt  before  executing 
target  program 

El  —  Enable  Interrupt  before  executing 
target  program 

F  -  Fill  memory  with  byte  value 
G  —  Go  execute  target  program,  break¬ 
point  optional 

H  —  Display  sum  and  difference  of  two 
hex  values 

I  —  Set  FCB  (File  Control  Block)  with 
filename. ext 

L  —  List  Z-80  mnemonics  by  disassem¬ 
bling  object  code 
M  —  Move  block(s)  of  memory 
QI  —  Get  a  value  from  an  input  port 
QO-  Put  a  value  on  an  output  port 
R  —  Read  the  file  as  defined  in  the  cur¬ 
rent  FCB 

5  —  Successively  examine  and  optional¬ 

ly  alter  memory  bytes 
T  —  Trace  a  program  through  optional 
number  of  steps 

U  —  Execute  an  optional  number  of  pro¬ 
gram  steps  without  display 
X  —  Examine  and  optionally  alter  pri¬ 
mary  registers  of  Z-80  CPU 

6  —  Same  as  X  except  operates  on 

prime  (alternate)  registers;  can  also 
unconditionally  exchange  primary 
and  prime  registers 


(Continued  from  page  22) 

At  the  completion  of  each  pass,  a 
summary  is  printed  on  the  console  in  the 
form  (all  numbers  are  in  hexadecimal,  see 
Fig.  3). 

Structure  of  memory  test 

Each  pass  through  memory  tests  the 
ability  to  write  and  read  ten  different  pat¬ 
terns.  In  order  to  trap  errors  in  mapping 
to  the  physical  address  space,  the  pattern 
for  the  entire  designated  memory  area  is 
calculated  and  written  before  any  locat- 
tion  is  read  back. 

#  1  Cambridge  pattern.  A  byte  is  either 
00  or  FF  depending  on  its  address. 
#2  Address  pattern.  The  contents  of 
each  byte  is  equal  to  the  least  sig¬ 
nificant  eight  bits  of  its  address. 

#3  Alternate  ones  and  zeroes.  Each 

byte  is  filled  with  the  bit  pattern 
10101010. 

#4  Address  inverse  pattern.  Logical 

NOT  of  pattern  #2. 

#5  Alternate  zeroes  and  ones.  Each 
byte  is  filled  with  the  bit  pattern 
01010101. 

#6  All  ones.  Each  byte  has  all  bits  set. 
#7  Cambridge  pattern  inverse.  Logical 
NOT  of  pattern  #1. 

#8  All  zeroes.  Each  byte  has  all  bits 
cleared. 

#9  Bit  crosstalk  pattern.  All  bits  in  a 
given  byte  are  set  or  reset  except 
one.  The  immediately  adjacent 
bytes  contain  the  logical  NOT  of 
the  given  byte.  For  example,  loca¬ 
tion  100=FE,  101=01,  102  =  FE. 
On  each  pass,  the  bit  crosstalk  pat¬ 
tern  is  rotated  left  one  bit,  so  that 
in  eight  passes  all  possible  patterns 
are  used. 

#10  Bit  crosstalk  inverse  pattern.  Logi¬ 
cal  NOT  of  pattern  #9. 

Test  availability  on  machine  readable 
media 

For  readers  not  wishing  to  retype  the 
program  source  text,  we  will  make  the 
test  available  on  an  eight-inch,  soft- 
sectored,  single -density  diskette  including 
source,  object,  and  documentation  files. 
Check  or  money  order  for  $25.00  should 
be  sent  to  Laboratory  Microsystems, 
4147  Beethoven  Street,  Los  Angeles,  CA 
90066.  ■  ■ 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


35 

81 


DOBB  S  Ex  Machina 


Occasionally,  a  reader  of  Dr.  Dobb’s 
Journal  will  experience  poor  product 
performance  or  what  he  considers  to  be  a 
company’s  failure  to  provide  the  quality 
of  service  they  advertise.  If  his  own 
honest  attempts  to  resolve  the  situation 
fail,  he  may  then  take  recourse  to  the 
impartial  (if  not  heavenly)  mediation  of 
Dobb 's  Ex  Machina. 

When  writing  a  complaint  to  us, 
please  send  backup  data  (e.g.,  carbons  or 
photocopies  of  letters  you  have  sent  to 
the  company  in  question,  replies  received, 
copies  of  registered  receipts).  It  is  not 
possible  to  cover  all  complaints  received, 
but  we  will  publish  a  representative  sam¬ 
ple.  DDJ  has  no  particular  ax  to  grind 
with  any  seller  or  manufacturer,  but  we 
will  pay  close  attention  to  those  compa¬ 
nies  about  which  we  receive  numerous 
and  consistent  complaints. 


Dear  Sir, 

We  have  come  to  know  that  your 
magazine  is  providing  assistance  for  read¬ 
ers  who  experience  difficulties  with  soft¬ 
ware  or  hardware  suppliers. 

Therefore,  as  we  did  not  receive  any 
answer  to  our  previous  letters  or  Telex 
messages,  we  would  like  to  request  you  to 
find  out  why  Electrolabs  is  not  supply¬ 
ing  the  software  package  for  which  they 
have  received  payment  on  or  before 
March  26th,  1980.  For  your  reference 
we  are  enclosing  a  copy  of  our  last  letter 
written  to  Electrolabs,  which  provides  all 
details  relating  to  our  order. 

Thanking  you, 

Sincerely  yours, 

Ulrich  Blass 

Aurelec  Data  Processing  Systems 
Aurelec,  Prayogashala 
Auroville,  Kottakuppam  605104 
India 
9/4/80 

P.  S.  The  fact  of  so  far  having  not  received 
the  software  package,  puts  us  in  a  diffi¬ 
cult  position,  as  we  are  answerable  to  the 
Indian  Foreign  Exchange  Control  authori¬ 
ties. 


Letter  written  by  Mr.  Blass  to  Electrolabs: 

Gentlemen: 

We  are  very  surprised  to  find  out  that 
so  far  you  neither  did  answer  our  letter 
dated  June  9th  nor  our  Telex  dated  July 
17th  where  we  reminded  you  to  ship  the 


software  package  OS-1  without  further 
delay. 

Please  note  that  as  early  as  March  7th 
we  have  sent  to  you  a  cashier’s  cheque  for 
the  full  amount  of  US$238  against  the 
cost  of  your  OS- 1  operating  system. 

On  April  10th  we  received  your 
order  acknowledgement  together  with  a 
software  license  which  was  returned  to 
you  on  April  19th  duly  filled  in. 

As  subsequently  we  did  not  receive 
the  shipment  we  sent  a  reminder  on  June 
9th  and  a  Telex  on  July  17th. 

As  by  today  we  still  did  not  receive 
any  communication  from  you,  we  have  to 
assume  that  either  the  OS-1  is  not  yet 
developed  or  Electrolabs  went  out  of 
business. 

Therefore  we  have  chosen  to  contact 
a  leading  American  microcomputer  maga¬ 
zine  to  assist  us  to  receive  a  software 
package  or  a  refund  of  US$238. 

Anticipating  an  immediate  reply, 
Yours  sincerely, 

Ulrich  Blass 

Aurelec  Data  Processing  Systems 
9/1/80 

DDJ  sent  a  letter  and  a  copy  of  the 
above  correspondence  to  Electrolabs  on 
9/22180.  When  no  reply  was  received,  we 
mailed  a  follow-up  letter  on  10/24/80. 
About  one  week  later,  we  called  their  of¬ 
fices  and  learned  that  orders  for  OS-1 
had  been  turned  over  to  Software  Labs, 
who  informed  us  that  Mr.  Blass’  order 
had  been  shipped.  His  letter  to  us,  follow¬ 
ing,  notes  a  few  of  his  observations. 

Dear  Marlin, 

Thank  you  very  much  for  your  letter 
of  the  24th  October.  As  already  commu¬ 
nicated  ...  we  have  now  finally  received 
the  software  package  ordered  from  Elec¬ 
trolabs.  I  thank  you  very  much  for  your 
very  efficient  help  in  this  matter. 

Apart  from  the  software  we  did  not 
receive  any  letter  from  Electrolabs  and 
the  long  delay  in  delivery  was  not  ex¬ 
plained. 

I  give  below  my  appreciation  of  the 
OS-1  Operating  System,  which  Electro¬ 
labs  claims  to  be  a  UNIX -like  DOS  with 
the  added  feature  of  CP/M  compatibility. 
We  cannot  state  that  this  claim  is  false, 
but  still  the  OS-1  is  much  less  useful  than 
anticipated. 

First  of  all,  OS-1  is  only  CP/M  1.4 
compatible. 

Secondly,  to  run  a  CP/M  program  a 


sort  of  utilitiy  -  the  CP/M  adapter  —  is 
automatically  loaded,  which  together 
with  OS-1  leaves  less  than  12K  to  the 
user  in  a  48K  system,  obviously  not  suf¬ 
ficient  to  run  any  larger  CP/M  program 
(ZSID  and  Wordmaster,  for  instance,  do 
not  even  load). 

Further,  the  documentation  is  still 
incomplete  and,  for  example,  all  informa¬ 
tion  regarding  the  adaptation  of  OS- 1  to 
a  different  mass  storage  device  than  an 
IBM  3740  Diskette  (double  density,  hard 
disk,  etc.)  is  not  provided  but  promised 
for  a  later  date. 

So  for  the  time  being,  OS- 1  might  be 
an  interesting  tool  to  experiment  with, 
but  in  its  present  state  of  development,  it 
certainly  cannot  claim  to  replace  either 
CP/M  2.0  nor  CP/M  1.4.  However,  the 
general  architecture  seems  to  be  rather 
promising,  but  we  would  really  appreciate 
to  receive  a  complete  and  finished  prod¬ 
uct  rather  than  a  prototype. 

I  hope  that  this  information  might  be 
of  some  use  to  your  readers.  Should  you 
receive  any  further  communication  from 
Electrolabs,  we  would  appreciate  very 
much  to  receive  a  copy. 

Thanking  you  again, 

Sincerely, 

Ulrich  Blass 
Aurelec 
11/11/80 

Editor’s  note:  As  one  of  Electrolabs’ 
creditors,  People's  Computer  Company 
recently  received  notice  that  MKW,  Inc., 
dba  Electrolabs,  has  filed  an  order  for  re¬ 
lief  with  the  United  States  Bankruptcy 
Court  under  11  U.S.C.  Chapter  11. 

John  White,  President  of  Software 
Labs  informs  us  that  his  is  a  separate  busi¬ 
ness  which  purchased  and  is  fully  sup¬ 
porting  OS-1,  with  updates  due  by 
early  January  1981.  Co-owner  of  the 
company  is  Cachun  Lee,  the  original  de¬ 
signer  of  OS- 1. 


36 

82 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


PAN 

( continued  from  page  1 7) 

The  PAN  Protocol: 

1)  The  originating  PAN  dials  the  number 
of  the  answering  PAN. 

2)  When  the  answering  PAN  detects  ring, 
it  goes  off  hook  and  sends  carrier. 

3)  When  the  originating  PAN  detects  car¬ 
rier  it  sends  the  string  “@@@ANN” 
where  ANN  consists  of  a  single  alpha 
character  followed  by  two  numerics. 
This  string  is  the  version  number  of 
the  answering  PAN;  for  the  CBM  PET 
version  of  PAN  it  is  P10.  For  experi¬ 
mental  versions,  A  is  X. 

5)  When  the  originating  PAN  receives  3 
or  more  characters  it  sends  five 
CTRL-S  characters. 

6)  When  the  answering  PAN  receives  one 
or  more  CRTL-S  characters  it  prepares 
to  accept  subsequent  received  charac¬ 
ters  as  a  PAN  message.  If  no  CTRL-S 
characters  are  received  the  answering 
PAN  times  out  and  goes  on  hook. 

7)  The  originating  PAN  sends  the  message 
text;  the  last  character  of  the  message 
text  should  be  UP  ARROW  ( t )  to  serve 
as  a  human  readable  end -to -message 
mark.  The  first  line  of  the  message 
text  (between  the  first  character  and 
the  first  carriage  return)  contains  the 
phone  number  of  the  originating  PAN 
in  the  form  (AAA)  NNN-MMMM 
where  AAA  is  the  area  code  and  NNN 
the  prefix.  It  is  desirable  but  not  re¬ 
quired  that  this  first  line  also  contain 
the  sender’s  initials  and  the  originating 
PAN’s  local  time  of  transmission  in 
twenty- four  hour  format  (HHMMSS 
where  HH  ranges  from  00  to  23). 

8)  Tue  originating  PAN  sends  five  CTRL- 
R  characters  to  signal  end-of-message; 
it  then  goes  on  hook. 

9)  When  the  answering  PAN  receives  one 
or  more  CTRL-R  characters  it  goes  on 
hook  and  places  the  received  character 
string  in  the  message  buffer.  If  the 
answering  PAN  loses  carrier  at  any 
time  during  message  reception,  it  goes 
on  hook. 


Correspondence  and  inquiries  about 
the  Personal  Computer  NETwork  should 
be  accompanied  by  a  business-size,  self- 
addressed  stamped  envelope  and  mailed 
to  PCNET,  P.  O.  Box  E,  1 263  El  Camino 
Real,  Menlo  Park,  CA  94025. 


Letters 

(continued  from  page  7) 

ccasr,  however,  shift  before  testing  for 
completion,  so  a  shift  of  zero  is  done 
wrong.  I  corrected  this  by  moving  the  test 
to  the  top  of  the  loop  as  follows: 

;  Shift  DE  arithmetically  right  by  HL 
and  return  in  HL 
ccasr:  XCHG 

DCR  E 

RM 

MOV  A,H 

RAL 

MOV  A,H 

RAR 

MOV  H,A 

MOV  A,L 

RAR 

MOV  L,A 
JMP  ccasr+1 

;  Shift  DE  arithmetically  left  by  HL 
and  return  in  HL 
ccasl:  XCHG 

DCR  E 

RM 

DAD  H 

JMP  ccasl +1 

I  would  like  to  applaud  Ron  Cain’s 
impressive  effort  in  writing  the  Small-C 
compiler  and  thank  DDJ  for  publishing 
it. 

Yours  truly, 

James  L.  Colvin  Jr. 

3394  E.  Styles  Ave. 

Camarillo,  CA  93010 

Byte-Count  Routine 

Dear  Marlin, 

A  letter  from  Ralph  Kelley  has  called 
to  my  attention  the  6502  byte-count 
routine  used  in  his  article  published  in  the 
Jan/ Feb  1980  issue  of  COMPUTE.  This  is 
similar  to,  but  more  code-efficient  than, 
Jim  Butterfield’s  CNTBYT  routine  that  I 
listed  in  my  own  article  in  DDJ  #22 
(February  1978).  The  first  17  bytes  are 
functionally  identical,  “weeding  out”  1 1 
opcodes  with  unusual  bit-patterns.  At 
that  point,  Ralph  noted  that  the  residual 
opcode  bit-patterns  had  become  $10  for 
all  one-byte  codes,  less  than  $10  for  all 
two-byte  opcodes,  and  greater  than  $10 
for  all  three-byte  opcodes.  This  makes  it 
possible  to  replace  the  four  instructions 
used  by  Butterfield  with  the  following 
three:  CMP  $10,  BEQ  ONE,  BCC  TWO.  If 
coded  as  a  subroutine,  it  needs  26  pro¬ 
gram  bytes  instead  of  28  and  also  runs 
about  two  cycles  faster  than  CNTBYT. 
However,  my  28-byte  non-linear 


BYTCNT  routine,  also  listed  in  DDJ  #22, 
runs  significantly  faster,  especially  in 
analyzing  the  two-byte  codes  that  tend 
to  be  predominant  in  6502  programs. 

DDJ  and  I  are  responsible  for  making 
the  byte-count  problem  a  6502  machine¬ 
coding-skill  game.  The  usual  fate  of  algo¬ 
rithms  is  to  be  anonymously  interred 
within  a  tumulus  of  code,  and  this  must 
be  true  of  byte-count  routines  for  other 
microprocessors.  The  circuitry  of  the 
6502  is  so  intricate  that  a  software  emu¬ 
lation  becomes  an  intriguing  puzzle, 
which  is  also  very  useful.  Although  there 
are  only  3  possible  counts,  each  one  is 
generated  by  2  distinct  opcode  bit- 
patterns,  so  that  every  solution  must  iso¬ 
late  6  classes,  requiring  5  branch  instruc¬ 
tions.  Each  branch  must  be  preceded  by 
at  least  one  bit -analysis  instruction,  and 
this  minimum  of  5  was  achieved  in  my 
BYTNUM  routine  (DDJ  #17),  but  code¬ 
efficiency  was  not  optimal  since  4  of 
them  were  3 -byte  BIT  instructions. 
Butterfield’s  masterly  solution  used  7  bit- 
analysis  instructions,  which  Kelley  has 
ingeniously  reduced  to  6.  My  BYTCNT 
routine  also  uses  6,  but  since  one  of  them 
is  a  BIT  it  cannot  be  as  code-efficient. 
If  the  6502  had  a  BIT-immediate  instruc¬ 
tion,  BYTNUM  logic  could  optimize  both 
code-  and  time-efficiency.  As  things  are, 
a  code  vs.  time  trade-off  is  inevitable. 

What  I  stressed  in  DDJ  #22  may  be 
worth  noting,  that  although  all  these 
routines  exit  with  thd  correct  byte -count 
in  the  X- register,  their  bit -analysis  in¬ 
structions  also  alter  the  status  flags  in  dif¬ 
ferent  ways,  such  that  even  more  than  6 
opcode  types  may  be  identifiable.  So  far, 
no  one  seems  to  have  used  this  auxiliary 
information,  but  it  ought  to  be  kept  in 
mind. 

Sincerely, 

H.  T.  Gordon 

College  of  Natural  Resources 
University  of  California 
Berkeley,  CA  95720 


Dr.  Dobb’s  Journal  welcomes  letters  to 
the  editor  as  a  forum  for  ideas,  innova¬ 
tions,  irascibility  and  even  idiosyncrasies. 
Some  letters  may  be  edited  for  clarity 
and  brevity.  The  Doctor  likes  hearing 
from  you  -  keep  on  writing! 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


37 

83 


Of  Interest 


Calls  For  Papers 

Papers  are  now  being  accepted  for 
the  Fifth  Western  Educational  Computing 
Conference  to  be  held  in  San  Francisco 
on  November  19-20.  Topics  are  comput¬ 
ers  and  computer  applications  in  any  area 
of  interest  to  instructors  and  administra¬ 
tive  personnel  who  deal  with  computers 
at  the  college  or  university  level.  Deadline 
is  March  1.  Write  to  Professor  Elizabeth 
Alpert,  Computer  Science  Dept.,  Hartnell 
College,  156  Homestead  Ave.,  Salinas,  CA 
93901. 

“Reliability  in  Electrical  and  Elec¬ 
tronic  Components  and  Systems”  is  the 
theme  for  Eurocon  ’82,  an  interdiscipli¬ 
nary  conference  on  reliability  and  risk  as¬ 
sessment,  to  be  held  in  Copenhagen.  Pre¬ 
liminary  titles  and  one-  to  two-page  sum¬ 
maries  of  papers  are  being  accepted  for 
the  event  to  take  place  June  14-18,  1982. 
Contact  the  Conference  Office,  Danish 
Engineers’  Postgraduate  Institute,  The 
Technical  University  of  Denmark,  Bldg. 
208,  DK-2800  Lyngby,  Denmark. 

Computer  Aid  For  Handicapped 

John  Hopkins  University  is  conduct¬ 
ing  a  nationwide  search  for  ideas  and  in¬ 
ventions  to  aid  the  handicapped  through 
computer  technology.  The  search  is 
funded  by  grants  from  the  National  Sci¬ 
ence  Foundation  and  Radio  Shack.  A 
$10,000  grand  prize  and  100  other  na¬ 
tional  regional  awards  have  been  estab¬ 
lished,  including  fifteen  personal  comput¬ 
er  systems.  Entries  may  be  a  device,  sys¬ 
tem  or  a  computer  program.  Major  ob¬ 
jectives  of  the  contest  are  to  focus  com¬ 
puting  technology  on  the  needs  of  the 
handicapped  and  to  harness  individual  in¬ 
novation  and  creativity  on  a  nationwide 
basis.  Information  is  available  from  Per¬ 
sonal  Computing  for  the  Handicapped, 
John  Hopkins  University,  P.O.  Box  670, 
Laurel,  MD  20810. 

Miscellany 

Tiny-c  two  runs  ten  times  faster  than 
the  original  tiny-c,  and  includes  new  fea¬ 
tures  like  32-bit  integers,  new  operators, 
redirectable  and  direct  access  I/O,  a 
UNIX,m -style  command  interpreter  and 
more.  The  Owner’s  Manual  costs  $50,  the 
diskette  is  $200  from  tiny-c  associates, 

P.O.  Box  269,  Holmdel,  NJ  07733 - 

Hardware  and  software  for  Heathkit  com¬ 
puters  is  available  from  a  number  of  sup¬ 
pliers  not  affiliated  with  the  Heath  Com¬ 
pany,  and  who  have  specialized  applica¬ 


tions  plus  general  interest  products  not 
yet  offered  by  Heath.  For  a  directory, 
send  U.S.  $7.50  to  Buss,  325 -D  Pennsyl¬ 
vania  Ave.  S.E.,  Washington,  DC  20003. 

. .  .  Hewlett-Packard,  realizing  it  is  soft¬ 
ware  that  will  sell  its  machines,  has  an¬ 
nounced  a  number  of  new  utilities  in¬ 
cluding  a  dumb  terminal  emulator.  For 
specifics,  write  to  the  Inquiries  Manager 
at  HP,  1507  Page  Mill  Road,  Palo  Alto, 
CA  94301.  . . .  Dilithium  Press’  new  cata¬ 
log  lists  over  sixty -five  books  on  micro¬ 
processing.  Also  included  is  software  for 
the  TRS-80  Level  II  and  the  8K  PET.  For 
a  free  copy,  send  to  30  N.W.  23rd  Place, 
Portland,  OR  97201. . .  .  Sorcim  has  in¬ 
troduced  a  version  of  their  Pascal/ M  for 
the  Intel  8086  CPU,  and  TRANS  86,  a 
program  that  “translates  existing  Z-80  or 
8080  code  into  8086-8088  code.”  The 
press  release  neglected  to  state  whether 
the  translation  is  done  in  assembly  lan¬ 
guage  or  at  the  level  of  a  hex  file.  If  you 
work  with  the  8086  and  check  this  out, 
send  a  review  to  DDJ.  .  . .  For  the  benefit 
of  readers  abroad,  here  are  the  addresses 
of  two  firms  that  now  represent  Digital 
Research  in  the  Far  East  and  Europe  '. 
Microsoftware  Associates 
102  Plasada 

3-16-14  Minami  Aoyama 
Mnato-ku 
Tokyo  107,  Japan 
03-403-2120 
Telex  2426875  MSA 
Vector  International 
Research  Park 
B-3030  Leuven 
Belgium 

32  (16)20-24-26 
Telex  26202  VECTOR 
For  a  Datapro  report  comparing  210 
alphanumeric  display  terminals,  and  the 
results  of  a  survey  covering  over  18,000 
installed  terminals,  send  $15  to  Datapro 
Research  Corporation,  1805  Underwood 
Blvd.,  Delran,  NJ  08075. 

New  Products 

Hewlett-Packard  has  announced  a 
plan  for  would-be  software  entrepreneurs. 
The  company  will  market  non- HP  soft¬ 
ware  for  their  Series  80  machines  through 
a  catalog  distributed  to  all  HP  dealers, 
and  expects  to  help  promote  applications 
software  in  a  large  variety  of  fields.  Devel¬ 
opers  of  quality  software  for  micros 
would  be  natural  participants.  HP  will 
work  with  software  developers  to  expand 
the  amount  of  software,  and  all  products 


listed  in  the  catalog  will  be  available  from 
HP  dealers. ...  In  a  related  announce¬ 
ment,  HP  has  offered  an  Assembler  ROM 
for  the  Series  80  machine.  The  $295 
ROM  contains  an  assembler  and  an  edi¬ 
tor.  One  interesting  feature  is  that  the 
editor  checks  each  line  for  correct 
assembly -language  syntax  as  the  line  is 
typed.  A  programmer  using  a  Series  80 
assembly  language  will  be  able  to  redefine 
BASIC  keywords,  add  new  BASIC  com¬ 
mands  and  functions.  Assembly-language 
programs  will  have  full  access  to  all  rou¬ 
tines  in  the  BASIC  operating  system,  in¬ 
cluding  those  for  math,  CRT  control  and 
general  I/O.  The  assembler  ROM  is  docu¬ 
mented  by  a  400 -page  manual.  .  . .  The 
Microperipheral  Corporation  recently  in¬ 
troduced  a  new  line  of  direct  connect 
modems  for  the  TRS-80,  ATARI,  APPLE 
and  virtually  any  terminal  or  computer 
with  provision  for  the  RS232  serial  I/O 
at  300  baud.  Prices  start  at  $199.95, 
with  the  AUTODIAL/AUTOANSWER 
option  at  $79.95.  Write  them  at  2643- 
151st  Place  N.E.,  Redmond,  WA  98052. 

.  .  .  Personal  Software  Inc.  has  given  Com¬ 
modore  International  Ltd.  exclusive  li¬ 
cense  to  reproduce,  sell  and  distribute 
Visicalc  outside  the  U.S.  in  German, 
French,  Spanish,  Italian,  Dutch  and 
Danish.  .  . .  Direct  input  of  temperatures 
is  possible  for  a  variety  of  micros  using 
TEMPSENS  by  Connecticut  Microcom¬ 
puter,  Inc.  Cost  for  a  two- probe  unit  is 
$49.95.  Address  inquiries  to  34  Del  Mar 
Drive,  Brookfield,  CT  06804.  .  .  .  The 
Cybervision  personal  computer  is  the  first 
major  product  of  United  Chem-Con’s 
new  Home  Products  Division.  It  is  based 
on  the  RCA  1802  chip,  accepts  input 
from  cassette  or  the  two  alphanumeric 
keypads  which  are  provided  (note  that 
these  are  not  the  usual  keyboard)  and 
professes  color  graphics  and  human 
quality  audio.  The  price  tag  is  $400.  For 
information  write  to  United  Chem-Con 
at  2950  Old  Tree  Drive,  Lancaster,  PA 
17603.  .  .  .  GROUP/ 380  is  a  microcom¬ 
puter  interest  group  for  micro  systems 
equivalent  to  IBM’s  360/370  mainframes. 
The  group  links  potential  users  of  these 
systems  to  the  large  amount  of  software 
available  from  organizations  either  for  a 
copying  charge  or  at  micro  prices.  Con¬ 
tact  Mokurai  Cherlin,  GROUP/380,  P.O. 

Box  1131,  Mt.  Shasta,  CA  96067 _ 

DOS/65  is  an  operating  system  which 
provides  features  for  6502’s  similar  to 
those  available  to  8080’s  and  Z-80’s  from 
CP/M*"1.  Prices  range  from  $  1 00- $  1 50. 


38 

84 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


For  details  mail  a  self-addressed,  stamped 
envelope  to  Richard  A.  Leary,  1363 
Nathan  Hale  Dr.,  Phoenixville,  PA  19460. 

.  .  .  6800  software  runs  on  Apple  II’s  with 
THE  MILL  processor  board  plugged  into 
any  peripheral  slot.  Its  heart  is  the  Moto¬ 
rola  6809E  processor.  Available  from 
Stellation  Two,  P.  O.  Box  2342,  Santa 
Barbara,  CA  93120.  Priced  at  $275.  .  .  . 
An  8 -inch  floppy  subsystem  for  North 
Star  requires  only  plug-in  installation. 
The  software-hardware  package  is  priced 
at  $1910,  with  the  software  alone  costing 
$150.  From  John  D.  Owens  Associates, 
Inc.,  12  Schubert  St.,  Staten  Island,  NY 
10305.  .  .  .  Eventide’s  memory  expansion 
board  for  HP  9845  desktop  computers 
claims  to  be  identical  in  operation  and  in¬ 


stallation  to  the  board  supplied  by  HP, 
but  costs  only  $2250  (one-half  of  HP’s 
price).  Each  WMAP-1  board  adds  128 
kilobytes  of  memory.  Write  265  West 

54th  St.,  New  York,  NY  10019 _ The 

M24SS  static  RAM  card  for  SS-50/ 
SS-50C  bus  computers  is  available  in  8-, 
16-,  and  24-kilobyte  configurations  from 
Percom  Data  Company,  211  N.  Kirby, 
Garland,  TX  75042.  . .  .  KIMSET1  is  an 
analog-to-digital  conversion  system  for 
KIM  microcomputers,  providing  16  chan¬ 
nels  of  input,  each  with  a  resolution  of  8 
bits.  Plugging  this  into  the  KIM  applica¬ 
tions  port  enables  it  to  read  and  process 
temperature,  velocity,  pressure,  db,  pH, 
acceleration,  humidity,  light  and  fluid 
levels,  etc.  Price  is  $285  from  Connecti¬ 


cut  microcomputer  Inc.,  150  Pocono 
Road,  Brookfield,  CT  06804.  ...  A  diag¬ 
nostic  software  package  for  Cromemco 
systems  exercises,  tests  and  reports  any 
errors  in  the  operation  of  floppy  or  hard 
disk  drives.  Information  available  from 
Cromemco,  280  Bernardo  Ave.,  Mountain 
View,  CA  94043.  .  .  .  Nestar  System, 
whose  Cluster/ One  makes  a  local  network 
out  of  a  dozen  Apples,  has  announced  an 
office  mail  program  they  call  The  Mes¬ 
senger.  Network  users  may  send,  receive, 
file,  make  notes  on,  copy  or  broadcast 
electronic  analogs  of  office  memos  from, 
to,  at  and  by  each  other.  The  Messenger 
costs  $2250;  call  Nestar  at  (415) 
327-0125. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Each  issue  includes: 

•  valuable  software  tools 

•  algorithms  &  problem  solving 

•  industry  news 

•  important  product  reviews 

With  in-depth  coverage  of: 

•  telecommunications 

•  systems  programming 

•  language  development 

•  machine  independent 

programs 

and  much,  much  more! 


Dr.  Dobb's  Journal 


Yes!  Please  enter  my  subscription  for 

□  1  yr.  (12  issues)  $25  □  2  yrs.  $47  (save  $13  off  newsstand) 

□  Please  bill  me  □  I  enclose  check/money  order 

Name _ 

Address  _ 

City _ State _ Zip _ 


Dr.  Dobb’s  Journal,  A  Publication  of  People’s  Computer  Company 
1263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  CA  94025 


Are  you  ready? 

DDJ,  the  world’s  foremost  microcomputer 
publication,  has  been  working  for  years  to  pre¬ 
pare  its  readers  to  be  innovators,  to  lead  the 
wave  of  breakthroughs  in  our  changing  tech¬ 
nology. 

Every  issue  of  Dr.  Dobb’s  Journal  helps 
one  to  understand  the  nuts  and  bolts  of  small 
computer  systems.  We  offer  entire  listings  of 
valuable  software:  our  pages  have  included 
compilers,  cross-assemblers,  editors,  new  lan¬ 
guages,  hardware  interfaces  and  more  —  usually 
before  anyone  else  thinks  of  them ! 


Even  more  important! 

Our  subscribers  share  insights,  correspond, 
and  contribute  to  one  another’s  work,  more 
than  any  other  group  we  know.  They  treat 
Dr.  Dobb’s  Journal  as  a  “hands-on”  publication. 

This  warm  cooperation  has  done  more  to 
refine  software  products,  and  generally  to 
advance  the  state  of  microcomputer  techno¬ 
logy,  than  perhaps  any  other  resource.  And  it  is 
available  to  you  through  our  pages ! 

For  the  straight  facts . 

If  you  are  a  serious  computing  professional 
or  enthusiast,  then  you  should  take  a  very  close 
look  at  what  DDJ  offers  you.  We’ve  been  on 
the  cutting  edge  since  1976. 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 


39 

85 


Book  Reviews 


TRS-80  INTERFACING,  BOOK  2 
By  Johathan  A.  Titus,  Christopher  A. 

Titus,  and  David  G.  Larsen 
Published  by  Blacksburg  Continuing 
Education  Series 
254  pages,  $9.95 
Reviewed  by  Steven  Wexler 

This  book  introduces  interfacing 
techniques  which  will  allow  the 
reader  to  utilize  the  TRS-80  (Models  I, 
II,  or  III)  for  control  purposes.  The  auth¬ 
ors  do  not  attempt  cradle-to-grave  de¬ 
scriptions  of  hardware  projects,  preferring 
to  concentrate  on  technique.  The  actual 
use  of  the  circuits  described  is  left  up  to 
the  reader. 

Some  of  the  topics  covered  are :  driv¬ 
ing  high-current  and  high-voltage  loads, 
generating  voltage  and  current  signals, 
measuring  unknown  voltages  and  cur¬ 
rents,  remote  control  techniques,  and 
new  interface/controller  chips. 

If  you  do  not  have  a  hardware  back¬ 
ground,  read  TRS-80  Interfacing,  Book  I 
before  attempting  to  read  this  book. 
Those  of  you  comfortable  with  the 
typical  magazine  hardware  article  should 
not  have  any  trouble. 

TRS-80  Interfacing,  Book  2  is  a  rea¬ 
sonably  good  textbook  (or  reference 
book)  at  a  fair  price.  If  it  fits  your  needs, 
by  all  means  buy  it. 

Z8000  ASSEMBLY  LANGUAGE 
PROGRAMMING 
By  Leventhal,  Osborne  and  Collins 
Published  by  Osbome/McGraw-Hill 
604  pages,  $  19.99 
Reviewed  by  John  B.  Palmer 

This  is  the  first  book  on  Z8000  pro¬ 
gramming  to  cover  everything.  There  is 
enough  good  info  to  make  two  regular 
size  books.  I  am  glad  the  publishers  re¬ 
leased  it  as  one  thick  volume. 

This  comprehensive  Z8000  refer¬ 
ence  work  sets  new  standards  of  quality 
for  microprocessor  documentation.  At 
$19.95  it  is  very  reasonable  if  compared 
to  more  expensive  (but  not  better)  soft¬ 
ware  literature  sold  by  some  leading 
semi-conductor  makers. 

Seventeen  chapters  give  a  well- 
rounded  coverage  of  Z8000  assembly  lan¬ 
guage  programming  and  closely  related 
subjects.  The  most  important  points  get 
enough  attention.  A  new  programmer 
should  be  able  to  start  producing  useful 
programs  after  reading  chapters  1,  2,  4 
and  5. 

Chapter  three  dominates  the  book 
with  376  pages  devoted  to  the  massive 


Z8000  instruction  set.  (If  you  don’t  want 
to  learn  the  entire  instruction  set,  skip 
over  to  chapter  four.)  It  is  a  joy  to  see 
at  least  a  full  page  of  text  for  each  in¬ 
struction  type.  Important  instructions 
may  have  four  or  more  pages  of  text. 
Lots  of  clear,  eye- pleasing  diagrams  are 
used  here  and  in  the  rest  of  the  book. 

I  was  pleased  to  see  even  a  few  pages 
on  floating  point  (I  am  weak  in  this  area). 
But  I  was  sad  to  find  very  little  about 
multitasking,  which  I  have  done  on  an 
8080. 

About  100  pages  of  the  book  deal 
with  the  modern  philosophy  of  program¬ 
ming.  It  stresses  program  design,  debug¬ 
ging  and  documentation.  Flow  charts  and 
structure  are  endorsed.  Compare  this  with 
ninety-six  pages  on  I/O  and  half  that 
many  for  interrupts.  The  text  tends  to 
favor  the  novice  programmer. 

Really,  at  times  the  tutorials  seem 
overly  helpful.  But  I  think  the  authors 
made  the  right  choice.  More  esoteric  stuff 
can  be  found  in  the  many  excellent  refer¬ 
ences  to  other  literature.  There  are 
twenty- five  such  references  just  in  the 
chapter  on  I/O.  If  you  can  not  find  the 
answer  in  this  book,  at  least  you  will  be 
told  where  you  can  find  what  the  authors 
may  have  set  aside. 

This  book  does  not  ignore  an  impoi- 
tant  Z8000  weakness.  Instead,  it  helps 
the  user  identify  which  early  production 
chips  failed  to  properly  execute  which  in¬ 
structions. 

The  last  two  chapters  give  practical, 
real  world  Z8000  application  programs. 
Not  just  source  codes,  but  all  the  design 
steps  a  software  engineer  would  need  to 
carry  out  his  job. 

This  book  has  one  unavoidable  fail¬ 
ure:  it  should  have  been  printed  one  year 
earlier.  But  that  is  more  Zilog’s  failure 
than  the  authors’.  Because  Zilog  was  late 
in  getting  the  Z8000  to  the  market,  few 
groups  had  running  systems  with  which 
to  test  software  designs. 

Overall,  the  book  is  very  practical 
and  reflects  a  modern,  conservative  ap¬ 
proach  toward  16-bit  microprocessor 
programming. 

COMPUTER  PERIPHERALS  FOR  MINI¬ 
COMPUTERS,  MICROPROCES¬ 
SORS  &  PERSONAL  COMPUTERS 
By  C.  Louis  Hohenstein 
Published  by  McGraw-Hill 
312  pages,  $  19.50 
Reviewed  by  Susan  Bowers 

This  book  was  a  very  pleasant  sur¬ 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 
86 


prise  —  a  technical  book  written  in  a  read¬ 
able  manner.  A  great  many  charts,  pic¬ 
tures  and  illustrations  are  included,  which 
help  clarify  the  material.  Exactly  enough 
background  information  is  given  to  en¬ 
able  the  reader  to  understand  the  basic 
principle  and  best  use  of  each  type  of 
peripheral. 

Computer  Peripherals  for  Minicom¬ 
puters,  Microprocessors  and  Personal 
Computers  is  divided  into  five  major 
parts.  The  first  is  an  introduction,  with 
the  selected  fundamentals  of  computers 
necessary  for  an  understanding  of  peri¬ 
pherals.  The  remaining  sections  deal  with : 
Output  Peripherals;  Input  Peripherals; 
Memory  Peripherals;  and  Data  Transmis¬ 
sion,  Remote  Terminals  and  Interfaces. 
The  several  kinds  of  equipment  in  each 
section  are  thoroughly  covered.  Included 
are  comparisons  and  discussions  of  all  the 
types  in  each  category,  with  drawings  and 
good  illustrations  of  how  they  work.  The 
clearly  stated  explanations  are  sufficient 
to  provide  a  basis  for  choosing  which  de¬ 
vices  would  be  most  useful  in  specific 
circumstances. 

There  are  so  many  peripherals  it 
would  have  been  easy  to  lose  the  reader 
in  a  confusing  maze  of  technical  terms. 
The  author  avoids  this  nicely,  charting  a 
clear  path  to  comprehension.  He  makes  a 
complex  subject  seem  simple.  This  is  an 
excellent  resource  book  for  those  who  are 
learning  about  peripherals,  and  would  be 
extremely  useful  to  someone  planning  to 
purchase  a  small  computer  system. 

CRT  CONTROLLER  HANDBOOK 
By  Gerry  Kane 

Published  by  Osborne/ McGraw-Hill 

184  pages,  $6.99 

Reviewed  by  Anthony  Skjellum 

CRT  Controller  Handbook  describes 
five  LSI  cathode -ray  tube  (CRT)  control¬ 
ler  chips.  It  contains  details  of  operations, 
and  the  numerous  figures  are  supple¬ 
mented  by  data  sheets.  An  introductory 
chapter  explains  the  concept  of  CRT  con¬ 
trol  and  the  technical  presentation  is 
quite  good  throughout  the  book.  The 
text  concentrates  on  microprocessor- 
based  CRT  systems  which  operate  in  con¬ 
junction  with  an  LSI  controller  device. 
Pertinent  topics  such  as  timing,  memory 
interfacing  and  contention  logic,  charac¬ 
ter  generation  and  video  display  genera¬ 
tion  are  discussed. 

CRT  designers  who  plan  to  use  an 
LSI  CRT  chip  will  benefit  from  this  book 
since  it  provides  a  good  comparison  of 


41 


The  Electric 
Phone  Book 


features  and  notes  pitfalls.  This  book  will  A  computerized  bulletin  board  Send  them  to  PCNET,  PCC,  P.O.  Box 

also  serve  as  a  useful  guide  when  choosing  works  just  like  an  ordinary  bulletin  E,  Menlo  Park,  C A  94025. 

a  device  for  your  application.  The  chips  board  system  except  that  instead  of  All  the  bulletin  board  systems  list- 
discussed  are  the  DP8350,  8375,  6845  paper  and  thumbtacks  it  uses  a  termi-  ed  here  can  be  accessed  by  telephone 

and  5027/9927.  The  book  deals  almost  nal,  a  computer,  and  the  dial-up  tele-  using  a  300-baud  ASCII  terminal  and 

exclusively  with  alphanumeric  CRT’s  al-  phone  network.  a  Bell  103  modem.  Most  use  carriage- 

though  graphic  terminals  are  mentioned  The  list  below  was  developed  return  as  a  speed  recognition  charac- 

in  passing.  While  the  experienced  designer  from  several  sources  including  the  Peri-  ter,  after  which  they  are  self- teaching, 

will  appreciate  the  information  provided  pheral  People  in  Mercer  Island,  Wash-  All  are  free  to  anyone  who  calls,  un- 

here,  case  studies  and/or  specific  exam-  ington,  and  the  People’s  Message  Sys-  like  Arpanet,  which  is  restricted,  and 

pies  would  have  improved  the  book  con-  tern  in  Santee,  California.  It  is  being  The  Source  and  MicroNet,  which  cost 

siderably.  Finally,  no  detailed  attention  maintained  by  People’s  Computer  money.  The  list  has  been  sorted  by 

is  given  to  software  which  would  relate  Company’s  PCNET  project,  our  effort  area  code;  consult  your  local  tele- 

to  microprocessor-based  CRT  systems.  to  bring  computers  and  telecommuni-  phone  directory  for  geographical  cor- 

This  is  not  a  tutorial  book  and  is  cations  into  the  hands  of  everyone,  respondence.  (Also  printed  in  Recrea- 

certainly  not  for  beginners.  Its  total  con-  While  this  is  the  most  complete  listing  tional  Computing,  January-February 

tent  will  be  mostly  of  interest  to  design-  we  have  as  of  this  writing,  we  would  1981.) 

ers  although  certain  sections  are  of  appreciate  additions  and  corrections. 


general  interest  as  well. 


Dr.  Dobbs  Journals 

COMPUTER  Calisthenics  6  Orthodontia 

Subscription  Rates:  $25  per  year  within  the 
United  States;  $44  for  first  class  to  Canada 
and  Mexico;  $62  for  airmail  to  other  coun¬ 
tries.  Payment  must  be  in  U.S.  dollars, 
drawn  on  a  U.S.  bank. 

Writer’s  Guidelines:  All  items  should  be 
typed,  double-spaced  on  white  paper.  List¬ 
ings  should  be  produced  by  the  computer, 
using  a  fresh,  dark  ribbon  on  continuous 
white  paper.  Please  avoid  printing  on  perfo¬ 
rations.  Payment  is  in  contributor’s  copies. 
Requests  to  review  galleys  must  accompany 
the  manuscript  when  it  is  first  submitted. 
Authors  may  receive  a  copy  of  the  com¬ 
plete  writer’s  guidelines  by  sending  a  self- 
addressed,  stamped  envelope. 

Donating  Subscribers 
Contributing  Subscriber:  $50/year  ($25  tax 
deductible).  Retaining  Subscriber:  $75/year 
($50  tax  deductible).  Sustaining  Subscriber: 
$100/year  ($75  tax  deductible).  Lifetime 
Subscriber:  $1000  ($800  tax  deductible). 
Corporate  Subscriber:  $500/year  ($400  tax 
deductible,  receives  five  one-year  subscrip¬ 
tions). 

Contributing  Subscribers:  Robert  L.  Edens, 
Eric  P.  Hanson,  J.  G.  Zeratsky,  Mervin  E. 
Frank,  Edward  W.  Carr,  Steven  Fisher, 
Thomas  H.  Grohne,  Richard  Washburn,  Les 
Hancock,  G.  V.  Elkins,  C.  A.  Forsberg, 
Daniel  R.  Lunsford,  J.  D.  Griffith,  Michael 
Slade,  Thomas  M.  Schaefges,  General 
Electric,  Louis  L.  Odette,  Robert  M. 
Connors,  William  J.  McEown,  Robert  C. 
Luckey,  Kim  Leary,  Robert  N.  Stabler, 
Dewitt  S.  Brown,  John  B.  Palmer,  E.  Glion 
Curtis. 

Retaining  Subscribers:  Mike  Faithful  and 
Osamu  Shimizu. 

Sustaining  Subscribers:  Gordon  Eubanks,  Jr. 
and  Robert  C.  Birss,  Ph.D. 


(201)  283 
(201)  457 
(201)  688 
(201)  753 
(201)  753 
(201)  835 
(201)  843 
(201)  874 
(201)  891 

(201)  968 

(202)  337 

(202)  635 

(203)  348 
(203)  357 
(203)  746 

(205)  945 

(206)  244 
(206)  246 
(206)  482 
(206)  482 
(206)  524 
(206)  546 
(206)  723 
(206)  937 
(209)  638 
(212)  245 
(212)  448 
(212)  787 

(212)  997 

(213)  276 
(213)  316 
(213)  329 
(213)  340 
(213)  346 
(213)  349 
(213)  360 
(213)  394 
(213)  395 
(213)  396 
(213)  424 
(213)  428 
(213)  459 
(213)  459 
(213)  566 
(213)  631 
(213)  657 


-2724 

(213) 

673 

2206 

(313) 588-7054 

(602) 

957-9282 

(714) 

952-2110 

-0893 

(213) 

675 

8803 

(314) 838-7784 

(604) 

687-2640 

(714) 

962-7979 

-7117 

(213) 

709 

5423 

(316)  746-2078 

(607) 

754-5571 

(714) 

963-7222 

-1225 

(213) 

795 

3788 

(319)  353-6528 

(607) 

797-6416 

(801) 

375-7000 

-8152 

(213) 

787 

4004 

(319) 557-9618 

(609) 

983-5970 

(801) 

466-1737 

-7228 

(213) 

799 

1632 

(404) 394-4220 

(612) 

561-6311 

(801) 

753-6800 

-4563 

(213) 

799 

6514 

(404)  733  3461 

(612) 

929-8966 

(802) 

748-9089 

-6833 

(213) 

826 

0325 

(404)  790-8614 

(614) 

272-2759 

(802) 

879-4981 

-7441 

(213) 

828 

3400 

(404)  793-1045 

(614) 

649-7097 

(803) 

270-5372 

-1074 

(213) 

843 

5390 

(404) 939-1520 

(615) 

254-9193 

(803) 

270-5392 

-4694 

(214) 

288 

4859 

(404) 939-8429 

(617) 

354-4682 

(803) 

279-5392 

-5730 

(214) 

634 

2668 

(404) 953-0723 

(617) 

388-5125 

(803) 

771-0922 

-6353 

(214) 

634 

2775 

(405) 353-2554 

(617) 

431-1699 

(803) 

772-1592 

-1920 

(214) 

641 

8759 

(405) 528-8009 

(617) 

649-7097 

(804) 

340-5246 

-4644 

(216) 

644 

1965 

(408) 241-1956 

(617) 

692-3973 

(805) 

484-9904 

-1489 

(216) 

754 

7855 

(408) 296-5799 

(617) 

864-3819 

(805) 

527-9321 

-5438 

(301) 

344 

9156 

(408) 263-0248 

(617) 

897-0346 

(805) 

682-7876 

-8983 

(303) 

759 

2625 

(408) 263-9650 

(617) 

963-8310 

(805) 

964-4115 

-5134 

(303) 

789 

0936 

(414) 241-5406 

(702) 

826-7234 

(806) 

355-5610 

-5590 

(305) 

261 

3639 

(702) 

873-9491 

(813) 

223-7688 

-0203 

(305) 

566 

0805 

(414) 241-8364 

(703) 

281-2125 

(816) 

523-9121 

-6239 

(305) 

689 

3234 

(414)  282-8118 

(703) 

281 -2222 

(816) 

531-1050 

-3282 

(305) 

772 

4444 

(415)  348-2139 

(703) 

379-0303 

(816) 

861-7040 

-0444 

(305) 

821 

7401 

(415)  348-2396 

(703) 

620-4990 

(816) 

931-3135 

-6392 

(305) 

989 

9647 

(415)  493-7691 

(703) 

734-1387 

(817) 

855-3916 

-4363 

(309) 

688 

0470 

(415)  527-0400 

(703) 

750-0930 

(817) 

855-3918 

-6576 

(309) 

694 

6531 

(415)  647-9524 

(703) 

893-9474 

(817) 

923-0009 

-5520 

(312) 

255 

6489 

(415)  661-0705 

(703) 

978-7561 

(901) 

276-8196 

-2186 

(312) 

269 

8083 

(415)  683-4703 

(707) 

448-9055 

(901) 

362-2222 

-4276 

(312) 

337 

6631 

(415)  792-8406 

(901) 

761-4743 

-5706 

(312) 

420 

7995 

(415)  851-3453 

(713) 

233-7943 

(902) 

794-8198 

-3715 

(312) 

622 

8802 

(415)  948-1474 

(713) 

693-8080 

(904) 

243-1257 

-0135 

(312) 

528 

7141 

(417) 862  7852 

(713) 

977-7019 

(904) 

243-8565 

-1849 

(312) 

545 

8086 

(419)  865-1584 

(714) 

•49-5689 

(913) 

362-6398 

-5728 

(312) 

622 

9609 

(502)  245  8288 

(714) 

463-0461 

(913) 

764-1520 

-6332 

(312) 

767 

0202 

(502)  896-9624 

(714) 

495-6458 

(913) 

782-5115 

-1505 

(312) 

782 

8180 

(503)  646-5510 

(714) 

526-3687 

(915) 

584  5393 

-1592 

(312) 

782 

9751 

(512)  657-0779 

(714) 

537-7913 

(916) 

393-4459 

3905 

(312) 

941 

9009 

(513)  671-2753 

(714) 

565-0961 

(918) 

224-5347 

-3506 

(312) 

964 

7768 

(513)  874-2283 

(714) 

571-5550 

-4718 

(313) 

288 

0335 

(515)  279-8863 

(714) 

582-9557 

-3177 

(313) 

357 

1422 

(516)  938-9043 

(714) 

730-1206 

-6400 

(313) 

465-9531 

(523) 223-3672 

(714) 

739-0711 

-8035 

(313) 

477-4471 

(602)  866-0258 

(714) 

751-1422 

-3186 

(313) 

484 

0732 

(602)  956  5612 

(714) 

772-8868 

-8803 

(313) 

569 

2063 

(602)  957-4428 

(714) 

898-1984 

42 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 

87 


The  Radio  Shack 
Pocket  Computer 


T 

1  he  curiosity  bug  bit  me  after  read¬ 
ing  a  review  of  Radio  Shack’s  pocket 
computer  in  the  December  1980  Inter¬ 
face  Age.  That  review  gives  several  ex¬ 
amples,  so  I  will  stick  to  the  surprises. 

There  are  26  variables  plus  an  array. 
The  array  includes  the  26  variables  and 
continues  through  however  much  mem¬ 
ory  may  be  left  over.  Any  of  these  data 
locations  can  be  treated  either  as  a  string 
or  a  floating  point  variable.  Note,  how¬ 
ever,  that  it  is  still  the  same  location  and 
can’t  be  used  both  ways  at  the  same  time! 

Numeric  precision  is  10  digits  plus  an 
exponent  of  ±  99.  Strings  are  limited  to 
7  characters.  You  start  with  1424  bytes 
free  plus  the  26  regular  data  locations. 
Keywords  fit  in  one  byte.  Data  words 
are  8  bytes. 

String  variables  can  be  INPUT  to, 
PRINTed  from  and  assigned  or  tested  for 
equality  to  other  string  variables  and 


by  Dick  Greenlaw 


Dick  Greenlaw,  251  Colony  Ct.,  Gahanna, 
Ohio  43230. 


string  constants.  However,  you  can’t  take 
them  apart  or  combine  them. 

I  ran  a  couple  of  benchmarks  from 
old  Kilobaud  articles.  The  pocket  com¬ 
puter  is  25  times  slower  than  my  Micro- 
polis  BASIC,  which  is  in  turn  fairly  slow 
compared  to  Microsoft.  That  was  a  disap¬ 
pointment,  but  probably  reasonable 
enough  for  a  computer  which  runs  300 
hours  on  four  camera  batteries  and  keeps 
all  of  its  program  and  data  memory  alive 
even  when  it  is  turned  off. 

Radio  Shack  has  crammed  into  a 
pocket-sized  computer  a  very  clever  in¬ 
terpreter  with  excellent  debugging  aids 
and  both  line  and  character  level  editing. 
Although  the  display  is  only  24  charac¬ 
ters  wide,  horizontal  cursor  controls  al¬ 
low  program  lines  up  to  80  characters 
long. 

The  optional  cassette  interface  allows 
storage  and  retrieval  of  programs,  data 
and  “reserved”  programs.  It  also  allows 
verification  of  programs  and  “reserved” 
programs. 

Programs  can  also  CHAIN  to  other 
programs  on  the  tape.  Motor  control  is 
provided  and  most  recorders  can  be  used. 
Files  obviously  have  to  be  in  order,  but 
they  don’t  have  to  be  consecutive!  All 
cassette  operations  require  a  file  name 
which  is  a  string  constant  or  variable.  For¬ 
ward  file  searching  is  automatic  and  you 


could  request  the  user  to  rewind.  Unfor¬ 
tunately,  I  haven’t  found  any  way  to  read 
or  catalog  a  file  with  an  unknown  name. 

“Reserved  programs”  are  definitions 
of  strings  assigned  to  keys  as  an  aid  to 
program  entry.  Typing  shift-key  inputs 
the  user-assigned  string  for  the  key. 

String  constants  can  also  be  used  as 
labels  by  placing  them  just  after  the  line 
number.  Then  GOTO  “THERE”  and 
RUN  “PROGRAM”  become  legal!  Single 
character  labels  can  be  used  to  run  rou¬ 
tines  by  name  when  in  a  special  run 
mode.  Again,  the  shift  key  gives  other 
keys  user-assigned  meanings. 

In  summary,  the  pocket  computer  is 
very  clever  and  should  appeal  to  users  of 
programmable  calculators.  It  has  trig  and 
log  functions  and  their  inverses!  However, 
it  is  a  bit  slow.  Lunar  lander  takes  several 
seconds  to  respond  to  each  burn  period. 
My  plans  of  cramming  a  small  checkers 
game  into  it  appear  a  bit  optimistic  be¬ 
cause  of  the  speed,  and  just  possible  in 
space.  (Remember,  each  data  location 
uses  8  bytes.) 

Documentation  consists  of  a  very  de¬ 
tailed  book  of  over  100  pages  and  a  sum¬ 
mary  card  that  fits  in  the  carrying  case. 
Radio  Shack  states  that  the  book  is  not 
for  beginners  and  recommends  some 
introductory  books. 


Sinclair’s  ZX80 

(continued  from  page  15) 

newline  key  if  there  is  an  error  (a  little 
IC  bug  may  come  and  bite  your  finger  if 
you  fry)!  The  newline  key  is  inactive  un¬ 
til  after  the  invented  letter  “S”  goes  away. 
But  if  you  need  to  change  a  line  that  was 
entered  earlier  for  some  other  reason, 
simple!  Move  the  up  or  down  cursor  con¬ 
trol  until  it  is  on  that  line.  Then  hold  the 
shift  key  and  hit  the  “edit/newline”  key 
and  watch  what  happens. 

The  power  in  this  method  of  text 
editing  is  greater  than  what  you  expect. 
Do  any  of  Dr.  Dobb’s  readers  remember 
the  Control  A  trick  in  MITS  extended 
BASIC  4.0?  It  was  not  fully  documented 
then,  and  even  now  the  Microsoft  man¬ 
ual  does  not  tell  all.  Something  like 
that  is  in  ZX80  BASIC,  and  it  is  ex¬ 
plained  clearly.  Just  look  in  the  index  of 
the  operating  manual  (what,  an  index 
too?)  under  EDIT  and  then  read  page  26. 
What?  You  didn’t  find  it  on  page  26? 


Sorry,  try  the  last  paragraph  on  page  90. 

Yes,  it  is  true.  The  edit  command 
may  be  used  to  change  the  line  number  of 
a  program,  and  the  original  line  is  still 
there!  This  is  perfect  for  those  programs 
where  a  dozen  lines  are  duplicates  or  have 
only  a  few  changes  to  be  made.  Think 
about  it! 

If  I  seem  excited  about  this  feature, 

I  am!  Do  you  really  need  a  line  editor  for 
a  very  simple  BASIC  system?  I  think  so. 
When  the  Radio  Shack  TRS-80  was  first 
introduced  about  four  years  ago,  it  was 
very  hard  to  program  if  you  were  not  a 
perfect  typist.  The  only  way  you  could 
edit  a  program  line  was  to  re-type  the 
whole  line.  If  you  got  it  wrong  the  second 
time,  try  again  and  again. 

Of  course,  I  cannot  compare  the  Sin¬ 
clair  ZX80  at  two  hundred  dollars  with 
the  new  Radio  Shack  Color  Computer  at 
four  hundred.  But  at  least  my  Sinclair  has 
a  simple  way  to  edit  a  line.  According  to 
Radio  Shack,  their  TRS-80  Color  Com¬ 
puter  and  the  TRS-80  Level  III  (for  seven 


hundred  dollars),  both  use  Level  I  BASIC. 
This  means  that  anyone  who  programs 
either  of  these  will  come  into  the  same 
snag  that  the  first  TRS-80  had  four  years 
ago.  This  is  why  I  am  so  pleased  with  the 
edit  mode  of  the  Sinclair  ZX80. 

JOHN  B.  PALMER,  P.  O.  Box  23,  Boon- 
ville,  CA  95415.  The  author  has  two 
other  home  computers,  both  older  and 
more  costly  than  his  new  Sinclair  ZX80. 
They  are  an  Apple  II  Plus  with  dual 
drives,  and  an  Altair  8800b  with  dual,  8- 
inch  drives,  56K  and  CP/M.  Before  his 
recent  move  to  small-town  living,  he 
spent  two  years  designing  software  and 
hardware  for  8080 -based  test  equipment 
at  Dysan  Corporation  in  Santa  Clara,  CA. 


Dr.  Dobb’s  Journal,  Number  52,  February  1981 
88 


43 


S3] 


(T^  *  * 


7TT~‘. 


$2.50  ($3.00  In  Canada) 


Dr.  Dobb  s  Journal  of 

COMPUTER  Calisthenics  6  Orthodontia 

FOR  USERS  OF  SMALL  COMPUTER  SYSTEMS 

Number  53  March  1981  Volume  6,  Issue  3 


Analysis  of  the  Use  of  the  6502’s  Opcodes 

Howard  W.  Whitlock,  Jr. 

ERGO:  A  “Thinking  Program” 

Sylvan  Rubin 

Byte  Manipulation  and  Byte  Pointers 

Edwin  E.  Freed 

Small-C:  Current  Status 

P.L.  Woods 

Interfacing  the  TRS-80  Voice  Synthesizer 
to  Other  Micros 

Michael  Hightower  and  Peter  B.  Maggs 


and,  once  again,  even  more . . . 


Kc 


P.O.  Box  E 
Menlo  Park 
CA  94025 


Dr.  Dobb’s  Journal  of 

COMPUTER  Calisthenics  6  Orthodontia 


Volume  6,  Issue  3 
Number  53 
March  1981 


Contents 


Articles 


Computer-Based  High  Speed  Reading . 10 

by  Dave  Caulkins 

Analysis  of  the  Use  of  the  6502’s  Opcodes . 11 

by  Howard  W.  Whitlock,  Jr. 

ERGO:  A  “Thinking  Program” . 16 

by  Sylvan  Rubin  and  Sheldon  Softky 

Using  WORD -MASTER  With  the  Compal-80.  .  .  18 

by  Anthony  Skjellum 

Byte  Manipulation  and  Byte  Pointers . 19 

by  Edwin  E.  Freed 

Small-C:  Current  Status . 20 

by  P.  L.  Woods 

DOSMOVER  for  the  North  Star . 40 

by  Thomas  W.  Cage 

Video  Underline  Modification . 42 

by  Dannie  E.  Davis 

Interfacing  the  TRS-80  Voice  Synthesizer 
to  Other  Micros . 46 

by  Michael  Hightower  and  Peter  B.  Maggs 


Departments 

Letters .  5 

Book  Reviews .  15 

Software  Reviews . 38 

Of  Interest . 50 

Electric  Phone  Book . 52 


Publisher 

Ann  Merchberger 
Editor 

Marlin  Ouverson 
Contributing  Editors 
Dave  Caulkins 
Dave  Cortesi 


Art  Director 
Clifford  West 
Artist 

Barbara  Ruzgerian 
Typesetter 
Renny  Wiggins 
Proofreader 
Nancy  Heubach 


Marketing  Director 
Gavin  W.  Cullen 
Advertising  Director 
Michael  Madaj 
Circulation  Manager 
Peter  Clark 
Circulation  Assistant 
Leah  Dansby 


©  1981  by  People’s  Computer  Company  unless  otherwise 
noted  on  specific  articles.  All  rights  reserved. 

Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per  year 
by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real,  Menlo 
Park,  CA  94025.  Second  class  postage  paid  at  Menlo  Park, 
California  94025  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  94025. 

Subscription  Rates  &  Writer’s  Guidelines  on  page  1 8. 


Editorial 


The  kinetic  energy  which  abounds  at  People’s  Computer 
Company  can  be  dismaying  to  new-found  friends  and  occa¬ 
sional  visitors.  Our  small  offices  are  charged  with  dynamics 
too  rarely  found  in  typical  business  settings.  A  few  steps 
through  our  miniature  maze  of  corridors  leads  the  unwary 
from  the  home  of  two  international  magazines  to  the  seat  of 
PCC’s  computer  literacy  project  (ComputerTown,  USA!)  and 
to  the  focus  of  PCNET’s  protocol  development.  Paths  lead 
in  several  directions  to  the  realms  of  marketing,  sales, 
accounting,  production  and  circulation. 

On  any  day  at  PCC  one  may  meet  government  officials 
and  hackers,  heads  of  state  and  solid  state  genii.  Well,  per¬ 
haps  not  heads  of  state.  They  come  to  meet  Dr.  Dobb’s 
consortium.  Thus  cross  the  paths  of  the  mighty  and  the 
humble  (well,  not  that  humble  .  .  .). 

It  is  the  diversity  which  is  so  astounding,  and  the  tangi¬ 
ble  evidence  that  each  component  is  interactive  with  the 
whole.  Each  part  functions  under  the  intense  scrutiny  of  Doc 
(peering  through  his  bifocals)  with  the  help  of  his  workers 
and  volunteers.  The  juxtaposition  of  various  personalities  and 


projects  at  PCC  creates  a  homogenous  kind  of  spontaneity 
(even  the  definition  defies  linear  logic!). 

One  of  the  guiding  hands  of  PCC  once  described  this  as  a 
place  where  a  thousand  lillies  may  blossom.  We  allow  the 
entrance  of  diverse  elements  into  our  schematic  —  the  strong 
ideas  thrive,  the  weak  ones  fade  into  the  sunset.  Gigo!  This 
is  the  course  nature  follows.  PCC  and  its  publications  do  not 
censor,  but  provide  a  proving  ground.  Success  or  failure 
should  be  inherent  and  not  a  matter  of  bias. 

Marlin  Ouverson 
Editor 


90 


Letters 


DDJ’s  responsive  readership  can  give  you 
invaluable  feedback  on  your  ideas  and  innova¬ 
tions.  Find  out  how  you  can  reach  them  by 
contacting  us  at : 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


OK 

FIBO 

OK 

1 

OK 

1 

50  LIST 

2 

SCR  #50 

3 

(  SCR#50DEC  -  FIBONACCI  NUMBERS  ) 

8 

13 

:  FIBO  0  1  1 1  1  DO 

21 

CRDUP. 

34 

SWAP  OVER  + 

55  OK 

LOOP  ; 

.  89  OK 

.  55  OK 

:  FIBONACCI  (  #  OF  FIB.NOS.  WANTED  -  >  ) 

.  0  EMPTY  STACK 

0  1  (SET  UP  FOR  CALCULATIONS  ) 

OK 

ROT  (  GETS  #  WANTED  ) 

OK 

0  DO  (SET  UP  LOOP  -  0  IS  LEGAL  ) 

OK 

CR  (  GO  TO  NEXT  LINE  ) 

10  OK 

DUP.  (DUP  TOP  #4  PRINT) 

SWAP  OVER  (  SWITCH  FOR  ADDITION  ) 

FIBONACCI 

+  (  ADD  2  TOP  NUMBERS  ) 

I 

LOOP  (  GO  BACK  FOR  NEXT  NUMBER  ) 

1 

DROP  DROP  (  CLEAN  UP  THE  STACK  ) 

2 

3 

5 

8 

OK 

13 

50  LOAD  50  OK 

21 

OK 

34 

OK 

55  OK 

.  0  EMPTY  STACK 

.  0  EMPTY  STACK 

Dr.  Dobb’s  Journal  welcomes  letters  to 
the  editor  as  a  forum  for  ideas,  innova¬ 
tions,  irascibility  and  even  idiosyncrasies. 
Some  letters  may  be  edited  for  clarity 
and  brevity.  The  Doctor  likes  hearing 
from  you  -  keep  on  writing! 


A  Flare  for  FORTH 

Dear  DDJ: 

Issue  Number  5 1  arrived  today,  and  I 
found  Dr.  Gordon’s  article  (“What  is 
FORTH?”)  interesting  but  confused. 

Your  production  department  ran  in¬ 
to  some  sort  of  proofreading  problem 
about  1/3  of  the  way  down  the  lefthand 
column  of  page  12,  producing  some  con¬ 
fusion  about  what  was  meant  ( see  box 
this  page.  -Ed.). 

Dr.  Gordon’s  basic  problem  is  that 
he  does  not  have  a  running  FORTH  sys¬ 
tem,  and  Bruce  Airy’s  NOVA  implemen¬ 
tation  is  seriously  out  of  date.  I  suspect  it 
was  done  from  a  very  early  FORTH 
model,  and  limited  by  the  machine. 

If  Dr.  Gordon  could  specify  just 
what  kind  of  computer  he  has  maybe  we 
at  FIG  could  provide  him  with  a  system 
to  work  with,  which  would  relieve  some 
of  his  confusion. 

Having  a  FORTH  system,  I  tried  out 
his  FIBO  program,  and  found  that  it  does 
indeed  work,  but  leaves  garbage  on  the 
stack  when  it  finishes. 

The  two  numbers  left  are  the  last 
two  Fibonacci  numbers,  which  are  wait¬ 
ing  to  be  used  to  calculate  the  next  one; 
but  the  program  exited  from  the  loop, 
leaving  them  behind.  In  order  not  to  mess 
up  the  programs  which  follow,  every  rou¬ 
tine  must  leave  the  stack  exactly  as  it 
found  it.  This  means  that  any  values  it 
puts  on  the  stack  while  it  is  running  must 
either  be  used  up,  or  DROPped  when  it 
finishes  execution. 

The  attached  listing  of  Screen  #50 
shows  a  cleaned-up  version  of  FIBO, 
called  FIBONACCI  (figFORTH  supports 
names  with  up  to  31  characters),  which  is 
a  bit  more  general  —  it  takes  a  parameter 
on  the  stack  which  tells  it  how  many  of 
the  Fibonacci  numbers  you  want  it  to  cal¬ 
culate. 

Sincerely, 

S.  B.  Bassett 

Guest  Editor,  FORTH  Dimensions 
c/o  151  University  Avenue 
Palo  Alto,  C A  94301 


.  .  .  another  sad  story 

Dear  DDJ  I  Ex  Machina: 

Regarding  the  Hazeltine  terminal 
letters  in  your  Jan.  81  issue:  Over  the  last 
three  years,  our  lab  has  purchased  eight 
Hazeltine  1500s.  The  first  was  selected 
for  its  price  ($860)  in  mid- 1977.  In  early 


1977  we  bought  another,  and  in  mid-78 
we  bought  two  more. 

At  that  time  we  also  purchased  the 
service  manual,  since  we  intended  to  fix 
them  ourselves.  A  little  while  later  the 
first  unit  required  a  replacement  picture 
tube.  At  that  time  we  removed  some  very 
overheated  parts  from  the  video  board, 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


5 

91 


and  brought  that  board  up  to  the  revision 
level  expressed  by  the  schematics  and  the 
two  new  terminals.  In  November  of  1978 
we  bought  our  last  4  Hazeltines.  Two  re¬ 
quired  replacement  of  the  main  logic 
board  upon  arrival,  and  a  third  required  it 
a  week  later.  (All  in-warranty  repair  work 
was  done  on-site  by  TRW). 

Since  then,  we  have  added  a  fan  to 
the  first  unit  to  cool  the  once- more  over¬ 
heated  video  resistors  (R13,  R63  and 
R64),  which  we  also  replaced  with  double 
the  design  wattage.  One  of  the  other  units 
also  fried  those  resistors,  but  did  not  re¬ 
quire  a  fan.  After  a  year,  another  unit  lost 
its  Intel  8224  chip,  which  we  replaced. 

After  16  terminal-years  of  operation, 
they’re  chugging  along  pretty  well,  with 
some  reservations.  The  keys  are  cheap 
switches,  with  a  periodic  cleaning  require¬ 
ment.  We  simply  pull  all  of  the  keycaps 
and  squirt  in  contact  cleaner,  wipe  with  a 
burnishing  tool  (or  newspaper)  and  put 
back  the  keycaps.  Somebody  recently 
tried  to  remove  a  powercord  by  catching 
it  in  a  door  hinge.  The  strain  relief  gave 
its  life  to  save  the  terminal’s  guts,  and  the 
repair  was  minimal. 

My  overall  impressions  are:  The 
Hazeltine  1500  series  uses  a  common 
master  logic  board,  a  common  video 
board,  and  (1520’s)  an  optional  extra 
board  for  printer  operations.  The  1500 
master  board  consists  of  an  8080  proces¬ 
sor,  2K  bytes  of  RAM,  a  character  genera¬ 
tor  ROM  (or  two)  and  a  program  ROM 
(or  two).  There  is  also  a  large  number  of 
support  chips  and  components.  The  key¬ 
board  is  an  integral  part  of  the  main  logic 
board.  All  components  (except  for  the 
character  ROM)  are  soldered  in  place,  and 
two  cables  lead  to  the  power  supply  and 
video  board.  The  RS232  connectors  and 
option  board/maintenance  connectors  are 
on  the  rear  edge.  We  have  found  this 
master  logic  board  to  be  quite  well  de¬ 
signed,  and  quite  reliable  -  AFTER  THE 
FIRST  WEEK.  At  the  time  of  our  “four 
in,  three  bad”  delivery,  other  people  on 
the  campus  were  reporting  50%  dead-on- 
arrival. 

The  video/monitor  board  is  another 
story.  Many  of  the  components  appear  to 
run  at  their  design  limits  ( 1  watt  resistors 
dumping  .9  watts).  This  has  led  to  the 
only  design-fault  repairs  we  have  had.  All 
of  the  units  are  visibly  cooking  up  there 
(the  boards  are  discoloring),  but  shouting 
at  people  who  block  the  cooling  vents 
keeps  the  repair  rates  down.  Our  first  unit 
did  not  have  ventilation  slots  that  later 


ones  grew,  but  it  now  has  a  fan.  The  first 
three  did  not  have  access  to  the  vertical 
hold  adjustment  pot.  We  drilled  the  hole 
that  later  appeared  in  Hazeltine’s  newer 
cases. 

Hazeltine  will  mail  replacement 
parts,  but  I  believe  there’s  a  $50  mini¬ 
mum.  Their  prices  are  such  that  meeting 
the  minimum  is  no  problem.  To  replace 
the  main  logic  board  is  about  $600.  To 
replace  the  8080  was  (old  pricelist)  $75. 
We  don’t  buy  our  parts  from  Hazeltine. 

They  used  to  sell  a  “kit”  version  of 
the  1500  for  $799.  The  only  assembly 
required  was  putting  the  power  supply 
and  main  board  into  the  case  and  bolting 
it  together.  It  was  almost  worth  it  for  the 
replacement  part  stock. 

The  dirty -key  problem  is  a  continual 
pain.  My  personal  view  is  that  the  rubout/ 
delete  should  NOT  be  a  SHIFT  function 
. . .  it  should  be  the  lowercase  code,  or  a 
separate  key.  The  control  key  is  located 
in  a  horrible  spot  (at  the  left  end  of  the 
space  bar).  Everybody  hits  it  instead  of 
SHIFT  (especially  when  doing  deletes). 
The  shift  keys  should  be  double  sized. 
The  CLEAR  key  should  be  a  local  func¬ 
tion,  not  a  send-to-computer,  computer- 
echo-to-clear  sequence. 

Nice  touches  are:  the  terminal  con¬ 
figuration  switches  are  easy  to  get  to  and 
well  labeled  (if  you  know  what  they 
mean).  The  RS232  connector  also  sup¬ 
ports  current  loop,  and  is  extremely  flex¬ 
ible  in  its  handling  of  the  control  signals 
that  RS232  can  throw  at  you.  The  termi¬ 
nal  can  be  run  with  the  simplest  3  wire 
hookup  (signal  in,  out  and  ground),  but 
is  fully  capable  of  being  controlled  by 
clear-to-send,  carrier-detect  and  the  rest. 
The  pass-through  AUX  port  is  very 
handy  for  classroom  repeater  applications 
and  testing  of  other  terminals.  If  you 
hold  down  RESET  when  turning  on  the 
terminal’s  power,  the  screen  maps  the 
control  area  of  RAM.  Our  units  give  dif¬ 
ferent  screens,  with  different  effects  from 
later  keystrokes,  but  it’s  a  valuable  quick - 
diagnosis  tool.  The  built-in  glare  killer  is 
very  effective. 

Since  then  we  have  switched  to 
Zenith  Z-91’s  (Heathkit  H-19).  These  are 
available  fully  assembled  for  $740  in  all 
the  magazines.  They  have  a  very  good 
keyboard  layout  (IBM  Selectric).  Their 
DEC  VT52-emulation  matches  our  two 
DEC  computers  very  nicely.  The  first  one 
we  played  with  lost  its  flyback  transform¬ 
er  after  two  hours.  A  call  to  Heath  re¬ 
vealed  that  they  had  gone  to  an  upgraded 


model,  which  was  mailed  to  us.  The  three 
Z-19’s  we  have  received  since  then  have 
worked  flawlessly.  From  a  self-repair 
point  of  view,  the  Heaths  shine  with  their 
fully-socketed  logic  boards,  although  I 
grant  that  contact  corrosion  could  be  a 
source  of  future  hassle.  The  video  board 
is  soldered,  but  well  laid  out  and  runs 
cool.  The  keys  are  the  same  cheap  switch 
that  the  Hazeltine  uses  (sigh).  The  termi¬ 
nal  configuration  is  set  by  internal  DIP 
switches.  The  switches  can  be  overridden 
by  keyboard  or  computer  command. 
Price  and  functionality  (buzzword)  will 
probably  keep  us  here  until  something 
better  comes  along.  The  Hazeltine  1552  is 
too  expensive  (the  dumb  1500  is  $790) 
and  the  Heath  will  be  easier  to  fix  (far 
fewer  parts,  cooler  video  design). 

When  people  ask  (and  they  do)  I  tell 
them  that  there  are  cheaper  terminals  on 
the  market,  but  if  you’re  talking  to  a 
DEC  (or  Heath  HI  1)  computer,  the  Z 1 9/ 
HI 9  is  the  way  to  go. 

My  views  toward  Mr.  Callas’  problem 
are  muted  by  the  same  lack  of  informa¬ 
tion  that  Hazeltine  complains  about. 
What  is  meant  by  “doesn’t  work  proper¬ 
ly”?  The  normal  user’s  manual  is  not  suf¬ 
ficient  for  some  strange  hookups.  I’ve  oc¬ 
casionally  had  to  reference  the  schema¬ 
tics  to  determine  which  side  of  the  con¬ 
nector  was  causing  the  zoo  marching  (or 
failing  to  march)  across  my  screen.  If  he 
means  that  some  random  keys  don’t 
work,  they’re  probably  dirty.  If  the  entire 
numeric  keypad  doesn’t  work,  it’s  a  real 
problem.  Our  experience  with  3-of-4  fail¬ 
ing  leads  me  to  mistrust  a  new  Hazeltine, 
but  many  other  factors  (temperature,  line 
noise,  trying  to  get  current-loop  out  of 
the  AUX  port  (you  can’t))  can  cause 
“faulty”  operation.  If  TRW  will  only  re¬ 
spond  to  “commercial  locations,”  Mr. 
Callas  can  walk  to  the  comer  grocery 
store  and  call  TRW  from  there.  Maybe  a 
local  Radio  Shack  would  be  willing  to 
have  him  camp  out  there,  waiting  for  the 
terminal  doctor.  Since  the  usual  on-site 
repair  method  is  total  replacement  of  the 
main  logic  board  (in  a  1500,  that’s  all 
there  is),  each  of  his  trips  to  TRW  should 
have  effectively  resulted  in  his  acquiring 
a  “new”  terminal.  I  do  wonder  what  his 
symptoms  were  . . .  could  he  demonstrate 
them  to  TRW?  Did  he  try? 

I  have  found  Hazeltines  to  be  quite 
reliable  after  the  first  few  minutes  of 
operation,  with  the  occasional  exception 
of  the  older  video  boards.  Our  campus 
has  (probably)  more  than  100  of  them. 


6 

92 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


and  any  I  see  in  offices  appear  to  be  hap¬ 
pily  working.  The  only  reasons  I  do  not 
plan  to  buy  more  is  price  and  perfor¬ 
mance  relative  to  terminals  which  were 
not  available  at  the  time  I  started  buying 
Hazeltines.  The  Hazeltine  1500  series  is 
fast  becoming  obsolete  for  the  self- 
maintainer,  due  to  construction  methods 
and  parts  count. 

Richard  Seymour 
University  of  Washington 
Nuclear  Physics  Lab  GL-10 
Seattle,  WA  98195 


Interaction  vs.  Speed 

Dear  DDJ, 

Anthony  Skjellum’s  preamble  to  his 
Z-80  video  driver  package  in  DDJ  #51 
has  prompted  a  few  thoughts  on  time- 
dependent  coding.  He  states:  “Scrolling 
is  the  rate  dependent  step  in  text  display, 
therefore  extra  attention  has  been  put 
toward  minimizing  the  execution  time  of 
[the  scroll  routine]  and  to  decoding  the 
linefeed  character  ....  If  scrolling  could 
be  removed,  the  display  speed  would  be 
much  faster  ....  Instead  of  scrolling,  the 
cursor  is  made  to  home  ....  The  only  dis¬ 
advantage  is  a  slight  loss  in  readability 
which  I  feel  is  made  up  for  by  the  gain  in 
throughput.”  Just  the  sort  of  remarks 
that  send  system  programmers  back  for 
another  squint  at  trustworthy  old  driver 
code! 

Our  console  display,  like  Skjellum’s, 
is  IK  (16  lines  by  64  columns)  and  mem¬ 
ory  mapped.  Scrolling  is  handled  in  the 
customary  way:  move  the  last  15  lines  up 
1  line,  blank  the  last  line,  write  the  cursor 
to  its  first  column.  Our  driver  was  written 
four  years  ago  in  8080  code,  without 
benefit  of  such  luxuries  as  LDIR  and  bit 
manipulation  instructions.  The  scroll 
handier,  which  was  speed-optimized  with 
some  care,  is  45  bytes  long,  including  up¬ 
dating  of  the  byte  variable  which  holds 
the  cursor  X  coordinate,  and  runs  in 
48220  clock  cycles.  Since  our  CPU  is 
Z-80  at  4MHz  and  the  driver  is  down¬ 
loaded  to  RAM  on  cold  boot,  a  scroll 
operation  takes  12.055  milliseconds. 
Then  there  is  overhead  to  test  an  escape 
sequence  flag  byte  (through  a  slow  LDA 
addr,  ORA  A,  JNZ  addr  sequence,)  strip 
the  cursor,  detect  the  linefeed,  branch  to 
the  scroll  routine,  restore  the  cursor,  and 
return,  requiring  another  57  bytes  (420 
clock  cycles,  or  0.105  milliseconds).  An 
infinite  loop  to  pass  linefeeds  continuous¬ 


ly  to  the  video  driver  requires  8  bytes  and 
34  cycles  or  .0085  milliseconds.  Thus 
such  a  loop  will  scroll  the  display  up  one 
line  every  12.1685  milliseconds  or 
82.179398  times  per  second.  This  is 
about  2.74  times  faster  than  standard 
video  frame  rate  (30  Hz)  WHICH  IS  THE 
ACTUAL  TIME  DEPENDENCY  IN  THIS 
CASE.  All  sixteen  lines  will  scroll  off  the 
screen  in  about  0.195  second.  Is  this  a 
rate  of  data  throughput  that  dissatisfies 
the  human  eye?  If  it  is,  then  hardware 
scrolling  (the  old  VDM-1  had  it),  like 
hardware  random  number  generation,  is 
to  be  preferred. 

I  haven’t  nickel-and-dimed  my  way 
through  Skjellum’s  drivers  (which  are  ob¬ 
viously  faster)  in  the  same  way,  and  the 
foregoing  in  no  way  implies  a  criticism  of 
them:  they  work  fine  within  his  stated 
limits,  a  good  tutorial  for  people  new  to 
a  nontrivial  problem  .  .  .  and  I’m  grateful 
for  the  reminder  that  our  own  system 
drivers  need  recoding  for  the  Z-80.  How¬ 
ever,  such  recoding  will  be  done  very 
largely  in  the  interest  of  wringing  the  last 
bytes  out  of  precious  space  in  the  mem¬ 
ory  map,  with  careful  attention  to  user 
legibility,  where  it  is  often  desirable  to 
slow  down  a  console  display,  rather  than 
speed  it  up.  Some  code  is  time  dependent 
only  within  rather  wide  limits,  and  not 
to  worry  if  it  doesn’t  tear  along  like  a 
Maserati.  This  applies  especially  to  user 
interface  I/O.  Human  beings  are  notori¬ 
ously  “slow  peripherals”  and  benefit 
more  from  interaction  than  speed,  assum¬ 
ing  the  system  isn’t  hopelessly  pokey. 

We’re  no  strangers  to  time  dependen¬ 
cy  around  here.  Raster  graphics  and 
sound  synthesis  are  the  main  concerns  of 
this  lab.  Floppy  disk  I/O  is  a  molasses 
nightmare,  and  waiting  for  the  so-called 
Fast  Fourier  Transform  to  do  its  job,  or 
watching  a  clever  cellular  automaton 
crawl  through  a  64K  pixel  array,  can 
bring  the  bravest  assembly  language  hack¬ 
er  to  the  verge  of  tears!  So  this  is  not  one 
of  those  “BASIC  is  always  good  enough” 
protests.  It’s  simply  to  offer  the  sugges¬ 
tion  that  we  take  a  hard  look  at  the  ac¬ 
tual  constraints  of  software  design  before 
tormenting  ourselves  about  squeezing  the 
last  nanosecond  out  of  a  loop.  To  do  so 
may  not  always  be  better,  but  it  is  AL¬ 
WAYS  harder,  and  there  may  be  more 
gratifying  places  to  use  our  energy. 

Thanks  for  a  publication  of  continu¬ 
ing  excellence.  Lab  copies  quickly  become 
battered  like  old  teddy  bears.  That’s  al¬ 
ways  high  praise. 


Best  regards, 

Hollis  Frampton 
Digital  Arts  Lab 
Center  for  Media  Study 
SUNY  at  Buffalo 
Buffalo,  NY  14214 

A  Doctor’s  Advocate  .  . . 

Dear  Doctor, 

It  is  over  a  year  since  I  have  taken 
word  processor  in  hand  and  dashed  off  a 
letter  to  my  beloved  Dr.  Dobbs.  The  im¬ 
mediate  cause  is  a  letter  from  a  Mr.  Ickler 
of  Corpus  Cristi,  whose  obvious  sexism 
shows  his  social  conscience  to  be  as  anti¬ 
quated  as  his  knowledge  of  computers. 
The  passage  that  referred  to  the  editor  as 
a  “girl  journalism  student”  shows  his  sex¬ 
ual  bias  (come  to  think  of  it,  what  ever 
happened  to  that  adjective  “female”?). 

When  he  says,  “I  am  looking  for  de¬ 
tails  on  writing  systems  utilities  such  as 
spoolers,  designing  compilers,  text  editors 
and  so  on.  Maybe  a  tutorial  on  CP/M  con¬ 
cepts  is  useful,  but  PASCAL[sic] ?”,  he 
shows  his  knowledge  of  system  design  to 
be  equally  out  of  date.  At  many  com¬ 
panies,  including  the  small  computer 
company  for  which  I  work  (Apple),  such 
system  software  is  often  written  in  Pascal. 

Anybody  who  claims  to  be  interested 
in  writing  system  software  but  decries 
Pascal  is  certainly  not  in  any  position  to 
criticize  the  editor  of  DDJ  on  technical 
grounds.  Mind  you,  I  am  not  taking  up 
the  cudgel  for  the  Pascal  language  or  the 
UCSD  operating  system,  nor  am  I  attack¬ 
ing  the  CP/M  operating  system  -  a  pox 
on  both  their  houses  —  I  am  merely  not¬ 
ing  how  neatly  male  chauvinism  goes 
along  with  hasty,  uninformed  judgment. 

That  problem  laid  to  rest,  let  me 
voice  my  support  of  DDJ :  may  you  con¬ 
tinue  on  your  merry  orthodontic  way, 
living  from  hand  to  mouth,  telling  the 
truth  and  representing  computer  con¬ 
sumers  as  you  have  been. 

Jef  Raskin 
10696  Flora  Vista 
Cupertino,  CA  95014 

CP/M  DUMP 

Dear  DDJ: 

Enclosed  is  a  software  modification 
for  the  CP/M  DUMP  Utility  Program  that 
will  greatly  enhance  the  readability.  This 
mod  will  print  2  SPACES  after  the  line 
number,  2  SPACES  after  the  4th  and 
12th  bytes,  and  3  SPACES  after  the  8th 
byte. 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


7 

93 


Following 

LXI 

SP.STKTOP 

in  the  SET  UP  STACK  routine  add 

DD2 10402 

LXI 

IX,0204H 

;  Set  up  byte  counters 

following 

CALL 

PHEX  in  the  GLOOP  routine  add 

3E20 

MVI 

A,  ‘  ’ 

;  Double  space  after  Line  Number 

CD6101 

CALL 

PCHAR 

following 

CALL 

PHEX  in  the  NONUM  routine  add 

DD2D 

DCR 

LX 

;  Decrement  4th  byte  counter 

C2D301 

JNZ 

GLOOP 

3E20 

MVI 

A,” 

;  Double  space  after  4th  and  12th  byte 

CD6101 

CALL 

PCHAR 

DD2E04 

MVI 

LX, 4 

DD25 

DCR 

HX 

;  Decrement  8th  byte  counter 

C2D301 

JNZ 

GLOOP 

3E20 

MVI 

A,” 

;  Triple  space  after  8th  byte 

CD6101 

CALL 

PCHAR 

DD2601 

MVI 

HX,2 

Sincerely, 

Tom  Cage 
P.  O.  Box  806 
Roswell,  GA  30075 
A>DUMP  TEST.  123 


0000 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0010 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0020 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0030 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0040 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0050 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0060 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0070 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0080 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

0090 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

00  A0 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

0E 

OF 

00  B0 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

OE 

OF 

ooco 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

OE 

OF 

00  DO 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

0C 

0D 

OE 

OF 

00  E0 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

0C 

0D 

OE 

OF 

00  F0 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

0A 

0B 

OC 

0D 

OE 

OF 

A>DUMP1  TEST.  123 


0000 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0010 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0020 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0030 

00 

01 

02 

03 

04  05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0040 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0050 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0060 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0070 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0080 

00 

01 

02 

03 

04  05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

0090 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

00  AO 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

00B0 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

OOCO 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

0F, 

OF 

00  DO 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

00E0 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

00F0 

00 

01 

02 

03 

04 

05 

06 

07 

08 

09 

OA 

OB 

OC 

OD 

OE 

OF 

Bitter  Buyer 

Dear  Editor: 

Please  accept  the  following  book  re¬ 
view  for  publication  in  your  magazine. 

It’s  a  sad  day  when  a  publisher  can 
successfully  market  high-priced  rubbish; 
more  interesting  than  what  it  tells  us 
about  the  author  and  publisher  are  its  im¬ 
plications  about  the  marketplace.  “Buyer 
beware”  could  hardly  be  overemphasized 
in  today’s  fast-moving  microcomputer 
marketplace.  I  recently  bought  a  copy  of 
The  CP/M  Handbook  with  MP/ M  by  Dr. 
Rodney  Zaks  (a  SYBEX  publication) 
hoping  to  obtain  a  good  reference  work 
on  CP/M.  What  a  shock! 

Chapters  1,  3,  and  4  amount  to  a 
primer  on  operating  a  CP/M  computer, 
using  PIP,  and  using  ED.  Beyond  the 
limited  value  of  this  hand-holding  the 
book  is  a  veritable  wasteland.  By  the  skill¬ 
ful  use  of  ill-defined  (and  undefined)  ter¬ 
minology,  Dr.  Zaks  confuses  the  novice 
computer  user.  On  the  other  hand,  a  total 
lack  of  in-depth  information  makes  the 
book  useless  for  the  seasoned  user.  Dr. 
Zaks  succeeded  in  missing  both  audi¬ 
ences. 

The  text  is  a  cluttered  mass  of  bad 
grammar.  Unrelated  thoughts  are  concate¬ 
nated  into  rambling  sentences,  and  these 
are  further  grouped  into  arbitrary  para¬ 
graphs.  Careless  errors  abound.  In  several 
places  the  text  is  actually  incompatible 
with  referenced  figures.  But  what  I  find 
most  intolerable  is  the  inadequate  presen¬ 
tation  of  facts.  The  reader  is  presented 
with  statements  of  the  following  types: 

1 .  Vague  and  misleading: 

“The  theoretical  difference  between 
a  compiler  and  an  interpreter  is  that  a 
compiler  executes  the  program  more 
efficiently  while  an  interpreter  allows 
interactive  program  development.” 
(pg-  26) 

2.  Inconsistent: 

“Whenever  you  use  a  filename  as  an 
argument  to  a  command,  you  must 
type  the  entire  filename,  including  the 
extension,  if  any.  The  only  exception 
is  when  you  use  a  file  as  a  transient 
command  .  . (pg.  58) 


(Continued  on  page  13) 


8 

94 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


Computer-Based 
High  Speed  Reading 


Introduction 

It’s  fairly  well  known  that  the  high¬ 
est  data  rate  path  from  the  outside  world 
into  the  human  brain  is  through  the  eyes. 
For  most  people,  reading  is  the  primary 
technique  for  getting  information  pro¬ 
duced  by  other  humans  into  our  brains. 
The  popularity  of  speed  reading  courses 
indicates  a  widely  felt  need  to  speed  up 
this  form  of  information  transfer. 

Some  interesting  work  in  this  area 
has  been  done  by  Mary  Potter*,  a  re¬ 
searcher  at  MIT.  Her  idea  was  simple:  pre¬ 
sent  text  material  sequentially,  one  word 
at  a  time.  In  the  experiment  set  up,  the 
subject  looked  at  a  rectangular  window  in 
which  the  words  to  be  read  appeared  one 
after  the  other.  The  interesting  aspect  of 
this  arrangement  is  that  reading  takes 
place  without  any  muscle  movement; 
there  is  no  mechanical  limit  to  the  speed 
at  which  the  reading  can  take  place.  Ms. 
Potter  used  modified  movie  projectors  to 
present  the  text;  it  occurred  to  me  and 
to  others  that  a  computer-based  imple¬ 
mentation  would  be  easier  to  develop  and 
modify. 

A  friend  of  mine  at  Xerox  PARC 
(John  Warnock)  first  told  me  about  Ms. 
Potter’s  work  and  also  wrote  a  program 
for  a  PDP-11.  He  found  that  reading 
speeds  of  1000  words  per  minute  were 
feasible.  Those  experiments  were  prelimi¬ 
nary  and  not  closely  controlled.  In  Ms. 
Potter’s  work,  the  upper  limit  had  ap¬ 
peared  to  be  720  wpm  The  BASIC  pro¬ 
gram  given  below  permits  a  range  of 
speeds  from  225  to  450  wpm;  faster  im¬ 
plementations  are  possible  but  would  re¬ 
quire  machine  language  for  the  word-at- 
a-time  display  routine. 

Just  providing  a  high  bandwidth  path 
from  eyes  to  brain  is  no  guarantee  that 
use  of  such  a  path  will  allow  high-speed 
reading  with  good  understanding  and  re¬ 
tention  of  the  material  read.  The  subjec¬ 
tive  judgment  of  the  word-at-a-time 
reader  is  especially  questionable  if  the 
same  person  has  previously  input  the 
material  to  be  read. 

Given  these  warnings,  I  still  find  the 
technique  intriguing.  I  hope  others  agree, 
and  will  experiment  with  it  further.  Any 
technique  which  has  the  possibility  of 
increasing  the  rate  at  which  text  can  be 
read  is  worth  looking  into. 

by  Dave  Caulkins 

Dave  Caulkins,  1263  El  Camino  Real, 
Box  E,  Menlo  Park,  CA  94025. 


Computer-Based  Word-At-A-Time 
Reading 

The  BASIC  program  whose  listing  is 
given  below  runs  in  a  Commodore  PET 
equipped  with  a  Compu/ Think  disk  sys¬ 
tem.  The  program  allows  the  user  to  enter 
natural  language  text,  which  is  then 
stored  on  a  disk  file.  This  same  text  can 
be  read  from  the  file  and  presented  to  the 
user  for  reading  in  word-at-a-time  form. 
The  user  has  continuous  control  of  the 
rate  at  which  the  words  appear.  By  enter¬ 
ing  a  number  from  1  (fast)  to  9  (slow)  he 
can  vary  the  rate  at  which  the  words 
appear  from  450  to  225  words  per  min¬ 
ute. 

The  rate  is  dynamically  variable  dur¬ 
ing  the  word-at-a-time  display. 

The  BASIC  Program 

Some  peculiarities  of  PET  BASIC 
should  be  explained.  The  PET  uses  special 
characters  for  cursor  control;  unfortu¬ 
nately,  they  do  not  print  on  my  printer. 
I’ve  added  comments  to  indicate  these 
characters;  an  example  appears  in  line 
27.  Here  V$  is  set  equal  to  a  string  of  10 
move-cursor-down  characters.  Because 
they  do  not  print,  all  that  appears  in  the 
listing  is  V$=“  ”.  The  PET  has  an  OS- 
defined  time  variable  TI;  it  is  incremented 
every  1/60  second  under  interrupt  con¬ 
trol. 

Lines  24-40  set  up  variables  for  rapid 
access.  In  PET  BASIC,  as  in  many  other 
Microsoft  BASICS,  variables  execute  with 
a  speed  proportional  to  the  order  in 
which  they  are  defined.  Variables  always 
execute  more  rapidly  than  constants. 
Similarly,  program  states  appearing  early 
in  the  program  execute  more  quickly 
than  statements  which  follow  them. 

In  line  80,  the  GOTO  skips  over  the 
fast  routines  to  get  to  the  set  up  and  user 
command  handling  starting  on  line  360. 
Line  370  fills  the  text  word  array  W$ 
with  a  non- printing  character  and  line 
374  opens  the  disk  file  TXT1  for  reading; 
line  376  turns  off  the  disk  drive  motor 
turned  on  in  374.  In  412  the  user  is 
prompted  to  select  disk  file  reading  or 
writing.  If  writing  (W)  is  selected,  the 
program  branches  to  480  where  instruc¬ 
tions  for  entering  text  are  given.  The  disk 
file  TXT1  is  opened  for  writing  in  510, 
the  disk  drive  is  turned  off  in  520  and  the 
text  string  entry  subroutine  at  600  is 
called.  When  a  carriage  return  signalling 
the  end  of  a  line  of  text  is  detected  in 
610,  the  subroutine  returns  control  to 
520;  the  disk  motor  is  turned  on  in  525 


and  the  text  line  is  written  to  the  disk  in 
530.  If  the  text  entry  terminate  string 
#E#  is  detected  in  535,  the  disk  file  is 
closed  in  550  and  the  program  restarted 
in  560.  The  user  will  be  returned  to  the 
read  or  write  prompt  of  412,  and  can 
read  the  file  just  written,  or  can  write  a 
new  one. 

If  reading  is  selected  in  420,  the  user 
is  given  a  menu  of  reading  rates  in  423- 
433  so  that  an  initial  word  rate  may  be 
selected  in  440.  In  448  a  subroutine  at 
3000  is  called;  this  displays  two  *  charac¬ 
ters,  one  above  and  one  below  the  place 
on  the  screen  where  the  center  of  each 
word  will  appear.  The  program  then 
branches  to  146,  the  start  of  the  fast 
word-at-a-time  display  routines.  Here 
the  cursor  is  positioned  to  the  center  of 
the  screen  in  146,  and  a  FOR-NEXT  loop 
started  to  read  successive  words  from  the 
text  word  array  W$.  The  timing  variable 
IT  is  initialized  in  148  and  the  next  word 
read  from  the  array  in  150.  If  the  next 
array  cell  contains  the  non- printing 
character  loaded  in  370  (this  will  be  the 
case  on  first  entry  to  146)  the  program 
branches  to  300  where  the  next  string  is 
read  from  the  disk.  In  304-344  the  text 
string  is  parsed  and  individual  words  are 
identified  by  their  delimiting  spaces; 
each  word  is  placed  in  one  cell  of  W$. 
Successive  strings  are  read  from  the  disk 
and  their  constituent  words  placed  in  W$ 
until  the  terminating  mark  #E#  is  en¬ 
countered;  when  this  occurs  the  disk 
drive  motor  is  turned  off  in  346;  the  pro¬ 
gram  branches  back  to  146. 

In  216  the  word  is  displayed,  cen¬ 
tered  in  the  visual  field  defined  by  the 
two  *  characters  written  by  the  subrou¬ 
tine  at  3000.  In  217  the  cursor  is  moved 
up  one  space  (again,  this  character  does 
not  print  in  the  listing  and  appears  as 
“  ”),  and  the  subroutine  at  224  is  called. 
This  reads  a  character  from  the  keyboard 
using  GET  so  there  will  be  no  pause  if  no 
key  is  pressed.  If  a  numeric  key  is 
pressed,  its  value  is  used  to  form  the 
delay  variable  D  which  in  turn  causes  the 
program  to  dwell  in  228  for  the  amount 
of  time  required  to  provide  the  inter¬ 
word  delay  corresponding  to  the  word 
display  rate  selected  by  the  user.  ■  ■ 

(LISTING  ON  PAGE  34) 


•  “Comprehension  And  Memory  In  Rapid  Se¬ 
quential  Reading,”  Potter,  M.  C.;  Kroil,  J.  F. ; 
and  Harris,  Carol.  From  Attention  And  Per¬ 
formance  VIII,  edited  by  R.  Nickerson. 
Published  in  1980  by  Erlbaum  (N.I.). 


10 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 

95 


Analysis  of  the  Use 
of  the  6502 ’s  Opcodes 


D  espite  its  remarkably  sparce  (151) 
set  of  opcodes,  the  6502  CPU  is  con¬ 
sidered  to  be  more  powerful  than  its 
cousin,  the  6800.  This  is  generally  as¬ 
cribed  to  its  “post-indexed”  addressing 
mode,  represented  mnemonically  by 
“LDA  (zpg),Y”.  This  instruction  com¬ 
putes  the  effective  address  of  its  operand 
by  an  unsigned  addition  of  the  Y  register 
(8  bits)  to  a  2 -byte  zero  page  pointer  (at 
zpg&  zpg+1). 

I  have  written  a  simple  program  that 
analyzes  the  Commodore  PET’S  usage  of 
the  6502  opcodes.  I  was  particularly  in¬ 
terested  in  the  frequency  of  usage  of  the 
above  type  of  indirection  in  this  reason¬ 
ably  big  piece  of  software.  I  had  noticed 
in  my  own  work  that  the  other  type  of 
indirection  on  the  6502,  “pre-indexed” 
indirection,  was  almost  never  of  use  and 
wondered  whether  this  was  just  peculiar 
to  my  programming  habits.  The  program 
written  merely  steps  through  the  BASIC 
system,  from  its  start  at  SCOOO  to  its  end 
at  $FFFF,  avoiding  data  tables,  messages 
and  other  non- instructional  areas,  and 
counts  the  number  of  times  each  opcode 
is  used.  Here  is  what  I  find: 

The  PET  BASIC  interpreter  occupies 
a  little  less  than  14K  of  instruction  mem¬ 
ory.  It  consists  of  6355  instructions,  give 
or  take  a  few.  The  “average”  instruction 
is  thus  about  two  bytes  long.  The  6502 
CPU  possesses  151  discrete  one-byte  op¬ 
codes;  the  remaining  105  are  not  imple¬ 
mented.  Their  frequency  of  use  in  the 
PET  ranges  from  very  heavy  (the  JSR  in¬ 
struction  itself  accounts  for  more  than 
10%  of  the  total)  to  not  at  all.  Table  1 
summarizes  the  situation  for  those  twen¬ 
ty  percent  of  the  instructions  that  are 
most  frequently  used.  We  see  that 

1)  The  80/20  rule  is  followed  closely. 
Thirty  opcodes  (20%  of  the  total)  ac¬ 
count  for  5131  (81%)  of  the  total 
6355  used. 

2)  There  are  only  three  instructions  in 
Table  1  that  employ  16-bit  operands. 
Two  of  these,  JSR  and  JMP,  have  no 
substitute  on  the  6502.  The  third  is 
store  accumulator,  STA  adrl6,  but  it 

by  Howard  W. 
Whitlock,  Jr. 

Howard  W.  Whitlock,  Jr.,  1614  Norman 
Way,  Madcity,  WI  53705. 


occurs  only  72  times.  Its  complement, 
LDA  adrl6,  is  interestingly  used  only 
38  times.  Compare  this  with  the  zero 
page  STA  and  LDA  instructions  that 
are  used  5 1 1  and  437  times  respective¬ 
ly.  If  we  assume  there  are  about  13 
subroutines  (136  RTS’s),  the  “aver¬ 
age”  subroutine  is  called  five  times 
(684  JSR’s). 


3)  The  most  popular  instructions  (#3- 
20)  are  described  fairly  well  by: 

Frequency=28+  1325/X 
where  X  is  the  ranking,  with  a  cor¬ 
relation  coefficient  of  0.978.  This  is 
similar  to  Zipf’s  law.  which  states  that 
the  nth  most  frequent  word  is  encoun¬ 
tered  1/n  as  frequently  as  the  most 
common. 


Table  1 


The  thirty  most -used  instructions  in  PET  BASIC  and  their  frequency  of  use. 


FREQUENCY 

INSTRUCTION 

FREQUENCY 

INSTRUCTION 

648 

JSR  adrl6 

116 

STX  zpg 

511 

STA  zpg 

110 

LDX  #data 

437 

LDA  zpg 

109 

LDA  (zpg),Y 

388 

BNE  loc 

96 

LDY  zpg 

320 

LDA  #data 

92 

LDX  zpg 

267 

BEQ  loc 

75 

BPL  loc 

221 

JMP  adrl6 

73 

STA  adrl6 

197 

LDY  #data 

72 

STA  (zpg),Y 

153 

CMP  #data 

72 

INC  zpg 

144 

ADC  #data 

67 

BCS  loc 

136 

TRS 

60 

TAX 

135 

STY  zpg 

56 

CLC 

127 

BCC  loc 

55 

ADC  zpg 

127 

PHA 

55 

ADC  #data 

121 

INY 

54 

BMI  loc 

Table  2 

The  forty-one  least-used  (i.e.,  never)  instructions,  in  numerical  order. 

BRK 

AND  adrl6,X 

ADC  adrl6,X 

ORA  (zpg,X) 

AND  adrl6,X 

ROR  adrl6,X 

ASL  adrl6 

ROL  adrl6,X 

STX  zpg,Y 

ORA  (zpg),Y 

EOR  (zpg,X) 

LDA  (zpg,X) 

ORA  zpg,X 

EOR  adrl6 

LDX  zpg,Y 

ORA  adrl6,Y 

LSR  adrl6 

CLV 

ORA  adrl6,X 

EOR  (zpg),Y 

LDY  adrl6,X 

ASL  adrl6,X 

EOR  zpg.X 

CPY  adrl6 

AND  (zpg,X) 

EOR  adrl6,Y 

CMP  zpg,X 

AND  adrl6 

EOR  adrl6,X 

DEC  adrl6,X 

ROL  adrl6 

LSR  adrl6,X 

SBC  (zpg,X) 

AND  (zpg),Y 

ADC  (zpg,X) 

SED 

AND  zpg,X 

ROR  adrl6 

INC  adrl6,X 

ROL  zpg,X 

ADC  zpg,X 

Dr.  Dobb’s  Journal,  Number  53,  March  1981 
96 


Table  3 


All  used  opcodes  and  frequency;  in  decreasing  order.  Those  opcodes  employ 
ing  post -indexed  addressing  are  flagged  with  a  *;  those  using  pre- indexing 


with  a  f. 

OPCODE:  20  COUNT=  684 

OPCODE:  85  COUNT=511 

OPCODE:  A5  COUNT=  437 

OPCODE:  DO  COUNT=  388 

OPCODE:  A9  COUNT=  320 

OPCODE:  F0  COUNT=  267 

OPCODE:  4C  COUNT=  221 

OPCODE:  AO  COUNT=  197 

OPCODE:  C9  COUNT=  154 

OPCODE:  68  COUNT=  144 

OPCODE:  60  COUNT=  136 

OPCODE:  84  COUNT=  135 

OPCODE:  90  COUNT=  127 

OPCODE:  48  COUNT=  127 

OPCODE:  C8  COUNT=  121 

OPCODE:  86  COUNT=  116 

OPCODE:  A2  COUNT=  110 

OPCODE:  B1  *  COUNT=  109 

OPCODE:  A4  COUNT=  96 

OPCODE:  A6  COUNT=  92 

OPCODE:  10  COUNT=  75 

OPCODE:  8D  COUNT=  73 

OPCODE:  E6  COUNT=  72 

OPCODE:  91  *  COUNT=  72 

OPCODE:  B0  COUNT=  67 

OPCODE:  AA  COUNT=  60 

OPCODE:  18  COUNT=  56 

OPCODE:  69  COUNT=  55 

OPCODE:  65  COUNT=  55 

OPCODE:  30  COUNT=  54 

OPCODE:  E8  COUNT=  49 

OPCODE:  C6  COUNT=  48 

OPCODE:  8A  COUNT=  48 

OPCODE:  88  COUNT=  48 

OPCODE:  98  COUNT  =  46 

OPCODE:  A8  COUNT=  45 

OPCODE:  CA  COUNT=  43 

OPCODE:  C5  COUNT=  43 

OPCODE:  38  COUNT=  40 

OPCODE:  29  COUNT=  40 

OPCODE:  AD  COUNT=  38 

OPCODE:  49  COUNT=  37 

OPCODE:  BD  COUNT=  35 

OPCODE:  09  COUNT=  31 

OPCODE:  E5  COUNT=  30 


OPCODE: 

4A 

COUNT  =  19 

OPCODE: 

45 

COUNT=  18 

OPCODE: 

E4 

COUNT=  17 

OPCODE: 

D1  * 

COUNT =  17 

OPCODE: 

CO 

COUNT=  17 

OPCODE: 

66 

COUNT=  16 

OPCODE: 

99 

COUNT=  15 

OPCODE: 

EA 

COUNT=  14 

OPCODE: 

46 

COUNT=  14 

OPCODE: 

58 

COUNT=  13 

OPCODE: 

78 

COUNT=  12 

OPCODE: 

2A 

COUNT=  12 

OPCODE: 

26 

COUNT=  11 

OPCODE: 

05 

COUNT=  11 

OPCODE: 

28 

COUNT =  10 

OPCODE: 

9A 

COUNT= 9 

OPCODE: 

08 

COUNT= 9 

OPCODE: 

B4 

COUNT= 8 

OPCODE: 

50 

COUNT = 8 

OPCODE: 

25 

COUNT = 8 

OPCODE: 

06 

COUNT= 8 

OPCODE: 

DD 

COUNT= 7 

OPCODE: 

BA 

COUNT= 7 

OPCODE: 

94 

COUNT = 7 

OPCODE: 

8E 

COUNT = 7 

OPCODE: 

70 

COUNT= 6 

OPCODE: 

6C 

COUNT= 6 

OPCODE: 

76 

COUNT = 5 

OPCODE: 

F5 

COUNT= 4 

OPCODE: 

AE 

COUNT= 4 

OPCODE: 

79 

COUNT= 4 

OPCODE: 

FI  * 

COUNT= 3 

OPCODE: 

CD 

COUNT= 3 

OPCODE: 

8C 

COUNT  = 3 

OPCODE: 

F6 

COUNT = 2 

OPCODE: 

EE 

COUNT =  2 

OPCODE: 

D9 

COUNT= 2 

OPCODE: 

D8 

COUNT= 2 

OPCODE: 

AC 

COUNT  =  2 

OPCODE: 

71  * 

COUNT= 2 

OPCODE: 

56 

COUNT =  2 

OPCODE: 

40 

COUNT = 2 

OPCODE: 

16 

COUNT  = 2 

OPCODE: 

FD 

COUNT=  1 

OPCODE: 

F9 

COUNT=  1 

(Continued  on  next  page) 

An  amazing  27%  of  the  6502’s  op¬ 
codes  are  not  used  at  all!  These  are  con¬ 
tained  in  Table  2.  We  see  that 

1)  The  not-used  instructions  are  heavily 
represented  by  logical  (especially 
XOR)  instructions. 

2)  While  there  are  no  pre-indexed,  indi¬ 
rect  memory  references  in  the  top 
20%,  they  are  fairly  common  (six  of 
eight  )  in  the  never- used  table.  The 
only  ones  used  at  all  (see  Table  2)  are 
STA  (zpg,X)  and  CMP  (zpg,X).  These 
are  used  in  conjunction  with  a  zero- 
page  string  descriptor  stack. 

3)  Neither  BRK  nor  SED  (set  decimal 
mode  for  arithmetic)  are  used. 

4)  The  only  post- indexed  instructions 
never  used  are  the  logical  ones,  ORA, 
AND,  and  EOR.  I  have  included  all 
used  opcodes  as  Table  3. 

I  have  also  counted  all  adjacent  op¬ 
code  pairs  drawn  from  the  instructions 
of  Table  1.  The  ten  most  frequently  used 
doublets  are  in  Table  4.  Almost  all  of  the 
doublets  are  encountered  more  frequent¬ 
ly  than  expected  in  a  statistical  sense 
(Fa*Fb/6355).  There  are  some  notable 
exceptions,  however.  The  two  compare- 
and-branch  pairs,  CMP  #data:  BNE  loc, 
and  CMP  #data:  BEQ  loc,  are  much 
more  common  than  expected.  On  the 
other  hand,  the  doublet  BNE  loc:  JSR  loc 
is  (relatively)  uncommon.  Rather  than 
delving  into  the  Freudian  implications  of 
these  and  related  observations,  I  invite 
interested  readers  to  send  me  a  SASE 
and  $  1 .00  for  the  complete  printout. 

Conclusions 

My  original  suspicions  concerning 
the  worthlessness  of  the  6502’s  pre¬ 
indexed  instructions  seem  confirmed.  On 
the  other  hand,  post-indexed  indirection, 
although  much  more  common  than  pre¬ 
indexing,  is  not  nearly  as  common  as  I 
had  assumed.  The  small  number  of  in¬ 
structions  actually  used  is  surprising.  The 
absence  of  any  “super”  two-op  con¬ 
structs  is  apparent  from  Table  4. 


12 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 

97 


OPCODE 

0A 

COUNT= 30 

OPCODE 

ED 

COUNT= 

1 

OPCODE 

2C 

COUNT= 29 

OPCODE 

EC 

COUNT= 

1 

OPCODE 

E9 

COUNT=  28 

OPCODE 

D6 

COUNT= 

1 

OPCODE 

24 

COUNT=  28 

OPCODE 

CE 

COUNT= 

1 

OPCODE 

E0 

COUNT=  25 

OPCODE 

Cl 

COUNT= 

1 

OPCODE 

95 

COUNT=  22 

OPCODE 

BE 

COUNT= 

1 

OPCODE 

B9 

COUNT= 21 

OPCODE 

81 

COUNT= 

1 

OPCODE 

C4 

COUNT= 20 

OPCODE 

6D 

COUNT= 

1 

OPCODE 

B5 

COUNT=  19 

OPCODE 

6A 

COUNT= 

1 

OPCODE 

9D 

COUNT=  19 

OPCODE 

0D 

COUNT= 

1 

Table  4 

The  ten  most  common  opcode  pairs,  and  their  calculated*  and  found  fre¬ 
quency  of  occurence. 


OPCODE- 1 

OPCODE-2 

FREQUENCY 

(CALC) 

JSR  loc 

JSR  loc 

145 

(74) 

LDA  #data 

STA  zpg 

106 

(26) 

JSR  loc 

LDA  zpg 

82 

(47) 

ST  A  zpg 

LDA  zpg 

76 

(36) 

CMP  #data 

BNE  loc 

73 

(9) 

JSR  loc 

LDA  #data 

71 

(34) 

BNE  loc 

JSR  loc 

57 

(42) 

LDY  #data 

JSR  loc 

55 

(21) 

JMPloc 

JSR  loc 

55 

(24) 

CMP  #data 

BEQ  loc 

52 

(6) 

Fa*Fb/6355,  where  Fa  is  the  frequency  of  occurence  of  the  first,  and  Fb  of  the  second 
opcode.  See  Table  1 . 


“There  are  times  when  I  worry  about  you,  George !” 


(Continued  from  page  8) 

That  is  an  interesting  statement  in  its 
own  right,  but  compare  it  to  this  one: 

“To  execute  ASM,  .  .  .  you  only  have 
to  specify  the  primary  name  of  the 
source  file.”  (pg.  82) 

3.  Erroneous: 

“Files  may  have  one  of  the  four  attri¬ 
butes: 

-  R/O  (read  only) 

-  R/W  (read/write) 

—  SYS  (system  .  . .) 

—  DIR  (directory  .  .  .)”  (pg.  94) 

4.  Incomplete: 

“XX  (positions  13  &  14):  This  is  a 
field  not  used  in  CP/M  1.4,  normally 

0.”(pg.  118) 

5.  Absurd: 

“A  BIOS  is  specified  by  passing  a 
function  number  and  an  information 
address.”  (pg.  192) 

6.  Amusing: 

“if  you  are  in  a  duplicating  mood 
[sic] ,  PIP  is  the  next  most  useful  pro¬ 
gram.”  (pg.279) 

What  is  the  most  useful  program  for 
those  in  a  “duplicating  mood?”  —  not 
the  faintest  clue  is  given. 

Reading  these  statements  in  context 
doesn’t  help  matters  at  all.  What  the  book 
lacks  in  content,  it  makes  up  in  redun¬ 
dancy.  Chapter  5,  “Inside  CP/M  (and 
MP/M),”  classically  illustrates  this  cur¬ 
ious  literary  style.  In  seventeen  pages 
(181-197)  Dr.  Zaks  manages  to  present 
the  CP/M  memory  map  three  times.  And 
twice  he  labels  the  fields  of  a  File  Control 
Block;  this,  with  a  spattering  of  floppy 
diskette  statistics,  he  calls  a  “detailed 
description”  of  the  CP/M  file  system. 

And  what  should  the  novice  user  do 
when  he  encounters  problems?  Listen  to 
this  sage  advice: 

“When  something  goes  wrong,  you 
may  want  to  stop  everything.  Do  not 
pull  the  electrical  cord  out  of  the 
outlet.”  (pg.  279) 

“Check  the  mechanicals  again  ...  re¬ 
move  boards,  clean  connections  .... 
If  the  malfunction  can  be  attibuted  to 
a  board,  remove  components  from 
sockets,  clean  connections,  and  rein¬ 
sert  them.”  (pg.  280) 

If  you  find  this  humorous,  then  ob¬ 
viously  you  haven’t  spent  $13.95  for  this 
book.  Good  for  you! 

Jim  Hendrix 

Rt.  1,  Box  74-B-l 

Oxford,  MS  38655 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 
98 


13 


Book  Reviews 


PROGRAMMING  TECHNIQUES  FOR 

LEVEL  II  BASIC 
By  William  Barden,  Jr. 

Published  by  Radio  Shack 
224  pages,  $4.95 
Reviewed  by  John  B.  Palmer 

This  is  not  another  book  about  how 
to  learn  to  program  in  BASIC.  If  you  are 
fluent  in  BASIC  and  wish  to  learn  details 
of  Radio  Shack’s  Level  II  BASIC,  then 
this  book  is  for  you.  Anyone  having 
trouble  with  BASIC  had  best  avoid  this 
book. 

For  most  TRS-80  users,  the  best  part 
of  the  book  might  be  chapters  seven  and 
eight,  where  the  author  gets  into  dimen¬ 
sions,  tables,  lists  and  sorts.  He  gives  some 
program  examples  and  good  illustrations 
of  the  well-known  Bubble-sort  (ugh!) 
and  the  better  Shell- Metzer  sort  (hoo¬ 
ray!).  Also  mentioned  are  linked  lists, 
merges  and  deletions.  This  is  good  stuff 
for  anyone  trying  to  maintain  a  mailing 
list  in  BASIC. 

It’s  too  bad  the  program  examples 
are  always  so  brief.  The  author  tries  to 
put  a  lot  of  information  into  a  book  of 
224  pages.  I  could  not  find  any  complete, 
practical  applications  of  the  techniques 
which  are  detailed.  Yet  I  feel  the  book  is 
very  good  in  overall  coverage  of  its  sub¬ 
ject.  If  you  are  in  need  of  an  obscure  de¬ 
tail  or  a  special  trick  in  Level  II,  check 
the  four- page  index  of  this  book. 

Of  the  twelve  chapters  in  the  book, 
my  own  favorites  are  the  last  two.  They 
are  where  you  learn  the  very  clever  trick 
of  BASIC-to-machine-language  interface. 
William  Barden,  Jr.  tries  to  sugar  coat 
the  horrible  details  of  Z-80  code  with  his 
strange  sense  of  humor. 

But  his  humor  is  not  the  worst  part 
of  the  book.  The  greatest  weakness  is  the 
lack  of  a  theme  to  tie  together  a  collec¬ 
tion  of  facts,  tricks  and  algorithms.  It 
would  have  been  better  if  there  were  at 
least  one  application  example  to  tie 
everything  together.  The  title  of  the  book 
mentions  technique.  It  has  technique;  it 
does  not  have  style. 

You  may  find  that  much  information 
covered  in  this  book  has  already  been 
published  in  letters,  memos  and  newslet¬ 
ters.  It  is  very  handy  to  now  have  the  se¬ 
crets  of  Level  II  BASIC  in  one  volume. 
Suppose  you  want  to  change  the  key¬ 
board  input  routine  of  your  TRS-80. 
Look  in  the  index  and  then  turn  to  page 
215.  Wow!  on  the  facing  page  there  is  a 
very  interesting,  top-secret  diagram  of 
the  Level  II  DCB’s!  Here  is  everything 


you  need  to  know  about  the  I/O  struc¬ 
ture. 

Many  users  will  find  the  chapter  on 
cassette  tape  technique  to  be  helpful.  The 
author  exposes  the  weakness  of  the  Radio 
Shack  tape  format  (unusual  in  view  of 
the  fact  that  the  book  is  published  by 
Radio  Shack).  There  are  some  hints  for 
overcoming  these  limitations.  I  think  the 
author  should  have  given  a  lot  more  at¬ 
tention  to  practical  examples  of  using  the 
tape  for  storage  of  data,  but  he  does  de¬ 
tail  how  the  BASIC  interpreter  puts  data 
onto  the  tape. 

I  paid  four  dollars  and  ninety- five 
cents  for  this  book  at  a  local  Radio  Shack 
store.  It  is  better  than  some  books  at 
twice  the  price.  Too  bad  it  does  not  have 
spiral  binding  and  will  not  lay  flat  on  the 
desk.  It  is  not  a  replacement  for  the  regu¬ 
lar  manual  you  get  with  Level  II.  But 
when  the  Level  II  manual  puts  you  to 
sleep,  pick  up  a  copy  of  Programming 
Techniques  for  Level  II  BASIC  by 
William  Barden,  Jr.  and  you  will  again 
have  sleepless  nights  with  your  TRS-80. 

Post  Script:  some  information  in  this 
book  may  be  in  error.  Also,  future  re¬ 
leases  of  Level  II  BASIC  may  not  have 
the  same  machine  code  addresses  men¬ 
tioned  in  the  book. 

BASIC  TECHNIQUES  OF  COMBINA¬ 
TORIAL  THEORY 
By  Daniel  I.  A.  Cohen 
Published  by  John  Wiley  and  Sons 
$20.95 

Reviewed  by  Jeff  Rubens 

The  “Curriculum  1978”  report  of 
the  Association  for  Computing  Machinery 
states,  in  effect,  that  the  traditional 
mathematics  curriculum  is  still  appropri¬ 
ate  for  computer  science.  Nonetheless, 
there  is  a  strengthening  opinion  among 
educators  that  students  majoring  in 
computer-oriented  disciplines  need  more 
discrete  mathematics  and  not  necessarily 
a  great  deal  of  calculus  and  analysis.  Since 
few  people  are  exposed  to  much  non- 
traditional  mathematics  in  school,  a  sensi¬ 
ble  move  for  those  who  are  contemplat¬ 
ing  study  in  computer  science  is  to  get  a 
college-level  text  devoted  to  this  “other” 
mathematics.  This  could  provide  a  valu¬ 
able  clue  to  whether  one  is  heading  in  the 
right  direction.  Basic  Techniques  of  Com¬ 
binatorial  Theory  is  the  sort  of  book  you 
might  consider  for  this  purpose. 

The  content  and  level  are  designed 
for  a  reader  with  limited  mathematical 
background.  A  semester  of  calculus  is 


recommended,  but  if  you  know  nothing 
of  calculus  there  are  only  a  few  pages  you 
will  have  to  skip.  It  would  be  foolish  to 
think,  though,  that  you  could  easily 
understand  this  book  if  you  had  to  strug¬ 
gle  to  get  through  high-school  geometry. 
Although  essentially  self-contained,  this 
is  still  a  technical  book.  The  more  famili¬ 
arity  you  have  with  ideas  of  deductive 
reasoning  and  proofs,  the  easier  the  book 
will  be.  The  most  difficult  sections,  on 
Polya  enumeration,  will  be  easier  for 
those  who  have  been  exposed  to  algebraic 
structures. 

Cohen’s  approach  to  instruction  is 
markedly  different  from  the  one  most 
commonly  found  in  mathematics  texts. 
He  proceeds  from  the  bottom  up,  show¬ 
ing  the  lesser  or  partial  results  along  the 
road  to  the  major  theorems.  This  tech¬ 
nique  not  only  gives  the  reader  a  reason¬ 
able  idea  of  how  the  subject  developed 
historically,  but  also  makes  many  com¬ 
plex  results  easier  to  understand  than  the 
traditional  technique  (which  first  hits  you 
with  the  entire  truck  and  tells  you  about 
wheels,  engines,  and  so  forth  only  while 
you  are  picking  yourself  up  off  the 
ground).  The  author  succeeds  admirably 
in  bringing  off  this  pedagogic  idea.  For 
example,  his  development  of  Ramsey’s 
Theorem  along  these  lines  is  splendid, 
especially  when  compared  with  the  treat¬ 
ment  of  this  subject  elsewhere.  It  seems 
likely  that  this  feature  is  responsible  for 
the  book’s  classroom  success. 

Another  valuable  instructional  aid  is 
the  provision  of  several  proofs  of  many 
of  the  results.  Those  with  good  under¬ 
standing  see  various  ideas  neatly  tied  to¬ 
gether;  those  groping  at  comprehension 
get  several  chances,  from  different  points 
of  view.  Unfortunately,  things  being  the 
way  they  are,  some  alternative  proofs 
must  be  delayed.  The  references  back, 
usually  by  number  alone,  seem  sterile  and 
impersonal.  (Also,  page  numbers  would 
have  been  helpful.)  In  contrast,  the 
author  goes  to  great  lengths  to  credit  re¬ 
sults  appropriately,  frequently  citing  two 
or  more  researchers  who  attained  the 
same  result  independently. 

In  order  to  achieve  his  objective  of  a 
meaty  book  within  the  scope  of  readers 
with  little  formal  training,  Cohen  concen¬ 
trates  his  energies  on  carefully  selected 
aspects  of  combinatorics.  The  bulk  of  the 
book  is,  one  way  or  another,  about 
counting,  with  side  trips  into  related 
realms  such  as  generating  functions,  re- 

(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


15 

99 


ERGO: 

A  “Thinking  Program” 


T 

A  his  article  is  about  a  “thinking  pro¬ 
gram”  that  we  wrote  some  time  ago.  It  is 
one  of  a  series  we  developed  to  investi¬ 
gate  some  ideas  on  educational  techno¬ 
logy.  The  purpose  of  publishing  it  now  in 
this  Journal  is  to  show  it  to  readers  with 
the  interest  and  skill  to  do  even  better. 
We  felt  it  would  be  constructive  to 
demonstrate  that  it  is  not  really  very  dif¬ 
ficult  to  design  a  program  that  does  genu¬ 
ine  thinking,  and  it  does  not  have  to  be 
very  large,  so  it  can  be  a  challenging  proj¬ 
ect  for  computer  hobbyists. 

ERGO  thinks  about  any  kind  of  in¬ 
formation  supplied  to  it,  and  does  deduc¬ 
tive  and  inductive  logical  analysis  of  its 
available  data  to  draw  new  conclusions 
not  explicitly  contained  in  its  original 
source  information,  similar  to  the  way  a 
person  would  do  it.  As  a  result,  it  general- 

by  Sheldon  Softky 
and  Sylvan  Rubin 

Sheldon  Softky  and  Sylvan  Rubin,  c/o 
P.  O.  Box  3074,  Santa  Clara,  CA  95051. 


ly  “knows”  considerably  more  than  the 
specific  facts  given  to  it. 

It  is  entirely  different  from  smart 
game-playing  programs,  because  it  can 
think  about  anything.  It  is  not  very 
clever,  however,  and  doesn’t  engage  in 
entertaining  conversations.  This  version 
does  sometimes  ask  random  questions 
based  on  its  knowledge,  so  it  is  somewhat 
conversational. 

To  be  more  specific  about  the  inter¬ 
nal  features  of  ERGO,  it  normally  gets  an 
initial  “information  load”  from  a  data  file 
that  it  reads  when  it  is  started.  Then  it  de¬ 
duces  everything  it  can  from  that  data 
and  adds  it  to  its  memory.  Any  state¬ 
ments  made  to  it  are  also  added  and  com¬ 
bined  with  the  facts  already  known,  to 
generate  more  deductions.  If  it  is  asked 
a  question,  it  gives  all  relevant  answers, 
and  then  also  does  inductive  analysis  to 
find  any  more  “possible”  answers,  but 
these  are  not  stored  in  memory.  One 
problem  we  had  with  it  was  that  if  it  was 
given  a  highly  interrelated  set  of  facts,  it 
deduced  so  many  more  facts  that  it  some¬ 
times  ran  out  of  computer  memory. 

When  you  look  at  the  listing,  you’ll 
see  that  by  far  the  biggest  part  of  ERGO 
is  devoted  to  trying  to  comprehend  the 


English  language.  The  essential  notion  is 
that  the  verb  is  the  most  important  word 
in  a  sentence,  because  it  states  the  rela¬ 
tionship  between  the  subject  and  the  ob¬ 
ject,  which  determines  what  kind  of  con¬ 
nections  there  are  with  other  objects.  The 
input  file,  and  the  internal  data  structures 
are  organized  in  terms  of  sets  of  relations, 
one  set  for  each  verb.  ERGO  only  knows 
about  the  verbs  “is”  and  “has.”  These  are 
two  of  the  most  logically  powerful  verbs, 
because  they  imply  extensive  relational 
connections  among  many  objects.  Most 
verbs  only  mean  “do,”  regardless  of  their 
great  variety,  and  are  therefore  logically 
very  simple. 

The  listing  is  published,  not  so  much 
for  anyone  to  exactly  copy  it,  but  to  pro¬ 
vide  a  starting  point  for  readers  to  pro¬ 
duce  new  and  different  thinking  pro¬ 
grams,  hopefully  much  more  powerful 
than  ERGO.  ■  ■ 


(LISTING  ON  PAGE  30) 


(continued  from  previous  page) 

currence  relations  and  permutations.  One 
chapter  deals  with  graph  theory.  The  top¬ 
ic  selection  satisfies  the  author’s  require¬ 
ments  and,  perhaps  coincidentally,  is  also 
excellent  for  readers  interested  in  com¬ 
puter  science. 

Each  chapter  provides  an  impressive 
collection  of  exercises.  For  many,  this 
alone  will  make  the  book  worthwhile. 
The  problems  are  not  formally  graded  as 
to  difficulty  (but  various  levels  are  repre¬ 
sented),  and  almost  all  are  of  a  strictly 
mathematical  nature.  The  reader  is  left  to 
discover  the  more  practical  applications 
for  himself  -  and  if  he  has  been  attentive, 
he  probably  will. 

A  certain  amount  of  reader  aware¬ 
ness  is  important  in  the  use  of  this  book. 
It  should  be  kept  in  mind  that  this  is  an 
introduction  to  combinatorics,  not  a  sur¬ 
vey.  Don’t  expect  to  get  a  head  start  on 
such  things  as  systems  of  distinct  repre¬ 
sentatives,  optimizations  or  block  designs. 
Similarly,  be  forewarned  that  only  a  thin 


surface  of  graph  theory  is  scratched,  even 
as  regards  a  list  of  its  subtopics.  If  you  are 
practical-minded,  rest  assured  that  there 
are  real-world  applications  (including 
many  important  ones)  for  this  material 
and  its  corollaries.  Finally,  be  on  guard  to 
watch  for  typographical  errors.  There  are 
quite  a  few,  several  of  which  could  be 
disconcerting  to  a  beginning  combinatori- 
cist.  If  you  are  lacking  in  mathematical 
self-confidence  and  don’t  have  a  friendly 
professor  nearby  to  answer  questions, 
you  might  want  to  wait  for  the  second, 
presumably  corrected,  printing.  There 
should  be  another  printing,  for  this  is  a 
useful  book  in  an  important  area  and 
its  pluses  far  outweigh  its  minuses. 

Godel,  Escher,  Bach 
By  Douglas  R.  Hofstadter 
Published  by  Random  House 
777  pages,  $8.95 
Reviewed  by  H.  T.  Gordon 

Its  title  -  a  string  of  3  names,  all 
Germanic  like  the  author’s  -  presages  a 


singular  book,  as  do  the  quasi-mystical 
subtitles:  “an  eternal  golden  braid”  and 
“a  metaphorical  fugue  on  minds  and  ma¬ 
chines  in  the  spirit  of  Lewis  Carroll.”  The 
minds  that  interest  Hofstadter  do  not  in¬ 
clude  many  Germanic  ones  that  I  find  no 
less  fascinating:  Brahms  and  Wagner, 
Goethe,  Durer  and  Rembrandt,  Freud 
and  Jung,  Nietzsche,  Spengler,  and  the 
nadiric  Hitler.  Their  work  is  pervaded  by 
the  unconscious  component  of  mind, 
either  not  or  else  too- complexly  mathe¬ 
matical.  Hofstadter  is  young  (ca.  34),  has 
a  Ph.D.  in  mathematical  physics  (ca. 
1976),  and  is  now  in  computer  science 
with  a  pro-AI  (artificial  intelligence)  bias. 
His  long  list  of  reference  works  (p.  746-) 
includes  most  of  the  AI  ones,  many  in 
mathematical  logic  (his  forte),  some  in 
biology  (not  his  forte),  a  few  on  music 
and  art  (to  justify  the  minor  Bach  and 
major  Escher  “strands”  of  his  golden 
braid,  in  which  the  Godel- like  strand  is 
dominant),  and  a  bit  on  Zen.  Zen  because 
he  is  enthralled  by  paradox  —  that  I  see 
as  an  antirational  upwelling  from  the  un- 


16 

100 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


conscious  —  as  were  Lewis  Carroll,  Zeno 
of  Elea,  and  surely  many  other  mathe¬ 
matical  minds  that  have  been  incarnate  in 
human  cerebra  from  the  moment  of  ori¬ 
gin  —  lost  in  the  mists  of  time  —  of  Homo 
sapiens.  A  long,  though  not  quite  eternal, 
“braid”! 

The  author’s  father  is  a  Nobel- 
laureate  in  high-energy  physics,  who  has 
since  1950  been  a  professor  at  Stanford. 
In  variety-show  parlance,  that’s  a  hard 
act  to  follow.  The  psychosociology  of 
everyone  who  gravitates  to  computers  — 
including  me  —  is  unusual.  Growing  up  in 
the  Palo  Alto  microcosm  —  as,  in  a  sense, 
DDJ  itself  has  —  is  an  exotic  experience. 
The  so-called  private  universities  (they 
are  lavishly  subsidized  by  Washington)  are 
foci  of  intellectual  and  many  other  (not 
all  admirable)  forces,  to  which  Stanford 
adds  the  peculiar  California  lifestyle.  Less 
weird  than  southern  California  perhaps, 
but  weird  enough.  I  have  intentionally 
(though  lightly)  stressed  the  wellsprings 
of  this  book,  though  only  the  more  “in” 
readers  of  this  review  may  fully  grasp  its 
relevance. 

The  author  concisely  describes  his 
own  book  (hidden  in  the  reference  to 
Gebstadter,  p.  748)  as  “a  formidable 
hodge-podge,  turgid  and  confused.” 
That’s  more  accurate  than  the  rave  re¬ 
views  it’s  had,  but  I  would  add  that  some 
of  it  is  ingenious,  imaginative,  even  bril¬ 
liant;  e.g.,  the  brief  sketch  of  computers 
in  Chapter  X  (p.  285).  The  book  may 
have  originated  as  an  introduction  to 
number  theory,  symbolic  logic,  and  the 
propositional  calculus  aimed  at  students 
in  computer  science.  Early  AI  work 
showed  that  this  kind  of  “thinking”  can 
to  some  extent  be  programmed  (cf. 
pp.  26-7).  The  first  250-odd  pages  espe¬ 
cially  have  a  lot  of  this,  with  long  pas¬ 
sages  that  could  be  lecture  notes  (learn- 
able  if  one  so  desires).  Not  everyone  is 
aware  that  the  number  5  can  be  written 
as  SSSSSO!  The  underlying  theme  is 
really  AI,  that  becomes  predominant  in 
the  last  half  of  the  book.  Seeing  that  this 
kind  of  hard  reading  would  not  “sell,” 
Hofstadter  spiced  it  up  with  interludes  on 
linguistic  and  genetic  coding,  music,  Zen, 
graphics  and  an  awful  lot  of  Escher  (no 
less  than  36  reproductions!)  Every  chap¬ 
ter  has  a  Zenoic-Carrollian  “dialogue” 
involving  several  imaginary  characters, 
principally  Achilles  and  the  Tortoise,  first 
used  by  Zeno  to  “prove”  what  Ecclesi¬ 
astes  merely  asserted,  that  the  race  is  not 
to  the  swift.  Zeno’s  trick  was  to  refuse  to 


give  Achilles  enough  time  to  overtake  the 
Tortoise,  but  Hofstadter’s  obfuscations 
often  make  no  sense  at  all,  being  a  mysti¬ 
fying  mysticism  glazed  over  by  termino¬ 
logy  that  makes  sense  in  other  contexts. 
This  can  be  entertaining  in  many  ways. 
Some  readers  will  extract  from  the  non¬ 
sense  the  particular  sense  that  pleases 
them,  and  admire  the  writer’s  insight 
(since  it’s  their  own!).  Others  will  only 
see  that  it’s  “deep,”  and  admire  the  Zen 
mind  that  must  surpass  their  own.  Others 
will  be  reminded  how  rare  sense  is,  and 
how  easily  it  is  transformed  into  non¬ 
sense,  wondering  if  they  themselves  avoid 
the  subtle  pitfalls  that  entrap  even  minds 
as  bright  as  Hofstadter’s. 

People  who  are  aware  of  the  moronic 
level  of  present-day  AI  work  will  be 
struck  by  the  fact  that  so  much  of  this 
book  is  at  an  empyrean  level  of  complex¬ 
ity  —  near  if  not  beyond  the  limits  of  un¬ 
derstanding  possible  to  the  most  mature 
and  experienced  human  minds.  No  AI 
program  could  even  comprehend,  let 
alone  paraphrase,  Hofstadter’s  prose.  But 
his  paradigm  of  human  verbalization  is 
Lewis  Carroll’s  famous  Jabberwock  poem 
(’Twas  brillig,  and  the  slithy  toves  .  .  .) 
plus  French  and  German  translations  of 
it  (p.  366).  One  need  not  be  an  AI  skep¬ 
tic  to  wonder  if  there  will  ever  be  a 
computer-generated  English  interpreta¬ 
tion  or  a  foreign-language  translation  of 
that  brief  masterpiece.  It’s  also  question¬ 
able  whether  a  computer-graphics  pro¬ 
gram  will  be  able  to  draw  something  that 
a  human  critic  would  take  as  the  work  of 
Escher,  or  whether  a  pattern -recognition 
program  will  identify  an  Escher  drawing. 
Also,  are  music-generator  programs  ready 
to  write  a  fugue  that  would  be  mistaken 
for  a  work  of  Bach?  Perhaps  the  classic 
“million  monkeys  banging  away  on  a 
million  keyboards  for  a  million  years” 
could  stumble  on  it  once,  but  that  wasn’t 
quite  Bach’s  technique!  Still,  his  work 
was  so  highly  structured  that  an  imitation 
might  be  programmable.  (For  non¬ 
musical  readers,  a  fugue  has  one  melodic 
theme  continuously  present  in  many  vari¬ 
ations,  with  subdivision  into  several 
“parts”  that  each  contain  an  independent 
though  consonant  melody,  creating  diver¬ 
sity  within  an  underlying  unity.  “Rules” 
are  known  that  restrict  the  composition, 
but  no  one  can  tell  what  proportion  of 
machine-made  fugues  would  be  near 
Bach -level!) 

The  book  is  too  mixed-up  to  be 
called  a  fugue.  It’s  more  like  a  kaleido¬ 


scope,  with  elements  being  somewhat 
haphazardly  rearranged  into  patterns,  one 
or  more  of  which  are  likely  to  prove 
interesting  to  nearly  any  kind  of  reader. 
That’s  why  it’s  being  so  widely  read. 
There’s  even  a  mystical  streak  (on  p.  xxi, 
the  book  is  said  to  be  a  statement  of  the 
author’s  religion!)  and  an  AI  version  of 
GOD  is  cited  in  the  index,  with  ITs  pic¬ 
ture  (non- sexist,  since  IT’s  a  computer) 
on  p.  143.  This  new  ITian  mythology  has 
enemies,  and  Hofstadter  crosses  swords 
with  the  English  philosopher  J.  R.  Lucas, 
who  first  used  the  incompleteness 
theorem  of  Godel  in  an  anti-AI  article 
(Minds,  Machines,  and  Godel,  1961). 
Symmetry  suggests  the  name  IDian 
(though  this  strays  from  Freud’s  concept 
of  the  ID)  for  the  anti- ITian  point  of 
view.  Though  myself  a  IDian,  I  tend  to 
agree  that  Godel  did  not  prove  that  AI 
is  impossible.  Readers  who  would  like  a 
less  argumentative  exposition  of  the  cur¬ 
rent  dilemmas  in  mathematics  can  find  it 
in  Morris  Kline’s  Mathematics,  The  Loss 
of  Certainty  (Oxford  Univ.  Press,  1980). 
The  only  way  to  prove  that  a  hardware/ 
software  system  can  do  anything  the 
human  mind  can  do  is  to  build  one  that 
does.  That’s  a  very  tough  problem,  but 
the  real  IDian  point  is  that  it’s  not  the 
only  problem.  The  more  complex  a  pro¬ 
gram  becomes,  the  more  likely  it  will  con¬ 
tain  very  subtle  and  undetectable  bugs 
that  will  cause  it  to  do  things  you  wish  it 
hadn’t!  It  will  have  “a  mind  of  its  own,” 
more  probably  crazy  than  sane,  possibly 
more  dangerous  than  useful.  In  the  1979 
edition  of  his  What  Computers  Can’t  Do, 
The  Limits  of  Artificial  Intelligence, 
Hubert  Dreyfus  draws  an  anlaogy  be¬ 
tween  believers  in  AI  and  the  ancient 
alchemists,  who  believe  it  would  be  possi¬ 
ble  to  transmute  lead  into  gold,  if  only 
you  kept  trying.  Their  work  led  to 
modern  chemistry,  that  cannot  do  trans¬ 
mutation  though  it  does  things  that  are 
useful  as  well  as  (in  many  senses  of  the 
word)  dangerous.  The  newer  science  of 
nuclear  physics  can  do  transmutations 
and  understands  how  formidable  the 
problem  of  changing  lead  into  gold  really 
is,  so  it’s  not  even  trying.  But  even  the 
useful  things  it’s  doing  involve  serious 
hazards.  Although  computer  programs  are 
still  stupid,  they’ve  been  wiring  me  a  lot 
of  junk  mail  with  a  “personalized”  look, 
and  I’m  not  looking  forward  to  locking 
horns  with  a  really  bright  human - 
simulation  program! 

(Continued  on  page  40) 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


17 

101 


Using  WORD-MASTER 
with  the  Compal-80 


Abstract 

WORD-MASTER  is  a  powerful, 
screen-oriented  text  editor  which  runs 
under  the  CP/M  operating  system.  The 
editor  makes  use  of  hardware-dependent 
features  which  require  system-dependent 
software  routines.  The  standard  package 
includes  such  patches  for  several  stan¬ 
dard  hardware  configurations.  This  article 
provides  the  routines  necessary  to  inter¬ 
face  the  WORD-MASTER  to  the  Compal- 
80  computer.  Similar  steps  could  be  used 
for  other  computers  which  use  the  Poly¬ 
morphic  VTI  display. 

Introduction 

The  WORD-MASTER  utilizes  several 
standard  terminal  features  to  provide 
screen-oriented  editing  capability.  These 
are  cursor  address,  '“delete  characters  to 
end-of-line”  (deol),  and  clear  screen. 
Many  video  terminals  provide  these  fea¬ 
tures  internally.  They  are  accessed  via  an 
“escape  sequence”  which  instructs  the 
terminal  to  perform  the  requested  func¬ 
tion.  However,  the  Compal-80  uses  a 
memory-mapped  display  which  has  no  in¬ 
trinsic  features  for  display  manipulation. 
Terminal  functions  such  as  clear  screen 
are  emulated  with  software  within  the 
Compal-80  (vl.5)  monitor  program.  This 
program  provides  the  lowest-level  inter¬ 
face  between  the  operator  and  system 
hardware  and  contains  a  video  driver  for 
the  VTI  display.  However,  the  WORD- 
MASTER  patches  must  still  provide  the 
cursor  addressing  and  “delete  to  end-of- 
line”  (deol)  features,  since  they  are  not 
implemented  in  the  video  driver. 

Terminal  Functions 

Before  continuing,  it  is  well  to  de¬ 
fine  exactly  what  is  meant  by  “cursor 
addressing”  and  “delete  to  end-of-line.” 
Essentially,  cursor  addressing  is  the  pro¬ 
cess  by  which  the  cursor  is  moved  from 
its  present  position  to  another  location. 
The  new  location  is  specified  by  a  row- 
and-column  address.  The  patch  in  Listing 
I  (TCURSOR)  converts  the  row-and- 
column  address  provided  by  WORD- 
MASTER  into  an  absolute  address  for  the 
cursor  and  moves  it  there.  The  character 


by  Anthony  Skjellum 


Copyright  1981  ©  by  Anthony  Skjellum. 
All  rights  reserved.  1695  Shenandoah 
Road,  San  Marino,  CA  91108. 


under  the  cursor  (STR)  is  also  maintained 
correctly. 

While  cursor  positioning  retains  dis¬ 
play  integrity,  the  “deol”  function  is  used 
to  delete  parts  of  the  display  screen. 
Characters  from  the  present  cursor  posi¬ 
tion  to  the  end  of  the  current  line  are  re¬ 
placed  by  spaces.  This  operation  does  not 
alter  the  position  of  the  cursor.  Both  of 
these  functions  are  essential  to  producing 
a  screen -oriented  editing  environment. 

Software  Patches 

Within  the  WORD-MASTER  pro¬ 
gram  an  area  is  specified  for  hardware- 
dependent  routines.  The  length  of  the 
patches  for  both  “deol”  and  cursor  ad¬ 
dressing  is  larger  than  the  provided  area. 
Therefore,  the  implementation  was  divid¬ 
ed  into  two  segments.  Cursor  addressing 
was  placed  directly  within  the  patch  area 
and  “deol”  was  placed  in  CP/M’s  CBIOS 
(Customized  Basic  Input-Output  System) 
under  CONOUT:  function  (console  out¬ 
put).  The  patch  within  CBIOS  (COM- 
OUT)  interprets  TD  as  the  “deol”  com¬ 
mand  character  and  acts  accordingly 
when  such  a  code  is  received. 

Several  routines  are  present  within 
VTI. ASM  (Listing  I).  For  clarity,  each 
will  be  described  briefly.  CLRSCRN  is 
the  clear  screen  function.  It  transmits  a 
t  F  (FF)  as  required  by  the  Compal  moni¬ 
tor.  As  stated  above,  TCURSOR  is  called 
when  cursor  addressing  needs  to  be  per¬ 
formed.  It  handles  all  display  manipula¬ 
tions  as  well  as  calculations.  Finally,  the 
HITE  and  WID  constants  are  set  at  16 
and  64  to  reflect  the  dimensions  of  the 
VTI  display. 

The  routines  which  reside  directly 
within  WORD-MASTER  are  presented  in 
Listing  I  (VTI. ASM).  This  assembly- 
language  file  is  assembled  with  ASM  and 
linked  into  WORD-MASTER  with  DDT 
and  the  CCP  (Console  Command  Proces¬ 
sor)  Save  command.  The  CBIOS  program 
must  also  be  reassembled  to  reflect  the 
“deol”  patch  and  new  CP/M  systems  have 
to  be  generated  with  SYSGEN.  The 
necessary  routine  is  given  in  Listing  II. 
Both  programs  directly  manipulate  the 
internal  variables  of  the  monitor’s  video 
driver  and  still  utilize  this  code  for  text 
display,  scrolling  and  cursor  positioning. 


CP/M  is  a  trademark  of  Digital  Research. 
WORD-MASTER  is  a  trademark  of  Micropro 
International.  COMPAL  is  a  trademark  of 
COMputer  Power  And  Light,  Inc. 


Conclusion 

With  the  routines  presented  in  this 
article,  WORD-MASTER  can  be  inter¬ 
faced  with  the  Compal-80  hardware  en¬ 
vironment.  A  similar  approach  could  be 
used  to  interface  other  systems  with 
memory-mapped  displays.  ■■ 

(LISTING  ON  PAGE  26) 


Dr  Dobb  s  Journal  of 

COMPUTER  C4i*lHcnks  £-  Orlhodomu 

Subscription  Rates:  $2  5  per  year  within  the 
United  States;  $44  for  first  class  to  Canada 
and  Mexico;  $62  for  airmail  to  other  coun¬ 
tries.  Payment  must  be  in  U.S.  dollars, 
drawn  on  a  U.S.  bank. 

Writer’s  Guidelines:  All  items  should  be 
typed,  double-spaced  on  white  paper.  List¬ 
ings  should  be  produced  by  the  computer, 
using  a  fresh,  dark  ribbon  on  continuous 
white  paper.  Please  avoid  printing  on  perfo¬ 
rations.  Payment  is  in  contributor’s  copies. 
Requests  to  review  galleys  must  accompany 
the  manuacript  when  it  is  first  submitted. 
Authors  may  receive  a  copy  of  the  complete 
writer’s  guidelines  by  sending  a  self- 
addressed,  stamped  envelope. 

Donating  Subscribers 
Contributing  Subscriber:  $  50/year  ($25  tax 
deductible).  Retaining  Subscriber:  $75/year 
($50  tax  deductible).  Sustaining  Subscriber: 
$100/year  ($75  tax  deductible).  Lifetime 
Subscriber:  $1000  ($800  tax  deductible). 
Corporate  Subscriber:  $500/year  ($400  tax 
deductible,  receives  five  one-year  subscrip¬ 
tions). 

Contributing  Subscribers:  Robert  L.  Edens, 
Eric  P.  Hanson,  J.  G.  Zeratsky,  Mervin  E. 
Frank,  Edward  W.  Carr,  Steven  Fisher, 
Thomas  H.  Grohne,  Richard  Washburn,  Les 
Hancock,  G.  V.  Elkins,  C.  A.  Forsberg, 
Daniel  R.  Lunsford,  J.  D.  Griffith,  Michael 
Slade,  Thomas  M.  Schaefges,  General 
Electric,  Louis  L.  Odette,  Robert  M. 
Connors,  William  J.  McEown,  Robert  C. 
Luckey,  Kim  Leary,  Robert  N.  Stabler, 
Dewitt  S.  Brown,  John  B.  Palmer,  E.  Glion 
Curtis,  Roger  Hanson,  Jack  Miller,  Burks  A. 
Smith. 

Retaining  Subscribers:  Mike  Faithful, 
Osamu  Shimizu,  Scott  B.  Guthery. 

Sustaining  Subscribers:  Gordon  Eubanks,  Jr. 
and  Robert  C.  Birss,  Ph.D. 

Foreign  Distributors 
UK  &  Europe:  LP  Enterprises,  8/11  Cam¬ 
bridge  House,  Cambridge  Road,  Barking,  Es¬ 
sex,  1G11  8NT,  England  (Tel.  01-591- 
6511,  TLX  892395).  Hofacker- Verlag, 
Tegernseer  Strasse  18,  D-8150  Holzkirchen, 
West  Germany.  Computerland/Computer 
Store  AB,  Box  7134,  Kungsgatan  19,  S- 
10387  Stockholmn,  Sweden. 

Asia  &  Australia:  Electronic  Concepts  Pty 
Ltd.,  55  Clarence  Street,  Sydney,  NSW2000, 
Australia.  Computer  Store,  POB  31-261, 
22 B  Milford  Road,  Milford,  Auckland  9, 
New  Zealand.  ASCII  Publishing  Co.,  Ltd., 
Aoyama  Building  5F,  5-16-1  Minami  Aoya- 
ma,  Minato-ku,  Tokyo  107,  Japan. 


18 

102 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


Byte  Manipulation 
and  Byte  Pointers 


n  a  microcomputer,  bytes  are  usual- 
ly  assumed  to  be  8 -bit  quantities  residing 
at  unique  addresses  in  memory.  This  is 
only  a  special  case  of  a  general  concept  in 
use  on  larger  computers  for  some  time. 
Some  machines  boast  instruction  sets  that 
support  operations  on  variable- length 
bytes  located  at  arbitrary  positions  inside 
words.  Some  advantages  of  these  opera¬ 
tions  are : 

(1)  Efficient  memory  usage  is  accom¬ 
plished  by  allocating  only  as  many 
bits  as  are  necessary  to  represent  a 
value.  This  is  particularly  useful  in 
programming  languages  like  Pascal 
which  allow  variables  to  be  declared 
as  a  subrange  of  integers. 

(2)  Efficient  array  storage  of  data  with 
unusual  bit  lengths  can  be  imple¬ 
mented  without  wasting  any  space 
between  elements.  Pascal  uses  this  in 
implementing  the  PACKED  ARRAY 
facility. 

(3)  Testing  and  modification  of  both 
single  bits  and  groups  of  bits  in 
words  are  made  simple. 

(4)  Assemblers  and  disassemblers,  which 
frequently  need  to  manipulate  bytes 
within  words,  can  make  use  of  byte 
operations. 

(5)  Data  packing  programs,  particularly 
those  which  use  Huffman  encoding, 
require  some  method  for  variable- 
length  byte  access  for  optimum 
operation. 

I  first  became  acquainted  with  byte 
manipulation  instructions  during  several 
years  of  programming  on  a  Decsystem- 
10.  In  making  the  transition  to  micro¬ 
computers,  I  found  I  missed  having  byte¬ 
mode  operations  readily  available,  and 
resolved  to  write  routines  to  provide 
these  capabilities.  This  article  presents 
such  a  set  of  routines  based  on  the  DEC- 
10  instruction  set,  written  in  PDP-11 
FORTRAN.  If  high-speed  operation  is 
desired,  the  routines  could  be  easily  trans¬ 
lated  into  assembly  language. 

In  order  to  deal  with  bytes,  some 
quantity  analogous  to  a  memory  address 


by  Edwin  E.  Freed 


Edwin  E.  Freed,  Physics  Department, 
Oklahoma  State  University,  Stillwater, 
Oklahoma. 


must  be  used  to  indicate  the  position  of 
the  byte  in  memory.  This  quantity  is 
called  a  byte  pointer,  and  it  consists  of 
three  parts.  The  first  part  is  the  length 
of  the  byte  in  bits.  The  second  is  the  bit 
position  of  the  rightmost  bit  of  the  byte 
in  a  computer  word,  and  the  third  is  the 
address  in  memory  of  the  word  which 
contains  the  rightmost  bit.  On  the  PDP- 
1 1 ,  the  pointer  is  stored  in  two  words, 
using  one  half-word  (8  bits)  for  the  size, 
another  for  the  length,  and  a  full  word 
for  the  address.  Access  to  the  various 
fields  of  the  pointers  is  provided  by  the 
routines  POINT  and  UNPNT.  These  rou¬ 
tines  serve  to  insulate  the  user  from  the 
internal  structure  of  the  pointers. 

The  two  basic  operations  performed 
using  byte  pointers  are  insertion  and  ex¬ 
traction  of  bytes.  The  two  routines  LDB 
(LoaD  Byte)  and  DPB  (DePosit  Byte)  ac¬ 
complish  these  functions.  An  LDB  is 
analogous  to  a  memory  read,  and  a  DPB 
is  analogous  to  a  memory  write.  Note 
that  in  a  load  operation,  the  other  bits  in 
the  word  are  ignored  and  the  extracted 
quantity  is  right  justified.  In  a  deposit, 
the  other  bits  in  a  word  are  unchanged. 

In  the  DEC- 10  implementation  of 
byte  pointers,  the  bytes  were  confined  to 
a  single  word.  On  micros,  where  every  bit 
counts,  I  feel  the  additional  code  to  sup¬ 
port  bytes  spread  between  words  is  justi¬ 
fied. 

Some  method  of  stepping  from  byte 
to  byte  is  needed  to  support  tables  of 
bytes  and  similar  constructs.  The  routine 
IBP  (Increment  Byte  Pointer)  adjusts  a 
pointer  to  address  the  next  successive 
byte  in  memory.  DBP  (Decrement  Byte 
Pointer)  sets  the  pointer  to  the  preceding 
byte.  ADJBP  is  a  more  general-purpose 
routine  that  can  be  used  to  adjust  a  point¬ 
er  by  any  offset,  positive  or  negative.  It  is 
much  slower  than  IBP  and  DBP.  ADJABP 
is  used  to  adjust  the  address  portion  only 
of  a  pointer.  For  programming  efficiency, 
some  combined  operation  routines  are 
provided.  ILDB  performs  the  functions  of 
an  IBP  followed  by  an  LDB.  DLDB, 
IDPB,  and  DDPB  perform  analogous 
functions  (see  listing). 

All  the  routines  are  implemented  as 
FORTRAN  subroutines  or  functions.  The 
specific  call  formats  are  included  in  the 
listing.  Note  that  byte  sizes  larger  than  16 
bits  are  not  supported.  A  word  length 
of  16  bits  is  assumed.  If  this  is  not  the 
case,  various  constants  and  tables  will 
need  to  be  changed. 

One  non-standard  FORTRAN  fea¬ 


ture  is  used  —  the  LOGICAL*  1  variable 
type.  This  is  the  accepted  way  in  PDP-1 1 
FORTRAN  to  access  8 -bit  quantities. 
These  are  used  to  access  the  parts  of  a 
pointer  easily  and  can  be  converted  to 
INTEGER  data  at  the  expense  of  making 
the  pointers  longer.  Some  external  assem¬ 
bly  language  routines  are  also  used. 
SFTLFT  (V.N)  shifts  the  integer  V  left 
by  N  bits,  and  SFTRGT  has  the  obvious 
effect.  Both  of  these  routines  are  includ¬ 
ed  as  MACRO- 11  code;  their  implemen¬ 
tation  in  other  assembly  languages  should 
be  easy.  The  external  routines  IPEEK  and 
IPOKE  are  used  to  read  and  write  into  a 
physical  memory  location.  Another 
routine  to  find  the  physical  address  of  a 
FORTRAN  variable  is  usually  necessary. 
This  routine  called  IADDR,  along  with 
IPEEK  and  IPOKE,  is  provided  on  the 
PDP- 11  as  library  subroutines.  Many 
other  FORTRAN  implementations  will 
also  provide  them. 

In  concusion,  byte  pointers  and  byte 
manipulation  routines  are  a  useful  tool 
that  should  be  part  of  any  programmer’s 
bag  of  tricks.  The  coding  of  the  routines 
is  straightforward  and  can  change  many 
programming  tasks  from  a  headache  into 
a  pleasurable  experience. 

This  software  was  developed  as  part 
of  a  subroutine  package  for  physics  re¬ 
search.  The  research  was  sponsored  by 
the  National  Science  Foundation.  ■■ 

(LISTING  ON  PAGE  22) 


THIS  PUBLICATION  IS 
AVAILABLE  IN  MICROFORM 


University  Microfilms 
International 

300  North  Zeeb  Road 
Dept.  P.R. 

Ann  Arbor,  Ml  48106 
U.S.A. 

18  Bedford  Row 
Dept.  P.R. 

London,  WC1R  4EJ 
England 

Name  _ 

Institution _ 

Street  _ 

City  - 

State  _ Zip _ 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


19 

103 


Small-  O  Current  Status 


M 

T  Ay  original  article  “Small-C:  An 
Implementor’s  Notes  and  a  Bug  Correct¬ 
ed”  ( DDJ  #52)  was  written  during  the 
testing  stage  of  the  FORTRAN  version  of 
the  Small-C  compiler.  This  testing  was 
completed  at  the  beginning  of  November 
1980,  and  I  then  started  to  construct  a 
version  of  the  compiler  written  in  Small- 
C  so  that  I  could  transfer  the  compiler 
across  to  my  home  computer  system 
based  on  a  Z-80. 

This  would,  however,  take  some 
time,  and  in  order  to  get  my  first  program 
in  Small-C  up  and  running,  and  also  so  as 
to  have  something  other  than  an  assem¬ 
bler  to  demonstrate  my  system,  I  decided 
to  use  the  FORTRAN  version  of  the  com¬ 
piler  to  compile  a  version  of  the  game 
“Nim”  which  I  had  written.  Although  the 
program  was  short,  only  forty- nine  lines 
in  length,  the  code  generated  was  about 
360  lines  long.  After  typing  this  all  in  by 
hand,  followed  by  a  one  thousand  line  li¬ 
brary  file  for  Small-C,  it  was  clear  that 
loading  the  compiler  by  typing  in  assem¬ 
bler  was  not  really  a  viable  proposition 
despite  my  earlier  hopes. 

I  therefore  set  to  work  on  two  aids 
to  lessen  the  amount  to  be  typed.  They 
both  involved  modifications  to  the  FOR¬ 
TRAN  version  of  the  Small-C  compiler. 
The  first  was  trivial  to  carry  out,  and  was 
to  make  the  compiler  generate  Z-80 
mnemonics  rather  than  Intel  8080  code 
for  its  output.  This  avoided  the  need  to 
make  a  mental  translation  from  the  8080 
code  produced  by  the  compiler  to  the 
Zilog  mnemonics  that  my  assembler  ac¬ 
cepts. 

The  second  modification,  which  is 
now  almost  complete,  was  to  add  a 
second  pass  to  the  compiler  so  that  it 
would  generate  its  output  as  relocatable 
machine  code  rather  than  as  assembler; 
the  idea  being  that  machine  code  takes 
far  fewer  key  strokes  than  does  the 
assembler,  and  so  should  be  faster  to  en¬ 
ter.  It  is  probably  also  more  error  prone, 
but  simple  checksums  can  easily  be  used 
to  detect  these  errors.  I  have  not  yet  been 
able  to  try  this  system,  so  do  not  know 
which  is  more  boring  —  entering  machine 
code  or  assembler.  As  an  easier  altema- 


by  P.L. Woods 


P.  L.  Woods,  78  Dukes  Avenue,  Muswell 
Hill,  London  N10  2QA  England. 


tive,  I  am  also  on  the  lookout  for  a 
secondhand  paper  tape  punch  that  I  can 
attach  to  my  Z-80  system  so  I  can  punch 
the  cross-compiled  code  onto  tape  and 
load  this  mechanically  with  no  effort  on 
my  part. 

As  an  example  of  what  my  second 
pass  of  the  compiler  can  produce,  refer  to 
the  listing  (see  page  36).  This  is  the  first 
three  functions  for  the  original  Small-C 
compiler.  The  listing  has  been  edited 
somewhat  from  that  produced  by  the 
compiler  so  as  to  accent  those  areas 
which  have  been  modified.  The  first 
hundred  lines  or  so,  where  the  static 
(global)  variables  were  defined,  have  been 
deleted  together  with  most  of  the  assem¬ 
bler  mnemonics  produced.  The  symbol 
definitions  have,  however,  been  left  in  to 
aid  anyone  who  goes  through  the 
machine  code  produced,  by  hand. 

The  final  section  of  the  listing  shows 
the  relocatable  machine  code  produced 
in  hexadecimal  notation.  The  first  num¬ 
ber  on  each  line  (in  parentheses)  is  the  ad¬ 
dress  at  which  the  code  is  to  be  loaded 
before  relocation.  Addresses  to  be  relo¬ 
cated  are  indicated  in  two  ways,  depend¬ 
ing  on  whether  or  not  they  are  yet  de¬ 
fined. 

If  the  address  is  defined,  then  the  ful¬ 
ly  computed  address  is  printed  (in  byte- 
reversed  order)  after  the  appropriate  op¬ 
code  and  followed  by  the  $  symbol  to  in¬ 
dicate  that  the  relocation  offset  must  be 
added  in  at  that  point  when  the  code  is 
loaded.  Thus  the  instruction  placed  at  ad¬ 
dress  0003H  is  a  reference  to  memory  at 
15B2H  which  must  have  the  relocation 
offset  added  in  as  indicated  by  the  S  sign. 

If  the  address  is  not  defined,  usually 
because  of  a  call  to  a  precompiled  library 
or  system  routine,  or  a  reference  to  a 
static  variable,  then  the  second  format  is 
used.  This  is  similar  to  the  first  format. 
The  offset  from  the  external  (undefined) 
name  follows  the  opcode  (again  in  byte- 
reversed  order),  and  this  is  followed  by 
the  external  symbol,  whose  address  must 
be  added  into  the  offset  at  this  point 
when  the  loader  knows  its  value.  As  an 
example,  consider  the  instruction  at 
0012H.  This  is  a  subprogram  call  to 
CCMULT  (in  the  run-time  library)  and 
there  is  a  zero  offset  from  this  address. 

The  second  section  of  the  machine 
code  produced,  from  address  01E3H,  is 
the  literal  constant  area. 

The  third  section  is  a  list  of  the  ad¬ 
dresses  of  all  the  labels  generated  by  the 
compiler.  These  are  not  in  byte-reversed 


order. 

The  fourth  and  final  section  is  a  sym¬ 
bol  table  which  contains  entries  for  all 
external  symbols  used  or  defined  in  the 
code,  and  would  be  used  by  the  loader 
to  link  together  separately  compiled 
modules  into  an  executable  program.  The 
type  of  the  symbol  is  printed  (variable  or 
function),  together  with  the  address  if 
known  ( not  in  byte-reversed  order)  or 
the  word  UNDEF  if  unknown  (unde¬ 
fined). 

The  machine  code  is  produced  in 
almost  exactly  the  same  way  Mr.  Cain 
originally  generated  the  assembler  mne¬ 
monics.  In  fact,  after  every  statement 
which  generates  a  mnemonic,  I  have  in¬ 
serted  an  extra  function  call  which  causes 
the  opcode  associated  with  that  mnemon¬ 
ic  to  be  stored  away  until  the  codegene¬ 
ration  phase  (second  pass)  of  the  com¬ 
piler.  There  is  thus  not  a  full  assembler 
built  into  the  compiler,  and  as  a  result  I 
have  to  inhibit  the  use  of  the  “#ASM” 
and  “#ENDASM”  pseudo-operations. 
This  turns  out  to  be  a  not- inconvenient 
restriction. 

A  little  further  work  has  to  be  car¬ 
ried  out  during  the  first  pass  in  order  to 
remember  the  address  of  each  symbol  as 
it  is  defined  so  that  memory  reference 
and  jump  instructions  may  be  correctly 
completed  with  their  destination  ad¬ 
dresses.  The  symbol  map  is  a  by-product 
of  this  process. 

This,  then,  is  the  progress  since  the 
writing  of  my  original  submission.  I  am 
afraid  it  seems  at  times  to  be  a  list  of 
problems,  after  re-reading  my  original 
manuscript,  but  then  one  only  ever  writes 
up  after  a  success,  and  then  carefully 
omits  most  references  to  the  difficulties 
experienced  en  route.  ■■ 


(LISTING  ON  PAGE  36) 


20 

104 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


Since  1976,  the  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Or.  Dobb’s  Journal 

For  Users  of  Small  Computer  Systems 


B  Tree  ISAM 
Concepts 


IBM  PC: 

Printing  Graphics 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 


Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


$25 

one  year  subscription 
12  issues 

saves  $5  off  the  newsstand  price 


w 

H 


u 

H 

>H 

CQ 


M 

o 


q 

< 


*sr 

(N  —  <N  —  ^  ^ 

^  V*>  '-'  m  ^  I-H  <N 

IT.Bj 

ZhZl  _ _ 

Mjwzz+qo 

2*Ohh  3  3 
—  fit  o  p  a  q  q 
(n  a.  a.  a 

■  ^  i  Oil 

_g_* ■ 3__ 

n  2n-'- *  m  *r  o 

M  *H  (N  ■  — 

H2ga5  05  C5ggp 
ZWZQQQZZH 


«  a  a  <n  os  a 

:hh  a  a 


H 

O 

s 

D 

tO 

M 

O 


m  h  q  q  q  w  m  q  q 

232355228  S3 


a 

1 

z 

M 

2  _  _ 

U  WO. 
hhO 
>*  X  *-* 
CQ  *h 

<gg 

h  A  ^ 

SCO  to 

a  < 

5  w  •• 

05  -3  CO 

y 

§°a 

.35 

q  o 

CL  <  05 
CQ  U  < 
Q 


N  « 
w  H 

05  w 
Q  05 

§9 

-•4 
^  05 

«ei 

Q  X  m 

2S~ 

h  A  W 

U 

IN  H  7 

«  «  0 

05  JW 

W  <  < 

ssys 

HUD 

ZQO 

m  a  u 


e 

222 
i  E  ♦ 

_S~ 

<N  <N  —  — »  * 


X  U  X  _  . 

m  u  m  z  z  i 


05  05  <N  05  05 
H  H  Q  Q 


S^SppQCJD 

cn  A  A  Q 

■  ■  q  i  i 

„g_‘ • 5~~ 

fNZN««  ro^O 
'-'M'-.HCM  I  *-'*-'10 

g2g^s«eee 

ZWZQQQZZ H 

m  m  q  q  q  m  m 

252555228 


H 

O 

3 


Q  Q 

S3 


|2 


Q  q  ••  i 

3  q  to  05 

u 

3  H  U  U 

z 

•  U  z  H  u 

»H 

0  z  z 

H 

CU  M  JH? 

D 

CQ  J  5  o  I 

o 

<  q  O  S  U 

05 

CQ 

q  u  3 

D 

3 

to 

U 

(9 


So  — 

*  «N 

is  g 


§£ 
w  2 


W  05  — 


58 

aH  *-» 
Z  O 
Q  m  £ 


gs 

Z  D 


0. 

CQ 

< 

►j 

s 


H 

8 

S 

S 


Q  Q 

as 


H 

Z 

5 

o 

5 


V  § 


*  H 
CQ  U 
to 
05  M 

h  u 
H  O 
z  - 

»“•  05 

8g 

z 

U  (-1 

CQ  — 
cl 

<  CQ 

►a 

52 
8 
2 
I 

••  Z 
A  JD 
CQ  q  O 
5  <  05 

ou2 


H 

<  • 

U  >j 
M  CQ 


05 

H 
H 
cn  z 


*32 

u  u 

HUM 
X  H  Z 
hzP 

2  M  H 

WWW 
H  Z  U 
>«  U  M 
CQ  h  O 
CO 

< 


q  •• 

*4  (0 
<  H 

°S 


U  H 
H  H 
Z  to 
*h  U 

2W 

o 


D 

U 


<8 

I 


* 

CL 

CQ 

►a 

2 

H  • 
<  to 

gS 

H 

u  z 

H  m 

82 


in  IO  CO  O'  O  H  (N  n  ^ 
OOOOHHHHH 

ooooooooo 

OOOOOOOOO 


uuuu  CJ  u 


(NM« 

o  o  o 
o  o  o 
o  o  o 


invOflOONOHNfl^ 
0000»H<-HiHrH  H 

ooooooooo 

ooooooooo 


uuuuuu  uu 


uuuuuuuouu 


c 

© 

3 

a 

s 

3 


CJ 


WO 


>*  S3 

pa  a 


to 

z 

o 

M 

H 

< 

05 

u 


8 

Q 

u 

H 

5: 

D  « 

r 

M  z 
CO  o 

8S 

«g 

u 

32 

H  05 
D  H 
O  OS 
«  O 
u 
I 

iH 

05  .H 

°  J 
u  cl 
•  o 

H  CL 


05 

5 


H 

Z 


u 

H 

CQ 


UUUUUUUUUUUUUUUUUUUUUUUUUUUUOUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUUU 


05 

H 

os 

o 

u 


22 

106 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


CALL:  CALL  POINT (SI ZE .BIT ,ADDR, POINTER)  I  0001  SUBROUTINE  ADJBP (POINTR .OFFSET) 


X  Q  X 

p 

Eh 

X  Eh  CM 

*9  5 

P 

U 

Z  W 

2*  <  9 

y  w 

ptflQ 

o  q  < 

W 

Z  X 

ZXh 

q  -  q 

U 

M  X 

X 

<  ~  * 

q 

Eh  O 

QOQ 

H  ’T  06 

q 

Eh  — 

S  ~  y 

-  —  Q 

< 

u  — 

X  w 

9WZh 
Du  m  ^ 

H  Du  o 
x  o  x  x 
<  y 

>?rs 

x  x  q  q 
15  w  <  < 

Says 

yhOD 
x  z  5  a 
a  m  q  x 


HNZZ 

Sgggg 

o  z  z 

05HH  |  » 

“•22  — 
U  hn 

£"  "2£ 
WhQQ 
H  n  m  q  q 
u  h  d  <  2 
y  x  a  q  q 


*38 

H  M  O  VO 
<  ffl  I  »H 

a  — 
x  i  o  a  + 

CU  •  Q 
O  H  W  q  E-t 

H  U  <  H 

E-<  CQ  *h  do 

Z«Z. *2 


y  m  q  m 
X  CQ  Du  <  x  o 
QdHHdu 


qg 

E-*  M  VO 

<  CQ  —  ♦  pH 
as  vo 
X  ♦  ^  X  I 
04  •  a 

o  h  h  g  H 

H  CQ  1  h  do 

SX  H  X  in 
Ml  <N 

z  a  x  a 

X  x  x  o 
2  ^ WQ  hr 
u  m  q  m 

Z  CQ  Du  <  CQ  Q 
H  OS  m  h  OS  U 


<  06  06 
UhQQ 
WNhqq 
Wwd?< 

x  x  os  q  q 

O  a  a  a  a 

9 - 

HNnrr 

w  w  w^w 


2  i'Sg’e  i‘Ss’p  s 

w  KhwQhF'  K  hwQ  hr  p  Z  Z  Z  Z  3 


<8  81 

SH  X  I 

z  x  : 

05  ►-*  * 

*•8  SI 

X  w  >4 

h  d  oa  i 
a  °  n  i 

<  u  .  E 

9  3  «i  i  i 

<  H  I 

3 -111 

:  sgsi 


M  H  2 

-x  q 
x  eh  q  - 


82222S  S§ 


o  o 
o  in 
y  y  »h  «-h 


o  o 
o  in 
y  y  cm  cm 


UUUUUU  UU 


in  vo  ao 
o  o  o  o 
o  o  o  o 
o  o  o  o 


WON  HM1 
•H  CM  CM  CM  CM 
O  O  O  O  O 
O  O  O  O  O 


in  vo  co  ov 

CM  CM  CM  CM  CM 

o  o  o  o  o 

o  o  o  o  o 


P  5  w 

3 

X 

E-*  DJ  b4  as 
q  3  W 
w-'h^ 
x  x  z 
w  Q  M 
q  q  w  o 
~  x  g  x 

Q  Du  Q 

q  c«4  os 
x  x  o  o 

EE*? 

a  6 

H  Du  O  Z 

X  °  S  ^ 

Eh  Z  Eh 
D3  H  Z 

x  cq  z  2 

Eh  M  Eh 

eh  q 

X  X  X  3 

o  o  x  x 

n  x  a 
noqw 

W  h  <  r 

06  P 
x  x 

~E£E  1 

W  P  X 

Eh  I  I  X 

S'  ~  H 

X  05  Z 
ZNhQH 

D  h  h  q  o 
y  x  x  2  x 

3 


a  • 

z  a  — — 

<%  iSJ 
x  x 

W  Q  Q 

§9 

x  ca  q  q 
x 

a  a  q  a  a 
Q 

H  CM  CO  H* 

Z  Z  Q  Z  Z  3 
M  H  Q  H  H  h 

o  O  <  O  O  w 

X  X  kh  X  X  X 


z  <  -q 
o  *— *  - 

H  h  M  (S 
Eh  M  — Q 

<  m  x  q 


Eh 

< 

z2 

X 

<  X 

Z  M 

— , 

D 

D  VI 

z 

q  n 

M  — 

X  ' 

O 

X 

D 

y  m 

p 

Eh 

X 

q  •• 

X  X 

X  X 

Z  1 

X 

q  x 

X 

Q 

y 

i—4  ; 

D 

Eh 

<  Eh 

z 

CM 

-<  z 

P  ' 

w 

<•>  7% 

M 

X  « 

«  X 

X  i 

1 

□ 

Eh 

q  x 

q  q 

X 

..  z 

D 

X  X 

<  < 

a 

o 

Eh 

q  o 

O 

<  y 

y  > 

Z 

q  y 

X 

M  x 

►H  M 

X 

Q  Q 

X 

<  X 

X 

X  Eh 

y  d 

N  I 

z  z 

z  y  < 

3 

<  z 

Q  o 

M  | 

□  u 

D 

X 

>  w 

q  x 

X  1 

CM  H  M 

x  2  2  x 

5  1  1  9 


a  x  x  c 
Q  Q  X  : 
Eh  q  q  q 


2~  t! 

X  X  X 
Eh  Eh 

>«  Z  X 
x  m  q 

*2  ° 
Eh  X  Z 


H  q  .. 
x  q  x  x 
y  <  Eh  w 

5°S£ 

••  Z  M 

i  q  d  p 
q  y  x 


u  u  y  u  u  u  u 


u  u  u  u  u  y 


y  y  u  y  u  y  y 


m  vo  r-  co  o  o 

O  O  O  O  O  "-H 

o  o  o  o  o  o 
o  o  o  o  o  o 


(N  n  m  m  vo  r*  ao  ov  o 

OOO  O  O  O  O  O  *H 

ooo  oooooo 

OOO  OOOOOO 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


23 

107 


0003  L0GICAL*1  POINTR  (4 )  .LADDR  (2)  0004  L0GICAL*1  POINTR (4) 

0004  EQUIVALENCE  (IADDR, LADDR (1) )  0005  INTEGER»2  POWER (16) 


z  cd 

3  X 

1-3  M 

M  J 

U  CD 

J 

9  • 

z  cd 

<  CD 

04  H 

04 

H  X 

flu 

<  M 

to  o 

H  H 

Z  04 

CD  N 

H  H  Z 

E-*  M 

E-» 

2 

flu  w 

<  E-* 

s^e 

CD 

uj  Cn 

Cd  M 

a;  CD 

p  <  u 

M  M 

U  HI 

P  u  a: 

pS  W  -  c 

P  w  a  c 

Z  JQ 


04  >  flu 

2  hg 


2  2£g  1 
,  US£2 

••  X  HI  □ 

(0  JDO  < 

04  ,J  (J  04  > 


CD  H  H 

D  02 

CO  04  M 


!  co  ^  vo  os 

•  * w*h  o  w 

.  cu  S  a;  9  h 

i  J  2  W  h  y 

iHh  J-K 

'  flu  O  O  H 
)  (0  0u  0.  CD  U. 

u  w 

INHN  * 

«  «  «  H  J 

i  W  <  CD  <  2 

is^bss 

'HUH3H 

;  z  5  z  ox 

IH  JhM  w 


s:s: 

X  cm  cm  — . 

H  wVO  ^  «H  CM 
an  a  w  w. 

-  EH  •  H  CM  OS  OS 

h  z  h  z  a  a 

SS^o+S§ 

iS-ia j j 

H  fN  Q 

a  B  ■  Q  N  N 

y_e_2~~ 

QN2N  n  4f  O 
Pz^ZOZZP 

M  M  Q  M  M 

QOCuO^OpO 


u  u  u  u  u  u  u  u 


U  U  U  U  UU  UU 


cm  cn  ^  in  vo  r*» 
o  o  o  o  o  o 
o  o  o  o  o  o 
o  o  o  o  o  o 


H  N  ^  irnc  (V  aj 


Sen  •*■  — *  * 
~  H 

°gg8S 


S  z  2  3 

O  M  M  M 


CD  \10 

04  04  x  U 

2zh 

flu  CD  + 

cd 

X  »H 

CD  CD  a 

HI  U 

D  CD 

u 

P  as  * 

p  N  N  CD  t- 

xp  *h 

H  04  P 

z 

U  *H 

P  04  04 

Z  04  H  H 

(0  mm 

B 

os  ^  as 

— H  CO 

<  ..  h  « 

CQ 

H  «H  CM 

u  ww  ■  ■ 
<  ct,  os 
BiQQhh 

h  Q  Q  H  H 
X  <  <  «  CD 
U  M  J  H  H 


CD  CD  CD  p 

CD  J  flu  Q  CD 

ID  H  H  J  K 


W  I  M 

S  H  ■  §  O 

H  U  CD  S  Ql 

W  J  Q  w  2  ; 

o  M  J  os  Hi 


'  05  -«  O'  —  — 

:  •  tn  cm  x  a 

•  Z  H  Z  Q  Q 

:  M  J  M  +  Q  Q 

>  8  —  8  os  5  5 

4  CM  Q 
H  w  II  Q  N  N 

~g  JL~ 

'CM  2  CM  n  MO 
I  ^  M  —  N  —  —  in 


)H  H  Q  M  H  h  H  H 

;ofluo<ooo  XDQCQ 

1  &  H  &  H  |1<  Q.U  W  H  H 


h  U  H 
X  O  •  w 
Zj  0.  H  OQ 

ii  w  w 

flu  *D  II  2 

m  h  m  as 

cd  u  S£ 
CD  j  u.  j  cd 

CO  H  H  H  os 


u  u  u  u  u  u 


u  u  r*  u  u 


CD  (J\  O  H 

O  O  i-»  »H 
O  O  O  O 
O  O  O  O 


cm  cn  *3*  in  id 
o  o  o  o  o 
o  o  o  o  o 
o  o  o  o  o 


co^OHnMinion 

OOHHHHHHH 

ooooooooo 

ooooooooo 


O  H  n  M 
CM  CM  CM  CM 

o  o  o  o 
o  o  o  o 


24 

108 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


Eh  U 
►H  P 

co  3 

w 

22 

W  - 

3 

< 

Q  06 

> 

w 

5zb) 

X  M  04 

B 

z 

QQZ  Cm 
Eh  OS  O 

M  J  J  p 

JJh  Q  C 

8SSS  5; 


uuuu  uu  u  u 


HZ  Cm 

<  05  o 

.  CQ  D 

I  Q  H  Q  Q 

I  *J  w  z  z 

i  •-«  os  w  w 


Eh  J  CQ  p 
J  Qr 

8<  JU 
U  Q  OS 


-  W  ~  ~ 

S  W  CN  — 

r-H 

C  HH  OES 

:  -  q  os 

H  Eh  Q  Q 

<  Q  H 

i  OS  J  <  Cm 

3  Eh  -  _J  J 

3  Cm  —  *  Eh 
C  CO  nr  VO  OS  £n 
h  "-'>H  Q  (0 

-  Eh  OS  ~  Q  - 

k  Cm  Eh  05  5*  Eh 

k  J  Z  W  w  U 

3  Eh  hh  5  05 

h  Cm  O  O  Eh 

0  CO  CU  0,  W  Cm 

U  CO 

J  tNHtN  7 
«  «  ♦  MJ 

s  OS  J  os  j  < 

j  W  <  W  <  Z 

5  O  U  U  >  06 


uuuu  uu  uu 


X 

s.  a  a  «  a  m  a 

<  <  in 

CO  Q  Q 

<  CO 

Eh 

m 

E*E<EC)EhDEh 

Eh  Eh  ON 

5  8  8 

0}  < 

Fh 

D 

p  z  z  o  z  O  X 

<  <  o 

OS  T. 

W 

£0  2 

co 

ShhJhUW 

Q  Q  ht 
* 

Cm  a  J 

U  HH 

u 

M  < 

u 

u  u 

u  u 

u  u 

u  u 

u  u 

U  U 

»H 

n  n  v  in  us  > 

ao 

ON  o 

•H 

CM 

O 

o  o  o  o  o  o 

o 

O  <H 

1— 1 

rH 

o 

o  o  o  o  o  o 

o 

O  O 

O 

O 

o 

o  o  o  o  o  o 

o 

O  O 

O 

o 

Dr.  Dobb’s  Journal,  Number  53,  March  1981 


25 

109 


0013  CALL  IPOKE (IADDR,IBIT  +  (SFTLFT (STUFF , 15-PO INTR (2 ) ) . AND . IMASK ) ) 


c_> 

O 


CO  «  CC  >o 

Z  £  u  O 

O  «'  f—  • 

0X0)  — 

o  <r 

•=>  x  ui 


oo  uj  *— 

o>-  oc  <r 


* 

*  *  * 

♦  *■ 

♦ 

* 

* 

* 

X 

* 

* 

_J 

UJ 

* 

* 

<r 

1— 

* 

* 

X 

cn 

►— 

* 

* 

o 

« 

*— 1 

* 

X 

X 

J* 

* 

t— 

1 

UJ 

♦ 

* 

•« 

« 

z 

oc 

1=1 

<Z  U. 

» 

CC 

o 

UJ  z 

* 

UJ 

UJ 

<a  <c 

lE  — J 

«• 

►— 

o 

• 

O  II 

* 

Z 

o 

O  H- 

cn  o 

■* 

►H 

l— 

1— • 

* 

CC 

•* 

X 

3 

4f 

o 

cn 

Hi  Ol 

c_>  z 

44 

OS 

z 

UJ  X 

* 

o. 

X 

— 1  UJ 

•* 

z  z 

«■ 

o 

u  cn 

* 

O  z 

oc 

— J 

* 

•-H  3 

♦ 

u 

•  ». 

•  »  •  Mb 

* 

H- 

•* 

* 

►H  O 

44 

* 

cn 

* 

cn  <j 

44 

H-  X  XX 

<r  to  CD  co  x 

O-  CO 

•  X  oc  <x 


J«  t5 

3  3 


SB 


^  ts 

05  3 


5  aSSl 

Q  D  y  Z  m 

O  U  S  h  u 

U  Z  m  U  Z 

m  U  2  O 
H  U  0  2 
C/3  -  Z 

«  -H 

CC  Eh  X  *Eh 
Z  O  H  X 
U  W  m.  pu  O 

SD  Z  U  h 

•j  a 

(A  (A 

E-»  hhlflW 
<  HHhh 
X  03  OQ  H  h 

H  03  03 

z  z 

w  z  z 

w  >h  >1 

M  ••  H  Eh  >H  >H 

Eh  W  h  h  Eh  Eh 

UOjhhHH 

U^zzh^ 
m  <3zz 
zwdd2< 

W  O  O  D  D 
OS  Z  OO 

W  M  E-«  Eh 
X  Eh  H  H  H  Eh 

r  D  03  CQ  h  h 
O  O  I  I  CQ  CQ 
OS  vo  VO  I  I 

Q  rH  rH  VO  VO 
2  U  -H  *-H 
<  X  <  < 

Eh  <  < 

C/3  W  W 
Z  •  Eh  Eh  Eh  Eh 
O  W  <  <  X  X 
H  O  OS  Eh  H  H 

Eh  <  O  O  X  X 
<  D  OS  OS  C/3  03 
OS  O 

£§  1  '  1  ' 

X  O  X  U 
ju Ja ja 
<  Z  J  J  Eh  Eh 
UHOOfc.fc. 
t-t  x  0S  OS  C/3  C/3 
U  U 


W  -3 

03  •  X 

W  CO 

Q  O 

D  <  U 

D  X  < 

O  U  2 

x  <  w5 

03  CL  Sm 


Eh 

u  o 

C3 

Eh 

z  W  X 

C/3  O 

M 

z  u 

B  D  ° 

<  P 

X 

Q 

Mow 

2  D  Q 

.... 

H 

2  J  Eh 

ZD” 

3  03  vo  (h 

I  <  £h  H  H 

*.>933 

X  ”  2  D  D 
J  D  D  Q  Z 

o  <  z 

Z  u  < 


D  <  Z  W 
U  >  W  D 
Z  H  < 
5  Z  Z 
W  D  - 
Eh  U  O  O 
03  W  U  Z 
<  Eh  w 
z  z  U  NJ 

H  "  S-4, 

gEn  m 
<  H 

SgS§ 

Z  p 

U  H  Q  Eh 
Z  U  2  X 

M  o  *<  z 


+  + 

+  — ' 

^  m  m 
m  os  os 

Z  ^  W 

w  <a»  <30  (N 


Eh  >  >  O 

cnoow 

Eh  X  2  CD 


OOHwn 

X  Z  Z  rH  z 


03 

u  D  U  u  U  03 

3  O  Q  U  Z  Eh 

u  z  <  q  cq  z 


in  o  h  in  rHoo-Hf'ir" 
niooo  tt  o  o  o  r-  o 

r-  in  in  nr  n:  — »  m  n  m  cm 

mrimH  ovominno 

OHHO  OOOOOO 
OOOO  OOO-HOO 

ON^VO  OIN'TVO  ON 

OOOO  H  H  rl  H  (N  (N 

OOOO  OOOOOO 
OOOO  OOOOOO 
OOOO  OOOOOO 


W  -  VO  C/3 
Eh  VO  ^  Eh 
<  >H  M 

Eh  Z  Z  CQ 

S<  u 

D  OX 

o  u  o 

8  Eh  Z  Z 
O  *h  U 
W  Z  ffl 
2D  W  £ 

5§  Eg 

D  II 

O  W  II 

ZD” 

D  C/3  vo  Eh 

I  <  Eh  rH  m 

E^BSS 

O  ••  2  D  D 
Z  J  D  a  Z 
D  D  U 
O  <  Z 
Z  U  < 


0HNnvfmvoi'coovoHOifnvinvoMnff'OHNn^invor'CO<j'OiH(Nnvruivor'ffl2° 

innTfinvcr'a3(j\HHHHHHHHHH(N(N(NNtvi(N(MNNNnnnnfnnnnnn^«T'Tvr'r^vrvTvrvrin 


g£S2 

Szt.< 

WO- 
Eh  O  O 
C/3  W  Z  Z 
<  Eh  W  W 
Z  Z  Eh  N 
M  Z 

Eh  D  X 
Z  Eh  °  m 

E3  <  u 

5  E  u  § 

z  z  p 

U  Eh  Eh  Eh 
z  w  u 
M  O  Eh  Z 
..  u  .. 
o 


+  — 

— '  m  in 
in  «  X 
X  ^  v> 
w  ca>  <a<  m 


Eh  >  >  a 

S!S£ 


in  o  H  t** 
cn  cm  o  o  o 

o  h  m  in  ^ 

o  mmenn 

o  OHHO 

o  oooo 

rf  VO  O  CN 
N  n  n  n 
oooo 
oooo 
oooo 

rH  cm  o  *r  in  vo  r* 
in  m  in  in  in  in  in 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


T  CURSOR 


0) 

Sp 

a 

* 

*  HP  * 

H- 

CL 

* 

HP 

♦ 

HP 

*P 

* 

HP 

* 

♦ 

cn 

*• 

* 

HP 

o 

* 

HP 

cn 

►— 

* 

* 

cn 

►—» 

z 

* 

HP 

3 

"a 

>- 

cn 

Hi 

* 

HP 

3 

<r 

UJ 

I 

3 

* 

HP 

— i 

P— 

o 

a 

* 

HP 

Ul 

u 

o. 

<L 

cn 

« 

* 

3 

O 

to 

_J 

(Z 

►— 

4* 

* 

►—* 

cn 

*— t 

3 

i— * 

• 

* 

HP 

cn 

cn 

UJ 

HX 

c 

CL 

CO 

■ 

* 

* 

o 

<1 

cn 

A 

z 

o 

o 

at 

■ 

* 

Hf 

cn 

J 

UJ 

O 

CD 

(J 

o 

u 

UJ 

■o 

UJ 

* 

HP 

z 

UJ 

CL 

CD 

UJ 

A 

z 

• 

-» 

3 

cn 

_J 

cn  a 

►— 

A 

i— 

Ul 

CL 

UJ 

* 

cn 

4P 

CD 

A 

Z 

o 

•— «  *— « 

•— i 

3 

3 

O 

O 

z 

* 

UJ 

* 

<r 

Ul 

Ul 

<x  => 

*-  o 

3 

a. 

-J 

h— 

* 

►— 

HP 

o 

A 

0- 

UJ 

3  CL 

1— 

Z 

•« 

I 

z 

-0 

* 

HX 

HP 

Ul 

CD 

iL 

U- 

3 

CL 

at 

»— 1 

3 

CD 

*— 1 

UJ 

* 

3 

HP 

A 

z 

Z 

CD 

A 

UJ  o 

Hi 

z  A 

<r 

»— « 

>- 

3 

* 

a 

z 

o 

►— « 

a 

cn 

*-H  _J 

Z 

UJ 

UJ 

X 

Z 

x 

A 

X 

•—» 

Z 

* 

HP 

3 

p— 

UJ 

o 

c_> 

3 

3 

*— i 

* 

HP 

fa— 

z 

CD 

UJ  =3 

o 

UJ 

"I 

<r 

UJ 

o 

Ul 

►— 

cn 

Ul 

i— 

ac 

HP 

cn 

<r 

»— « 

Ul 

3  _J 

cn 

3  h- 

►— 

cn 

cn 

3 

CL 

z 

-J 

3 

3 

z 

* 

o 

HP 

Hi 

CO 

CO 

UJ 

— J 

<X  HX 

— j 

<X  uj 

UJ 

z 

z 

<x 

UJ 

<x 

3 

_l 

HX 

o 

* 

►— 

HP 

z 

o 

Ul 

CO  3- 

<X 

cn  CD 

CD 

3 

3 

cn 

ru 

z 

z 

CL 

cn 

o 

«■ 

«— • 

HP 

CD 

-i 

A 

cn 

•  M 

•  « 

•  “• 

• 

•  •. 

•  •> 

•  r. 

•  •» 

■  M 

* 

z 

HP 

■  M 

* 

o 

HP 

* 

z 

HP 

z 

z 

HP 

z 

z 

z 

a 

m 

HP 

UJ 

A 

o 

C_J 

cn 

cn 

• 

HP 

u 

U 

o 

to 

A 

CL 

<X 

z 

O 

z 

cn 

z 

* 

r— 

HP 

A 

A 

A 

3 

o 

* 

HP 

UJ 

UJ 

U- 

a  £=> 

A 

Z  CD  A 

cn 

z 

Z 

UJ 

z 

A 

z 

z 

z 

Z 

Z 

o 

« 

O 

HP 

o 

o 

o 

CO 

HP 

1 

HP 

* 

— J 

HP 

« 

HX 

HP 

Z 

a: 

X  A 

A 

♦ 

a. 

HP 

cn  «— « 

cn 

cn  _J  a 

<x 

=> 

CL 

3 

r— « 

3 

A 

A 

A 

A 

A 

«* 

z 

HP 

3 

3 

O  X 

A 

3  z  <x 

A 

o 

O 

O 

3 

o 

HX 

<r 

HI 

HI 

<r 

Hi 

<E 

Z 

z 

HP 

o 

HP 

a 

a 

C3 

a 

a 

o_  _J 

Cl. 

•-  CL  _1  A 

_J 

r 

•  -  a. 

z 

Z 

z 

•  -  A 

A 

A 

A 

A 

A 

cn 

3 

* 

u 

HP  •• 

UJ 

UJ 

UJ 

UJ 

UJ  •  -  •  -  •  -  .* 

■* 

HP 

HP 

HP 

* 

HP 

HP 

HP 

cn 

-J 

HP 

HP 

cn 

z 

_i 

CD 

HP 

HP 

cn 

A 

A 

CD 

UJ 

HP 

HP  HP  HP 

HP 

►— 

3 

CJ 

Z 

z 

cn 

CD 

cn 

CD 

CD 

CO 

A 

A 

U- 

UJ 

UJ 

Ul 

O 

o 

A 

UJ 

O 

A 

o 

U. 

u 

o 

U- 

u 

UT  r- 

IT) 

ID  <X  O' 

HX 

rv. 

■. — 

CJ 

'O 

O' 

O' 

O' 

O' 

O' 

O' 

O' 

CM 

PO 

A  «— 

A 

UJ  CM  — 

ro 

UJ 

un 

CM 

m 

CM 

CM 

CM 

CM 

CM 

CM 

— 

CM 

o 

h 

II 

ii 

II 

II 

HD  IN. 

<X 

A  CJ  U 

o 

PO 

U“> 

'O 

ao 

O' 

HX 

A 

a 

A 

UJ 

U- 

O 

ro 

UJ 

A 

o 

'O 

O'  O' 

O' 

O'  O'  O' 

<x 

<r 

<X 

<x 

HX 

<x 

<x 

HX 

HX 

HX 

HX 

HX 

HX 

A 

A 

u. 

U 

o 

o 

o 

•—  — 

r— 

•- 

•— 

— 

•— 

•— 

•— 

■»— 

— 

•*— 

•— 

•— 

A 

A 

CD 

o 

o 

o  O  O  O  O  O  O  O  O  O  O  O  OOOOOOOOO  UJ  UIU.  o  o 


o  z  z 

O  ph 
Eh 

H  x  H 

U  M 

O  x  q 
x  cn  < 


x  x  d 

H  O 

Sop 

ss* 

x  * 

UQU 

S5S 


X  O  Q  u  W  X 

O  U  Q  w  Z  Eh 

05  CO  <  O  OQ  05 


m  cm 

ONOOHHh 

O  O  O  O  O  fH.  o 
o  o  r*  o  ro  ro  cm 
vo  m  cm  o  in  rH  o 
o  o  vo  o  o  o  o 

O  rH  O  rH  rH  o  O 

VO  O  CM  VO  O  CM 
m  *<r  m  m 
o  o  o  o  o  o 
o  o  o  o  o  o 
o  o  o  o  o  o 

O  H  CM 


0 

o 


Px 

ei 

H 

Eh  U 

3S 

3  Eh 
O  O 
05 
Eh 

W  O 
CQ  E- 
I 


05  03 

W 

O  Cm 

w  o 

Eh 

Z  05 
►h  w 
CQ 
W  £ 


i  5! 

X  0 

o» 

8h 

X 
U  3 
Z  Eh 
M  X 
Eh  X 
0  U 
O  W 
X  0  •• 

>-3  CO  VO  Eh 
I  <EhHH 

X  -  SDD 
D  D  0  O  Z 
Eh  3  0 
X  <  X 
X  U  *3 


I  I 


0 

o 

u 

Eh 

§ 


3 

Eh 

£ 

u 

Cm 

DUEm 

U 

a 

O  DO 

o 

D 

S 

X  D  O 

2 

Eh 

Eh 

<  <  X  CQ 

u 

Z 

CQ 

< 

>  W  D 

05  Cm 

D  W 

Eh 

Eh 

Eh  Eh  < 

W  M 

O  X 

M 

O 

CQ  X  Z 

X  u 

CJ  O 

X 

X 

CUD  •* 

Pkk 

X  X 

X  fj  O  O 

-  fe?  w 

w  w 

z 

u 

w  u  x 

Eh  D 

a  CO 
Q 

co  3 

u  0 


.  -  w 

Z  Z  W  N 

WHS 

SH  Cm 
Eh  m 
05  <  Eh 

££gg 

~EhQ8 
w  z  w 
0  <  05 


in  +  + 
05  —*  —* 
—  m  in 
05  a: 


6 

Eh 

>  >  a 

gig 


m3 

Eh 

Cm 

CO 

in  o  «h  m 
<n  o  o  o 
r*  m  in  ^ 
inmnn 

O  rH  rH  O 
O  O  O  O 

'f  VOOCM 

m  in  vo  vo 
o  o  o  o 
o  o  o  o 
o  o  o  o 


Eh 

X 

0 

M 

Q 

X 

W 

Eh 

Eh 

Z 

CQ 

< 

D  W 

Eh 

Eh 

O  X 

M 

O 

U  O 

X 

X 

£  X 

u  u 

z 

W 

X  X  D 

X 

>  Eh  O  J 

O  Cm  < 
Eh  U 

hS3s 

Cm  05  X 

m  u  Q  U 


CQ 

3  o  W  CO 
CO  W  z  Eh 
<  a  CQ  05 


CQ  Eh 
I  M 
VO  CQ 
-« £ 

<  z 


x  3 

CO  D 

a 

8? 
0 
U  05 
Z  Eh 


Eh  X 

55 

0  Eh 

°S 

Eh 

03  8 

I 

VO  CO 
rH  Eh 

PH 

05  CQ 

W 

0  Cm 
W  O 
Eh 

Z  05 
w  u 
CQ 
U  £ 


+  + 

«in  m 
in  05  05 
X  —  ~ 


sg  Pi 

D  N 

Eh  D 
y  X 

«/> 

O  W  II 

X  D  .. 

W  Q 

X  D 

CM 

EH  >  > 

X  u 

D  CQ  vo  Eh 

U  0 

X  o  O 

X  faH 

1  <  Eh  rH  M 

Eh  £  £ 

<  X 

0  ••  £  D  p 

X  D  P  O  Z 

Eh  D  O 

Cm  <  X 

TRGT: 

BEQ 

CQ  0  3 

</> 

oj 


U  W  CO 
W  Z  EH 
Q  CQ  05 


Cm 

U 

*h  Q 
§« 


O 

Q 


CO 

in  o  h  in 

CM  O  O  O 
r-  m  m  ht 
innnH 
O  »H  rH  O 
o  o  o  o 


CM 

o  o  o  *h  m 
o  o  o  o  r>  o 
cm  o  cn  po  cm 

VO  CM  o  in  rH  o 
o^oooo 
O  O  rH  rH  o  O 


rH  CM 

o  «-h  m  r" 
o  o  o 
m  m  co  cm 
vo  m  rH  o 
o  o  o  o 
O  rH  o  O 

T  VO  O  CM  'T'COCM  -«T  VO  CM^TvO 

vo  vo  r'  p-  r^r-'oooo  hhh 

OOOO  O  O  rH  rH  H  H  HHH 

OOOO  OOOOOOOOO 

OOOO  o  o  o 

o  h  cm  n  hj-  m  vo  oo  <r>  o 
KMfn^iniOhcooioricMnvfirnoMswoooo  oooooo»h 
cococococococococncT'avcTvcT'avavavcnavrHrHrHrH  hhhhhhh 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


27 

in 


Using  WORD-MASTER 


co  ujz 


A  O'  o 
u_  A  O 
A  *-  CD 
Ui  o  u. 


h  O  O 
X  Uj  liJ 
O  CC  A 
U  U  CL 


a:  uj  oc 
CJ  OC  X 
(A  UJ  U 

Ct  _J  , 


»n  e  f 
Of  QJ  -O 

u  ai  id 

T?  t- 

0i  7  u  Oj 


CO  o 

— J  =3  O  CO 

O  U  H.  OC 

Ui  _J  A  A 

X  ui  o  cj 


♦*  -o  ^ 

a*  -o 

A  iTS  C 


O  a  aq 

O  —  —  — 
O  O  O  O 


co  _j  ac 
J  u  o 
U  J  C  I 


>  -h  a. 

o  a  n  c 
C  u  — >•*  -». 


£  x  n 

-  — •  “O 


■O  -  CD  UJ 
O  CJ  A  U. 
0-0-0 
o  o  n  uj 


*  « 
# 

4  44 

44 

• 

44 

44  41 

>  * 

44 

44 

* 

44 

• 

• 

A 

44 

CJ 

* 

UJ 

44 

o 

44 

A 

44 

—1 

* 

UJ 

44 

* 

UJ 

UI 

44 

F— 

* 

z 

CD 

44 

CJ 

44 

Ui 

OL 

44 

UJ 

* 

CO 

CO  A 

<r 

44 

QC 

44 

A 

z 

— I 

44 

OC 

44 

<x 

44 

o 

44 

o 

UJ 

■<r 

44 

CJ 

» 

»— 

(J  CO 

44 

<r 

t— 

UJ 

44 

O 

44 

>- 

a. 

Z 

CO 

44 

4— 

44 

CL 

CO 

1-4 

A 

44 

44 

O 

o 

44 

UJ 

44 

z 

u 

a. 

o 

44 

CJ 

44 

UI 

•—i 

F— 

44 

CL 

44 

z 

CO 

44 

O 

4f 

• 

OC 

44 

u. 

* 

u_ 

A 

z 

UI 

44 

■  — 

44 

o 

<r 

A 

44 

* 

a- 

Z 

44 

* 

CD 

z 

UI 

UI 

44 

44 

z 

CJ 

oc 

z 

44 

44 

►H 

4— 

UI 

UJ 

44 

44 

z 

<r 

z 

at 

44 

Z 

44 

z 

DC 

A 

44 

fN 

44 

*—* 

CJ 

• 

• 

44 

ro 

44 

CD 

CO 

z 

A 

44 

+ 

44 

UJ 

UI 

UI 

Z 

44 

Z 

44 

A 

A 

z 

1— 

•« 

44 

oc 

44 

Z 

I— 

z 

Z 

44 

CJ 

* 

O 

<r 

M 

z 

44 

CO 

44 

4— 

4— 

o 

o 

44 

oc 

44 

oc 

A 

a. 

CJ 

44 

—i 

>- 

44 

CO 

UJ 

a- 

44 

CJ 

oc 

44 

►— 

u. 

co 

= 

44 

o 

4* 

z 

u. 

UI 

• 

z 

44 

(— « 

A 

co 

z 

:> 

44 

UJ 

* 

o 

A 

UI 

F— 

<x 

44 

z 

44 

a. 

z 

CO 

44 

* 

4— 

CJ 

UJ 

= 

44 

CD 

A 

44 

z 

►— « 

4— 

CO 

44 

oc 

A 

* 

UJ 

A 

<r 

<L 

z 

44 

...  o 

* 

z 

Ui 

a_ 

UI 

CD 

44 

•  • 

44 

CD 

oc 

A 

44 

Z 

* 

UI 

OC 

oc 

CJ 

O 

44 

UI 

* 

A 

o  o 

z 

Z 

44 

z 

44 

a_ 

u. 

u. 

*— « 

UI 

44 

CD 

44 

44 

UI 

*  • 

*4  44 

44 

44 

44 

44  4 

4  44 

A 

CD  * 

Z  t 

*-«  * 


uj  i  <r  uj 

x  U  3  CO 

CJ  =5  A  ZD 

CO  CO  CL 


<r  —i  co 

cr  - «  «-i 

UJ  z  z  • 

o  m  uj  o 

O  to  t  4  H 

I-  DC  QC  •«  A 


<1  t-  UJ  UI  u 
I3JK 
C— >  O  A  «  o 


co  uj  <r 
Z  Z  UI  >- 
— •  CO  A  _l 


O  UJ  A  O  O 


lDC  O  X  U.  A 
UJ  h-  U  M  « 


28 

112 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


{  push  h  ;  save  extra  copy 

01 BB  04  EREOL :  BB  CHEOL  {(FIRST)  CHARACTER,  OR  0  IF  NONE  nov  a,l  j  jet  low  order 

01 BC  00  BB  0  {SECONB  CHARACTER  IF  TERMINAL  ani  43  ;  jet  position  on  current  line 

{...REQUIRES  2-CHARACTER  nov  b,a  {  save  in  b 

{...SEQUENCE,  ELSE  A  0.  nvi  a, 44  {  Max.  value  is  44 


O' 

0) 

t~  (9 

0> 

C  jZ  3 

o  -b*  o 

at  ^  C 

c  s- 

*  o  <H  iTJ  C- 

C  T5  «i  i  o 

O  O  Cl  m 

C  H  Cl  U 

f=  -f>  S-  D 

O  X  O  +>  -i  O  U 

•-  a*  u  mm  o 

-♦->  c  ♦>  j=  j_  t-  o 

•-I  ■*■>  nj  h  3  oj  -*-> 

o  c  •/  cr>  u  T3  -r-> 

O  V  m  Q.  H  f=  — 

Cl  C  Q)  L  (C  3  H  X 

♦>  Oi  L  o  Ol 

«-i  ff  c-  oi  *-  at 

cj  "O  >  m  >  12 

^-<oaica>i'o^:rcc 
V  O.TJ  ffl  ffi  in  y  i»i  d 


D  — 

*i?  u  U 

Oi  (.(VC 

*0  Qi  O  X  'H 

13  >  l/l  U 

(V  ri  (_  Ol 

D  C 
>»  •“«  rtJ  U  O  •*« 

^  Ol  *►> 

0l  i-  "O  D 

J-  U  Ol  o 

iU  v  r?  T?  U 
cl  o  <*-  c  a  t 

o  3  -*»  ■*» 

S  ♦>  U  3 

3  (_  •  (.  oi  a. 

ro  o  (0  ^ 

n  v  o  x  ti  3 

ro  m  h  u  ai  o 


«  —mm 

CL  -+  \n  Cl 

ui  x  o  cm  at  u. 

a t 

.oaocxm-oxcmm 


j  c  x  x 

0X3  0 » 

X  O  ft-  %- 
0  00  VTJ 
O  V  ft  « 
O  O  O  O 


>  X  (_  N  CL^*  rH  ,u 

OCi_iCO>>-*-> 

C  -r*  — >  Q.  C  C  tfl 


in  in  u  in  cj  u 


* 

*  *  * 

• 

* 

*  # 

* 

* 

* 

* 

♦ 

*  * 

« 

* 

* 

* 

* 

* 

* 

♦ 

■ 

QC 

■* 

* 

* 

* 

o 

o 

* 

* 

B. 

* 

• 

UI 

CO 

* 

* 

CO 

UJ 

U- 

■  . 

« 

CJ 

CO 

■ 

cc 

* 

g 

CO 

a 

■ 

o 

X 

UI 

X 

CJ 

3 

* 

« 

UJ 

UJ 

CO 

o 

■ 

* 

CO 

+ 

UI 

CJ 

■* 

X 

CC 

UJ 

CO 

CO 

CO 

o 

♦ 

X 

o 

CO 

1— 

o 

♦ 

* 

»— 

«— » 

t— 

CO 

CO 

00 

* 

X 

* 

>— < 

o 

CJ 

3 

<£ 

o 

UI 

o 

* 

♦ 

cc 

QC 

* 

:> 

* 

*• 

X 

■ 

a 

QC 

— 1 

>- 

O 

00 

* 

ID 

-♦■ 

o 

o 

* 

* 

3 

-J 

UJ 

<z 

o 

* 

CM 

g 

m 

u_ 

CO 

* 

JL. 

♦ 

u_ 

<L 

at 

A 

-J 

QC 

*M 

* 

oc 

<x 

X 

UJ 

UJ 

a. 

X 

* 

CO 

X 

•* 

CO 

■* 

Cl. 

* 

— J 

►H 

CO 

iX 

— i 

o 

X 

X 

X 

—i 

CJ 

CJ 

* 

X 

<c 

X 

<r 

JQ 

0. 

fM 

<N 

*■ 

UJ 

3 

o 

y— 

* 

M 

* 

X 

QC 

X 

X 

X 

UJ 

CJ 

ui 

<x 

X 

* 

* 

* 

UI 

X 

<x 

CJ 

X 

OC 

*■ 

X 

a. 

oc 

Ui 

QC 

X 

a 

CD 

X 

<x 

O 

• 

CJ 

X 

o 

A 

A 

* 

O 

* 

•* 

X 

UJ 

UI 

u_ 

* 

CO 

o 

►— 

o 

z 

A 

X 

* 

u_ 

■* 

o 

* 

UJ 

o 

X 

z 

* 

»— « 

X 

X 

<r 

3 

♦ 

i — 

1 — 

o 

X 

* 

X 

»— 

Ui 

C_) 

* 

X 

■» 

3 

# 

<z 

*— I 

CO 

CO 

CO 

CO 

CC 

«*• 

o 

* 

•* 

CO 

u 

z 

CO 

o 

<*• 

UI 

CO 

<r 

CO 

II 

CO 

«z 

* 

o 

« 

■*■ 

C3 

X 

#■ 

-J 

o 

oc 

UI 

UJ 

<r 

X 

* 

_J 

* 

•* 

z 

«■ 

CJ 

a_ 

Ui 

oc 

CJ 

♦ 

* 

CJ 

UJ 

* 

UI 

OC 

o 

A 

UJ 

»— 

«• 

* 

OC 

CO 

CJ 

CJ 

CJ 

CO 

* 

X 

ac 

oc 

A 

►— 

X 

1— 

« 

o 

* 

* 

« 

Z 

CO 

UI 

<c 

* 

Ui 

UJ 

UI 

UI 

<r 

UJ 

* 

x 

« 

CO 

#■ 

»— 

►— 

H- 

o 

X 

CD 

*■ 

♦ 

•  B. 

■  •* 

* 

<Z 

X 

QC 

M 

CD 

u_ 

u. 

u. 

u_ 

»  •• 

•  B. 

■  B. 

* 

—1 

* 

■* 

OC 

UI 

X 

<T 

-J 

z 

<r 

<z 

<c 

o 

■* 

—1 

♦ 

UJ 

UJ 

►— « 

X 

UJ 

UI 

_J 

o 

■» 

1— » 

* 

►— 

3 

a. 

—1 

_J 

>- 

>- 

>- 

X 

* 

* 

u. 

CJ 

QC 

X 

CJ 

X 

* 

<z 

<c 

<z 

o 

»  u.  o 

*  u.  •> 

•  o  o 


<r  <r  ui  co  uj  co 

QC  »—  _l  QC  b.  4 
O  <  «  3  UJ  O 

UJ  I  a  Z  O  I-  UJ 
HOOHj-lfcfltO 


t-t  bJ  UJ  Z  (O 
►—  UI  CO  *—  M 

x  <r  cj  x 


m 

m 

z  oc  M 

-  ►—  *• 

4  CO  Z  Q 


a  x  co  x  a_  a c  •- 


«  A  M  U  « 


OC  CO  UJ 

— I  3  oc 

CJ  CJ  Ui 


o  o  o  o  o  o  o 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


(continued  on  the  top  of  page  28) 


CN 

£ 


o 

£ 

rrf 

3 


O 

-1 

-J 

X 

to 


o 

Cu 

(N 

q 

z  a 
3  o' 
3  O' 

5c? 


(O 

z_ 

© 

o 

< 


o 

< 

o 

in 


>< 

ro' 

X_ 

(N 

X 


—  tN 

N  N 

O  O 
H  H 

7  IT 

1 — i  “ i 

oS  a: 
O  O 
uu  U. 

X*S 

(N  <N 


<N 


.  on  on 


o 

^  X 
Sx 
n.h 

N 

_'Q 

N  (j 

R1 

®  f- 

>>  C/5 


L_r  CM 

PN. 
a-  — 
Z  N 


CN  _T  _- 

+  CCi 

N  5/5  M 


CN 

o 

H 


aS 

O 

u. 


O  S 
z  ^  z 
..  o  •• 
-  z  - 
s  *,  s 
o  Ci  o 
as  Z  as 
tu  a  U. 

525 

3,  «  £ 

Z  H  z 
3  oo  3 


o 

ii 

o 

O 


N  - 


UQ  N 

on  ii 
O  ~ 

"J  w 
U  N 


o 

P,  w  ki 

a  2 
z  £ 

a!  Cu 
®  1/5 

il  11 

as  cu 


uu 

2 

< 

Z 

os 

3 

o 

> 

co 

H 
o  < 


CQ 

3 

CO 

O 

O 


X 

=s 

H 

Z 

OS 

a. 


H 
Z 
uu 
Q 
3 
H 
co 

UU 
ft,  x 
3  H 

~  os  v 

^  1  O  j 

a-  >- 1  ft,  3 

«0  */»  " 

z  z  z 


<N 

A 


o 

ii 

o 

a 

oc 

O 


tg 


uq 


CO 


+ 

S 

< 

+ 

uu 

OS 

< 

H 

< 


as 

O 


Q 

OS 

o 

>" 

uu 

X 

H 

1l 

Q 
_  OS 
-  O 

i  „ 

h  Q 

£ 

3  “ 
II 

Q 


ll 

O 


ro  f 

X  ” 

w  ro 

2* 


O 

o 

r-~ 


UU  cu 

M  3  H 
wOO 

z  o 


_  OS 

Q  J3 
z  p  z 

OS  H  — 
II  O  II 

oS  o  as 


^nZ 
-  y  - 


o 

Cu 

O'  _- 

Uu  II 

— I  o 

<N  ** 

r- 


cu  cu 


04 
H 

«  S  «o  s 

00  <  P  < 

II  J  H  || 
ro  II  O  — 


3  O  X  Q  O  X 


o 

—I  o 
o>  o 
ro  cn 

00  “ 
3  2 

C/5  H 

O  O 

a  o 


CO 

Z 

+ 

q' 

< 

uu 

X 

< 

o 

p 

H 

z 

2 

cu 


o 

o 

o- 

vo 

CQ 

3 

co 

O 

O 

z 

uu 

3 

H 

o 

z 


—  ooo  ooooooooooooooooooooooo 

onrt  \oo-nn^in\OhO\0'H(NTto-nno-(NfnTt 

Q  ^  -H(N(NfN(Nr)tNMnM^nmri^T}-tTfin^in^^ 


OOOrMrr 
in  \0  Is  Is 
m  in  in  >o  in 


VOOOOOOOOO 

r'OoaNOO^fNmrt 

inm^m'sDr^r^r^r-r- 


30 

114 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


o 

H 

H 

Z 

o 

II 

> 

o 

Q 

H 

g 

o 

H 

O 

5 

Pn 

Z 

5 

O 

O  On 

< 

cu 

o 

o 

O 

o 

<N 

o 

O 

•— < 

<N 

r- 

00 

00 

00 

00 

<N 

<N 

<N 

<N 

(N 

°=  ^ 
:  O  O 
O  O  Z 

a  >  x 

■  <  £  £  £ 

3-  U,  U,  [1, 
•»  ►“*  >-^ 

II  _ 

S  1  "  " 

w  o  O  — 
£  Q  >>  >- 


z 
& 
3 
H 
UJ  j 
os 
o  Z 

§  a 

vo  3* 

z  H 

5  rO  1 

X  V 

H  < 

VZ 
o  z 

>  < 

i  _ 

r  " 

>  > 

Q  OS 

Z  o 
r  <  o 

H  o  u 

$>> 
z  a  a 


X  o  > 

*h  P  Si 

>  a  u 

O  ;  00 

^  C«  J 
'  UJ  UJ 

S  O  ° 

°  Q  ll 

J  :  o 

£  a* 

<§£ 


Q 

Z 

<  g  « 
L  £  » 


ggfc 

&-  Dh  - 


>  N-  1  O  1 

:  £<o> 
||  —  ll  o  II 

A  _  <N  ro  <N 

CA  ”.0 

^  ^  II  o  II 

u,  u.  —  ~ 

•—  i— i  ■— i  u  •— » 


z  o  —  z 
S  h  3D 
*  -  £  o. 
^  —  +  + 

£  -  *  * 
Q  06  II  II 

a  £  x  x 


o  o  o  o 

O  M  m  Tf 


M  w  m 


oooooooooooooooooooo 

i^^hO^fNnTtin'OO'-ifOO^O-HO-'fN 

—  ^  (N(S(S(N(S(N(Nn(nnTfrf^^'O\0'0 


W  >  X 
X  L> 
H  g  2 

(N  ^ 

II  o  ^ 

£  >  £ 
u.  u,  u. 


H 

II  II 

X  X 

o 

2 

X 

o 

Q  Q 

X 

5 

2  2 

i— 

i r> 

<  < 

fN 

o 

H 

H 

o  ^  ^ 

^  V  ^ 
N  o'  o" 

OS 

o 

—  (N 

aa 

Uh  Pu 

< 

X 

H 

C 

X 

H 

_  >— 1  1— H 

P  W  VO 

o 

o  o 

H 

O 

to 

UJ 

H  II  II 

-H  (N  (N 

Cu 

<N  Tj- 
^  Tj- 

Z 

O 

o 

>- 

£  ii  ii 

&  S"? 
w  o;  os 

os  -  o 

-On, 


X  X  - 
w  w  2  H 
II  H  W  X 
-  <N  W 


U  w 

5°  ?  o 

-  -  ir, 

H  H  n 

zzp 
5  2  o 
a.  a  O 


LL, 

Sm-Oo 
-  II  Z  w 

*  £  £ 'm’ 

’zH- 
.w  <  d 
>  £  1  < 

I  ^  UJ  _T 

+  - 

l  ^  §  M1  ii 

l  fe  "  2  3 


z 

uj  33 

X  W 

H  N 

o  O  o 

UJ  A  ^  H 

«  V  n  " 
<  £  H  os 

s  Z  o  o 

-■SOU, 


o  c  X  o 

L_  r/}  O  [—4 

-  A  a  So 

II  _)  u.  -j  —  II 

J  <  o  H  °  * 

OS  ^  3  x  H  OS 

O  11  H  UJ  O  O 

u.  O'  j  z  a  u. 


_ _ ooooooooo 

oooo—  fNm-rrin'or--oo 

OOOlONM(NM(N(N(S(NM 


ooooooooooooooooooooooooo 

o^Mn^mioo^n^vi'oaO’-'nhooO'O'^ro^ifl 

^■'t^f^trfTj-Tj-sovo'oovo'ovor't^t^r'r't'-cxjoooooooo 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


31 

115 


(Continued  on  the  top  of  page  30)  I  (Continued  on  next  page) 


X 

O 


O 

X 


ii 

1 — i 

on 
co 
x 
X 

+  3  D 

C  ^  a. 

H  +  + 

X  3.00  i_ 

3  ^  X'x  b 

n  »  ||  ,|  >< 

™  O  n  m  W 

£  x  x  x  z 

O  o  O  O  O 

— «  CN  m  Tf-  ly-) 

o  o  o  o  o 

\0  VO  VO  SO  VO 


b 

z 

X 

D 

O 

£ 

m 

X 

< 

>. 

z 

< 

o 

z 

"’ll 

X 

Q 

— 

X 

o 

co 

o 

z 

7  u 

£ 

~  5  * 

X 

co  -  X 

X  II  D 

X  Q  O 

X 

£ 

o 

Hfc5 
“j  =  f  o 

—  co 
X  X 

II  II 


II 


II  II  X 

q  O'  Q 

eu  —  O 
m  i  * 
X  *  o 

x  x  £ 


Os 

m 

W 

co 

w 

o 

VO 

O 

VO 

Z 

w 

X 

H 

a~ 

tL,  II 

x  o 


o  o  o  o 

vo  r-  oo  o 

o  o  o  — 

VO  vo  vo  vo 


Q  *  p 

z  5  w 

T  «  £ 

-DO 

-  CO  CO 
O  ||  2 
II  ro  II 

ox  a 


N 


o'  O 

S3 

A  x 

V  * 


X  2 
x  x 


o 

<N  (N 
• "  CN 


O' 

x 


II  II 


Z  '+ 


CN 

II 

o 

-  Q 

ii  Z 

-  2  V  < 

II  ~  O  <-» 

o  S  -  II 
'  Z  Q  ~ 
l  <  z  fe 


Q 

Q  <§! 
I  V< 
7  £  - ! 
x  o&  ! 


’T 

X 
X 

S  co  O  Z 

X  X  " 

ft.  + 


fN  o 

•n  w 

§¥ 

oo  : 

+  u 

.  CO 

X  >> 
X  < 
<  £ 


00 

?,+ 
’-x 
2  O 

oo  X 
+  X 
-  < 
x  ft. 


o  o  o  o  o 

-*  IN  fO  VI 

\0  \0  'fi  'O  \o 


II  ft! 
O  £ 

o  o 

VO  I" 


H  X  X  X  i_ 

Z  Z  Z  Z  £ 

2  2  2  2  u 

ft.  ft.  ft.  a.  z 

o  o  o  o  o 

00  On  O  ^  fN 

-  -  (N  M  H 

vo  vo  vo  vo  vo 


x 

c o 

< 

X 

< 

I 

X 

Z 

o 

o 

z 

55 

H 

>■ 

Z 

< 

Q 

Z 

to 

X 

Z 

Q 

3°' 
o  b 

U  ; 

~  x 

>  x 
ft!  X 
ft!  U 
O  < 
oo  to 
5  X 

b  ^ 

02  2 

a.  >> 


x 

co 

X 

X 

x 

Z 

O 

>• 

z 

< 

X 

Z 

5 

CL. 


Q 

X  X 
D  Z 

ft.  «-« 

z  £ 

—  ft. 


o 

o 

tj- 

X 

00 

X 

x 

ft. 

O 

X 

oo 

Z 

X 

X 

X 

o 

z 

"ll 

Q 

x 


x 

X 

D 

O 

>> 

O 

z 

55 

X 

> 

Z 

< 

X 

D 

O 

OQ 

< 

X 

z 

K 

H 

Z 

c 

u 


o  o 
co  oo 

CN  CN 
VO  VO 


O  O  O  O 
O  O  — t  CN 
CO  ^  -Vj-  Tt 

vo  VO  VO  vo 


X 

c  E 
X 

55  O 

b  5 

O  to 

z  s 

X  co 

w  b 
X  z 
X  w 
5  £ 
X 
H 
< 
H 


co 

Z 

o 


X 
co 

x  z 

x< 


O 

X 


co 
> 

X  . 

X  CO 

>  X 

a  > 

„  Z  H 

2  <  < 

X  H  x 
oo  oo  ^ 

X  X  J 
D  X  G  . 

ao  x  : 

at  Z  Q  co 

>.  X  X 
X  ft.  ' 

Z2“ 

o  E  o 


X 

X 

co 


X 

X 

oo 


X 

u 

X 

<—> 

flQ 

o 

z 

< 


co 


Q  6- 

x  5  x  x 
z  <zz 

5  S  2  5 

a.  S  a,  cu 


CO 

H 

UJ 

CO 

O 

Q 

p.. 

x 

X 

co 

< 

X 

u 

X 

m 

O 

z 

< 

co 


X 

X 

co 


X 

X 

co 


X 

U 

X 

3 

o 

z 

< 


co 

Z 

o 

X 

co 

X 

D 

a 

x 

x  e 

Q_  C.- 

C  S  CO 

co  S  H 
X  co  ft! 
ft!  < 
J  <  5  X 

X  &,  X 


c^- 
CO 
H 
Pi 

b  ^  b  w  b  x 

Uj  CO  ^  >•  ^  CO 
ft!  <  ft!  <  ft!  < 


o  o  o  o  o  o 

7T  SO  ^  ^  VO 

o  o  o  o  o  o 

o  o  o  o  o  o 


Pi 

o 


o 

a 

H 


II 

—I 

CO 

CO 

o  x 

->  X 

o  ~  z 
x  3D 

co  ^  X 
+  + 
co  co 
X  X 


II 


Z  X 


o\ 
I-,  co 

X  O 
II  II  X  X 
co  co  X  O 

X  X  z  o 


Q 

z 

x 

x 

< 

oa 

X 

X 

> 

X 

o 

X 

X 

X 

D 

X 

X 

< 

u 

X 

X 

CO 


I 

o 


II 


-  £ 


co 

co 

X 

X 

—  z; 
3d 

^  X 

+  + 

CO  CO 

X  X 
II  II 
CO  CO 

X  X 


£ 

X 

o 

■VI¬ 

OL 

CO 

O 

X 

o 

o 


o 

o 

o 

-3- 

m 
-  D 
X  £ 

II  o 

X  o 


o 

o 

o 

■vl- 

m 

D 

oo 

O 


CO 

X 

II 

X  O 


X 

X 

y 

x 

x 

< 

a. 

O 

X 

Q 

=8 

Z 

D 

O 

Z 

X 

< 

X 

D 

O 

z 

3 

x 

o 

x 

X 

CO 

X 

X 


5  z 

<  < 

"’ll  "’ll 


X  X 

X  X 
X  X 
X  X 
X  X 
X  X 


X 

X 
X 

U  II  J 

O'  O'  7 

-X  Q 
co 


>. 

z 

< 

ll 

Q 

X 

o 

X 

X 

< 

"’ll 

Q 

X  . 
o  * 

II  X 

<y  ^ 


x  x 

X  X 
X  X 
oo  oo 

X  OQ 

D  D 

CO  CO 
II  II 


OX  X  Z 


X  O 

x  “ 

CO  S 

«  O 

CO 

co  : 

II  II 

X  Q 


CO 

Z 

D 

O 

z 

x 

< 

X 

D 

X 

x 

O  CN 

H  X 

X  pa 

co  x  o 
to  rr  z 
x  O  f 
X  Z  cN 


X  : 

X  K 

s 

2 

Qt  Q 
II  X 
Q  O 


O' 

.  £  to 


N 

II 

Q 

X 

O 


O'  O'  x  SC  3  I 


x  x 


229S222002000000000°000000 

t!!t^2r^000"'(SW'Cl''00«OICOCfVIVOI^O-'NCOVtVl 

VOVOvovovOVOr-r-r-'r-'C-~t''CTvCvOv0\OvOvO\CT\OOO©O© 

COXCOCOCOCOCOcOCOCOCOCOCOCOCOCOCOCOCOCO'^-^-'^-^'^-'^- 


Z  ' 

11  Z 
X  ? 

o  A 


K 

-ZO 

+  X  z 

3  D  x 

Z  X  X 

II  X  II 

xxx 


U  x*  GO  $* 


O 

O 

cn 

o 

oo 

<N 

o' 

vo 

(N 


o 

H  : 
O  ^ 

o  V 
^  x 

Z  ii 
O  X 


oooooooooooooooo 

ovOfNm^tovor^o^fNr^Ttu-ivor^ 
O  —  i^^^fNfNfNCNfNfNfNfN 


32 

116 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


O  C/5 

< 

-  as  - 

H  H  H 

z  <  z 
52  5  2 

O.  S  Cl. 


o  o  o 

00  ON  o 

o  o  — 

o  o  o 


x  < 

£  H  O 

ST  Jr  O 

H  H  2  H  H 

5  5  U  5  S  °  o 

52  52  j  52  52  o  o 

Cl.  CU  UJ  Cl.  ft.  O  2 

o  o  o  —  o  O 

m  vn  vO  vo  O  f— i 

—  —  -  -  O  ^ 

2  2  2  2  2  § 


_  CO 

zr  ii 


CO  ^  c  s 
w  5  H  < 
C  05  [L  2 
+  3  w  ii 
XHjQ 

II  W  II  r. 

X  OS  X  = 
o  o  o  o 

00  On  O  " 
<N  <N  r^i  r>5 
■'t  ^ 


.  ~  U 

X  z  u 

£  D  Q 
n  H  W 
a  w  Q 
OS  OS  — 


<=>  ii  A 

i— >  mC 

os  oS  ns 
O  O  O 
b.  u.  u. 


§ojif 
w  I 
r  n  x  o 
"  II  wc 
a  j  z  n 


N 

N— ' 

CO 

C 

/*\ 

ftf 

CO 

< 

A 

co 

CM 

A 

on 

cJ 

X 

CO 

w 

J 

N 

X 

CO 

W 

J 

—  j 

cm" 

— 1 

ro  <n 

N  P 

°  1 
H  ~ 

z 

D 

o 

u-> 

N  5/5 

O  Q 
H  - 

O 

b. 

CO 

+ 

P 

Z 

3 

Z 

D 

o 

o 

■w-  - — ' 

N  V5 

o  A 

H  «"i 
_ _  •— » 

OOOOOOCM'^tvOooO 

r^OOOOOOOOOO 

TftniriioiDini^iAiininiAi 


W  h  h  ^  ^ 

•J  X  X  *  <* 

ZWUOO 
DZZ^fc 

O  O  Q  O 

M»  O  -h 

o  o  —  — 

m  vo  \n 


n  N  * 
11  II  w 

ajz 

Tf  NO  00 
n  m  m 


fJ  O' 

>— i  u. 

~  X  -J 
oo  H 
"NX 


■  N>  Z 

X  i— >  rs 

H  H  5 
X  X  H 


O  O  O  r-i 
»o  vO  r-  oo 


11  ii  tu  CJ  w  w  w 

OJZNZZK 

■NT  no  oo  o  o  o  o 

oo  oo  oo  on  o  — i  o 

«  «  -  -  n  m  m 

i/->  i/-)  i/->  i/->  i/->  m  i/-> 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


33 

117 


6000  !  INQUIRY  FOR  AVAIL  INFO. 


Computer  Based  Reading 


to 

X 

S 

c 

e 


3 

£ 

D 

to 


d 

uJ 


Z 

UJ 

u 


d 

D 


3 

3 

o 

z 

<r 

z 

u 

u 

d 

u 

If) 

d 

£  to 
u 


z  o 
u  u> 
a  •• 

s  3 

s  3 

3  3 
m  lh 
pa  v 

X  w 

3  in 
o  >- 
cp  in 


d 

u 


x 

F 


i 

u 

<r 

3 

o 

z 

UJ 


J— 

X 

UJ 

h- 


in 

£ 


u  > 
I  O' 


z 

Of.  UJ 


3  X 
£  UJ 
h* 
Z 

d  uj 
3  h- 
H  £ 

w  z 

Cl  •-< 
z 

UJ  £ 
0  UJ 
£  I- 


3 

O 

Cl 


U  P  • 
Z  £  • 

h  UJ  > 

■  £*  _j 

z 
UJ  o 
ffl 

UJ 

uj  o  in 
h  k  £ 
M  u 

d  h- 
3  X  d 
UJ  3 
UhQ. 
3  d 
h  d  3 
3  3 
H  UJ 

•  z  in 


d  o 

d  H 
£ 

u  ~ 
d 
P  u 
Z  W 
£ 

* 

u  u 

u  * 

£ 

CL  UJ 

in  o. 


inuDhh 
P  H  H-  H  f- 

z  z  z  z 

E  M  M  M  M 

ui  d  d  d  d 

d  CL  d  0.  d 

CD  D  IS  N  f  iD  m 

*  in  CO  CD  3  CD  CO 

*r  v  *  T  TT  *■ 


d 

3 

in 

3 

E 

O 

d 

u. 


3 

d 

Z 


H 

X 

UJ 

K 


M  UJ 

3  UJ 
3 
d  M 
O  d 
U-  P  I 

uj  *:  i 

-)  in  i 

M  M  1 

U  P 

X  u. 

in  3 

M  o 

p 

ri 

U  3 
d  K- 
O 

z 

Z  UJ 
UJ  d 
d  •• 

..  o 

*  s 

M  LD 

•  m 

■  D 
•h  cn 
H  O 
X  u> 


u 

-J 


u 

cn 

o 

-I 

u 

X 

d 

£ 

z 


O  H 
Z  X 
Y  UI 

uj  in  h 
3  m  i 
M  o  U 

d  o 
p  o  i 
H  P 
X  z 
in  H-  uj 
£  3  ,  I- 
P  d  u  3 
Z  M  d 

z  M  r 

o  Z  M 
h-  UJ 

z  x  d  p 
d  uj  ••  z 

3  H  3  £ 

►-  in  z 
u  LQ  z 
Z  I-  O  O 

kl  h  h  (J 

d  d  o 

••  3  15  d 


•  in 

•  cn 

3  3 

•  in 

• 


l  CM  Z  ♦ 
j  cn  uj  uj 
)  3  d  * 

i  in  ••  ■  i 

.  »  u  i 

w  d  » 

i  in  -  d 

_-,'X3U^ 

*-•  hi  in  in  »  m  ^ 


,  -  in 
1  o  > 


z 

UJ 


g  s  s  in  s  in  cn 
®  -•  n  n  m  cn  m 
3  in, in  in  in  in  m 


x 

UJ 


d 

UJ 

cn 

3 


d 

o 

z 


X 

u 

£ 

P 

z 

UJ 

d 


d 

o 

h- 

O  x 
z  in 

M 

UJ  P 

3 

M  E 
d  O 
p  d 


s 

CD 

UJ 

z 

UJ 

X 


8 

M 

X 

+ 

» 

d 

a 

* 


u  ..  * 

®  M  *  x 

N  ••  X  w 

•  ui  »  m  (-  u 

;  g  •  *  Z  in 

H  r-  II  Z  H  m  cr 

WOUW3UdiZ 

dlDHIddCDaiP 

Nssmssin® 

inuaininininujuj 


in 

cn 

3 
m 
z  v 

d  w 

3  in 
H  >  < 
u  in  i 

d 

®  c 

3  p  r 

m  cd  c 

in  -<  . 


3 

P 

M 

Z 

d 

H 

M 

z 

k 

Z 

H 

o 

in 

H 

3 

d 

O 

z 

K 

d 

d 

d 

X 

ffi 

3 

3 

1- 

3 

h- 

Z 

Z 

in 

3 

M 

Z 

P 

3 

d 

p 

3 

£ 

(D 

d 

£ 

d 

3 

N 

3 

•• 

d 

O 

K 

d 

h- 

Z 

N 

Z 

O 

M 

X 

cn 

3 

CD 

3 

d 

in 

s 

d 

3 

d 

M 

in 

•• 

• 

z 

•H 

P 

v 

* 

H 

d 

N 

H 

d 

* 

3 

O 

Z 

z 

in 

d 

H 

H 

M 

3 

> 

d 

3 

3 

O 

U 

d 

d 

in 

* 

M 

d 

U) 

HI 

d 

3 

3 

3 

3 

3 

3 

3 

3 

cn 

— H 

3 

3 

3 

3 

3 

cn 

3 

rn 

V 

LH 

CD 

ID 

•4 

CM 

N 

N 

N 

CM 

N 

CM 

z 

M  Z 
d  3 
d  d 

3  3 
3  -h 


©JO 

S 

*5 

3 


3 

0. 

Z 


X 

K 


P 

Z 

X 

z 


J 

UJ 

u 


z 

£ 

d 

(J 

o 

d 

d 

UJ 

z 

w 

p 

£ 

UJ 

d  in 

z 

K  l-H 

in  x 

£  _J 
U  D 
£ 
UI  U 
E  • 
m  n 


3 

m 


in 

in 

Ld 

o 

u 

£ 


in 

N  d 
H  UI 
N  H 

o  u 

..  CC 
3  d  d 

in  £  uj 

II  X  - 
3  U 

u 


1  u 

£ 
:  d 


m 

d  in 

O  N 
U  w 

•» 

in  3 

Ld  E 
3  m 
ffl  P 
£  •• 
M  « 

d  £ 
£  * 
3  II 
« 
d  U 
3  •• 


3  3  £ 
N  O 
II  P 
3  i 
H  d  _ 

..  O  E 

co  in  o 

ii  d  i 
ID  3  i 
O  U  O 

••  1  h- 

N  UJ  i 


X 

l  u 


UJ 


U  UJ 

in  ♦ 


o  E  E 
UI  UJ 
d  d 


E  Z  E  Z 
Id  UJ  UJ  Id 
d  d  d  d 


ii  cn  h 

»  ii  # 

Id  CD  3 


UIQN^VUJNCD 
•h  N  N  N  N  r-J  N  N 


d 

U 

in 

3 

P 

Z 

£ 

d 

3 

F 

UI 

in  in 

d 

uj  o 

H  H 
U  „ 

£  in 

d  uj 

£  Z 
I  m 

u5 

C8 

U 

J  H 
i  in 
d  x 

1  o  U 

in 

d  d 
3  UJ 

V§ 

UJ 

3  d 
O  « 
Z  X 

in 

3 

N  Z 


Z  d 
U  ” 
d  3 
..  ID 
.  ft) 

.  .  o 

H  B  H  Z 

•  *  o  U 

d  oa  uj  d 

IS  s  3  111 
fD  f  CD  H) 


O 

H 


in 

£ 

u 


_j 

3 


O 

in 

UJ 

P 

o 

u 

u 

o 

Id 

Z  I- 
M  d 
I-  £ 

3  H 
o  in 

d 

o  . 

> 

£ 

3 
CL 


UJ  H 
_  in  z 
in  o  m 

M  3  d 

p  u  £ 


p  i-  » 

a  3  x 

o  d  K 

d 

3  CD 
3  3  -T 
cn  *h  -h 


UJ 

3 

3 

£ 

3 

d 

id 

H 

Z 

3 

o  : 
u  < 
£ 

U  I 
Ld  < 

in 

3 

ID 

\ 


X 

UJ 


a 

z 


E 

UJ 

d 


3  3 
3  3 
CO  CD 
•h  IN 


••  Ld  w 
HUH 
K  3 
n  E  ll 
t-  U  • 
M  d  U 


u  o 


gz 

n  m 

3* 

O  d 
uj  .. 
Id  3 

d  (XI 

in  n 
o 
>-  j- 

£  O 
3  UJ 

d  • 


O 

O 

o 

£ 

o 

M 

II 

H 

H 

II 

3 

N 

HI 

CD 

P 

Z 

P 

HI 

O 

O 

*** 

3 

O 

t- 

3 

3 

X 

CD 

UJ 

m 

HI 

U 

u 

•» 

3 

d 

P 

u 

• 

HI 

u 

U 

J 

3 

3 

• 

O 

•• 

d 

M 

■ 

3 

w 

w 

£ 

w 

3 

■ 

X 

P 

o 

II 

H 

z 

u 

U 

h- 

h- 

h- 

3 

Z 

3 

HI 

HI 

HI 

3 

3 

Z 

Z 

Z 

3 

X 

U 

U 

_J 

£ 

z 

M 

M 

M 

Z 

•• 

E 

f- 

U 

u 

II 

U 

3 

H 

d 

d 

3 

U 

3 

3 

w 

M 

3 

d 

3 

d 

d 

d 

HI 

d 

0 

3 

in 

N 

3 

3 

ft) 

3 

N 

3 

3 

N 

CD 

in 

3 

N 

3 

3 

—4 

•H 

•H 

N 

fM 

N 

*H 

CM 

CM 

N 

fM 

CM 

N 

N 

3 

Z 

p 

3 

M 

d 

M 

s 

3 

g 

X 

W 

K 

If) 

d 

X 

M 

K 

z 

P 

3 

UI 

X 

d 

X 

U 

o 

h- 

£ 

3 

E 

3 

3 

o 

E 

Z 

d 

o 

w 

3 

d 

H 

3 

3 

3 

UJ 

P 

M 

z 

d 

fc 

M 

o 

z 

d 

3 

5 

M 

X 


£ 

3 

Z 

u 

d 

CD 

N 

N 

O 

H 

o 

U) 


p 

5  £ 

3 

+ 

N 
E  O 


in  u 

3 
in  w 
k  in 
u  in 
CD  Id 
u 

3  U 
O  3 
3  cn 

m  x 

3  £ 

z  u 


I  P 
Z 


^  Z  X  _ 
v  d  I-  £ 
f  3 

f“  I-  E  E 
3  3  3  3 
m  d  d  d 


m  in 

N  N 


34 

118 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


z 


Z  Id  H  Q 

Ld  J  C£  X 

U  U  CL  <S 

..  m 

>  E  I-  O 

X  Id  Z  h- 

-d  a  M  O  O 

Q.  ••  Ct  IS  U> 

x  •  a  cn  h 

. . +  W  Z. 

PHKKK-I-Mva' 

ZZZZZHmS 

E  M  M  M  M  M  II  K-K 

uaaaaai-auj 

Q'O.Q.CLQ.a.MMtt: 

SSSSNU1SSS> 

s-.NmmmviPuDP 

DQSSQiSSSiSI 

cncncncncncncncncnui 

a 


z 

□ 

I 

z 

h- 

u> 

• 

a: 

CL 

U 

<r 

U 

O 

z 

ZA 

D 

Z 

-J 

E 

w 

E 

H 

AH 

U> 

u 

M 

h* 

Cl 

si 

Z 

in 

L. 

UJ 

H 

3 

x 

za 

P 

M 

x 

r> 

UJ 

AH 

in 

z 

H 

u 

X 

ah 

in 

P 

cn 

x 

Z 

AH 

in 

or 

Ld 

s 

E 

AH 

h“ 

z 

M 

p 

p 

■ 

1- 

E 

in 

E 

a 

X 

AH 

P 

y 

■ 

□ 

O 

<r 

O 

Q_ 

Ld 

X 

u 

3 

Z 

£ 

u 

i 

Z 

in 

2 

in 

Q. 

O 

if) 

M 

U. 

in 

z 

u 

u 

AH 

• 

in 

_l 

3 

E 

> 

QC 

o 

/-s 

-i 

a. 

p 

in 

O 

0 

in 

Ld 

z 

in 

AH 

o 

> 

J 

DC 

Z 

a* 

in 

w 

L. 

li. 

>x 

<J) 

_J 

u 

M 

E 

3 

I 

* 

E 

L. 

UJ 

_i 

* 

o 

0. 

* 

in 

AH 

ii 

AH 

h 

.. 

z 

3 

u 

AH 

z 

a 

M 

X 

m 

P 

. 

, 

, 

, 

■ 

i 

t 

, 

3 

w 

u 

w 

u 

in 

X 

ii 

w 

* 

a 

W 

P 

a 

X 

a 

E 

E 

r 

E 

E 

E 

E 

E 

» 

z 

• 

z 

* 

A-» 

.j 

o 

ii 

o 

a 

a 

n 

a 

a 

a 

a 

a 

>• 

Ld 

CM 

id 

Ld 

—* 

a 

3 

M 

m 

•• 

h- 

K 

P 

—4 

u 

3 

3 

3 

3 

3 

3 

3 

3 

3 

X 

O 

ZA 

ro 

*-> 

X 

I 

o 

3 

Ld 

• 

a 

O 

IS 

(V 

w 

a 

DC 

* 

•H 

cn 

1- 

K 

H 

> 

W* 

in 

E 

i5 

X 

o 

X 

X 

CS 

IS 

N 

CD 

N 

N 

X 

X 

DC 

E 

a 

+ 

1 

* 

is 

O 

►- 

X 

3 

o 

K 

a 

* 

T 

in 

X 

X 

CM 

CD 

N 

X 

(M 

N 

X 

Ld 

M 

i- 

a 

* 

a 

♦ 

CD 

u> 

U 

a 

-J 

X 

a 

' ' 

• 

O 

in 

T 

cn 

n 

cn 

(M 

N 

N 

CM 

o 

a 

z 

o 

UJ 

UJ 

m 

in 

a 

m 

u 

1- 

p 

ii 

H 

1 

P 

Id 

+ 

15 

UJ 

* 

UJ 

* 

♦ 

« 

* 

o 

A 

X 

in 

• 

'A 

** 

O 

X 

a 

h- 

i 

1 

i 

1 

i 

l 

I 

i 

1 

p 

Z 

CD 

J 

a 

• 

p 

■ 

p 

• 

H 

in 

(\j 

u 

X 

U 

X 

A1 

id 

X 

ii 

M 

m 

o 

w 

H 

II 

AH 

|| 

o 

(7) 

a 

j 

o 

*• 

t 

U) 

a 

• 

1- 

a 

a 

•H 

CM 

cn 

X 

X 

N 

X 

X 

p 

DC 

in 

cs 

1- 

■ 

E 

m 

E 

/a 

15 

IS 

X 

a 

H 

a 

u 

a 

-H 

4* 

3 

M 

X 

H 

-H 

ii 

A) 

u 

X 

s 

in 

H 

w 

•H 

E 

* 

u) 

* 

U 

» 

2 

■ 

f 

* 

• 

■ 

■ 

• 

■ 

• 

• 

p 

in 

P 

UJ 

II 

M 

•H 

ZA 

w 

m 

M 

^H 

A 

/N 

in 

a 

il 

u 

h~ 

9* 

h- 

II 

KH 

y- 

i- 

1“ 

1- 

H 

1- 

1- 

y- 

I- 

t- 

H 

i- 

3 

•  • 

M 

E 

* 

+ 

X 

« 

+ 

o 

+ 

* 

* 

V 

w 

M 

a 

i- 

u 

Z 

• 

Z 

z 

z 

z 

Z 

z 

z 

z 

Z 

z 

Z 

3 

E 

If) 

•H 

a 

u 

a 

3 

AH 

h- 

X 

X 

3 

UJ 

in 

E 

E 

a 

cs 

in 

h- 

hH 

u 

E 

M 

*-H 

M 

M 

M 

A4 

M 

w 

n 

Ld 

O 

II 

o 

« 

Li- 

W 

u. 

II 

O 

UJ 

* 

a 

a 

> 

a 

Id 

o 

ii 

u 

c> 

>- 

a 

U 

a 

a 

U 

a 

a 

a 

a 

a 

a 

a 

a 

a 

a 

a 

z 

DC 

15 

U. 

X 

3 

AH 

A) 

U) 

z 

X 

3 

AH 

in 

a 

a 

a 

a 

«« 

if) 

a 

X 

a 

At 

a 

a 

a 

a 

a 

a 

a 

a 

a 

a 

a 

a 

M 

GO 

CD 

* 

CD 

CM 

in 

IS 

in 

CD 

s 

N 

in 

CD 

cm 

cn 

IS 

X 

(S 

N 

cn 

X 

CM 

T 

X 

(S 

N 

cn 

X 

X 

N 

ro 

cn 

X 

N 

m 

CS 

in 

CD 

s 

CJ 

-H 

~h 

rvi 

CM 

lM 

CM 

m 

m 

cn 

m- 

'T 

in 

X 

N 

r- 

N 

N 

—i 

-4 

!M 

CM 

CM 

CM 

CM 

CM 

N 

N 

N 

cn 

cn 

cn 

cn 

n- 

N 

m 

cn 

ro 

m 

cn 

cn 

cn 

m 

m 

m 

m 

m 

cn 

m 

cn 

cn 

cn 

cn 

in 

p-j 

cn 

cn 

cn 

T 

T 

■«r 

M- 

T 

M- 

■'T 

■f 

<r 

T 

Dr.  Dobb’s  Journal,  Number  53,  March  1981 


35 

119 


(Continued  on  the  top  of  page  34) 


iaQQ»Q»vma 


X, 

m  O  0 
Q  U  4 


>  OC  O 
U 

>  J  o 

3  >-<  O 

iS-u 

JHNU 


o  o  o  o  c 

o  o  o  o  c 

u  u  o  o  c 

o  o  o  o  c 

-H  -H  -H  -Hr-.  Q  c 

»NN»Q  »»NO»U»K 


Jf'Nffl  V> 


ss 


a  «n  «* 

k;  ^  “ 


J  U  H 

U  < 

mount  (i 
Q  r~  O  (N  <  «/>  ; 


HVXNOWVH/VCN 


O  u  O  o  o  Q  c 

a  u 

*  <  O  h  Q  Q  <  C 
>UNOWOU»UU(. 


»  o  o  o  o 


5HHHNU 
NNQNC 


MinHQQOiI 

.NQNUUUl 


KO<mQ9>^Q»^U«t<0DH<ma)«OO<N9i«U^U 

S00HHNnn»ifli/li«K)MS09l»i<lllSUUQQUU 

UOOOOOOOOOOOOOOOOOOOOOOOOOO 

oooooooooooooooooooooooooo 


»0<(JNCDM»< 
OOnQUUUkk 
ifl*(NNNNNNN 
HH( NNNINNNN 


uuuuuuuuu 

<<<<<<<<< 

KKKKKKEKK 

<<<<<<<<< 

>>>>>>>>> 


h  a  < 

<  a  j 
x  <  m  w 

a  o  o  o  u 


Nor 

o  in  c 


a  a  m  OH 
H  H  <  H  J  in 
O.OO.OS 

8HOHHX£Xsntn 


o 

u  » 

</>  U  3 
3  U  O  C 


X  O  fN  O  fN  C 
U  Z  O  O  O  U 


m  H 
O  J 
-too 

a  o  u 


t~)  &\  nQNUl(NUO«UNM 

•n  HHinr'inoouuuk.fc, 

OOmmufNiNfNfNfNfN 
Mr-  fS  N  (N  tNfNIN 

HIAflH 

^  »  O  -H  ^ 

OOHHUUUUUUUUU 
UUJ  JJJJJJJJ 

n  m  uumoasiaiDiiiiaa 

fN  O'  <<<<<<<<< 

U  U  MHHMHHHHH 

O  U  OSBKKBBBKK 

-  t<<<<<<<< 


r-  Q 


>>>>>>>>> 


m  n  q  u  o  o 

-HU  *  CD  1C 

-HO  H  06  u  C  H 

UooomcoBHOZ  J«1 

^  o  .  —  » . -  - 


H  U 

- - - -  30 

-’H.OO.UhHUDuB.O 
uojo<jxzozx 
mooUUOX*rZ<U>HU 

«muu 
u  u 


a»M»IONB(»U 


QhOhU 
H  O  M  O  O 
3  O  U  O  U  u 
O  O  o  O  u  a 


30000000000000 


O  ^  Q 

H«N>OOUU»<0* 
EDr-HHOOi/imQUUllfcCL 
(NlflBHOON^UNNNNINM 
mm  o  -H  OHHNNNNNN 

o  o 

fN  r- 

-H(J  -h-hUUWUUUUUU 

■♦•♦fNr'UUJJ.JJJJJJJ 
(JOCJOEQfflEQCOCOCOCQCQffi 

O  O  <4C<<<<<<< 

^  »  BBBBSBBBB 

<<<<<<<<< 
>>>>>>>>> 

<  w  n  u  r»  o 

J  U  ^  *  ri  o  h  U1 

U  Q  rH  -H 

-H  o  o  o 

o  o  a 


H  H 
Z  3  H 

_  u  o.  x 

— H  m  -«  rH  x  HZH  BHU 
UUUUHO'-'.-.O.CxaoH 
UUUW  J  J  JIU1UOU 


a  u  c 


o  o  o  o 


\\\\' 


SWSWSWNNWN 


a j 

i 

u 


-s 

cs 


U 

13 

£*43 
£ 

a 


o 

S 

« 

eS 

£ 

■ 

WD 

s 


4>  Ob  Z 
-HUM 
hQB 

am  u 
e  j  o 
o  o 


KlflIOKlA 
<  *  J  <  *  »  »  X  -  »  * 

inx— inxxxxxauaxxxax 


Q.  OH 

8  *-S 


_  _  V)  (/)  Di  JBOU)  Om  Q 

H00HQ30300<QQ3Q0QC 
*  ‘  '(hJOiJO!  JbU6i<B  JB<. 


b  J  Jb  JO.  JB.  JB.U 

3  8 

O  O  —  ~  O  j 


<0  Z  M  •• 

E  m  «  <  z 

W  W  \X  M 

. 3  ~~ 


oSi 

*  u 
OH* 
<  M  U 
X  J  H 


H  H  5. 

*  «  W 
<  <  O 
u  u  < 
J  J  H 
o  o  in 


u 
•  j 


H  H 
<  w 
H  X 


O  Z 
z  u 
•  3  X 
U>  O  W 
•  J  b  H  b  H 

EX  «  _  X  < 

•  OBUZOH 
U)  U  O  3  O  V) 
*  H  3 

O  H  3  J  Z  Z  H 

BUbUUUUl 

K»zza.&< 

U  M  H  O  O  O 

oSokooo 

z  z  z  o  z  z  z 


>  eS 

:  w 

l  H  O 

*  M  Z 
J  M 

)  in 
-  a  in 
u  u 

J  o  8 


J  H 
in  «  d 
—  u  * 


sx  j  u  • 
*2 


—  a  j 
O  H  < 
3  m 
*  O  H 


U  ffi 
•  *  < 
•  <  z 
.  Ck.  u 


H  H  Q 
u  u  z 
O  O  < 


WOO 
«  H  M  * 

J  m  H  « 
.  J  J  <  u 
w  <  H 

-  ex  w  u 
w  X  in 
u  in  3  J  h 
in  a  j  « 
O  w  <  < 

a  o  z  x 
H  O  u  o  x 
z  *  x  z  3 
m  o.  h  <  in 


—  u 
H 
H  W 
•  3  >4 
u  ex  in 
o  H 

0  3  0 
O  O  H 

*  U  H 

3  X  m 

H  X 


J  in  z 

J  Q  U 
O  Hi 
W  O  H 


swswww  wwwwwww 


•  - 


■  ■ 


a  — 


*  * 

O  H 

$  J 


a  o 

*  EX 

ex  *  o 
in  w  u 


•»  -X  ~ 

..  ~  ~  a  -  — 

- -  ~  X  ~- 

->t n  in  x  H 
H  -H I 3  B  3  - 
3  Z  *  mJWUOZ 
OhUUJUBJUB 

s  j  m  h  r<  r  s-*u  zzQinbbOwinD 
EX  EX  H  X  in  O  OOWWU<*XX*<OH 

ZZ3O<O*‘3Xin0uatU<33«*JU  - 

SSozJOOOO<OOX£XQQWHO« — • *■ 


fN  H  a  H  —  *—  —  — 

HHo  in  u  u  u  —  o 
330.EXHH  HO  — 
■  - - in  o 


36 

120 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


fa.  Ci.  Cl.  fa.  fa.  fa.  fa,  fa. 
OUCdUUUUUUU 
OQQ^QQQQQQ 
roZJEuHZZZZZZ 
CN33CJ333333 


b.  b.  k 

fa]  fa]  fa) 

a  q  q 
z  z  z 
3  3  3 


CJ 


hiUCJOUCJUUCJCJ 

XZZZZZZZZZ 
<333333333 
>  tu  b.  h  b.  ft.  b.  b.  b.  b. 


H  H  H 
u  o  u 

z  z  z 

3  3  3 
Ikb.b. 


CC  H  ex  < 

<  Z  *H  fa]  X  U  JH 
XhJJux<HZ 
06UZQ.aHHUZZ*-« 
HbUI<<HSHO 
bUfii3KI<Q8U 
>-*OOQH<Z<0.0 


QUID 

H  O  H 
3  CJ  3 
QUO 


fa.  fa-  fa.  fa.  fa.  fa.  Du  fa. 

uuucouuuuuu 

OuQQODQDDQQQ 

fNZZOZZZZZZ 

(N330333333 


fa.  bu  Du 
u  u  u 
0  0  3 

z  z  z 

3  3  3 


500000000 

►-•cjcjcjijcjcjcjcjcj 

XZZZZZZZZZ 

<333333333 

>faaOufa.Oufa.fa.fa.Duh. 


H  3  CO  Jlflh 

JOU8  UUZ 

063ZC0OO  ZZ-< 
HIU8SU  M  <  Q. 

a.ua.<«uuo  ju 
uuofauuzosiu 


fa] 

H 

x  o 

CD  Z 
fa.  < 
fa]  CJ  -1 
QUZ 


faih.fa.fa.fa.fa.Duh. 

(JOblblUUblUUU 

b.O0QQ0000Q 

CNOZZZZZZZZ 

^033333333 


fa.  fa.  Du 
fa]  fa]  fa] 
O  Q  Q 

z  z  z 

3  3  3 


►-•CJCJUCJCJCJCJCJCJ 

BZZZZZZZZZ 

<333333333 

>fa.bufa>fa.fa>h.bufa.h. 


CO  H 

CD  Q  CD  U 

H  JO  J  Z 

fa]  UUUUZ3 

HZ  Q  D.  10  J  W  Cl 

0-*<<ZQO<ZJ 

3<tflfa)3JhlOblO 

oz<xouaozo 


H  H  H 

CJ  CJ  O 

z  z  z 
3  3  3 
Du  fa.  fa. 


t-  CJ  * 
J  O  O 
uuu 

CJ  O  CJ 


'O 


fa]  kJ 
X  < 
H  * 
fa) 
O  H 
Z  ~ 
>-  3 


Z  -< 
X 
fa.  a. 


z  o 
06  u 


Z  cu 

”8 
Z  J 


§  00 
3 

hi  X 

co  < 
o.  r 


\S  NS 


—  —  a: 

^  H  fa) 

—  fa] 

■f  J  z 
+  ■ 

X  /\  • 

-1C  N 


2"-  ~ 


ft. 

o 

c 

o 

•X3 

3 

•S 

c 

$3 


—  ~  H  ' 


■ — *  f*  •• 
«->  CO 
J  H 

O.  M 


U  CJ  G 
uu  ••  - cj  ■ 


••as  3 
x  h  fa) 
a.  m 
•  H  < 
IHj 
J  H 
H  —Z 
Z  M 
-I  fa.  OS 

—  a. 


xxx 


NNIMNHNOOCONNr 


••XX  ••  mm 
x  ••  I*  "  t*  ••«••••  <  < 

HOBOA.UZBXJJ 


<(NNNNNCNNNN 


X  H  "  H  N  U  ••  «- 

H  ••  Z  t"3H  JHUUlfa]  ••  •• 
0  X  CJ  ••3Q.3XXOHHXX 


Zl  Z.  Z.  HOXOiXUZXXJJ  CO  0.  CJ  ••  3Q.3XXOHHX 

r?  Tf  r|  rj  *  ®  y  ••XHHUOZ>-<HHHH”bzXXXe-Xa)fa]OcoOH 

.  H  H  H  H  X  X  00*-**-<<<*-'JXXX>-<XXUXOZ3ZJHZ<3X 

'*  . . •  U  ••  U  •*  CJ  ••  U  Ifl  U  J  ZZJJZZJ*J*ZJC0<Zfa)fa)*-<O'-<OOUJOO 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


37 

121 


of  page 


Software  Reviews 


CLOAD  Magazine,  Inc. 

Published  by  CLOAD 
Box  1267 
Goleta,  CA  93017 
Price:  $  42/year 
Reviewed  by  John  Hatfield 

CLOAD  Magazine  is  a  monthly  of¬ 
fering  costing  $42  per  year.  Sounds  like 
a  lot  of  money  for  a  magazine,  however 
what  you  get  is  a  cassette  tape  with  4  to 
6  pre-recorded,  debugged  and  tested 
programs  for  your  level  I  or  level  II  TRS- 
80.  Not  too  shabby  for  only  $3.50  per 
cassette! 

CLOAD’s  programs  cover  a  fairly 
wide  spectrum  of  interests  from  the  latest 
way  to  do  battle  among  the  stars  to  more 
serious  programs  like  mailing  lists  to  ex¬ 
tremely  challenging  games  like  Psycho 
Logic  which  are  guaranteed  to  send  you 
to  the  funny  farm  if  you’re  not  there  al¬ 
ready  from  playing  the  latest  version  of 
Adventure.  (Anybody  figured  out  how  to 
get  by  the  Iron  Statue  yet?) 

Tape  loading  on  the  four  samples 
were  either  excellent  or  horrible.  The  two 
that  loaded  without  incident  were  fresh 
copies  direct  from  CLOAD.  The  two  that 
didn’t  load  at  all  were  opened  and  ap¬ 
parently  used  before  I  got  them. 

CLOAD’s  program  index  is  shown  on 
the  face  of  the  cassettes  along  with  the 
tape  counter  locations  for  each  of  the 
two  recordings  of  each  program. 

Along  with  the  tape  each  month 
comes  a  one-  to  three-page  blurb  from 
the  Publisher  containing  announcements, 
special  instructions  if  required  for  the 
programs  on  tape,  and  other  items  of 
interest  to  the  publisher  and  us  semi- 
serious  computernicks. 

If  you  like  a  variety  of  different  pro¬ 
grams  and  are  not  in  love  with  entering 
code  using  the  hunt  and  peck  technique 
reading  code  by  microscope,  the  CLOAD 
Magazine  should  be  on  your  list  of  things 
to  try. 


MON  3 

Published  by  Howe  Software 
14  Lexington  Road 
New  City,  NY  10956 
Price:  $39.95 

Reviewed  by  Steven  Wexler 

MON  3  is  a  powerful  monitor  de¬ 
signed  for  the  TRS-80  Lv.2  with  at  least 
16K  memory.  The  program  carries  out 
many  different  tasks;  it  is  in  effect  several 
programs  inside  of  one  program.  I  will 


38 

122 


discuss  some  of  the  more  important  func¬ 
tions  below. 

ASCII  DUMP.  This  command  dis¬ 
plays  the  contents  of  each  memory  loca¬ 
tion  in  a  specified  block  of  memory  in 
ASCII  format.  This  allows  strings  to  be 
distinguished  from  other  surrounding 
data. 

HEX  DUMP.  This  command  displays 
the  contents  of  memory  in  hexadecimal 
form. 

DISASSEMBLE.  Shows  the  symbolic 
instructions  in  Zilog  mnemonics  that  cor¬ 
respond  to  the  object  code  already  in 
memory.  Optionally,  the  disassembled 
code  can  be  dumped  to  cassette  and 
loaded  into  Radio  Shack’s  assembler! 

HEX  ARITHMETIC.  Takes  two  in¬ 
puts  and  prints  them,  their  sum,  and  their 
differences  in  both  hexadecimal  and  deci¬ 
mal  form. 

FIND  BYTE.  This  command  will 
search  a  block  of  memory  for  all  loca¬ 
tions  that  contain  a  specific  byte. 

FIND  WORD.  Searches  a  block  of 
memory  for  all  locations  that  are  the  start 
of  two  byte  numbers. 

EDIT  MEMORY.  Allows  you  to  en¬ 
ter  new  values  into  memory  in  hexadeci¬ 
mal  form. 

MOVE  BLOCK.  With  this  command, 
blocks  of  memory  may  be  moved  from 
one  area  of  memory  to  another. 

RELOCATE  OBJECT  CODE.  Using 
this  command  a  program  can  be  altered 
and  moved  to  run  in  a  different  area  of 
memory!  Not  all  programs  can  be  relocat¬ 
ed.  With  Relocate,  Mon  3  can  be  run  any¬ 
where  in  memory! 

JUMP.  Jump  transfers  control  to  any 
location.  It  is  assumed  that  a  legitimate 
program  resides  there. 

LOAD  CASSETTE.  This  command 
reads  a  tape  written  in  SYSTEM  format 
into  memory.  You  do  not  need  to  know 
what  the  file  name  is.  The  name  of  the 
tape  file  and  the  starting,  ending,  and 
entry  locations  of  the  file  are  supplied  by 
the  program. 

PUNCH  OBJECT  TAPE.  This  com¬ 
mand  will  write  onto  cassette  the  object 
code  of  a  program  in  memory. 

UNLOAD  OBJECT  PROGRAM.  Un¬ 
load  is  used  for  saving  object  programs 
that  reside  below  6C00H  onto  disk.  After 
moving  the  target  program  above  6C00H, 
a  block  transfer  routine  is  added  to  the 
target  program  so  that  when  you  run  the 
target  program,  it  is  moved  to  the  proper 
location,  and  then  executed. 

These  are  most,  but  not  all  of  the 


commands  available  in  Mon  3.  The  out¬ 
put  of  commands  may  optionally  be 
directed  to  the  line  printer. 

A  disk  based  upgrade  has  been  re¬ 
leased  called  Mon  4.  I  have  found  Mon  3 
to  be  an  extremely  useful  program 
and  can  strongly  recommend  it. 


DISK  KEYPLUS 

Published  by  SJW,  Inc. 

P.O.  Box  438 

Huntingdon  Valley,  PA  19006 
Price:  $19.95 

Reviewed  by  Marcia  Kalish 

Disk  Keyplus  is  a  very  powerful,  un¬ 
derpriced  multi-purpose  TRS-80  inte¬ 
grated  utility  package  with  excellent 
documentation  —  a  must  buy!  A  16K  cas¬ 
sette  version,  without  the  disk-based  util¬ 
ities  is  also  available  for  $14.95. 

Disk  Keyplus  is  a  powerful  collec¬ 
tion  of  Utilities  for  the  TRS-80.  32K  and 
48  K  versions  are  available  that  are  de¬ 
signed  to  run  under  either  TRSDOS  or 
NEWDOS. 

Keying  <  SHIFT-CLEAR  >  will  en¬ 
ter  Keyplus  Command  Mode.  You  may 
enter  Command  Mode  anytime  the  TRS- 
80  is  accessing  the  Keyboard. 

Once  in  Command  Mode  you  may 
enable  or  disable  specific  utilities  by 
typing  a  key. 

Disk  Keyplus  contains  the  following 
routines: 

AUTO-REPEAT.  This  utility  allows 
you  to  repeat  a  key  by  pressing  it  without 
releasing  it.  This  is  particularly  useful 
when  editing  BASIC  programs. 

AUTO  INPUT  FILE.  This  extremely 
powerful  routine  allows  you  to  define  a 
string  that  may  be  automatically  input 
three  different  ways:  at  power  up,  during 
Keyplus  initiation,  or  by  hitting  just  two 
keys. 

More  flexible  than  the  DOS  AUTO 
command,  Disk  Keyplus  may  automat¬ 
ically  execute  a  complex  combination  of 
commands  and/or  programs. 

SAVE  STATUS.  This  routine  allows 
users  to  initialize  Disk  Keyplus  with  any 
combination  of  utilities  enabled  or  dis¬ 
abled. 

LOWERCASE  VIDEO.  If  your  TRS- 
80  has  a  hardware  modification  installed 
for  lowercase  video,  this  routine  adds  the 
software  needed  to  make  it  work. 

RESTORE  LOST  BASIC  PROGRAM 
ROUTINE.  This  routine  will  restore  a 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


BASIC  program  that  has  apparently  been 
lost. 

TYPEWRITER  STYLE  KEYBOARD. 
Lowercase  alphabetic  characters  are  gene¬ 
rated  without  using  the  SHIFT  key.  Up¬ 
percase  requires  the  SHIFT  key. 

DIRECT  GRAPHIC  ENTRY.  Allows 
graphic  characters  to  be  typed  directly 
from  the  keyboard.  Three  different 
modes  are  available. 

BASIC  SHORTHAND.  Generates 
BASIC  key  words  (i.e.,  GOTO,  NEXT, 
INPUT,  etc.)  in  a  single  key  stroke.  I 
found  that  this  utility  saves  considerable 
time  when  typing  a  program. 

USER  DEFINABLE  STRINGS.  Two 
user- definable  strings,  up  to  32  characters 
long,  may  be  generated  in  a  single  key¬ 
stroke.  The  contents  of  these  strings  may 
be  changed  at  any  time. 

These  are  some  but  not  all  of  the 
routines  available  in  Disk  Keyplus. 

CONCLUSION:  I  received  my  copy 
of  Disk  Keyplus  by  first  class  mail  just 
eight  days  after  I  ordered  it.  That’s  what 
I  call  service! 

This  is  one  of  the  most  useful  pro¬ 


grams  I  own.  The  Auto  Input  Routine 
alone  is  worth  the  price.  In  short,  impres¬ 
sive  software  at  a  bargain  price. 


Editor/ Assembler  Plus  for  TRS-80 
Published  by  Microsoft 
10800  N.  E.  8th 
Bellevue,  WA  98004 
Price:  $29.95 

Reviewed  by  Ronald  L.  Nicol 

As  an  avid  assembly  language  pro¬ 
grammer,  I  have  found  the  Microsoft 
Editor/Assembler  Plus  to  be  invaluable. 
It  is  a  cassette-based,  assembly  language 
development  system  and  is  orders  of  mag¬ 
nitude  superior  to  Radio  Shack’s  Editor 
Assembler.  Prior  to  my  experience  with 
this  particular  software,  I  had  occasion  to 
use  Radio  Shack’s  Editor  Assembler  and 
Apparat’s  Disk  Editor  Assembler  and 
even  though  I  have  a  disk  system  I  much 
prefer  the  Editor/ Assembler  Plus  to  the 
others. 

The  Radio  Shack  Editor  Assembler 
is  a  subset  of  Editor/Assembler  Plus  and 


the  Editor/ Assembler  Plus  is  supplied 
with  its  own  monitor,  Z-Bug,  which  itself 
is  much  superior  to  T-Bug,  the  Radio 
Shack  monitor.  Z-Bug  and  the  Editor/ 
Assembler  Plus  can  be  co-resident.  A 
powerful  advantage  of  this  arrangement  is 
that  symbolic  debugging  is  allowed  (i.e., 
locations  in  the  in-memory  object  code 
can  be  referenced  by  Z-Bug  by  their 
labels  vice  their  absolute  memory  loca¬ 
tions).  Z-Bug  can  display  values  as  deci¬ 
mal  and  octal  as  well  as  hexadecimal.  Z- 
Bug  allows  multiple  breakpoints  and  also 
single-stepping  through  a  program.  All  in 
all  it  is  an  impressive  monitor. 

The  Editor/ Assembler  Plus  fully  sup¬ 
ports  Macro  usage  and  conditional  assem¬ 
blies.  A  useful  feature  is  the  ability  to  as¬ 
semble  in  memory  while  the  Editor  As¬ 
sembler  and  Z-Bug  are  resident.  This 
eliminates  the  need  to  dump  object  code 
to  tape  and  reload  using  a  monitor  which 
overwrites  the  assembler.  This  reduces  de¬ 
bugging  time  significantly,  but  this  attri¬ 
bute  is  not  without  its  disadvantage  be¬ 
cause,  as  always,  there  is  a  trade  off  be¬ 
tween  time  and  memory  space,  and 
having  the  Assembler/ Editor  and  Z-Bug 
co-resident  with  the  user  program  can 
lead  to  severe  program  size  constraints. 
For  example,  if  a  program  is  assembled 
using  the  automatic  origin  feature  of  the 
Assembler,  it  will  be  assembled  beginning 
at  location  71 ADH.  The  problem  of  space 
is  not  without  a  partial  solution,  however, 
through  the  use  of  the  QUASH  command 
which  allows  the  user  to  purge  Z-Bug  and 
the  Assembler.  QUASHing  just  Z-Bug 
frees  up  3.2K  bytes,  while  QUASHing 
both  frees  8. IK  bytes. 

The  Editor  portion  of  this  software  is 
extensive.  In  addition  to  standard  editing 
features,  it  allows  the  following:  collec¬ 
tive  editing  (i.e.,  editing  a  contiguous  set 
of  lines),  movement  and  copying  of 
blocks  of  lines,  a  substitute  command 
which  finds  and  replaces  a  specified 
string,  and  automatic  extend  over  a  range 
of  lines. 

Assembler  expression  evaluation  al¬ 
lows  addition,  subtraction,  multiplica¬ 
tion,  division  and  logical  operators  which 
include  Not,  Shift,  Modulo,  Equal  and 
Not  Equal  operators. 

The  software  is  supplied  with  excel¬ 
lent  documentation  and  includes  a  refer¬ 
ence  card  of  all  available  functions.  The 
Editor/ Assembler  Plus  requires  a  16K 
Level  II  TRS-80.  The  quality-to-price 
ratio  of  this  program  far  exceeds  any 
other  that  is  presently  available.  ■  ■ 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


39 

123 


DOSMOVER 
for  the  North  Star 


T 

he  standard  2000  hex  address  of 
the  North  Star  DOS  5.1DQ  is  inconven¬ 
ient  for  many  uses.  A  version  for  hex  ad¬ 
dress  0100  is  available  from  North  Star, 
but  I  wanted  a  version  for  hex  address 
F000;  to  get  it,  I  would  have  to  relocate 
the  code  of  the  N*DOS  monitor. 

In  theory,  relocation  of  an  8080  pro¬ 
gram  is  simple:  find  all  three-byte  in¬ 
structions  and  alter  their  second  and  third 
bytes  by  a  relocation  factor.  This  can  be 
made  even  simpler  if  the  relocation  fac¬ 
tor  (the  distance  the  program  is  to  move) 
is  a  multiple  of  256.  Then  only  the  third 
byte  of  the  instruction,  the  most  signifi¬ 
cant  half  of  the  address,  need  be  changed. 

In  practice,  it’s  not  so  easy.  N*DOS 
contains  ASCII  constants  —  messages, 
command  names  in  the  command  table, 
etc.  —  and  if  these  constants  were  relo¬ 
cated  as  if  they  were  instructions,  chaos 
would  result.  I  studied  N*DOS  very  care¬ 
fully  to  find  the  parts  that  should  not  be 
altered. 

I  made  a  hex  dump  of  the  program 
on  paper  —  hard  copy  is  essential  for  this 


by  Thomas  W.  Cage 


kind  of  work  —  and  also  an  ASCII  dump. 
The  ASCII  dump  revealed  the  command 
table;  the  hex  dump  of  the  command 
table  showed  the  addresses  of  the  major 
routines.  The  ASCII  dump  also  revealed 
message  constants.  With  that  information 
I  could  disassemble  the  program  (I  used 
the  XEK  disassembler).  With  some  trial 
and  testing,  this  information  allowed  me 
to  define  the  areas  of  N  *DOS  that  should 
be  relocated  in  order  to  make  it  run  at  its 
new  address.  I  wrote  DOSMOVER  in 
North  Star  BASIC.  I  will  relocate  N*DOS 
version  5.1DQ.  Run  it  as  follows: 

Load  an  unaltered  copy  of  the  stan¬ 
dard  N*DOS  5.1DQ  at  the  new  address 
that  you  want,  load  BASIC,  load  DOS¬ 
MOVER,  and  type  RUN.  The  prompt  will 
ask  for  the  starting  address  of  the  new 
version  of  DOS.  The  runtime  after  you 
type  <CR>  will  be  about  two  minutes 
and  thirty-seven  seconds.  When  the  done 
message  is  printed  out,  type  BYE.  Create 
a  disk  file  twelve  sectors  long  and  save  the 
new  version  of  N*DOS. 

The  DOSMOVER  program  assumes 
that  the  I/O  program  is  the  same  as  the 
one  in  the  North  Star  System  Software 
Manual,  page  H-l.  If  you  are  using  a  cus¬ 
tom  I/O  routine,  delete  line  330.  Change 
the  high  address  bytes  in  your  custom 
I/O  routine  with  the  monitor  program, 
then  save  the  new  N*DOS.  The  I/O  page 
is  at  sector  8  on  a  standard  disk. 


Since  I  wrote  DOSMOVER,  North 
Star  has  released  a  new  version  of  DOS, 
N’DOS  5.2DQ.  This  comes  as  a  Type  3 
File  with  a  BASIC  program  called 
MOVER.  When  MOVER  is  RUN  against 
the  FILE  -DOS,  N*DOS  5.2DQ  can  be 
located  anywhere  in  memory.  However, 
N*DOS  5.2DQ  uses  Z-80  relative  addres¬ 
sing  and  therefore  will  not  run  on  systems 
using  8080  and  8085  microprocessors. 


(LISTING  ON  PAGE  41) 


Book  Reviews 

(Continued  from  page  1 7) 

Much  of  the  writing  is  indeed  meta¬ 
phorical  -  abstractions,  remote  analogies, 
and  generalities  everywhere,  often  briefly 
touching  programming  problems.  The 
Fibonacci  sequence  (that  I  dealt  with 
concretely  in  DDJ#  51)  is  used  as  an  ex¬ 
ample  of  a  “recursively  enumerable  set,” 
and  later  analogized  with  biological 
“genotypes”  and  the  deciphering  of 
ancient  script.  Much  of  what  he  says 
about  AI  is  uncritical  or  hypothetical  — 
but  never  boring,  and  the  chapter  on  Bon- 
gard  problems  (p.  641)  was  mostly  new 
to  me.  The  fact  that  the  author  is  strad¬ 
dling  —  however  precariously  -  so  many 
diverse  fields  almost  guarantees  that, 
whoever  you  are,  some  of  the  near-800 
pages  (a  bargain  at  a  penny  a  page!)  will 
be  instructive  or  entertaining.  Each  read¬ 
er  must  search  out  for  himself  in  this 
chaos  the  passages  that  will  enlighten 
or  amuse  him.  DDJ  readers  might  mini¬ 


mize  perplexity  by  starting  with  chapter 
X,  then  XIX,  then  (having  perhaps  gotten 
used  to  the  peculiar  flickering  style)  shift 
to  random  browsing  with  a  lot  of  skip¬ 
ping,  until  they  strike  their  kind  of  gold. 
Some  may  find  the  author’s  own  “over¬ 
view”  (p.  viii-)  helpful  as  a  guide,  though 
I  did  not. 

Untamed  thinking  like  Hofstadter’s, 
when  forcibly  disciplined  by  the  writing 
of  a  program  that  a  computer  will  run, 
has  at  times  created  novel  data  structures 
and  algorithms  that  crystallize  ever  more 
complex  fragments  of  human  intelligence, 
making  possible  the  doing  of  specific 
operations  with  superhuman  speed  and 
precision.  Perhaps  they  can  only  do  this 
if  sustained  by  faith  that  anything  is  pos¬ 
sible.  The  role  of  skeptics  is  to  remind 
them  that  a  possible  thing  is  not  neces¬ 
sarily  humanly  desirable  or  what  they 
hope  and  believe  it  is.  (What  would  be  the 
long-term  effect  of  an  unbeatable  chess¬ 
playing  program?)  Hofstadter  says  (p. 


676,  speaking  of  AI)  “And  one  must  run 
on  faith  at  this  point,  for  there  is  so  far 
to  go!”  To  get  to  where ?  Had  the  alchem¬ 
ists  succeeded,  would  our  fate  have  been 
that  of  Croesus? 

It’s  a  book  of  questions  and  prob¬ 
lems,  not  answers  and  solutions,  nor  even 
many  clear  hints  on  how  to  work  any¬ 
thing  out.  It  won  the  Pulitzer  prize  not 
for  utility  but  “literary”  value  -  food  for 
thought,  glimpses  of  a  “big  picture,”  and 
what  other  reviewers  have  seen  as  an  “ex¬ 
citing”  and  “exhilarating”  quality.  One 
wonders  if  his  next  book,  in  the  style  of 
Lewis  Carroll,  won’t  be  the  Adventures 
of  Alice  in  Computerland !  With  frenzy 
subdued  into  whimsy,  and  with  greater 
insight  into  human  minds  and  their  emu¬ 
lation  by  machines,  a  fantasy  might  be  an 
effective  way  to  transmit  to  a  multifari¬ 
ous  readership  some  understanding  of 
what  computers  really  are. 


40 

124 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


REM  ***  North  Star  DOS  5. IDG  Mover 
REM  Oria.  Tom  Code  15  September  1980 

REM  ***  PUBLIC  DOMAIN  30  October  1980 
REM  *** 

REM  ttt  B=Base  Address*  Hidh  Bute  M=Memory  Address 

REM  *#*  L~Low  Address  H=Hidh  Address 

REM  ***  D=Data  at  Address  M  E=Error 

REM  ***  Runtime  about  2  minutes  37  seconds 

REM  *** 

!\  !\  !\  INPUT  'Enter  DOS  Starting  Address  In  HEX  "*M$ 

IF  LEN  <  M$  >  =4  THEN  120\  ! "Input  Error"\  »\  GOTO  100 

M=0\  FOR  1=1  TO  4\  M1=ASC(M$< I * I ) )\  GOSUB  450\  IF  E=1  THEN  EXIT  100\  NEXT  I 
REM  *** 

REM  ***  Base  Address 
B=INT (32-<8192-M>/256) 

REM  *** 

REM  ***  Modify  DOS 

FILL  B*256*B\  REM  ***  DOS  Hidh  Byte  Startind  Address  for  ROM  BOOT 
L=B*256+10\  H=B*256+42\  GOSUB  530 
M=B*256+46\  D=EXAM<M)\  FILL  M*D+B-32 

M=B*256+50\  D=EXAM(M)\  FILL  M*D+B-32\  REM  **  Hidh  Byte  Input  Buffer  Address 

L=B*256+53\  H=B*256+80\  GOSUB  530 

L=B*256+99\  H=B*256+654\  GOSUB  530 

M=B*256+169\  FILL  M*B-1 

L=B*256+663\  H=B*256+1455\  GOSUB  530 

L=B*256+1481\  H=B*256+1791\  GOSUB  530 

M=B*256+1708\  D=EXAM(M)\  FILL  M*D+B-32 

M=B*256+1713\  D=EXAM(M)\  FILL  M*D+B-32 

M=B*256+1 732\  D=EXAM(M)\  FILL  M*D+B-32 

L=B* 256+1 88 3\  H=B*256+1957\  GOSUB  530 

REM  *** 

REM  ***  Standard  I/O  Routine*  pade  H-l 
L .  =  B*256  +  2048\  H=B*256+2239\  GOSUB  530 

REM  ***  - 

L=B»25A+2304\  H=B*25&+2388\  GOSUB  530  (D2>31)  ftNr 

M=B*256+2309\  FILL  H,32  Zl0  « turn 

L=B#25A+2421\  H=B*254+2631 \  GOSUB  530  ppm  *** 

FOR  M~B*25A+2635  TO  B*256+2675\  REM  ***  Command  Table  ***  ..  ... 

D-EXAM  <  M  > \  FILL  H»D+B~32\  M=M  +  3  5“e5S5<K£ 

NEXT  M  c  T |  |  Mio  ri'iifi- 

L-=B*256+2676\  H=B*256+3063\  GOSUB  530 
M=B*25A+2702\  P=EXAM<M>\  FILL  M,P+B-32 

GOTO  880  . 


REM  *** 

REM  ***  Convert  HEX  to  Decimal  I - 

M=M*16\  E=0 

IF  ( Ml >47 )  AND  <M1<58)  OR  (Ml>63)  AND  <M1<71>  THEN  490 

•"Invalid  HEX  Character"\  !\  E=l\  GOTO  510 

IF  Ml <58  THEN  Ml=Ml-48  ELSE  Ml=Ml-55 

M=M+M1 

RETURN 

REM  *** 

REM  ***  Test  for  1*  2*  or  3  Byte  Instructions 
FOR  M=L  TO  H 
D=EXAM ( M ) 

REM  ***  18  2  Byte  Instructions 

IF  ( D=198 )  OR  ( D=206 )  OR  <D=230>  OR  (D=254)  OR  <D=219>  THEN  700 

IF  ( Ii=246 )  OR  ( D=21 1 )  OR  <D=214)  OR  <D=222>  OR  (D=238)  THEN  700 

IF  <  D  =  062 )  OR  ( D=006 )  OR  <D=014>  OR  (D=022)  OR  <D=030)  THEN  700 

IF  ( D=038 )  OR  ( D=046 )  OR  <D=054>  THEN  700 

REM  26  3  Bute  Instructions 

IF  ( D=205 )  OR  ( D=204 )  OR  (D=196)  OR  <D=244)  OR  (D=252)  THEN  720 

IF  ( D=220 >  OR  ( D=212 )  OR  (D=236>  OR  <D=228>  OR  <D=049)  THEN  720 

IF  <  D=202 )  OR  C  0=194 )  OR  <D=242)  OR  (D  =  250)  OR  (D=218)  THEN  720 

IF  ( D=210 )  OR  ( D=234 )  OR  <D=226)  THEN  720 

IF  <  D=195 )  OR  <D=017)  OR  <D=033)  OR  (D=034)  OR  <D=042>  THEN  730 

IF  ( D=050  >  OR  ( D=058 )  THEN  730 

IF  ( D=001 )  THEN  710 

GOTO  740\  REM  #**  200  1  Byte  Instructions  and  12  Null  Instructions 
M=M+1\  GOTO  740 
M=M+2\  GOTO  740 
GOSUB  820\  GOTO  740 
GOSUB  770 
NEXT  M 
RETURN 
REM  *** 

REM  ***  Test  Rande  for  Hidh  Byte 
D2=EXAM<  M+2 ) 


790 

IF  <D2>31)  AND  <P2<45>  THEN  GOSUB  820  ELSE 

M=M+2 

800 

RETURN 

BIO 

REM  *** 

820 

REM  ***  Modify  Hidh  Order  Address 

930 

D2=EXAM  <  M+2 ) 

840 

FILL  M  +  2  *  D2+B-32 

850 

M=M+2 

860 

RETURN 

870 

REM  *** 

880 

REM  ***  End  of  Prodram 

990 

!\  !\  !\  !"Finished"\  ! "Save  DOS  on  Disk"\ 

!  \  !  \  ! 

900 

END 

Dr.  Dobb’s  Journal,  Number  53,  March  1981 


41 


Video  Underline 
Modification 


O  rainy  day  I  had  finished  my 
semi-annual  look,  feel,  and  wiggle  inspec¬ 
tion  of  all  the  cards,  wiring,  plugs  and 
cabling  in  my  Altair  8800B.  The  system 
diagnostic  program  verified  that  the  cas¬ 
sette  system  was  tuned  and  working  fine, 
and  all  memory  had  passed  the  exhaustive 
pattern  sensitivity  test.  I  was  looking  at 
the  video  display  and  trying  to  remember 
any  ideas  for  minor  hardware  or  software 
changes  that  had  occurred  to  me,  when 
my  thoughts  turned  to  the  joys  and  pains 
of  screen  text  editors. 

The  little  beast  used  on  the  video  dis¬ 
play  to  indicate  a  control  location  is  well 
named  a  cursor.  The  aggravation  of  trying 
to  guess  where  a  blinking  cursor  will  ap¬ 
pear  can  give  unwanted  frustration  to 
text  entry.  My  cursor  on  the  video  dis¬ 
play  is  the  inverted  video  for  any  or  all 
characters  on  display,  and  usually  only 
one  cursor  is  allowed  on  the  display  at 
any  instant.  I  wondered  if  using  an  under¬ 
line  would  look  better  and  ease  some 
operator  strain.  The  more  1  considered 
using  underline  instead  of  total  video  in¬ 
version  of  a  single  character,  the  more  the 
idea  appealed  to  me.  The  next  step  was 
to  find  out  how  difficult  changing  the 
video  inversion  to  an  underline  would  be 
on  my  VDM-1  card  (from  Processor 
Technology). 

Examination  of  the  character- 
generation  process  in  the  VDM-1  manual 
led  to  a  clear  definition  of  what  would 
have  to  be  done  to  give  the  underline  ef¬ 
fect.  The  ninth  row  of  dots  (figure  one) 
of  the  character  would  be  inverted  if  D7 
(the  eighth  bit  of  the  ASCII  character 
being  formed)  was  high.  Armed  with  this 
specification,  an  examination  of  the 
VDM-1  schematic  led  me  to  believe  that 
a  few  cut-and-bypass  changes,  and  the 
addition  of  an  IC  to  decode  the  ninth  row 
of  dots,  would  allow  this  improvement. 

The  schematic  of  the  modification 
was  drawn  with  a  checklist  of  cut-and- 
bypass  changes,  to  insure  that  every 
change  was  done  correctly.  The  actual 
layout  was  considered  and  a  good  site  was 
chosen  for  the  additional  IC  to  be  placed 
(Continued  on  page  49) 

by  Dannie  E.  Davis 

Dannie  E.  Davis,  101st  MI  Bn,  Ft.  Riley, 

KS  66442. 


Figure  1. 

Dot  matrix  of  character  “y”. 

Row  0 

o 

O 

o 

o 

O 

o 

o 

o 

Row  1 

o 

O 

o 

o 

O 

o 

o 

o 

Row  2 

o 

O 

o 

o 

O 

o 

o 

o 

Row  3 

o 

O 

o 

o 

O 

o 

o 

o 

Row  4 

o 

• 

o 

o 

O 

o 

• 

o 

Row  5 

o 

• 

o 

o 

O 

o 

• 

o 

Row  6 

o 

• 

o 

o 

O 

o 

• 

o 

Row  7 

o 

o 

• 

• 

• 

• 

o 

o 

Row  8 

o 

o 

o 

o 

o 

o 

o 

o 

Row  9 

o 

o 

o 

o 

o 

o 

• 

O  - Underline  Row 

Row  10 

o 

o 

• 

o 

o 

o 

• 

o 

Row  1 1 

o 

o 

o 

• 

• 

• 

o 

o 

o 

« 

fO 

V) 

o 

f* 

c 

I 

3 

c 

6 

3 

e 

E 

3 

c 

E 

3 

c 

E 

3 

c 

E 

3 

e 

£ 

3 

c 

E 

3 

0 

u 

o 

u 

0 

u 

0 

u 

0 

u 

0 

u 

0 

u 

0 

u 

42 

126 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 


TRS-80  Voice  Synthesizer 
on  Other  Microcomputers 


Abstract 

The  TRS-80  Synthesizer  compares 
favorably  in  price  ($399),  quality  of 
speech,  and  ease  of  use  with  other  synthe¬ 
sizers.  Sales  and  service  for  the  synthesiz¬ 
er  are  widely  available  and  software  for  it 
is  beginning  to  appear.  The  main  draw¬ 
back  to  date  has  been  the  fact  that  it 
could  only  be  used  with  TRS-80  comput¬ 
ers.  This  article  will  show  how  to  inter¬ 
face  the  synthesizer  to  the  S-  ICO  bus  and 
to  the  Exidy  Sorcerer  bus,  and  also  will 
describe  general  principles  applicable  to 
interfacing  the  syntheiszer  to  any  micro¬ 
computer.  (All  the  computers  we  have 
used  to  date  have  clocks  that  run  at  ap¬ 
proximately  2  megahertz.  There  may  be 
timing  problems  in  using  our  circuitry  on 
other  computers.)  The  interface  requires 
only  wires  and  connectors;  the  total  cost 
should  be  from  zero  to  thirty  dollars  de¬ 
pending  upon  what  is  available  in  your 
scrap  box.  The  only  labor  required  is 
soldering  three  dozen  connections. 

The  TRS-80  Voice  Synthesizer 

The  TRS-80  Voice  Synthesizer  is  a 
small  gray  box.  To  operate  it  with  a 
TRS-80,  all  one  has  to  do  is  to  plug 
the  synthesizer’s  connecting  cable  into 
the  computer  and  its  power  supply  into 
an  electric  socket.  Then  the  synthesizer 
will  say  whatever  is  sent  to  it  in  special 
codes.  (For  instance,  if  the  computer 
sends  it  the  string  “H;U;RY(UU”  it  will 
say  “How  are  you.”)  Software  is  adver¬ 
tised  in  computer  magazines  by  Supersoft 
which  automatically  turns  ordinary  Eng¬ 
lish  into  these  special  codes.  The  quality 
of  the  synthesizer’s  speech  is  close  to  that 
of  synthesizers  costing  ten  times  as  much. 
After  a  few  hours  of  listening,  the  average 
user  can  understand  it  fairly  well. 

How  the  TRS-80  Synthesizer 
Interfaces  to  the  TRS-80 

The  first  step  in  interfacing  the  TRS- 
80  synthesizer  to  your  computer  is  to 
understand  how  Radio  Shack  interfaced 
it  to  the  TRS-80.  Radio  Shack  wanted  to 
make  it  easy  for  anyone  who  knew 
BASIC  to  run  the  synthesizer.  Therefore 
they  designed  the  synthesizer  so  that  any¬ 
thing  written  by  a  BASIC  program  on  the 
bottom  right  corner  of  the  screen  would 
be  received  by  the  synthesizer. 


by  Michael  Hightower 
and  Peter  B.  Maggs 


FIGURE  1 

TRS-80  SYNTHESIZER  CONNECTIONS  TO  THE  EXIDY  SORCERER 


TRS-80 

Signal 

Name 


TRS-80 
Synthesizer 
Connector* 
Pin  No. 


Connection 
to  be 
made 


SORCERER 

Bus 

Pin  No. 


SORCERER 

Bus 

Signal 

Name 


A5 

A6 

A7 

A8 

A9 

A10 

All 

A12 

A13 

A14 

A15 

WR 

DO 

D1 

D2 

D3 

D4 

D5 


GND 


SYSRES 


34 

40 


-29 

AO 

-32 

A1 

-31 

A2 

-34 

A3 

-33 

A4 

-36 

A5 

-35 

A6 

- 18 

IORQ 

-20 

WR 

-37 

DO 

-40 

D1 

-39 

D2 

-42 

D3 

-41 

D4 

-44 

D5 

4 

Data  Bus 

Enable 

49 

GROUND 

50 

GROUND 

2 

RESET  Ol 

•WARNING  —  Synthesizer  connector  pin  numbers  are  not  the  same 
as  pin  numbers  on  the  connector  on  the  TRS-80  keyboard  unit. 


46 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 

127 


If  you  had  a  Level  II  TRS-80,  the 
first  step  would  be  to  clear  out  the  syn¬ 
thesizer  with  the  following  BASIC  state¬ 
ment: 

PRINT@  992,“?-?” 

Since  the  location  992  is  in  the  lower 
right  comer  of  the  TRS-80  screen,  this 
statement  would  send  the  characters  “?”, 
and  “?”  to  the  synthesizer  in  that 
order.  The  question  mark  is  a  signal  to 
the  synthesizer  to  turn  on  if  it  is  off  and 
to  turn  off  if  it  is  on.  (In  Radio  Shack  ter¬ 
minology  the  first  question  mark  “opens 
the  window”  and  the  second  question 


mark  “closes  the  window.”  The  dash  sig¬ 
nals  the  synthesizer  to  be  silent.) 

Then  the  synthesizer  may  be  made  to 
speak.  For  instance  on  a  TRS-80  the  fol¬ 
lowing  BASIC  program  would  cause  the 
synthesizer  to  say  “one,  two,  three.” 

10  PRINT@  992,“?  W877NN  ?” 

20  PRINT@  992,“?  T((UU  ?” 

30  PRINT@  992,“?  ==R.&  ?” 

The  synthesizer  has  a  thirty- character 
buffer.  In  programming,  one  must  take 
care  not  to  get  too  far  ahead  in  sending 
its  words  or  the  buffer  will  overflow  and 
the  synthesizer  will  stop  speaking. 


How  does  the  synthesizer  know  that 
something  is  written  in  the  bottom  right 
comer  of  the  screen?  In  the  TRS-80  com¬ 
puter,  the  video  screen  displays  whatever 
is  in  memory  locations  3C00H  through 
3FFFH  (15360  decimal  through  16383 
decimal).  Anything  in  the  last  thirty- two 
locations  may  be  a  signal  to  the  synthe¬ 
sizer.  The  synthesizer  is  attached  to  the 
TRS-80  bus.  It  decodes  bus  address  sig¬ 
nals  to  determine  if  a  location  between 
3FE0H  and  3FFFH  is  being  addressed. 
This  will  be  so  whenever  address  lines 
A 14  and  A15  are  low  and  address  lines 
A5,  A6,  A7,  A8,  A9,  A10,  All,  A12 
and  A13  are  high.  Then,  when  the  Radio 
Shack  Memory  Write  Strobe  Output  Sig¬ 
nal  goes  low,  the  synthesizer  accepts  the 
data  present  on  lines  DO,  Dl,  D2,  D3,  D4 
and  D5. 

Interfacing  the  Synthesizer  to 
Other  Computers 

The  secret  of  interfacing  the  synthe¬ 
sizer  to  other  computers  is  to  find  the 
lines  on  its  bus  which  correspond  to  the 
lines  on  the  Radio  Shack  bus  used  by  the 
synthesizer.  In  our  interfacing,  we  have 
chosen  to  use  port  rather  than  memory- 
mapped  output,  because  the  memory  of 
our  computers  was  entirely  dedicated  to 
other  purposes;  however,  it  would  be 
quite  simple  to  adapt  our  circuit  diagrams 
and  programs  for  memory-mapped  out¬ 
put. 

The  only  parts  needed  for  each  of 
the  computers  we  have  interfaced  it  with 
to  date  (SOL,  North  Star  running  at  2 
megahertz,  Vector  Graphic,  Exidy  Sorcer¬ 
er),  are  one  connector  to  fit  the  computer 
bus  and  one  connector  to  fit  the  synthe¬ 
sizer  connector.  For  the  S-100  bus,  any 
sort  of  100-pin  male  S-100  connector  or 
blank  S- 100  board  will  do.  These  are  sold 
by  almost  all  computer  stores  and  by 
many  mail  order  companies.  For  the 
Sorcerer  bus,  a  connecting  cable  is  avail¬ 
able  from  Exidy  dealers.  We  were  unable 
to  find  a  ready-made  male  connector  to 
fit  in  the  female  connector  on  the  Radio 
Shack  synthesizer  cable;  you  may  have 
better  luck.  If  you  do  not,  buy  a  blank 
circuit  board  with  one-tenth  inch  spacing 
between  connectors  and  at  least  20  con¬ 
nectors  on  each  side  of  the  board,  and 
then  cut  it  to  fit  exactly  in  the  synthesiz¬ 
er  connector.  Essentially,  the  idea  is  to 
duplicate  the  male  edge  connector  that 
protrudes  from  the  left  rear  of  the  TRS- 
80  keyboard  unit.  We  do  not  recommend 


FIGURE  2 

TRS-80  SYNTHESIZER  CONNECTIONS  TO  S-100  BUS 


TRS-80 

Signal 

Name 

A5 

A6 

A7 

A8 

A9 

A10 

All 

A12 

A13 

A14 

A15 

WR 

DO 

Dl 

D2 

D3 

D4 

D5 

GND 


SYSRES 


TRS-80 
Synthesizer 
Connector* 
Pin  No. 


Connection 
to  be 
made 


5- 
4- 

6- 
29- 

23- 
38- 

31- 

35- 

36- 

32- 

33- 

27- 

12- 

20- 

10- 

16- 

24- 
14- 

34- 


40- 


S-100 

S-100 

Bus 

Bus 

Signal 

Pin  No. 

Name 

-  45 

SOUT 

-  84 

A8 

-  34 

A9 

-  37 

A10 

-  87 

All 

-  33 

A12 

-  85 

A13 

-  86 

A14 

-  32 

A15 

-  77 

PWR 

-  36 

DO 

-  35 

Dl 

-  88 

D2 

-  89 

D3 

-  38 

D4 

-  39 

D5 

—  100 

GND 

_  50 

—  99 

POC 

•WARNING  -  Synthesizer  connector  pin  numbers  are  not  the  same 
as  pin  numbers  on  the  connector  on  the  TRS-80  keyboard  unit. 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 
128 


47 


I4AM4. 


the  alternative  of  cutting  the  connector 
off  the  synthesizer  and  soldering  the 
wires  straight  to  the  S- 100  connector. 
This  will  void  your  warranty  and  make  it 
impossible  to  test  your  synthesizer  on 
Radio  Shack  equipment. 

The  next  step  is  to  connect  the  two 
connectors  as  shown  in  Figure  2  for  the 
S-100,  or  in  Figure  1  for  the  Sorcerer 
bus.  Check  your  wiring  and  soldering 
carefully,  since  most  microcomputer 
buses  have  power  and  ground  pins  located 
close  to  one  another;  connecting  them  to¬ 
gether  could  be  fatal  to  your  computer. 

Once  the  adapter  cable  has  been 
made,  all  you  have  to  do  is  plug  in  the 
synthesizer  and  you  are  ready  to  make  it 
talk.  To  do  this,  you  will  need  some  soft¬ 
ware.  Typical  BASIC  and  assembly  lan¬ 
guage  software  is  shown  in  Figures  3  and 
4.  Using  this  software  requires  an  under¬ 
standing  of  the  system  of  phonetic  codes 
explained  in  the  TRS-80  Synthesizer 
manual.  One  of  the  authors  has  written 
more  elaborate  software  that  translates 
ordinary  English  into  the  needed  pho¬ 
netic  codes  and  automatically  buffers 
output  to  avoid  getting  ahead  of  the  syn¬ 
thesizer.  This  software  is  available  from 
Supersoft,  Box  1628,  Champaign,  IL 
61820.  ■■ 


Figure  3 


PAGE  01 
A/ VOICE 
0001 
0002 


*  8080  PROGRAM  FOR  TRS-80 

*  VOICE  SYNTHESIZER 


0003 

* 

0004 

ORG 

256 

0005 

PORT 

EQU 

63 

;  OUTPUT  PORT  (3FH) 

0006  0100  212401 

LXI 

H,INIT 

;  INITIALIZE 

0007  0103  CD0F01 

CALL 

TALK 

0008  0106  212601 

LXI 

H,MSG 

;  SEND  MESSAGE 

0009  0109  CD0F01 

CALL 

TALK 

0010  010C  C30C01 

WAIT 

JMP 

WAIT 

; RESET  TO  ESCAPE 

0011 

• 

0012  010F  3E3F 

TALK 

MVI 

A,63 

;  CODE  TO  OPEN  WINDOW 

0013  0111  D33F 

OUT 

PORT 

0014  0113  7E 

TLOOP 

MOV 

A,M 

0015  0114  FEFF 

CPI 

255 

;  TEST  FOR  END 

0016  0116  CA1F01 

JZ 

TDONE 

0017  0119  D33F 

OUT 

PORT 

;  SEND  OUT  PHONEME 

0018  01  IB  23 

INX 

H 

;  POINT  TO  NEXT  ONE 

0019  01 1C  C31301 

JMP 

TLOOP 

0020  01  IF  3E3F 

TDONE 

MVI 

A,  63 

;  CODE  TO  CLOSE  WIN¬ 

DOW 

0021  0121  D33F 

OUT 

PORT 

0022  0123  C9 

0023 

* 

RET 

0024  0124  2D 

INIT 

DB 

45 

;  CODE  TO  CLEAR  SYN¬ 

THESIZER 

0025  0125  FF 

0026 

• 

DB 

255 

;  END  OF  MESSAGE 

0027  0126  14 

MSG 

DB 

20 

;  CODE  FOR  T 

0028  0127  33 

DB 

51 

;  CODE  FOR  E 

0029  0128  13 

DB 

19 

;  CODE  FOR  S 

0030  0129  14 

DB 

20 

;  CODE  FOR  T 

0031  012A20 

DB 

32 

;  CODE  FOR  PAUSE 

0032  01 2B  FF 

DB 

255 

************************* 


48 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 

129 


Figure  4 


100  REM  BASIC  PROGRAM  TO  USE  THE 
110  REM  TRS-80  VOICE  SYNTHESIZER 
120  REM  WRITTEN  IN  NORTH  STAR  BASIC 
130  DIM  S$(25) 

140  REM  INITIALIZE  SYNTHESIZER 
150  LET  S$=“-” 

160  GOSUB  260 

170  REM  NOW  SAY  STRINGS  THAT  ARE  TYPED  IN 
180  PRINT  “TYPE  IN  PHONETIC  CODES” 

190  INPUT  S$ 

200  GOSUB  240 

210  REM  LOOP  BACK  FOR  MORE 
220  GOTO  190 
230  REM 

240  REM  SUBROUTINE  TO  SEND  OUT  PHONETIC  CODES 
250  REM  START  WITH  ?  TO  OPEN  WINDOW 
260  OUT  63,ASC(“?”) 

270  REM  NOW  SEND  OUT  STRING  CHARACTER  BY  CHARACTER 
280  FOR  N=1  TO  LEN(S$) 

290  CHECK  YOUR  BASIC  MANUAL  FOR  SUBSTRING  NOTATION 
300  REM  OUTPUT  PORT  63  DECIMAL  IS  3F  HEXADECIMAL 
310  OUT  63,ASC(S$(N,N)) 

320  NEXT  N 

330  REM  NOW  A  PAUSE  FOR  SILENCE 
340  OUT  63,ASC(“  ”) 

350  REM  NOW  A  ?  TO  CLOSE  WINDOW 
360  OUT  63,ASC(“?”) 

370  RETURN 

READY 

RUN 

TYPE  IN  PHONETIC  CODES 
7H38L80U 
?H;U;RY(UU 
? 

STOP  IN  LINE  190 
READY 


M, 


X  ▼  A  ichael  Hightower  received  the 
B.  S.  and  M.  S.  degrees  in  electrical 
engineering  from  the  University  of 
Illinois.  He  is  Research  Engineer  at  the 
Computer-Based  Education  Research 
Library  at  the  University  of  Illinois  in 
Urbana,  Illinois.  He  joined  the  staff  in 
1975,  participating  in  the  design  of  the 
PLATO  V  terminal  and  resident  oper¬ 
ating  system.  Recently  he  has  been 
involved  in  the  design  of  a  low  cost 
PLATO  terminal  using  a  color  CRT 
display  and  automated  microcomput¬ 
er  system  diagnostic  equipment. 

Peter  B.  Maggs  majored  in  math¬ 
ematics  and  foreign  languages  at 
Harvard  College  and  received  a  law 
degree  from  Harvard  Law  School.  He 
is  currently  Professor  of  Law  at  the 
University  of  Illinois  in  Champaign, 
Illinois.  He  has  been  active  in  comput¬ 
er  applications  in  the  law  and  in  the 
development  of  talking  computer 
hardware  and  software  for  blind  and 
speech  handicapped  users.  Talking 
computer  terminals  of  his  design 
have  been  in  use  by  blind  lawyers  in 
the  United  States  Department  of 
Justice  since  1978. 


Video  Underline  Modification 

( Continued  from  page  42) 

ing  was  modified  to  produce  underline  in¬ 
stead  of  character  video  inversion  (figure 
two). 

After  carefully  inspecting  the  fin¬ 
ished  modification,  I  was  pleasantly  sur¬ 
prised  when  the  system  operated  perfect¬ 
ly  on  the  first  try.  Full  diagnostic  testing 
found  that  any  resident  gremlins  were  on 
vacation. 

I  am  very  pleased  by  the  change  in 
the  video  appearance  and  find  new  ways 
to  use  the  underline  on  the  display.  My 
favorite  use  is  a  fill -in -the -blank  line  for 
menu  or  local  entries.  This  permits  com¬ 
plex,  static,  interactive  page  entry,  and  is 
a  welcome  relief  from  the  occasional 
nausea  of  scrolling  text  displays.  This 
small  hardware  change  has  a  large  effect 
on  the  operation  of  my  system. 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 
130 


49 


Of  Interest 


by  Dave  Cortesi 


O..  of  the  perks  of  working 
around  an  editorial  office  is  that  we 
get  to  read  a  lot  of  press  releases.  We 
learn  of  all  the  latest  and  (the  press  re¬ 
leases  claim)  greatest  things.  By  read¬ 
ing  between  the  lines  we  get  hints  of 
what’s  going  on  in  the  trade.  Some¬ 
times  we  compare  the  PR  fluff  in  the 
releases  to  the  real  information  -  in¬ 
dustry  word  of  mouth,  the  infallible 
source  —  and  thereby  get  a  lot  of 
laughs. 

Starting  this  month  we’re  going  to 
experiment  with  the  “Of  Interest” 
section.  Instead  of  excerpting  from  the 
press  releases  with  only  minor  editing, 
we’re  going  to  comment  more  freely, 
juxtapose,  and  rewrite.  Let  us  know 
how  we’re  doing,  won’t  you? 


Get  Rich  Quick  -  Become  a 
Software  Vendor  . . . 

Texas  Instruments  took  a  lot  of 
knocks  for  not  providing  applications 
software  for  their  99/4  Home  Computer. 
The  company  got  the  point,  and  is  re¬ 
sponding  vigorously.  According  to  the 
first  of  a  flurry  of  releases,  TI  “recognizes 
that  the  company  cannot  produce  all  the 
software  required  for  all  the  applications 
for  which  the  TI-99/4  is  well  suited.”  As 
a  result,  “TI  offers  software  development 
systems  for  sale  to  . . .  software  authors 
who  want  to  develop  Solid  State  Soft¬ 
ware  command  modules.” 

The  new  99/4  development  system 
includes  an  extra  32K  of  RAM  (for  a 
total  of  48K),  two  disk  drives  and  their 
controller,  an  assembly  language  module, 
and  two  new  languages.  One  of  these  is 
the  UCSD  Pascal  system  from  Softech! 
The  other  is  TI  Extended  BASIC,  with  a 
number  of  graphics  statements  and  the 
ability  to  write  true  subroutines  with 
their  own  local  variables. 

If  you  would  like  to  become  a  third- 
party  software  vendor  for  the  TI-99/4 
(and  that  appears  to  be  the  only  way  to 
get  the  development  system,  at  least  for 
now),  call  TI.  If  you  live  in  Texas,  call 
800-692-4979;  if  you’re  unfortunate 
enough  to  live  outside  the  Lone  Star 
State  call  800-858-4565. 


. . .  Then  Get  Your  Name  in  a 
Dictionary . . . 

An  organization  called  The  American 
Microcomputer  Association  (POB  1266, 
Glen  Bumie,  Maryland  21061)  is  compfl¬ 
ing  a  directory  of  microcomputer  consul¬ 
tants.  Write  to  them,  they’ll  list  you  in  it 
for  $10.  They  promise  to  send  you  a  veri¬ 
fication  printout  before  publication,  and 
plan  to  place  their  directory  in  “Libraries, 
Computer  Stores,  and  other  key  loca¬ 
tions.” 

. .  .  And  Publish  a  Scholarly  Article 

The  erstwhile  Journal  of  Design 
Automation  and  Fault  Tolerant  Comput¬ 
ing  has  decked  itself  out  with  a  new  title. 
It  is  now  the  Journal  of  Digital  Systems, 
and  has  expanded  its  areas  of  interest  to 
include  computer  architecture,  perfor¬ 
mance  evaluation,  and  the  like.  The  first 
issue  has  handsome  typography  and  looks 
like  a  worthy  spot  to  place  your  thesis  — 
but  if  you  want  appreciative  readers, 
think  of  DDJ. 

Buy  an  ADA  Manual . . . 

That  music  you  hear  in  the  distance 
is  the  ADA  bandwagon.  Pony  Express 
Services  (100  West  57th  St.,  NY,  NY 
10019)  wants  to  help  you  jump  on  it. 
They’ll  sell  you  a  manual  for  the  Depart¬ 
ment  of  Defense’s  new  standard  language 
for  just  $100,  and  then  keep  it  up  to  date 
for  you.  “ADA  is  certain  to  become  the 
most-used  computer  language  in  the 
world,”  they  burble  happily.  DDJ  wel¬ 
comes  comments  on  that  statement,  and 
on  ADA  in  general. 

...  or  One  on  FORTH 

If  that’s  too  high  a  leap,  even  for  a 
very  fancy  bandwagon,  then  a  $20  step 
will  get  you  onto  the  FORTH  pogo  stick. 
Send  it  to  the  Mitchell  E.  Timin  Engineer¬ 
ing  Co.  at  9575  Genesee  Ave.,  Suite  E-2, 
San  Diego,  CA  92121,  and  they’ll  send 
you  a  67 -page  manual  on  Timin  FORTH, 
“an  enhancement  to  FIG- FORTH  for 
CP/M.”  That’s  29.8  cents/page,  which 
raised  our  eyebrows,  but  then  FORTH 
is  a  very  concise  language. 

Talk  to  a  Publisher’s  Computer 

Note  another  entry  in  your  little 
black  book  of  CBB  phone  numbers. 
McGraw-Hill  Book  Company  has  initiat¬ 
ed  a  computer  bulletin  board.  It  operates 


from  6  pm  to  8  am  EST  Monday  to 
Thursday,  and  6  pm  Friday  to  8  am  Mon¬ 
day.  Call  it  on  212-997-2186  and  have  it 
tell  you  about  McGraw-Hill’s  titles.  They 
use  an  Apple  II  and  the  ABBS  software 
from  Peripherals  Unlimited. 


Buy  a  Bunch  of  CP/M  Software 

Lifeboat  Associates  (1651  Third 
Ave.,  NY,  NY  10028)  announces  the 
availability  of  RAID,  a  new  software 
debugging  tool  for  the  8080/8085  under 
CP/M.  We  have  to  fault  the  publicist  who 
wrote  the  release,  which  sketches  a 
number  of  the  program’s  features  but  fails 
to  make  clear  exactly  wherein  RAID  is  an 
improvement  on  good  old  SID.  There 
must  be  such  points,  for  at  $250  RAID 
costs  twice  as  much.  The  manual  should 
make  it  clear,  at  $25.  DDJ  would  like  to 
see  articles  on  debuggers,  especially 
comparative  reviews  of  two  or  more  of 
them. 

Computer  Control  Systems  (298  21st 
Terrace  S.E.,  Largo,  FL  33541)  have  pro¬ 
duced  Ultrasort  II,  a  machine-language 
sort  program  that  can  be  used  alone  or  as 
a  subroutine  of  CBASIC.  This  sort  uses  an 
interesting  tehcnique  to  acquire  working 
storage  space;  it  rolls  out  the  whole 
Transient  Program  Area  to  disk,  uses  all 
the  spqce  to  do  the  sort,  then  rolls  the 
calling  program  back  in  again.  Wonder 
how  it  does  on  very  short  files? 

Supersoft  (POB  1628,  40  Main  Street 
Suite  402,  Champaign,  IL  61820)  has  en¬ 
hanced  its  CP/M  diagnostic  package.  Each 
of  the  test  components  can  be  run  from  a 
submit  file  -  an  excellent  move,  in  our 
opinion  —  and  will  write  its  report  to  a 
disk  file,  so  presumably  an  entire  check¬ 
out  session  could  be  automated  into  one 
submit  command.  DDJ  will  be  printing 
articles  on  diagnostic  programs  in  upcom¬ 
ing  issues,  and  we  wouldn’t  mind  seeing 
more,  including  reviews  of  packages  like 
this  one. 

The  same  company  announces  C 
compilers  for  the  8080  and  the  Z8000. 
The  compiler  is  really  one  program,  writ¬ 
ten  in  C,  compiling  itself  three  different 
ways.  It  is  a  two-pass  program,  claiming 
to  optimize  for  both  space  and  speed  (a 
claim  we  beg  leave  to  doubt,  but  then 
compiler  optimization  techniques  are  not 
normally  the  province  of  the  authors  of 
press  releases).  The  CP/M  version,  pro¬ 
ducing  8080  object  code,  is  priced  at 
$175.  A  CP/M  version  cross-compiling 
to  Z8000  code  is  $500,  as  is  the  Z8000- 


50 


Dr.  Dobb’i  Journal,  Number  53,  March  1981 

131 


coded  compiler.  The  DDJ  Editor  would 
be  in  seventh  heaven  if  someone  who  real¬ 
ly  understood  compiler  technology  would 
write  a  thorough,  comparative  review  of 
the  C  compilers  available  for  the  8080. 

Digital  Research  hasn’t  been  sitting 
on  its  byte,  either.  They’ve  come  up  with 
a  new  access  method  for  CP/M.  Well, 
they  call  it  a  “record  retrieval  system,” 
but  an  access  method  is  what  it  is,  and 
not  a  bad  one  to  judge  from  the  fairly 
sketchy  information  in  the  release.  BT- 
80  (with  a  little  TM  just  above  and  to  the 
right,  please)  maintains  a  balanced  beta- 
tree  index  or  indices  to  a  collection  of 
records.  The  data  can  be  spread  across  as 
many  as  8  Hies  to  reach  a  maximum  of 
64MB  —  not  too  shabby  for  a  microcom¬ 
puter.  Records  can  be  inserted,  deleted, 
and  retrieved  by  key  through  as  many  as 
4  indices  concurrently,  or  scanned  in  key 
or  reverse-key  sequence.  The  PL/I-80 
runtime  library  package  is  a  pre-req;  it 
and  BT-80  together  will  cost  you  $300. 
Write  to  POB  579,  Pacific  Grove,  CA 
93950  or  call  408-649-3896. 

Learn  to  Make  Circuit  Boards  . . . 

Those  who  want  to  work  on  the  lead¬ 
ing  edge  of  home  computing  must  be 
ready  to  make  their  own  parts.  Heathkit 
has  added  a  course  to  their  line  of  self- 
teach  courses  that  may  help  prepare  you. 
El -3 1 34  is  a  course  in  the  construction  of 
printed  circuit  boards.  Besides  the  text, 
the  course  package  contains  all  the  com¬ 
ponents  of  two  of  Heath’s  simpler  kits  ex¬ 
cept  for  the  PCB’s,  a  stroke  of  motiva¬ 
tional  genius.  Just  complete  the  course, 
creating  the  missing  boards  as  lab  exer¬ 
cises.  Price  is  $65 ;  package  available  only 
in  the  continental  USA;  catalog  from 
Heath,  Dept  350-550,  Benton  Harbor, 
MI  49022. 


. . .  Connect  Them  With  Impossible 
Cable 

Given  the  present  concern  over  noise 
emission  it  had  to  happen,  but  it  still 
looks  topologically  impossible.  Belden 
Corp.  has  introduced  twisted-pair  ribbon 
cables.  They  call  it  Vari-Twist,  and  it’s 
a  flat  cable  composed  of  tiny  twisted 
pairs  of  conductors.  Adjacent  pairs  have 
opposing  twists;  periodically  the  whole 
thing  flattens  out  to  look  like  ribbon 
cable  for  an  inch  or  so,  then  the  pairs 
twist  up  again.  How  do  they  do  it?  Ask 
the  Manager,  Marketing  Communications, 


Belden  Corp.,  2000  S.  Batavia  Ave., 
Geneva  IL  60134.  If  you  solve  a  sticky 
RFI  problem,  with  Vari-Twist  or  with¬ 
out,  write  about  it  for  DDJ. 


Vari-Twist:  a  solution  to  the  RFI  problem? 

Control  64  Voltages  at  Once 

An  intriguing  S-100  board  has  been 
announced  by  an  outfit  called  Digital 
Multi-Media  Control  (2338  Patterson 
#12,  Eugene,  OR  97405,  503-342- 
3181).  This  single  board  contains  64 
digital -to -analog  (D/A)  converters.  Sixty- 
four  channels  on  a  single  board?  They  do 
it  by  multiplexing  one  very  hard-working 
8 -bit  D/A  converter  across  64  latches. 
All  64  channels  are  memory-mapped  to 
a  single  256-byte  page  of  address  space. 
The  makers  suggest  you  could  control  64 
AC  motors,  or  drive  64  lights  in  a  disco. 
They  note  that  a  channel  is  just  $8.25, 
for  a  board  price  of  $514  (check  it; 
there’s  some  quantization  error  in  those 
numbers). 


Talk  a  Little  Faster 

If  you  don’t  mind  being  non¬ 
standard,  a  new  acoustic  modem  from 
Anderson  Jacobson  will  let  you  commu¬ 
nicate  at  450  bits  per  second,  50%  faster 
than  the  usual  300  bps  (which  it  also  sup¬ 
ports).  The  AJ  347  is  crystal-controlled, 
works  in  originate  or  answer  mode,  and 
will  auto-answer.  It  costs  $365;  just  ask 
at  521  Charcot  Ave.,  San  Jose,  CA. 


Get  an  LSI- 1 1  for  Less 

This  is  an  older  item;  some  of  you 
may  already  have  heard.  Digital  Equip¬ 


ment  Corp.  has  entry-level  versions  of 
their  LSI-11/2  and  11/23  products,  and 
has  reduced  prices  on  all  of  those  ma¬ 
chines.  For  example,  an  LSI-11/23  with 
32KB  and  two  serial  lines  is  now  priced  at 
$2900;  an  LSI- 11/2  with  64KB  and  two 
serial  lines  has  been  reduced  20%  to 
$2100.  DEC  didn’t  note  whether  those 
prices  got  you  a  case,  or  a  power  supply, 
or  other  details,  but  if  you’ve  been  anx¬ 
ious  to  get  into  16-bit  machinery  these 
might  repay  investigation.  They  didn’t 
give  us  an  address  for  more  information, 
but  a  DEC  salesman  shouldn’t  be  too 
hard  to  find. 


Go  to  a  Conference;  Present  a  Paper 

The  5th  International  Conference  on 
Software  Engineering  will  be  held  March 
9-12,  1981  at  the  Town  and  Country 
Hotel,  San  Diego.  A  highlight  of  the  con¬ 
ference  will  be  a  Software  Tool  Fair  fea¬ 
turing  demonstrations  of  software  tools 
and  development  systems.  Write  (quickly) 
to  Ray  Houghton,  National  Bureau  of 
Standards,  Technology  Building,  Room 
A265,  Washington,  DC  20234. 

Did  we  pass  that  one  on  too  late? 
You  can  still  make  The  Cincinnati  Busi- 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 

132 


51 


The  Electric 
Phone  Book 


ness  Show  at  the  Cincinnati  Convention- 
Exposition  Center,  March  31  to  April  2. 
The  latest  in  office  equipment  and  ser¬ 
vices,  and  a  program  of  business  seminars 
will  be  presented.  Contact  Ray  Nemo, 
Show  Manager,  5679  Creek  Road,  Cin¬ 
cinnati,  OH  45242,  513-531-5959. 

Educators,  and  authors  of  course¬ 
ware,  might  like  to  check  out  AEDS  ’81, 
the  19th  annual  convention  of  the  Associ¬ 
ation  for  Educational  Data  Systems.  It 
happens  May  5-8  in  Minneapolis.  Contact 
AEDS  1981  Convention  Registration, 
1201  16th  Street  NW,  Washington,  DC 
20036. 

If  you  plan  it  right  you  can  follow 
that  with  Microcomputers  in  Education, 
the  first  annual  conference  of  CUE, 
Computer- Using  Educators.  That’ll  be 
held  May  15-16  in  Bloomington,  Califor¬ 
nia  (where?).  This  is  a  newer,  possibly 
looser  organization  than  AEDS.  If  you 
want  to  speak  or  display  to  the  group, 
call  Craig  Walker,  Conference  Director, 
at  714-886-9118.  To  pre-register,  write 
Forest  Miller,  Co-ordinator  of  Math  Sci¬ 
ence,  San  Bernardino  County  Schools, 
602  S.  Tippecanoe,  San  Bernardino,  CA 
92415. 

A  whole  week  of  artificial  intelligence 
talks  might  be  purgatory  for  some  of  us, 
but  if  it’s  heaven  for  you,  you  can  get  it 
at  the  1981  International  Joint  Confer¬ 
ence  on  Artificial  Intelligence,  August  24- 
28.  The  deadline  for  papers  has  passed, 
but  you  can  get  attendance  details  from 
Louis  G.  Robinson,  American  Association 
for  Artificial  Intelligence,  Stanford  Uni¬ 
versity,  Box  3036,  Stanford,  CA  94305. 

If  you  have  something  to  say  about 
programming  productivity  (and  what  pro¬ 
grammer  doesn’t?)  you  might  consider 
saying  it  to  the  IEEE  Computer  Society 
at  their  Fall  1981  conference.  “Produc¬ 
tivity  —  an  Urgent  Priority”  will  be  the 
topic,  and  Dr.  Harlan  Mills  will  be  general 
chairman.  Submit  your  paper  in  four  cop¬ 
ies  to  one  of  the  program  chairmen,  Drs. 
Raymond  T.  Yeh  and  Victor  R.  Basili, 
University  of  Maryland,  Department  of 
Computer  Science,  College  Park,  MD 
20742.  If  you  would  rather  just  listen, 
write  to  COMPCON  FALL  ’81,  POB  639, 
Silver  spring,  MD  2090 1 .  ■  ■ 


A 

i.  A.  computerized  bulletin  board 
works  just  like  an  ordinary  bulletin 
board  system  except  that  instead  of 
paper  and  thumbtacks  it  uses  a  termi¬ 
nal,  a  computer,  and  the  dial-up  tele¬ 
phone  network. 

The  list  below  was  developed 
from  several  sources  including  the  Peri¬ 
pheral  People  in  Mercer  Island,  Wash¬ 
ington,  and  the  People’s  Message  Sys¬ 
tem  in  Santee,  California.  It  is  being 
maintained  by  People’s  Computer 
Company’s  PCNET  project,  our  effort 
to  bring  computers  and  telecommuni¬ 
cations  into  the  hands  of  everyone. 
While  this  is  the  most  complete  listing 


we  have  as  of  this  writing,  we  would 
appreciate  additions  and  corrections. 
Send  them  to  PCNET,  PCC,  P.O.  Box 
E,  Menlo  Park,  CA  94025. 

All  the  bulletin  board  systems  list¬ 
ed  here  can  be  accessed  by  telephone 
using  a  300-baud  ASCII  terminal  and 
a  Bell  103  modem.  Most  use  carriage- 
return  as  a  speed  recognition  charac¬ 
ter,  after  which  they  are  self- teaching. 
All  are  free  to  anyone  who  calls,  un¬ 
like  Arpanet,  which  is  restricted,  and 
The  Source  and  MicroNet,  which  cost 
money.  The  list  has  been  sorted  by 
area  code;  consult  your  local  tele¬ 
phone  directory  for  geographical  cor¬ 
respondence.  (Also  printed  in  Recrea¬ 
tional  Computing,  March/ April  1981). 


(201)  283-2724 

(201) 457-0893 
(201)  688-7117 
(201)  753-1225 
(201)  753-8152 
(201)  835-7228 
(201)  843-4563 
(201)  874-6833 
(201)  891-7441 

(201)  968-1074 

(202)  337-4694 

(202)  635-5730 

(203)  348-6353 

(203)  357-1920 
(203)  746-4644 

(205)  945-1489 

(206)  244-5438 
(206)  246-8983 
(206)  482-5134 
(206)  482-5590 
(206)  524-0203 
(206)  546-6239 
(206)  723-3282 
(206)  937-0444 
(209)  638-6392 
(212)  245-4363 
(212)  448-6576 
(212)  787-5520 

(212)  997-2186 

(213)  276-4276 
(213)  316-5706 
(213)  329-3715 
(213)  340-0135 
(213)  346-1849 
(213)  349-5728 
(213) 360-6332 
(213)  394-1505 
(213)  395-1592 
(213)  396-3905 
(213)  424-3506 
(213)  428-4718 
(213)  459-3177 
(213)  459-6400 
(213)  566-8035 
(213)  631-3186 
(213)  657-8803 


213) 

673 

2206 

213) 

675 

8803 

213) 

709 

5423 

213) 

795 

3788 

213) 

787 

4004 

213) 

799 

1632 

213) 

799 

6514 

213) 

826 

0325 

213) 

828 

3400 

213) 

843 

5390 

214) 

288 

4859 

214) 

634 

2668 

214) 

634 

2775 

214) 

641 

8759 

216) 

644 

1965 

216) 

754 

7855 

301) 

344 

9156 

303) 

759 

2625 

303) 

789 

0936 

305) 

261 

3639 

305) 

566 

0805 

305) 

689 

3234 

305) 

772 

4444 

305) 

821 

7401 

305) 

989 

9647 

309) 

688 

0470 

309) 

694 

6531 

312) 

255 

6489 

312) 

269 

8083 

312) 

337 

6631 

312) 

420 

7995 

312) 

622 

8802 

312) 

528 

7141 

312) 

545 

8086 

312) 

622 

9609 

312) 

767 

0202 

312) 

782 

8180 

312) 

782 

9751 

312) 

941 

9009 

312) 

964 

7768 

313) 

288 

0335 

313) 

357 

1422 

313) 

465 

9531 

313) 

477 

4471 

313) 

484 

0732 

313) 

569 

2063 

(313)  588-7054 

(314)  838-7784 
(316) 746-2078 
(319) 353-6528 
(319) 557-9618 
(404)  394-4220 
(404) 733-3461 
(404)  790-8614 
(404)  793-1045 
(404)939-1520 
(404) 939-8429 

(404)  953-0723 

(405)  353-2554 
(405) 528-8009 
1408) 241-1956 
(408) 296-5799 
(408)  263-0248 
1408) 263-9650 

1414)  241-5406 

(414)  241-8364 

(414)  282-8118 

1415)  348-2139 

(415)  348-2396 
1415)  493-7691 
(415)  527-0400 
1415)  647-9524 
(415)  661-0705 
(415)  683-4703 
(415)  792-8406 
1415)  851-3453 
(415)  948-1474 
1417)  862-7852 
(419)  865-1584 
(502)  245-8288 
(502)  896-9624 
1503)  646-5510 

(512)  657-0779 

(513)  671-2753 
(513)  874-2283 

(515)  279-8863 

(516)  938-9043 
(523)  223-3672 
(602)  866-0258 
1602)  956-5612 
(602)  957-4428 


6021 

957-9282 

604) 

687-2640 

607) 

754-5571 

607) 

797-6416 

609) 

983-5970 

612) 

561-6311 

612) 

929-8966 

614) 

272-2759 

614) 

649-7097 

615) 

254-9193 

617) 

354-4682 

617) 

388-5125 

617) 

431-1699 

617) 

649-7097 

617) 

692-3973 

617) 

864-3819 

617) 

897-0346 

617) 

963-8310 

702) 

826-7234 

702) 

873-9491 

703) 

281-2125 

703) 

281 -2222 

703) 

379-0303 

703) 

620-4990 

703) 

734-1387 

703) 

750-0930 

703) 

893-9474 

703) 

978-7561 

707) 

448-9055 

713) 

233-7943 

713) 

693-8080 

713) 

977-7019 

714) 

449-5689 

714) 

463-0461 

714) 

495-6458 

714) 

526-3687 

714) 

537-7913 

714) 

565-0961 

714) 

571-5550 

714) 

582-9557 

714) 

730-1206 

714) 

739-0711 

714) 

751-1422 

714) 

772-8868 

714) 

898-1984 

(714)  952-2110 
(714)  962-7979 
(714)  963-7222 
(801)375-7000 
1801)  466-1737 

(801)  753-6800 

(802)  748-9089 

(802)  879-4981 

(803)  270-5372 
(803)  270-5392 
(803)  279-5392 
1803)  771-0922 

(803)  772-1592 

(804)  340-5246 
805) 484-9904 

(805)  527-9321 
(805)  682-7876 

(805) 964-4115 

(806)  355-5610 
813) 223-7688 

816)  523-9121 
(816)  531-1050 
(816) 861-7040 

(816)  931-3135 

(817)  855-3916 
(817)  855-3918 

817)  923-0009 
(901)  276-8196 
(901)  362-2222 

(901 )  761  -4743 

(902)  794-8198 
904) 243-1257 
(904)  243-8565 
(913)  362-6398 
(913)  764-1520 
913)  782-5115 
(915)  584-5393 
916) 393-4459 
(918)  224-5347 


52 


Dr.  Dobb’s  Journal,  Number  53,  March  1981 

133 


:  c  t  * 


$2.50  ($3.00  In  Canada) 


Dr.  Dobb  s  Journal  of 

COMPUTER  Calisthenics  6  Orthodontia 

FOR  USERS  OF  SMALL  COMPUTER  SYSTEMS 

Number  54  April  1981  Volume  6.  Issue  4 


Z-80  Floppy  Disk  Test 

Ray  Duncan 

Polynomial  Evaluation  in  BASIC 

R.A.  Hoffman 

MINCE  —  Not  Just  Another  Editor 

Barry  A.  Dobyns 

A  SLIC  Label  Program 

Robert  Hal  lent 

Important  Features  of  the  PCNET  Protocol 

David  C.  Harris 


. . .  and  more  inside ! 


P.O.  Box  E 
Menlo  Park 
CA  94025 


Dr.  Dobb's  Journal  of 

COMPUTER  Calisthenics  6  Orthodontia 


Volume  6,  Issue  4 
Number  54 
April  1981 


Contents 


Articles 


Departments 


Z- 80  Floppy  Disk  Test .  8 

by  Ray  Duncan 

Polynomial  Evaluation  in  BASIC . 14 

by  R.  A.  Hoffman 

Algorithms  in  FORTH . 16 

by  S.  B.  Bassett 

A  SLIC  Label  Program .  17 

by  Robert  Hallem 

A  Cassette  I/O  Routine  for  BASIC  Arrays . 18 

by  Ame  Rohde 

Important  Features  of  the  PCNET  Protocol  ....  47 
by  David  C.  Harris 

MINCE:  Not  Just  Another  Editor . 48 

by  Barry  A.  Dobyns 


©  1981  by  People’s  Computer  Company  unless  otherwise 
noted  on  specific  articles.  All  rights  reserved. 


Letters .  4 

Of  Interest . 42 

Electric  Phone  Book . 44 

Software  Review . 48 

Club  News . 52 


Publisher 

Ann  Merchberger 
Associate  Publisher 
Michael  Madaj 
Editor 

Marlin  Ouverson 
Contributing  Editors 
Dave  Caulkins 
Dave  Cortesi 


Art  Director 
Clifford  West 
Artist 

Barbara  Ruzgerian 
Typesetter 
Renny  Wiggins 
Proofreader 
Nancy  Heubach 


Marketing  Director 
Craig  S.  Harper 
Advertising  Director 
Michael  Madaj 
Circulation  Manager 
Peter  Clark 
Circulation  Assistant 
Leah  Dansby 


Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per  year 
by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real,  Menlo 
Park,  CA  9402S.  Second  class  postage  paid  at  Menlo  Park, 
California  94025  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  94025. 

Subscription  Rates  &  Writer’s  Guidelines  on  page  15. 


Editorial 


Whenever  we  get  much  response  to  a  particular  issue  of 
DDJ,  we  feel  good.  It  shows  what  we  are  doing  is  significant, 
and  that  our  readers  recognize  that  fact. 

The  response  to  recent  articles  on  FORTH  ( DDJ  #51 
and  #52)  has  been  gratifying.  There  have  been  both  positive 
and  negative  comments,  all  indicating  much  interest  in  the 
FORTH  language.  From  what  I  hear  about  the  efforts  of 
“FORTHians”  (FORTHites?  FORTHists?)  to  organize  them¬ 
selves  and  to  promote  their  language,  we  will  be  hearing  more 
from  them  in  the  future. 

The  other  day,  Doc  Dobb  poked  his  head  into  my  office. 

“What’s  the  FORTH  Interest  Group  had  to  say  about 
Hal  Gordon’s  articles?”  he  asked. 

I  stammered  a  couple  of  things  under  my  breath. 

“Well,  speak  up!”  His  blue  eyes  flashed.  Never  can  get 
away  with  much  when  Doc’s  around. 

“The  FIG  folks  don’t  seem  real  thrilled  ...”  I  under¬ 
stated. 

“Figures,”  he  snorted.  “Everything’s  got  to  be  just  so  to 
please  them  FORTH  people.  I  suppose  they’re  still  com¬ 
plainin’  about  the  garbage  on  that  stack,  too.” 

“Uh-huh,”  I  admitted. 


“Well,  there’s  only  one  thing  to  do!”  he  cried  gleefully. 
“Let  them  tell  it  the  way  they  think  it  should  be.” 

“We  are  printing  a  few  of  their  letters  to  the  editor  — ” 

“Not  good  enough.  Give  ’em  a  whole  issue.” 

In  a  twinkling  the  door  slammed  shut  and  I  heard  Doc’s 
footsteps  head  down  the  hall  in  search  of  another  sail  to 
trim. 

Anyone  who  knows  Doc  realizes  that  it’s  no  use  arguing 
with  him  even  if  you  want  to,  which  I  don’t.  So,  FORTH 
fans  and  foes,  here  is  your  chance  to  grab  pens  and  proces¬ 
sors,  paper  and  postage.  Later  this  year,  DDJ  will  publish  an 
issue  dedicated  to  FORTH.  We  don’t  expect  every  reader  or 
group  to  agree  with  everything  we  publish;  but  like  Doc  is 
fond  of  saying,  if  it’s  grist  for  the  mill,  we’ll  grind  it. 


Marlin  Ouverson 
Editor 


136 


Letters 


Back  and  FORTH 

To  the  Editor: 

H.  T.  Gordon’s  “What  FORTH  Is?” 
article  is  a  truly  amazing  document.  It 
could  only  have  been  written  by  an  ex¬ 
pert  on  microprocessor  instruction  sets 
who  has  admittedly  “never  used  an  as¬ 
sembler.”  I  get  the  feeling  that  we  are 
hearing  a  weird  echo  of  the  point  of  view 
of  those  who  argued  (circa  1959)  that 
payrolls  should  continue  to  be  written  in 
machine  language. 

Reasoning  by  analogy  of  FORTH 
command  word  to  CPU  opcode,  Gordon 
observes  that  the  information  density  of 
an  opcode  (bit  by  bit)  is  high,  while  the 
character  by  character  information  of  a 
FORTH  word  is  (sometimes)  low,  and 
concludes  that  something  is  going  to 
waste.  This  is  not  so  much  a  useful  insight 
as  it  is  an  example  of  the  danger  of 
reasoning  by  analogy.  FORTH  words  are 
not  opcodes.  In  particular,  the  “English- 
semantic”  content  of  FORTH  command 
words  (like  DROP)  is  critical  to  what 
little  readability  FORTH  has,  and  the 
information  density  of  a  FORTH  word  is 
of  no  use  to  FORTH,  while  the  bit  by  bit 
information  density  of  an  opcode  is  of 
very  much  use  to  its  CPU,  and  the  opcode 
mnemonic  makes  little  difference  to  as¬ 
sembler  program  readability. 

Changing  the  FORTH  word  DROP 
into  such  gobbledygook  as  ?SXY  would 
be  questionable  practice  even  if  done  for 
a  good  reason.  Proposing  such  a  thing  for 
the  purpose  of  rendering  a  change  to  the 
9th  place  “down”  in  the  FORTH  variable 
stack  is  simply  incomprehensible  to  me. 
What  purpose  could  be  served  by  turning 
the  stack  into  a  kind  of  bastard  RAM? 
And  of  course  the  code  servicing  all  this 
new  complexity  is  to  be  built  into  the 
FORTH  kernel,  so  that  in  short  order 
bringing  up  FORTH  on  a  new  machine 
would  be  as  much  work  as  building  a  new 
COBOL  compiler. 

Admittedly  FORTH’S  all  encompass¬ 
ing  stack  discipline,  extending  even  to  re¬ 
quiring  0  or  1  on  TOS  to  control  branch¬ 
ing,  must  seem  terribly  rigid  and  confin¬ 
ing  to  one  accustomed  to  working  direct¬ 
ly  with  a  machine’s  instruction  set,  with 
many .  instructions  and  a  complex  status 
register  dedicated  to  branching.  Things 
are  not,  however,  always  what  they  seem. 
Some  things  buy  simplicity  and  don’t 
confine  much. 

Confronted  with  all  the  power  and 
freedom  ( and  the  complexity)  of  an  as¬ 


sembly  language,  a  very  good  programmer 
responds  by  producing  20  lines  of  de¬ 
bugged  code  per  day,  an  average  one 
makes  10.  Given  an  interpretive  HLL 
with  nice  extensions,  a  mediocre  pro¬ 
grammer  does  around  40  loc/day.  Given 
the  goal  of  solving  some  real  problem  for 
a  user  with  real  economic  constraints,  one 
might  be  forgiven  for  sacrificing  some 
power  in  return  for  some  simplicity. 

[Parenthetically,  Gordon’s  explana¬ 
tion  of  FORTH,  before  he  embarked  on 
questionable  extensions,  was  possibly  the 
best  I’ve  ever  read. . . .] 

David  Carew 

2925  Sage  St.  No.  4 

Colorado  Springs,  CO  80907 


Dear  Dr.  Dobb’s, 

Thinking  about  “What  FORTH  Is?” 
( DDJ  51  by  H.  T.  Gordon)  I  think  that 
one  of  the  reasons  why  FORTH  programs 
are  said  to  be  “cryptic”  is  the  stinginess 
of  your  typesetter  (and  BYTE  ones  too) 
in  using  blanks.  Furthermore,  it’s  consid¬ 
ered  good  programming  style  among 
FORTH  programmers  to  use  indentation. 
So,  FIBO  may  look  like 
:  FIBO  (  —  N1  N2  ) 

0  1 

11  1  DO  CR  DUP  .  SWAP  OVER  + 
LOOP  ; 

the  comment  in  the  “(“  ,  ”)”  showing  the 
effect  of  FIBO  on  the  stack. 

And  thinking  about  “good”  FORTH: 
I’d  rather  do  it  this  way 
:  FIBO  (  —  ) 

0  1 

10  0  DO  CR  DUP  .  SWAP  OVER  + 
LOOP 

DROP  DROP  ; 

Sincerely, 

Klaus  Schleisiek 
126  Sussex  St. 

Jersey  City,  NJ  07302 


ZDM  Note 

Dear  Mr.  Ouverson, 

I  am  writing  to  thank  both  DDJ  and 
your  reviewer,  Mr.  Gene  Head,  for  the 
positive  review  of  our  software  package, 
ZDM,  which  was  published  in  your 
February  1981  issue. 

I  would  also  like  to  point  out  that 
the  “very  small  bug”  referred  to  in  the 
review  was  corrected  before  any  packages 
were  released  for  sale.  Our  customers, 
therefore,  need  not  be  concerned. 


Thank  you  again  for  devoting  space 
to  this  review. 

Sincerely, 

R.  F.  Doolittle 
RD  SOFTWARE 
1290  Monument  St. 

Pacific  Palisades,  CA  90272 

Atmospheric  Perturbation? 

Dear  Sir, 

I  am  delighted  to  learn  from  his  arti¬ 
cle  in  Dr.  Dobb’s  Journal  that  Mr.  John 
B.  Palmer  derives  “pleasure  and  satisfac¬ 
tion”  when  he  relaxes  of  an  evening 
hidden  away  with  his  Sinclair  ZX80  com¬ 
puter.  I  mean  that  seriously,  as  I  am  tired 
of  reading  stupidly  derogatory  articles 
about  an  excellent,  inexpensive,  dedicat¬ 
ed  mini- machine. 

I  am  sorry,  however,  to  read  again 
(and  again  and  again)  about  certain  al¬ 
leged  deficiencies  which  do  not,  in  fact, 
detract  from  the  excellent  qualities  and 
capabilities  of  the  ZX80.  To  build  a  com¬ 
plete  computer  for  less  than  $200  is  quite 
an  engineering  feat  in  itself. 

In  the  first  place  I  should  like  to  dis¬ 
pel  all  past  and  future  nonsense  about  the 
size  of  the  keyboard.  If  Mr.  Palmer  saw  a 
ZX80  before  purchasing  one,  or  if  he  saw 
any  Sinclair  Research  advertising,  it  is  ob¬ 
vious  that  the  entire  machine  is  6-1/2” 
x  8-1/2”  overall,  keyboard  included.  If 
that  is  too  small  for  Mr.  Palmer,  then  he’d 
best  stay  with  his  Apple  II  and  not  leap  in 
where  angels  fear  to  tread.  One  can  hard¬ 
ly  expect  to  find  a  6”  x  1 6”  keyboard  on 
a  machine  dimensioned  as  above,  not  to 
mention  a  $50  keyboard  in  a  $200  ma¬ 
chine.  So  his  grading  of  “2,  weak”  is  real¬ 
ly  not  germane  to  the  subject. 

As  to  Mr.  Palmer’s  apparent  lack  of 
video  quality,  I  have  had  no  difficulties 
whatsoever  in  this  respect,  and  I  imagine 
Mr.  Palmer’s  problem  is  due  entirely  to  a 
“lowcost”  third-rate  “black-and-white” 
television  set.  Low-cost  TV’s  are  apt  to 
be  of  the  “hot  chassis”  variety  and  this 
could  easily  account  for  spurious  radia¬ 
tion  pickup  from  power  lines.  As  to  the 
power  output  of  the  modulator  unit,  I  am 
familiar  with  this  device;  it  outputs  at 
least  one  volt  peak-to-peak,  which  is 
more  than  adequate  to  drive  anything  ex¬ 
cept  possibly  a  1902  crystal  set.  As  to 
altering  the  bandwidth  of  the  output  to 
operate  within  the  constraints  of  a  low 
quality  TV,  as  a  former  engineer  in  Sili¬ 
con  Valley,  Mr.  Palmer  should  know  that 
the  minimum  bandwidth  requirement  is 
determined  by  the  line  dot  width  and 


4 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 

137 


number  of  lines  displayed  and  thus  is  un¬ 
alterable.  In  the  case  of  the  ZX80  this  fig¬ 
ure  is  deliberately  minimal  at  32  charac¬ 
ters  by  24  rows,  being  768  characters  per 
screen  image,  times  5  dots  as  the  horizon¬ 
tal  component  of  the  matrix,  times  7  dots 
as  the  vertical  component.  These  charac¬ 
teristics  should  not  demand  a  TV  receiver 
bandwidth  in  excess  of  3.5  MHz  (the  fig¬ 
ure  is  explicitly  calculable),  which  is  usual 
for  a  B/W  receiver  of  any  quality  at  all. 
So,  let  us  lay  off  abusing  the  ZX80  on  the 
grounds  of  home-generated  video  faults, 
take  it  down  to  the  local  TV  shop  and  try 
it  on  a  respectable  receiver  before  we 
start  grading  Video  Display  “1,  Very 
poor.”  Quite  ridiculous! 

Integer  BASIC  means  just  what  it 
says,  so  for  the  most  part  the  redoubtable 
hobbyist  had  better  just  lay  off  of  maths 
and  stick  to  the  fine  art  of  writing  pure 
logic  programs  where  only  simple  addi¬ 
tions  and  subtractions  will  suffice  (will 
have  to  suffice).  There  is  simply  no  way 
to  obtain  a  remainder  in  any  variable  in 
Integer  BASIC,  as  there  is  no  subroutine 
in  the  ROM  designed  to  write  even  sin¬ 
gle  precision  notation,  and  no  room  for 
it.  I  am  confused  by  the  allusions  to  the 
ZX80  graphics  capability,  which  is  “pri¬ 
mitive”  on  one  page,  and  “good”  on  the 
next,  and  worthless  in  any  event  in  all 
machines  (e.g.,  TRS-80,  PET)  which  are 
not  designed  to  write  a  full-screen  dot 
matrix. 

Speaking  of  the  ZX80  ROM,  the  in¬ 
teger  BASIC  is  only  about  2K  bytes  long, 
and  that  is  quite  sufficient  for  a  very 
powerful  little  interpreter  (some  may 
recall  the  excellent  TSC  2.2K  Micro 
BASIC).  At  least  1.5K  of  the  ZX80  ROM 
is  devoted  to  monitor  functions,  charac¬ 
ter  generation,  video  and  cassette  control, 
editing  utility,  to  mention  a  few.  A  full 
8K  BASIC  chip  at  about  $40  should  be 
available  shortly,  and  this  will  undoubted¬ 
ly  contain  both  single  and  double  preci¬ 
sion  arithmetic  routines.  And  for  those 
with  big  ideas  about  RAM,  there  will  be 
an  8K  plug-in  for  the  card  edge  connec¬ 
tor,  and  this  will  not  require  any  sculp¬ 
tural  ability  with  a  sharp  knife. 


pals  with  whom  to  tape-swap.  With  re¬ 
gard  to  Kansas  City  Standard  cassette 
tape  format,  this  was  not  instigated  by 
“many  users  got  together  in  Kansas 
City.”  Mr.  Wayne  Green  of  MICROCOM¬ 
PUTING,  the  president  of  SWTPC,  and 
several  other  manufacturers  and  industrial 
people  agreed  to  meet  and  establish  a 
standard  cassette  format.  Unquestionably 
KCS  is  a  good  format,  but  it  does  have 
certain  serious  limitations  with  regard  to 
data  transfer  rates.  Two  or  three  compa¬ 
nies  since  that  famous  meeting  have  man¬ 
aged  to  develop  enhancement  cards 
which  are  capable  of  decoding  fractional 
wave-shapes,  and  I  have  one  on  another 
machine  which  will  transfer  data  reliably 
at  3,600  bps  and  is  fairly  reliable  at  7,200 
bps,  the  latter  being  somewhat  error 
prone. 

To  sum  up,  I  repeat,  I  am  happy  that 
Mr.  Palmer  enjoys  his  little  ZX80,  but  I 
think  his  grousing  and  grumbling  about 
what  it  is  not,  what  it  has  not,  and  what 
it  was  never  intended  to  be  or  to  have,  is 
simply  unnecessary  “atmospheric  pertur¬ 
bation.”  You  take  it  the  way  it  is  and  you 
enjoy  it,  or  you  just  find  some  innocent 
youngster  and  sell  it  or  give  it  to  him. 
And  the  power  of  this  little  machine 
should  never  be  underestimated.  I  thor¬ 
oughly  disagree  with  the  statement  that 
“After  all,  the  real  reasons  anyone  would 
buy  a  low-cost  personal  computer  should 
not  include  anything  very  serious.”  There 
is  a  very  great  deal  to  be  learned  from  the 
Sinclair  ZX80,  which  is  why  I  bought  one 
(bringing  my  total  to  four,  LP/6800, 
TRS-80  and  Vector  Graphic),  and  I  ex¬ 
pect  to  learn  a  great  deal  from  the  ZX80. 
I  also  think  that  it  will  offer  Mr.  Palmer  a 
very  great  and  beneficial  learning  oppor¬ 
tunity,  as  a  benefit  added  to  the  “plea¬ 
sure  and  satisfaction"  he  now  assures  us 
he  has  with  his  little  ZX80. 

Most  sincerely  yours, 

Langdon  Proctor 

707  South  Orange  Grove  Ave.  -  F 

Pasadena,  CA  91105 


Engineers,  scientists,  systems  pro¬ 
grammers,  and  business  owners... 
All  these  read  Dr.  Dobb’s  Journal. 
Reach  them  with  cost-effective 
advertising.  (415)  323-31  1 1. 


As  to  the  limitations  of  the  cassette  ■  ■ 

tape  handling  utilities  in  the  ZX80  ROM, 
they  work,  and  that  is  all  Mr.  Palmer 
needs  to  know.  A  new  magazine  called 
SYNCH  [sic]  is  available  now,  devoted  to 
ZX80  users  and  their  machines,  and  I  am 
sure  that  if  Mr.  Palmer  wants  to  swap 
cassette  tapes  he  will  find,  through 
SYNCH,  a  good  number  of  willing  pen- 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 
138 


5 


Since  1976,  the  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 


Dr.  Dobb’s  Journal 

For  Users  of  Small  Computer  Systems 


B  Tree  ISAM 
Concepts 


CP/M  BOOS 
and  BIOS  Calls 
for  C 


IBM  PC 
Printing  Graphics 
and 

Game  ot  life 


Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


1 

YES!  Enter  my  subscription  to  Dr.  Dobb's  Jour¬ 
nal  and  bill  me  later. 

$25 

name 

one  year  subscription 

12  issues 

saves  $5  off  the  newsstand  price 

city  state  zip 

Mail  to:  DDJ,  P.O.  Box  E., 

Menlo  Park,  CA  94025 

Z~80  Floppy 


T 

he  Z-80  Floppy  Disk  Test  is  a  general  purpose  utility  for  testing  or  initializing 
a  diskette.  It  requires  a  Z-80  microprocessor,  at  least  32  kbytes  of  random  access 
memory,  two  flexible  disk  drives,  and  the  Digital  Research  CP/M  2.x  operating  system. 
Program  mode  and  area  of  diskette  to  be  tested  are  controlled  from  the  keyboard.  Er¬ 
rors  may  be  audited  on  the  console  or  the  line  printer. 

All  console  I/O  is  done  using  the  standard  CP/M  function  calls.  For  maximum  test 
speed,  access  to  protected  system  areas,  and  to  avoid  error  interception  by  the  CP/M 
operating  system,  disk  I/O  is  performed  directly  by  calls  to  the  BIOS  drivers.  The  test 
will  not  execute  correctly  under  MP/M  -  don’t  even  try  it! 

In  the  accompanying  listing,  the  program  is  configured  to  test  a  soft -sectored, 
single-density  disk  with  77  tracks,  26  sectors  per  track,  and  128  byte  sectors.  If  you 
are  using  a  different  type  of  disk  drive,  the  number  of  tracks  and/or  sectors  per  track 
may  be  specified  during  the  initialization  dialogue,  or  the  program  may  be  reassembled 
to  modify  the  default  configuration. 

The  program  does  not  exhaustively  check  out  the  disk  drive,  and  any  errors 
detected  by  the  program  must  be  interpreted  with  care.  Intermittent  errors  occurring 
throughout  a  broad  range  of  disk  addresses  probably  indicate  a  problem  with  the  disk 
drive  unit.  Errors  indicated  at  consistent  addresses  within  adjacent  tracks  may  result 
from  a  worn  or  damaged  flexible  disk.  Error-free  execution  of  the  test  certainly  indi¬ 
cates  an  intact  and  usable  diskette,  and  also  is  fairly  good  evidence  of  proper  operation 
of  your  disk  drive.  Note  that  the  program  is  rather  insensitive  to  drive  problems  related 
to  head  movement,  since  the  diskette  is  addressed  in  a  smooth  sequential  manner. 

Using  The  Test  Program 

Put  your  system  disk  in  drive  A,  boot  up  the  CP/M  operating  system,  and  type: 


A  >  dtst 


The  test  program  will  load  into  memory  and  print  the  identifying  message: 

Z-80  Disk  Test  version  1.0 

Copyright  1980  Laboratory  Microsystems 

If  there  is  inadequate  memory  in  the  transient  program  area,  or  if  the  operating 
system  is  not  CP/M  version  2.0  or  greater,  the  program  will  immediately  print  a  warn¬ 
ing  message  and  exit.  Otherwise,  the  test  proceeds  to  the  initialization  dialogue.  The 
test  mode  is  set  via  a  series  of  questions  presented  to  the  system  console.  Answers 
calling  for  an  alphabetic  character  may  be  upper  or  lower  case;  a  carriage  return  is  not 
required.  Answers  calling  for  a  number  must  be  two  digits,  or  one  digit  followed  by  a 
carriage  return. 

QUERY  RESPONSES  EXPLANATION 

Itemize  errors?  Y  or  N  If  answered  Y,  each  error  detected  is 

audited  on  the  selected  device.  If  an¬ 
swered  N,  only  the  total  error  count 
is  printed  at  the  end  of  each  pass. 

Console  or  Printer?  C  or  P  If  itemizing  errors,  select  the  device 

on  which  the  itemized  error  listing 
will  be  printed. 


by  Ray  Duncan 


Ray  Duncan,  Laboratory  Microsystems,  4147  Beethoven  Street,  Los  Angeles,  CA 
90066. 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


QUERY 

RESPONSES 

EXPLANATION 

Lock  on  read  or 
write? 

N,  R,  or  W 

N  =  no  locks.  R  =  lock  on  read  mode 
(no  data  is  written  to  the  disk  —  use¬ 
ful  for  detecting  any  damaged  areas 
on  the  media).  W  =  lock  on  write  (all 
data  on  the  disk  is  destroyed  —  this 
may  be  used  to  erase  a  diskette  by 
also  locking  on  pattern). 

Restore  original 
data? 

YorN 

Y  =  restore  existing  data  on  diskette 
after  testing  each  sector.  N  =  do  not 
restore  existing  data.  Test  runs  much 
faster  when  restore  mode  is  not  used. 

Lock  on  data 
pattern? 

YorN 

Y  =  user  wishes  to  specify  specific 
data  to  be  used  as  the  test  pattern. 
N  =  random  data  pattern  is  generated 
by  the  test  program. 

Enter  data  pattern 

hex  OO-FF 

If  you  answered  Y  to  Lock  On  Pat¬ 
tern,  enter  the  eight -bit  data  pattern 
to  be  used  during  disk  testing.  If  you 
answered  N,  this  question  is  by¬ 
passed. 

Drive  to  be  tested 

B,  C,  or  D 

Specify  disk  drive  to  be  used  for 
diskette  testing.  In  order  to  prevent 
accidental  destruction  of  the  system 
disk,  the  use  of  drive  A  is  not  al¬ 
lowed. 

Test  all  tracks? 

YorN 

Y  =  test  all  tracks  (00-76)  in  se¬ 
quence.  N  =  user  wishes  to  specify 
range  of  tracks  (may  be  used  to  test 
only  part  of  a  diskette,  or  if  disk 
drive  is  other  than  standard  8 -inch 
single  density). 

First  track  to  test 

decimal  00-76 

If  you  answered  N  to  Test  All 
Tracks,  specify  here  the  number  of 
the  first  track  to  test. 

Last  track  to  test 

decimal  00-76 

If  you  answered  N  to  Test  All 
Tracks,  specify  here  the  number  of 
the  last  track  to  test.  Must  be  the 
same  or  greater  than  the  number  of 
the  first  track  to  test. 

Test  all  sectors? 

YorN 

Y  =  test  all  sectors  (1-26)  in  se¬ 
quence.  N  =  user  wishes  to  specify 
range  of  sectors  (may  be  used  to  test 
only  part  of  each  track,  or  if  disk 
drive  is  other  than  standard  8 -inch 
single  density). 

First  sector  to  test 

decimal  01-26 

If  you  answered  N  to  Test  All  Sec¬ 
tors,  specify  here  the  number  of  the 
first  sector  to  test  on  each  track. 

QUERY 


RESPONSES 


EXPLANATION 


Last  sector  to  test  decimal  01 -26  If  you  answered  N  to  Test  All  Sec¬ 
tors,  specify  here  the  number  of  the 
last  sector  to  test  on  each  track.  Must 
be  the  same  or  greater  than  the  num¬ 
ber  of  the  first  sector  to  test. 

decimal  01-99  Enter  the  number  of  test  passes  to  be 
made  on  the  diskette.  At  least  one 
pass  is  always  made  even  if  you  enter 
zero. 

After  entry  of  the  number  of  test  passes,  the  program  immediately  begins  execut¬ 
ing.  The  program  may  be  interrupted  by  pushing  any  key,  however  response  may  be 
delayed  for  several  seconds  depending  on  the  speed  of  the  processor  and  disk  drive.  Do 
not  stop  the  test  by  resetting  the  computer  system  if  you  are  using  restore  mode,  or 
unpredictable  amounts  of  data  may  be  lost. 

Error  Listing 

Errors  detected  by  the  program  may  be  itemized  on  the  system  console  or  the  line 
printer.  The  pass,  drive  name,  track,  and  sector  where  the  error  occurred  are  listed.  All 
numbers  are  in  decimal.  The  error  type  is  designated  at  the  right.  In  the  explanations 
below,  “hardware  error”  signifies  an  error  status  code  returned  from  the  low-level  disk 
driver,  and  usually  means  a  CRC  fault  or  seek  incomplete. 

ERROR  TYPE  EXPLANATION 

read  error  —  original  data  If  running  in  restore  mode,  hardware  read  error 

noted  as  the  original  data  was  being  loaded  into 
memory. 

write  error  —  test  data  Hardware  error  noted  as  the  test  data  pattern 

was  being  written  on  the  diskette. 

read  enor  —  test  data  Hardware  error  noted  as  the  test  data  pattern 

was  being  read  back  from  the  diskette. 

compare  error  —  test  data  Difference  was  found  between  the  data  pattern 

that  was  written  to  the  diskette  and  the  data 
that  was  read  back. 

write  error  —  restore  phase  Hardware  error  noted  as  the  original  data  was 

being  written  back  to  the  diskette. 

read  error  -  restore  phase  Hardware  error  noted  as  the  restored  original 

data  was  being  read  back  for  verification. 

data  cannot  be  restored  Compare  error  found  between  the  original  data 

rewritten  to  the  diskette  and  the  same  sectors 
read  back  for  verification. 

General  Logic  of  Test  Program 

1.  Check  CP/M  version  and  amount  of  user  memory  available.  If  they  do  not 
meet  program  requirements,  exit  with  error  message. 

2.  Configure  test  mode  via  interview  with  console  operator. 

3.  Initialize  current  drive,  track,  and  sector  assignments. 


How  many  test 
passes? 


10 

142 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


4.  If  not  restore  mode,  go  to  <5  >,  else  read  existing  data  on  diskette  for  this 
track  into  memory  and  save  it. 

5.  If  this  pass  is  locked  on  read,  go  to  <6>,  else  generate  a  data  pattern  and 
write  all  selected  sectors  for  this  track. 

6.  If  this  pass  is  locked  on  write,  go  to  <9>,  else  read  all  selected  sectors  for 
this  track. 

7.  If  locked  on  read  or  write,  go  to  <9>,  else  compare  the  test  data  pattern 
that  was  written  to  the  data  that  was  read  back  from  the  disk. 

8.  If  not  restore  mode,  go  to  <  9  >,  else  write  the  original  data  back  to  the 
diskette  for  this  track  and  verify  it. 

9.  Advance  to  next  track,  if  current  track  not  greater  than  last  track  to  test 
then  go  to  <4>. 

10.  End  of  test  pass,  print  pass  number  and  total  error  count  on  selected 
devices. 

1 1 .  If  current  pass  not  equal  to  last  pass,  go  to  <  3  >. 

12.  If  user  wishes  to  continue  testing,  go  to  <2>,  else  exit  to  CP/M. 

Major  Program  Subroutines 

RDBUF  Read  up  to  one  track  from  the  disk  into  buffer  specified  by  caller. 

Audit  any  hardware  errors  on  the  selected  device,  using  descriptive 
message  supplied  by  caller. 

WTBUF  Write  up  to  one  track  from  the  user-specified  buffer  to  the  disk. 

Audit  any  hardware  errors  on  the  specified  device,  using  descrip¬ 
tive  message  supplied  by  caller. 

BUFPAT  Fill  a  buffer  with  a  data  pattern  to  be  used  while  testing  the  cur¬ 
rently  selected  track.  The  user  may  specify  a  fixed  eight -bit 
pattern,  or  the  subroutine  will  generate  a  semi-random  pattern 
from  a  combination  of  the  refresh  register  contents  and  the 
memory  address. 

BUFCMP  Compare  two  buffers  specified  by  caller.  If  any  differences  are 
found,  print  an  error  message  on  the  selected  device. 

PERR  Subroutine  called  by  all  other  subroutines  to  print  an  error  message 

on  the  selected  device.  Current  drive,  track,  sector  and  pass  number 
are  formatted  together  with  a  variable  message  supplied  by  caller. 

Comments  on  Program  Listing 

The  equates  in  lines  3 1  -40  define  the  default  drive,  track,  and  sector  limits.  If  you 
are  not  using  a  soft-sectored,  single- density,  eight-inch  diskette  drive,  test  convenience 
may  be  maximized  by  modifying  these  references  and  reassembling  the  program. 

The  reference  “$dig”  in  line  45  defines  the  maximum  number  of  digits  to  be  ac¬ 
cepted  during  console  entries  of  hexadecimal  or  decimal  integers  in  the  test  configura¬ 
tion  sequence.  This  reference  must  be  changed  to  a  larger  number  if  the  test  is  to  be 
used  on  disk  drives  having  more  than  99  tracks. 

Lines  1072-1075  define  the  size  of  the  disk  I/O  buffers.  In  the  accompanying  list¬ 
ing,  these  have  been  made  twice  as  large  as  necessary  so  that  the  test  can  also  be  used 
on  double-density  drives.  If  the  program  will  only  be  used  on  single -density  disk 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


11 

143 


drives,  you  can  minimize  memory  requirements  by  changing  the  source  program  as 
follows: 


1072 

buffi 

equ 

1000h 

1073 

buff2 

equ 

Sb.pt + buffi 

1074 

buff3 

equ 

$bpt+buff2 

1075 

buffend 

equ 

$bpt+buff3 

Note  that  the  starting  memory  address  of  each  disk  buffer  should  be  evenly  divisible 
by  the  value  of  $bps  (bytes  per  sector). 

Program  Areas  of  Interest  to  Users 

To  use  the  program  on  other  types  of  disk  drives  without  editing  the  source  file 
and  running  an  assembly,  it  may  become  necessary  to  change  the  first  two  locations 
given  below.  This  may  be  done  by  reading  in  the  COM  file  with  DDT,  patching  the  de¬ 
sired  location,  and  SAVEing  a  new  COM  file. 


01 19H  (8  bits)  Sector  skew  flag.  If  byte=0,  skew  is  not  used.  If  byte=l,  re¬ 

map  sector  numbers  as  given  in  the  sector  translation  table.  On  Z-80 
systems  at  4  mHz,  skew  is  not  needed  and  this  byte  may  be  left  zero. 
On  systems  with  slower  processors,  test  speed  may  be  improved  by 
use  of  skew. 

0121H  (8  bits)  Contains  the  number  of  digits  to  be  accepted  by  the  numeric 

input  routines  during  the  initialization  dialogue,  the  value  is  two  in 
the  distributed  version.  If  test  is  to  run  on  a  drive  with  greater  than  99 
tracks,  change  the  value  of  this  byte  to  three. 

0122H  (16  bits)  Contains  the  address  of  the  sector  translation  table.  In  the 

distributed  program,  the  table  is  built  with  a  skew  factor  of  three,  and 
is  26  bytes  long. 


Test  Availability  on  Machine  Readable  Media 

For  those  readers  who  do  not  wish  to  retype  the  source  text,  Laboratory  Micro¬ 
systems  will  make  available  the  .ASM,  .COM,  and  .DOC  files  on  a  standard  eight-inch, 
soft -sectored,  single -density  diskette.  Send  check  or  money  order  for  $25.00  to 
4147  Beethoven  Street,  Los  Angeles,  California  90066. 

TEST  SAMPLE 

A  >  DTST 


Laboratory  Microsystems  Disk  Test  version  1.0 


Itemize  errors?  (Y/N)  >  Y 

Use  console  or  printer?  (C/P)  >  C 

Lock  on  read  or  write?  (N/R/W)  >  N 

Restore  original  data?  (Y/N)  >  N 

Lock  on  data  pattern?  (Y/N)  >  N 

Drive  to  be  tested  (B-D)  >  B 

Confirm:  test  drive  B  ?  (Y/N)  >  Y 

Test  all  tracks?  (Y/N)  >  Y 

Test  all  sectors?  (Y/N)  >  Y 

How  many  test  passes?  >  1 


Beginning  disk  test  -  push  any  key  to  abort  program. 
Warning:  user  data  will  not  be  restored. 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


Pass 

Drive 

Track 

Sector 

Error  type 

0001 

B 

0062 

0003 

read  error  -  test  pattern 

0001 

B 

0062 

0003 

compare  error  -  test  pattern 

0001 

B 

0065 

0023 

read  error  -  test  pattern 

0001 

B 

0065 

0023 

compare  error  -  test  pattern 

0001 

B 

0066 

0007 

read  error  -  test  pattern 

0001 

B 

0066 

0022 

read  error  -  test  pattern 

0001 

B 

0066 

0023 

read  error  -  test  pattern 

0001 

B 

0066 

0007 

compare  error  —  test  pattern 

0001 

B 

0066 

0022 

compare  error  -  test  pattern 

0001 

B 

0066 

0023 

compare  error  —  test  pattern 

0001 

B 

0067 

0007 

read  error  -  test  pattern 

0001 

B 

0067 

0007 

compare  error  -  test  pattern 

0001 

B 

0068 

0014 

read  error  -  test  pattern 

0001 

B 

0068 

0014 

compare  error  -  test  pattern 

0001 

B 

0069 

0012 

read  error  —  test  pattern 

0001 

B 

0069 

0012 

compare  error  -  test  pattern 

Pass  0001  complete,  0016  errors. 

Continue  or  exit  test?  (C/E)  >  E 

Goodbye 

A> 

A>  (LISTING  ON  PAGE  22)  ■■ 


YOU  CAN  HELP  YOUR  COMMUNITY 
LEARN  ABOUT  COMPUTERS _ 

SUPPORT 

(^mputerjown™ 

ComputerTown ,  a  computer  literacy  project  sponsored  by  People’s  Computer  Company  and  later  funded  by  the 
National  Science  Foundation,  began  operations  in  1979.  The  project’s  ongoing  goal  is  to  design,  publish  and  dis¬ 
seminate  materials  for  the  development  of  community -based  computer  literacy  projects  around  the  world. 

You  too  can  help!  Your  tax -deductible  donations  of  new  and  used  computer  hardware  and  software  will  enable 
us  to  bring  “hands-on”  experience  to  people  everywhere.  These  items  can  mean  the  difference  between  a  person 
just  hearing  about  computer  technology  and  actually  being  able  to  sit  down  and  use  it.  A  ComputerTown  can 
be  set  up  in  a  public  library,  museum,  school,  business  or  a  number  of  other  places.  What’s  needed,  along  with 
the  information,  resources  and  experience  we  provide,  is  just  a  few  machines  and  some  software  to  get  started. 


Already  there  are  more  than  eighty  ComputerTown s  in  the  U.S.,  Canada,  England  and  other  countries.  Your 
generous  donations  can  help  this  number  grow. 


For  more  information  about  ComputerTown,  and  for  details  on  how  to  make  contributions,  contact: 

Fritzi  Lareau,  c/o  ComputerTown 
1263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  CA  94025 
(415) 323-3111 


Di.  Dobb’s  Journal,  Number  54,  April  1981 


13 

145 


Polynomial  Evaluation  in  BASIC 


T 

he  need  to  evaluate  polynomials  oc¬ 
curs  fairly  often  in  scientific  program¬ 
ming.  For  example,  in  order  to  plot  a 
polynomial,  one  has  to  evaluate  it  on  a 
large  number  of  points;  finding  the 
“zero’s”  of  a  polynomial  -  say,  by  the 
Newton- Raphson  method  —  also  entails 
evaluation  of  the  polynomial  many  times. 
Because  many  difficult  functions  can  be 
closely  approximated  by  a  polynomial 
(power  series  expansion),  this  mathemati¬ 
cal  form  appears  often. 

In  addition  to  the  above,  it  is  often 
necessary  to  evaluate  the  derivatives  of  a 
polynomial,  which,  of  course,  are  poly¬ 
nomials  themselves.  In  general,  a  poly¬ 
nomial  can  be  expressed  as  follows: 

(1) 

pn(x)=a„xn+an_1xn-1  +  .  . .  +a,x+a0 

Where  x  is  the  independent  variable 
and  the  a’s  are  constant  coefficients.  The 
highest  power  of  the  independent  vari¬ 
able  is  the  degree  of  the  polynomial. 
pn(x)  is,  therefore,  a  polynomial  of  de¬ 
gree  n,  with  the  independent  variable  x.  A 
short  form  for  expressing  pn(x)  is: 

(2) 

n 

Pn(x)=2  aix* 


Representation  of  p„(x)  in  a  com¬ 
puter  can  be  accomplished  in  several 
ways.  The  simplest  (but  not  necessarily 
the  most  efficient)  uses  a  vector  of  di¬ 
mension  (n+1).  We  do  this  by  stating: 

80  DIM  A(N) 

This  reserves  (n+1)  locations,  in 
which  we  store  the  (n+1)  coefficients  of 
our  polynomial,  such  that  ao  occupies 
A(0),  aj  occupies  A(l)  and  so  on  to  an 
sitting  in  A(N). 

If  we  wish  to  find  the  value  of  pn(x) 
when  x  assumes  a  specific  value  (say, 
x=7),  we  say  that  we  wish  to  evaluate  the 
polynomial  at  the  point  x=7  and  write: 

(3) 

Pn(7)=an7n+an_17n~1+  . . .  +aj7+ao 


by  R.A.  Hoffman 


Since  the  a’s  are  simply  numbers, 
using  the  computer  to  carry  out  the  eval¬ 
uation  is  —  at  least  in  principle  —  simple 
enough:  first,  we  calculate  7  to  the  power 
of  n;  we  then  multiply  it  by  an.  Next,  we 
calculate  7  to  the  power  of  (n- 1 ),  multi¬ 
ply  the  result  by  an_j  and  add  this  to  the 
previous  result.  We  continue  in  this  way, 
until  the  polynomial  is  finally  evaluated. 

There  are  two  disadvantages  to  this 
evaluation  scheme.  It  is  easy  to  show  that 
it  involves  n*(n+l)/2  multiplications, 
plus  n  additions  (i.e.,  36  multiplications 
and  8  additions  for  an  8th  degree  poly¬ 
nomial).  This  is  both  inaccurate  (due  to 
the  accumulation  of  truncation  and 
round-off  errors)  and  slow.  Because  the 
calculation  usually  has  to  be  carried  out 
many  times,  and  often  for  some  or  all  of 
the  derivatives  as  well,  this  process  proves 
very  unsatisfactory. 

The  algorithm  to  be  presented  below 
is  much  more  efficient.  Evaluation  of  the 
polynomial  can  be  accomplished  with  n 
multiplications  and  n  additions  (8  each 
for  an  8th  degree  polynomial).  Better 
still,  the  derivatives  of  the  polynomial  fol¬ 
low  naturally.  They  can  be  produced  at 
the  same  time,  with  just  over  n*(n+l)/2 
multiplications  and  additions  for  all. 

The  next  section  will  present  the 
mathematical  derivation  of  this  decep¬ 
tively  simple  algorithm.  Readers  who  are 
interested  in  results  only  will  miss 
nothing  by  skipping  it  and  picking  up  the 
action  at  the  following  section. 


Mathematical  Derivation 

We  start  by  dividing  our  polynomial 
by  (x-Xl).  Please  note  that  (x-Xl)  hap¬ 
pens  to  be  a  polynomial  of  degree  one, 
with  the  independent  variable  x  and 
al=l,  a0=Xl  (XI  is,  of  course,  a  con¬ 
stant). 

(4) 


Pn(x) 

x-Xl 


=  qn-i(x)  + 


Ro 

x-Xl 


The  quotient  qn-i(x)  is  a  polynomial 
whose  degree  is  one  less  than  that  of 
pn(x).  R0  is  a  constant  remainder,  whose 
value  depends  on  the  coefficients  of 
pn(x),  as  well  as  on  the  value  XI.  Rear¬ 
ranging  terms: 

(5) 

Pn(x)=(x— XI  )q„-i  (x)  +  Ro 


to  zero  when  we  evaluate  at  X 1  by  setting 
x=Xl .  It  seems  that  if  a  neat  way  of  eval¬ 
uating  R0  exists,  then  the  same  way  may 
be  used  to  evaluate  pn(Xl). 

Diverting  our  attention  to  polynomi¬ 
al  q„-i(x): 

(6) 

qn-i(x)=bnxn'1+bn.iXn-2+.  ,.+b2x+b1 

We  can  find  the  coefficients  by  actually 
carrying  out  the  division  called  for  by 
equation  (4).  Doing  this,  we  find: 

(7) 

bn  =  a„ 

bn-i  =  b„*Xl  +an_i 

bn-2  =  bn-i  *X1  +a„_2 


with  the  general  term  being:  bj  =  bj+]  * 
Xl+a;,  (i=n-l,  n-2, . . 1).  Please  note 
that  b„  is  the  coefficient  for  the  xn_1 
term,  b„_i  is  the  coefficient  for  the  xn-2 
term  and  so  forth  down  to  bj,  which  is 
the  constant  term  of  polynomial  qn-i(x). 
It  turns  out  that  b0,  which  may  be  calcu¬ 
lated  by  equation  (7),  but  is  not  a  coeffi¬ 
cient  of  qn-i(x)  at  all,  is  equal  to  R0. 
The  reader  is  invited  to  carry  out  the  long 
hand  division  (4)  and  thus  verify  this  (the 
operation  is  not  difficult  -  just  messy). 

Now,  let  us  divide  polynomial 
qn-i(x)  by  the  polynomial  (x-Xl).  By 
analogy  with  previous  results: 


(8) 


qn-i(x) 

x-Xl 


qn-2(x) 


+ 


Ri 

x-Xl 


(9) 

qn-i(x)  =  (x-Xl)qn_2(x)+Ri 


Just  like  before,  qn-2(x)  may  be  ex¬ 
pressed  by: 

(10) 

qn-2(x)=cnxn-2+cn.,xn-3  +  . .  .+c3x+c2 

With  the  general  expression  for  the  coef¬ 
ficients  being: 

(11) 

cn  =  bn 

q  =  cj+iXl  +bj  (i=n-l,  n-2 . 2) 


R.  A.  Hoffman,  9  Greenway  Ct„  Brook-  Obviously,  Pn(Xl)=R0,  because  the  Plugging  the  result  into  the  original  ex¬ 
line,  MA  02146.  rest  of  the  right  side  of  the  equation  goes  pression  for  pn(x),  we  get: 


14 

146 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


(12) 

Pn(x)=(x-Xl)2qn.2(x)+(x-Xl)R1  +  R0 
Taking  the  derivative  of  pn(x): 

(13) 

p'n(x)=2(x-Xl)q„.2(x) 

+(x-Xl)2q'n.2(x)+R1 

So  that  p'n(x)  evaluated  at  XI:  p'n(Xl)= 
Rj.  But  Rj  =  Cj,  as  calculated  by  (11) 
above. 

In  a  completely  analogous  manner  it 
is  possible  to  show  that : 

(14) 

p"„(Xl)  =  2*R2 
p'''„(Xl)=6*R3 


with  the  general  expression  being: 
p„(il(Xl)=i!  *  Rj.  In  words:  the  i’th 
derivative  of  polynomial  p„(x),  evaluated 
at  point  XI,  is  equal  to  i  factorial,  multi¬ 
plied  by  the  i’th  remainder  of  p„(x)  di¬ 
vided  by  (x-Xl).  This  statement  is  of  a 
very  general  nature,  if  we  agree  that  the 
zeroth  derivative  of  a  function  is  the 
function  itself  and  that  01*1. 


The  BASIC  Routine 

In  contrast  with  the  frightening  na¬ 
ture  of  the  mathematical  derivation,  the 
BASIC  routine  which  carries  out  the  cal¬ 
culation  is  deceptively  trivial.  We  start 
with  three  parameters  which  the  routine 
receives  from  the  calling  program : 

N  —  is  the  degree  of  the  polynomial  to 
be  evaluated. 

V  —  is  a  vector  of  dimension  N  (that  is, 
contains  N+l  elements,  starting 
with  V(0)  and  ending  with  V(N)), 
which  contains  the  coefficients  ao, 
ai , . .  .,  an  of  the  polynomial. 

XI  —  point  of  evaluation. 

The  routine  returns,  in  vector  V,  a 
series  of  values  such  that  the  value  in  V(i) 
is  the  value  of  the  i’th  derivative  of  the 
polynomial,  evaluated  at  XI.  V(0),  of 
course,  will  contain  the  value  of  the  poly¬ 
nomial  itself,  again  -  evaluated  at  XI. 

Here’s  how  it  is  done:  to  calculate 
the  “b”  coefficients  of  polynomial 
qn-i(Xl),  we  do  the  following  loop: 


1060  FOR  J=N-1  TO  0  STEP  -1 

1070  V(J)=V(J+1)*X1+V(J) 

1080  NEXT  J 

The  idea  is  to  calculate  the  “b”  co¬ 
efficients  in  situ  —  that  is,  replace  the 
content  of  V  (which  is  the  “a”  coeffi¬ 
cients  of  pn(x)),  with  a  new  content 
(which  is  the  “b”  coefficients  of  qn_  j  (x) ). 

Location  V(N)  contains  an.  Since 
bn  =  an,  we  leave  it  alone  and  start  the 
loop  at  location  V(N-l),  repeating  the 
calculation  all  the  way  down  to  location 
V(0). 

We  now  have  b0  sitting  in  location 
V(0).  But  b0  =  Ro,  and  R0  is  one  of  the 
values  we  are  after.  Therefore,  we  would 
like  to  repeat  the  calculation  for  the  “c” 
coefficients  of  polynomial  qn_2(x),  start¬ 
ing  again  at  location  V(N-l),  but  going 
this  time  down  to  location  V(l),  leaving 
V(0)  alone. 

We  will  now  have  R0  in  location 
V(0)  and  Rj  in  location  V(l).  We  would 
like  to  repeat  the  calculation,  this  time 
for  the  “d”  coefficients  of  polynomial 
qn_3(x),  going  from  V(N-l)  down  to 
V(2).  . . . 

The  pattern  is  now  clear. . . .  The 
routine  looks  like  this: 

1050  FOR  1=0  TO  N-l 

1060  FOR  J=N-1  TO  I  STEP-1 

1070  V(J)=V(J+1)*X1+V(J) 

1080  NEXT  J 

1090  NEXT  I 

After  execution  of  this  loop,  V  will 
contain  the  Rj  series.  To  calculate  the 
actual  derivatives,  we  need  to  multiply 
each  term  by  the  appropriate  factorial, 
so: 


1120  F=1 

1130  FOR  1=2  TON 
1140  F=F*I 
1150  V(I)=V(I)*F 

1 160  NEXT  I 

In  this  loop,  F  assumes  the  value  of 
I  factorial  in  each  iteration,  by  virtue  of 
line  1 140. 

That’s  it! 

Listing  1  shows  a  short  program 
which  demonstrates  the  polynomial  eval¬ 
uation  subroutine  (lines  1000  to  1170). 
It  requests  from  the  user  a  polynomial 
and  an  evaluation  point,  evaluates  the 
polynomial  and  prints  out  the  results.  A 
sample  run  is  shown  in  Listing  2. 


(LISTING  ON  PAGE  40) 


Dr  Dobb  s  Journal  of 

COMPUTER  Calisthenics  (f-  O'thodontM 

Subscription  Rates:  $2  5  per  year  within  the 
United  States:  $44  for  first  class  to  Canada 
and  Mexico;  $62  for  airmail  to  other  coun¬ 
tries.  Payment  must  be  in  U.S.  dollars, 
drawn  on  a  U.S.  bank. 

Writer’s  Guidelines:  All  items  should  be 
typed,  double-spaced  on  white  paper.  List¬ 
ings  should  be  produced  by  the  computer, 
using  a  fresh,  dark  ribbon  on  continuous 
white  paper.  Please  avoid  printing  on  perfo¬ 
rations.  Payment  is  in  contributor’s  copies. 
Requests  to  review  galleys  must  accompany 
the  manuscript  when  it  is  first  submitted. 
Authors  may  receive  a  copy  of  the  complete 
writer’s  guidelines  by  sending  a  self- 
addressed,  stamped  envelope. 

Donating  Subscribers 

Contributing  Subscriber:  $50/year  ($25  tax 
deductible).  Retaining  Subscriber:  $75/year 
($50  tax  deductible).  Sustaining  Subscriber: 
$  100/year  ($75  tax  deductible).  Lifetime 
Subscriber:  $1000  ($800  tax  deductible). 
Corporate  Subscriber:  $500/year  ($400  tax 
deductible,  receives  five  one- year  subscrip¬ 
tions). 

Contributing  Subscribers:  Eric  P.  Hanson,  1. 
G.  Zeratsky,  Mervin  E.  Frank,  Edward  W. 
Carr,  Steven  Fisher,  Thomas  H.  Grohne, 
Richard  Washburn,  Les  Hancock,  G.  V. 
Elkins,  C.  A.  Forsberg,  Daniel  R.  Lunsford, 
J.  D.  Griffith,  Michael  Slade,  Thomas  M. 
Schaefges,  General  Electric,  Louis  L. 
Odette,  Robert  M.  Connors,  William  J. 
McEown,  Robert  C.  Luckey,  Kim  Leary, 
Robert  N.  Stabler,  Dewitt  S.  Brown,  John 
B.  Palmer,  E.  Glion  Curtis,  Roger  Hanson, 
Jack  Miller,  Burks  A.  Smith,  Transdata 
Corporation. 

Retaining  Subscribers:  Mike  Faithful, 
Osamu  Shimizu,  Scott  B.  Guthery,  Robert 
L.  Edens,  David  Dick. 

Sustaining  Subscribers:  Gordon  Eubanks,  Jr. 
and  Robert  C.  Birss,  Ph.D. 

Foreign  Distributors 
UK  A  Europe:  LP  Enterprises,  8/1 1  Cam¬ 
bridge  House,  Cambridge  Road,  Barking,  Es¬ 
sex,  1G11  8NT,  England  (Tel.  01-591- 
6511,  TLX  892395).  Hofacker- Verlag, 
Tegernseer  Strasse  18,  D-81S0  Holzkirchen, 
West  Germany.  Computerland/Computer 
Store  AB,  Box  7134,  Kungsgatan  19,  S- 
10387  Stockholmn,  Sweden. 

Asia  A  Australia:  Electronic  Concepts  Pty 
Ltd.,  55  Clarence  Street,  Sydney,  NSW2000, 
Australia.  Computer  Store,  POB  31-261, 
22B  Milford  Road,  Milford,  Auckland  9, 
New  Zealand.  ASCII  Publishing  Co.,  Ltd., 
Aoyama  Building  5F,  5-16-1  MinamiAoya- 
ma,  Minato-ku,  Tokyo  107,  Japan. 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


15 

147 


Algorithms  in  FORTH 


W 

▼  T  hile  I  have  no  particular  claim  to 
being  an  expert  in  FORTH  programming, 
I  have  been  using  Cap’n  Software’s 
FORTH  systems  for  a  couple  of  years, 
and  have  gotten  familiar  with  the  opera¬ 
tion  of  figFORTH  in  its  various  incarna¬ 
tions. 

When  I  thought  about  Algorithms, 
the  first  thing  that  occurred  to  me  was 
Kemighan  and  Plauger’s  Software  Tools, 
since  the  programming  techniques  they 
present  are  very  general,  and  the  func¬ 
tions  they  perform  are  quite  useful.  I  got 
out  my  copy,  re-read  it,  and  found  they 
lend  themselves  to  programming  in 
FORTH  very  well. 

The  first  functions  that  K  &  P  pre¬ 
sent  are  <  getc  >  and  <  putc  >,  which  get 
and  put,  respectively,  one  character  from 
and  to  standard  I/O  devices.  They  ignore 
the  details  of  where  the  characters  come 
from,  what  their  form  is,  and  all  other 
“details.” 

FORTH  always  works  very  close  to 
the  hardware  level  of  the  machine  that  it 
runs  on,  so  a  little  attention  to  some  of 
the  details  is  in  order. 

First,  I  am  going  to  assume  that  any 
character  we  are  dealing  with  is  an  ASCII 
code  right -justified  in  an  8-bit  byte. 
Standard  FORTH  systems,  to  my  know¬ 
ledge,  all  make  this  assumption.  The  high- 
order  bit  is  assumed  to  be  zero  for 
character-to-character  compares. 

Second,  I  am  going  to  assume  that 
the  FORTH  system  normally  talks  to  the 
outside  world  through  a  CRT  terminal  - 
all  input  and  output  come  and  go  through 
it,  unless  directed  to  some  specific  peri¬ 
pheral. 

FORTH  provides  two  “primitive” 
words  which  link  the  system  to  machine- 
code  routines  which  do  the  actual  work 
of  I/O: 

KEY  This  word  takes  the  next  char¬ 
acter  received  from  the  standard  input, 
and  pushes  it  onto  the  top  of  the  working 
stack  (SO,  in  Dr.  Gordon’s  terminology). 
The  stack  is  1 6  bits  wide,  so  the  character 
is  put  into  the  low-order  byte. 

EMIT  Pops  the  low-order  7  bits 
from  the  top  of  the  working  stack,  and 


by  S.B.  Bassett 


Samuel  B.  Bassett,  1010  Ashbury  # 4 , 
San  Francisco,  CA  94117. 


puts  it  to  the  standard  output  device. 

FORTH  usually  assumes  that  pro¬ 
grams  and  data  are  stored  on  a  disk  drive, 
and  provides  a  word  to  do  disk  I/O: 

R/W  Reads  or  writes  one  sector  of 
data  from  or  to  the  disk.  R/W  takes  three 
parameters  from  the  stack: 

Top  (TOS)  =  a  Boolean  flag,  with  0 
meaning  “Write”  and  1  meaning  “Read.” 

2nd  =  the  number  of  the  block  to 
be  fetched/written. 

3rd  =  the  starting  address  of  the 
text  buffer  into/out  of  which  data  is  to 
be  read/written. 

I  will  specify  parameters  for  FORTH 
words  like  this: 

3rd  2nd  TOS  Word 

addr  blk#  f  R/W(or“— ”) 

where  the  value  on  the  top  of  the  work¬ 
ing  stack  is  closest  to  the  right,  and  values 
deeper  in  the  stack  are  successively  furth¬ 
er  to  the  left. 


Let’s  assume  we  have  gotten  a  buffer 
full  of  text  from  the  disk,  using  R/W,  and 
that  it  is  located  at  address  B000  Hex, 
and  we  want  to  move  it  to  B400.  This  is 
the  job  which  K  &  P  describe  for  <  getc  > 
and  <  putc  >. 

First:  HEX 

To  put  the  FORTH  system  into 
Hexadecimal  mode,  so  that  all  numbers 
are  interpreted  as  Hex  and  not  Decimal. 

The  second  step  is  to  define  variables 
to  hold  the  “from”  and  “to”  addresses 
and  a  pointer  variable: 

VARIABLE  INPUT.BUFFER 

VARIABLE  OUTPUT. BUFFER 

VARIABLE  PTR 

(79 -Standard  FORTH,  unlike  earlier 
models,  does  not  provide  for  setting  the 
initial  value  of  a  variable.  Earlier  versions 
would  have  entered:  B000  VARIABLE 
INPUT.BUFFER.  Notice  the  length  of 
the  name  —  79-Standard  FORTH  accepts 
names  of  up  to  3 1  characters.) 

VARIABLES  return  the  address  of 
the  area  where  their  values  are  stored 
when  their  names  are  called.  The  address 
is  put  on  the  top  of  the  stack. 

Next,  of  course,  we  need  to  initialize 
the  variables: 

B000  INPUT.BUFFER  ! 

B400  OUTPUT.BUFFER  ! 

0  PTR  ! 

The  word  “!”  (pronounced  “store”) 
stores  the  value  on  the  TOS  into  the  ad¬ 
dress  which  is  in  the  second  position  on 
the  stack.  So  here  we  have  stored  B000  in 
INPUT.BUFFER  and  B400  in  OUTPUT.¬ 


BUFFER  without  having  to  worry  much 
about  where  the  value  is  located. 

Next  we  will  define  GETC: 

:  GETC 

INPUT.BUFFER  @ 

PTR  @  + 

C@ 

A  colon  (“:”)  is  the  FORTH  word 
which  starts  a  definition  of  a  new  word. 
A  semicolon  ends  the  definition. 

GETC  is,  of  course,  the  name  of  the 
new  word. 

INPUT.BUFFER  puts  the  address  of 
the  Input  Buffer  on  the  TOS. 

@  (pronounced  “fetch”)  is  the 
FORTH  word  which  takes  an  address  off 
the  top  of  the  working  stack,  and  replaces 
it  with  whatever  was  stored  at  that  ad¬ 
dress  —  the  actual  address  of  the  Input 
Buffer. 

PTR  puts  the  address  of  the  Pointer 
in  the  top  of  the  stack. 

@  pops  the  address  of  the  pointer  off 
the  working  stack,  and  pushes  the  con¬ 
tents  of  that  address  back  on  the  stack  — 
the  offset  into  the  buffers. 

+  (pronounced  “plus”)  takes  the  two 
top  numbers  on  the  stack,  adds  them,  and 
puts  the  result  back  on  the  stack. 

(At  this  point,  we  have  put  the  ad¬ 
dress  of  the  Input  Buffer  on  the  top  of 
the  stack,  then  pushed  the  address  of  the 
pointer  on  top  of  it,  replaced  the  pointer 
address  with  the  pointer’s  contents,  and 
added  the  contents  of  the  pointer  to  the 
beginning  address  of  the  Input  Buffer  — 
in  effect,  doing  an  offset  from  the  begin¬ 
ning  of  the  buffer.) 

C@  We  “fetch”  the  low-order  byte 
of  the  offset  address  in  the  Buffer,  and 
push  it  on  the  top  of  the  stack. 

PUTC  is  defined  very  similarly: 

:  PUTC 

OUTPUT.BUFFER  @ 

PTR  @  + 

C! 

Notice  that  I  have  been  very  careful 
to  leave  spaces  between  words  in  the  defi¬ 
nitions  —  spaces  are  just  as  significant  in 
FORTH  as  they  are  in  English  —  the  dic¬ 
tionary  look-up  routine  uses  spaces  as  de¬ 
limiters,  and  will  not  dig  PTR,  @  and  + 
out  of  “PTR@+”.  It  will  simply  reject  it 
as  an  error. 

C!  (“c-store”)  pops  an  address  off 
the  TOS,  and  stores  the  low-order  byte 
of  the  number  at  2nd  in  that  address. 

(Born-again  FORTH  programmers 
will  now  scream  in  chorus:  “But  there  are 


16 

148 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


LOTS  of  better  ways  to  do  that ! ! !”  This 
is  indeed  true,  but  I  am  deliberately  mak¬ 
ing  this  algorithm  follow  K  &  P’s  Ratfor 
examples.) 

Having  now  defined  GETC  and 
PUTC,  it  is  time  to  write  the  COPY  which 
appears  on  page  eight  of  Software  Tools 
in  FORTH,  but  first  we  need  to  define 
EOF: 

FF  CONSTANT  EOF 

CONSTANT  returns  the  value  stored 
in  it  when  it  is  invoked.  Every  time  we 
type  “EOF”,  the  CONSTANT  routine 
will  push  FF  onto  the  TOS. 

:  COPY 
BEGIN 
GETC 

DUP  EOF  =  0= 

PTR  @  400  < 

AND 
WHILE 
PUTC 
1  PTR  +! 

REPEAT 

BEGIN  .  . .  WHILE  .  . .  REPEAT  is  the 
FORTH  equivalent  of  the  <  while  >  con¬ 
struct  in  Ratfor.  It  works  by  testing  a  flag 
at  the  WHILE.  If  the  flag  is  True  (non¬ 
zero  in  most  FORTHs),  the  code  between 
WHILE  and  REPEAT  is  executed,  and 
the  program  loops  back  to  just  after  the 
BEGIN.  If  the  flag  is  False  (zero),  then 
the  program  exits  the  loop,  and  executes 
whatever  code  is  after  the  repeat. 

In  this  case,  we  GETC  to  put  a  value 
on  the  top  of  the  stack. 

DUP  duplicates  whatever  is  on  top  of 
the  stack,  so  that  TOS  and  2nd  are  now 
the  same.  We  duplicate,  so  that  we  can 
test  the  value  without  losing  it  —  this  is  a 
very  common  operation  in  FORTH. 

EOF  pushes  the  value  “FF”  on  the 
stack. 

=  (“equals”)  pops  the  two  top  values 
off  the  stack,  and  tests  them  to  see  if 
they  are  equal,  and  pushes  a  boolean 
value  back  on  the  stack.  If  they  are  equal, 
it  leaves  a  “1”,  and  if  non,  a  “0”. 

0=  (“zero-equals”  or  “not”)  pushes 
zero  on  the  stack,  pops  the  two  top  num¬ 
bers,  compares  them,  and  pushes  “1” 
(True)  if  the  2nd  number  was  0,  and 
pushes  “0”  (False)  otherwise. 

(The  next  line  checks  for  buffer  over¬ 
flow  —  FORTH  does  not  provide  this 
automatically,  and  we  must  provide  it 
for  ourselves.) 

PTR  @  gets  the  current  value  stored 
( Continued  on  page  20) 


A  SLIC  Label  Program 


i  was  finishing  a  fancy  maifing  list 
program,  with  keyed-access  files,  CRT 
masks  and  so  forth,  when  I  began  to  won¬ 
der  if  this  might  not  be  overkill.  All  I  real¬ 
ly  needed  was  a  sequential  file  of  names 
and  addresses,  plus  some  “selection 
codes”  to  categorize  each  entry.  Then  if  I 
had  a  program  to  read  the  entire  file 
and  print  labels  for  those  entries  with 
specified  codes  -  that  would  do  the  job! 

The  accompanying  listing  shows  this 
simple  mailing  list  label  printer.  The 
name  and  address  file  is  created  with  a 
standard  text  editor  (CP/  M’s  ED,  in  my 
case).  Each  entry  consists  of  a  name  line 
(last,  comma,  first),  one  or  two  address 
lines,  a  city-and -state  line,  a  zip-code 
line,  and  a  selection  code  line.  The  selec¬ 
tion  code  line  must  begin  with  a  space, 
and  it  may  contain  up  to  ten  code  num¬ 
bers  separated  by  spaces.  Entries  are  sepa¬ 
rated  by  one  or  more  “empty”  lines  (con¬ 
taining  return  and  line  feed,  under 
CP/M). 

The  use  of  a  sequential  file  and  an 
existing  editor  for  file  maintenance  means 
you  aren’t  stuck  with  a  fixed  record  lay¬ 
out.  For  instance,  if  you  must  switch  to 
9 -digit  zip  codes,  you  just  edit  the  file  to 
add  the  extra  digits.  You  can  also  store 
additional  information  after  the  code 
line,  say  a  phone  number;  additional  lines 
are  ignored  by  the  program  if  they  begin 
with  a  space.  The  main  formatting  re¬ 
striction  is  that  you  must  include  the 
code  line,  since  the  form  assumes  the 
line  before  the  code  line  is  the  zip  code, 
and  the  line  before  that  is  the  city  and 
state. 

Another  advantage  of  this  free- 
format  sequential  file  is  space-saving: 
short  entries  take  up  less  space  than  long 
ones.  With  the  usual  fixed-length-record 
programs,  all  entries  must  have  enough 
room  to  accommodate  the  longest  name 
and  address.  And  best  of  all  for  those 
without  disk  storage:  even  a  TRS-80 
Model  I  with  cassette  or  stringy  floppy 
can  use  this  program. 

The  major  disadvantage,  clearly,  is 
the  lack  of  order  within  the  file.  Labels 
are  printed  in  the  order  they  are  found  in 


by  Robert  Hallem 


Robert  Hallem,  RTG  Data  Systems,  1003 
Wilshire  Blvd.,  Suite  202,  Santa  Monica, 
CA  90401. 


the  file,  not  sorted  alphabetically  by 
name  or  numerically  by  zip.  To  find  a 
particular  name  you  must  use  your 
editor’s  “find”  or  “search”  command. 
But  if  you  don’t  need  sorted  output,  this 
is  a  good  way  to  go. 

The  program  is  written  in  SLIC,  a 
structured  language  I  wrote.  SLIC’s  big 
advantage  is  that  it  has  both  an  inter¬ 
preter  for  modification  and  debugging, 
and  a  compiler  for  speed  and  compact¬ 
ness.  The  interpreter  and  compiler  are 
largely  (but  not  yet  entirely)  compat¬ 
ible.  This  program  was  debugged  with  the 
interpreter,  then  compiled  (without 
changes)  for  speed.  The  compiled  version 
uses  less  than  7.5 K  bytes  of  memory,  in¬ 
cluding  the  4K  run-time  system,  plus 
some  stack  space. 

SLIC  syntax  is  quite  similar  to  C  and 
RATFOR,  so  translation  shouldn’t  be  too 
difficult.  SLIC  is  fully  documented  in 
“Structured  Programming  in  SLIC,”  avail¬ 
able  from  RTG  Data  Systems  for  $10. 
However,  I’ll  go  over  the  major  differ¬ 
ences  from  C  for  those  who  may  want  to 
do  the  translation. 

In  SLIC,  the  symbol  precedes 
each  function  name,  so  they  stand  out 
clearly.  Functions  may  normally  alter 
their  arguments  in  SLIC,  as  in  FORTRAN 
and  RATFOR.  This  eliminates  much  of 
the  confusion  caused  by  the  extensive 
use  of  pointers  in  C.  However,  an  expli¬ 
cit  call-by-value  is  possible  by  surround¬ 
ing  the  argument  variable  (in  the  call) 
with  parentheses. 

I/O  uses  built-in  functions,  and  the 
“ask”  and  “type”  statements  (which  are 
somewhat  like  INPUT  and  PRINT  in 
BASIC).  At  any  given  moment  there  is  a 
current  input  device  and  a  current  output 
device.  The  default  values  are  0  (the  key¬ 
board)  for  input  and  1  (the  video  display) 
for  output.  They  are  changed  with  state¬ 
ments  like  “type  #3;”  to  send  output  to 
the  printer  (unit  3),  or  “ask  #6;”  to  read 
from  the  file  open  on  unit  6.  Function 
“@ask”  reads  a  line  and  “@type”  outputs 
a  line. 

SLIC’s  “for”  loop  has  the  condition 
to  be  tested  in  the  third  position,  not  the 
second  as  in  C.  This  was  not  just  to  be 
difficult  —  it’s  a  bit  easier  for  an  inter¬ 
preter  to  scan.  (Compilers  don’t  care.) 
Also,  the  SLIC  “do”  loop  is  like  FOR¬ 
TRAN’S.  C’s  “do-while”  is  SLIC’s 
“repeat -until”. 

Of  course,  there  are  many  other  dif- 
( Continued  on  page  20) 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


17 

149 


A  Cassette  I/O  Routine 
for  BASIC  Arrays 


ne  of  the  main  disadvantages  of 
using  cassette  tapes  as  the  medium  for 
storing  programs  and  data  is  the  speed 
with  which  data  can  be  read  and  written. 
The  TRS-80  Level  II  records  data  on  tape 
at  about  500  baud,  and  can  therefore 
transfer  data  at  about  60  bytes  per  sec¬ 
ond.  For  each  block  written  to  tape  there 
is  a  preamble  consisting  of  256  bytes  of 
binary  zeroes,  requiring  about  4  seconds 
to  write  or  read.  Since  data  blocks  in 
BASIC  may  be  a  maximum  of  256  bytes 
in  length,  the  preamble  will  always  re¬ 
quire  at  least  half  of  the  total  data  tape 
processing  time.  For  very  short  data 
blocks,  the  proportion  of  time  spent  on 
the  preamble  may  well  be  over  90%. 

As  an  example,  a  two-dimensional 
array  is  to  be  stored  on  tape.  The  array 
consists  of  150  x  5  elements,  or  750  inte¬ 
ger  values  altogether.  Since  integer  values 
require  two  bytes  each,  the  array  will 
require  1500  bytes  plus  a  few  for  the 
definition  of  the  array.  If  5  elements  are 
written  in  each  tape  block,  then  150 
blocks  will  require  about  600  seconds,  or 
10  minutes  to  write.  The  format  for  the 
data  portion  of  each  block  is  the  same 
as  it  would  be  for  a  screen  display,  in 
other  words  expanded  to  decimal  form 
with  room  for  a  sign  and  a  trailing  blank 
for  each  value,  but  with  a  comma  as  de¬ 
limiter  between  the  values.  The  5  values 
will  therefore  require  from  3  to  7  bytes 
each,  plus  4  commas,  giving  between  19 
and  39  bytes  depending  on  the  number  of 
significant  digits  in  each  value.  Assuming 
an  average  of  30  bytes  per  block,  or  4500 
data  bytes  in  all,  the  data  alone  will  re¬ 
quire  about  75  seconds  to  write.  The  pre¬ 
ambles  take  almost  90%  of  the  total  tape 
time  of  675  seconds,  assuming  no  pauses 
are  needed  between  the  blocks.  If  the 
data  could  be  written  in  its  original  form 
with  the  1500  data  bytes  written  as  one 
large  block,  then  only  4  seconds  would  be 
required  for  preamble  and  about  25 
seconds  for  data,  giving  29  seconds  in  all. 
The  standard  TRS-80  method  takes  more 
than  23  times  as  much  time  as  our  hypo¬ 
thetical  method  would  take.  Savings  of 
this  dimension  can  at  least  be  considered 
significant! 

When  string  variables  are  written  to 

by  Arne  Rohde 

Arne  Rohde,  Pilevej  31,  7600  Struer, 
Denmark. 


tape  with  the  PRINT  statement,  the 
variables  must  not  contain  quotes,  com¬ 
mas,  or  colons,  since  these  will  be  treated 
as  delimiters  when  the  tape  is  read,  nor 
may  they  contain  leading  spaces  since 
these  will  be  removed  when  they  are  read 
from  tape.  All  except  the  quotes  can  be 
accepted  if  the  variable  is  extended  with  a 
leading  quote  (ASCII  value  34)  before  the 
string  is  written  to  tape.  A  trailing  quote 
is  not  required,  unless  other  data  values 
follow  the  string  in  the  same  data  block. 
The  final  value  in  a  block  will  be  termi¬ 
nated  with  a  carriage  return  control  char¬ 
acter.  The  method  can  be  illustrated  as 
follows: 

10  Q$=CHR$(34) 

250  PRINT  #-l,Q$;A$ 
where  A$  is  the  string  which  may  contain 
commas,  colons,  or  leading  spaces.  The 
remaining  problem  of  the  quote  could 
also  be  solved  if  it  were  possible  to  write 
the  strings  to  tape  without  the  need  for 
delimiters  between  the  variables. 

Another  problem  with  the  normal 
tape  I/O  method  is  that  no  checksum  or 
any  other  control  character  is  written  in 
the  block,  resulting  in  I/O  errors  being  ac¬ 
cepted  without  any  possibility  of  check¬ 
ing  the  validity  of  the  data.  Since  tape  is 
a  relatively  unreliable  medium,  no  I/O 
should  be  performed  without  any  means 
for  a  validity  check.  I  realize  that  BASIC 
programs  are  written  without  a  check¬ 
sum,  but  I  also  consider  this  to  be  a  de¬ 
sign  flaw! 

These  factors  which  had  long  an¬ 
noyed  me  and  restricted  the  type  of  pro¬ 
grams  I  could  reasonably  run  on  a  tape- 
based  system,  motivated  me  to  find  a 
solution  and  write  a  routine  which  could 
cure  most  of  the  ills.  I  realize  that  one  or 
two  of  the  utility  programs  advertised  in 
the  microcomputer  magazines  state  that 
they  have  array  I/O  routines,  but  living 
in  Denmark  naturally  restricts  one  in  the 
possibility  of  trying  and  buying  software. 
I  have  never  tried  any  of  these  utilities, 
and  have  no  idea  how  they  implement 
these  functions.  Also,  none  of  the  maga¬ 
zines  I  have  read  has  contained  a  routine 
which  could  be  used. 

In  order  to  construct  a  routine  which 
will  read  or  write  arrays  in  BASIC,  it  is 
necessary  to  know  how  array  data  is 
stored  in  a  program.  Immediately  follow¬ 
ing  the  source  program  in  memory, 
BASIC  stores  information  concerning  all 
variables  and  arrays  defined  or  referenced 
in  the  program.  All  simple  variables  are 


stored  first,  followed  by  array  variables. 
There  are  three  pointers  in  reserved  mem¬ 
ory  which  are  useful  for  referencing  this 
area.  The  first,  at  40F9  and  40FA,  points 
to  the  start  of  the  variable  storage  area. 
The  next,  at  40FB  and  40FC,  points  to 
the  end  of  the  simple  variables  and  the 
beginning  of  the  array  area.  The  address 
at  40FD  and  40FE  is  the  end  address  of 
the  array  area.  A  consequence  of  this 
storage  method  is  that  arrays  must  be 
moved  in  memory  when  a  new  simple  var¬ 
iable  is  defined  or  referenced. 

Since  we  will  be  concerned  only  with 
arrays,  we  shall  look  at  the  method  for 
storing  arrays.  Numeric  and  string  arrays 
are  stored  differently,  although  the  meth¬ 
ods  are  very  similar.  The  first  byte  of  the 
array  area  defines  the  type  of  array  varia¬ 
ble  —  integer,  single  or  double  precision 
real,  or  string.  This  definition  consists  of 
the  number  of  bytes  needed  for  storing 
each  element  in  the  array.  The  values  are 
2  for  integer,  3  for  string,  4  for  single 
precision,  and  8  for  double  precision.  The 
next  two  bytes  are  used  for  the  array 
name,  without  any  type  qualifier  (%,  #, 
!,  or  $)  since  this  is  already  implicit  in  the 
value  of  the  first  byte.  The  name  is  stored 
with  the  least -significant  byte  first,  with 
zero  if  a  one-character  name  is  used.  The 
next  two  bytes  contain  the  length  of  the 
area  required  for  storing  the  array,  ex¬ 
cluding  the  first  5  bytes  of  the  definition 
area.  The  next  byte  is  the  number  of 
array  dimentions,  from  1  to  255.  For 
each  dimension,  two  bytes  are  used  to  in¬ 
dicate  the  number  of  elements  in  that  di¬ 
mension.  This  value  will  be  one  greater 
than  that  used  in  the  DIM  statement.  The 
following  area  contains  2,  3,  4,  or  8  bytes 
for  each  of  the  elements  in  the  array.  For 
numeric  arrays  these  bytes  contain  the 
actual  values  of  each  variable,  for  string 
arrays  the  first  byte  contains  the  length 
of  the  string  and  the  next  two  bytes  the 
address  of  the  first  byte  of  the  string.  The 
array  definition  for  an  array  defined  as 
DIM  A%(2)  would  be  as  follows: 

02  0041  0900  01  0300  0000  0000  0000 
where  02  is  the  type  (integer),  0041  the 
name  (A),  0900  the  remaining  length  of 
the  definition  (9),  0300  the  number  of 
elements  in  the  first  dimension  (3,  since 
subscripts  0,  1,  and  2  can  be  used),  and 
the  following  zeroes  are  the  values  of 
each  element  on  the  array. 

For  string  values,  the  address  pointer 
can  point  to  a  position  in  the  string  area 
(defined  with  the  CLEAR  n  statement)  or 
to  a  point  within  the  BASIC  program.  If 


18 

150 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


a  string  is  assigned  a  value  with  a  READ 
statement  or  assigned  to  a  literal  then  the 
pointer  will  point  to  the  original  string 
definition  in  the  program  and  the  string 
will  therefore  not  take  up  space  in  the 
string  area.  However  if  a  string  array  is 
written  to  tape  and  then  read  into  the 
program  from  tape,  then  every  string  in 
the  array  will  be  stored  in  the  string  area. 
The  need  for  string  storage  may  thus  of¬ 
ten  be  considerably  greater  when  strings 
are  read  in  from  data  tapes.  This  factor 
must  be  taken  into  account  when  tape 
storage  is  used  for  string  arrays,  or  for 
other  string  variables. 

The  array  I/O  routine  as  implement¬ 
ed  is  written  in  machine  language,  and  is 
resident  in  the  top  of  memory.  Calls  to 
the  routine  are  through  the  USR  inter¬ 
face,  with  a  single  POKE  required  when 
changing  from  a  read  to  a  write  and  vice 
versa.  Read  and  write  functions  are  con¬ 
tained  in  the  same  program,  requiring  less 
than  300  bytes  in  all.  It  can  handle  all 
types  of  arrays,  with  any  number  of 
dimensions  in  each  array. 

Since  the  USR  call  only  allows  the 
passing  of  a  single  2 -byte  parameter  to 
the  called  routine,  an  extra  POKE  must 
be  made  to  distinguish  between  a  read 
and  a  write  function.  The  parameter 
passed  to  the  routine  is  the  address  of  an 
element  in  the  array  to  be  read  or  writ¬ 
ten.  Arrays  to  be  read  must  therefore 
have  been  defined,  either  by  DIM  or  by 
reference,  before  the  read  routine  is 
called.  The  routine  also  returns  a  value  to 
the  calling  program  indicating  whether 
the  read  or  write  was  successful  or  not. 
The  definition  of  the  array  to  be  read 
must  be  identical  to  the  definition  of  the 
array  written  to  tape  as  concerns  variable 
type,  number  of  dimensions,  and  number 
of  elements  in  each  dimension.  Partial 
arrays  cannot  be  read  or  written,  and  a 
separate  block  is  used  on  tape  for  each 
array. 

The  routine  is  constructed  so  that 
the  entry  points  for  write  and  read  are  at 
7F00  and  7F08  respectively  for  a  16K 
system.  This  gives  the  commands  POKE 
16526,0  and  POKE  16526,8  before  each 
write  or  read  if  the  MSB  of  the  USR  ad¬ 
dress  is  left  unchanged  during  execution. 
A  typical  sequence  for  writing  an  array  to 
tape  would  be  as  follows: 

220  PRINT  “MOUNT  TAPE  WITH 
RECORD,  HIT  ANY  KEY” 

230  IF  INKEY$=“”  THEN  230 

240  POKE  16526,0:  IF 

USR(VARPTR(array  element)) 


PRINT  “ARRAY  WRITE 
ERROR”:  STOP 

where  (array  element)  is  a  reference  to 
any  element  in  the  array  to  be  written, 
typically  element  zero.  The  value  re¬ 
turned  by  the  routine  is  -1  if  an  error  is 
found,  else  zero.  The  IF  statement  can 
thus  be  coded  as  shown,  recalling  that 
-1  is  the  value  for  true  and  0  the  value  for 
false.  The  only  possible  error  for  a  write 
is  that  the  parameter  passed  to  the 
routine  does  not  point  to  a  byte  within 
an  array  definition.  The  cassette  used  for 
writing  will  be  the  on-board  cassette,  al¬ 
though  this  could  easily  be  changed  if 
necessary. 

The  procedure  for  reading  a  numeric 
array  is  very  similar  to  that  for  writing 
an  array.  The  following  could  be  used: 

320  PRINT  “MOUNT  TAPE  WITH 
PLAY,  HIT  ANY  KEY” 

330  IF  INKEY$=“”  THEN  330 

340  POKE  16526,8:  IF 

USR(VARPTR(array  element)) 
PRINT  “ARRAY  READ 
ERROR”:  STOP 

where  the  parameters  used  are  as  for 
write.  The  procedure  for  reading  string 
arrays  is  more  complicated,  since  the 
maximum  space  possible  should  be  made 
available  in  the  string  area  before  the 
array  is  read.  The  read  routine  does  not 
have  time  during  the  read  process  to  initi¬ 
ate  and  wait  for  a  string  compress,  and 
this  should  therefore  be  done  by  the 
BASIC  program  before  the  read  routine  is 
called.  The  maximum  area  is  made  avail¬ 
able  by  assigning  each  element  in  the  ar¬ 
ray  to  be  read  to  a  null  string,  and  then 
calling  the  FRE  function  to  force  a  string 
compress.  The  reassignment  is  only  re¬ 
quired  if  the  array  has  been  used  previ¬ 
ously.  The  initial  process  could  be  coded 
as  follows: 

300  FOR  I%=0  TO  AM%:  A$(I%)= 
“”:NEXT  1% 

310  IF  FRE(“”)<  minimum  PRINT 
“INSUFFICIENT  STRING 
AREA”:  STOP 

for  a  single-dimension  string  array  A$, 
where  AM%  is  the  DIM  value  used  for  the 
array.  The  lines  following  310  are  identi¬ 
cal  to  those  used  for  a  numeric  array 
read. 

A  number  of  error  conditions  are 
possible  when  reading  arrays: 

a)  The  value  passed  to  the  routine  does 
not  point  to  an  array  element. 

b)  The  array  definitions  on  tape  and  in 
memory  are  different.  Only  the  names 
may  differ. 


c)  A  checksum  error  occurred  during  the 
read. 

d)  There  was  insufficient  string  storage 
area  available. 

Since  the  routine  uses  the  Level  II 
ROM  routines  for  tape  I/O,  two  asterisks 
will  appear  in  the  upper  right  comer  of 
the  screen  when  a  block  header  has  been 
found.  If  the  tape  read  is  successful,  these 
asterisks  will  be  cleared  from  the  screen 
before  returning  to  the  BASIC  program. 
Any  data  contained  in  these  positions  will 
be  lost.  No  blinking  of  the  asterisks  will 
occur,  even  for  very  long  arrays. 

Since  I  did  not  have  an  editor/ 
assembler  at  the  time  the  routine  was 
written,  the  routine  was  hand-coded  and 
converted  to  machine  code.  It  is  entered 
into  memory  with  a  BASIC  program  con¬ 
taining  the  hexadecimal  values  of  the 
bytes  to  be  entered.  The  routine  can  easi¬ 
ly  be  relocated,  with  only  a  few  minor 
changes  in  the  program.  The  entry  pro¬ 
gram  calculates  the  relative  jump  values 
and  the  addresses  of  the  branch  points 
used  in  the  program.  A  similar  concept 
has  been  used  in  a  MACROPOKE  moni¬ 
tor  by  Larry  Suter  ( 80-Microcomputing , 
April  1980),  although  the  one  shown  here 
is  easier  to  use  when  segments  are  to  be 
entered  in  different  portions  of  memory. 
The  program  will  check  whether  suffi¬ 
cient  storage  has  been  reserved  for 
machine-language  code,  and  will  reserve 
space  if  none  has  been  reserved.  It  is 
therefore  not  necessary  to  answer  the 
MEMORY  SIZE  message  with  any  speci¬ 
fic  value. 

A  few  comments  on  the  format  of 
the  machine  code  DATA  entries  may  be 
needed.  Each  DATA  statement  contains 
3  string  values,  each  of  which  may  be 
null.  The  first  is  the  hexadecimal  address 
where  the  code  on  the  line  is  to  be  en¬ 
tered.  If  null,  the  code  will  follow  imme¬ 
diately  after  the  previous  line.  The  ad¬ 
dress  should  be  entered  for  the  first  line 
of  each  segment.  The  second  value  is  an 
optional  one-character  label  which  can  be 
referenced  in  the  code  portion  of  the  rou¬ 
tine.  All  ASCII  characters  are  valid  labels, 
except  those  recognized  by  BASIC  as  de¬ 
limiters  (quote,  comma,  and  colon).  The 
third  string  is  the  actual  hexadecimal 
code  to  be  entered,  with  the  following 
extension.  Spaces  may  be  used  to  sepa¬ 
rate  bytes  to  improve  legibility,  as  in  the 
listing  where  a  space  is  used  to  separate 
each  of  the  instructions.  Each  byte  must 
be  written  as  two  characters,  leading 
zeroes  may  not  be  omitted.  If  the  first 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


19 

151 


character  is  an  R  (for  relative  jump  value) 
then  the  following  character  must  be  the 
label  of  the  byte  to  be  jumped  to.  If  the 
first  character  is  a  W  (for  word  address) 
then  the  following  character  is  again  a 
label.  The  next  two  characters  must  be 
hexadecimal,  and  are  interpreted  as  a  one- 
byte  two’s  complement  displacement 
from  the  label.  WLOO  would  be  the  ad- 
ress  of  the  label  L,  WL05  the  address  +  5, 
and  WLFB  the  address  -  5.  The  DATA 
statements  are  read  in  two  passes,  the 
first  to  resolve  the  label  values,  and  the 
second  to  POKE  the  values  into  memory. 
A  listing  of  each  label  used  is  given  in  the 
first  pass  for  control  purposes.  Error  mes¬ 
sages  may  be  listed  for  various  error  con¬ 
ditions. 

The  assembler  language  routine  may 
also  need  a  few  comments.  The  labels 
WRTARY  and  RDARY  are  entry  points 
for  array  write  and  read  respectively. 
Each  of  these  calls  the  routine  ARAYA 
which  finds  the  start  and  end  addresses 
of  the  array  to  be  written  or  read.  The 
cassette  will  also  be  switched  on,  ready 
for  write  or  read  commands.  In  the  read 
routine,  the  first  6  bytes  are  read  from 
tape;  these  bytes  are  the  first  6  array  defi¬ 
nition  bytes.  All  except  the  array  name 
portion  is  compared  with  the  definition 
of  the  target  array  definition.  If  these  are 
equal,  the  remaining  array  bytes  are  read 
directly  into  the  array  area.  Numeric  ar¬ 
rays  only  need  the  checksum  to  be  read 
after  all  the  data  bytes  have  been  read. 
String  arrays  require  a  reference  to  the 
length  of  each  string  and  must  update  the 
string  address  pointers  to  the  new  address 
where  each  string  will  be  stored.  BYPLN 
will  bypass  the  dimension  length  codes  in 
the  array  definition,  and  point  to  the 
definition  of  the  first  element.  Address 
40A0H  contains  the  address  of  the  first 
byte  reserved  for  string  storage  (the  low¬ 
est  address)  and  40D6H  one  less  than  the 
last  byte  used  for  previous  strings.  Strings 
are  stored  starting  at  the  highest  available 
address,  so  the  pointer  in  40D6H  must  be 
reduced  for  each  string  stored.  If  the 
string  length  was  zero,  then  no  bytes  are 
read  from  tape  for  that  string,  otherwise 
up  to  255  characters  will  be  read  for 
each  string,  until  all  strings  in  the  array 
have  been  read.  The  checksum  is  then 
read  and  checked,  and  the  two  asterisks 
cleared  from  the  screen. 

The  array  write  routine  writes  the 
first  6  definition  bytes  followed  by  a 
pause  to  allow  time  during  input  for  the 
comparison.  The  remaining  part  of  the 


array  area  is  then  written.  For  string  ar¬ 
rays  this  is  followed  by  the  string  data  for 
each  string  with  non-zero  length.  A  pause 
is  left  before  each  string  to  allow  for  ad¬ 
dress  calculation  on  input.  Finally  the 
checksum  is  calculated  and  written,  and 
the  cassette  switched  off  before  returning 
to  the  calling  program. 

The  routine  ARAYA  is  used  to  step 
through  the  array  definitions  until  the 
required  array  has  been  found.  The  rou¬ 
tine  called  by  RST  18H  is  used  several 
times  to  compare  the  values  in  DE  and 
HL,  but  unfortunately  the  value  in  HL  is 
not  saved  by  this  routine. 

The  program  should  be  easy  to  relo¬ 
cate  to  another  address  if  required,  since 
the  BASIC  program  takes  care  of  all  the 
instructions  with  direct  address  refer¬ 
ences.  The  values  which  will  have  to  be 
changed  are  the  ones  which  check  for  and 
set  the  memory  size,  and  the  two  address 
values  in  the  DATA  statements  for  the 
two  code  segments.  The  USR  call  address 
will  automatically  be  changed,  as  will  all 
the  absolute  JMP  and  CALL  instructions. 
The  routine  is  not  intended  for  use  with 
DOS  systems,  although  it  could  be  modi¬ 
fied  to  cater  for  this.  The  usual  408EH 
address  vector  for  USR  has  been  moved, 
so  DEFUSR  could  be  used  instead,  or  the 
two  addresses  could  be  set  in  the  BASIC 
routine.  Also,  interrupts  should  be  dis¬ 
abled  during  the  tape  I/O  process. 

The  enclosed  listings  show  the 
BASIC  program  used  to  enter  the  routine 
into  memory,  and  a  listing  of  the  program 
in  Z-80  assembler  format.  Unfortunately 
the  TRS-80  assembler  does  not  allow 
labels  to  be  defined  on  separate  lines,  so 
they  have  been  defined  with  an  EQU  $ 
statement.  I  prefer  labels  on  separate 
lines  for  easing  insertions  and  deletions 
at  a  later  stage. 

Hopefully,  these  routines  can  make 
cassette  tapes  a  realistic  medium  for  stor¬ 
ing  data  in  BASIC  programs. 


Algorithms  in  FORTH 

(Continued  from  page  1 7) 

in  the  pointer. 

400  <  compares  that  value  to  400 
and  leaves  a  True  if  it  was  3FF  or  less. 

AND  pops  the  two  top  numbers  off 
the  stack,  does  a  bit-by-bit  Logical  AND 
on  them,  and  pushes  the  result  back  on 
the  stack. 


(At  this  point,  the  Top  Of  the  Stack 
has  a  boolean  value  in  it  —  if  the  charac¬ 
ter  returned  by  GETC  was  not  equal  to 
EOF,  and  the  contents  of  PTR  are  less 
than  400  Hex,  it  is  a  “1”,  or  True.  Other¬ 
wise  it  is  “0”,  False.) 

WHILE  tests  the  top  of  the  stack, 
and  if  it  finds  a  “1”,  it  goes  to  PUTC,  be¬ 
low.  If  WHILE  finds  a  “0”,  the  program 
ends,  and  whatever  is  after  REPEAT  is 
executed. 

PUTC  takes  the  value  returned  by 
GETC,  and  puts  it  in  OUTPUT.BUFFER 
at  the  offset  pointed  to  by  PTR. 

1  PTR  +!  adds  1  to  the  contents  of 
PTR  -  it  increments  the  pointer,  so  that 
it  points  to  the  next  character  in  the  buf¬ 
fer. 

The  program  now  loops  back  to 
GETC  to  fetch  another  byte  for  testing. 

If  nothing  follows  REPEAT  when 
the  test  at  WHILE  branches  out  of  the 
copy  program,  the  FORTH  system  re¬ 
turns  control  to  the  terminal,  prints  out: 

OK 

and  waits  for  further  instructions. 

Next  issue,  I  will  show  how  to  code 
K&P’s  Counting  programs  from  pages  12- 
18  of  Software  Tools. 


A  SLIC  Label  Program 

(Continued  from  page  1 7) 

ferences  between  SLIC  and  C.  I’ve  just 
mentioned  the  ones  I  feel  are  most  like¬ 
ly  to  confuse  the  C  programmer  reading  a 
SLIC  program. 

For  those  who  appreciate  the  advan¬ 
tages  of  a  structured  language  interpreter, 
SLIC  is  available  in  several  forms:  A 
DISK  SLIC  interpreter  and  SLIC  compil¬ 
er  for  CP/M  systems.  TAPE  SLIC  for  the 
TRS-80  (Model  I,  Level  II,  16K)  is  on 
cassette.  That’s  the  interpreter  only,  no 
compiler.  Write  to  me  for  information. 
The  TAPE  SLIC  interpreter  is  also  avail¬ 
able  on  stringy  floppy  wafer,  directly 
from  Exatron,  181  Commercial  St., 
Sunnyvale,  CA  95051. 

As  for  that  fancy  mailing  list  pro¬ 
gram  with  keyed -access  files,  I  finished  it 
anyway  so  I  could  test  the  keyed-access 
routines.  Works  pretty  well,  too,  but  it 
really  gobbles  up  disk  space  with  those 
fixed -length  records! 

(LISTING  ON  PAGE  36)  ■  ■ 


20 

152 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


Since  1976,  the  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 


Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


YES!  Enter  my  subscription  to  Dr.  Dobb's  Jour- 

ml  and  bill  me  later. 

$25 

name 

one  year  subscription 

12  issues 

saves  $5  off  the  newsstand  price 

address 

city  state  zip 

Mail  to:  DDJ,  P.O.  Box  E., 

Menlo  Park,  CA  94025 

4* 


U  u 

*•3  0  »- 

0-0-0  O  • 

o  4*  . 

»•  -O  M  .  u 

*004*  »  - 

a  4»  r  3  * 

Co.  Q. 

3  •  I-  C  «4 

C  u  O  -*4  o  - 

C  U 

3  f  O  **  U  » 

(-  3  «  -i  «  . 

6  •  «  (.  o 

4*  H  X>  -H  i  fr. 

o  «  u  €  -o 

•  8  0  0  3  -o 

4*  8  4*  -o  c  m  ■ 


■  ■  > 

•  o 

W  «  • 


%- 

o  o 

*  8 

C 

•  o 


•  **  O  *  »  «  ^  i  O  «4  I  H 

'  •  •  **  W  •  -  0.4*  .  a.  * 

v«rcvuu)uu« 


Ojc-o  *  Ch  8  o  a  >ji  • 
^  O  »  •  *  .  a  •< 

OMNouulfww' 


f O  -0«-0-0(-A(.-0-0 
'  -«  U  *4  O  *  -*  >H  *4 


!2  «  u  2  3  *2222221 


^  -o  £ 

22225§23S52325^!jJJj;;;5»^"5!SSKSS;R!:S;33S5i555g 

OOOOOOOOO  O OOOOOOQQOQQpQQ Q  Q  Q  Q q q O  Q  Q  Q  Q  Q  Q  q ^ ^ ^ h  h  h  h h h h h h ^ ^ ^ ^ ^ 


sisiis  sslsllsi  sssisil  ||||si||||  ss^-g* 

2  =  8§|  =  SiSl  =  !!!§SSS§e^inii!§0!iSS?!ajl!gisai  Hgtfisfi® 

S»8»SBSBSS^2»!S!sB2K»S22»»R  ssssssss 

o  ooo  ooooooooooooooooooooooooooooo  SSSSSSS 


OBIllOOIt  N 
N  N  N  00  03  CD  OD 

4  H  *4  H  H  H  H 

O  O  O  O  O  O  O 


•  »  U 

k  04*  I 
•  Oh  «  o 


•CO  |« 

•H  •  O  H 
■  <  4»  *  O 


♦»  <  4»  I. 

•  *  •  I  M  O  U. 

O  O  >  O  O  U  «  4»  O 

«-*4w>  8  U  U  4* 

•J  U  -*  (-  O  O  u 

»  C  O  c  4*  8 

H4*4»4  4  4*  4* 

a  ■*«  8  4*  4*  4*  84*  8  4* 

3C-H»8t48-!<S 

•  ®^**>^4*4h4h, 


«  o 

u  «  u  (► 
OOOO 

- 

n 

0 

76 

1 

26 
12E 
•  bp 

01 

•4  O 

3  3 
o'  o’ 

•  • 

3  3  3  3 

O'  O’  O’  O' 

OOOO 

3 

O' 

o 

nb» 

3  3  3  3  3  3 

O'  O’  O'  O’  Of  O' 

3 

* 

O 

3  3 
O'  or 

o  o 

4* 

*■ 

4 

«•»  *4  *4 

O 

> 

> 

g) 

(.  > 

1  O 

-O 

1- 

u 

(.(•  0  0  0.0. 

-*4 

•  • 

H  A 

(■  o-  %■  0 

O 

o 

4*  4*  O  •  A  A 

>  ^ 

u  1  - 

«  g  h  4  4>  ^  « 

• 

• 

-  o  o 

;2«22222£2£SS88!58;$!5B&8SB!2!JE:8E:fi2:o’-t'in*,''0,'®®‘2-(»n* 

:88888888888888SS88S8888888g8§S§l8iiliiiiiiiii 


o 

* 

8 

1 

u 

o 

§ 

n 

o 

*4 

o 

*4 

o 

22 

154 


Di.  Dobb’s  Journal,  Number  54,  April  1981 


*-  c 

O  V  o 

(-  •  u 

(-  4»  o- 

•  •  c  u 

■HO* 

•  *4  4»  • 

U  •  C  *h 

c  •  u  o 

ja  o  t-  m 

•  (-  a  c 

4»  (-  o 

•  o  •  •  u 

•  c  c 


>  H  r  3  o 

•  —  3  I-  I  C 

<0340  u 

-  — .  ~  -  n 

U  5  90 

4*  O  (-  ♦* 

•  4*  t  « 

4*  «  3  4* 

■O  h  4*  If  T> 


c 

O 

0- 

(- 

4* 

c 

• 

n 

• 

u 

4* 

(•  c 

o 

4* 

•  (- 

o 

hh  m 

4* 

•  c 

a  • 

a 

m  a 

4* 

a  (. 

O  4* 

u  » 

« 

o 

4» 

o 

-*4  M 

a 

•  4» 

9  O 

4» 

a 

H  4* 

a  a 

to 

4» 

o  « 

« 

a  « 

(- 

• 

•  4* 

4» 

«  a 

•o  « 

« 

> 

• 

■n 

'S'-. 


4*  (.  4» 

«  O  * 

4*  4»  4*  C 


9  M  C  . 

I'  C  (vfl  *»  M 


■  (-  a  (.  «  «  (. 


a  «  ».  «  < 

U  U  “»  H  . 


-wot  r-osoa-OH 

nnnnnnnnnIo 

H  H  H  H  H  H  H  H  H  *4  H 

ooooooooooo 


SSS£S£SS?»??JS^^§388SS 

oooooooooooooooooooooooo 


§§2!§9!2£!5!2555Nf3r3r3r3r3r3oi88rSr5r! 


>0000000000 


SS  S  S  SS  O 

(M  uj  n  o  o  <0  u.  ^  <  AuiyiMVNHBn 
u  <<oosnuoH  op-soo-n 
•h  O  UJ  CD  Ul  *  O  UJ  Of  ~  a  UJ  CD  UJ  O  UJ  w  CD 
Hou.rtu.oNnn  Hou.rtu.rtnnH 

SSIfc;:???** 

ooooooooo  ooooooooo 


N  <Q  <t  01  (B  II 
NOUOhJ 

Ui  <  o  UJ  rt  09 
yortnnH 

♦  <  (MB  Q  O 

■BBBBU 

H  H  H  H  H  H 

o  o  o  o  o  o 


o  o  o  3  S  pSJooS  < 

nnthnHoynuuiHQnBiijfiui^^. 

o*?^$OHnO'OoOHf)pHS«^oi 

^oiuouioi^Dujoujoi^arM*HO<ouj( 

HoyrtnnHourtnnHonHOQui 


rtoo<oy HtN^aQoi 

OUOOOOOQOOOOUJI 

OOOOOOOOOOOOOl 


I^Ulinn 
I  UJ  UJ  UJ  u.  u. 

I  f<  *4  •<  H  N 

I  o  o  o  o  o 


*•  %»  (-  4*  m 

«  «  m  *4* 

C  >  i  « 

u  9  m  »  i  o 

4  O  (.  J>  «J>  •  I  4» 

u  4»  O  4»  C  m  a  I 

«  U  f  -*4  4*  4B 

4»  •  I  •  O  4=  C  >  • 

a  *h  4*  o  h  (. 

4*  4*  4»  ^  H  J.  4* 

C  C  C  o  •  X)  T) 

•  t  •  •  4>  C  •  4* 

H4*  Ji 

(-(.(.4*  •  %>••(. 


l  j*  m  m  *  t-  a 

•  4*  j-  a  u 

>  I-  O  I  •*« 

I-  O  *0  I-  *H  > 

I  O  4>  •  (.  • 

4*  U  •  •  «  TJ  -M 

u  •  8  -*  u 

•  •  •  4>  «  4»  O 

•  (-  C  C  •  ■ 

•  U  ■*«■*«•** 

19  0*C  J-  8  —  O 

1  ^  C  3  -*«  a  4-  C  - 

I  C  II  I  •  C  I 

*  o  o-i  o  4*  o  6  - 


o  o  o  o  o 


u 

•  c 

%■  m 

>  J*  U  a  <-4 

(-(-•30 


(-(-•• 
4*  4»  *  4* 


ihOHrtntO'OMDihOHrtntO'ONBi’OHrtntoiNo^OHrtntO'ONgja'QHrtntO'OMp^OHrt  n  * 

B^^'O-O-O'OO^'ONNNShNNNNNafflOaKDmCDmfiaUh^a'MMha-IMhfrOOOOOOOOOOHHH 

88888888888888888888888888888888888888888S000S00000000 So 


oSooS 

H  H  H  H  H 

o  o  o  o  o 


O  Oi  *■  o 

H  H  H  H 
*4  ^  *4  H 

o  o  o  o 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


(Continued  on  top  of  page  22)  I  (Continued  on  next  page , 


*  (•  a-H 

E  *- 

*>  «  3  3 

c  c  -»  *  m 

•*<  -*4  *  4  4* 

f>  4  o  o  m 

Ol.  3  C  9  -D 

•»  t  •»  ■*  .* 

o  o  n-o 

4>  ©  4-  »- 

Q.  4  P  4-  (- 

Eft  4  3  ft  < 

u  t-  P  J»  6 


4  U  3  .  ..  . 

£  V  i)  A  «  «  n 


~  4  * 

-«  T3  J*  4> 

*-  -  *-  4 

P  ^  4>  4  P 

w  jc  w  -OT5 

»  (•  »  ^  *  « 

**-*->—  ,  -H  U 

•o  t>  ~  .c  (f  x:  C 


•»4  01 

P 

E  ~  4  T> 


*  ■»  *-  *-  *0-0  4’ 

U  •-«  O  ”*  9-4  —«  u  • 


C  TJ  T3  (-  A  a. 

■H  H  H  O  *  -* 


■o  C  "O  TJ  «  v  V 


a>£o*4Nn*n-oNa>(ho~ra 

535555nnnnnf'f'nn 

ooooooooooooooo 


w  ^  «o 

2«ESt:82:2^!)!!2!S5,Sr;l2,5:Prn,n»lo-0,'®(>'0',™n»n<NODo-o-.M 

RSSS22S22C5C255np)nP5P)nn|,Jnnnnnp)p)nnSSnnSSSn 

oooooooooooooooooooooooooooooooooooooooo 


210010 

U002A 

010E09 

CD1F04 

3A1C01 

B7 

28  IE 

210044 

1 14C09 
CDB303 
210010 

1 16809 
CD8703 
210010 
110044 
012B09 
CD1F04 

EDSB080 

13 

ED53080 

2A1201 

B7 

ED52 

D2A102 

ED4B030: 

03 

ED43030: 

219B07 

CD7A0A 

ED4B0301 

21AA07 

CD7A0A 

119307 

0E09 

CD0500 

3A1A01 

B7 

2806 

«  Q  0  n  o  O'  < 

OOOOOOO 

0  u.  ry  n 
u.  u.  o  o 
ry  ry  n  n 
0000 

0308 
030B 
030E 
031 1 
0314 
0317 

<  uj  u.  n  o  n  ^ 

~  ~  -  ry  ry  ry  ry 
n  n  n  n  n  n  n 

OOOOOOO 

‘r>o^j>QDmitryn©<Qo- 

nnnnnnnnnnonnn 

OOOOOOOOOOOOOO 

r- 

C 

p 

4 

■94 

C  P  3 

> 

4 

^  C  a 

■*4 

Ol 

4  4  P 

u 

4 

«  •  3 

ECO 

•a 

9 

^■ 

at 

"O 

u 

M 

4 

u 

O 

p 

u 

m 

*-4  0 

p 

% 

4 

u 

P  4  4. 

u 

50 

*. 

4 

*  0 

4 

0 

P 

(- 

4  P 

^4 

c 

P 

«  4  4 

4 

fr. 

4 

*-  >  E 

4 

■94 

M 

9-4 

•  -«  *- 

4. 

^4 

H  *.  O 

c 

c 

4 

50  %• 

u 

0 

0  * 

O 

■94 

u 

■94  P 

P 

0  4  0 

4- 

P-94 

4 

4*  >  4 

c 

p 

-4  E 

4 

-  4  ^ 

0 

0 

P 

n.  ?  * 

4  u 

c 

■^^4 

- 

■c  o  u  4  u 

4*  -P  4  J.  4 

*-  p  (- 

4-4  4*  P 

OP  P 

C  4.  4  p 

4  O  (.  P  4 

-<  1  -«  •*  4 

4  4  4-  P  ~4  . 

(-at  44 

4  4  C  *-  4  >  »- 

4  4  4  4  P  4  4  • 

3  3  *-  P  4  P 

II  C  O  ..  c 

9  C  4  P  4  • 


t'  4*  ,  p  • 
i  *0  <  *4  4  4 


■o  C  -*  -O 

«  p  *-  -  • 

4  4  P  4 


■o  C  u  -o  c  u 
-  P  4  ,  P  • 

T>  Ol  w  -o  Ow  ' 


(-  al  tfltTiT)  |  at 
-»  u  u  4  -H  u  u  -» 


*+  «-4  9-4  U  9-1 

IT3-04a.(.  TJ(T3TJ<T3TltAlt  T3  ■ 

I  -*  -*  U  U  -»  <-». 


T3  T7  T3  4  Q  t- 

— <  — <  — <  U  U  ~> 


•“*  •-I  u  •-* 

a  (IUT3  (TIT3  mu  t 

huhhuhhOi*U"» 


■°  t>  X>  T3  T3 

SnS  ^  mmmlS*  ®  £  2^Q!f!25,f>,orv®t*‘0^f*n«*f>oN©(>*o^rynE,««oNfflO'0-*nin*n*ONffio*o»*ry 

HSv2H22GG2GGBGn******,r***,fi,0,n,0,fl'f'*>'n,n,n'0'0'00'0'0'0'0'0'ONNNfvNN£kr!:,ivgBm 

000800008888880808800080880000888808888880888888888888888 


$  s  sss 

©ujyrOfyor*-.Quj© 

niLonnunHuiLin 


O-O-Olh  o  a*  -  o  o* -•  o  < 

000000  000000^  o 

o  o  o  01  u.  n  (h  ui  4  n  o  n  *)  n  o  mom 
o-<4,*-«<©s-'  uu^iuy^r  m  «  uj 

-•  01  ^  01  -1  a  UJ  ©  *«QNHQniQNQU© 

ryr^rgni^ou-Oi  ^uN^uonuoujQn 


OnO-'Oth 

OOOOOO 

-^<ooniMu 

^OI^OI-<OUJ© 

ryryNry-*ou.cy 


N  (h  »<  N  lh  h  ♦  < 

o  00  000-  o 
m  *  o  «  o  m  cy  o  ry 

h  y  h  n  u  ^  ^  ifjiouj 

^om^onoNOu© 
HUN^uNLinuon 


«4>©<QUlOI*N«OU. 

IlIlIlIlIlOOOOOO 

HHH^^nnriririin 

00000000000 


*  n  «  q  o  n  r>  n  <  a  o  n  o  a*  o  in  o  n 
Nnoinnnnnnt^ 
ry  cy  ry  ry  ry  ry  m  n  ry  ry  ry  ry  ry  ry  ry  ry  ry  ry  ry 
00000000  00000000000 


^©OOUJ^^f^O' 

4-4-^<iDif>inn 

ryryryryrumryry 

00000000 


rj^4)«0'0'0'0Nr'r'rN 

ryryryryryryryniryryry 

00000000000 


24 

156 


Di.  Dobb’s  Journal,  Number  54,  April  1981 


*  P  P 

ft  -*H  ft 


O  ft 


*"«  P 


%  t 

ft  ~  ~  ft 

-*•  +  ft  ft 

ft  ft  ft  ft 

t  t  ft  *1 

0  0  0.0. 
t  t  ~  *- 

ft  t  t  -  -  ft 

-  ft  *  ^  cu  .  . 

ft  «-  a  tj  m  . 


3 
C 

o  ft  (-  -m 

O  ft  P  ft 

a  a  C  3 

..  P  P  O  C 

P  -M  Cl  u  h 

*  a  £  p 

»  3  O  C 

ft  P  O 
PC-*  u 

o  o  ft  t  a 

C  TJ  ft  O  U 


o 

<r 


C  p 

c 


(h  x 

P  P 
ft  ft 

•  P  P 

•  -O  TJ 

I  '  -  -  O' 

.  ft  M  ft  * 

I  '  C  TJ  U 


c 

t 

3 

p  r 

ft  V 

*-  (L 
U 

TJ 

C  O 

ft  P 


6  O 
o  a 
u  3 


P  rH 
C  u 


TJ  4 

ft  u 


TJ  ft  ft  P 

TJ  t  ft  ft  3> 

ft  TJ  t  ft  A 

TJ  ft  |> 

ft  ft  TJ  TJ  t 

ft  ft  TJ  ft 

ft  e*  ft  «*- 

43  ft  ft  ft 

6  W  t  C 

I-  ft  ft  ft 

ft  t  ft  4>  t 

4-  O  ft  4.  P 

4-  (-  ft  3  -* 

3  t  6  43  ft  ft 

Aft  H  -H 

N  I  ft  ft  -X  p  TJ 

**  ft  >  >  C 

A  TJ  ft  ft  ft  3  P 

ft  ft  p  o  u 

r+  -  -  P  U  ft 

rH  f<  ^  H 

ft  ft  C  ft 

U  TJ  4  H  h  K 

.  -  -  -  «  —  A  —  « 


|  E 

i  -  t 
(-  ft  O 

O  4  rH 

:  p  ft  3 
I  U  C  4. 

ft  ft  ft 

ft  t  ft 

I  -  p  ft 


U  P 
o 
c 


u  £ 


u  P  u 
ft  ft  3 
t  ft  ft 
P  3 

a*  o 

a  ft  s 


p  ft 

tj  t  -o 

3  O  ft 
ft  P  ft 

u  t 


3  ft 

O  ft 

C  3 


ft  t  ~ 

4-  ft  C  -M 

3  4  ft  ft 

A  4  O  -•  TJ 

TJ  3  ,  Oh 

I-  A  -H  -M  ft 


ft  ft  ft 


:  ~  ft  A  ~  ft  t  ft 


*  C  ft  ft 

toe 

O  C  ft  O 

t  i-  U  TJ  . 

c  ft  c 

ft  ftp. 

o  >  o 

O  H  \  TJ  c 

C  ft  -m  ft  - . 

..  4  ...  ...  rH 

ry  3  4 

4  A  3 

3  TJ  A 

At  >  TJ 

TJ  ~  t  TJ  (- 

t  *  t  ft  * 

-  ft  ft  3  u 

MTJQ.CC 


t  t 

ft  t 

ft 

M 

ft  4 

u  O 


ft  ^ 

t  U 


c  o 

ft  p 

t 

t  4 
3  u 


P  E 

■M  O 
t  t 
3  4 


ft  ft 

ft 

Ol  ft 
ft  A 

E 

C 

t  ft 

O  4 
t  4 
t  3 

ft  A 

N  H 

ft  rH 


TJ  TJ  c 

ft  TJ  ft 
ft  4 
ft  ft 

w  :»  C 

ft  t  ft 

*  O  C  P 

ft  E  p  C 

ft  ft  3 

E  E  ft  o 
m  u 

ft  ft  -M 

>  >  M.  ft 

ft  ft  ft  P 

ft  ft  M  9 

«.  -PA 

•H 

•  C 


ft  t  ~ 

4ft  C 

3  4  ft 

A  4  O  HI 
P  3  -  O 
3  A  m 


H 

c 

c 

o 

■8 

a 

•S 

c 

<3 


tj  ft  a.  a.  a.  (-  tj  tj 

"-H  u  U  *■»  U  r-H  r-H 


rH  rH  P 


TJTJTJTJftTJTJftftCCTJftftC 
HHHHUHHUUO  ~ >  f-H  U  U  “» 


3 

t  TJ 


TJ  TJ  TJ  TJ 


ft- 

O' 


nft«oMD(hOH(vnftn«oha)(h  o 

(MMMMMH^OOOOOOOOOO  m  h 

nnnnnnnftftftftftftftftftft  ft  ft 

ooooooooooooooooo  o o 


-  t  t  C  -  3 

ft>o4)fv©(ho-4rynft«ONaDa'O^rynftinor*v©0'O^rynft«*0fvcD(h 

^^^■^^^niNryruNNryryNOinnnnnnnnnnftftftftftftftftftft 

oooooooooooooooooooooooooooooooooooo 


o 

^  -•  -•  it  ra 
o  o  o  o 

m  >o  n  a  (M  o 

o  o  o  m  m  O' 

iLmm<QNQ< 
cnncMwauja 


CD  O'  -  QD 

O  O  O  O 

UJUJDftm-.QO' 

ft<>oni'OitNO 

^QUJ<UJO^IU 

xUlLOUfilHO 


o  o 
o  o 
m  o 
o  o 
a  n 
o  u 


n  n 

o  o 

OHOHiftHHftft  n  ft  n 

05OOOOOOOO  £300 

nooiuQft<ON  n  ca  <  m  o  o 

mooo-<  —  Oftri  otnouju  o 

QfjHf|)Q<n|QQS(DQQQO(hO 

lUfyruraoniruoucDCMiuuonoo 


n 

o 

n  -  o  - 
oooo 
nuonj 
r»  o  o  o 
q  ni  ^  ry 
lumnni 


O'  <  a 
m  m  m 
n  n  n 
o  o  o 

0360 

0363 

0367 

0368 

036A 

036D 

0370 

0373 

0375 

0378 

037A 

037C 

037F 

0381 

0384 

0387 

038B 

038E 

0391 

0394 

0397 

039A 

039D 

03A0 

03A3 

03A4 

03A6 

03AA 

03AD 

oaco 

03B2 

03B3 

03B5 

03B9 

03BC 

03BF 

j* 

u 

c 

r 

c 

<N 

ft 

CR 

A 

t 

r- 

ft 

t 

c 

•• 

a. 

A 

ft 

■H 

TJ 

p 

ft 

•rH 

t 

3 

ft 

ft 

C 

ft 

ft 

c 

•H 

p 

P 

TJ 

ft 

ft 

ft 

t 

ft 

t 

C 

t 

p 

ft 

c 

Cl 

P 

r-t 

ft 

ft 

- 

E 

P 

t 

» 

t 

3 

ft 

■  rH 

o 

ft  zr 

3 

ft 

E 

P 

p 

TJ 

c 

p 

ft 

Q. 

K 

ft  C 

O 

ft 

ft 

ft 

t 

ft 

ft 

c 

p 

P 

C 

ft 

ft 

A 

a. 

ft 

A 

ft 

t 

C 

O 

ft 

P 

o 

P 

ft 

Ci. 

ft  E 

ft 

t 

c 

3 

t 

U 

t 

ft 

CL 

« 

ft 

TJ 

JB 

ft 

4 

O 

•M 

3 

p 

-X 

CL 

-X 

ft 

ft 

—  3 

ft 

O 

ft 

Ol 

-h 

P 

ft 

u 

c 

u 

P 

u 

P 

ft 

A  O 

ft 

ft 

ft 

c 

ft 

ft 

O 

ft 

P 

o 

t 

ft  A 

tfi 

* 

> 

A 

ft 

■M 

ft 

TJ 

t 

ft 

p 

M 

ft 

ft 

rH 

-X 

3 

•M 

ft 

TJ 

3 

ft 

c 

> 

c 

CL 

P 

ft 

CL 

U 

P 

4 

t3 

t  1 

ft 

ft 

ft 

P 

3 

-X 

CL  ft 

o 

ft 

E 

P 

ft 

E 

ft 

ft 

-rH 

ft 

ft  1 

a. 

> 

ft 

TJ 

u 

ft 

M 

E  ft 

u 

•M 

3 

CL 

■fH 

3 

A 

3 

.rH 

>  1 

r- 

ft 

P 

ft 

c 

ft 

A 

3 

A 

— > 

3 

ft 

A 

— > 

— > 

ft 

p 

ft 

ft 

c 

P 

•M 

■M 

u 

u 

E 

t 

P 

—»  , 

-X 

P 

P 

P 

* 

TJ 

P 

-i  3 

ft 

E 

•M 

A 

.  ft 

ft 

ft 

P 

-rH 

ft 

ft 

t 

ft 

-»  o 

ft 

ft 

t 

ft 

ft 

t 

A 

t 

— 

ft 

O  ft 

-fH 

ft 

ft 

ft 

c 

ft 

ft 

ft 

O 

TJ 

ft  e 

p 

E 

lH 

o 

ft 

t 

u 

•*4 

C  ^  TJ 

•H 

3" 

ft 

3 

•rH 

t 

•w 

h-  rH 

r0x 

o 

ry 

> 

4 

rH 

O' 

o 

m  n 

^H 

•H 

N 

rH 

rH 

ry 

o  ry 

n  m 

P 

A 

P 

P 

p 

-X 

A 

P 

p 

Tf  4 

t 

-X 

ft 

4 

p 

4 

t 

-X 

N 

4 

* 

r-i 

ft 

ft 

ft 

- 

A 

ft 

ft 

P  4 

t 

u 

p 

4 

CL  P 

4 

t 

u 

4 

p 

ft 

P 

p 

ft 

4 

p 

ft 

ft  3 

ft 

4 

o 

ft 

3 

A 

ft 

3 

» 

4 

o 

ft 

TJ 

C 

ft 

TJ 

TJ 

t 

w 

JC 

TJ 

t 

P  A 

t 

3 

•M 

p 

A 

* 

Q. 

A 

E 

3 

rH 

P 

A 

E  3  rH 

P 

ft 

-  O'  E 

—■ 

* 

- 

t 

>0  0  6 

ft 

- 

ft 

TJ  - 

• 

A 

TJ 

- 

- 

4 

« 

« 

A 

•w 

ry 

TJ 

* 

ft 

ft 

a. 

ft  -  a. 

ft 

-  - 

- 

•M 

- 

-  CL 

- 

M 

- 

- 

-  >—• 

ft 

TJ 

rH 

ft 

3 

rH 

ft 

P 

rH 

TJ 

Ol 

TJ  U  U 

TJ 

ft 

U 

u 

A 

u 

ft  U 

ft 

c 

ft 

ft 

m  x: 

TJ 

t 

ft 

ft 

M 

A 

TJ 

A 

A 

TJ 

3 

ft 

ft 

A 

TJ  t  ft  ft 

rH 

r-t 

■H 

rH 

M 

r-H 

»H 

TJ 

ft 

TJ 

TJ  TJ  ft 

TJ 

TJ 

t  t 

TJ 

TJ 

ft 

TJ 

TJ 

TJ 

TJ  ft 

t 

a. 

TJ 

t 

t  TJ 

TJ 

ft 

TJ 

CL 

t 

TJ 

TJ 

ft 

TJ 

TJ 

ft 

TJ 

CL 

t 

TJ 

U 

H 

»-l  »-«  U 

r-H 

■H 

H 

u 

r-4 

>-4 

rH 

•-H  U 

o 

■*» 

o 

“>  r-H 

u 

*”• 

U 

r-H 

r-H 

u 

rH 

rH 

u 

rH 

U 

— J 

rH  U  rH  O 

o 

ry 

o 

ry 

m 

N 

ry 

n 

ft- 

ft- 

ft 

ft 

m 

p 

p 

P 

ft 

ft 

ft 

ft 

ft 

p 

p 

p 

P 

TJ 

TJ 

■o 

TJ 

TJ 

TJ 

TJ 

n  ft  m 

<J 

ID  O'  O 

-  ry  n  ft- 

m 

- 0  N 

© 

O' 

O  -< 

ry 

n 

ft-  m 

o 

N  ©  O' 

O 

ry 

n 

ft-  m 

>0 

N 

©  O' 

o 

•H 

ry 

n 

ft 

m 

>0 

N 

© 

O' 

o 

ry 

n  ft-  m  o 

m 

m 

O' 

O'  O' 

O' 

O' 

o  o  o 

o 

o  o  o 

O  O  O 

»H 

— H 

«-4 

»H  ^H 

H 

H 

r-H 

ry 

ry 

(y 

ry 

ry 

ry 

ry 

ry 

ry 

ry 

n 

n 

n 

ry  ry  r»i 

ry 

ry 

ry  ry  ry  ry  ry  ry  cy 

ry 

ry  ry 

ty 

(y 

n  n  n 

n 

n  n 

n 

n  n  n 

n  n 

n 

n 

n  n 

n 

n 

n  n 

n 

n 

n 

n 

n 

n 

n 

n 

n 

n 

n 

n 

n 

n 

o  o  o 

o 

o 

o  o  o  o  o  o  o 

o 

o  o 

o 

o 

o  o  o 

o 

o  o  o 

o  o  o 

o  o 

o 

o 

o  o 

o 

o 

o  o 

o 

o 

o 

o 

o 

o 

o 

o 

o 

o 

o 

o 

o 

oooo 

o 

N 

O' 

N  o 

00 

© 

o 

O 

n 

ft 

© 

n 

o 

Q 

ft 

o 

© 

n 

< 

©  n  h 

o 

o 

o 

o  o 

o 

o 

o 

o 

o 

o 

O 

o 

o 

ft- 

o 

o 

o 

r-H 

O 

o 

o 

o 

o 

ry 

o  o  o 

a 

in 

LL 

m  O'  m 

m 

u 

n 

o 

O' 

o 

© 

>0  Ll_  « 

Q 

o 

O'  o 

© 

n 

03 

ry 

o 

o 

ry 

o 

O' 

m 

© 

ry 

o 

ft 

o 

H 

Q  o  o 

«H 

w-i 

o 

o 

o 

*H 

o 

O  ©  O 

•0 

o  o 

m 

© 

»-H 

o 

r-H 

o 

o 

o 

o 

Q 

© 

o 

o 

©  CD  rH 

Q 

ry 

hUJQ 

•H 

< 

r*"  © 

w 

Q 

< 

ry 

©  ©  a 

n  ry 

< 

N 

CO  H 

•H 

Q 

<  © 

© 

Q 

Q 

< 

© 

m 

r*  Q  < 

O 

ra 

-  O  O 

n 

o  ry 

o 

u 

iy 

ry 

O 

—  u 

CO 

o 

n 

G3 

ry  ry 

^4 

o 

n  © 

ry 

ry 

O 

ry 

o 

n 

© 

ry 

ry 

o  n  © 

O' 

O 

IL 

ry  m  r-  < 

Q 

o  - 

n 

o 

© 

£3 

© 

_ 

n  n 

©  O' 

u 

© 

o  ry 

© 

£0 

© 

o 

ry 

in 

© 

CQ 

© 

ft 

r- 

O' 

N 

N 

N 

(D  00  00 

00 

00 

O'  O' 

O' 

O' 

O' 

O' 

O' 

<  <  < 

<  < 

< 

< 

03  £□ 

£Q 

03 

m  m 

u 

u 

u 

o 

o 

o 

Q 

Q 

Q 

Q 

a 

ry 

ry 

ry 

ry  ry  ry  ry 

(y 

ry  ry 

iy 

ry 

ry 

(y 

ry 

ry  ry  ry 

ry  ry 

ry 

ry 

ry  ry 

ry 

ry 

ry  ry 

iy 

ry 

ry 

ry 

ry 

ry 

ry 

ry 

ry 

ry 

ry 

o 

o 

o 

oooo 

o 

o  o 

o 

o 

o 

o 

o 

o 

o  O 

o  o 

o 

o 

o  o 

o 

o 

o  o 

o 

o 

o 

o 

o 

o 

o 

o 

o 

o 

o 

oooo 

Dr.  Dobb’s  Journal,  Number  54,  April  1981 


25 

157 


page) 


*  ft 
ft  £ 

•  B 

u 

T>  U  * 


c 

•*4  (~ 
4»  O 
3  4* 
O  u 
t-  • 


u 

o 

TJ 

TJ 

(- 

3 

6 

9  ft 

4. 

TJ 

ft 

ft 

u 

t~  ft 

ft 

-4 

o 

C 

C  ft 

ft 

-4 

E 

O 

6  ft 

ft 

t- 

ft 

o 

C 

Ol 

ft  -*4 

3 

ft 

u 

o 

C  3 

E  £ 

4- 

£ 

ft 

ft  O 

u 

4- 

4* 

4* 

4- 

9 

4* 

4> 

o 

3 

•*4 

-*4 

-P4 

*- 

•H 

ft 

U  4- 

(- 

£ 

3 

K 

ft 

■o 

ft  f. 

C  O 

t- 

ft 

JK 

TJ 

TJ 

ft 

ft 

Q- 

ft 

. 

u 

c 

c 

ft 

04* 

>  4* 

6 

C 

ft 

ft 

3 

3 

f- 

ft  U 

c 

3 

o 

ft 

£ 

O 

O 

o 

ft  ft 

ft  O 

ft  £ 

TJ 

9 

U 

£ 

4- 

E 

-x  ft 

•*  •* 

•» 

•* 

■. 

•« 

•« 

•« 

.. 

•«  .. 

6 

P-4 

u 

1 

4- 

E 

ft 

3 

u 

£ 

U 

Q. 

£ 

«*- 

U 

* 

* 

£ 

£  ft 

£ 

ft 

ft 

N 

ft 

• 

N 

£ 

•  * 
1  • 

u  u 

O  V 

I-  TJ 

(-  ft 

• 

t- 

**-  ft 
O  «*. 
ft. 

ft  3 
ft  A 

ft 

f-  ft 
-ft  ft 
ft  ft 


ft  u  C  ft 

C  ft  O  u 

•ft  (-  -h 

4*  4>  ft  »-  > 

3  -  n  ft  ft 

o  ft  ft  ^  ft 

*-  >  ft 

■**  ft  ft  4* 

w  C-  ft  u  ft 

C  ft  E  - 

•*«  .  9-4 

4*  ft  ft  A 

C  ft  c  u 

^  ft  ft  ft  o 


ft  U-  ft-  -4 

t~  •*»  o  -*4  o 

O  C  4*  u  ft 

(-  -*4  u  ft  c 

U  I-  ft  O  O 


l>  -ft 

I  o  ft 

u 

u.  ft 

ft  Ol 

ft 

4*  ft 
C  ft 
.  3  ft 

O  E 


3  C  ft 


ft  ft 

ft  * 

Q.  ft 


O  > 

Ol  ft 


nt 

t- 


« 

«  « 


O 

U 

ft 

u 

4* 

O 

ft 

ft 

U 

4* 

c  n- 

ft 

ft  (^* 

u 

o  u 

O 

4* 

ft  4* 

ft 

• 

U 

ft 

ft  4*  U 

4* 

ft 

4* 

4*  ft 

£  C  ft 

C 

E 

c 

C  4- 

ft 

•*4  4* 

ft 

ft 

ft 

ft  4- 

4* 

4*  (.  C 

(- 

C 

u 

U  ft 

ft 

3  O  **4 

l> 

u 

U 

-4 

o  l 

3 

ft 

3 

3  C 

ft 

4*  (.  O 

u 

> 

u 

U  ■h 

c 

3  O 

•*4 

ft 

O  ft 

4* 

t- 

4* 

4*  3 

u 

ft  ft 

c 

>  ft  ft 

■«  ^ 


ft  ft 

U  Q. 
I-  ~ 


O  >  TJ 

*  c  ~  ■ 

-4  O  .  « 


ft  •* 

*  —  ft 

■o  U  U 
(-  4*  ft 
~  a.  > 

•  *  .  C 

:  a.  u  *h  o 


(.  ft 
ft  -* 
>  ft 

c 

O  ft 

u  -*4 


u  3 


o  c  u 
(-  ft  t- 
u  u. 


^  H  3 
-4  0* 

3  ft  a. 

o  c  E 

£03 

ft  u  -» 

ri 

4*  f~ 

ft  I- 


.  >  -4  a. 

u  *  C  >-  ft  * 

•  -4  O  *  *  M 

ft  £  U  ft  ft  c 


c  C  ft  TJ  J-  ft  TJ 
■**  •*  -O  -4  O  (-  -4 


3  3 


'"I  O  “*  rH  r-t  -H  _| 


l  -o  -o  -o  -o  *o 

I  —4  Q  r-4  »4  pH 


^  n  (■  MTJ  «TJ  (.  t 
-*-*0^U-4U-40“» 


'©©SSSaomm©? 

>r>nr>r>nr>r>r>r>r> 


o 

i- 


ooooooooooooooooooooooooooooooooooio 


?S!??S;i?£:Sg:§588SS§5SS2n2”;22^!22:2sa 
$8288S22S28SS882§828§ 


Q  (J 


N  00 

r>  in 


o  o 


u.  -o  n 

K  y  |» 

nncooD-4(DQ<j0  d 

fy -4  o  mb  u  mu  ry 

0^<GQUQUIU.Ory  ft 
nmmifiinnno^  5 

^^■ftftftftftftft  ft 

ooooooooo  o 


33 

ss 


«  N 
n  qq 


<  a 
o  o 


o  o 


< 

n 

o 

m 


us 

ft 

o 


28 
.  o 

)  CD 


O  o 

r»<-4  non<<H 

ooo  oooooo 
0<rv^cDmiu<aa(h 

—  -  ONOftOftONft-4 

QQD-4Q<^)ritfQ-4QO<h. 

luajoniununiurtuuno 


o  i 

8! 

n  • 


r>  ft  <  h 

,0000 

n  -4  #)  <  <  m 

-4  rs.  -4  ft 


82  = 
mon 


Q<no 
n  a  ry 


pft©p‘piLOjftNMUi-4«aD(h«UJ-4ftNOD 

QD(DODaDGDCh^Olh(h^<<<< 

‘ftftftftftftftft  -  --  - 

o  o 


N  N  N  N  N  N 

ftftftftftftTW<TV7T7V 

OOOOOOOOOOOOOOO 


o  o  o  o 


•O 

a> 

3 


C 

O 

u 


p* 

C/5 


o 

• 

ft 

■  ft 

•  4* 

(.  -4 

o  ».  r- 

4*  3  ft 

U  (- 

ft  £  O 

ft  ft 


(- 
t- 

••4  N  JM)  ft 


(-  O 

TJ  c 

■O  ft 
ft 

ft 

f-  4* 
O  *4 
4*  (- 

u  3 


u  o 

ft 


4>  O 

ft  V 

ft  -*4 
3 

Of  ? 

ft  C 
(-  ft 


«*-  -4 
U  £ 


•44  ft 

I-  * 

3  ft 


o  ~ 

C  ft 

.*  <4 
W  3 
«*-  £ 
3  4* 

£  3 

4*  w 

3  * 


ft  4» 

>  O 

TJ  C 


ft  ft 

U  (. 


O  T> 

4*  ft 


U  > 

ft  ft 


ft  TJ 

ft  TJ 


C  (. 

ft  O 

>  e 


i 

v 


I  Q.  *"4  O 

I.  3  £  ~  U  . 

.  ft  ■*  -  C  •*  . 


>  4* 

TJ  3 

ft  . 

3  u 
(.  C 


ft  4- 

a.  3 


4-  -*4 
4-  ^  ■ 
3  * 


—  ft  • 

U  TJ 

ft 

ft 

U  > 

ft 

ft  ft  ft  p 


C  -*4  C 
o»*o 

TJ  ft  TJ 


ft  TJ  -O 

U  -4  1-4 


-4  p-4  ^4  4*  3 

ft(-(-‘Oftftt-ftO‘ 

U  O  -»-4  U  U  ->  l~  ft 


•a  T>  TJ  TJ  TJ  TJ  c  TJ  • 
I  ft  HH  ft  H  H  H  H  i 


4-  a. 

O  3 


4-  4*  ft 

o  u.  at  ft 

ft  C 

ft  4-  ft  O 
ft  4.  -4  4» 
ft  3 

£  ft  ft 
TJ  4»  ft 
TJ  4-  ^  |_ 
ft  O  £  ft 

N  N 


<^- 

C 

U  (. 

ft  ft 
ft  4* 

3  4* 


•ft  TJ 

U 

O  -ft  OL 

-4  ft  e 

•*4  3 
ft  4.  -» 
3  -4  * 


(-091 

^  ft  ft.  I 

-  •«  4*  .*  ..CM  . 


C 

3 

4- 


I-  4* 

ft  ft 


«  (-  44  ft.  ft 

TJ  3ft 
ft  -o  ft  £  4»  r 
4»  ft  (-  94* 

ft  O  ft  £  ft 

V  94*  U  9 

l>  ft  C  4* 
ft  O  ft  C  ft 

£  C  -O  >  3  c 

ft  ft  C  TJ  O  O 

E  E  ft  ft  U  TJ 


w  ft  *  *-  £  -4 

*  »  *1  *  *  • 

ft  ft  C  ft  ft  ft 


*-  TJ 

U  MJ  O  T3 

O  -*  *4  ft 


^  £  -O  ft  ft  C 


U  U  4* 

TJ  C  ft  TJ  U-  U  ft 
-4  -*4  ^  O  -*  |_ 


| 

pS 

b 

o 

X) 

i 

N 


rri 

4- 

3 


ft. 

3 


4* 

ft 


2^D!!2X5!5^?^(5^^^^in>®^®^O’Hr<ntn'0N{D^o-4  wft  n<oNoihOHnntn-oNoihO'4nnftn4iN 

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo 


n 

ftHHfift  n  ft-  n  -*• 
ooooo  boo  n 

Q  ft  <  Q  O  MU  <  H  ffl  B 

-4-40ftr>  o^*oujuj  n 

Q<riQQNOQQQOIhO 

umruuuajwiuuunu- 

OI^GOBUJ^ryftBBUJO 

OOUOOOOQQQOUJ 

nnnnnnnnnnnn 

OOOOOOOOOOOO 


—4  *4 

O  O 

-4  <  «  - 

*4 

O  O  O  O  o 

ui  a  n  o  m  q 

on  r>  -4  n 

pH 

Ch(MOnO<NO 

0* 

«  N 

-4t\iuj-4iijrtfBiu 

o 

n  a 

UilLHIONBlUL 

m  n 

UUIU.U.U.U.U.U. 

o 

o  o 

nnnnnnnn 

ft- 

ft-  ft 

OOOOOOOO 

o 

o  o 

o  q  u  n 

rw  lu  <  cd 


-O  Q3  <  B 

O  O  O  o 


n 

ll. 

n  n  b  <  n  o  a- 

N  N  h  s  a  fu  y 


o  q  iii  ii  o  *4  n 

O  O  O  O  *4  -4  ^4 

ftftftftftftft 

O  O  O  O  O  O  o 


26 

158 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


**  C“  .4* 

ft  •  4-  4-  u 

Q.  ft  '  4-0  TJ  ft 

9  4-  •  ft  4-»  T3  4- 

4>  O  9  9  u  £.  4  ft  m 

4-  C  a  u  c  .c 

I-  4-  •**  >  •*«  Ol  u 

Oft  4-  TJ  ft  4>  E  C 

4-  4*  i  V  K  (.  -H  « 

4-  4>  *  A>  I  14* 

•  C  ft  4*  C  4*  *  4»  x: 

3  ft  C  ft  *  *  +> 

4»  O  -fH  •**  £  4»  ft 

C  U  T3  6  ^  U  -H  .  ft  13 

•*<  C  4-  4»  ft  >  C 

4-0  ftftOftWftftft 


**  ■*  »  O' 

♦  Hi, 

m  c  x)  u 


e  -  (h  e 

a  •  ♦  a 

U  TJ  U  U 


•  O'  a.  O'  ry 
L4-~4-4- 
.  4-  -  4-  4- 

I  ft  m  ft 

:  cl  jz  &  a. 


a  a  w  ^  »  u  o  , 


XI  C  V  I 

H  H  H  4. 


4*  ft  -•  a.  u 

a»  dtjx)  i  o  c  t 

U  4-  a.  r-t  H  U  Q.  -T-«  -» 


•  •  •»  »  •  »  «  i 

a.  Q.  O-  &  a  a  a  a 

nfp-ONOj'OHrtn^ft'OMDD'OHfKntft'OMDihOHnintftOMDiho^fiintft'OMiff'OHMnt 

MdmrunNnrinnnnnnnni'Ktt^ttyyytonnnAAAn^A-O'O-ooo-oo-oooNNNSK 

'O'O-C'O-OO-O-OO'OOO-O-O-COC'O-C-O-O'O-OO'CO-O'O'OO-O'O'O'O'O’O'OO'C-O'O'OO-OO'OO-O'OOOO 

oooooooooooooooooooooooooooooooooooooooooooooooooooo 


N  O  * 

o  o  o  * 

)  n  0*  n  ui  0*  i 

>  -o  o  o  u.  o 


o  o«ooouoor>oo 

<umO^UJQ*HliJOQUJQ 

ryNmry  —  oo  —  ooiuou 

<QUJU.-'^'00'UUJ  —  mN 

<<Unooonouuu 

ooooooooooooo 


o  o 

m  r> 

o  o 
<  n  ry  O' 
ry  ry  ry  o 


<QLJh 
U  U  U  Q 


«  (♦ 

o  a. 

•  4-  ■*»  o 

**•»«•  o 

9«-  r-. 

X>  4-  * 

3ft  ft 

•  a  ♦*  r  c 

C  94*  O 

o  n  m  ft  -a 

U  9 

I  ca  4* 

4-  ft  C  ft  0  4* 

O  >  3  C  C  h 

4»  n  O  O  -  »< 


*  E  *  ft 

*  ft  ft 
ft  4-  ft  • 

4-0  4-4- 

13  4-  "O  TJ 

TJ  4-  TJ  TJ 


•<  ♦ 

O  O  O  O  O  O  O 

m  ONQliJQuQQ 

O  0-OUJU.UJU.UJQ 

<ur>o~*5-»5<o© 

ryr^mryryoryoryu-* 


lO-ONO'UlLtyOIDl 

IQQQQQQUIUJUJI 

iOOOOOOOOOi 

-  4- - 

ft 

•*-  4-  ft 

H-  ft  a.  ft 

3  <4-  E  ft 
ft  A  <4-  3  « 

4-  3  “»  ft 

«  4>  A  ♦  4- 

a  ft  -a  tj 

E  ^  13  C  TJ 
O  C  3  ft 

u  in  o 

O  H-  4- 

0  4-0  ft 


O 

O 

ft-  m  ~  O 

ry  o  o  u  o 

uj  lu  cd  m  u  ui  Q  -  n  qd  o 

NU.D  UjSOUUjnH  o 


Qujo-Hfynr>mo'< 

UIUIUU.UUUUUU 

oooooooooo 


UJOO  UJ 

-o  c*  ry  -o 

uj  o  o  UJ 

-o  ry  ry  o 

<  UJ  O  O  O  UJ 

o  3  ry  ry  ry  -o 
o  uj  o  uj  o  UJ 
o-on-on-o 

UJ  O  ©  UJ 

U.  Q  O  O 

ft  n  r>  m 

o  o  o  o 


£  ft  4*  c  3  ft 

4*  4»  •**  ft  a  4*  <*• 

«  9  I.  9  4* 

C  -o  ft  ft  ft  X>  ft 

I  ft  4-  <4-  U  9 

—  -c  ft  1-  C  4> 

-  U  CL*-<  ft  C  • 

4*  C  TJ  >  3  C 

ft  O  .  TJ  O  O 

—  4-  U  ft  U  TJ 

C««  (*)  •-  ... 

ft  E 


<4-  ft  E 
3-003 
A  -H  4>  C 
> 

ft  *  4-  4- 
T3  O  O 
TJ  4*  4» 
C  3  u  u 

-H  O  ft  ft 

<4-  C  «  ft 


A  U  TJ 

ft  ft  ft 

^  ft  tr 
ft  ~  at 
4-  4*  ft  UJ 

ft  30. 

TJ  4-  4* 


U  U  4» 

T3TJCftT34-4-ft 
H  H  -H  TJ  H  O  “34- 


U  U  U  4> 

iTJTJT3a4-CCftTJ4-4-ft 
'  —  —  —  u  O  -»  4- 


ftftft  u  ft  a.  »-*  o 

333TJ4-XJ30TJftTJTJ 

a  a  a  >h  o  »  a  a  ^  u  •-<  ft 


ODO'O^rynft'^oojO'O^rynft’ft-oNmO'O^rynft-n-ONCDO'O^ryn^in-ONmo'O^rynft-n-oNDDO'O^ryn^ 

ooHHHHHHHHHnnnnnnnnfynnnnnnnnnnnttf^yyytT^oooftiftioooooo-O'O'O'O 

oooooooooooooooooooooooooooooooooooooooooooooooooooooooo 


<NH®<nOO' 

DNry^r^caryo 


ft-  -H 

o  o 

-0  ft  UJ 

-0  o  o 

n  oo  m  ©  m 

ft  -0  ft  o  u 

aryQ<ujonnm(D-HO0' 

ufyuj-cQryra  —  ONaaryu 


ft  ft 

o  o 

©  O  «  -  ^  -O  ft 

-0  O  O  O  0-0  0 

mry  o  -•  ft  <o< 

•on  me—  om-o 

nmmQNQm^.^Q<0'  ryaa- 

uQUJUJQUJUJu^unio  ry  uj  u  uj 


ftN©0'<4QOUJ 


ftftftftftftftft 

oooooooo 


y.n  <i  <  ouiuiio-ryno 

-ryryryryfyrurynnnnn 

ftftftftftftftftftftftftft 

ooooooooooooo 


OMDo-QuiOHOiomai  uun-o 

nnnnnnftftftftftft  ftftr»m 

ftftftftftftftftftftftft  ftftftft 

oooooooooooo  oooo 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


( Continued  on  top  of  page  26)  I  (Continued  on  next  page ) 


> 


* 

K 


C 

c 

t- 


c 

UJ 


u 

Ll 

I 

o 

o 


u 

a 


-  *  6 

'  L 
ft  ~ 

-  -  «*- 
■f  -  C 
«*-  '  o 
>  ft  CJ 
L  '  ' 
■O  4-  , 

•  ph  H- 

.  >  — 

^  -O  »- 

'  ft  u 


•H 

U 


CD 

« 

K 

O 


O' 

ft 

N 

O 


O 

'O 

N 

O 


<0 

N 

o 


ry 

•o 

N 

o 


n 

-o 

n 

o 


N 

o 


m 

<i 

n 

o 


<0 

o 

N 

O 


N  ©  O' 
'O  O  O 
N  N  N 
O  O  O 


O 

N 

N 

O 


CM 

N 

N 

O 


n 

n 

N 

O 


N 

N 

o 


n  m  uj  n  m  ry 
n  *o  ft  ft  on 
o  ft  ©  u.  ft  ru  u. 
ry  n  ry  ry  ry  m  o 
cm  O'  o  ry  o  ft  ft 
n  o  ry  m  ry  o  n 


n  y  t  <tit  it 
o  o  n  ry  o  o 
O'  -h  ah  o  o  o 
o  o  o  ry  ^  ry 


ph  ft  UJ  UJ  o  ph 

•o  n  o  o  ry  o 

ft  ph  ry  ft  r>  ry  ft 
n  o  n  ry  ft  N  N 


ft  u  ©  q  ry  o  ry  m  ft 
NryNry  nojooo 


t  ItN^O-O 
CM  *0  N  N  CM  N 
oono'OMih 
ry  ry  ft  >o  ry  n  o 


n  ~  noftO'onu.noft 
o  o  o  ry  ry  o  ry  o  o  n  ry  cm 
♦  ooHito-oyH^noo 

rj  rj  n  ^  *  k  a  k  a  ai  <T> 


gB^ii!i!lIliliIIIiII|s|lIIiIII!iJiIlll!iiall|l|IiiIiill 


o 

o 


ry 

o 

o 


ry 

o 

o 


O' 

ft 

o 

o 


r> 

o 

o 

o 


o 

Q  O  ft 

© 

©  O'  O' 

o 

*0  O  O 

o 

o  o  o 

< 

o 

o 


o 

o 


o 

o 

o 

o 


UJ 

o 

o 

o 


’S 


c 

o 

u 


m 

r 


CL 

O 


c 

*o  • 

4»  L  ph 
y  3  f  a 

«  O  T)  « 

C  L  C  4> 

•PH  1 
-•  -O  4J  Q. 

•  ye 

•  L  3 
C  •*«  •  -» 

•*«  •  ir 

4*  •  4>  © 

3  -o  O 

O  £.  *h 

L  •  am 
£  3 

•  4»  o  r 

■*  t.  \  ^ 
■CO.CQ_-. 

4>  4*  4»  O  ♦ 

4> 


> 

L  ft 

•o  ry 

^  •  « 
.  .  i 

•  U  -O 


N 

9 


l  y 

4*  N  O 

-  ry  * 


u  a 

•  • 

y  o  -* 

~  n  * 

u  »  , 

£  n  i 


o  *» 

C  4* 

y 

o  c 
y  y 

-o  (-  o 

O.  4>  -H 

•  “»  U  -O 

-  %  •  Q. 

•  w  y  -» 


o  y  • 

4*  y  » 
u  *  u- 

•  L 

•  -O  4» 

-■DC 

•  m  • 

U  3 

•  a  or 
L  (-  • 

♦»  o  y  m 
ea4> 
a.  y  3  ^ 
3  6  y  u 
3 

4»  -O  fr. 

•  cot- 
y  •  «*-  o 


x>  n  o 
~  n  *« 


1  u  « 

■  •  e 

■  y  "o 
•  4»  4> 

i  «  » 


O 

n 


O  A 

4»  e 

3 

^  C 

« 

u  (- 
•*  o 
a  4* 

o  u 

ft 


4*  — 

•  * 


c  y 
•  a 

(-  £ 
4*  Q. 


L  u 

O  ft 

4»  y 


•y  £ 
a  q. 
o  N 


■a  C 
U 

pH  D 
pH  4> 

ft  ft 

U  L 


O'  O 

n  -h 

A  A 


p^S 


| 

o 

00 

I 

N 


C  pH  ^  AH 


VT30.  o  o  t  o  o  o  t  t  «  t  -a  TJ  t- 

^  ft  “*  AHH  ■)  H  H  H  o  -»  u  ->  HH  1 


AH  AH  AH  4> 

ft  ft  ft  ft 

u  u  u  t- 


N 

N 

O 

o 


©o  -H  ry 

NO©© 
O  O  O  >0 

oo  o  o 


3  T3  T3 
a.  ph  «  . 


UJ  ft- 
O  CM 
O  UJ  o 
ry  o  ry 
O  UJ  o 
ry  o  ry 
o  uj  o 
ry  o  ry 


i r> 

o 


n  ft-  m  o  n  © 
©©©©©© 
o  o  o  o  o  o 
o  o  o  o  o  o 


o  o 

N  © 

o 


O'  o  ph  ry 
©  0“  0*  0“ 
o  o  o  o 
o  o  o  o 


ntmo 
O'  O'  (h  O' 

o  o  o  o 
o  o  o  o 


>0-0<0N 

o  o  o  o 


rtP!2^J5^^2^o'sryn^,n'0N®0'O^f'*nft-noN©0'OpHry 

NNNNNNNNNNNNNNNNNNNNNNNNNNNNNNNN 

oooooooooooooooooooooooooooooooo 


<  IL  PH 

n  y  ph 


Q  O  PH 

-  ry  ry 
r»  r>  m 
o  o  o 


o 

o 

o 

8 

88 

ft  O  pH  tr> 

O  O  O  O 

V  o 
o  o 

aH 

m  m  ry 

m  uj  O'  ©  ph  o 

m  ph  n 

o 

ft  pH  U. 

ft-  AH  AH  UJ  *0  UJ 

ft  ry  o 

<  O'  O' 

Q  pH  © 

a  ph  ft  n  ©  o  © 

Q  PH  © 

ry  ph  uj 

Ui  pH  pH 

uj  ^  n  m  ry  o  ph 

UJ  PH  AH 

ft  N  © 

O'  Q  O 

ry  o  O'  y  q  u.  ry 

ft  ©  m 

ry  ry  ry 

ry  ry  n 

n  n  n  n  n  n  ft 

ft  ft  ft 

Dnm 

Amm 

n  m  r>  m  m  «  n 

r>  m  m 

o  o  o 

o  o  o 

o  o  o  o  o  o  o 

O  o  o 

m  m  n 

O 

o 

ft 

o  o  o 

O 

o 

o 

0-  (M  A 

ft  © 

n  n 

© 

ry  n  ft 

ry  o 

ry  u 

o 

Q  Q  Q  O' 

aH  © 

pH  © 

m  ah  O'  © 

V  u  u  o 

aH  aH 

pH  pH 

uj  ry  o  ft 

Q  o  n  o 

N  ft 

o  u. 

ph  ry  ft  <3 

•t  ir>  m  m 

»n  in 

ft  ft 

r»  m  r>  n 

m  in 

ft  m 

ft  ft  ft  ft 

o  o  o  o 

o  o 

o  o 

o  o  o  o 

28 

160 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


n  «r 

o  o 

N  K 

o  o 


CD  O'  O 

©  CD  O' 

N  N  N 

O  O  O 


3  2  !o  P  S  S  S  3  jj  il  o 

jsslsiassasss  sfesaSSa^s^ssssssNsES  ss  5ss  ssks  S2£!ns8!i! 

<niftoio^o<^ftryo^o<Off'ifloioo  <  n  no*^onnriiQA<<niijnuuiij 
©  m  »  £  £  2  SS  2  £:  :*?  £  h  3  -  2  t-  5  N  w  n  <m  o  n  -o  n  m  n  n  o  ra  n  -o  n  o  m  on  n  S  o  S  5j  n  n  3  5  o  o  n  io  2  !c  ri  S 
nl'?iJ22!Jf5r^£?5n£?!n2!M0!^£?H;4;^2®^^li“^1'^’©©rvW^OOO^Q»*O*lOniOnu.mrtlOClQ-«UlOOlOUJ 
ONN-OniNIMON-ON-OOiruONN-OONrvONN^-ONn/ON^NniNNniO-OniW^NriiDio^NNOOoioSNSio 


o-  o  *  «r  *>  o  —  **no*ii.-  «niLO 

■oruNN-cm  <i  NNoriiM-o-o  n  n  o  ra 

■5^no>to«oono>tooroQoo-no 

»t<!NNnini»ni'OnM^N».oriN<iNN 


<T  O  U.  O' 
NM'ON 

nor** 

■oniNs 


OOUDV  LU 

inoi'fl'ON  o 
*«nuju_nouj 

(MON>04DOni>0 

><<munuuiu 


OJ 

O' 

Q 

© 

if) 

Q 

O 

N 

CD 

o 

fv 

o 

jy 

UJ 

U. 

o 

»-< 

n 

n 

* 

m 

o 

N 

>0 

•0 

o 

N 

N 

N 

n 

N 

N 

N 

t*K 

fv. 

o 

o 

o 

O 

O 

O 

o 

O 

O 

o 

o 

o 

on  m 

O'  O'  O' 

N  N  N 

O  O  O 


n  *  «  ^  n 

n  n  n  n  n 

h*  ?**  s  s 

o  o  o  o  o 


©  O'  r*  n  *  m  *0 
n  n  *■***■  *  * 

N  NNNNNNN 

o  ooooooo 


O' 

UJ  O  (D 

O  li.  O  CD 

*  ru  uj 

O  O  ^ 

n  o  r*  o 

NNO 

o 

m  n  in 

<  ©  o  0-  n 

n  m  u_ 

w4 

O  O  - 

o  n  O  N  N 

N  o  o 

n 

©  *  <  o  c* 

«  Q  o  O  O' 

moo* 

O  *-  O 

o  fa  *  n  o 

O  N  o 

Qowm-.NO'U. 

a<oo*o*on 

o 

oo^^oo 

oiftniN^ryiftoiN 

UJ 

n  O'  u. 

n  o 

N 

o 

N  N  N 

©  © 

O' 

m 

m  m  in 

m  m 

m 

o 

o  o  o 

o  o 

o 

O  O  O 
OONO 


Qloo^o^onoHOOHOiLiLQinfQQiftinmftiooiftnii  u  m  in  ti  ii  **  ***■  ^  « •  * 

oift(\iN«-riiin(\iNrynn(\inru'0o**0Nooo>0'0r^r*O'0'0'0'0f'->0n(\irtJO'0'0'0 


Q 

o 

o 

r* 

© 

< 

n 

CD 

o 

a 

UJ 

UJ 

u. 

o 

m 

m 

m 

m 

m 

o 

o 

o 

o 

o 

o 

o 

Dr.  Dobb’s  Journal,  Number  54,  April  1981 


29 

161 


(Continued  on  top  of  page  28)  \  (Continued  on  next  page) 


c  m 

(- 
i-  • 


m 

l  m 
» 

•o  c 
u 

3 


*  m 
m  » 

t-  • 


■o  E 

'  1 


«•  3 
3  u 


•  C 

>  •*« 
m  t- 


c 

*  •*« 

•  » 
t  « 


i  -  3 
o  o 


W  P 

E  -o 
'  o 
I  >-  o 
»  «*.  «*- 


•  »  c 

I- 

ft  ft  3  ft.  ft. 

fr.  ft  «•  •*«  -*« 

Oft  JK 
P  U  ft  O  P  4* 


(-  Ol 

ft  ft 

€ 


3  W 
O'  o 

p  3- 
C 

P 

t-  o 

CX  C 


I-  . 

ft  c. 

P  o 
p  p 

ft  ft 

•H  fr. 


E  . 

Q.  ft 

U  T9 


O'  E  p 

-  Q.  ft 


8 

.  • 
ft  *0 


**  **  m  *o  a*  i 


3  -O  ft  T9  -O  ft  ft 


p  p  «  h  a 

ft  O.  ft  3  ft  O  I 

t  u  t-  a.  u  a.  ■ 


O 

CM 

© 

O 


CM 

© 

O 


N 

U 

u 


CM 

CM 


§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§§ 


«0N0>0 

nnr 


ryiLt^rtomniffitr^NonnH 

''■,.Oa**CMOaCMB 


U  i.  I'  »•  ■v  I'  ^  I*  >«  II  ■« 

oftftO'aiMruu.oa^cMoacM 

£»?5£,24;£?‘2P,G,£r*£lltP,n 

$ 


S0!,Q£?it^,Qr-Qtr,lO^r*101^  o^or3 

M'O-ONN-ONWN-O'ONnMJOlNfKN 


O' 

o 


O' 

o 


CD 

<0 

O' 

o 


8  O'  o  c 

So  o  o 

a  ft  O'  a  ft 

O  C  O  O  >0 

in  u  Q  h  u  o  a 

QOUhOUU 


d?  ?  ^  ?  y  ^  j 


©  ©  ©  © 

O'  O'  O'  O'  O' 

o  o  o  o  o 


O' 

N 


ss 


—« 

UJ 

©  uj  ©  a 

Q 

u. 

U11.UQ 

43 

N 

O'  <  U  Q 

O' 

O' 

O'  O'  O'  O' 

O' 

O' 

O'  O'  O'  O' 

o 

O 

o  o  o  o 

O'  O'  O'  O' 

o  o  o  o 


'  o 

•  z 


c-  I- 
u  o 


a 

'  . 
•  «*- 
'  H 

«*. 


c 

I- 

ft 

3 


ft 

D 


C 

O 

o 


cm  n 

ft* 

a  43 

N 

© 

O'  0* 

O' 

O'  O' 

O' 

O* 

N  N 

K 

N  N 

N 

K 

O  O 

O 

O  O 

O 

O 

p 

p 

p 

p 

p 

p 

p 

T9 

T9 

T9 

"O 

T9 

T9 

3 

> 

9 

P 

P 

p 

ft 

ft 

ft 

P 

P 

p 

T9 

T9 

X: 

o 

CM 

n 

ft 

A 

O' 

o 

o 

O 

o 

o 

o 

N 

$ 

© 

© 

© 

© 

© 

O 

o 

o 

o 

o 

o 

o 

43 

o 

© 

o 


CM 

UJ 

u. 

UJ 

© 

U. 

ft 

© 

ft 

CM 

UJ 

N 

a 

n 

O 

© 

>0 

O 

o 

N 

CM 

-0 

>0 

43 

■0 

N 

N 

N 

ft 

43 

43 

-0 

N 

CM 

CM 

CM 

(M 

n 

ft 

© 

IT9 

N 

Q 

O 

in 

m 

ft 

ft 

O' 

UJ 

n 

a 

O 

n 

O' 

O' 

N 

N 

CM 

ft 

43 

O 

O 

CM 

43 

N 

ru 

O 

43 

>0 

-0 

CM 

N 

N 

N 

a 

CM 

ft  « 

o 

a 

in 

O' 

o 

n  l 

j  < 

< 

N 

O' 

O' 

ft 

O 

n 

UJ 

m 

43 

N 

o  o 

CM 

N 

43 

N 

CM 

o  r 

J  o 

o 

43 

«) 

-0 

N 

CM 

N 

-0 

-0 

o 

U. 

Q 

Q 

ft 

U_  O  Q 

CM 

lL 

in  m  q 

Q 

tfi 

UJ 

O 

ft 

O 

ft 

O 

O 

a 

CM 

43 

O 

o 

43  CM  >0 

N 

43 

0-0  0 

O 

43 

43 

CM 

-0 

CM 

fv 

CM 

3 

43 

N  U1 

o  cm 
*■ 


uj  ft  a  Hulun 

35  D  -0  43  >0  -O  >0 

q  ft  cm  n  n  ft  O'  uj  cm 

-0  CM  N  >0  K  N  -0  3  O 

H^HLJftOHNOO 
<O<5N0H)NNf( 


ft  ft  ft  cm  ft  O'  cm  ft  ft  ■ 

N  *0  l 

n  a  <  a  n  o  cn  a 

N-OCOONN  N  >0  ' 
nmontpooftNi 
-ONON-ONON-ON 


'  Ll_  LU  U_  ft*  m  © 

<  -0  >0  43  N  K  CM 

:  n  O'  o  O'  a  o 

>  ft  o  cm  «  >o  cm 

i<tnootbL 


1  oo 

-0 

©  a 

© 

O' 

< 

a 

n 

ft 

o 

CM 

UJ 

CJ 

^  1  an 

Q  a 

© 

U. 

o 

CM 

n 

ft 

a 

a 

43 

N  N 

N 

n  n 

N 

N 

© 

© 

© 

© 

© 

© 

© 

© 

L^|  o  o 

O 

o  o 

O 

O 

o 

o 

o 

o 

o 

o 

o 

O 

30 

162 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


ft 

ft 

■at 

3 

3 

o 

ft 

t- 

U 

•D  (- 

ft 

f-N 

1 

r* 

-o  % 

X 

ft 

u 

X 

<*- 

ft  4* 

n 

ft 

C 

C 

c 

E 

o 

ft 

c 

3 

ft 

« 

3  * 

J- 

ft  ^ 

•H 

ft 

•*> 

o 

C  -« 

«•  ft 

o» 

ft 

u 

E 

t- 

C 

u 

a  O' 

in 

o 

1- 

ft 

3 

-*  + 

ft  E 

ft  ft 

ft 

■o 

o 

4* 

O 

ft  c 

U-  3 

ft  -o 

C 

<4. 

U 

u 

ft 

f- 

fi  3 

6  O 

■O  C 

ft  ft 

6 

ft 

ft  4*  U 

f4 

ft 

(.  4* 

u 

•*«  U 

■O  || 

E  ft 

ft 

<-  3  ft 

O  ft 

u 

ft  ^ 

C 

X 

IN 

«  a  1 

fr-‘ 

ft 

«*-  (. 

C 

•  ft 

1  X 

ft 

ft 

x  C  ft 

ft 

c 

'O  (.  o  o 

■O  X 

ft 

3  ft 

u 

4* 

U  -**  C 

X 

o 

ft 

ft  ft 

ft  E 

4> 

'D  C 

u  ft 

ft 

u 

ft 

u 

u 

(- 

ft 

1- 

ft 

-*4 

ft 

^  ft 

o 

ft 

E 

3 

ft  u 

c 

C 

4» 

1 

ft  X  ft 

ft 

■O 

4* 

4»  4* 

■ 1 

4*  O 

> 

«-« 

ft 

4>  > 

> 

ft 

•  1- 

ft  ft 

ft  C 

t- 

(- 

C 

c 

O  O  ft 

ft 

ft 

ft 

ft  ft 

W  «*- 

U  i- 

ft  -* 

a 

a 

•»N 

ft 

4>  4*  ft 

ft 

(. 

(• 

J-  -« 

9 

■1  C  -44 

' 

* 

• 

ft 

4» 

*■«  c 

c 

•94 

u 

O' 

4>  m 

A 

4* 

a 

ft 

•  4=  X 

v 

ft 

•H 

X 

o* 

E 

a  u  O 

-  O'  €  4>  CM 

X 

O' 

E 

Ol 

.  O' 

S 

o 

■O 

ft 

u 

ft 

ft 

♦ 

• 

a 

ft 

ft 

a 

ft  . 

a 

>-N 

*  >H 

u 

ft 

o  - 

-U  U 

u 

■O  u 

u 

X 

ft 

X  X 

X 

a 

X 

X  u 

M 

*  u 

x  O 

ft- 

* 

E 

o  m 

**  *> 
*»  « 
O  'O 


“»H  > 

*  O  ft 


~  ~  ~  O 

CM  *  «  ^  9 
*  *  *  *  o 

w  w  w  w  C 


r  £  T)  £ 


a.  tic 

•  *>  m 

U  4*  ft 
U  T)  « 

•  *  *- 

•  J-  ft 

•*  »  t 

>-■0  4* 

•  ft  u  C 

4*  4*  ft  e  4* 

u  a  (.  ■*«  d 

i  •  1  4>  a 

t-  U  x  «  c 

X  ft  3 

U  H  Cf^l 

X  ft  (- 

4*  «  Oi4>  « 
C  3  ft  C  4> 

3  O  -*  « 

O  C  ^  t  ft 

u  *  »*  a.  (_ 


•  ^  O' 
■O  c  c 

%  4*  4> 


ft  ft  t-  •  x 

u  o  o  i.  «o 


o  o  a  u 
a  a  u  ”» 


a  u  c 
•  u  -»  ft 


»  av  -o  w  tic 

3  OTITJTJ'OTJTJ'O  -»  (. 


n 

c 


HNOfft-OM 


mmmm;£;S!;£;S:2E:NNNN^*^^^a5®®DDtDQDCD©®©0'0'0'0'0'0'(>-0'0- 

ssssssssssssssssssssssssssssssisssilss 


)000000000«4«4^^*H^<-I 

;8S888S8888S5858S 


o  £ 

9  <  o 

o  «  o  o 

v4 

< 

o  o 

OOOC 

o  o  m 

;83S  K 

O'  m  m  O'  m  o 
o  o  o  o  o  o 

o 

(M 

5  8SgiS2fe  §  1! 

oo-c 

J  Q  Q  *0  O'  O' 

>  O  (J  u.  o  o 

m  UJ  Q  — •  UJ  Q  — • 

Q  O  U  -  O  O  (M 

Si 

mmQ-N-.ujaDuJCDujO'O  «  ^  immmml  «o  o- c 
uiououju.oiu.nu.nuj  uj  q  cm  cm  -  cm  m  ~  -i  - 

uon^GDmiuo^ 


m  03  m  aa  m  cd 

_  O'  O'  O'  0"  -  - 

o  o  o  o  o 


IMMMMl'a-(>^(> 

oooo 


ti 

u 

O' 

o 


-oonujon 

u  u  u  u  Q 
[MMMMh 

*  *)  o  o 


o  o  < 


Q 

-  * 
o  o 


88 

88 


<noiL 

Q  Q  Q  Q 
O'  O'  O'  O' 

oooo 


O^DftN(MBQ 

oooooooo 


U.O^rtDT-n-OCDO'BJ 

£  fc  *  £  £  £  £  t  It  *  t 

ooooooooooo 


< 

o 


o  - 

U  Q 


o  o 
o  o 


^  o 
.  o 
*-  o 


r 

V 


c 

3 


» 

C 

I- 

• 


c> 

<+> 


2 

K 

O 

*8 

3 

C 

C 

K 

5 


O' 

o 


o  ^ 

H  «4 

s  s 


(m 

s 


- E 

n  *■  n 

§88 


m 

u 

u 

m 

E 

O 


n 

t* 

i> 

• 

E 

N 


03 

8 


m 

t» 

t- 

• 

E 

O' 

•* 

8 


•  uj  nmn 
IN  N  O  N 


O' 

Hi  <0 

«  <[LntnniL 
*■  o  o  -o  n  «  n  «o 

ft  msm 

ntQNMQQmno 

♦  mot  >ooO'0'Ort 


Ntnnoonno 

NrtO4mni<0NO 

nouoooonu 

or^ft-nift-Nro-om 

3S85ftftiSSS 

P)U.QftON^(D^< 

rvnO'0««Nr^r*o 


eg 

88 


B 

CD 

ao 

o 


o 

< 

at 

o 


o 

to 

8 


♦  WOlhH^ 
*0  N  (M  -0  O  «0 


UJ  N  O  ft-  -«  ft 

•  3  <-0N<N 

o  io  m  o  n  h  m 

- “  NON  O  O  >0  O  >0 

mom  cm  uj  ft  o  uj 

O  N  «>  N  >0  O  N  O 

ftOftftU.0'O-«UJ 

-  -  - 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


31 

163 


( Continued  on  next  page) 


c  c 

"■«  c-  --I 

ft  o  ft 

P  P  CL  T9 

Cup  c 

ft  (  H  4»  H 

■**  L-  3  ft 

p  I  *  a  E 

O  P  f-  P  ft 

3  U  O  3  C 

or  p  o 

IN  | 

C  *-•  Cl  V 

C  O  T»  6 

3  0)  C  3  U 

P  «  ft  P  P 


-.Op-*  at  u 

ft  '  P  T9  P 


*-  C  (- 

CO  ft  ft 

OP  C-  ~  T9 

•*«  ft  O  P  C 

«  (.  tf  O  * 

•h  •  h  3  (| 

u  E  >  o'  6 

ft  3  -•  M  ft 

C  C  T9  U  c 

CL  I  H  P  I 

U  ft  ft 

ft  P  T9  C  T9 
-*  t- 

Ol-t  3 
C  -*  4J 

•n  ft  ft 

ft  u  (. 


ft 

O  T9  P  O  N 

— '  — •  *  *-«  ft  -H  . 

P  P  1  £  T  £  ft 


I  U  ft  — «  «*. 

:  p  C  ~  x  ft  u  . 


4-  M  * 

:  ft  ft  C  ft  . 


ft  w  n 

■q  4-  4>  4. 
-  3  3  3 
P  P  P 
♦  +  ♦ 
rg  rw  ai 

p  *  *  * 

o  P  P  P 
O  CL  Q.  CL 
O  P  P  p 


■o  u  ft  a.  p 

T9  T9  T9  C  3  O  ft 
-*  ft  -*  •*  CL  CL  t- 


3-0  f-  P  x  -o  - 

Q.  — •  O  ft  ft  — <  • 


•*  o.  ft  a  u  ap 

3'O(_x03^-.r-.^^0ftt-f_(.(_x0ft 
a-<”*fta.aucj-j.a.T9-»oti-»a.c 


3  3  3  3 

o*  a*  a*  o* 

ft  ft  ft  ft 


Illlllilllilllssssssl  sssssssssilsslslsli 


nmn 

ft-  «»■  (».  < 
«*-  ft-  ft- « 
3  3  3 
•«  P  P  P  „ 

o  *h  rg  n  ^  i 

NNNNNf 
o  o  o  o  o  < 


Ift-ONO 

NNNN 

o  o  o  o 


ih  -o  n  n  io  h  (h 
SUNfyQUU 


O'  <  o  a  in  ul  o 

0-  0“  (h  O'  O'  O'  < 
<<<<<<< 
o  o  o  o  o  o  o 


o  o 

§  K  i-  s  H22:  s  22 
ESSSSSB  £iRSSSS5SS;SSS35S3S 

<<S2£S£®££££ko232SS 


o  o  o  o 
o  o  o  o 
O  <  ft-  W 
(M  ft-  J5 


*  .  c 

p  f- 

X  ft  p 

p  p  ■* 

ft  E  p 

3  CD  3 
u  CO 
(-  -* 
ft  ft  T9 

o  3  ft  ft 

o  c  c 
f-  ~  ft  •*« 

T9  ||  P  P 
T9  U  C  C 

ft  U  ft  ft 

II  «  II 

ft  ft  -H 
T9  C  O  P 


C  ft 

*  L-  OI 

C  3  ft  o 

ftp  •»  p 

P  ft 

*  f-  ft  T9 

X  P  r-« 

OI  ft  H  O 


M 

ft 

P 

■r4 

o 

ft 

ft  OI 

C  ft 

ft 

4- 

ft 

ft 

ft 

ft 

1  u 

OI 

c 

•»H 

1- 

ft 

ft 

(- 

4- 

ft 

ft  1- 

3 

CL  P 

u 

3 

4- 

ft  T9 

u 

c  c 

O  ft 

ft 

6  CL 
3  m 

C 

ft 

E 

o 

3 

TJ 

p  u 

ft 

->  ft 

ft 

ft 

■ft 

> 

ft 

ft 

JB 

3 

-X 

C  ft 

ft 

ft 

01  >4- 

ft 

O  4- 

o 

ft 

ft  ^  E 

ft  .. 

ft 

f- 

C  --4 

E 

C  M 

E 

C  u 

■»  ft 

p  C  I 

O  4 

.  P  U  -K  -• 

*-  -«  U  4 

ft  3  a  ft 

P  ft  C  P  C 

U  ft  M  ft 

(-  T9  | 

ft  ft  CL  I 

a*  •  3  ; 

P  C  C  I 

P  -H  C  «■ 

6  cl  ft 

■O  C  ft  ft  ^ 

t  o  jih  : 

ft  4-  M  U  t 


p  p  -h  p  ai 

ft  ft  -f  ft  -f  a» 

»'  ON  '  oi  p  -  .  ' 

etc  -  O  -  (h  .  O  u  ft 

pum«  u  "  u  rg  '  cn 


P  P  P  ft  -*  at  T9 


CL  P 

O  ft  P  P 
CL  C  T9  T9 


P  P  -* 

ft  ft  »-*  Q.  CL  T3  TD  TJ  TD 

,T5  3  3  ft  O  O  CL  L-  CL  L-  a  (.  CL  L-  CL  C-  T9  C  T3  T> 

|>-»a.Q.ucL(Lu~>u~»u— >ou~'u->ftftmft 


T9  T9  c  CL 
O  T9  T9  -*  o  T 


r^ffi(ho^riinft-NO>0N©(>o^CMnft-moN0D(hO^CMnft-inoNGD0'O^rgnft'inoN©a'O^rgnft-nor^mchCi^rur» 

ooooooooooooooooooooooooooooooooooooooooooooooooooooooooo 


ft 

Cg 

O 

ti 

Ui  ft 

n  rg 

^  O'  O'  \L 

quo  n 


n  ft-  m  (h 

o  o  o  o 
<<<< 
o  o  o  o 


o  <  o  o  ^  < 

o  o  o  o  o  o 

D-^rgiMfio  ^  ft  QiuoQ<(\ioMnHNiML 

oonooo  eg  o  o-Hn^norgo'J-'OOOO  q 

m  uj  o  —  uj  a  *-«  <Ninino^^uj©uj©uj©*oiiJOUi©oo(h(h&‘(hinii.o^Q 

q  ouhouoi  nftouioiuuLLrgiLnii.nii.iLniLn(juirgrgrgrg©>o^Qrv 

«  UUJ^ftOO'  UU.O^Nifi>OMMaQU.Hntf)MMDQlLH(\inftrXM)-< 

o  ^^rgrgrgrgrgrgrgrgrgrgnnnnnnnnftftftftftftftftft 

<  <<<<<<  <<<<<<<<<<<<<<<<<<<<<<<<<<<<< 

o  oooooo  o o o o o o o o o o o o o o o o o o o o o o o o o o o o o 


32 

164 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


Ey£2,f!£n£Ps,5®yruajr,<,s'®®®<-)<n<<no*otf3Q<Qo*on 

OOOOlOOOOOOOOOOOOOOOOOOOOOOOOOOOOan 


j  jcn< 

>  i  U  LL  Q. 


ooooooooooooooooooooooooooooo 

noit  mo  r*  *  < 

o-*m*<hoxjoK>  n^z  n  ^<u.u.  in  ku. 

?  X  U  U.  a.  •HHKh-Kh-KKKKKKXXZ>KO:03Q:(r£rD  Q  3  n  5 

KKiiiLiiE>(D(n(n(n(ji(flU)www(flhhhhWB:(niEQ:Q:fflujiuoBa 

M«»»U00DD0DQDD0tlQ()90!ljtiiiu.l£S||ii5j' 


n  •<  rj  m  r(  r(  o  <«  —maCM 

tn.r-«i>  oon«oaa£iinxiN  m  niNo»-iiiii.>itK 

>aCOU.O->OHKh-HK»-K>-KKHOIZZ  ttdireaDQhhJD 
K0ClLlLlLZ>lfltf)WW(O(D(DID(niflWhl-hl-  EECECUKUhllD 
OKDD3Q*-«Kh-Kh-h*HHh,h"H-h-UJUJUjllJll.liJUJUJUJUJQ3UJUJQ:K 
MQDfflUQQQQQQQQQQQQ03OOJEE(LQ.O.Q:Q:l/l(/lh3 

M<ujiL(j<^(Mruinn>oniLU.o<ui(jii.^ri<-uj(j<u.ONu^ryom 

o^niHON<<ry<riMicDn<n<ronuowca«-oQOQ3^'OnHn 

oooooooooooooooooooooooooooooooooo 


rji  ^  a:  ^oooo  oi  in  a  <  o  - 

JEElii  OON^N<H')O0:3  Oi  <  <  O  >0  Q  II  O  K  U  Ul 

OOUUlL>  ►-HHh-HKKh-i-Kh-  IJZ^KKKKKOKhWlLD 
^uju.ULULZ>(n(n(n(/)incncninco(nw  hhhntKirtEaiiiui-io 
QWOODOH|-KhhhKHhhhhll.UJUJUJ(LliJUJUJUJllJQlUlJJliJli:h 
#*OJIDOUQQQQQQQQQQQQ|LOOO‘)rElLa.Q.B:t(nini-3 

o*^<ooa)^^<r^'O^Qn<ncaonnujnujQcaiuwo^N'OQ®n 

00(M00HniniiaryiMU-flni4H^^0n<o0HryHQ0'0mH^0o 

oooonooooooooooooooooooooooooooooo 

-  Q  Z  ®  U)  ON  Pi  O  ♦  ^  0)  «  HZ  < 


^  «o  o  o  o 

O  O  N  ♦  N  1 


HUJJJJ/-"rrr-rrrrrrr 

•  #idoiqiqqqqqqqqqqdq 


22^'£SD!S£tQ?‘5£C??Qn,noor'|Q,*'a:>wii.«iij'On«**(hory 

OOO444OHHNrtrtn-0>COMDa)44lMhH0hHiflt<SHSo!!H 

0000<0000000000000000000000000000t3a 


*-  4> 

~  m  d 

9  C  E  a. 

■a  L  C 

3  C  M 

4>  4»  O 

•H  •  h  4» 

*  *-  p  (■ 

fc  «d 

fc  •  4> 

li  Oi  3  HI 

*  m  a*  OI 

*  h  f. 

u  f.  4> 

(-  c  c 

c  «  -h  ft 

HU  »-  .C 

—  Q.  4> 


i-  -c  , 

fc  v  a 

3fcO.iT) 

O*  TJ  o»  *> 


a* 

Ch  *  E 

-fca-u- 

I  u  "O  u  *B 


O-  co 

•  cm 

fr  •H  -H 

•  MJ. 

h  £  CM- 

o  4>  m  m  4» 

•  U  -H 

C  OI  > 

o  c  t~  m  o 

U  H  4>  £ 

C  .  V  U 

o  v  o  -h  q, 

m  9  c  *  - 

•  C  •.  *  at  o 

t-  m  -h  =o  c 

■»  •*  f-  •*  •*  •« 

« 


•0  E  O  » 

•  a  •  •  i. 

U  U  I  N  U 


C  (h  I-  4» 
•H  (h  T5  3 

O-  tj  a. 

-  Ch  m  ♦» 
«  I  3 
4»  O  •  O 
*  O  4» 

■O  O  3>  • 
O  x>  f- 
9  O 

f-  »  4>  4» 

1  Oh  «  * 

C  C  t- 
H  fl  -H  O 
X)  (-  <4-  4* 

N  H 

u 


O 

O  O 

O  (h  O  (h  O  (h  Ch 
H  ^  >  ~  >  > 

->c  ~  >  c  *>cc 

•<  -H  o  •  -n  O  fc  •*«  o  O 

TJ  T)  U  T3  TJ  U  T)  'D  U  U 


4*  >— «  CX 
fc  <0  O  ^  XI 
l-  u  a  ->ti 


*  a.  4» 

3  TJ  T5  H  O  *  . 

a.  -i  u  a.  (_  - 


-•  4>  *  «-l  0.4* 

TMJ«t(.al3UT)l«OI 


•— I I  >-«  «-l  H  H  H  4J 

o«otjoot)iiiiii«i 

’-'UU’HUU’HUUUt- 


SS^5^Bggis2il**K8!S?5S5:||!|:8SS8888B882  =  22S22^5S8S!ll8SS!S{J8!6 

SSSSSSSSSSSSSSSSSSSSSSSSSS222222222222222222222222222222 


<■ 

N 

<  o 

<  o 

<r 

o 

O  01 

o  o 

01 

o 

s.  *  y 

&  m 

u. 

il  o  m 

m  aa  n 

0-0  0 

n 

IlOO 

o-  a  ~  cd  ^ 

m  iu  h  q  h 

O'  o 

LU  UJ  O 

nunon 
<  <■  <  m  m 
<<<<< 
o  o  o  o  o 


IlOhoIlOPI 


<0  N  Ch  O  U.  O  «h 

m  in  m  if)  ip  ^  o 
<<<<<<< 
o  o  o  o  o  o  o 


TromooujOHfiinmfflO' 

00*0«0«0'ONNNNNNN 

<<<<<<<<<<<<< 

ooooooooooooo 


H<<0<<0<<< 

oooooooooo 

1D«J'Oh|J><h(M> 

UJ<(h'0<0‘-0<(h(h 

^QQ-.QQ^QQQOs 

•HOO^OO^OOOO 

<Qonoo'ou.oim® 

<<<<<<<<<<< 

ooooooooooo 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


(Continued  on  top  of  page  32) 


=?  <  cr 

3  <  S) 

Oh  rr 

<  x  c 

C3-5 
2  Cr 

>-  *C  X 
*<  'J 

<s>  CC  X  • 

J-  cr  x  C 

>•  <  CJ  2 


x  cr  a: 

3  h- 
c  >-  3  h-  2 

}  <  <  <  < 

J  cr  x  h-  <■ 
c  or  f-  a  <x, 

<  -•<  jj  ; 

-  -Li  CC  <  - 

c  cr  2-  h~ 

J  w  *  <  J 

:  I  x  J  Q  : 

cr  ?  > 

:'jh  < 

i  x  co  h-  2  a 
•  x  -l1  c  cr  * 
D2Z<; 


h-  -O  < 

30*3 

<<U'JI 
x  cr 

cr  <  c  x 

IhO 

jjj  < 

CL  Q  X 

h-  2  <  cr 

—  C  h 

2  h-  2 
CO  <  r-  3 

*  c 

coax: 

a  <  <  a  2 


:ap«>§xux2x<u2xax«AX: 


xx-x-xxp- 


2  XX 
X  CO  ’J 
•  3  3  -IL 

‘N  «cccr«x: 


3~ZS33  «33?3S2^332l3532l252^|^il|||^ 


)  o  o  o  o  o  c 

■  <\n  vin  or* 


>  o  o  o  o  c 

>  O  O  O  o  c 


O  o 
CO  <  JJ  o  r 
<M  —  X  fV 

••m  xi  o  x  : 
O.  C\  (\  f\  <\  c 
x  x  x  x  x  . 


■(MOVO' 
IOOOO' 
.XX  LX. 


3?5l°l>B2RS go Ogogo 00030000000000 

8iiaRSs3o3g§SS3^2  2 33 32  =  321 

>OOOCCOOOOCCOCOO~r-  3T  - - 

w  °  00X00  0  00000000 


O  f  I  ? 

1 2 1  ?  1 1 1 1 1 1  j  -  2  ?  i 


QQOOOOOOOOOOOOO 
s\  or-coao  —  c\nvxi  on  3}  > 

ocooooooooooooo 


c  cj  3  x  x 
inroinn 

.  X  X  x.  X 

‘  N-  h*  **»  (S-. 


o 

'  o  CO  ^  o 
-  X-  N-  23  f\j 


rsj  t/? 

on  c 

v  i  3 


—  «  c  « 

J  *  *  h-  II 

:  <  i»  lo  * 

J  II  -  -  « 

J  <  o - 

••  J  CJ 

)  o  x  .* 

\  O  — .  I  K 


I  o<i>  * 

)  II  X  x  w  X  J 

>  1  0  J  - 

«  s 

•  o  o  o  c 

'^OhOhr 


i  is 

jj  o  h-  n 

-J  II 

CJ  <  -'  00 

o  - 

2UJvl/) 

■i-^7  2 

1  Jlj 

h-  X  _l  - 

II  o  c 

•  o  v  II  C 

3  O  ~  > 

2  — 

X  x  x  o  ; 

*  c  —  cn  o  h 

II  f—  — _ I  —  - 

0  CJ  O  >  X 

-  3  ♦  2 ; 

X  -  <  o  X  c 

:  ~  l>  *  x  x  j 

-  -  O  h-f 

:uo-z 

0  <  II  X  I 

•  3  X  <  X 

►  x“  O  ~  n 

c  cc  2  o  «s  a 

i  -  x  n  cj 

c  ..  x  W  X  c 

•  *  1-  CU  2  —  C 

-  *  XX  r 

-  *  t  S)  J  X 

r  p  a  cr,  r 

i  h-  II  3  —  -I : 

-20-  X  Ci 

-  ox  ; 

LJ  OC  x  II  —  O  , 

o  x  —  >  r\j 

i  o  -  o  8  ~  - 

00  II  O  —  2  - 


■  S.  2  —  5 
«  2  •  • 

1N2-  . 

■Oh-  *  x 

"«  X  o  CO 

JOJOTwO 
:  ^  “  o  v 
:  A  —  p 

<  +  —  c 


<  rsj  n 

“  o  co  a  . 
°  : 
o  o  - 

o  a  (a  ij  j 

N  O  l\ 

5  o 

a  o  o  2  ; 

o  o  o  o  c 

*\x-> 

<25  « 

oan  : 
ojo-: 
o  *  •  * 

x  X  o  3  l 


o 

O  O  o  2  C 

—  CNJ  Q_  "I  <  1 

—  C  —  2  - 


)  o  o  o  o 
■  s\  o  o  o 
j  <N  (\  n  < 


:<<<<. 

>3333: 

>  o  o  o  o  c 

>  —  fM  n  ^  j 

•  ''T  <7  ■'T  ^  > 


X'  2  < 

o  o 

:  x  rvj  < 

:  3  O 

>  —  n 

-  O  CO  U 

X 

)  CNlO  — 

3-000 
e  3  Xi  O  x 

■  n  o  x 

3  x  3  C\  o  - 


3  0  0  0  0  0 

3  o  o  —  (\  n 
r  ^  x\  x>  >n  x* 


:  2  X  x  < 

JCO  W  (\ 


v  n  n  o 

.  O  c\j  CM  n 
1  3 

O  N-  fNJ  ^ 
>  N-  O  ^ 

J  n  n 

^  <\  o  < 

)  3  0  0  0 
i  x  x>  o  X 
n  n» 
■  >  3  X  O 
i^ONO 


CVJ  o 

XI  ° 

x  rvj 

•  o 

—  f\ 

•  -  o 

0  3  0 
X  CJ  *3 

X  «  p- 


:<<<<<<« 

'hhhhhhl 

:<<<<•<<« 

1333333: 


:  <  <  <  < 

.  I-  l-  L_  h.  Q 

(  <  <  <  <  o 
>3333- 

>  o  o  o  o  n  < 

j  o  vr  xi  O  CJ  r 

>  o  o  o  o 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


2 

CJ 

a 


3  2 

aS 


X  a 


o  UJ  - 

►  '«!)  I—  c 

)  X  >- 

i 0  33  f 

-33 

;  x  jj 

:  a:  2 


l 

<2  f 


)  <  a 

•  *  CJ  2 
:C«< 
j  o  u  h-  x 

:  O  —  x  o  ^  <m 

:  < 

7.  ^  M  X  Z  - 

:  2  c  OKfc 
CO  O.  —  —  C 

JhHC-Hl 
JUlih^xa 
j  2  a  a  a  2  x 


2 

I— 

2  X' 

c  cr 

£  a 

Z  <2 

a  o  < 
h  a  uj 

JJ  Z  X 
2  -•  < 
I— 

cr  a 

£S% 
2  2  1— 
UJ  X  a 


< 

XJ  XI 
3  -J 
O 


xj  a  i/3 
a  z  * 
<myi 


-J  V) 
J  X 


>-  X  >-  f 
—  <  CD  - 
2  i—  c 
*  a  w«  i 


to  ; 

^  * 

O  (O  L 

XJ : 
-J  f- 

<  >-  c 

j  CJ  oq  ; 

2  ♦  o' 

:  2  2  : 


H  XJ  t 

—  a : 

CE  UJ  * 
*  x  : 


a 

ir 

(J 


a 

:  uj  a 

J^< 


j  <  < 

-h-x 

-  <  CJ 

j  a 

XJ 
- t-  *— 
C  X  — 
J  XJ  CE 
:  2  2 


a  c 
>•  to  - 
<  x  o 

CE  CJ  3 

XXL 

<x  a 
CJ- 
j  x  : 
c  UJ 


in 

x 

a 

8s 

i-  x  a 

CE  I- 

<o« 


£Euj: 

CE  3 
iCC- 
CJ  H 
X  <o  t- 
X  X  - 
CJ  CE  3 


:gE£*  o- 


I-  CE  l 

<  ce  : 
a  <  : 


xv  <> 

<COam 

j  <  >- 

)  ^  CD  CD  CM 


t-  73 

X  < 

o  ax 

<  a  cj  x 

X  =3  <  I- 

x  a 

2  >  2 
C  2  2  X 


x  ►-  in  — 
o.  x  a  cr 
x  x  <  h- 
CE  2  x  in 


a  x  < 
a  x  2  h  x 

2  f-  X—  CJ 

—  a  N  CE 

2  CE  X  Z  <  I- 

21-  X  UJ  CE  X 

in  x  c  a  x 

<  a  x  2  z 


CJ  X 

I— 

a  >• 

I-  CD 

35 

<  < 

X 

x  cr 
i—  a 

>-  X 


:  a  a  cr 
•  in  3  h _ 

)  X  <  tO  CJ  N 


■  I—  x 
.  a 
:  Cr  x 
:  s  2 


x  cno  — 

l—  x  2  r\j  re  to 

x  f—  2  o  x  x  < 

z  >-  XCNJH  o  x  x 

•  3  'J  •  *  l/i  •  a  n- 

x  inj  a  --sj  x  <  x  Ex  x  x 

X2v>2<ZX'-'<AX«aH2«aX«»X 


£ 

X 

X  1- 

>  X 

5  «  8 

3  X 

3 

a 

X  X 

2  a  a  o 

32 

a 

x 

O  cr 

<  Jxo 

a 

X 

Jh 

E—  •  • 

UJ  2XCJ 

X  f- 
O  2 

5 

-.8 

x  a 

i—  </»  2  o  a  </> 

E  E  <A 

X  «A  2 

X  o 

in 

o 

>•  X  -* 

2  CE  X 

<  i  X 


X  -5  0  0 

x  a  ax 

—  <  X  Z  x  2 

j  x  *  •  •  •  a  5 

:xxx<<*sj«>-*t-E 


cl  -  x  a  a  ax  a  x  a  a 

02o<a230oao<2ooco 

20XCJ*<-)XXXXXa“)XXXX 


XNNJI  XX 
aX2Z  ^3XI/)hl 


-  —  _  —  _ _ .  _ _ _  u  a  a  cj  o  z  a  z  o  o  in  oxz 

a<xaa<->-)3o<=5ina2accL2xazo2z->o->a2a2oaaa.2  20<-) 
xxoxaxoaaxxoaarx-^xxo-ioa—x. - axax _ i— o-xxxaoxcja 


a 


x 


X 

CJ 


CO 


2S2802  2299P2920P2°9!20202000000oooqoooooooqoqoo 
M0>O-fMn<r^  0  co  >  O  —  rg  ^  ^  o^rooo-fMnviTiONCO^O-nj^^^  o  r->  a  o  O  —  rg 

oooooooooooooooooooooooooooooooooooooooooooooo 


ooooooooooooooooo 


a  a 
-  o  a 
x  rg  a 

c\  n  n  n 
r*-  r-  r-  i*- 
X  X  X  X 


■  rg  n 
>  —  r\ 
J  r  g  <\ 


a  > 

x  x 


CC  C3  C 


:  <  a  x 
>  a  a  a 

.  x  ’X  X 


x  n 
X  X 

—  CO 

rg  — 

a  a  x 
a  a  a 

X  X  ’X 


x  a  x  x  a  f'")  O  ax  lO  x  a 

axxa  x®<\  xx  o  ax 

a  o  o  a  a  a  x  —  o - xomon  n  a  o  oonx^j^  oxon®  ao 

a - X  axaxcgxxxcg<\*-cg  rg  rg  —  —  •vrgr-cgXOOr-CDrg  U  — 

—  —  ^■aaaaaxooa^inoao><ouju.o  —  —  rgnaar>-ao<aoaxixorgrga 
^^<>c>o>o>^0'^<<<<<<<<<<<<acoaaaaaa;aaac-iaaaacjL)',j'j 
.  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  x  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X  X 


a  o 
a  a  — 
a  -u  o 


OJC 

e 

V 

3 


o 

a 

3  > 


a  >• 
>•  < 
a  3 


>  2 
X  X 

a  o 
2 
O  f- 
co  a 

1 

a  * 

2  x 

i—  a 

x 

?5 

x 

X 
X  z 
z  a 

—  < 
J— 

o  >• 

s“ 

a 

C  X 

\  s 

—  7 


2  CE 

<  a 


a  x  x  s 

>■  Q.  E  < 

<  <  a 

2  (—  h- 


a  1 2  a 

2  X  S  X 

—  3  2 

i-  a  — 

—  a  z  x 
a  i-  <  x 


a  2  x  a 

X  X  21  D 

a  <  3 

a  z 
x  <  >• 
x  x  a  < 


a » 


51: 


x  a 
x  a 

X  3 
<£ 


a  —  • 

cr  a 

ilH> 

2  a  < 


•—  a  •  — 
—  022 
2  X  X  f- 
J2ha 
H 

a  >-  —  o 
<<22 
*  3  S  — 

a 

i—  a  x  < 
—  >■  2  x 
<  <  2 
2  2 

X  2  >•  X 
X  <  -  ' 


3 
0  2 
c  —  _ 

2  X 


is  25: 


:  2  a 

iu?J 

e  a  I  < 

:  <  x 

:  a  x  a 


<22  a  x  a 

»-  X  <  X  2  2  h- 

a  i—  x  *  <  — .  cr 


a 

£ 


<  <  <  x  2  a  h- 


jecajHf 


[J.  S.Z 


il-  x 

XX232a<<(— 

J2h-<a»-  —  xxa 
•  <>-h-  a<22< 


il  8 


■  a  z  x  i- 
<020 
ana 

:hh-7 

•  a  2  a  x  c 


:5i  i 


X  5 

► 

i-  a  s 
a  z  l 
2  x : 


>■  >• 
'  <  < 
2  2 
2  2 


8  Si 


—  a 
a  z 

3  < 

2  H- 

3  0  2  X 

X  UL  <  f- 

f—  I—  — 

a  h-  a  2 

>•  2  X  S 

a  —  >•  a 

w  a  <  >•  r—  X 

II  ^lleh-D 
CD  O  2  z 

to  —  X  >  X  — 

a  2  <2*- 

2  1—1—202 
C  O  2  X  2  i-  c 

i—  x  x  a  <  a  a 

a 

x 

O  c 


-I  < 

r- 

i—  a 
2 

—  >• 

£3 

2 

>•  < 


£l 

2  CD 


53: 


X  X  X  X  X  X  C 

—  exxxxxx  oocoax  X  • 

fs»>rgoar^^ax<axxo  gi 
<  <  —  o  n  a  o  x  oo  o  o  5  o  cj  5; 

noorgrgrgrgrg - nvvvn  v 


.  2  •  X  2  " 

•«*<<<?: 


X 

n 


ox  2  a  —  — 

ce  x  o  a  c  <  O  —  Q.  : 

o  a  □  o  x  o  a  2  o  f- 


8£ 

88liiii8 


8S82 

- rg  rg 

8888 


z 

O  —  oaoooorjaaooo^o 

—  300000000000000 
|— xxxxxxxxxxxxxxx 

2 

—  >- v- a  x  2  x  a  a  i-  o 

X  2  2  <  2h-ah-XXZ<H22 

x<2mz3>-a>-xxxzaxx 

a2<MOacOHOOr:322>->-h« 

X>X2  a  02222XX22a 

-**a0  2h-225XMooa<<<-  -  -  s. 

OOOOOOQOQOOOOOOQOQOOOOOOOQPQ 
esi  ONO>o-rMnin  oncooO  -  rgn^a  ono5o 

cvrgrgrgrgiNiigfgnnnrinfnnnnv^w^vv^vv/i 

8888888888888883888888888888 


2 

< 

(— 

a 


o  o  o 

—  rg  n 

sss 

o  o  o 


nx<rgoa>-^aaooaax  xx 

8r^>  —  »noox— <oxxn  am 
<<rgrgrgrgrg  —  OOOOOO  OO 
OOOOOOOOOOv^v^ro  •» 


Soon  v/i 
o  o  o  o  o 

U.  X  X  X  X  X 


f-  o 
>•  a 
a  -y 
cj  a 
2  ■< 

O  <  X  o  x 
2  x  a  I—  2 

X  2  < 

<  x  a  x  x 
>-  t  O  2  3 
>•  X  < 

maze 


J—  <  X  X 


<  X 
2  2H 

^  a  c  x  a  3 
—  <1-  x  z  o  —  x 

a  z  <  h-  z  o 
5  22  a  a  v  x  h- 

003<<0H2 
I— I— xxx<>»< 
aar-22aaa 


a  — 
x  h- 
>•  a 


*—  •  a  a  z 

cj  •  x  aa  a  a  • 
a<<xo<A2x<r»r^v 


ax  a 
a  a  o  a  a 

axoao<xa2  2  2 

aa22axoaao->cj 


n  o>>a>o  —  o 

iSi^"1ooocooc 
000000003000 

ccooooooocco 


5  a  o  a  a  ^ 

°  x  o  o  o  o 

—  <  a  -o  —  a  a  a  x  a  x 

O  —  X  X  (\  u  f\i  N  X  <\  t 

x-r\n’iNi''<ajjxo 

O— - - 

x  XX  XXX  XX  x  X  X  u 

>*  ^  ^  >-  r*  r- 


Ci. 

2 

c 

o 

*8 

a 

•S 

Cl 

K 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


35 

167 


of  page  34)  I  (Continued  on  next 


ft  C 
— <  >  OJ 

U  -HO) 
T3  t)  y 


I  U 

»  O  TJ  CO 
C  I* 

»  •  flj  -H 

•  <0  f  **-i 

10  4)  0) 

:  -h  b  •  *j 

I  C  A  II  h  N  B 

i  o  c  e  i  i  u 

I  3E  <B  co  co  ® 

C  C  to  as 

«  -h  I  01  a> 

I  U  4J  t-i  U  ►, 

•  C  >,  B  *0  T)  W 

•  tO  U  <0  T3  "X3  *H 

i  vi  w  h  a  «  u 

c 


00  4)  x 

v  e  w  « 

•n  -h  b 
hc« 

W  -H  C 

4)  >S  | 

C  u  t)  u 

■H  Q.  4)  CD 

O'  ^  B  «  «J 

O  4)  C  ft 

•  ft  ^ 

•  «  41  l<  Jl 

•  c  ki  a  s  cm 

•  o  o  all 

•  -H  B  4)  C  «  CD 

*-»  k<  |  0)  CD 

U  k  a  U  41  41 

•  TJ  O  CO  k  k 

0.0  *T3  CD  kc  *T3 

•H  U  <  -  h  Tl  T3 
N  •—  •— ’  ft)  cm  «  9 


a-H  41  to 
k  ^3  4J 
N  O.  CQ  C 


«  CD  0) 

*J  O  B  u 

co  a.  d  o 

CD  0) 

•  x>  m  ft 

►,  B  O  41 

*-»  u  CD 
•H  ►,<&> 


00  H  .*»!  « 

CM  CO  «~S  4) 

—  c 

VHWOOU'H 
—I  4J  0)  s-'  ft 

^  o  k  a;  —  — 

d  co  T3 
jo  ft  •*-)  o 

•  •  o 

^  4)  -s  * 
sO  C  ^  ^ 

CO  O  CO  H  .« 

.  w  V-  00  c 

:  — •  u  4)  ■ — o 
.  xi  o  E  a  «  •* 

*  a  «ki  «  ft  u  j 

)  C  N  4)  (O 

CO  o.  _J 

<  k  k  k  k 

)  co  co  co  CO  u  u 

4  £  T)  JT  J=  c  c 

•  O  —  U  U  ft  ft 


J  =>  o  z  in 

.  in  in  x  < 

J3C  2  CQ 

c  O  3  X 

UJIU  J  JC 

i  o  <  x  in 

-  ->  c  z 

j  x  =>  5  x  5: 

MO  M  => 

-  ~  _i  in  —  m 
:  cc  <  \  cclu 
:  x  O  m  s  a; 


—  <  x  O  * 

CC  hlULUD 

2  z  x  in 

c  o 

O  M  X  OJ 
M  CCQ: 

LU  MC 
CC  M  a  M 
<  -  3  3  in 
x  cc  3  5  x 
o  2  <  <  a 


<  <  a 

>  O  uj  cc  cc  > 

ca  3  q:  <  ^ 

a:  <  >  cc  a 

mc  c  e  c 

a.  m  m  x  u.  cc  « 

ex.  e  —  cc 

<0:  cc  uj  u 

>  M  MMX  C 

a.  a.  a  o  * 

m  a  cc  <  uu  in  : 

in  OJ  <  <MXLU2 

uj  o  >  >inu>  j 


C  OJ  CC  — 

Hc8£  1 

cc  m  <  a  cr 

§i-x“33 

<JC5<< 

3  in  00  3  3  3 
3  x  in  3  z  z 
<  a  s  <  uj  uj 


3  •  O  CD  M 

J  J  JQ.  J\  •  CC  M 

</>XXXOXZ«/><  S  CC 


I  >-  ~ 

33  -J  O  < 
3  X  -J  *  • 

«CCvI<(j 


)  WQ  O  < 

•  a:  j  •  • 
ca  <  2  X  <  O 


in  a  jj 

>•  M  >- 

m  a:  o  in  cc  - 

cl  J<icr<: 

CC  x  ^  Ul  UJ  ^  y 

<xu  *  •  3  -  •: 

>  •  ‘UJJ1JJC 

►  3C3Q3XOZXC 


CAXXXX<X<UJ<<3Q 


aaui n 

□  c  z  - 

Ul  X  —  CL 


m  a  3 

in  e  cr  c  : 

Q:  Q.  “>  Ul  . 


C  -J 

ra-i  0  3  m 
CO<3z33UJ 
:  uj  o  -J—  <  _j  a 


Me  J'jg  m 

>-33<Z33UJ 

C3  uj  _l  o—  <  JQ: 


>-3  0  M 

<C<33x3vnrr 

ceuju  jji  jcc-i. 


!33  =  8: 


2299922S0P2099P2220?0009020200o0°ooooqoooooooo 
~  ^  n  OMJJOO-Mncrifl  OMDOO-fNincTJ^  ON  CO  0>O  -  OJCO^XI  ON03>O-f\^Cln  O  N  CD 

>0>>00*C>0000033000  —  —  — - f\jrMr\jOy40grvj(Mrsif\jC\coco'^co."Oron^rn 

- - ojrsjf\jcNjf\jc\rur\jrsirvjf\jr\f\jf\f\jf\jrgogr\jr\jrvjojojf\f\c\f\f\jf\jf\rsjCMr\irsjf\r\jf\f\Os 

0000000300000000000000000000000000000000000000 


ooooooooooooo 
c\  n  4T  in  ono3  5o  -  rvjn^ 
nx» 

(Mf\jrsjf\jrsjrNjf\f\jr\jrsjr\jcNjr\j 

ooooooooooooo 


<\ 

o 

>.  v  cf  CQ 

X  <T  O  < 

—  n  u  -  O  0330 
uir\juJ3ur\i  r-ui  o  — 

s«nco>  <a  j  jjxu.-cr 
,L>  3  00000  0  0033 
'X  _l  x  u  Cl  x  u.  x  u  u  x  x 


o  o  ><  a  'j  a 

3  3  3  3  3  3  3 


o 

JJ  3  n  —  U  O 

^UMScro 

ui  uj  x  rvj  n  m-  x' 
3  3  3  UJ  x  x  x 
u  u  X  x  X  X  X 


<  O  O  OX 

O  cr  TT  -T  ^ 

X  in  0  3  rn  3  O 

M  U  >  U  O'  u  u 

3^3x<xo<ux<,n 
0,r^xc\3'nnj3nc\'j 

ooo<auxonjn  033 
xxxxxxxuuuuuu 
X  X  x  X  X  X  u  X  X  U  X  x  u 


,nnnnxn^j.OJJNn 

iJ(M(\i(\N^C0^N  COlTi- 

o  oo  —  rgrncrnoNOXai 

X  3XXXUXUXXXXXXU 

x  x  x  u  x  x  x  u  u  X’  x  x  x  uu 


36 

168 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


O  tl  M 

fH  U  > 

00  u 


N  4)  C/3 
■H  X  -J 
HUM 
«  CO 
■H 

*j  ta  j 


c 

3 


B  *J 
O  -H 
K  5 


Q.  *J 
C  0) 


PS 

i  r  m  \c  ■ 


p  C  C 
43  -H  43 


C  CD 
«H  *3  -H 


h  41  ^ 


<0  *->  W 

•H  CD  I 

=  03  W 

41  »-  O 

U  «M  I 

o  43  Q 

C  X  Z 

60  W  W  U 

•H  m 

3  T3  Q 

■3  ■*-»  CD  W 

C  T3  03  H 

«  c«  U  (_> 


O  —  —  — 


O  0)  — 

4J  O 

^  M  «0  % 

u  ^  c  a  oi 

3  « 

CX.  W  «H  % 

W  O  ^  60  I  . 

3  w  d  ^ 

o  «•.  w«  o 

03  *w  CD  43 

B  43  B 

a 


<b»  o 

w 


«  M  *H 

a  o 


J<£  O 
cd  y 
<d  —  — 


w  o  w  ' 


a 

o 


>•  TJ  W  *J 


wax 
>s  v 

I  4->  <S> 


41  4) 

*j  e 


3  43  /-v 


CO 


43 

00  43 
C  M 

OS  43  s-l  -os  t4  y 


W 

>-  •• 

I  w 

^  3 
*H  O  •• 


J  CD  •»  U  Q,  BJ 
Cd  O  ^  y 


>  oH 

r-C  O  «J 
43  O  > 
T3  ««-i  OD  — 
O  4)  * 
y  43  *3  O 
OXO  X 
•3  H  y  CD 


H  41  U  ® 


w  CX 
4)  >s 


OS  V 

os  a 
w  ►> 

I  *-» 


•  c 

o*  4) 


H 

3-3 

» x 


43  -H 

a  x 

>s  43 


*  X 

a 


43-43 

B  O  X* 

15  41  - 
C  *3 
^■4 
03  > 

CD 

O  09 
O  -H 
X 

c_>  •• 
a  o 
>  •• 


£ 

! 

«<• 

x 

*> 

c 

c 

© 

*8 

a 

•S 

c 

§ 


•-  »-3  a  -h  js  a 
oo  y  cd  >s 

<SJ<SJU<SJ  <0  *J 


a 

h3 

<  < 

LU 

a  uj 

M  H 

a  h 


uj  co 
3  oj  o  < 

Z  32  J 

UJ  -J  <  z 

X  c  =  3  c 

UJ  H  QC 

cc  C  z  <  X 
<  C  O 

a  a:  co  f- 

3-  Q  c  h-  i  — 

c  z  h  c  z  ■»: 

O  LU  CO  Z  C  CO 


UJ  x  z  z 

CD  U  3  *  -  £ 

*  -  Q.  UJ  LU  o  a 

I JU33Z<h 


o  o 
o  C* 
O  (\ 


H  a  CE  Jhli  3 
33I/3XCCTC  <  IKL  Z 
JJtrjiaixU3:3ii 


OOOQOOOOOOO 
x  o  r-  co  >  o  —  c\ro^rxco 
XiXiT»/»X3000000^ 
f\<Sjc\jf\(Sjrgc\rvjc\rvjc\3 
OOOOOOOOOOOO: 

z 

LU 

eg  j 

o  < 

3  (\  (- 


J3HXO-00>— 03 
X1XX11XJ.XOOO 
LUXXXUJXUJUJXOOO 
p»r-i^>-r^r^.p^p>s!^oOO 


o 

o 

n 

r\j 


o  o 
n  o 
o  o 


o  o 


o  o 

iTi  co 

n  o 


o 

o 

o 

OJ 

o 


o o o o o o o o o o o o o o o oooooooc 
r-nor^nr-inooo^ircrvjo—  ooxoo  —  >r- 
^■nnroa^oooocoirinrnr-fNj  ^iinocDonoo 

ocgrg  —  o— OO  —  Oc\j  —  ego  —  <\  o  O - eg 

c o o o o O o o o o o o o o o oooooooo 


2  2  °  ° 

co  co  r\j  oo 

O  r-  o  — 

r*  O  —  CSJ 

o  o  o  o 

gogoooooooooooo 
nv  o  vojo  -  rg  ^  o  —  rvjr^rorg 
for\jCDxiCOfvO'rovvOinoO' 
- OOOQO  —  Oj  —  —  rg  —  f\  — 

ooooooooooooooo 


8  S  8  n  8 

s\  *  r*  &  x 


oooooooooo 

CMOOO(>M\nno 

aoooo— oooo 
oooooooooo 

03aJJx-oooo 
x  nooao<3  — 
xoooxxcooo 

N  VO 

3J  Z>3HJ 

<  z  h  o:  z  -J  a:zxx 

>JJ(DX  JV3<iJZ  JJ 
<>>hhij:xci  Sj 
22E«>>XII1 

<  <  <  <  Q  D  'J  'J  'J  'J 


o  o  o  o 
r-  n  s\ 

V  Wf\l 


o  o  o 
— 
O  r- 
o  c\  o 
o  o  o 


OOgQOpOOOQOOOOOOOOQOQOOQOO 
^  —  ^C0rgrvjof\jrgC0(>-or^oc0Oc\r^O  —  o<\OOOo 
O  o^rs.^-Lnr\jf\jrnr\jr~  oo^nvnfM-no/i’»on^ 

r  r  2r^32r~  - ooc\o - ga  o- 

oooooooooooooooooooooo 


CD  30 

—  55  a 


■  r-  o  r-  r» 


NO<Oif(OCOX>>i^  O  UJ  P1*  0<  —  ^rOD(NLUVC\J  —  OUJ^-CO 

■J<vailOO0ND(M-3>lDOi-30'JO0oa)O 
XXXLLXltMlU.(\liU.U.<U.U.-\U.(^xXXU.OjX 
p^r"-^r''-r''-fv'OP--'-or-r— r-or-r'-oor-'Or^r-.p'-r'-op- 


2.  —  c\ 

a  a 

CO  r-  i—  P- 
UKKx 
cs  ^  u:  z 


•—a  (-•  — •  mas  jd  h-  suji 

(-*  X  X  >■  Z  Z  >■  H  J  —  2  I5<xxi  =5  h- CJ  a.  cc  CO  : 
CEl030fflUJJJ>2>Il032x003C2i.Z(/5>X<<3. 
<UJ|3hhh<9yjJJ2lT,hha.pCIQZHhH3 
>3  33xxxx3DD33333iiiJHiiua3;an:n:c 
OXzzzzzza:a:cEO:n:zQ:a:n:a:to»-Ms-^^s  55- 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


37 

169 


Cl  -H  Cl  «H 


£>  4J  to  01 
nJ  C  h 
rH  (I  <g^ 


c  c  . 

fl  -H 


M  41  U  U  *H  O 


O  £ 

B  u  V  M 


•O  •  0)  0) 

«  41  £  £ 


oi  x  aj 

>  3  - 

a  O  T3 


O  4J 


B  M  O 
0)  to  £ 


O 

0)  *-»  TJ 
>  -* 


«  OJ  HH 


41  3  41  « 
CU  M  2  H 


J  (0  ••  0) 

•  M  ^  8 

■H  ^  fO 
VW>^  C 
^  0)  ^ 
C/5  01  Cl  0) 

w  a  «o  a. 

►<  x  a  ►. 


to  l-<  ^  0) 


oi  m 

a  ■ 

X  to 
*-*  0) 
®>  c 


N  —  — i 


-H  CO  -H 


01  U  BH  U 

a  to  o>  c  o) 
a  c  <s>  m 


C  u  k 


c 

o 


o 

c 

3 

a 


& 


»  K 

T3  a) 

C  U  T> 
■H  <8  C 
•w  £  f< 
—  U  <&» 


CO 

-X 

c 

to 


£5 


00 

c 

TJ 


0) 


01  v-'W 


>  «  8 

O  v4 

B  h  b 
01  «  ci 
^  -C  -4 


^  I  to 

«  V-  (N  TJ 
••  0)  ^ 

«  U  01  o 

I  C  B  01 
X-S  -H  to  TJ 

tN  C.  C  «H 

a  > 

0)  ‘O 

B  CD  CO 
to  -H  *  *H 

c  o 

CO  %  ~i 


4-j  ac 

a 


tO  £5 

C  <N 


H 

1-4 

-  X 


rt  ■  — I 

I  ^  I 

i  4-1  O  u 

•«  ft.  3  v  3 

4J  «  O  01  o 

■H  |  B 

X  ^  U  (0  W 

a  o  oi  c  o) 

S>  ®  CD 

a>  v-' 


3 

I  o 

4-1  • 

3  0) 
O  B 
to 

*J  c 
0)  ^ 
CO  C 
0) 
a 
o 
«a> 


01 

a 


<a* 


o 

c 

c 

to 

u 

c 


X  o 

4J  <S> 


0) 


to 

c 


to 

8 

8 

o 

u 

0) 

8  C.  to 

<0  OB 

C  u-i  B 

O 

C  MUG 

■H  o  O 

O  O  to 
to  .H  c  U 

8  — •  —•  0) 

B  a 

o 

o  to 


•« 


CO 

Ci 


00  c 

C  3 


3  CO 

a  *h 

•  to 
0)  8 
C  8 
*H  O 
«H  U 

01  (0 
8 

to  «ci 
C  "H 


■H  05  C» 

<2;  OS  01 

••  I  u  o 

C  ••  C  I 

nine 

O  •  O  CD 

a  *-)  a  o 

a 


C  C  01  <44 
•H  -H  CD  -H 


n  n  v 
CO  00  0) 

01  c  8 
U  -H  to 
o  u  c 
u  d  o 

ft.  mj 

—  —  <Si 


01 

ce 


0) 


0)  W 

8  01 

to  8 


to 

+ 


*-»  t-)  4-1  £0 

to  •  to 

C  -H  c  00 

■H  +  -H  C 

8  £  ••  8  -H 

l<  I  ^  li  o 

O)  £  f)  01  to 

d  ^  41  4) 

C  —  4-1  4)  —  *H 

O  0)  8 

0)  CO  to  0> 

c  c  > 

01  •-  I  o 

a  e  — .  B 


— — •  a  4->  *  — 

<  +  n  4i 

••I  -H  U 

V)  ^  I  •*  %  .m 

W  C  ■*->  <44  I  ^ 

>t  «»  »  /N  U 

I  O  O  4J  M  CD 

c  a  i  oi  ^  u 

O  ^  M  CD  4J  -H 

CO  01  to  144 

C  8  41  Cl  V_* 

01  to  OI  T4  B 

a  c  id  u-i  -h 


41  41  C 

01  01  o 

0)  0)  «44 


Cl 


01  fH 

to  <Hj 


"T3  "H  *H 


~  a 
a  o 
o  a 


(0  O  3T3 

CD  T3  41  3 

01  to  01  CO 

14  '  C.  •— 


a  a 
o  o 
a  a 

^  i 

c  ^ 

Cl  >S 
3  4-1 


o  a 
W  o 
^  a 

C  I 

Cl 

3  a 

Cl  *H 
01  N 
’  Cl  W 

M 


a 


o»  a  -h 
•3  -h  c» 
ON  •>  •• 
Cl  •  CN  = 

-  X  U  = 

a  4i  3  i 

•H  tl  t3  (N 

^  N  O  «  Ci 


e  '  x  x  >s  tj 

Ct  a  a  a  « 

Os  o  o  o 

Cl  |  Cl  Cl  Cl  4J 

oi  n  n  to  oi 

C  O  <Si  Ci  (&<  CD 


38 

170 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


int  i,k;  Icopy  string  si  to  string  s2 

set  1-0;  lindex  into  string  char  sl(),s2(); 

do (k , 0 , 9  )  @scopy (s 1 , s2 ) { 


c  **-• 

-H  O 

* 

•J  4)  o 

•H  00  C 

x  c 

I  as  n 

00  o 


x.  ^  ■« 

*J  C/5 

0)  W  »H  4 

J=  ►«••»«>  I 

>  ~  >  - 
0) 

Cl  C  H  U 
TJ  i-  «  y 
■H  3  >  41 
O  *-l  .H 

41  4)  *-»  0) 
o  «  C  01 


O  T3 
I  4)  O 

N  «H  O 

CO  4) 

•H  05  4) 

05  •  B 

■H  a  O  O 

«H  4J  0) 

S  N  O 

oo  r  *j  ■ 

C  <H  «H  3 

O  O  «  O  —i  •• 

— I  *J  >  *'». 

r  «  a  h  ^  c/5 

—  <S/  -H  O  «  O  W 

■  N  41  >2  ►< 

H  !  H  ^  ^ 

<0  4)  *-0  C  C 

>  4)  «  *<•  »- 

••  a  CD  — <  3  3 

•— (  *H  3  U  A  4J  *J 

CO  N  0)  *-n  4)  4) 

>  TJ  3  O  U  U 

Cl.  •  fH  *->  w 

•H  O  3  *H 

•  N  |  O  H  CO 

i  n  y  h  > 

00  '  41 

J  e  *-*  4)  4)  05 

:  o  4>  >  S  *h 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


39 

171 


(Continued  on  top  of  page  38) 


Polynomial  Evaluation  in  Basic 


X 

t 

5 

H 


r 

i 

K 

U1 

a 


c 

2 


X 

2 

e 

2 

> 

□ 

CL 

Of 

2 


OJ 

II 


X 

2 

41 

c 

2 

> 

a 

x 

a 

2 


sO 


OJ 

II 


X 

a! 


> 

a 

a. 

x 

2 


«■ 

ii 

£ 


00 

in  so  o 
00  U) 

»i  00 

II  II  II 

oo  ♦  in 

iu  LU  UJ 

>  >  > 


XXX 
>  >  > 
MI-4  1-1 

a  a  x 

LLI  UJ  UJ 

q  a  a 


x 

a. 


X 

□ 


X 

\ 

X 


£ 

UJ 


X 

3 

2 

<r 

a 

□ 

u. 


* 

* 

* 

♦ 

* 

* 

* 

* 

* 

* 

* 

# 

* 

* 

# 

* 

* 

I 

* 

* 

* 

j 

* 

* 

* 

5 

# 


II 

Z 


V  > 


$ 

i- 

* 

a. 


# 


r 

a 


<x 

3 


<E 

> 


U- 

□ 


a 

a. 


QL 

U1 


r 

UJ 


aj 

00  (\J 
+  <L  ~ 
^  OJ  . 

•  •  N 
00  ^  N 
t  00  o 
CO  vD 

II  II  II 

~  OJ 

2 


UJ  UJ 

>  > 


OJ 

• 

m 

moo 
OJ  s0  \0 
—I  <Xs  00 

II  II  II 

(o  <t  m 

UJ  UJ  UJ 
>  >  > 


E  H  K 

□  XX 
£  >  > 
>  M  M 

JXX 

□  UJ  UJ 
X  O  Q 


XXX 
>  >  > 
M  M  M 

XXX 
UJ  UJ  UJ 

1=1  a  a 


it 

x 


B 

M 

§ 


£ 

fe 

CL 

UJ 

§ 


O  I 
m  cl  h 
lx  UJ  •% 
lx  K  S  r\ 
Ui  if)  <  — 
“  _  X  ^ 

o  a: 


* 

* 

* 

# 

1 

* 

* 

* 

* 

* 

§ 

* 

* 

I 

* 

* 

* 

* 

§ 

* 

* 

* 

* 

* 

* 


z  z 

£  M  M 

Lu  oc  a 
&  cl  cl 


* 
H  * 
Z 

E 

£2 


8 

CL  O  &  s' 
UI  *-  lx 
H-  H 

£  f  *  a 

■w  s  »—  h- 

I-  <r  H  K  z  3 

3  Z  Z  £  ^ 

IL  E  -»  »-  o  ql  z 

Z  —  CL  CL  lx  CL 


z  ~ 
UJ  z 


E 

UJ  - - - 

tt  G  Cl  CL 


z  * 

s  5 

CL  K  T 
Z  <L 
Qc.  *-«  O 

z  * 

UJ  -  f 
*  * 

.  .  h-  *-  * 

X  Z  3  Z 


ql 

□ 

u. 


x 

\ 

a: 

UJ 

K 

r 


3 

UJ 

r 


a 

□ 

u. 


z 

o 


r 

a 


<r 

3 

s 

> 


U. 

□ 


□ 

CL 


QL 

UJ 


r 

UJ 


* 

* 

t 

* 

* 

§ 

# 

* 

* 

* 

* 

* 

* 

* 

* 

* 

* 

* 

* 

* 

* 

-X 

Xi 


•* 


00 

V0 

* 

N  CU 
O 

4  4 

O  41 
41  00 

m  a> 
ii  ii 


oo  + 

4  4 

N  ♦ 

*  m 

oo  ♦ 


25 

►H  H4 

E  K 

25 

>  M 

-I  X 
□  UJ 

x  a 


ii  ii 

OJ  00 

UJ  UJ 
>  > 


X  X 
>  > 
M  1-4 

X  X 
UI  UI 

a  a 


OJ 

00  O 
O  \£) 

M  00 

II  II 

♦  in 

UJ  UJ 
>  > 
41  M 

I-  K 

55 

1-4  M 

X  X 
UJ  UJ 

a  a 


x 

□ 


x 

UJ 


£ 

UJ 


3 

2 


QL 

□ 


>■  •• 


□ 

Ql 


□ 

QL 

UJ 

P 

QL 

□ 


r 

UJ 


V) 

K 

r 

UJ 

CJ  CO 
U.  II 


□  < 

O  X 


QL  QL 
UJ  □ 


<r 

s 

*  * 

* 

Z 

*  # 

* 

lit 

*  * 

* 

3' 

*  # 

* 

K 

*  * 

* 

Ll. 

*  * 

* 

IX 

* 

* 

* 

t— 

*•  * 

* 

1-4 

>  * 

* 

I 

~  * 

* 

«-  * 

* 

X 

•V  * 

* 

}  * 

* 

►—i 

r-.  * 

* 

E 

2 

*  * 

•O  * 

3 

* 

L 

-D  * 

o 

O 

C  x 

Cl 

•Ti  * 

u 

* 

0- 

CL 

—  * 

2 

8 


u. 

i 

z 

Ui 


O  CL 


o 


o  w  o  * 

H  1  * 

*-  II  * 

CL »  * 


UJ 

-J  3 
T  *— 

•—  h- 

gz5 


X  Z  3  Z  a  ►-  X  3 

UJ  M  jl  M  E  E  G  ^  Ul  0)  E 
ZX2Xli4UJU=>ZOUJ 
X  41  x  X  X  ox 


fin 

I—  z 

£  Z  O  X 
_  _  UJ  x  u  x 
O  X  X  X 


o 

in 


x  z  □ 

2S2 

CL  ►— 


gfe 

O  h- 
•-D  iff 


*  * 
~  * 

S5 

C  * 

T  * 
—  # 
O  * 
6.  * 
* 
* 

♦-  * 
*  * 
=>  * 
—  * 
*  * 
2  * 
*  * 
* 

1  * 
* 

!*i 

»-  * 

2  * 

£{ 

|| 
v'l 
*  * 

3  t 

*  * 

E  E 


* 

3 

3 

* 

» 

* 

* 


i 

(L  ^ 
UJ  »“> 

H*  ’w 
iff  3 

+ 

M  1—4 

X 

O  * 


^  + 
I  »-> 
Z  w 

H  3 
*">  M 

4^ 

oc.  n 

O 

iL  3 


X  h- 

2q 


E  E  E  G 

UJ  UJ  UJ  U. 

k  >» - -  w  4k  M.  It.  •—  U.  I*.  I*.  W  I*.  I*.  U.  VJU  "—  ’Jf  L*.  U.  CL  CL  QL 

DOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOOO 

u  )  ^  io  l4  r-  00  <r-  o  ^  04  k>  m  r--  oo  T*  o  i-.  cs  to  m  •>£»  r--  oo  ^Or,u  ro ’t  o  ^  cs  ^  ic  ^  n  oo  cr* 
— 1  —  —  —  t-*  ~  •  T-.  (ij  <>i  <^i  <4  <4  C’j  c>4  n  n  (J  D  r  >  r)r>oooooooooo 


40 

172 


Di.  Dobb’s  Journal,  Number  54,  April  1981 


X 


r 

U_ 

r 

□ 

a 

►H 

■  r 

f* 

K 

\ 

K 

(C 

X 

cr 

3 

\ 

3 

00  s0 

a 

a* 

O'  *-i  \D  ID  CU 

UJ 

> 

UJ 

|f)  *H  fH  N 

K 

UJ 

r 

~  ID 

u. 

II  II  II  II  II 

UJ 

Ul 

cu  i  cu  i 

□ 

□ 

«-•  OJ  CO  * 

ii  ii  n  ii 

K 

X 

K 

t 

1  UJ  UJ  UJ  UJ 

C 

CO  CU  «  O 

H 

£  >  >  >  > 

3 

<  <  <  < 

□ 

UJ 

□ 

X  X  X  X 

CL 

E  K  H  K  K 

E 

a. 

□  <r  Ct  (t  IT 

Ct  Ct  OL  0: 

QC 

r  >  >  >  > 

H 

QL 

a  d  □  □ 

UJ 

>  M  H  M  H 

UJ 

u.  ll  u.  u. 

K 

_j  ct  ct  ct  ct 

Ct 

K 

z 

□  uj  uj  uj  uj 

□ 

z 

UJ 

Q.QQQQ 

u. 

UJ 

CO 

o 

O  00 
♦  00 
N  9< 

N  U> 

CU  N  CO 
CO  o  o 
O  ♦  *■  00 
0J  CD  ♦  CU 
00  00  CD  O' 

CD  •  .  . 

•  n  id  id 

oo  —  so  in  cu 

ID  1H  w  rt  ^ 

II  II  II  II  II 

«-■  CU  CO  ♦ 

i  UJ  Ui  Ui  Ui 
£  >  >  >  > 
M  M  H  H  M 

EKHKK 

piKri 
z  >  >  >  > 

M  >H  M  M 

_i  a  a  a  oc 

□  UJ  UJ  UJ  Ui 

(LChmO 


'  c 

x  a 
'  r 

> 

a  _i 
uj  □ 
i-  a. 

5  »i 

«-i  uj 
x  a  a. 
uj  a: 

3  Q  (J 

UJ  QL  (/> 


SO* 

II  3  ^ 

*  ~  ~  H  Z 

*  *  ~  h-  Ct 

__  ^  II  M  X  D 

2:  z  ~  o  ii  ^  U;  h 

Ui  Ui  II  U.  U-  z>  z  u. 

a  a  U.  Lt 

oooooooo 
o  *-•  o*  k>  ■*■  m  \G  is. 


CU  N 
O  CO  *  I  O  ID  I 


N 

> 

at 

UJ 

U.  II  II  II  II  II  II 

u. 

W> 

□ 

n 

UJ  If)  '*■  CO  (U  «-•  O 

a. 

ac 

□<<<<<< 

(6 

a 

(J  X  X  X  X  X  X 

*■5 

z 

ac 

ac  a  ac  a  ct  oc  a: 

3 

UJ 

uj  □  a  □  □  a  □ 

•p^ 

a 

K 

H  LL  U.  Ul  U.  U.  Ll 

nJ 

/\ 

Z 

UJ 

Z 

UJ 

r 

□ 

ID 

« 

N  ID 

K 

00  N 

Ct 

UJ  CO  ID 

3 

*  ♦  . 
■  ■  N 

CO  CO  O 

> 

cu  o  (u 

UJ 

+  CD  « 

LL 

II  II  II 

□ 

-  cu 

h- 

r 

i  uj  uj 

►i 

£  >  > 

□ 

H  W  H 

cl 

E  K  K 

gti 

QL 

z  >  > 

UJ 

H 

-i  ac  ac 

£ 

□  UJ  UJ 

UJ 

a.  a  a 

Dr.  Dobb’s  Journal,  Number  54,  April  1981 


(Continued  on  top  of  page  40) 


Of  Interest 


by  Dave  Cortesi 


Phillip  Woellhof  Spins  Off 

Mr.  Woellhof,  formerly  Director  of 
New  Products  for  Lifeboat  Associates, 
has  apparently  contracted  a  case  of 
Spinoff-itis,  an  occupational  hazard  more 
common  in  Silicon  Valley  than  in  Con¬ 
necticut  where  he  has  founded  Westico, 
a  new  software  distribution  house.  Westi¬ 
co  aims  to  distinguish  itself  through  over¬ 
night  delivery  and  technical  support  that 
is  “fast,  accurate,  and  courteous.”  And 
more  power  to  him,  say  we. 

Your  Whole  Summer  is  Booked 
Already 

.  .  .  or  it  would  be  if  you  attended  every 
interesting  conference  we’ve  been  told 
about.  If  you  hurry,  you  might  be  able  to 
catch  the  Southwest  Computer  Show  at 
the  Dallas  Market  Center  in  Dallas,  April 
9-12.  $50  million  worth  of  hardware  will 
be  on  display,  plus  the  usual  robot  and 
computer  art  sideshows. 

Readers  in  Michigan  might  like  the 
more  modest  Annual  Computer  Show 
presented  by  the  Saginaw  Valley  Chapter 
of  DPMA,  to  be  held  May  7-8  in  Midland. 
East  Coast  TRS-80  users  may  prefer  the 
First  Annual  TRS-80  Microcomputer 
Show,  May  22-24  at  the  Statler  Exposi¬ 
tion  Center  in  New  York  City.  The  show, 
which  isn’t  sponsored  by  Radio  Shack  or 
Tandy,  will  feature  wares  related  to  all 
the  Tandy  computer  products. 

If  you  are  into  graphics,  plan  to 
make  the  annual  conference  of  the  Na¬ 
tional  Computer  Graphics  Association, 
June  14-18  at  the  Baltimore  Convention 
Center.  The  last  day  will  be  a  theme  day 
for  Personal  Computer  Graphics,  and  a 
number  of  rooms  in  the  exhibition  area 
will  be  set  aside  for  personal  computers 
running  graphics  applications. 

Dealers  and  distributors  in  the  com¬ 
puter  trade  have  been  invited  to  the 
Computer  Industry  Trade  Expo,  spon¬ 
sored  by  the  Microcomputer  Industry 
Trade  Association  (MITA)  and  scheduled 
for  June  24-26  in  the  Atlantic  City  NJ 
Convention  Center.  Dealers  and  users 
both  are  wanted  at  the  National  Small 
Computer  Show,  August  26-29  in  the 
New  York  Coliseum. 

Geverest  New  Product  This  Month 

That’s  how  an  announcement  from 
Data  Node,  Inc.  struck  us.  They’ve  built  a 
board  that  installs  in  the  common  DEC 
VT100  terminal,  converting  it  from  a 
mere  terminal  into  a  personal  computer 


42 

174 


with  networking  abilities.  The  board  costs 
$1850,  contains  a  Z-80  and  64K  of 
RAM,  and  comes  with  networking  soft¬ 
ware  so  that  it  can  communicate  with  a 
PDP- 1 1 .  The  erstwhile  terminal  can  run 
either  CP/M  orMP/M. 

An  S-100  Do-All  Board 

Digicomp  Research,  like  Godbout 
and  others,  have  designed  an  S-100  board 
that  handles  all  the  miscellaneous  I/O 
functions  needed  by  an  MP/M  system. 
Theirs  contains  four  serial  ports  with  in¬ 
dependent  baud  rates,  24  bits  of  parallel 
I/O,  five  timers,  an  interrupt  controller 
and  a  clock-calendar  with  battery  back¬ 
up.  Evaluation  units  should  be  available 
now,  but  the  writer  of  the  release  neglect¬ 
ed  to  mention  the  price. 

An  IEEE-488  Bus  Driver 

The  instrumentation  bus  protocol 
brought  to  the  micro  community’s  atten¬ 
tion  by  the  Commodore  PET’s  use  of  it 
has  acquired  another  supporter.  Ziatech 
Corp.  have  a  board  designed  for  use  in 
Multibus-based  machines  that  can  drive 
an  IEEE-488  bus  at  as  much  as  250 
Kbytes  per  second.  The  high  data  rate 
persuades  the  company  to  claim  that  “the 
GPIB  has  replaced  RS232  as  a  lo¬ 
cal  computer-to-computer  connection,” 
which  qualifies  as  the  month’s  best  exam¬ 
ple  of  wishful  thinking.  The  board  costs 
$  1 200  if  you  only  want  one. 

A  Sideways  L.E.D. 

Tiny  PC  board  hardware  items  fasci¬ 
nate  us.  The  latest  is  a  subminiature  LED 
indicator  light  that  points  at  ninety  de¬ 
grees  to  its  mounting  base,  like  a  beady- 
eyed  little  periscope.  Industrial  Devices, 
Inc.  make  it,  call  it  their  Series  5322,  and 
charge  45  cents  each,  provided  you  buy  a 
bunch  of  them. 

A  TRS-80  In  Orbit? 

Parasitic  Engineering,  makers  of  add¬ 
on  drives  for  TRS-80s,  want  to  sell  their 
Data  Separator  separately.  The  unit  in¬ 
cludes  an  FD1770  controller  chip,  plugs 
into  the'  TRS-80  with  no  modifications 
needed,  and  costs  $250.  The  writer  of  the 
release,  clearly  not  an  engineer,  is  most 
impressed  with  the  phase  locked  loop  cir¬ 
cuit  used  in  the  device.  It’s  “used  in  satel¬ 
lite  communications,  where  errors  can’t 
be  tolerated,”  we’re  told.  And  in  acoustic 
modems,  and  broadcast  FM  receivers,  and 
every  disk  controller  but  Tandy’s  . . . 


Useful  Reference  Cards 

We  are  indebted  to  Micro  Logic 
Corp.  for  sending  us  a  free  copy  of  their 
solid -plastic,  8”  x  11”,  8080  cpu  refer¬ 
ence  card.  It  shows  absolutely  anything 
the  hobbyist  would  need  to  know  in  a 
hurry,  from  pinouts  to  instruction  tim¬ 
ings,  and  has  found  a  permanent  home 
under  the  writer’s  terminal.  It  even  makes 
neat  sounds  if  you  flap  it  back  and  forth, 
as  in  the  old  record  Tie  Me  Kangaroo 
Down,  Sport.  They  make  one  for  the 
6502  as  well.  Either  is  $4.95  plus  $1 
handling  per  order. 

Cromemco  Announces  C 

Cromemco  brags  that  it  is  “the  only 
microcomputer  manufacturer  who  cur¬ 
rently  supplies  the  C  language.”  That’s 
true,  as  far  as  it  goes;  the  others  let  soft¬ 
ware  vendors  supply  it.  Anyway,  their 
new  C  compiler  runs  on  the  CROMIX 
multi-user  system,  produces  object 
modules  that  can  be  linked  with  FOR¬ 
TRAN  or  COBOL  modules,  and  costs 
$595.  The  price  includes  “extensive  docu¬ 
mentation.”  It  will  be  a  genuine  first  if 
that  isn’t  a  reprint  of  the  Kemighan  and 
Ritchie  book. 

A  New  Version  of  OASIS 

An  announcement  from  Phase  One 
Systems  comes  just  in  time  to  remind  us 
that  Digital  Research  doesn’t  have  a 
monopoly  on  small  operating  systems. 
OASIS  is  available  at  level  5.5;  it  has  a 
new  spooler  and  a  new  backup  utility. 
The  spooler  supports  26  different  file 
queues  and  allows  for  forms  set-up  and 
multiple  copies.  The  utility  will  save  only 
the  changed  files,  and  can  do  data  com¬ 
pression.  DDJ's  editor  would  like  to  see 
some  submissions  related  to  OASIS,  just 
for  variety. 

An  Improved  FORTH  for 
Alpha  Micro 

AM-FORTH  is  an  implementation  of 
that  language  for  use  on  Alpha  Micro 
computers  under  the  AMOS  operating 
system  (hah!  there’s  another  one!).  Sierra 
Computer  Co.,  who  publish  it,  have 
adopted  the  refreshing  custom  of  desig¬ 
nating  release  levels  with  letters.  Release 
B  of  AM-FORTH  is  improved  in  that  the 
basic  dictionary  is  re-entrant;  a  single 
copy  can  be  shared  by  all  the  system’s 
users  at  once.  New  licenses  are  $150; 
users  of  version  A  can  have  it  for  $  1 20. 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


HUMBUG?  Bah! 

HUMBUG  is  said  to  have  been  a  pop¬ 
ular  ROM  monitor  for  SS-50  systems. 
Star- Kits  have  now  produced  HUMBUG- 
09,  derived  from  the  original  but 
written  for  the  6809  CPU  on  the  SS-50 
bus.  The  package  includes  two  ROMs,  a 
manual,  and  your  choice  of  a  source  list¬ 
ing  or  the  source  code  itself  on  diskette. 
The  price  is  $75,  which  sounds  like  a  bar¬ 
gain  to  us.  (My  editor  wonders  where  all 
the  68xx  experimenters  have  gone,  and 
why  he  only  gets  articles  on  the  Z-80 
anymore?) 

An  Intriguing  Report  Writer 

A  product  announcement  from 
Friends  Software  piques  our  interest. 
Access/80  is  claimed  to  be  a  sophisticated 
report  writer  and  data  reorganizing  tool 
for  CP/M.  It  will  scan  any  file,  select¬ 
ing  records,  sorting  them,  tabulating  and 
doing  sub-totals,  and  formatting  a  report 
to  your  specifications.  The  intriguing  part 
is  that  it  claims  to  be  “the  microcomput¬ 
er  version  of  a  system  running  on  IBM 
and  Univac  compuers,”  but  they  don’t 
give  the  name  of  the  original  model.  The 
implementation  sounds  interesting,  too: 
“Access/80  is  built  on  top  of  its  own 
virtual  machine,  ‘S380,’  and  virtual 
operating  system  ‘VOS’ .  . .  modeled  on 
the  operating  system  used  on  an  IBM 
370.”  A  report  writer  in  a  virtual  IBM 
operating  system  in  a  virtual  machine  in  a 
CP/M  system  is  something  we’d  like  to 
see.  Or  perhaps  not. 

Artificial  Intelligence  Faces 
The  Music 

The  MIT  Press  publishes  a  quarterly, 
Computer  Music  Journal.  They’d  like  you 
to  know  that  a  special  two-part  issue  is 
just  out,  in  which  are  surveyed  all  the 
ways  that  Artificial  Intelligence  research 
can  complement  computer  music  re¬ 
search.  Sounds  like  a  must  for  anyone  ser¬ 
ious  about  either  topic. 

An  OEM  Wishbook 

This  has  been  a  good  month  for  free¬ 
bies.  We  are  in  receipt  of  a  copy  of  Sen¬ 
try  Publishing  Company’s  Dataguide,  sub¬ 
tilted  “the  master  catalog  and  directory 
of  OEM  computer  products,”  which  pret¬ 
ty  well  describes  it.  Each  of  its  14  prod¬ 
uct  sections  is  headed  by  an  article  ana¬ 
lyzing  that  marketplace,  all  of  which  con¬ 
tain  bullish  forecasts  of  market  growth. 
The  rest  of  the  editorial  matter  consists 


of  listings  of  manufacturers;  these  fill  the 
space  between  hundreds  of  display  ads. 
A  year’s  subscription  (two  issues)  is  $50. 
Write  them  on  letterhead  paper;  who 
knows,  you  might  get  a  free  copy  too. 

An  Exhaustive  Directory 

Datapro  Research  Corp.  have  been 
publishing  detailed,  authoritative  descrip¬ 
tions  of  computer  hardware  for  years. 
Now  they’ve  turned  their  attention  to 
personal  machines  and  have  produced 
their  Directory  of  Small  Computers.  It 
contains  200-odd  system  descriptions, 
each  thorough,  all  in  the  same  format  for 
easy  comparison,  plus  900  company  pro¬ 
files  and  several  vendor  directories.  The 
two  compendious  tomes  with  1 2  monthly 
supplements  are  not  cheap;  they’ll  set 
you  (or,  more  likely,  your  employer) 
back  $280.  Would  that  PCC  would  get 
one  of  these  as  a  freebie! 

A  Software  Author’s  Hopebook 

The  1981  Software  Writer’s  Market 
can  be  had  from  Kern  Publications.  It 
lists  the  names  and  addresses  of  “more 
than  1800  firms  who  will  market  and  dis¬ 
tribute  programs  for  independents.”  Not 
every  entry  will  be  a  winner,  but  the 
book’s  bulk  is  an  indication  of  the  extra¬ 
ordinary  breadth  and  vigor  of  the  inde¬ 
pendent  software  market.  At  $45  a  copy 
it  isn’t  priced  for  the  casual  reader,  but 
if  you’re  really  in  that  trade  you’ll 
probably  find  it  priceless. 

Free  Observations  of  Industry 

The  formidable  Wayne  Green  runs 
1001001,  Inc.  (get  it?),  which  publishes 
Microcomputing  Industry,  a  monthly  that 
analyzes  and  comments  on  matters  of  in¬ 
terest  to,  well,  people  in  the  industry. 
Subscriptions  are  “free  to  qualified  sub¬ 
scribers”  and  (presumably)  unattainable 
to  those  who  aren’t.  Swipe  some  letter¬ 
head  stationery  from  that  friend  of  yours 
whose  consultancy  went  broke  and  write 
for  it ;  it’s  an  excellent  value  at  the  price. 

USC  Nerves  Itself  for  the  Future 

The  press  release  pile  yields  up  a  lot 
of  piffle  and  tosh,  which  we  routinely 
round-file.  University  P.R.  departments 
seem  to  turn  out  more  than  their  share. 
These  diligent  scribes  interview  a  profes¬ 
sor,  write  up  his  opinions  in  what  they 
believe  to  be  layman’s  langauge,  and  send 
the  result  out  in  hopes  of  getting  the  old 
school  a  little  free  ink. 


Word  has  filtered  through  to  USC 
that  chips  are  all  the  rage,  and  they  im¬ 
posed  upon  Professor  John  Nelson  of  the 
E.  E.  department  to  give  them  a  few  hot 
quotes.  The  awful  result  is  not  to  be  laid 
at  Prof.  Nelson’s  door;  the  man  sounds  as 
if  he  knows  his  onions.  But  someone  has 
surrounded  the  Professor’s  words  with 
wide-eyed  baby  talk,  turning  it  into  a 
prime  example  of  what  Ted  Nelson  calls 
Cybercrud.  Try  the  taste  of  this  lead  para¬ 
graph: 

Tomorrow’s  “superchips”  - 
postage-stamp-size  computers 
that  will  outperform  the  massive 
electronic  brains  that  are  cur¬ 
rently  as  big  as  bank  vaults  — 
may  enable  us  to  talk  to  our 
home  appliances  and  free  us 
from  ever  again  having  to  com¬ 
mute  to  work. 

Gosh!  This  sort  of  Tom  Swift  journalism 
with  its  nattering  of  “massive  electronic 
brains”  is  harmless,  if  irritating.  The  writ¬ 
er’s  real  sin  is  his  use  of  anthropomorphic 
terms: 

And,  because  superchips  will  be 
endowed  with  “nerve”  cells  by 
the  millions,  Nelson  believes 
superchips  can  become  the  hu¬ 
manoid  brains  necessary  for  to¬ 
morrow’s  military  and  consumer 
robots  to  engage  in  “signal  pro¬ 
cessing”  —  the  technical  term  for 
sensory  skills  resembling  human 
speech  and  sight. 

Never  mind  the  technical  errors;  what’s 
wicked  about  this  kind  of  gee-whizzery 
is  its  deliberate  perpetuation  of  the  worst 
of  the  public’s  myths  about  computers.  It 
goes  on  and  on: 

The  original  integrated  circuits 
of  microelectronics,  in  the  early 
1 960s,  were  chips  of  silicon  crys¬ 
tal  impregnated  with  less  than 
10  metallic,  transisitor-like  com¬ 
ponents.  Those  first  models  were 
analogous  to  single  brain  cells. 
Today,  with  thousands  of  com¬ 
ponents,  the  chips  can  be  com¬ 
pared  to  specialized  brain  lobes 


No  doubt  there  are  small  newspaper  a- 
round  the  country  that  will  pick  up  on 
this  turkey  as  a  welcome  space-filler. 
Thus  is  the  cause  of  computer  literacy  set 
back. 


(Continued  on  page  44,  column  1) 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


43 

175 


Electric  Phone  Book 


Of  Interest 

(Continued  from  page  43) 

Contact  Points 

1001001,  Inc.,  Pine  Street,  Peterborough 
NH  03458. 

Computer  Industry  Trade  Expo,  100  Char¬ 
lotte  Place,  Englewood  Cliffs  NJ  07632, 
(201)  569-8542. 

Cromemco,  280  Bernardo  Ave.,  Mountain 
View  CA  94043,  (415)  964-7600. 

Data  Node,  Inc.,  432  Toyama  Drive,  Sunny¬ 
vale  CA  94086,  (408)  744-0561. 

Datapro  Research  Corp.,  1805  Underwood 
Blvd.,  Delran  NJ  08075,  (609)  764-0100. 
Friends  Software,  Tioga  Building  Suite  400, 
2020  Milvia  St.,  POB  527,  Berkeley  CA 
94701,(415)540-7282. 

Industrial  Devices,  Inc.,  7  Hudson  Avenue, 
Edgewater  NJ  07020,  (201)  224-4700. 

Kern  Publications,  190  Duck  Hill  Road, 
POB  1029,  Duxbury  MA  02332,  (617) 
934-0445. 

Micro  Logic  Corp.,  Dept.  CDJ,  POB  174, 
Hackensack  NJ  07602,  (201)  342-6518. 

MIT  Press,  28  Carleton  Street,  Cambridge 
MA  02142,(617)253-2889. 

National  Computer  Graphics  Association, 
2033  M  Street  NW,  Suite  330,  Washington 
DC  20036,(202)466-5895. 

National  Small  Computer  Show,  110  Char¬ 
lotte  Place,  Englewood  Cliffs  NJ  07632, 
(201)  569-8542. 

Parasitic  Engineering,  1101  Ninth  Avenue, 
Oakland  CA  94606,(415)839-2636. 

Phase  One  Systems,  Inc.,  7700  Edgewater 
Dr.  Suite  710,  Oakland  CA  94621,  (415) 
562-8085. 

Saginaw  Valley  Chapter  of  DPMA  Annual 
Computer  Show  at  2914  W.  Midland  Road, 
Midland,  Michigan;  pre- show  contact  is  Don 
Seidel,  (517)  790-4220. 

Sentry  Publishing  Company,  5  Kane  Indus¬ 
trial  Drive,  Hudson  MA  01749. 

Sierra  Computer  Company,  617  Mark  NE, 
Albuquerque  NM  87112,(505)296-8085. 
Star  Kits,  POB  209,  Mt.  Kisco  NY  10549. 
TRS-80  Microcomputer  Show:  Exhibitors 
contact  Kengore  Corporation,  3001  Route 
26,  Franklin  Park  NJ  08823,  (201)  297- 
6918. 

Westko,  25  Van  Zant  St.,  Norwalk  CT 
06855,(203)  853-6880. 

Z  is  tech  Corporation,  2410  Broad  Street, 
San  Luis  Obispo  CA  93401,  (805)  541- 
0488. 

■  ■ 

A  we  have  as  of  this  writing,  we  would 

ZA  appreciate  additions  and  corrections. 

X  A.  computerized  bulletin  board  Send  them  to  PCNET,  PCC,  P.O.  Box 
works  just  like  an  ordinary  bulletin  E,  Menlo  Park,  CA  94025. 
board  system  except  that  instead  of  All  the  bulletin  board  systems  list- 

paper  and  thumbtacks  it  uses  a  termi-  ed  here  can  be  accessed  by  telephone 
nal,  a  computer,  and  the  dial-up  tele-  using  a  300-baud  ASCII  terminal  and 
phone  network.  a  Bell  103  modem.  Most  use  carriage - 

The  list  below  was  developed  return  as  a  speed  recognition  charac- 
from  several  sources  including  the  Peri-  ter,  after  which  they  are  self- teaching, 
pheral  People  in  Mercer  Island,  Wash-  All  are  free  to  anyone  who  calls,  un- 
ington,  and  the  People’s  Message  Sys-  like  Arpanet,  which  is  restricted,  and 
tern  in  Santee,  California.  It  is  being  The  Source  and  MicroNet,  which  cost 
maintained  by  People’s  Computer  money.  The  list  has  been  sorted  by 
Company’s  PCNET  project,  our  effort  area  code;  consult  your  local  tele- 
to  bring  computers  and  telecommuni-  phone  directory  for  geographical  cor- 
cations  into  the  hands  of  everyone,  respondence.  (Also  printed  in  Recrea- 
While  this  is  the  most  complete  listing  tional  Computing,  March/ April  1981). 

(201)283-2724  (213)787-4004  (404)  394-4220  (604)687-2640  (714)962-7979 

(201)467-0893  (213)795-3788  (404)  733-3461  (714)963-7222 

(201)688-7117  (213)799-1632  (404)  790-8614  (607)764-5571 

(201)753-1226  (213)799-6614  (404)  793-1045  (607)797-6416  (801)375-7000 

(201)763-8152  (213)826-0325  (404)930-1620  (801)466-1737 

(201)836-7228  (213)828-3400  (404)939-8429  (609)983-5970  (801)  753-6800 

(201)  843-4663  (213)843-5390  (404)953-0723 

(201)  874-6833  (612)  561-6311  (802)  748-9089 

(201)891-7441  (214)288-4859  (405)  353-2554  (612)929-8966  (802)879-4981 

(201) 968-1074  (214)634-2668  (405)  528-8009 

(214)634-2775  (614)272-2759  (803)  270-5372 

(202) 337-4694  (214)641-8759  (408)  241-1956  (614)649-7097  (803)  270-5392 

(202)  635-5730  (408)  296-5799  (803)  279-6392 

(216)644-1965  (408)  263-0248  (616)264-9193  (803)  771-0922 

(203)  348-6353  (216)745-7855  (408)  263-9650  (803)  772-1592 

(203)  367-1920  (617)  354-4682 

(203)  746-4644  (301)344-9156  (414)  241-5406  (617)388-5125  (804)  340-5246 

(414)  241-8364  (617)431-1699 

(206)945-1489  (303)759-2625  (414)  282-8118  (617)649-7097  (805)484-9904 

(303)789-0936  (617)692-3973  (805)  527-9321 

(206)  244-5438  (415)  348-2139  (617)864-3819  (806)682-7876 

(206)  246-8983  (305)261-3639  (415)  348-2396  (617)897-0346  (805)964-4115 

(206)482-5134  (305)566-0805  (415)493-7691  (617)963-8310 

(206)482-5590  (306)689-3234  (415)  527-0400  (806)  356-5610 

(206)  524-0203  (305)772-4444  (415)  647-9524  (702)826-7234 

(206)  546-6239  (305)821-7401  (415)  661-0705  (702)873-9491  (813)  223-7688 

(206)  723-3282  (305)989-9647  (416)  683-4703 

(206)937-0444  (415)  792-8406  (703)  281-2125  (816)  523-9121 

(309)688-0470  (415)851-3453  (703)  281-2222  (816)  531-1050 

(209)638-6392  (309)694-6531  (415)948-1474  (703)  379-0303  (816)  861-7040 

(703)620-4990  (816)931-3135 

(212)  245-4363  (312)265-6489  (417)  862-7852  (703)  734-1387 

(212) 448-6576  (312) 337-6631  (703)  750-0930  (817) 855-3916 

(212)  787-5520  (312)359-9450  (419)  865-1584  (703)  893-9474  (817)855-3918 

(212) 997-2186  (312)420-7995  (703)  978-7561  (817)923-0009 

(312)545-8086  (502)  245-8288 

(213)  276-4276  (312)622-9609  (502)  896-9624  (707)448-9055  (901)  276-8196 

(213)  316-5706  (312)729-2403  (901)  362-2222 

(213)  329-3715  (312)782-8180  (503)646-5510  (713)  233-7943  (901)761-4743 

(213)340-0135  (312)941-9009  (713)  693-8080 

(213)  346-1849  (312)964-7768  (512)  657-0779  (713)  977-7019  (902)  794-8198 

(213)  349-5728 

(213)  360-6332  (313)288-0335  (513)  671-2753  (714)449-5689  (904)  243-1257 

(213)  394-1505  (313)357-1422  (513)  874-2283  (714)463-0461  (904)243-8565 

(213)  395-1592  (313)465-9531  (714)495-6458 

(213)396-3905  (313)477-4471  (515)  279-8863  (714)  526-3687  (913)362-6398 

(213)424-3506  (313)484-0732  (714)  537-7913  (913)  764-1520 

(213)428-4718  (313)569-2063  (516)  938-9043  (714)  565-0961  (913)  782-5115 

(213)459-3177  (313)588-7054  (714)  571-5550 

(213)459-6400  (523)  223-3672  (714)  582-9557  (915)  584-5393 

(213)  566-8035  (314)838-7784  (714)730-1206 

(213)631-3186  (602)  866-02j8  (714)  739-0711  (916)393-4459 

(213)657-8803  (316)746-2078  (602)  956-5612  (714)  751-1422 

(213)673-2206  (602)  957-4428  (714)  772-8868  (918)  224-5347 

(213)675-8803  (319)353-6528  (602)  957-9282  (714)  898-1984 

(213)709-5423  (319)557-9618  (714)  952-2110  ■■ 

Dr.  Dobb’s  Journal,  Number  54,  April  1981 


176 


Important  Features  of 
The  PCNET  Protocol 


p 

JL  CNET  means  Personal  Computer 
NET.  The  PCNET  Project  is  a  group  of 
volunteer  computer  professionals  who  are 
working  together  to  create  tools  that  will 
accelerate  the  spread  of  computer-aided 
communication.  Currently  we  are  concen¬ 
trating  upon  three  tasks: 

(a)  arranging  the  publication  of  the 
“Electric  Phone  Book,”  a  list  of  Bul¬ 
letin  Board  Systems,  which  appears 
frequently  in  Dr.  Dobb’s  Journal  and 
Recreational  Computing, 

(b)  describing  and  encouraging  the  use  of 
the  PAN  protocol  for  simple  elec¬ 
tronic  messages,  and 

(c)  creating  the  PCNET  protocol,  a 
powerful  set  of  conventions  for  com¬ 
puters  communicating  through  the 
telephone  system.  This  remains  our 
most  important  and  significant  activi¬ 
ty,  and  is  the  topic  of  this  article.  We 
will  be  publishing  more  details  in  the 
future,  particularly  in  Dr.  Dobb’s 
Journal. 

The  PCNET  Project  undertook  an 
unusually  large  set  of  design  goals,  so  that 
the  PCNET  protocol  can  serve  as  the  base 
for  a  wide  variety  of  communication  tasks. 
We  have  designed  from  the  start  to  make 
this  protocol  useful  to  personal  comput¬ 
ers,  and  have  included  the  ability  for  per¬ 
sonal  computers  to  communicate  with 
other  emerging  networks.  This  article 
describes  some  goals  of  our  design,  and 
our  current  strategy  for  implementation. 

Since  computers  have  limited  a- 
mounts  of  storage  for  incoming  messages, 
messages  are  broken  into  packets  that  car¬ 
ry  portions  of  the  message  between  com¬ 
puters.  The  receiving  computer  will  put 
the  contents  of  the  packets  back  to¬ 
gether,  yielding  the  original  message. 

Like  all  serious  protocols  for  use  in 
an  environment  where  electrical  noise  in¬ 
troduces  errors,  the  PCNET  protocol  has 
a  method  for  sending  a  checksum  with 
the  data,  so  that  errors  may  be  detected. 
Through  the  use  of  counters  that  indicate 
which  packets  are  wanted  next,  and  labels 
telling  which  have  arrived,  the  protocol 
will  signal  when  any  erroneous  packets 
must  be  retransmitted. 


by  David  C.  Harris 


David  C.  Harris,  c/o  PCNET,  1263  El 
Camino  Real,  P.O.  Box  E,  Menlo  Park, 
CA  94025. 


The  PCNET  protocol  attempts  to  iso¬ 
late  logically  separable  activites  in  sepa¬ 
rate  “layers”  of  the  protocol.  This  tech¬ 
nique,  widely  used  and  respected  in  data 
communications,  makes  it  easier  to  modi¬ 
fy  parts  of  the  protocol  without  damag¬ 
ing  other  parts  at  the  same  time.  When 
optical  fibers,  satellites,  broadcast  radio, 
or  cable  television  become  available  for 
computer  communication,  the  PCNET 
protocol  should  be  easy  to  adapt  to  these 
opportunities. 

A  user’s  program  can  treat  the 
PCNET  protocol  as  an  input  or  output 
device,  issuing  “PREAD”  and  “PWR1TE” 
commands.  The  PCNET  protocol  will 
transmit  or  receive  until  error- free  infor¬ 
mation  has  been  communicated,  and  the 
return  to  the  user’s  program.  Although 
the  initial  versions  of  the  PCNET  proto¬ 
col  will  be  oriented  to  file  and  mail  trans¬ 
fer,  this  aspect  of  the  design  will  allow 
many  imaginative  uses  to  be  created  rela¬ 
tively  easily. 

In  the  inital,  “simple”  version  of  the 
PCNET  protocol,  two  bytes  of  the  packet 
will  be  converted  to  three  bytes  from  a 
set  of  41  characters  that  may  be  safely 
sent  even  to  large  mainframe  computers 
that  would  otherwise  do  undesirable 
things  when  they  receive  special  charac¬ 
ters  such  as  RETURN,  control-C,  or  ESC. 
This  should  make  it  possible  for  a  version 
of  the  PCNET  protocol  to  run  on  almost 
all  large  computers  without  requiring  spe¬ 
cial  system  modifications.  Later  versions 
of  the  PCNET  protocol  will  send  and  re¬ 
ceive  all  256  possible  bytes,  which  will 
improve  the  communication  speed,  but 
may  not  be  suitable  for  older  operating 
systems  on  large  computers. 

The  PCNET  protocol  is  designed  to 
use  modems  that  can  dial  the  telephone 
(electronically)  and  answer  incoming 
calls.  This  will  make  possible  fully  auto¬ 
matic  operation,  so  the  computer  can 
make  calls  when  the  phone  rates  are  low¬ 
est.  In  the  most  advanced  versions  of  the 
PCNET  protocol,  the  computer  will  be 
able  to  automatically  receive  an  incoming 
call,  store  a  file  or  message,  and  call 
another  computer  to  forward  the  materi¬ 
al  all  without  requiring  that  the  user  be 
present.  The  protocol  will  include  the 
necessary  estimation  of  time  (“time¬ 
outs”)  so  that  expensive  phone  calls  are 
not  continued  indefinitely  when  some¬ 
thing  goes  wrong. 

We  will  propose  an  addressing  meth¬ 
od  that  uses  latitude  and  longitude  to 
help  the  computers  figure  out  which  di¬ 


rection  to  forward  messages,  and  the 
phone  number  to  dial  once  the  message 
reaches  a  computer  that  knows  how  to 
call  the  desired  destination  computer. 
Sometimes,  calling  the  destination  com¬ 
puter  will  require  stored  knowledge  of 
a  login  procedure. 

Although  designed  for  automatic  dial 
and  answer  modems,  the  PCNET  protocol 
may  be  modified  so  that  less  versatile 
modems  may  be  assisted  by  a  user  who  is 
willing  to  do  the  dialing  and  answering 
when  needed. 

The  simple  version  of  PCNET  will 
only  communicate  in  half-duplex  mode, 
sending  information  in  only  one  direction 
at  a  time.  While  this  is  necessary  for  some 
kinds  of  hardware  and  our  goal  of  univer¬ 
sality,  later  versions  will  add  the  ability 
to  communicate  in  full  duplex,  sending 
information  in  both  directions  at  the 
same  time  (on  different  pairs  of  tones). 

An  advanced  feature  that  will  only 
be  available  later  is  the  ability  to  have 
multiple  logical  “streams”  of  data  multi¬ 
plexed  together.  This  could  become  use¬ 
ful  as  personal  computer  operating  sys¬ 
tems  become  more  powerful,  so  that 
several  programs  on  one  machine  could 
be  communicating  with  several  on  an¬ 
other  machine  at  the  same  time,  with 
only  one  phone  line.  The  PCNET  proto¬ 
col  would  get  data  from  the  correct 
programs  and  deliver  it  to  the  correct 
destination  programs,  automatically. 

Perhaps  more  important  than  the 
technical  aspects  of  the  protocol  is  the 
process  by  which  we  intend  to  make  the 
PCNET  protocol  available  to  everyone. 
This  protocol  is  a  creation  of  the  personal 
computer  community.  Almost  all  the  de¬ 
signers  are  owners  of  personal  computers 
who  recognize  the  immense  value  of  a 
standard  method  for  communicating 
among  personal  computers.  We  dream  of 
grocery  price  clubs,  of  sending  education¬ 
al  materials,  of  medical  care  advice,  of 
software  being  shared  between  incompati¬ 
ble  brands  of  computers,  of  electronic 
mail  around  the  world,  of  robots  com¬ 
municating  by  radio  links  in  noisy  envi¬ 
ronments,  of  coded  messages  being  de¬ 
livered  without  the  errors  that  would  ren¬ 
der  the  message  unreadable.  We  work  to¬ 
gether,  sharing  programs,  building  upon 
each  other’s  work,  to  make  the  dreams 
become  reality. 

When  we  have  created  and  tested  an 
implementaiton  of  the  PCNET  protocol 

(Continued  on  page  52) 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


47 

177 


Software  Review 


MINCE:  Not  Just  Another  Editor 


A 

X  ^.s  computing  power  gets  cheaper 
and  cheaper,  we  approach  the  problem  of 
getting  useful  data  into  computers  in  a 
fashion  that  is  acceptable  to  the  user  of 
the  computer.  Programmers  in  particular 
are  going  to  be  under  increasingly  greater 
pressure  to  be  more  and  more  productive. 
Their  ability  to  deal  with  the  problem  of 
getting  the  solution  out  of  their  heads 
and  into  the  computer  will  be  influenced 
in  great  measure  by  the  ease  with  which 
they  can  physically  enter  data  into  the 
machine.  Electronic  communications,  still 
a  budding  field  in  many  ways,  will  have 
its  success  measured  in  part  by  the  ease 
with  which  the  user  can  use  the  system, 
primarily  the  ease  with  which  messages 
can  be  composed  and  edited. 

With  few  exceptions,  all  the  pro¬ 
grams  and  data  in  every  computer  origi¬ 
nated  with  someone  typing  to  (at)  an  edi¬ 
tor  or  parser  of  some  sort.  This  is,  I  real¬ 
ize,  a  gross  over-simplification,  and  there 
are  cases  which  may  be  considered  to  be 
not  connected  with  any  editors  at  all  (a 
friendly  IBM  029  card  punch,  for  in¬ 
stance),  but  the  point  is  well  made:  in 
most  cases  someone  uses  a  text  editor  of 
some  sort  to  generate  a  source  program 
(even  DDT  can  be  considered  a  crude  sort 
of  editor  for  hex),  or  to  enter  data,  or  to 
generate  a  program  which  may,  itself,  be 
a  restricted  type  of  editor  or  parser  for 
data  entry.  A  lot  of  users  never  consider 
using  any  editor  other  than  the  one  which 
came  with  their  system  for  the  produc¬ 
tion  of  text  and  programs.  Some  realize 
they  can  improve  their  efficiency  by  pick¬ 
ing  another  editor  that  is  better  suited  to 
their  requirements.  Most  users  have  video 
terminals  of  one  sort  of  another,  yet 
don’t  have  an  editor  that  takes  advantage 
of  the  power  available  to  them.  This  arti¬ 
cle  is  about  a  class  of  editors  whose  popu¬ 
larity  is  gaining,  screen  editors,  and  one 
of  these  for  CP/M  in  specific,  MINCE 
($125.00,  Scribble  $125.00,  AMETHYST 
$350.00,  available  from  Mark  of  the  Uni¬ 
corn,  P.  O.  Box  423,  Arlington,  MA 
02174). 

Screen  Editors  in  General 

Simply  put,  screen  editors  are  a  class 
of  editors  that  are  meant  to  take  advan¬ 
tage  of  the  fact  that  CRT’s  (Cathode  Ray 


by  Barry  A.  Dobyns 


Tube  terminals)  don’t  use  paper.  The 
major  advantage  of  this  is  that  the  image 
on  the  screen  can  be  changed,  modified, 
and  updated  quickly.  This  is  in  stark  con¬ 
trast  to  paper  terminals,  where  any  modi¬ 
fications  usually  require  that  the  entire 
element  to  be  modified  be  printed  out 
again  rather  than  just  changing  the  part 
that  was  modified;  or  worse,  the  editor 
requires  that  one  remember  the  changes 
made,  until  one  specifically  requires  that 
the  region  which  has  been  modified  be 
printed  out. 

Many  people  are  making  the  move 
from  paper-terminal-oriented  editors  to 
screen-oriented  editors  which  show  the 
text  being  edited  at  all  times.  These  edi¬ 
tors  show  the  changes  in  the  text  dyna¬ 
mically,  so  the  user  always  knows  what 
effect  his  changes  have  made.  These  usu¬ 
ally  allow  the  user  to  move  about  in  the 
text  with  simple  single  character  com¬ 
mands  and  allow  modification  of  the  text 
at  the  cursor.  (Cursor:  1 .  the  place  on  a 
terminal  at  which  the  next  character  will 
be  inserted,  usually  a  block  or  under¬ 
score,  sometimes  blinking.  2.  the  place 
in  the  text  file  where  most  commands 
will  have  effect  next,  sometimes  called 
the  Point  usually  the  same  as  1 .  in  screen 
editors.)  Many  display  editor  users  can 
dispense  with  numerous  listings  of  then- 
text,  as  it  is  often  easier  to  enter  the  edi¬ 
tor  and  use  a  search  facility  to  find  some¬ 
thing  than  to  peruse  many  pages  of  print. 
Other  users  may  find  that  the  act  of  com¬ 
position  itself  is  made  much  easier,  rather 
than  writing  the  text  out  on  paper  first, 
one  can  start  by  typing  it  into  the  editor, 
using  the  editor  to  update  and  revise  it.  In 
general,  display  editors  are  also  easier  to 
use,  as  the  user  can  see  the  text  he  is  edit¬ 
ing  and  immediately  see  the  effect  of  the 
commands  he  enters  on  it.  On  a  printing 
terminal  this  usually  requires  a  non-trivial 
amount  of  mental  effort  to  remember 
what  has  happened,  or  results  in  a  lot  of 
wasted  paper  and  time,  especially  if  a  lot 
of  changes  are  to  be  made. 

A  simple  type  of  screen  editor  could 
have  merely  five  commands,  and  still  be 
very  powerful.  These  would  be  up,  down, 
right,  left,  and  delete  (one  character).  The 
screen  of  the  terminal  would  display  the 
area  of  text  around  the  cursor,  called  a 
“window”  because  it  acts  just  as  a  win¬ 
dow  onto  the  text  might,  hopefully  re¬ 
displaying  it  if  the  user  moved  off  the 
portion  of  text  currently  shown  on  the 
screen.  Usually  the  commands  would  be 
delegated  to  single  characters  easily  typed 


from  the  keyboard  (control  characters  are 
relatively  easy  to  type  on  most  termi¬ 
nals),  and  characters  which  are  not  com¬ 
mands  should  be  self-inserting,  that  is 
they  should  insert  themselves  into  the 
text  at  the  place  marked  by  the  cursor. 
Most  screen  editors  do  that  and  a  lot 
more,  offering  most  of  the  usual  search 
and  replace  facilities  that  other  editors 
offer,  and  often  many  special  features  of 
their  own.  Some  editors  also  offer  an  em¬ 
bedded  text  formatter  which  can  be  used 
for  the  production  of  “pretty”  printed 
copy. 

What  Makes  a  Screen  Editor  Good 

Unfortunately,  even  the  minimum 
screen  editor  is  not  a  simple  program  to 
write  at  all  when  one  has  to  deal  with 
more  text  than  there  is  available  memory. 
There  is  also  the  problem  of  getting  al¬ 
ready  prepared  text  into  the  editor,  and 
saving  it  when  the  user  is  done.  How  the 
editor  deals  with  these  problems  and 
what  other  conveniences  or  inconven¬ 
iences  it  offers  to  the  user,  determine  in  a 
large  part  the  utility  of  that  editor. 

Herewith  I  examine  the  features  that 
I  believe  a  good  editor  should  be  en¬ 
dowed  with  (this  is  by  no  means  the  final 
word  on  this  subject,  you  can  still  love 
ED  all  you  like,  I  just  don’t  use  it  myself 
anymore). 

Firstly,  it  should  be  at  least  as  fast  as 
I  am.  I  am  by  no  means  a  speed  typist.  I 
flunked  every  typing  course  I  took 
(three),  and  my  technique  at  a  keyboard 
has  been  described  in  numerous  degrading 
ways  that  I  will  decline  to  mention.  Still, 
if  I  am  provided  with  a  delete  key  (the 
correction  key  on  those  very  expensive 
Selectrics  does  fine),  I  can  make  any  tele¬ 
type  in  the  land  tremble  with  fear  and 
awe  (not  recommended,  they  tremble 
enough  as  it  is).  Insertion  from  the  key¬ 
board  should  never  be  interrupted  by  disk 
I/O,  calculation,  redisplay  or  Acts  of 
God.  I  refuse  to  use  any  editor  that  loses 
characters  that  I  type.  However,  I  may  be 
convinced  to  use  it  if  it  is  merely  slow 
in  showing  me  what  it  is  up  to,  but 
doesn’t  lose  anything.  On  the  other  hand, 
my  spooler  causes  my  system  to  lose 
characters  all  the  time.  I  do  not  like  to 
see  any  piece  of  software  choke  to  death. 
In  particular,  the  editor  should  not  choke 
on  files  over  200K  long.  Maybe  you  can 
always  get  along  with  very  short  files 
(much  less  than  64K),  but  I  always  seem 
to  have  all  these  files  around  that  exceed 
100K  (source  code  for  interpreters  and 


48 

178 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


compilers  can  often  get  big).  Indeed, 
there  should  be  no  limit  to  the  length  of 
the  file  you  can  edit  other  than  the 
amount  of  storage  you  have  available. 

I  want  to  be  able  to  move  about  fast¬ 
er  than  one  character  at  a  time.  Character 
movement  commands  in  line,  screenful, 
word,  sentence,  paragraph  (or  atom, 
statement,  and  procedure)  increments  are 
a  must.  There  should  be  modes  for  dif¬ 
ferent  types  of  text.  If  I  am  editing  Pascal 
instead  of  English  I  should  be  able  to 
tell  the  editor  (or  insert  a  keyword  at  the 
beginning  of  the  file  as  a  comment  that 
the  editor  will  pick  up  on)  this  fact  so 
that  my  paragraph  (English)  commands 
now  work  on  procedures  (Pascal)  or 
defuns  (LISP)  or  whatever.  There  should 
be  commands  for  deletion  of  the  same 
units  as  movement.  I  should  also  be  able 
to  specify  a  “region”  not  normally  de¬ 
limited  by  the  regular  units  for  destruc¬ 
tion  and  other  purposes  like  saving,  copy¬ 
ing  and  moving.  Any  command  which 
kills  more  than  one  character  at  a  time 
should  be  reversible,  should  I  turn  fickle. 
Having  to  return  to  the  original  file  in  the 
event  of  massive  failure  is  only  marginally 
acceptable  (it  is  expected  after  catastro¬ 
phic  failure).  I  should  not  be  forced  to 
save  the  new  text  out  to  the  same  file¬ 
name,  (nor  should  backups  always  have 
the  extension  .BAK).  I  should  be  able 
to  create  more  than  one  output  file  from 
a  single  editing  session,  without  exiting 
and  reentering  the  editor.  I  may  want  to 
create  a  number  of  slightly  different  files, 
all  with  different  names  from  the  same 
initial  file.  (Form  letters  the  hard  way,  or 
ten  programs  which  only  differ  by  one 
line  or  so.) 

Searching  and  replacement  should  be 
straightforward  and  related.  Insertion 
from  other  files  should  be  easy.  If  it  is 
doing  redisplay,  and  I  give  it  another 
command  which  requires  redisplay  also, 
it  should  execute  the  second  command 
before  finishing  the  redisplay  for  the  first 
(if  I  give  it  sixteen  consecutive  “next 
screenful”  commands,  I  want  the  six¬ 
teenth  screen,  not  all  fifteen  in  between). 
All  commands  should  take  numeric  ar¬ 
guments  where  appropriate  (one  should 
type  a  command  for  “5  line  deletes” 
rather  than  typing  “delete  a  line”  five 
times).  In  fact,  the  single  action  version 
of  each  command  may  merely  be  the  spe¬ 
cial  case  of  the  command  without  argu¬ 
ments.  In  addition,  whole  command  se¬ 
quences  should  be  delimitable  in  order  to 
accept  repetition  counts.  No  command 


primitive  should  require  more  than  two 
characters  (keystrokes).  All  potentially 
catastrophic  commands  (like  deleting 
whole  paragraphs,  and  saving  files)  should 
be  several  keystrokes  long. 

Command-naming  strategies  should 
be  as  internally  consistent  as  possible.  If 
they  are  to  be  mnemonically  related, 
make  them  all  that  way.  If  they  are  to  be 
positionally  related,  pick  a  home  key  that 
gives  you  enough  space  around  it  to  do 
the  job  properly.  My  personal  preference 
is  for  mnemonically  related  command 
structures,  as  they  tend  to  be  distributed 
all  over  the  keyboard,  and  can  actually  be 
touch-typed  on  many  terminals,  whereas 
position-oriented  schemes  usually  are  im¬ 
possible  to  touch- type,  and  cramp  my 
hand.  There  is  much  to  be  said  for  an  edi¬ 
tor,  all  of  whose  commands  can  be  touch- 
typed  (that  is,  typed  with  the  hands  re¬ 
maining  in  the  “home”  position  on  the 
keyboard).  This  is  often  a  function 
of  both  the  editor  and  the  terminal/ 
keyboard  design  (many  keyboards  have 
the  “Control”  key  in  an  awkward  place, 
and  have  repositioned  many  of  the 
“normal”  keys,  like  “DEL”  and  “BACK¬ 
SPACE”  so  that  they  are  hard  to  get  to). 
In  any  event  I  am  vehemently  opposed  to 
the  use  of  “special  function”  keys  that 
require  the  operator  to  move  his  hands 
away  from  the  keyboard.  The  time  lost 
by  locating  the  function  key  and  relocat¬ 
ing  the  home  key  is  much  greater  than 
the  time  saved  by  typing  one  less  key¬ 
stroke.  Sufficient  documentation  should 
be  built  in  so  as  to  enable  a  new  user  who 
is  familiar  with  editors  of  that  type  to  be 
able  to  learn  it  quickly. 

Special  cases  should  not  break  the 
editor  (a  file  made  up  of  only  one  very 
long  line,  for  instance,  will  break  many 
editors;  trying  to  edit  object  code  usually 
will  break  an  editor,  too).  Broken  pro¬ 
grams  are  not  to  be  tolerated,  unless  I 
have  authored  the  program. 

The  file  produced  by  the  editor 
should  be  compatible  with  other  editors 
for  the  same  operating  system,  and 
should  not  be  filled  with  “silly”  things. 
I  do  not  like  the  idea  of  an  editor  doing 
its  bookkeeping  in  the  file  being  edited. 
“Soft”  characters  is  one  such  concept 
that  still  gives  me  the  creeps.  The  prob¬ 
lem  here  seems  to  be  that  the  editor/ 
formatter  can’t  tell  where  a  paragraph  be¬ 
gins  or  ends,  so  the  user  must  put  in  a  car- 
raige  return  to  insure  that  paragraph 
breaks  are  not  “filled”  over.  Maybe  I’m 
harsh,  but  “soft”  characters  seem  to  be 


an  attempt  to  overcome  a  design  over¬ 
sight,  rather  than  a  feature.  Why  not  give 
the  user  of  the  editor  a  command  that 
“fills”  the  text  out  to  a  specified  column, 
so  the  user  can  get  the  column  he  wants  it 
filled  to  and  “grind”  his  text  all  he 
wants?  Maybe  give  the  user  a  mode  for  in¬ 
put  that  automatically  breaks  lines  off  as 
they  are  input  too,  but  keep  non-ASCII 
garbage  out.  I  have  a  need  for  a  utility 
that  does  nothing  but  take  “soft  charac¬ 
ters”  and  replace  them  with  “hard”  ones 
if  PIP  didn’t  do  it  already. 

My,  he  doesn’t  want  very  much,  you 
might  say.  Indeed,  as  long  as  I  can  pick 
and  choose  about  what  I  want,  I  will  pick 
lots  of  features  designed  to  make  life 
easier  for  me.  I  compose  at  the  keyboard 
of  my  terminal,  and  I  like  having  only 
one  editor  for  everything  (text,  papers, 
documentation,  programs,  data).  I  want 
my  editor  and  my  formatter  separate 
though,  thank  you,  as  (I  can  hope)  the 
creation  of  two  programs  (an  editor  and 
a  formatter)  will  result  in  a  more  power¬ 
ful  one  of  each,  as  there  is  more  memory 
available  if  they  don’t  have  to  be  co¬ 
resident.  Besides,  I  may  have  a  number  of 
formatters,  one  that  is  fast  and  clumsy, 
and  one  that  is  slow  but  fancy,  and  one 
that  is  worthless  but  I  wrote  it  myself,  so 
I  use  it  anyway.  It  is  difficult  to  separate 
the  editor  and  the  formatter  in  many  of 
the  do-it-all  programs,  especially  if  they 
do  “bookkeeping”  in  your  files.  On  the 
other  hand,  there  is  the  case  for  several 
editors  and  only  one  formatter,  but  the 
need  for  separate  formatters  and  editors 
is  still  valid. 

Reality  vs.  Fantasy 

Unfortunately,  as  you  may  have  sus¬ 
pected,  gentle  reader,  the  perfect  text 
editor  will  take  infinite  memory,  an  in¬ 
finitely  fast  computer,  and  will  be  perfect 
to  only  one  user.  (No  two  users  have  ever 
agreed  completely  on  what  constitutes  a 
perfect  editor.)  I  often  feel  that  there  is 
no  middle  ground  in  computers  at  all  (be 
it  languages,  editors,  or  hardware),  which 
is  fine  since  many  of  us  depend  on  just 
that  fact  for  our  livelihoods.  As  it  is, 
many  of  the  editors  now  available  for 
CP/M-based  8080/Z80  computers  are 
very  good,  even  by  the  standards  of  what 
is  available  for  many  “big  mainframes.” 
(Anyone  who  has  ever  used  the  CMS  edi¬ 
tor  on  a  video  terminal  and  agonized 
about  the  fact  that  there  wasn’t  anything 
any  better  understands.) 

At  some  point  (usually  very  early, 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


49 

179 


before  any  code  ever  gets  written)  the  de¬ 
signer  of  an  editor  is  going  to  make  some 
very  important  trade-offs  and  some  de¬ 
cisions  that  will  affect  the  nature  of  his 
editor.  One  way  to  protect  against  mak¬ 
ing  the  wrong  choice  is  to  put  these  de¬ 
cisions  off  as  long  as  possible,  i.e.,  don’t 
start  with  a  command  set  in  mind  that 
you  may  not  want  to  use  later,  but  build 
a  command  dispatch  table  so  that  you 
can  link  any  of  the  commands  (like 
Control- P)  with  any  of  the  procedures 
that  actually  accomplish  the  work  you 
want  done  (like  Previous* Line).  Many  of 
these  sort  of  choices,  if  deferred  long 
enough,  can  be  incorporated  into  a  set  of 
configurable  options  that  the  user  can  use 
to  make  the  designer’s  version  of  a  “per¬ 
fect”  editor  into  his  own  version  of  per¬ 
fection. 

Most  of  us  can’t  afford  infinite  mem¬ 
ory,  but  our  editor  and  operating  system 
can  often  be  expected  to  gobble  up  as 
much  as  32K,  and  that’s  not  very  much 
space  left  to  edit  in.  The  editor  needs  to 
make  some  very  smart  decisions  about 
what  part  of  the  file  to  read  in,  and  when, 
if  it  is  to  give  the  user  the  feeling  of 
having  the  entire  file  in  memory  at  once; 
or  it  will  have  to  do  something  like  ED 
does,  and  make  one  pass  at  the  file,  with 
no  going  back  to  the  beginning  unless  it’s 
still  in  memory.  The  editor  can  swap  sec¬ 
tions  of  the  file  back  out  to  disk  on  a 
least-recently-used  (LRU)  basis,  but  one 
can  get  into  trouble  if  one  spends  too 
much  time  doing  disk  I/O  (one  can  lose 
characters  from  the  keyboard),  and  it 
usually  requires  a  special  file  on  disk  to 
swap  to,  which  must  be  as  big  as  any  file 
that  is  to  be  edited.  Smart  swapping  on 
an  LRU  basis  is  what  many  operating  sys¬ 
tems  (and  cache  buffers)  do  to  act  as  if 
available  memory  (or  available  fast  mem¬ 
ory)  is  much  larger  than  it  really  is. 

MINCE,  AMETHYST  &  EMACS 

MINCE  (Mince  Is  Not  Complete 
Emacs)  is  a  recent  addition  to  the  proli¬ 
feration  of  Screen  Editors.  MINCE  is 
modeled  after  EMACS,  an  editor  which 
grew  out  of  many  years  of  experience 
with  TECO  at  MIT.  EMACS  is  interac¬ 
tively  extensible,  a  nice  feature  indeed. 
MINCE  is  merely  extensible.  (The  differ¬ 
ence  being  that  the  High  Level  Code  un¬ 
derlying  EMACS  (TECO)  is  interpreted, 
so  that  one  can  edit  up  a  routine,  and 
then  execute  it  immediately,  whereas  the 
High  Level  Code  underlying  MINCE  (C) 
is  compiled.) 


50 

180 


The  advantages  of  extensibility  are 
numerous.  Short  of  actual  extension,  one 
can  customize  the  editor  to  meet  one’s 
tastes.  The  simplest  sort  of  customiza¬ 
tion,  the  rearrangement  of  commands,  is 
by  itself  of  inestimable  value  to  those 
who  do  not  share  my  penchant  for 
mnemonically  related  commands.  (You 
can  use  the  “D”  key  for  your  home  key 
if  you  like,  and  run  out  of  room  if  you 
like  too,  while  trying  to  design  a  position- 
oriented  command  set).  Another  sort  of 
customization  is  making  supplied  com¬ 
mands  behave  the  way  you  think  they 
should  behave,  not  the  way  the  manual 
says  they  do.  Movement  commands  often 
behave  as  intended,  but  rarely  as  expect¬ 
ed.  It  is  a  simple  matter  to  change  the  be¬ 
havior  of  existing  commands.  In  fact,  the 
dividing  line  between  extension  and  com¬ 
plex  customization  is  not  a  clear  one. 
MINCE  can  be  bought  in  a  standard  con¬ 
figuration,  or  can  be  bought  with  the 
source  code  for  the  command  set,  so  that 
extensions  can  be  made.  Users  can  write 
commands  of  their  own  to  perform  often- 
needed  functions,  or  write  “modes”  in 
which  some  command  definitions  are 
slightly  altered  to  facilitate  easier  editing 
of  different  text  types.  For  example,  one 
might  have  an  ALGOL  mode  where  the 
function  that  looked  for  paragraphs  (an 
internal  one)  looked  for  “BEGIN”  and 
“END”  pairs  starting  in  the  first  column 
while  in  English  Mode  it  might  merely 
look  for  a  lone  tab  in  the  first  column,  so 
that  the  existing  paragraph  movement 
and  modification  commands  will  work  in 
a  useful  manner.  This  extensible  MINCE 
(which  comes  with  BDS  C  and  Scribble, 
a  text  formatter)  is  called  AMETHYST. 

MINCE  is  completely  portable.  Writ¬ 
ten  in  the  language  C,  it  is  conceivably 
portable  to  any  machine  that  will  support 
C.  Although  developed  on  a  CP/M  sys¬ 
tem,  Mark  of  the  Unicom  has  brought 
MINCE  up  on  a  DEC  1 1  /70  already  and 
the  conversion  and  installation  took  a 
mere  two  days  to  perform.  This  sort  of 
portability  means  that  you  can  continue 
to  use  MINCE  on  your  16-bit  or  32-bit 
computer  which  supports  **NIX  or  C. 
Site  license  agreements  (some  clubs  can 
qualify  as  sites)  are  also  available.  It  is 
conceivable  that  MINCE  could  be  the 
last  editor  you  will  ever  need  to  get,  no 
matter  what  you  upgrade  to  or  grow  into. 

MINCE  tackles  the  problem  of  file 
management  with  an  LRU  scheme  that 
works  very  wel),  even  for  files  of  appre¬ 
ciable  size.  MINCE  does  all  if  its  work  in 


in  a  MINCE. SWP  file  either  on  the  logged 
disk,  or  on  the  A:  drive.  MINCE  also  al¬ 
lows  the  user  to  edit  up  to  seven  files  con¬ 
currently.  This  may  seem  like  a  good  way 
to  get  oneself  into  trouble  at  first,  but  it’s 
an  excellent  way  to  compose  a  paper  or 
program  from  several  other  papers  or 
programs.  MINCE  also  will  display  one  or 
two  windows  at  once.  These  windows  can 
be  into  the  same  file  or  into  different 
files. 

MINCE’s  ability  to  display  multiple 
windows  and  to  edit  multiple  files  is  an 
invaluable  aid  in  composing  text  or  pro¬ 
grams  from  many  small  subunits  in  differ¬ 
ent  files.  One  might  use  it  to  create  a 
new  program  which  contains  routines  or 
functions  swiped  from  a  number  of 
others,  or  to  include  part  of  a  previous 
letter  in  a  follow-up  letter. 

MINCE  allows  the  user  to  save  files 
to  whatever  filename  (d:filename.ext)  he 
wants,  at  any  time  in  the  edit  session.  File 
saving  is  only  done  when  an  explicit  com¬ 
mand  to  do  so  is  issued.  No  .BAK  files  are 
created.  Furthermore,  no  files  are  created 
automatically,  even  upon  exit  from  the 
editor,  although  an  attempt  to  exit  when 
modifications  have  been  made  since  the 
last  save  will  result  in  a  prompt  to  allow 
you  to  reconsider  abandoning  your  work. 
A  disadvantage  of  this  scheme  is  that  the 
default  filename  for  a  C-X  C-S  (Save 
File)  is  the  same  filename  that  the  file  ori¬ 
ginally  had,  which  could  potentially  ob¬ 
literate  the  original.  There  is  also  a  C-X 
C-W  (Write  File)  which  prompts  for  a 
filename.  Users  should  probably  get  ac¬ 
customed  to  using  Write  File  instead  of 
Save  File  unless  they  are  certain  there  is 
no  need  for  backup.  Using  Write  File  with 
a  generation  number  for  the  extension 
(extensions  of  the  form  .001,  .002  and 
so  on)  would  probably  be  the  best  bet  for 
text  creation.  An  operating  system  that 
provided  for  generation  counts  as  a  third 
extension  would  be  the  best. 

MINCE  produces  files  which  are 
compatible  with  ED,  and  every  interpret¬ 
er  and  compiler  I  have  tried.  MINCE- 
produced  files  also  can  be  fed  into  most 
of  the  text  formatters  I  have  attempted 
to  use.  The  only  problem  will  be  with 
“automatic  justification”  with  those  for¬ 
matters  that  will  not  take  out  “hard” 
carriage  returns.  Justify  your  text  in 
MINCE  first.  MINCE  leaves  no  bookkeep¬ 
ing  at  all  in  the  files  it  creates,  either  dur¬ 
ing  the  session  or  after  it  is  written.  (You 
can  reset  out  of  MINCE  with  impunity, 
and  be  assured  that  nothing  is  damaged, 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


except  your  ego.) 

For  all  my  ravings  about  losing  char¬ 
acters,  MINCE  occasionally  loses  charac¬ 
ters  on  my  system,  but  that  is  because  my 
DMA  disk  controller  can’t  possibly  poll 
my  console.  MINCE  would  probably  lose 
even  less  on  a  system  that  had  interrupt- 
driven  console  input.  MINCE  has  a  type- 
ahead  buffer  of  80  characters,  and  does 
a  lot  of  console  input  checking.  It  will 
only  lose  characters  when  a  disk  opera¬ 
tion  is  in  progress,  and  prints  a  message 
on  the  screen  to  this  effect  during  every 
disk  operation.  Still,  MINCE  waits  until 
the  console  has  been  idle  for  a  while  (a 
time  unit  that  the  user  sets  for  himself 
when  he  first  configures  the  program  for 
his  system)  before  doing  any  disk  opera¬ 
tions.  MINCE  should  never  have  to  go  to 
disk  while  the  user  is  typing  (it  really 
hasn’t  on  me,  either),  unless  you  can  type 
continuously  for  20K  or  more  without 
pausing.  (If  you  can,  I’m  very  impressed.) 

The  largest  file  size  which  can  be 
edited  is  determined  by  the  size  of  the 
MINCE.SWP  file,  another  parameter  you 
set  when  configuring.  The  authors  recom¬ 
mend  a  64K  .SWP  file,  which  I  find  quite 
reasonable  for  everything  but  those  few 
monster  files  I  mentioned  earlier.  Cur¬ 
rently,  the  maximum  allowable  size  for  a 
.SWP  file  is  248K,  and  the  largest  file  I 
have  is  208K  (but  I  never  edit  it  anyway, 
I  just  print  it  out),  so  I’m  not  in  trouble 
yet.  I  presume  the  maximum  .SWP  file 
size  will  be  upped  in  future  versions  of 
MINCE  (or  when  the  authors  get  a  hard 
disk). 

The  command  set,  as  supplied,  is  a 
delight.  There  are  several  types  of  com¬ 
mands,  determined  by  command  prefix 
(or  lack  of  prefix).  Control-F  (Control 
characters  will  be  represented  by  the  pre¬ 
fix  “C-”)  moves  forward  one  character 
(F  for  forward,  get  it?).  C-B  moves  back 
one  character  (guess  what  the  B  is  for). 
Meta-F  forward  one  word  (Meta  charac¬ 
ters  are  actually  characters  preceded  by 
the  ASCII  “ESC”  character,  but  for  rea¬ 
sons  of  MINCE’s  heredity,  they  are  called 
Meta-  characters.  (It  is  possible  to  gener¬ 
ate  Meta-  characters  in  hardware,  the 
authors’  keyboard  does  this).  If  the  term 
Meta-  is  taken  to  mean  “greater  than,” 
then  many  of  the  command  definitions 
make  lots  of  sense),  and  M-B  goes  back 
one  word.  C-A  and  C-E  go  to  the  begin¬ 
ning  and  end  of  a  line,  respectively,  while 
M-A  and  M-E  do  the  same  for  sentences. 
“DEL”  and  C-D  delete  forward  and  back 
words.  C-K  deletes  lines,  and  M-K  deletes 


sentences.  M-[  (square  bracket)  moves 
to  the  beginning  of  a  paragraph,  and  M-] 
moves  to  the  end. 

File  commands  are  all  preceded  by 
C-X  (for  extended  commands).  C-X 
C-F  finds  a  file  and  reads  it  into  a  buffer. 
C-X  C-R  reads  a  file  into  an  already 
existing  buffer.  C-X  C-S  saves  a  file  to 
the  last  specified  filename,  destroying 
anything  with  that  filename.  C-X  C-W 
writes  to  a  different  filename  (prompting 
you  for  it).  Other  C-X  commands  select 
Modes  (C-X  M  prompts  for  and  selects 
a  mode,  like  Page  Mode  (overwrite))  or 
tell  you  just  where  you  happen  to  be  in 
the  text  (C-X  =).  C-X  K  kills  the  current 
buffer  (if  you  are  using  more  than  one, 
and  you  need  to  free  up  space).  Termina¬ 
tion  is  accomplished  by  C-X  C-C,  which 
prompts  if  you  have  modified  anything 
since  the  last  save,  asking  if  you  really 
want  to  throw  it  away. 

MINCE  uses  two  lines  at  the  bottom 
of  the  screen  to  give  useful  information. 
On  the  “Model  Line”  MINCE  shows  its 
version  number,  the  currently  selected 
mode  (if  any,  otherwise  it  shows  “nor¬ 
mal”)  the  buffer  name,  the  current  file¬ 
name,  the  distance  the  point  is  from  the 
beginning  of  the  buffer  expressed  as  a 
percentage,  whether  the  buffer  has  been 
modified  or  not  and  whether  there  is  any¬ 
thing  in  a  special  buffer  called  the  “kill 
buffer.”  On  the  last  line  of  the  screen,  the 
“Echo  Line,”  MINCE  prompts  for  input, 
echoes  command  prefixes  if  you  type 
too  slow,  tells  you  when  it  is  writing  to 
disk,  or  swapping,  and  signals  completion 
of  certain  commands. 

There  is  no  help  available  within 
MINCE,  but  I  suppose  one  could  make  a 
second  window  (C-X  2),  switch  to  it  (C- 
X  0)  and  read  the  MINCE  short  command 
list  into  it  (C-X  C-F  SCOMM.DOC’CR’) 
and  scroll  through  it  C-V  forward,  and 
M-V  backwards)  until  one  finds  what  one 
wants.  On  the  other  hand,  the  tutorial 
that  comes  in  the  manual  is  as  good  as 
any  tutorial  I  have  seen  in  a  long  time, 
and  it  comes  in  two  versions,  one  for 
novices,  and  one  for  folks  who  think  they 
have  experience.  If  one  has  had  experi¬ 
ence  with  EMACS  one  may  never  need  to 
consult  the  manual  at  all  (except  to  con¬ 
firm  that  you  can’t  really  have  minibuf¬ 
fers  full  of  TECO  code,  and  to  get  the 
wall  chart  out  of  the  manual  and  onto 
your  wall).  The  wall  chart  can  be  cut  up 
and  pasted  to  your  terminal  (it  fits  on 
mine)  or  posted  on  the  wall  by  your 
terminal  (or  bathroom  mirror).  Once  you 


successfully  make  it  through  the  tutorial 
you  can  do  most  of  the  terribly  difficult 
things,  and  understand  enough  that  you 
needn’t  always  look  in  the  manual  for 
assistance.  The  command  set  is  easy 
enough  to  remember  so  that  one  doesn’t 
really  miss  internal  documentation.  (I 
learned  how  to  use  EMACS  without  any 
sort  of  manual  at  all,  but  there  really  is 
no  excuse  for  stupidity.) 

Extending  MINCE  with 
AMETHYST 

Purchasers  of  the  AMETHYST  pack¬ 
age  will  receive  a  MINCE,  a  Scribble  (a 
text  formatter  to  be  the  subject  of 
another  article),  a  BDS  C  compiler  and 
the  source  code  in  C  for  the  MINCE 
command  set,  and  support  routines  for 
the  commands  and  the  terminal  in  C.  It 
does  not  include  the  source  for  the 
multiple-window  redisplay,  or  the  buf¬ 
fered  file  I/O,  which  is  most  of  the  body 
of  MINCE.  It  is  the  intent  of  Mark  of  the 
Unicom  that  you  can  rewrite  the  com¬ 
mand  set,  and  your  own  commands  all 
you  want,  but  that  you  cannot  rewrite 
the  editor  itself  (or  gronk  it  for  all 
eternity)  and  resell  it.  For  **NIX  users, 
who  are  usually  provided  with  source 
code  for  everything,  the  source  for 
MINCE  is  negotiable  on  a  per  site  basis. 

This  may  sound  disheartening  at 
first  to  all  the  hard  core  C  hackers  out 
there  who  are  gearing  up  to  perform 
wizardry  on  their  version  pf  MINCE. 
However,  Mark  of  the  Unicom  has  prop¬ 
erly  abstracted  most  every  conceivable 
function  so  that  linking  to  internal  func¬ 
tions  is  a  simple  task.  AMETHYST  is  pro¬ 
vided  with  an  exhaustive  program  logic 
manual  which  details  the  internal  organi¬ 
zation  and  function  of  all  the  routines  ac¬ 
cessible  to  the  programmer,  entry  point 
documentation  is  provided  for  every 
primitive  available  within  MINCE,  and  an 
excellent  discussion  of  state  of  the  art 
theory  of  text  editors  is  included. 

MINCE  is  implemented  as  two  edi¬ 
tors,  one  inside  the  other.  The  inner  edi¬ 
tor  consists  of  the  redisplay  and  file 
handling  functions,  and  editing  primi¬ 
tives.  The  outer  editor  parses  the  terminal 
input,  provides  command  dispatch,  and 
interprets  many  of  the  more  complex 
commands.  It  is  the  outer  editor  for 
which  the  source  code  is  provided.  In  the 
outer  editor,  command  names  (characters 
typed  at  the  keyboard)  are  bound  to  the 
commands  (functions  in  C  which  in  turn 
call  the  primitives  contained  within 


Dr.  Dobb’s  Journal,  Number  54,  April  1981 


51 

181 


Club  News 


MINCE).  Such  is  the  flexibility  of  this 
scheme  that  it  is  plausible  that  a  program¬ 
mer  could  create  a  MINCE  mode  to  emu¬ 
late  nearly  any  video  editor  (although  the 
motivation  for  such  an  act  is  beyond 
me). 

Also  provided  is  a  terminal  abstrac¬ 
tion  which  could  be  modified  to  allow 
MINCE  to  support  any  sort  of  video  de¬ 
vice  whatsoever.  The  terminal  abstraction 
could  be  written  to  support  memory - 
mapped  video  boards,  terminals  which  do 
not  support  cursor  addressing,  or  termi¬ 
nals  which  cannot  be  supported  through 
CONFIG.COM  (the  MINCE  configuration 
program).  The  terminal  abstraction  could 
also  be  used  to  make  an  inconvenient  ter¬ 
minal  livable.  My  terminal  has  the  “DEL” 
and  (underbar)  on  the  same  key,  but 
the  “DEL”  is  a  shifted  character.  I  could 
alter  the  Terminal  abstraction  to  swap  the 
two  on  input,  so  I  don’t  have  to  shift  to 
type  “DEL.” 

Conclusions 

MINCE  is  one  of  the  finest  editors  I 
have  ever  used,  on  any  machine.  It  is 
without  question,  in  my  opinion,  a  ab¬ 
solute  steal  at  the  base  price,  and  a  fan¬ 
tastic  bargain  as  AMETHYST.  MINCE  is 
not  perfect,  and  I  am  ready  to  admit  that. 
MINCE  lacks  some  features  like  provi¬ 
sion  for  iteration  of  more  than  one  com¬ 
mand  as  a  group,  and  a  “grind  region”  in 
addition  to  the  “grind  paragraph”  it  now 
has.  The  exquisite  beauty  of  AMETHYST 
is  that  the  features  I  think  it  lacks,  I  can 
write  in.  And  I  will.  So  can  you. 

I  hope  there  will  be  some  sort  of  ex¬ 
change  program  for  AMETHYST  func¬ 
tions  and  modes  that  users  write.  Judging 
from  the  EMACS  history  this  will  be  the 
major  way  in  which  the  program  will 
grow,  through  input  from  its  users.  Most 
of  the  current  library  functions  in 
EMACS  were  submitted  by  users  in  the 
community.  This  sort  of  exchange  and 
support  could  ensure  that  MINCE  will 
stay  as  far  ahead  of  everyone  eke  as  it  k 
now. 

Mark  of  the  Unicom  k  ambitious 
about  MINCE,  AMETHYST,  and  Scrib¬ 
ble.  I  feel  they  have  every  reason  to  be. 
The  complete  system  k  supportable  on 
nearly  every  machine  available,  and  k 
patterned  after  systems  (EMACS  and 
SCRIBE)  which  have  fared  very  well  in 
demanding  user  environments.  There  k 
no  reason  why  MINCE  and  Scribble  could 
not  make  the  bask  of  an  office-type 
word  processing  system  that  could  rival 


52 

182 


the  best  of  the  “big  name”  systems. 
There  k  no  reason  that  MINCE  could  not 
be  used  as  a  program  development  tool  of 
the  highest  caliber.  If  you  feel  like  you 
got  locked  into  an  editor  that  k  merely 
mundane,  then  maybe  you  need  MINCE. 

Bibliography 

C.  A.  Finseth,  B.  N.  Hess,  S.  Layson,  J.  T. 
Linhart,  MINCE  User  Documentation  (Mark  of 
the  Unicom,  1980). 

C.  A.  Finseth,  B.  N.  Hess,  S.  Layson,  J.  T. 
Linhart,  MINCE  Internal  Documentaiton  (Mark 
of  the  Unicom,  1980). 

B.  W.  Kemighan  and  D.  Ritchie,  The  C  Pro¬ 
gramming  Language  (Prentice  Hall  1978). 

B.  K.  Reid  and  J.  H.  Walker,  SCRIBE  Introduc¬ 
tory  Users  Manual,  Second  Edition  (Camegie- 
Mellon  University,  1979). 

R.  M.  Stallman,  EMACS  The  Extensible,  Cus¬ 
tomizable,  Self- Documenting  Display  Editor 
(Massachusetts  Institute  of  Technology,  AI 
Memo  No.  519, 1979). 

R.  M.  Stallman,  EMACS  Manual  for  TWENEX 
Users  (Massachusetts  Institute  of  Technology, 
Al  Memo  No.  555, 1980). 

L.  Zolman,  BD  Software  C  Compiler  V1.4 
User’s  Guide  (BD  Software,  1980). 


PCNET  Protocol 

( Continued  from  page  47) 

that  k  understandable  enough,  we  will 
follow  the  example  of  the  FORTH  Inter¬ 
est  Group,  conducting  a  large  workshop 
in  which  the  owners  of  many  different 
kinds  of  computers  recode  the  “model” 
implementation  into  their  favorite  lan¬ 
guage,  for  their  own  machine  -  but  ako 
for  all  other  users  of  their  kind  of  com¬ 
puter.  We  will  dktribute  the  basic  ver¬ 
sions  of  the  PCNET  protocol  without 
copyright.  We  will  then  encourage  people 
to  develop  other  services  and  products 
that  use  the  PCNET  protocol  as  the  basic 
means  of  communication.  We  have  the 
support  of  People’s  Computer  Company, 
which  k  noted  for  encouraging  the  bene¬ 
ficial  application  of  personal  computers. 

We  are  grateful  for  the  talented  con¬ 
tributions  of  many  individuak  who  have 
recognized  thk  effort’s  importance.  We 
would  welcome  further  contributions  in 
money,  materiak,  or  participation.  We 
will  soon  be  ready  for  the  large  workshop 
to  recode  the  model  implementation  for 
many  kinds  of  computers,  and  enthusias¬ 
tic  volunteers  from  the  San  Franckco  Bay 
area  are  particularly  welcome.  ■  ■ 


San  Diego  Computer  Society 

The  SDCS  Board  of  Directors  has  au¬ 
thorized  the  formation  of  an  Educator’s 
Interest  Group.  In  order  to  better  support 
the  use  of  computers  in  schook,  EDIG 
will  provide  teachers,  students  and  admin- 
ktrators  (presumably)  with  information, 
techniques  and  other  forms  of  assistance 
in  areas  of  computers  and  computer  sci¬ 
ence.  They  have  scheduled  monthly  meet¬ 
ings  for  different  parts  of  the  San  Diego 
metro  area.  Questions  or  comments  may 
be  directed  to  Mel  Zeddies,  c/o  SDCS, 
P.  O.  Box  81537,  San  Diego,  CA  92138. 

British  Computer  Club 

Hobby  computer  club  members  at 
the  Polytechnic  of  North  London  will  run 
an  inner  city  computer  center  in  conjunc¬ 
tion  with  staff  members  and  senior 
students.  They  will  be  available  to  give 
demonstrations,  familiarization  courses 
and  advice  to  visitors. 

The  computer  center  aims  to  help 
small  businesses  in  the  urban  area.  A 
£20,000  grant  from  the  Hackney/Isling¬ 
ton  Inner  City  Partnership,  in  association 
with  the  Inner  London  Education  Au¬ 
thority,  will  be  used  to  acquire  several 
computer  systems  in  a  broad  range  of 
prices.  Small  businesses  will  be  able  to  use 
these  for  a  computer-based  business  con¬ 
trol  system,  integrated  with  the  rest  of 
their  business  and  with  the  owner  educat¬ 
ed  in  how  to  exploit  the  full  potential  of 
the  computer  operations. 

The  project  k  hoped  to  alleviate  a 
major  cause  of  job  loss  —  the  high  mortal¬ 
ity  rate  of  small  business  in  the  area.  A 
principal  cause  of  the  failure  appears  to 
be  lack  of  financial  control,  poor  purchas¬ 
ing  and  marketing  systems  and  need  for 
better  management  skilk.  The  Polytech¬ 
nic  has  a  thriving  computer  club  with  an 
active  business  computing  section.  They 
plan  to  open  the  center  each  evening  and 
all  day  on  Thursdays  and  Fridays. 

FORTH  Interest  Group 

In  the  San  Francisco  Bay  area,  FIG 
members  and  interested  parties  meet  the 
fourth  (FOURTH?)  Saturday  of  each 
month  from  1 0  a.m.  to  4  p.m.  Thk  long- 
kh  meeting  k  in  two  parts.  The  mornings 
are  for  demonstrations  and  various  pre¬ 
sentations,  while  the  afternoon  schedule 
conskts  of  more  formal  proceedings.  You 
can  find  it  in  the  Community  Hall  of  the 
Southland  Mall  in  Hayward. 


Di.  Dobb’s  Journal,  Number  54,  April  1981 


m 


a-  ~ 


.  wm 


S2.50  ($3.00  In  Canada) 


Dr.  Dobb's  Journal  of 

COMPUTER  Calisthenics  &  Orthodontia 

FOR  USERS  OF  SMALL  COMPUTER  SYSTEMS 

Number  55  May  1981  Volume  6,  Issue  5 


Santa  Barbara  Tiny  BASIC  for  6809’s 

by  James  A.  Hinds 

A  Smart  2716  EPROM  Programmer 

by  Eric  M.  Miller 

CAD  for  Time  Delay  Circuits 

by  Hal  Knippenberg 

What  to  Do  with  Those 
Extra  Function  Keys 

by  John  B.  Palmer 

and  more! 


Kg 


P.O.  Box  E 
Menlo  Park,  CA 
94025 


Dr.  Dobb's  Journal  of 

COMPUTER  Calisthenics  6  Orthodontia 


Volume  6,  Issue  5 
Number  55 
May  1981 


Contents 


Articles  Departments 


Using  (and  Misusing)  the  Z-80  Microprocessor  .  .  7 

by  Ray  Duncan 

A  Smart  2716  EPROM  Programmer . 10 

by  Eric  M.  Miller 

What  to  Do  With  Those  Extra  Function  Keys ...  14 

by  John  B.  Palmer 

CAD  for  Time  Delay  Circuits .  17 

by  Hal  Knippenberg 

Santa  Barbara  Tiny  BASIC  for  6809’s . 22 

by  James  A.  Hinds 


Dr.  Dobb's  Journal  (USPS  307690)  is  published  twelve  times  per  year 
by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real,  Menlo 
Park,  CA  94025.  Second  class  postage  paid  at  Menlo  Park, 
California  94025  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  94025. 

©  1981  by  People’s  Computer  Company  unless  otherwise 
noted  on  specific  articles.  All  rights  reserved. 


Letters .  4 

Of  Interest .  12 

Book  Reviews .  18 

Dr.  Dobb’s  Clinic . 20 

Software  Reviews . 40 


Publisher 

Art  Director 

Marketing  Director 

Michael  Madaj 

Clifford  West 

Craig  S.  Harper 

Editor 

Artist 

Advertising  Sales 

Marlin  Ouverson 

Barbara  Ruzgerian 

Janice  Powell 

Contributing  Editors 

Typesetter 

Circulation  Manager 

Dave  Caulkins 

Renny  Wiggins 

Peter  Clark 

Dave  Cortesi 

Proofreader 

Circulation  Assistant 

Business  Manager 

Maureen  Christine 

Nancy  Heubach 

Leah  Dansby 

Editorial 


Computers  and  their  owners  are  at  the  leading  edge  of 
this  information  era.  Whether  they  will  remain  there  long 
enough  for  us  humans  to  more  fully  realize  our  potential  for 
self-determination  depends  upon  several  things. 

First,  the  computer  user  must  know  what  information 
he  requires.  Next  he  needs  to  learn  who  has  it,  how  to  access 
it  and  what  to  do  with  it.  Networking  in  general,  and  com¬ 
puter  bulletin  boards  specifically,  are  moving  toward  the  ful¬ 
fillment  of  personal  computing  power.  This  is  done  by 
making  many  kinds  of  information  available  to  many  people 
who  would  otherwise  not  have  access  to  it  (or  else  it  would 
take  much  longer  periods  of  time  without  computers). 

Dr.  Dobb's  Journal  has  provided  a  simple  list  of  CBBS’s 
for  some  time.  Too  simple  a  list,  actually,  to  be  used  in  the 
efficient  process  outlined  above.  Instead,  the  user  is  forced  to 
browse  through  the  telephone  numbers  as  he  would  through 
books  on  a  bargain  table,  sifting  through  thousands  of  items 
before  finding  one  or  two  that  only  coincidentally  meet  his 
needs. 

Reader  response  has  been  a  great  help  to  us,  with  up¬ 
dates,  deletions,  changed  numbers  and  additions  coming  in 
daily.  But  what  is  the  best  way  to  present  all  these  valuable 
numbers?  One  reader  sent  a  list  of  six  hundred  CBBS’s, 
stating  “. . .  I  can’t  always  keep  every  number  current,  but 


at  least  90%  of  the  numbers  should  work.” 

DDJ  needs  to  know  what  you  need  to  know  about  these 
bulletin  boards  so  we  can  be  of  greater  service  to  you.  Some 
points  might  be:  the  necessity  to  have  a  particular  piece  of 
hardware  or  software  to  use  it;  hours  of  the  day  and  night 
when  it  is  available;  if  it  is  mainly  for  a  special  interest  group; 
the  type(s)  of  information  provided. 

Additionally,  bulletin  board  pros  (and  those  just  testing 
the  water)  can  provide  another  kind  of  assistance.  Because 
much  CBBS  information  changes  rather  often,  it  will  take  a 
lot  of  manpower  to  keep  track  of  it.  If  you  can  monitor  the 
numbers  within  a  given  area  code  on  a  periodic  basis  (say, 
once  a  month),  send  your  name  and  other  pertinent  informa¬ 
tion  to  my  attention  with  a  “CBBS”  on  the  envelope’s  lower 
left-hand  comer. 

Let  us  know  what  you  need.  We’ll  incorporate  that  into 
our  soon-to-be-redesigned  Electric  Phone  Book. 

Marlin  Ouverson 
Editor 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 
184 


Letters 


Analysis  of  an  Analysis 

Sirs: 

I  read  Howard  Whitlock’s  “Analysis 
of  the  Use  of  the  6502’s  Opcodes”  ( DDJ 
#53)  with  considerable  interest,  partly 
because  of  my  own  researches  into  an 
improved  instruction  set,  and  partly  be¬ 
cause  of  my  experience  in  comparing  the 
6800  with  the  6502.  I  think  his  conclu¬ 
sions  are  not  adequately  supported. 

The  power  of  the  6502,  compared  to 
the  6800,  is  indeed  based  on  its  variety 
of  addressing  modes,  including  indirect 
post-indexed.  However,  this  particular 
addressing  mode  on  the  6502  is  only 
powerful  by  comparison  when  applied  to 
the  small  tables  and  data  structures  typi¬ 
cal  of  small  control  applications,  for 
which  the  6502  was  intended.  The  index 
register  is  too  small  to  be  useful  in  large 
applications  like  a  general  purpose  inter¬ 
preter  such  as  Pet  BASIC  might  be, 
except  and  unless  arbitrary  restrictions 
are  placed  on  such  structures  as  string  and 
line  length  (though  this  is  common  in 
BASIC). 

My  6502  Tiny  BASIC  shows  exactly 
the  same  high  incidence  of  this  one  ad¬ 
dress  mode  for  exactly  the  same  two  in¬ 
structions,  namely  LDA  and  ST  A.  I  have 
not  examined  the  code  in  Pet  BASIC,  but 
I  would  guess  that  these  two  instructions 
are  used  the  same  way  there  as  in  my  in¬ 
terpreter,  namely  with  a  constant  zero 
in  Y  (notice  the  very  high  incidence  of 
LDY  —  Howard  does  not  mention  the 
value  of  the  constant  so  loaded:  is  it 
usually  zero?).  The  point  is  that  the  sup¬ 
posed  power  of  the  post -indexed  indirect 
addressing  mode  is  not  used  at  all,  but 
this  happens  to  be  the  only  way  to  simu¬ 
late  in  the  meager  6502  instruction  set 
the  power  of  a  16-bit  index  register. 

This  is  not  to  say  that  the  6502  is 
not  “more  powerful  than  the  6800”  or 
that  post  indirect  indexing  is  useless.  The 
intelligent  programmer  will  use  all  of  the 
tools  (opcodes  and  addressing  modes)  at 
his  disposal  to  get  the  job  done,  and  the 
algorithms  to  do  the  same  job  in  the  6502 
are  necessarily  different  than  in  the  6800. 
For  a  long  time  the  Microsoft  6502 
BASIC  was  the  “fastest”  BASIC  around, 
even  after  normalizing  for  memory  cycle 
time.  I  do  not  know  whether  this  was  be¬ 
cause  the  6502  was  indeed  more  powerful 
than  the  others,  or  if  the  programmer  was 
more  able  to  adapt  his  style  to  its  instruc¬ 
tion  set,  or  if  even  it  was  simply  the  most 
recent  try  so  it  benefitted  from  the  mis¬ 
takes  of  ail  previous  versions.  I  hope  that 


the  new  IEEE  standards  work  on  bench¬ 
marks  will  enable  a  reasoned  and  bal¬ 
anced  analysis  of  the  various  instruction 
sets. 

It  is  interesting  that  the  most  fre¬ 
quent  instruction  in  Pet  BASIC  is  the  JSR 
subroutine  call.  This  tends  to  imply  that 
the  programmer  has  redefined  the  6502 
into  a  virtual  machine  of  his  own  liking, 
whose  opcodes  are  the  JSRs.  I  wonder 
how  many  of  the  subroutines  so  called 
could  be  replaced  by  one  or  two  in-line 
instructions  from  the  Z-80  or  6809  in¬ 
struction  set? 

In  any  case,  a  general  comment  on 
the  utility  of  a  class  of  instructions  is  not 
justified  on  the  basis  of  the  analysis  of  a 
single  program,  especially  one  with  so 
limited  a  scope  as  a  BASIC  interpreter. 
I  suspect  that  a  chess  program  will  show  a 
radically  different  distribution,  because 
the  data  structures  are  more  compatible 
with  the  limitations  of  the  6502  register 
sizes.  A  video  game  might  be  still  differ¬ 
ent  than  either. 

I  recognize  that  Howard’s  analysis  is 
based  on  hard  facts,  and  that  my  criti¬ 
cism  is  largely  based  on  speculation  and 
supposition.  It  may  be  that  his  conclu¬ 
sions  are  true  and  correct.  I  only  claim 
that  not  enough  data  has  been  examined 
to  establish  that  they  are  valid. 

Tom  Pittman 
Itty  Bitty  Computers 
P.  O.  Box  23189 
San  Jose,  CA  95153 

FORTH  Notes 

Dear  Marlin: 

H.  T.  Gordon’s  recent  article  about 
FORTH  {DDJ  #51  and  #52)  have  moti¬ 
vated  me  to  write  in  with  these  com¬ 
ments.  I  received  the  FIG  installation 
manual  and  8080  assembly  language  list¬ 
ing  last  September  and  have  had  a  run¬ 
ning  version  of  FORTH  since  December. 
My  experiences  in  implementing  and 
using  FORTH  make  me  agree  that 
FORTH  “.  .  .  is  a  high-level  assembly  lan¬ 
guage  for  a  virtual  machine.  ...”  I  do  not 
agree,  though,  that  his  machine  “.  .  . 
ought  to  have  a  much  more  powerful  core 
structure  than  it  has.”  The  strength  of 
FORTH  comes  from  the  dictionary  defi¬ 
nition  that  acts  as  a  macro  for  the  high- 
level  assembler.  These  macros  string 
(thread?)  together  the  primitives  of  the 
processor  to  form  what  appear  to  the  user 
as  new  primitives. 

I  feel  that  Dr.  Gordon  has  not  been 
careful  to  distinguish  between  “macros” 


and  “primitives”  in  his  articles  about 
FORTH.  For  example,  Dr.  Gordon  pro¬ 
poses  extensions  of  the  stack  manipula¬ 
tion  instructions  based  upon  the  actions 
of  the  FORTH  primitive  ROT.  This 
primitive,  however,  can  be  defined  in 
terms  of  other  operations  such  as  trans¬ 
fer  between  the  two  FORTH  stacks 
[  >R  R  R>  ]  and  manipulation  of  the 
top  two  items  on  the  stack  [  SWAP  ] . 
Thus,  ROT  becomes  a  higher-level  macro 
given  by  the  colon  definition: 

:  ROT  >R  SWAP  R>  SWAP  ; 
Other  FORTH  words  can  be  defined  in  a 
similar  manner: 

:  DUP  >R  R  R>  ; 

:  OVER  SWAP  >RRSWAPR>  ; 

Of  course,  the  above  definitions  may 
be  implemented  directly  in  the  machine 
code  of  the  target  processor  as  in  the  FIG 
implementation  for  the  8080.  The  choice 
of  a  macro-like  colon  definition  or  ma¬ 
chine  code  depends  upon  the  target  pro¬ 
cessor.  Machine  code  will  take  advantage 
of  particular  features  of  the  target 
processor  and  provide  maximum  speed. 
A  colon  definition  macro,  on  the  other 
hand,  allows  a  very  compact  nucleus  of 
primitive  functions.  The  FIG  implementa¬ 
tion,  for  example,  has  only  about  25%  of 
over  two  hundred  definitions  in  machine 
code  for  the  8080.  FORTH  Inc.  uses  only 
about  512  bytes  of  machine  code  primi¬ 
tives  in  their  4K  polyFORTH  package  as 
described  in  FORTH  Dimensions  Vol.  1, 
No.  4. 

The  proliferation  of  primitives  pro¬ 
posed  to  enhance  the  FORTH  virtual  ma¬ 
chine  runs  counter  to  the  simplicity  in¬ 
herent  in  a  zero- address  machine.  Operat¬ 
ing  only  on  the  values  on  the  stack  allows 
great  simplification  since  the  operands  are 
not  scattered  around  in  memory.  A  multi¬ 
tude  of  addressing  modes  is  therefore  not 
necessary.  In  addition,  a  multitude  of 
registers  is  not  required  since  the  stack 
serves  as  the  general  purpose  accumula¬ 
tor.  These  considerations  are  reflected  in 
the  P-Codes  used  by  Wirth  to  develop  a 
PL/0  compiler  ( Algorithms  +  Data  Struc¬ 
tures  =  Programs,  by  Niklaus  Wirth, 
Prentice- Hall,  1976).  Chung  and  Yuen 
also  give  a  thorough  explanation  of  a 
Zero-address  machine  used  to  implement 
their  “Tiny”  Pascal  compiler  {Byte, 
September-November,  1978).  Both  of 
these  examples  define  machines  with 
simple  memory  reference  instructions,  a 
few  special  purpose  registers,  and  a  few 
conditional  and  unconditional  branch  in¬ 
structions.  The  power  inherent  in  a 


4 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 

185 


simple  zero -address  machine  is  hinted  at 
by  R.  L.  Gulbranson  in  Computer ,  April 
1979  (reprinted  in  FORTH  Dimensions, 
Vol.  1 ,  No.  5). 

The  extensions  suggested  by  Dr. 
Gordon  for  PARFOR  should  in  my  opin¬ 
ion,  be  directed  towards  the  higher  level 
of  FORTH  and  not  at  the  virtual  stack 
machine  level.  I  am  basing  this  on  the 
macro-like  character  of  the  colon  defini¬ 
tions.  Unfortunately,  the  “macro”  de¬ 
fined  by  a  colon  definition  cannot  have 
parameters  that  control  the  macro  expan¬ 
sion.  A  new  defining  word  that  would  al¬ 
low  compile-time  parameters  would  thus 
be  needed  to  achieve  this  end.  An  exten¬ 
sion  at  this  level  would  allow  defining  the 
operations  of  PARFOR  in  terms  of  other 
FORTH  primitives.  Such  an  extension 
would  truly  lead  to  a  parameterized 
FORTH-like  high-level  language  that  re¬ 
tains  all  of  the  FORTH  structure.  The 
basic  core  of  FORTH  would  remain  in¬ 
tact  while  extending  the  language  to  a 
higher  level.  Of  course,  such  a  parameter¬ 
ized  macro-type  defining  word  needs  to 
be  carefully  thought  out  in  more  detail 
than  is  presented  here.  In  addition,  the 
nucleus  of  primitives  necessary  for 
FORTH  has  not  really  been  addressed 
here.  The  512  bytes  used  in  polyFORTH 
probably  defines  the  minimum  for  the 
core;  however,  thought  needs  to  be  given 
here  to  the  tradeoffs  of  having  a  larger 
core  of  primitives  in  the  code  of  the 
target  machine. 

G.  Wayne  Smith 
7413  S.  Woodward 
Woodridge,  IL 

Bullet  Proofing  for  Everyone 

Dear  Marlin, 

I  feel  Gene  Head  missed  the  point 
of  having  an  A  (for  Assemble)  command 
in  a  debugger,  in  his  review  of  ZDM  in  the 
February  issue  of  Dr.  Dobb’s. 

An  in-line  assembler  is  not  only  a 
“hot  patcher”  using  mnemonics,  it  can  be 
a  useful  development  tool  in  its  own 
right.  Short  subroutines  can  often  be 
quickly  keyed  in  using  mnemonics  and 
executed  immediately  in  Trace  mode  to 
ensure  correct  operation.  Also  an  in-line 
assembler  can  be  very  useful  for  small 
throwaway  routines.  For  example,  the 
Monow  Disk  Jockey  disk  controller  uses 
an  inverted  internal  data  bus  —  recently 
I  needed  to  make  a  small  modification 
to  the  contents  of  the  firmware  ROM. 
The  data  read  in  from  the  ROM  (which 
by  the  way  is  different  from  the  listing 


supplied  in  the  Disk  Jockey  documenta¬ 
tion)  was  complemented,  so  a  short  in¬ 
line  assembler  routine  was  located  in  a 
vacant  area  of  memory  to  invert  the  data 
read  from  the  ROM  so  that  I  could  check 
it  with  the  in-line  disassembler.  It  took 
perhaps  two  minutes  to  key  AND  execute 
the  routine,  had  I  been  forced  to  use  a 
text  editor  to  generate  an  assembler 
source,  run  the  source  through  the  assem¬ 
bler,  load  the  hex  output  of  the  assembler 
and  then  execute  the  object  program  it 
would  have  taken  at  least  8  to  10 
minutes;  all  for  a  program  I’ll  probably 
only  ever  use  once! 

As  a  programmer  who  tries  to  take 
care  over  documenting  programs  I  can 
only  despair  at  Gene’s  “I  didn’t  even 
bother  to  read  the  manual.”  No  matter 
how  friendly  a  program  is  made  in  terms 
of  user  prompting,  there  are  ALWAYS 
some  aspects  that  can  only  be  made  clear 
in  external  documentation.  While  I  guess 
we  should  all  try  to  write  bullet  proof 
programs,  it’s  certainly  discouraging  to 
think  that  the  bullet  proofing  isn’t  only 
there  for  the  inexperienced  users.  Let’s 
encourage  end  users  to  thoroughly  read 
all  documentation  before  attempting  to 
execute  any  program ! ! ! ! 

It  was  disappointing  to  see  that  a 
new  product  like  ZDM  is  still  using  the 
TDL  mnemonics  for  Z80  code.  At  pre¬ 
sent  there  are  4  sets  of  Z80  mnemonics  in 
use:  Zilog,  TDL/XIT AN/PSA,  Digital  Re¬ 
search  (Z80Lib)  and  Intersystems.  The 
dismaying  part  is  that  the  last  3  are  all 
supposedly  extensions  of  the  Intel  8080 
mnemonics  to  “logically”  cover  the  Z80, 
yet  all  are  different.  While  the  Zilog 
mnemonics  aren’t  perfect,  it  IS  possible 
to  use  them  quite  successfully  and  they 
are  the  prime  manufacturer’s  recommen¬ 
dation.  Microsoft’s  M80  will  assemble 
Zilog  mnemonics,  their  L80  will  generate 
a  symbol  table  that  Digital  Research’s 
ZSID  can  use  for  symbolic  debugging  — 
all  the  basic  elements  for  developing 
machine  language  programs  using  Zilog 
mnemonics  are  now  READILY  available 
in  the  marketplace.  New  Z80  software 
should  be  using  Zilog  mnemonics,  not 
mnemonics  sets  from  companies  long  out 
of  business. 

Dr.  Dobb’s  keeps  getting  better  all 
the  time,  keep  up  the  good  work! 

Bill  Bolton 

Software  Tools 

P.  0.  Box  80 


Newport  Beach 
NSW,  2106 
Australia 

Of  Words  and  Cardboard 

Dear  DDJ: 

Readers  interested  in  Caulkin’s  arti¬ 
cle  in  DDJ  #53  (“Computer  Based  High 
Speed  Reading”)  can  use  ED  and  PIP  in 
the  CP/M  system  to  obtain  essentially 
the  same  results  without  additional  pro¬ 
gramming  of  any  kind.  Although  the 
speed  of  single  word  presentation  is  not 
continuously  variable,  it  can  be  readily 
changed.  Very  high  speeds  (depending  on 
available  terminal)  may  be  achieved. 

The  CP/M  user  will  require  a  video 
terminal  which  clears  and  homes  the 
cursor  when  receiving  a  form -feed  (such 
as  Intertec  and  others).  First,  edit  any 
existing  text  file: 

A >  ED  FILE.TXT  (t  Z  is  control-Z, 
etc.) 

*#A  (for  simplicity,  as¬ 

sume  it  fits  in 
memory) 

*Ib  t  Z  (insert  initial  blank) 

[note:  b=blank] 
*#StItZbtZ  (change  all  tabs  to 

blanks) 

*B#StLtZbtZ  (change  all  line-feeds 

to  blanks) 

(Continued  on  page  45) 


6 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


Using  (and  Misusing) 
the  Z-80  Microprocessor 


E 

-M^Jver  since  its  introduction,  the  Zilog  Z-80  microprocessor 
aas  had  an  aura  of  glamor  and  power  compared  to  the  work¬ 
horse  Intel  8080  or  8085.  This  reputation  is  justified  to  some 
extent  by  the  additional  instructions,  registers,  addressing 
modes,  and  vectored  interrupt  capabilities  of  the  Z-80.  How¬ 
ever,  unless  the  additional  Z-80  instructions  are  employed  very 
carefully,  they  may  cause  a  definite  decrease  in  performance 
compared  to  using  the  8080  instruction  set  alone  (assuming  the 
same  machine  speed,  of  course).  In  particular,  indiscriminate 
use  of  the  index  registers  can  lead  to  severe  speed  and  memory 
requirement  penalties.  In  this  brief  communication  I  will  try  to 
point  out  some  “good”  and  “bad”  examples  of  Z-80  coding. 
Zilog  mnemonics  will  be  used  throughout  for  clarity.  All  execu¬ 
tion  times  assume  a  4  mHz  system  clock,  and  are  obtained  from 
the  specifications  published  by  Zilog,  Inc. 

Observe  the  following  common  example  of  an  “indirect” 
16 -bit  fetch  from  memory  to  register  BC,  using  the  contents 
of  a  named  variable  for  the  target  address: 


8080 

version 

bytes 

microseconds 

LD 

HL, (label) 

3 

4.00 

LD 

C,(HL) 

1 

1.75 

INC 

HL 

1 

1.50 

LD 

B,(HL) 

1 

1.75 

6 

9.00 

Z-80 

version 

bytes 

microseconds 

LD 

IX, (label) 

4 

5.00 

LD 

C,(IX) 

3 

4.75 

LD 

B,(IX+1) 

3 

4.75 

10 

14.50 

The  Z-80  oriented  code  looks  much  neater,  but  causes  an  ap¬ 
proximately  60%  increase  in  both  execution  time  and  memory 
requirements. 

How  about  an  indirect  increment  of  a  counter  in  memory? 


8080  version 

bytes 

microseconds 

INC 

(HL) 

1 

2.75 

Z-80  version 

bytes 

microseconds 

INC 

(IX)  or  (IY) 

3 

5.75 

Using  the  index  in  this  case  causes  more  than  doubling  of  exe¬ 
cuting  time  and  memory  requirements! 

Your  use  of  the  index  registers  also  causes  penalties  when 
subroutines  must  save  and  restore  them: 

8080  version  bytes  microseconds 

PUSH  BCorDEqrHL  1  2.75 

POP  BC  or  DE  or  HL  1  2.50 


by  Ray  Duncan 


Ray  Duncan,  Laboratory  Microsystems,  4147  Beethoven  Street, 
Los  Angeles,  CA  90066. 


Z-80  version  bytes  microseconds 

PUSH  IX  or  IY  2  3.75 

POP  IX  or  IY  2  3.50 

One  would  imagine  that  the  index  registers  would' be  well 
suited  to  table  translations  by  incrementing  the  index  to  com¬ 
pare  bytes  through  one  table  until  a  match  was  found,  then  ex¬ 
ploiting  the  indexed  offset  addressing  mode  to  extract  a  corre¬ 
sponding  byte  from- another  table.  Yet  in  the  simpler  cases  at 
least,  the  overhead  of  the  index  registers  again  outweighs  the 
cleanness  of  the  assembler  code.  For  example: 


8080 

version 

bytes 

microseconds 

CP 

A,(HL) 

1 

1.75 

JP 

NZ, nomatch 

3 

2.50 

LD 

DE, offset 

3 

2.50 

ADD 

HL,DE 

1 

2.75 

LD 

A,(HL) 

1 

1.75 

9 

11.75 

Z-80 

version 

bytes 

microseconds 

CP 

A, (IX) 

3 

4.75 

JP 

NZ, nomatch 

3 

2.50 

LD 

A,(IX+offset) 

3 

4.75 

9 

12.00 

What  about  the  relative  jump  (JR)?  Many  programmers 
new  to  the  Z-80  observe  that  the  unconditional  JR  instruction 
occupies  only  two  bytes  compared  to  the  three  required  by  the 
absolute  jump  (JP),  and  quickly  set  about  editing  all  their  tight 
little  time-dependent  loops  to  incorporate  this  neat  looking 
mnemonic.  Surprise  —  the  JR  instruction  takes  3  microseconds 
to  execute,  compared  to  2.50  microseconds  for  JP,  an  increase 
of  about  20%  in  execution  time.  Now  that  we  have  excellent 
relocating  assemblers  available,  use  of  unconditional  JR  should 
probably  be  avoided.  On  the  other  hand,  the  conditional  relative 
jump  gives  a  slight  advantage  in  execution  time  (1.75  micro¬ 
seconds  false  case,  3.00  microseconds  true  case)  over  the'  condi¬ 
tional  absolute  jump  (always  2.50  microseconds),  as  long  as  the 
branch  condition  is  not  met  over  50%  of  the  time. 

Naturally,  the  Z-80  would  never  have  become  so  popular 
unless  there  were  significant  hardware  and  software  advantages 
to  its  use.  Careful  study  of  the  code  set  reveals  a  number  of  in¬ 
stances  where  use  of  the  Z-80  instructions  and  registers  can 
yield  striking  improvements  in  execution  time  and  memory  re¬ 
quirements. 

Consider  an  entry  to  a  subroutine  where  all  registers  will  be 
needed  for  working  storage  yet  the  main  program  requires  that 
the  contents  of  all  registers  be  unchanged  at  the  end  of  the  call. 
The  8080  requires  that  everything  be  pushed  onto  the  stack  and 
later  restored,  but  the  Z-80  allows  you  to  swap  with  the  alter¬ 
nate  register  set  for  a  dramatic  increase  in  speed : 

8080  version  bytes  microseconds 


PUSH  BC  1  2.75 

PUSH  DE  1  2.75 

PUSH  HL  1  2.75 

(subroutine  body) 

POP  HL  1  2.50 

POP  DE  1  2.50 

POP  BC  1  2.50 


6  15.75 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


7 

187 


Z-80  version 

bytes 

microseconds 

EXX 

1 

1.00 

(subroutine  body) 

EXX 

1 

1.00 

2 

2.00 

The  augmented  sixteen-bit  arithmetic  capabilities  of  the 
Z-80  are  a  godsend  both  for  the  sake  of  performance  and  clarity 
of  program  code.  For  example,  subtracting  DE  from  HL,  leaving 
the  result  in  HL: 


8080  version 

bytes 

microseconds 

LD 

A,L 

1 

1.00 

SUB 

A,E 

1 

1.00 

LD 

L,A 

1 

1.00 

LD 

A,H 

1 

1.00 

SBC 

A,D 

1 

1.00 

LD 

H,A 

1 

1.00 

6 

6.00 

Z-80  version  bytes  microseconds 

LDIR  2  5.25  per 

byte  transferred 

The  corresponding  compare  with  auto -increment  instructions  is 
more  difficult  to  use  effectively,  but  can  be  exploited  with  good 
results  in  table  lookup  routines. 

The  point  of  this  little  demonstration  was  that  the  Z-80  is 
indeed  a  powerful  processor,  but  the  proper  use  of  its  many 
added  capabilities  in  a  time-dependent  application  requires  an 
intimate  knowledge  of  the  instruction  set  at  the  machine  level. 
The  very  elegant  Zilog  mnemonics,  which  tremendously  im¬ 
prove  the  understandability  of  an  assembly  listing  compared  to 
the  Intel  mnemonics,  blur  the  machine-level  code  distinctions 
for  a  new  programmer,  since  they  make  all  register- memory  and 
register- register  operations  appear  very  similar.  I  hope  that 
other  readers  will  be  provoked  into  contributing  other  examples 
of  “bad”  and  “good”  uses  of  the  Z-80.  B  ■ 


Z-80  version  bytes  microseconds 

SBC  HL,DE  2  3.75 

(This  assumes  that  the  status  of  the  carry  flag  is  known,  other¬ 
wise  it  must  be  turned  off  with  a  preceding  OR  A, A  instruction 
which  wastes  some  time.) 

The  additional  direct  register  load  and  store  instructions  of 
the  Z-80  are  both  handy  and  speedy.  Contrast  the  task  of  get¬ 
ting  a  16-byte  quantity  from  memory  into  the  BC  register: 


8080  version 

bytes 

microseconds 

PUSH  HL 

1 

2.75 

LD  HL, (label) 

3 

4.00 

LD  B,H 

1 

1.00 

LD  C,L 

1 

1.00 

POP  HL 

1 

2.50 

7 

11.25 

Z-80  version 

bytes 

microseconds 

LD  BC, (label) 

4 

5.00 

The  Z-80  has  a  string  move  instruction,  as  everyone  knows, 

which  is  practically  worth  the  price  of  the  chip  itself.  If  one  sets 
up  HL  with  the  source  address,  DE  with  the  destination  address, 
and  BC  with  the  number  of  bytes  to  transfer: 

8080  version 

bytes 

microseconds 

LOOP.  LD 

A,(HL) 

1 

1.75 

LD 

(DE),A 

1 

1.75 

INC 

HL 

1 

1.50 

INC 

DE 

1 

1.50 

DEC 

BC 

1 

1.50 

LD 

A,B 

1 

1.00 

OR 

A,C 

1 

1.00 

JP 

NZ.LOOP 

3 

2.50 

10 

12.50  per  loop 

You  Read  Dr.  Dobb’s  Journal 
And  You  Don’t  Subscribe?! 

Save  $13  off  newsstand  prices  for  2  yrs. 
Save  $5  for  1  yr. 

Can  you  afford  to  miss  an  issue  with  information  vital 
to  your  interests?  As  a  subscriber  you  can  look  for¬ 
ward  to  articles  on  Small-C,  FORTH,  CP/M,  S- 100, 
Compiler  optimization,  Concurrent  Programming  and 
more,  delivered  right  to  your  door.  And  you’ll  never 
miss  the  issue  that  covers  your  project. 

DR.  DOBB’S  JOURNAL 
P.O.  Box  E 

Menlo  Park,  CA  94025 

Yes!  Sign  me  up  for  _ 2  yrs.  $47  _ 1  yr.  $25 

_  I  enclose  a  check/money  order 

_  Charge  my  Visa,  MasterCard,  American  Express 

_  Please  bill  me  later 

Name  _ 

Address  _ _ _ 


Credit  Card . 
Acct  No.  _ 
Signature  _ 


Exp.  date 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 
188 


9 


A  Smart  2716 
EPROM  Programmer 


M 

X  ▼  ost  of  us  reach  a  stage  where  it 
seems  ludicrous  to  use  our  home  comput¬ 
er  system  with  64K  of  RAM  and  dual 
floppy  disk  drives  to  control  the  lawn 
sprinklers.  Many  such  applications  can 
best  be  served  by  small  dedicated  micro¬ 
computer  systems.  The  industrial  and 
commercial  electronics  companies  enjoy 
the  luxury  of  purchasing  single  board 
microcomputers  from  Intel,  National 
Semiconductor,  Pro-log  and  others.  Un¬ 
fortunately,  these  boards  are  priced  at 
$350  and  up,  a  prohibitive  cost  for  all  ex¬ 
cept  the  most  avid  (read  fanatic)  micro¬ 
computer  enthusiast. 

Miller  Technology  has  recently  intro¬ 
duced  the  M-80  single  board  microcom¬ 
puter,  priced  in  kit  form  as  low  as  $69  — 
see  inset. 

A  2716  Programmer 

Although  the  application  of  a  com¬ 
puter  like  the  M-80  is  limited  only  by 
your  imagination,  I  used  it  to  build  a 
2716  EPROM  programmer  for  less  than 
$150. 

EPROMs  may  be  programmed  using 
data  that  was  copied  from  another  ROM, 
by  data  obtained  from  downloading  from 
a  computer  or  development  system,  or 
from  manual  entry  byte  by  byte.  The 
EPROM  can  be  checked  for  full  erasure, 
and  can  be  verified  to  ensure  the  success 
of  the  programming.  Contents  of  the 
EPROM  or  on-board  RAM  may  be 
dumped  to  the  terminal,  and  checksums 
generated.  Checksums  of  EPROM  con¬ 
tents  are  handy  for  microcomputer  sys¬ 
tems  performing  self- testing  functions. 
All  communications  to  the  programmer 
are  via  a  serial  RS-232  data  link. 

Programmer  Hardware 

The  2716  is  a  single  supply  2K  by  8 
EPROM.  Erasure  is  accomplished  by  ex¬ 
posing  the  die  to  UV  light.  Programming 
is  done  by  pulsing  pin  18  at  TTL  levels 
for  50  milliseconds  while  +25  volts  is  ap¬ 
plied  at  pin  21. 

Figure  1  shows  the  2716  pinout. 
Lines  Oo  through  0^  are  the  data  outputs, 
and  Ao  through  A)0  are  for  addressing 
the  contents  of  the  EPROM.  Vcc  is  5 
volts  plus  or  minus  5%,  and  Vpp  must  be 
brought  to  +25  volts,  plus  or  minus  1 


by  Eric  M.  Miller 


volt,  for  programming.  Pins  18  and  20 
select  the  chip  and  enable  the  data  out¬ 
puts  respectively. 

Three  2716  modes  of  operation  are 
used  by  the  programmer.  The  READ 
mode  is  used  for  copying  the  EPROM 
contents  into  RAM,  generating  check¬ 
sums,  verifying  programming,  checking 
erasure,  and  dumping  contents  of  the 
EPROM  to  the  terminal.  The  PROGRAM 
mode  is  used  only  for  entering  data  into 
the  EPROM.  The  PROGRAM  VERIFY 
mode  is  used  for  verifying  that  the  pro¬ 
gramming  was  successful  immediately 
after  programming.  These  three  modes 
and  the  proper  pin  conditions  are  summa¬ 
rized  in  Figure  1. 

Generating  Vpp 

The  only  non-TTL  signal  level  need¬ 
ed  is  +25  volts  for  programming.  This 
voltage,  which  might  otherwise  need  a 
special  power  supply,  can  be  generated  by 
a  simple  DC  to  DC  converter,  along  with 
the  remainder  of  the  electronics  for  the 
programmer.  U3  is  the  ubiquitous  555 
timer.  The  555  produces  1 7  volt  pulses  at 
pin  3  which  are  stepped  up  by  voltage 
double  Dl,  D2  and  Cl,  C2.  Regulation 
at  the  +25  volt  level  is  maintained 
through  feedback  resistors  R3  and  R4  by 
varying  both  frequency  and  pulse.  Load 
regulation  is  better  than  0.16%  from  no 
load  to  45  milliamperes. 

Programming  a  location  of  the  2716  is 
done  by  pulsing  the  CEline  for  50  milli¬ 
seconds  while  Vpp  is  held  at  +25  volts. 
There  is  a  secondary  requirement  that  the 
address  and  data  lines  be  stable  for  2 
microseconds  before  the  application  of 
the  programming  pulse.  Section  one  of 
dual  one  shot  U2  gives  a  5  microsecond 
delay  for  the  address  and  data  setup 
times.  It  also  pulls  the  wait  line  low  to 
preserve  the  status  of  the  address  and 
data  buses.  The  second  section  of  U2, 
triggered  after  the  5  microsecond  time¬ 
out,  produces  the  50  millisecond  pro¬ 
gramming  pulse.  For  programming  to 
occur,  both  a  manual  enable  via  the  PRO¬ 
GRAM  switch  and  a  software  enable  by 
one  of  the  I/O  bits  must  be  true  to  allow 
a  programming  pulse  to  appear.  This 
makes  it  a  little  more  difficult  to  acci¬ 
dentally  program  an  EPROM.  The 
EPROM  is  located  B000  to  B7FF,  and 
from  a  software  point  of  view,  program¬ 
ming  is  as  simple  as  writing  to  those  loca¬ 
tions.  Program  switch  status  is  sensed  by 
bit  1  of  Port  A,  and  software  program¬ 
ming  enable  is  by  bits  0  and  2  of  Port  A. 


The  INSERT/ RUN  switch  removes  pro¬ 
gram  power  from  Vpp  of  the  2716  and 
halts  the  Z-80  during  the  insertion  or  re¬ 
moval  of  a  2716  from  the  zero  insertion 
force  socket.  27 1 6’s  may  be  damaged  by 
applying  +25  volts  to  Vpp  before  Vcc  is 
present. 

Communications  with  the  outside 
world  are  via  a  serial  RS-232  link.  Bits  4 
and  5  of  Port  B  perform  serial  I/O  by  a 
software  UART. 

Programmer  Software 

Once  the  hardware  is  in  place,  an 
EPROM  can  be  loaded  in  its  entirety  by 
a  sequence  like  this: 

LXI  D,0B000H  ;DE  -+  EPROM 

LXI  H,data  address 

LXI  B,2048 

followed  by  a  single  Z80  LDIR  instruc¬ 
tion!  Of  course,  those  instructions  must 
be  preceded  by  a  routine  that  tests  the 
program -enable  switch,  setting  Port  A  bit 
0  true  when  the  switch  is  operated.  I’ve 
expanded  that  simple  idea  with  a  number 
of  commands  to  accept  data  from  a  ter¬ 
minal,  to  verify  the  EPROM  after  it’s 
been  programmed,  and  so  forth.  Any 
reader  wanting  to  build  this  circuit  may 
write  to  me,  enclosing  $1.50  for  copying 
costs,  and  I’ll  send  a  hard  copy  of  the 
complete  program. 

Construction 

Building  the  basic  M-80  takes  no 
longer  than  a  half-hour.  Sockets  and  the 
few  discrete  components  are  quickly 
soldered  into  the  board.  The  point  to 
point  wiring  of  the  additional  circuitry 
for  the  programmer  takes  about  two 
hours. 

A  Textool  zero  insertion  force  socket 
is  used  for  the  2716  EPROMs.  A  mother- 
daughter  socket  approach  is  used,  since 
ZIF  sockets  do  eventually  wear  out.  The 
mother  socket  is  soldered  directly  to  the 
M-80  board.  The  daughter  socket  consists 
of  the  ZIF  socket  soldered  to  two  headers 
and  plugs  into  the  mother  socket.  The 
two  headers  provide  the  correct  height 
for  the  ZIF  socket  when  the  M-80  board 
is  attached  behind  the  front  surface  of 
the  enclosure. 

A  PS-80  power  supply  is  mounted 
to  the  base  of  the  -enclosure  and  pro¬ 
vides  the  regulated  voltages  for  the  pro¬ 
grammer.  1 15  VAC  line  voltage  is  con¬ 
verted  to  +5  at  800  milliamperes,  +12  at 
150  milliamperes,  -5  and  -12  at  150  mil¬ 
liamperes.  In  this  application,  the -5  sup¬ 
ply  was  not  used.  The  PS-80  also  has  an 


10 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 

189 


on-board  fuse  for  the  incoming  1 15  VAC, 
and  a  connector  for  easy  wiring  to  a 
power  switch  and  AC  power. 

Modifications 

Customizing  the  programmer  for 
your  particular  needs  can  most  likely  be 
taken  care  of  with  software  changes 
alone.  Programming  a  selected  byte  or 
portion  of  an  EPROM  may  be  accom¬ 
plished  by  enabling  programming  by  the 
program  switch,  setting  Port  A  bit  2  to  a 
0,  Port  A  bit  0  to  an  input,  and  perform¬ 
ing  a  memory  write  to  the  desired  loca¬ 
tion  with  the  data  byte  to  be  pro¬ 
grammed. 

Stand-alone  operation  for  use  of  the 
programmer  as  a  2716  copier  can  be  ac¬ 
commodated  without  the  use  of  terminal 
or  host  computer.  The  necessary  switches 
or  pushbuttons  may  be  added  to  the  en¬ 
closure  and  sensed  by  a  few  of  the  input 
bits.  LEDs  could  display  status,  such 
as  “Programming  Complete”,  and  be 
driven  by  the  output  bits. 

Multiple  2716s  may  be  programmed 
simultaneously  by  simply  paralleling 


A7C 

- W - 

1 

□  VCC 

A6  C 

I]  A8 

A5  C 

□  A9 

A4  C 

□  VPP 

A3C 

□  OE 

A2C 

□  A10 

A1  C 

□  CE 

AO  C 

Cl  07 

ooc 

□  06 

Ole 

d  05 

02C 

d  04 

GNDC 

□  03 

2716 


PINS 


CE / PGM 

OE 

Vpp 

READ 

0 

+5 

PROGRAM 

Pulsed  0  to  1 

1 

+25 

PROGRAM 

VERIFY 

0 

D 

Figure  1 . 2716  pinout  and  mode  selection. 


them.  Verifying  each  2716  would,  how¬ 
ever,  mean  separately  driving  each  OE 
line.  Four  output  bits,  along  with  a 
74  LS32  quad  or  gate  could  control  four 
2716s  by  OR-ing  the  present  OE  line 
with  an  output  bit.  Setting  an  output  to 
zero  would  enable  that  particular  2716. 
Complete  software  operation  of  the  pro¬ 


grammer  would  require  a  reed  relay, 
driven  by  one  of  the  output  bits,  to  con¬ 
trol  the  +25  volt  supply  to  Vpp. 

Conclusion 

There  are  many  other  instances  in 
which  the  application  of  inexpensive  in¬ 
telligence  via  single  board  microcomput¬ 
ers  can  be  useful.  Bus-oriented  microcom¬ 
puter  systems  with  mass  storage  and  a 
multiplicity  of  peripherals  cannot  address 
the  convenience  and  economy  necessary 
for  dedicated  control  and  processing  situ¬ 
ations.  The  M-80  single  board  microcom¬ 
puter  provides  the  needed  computing 
power,  versatility,  and  compact  size  at  a 
low  cost.  ■■ 


Miller  Technology  products  are  distributed 
by  Quest  Electronics,  2322  Walsh  Ave.,  Santa 
Clara,  CA  95051.  The  M-80  contains  a  Z80 
CPU,  sockets  for  2K  of  2708  EPROM  and  2.1K 
of  RAM,  16  I/O  lines  and  a  system  clock.  Bare 
board  prices  $28.50.  Minimum  kit  (128  bytes 
RAM)  $69.  Full  kit  (2176  bytes  RAM)  $99. 
Fully  assembled  and  tested  $185.  Monitor 
ROM  $20.  Tiny  BASIC  ROM  $30.  Power  sup¬ 
ply  kit  $35,  assembled  and  tested  $60. 


Even  if  you  have  never  been  published  before, 
Dr.  Dobb’s  wants 
to  see  your  good  computing  ideas. 
Contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)  323-3111 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 
190 


11 


Of  Interest 


by  Dave  Cortesi 


i^t  must  have  been  a  slow  month  at 
the  ad  agencies;  the  press  release  heap  is 
fairly  small.  Even  so  there  are  several 
items  you  might  like  to  know  about. 
Let’s  begin  with  two  conferences,  one 
popular  and  the  other  esoteric. 

Two  Conferences 

The  Personal  Computer  Arts  Festival 

is  to  be  held  in  conjunction  with  Personal 
Computing  81,  the  big  Philadelphia  show 
scheduled  for  August.  We  haven’t  seen 
anything  on  the  parent  show  as  yet,  but 
the  Arts  Festival  Committee  is  on  the  ball 
with  an  early  announcement.  They  want 
anyone  working  in  digital  art  or  music  to 
participate  with  a  talk,  an  exhibit,  or  a 
performance.  If  you  want  to  take  part 
you  should  send  a  short  description  of 
your  presentation  to  them  by  July  1st. 
Include  tapes  or  slides  if  possible;  return 
is  promised.  If  you  want  to  be  listed  in 
the  resource  guide  they’re  assembling, 
get  your  entry  to  them  by  June  1st. 

Readers  who  are  into  robotics  might 
want  to  investigate  the  Tenth  Annual 
Symposium  on  Incremental  Motion  Con¬ 
trol  Systems  (IMCSS)  to  be  held  in 
Rosemont  IL  June  1-4.  Experts  from 
many  countries  will  talk  about  all  sorts  of 
stepping  motors  and  their  microprocessor 
controllers. 

The  Contest  Is  Still  Open 

One  or  two  readers  may  have  been  in 
a  submarine  (or  much  the  same  thing,  a 
university  computer  center)  for  the  past 
couple  of  months  and  so  won’t  know 
about  the  national  competition  in  person¬ 
al  computer  aids  for  the  handicapped. 
The  competition  is  being  run  by  John 
Hopkins  University  and  is  co-sponsored 
by  Radio  Shack.  There’s  a  $10,000  grand 
prize,  a  bunch  of  computers,  and  a  lot 
of  glory  up  for  grabs.  Information  and  en¬ 
try  forms  should  be  available  at  any 
Radio  Shack  store,  but  hurry  because  the 
contest  closes  June  30th. 

Elicon  Goes  FORTH  to  an  Oscar 

The  Elicon  company  sent  us  a  brag 
on  their  motion- control  system,  which  as 
part  of  their  Camera  Control  System  for 
movie  special  effects  received  an  Acade¬ 
my  Award  nomination  for  technical 
achievement.  What  caught  our  interest 
was  that  the  programming  for  the  sys¬ 
tem  was  done  entirely  in  FORTH.  Elicon 
credits  the  language  with  easing  design 


and  lowering  costs. 

While  we  have  the  attention  of 
FORTH  fans,  we’U  pass  on  the  FORTH 
Interest  Group’s  claim  that  they  now 
have  over  2500  members.  That  doesn’t 
mean  that  they’re  satisfied,  of  course. 
They  want  even  more  (at  $12  a  year)  and 
have  lots  of  pubs  and  cheap  code  to  at¬ 
tract  them  with. 

APLers  Need  Love,  Too 

Members  of  the  class  of  applicative 
languages  seem  to  engender  strong  loyal¬ 
ties  in  the  breasts  of  their  users.  There 
are  FORTH  fans,  of  course  and  LISP 
lovers,  and  APL  fanatics.  The  latter  are 
deprived  in  that  an  efficient  interpreter  is 
too  complex  a  beast  for  a  really  satisfac¬ 
tory  implementation  on  present  micros, 
although  we  have  hopes  for  the  new 
16-bit  machines.  While  they’re  waiting, 
frustrated  APLers  might  pass  the  time 
with  the  APL  Market  Newsletter,  a  small 
quarterly  which  reports  on  new  imple¬ 
mentations  and  applications.  It  costs  $8 
a  year.  The  latest  issue  predicts  that 
Microsoft’s  version  of  Unix  will  have 
APL,  and  reports  that  Softworks  Limited 
has  an  APL  for  Alpha  Micro  systems. 

The  Software  Market  Served 

The  chaotic  state  of  the  software 
marketplace  is  drawing  the  attention  of  a 
number  of  publishers.  Software  News,  a 
new  monthly  tabloid,  will  commence 
publication  in  May  1981  to  “fill  the  in¬ 
dustry’s  compelling  need  for  a  newspaper 
devoted  exclusively  to  software.”  We 
wish  them  well  in  a  challenging  task. 

Micro -Serve  writes  to  announce  the 
fourth  edition  of  their  Software  Vendor 
Directory.  It  claims  to  list  over  4000 
products  from  over  1000  vendors,  in¬ 
dexed  by  hardware  and  application  type. 
They  sell  it  two  ways:  as  a  book  for 
$57.95,  and  as  a  CP/M -compatible  disk¬ 
ette,  with  a  search  program,  for  $78. 
Semi-annual  updates  are  $25. 

OK,  Who  Is  Who? 

An  organization  called  Altemet  pro¬ 
duces  a  Community  Computerist's  Direc¬ 
tory,  which  they  rather  grandiosely  bill  as 
“the  Who’s  Who  of  people  and  comput¬ 
ers.”  It  appears  to  contain  entries  (writ¬ 
ten  by  the  subjects)  for  just  about  any 
person  or  organization  that  relates  to 
computers  in  any  way.  Buy  the  book  for 
$4,  or  list  yourself  in  it  for  $5. 


What’s  in  a  Name? 

Carl  Helmers,  the  well-known  fellow 
who  recently  stepped  down  from  the 
editorship  of  Byte,  notifies  us  that  he  is 
commencing  a  personal  newsletter,  the 
Carl  Helmers  Personal  Computer  Letter. 
It  will  be  published  by  North  American 
Technology.  Carl  expects  the  newsletter 
to  provide  you  with  “a  valuable  and  per¬ 
ceptive  perspective  on  the  field  of  person¬ 
al  computing.”  We  can’t  believe  an  exper¬ 
ienced  editor  wrote  that  sentence.  Re¬ 
gardless,  you  can  become  a  charter  sub¬ 
scriber  for  just,  urn,  200  dollars.  Now  you 
know  what’s  in  a  name. 

Pubs  Potpourri 

Tab  Books  have  sent  us  a  wad  of 
book  flyers,  and  several  of  the  books  look 
good.  Here  are  the  titles  that  turned  us 
on,  with  the  paperback  price  and  order 
number  in  parentheses:  33  Challenging 
Computer  Games  for  TRS-80,  Apple,  and 
PET,  D.  Chance  ($7.95,  1275);  Program¬ 
mer’s  Guide  to  LISP,  K.  Tracton  ($6.95, 
1045);  The  MC6809  Cookbook,  C.  D. 
Warren  ($6.95,  1209);  Microcomputer  In¬ 
terfacing  Handbook:  A/D  and  D/A,  J.  J. 
Carr  ($8.95,  1271);  The  PLL  Synthesizer 
Cookbook,  H.  Kinley  ($7.95,  1243).  We 
take  pleasure  in  noting  Tab’s  resistance  to 
the  current  practice  of  charging  10  cents 
a  page  and  up  for  technical  paperbacks. 

Software  For  All 

There  weren’t  very  many  software 
announcements  this  month,  but  those 
that  came  were  nicely  spread  over  a  num¬ 
ber  of  systems.  Phase  One  Systems  wrote 
that  they  now  have  OASIS  device  drivers 
for  the  Corvus  hard  disks.  Phase  One  also 
sent  us  a  copy  of  their  new  OASIS  refer¬ 
ence  card.  It  looks  useful  and  costs  a 
buck. 

The  lone  CP/M  entrant  comes  from 
Softronics.  It  tells  of  DATABS,  a  data  ab¬ 
straction  language  derived  form  the  CLU 
language  (CLU  was  one  of  the  first  struc¬ 
tured  systems  programming  languages;  it 
made  a  few  waves  in  computer  science 
circles  some  years  back).  The  release  is 
not  awfully  specific  about  DATABS,  so 
we  can’t  be  sure  just  what  they  mean  by 
“data  abstraction,”  but  the  usual  idea  is 
that  you  declare  not  only  the  arrange¬ 
ment  of  a  data  type  as  in  Pascal,  but  the 
operators  that  will  work  upon  that  type 
as  well.  At  any  rate,  the  price  of  $49.95 
for  compiler  and  run-time  library  is  low 
enough.  Language  freaks  might  want  to 


12 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 

191 


check  it  out. 

Users  of  Pascal,  whether  it  be  Pascal/ 
M  or  UCSD  on  an  Apple,  may  like  to 
know  that  HDP  has  three  software  tools 
for  sale.  The  first  is  a  Screen  Handler 
($75);  you  describe  a  screen  layout  in  a 
file  and  the  Handler  takes  care  of  format¬ 
ting  the  screen.  The  Output  Formatter 
($37.50)  does  something  similar  for  print¬ 
ed  reports.  The  Forms  Generator  ($50)  is 
a  superset  of  the  latter.  With  it,  the  pro¬ 
grammer  sets  things  up  and  thereafter  the 
non- programming  user  can  choose  and 
run  his  own  output  format. 

TSC  tells  us  of  their  new  sort -merge 
package  for  UniFLEX  systems.  The  sort 
is  written  in  6809  machine  language;  it 
claims  to  handle  any  size  and  format  of 
input  file,  sort  on  20  keys  of  up  to  250 
bytes  each,  and  allow  for  record  selection 
or  exclusion.  The  package  costs  $100. 

The  Electronic  Typing  package  for 
Zenith  and  Heath  Machines  has  been  up¬ 
graded.  Version  5.0  supersedes  version 
4.5,  adding  automatic  page  numbering 
(it  didn’t  have  it  before?)  and  other 
features. 

Electronic  Ordering 

We  noted  above  a  software  directory 
that  is  available  in  print  or  as  a  diskette. 
The  new  Westico  software  distribution 
company  aims  to  be  equally  imaginative; 
they’ve  set  up  a  dial-up  order  line.  Call 
(203)  853-0816  with  your  300  baud 
modem  and  you  can  review  their  product 
list  and  place  orders.  Their  release  does 
not  say  so,  but  we  can  see  the  day  ap¬ 
proaching  when  one  might  report  prob¬ 
lems  and  check  lists  of  known  bugs  the 
same  way.  It’s  good  to  see  some  of  the 
endless  chatter  about  the  electronic  mail 
being  realized. 

Another  Single-Board  Computer 

BASYS/1  is  the  monicker  that  TMSI 
have  used  for  their  all-CMOS  computer 
board.  The  design  places  an  1802  CPU, 
healthy  hunks  of  ROM  and  RAM,  and 
I/O  circuitry  on  a  4.5”  x  6.5”  board.  A 
motherboard  and  memory  expansion 
board  are  available,  and  more  boards  are 
planned  to  follow.  Prices  range  upward 
from  $175. 

64K  Chips  Are  Really  Here 

OKI  Semiconductor  wants  you  to 
know  that  they  are  shipping  their  64K- 
bit  RAM  chips.  The  ICs  are  still  a  bit 
pricey;  they  cost  from  $30  to  $60  (de¬ 
pending  on  speed)  in  lots  of  1000.  Still, 


how  long  can  it  be  until  a  64K-byte 
board  will  use  just  eight  chips?  Do  we 
dare  hope  that,  when  it  uses  just  one 
extra  chip,  we  might  actually  see  person¬ 
al  computer  storage  with  parity  checking? 
Dream  big;  single-bit  error  correction 
only  needs  four  extra  bits  per  16-bit 
word.  A  board  that  contains  64K  of  16- 
bit  words  with  error  correction  can  now 
be  built  around  just  20  ICs.  .  . 

Osborne  I  Is  Bom 

Adam  Osborne,  well  known  as  a  pub¬ 
lisher  of  reference  books  and  business 
software,  has  launched  a  hardware  ven¬ 
ture,  the  Osborne  Computer  Corporation. 


Its  first  product  is  the  Osborne  I  Comput¬ 
er  System,  a  dual-drive,  64K,  CP/M- 
compatible  computer  with  a  retail  price 
of  $1795.  After  its  price,  the  machine’s 
most  remarkable  feature  is  its  portability; 
keyboard,  screen  and  drives  are  all  built 
into  a  single  aluminum  carrying  case.  The 
only  design  compromise  apparent  from 
the  initial  press  material  is  the  small  size 
of  the  CRT.  Osborne  elected  to  use  a 
5”  CRT,  formatted  into  24  rows  of  52 
characters  each.  The  small  size  may  be 
mitigated  by  the  fact  that  the  small  CRT 
“is  a  window  on  a  1 28  x  34  row  screen.” 
We’re  all  eager  to  see  how  that  works  out 
in  practice.  ■  ■ 


Contact  Points 

Altemet,  POB  4872,  Santa  Rosa,  CA 
95402,(707)542-7200. 

APL  Market  Newsletter,  POB  5314, 
Mt.  Carmel,  CT  06518. 

Elicon,  254  Viking  Avenue,  Brea,  CA 
92621,(714) 990-6647. 

FORTH  Interest  Group,  POB  1105, 
San  Carlos,  CA  94070,  (415)  962- 
8653. 

HDB,  222  East  Anapamu  Street,  Santa 
Barbara,  CA  93101,(805)965-4477. 
IMCSS,  Dr..  B.  C.  Kuo,  POB  2772- 
Station  A,  Campaign,  IL  61820,(217) 
333-4341. 

Micro -Serve,  Inc.,  250  Cedar  Hill  Ave¬ 
nue,  Nyack,  NY  10960,  (914)  358 - 
1340. 

North  American  Technology,  Strand 
Building,  174  Concord  St.,  Suite  23, 
Peterborough,  NH  03458,  (603)  924- 
6048. 

OKI,  1333  Lawrence  Expressway, 
Suite  401,  Santa  Clara,  CA  95051, 
(408)  984-4842. 

Osborne  Computer  Corporation,  26500 
Corporate  Avenue,  Hayward,  CA 


94545,(415)887-8080. 

Personal  Computer  Arts  Festival,  c/o 
PCAF-81,  POB  1954,  Philadelphia,  PA 
19105. 

Phase  One  Systems,  7700  Edgewater 
Drive,  Oakland,  CA  94621. 

Softronics,  36  Homestead  Lane, 
Roosevelt,  NJ  08555. 

Software  News,  5  Kane  Industrial 
Drive,  Hudson,  MA  01749,(617)  562- 
9308. 

Softworks  Limited,  607  W.  Welling¬ 
ton,  Chicago,  IL  60657,  (312)  327- 
7666. 

Tab  Books,  Blue  Ridge  Summit,  PA 
17214,(717)  794-2191. 

TSC,  POB  2570,  1208  Kent  Avenue, 
West  Lafayette,  IN  47906. 

TMSI,  POB  7227,  Ann  Arbor,  MI 
48107,(313)994-0784. 

Westico,  25  Van  Zant  Street,  Norwalk, 
CT  06855,  (203)  853-6880  for  peo¬ 
ple,  (203)  853-0816  for  computers. 
Zenith  Data  Systems,  1000  Milwaukee 
Avenue,  Glenview,  IL  60025,  (312) 
391-8181. 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 
192 


13 


Since  1976,  the  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 

Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


YES!  Enter  my  subscription  to  Dr.  Dobb's  Jour- 

ml  and  bill  me  later. 

$25 

name 

one  year  subscription 

12  issues 

saves  $5  off  the  newsstand  price 

address 

city  state  zip 

Mail  to:  DDJ,  P.O.  Box  E., 

Menlo  Park,  CA  94025 

What  to  Do  With  Those 
Extra  Function  Keys 


II 

X  X  ere  is  a  CP/M  program  to  allow  a 
user  to  define  special  functions  of  his 
keyboard  so  that  a  single  keystroke  can 
recall  a  word  or  an  entire  phrase.  There 
has  already  been  a  similar  program  in 
DDJ  for  users  of  North  Star  BASIC.  This 
program  is  perhaps  more  versatile. 

So  you  have  a  CRT  with  those  16 
extra  function  keys?  You  say  that  some¬ 
day  you  will  do  something  with  them, 
but  you  just  have  not  got  around  to  it?  I 
know  how  you  feel.  I  finally  did  some¬ 
thing  about  it  though,  and  had  some  fun 
in  the  process.  Maybe  you  would  like 
to  know  how  I  did  it  so  that  you  can  be 
sure  to  do  it  different  and  perhaps  better. 

The  Motivation 

I  have  a  nice  Lear-Siegler  terminal 
with  lots  of  fancy  keys.  Many  will  never 
be  of  any  use  in  a  single-user  system.  I 
thought  it  would  be  nice  to  define  the  16 
keys  that  run  along  the  top  of  the  key¬ 
board.  I  had  seen  the  same  layout  on 
other  makes  of  terminals.  Beehive,  Tele¬ 
video  and  Hazeltine  offer  the  extra  keys 
as  standard  equipment  on  higher  price 
models. 

After  playing  with  my  terminal  I  dis¬ 
covered  that  the  16  extra  keys  all  gener¬ 
ate  a  three- character  sequence  for  just 
one  push  of  the  key  button.  (I  could  have 
read  the  manual  and  saved  some  time.) 
The  operator’s  manual  calls  this  a  “Spe¬ 
cial  Function  Transmission”  that  always 
starts  with  control- A,  which  is  the  ASCII 
code  for  SOH,  followed  by  one  of  the 
characters  @  through  the  letter  O,  termi¬ 
nated  with  RETURN.  Use  of  the  SHIFT 
key  gives  16  more  functions.  Figure  1  is 
a  table  to  show  how  this  works. 

The  ASCII  code  for  SOH  is  1,  the 
code  for  RET  is  13.  So  if  you  hit  the  FI 
key,  the  sequence  would  be  1,64,13;  if 
you  hit  the  F16  key  it  would  be  1,80,13. 

From  this  I  could  see  that  the  SOH 
is  a  lead-in  character.  It  means  that  a 
function  code  follows.  The  RET  charac¬ 
ter  is  not  needed  in  my  application,  so  I 
must  plan  to  discard  it. 

It  seems  easy.  Just  write  a  keyboard 
input  routine  that  tests  to  see  if  the  SOH 

by  John  B.  Palmer 

John  B.  Palmer,  P.  O.  Box  23,  Boonville, 
CA  95415. 


Figure  1. 


Function 

Key 

Sequence 

Sequence  with 
SHIFT 

FI 

SOH,  RET. 

SOH,  ’,  RET. 

F2 

SOH,  A,  RET. 

SOH,  a,  RET. 

F3 

SOH,  B,  RET. 

SOH,  b,  RET. 

F4 

SOH,  C,  RET. 

SOH,  c,  RET. 

F5 

SOH,  D,  RET. 

SOH,  d,  RET. 

F6 

SOH,  E,  RET. 

SOH,  e,  RET. 

F7 

SOH,  F,  RET. 

SOH,  f,  RET. 

F8 

SOH,  G,  RET. 

SOH,  g,  RET. 

F9 

SOH,  H,  RET. 

SOH,  h,  RET. 

F10 

SOH,  I,  RET. 

SOH,  i,  RET. 

FI  1 

SOH,  J,  RET. 

SOH,  j,  RET. 

F12 

SOH,  K,  RET. 

SOH,  k,  RET. 

F13 

SOH,  L,  RET. 

SOH,  1,  RET. 

F14 

SOH,  M,  RET. 

SOH,  m,  RET. 

F15 

SOH,  N,  RET. 

SOH,  n,  RET. 

F16 

SOH,  0,  RET. 

SOH,  o,  RET. 

character  ever  comes  in.  Hold  on!  That 
means  I  have  to  redo  my  CP/M  BIOS.  And 
what  if  I  ever  want  to  change  it  again? 
And  what  about  some  of  my  software 
that  already  uses  the  SOH  for  a  special 
purpose. . .  .  This  sounds  like  a  lot  of 
work.  So  I  put  it  off  for  awhile.  Needed 
to  think  it  out. 

Later,  I  got  a  Sinclair  ZX80  and  dis¬ 
covered  that  it  has  built-in,  single-stroke 
keywords.  Real  nice,  just  hit  the  SHIFT 
and  a  letter  and  a  word  appears  on  the 
screen.  But  only  the  words  used  in  BASIC 
programming.  There  is  no  provision  to  re¬ 
define  the  letters  to  represent  a  new  set 
of  words.  Still  need  to  think  it  out. 

Then  along  comes  DDJ  number  50. 
Leonard  E.  Garcia  has  done  it  for  me! 
Well,  almost.  He  has  a  North  Star  system. 

I  have  a  one-of-a-kind  collection  of  odds 
and  ends  that  is  held  together  by  the 
CP/M  operating  system.  If  I  can  make 
this  idea  work  on  my  system  it  should 
be  usable  on  any  microcomputer  with 
CP/M. 

So  I  would  take  on  this  project  only 
if  I  could  make  a  program  that  meets 
these  requirements: 

1.  It  does  not  require  the  user  to  rewrite 
the  BIOS  software; 

2.  When  not  in  use  it  does  not  hinder 
other  software  that  uses  SOH  code 
(control -A); 

3.  The  user  may  rewrite  the  definitions 
and  save  them  on  disk; 

4.  It  is  hardware  independent  and  even 
works  on  the  Apple  II. 


Is  this  going  to  be  hard  to  explain  to 
someone  in  your  family  or  group?  Can 
anybody  use  it  without  a  course  in  assem¬ 
bly  language?  Yes.  It  is  very  easy  to  use. 
Here  is  a  description  of  how  to  make  use 
of  this  method  of  Keyboard  Input  Defini¬ 
tion. 

The  Procedure 

After  you  power  up  your  system  and 
hit  reset,  or  whatever  button  it  is  that 
you  push  to  get  the  disk  to  boot,  give  the 
DIR  command  and  see  if  the  following 
files  are  on  the  disk: 

DDT.COM 

KIP.HEX 

KID.COM 

CPM.KID 

Now  give  the  command  “DDT 
KIP.HEX’”  The  words  “NEXT”,  “PC” 
should  appear  and  some  letters  and  num¬ 
bers.  If  all  is  well,  give  the  command 
“GO”. 

It  is  not  necessary  to  repeat  the  above 
procedure  until  the  computer  is  again  re¬ 
set  or  the  power  is  turned  off  and  back 
on. 

At  this  point  you  may  give  the  com¬ 
mand  “KID  CPM”.  But  if  you  are  going 
to  be  doing  BASIC  programming,  you 
may  rather  give  the  command  “KID 
BASIC”  if  your  disk  has  BASIC.KID  on 
it. 

Anytime  you  are  at  the  CP/M  com¬ 
mand  level  you  may  redefine  the  special 
function  keys  with  the  command  “KID 
filename”,  where  filename  is  a  proper  file 
of  type  “.KID”  and  is  on  your  disk. 

If  the  filename  you  gave  is  not  on  the 
disk,  the  message  “NO  KID  FILE”  will 
appear.  You  may  have  spelled  the  file¬ 
name  wrong.  Or  else  it  is  not  on  your 
disk. 

It  is  possible  that  you  may  get  the 
message  “KIP  ABSENT”.  This  means  that 
you  forgot  to  load  “KIP.HEX”  with  DDT 
or  else  the  computer  has  been  reset. 

When  everything  goes  right  you  will 
get  this  message:  “KID  READ  OK”.  Now 
hold  the  CTRL  key  down  and  strike  the 
letter  A  twice.  You  should  see  the  con¬ 
tents  of  the  file  that  was  just  read  and 
now  defines  the  Special  Functions  of  the 
keyboard. 

You  may  wish  to  use  transparent 
tape  and  a  marker  pen  to  identify  keys 
FI  through  FI 6.  The  definition  for  FI  is 
quotation  after  the  sign,  F2  corre¬ 
sponds  to  “A”,  F3  to  “B”  and  so  on. 
(Sometimes  the  “  I  ”  is  used  in  place  of 


14 

194 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


a  quotation  mark.) 

From  now  on,  whenever  you  hit  the 
F 1  key  the  word  or  words  inside  the  quo¬ 
tation  marks  after  the  sign  should 
now  appear.  If  you  hit  the  F2  key  the 
quotation  after  the  “A”  will  appear  and 
so  on.  Notice  that  the  quotation  marks 
do  not  show.  Neither  does  the  or  the 
letters  that  identify  the  16  keys  FI 
through  F 1 6. 

Remember,  whenever  you  wish  to 
see  the  contents  of  the  current  Keyboard 
Input  Definition,  just  hold  the  CTRL  key 
and  strike  the  letter  “A”  twice.  If  you  do 
this  while  using  a  word  processor  pro¬ 
gram,  be  sure  to  clear  the  screen  or  home 
the  cursor  before  you  do  any  more 
editing. 

You  may  use  the  text  editor  to  make 
your  own  custom  definitions  and  save 
them  on  disk.  Use  the  present  definitions 
as  a  guideline  for  your  work.  Remember 
to  put  quotation  marks  before  and  after 
each  definition.  You  do  not  have  to  de¬ 
fine  all  16  keys.  If  for  some  reason  you 
must  have  a  quotation  mark  itself  as  part 
of  a  group  of  words  of  a  definition,  then 
use  some  other  symbol  to  mark  the  start 
and  finish  of  that  group  of  words. 

If  you  have  made  an  error  in  your 
custom  definition,  some  of  the  function 
keys  will  give  bizarre  results.  Anytime 
you  change  your  definitions  you  must 
give  the  command  “KID  filename”  again 
in  order  to  put  the  new  definition  into  its 
proper  place  in  memory. 

If  you  get  a  question  mark  when  you 
strike  a  function  key  it  means  that  key 
was  not  defined.  An  improper  definition 
may  also  cause  a  question  mark  to  ap¬ 
pear.' 

The  Theory 

So  much  for  the  user  guide.  Now 
about  the  theory.  Really,  I  don’t  have  a 
very  good  explanation  about  how  it 
works.  One  of  the  requirements  of  this 
system  is  that  you  have  about  512  bytes 
of  RAM  somewhere  in  your  system  that 
can  be  used  by  the  programs  “KIP” 
and  “KID”.  Let’s  call  its  first  address 
FRERAM. 

The  program  “KID”  is  an  almost- 
normal  CP/M  program  that  is  called  into 
the  TPA.  It  can  be  used  as  often  as  you 
like.  It  reads  into  FRERAM  +  256  the 
definition  file  the  user  specifies. 

The  definition  file  must  be  of  type 
“.KID”.  Thus  a  file  that  might  be  used  in 
BASIC  programming  could  be  named 
“BASIC. KID”.  Of  course  you  can  name  it 


anything  you  like,  just  make  the  filetype 
“.KID”.  I  have  included  in  the  listings  my 
personal  definitions  for  CP/M  and  BASIC. 

If  I  wish  to  do  quite  a  bit  of  work 
with  CP/M  at  the  command  level,  I  give 
the  command  “KID  CPM”.  CP/M  loads 
KID.COM  into  the  TPA.  It  in  turn  loads 
the  sequential  file  “CPM. KID”  into 
FRERAM  +  256.  Next  a  test  is  made  to 
see  if  the  file  “KIP.HEX”  has  already 
been  called  in  by  DDT.  There  should  be  a 
JMP  instruction  at  FRERAM.  If  so,  then 
another  test  is  made  to  see  if  the  address 
field  after  the  JMP  is  all  zeros.  If  it  is  all 
zeros  then  a  patch  must  be  made  to  the 
address  fields  of  BIOS  vectors  for  Console 
Status  and  Console  Input.  But  first  we 
must  store  those  address  fields  into 
FRERAM  +  1  and  FRERAM  +  4  or  we 
will  really  mess  up  everything. 

From  this  you  can  understand  that 
this  method  is  really  very  risky.  Do  some¬ 
thing  wrong  and  the  whole  system  will 
crash.  It  really  would  be  better  if  there 
was  a  nice  clean  way  of  doing  this  trick 
inside  the  CP/M  system  rules.  I  consider 
this  method  to  be  very  nasty  and  against 
the  rules.  You  can  not  use  KID  with  the 
CP/M  XSUB  utility.  The  XSUB  program 
also  will  modify  the  BIOS  vectors.  I 
tried  to  use  the  two  together  and  they  did 
not  respect  each  other.  But  there  are  few 
cases  where  anybody  would  use  XSUB. 

Now  what  about  using  KID  with  any 
program  that  wants  to  use  the  SOH  char¬ 
acter?  You  can  do  either  of  two  things. 
One  is  to  just  reset  your  computer  and  re¬ 
boot.  This  will  restore  the  BIOS  to  its 
original  condition.  Or  you  can  define  a 
special  function  to  generate  a  control  A, 
which  is  SOH.  I  did  it  like  this: 

q“tA” 

So  if  I  hit  control-A  and  then  lower 
case  Q,  I  get  a  control-A.  Why  not  define 
control-A  as  being  itself?  Because  the 
program  KIP  (Keyboard  Input  Patch)  ex¬ 
pects  control-A  to  be  the  KIFUN  lead-in. 
If  you  want,  you  could  edit  the  program 
KIP.ASM,  define  some  other  control  to 
be  the  KIFUN  constant  and  assemble  it. 
But  most  terminals  use  control-A  as  the 
lead-in.  What  about  the  ESC  key?  That 
would  be  alright  if  your  terminal  does  not 
use  ESC  as  the  lead-in  for  cursor  address, 
clear  screen  or  whatever. 

This  leads  to  a  consideration  of  how 
the  program  KIP  does  its  job.  Because 
KIP  must  be  loaded  into  an  area  above 
the  BIOS,  it  can  not  be  a  regular  CP/M 
“.COM”  file.  You  have  to  use  DDT  to 
read  and  load  KIP.HEX  into  your  free 


RAM  area.  On  my  system  this  is  at 
OFCOO  hex  and  that  value  is  given  the 
constant  FRERAM  on  line  14  of  the  list¬ 
ing  for  KIP.  Change  this  if  your  system 
has  reserved  RAM  at  some  other  location. 
If  you  are  now  running  a  64K  CP/M  sys¬ 
tem,  you  will  have  to  move  CP/M  down 
to  63K  to  make  room  for  KIP. 

All  console  status  calls  and  console 
input  calls  via  the  BIOS  are  vectored  first 
to  KIP.  If  the  SWITCH  is  inactive,  KIP 
will  cause  a  call  for  status  to  be  vectored 
to  the  original  status  routine  in  the  BIOS. 
Whenever  there  is  a  call  for  the  console 
input,  KIP  calls  the  input  routine  in  the 
BIOS  and  then  tests  for  a  KIFUN  charac¬ 
ter.  (KIFUN  is  control-A,  unless  you 
change  it  to  something  else.)  If  it  is  not 
the  KIFUN  character  then  a  normal  re¬ 
return  is  made  and  the  calling  program 
gets  to  have  the  character  that  just  came 
in  from  the  keyboard.  But  if  it  was  the 
KIFUN  character,  sparks  start  to  fly.  A 
call  is  made  again  to  the  original  BIOS 
input  routine.  If  it  is  another  KIFUN, 
then  a  jump  is  made  to  PEEK  so  that  the 
user  gets  to  see  what  is  in  the  current 
Definition  Block;  otherwise  the  Defini¬ 
tion  Block  is  searched  for  a  definition 
that  corresponds  to  the  character  that  fol¬ 
lowed  KIFUN. 

One  minor  note.  I  did  not  want  the 
RETURN  character  that  is  given  when¬ 
ever  keys  FI  through  FI 6  are  hit.  If  the 
character  after  KIFUN  is  in  the  range  of 
40  hex  through  4F  hex  or  in  the  range  of 
60  hex  through  6F  hex,  then  a  dummy 
call  is  made  to  the  BIOS  input  routine  to 
destroy  the  unwanted  RETURN. 

Now  then,  where  were  we?  Oh,  yes, 
a  search  was  made  for  a  definition.  If 
found,  the  SWITCH  is  turned  on,  the 
EOSTR  (end  of  string)  is  notea,  the 
STRPTR  (string  pointer)  is  set  to  the  first 
character  of  the  string  and  we  start  giving 
the  string  a  character  at  a  time.  When  we 
get  to  the  last  character  it  is  time  to  turn 
off  the  SWITCH  and  restore  normal  con¬ 
sole  input. 

What  are  the  rules  for  the  Definition 
Block?  The  Definition  Block  is  nothing 
more  than  a  text  file  created  by  the  user 
with  any  standard  CP/M  editor.  TAB, 
RETURN  and  LINE-FEED  are  allowed, 
but  do  not  put  other  control  codes  nor 
high  parity  bits  in  the  file.  The  first  char¬ 
acter  in  the  file  other  than  SPACE,  TAB, 
RETURN  and  LINE-FEED  identifies  the 
start  of  another  definition.  This  goes  on 
until  the  end  of  the  file  is  found.  The 
CP/M  editor  automatically  puts  the  end 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


15 

195 


of  file  marker  in  the  file  although  you 
don’t  see  it. 

Some  examples 

Example  1 

@“STAT  ”  A“ASM”  B“BASIC” 


Example  2 

1  “PIP t  M”  2“DIRt  M” 

In  the  first  example  there  are  three 
definitions.  When  the  user  hits  the  FI 
key,  the  word  ST  AT  will  appear.  If  F2  is 
hit  the  word  ASM  will  appear.  If  F3  is  hit 
the  word  BASIC  will  appear. 

The  second  example  has  two  defini¬ 
tions.  The  function  keys  are  not  used 
here.  When  the  user  hits  control-A  fol¬ 
lowed  by  the  number  1  the  command  PIP 
will  be  given.  When  the  user  hits  control- 
A  followed  by  the  number  2  the  com¬ 
mand  DIR  will  be  given.  In  both  cases  the 
up  arrow  and  the  letter  M  represent  the 
control  code  for  RETURN.  Then  how 
could  you  ever  put  an  up  arrow  in  the 
definition?  Use  two.  Notice  example  3 : 

Example  3 
8”t  >” 9“ ft” 

These  two  definitions  have  little 
practical  value,  but  show  how  to  put  con¬ 
trol  up  arrow  and  up  arrow  itself  into  the 
Definition  Block.  Control-A  followed  by 
8  gives  control  up  arrow.  Control-A  fol¬ 
lowed  by  9  gives  up  arrow. 

You  may  use  other  symbols  for  the 
string  delimiter  instead  of  the  quotation 
mark.  In  BASIC  programming  the  quota¬ 
tion  mark  is  used  as  an  unchangeable 
string  delimiter.  In  the  Definition  Block 
for  KIP  the  string  delimiter  is  always 
whatever  comes  after  the  string  identifier. 
Notice  example  4: 

Example  4 

6 1  FILE$=” !  7!  RUN  FILES! 

In  example  4  above  we  wanted  to 
put  the  quotation  mark  into  the  defini¬ 
tion.  We  used  a  funny  character  that  is 
found  on  some  keyboards  by  hitting  the 
SHIFT  and  the  backslash.  In  fact,  the 
backslash  could  have  been  used  too,  but 
some  BASICs  use  the  backslash  to  mean 
something.  Try  to  pick  a  string  delimiter 
that  you  know  will  never  have  to  appear 
inside  the  string.  You  can  not  use  the 
string  delimiter  inside  of  the  string.  It 
only  and  always  comes  at  the  start  and 
the  finish. 


Improvements 

So  much  for  the  theory.  What  about 
improvements?  That  is  up  to  you.  I  tried 
to  keep  the  KIP  program  inside  of  256 
bytes  using  8080  code.  If  you  wish  to 
modify  either  KID  or  KIP,  go  ahead. 

These  programs  are  not  of  commer¬ 
cial  quality.  There  are  too  many  things 


that  can  go  wrong.  A  better  method 
would  be  to  put  this  sort  of  thing  into  the 
operating  system  itself  instead  of  grafting 
it  into  the  BIOS.  As  mentioned  earlier,  it 
can  not  be  used  with  XSUB.  Hopefully, 
Digital  Research  will  put  something  like 
this  into  a  future  version  of  CP/M.  ■■ 

LISTING  ON  PAGE  34 


Do  you  have  a  microcomputing  manuscript 
that  seems  too  advanced  for  most  magazines, 
but  too  exciting  for  an  academic  journal? 
DDJ  may  be  the  niche 
you  have  been  looking  for. 

Let  us  hear  from  you  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415) 323-3111 


16 

196 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


CAD  for  Time  Delay  Circuits 


i  n  the  September  1979  issue  of  Popu- 
lar  Electronics,  there  is  an  excellent  arti¬ 
cle  called  “A  Monostable  Catalog  for  Ex¬ 
perimenters.”  This  article,  by  Clement  S. 
Pepper,  outlines  the  key  features  of  the 
most  popular  monostable  IC’s.  With  the 
article  as  a  guide,  an  experimenter  can  de¬ 
sign  his  own  one-shot  timing  circuits. 

Even  with  the  article,  however,  I 
found  my  self  spending  far  too  much 
time  “designing”  before  I  could  construct 
a  working  circuit.  My  time  was  spent 
making  numerous  design  decisions  and 
solving  equations  to  come  up  with  cor¬ 
rect  timing  components  —  tasks  that 
could  be  done  easily  with  a  hobby  com¬ 
puter.  With  that  idea  in  mind,  I  spent  an 
evening  developing  a  BASIC  computer 
program  that  would  take  all  the  drudgery 
out  of  IC  design. 

Once  you  hit  RUN,  the  computer 
asks  you  for  the  most  important  design 
information  only.  It  then  goes  on  its  own 
to  determine  the  closest  standard  value 
parts  needed.  The  program  design  is 
straightforward  and  has  been  structured 
so  that  it  is  self-documenting. 

Lines  265  through  340  allow  you  to 
choose  an  IC  chip  you  have  on  hand  if  it 
can  supply  your  needed  pulse  width. 

Lines  360  through  595  make  the  de¬ 
sign  limit  decisions  for  you.  The  program 
is  quite  conservative  when  setting  design 
limits. 

Lines  615  through  655  ask  for  your 
required  pulse  width.  These  lines  also  test 
your  requirements  against  the  design 
limits,  just  to  keep  you  honest. 

Lines  675  through  715  ask  for  the 
standard  value  capacitor  you  wish  to  use 
and  check  it  against  the  design  limits.  The 
program  could  have  been  designed  to 
compute  a  specific  value  capacitor,  but 
the  method  actually  used  has  one  big  ad¬ 
vantage  for  the  experimenter  —  he  can 
use  parts  values  he  already  has  on  hand.  If 
you  are  like  me,  your  junk  box  will  con¬ 
tain  a  part  close  enough  for  your  design. 
By  the  way,  if  you  don’t  have  a  capacitor 
on  hand,  I  suggest  you  use  a  value  that  is 
a  multiple  of  10,  22,  or  47.  You  should 
be  able  to  find  these  values  in  any  parts 
store. _ 

by  Hal  Knippenberg 

Hal  Knippenberg,  2514  Blueberry  Drive, 
Augusta,  GA  30906. 

Reprinted  from  the  CSRA  Computer  Club 
Newsletter. 


Lines  725  through  780  compute  the 
proper  timing  resistor  value  for  the  chip 
and  capacitor  you  have  chosen.  The  com¬ 
puted  resistance  is  checked  against  de¬ 
sign  limits  and,  if  it  doesn’t  work,  the 
program  will  ask  for  another  value  capaci¬ 
tor.  It  usually  takes  two  or  three  tries  be¬ 
fore  the  program  presents  a  usable  set  of 
values. 

Lines  800  through  825  print  out  the 
results  of  a  successful  choice  of  values. 
However,  the  resistance  called  for  will  not 
be  a  standard  value  since  it  is  computed 
to  six-  or  eight-digit  accuracy. 

Lines  845  through  890  ask  for  the 
closest  standard  value  resistor  you  can 
use.  I  suggest  you  pick  a  value  from  a  list 
of  standard  5%  values.  As  with  the  sug¬ 
gested  capacitor  values,  5%  resistors  can 
be  bought  in  almost  any  parts  house. 

RUN 


Lines  910  through  965  compute  the 
actual  pulse  width  you  should  get  using 
the  standard  values  you  have  entered. 

If  you  require  closer  tolerance  pulse 
widths,  you  should  use  an  adjustable  re¬ 
sistor.  Try  a  ten-  or  twenty-turn  adjust¬ 
able  resistor  with  a  value  about  twice  that 
computed  for  R  by  the  program.  Also, 
use  a  fixed  resistor  in  series  with  the  ad¬ 
justable  one.  The  fixed  resistor  should 
have  a  value  about  20%  of  the  value  com¬ 
puted  by  the  program.  This  combination 
will  allow  you  to  set  your  pulse  width 
right  on-the-money. 

Now  that  my  computer  can  call  upon 
this  program,  I  can  design  a  one-shot 
multivibrator  in  just  a  few  mintues.  Not 
only  that,  but  most  of  the  time,  my 
designs  use  parts  already  on  hand.  I  hope 
this  program  helps  you  do  the  same.  ■■ 

LISTING  ON  PAGE  39 


COMMON  ONE-SHOT  CHIPS  (POSSIBLE  PULSE  WIDTHS) 


1.  9600  (74  NS  -  8  SEC) 

6. 

74123 

(40  NS  -  8  SEC) 

2.  9601  (45  NS  -  8  SEC) 

7. 

74LS221 

(30  NS  -  70  SEC) 

3.  9602  (72  NS  -  8  SEC) 

8. 

74C221 

(50  NS  -  175  SEC) 

4.  74121  (30  NS  -  14  SEC) 

9. 

4098B 

(30  NS  -  270  SEC) 

5.  74122  (40  NS  -  8  SEC) 

10. 

4528B/ 

(100  NS  -  270  SEC) 

MC14528C 


WHICH  CHIP  WILL  YOU  USE  ?  (1-10)  6 

WHAT  LENGTH  PULSE  IN  MICROSECONDS  ?  10 
WHAT  STANDARD  VALUE  CAPACITOR  IN  MICROFARADS  ?  1 
USE  A  SMALLER  VALUE  C 

WHAT  STANDARD  VALUE  CAPACITOR  IN  MICROFARADS  ?  .1 
USE  A  SMALLER  VALUE  C 

WHAT  STANDARD  VALUE  CAPACITOR  IN  MICROFARADS  ?  .01 
USE  A  SMALLER  VALUE  C 

WHAT  STANDARD  VALUE  CAPACITOR  IN  MICROFARADS  ?  .001 
USE  A  LARGER  VALUE  C 

WHAT  STANDARD  VALUE  CAPACITOR  IN  MICROFARADS  ?  .0047 
USE  A  SMALLER  VALUE  C 

WHAT  STANDARD  VALUE  CAPACITOR  IN  MICROFARADS  ?  .0022 
FOR  A  PULSE  WIDTH  OF  10  MICROSECONDS,  USE: 

CAPACITOR  =  .0022  MICROFARADS 
RESISTOR  APPROX  =  14204  OHMS 

WHAT  IS  THE  CLOSEST  STANDARD  VALUE  RESISTOR  YOU 
CAN  USE?  15000 

USING  A  CAPACITOR  OF  .0022  MICROFARADS  AND  A 
RESISTOR  OF  15000  OHMS  WILL  RESULT  IN  A  PULSE  WIDTH  OF 
10.560493  MICROSECONDS. 

ANOTHER  DESIGN  ?  N 
READY 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


17 

197 


Book  Reviews 


Disassembled  Handbook  for  the  TRS-80 

By  Robert  M.  Richardson 

Published  by  Richcraft  Engineering,  Ltd. 

$10.00 

TRS-80  Disk  and  Other  Mysteries 
By  Harvard  C.  Pennington 

Published  by  IJG,  Inc. 

$21.95 

Reviewed  by  John  R.  Culleton,  Jr. 

You  can  always  spot  the  future  pro¬ 
grammer  in  a  gang  of  pre-schoolers.  Just 
look  for  the  tyke  who  has  dismantled  a 
perfectly  good  music  box  in  the  vain 
hope  of  catching  a  glimpse  of  the  tiny 
orchestra  inside.  Radio  Shack  has  provid¬ 
ed  software  for  the  TRS-80  aimed  at 
obedient  appliance  operators,  not  prying 
tinkerers.  The  two  principal  programs 
(Microsoft  BASIC  and  Randy  Cook’s 
TRSDOS)  are  slick,  easy  to  use,  and  rela¬ 
tively  impenetrable.  A  challenge  of  this 
character  is  not  to  be  ignored,  and  two 
venturesome  technologists  have  attacked 
the  Tandy  software  offerings  with  ingenu¬ 
ity  and  persistence.  The  results  are  fasci¬ 
nating. 

The  books  are  complementary  in 
that  Richardson  deals  with  the  subrou¬ 
tines  found  in  the  Microsoft  BASIC,  and 
Pennington  discusses  the  organization  of 
TRSDOS  files  and  the  file  directory  sys¬ 
tem.  There  is  little  overlap  of  informa¬ 
tion.  Both  books  are  self- published,  set  in 
large  clear  type  using  the  TRS-80  and  the 
Electric  Pencil  program.  Pennington  has  a 
handsome  product,  with  illustrations  by 
the  author  and  carefully  drawn  graphics 
to  hold  the  reader’s  interest.  Richardson 
has  turned  out  a  more  utilitarian  volume, 
and  could  have  spent  more  time  on  proof¬ 
reading.  Both  present  plenty  of  fascinat¬ 
ing  inside  information  on  how  the  TRS- 
80  software  does  what  it  does,  and  both 
leave  plenty  of  room  for  further  investi¬ 
gation  by  the  reader.  Both  feel  obligated 
to  castigate  Tandy  Corporation  with  tire¬ 
some  regularity.  Richardson  at  least  has 
the  grace  to  offer  this  curious  disclaimer: 
“Please  disregard  the  ‘curse  you, 

Red  Baron’  comments  in  chap¬ 
ters  2  and  3.  They  were  put  in 
for  revie  were/ publishers  who 
were  given  only  a  single  chapter 
of  this  handbook.” 

We  leave  it  to  others  to  explain  why  pub¬ 
lic  and  frequent  excoriation  of  Tandy 
Corp.  and  all  its  works  is  considered  a 
required  exercise.  This  reviewer  neither 
understands  nor  appreciates  this  curious 
form  of  reverse  partisanship  on  the  part 


of  TRS-80  users. 

If  Mr.  Pennington  has  problems  find¬ 
ing  any  virtue  in  Tandy,  he  has  equal  dif¬ 
ficulty  finding  any  vice  in  his  two  favorite 
software  products  -  NEWDOS+  and 
Electric  Pencil.  Nevertheless,  on  page  82 
under  the  heading  “Electric  Pencil  Good¬ 
ies”  he  lets  slip  the  fact  that  the  two  are 
mutually  incompatible  as  sold.  He  does 
give  the  necessary  modifications  to  Pencil 
to  correct  the  problem,  but  this  reviewer 
wonders  what  he  would  say  about  a 
Tandy  product  that  had  the  frequent 
compatibility  problems  of  NEWDOS.  (Mi¬ 
crosoft  FORTRAN  and  Percom  PATCH- 
PAK  are  among  those  programs  that 
won’t  work  with  NEWDOS,  by  the  way.) 
Where  Pennington  really  shines  is  in  his 
lucid  and  exhaustive  explanation  of  the 
intricacies  of  the  many  file  formats  used 
under  TRSDOS,  and  the  inner  workings 
of  the  directory.  There  are  many  file  and 
directory  layouts  illustrating  the  variants, 
from  TRSDOS  to  VTOS  and  from  Elec¬ 
tric  Pencil  files  to  those  created  for  the 
Microsoft  Macro  Assembler.  Pennington 
is  particularly  strong  on  file  recovery 
techniques.  He  has  unlocked  most  of  the 
secrets,  although  the  “hashing”  algorithm 
for  file  names  eludes  him.  His  clever  use 
of  graphics  to  highlight  file  formats  is 
an  excellent  feature.  It  should  be  noted 
that  Pennington  deals  with  TRSDOS  files 
and  not  with  the  activity  of  TRSDOS  it¬ 
self.  There  is  no  penetration  of  the  oper¬ 
ating  system  routines  proper.  Perhaps 
that  will  be  in  his  next  book.  Whatever 
the  limitations  and  annoyances,  Penning¬ 
ton  has  written  a  “must  have”  book  for 
all  card-carrying  Tandy  tinkerers. 

Richardson  plumbs  the  innards  of 
TRS-80  software  more  directly,  speci¬ 
fically  the  Level  II  BASIC  found  in  the 
TRS-80  ROM.  But  while  Pennington 
packs  128  pages  with  information, 
Richardson  has  to  use  considerable  pad¬ 
ding  to  fill  69.  For  example  page  37  to 
52  of  Richardson  consist  of  a  dump  of 
the  Level  II  ROM.  Not  a  disassembly, 
mind  you,  just  a  dump,  presumably  pro¬ 
duced  by  the  ubiquitous  SUPERZAP  pro¬ 
gram.  He  has  a  real  problem.  He  has  come 
in  possession  of  a  body  of  immensely 
valuable  information,  but  only  needs  a 
dozen  or  so  pages  to  tell  all  he  knows.  So 
he  pads.  Never  mind,  the  information  he 
provides  is  well  worth  the  ten  bucks.  He 
has  unveiled  the  locations  of  the  Level  II 
ROM  routines  and  learned  how  to  use  at 
least  some  of  them  in  assembly  language 
programs.  An  assembly  language  program 


consisting  primarily  of  calls  to  well- 
written  subroutines  has  obvious  advan¬ 
tages  in  brevity,  readability  and  efficiency 
over  the  handcrafted  variety.  Armed  with 
Richardson’s  book  a  clever  programmer 
could  even  develop  his  own  BASIC  com¬ 
piler  and  really  make  the  TRS-80  zip 
along.  Curiously,  he  fails  to  decode  the 
Level  II  shorthand  notation  for  BASIC 
reserved  words  (verbs  and  such).  No  mat¬ 
ter,  Pennington  lists  them  in  an  appendix. 
One  could  wish  for  greater  variety  of 
“worked  examples”  covering  routines  in 
addition  to  the  arithmetic  functions  and 
data  type  conversion.  Nevertheless,  the 
book  whets  the  appetite  very  well,  and 
few  readers  will  resist  the  temptation  to 
try  their  hand  at  direct  calls  of  ROM 
functions. 

This  reviewer  has  found  Ms.  TRS-80 
to  be  a  demure  and  secretive  female. 
Pennington  and  Richardson  have  exposed 
some  of  her  fascinating  features.  Of 
course,  even  more  fascinating  are  the 
secrets  yet  kept,  such  as  the  inner  work¬ 
ings  of  the  file  access  routines.  Sally  Rand 
and  Gypsy  Rose  Lee  well  understood  the 
principle.  We  will  all  be  a  little  sadder 
when  the  last  veil  is  dropped  and  there 
are  no  more  mysteries  in  Mr.  Tandy’s 
marvelous  creation.  In  the  meantime,  all 
dedicated  software  voyeurs  will  have  to 
have  both  Richardson’s  Disassembled 
Handbook  and  Pennington’s  TRS-80 
Disk  and  Other  Mysteries. 

Pascal  Programming 
By  Laurence  Atkinson 
Published  by  Wiley  &  Sons,  Inc. 

$49.50  hardbound,  $21.00  softbound 

428  pages 

Reviewed  by  Doug  DeGroot 

With  the  ever-increasing  popularity 
and  acceptance  of  Pascal,  it  is  inevitable 
that  a  flurry  of  Pascal  instructional  books 
will  continue  to  appear.  Pascal  Program¬ 
ming  by  Laurence  Atkinson  is  one  of  the 
most  recent  of  these.  The  book  has  a  dual 
purpose:  to  teach  Pascal  to  experienced 
programmers  and  to  teach  progrmming  to 
those  with  no  previous  experience.  It  is 
intended  for  use  as  a  main  text  in  a  teach¬ 
ing  course.  These  two  aspects  combine 
to  give  the  book  most  of  its  problems,  al¬ 
though  the  author  does  an  admirable  job 
of  overcoming  them.  The  first  few  chap¬ 
ters,  intended  to  introduce  programming 
to  novices,  suffer  from  poor  organization 
and  lack  of  clarity.  It  is  doubtful  whether 
or  not  a  true  novice  can,  without  an  in¬ 
structor  available  to  answer  his  questions, 


18 

198 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


wade  his  way  through  the  material  and 
come  out  with  sufficient  understanding 
to  complete  the  remainder.  Truly  experi¬ 
enced  programmers  wishing  only  to  learn 
Pascal  will  almost  certainly  find  the  book 
too  slow,  too  verbose,  but  certainly  not 
useless.  Medium  level  programmers  and 
those  with  their  own  home  computer 
who  have  mastered  BASIC  will  best 
find  the  book  suited  for  their  needs. 

First,  a  few  of  the  faults.  The  coding 
conventions  used  throughout  the  text  are 
abysmal  and  even  inconsistent.  They  can 
easily  be  tolerated  since  most  of  the 
program  examples  are  short  and  not  com¬ 
plex,  but  they  definitely  should  not  be 
adopted.  Occasionally  a  programming 
function  or  concept  is  used  before  it  is 
introduced  and  explained.  Also,  some  of 
the  author’s  stylistic  attitudes  are  highly 
questionable  and  are  not  to  be  recom¬ 
mended. 

As  for  good  points,  the  book  is  well 
written,  explanations  are  well  worded  (if 
not  always  lucid)  and  there  is  an  abun¬ 
dance  of  material.  The  organization  is 
highly  conceptual  —  a  concept  such  as 
looping  is  introduced  and  then  given  a 
thorough  and  detailed  examination.  One 
problem  with  this  approach  when  accom¬ 
panied  by  the  author’s  dual  purpose  is 
that  programming  constructs  often  get  in¬ 
troduced  painfully  late.  The  author  states 
that  his  solution  to  this  problem  is  skip¬ 
ping  around  the  chapters  as  needed. 
Readers  unfamiliar  with  the  text’s  con¬ 
tents  and  purpose  may  not  readily  be  able 
to  do  this  on  their  own.  A  wealth  of  ex¬ 
amples  accompany  each  concept,  and 
each  chapter  contains  a  comprehensive 
list  of  challenging  exercises.  Concepts 
covered  include  different  data  types, 
loops,  procedures  and  functions,  program 
construction,  scalar  types,  and  advanced 
data  structures.  A  set  of  short,  useful  ap¬ 
pendices  is  included. 

How  To  Build  Your  Own  Working 

Microcomputer 
By  Charles  K.  Adams 

Published  by  Tab 
$9.95,  308  pages 
Reviewed  by  Carl  E.  Whitney 

This  book  is  ill- conceived,  and  its 
audience  poorly  targeted.  Beginners 
would  be  better  off  with  a  kit,  since 
much  of  the  information  presented  here 
is  in  a  condensed,  formal  style.  Experi¬ 
enced  hobbyists  will  not  be  very  interest¬ 
ed  in  an  8080  machine  with  hexadecimal 
input  and  LED  display.  Adams  should 


devote  more  thought  to  his  potential 
audience  and  their  information  needs  — 
and  he  should  insist  that  his  publisher  not 
print  a  cover  depicting  a  typewriter- 
ASCII  input  and  video  output,  when  the 
project  includes  neither. 

There  is  some  useful  material  here  on 
the  hardware  and  software  required  to 
program  EPROM’s  —  but  periodic  typo¬ 
graphical  errors  make  one  wonder  how 
carefully  the  book  has  been  proofread, 
and  how  bug-free  the  programs  are. 

The  Dartmouth  Time  Sharing  System 

By  G.  M.  Bull 

Published  by  Halsted  Press 

(John  Wiley  &  Sons) 

$65.00,  240  pages 

Reviewed  by  Edward  T.  Ordman 

New  England  College 

It  is  hard  to  understand  the  high 
price  of  this  book.  Does  the  publisher  feel 
there  will  be  enough  library  sales  to  pay 
for  the  publishing  costs,  and  sales  to  in¬ 
dividuals  can  be  neglected?  It  is  an  ex¬ 
cellent  book,  and  could  be  very  widely 
recommended  at  one-third  of  the  price. 
At  this  cost,  it  can  be  recommended  only 
for  the  libraries  of  schools  or  companies 
which  actively  use  the  Dartmouth  Time- 
Sharing  System  (DTSS)  or  which  are  en¬ 
gaged  in  writing  a  time-sharing  system 
large  enough  to  require  man-years  of  ef¬ 
fort.  Perhaps  others  can  read  it  by  inter- 
library  loan. 

DTSS,  while  physically  installed  at 
about  a  dozen  sites,  is  far  more  widely 
used:  Dartmouth  College  is  tied  into  all 
the  major  networks,  and  DTSS  was  a 
major  formative  influence  in  eduational 
computing.  The  commands  LIST,  RUN, 
SAVE  and  others  common  nowadays  first 
existed  (about  1964)  as  system  com¬ 
mands  in  DTSS. 

The  book  is  a  very  technical,  but 
very  readable,  distillation  of  a  great  many 
manuals  and  technical  documents  about 
DTSS.  It  is  not  an  introductory  user’s 
manual,  and  does  not  replace  the  stan¬ 
dard  manuals;  it  is  very  useful  reading  for 
someone  who  has  a  modest  acquaintance 
with  the  system  and  would  like  to  be¬ 
come  an  expert.  More  important,  for  the 
person  interested  in  internals  of  operating 
systems,  it  gives  a  great  deal  of  detail 
about  the  parts  of  DTSS  and  how  they 
communicate  with  one  another.  Organiza¬ 
tions  of  buffers,  flags,  job  tables,  details 
of  fault  handling,  communication  be¬ 
tween  jobs,  and  techniques  used  in  dead¬ 
lock  avoidance  are  described  in  detail. 


There  is  an  excellently  documented  list 
of  parameters  used  in  adjusting  schedul¬ 
ing  and  of  the  consequences  of  changing 
parameter  values.  There  is  a  good  expla¬ 
nation  of  swapping  algorithms  (determin¬ 
ing  which  jobs  should  be  in  core  at  any 
moment).  There  is  a  discussion  of  how  it 
looks  to  the  operator,  jobs  to  be  per¬ 
formed  by  the  operator  and  by  the  com¬ 
puter  in  starting  the  system,  stopping  the 
system,  modifying  the  operating  system. 

DTSS  is  definitely  a  “big  computer” 
system  —  at  least  in  1981.  As  the  operat¬ 
ing  systems  of  small  computers  grow, 
more  small  computer  users  will  want  to 
know  about  big  operating  systems  and 
the  techniques  they  use.  DTSS  is  con¬ 
ceptually  simpler  and  more  user-oriented 
than  many  large  systems,  and  this  book  is 
full  of  ideas  that  will  be  valuable  to  some¬ 
one  writing  a  large  operating  system.  It 
does  not  replace  a  textbook  on  operating 
systems,  since  it  refers  purely  to  DTSS 
and  does  not  discuss  other  possible  solu¬ 
tions  to  the  problems  faced  by  operating 
systems;  but  it  discusses  the  solutions 
used  in  DTSS  in  far  more  detail  than  can 
be  done  in  a  more  general  text.  ■  ■ 


This  publication 
is  available 
in  microform. 


University  Microfilms 
International 


300  North  Zeeb  Road 
Dept.  PR. 

Ann  Arbor,  Mi.  48106 
U.SA. 


30-32  Mortimer  Street 
Dept.  P.R. 

London  WIN  7RA 
England 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


19 

199 


Dr.  Dobbs  Clinic 


D.  E.  Cortesi,  Resident  Intern 


D  octor  Dobb’s  Clinic  is  a  new  venture.  It  is  a  place  for  the 
display  of  techniques  and  discoveries.  We  want  to  cover  any  sort 
of  method  or  trick  you’ve  found  in  your  exploration  of  (for 
example,  but  not  limited  to):  CP/M  or  OASIS  or  FLEX  or 
APPLE  DOS  or  TRSDOS  or  NEWDOS  or  RSTS  or  UNIX  or 
UCSD  PASCAL  or  .  .  . 

During  our  rounds  at  the  clinic  we  may  examine  a  compiler 
or  an  interpreter,  revealing  its  bugs  or  showing  how  it  can  be 
made  to  perform  better.  We’d  like  to  tell  of  unobvious  uses  for 
standard  utilities.  We  want  to  uncover  errors  in  published 
documentation,  to  warn  people  away  from  pitfalls,  and  to  show 
off  those  eureka!  moments  that  make  systems  work  rewarding. 

This  first  appearance  of  Doctor  Dobb’s  Clinic  has  used  up 
all  the  material  we  have  at  hand.  It  can’t  appear  again  until  we 
have  more  things  to  tell.  Where  will  that  material  come  from? 
From  you,  the  readers,  or  not  at  all.  The  requirements  are  very 
simple,  much  easier  than  those  for  an  article. 

Write  to  us.  Describe  your  discovery  or  technique  in  a 
couple  of  pages,  in  any  format  you  like  —  so  long  as  we  can  read 
it.  Don’t  worry  about  being  “literary.”  Don’t  bother  with  a 
tutorial  introduction  for  the  novice  reader;  this  isn’t  a  column 
for  novices.  Do  include  a  daytime  phone  number  so  that  if  we 
have  questions  we  can  call  you. 

The  items  that  follow  are  examples  of  the  kind  of  thing  we 
think  the  Clinic  should  contain;  if  you  think  differently,  send 
us  what  you  have. 


Getting  ’Round  DDT 

DDT,  CP/M’s  degugging  tool,  can  be  started  against  a 
program  file  from  any  drive  by  naming  that  file  as  the  command 
operand.  For  example, 

A>ddt  b:  first  .hex 

will  load  DDT,  which  in  turn  will  load  FIRST. HEX  from  the 
B-drive.  Once  it’s  started,  DDT  doesn’t  want  to  load  further 
program  files  from  any  drive  but  the  default  one.  You  can  try 
it: 

— ib:second.hex 
—  r 

but  DDT  will  insist  on  searching  for  SECOND. HEX  on  the 
A -drive  (or  whatever  the  default  drive  currently  is). 

DDT’s  R  subcommand  uses  the  default  File  Control  Block 
(FCB)  at  5Ch  to  open  and  read  the  file.  The  I  subcommand  is 
just  a  way  of  initializing  that  FCB  with  the  name  and  type  of 
the  file  to  be  read.  The  problem  is  that  the  I  subcommand 
ignores  the  drivecode.  It  always  leaves  the  drive  number  in  the 
FCB  set  to  OOh,  meaning  “use  the  default  drive,”  regardless  of 
what  drive  you  said  to  use. 

The  S  subcommand  can  be  used  to  circumvent  this  irritat¬ 
ing  restriction.  Use  it  to  set  a  drive  number  (1=A,  2=B,  and  so 
on)  in  location  5Ch: 

-isecond.hex 

-s5c 

005C  00  02 
005 D  53  . 

-r 

Now  the  FCB  is  set  up  to  search  the  B-drive,  and  the  R  sub¬ 
command  will  find  the  file  you  want. 


A  Handy  Approximation 

We  are  working  on  a  kid’s  game  we  call  “Flea  Circus.”  In  it, 
a  bunch  of  fleas  (spots)  hop  randomly  around  the  screen.  The 
player  controls  a  spider  with  an  endless  appetite  for  fleas.  The 
object  of  the  game  is  to  maneuver  the  spider  onto  one  flea  after 
another  until  they’re  all  eaten.  To  make  the  game  harder, we 
want  the  fleas  to  avoid  the  spider  by  hopping  harder  when  the 
spider  is  nearby. 

But  what  does  “nearby”  mean,  in  the  terms  of  the  pro¬ 
gram?  Spider  and  fleas  are  represented  by  screen  coordinate 
pairs  (h,v).  A  flea’s  distance  from  the  spider  could  be  comput¬ 
ed  with  the  Pythagorean  rule: 
dh  =  abs(  h(flea)  -  h(spider) ) 
dv  =  abs(  v(flea)  -  v(spider) ) 
d  =  squareroot(  dh*dh  +  dv*dv  ) 
but  that  would  mean  several  floating-point  operations  per 
fleahop,  and  we  want  to  support  a  lot  of  fleas.  We  need  a  fast 
approximation  to  the  hypotenuse  that  can  be  done  on  integer 
values. 

And  we’ve  stumbled  onto  one.  Calculate  dh  and  dv  as 
above.  Then, 

dapprox  =  max(dh.dv)  +  min(dh,dv)/2 
That  is,  the  hypotenuse  of  a  right  triangle  is  approximately  the 
sum  of  the  longer  side  plus  half  the  shorter  side. 

We  dusted  off  our  memories  of  algebra  and  worked  out  that 
the  approximation  is  dead  accurate  when 
min(dh,dv)  =  0 

that  is,  when  flea  and  spider  are  on  a  horizontal  or  vertical  line 
and  the  triangle  degenerates  to  a  straight  line.  We  had  some 
trouble  analyzing  the  worst  case,  but  a  check  with  this  program 
reassured  us: 

FOR  DH=  1  TO  20 
FOR  DV=  1  TO  DH 

APPROX  =  DH+(DV/2) 

ACTUAL  =  SQR(DHt2  +  DV  1 2) 

ERRPCT  =  I  NT(100*(ABS(  ACTUAL- APPROX)/ 
ACTUAL)) 

PRINT  DH,DV,  ACTUAL, APPROX, ERRPCT 
NEXT  DV 
NEXT  DH 

It  would  appear  that  the  approximation  is  never  worse  than  12% 
off.  Surprisingly,  when  changed  to  shift  instead  of  divide  (use 
“APPROX=DH+INT(DV/2)”)  it  is  still  never  worse  than  12% 
off,  except  for  the  case  of  dh=dv=l.  Not  too  shabby  for  an  al¬ 
gorithm  that  uses  only  two  compares,  an  add,  and  a  shift ! 

The  Doctor  opines  that  an  approximation  this  neat  must  be 
common  knowledge  among  people  less  ignorant  than  we.  Does 
any  reader  know  if  it  has  a  name,  and  what  (presumably 
famous)  mathematician  found  it  first? 

Comments  In  Submit  Files 

CP/  M’s  Submit  command  can  be  very  useful.  It  could  be 
even  more  useful  if  there  were  any  way  to  put  comments  and 
operator  instructions  into  a  submitted  file.  But  all  submitted 
lines  pass  through  the  Console  Command  Processor  (CCP),  and 
the  CCP  has  no  format  for  a  comment  statement.  Or  so  the 
CP/M  manuals  would  lead  you  to  believe. 

Surprise!  The  CCP  has  a  comment  command  format.  If  an 
input  line  begins  with  a  colon,  the  CCP  echoes  it  to  the  terminal 
and  (apparently)  does  nothing  else.  Therefore,  you  can  decorate 
submit  files  with  all  the  comments  you  like: 


20 

200 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


:  THIS  WILL  SHOW  ON  THE  SCREEN  BUT  DO  NOTHING 
.  AND  SO  WILL  THIS. 

DIR  *.COM 

:  ..  .BUT  THE  ABOVE  WAS  A  COMMAND. 

Comments  are  also  useful  when  you’ve  tied  the  printer  to 
the  terminal  (with  control -p)  in  order  to  create  hardcopy 
documentation  of  an  operating  procedure  or  of  a  bug. 

Doc  observes  that  since  Digital  Research  hasn’t  documented 
this  feature,  they  aren’t  committed  to  supporting  it  in  later 
releases.  Does  any  reader  know  whether  MP/M  or  CP/M-86 
supports  it? 

Handling  MP/M’s  Integer  Date 

MP/M  contains  a  Get  Date  and  Time  service  request.  It  re¬ 
turns  the  time  of  day  in  BCD,  very  handy  for  printing.  It  returns 
the  date  as  a  16-bit  integer  representing  a  count  of  the  number 
of  days  that  have  elapsed  since  31  December  1977.  If  we  read 
the  manual  right,  on  1/1/78  the  date  value  would  have  been 
OOOOh ;  on  1  /2/78  it  would  have  been  000 1  h,  and  so  on. 

Now,  that’s  a  handy  format  for  some  purposes.  You  can 
put  the  date  in  a  file  at  the  cost  of  only  two  bytes;  you  can 
compare  dates  as  integer  values.  What  is  not  simple  is  the  con¬ 
version  of  that  number  into  a  year  and  a  Julian  day  number,  or 
into  a  year,  a  month,  and  a  day. 

If  it  weren’t  for  leap  years,  conversion  would  be  simple: 
just  divide  the  number  by  365.  the  quotient  (plus  1978)  would 
be  the  year  and  the  remainder  (plus  1 )  would  the  be  day  num¬ 
ber.  Unfortunately,  leap  years  foul  things  up.  1980  was  one,  and 
1984  will  be  another.  A  program  you  write  now  might  well  be 
in  use  then,  but  you  probably  won’t  be  nearby  to  fix  it  when  it 
comes  up  with  the  wrong  date.  What’s  needed  is  a  general  algo¬ 
rithm  for  conversion,  one  that  will  still  be  working  when  the  last 
MP/M  system  is  retired  to  the  Smithsonian  around  1997. 

It’s  a  darn  shame  Digital  Research  didn’t  choose  to  origi¬ 
nate  their  date  value  at  the  start  of  a  leap  year,  because  we 
know  a  cute  algorithm  for  conversion  that  only  works  under 
that  condition.  Of  course  the  MP/M  date  can  be  adjusted  by 
subtracting  730  from  it;  that  moves  day  zero  to  1/1/80.  Assume 
we’ve  done  that.  The  date  value  will  have  two  high-order  zero 
bits  until  2022.  Therefore  it  can’t  hurt  to  multiply  it  by  four 
(shift  it  left  twice).  The  average  length  of  a  year  is  365.25  days; 
four  times  that  is  1461.  The  integer  division 
(  mpmdate  shl  2)  div  1461 

is  a  sort  of  very-short-precision  float  divide  by  365.25.  Thus: 
quotient  =  (mpmdate  shl  2)  div  1461 
remainder  =  (mpmdate  shl  2)  mod  1461 
year  =  1980  +  quotient 
day  =  1  +  (remainder  shr  2) 

which  comes  down  to  shifts  and  increments,  plus  one  call  on  a 
standard  16-bit  integer  divide  routine.  If  you  don’t  believe 
something  that  simple  can  cope  with  leap  years,  here  it  is  in 
Microsoft  BASIC.  Try  it  out: 

DEFINT  A-Z 
FOR  MPM=0  TO  1462 
MPMSHL2  =  MPM*4 
YEAR  =  1980  +  MPMSHL2  1461 
DAY  =  1 +(MPMSHL2  MOD  1461)  \4 
PRINT  MPM,  YEAR, DAY 
NEXT  MPM 

This  algorithm  goes  awry  in  2000,  which  isn’t  a  leap  year, 
but  a  19-year  span  isn’t  bad.  The  problem  of  getting  from  the 
day  number  to  a  month  and  day  is  something  else  again.  Has 


anyone  a  good  trick  for  that? 

The  Doctor  is  Aghast 

We  recently  tried  to  use  the  built-in  functions  MIN  and 
MAX  and  were  astounded  to  find  that  MB  ASIC  5.0  seems  to 
lack  them.  Maybe  that  isn’t  hot  news  to  habitual  users  of 
BASIC,  but  we  try  to  avoid  BASIC  as  much  as  the  micro  milieu 
will  allow.  We  just  sort  of  assumed  that  those  useful  functions, 
solid  stand-by  primitives  in  every  other  programming  language, 
would  be  there  when  we  needed  ’em.  Who  could  conceive  of  a 
language  without  MAX  and  MIN?  Microsoft,  apparently. 

OK,  so  BASIC  doesn’t  have  them.  It  has  a  DEF  FN  state¬ 
ment;  we’ll  make  our  own.  Or  so  we  thought,  until  we  tried,  and 
ran  up  against  a  stone  wall.  MBASIC  allows  only  expressions, 
not  verbs,  in  functions,  so  the  obvious 

DEF  FNMIN(X,Y)  =  IF  X<  Y  THEN  X  ELSE  Y 
is  out  of  the  question.  And  we  can’t  think  of  any  expression  on 
two  values  that  will  always  yield  the  lesser  of  the  two  values. 
Can  a  reader  help? 

Length  of  an  8085  Instruction 

Tom  Martin  sent  us  the  following  listing,  demonstrating  a 
compact  method  of  calculating  the  length  of  an  8085  instruc¬ 
tion  from  its  opcode.  Can  you  find  a  more  compact  one?  The 
Doctor  opines  that  the  8086  would  be  rather  more  difficult.  Has 
anyone  a  solution  for  it?  ■  ■ 

_ LISTING  ON  PAGE  32 _ 

Are  you  ready? 

DDJ,  the  world’s  foremost  microcomputer 
publication,  has  been  working  for  years  to  pre¬ 
pare  its  readers  to  be  innovators,  to  lead  the 
wave  of  breakthroughs  in  our  changing  tech¬ 
nology. 

Every  issue  of  Dr.  Dobb’s  Journal  helps 
one  to  understand  the  nuts  and  bolts  of  small 
computer  systems.  We  offer  entire  listings  of 
valuable  software:  our  pages  have  included 
compilers,  cross-assemblers,  editors,  new  lan¬ 
guages,  hardware  interfaces  and  more  —  usually 
before  anyone  else  thinks  of  them ! 

Even  more  important! 

Our  subscribers  share  insights,  correspond, 
and  contribute  to  one  another’s  work,  more 
than  any  other  group  we  know.  They  treat 
Dr.  Dobb ’s  Journal  as  a  “hands-on”  publication. 

This  warm  cooperation  has  done  more  to 
refine  software  products,  and  generally  to 
advance  the  state  of  microcomputer  techno¬ 
logy,  than  perhaps  any  other  resource.  And  it  is 
available  to  you  through  our  pages ! 

For  the  straight  facts . 

If  you  are  a  serious  computing  professional 
or  enthusiast,  then  you  should  take  a  very  close 
look  at  what  DDJ  offers  you.  We’ve  been  on 
the  cutting  edge  since  1976. 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


21 

201 


Santa  Barbara 
Tiny  BASIC  for  6809’s 


DJ  is  pleased  to  present  this  version  of  Tiny  BASIC  for 
the  6809.  It  is  a  direct  descendant  of  Li-Chen  Wang’s  Palo  Alto 
Tiny  BASIC  ( refer  to  DDJ  # 5 )  which  its  author,  James  A. 
Hinds,  has  named  Santa  Barbara  Tiny  BASIC. 

SBTB  is  an  example  of  a  transliteration  of  a  large  8080  pro¬ 
gram,  and  contains  a  number  of  6809  techniques  which  should 
be  useful  to  those  who  want  to  get  familiar  with  the  6809.  The 
program  was  developed  on  an  Apple  II  with  The  Mill  (which 
puts  the  6809  under  the  hood)  and  Technical  Systems  Consul¬ 
tants’  operating  system,  FLEX. 

The  following  introductory  paragraphs  are  the  same  as 
those  printed  with  the  original  Palo  Alto  Tiny  BASIC.  The  few 
differences  in  documentation  can  be  noted  as  follows:  in  this 
version,  there  is  no  Control  O  function;  NEXT  statements  do 
not  require  a  variable  name;  there  is  no  overprint  function;  and 
no  spaces  are  allowed  in  the  input  language  except  in  GO  TO 
commands. 

In  addition,  this  program  is  completely  relocatable  on  a 
page  basis  to  any  position  in  memory.  It  requires  about  the 
same  amount  of  space  as  did  Li-Chen  Wang’s  PA  TB.  -  Ed. 

Numbers.  All  numbers  are  integers  and  must  be  less  than 
32767. 

Variables.  There  are  26  variables  denoted  by  letters  A 
through  Z.  There  is  also  a  single  array  @(I).  The  dimension  of 
this  array  is  set  automatically  to  make  use  of  all  the  memory 
space  that  is  left  unused  by  the  program.  (I.e.,  0  through 
SIZE/2,  see  SIZE  function  below.) 

Functions.  There  are  3  functions: 

ABS(X)  gives  the  absolute  value  of  X. 

RND(X)  gives  a  random  number  between  1  and  X  (inclusive). 
SIZE  gives  the  number  of  bytes  left  unused  by  the  program. 

Arithmetic  and  Compare  Operators: 

/  divide. 

*  multiply, 
subtract. 

+  add. 

>  greater  than  (compare). 

<  less  than  (compare). 

=  equal  to  (compare). 

#  not  equal  to  (compare). 

>=  greater  than  or  equal  to  (compare). 

<=  less  than  or  equal  to  (compare). 

+,  *,  and  /  operations  result  in  a  value  between  -32767  and 

32767.  (-32768  is  also  allowed  in  some  cases.)  All  compare 
operators  result  in  a  1  if  true  and  a  0  if  not  true. 

Expressions.  Expressions  are  formed  with  numbers,  varia¬ 
bles,  and  functions  with  arithmetic  and  compare  operators  be¬ 
tween  them.  +  and  -  signs  can  also  be  used  at  the  beginning  of 
an  expression.  The  value  of  an  expression  is  evaluated  from  left 
to  right,  except  that  *  and  /  are  always  done  first,  and  then  + 
and  -,  and  then  compare  operators.  Parentheses  can  also  be  used 
to  alter  the  order  of  evaluation.  Note  that  compare  operators 
can  be  used  in  any  expression.  For  example: 

_ by  James  A.  Hinds _ 

Original  Introduction  to  Palo  Alto  Tiny  BASIC  by  Li-Chen  Wang 


10  LET  A=  (X>Y)*  123+(X=Y)*456+(X<Y)*789 
20  IF  (U=l) *(V < 2)+(U >  V)*(U<99)*(V >3)  PRINT 
“YES” 

30  LET  R=RND(100),  A=(R>3)+(R>  15)+(R>56)+ 
(R>98) 

In  statement  10,  A  will  be  set  to  123  if  X>Y,  to  456  if  X=Y, 
and  to  789  if  X<  Y.  In  statement  20,  the  operator  acts  like 
a  logical  AND,  and  the  “+”  operator  acts  like  a  logical  OR.  In 
statement  30,  Y  will  be  a  random  number  between  0  and  4  with 
a  prescribed  probability  distribution  of:  3%  of  being  0,  15-3  = 
12%  of  being  1,  56-15=41%  of  being  2,  98-56=42%  of  being 
3,  and  100-98  =  2%  of  being  4. 

Direct  Commands.  All  the  commands  described  later  can  be 
used  as  direct  commands  except  the  following  three;  they  can 
only  be  used  as  direct  commands  and  not  as  part  of  a  statement: 
RUN 

will  start  to  execute  the  program  starting  at  the  lowest  state¬ 
ment  number. 

LIST 

will  print  out  all  the  statements  in  numerical  order. 

LIST  120 

will  print  out  all  the  statements  in  numerical  order  starting  at 
statement  120. 

NEW 

will  delete  all  statements. 

Abbreviation  and  blanks.  You  may  use  blanks  freely,  ex¬ 
cept  that  numbers,  command  keywords,  and  function  names 
can  not  have  embedded  blanks. 

You  may  truncate  all  command  keywords  and  function 
names  and  follow  them  by  a  period.  “P.”,  “PR.”,  “PRI.”,  and 
“PRIN.”  all  stand  for  “PRINT”.  Also  the  word  LET  in  LET 
command  can  be  omitted.  The  “shortest”  abbreviation  for  all 
keywords  are  as  follows: 

A.  =  ABS  F.  =  FOR  GOS.=GOSUB  G.=GQ10 

IF=IF  IN.  =  INPUT  L.  =  LIST  N.  =  NEW 

N.  =  NEXT  P.  =  PRINT  REM=REMARK  R.=RETURN 

R.  =  RND  R.  =  RUN  S.=SIZE  S.  =  STEP 

S.  =  STOP  TO=TO 

Implied  =  LET 

Statements.  A  statement  consists  of  a  statement  number  of 
betweeen  1  and  32767  followed  by  one  or  more  commands. 
Commands  in  the  same  statement  are  separated  by  a  semi-colon 
“GOTO”,  “STOP”,  and  “RETURN”  commands  must  be 
the  last  command  in  any  given  statement. 

Commands.  Tiny  BASIC  commands  are  listed  below  with 
examples.  Remember  that  commands  can  be  concatenated  with 
semi-colons.  In  order  to  store  the  statement,  you  must  also  have 
a  statement  number  in  front  of  the  commands.  The  statement 
number  and  the  concatenation  are  not  shown  in  the  examples. 
REM  or  REMARK  Command 
REM  anything  goes 
This  line  will  be  ignored  by  TBI. 

LET  Command 

LET  A=234-5*6,  A=A/2,  X=A-100,  @(X+9)=A-1 
will  set  the  variable  A  to  the  value  of  the  expression  234-5*6 
(i.e.,  204),  set  the  variable  A  (again)  to  the  value  of  the  expres¬ 
sion  A/2  (i.e.,  102),  set  the  variable  X  to  the  value  of  the  expres¬ 
sion  A-100  (i.e.,  2),  and  then  set  the  variable  @(11)  to  101 
(where  11  is  the  value  of  the  expression  X+9  and  101  is  the 
value  of  the  expression  A-l). 

LET  U  =  A#B,V=(A>B)*X+(A<B)*Y 


22 

202 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


will  set  the  variable  U  to  either  1  or  0  depending  on  whether  A 
is  not  equal  to  or  is  equal  to  B;  and  set  the  variable  V  to  either 
X,  Y  or  0  depending  on  whether  A  is  greater  than,  less  than,  or 
equal  to  B. 

PRINT  Command 
PRINT 

will  cause  a  carriage-return  (CR)  and  a  line-feed  (LF)  on  the 
output  device. 

PRINT  A  *3  +  1,  “ABC  123  !@#”,  ‘  CBA  ’ 
will  print  the  value  of  the  expression  A*3+l  (i.e.,  307),  the 
string  of  characters  “ABC  123  !@#”,  and  the  string  “  CBA  ”, 
and  then  a  CR-LF.  Note  that  either  single  or  double  quotes  can 
be  used  to  quote  strings,  but  pairs  must  be  matched. 

PRINT  A *3+1,  “ABC  123  !@#”,  ‘  CBA  ’, 
will  produce  the  same  output  as  before,  except  that  there  is  no 
CR-LF  after  the  last  item  is  printed.  This  enables  the  program 
to  continue  printing  on  the  same  line  with  another  “PRINT”. 

PRINT  A,  B,  #3,  C,  D,  E,  #  10,  F,  G 
will  print  the  values  of  A  and  B  in  six  spaces,  the  values  of  C,  D, 
an  E  in  3  spaces,  and  the  values  of  F  and  G  in  10  spaces.  If  there 
are  not  enough  spaces  specified  for  a  given  value  to  be  printed, 
the  value  will  be  printed  with  enough  spaces  anyway. 

PRINT  ‘ABC’,-, ‘XXX’ 

will  print  the  string  “ABC”,  a  CR  without  a  LF,  and  then  the 
string  “XXX”  (over  ABC)  followed  by  a  CR-LF. 

INPUT  Command 
INPUT  A,  B 

When  this  command  is  executed,  Tiny  BASIC  will  print  “A:” 
and  wait  to  read  in  an  expression  from  the  input  device.  The 
variable  A  will  be  set  to  the  value  of  this  expression.  Then 
“B:”  is  printed  and  variable  B  is  set  to  the  value  of  the  next  ex¬ 
pression  read  from  the  input  device.  Note  that  not  only  num¬ 
bers,  but  also  expressions  can  be  read  as  input. 

INPUT  ‘WHAT  IS  THE  WEIGHTA,  “AND  SIZE”B 
This  is  the  same  as  the  command  above,  except  the  prompt 
“A:”  is  replaced  by  “WHAT  IS  THE  WEIGHT:”  and  the 
prompt  “B:”  is  replaced  by  “AND  SIZE:”.  Again,  both  single 
and  double  quotes  can  be  used  as  long  as  they  are  matched. 

INPUT  A,  ‘STRING’,  -,  “ANOTHER  STRING”,  B 
The  strings  and  the  have  the  same  effect  as  in  “PRINT”. 

IF  Command 

IF  A<B  LET  X  =  3;  PRINT  ‘THIS  STRING’ 
will  test  the  value  of  the  expression  A<B.  If  it  is  not  zero  (i.e., 
if  it  is  true),  the  commands  in  the  rest  of  this  statement  will  be 
executed.  If  the  value  of  the  expression  is  zero  (i.e.,  if  it  is  not 
true),  the  rest  of  this  statement  will  be  skipped  over  and  execu¬ 
tion  continues  at  next  statement.  Note  that  the  word  “THEN” 
is  not  used. 

GOTO  Command 
GOTO  120 

will  cause  the  execution  to  jump  to  statement  120.  Note  that 
GOTO  command  cannot  be  followed  by  a  semi-colon  and  other 
commands.  It  must  be  ended  with  a  CR. 

GOTO  A*10  +  B 

will  cause  the  execution  to  jump  to  a  different  statement  num¬ 
ber  as  computed  from  the  value  of  the  expression. 

GOSUB  and  RETURN  Commands 

GOSUB  command  is  similar  to  GOTO  command  except 
that:  a)  the  current  statement  number  and  position  within  the 
statement  is  remembered;  and  b)  a  semi-colon  and  other  com¬ 
mands  can  follow  it  in  the  same  statement. 


GOSUB  120 

will  cause  the  execution  to  jump  to  statement  120. 

GOSUB  A*1 0+B 

will  cause  the  execution  to  jump  to  different  statements  as  com¬ 
puted  from  the  value  of  the  expression  A*10+B. 

RETURN 

A  RETURN  command  must  be  the  last  command  in  a  statement 
and  followed  by  a  CR.  When  a  RETURN  command  is  encoun¬ 
tered,  it  will  cause  the  execution  to  jump  back  to  the  command 
following  the  most  recent  GOSUB  command. 

GOSUB  can  be  nested.  The  depth  of  nesting  is  limited  only 
by  the  stack  space. 

FOR  and  NEXT  Commands 

FOR  X  =  A+ 1  TO  3*B  STEPC-1 
The  variable  X  is  set  to  the  value  of  the  expression  A+l.  The 
values  of  the  expressions  (not  the  expressions  themselves)  3*B 
and  C-l  are  remembered.  The  name  of  the  variable  X,  the  state¬ 
ment  number  and  the  position  of  this  command  within  the 
statement  are  also  remembered.  Execution  then  continues  the 
normal  way  until  a  NEXT  command  is  encountered. 

The  STEP  can  be  positive,  negative  or  even  zero.  The  word 
STEP  and  the  expression  following  it  can  be  omitted  if  the  de¬ 
sired  STEP  is  +  1. 

NEXT  X 

The  name  of  the  variable  (X)  is  checked  with  that  of  the  most 
recent  FOR  command.  If  they  do  not  agree,  that  FOR  is  termi¬ 
nated  and  the  next  recent  FOR  is  checked,  etc.  When  a  match  is 
found,  this  variable  will  be  set  to  its  current  value  plus  the  value 
of  the  STEP  expression  saved  by  the  FOR  command.  The  up¬ 
dated  value  is  then  compared  with  the  value  of  the  TO  expres¬ 
sion  also  saved  by  the  FOR  command.  If  this  is  within  the  limit, 
execution  will  jump  back  to  the  command  following  the  FOR 
command.  If  this  is  outside  the  limit,  execution  continues  fol¬ 
lowing  the  NEXT  command  itself. 

FOR  can  be  nested.  The  depth  of  nesting  is  limited  only  by 
the  stack  space.  If  a  new  FOR  command  with  the  same  control 
variable  as  that  of  an  old  FOR  command  is  encountered,  the  old 
FOR  will  be  terminated  automatically. 

STOP  Command 

This  command  stops  the  execution  of  the  program  and  re¬ 
turns  control  to  direct  commands  from  the  input  device.  It  can 
appear  many  times  in  a  program  but  must  be  the  last  command 
in  any  given  statement;  i.e.,  it  cannot  be  followed  by  a  semi¬ 
colon  and  other  commands. 

Stopping  the  Execution.  By  the  Control-C  key  on  the  input 
device. 

Control  of  Output  Device.  The  Control-O  key  on  the  input 
device  can  be  used  to  turn  the  output  device  ON  and  OFF.  This 
is  useful  when  you  want  to  read  in  a  program  punched  on  paper 
tape. 

To  produce  such  a  paper  tape,  type  “LIST”  without  CR. 
Turn  on  the  paper  tape  punch  and  type  a  few  Control-Shift-P’s 
and  then  a  CR.  When  listing  is  finished,  type  more  Control- 
Shift-P’s  and  turn  off  the  punch. 

To  read  back  such  a  paper  tape,  type  “NEW”,  CR,  and 
Control-O,  then  turn  on  the  paper  tape  reader.  When  the  paper 
tape  is  read,  turn  the  reader  off  and  type  a  Control-0  again. 

Error  Report.  There  are  only  three  error  conditions  in  Tiny 

(Continued  on  page  45) 

LISTING  ON  PAGE  24 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


23 

203 


O 

£ 

I 

K 

3 

3 

<X 

£ 

Z 

K 

UJ 

Z 

z 

Z 

UJ 

K 

0 

£ 

£ 

Q  £ 

K 

3 

UJ  O 

3 

U 

3  £ 

U 

3  £ 

> 

UJ 

£  a 

<1  UJ 

0 

X 

H  Z 

> 

0 

UJ 

UJ 

0  £ 

£ 

0 

Z 

UJ 

UJ 

K  K 

0 

ro 

K> 

£ 

K 

E 

3 

Z  <1 

UJ 

d 

£ 

K 

Z 

UJ 

0 

a, 

m 

> 

Z 

O 

<1 

•-H 

E  K 

a 

►H 

£ 

I 

K 

uj  g 

r 

> 

O 

E 

£ 

3 

z 

K  z 

£ 

4*  £ 

K 

£ 

£ 

K 

£ 

UJ 

G 

O 

<1 

O 

4*  O 

<1 

O 

£ 

UJ 

£ 

u 

K  0 

£  Z 

44  £ 

X 

£ 

O 

Q 

K 

• 

Q 

0  -1 

£  - 

4»  £ 

3 

£ 

0 

UJ 

UJ  Q  • 

0 

UJ  £ 

44  UJ 

UJ 

0 

3 

0 

85 

K 

K  K 
x  Z 

£  E 

O 

UJ  UJ 

K 

0 

Q 

£  E 

u  0 

UJ 

Z  E 

<X 

44  £ 

£ 

*■* 

Z 

0  O 

K  K 

0 

UJ 

Z  £ 

44  0  (J 

0 

U 

<1 

U  0  <1  m 

3 

I  K 

3  0 

44  0  (J 

0 

u 

¥ 

E 

£ 

K  £ 

K  <1 

-  0 

44  3  £ 

3 

£ 

I 

E 

(J  UJ 

*-•  K 

44 

U 

O 

I 

UJ 

3  0 

<1 

44 

Q 

U 

<1  K 

¥ 

z 

44 

> 

Z 

I 

►1 

44  h~ 

£ 

UJ 

<x 

U 

£ 

UJ 

44  <1 

£ 

O 

z 

44  Z 

Q 

z 

►H 

44  3 

0 

44 

m 

**  «* 

UJ 

♦* 

«»  «» 

«*  £ 

44  O 

a 

> 
<1 1 
0  . 


o 
U 
K  K 
4  CD  <1 
4  £  Q 

ii^ 

4  (D  £ 
4  K  Z  K 
»  CD  £  CL 
4  d  3 
»ILh(D 
i  Ui  O 

>  <r  q 

185? 

4  »-* 

>  (0  3 
»  Ui 

>  u  £ 

>  ¥  <t  d 

»  JO.  z 

»awu 
i  z 

>  0 


;  x 

!s 


>  > 
-  oi 


d 

a 


44  0 

:v 
»  *-• 

*  K 

>  d  (0«O 

<i  <z  £  a  h  »  r 

uj  a  r  uj  <x  « 

JJUStttl 


£§ 

d 

j  1  tn 

)  8  u  £ 


0  0  0  o 

h-  h-  K  O  0 

3  3  D  K  . 

Cl  0-  Cl 


UJ 

s 


cm  d  *  3 
>0  £ 


K  K>  <1  0 
_  -  *  £ 

•  <1  • 


_  £  UJ 

U£UO3ddd0K 
4  Jt-U.UQ£Ox0 
£  CL  D  JlDJlilh 

i  0  u  o 


a 

z 

-  0 


I  U  £  CJ 

d  3  K 

£  £  D 

«•«•«•«  (S)  u  o 


*-*  0 

Z«M 
d  K 
£  £  ~ 
•-  0 

£ 

O  UJ  H 
£  0 
UJHU 


£ 

ui 

o  u 

-I 

*s 

i  £ 

u  ~ 


0 

D  _ 
rj  _j  u 
u 


i  uj 


uj  k 
0  z 
•i  u 

Ik 

¥~ 
K  0 
O  - 


U 


0 
<1 

w  **  a 
£  «* 

**  £ 

82° 
♦*  K 
**  0 
**  £ 


44 

M  3 

z  z  «* 

£ 

44 

£  0 

UJ  £  UJ  £  44 

U- 

44 

Z  UJ  <Z 

£  3  £.«  1  # 

0 

44 

£X0U0K®OK44 

£ 

44 

3  £ 

£  UJ  £  •  UJ  <4 

• 

2X 

H  h  0 1  ? 

•  £  •  #  £  44 

44  K  £ 

0  »  3  5 

[  K  «4  O  O  X 


r  e 

10  S 

Ui  O  4 


J  X.  f —  nuuxuiuiiu 

!(-4«£hU£UQUJ 
I0£«  ¥  Jffi 

sss 

si 


<t 

51 

u  u 


«*  <1 
«*  3 
«*  UJ 
**  £ 
UJ  ** 

Z  «* 

®  »  K 
m  £ 
•*  <1 
**  K 
**  0 


S 

K 
'  0 


+ 

M 

m 

m 

in  u 

0  -  n 

CM 

Q 

;  *r  ^ 

in 

v4 

O  0 

Q 

0  0 

CM 

<x 

CM  £ 

0  Q 

£  Q 

O 

*  0 

O 

NN£N 

W  (h 

0 

O 

-•  m  m  - 

in  m 

M 

<1 

0  CM 

K)  0 

U 

ui  h  in  n 

<X  UJ 

O 

CM 

^■>00 

m  in 

m 

m  >0  >o  >0 

•0  *0 

N 

N 

N  N  N 

0  0 

0 

0000 

0  0 

O 

O 

OOO 

£ 

£ 

UJ  UJ 

0 

£ 

O  CM  Q  0  0 

O'  0 

£  £ 
a  <1  0  K)  ki 

CM  O  O  0  £ 

£  £ 

£  £  £  O  £ 

0 

>0  0  >0  UJ  o 

MJ  N 

>0N£h< 

■0 

0  CM  0  -•  N 

CM  a 

0  CM  fs  0  CM 

O'  0  O  £  ^ 

*'0  0' 

<1  Q  £  CM  * 

0 

N  N  N  N  0 

0  0  0 

0  0  0  O'  0- 

O' 

H  H  H  W  ^ 

OOOOO 

OOO 

OOOOO 

O 

rr- 

On 

O 

00 


*C/5 

C3 

CO 

& 

H 

CO 

c/5 


O 

3 

K 

Z 

O 

0 

z 

K 

a 

<1 

3 

3 

3 

Z 

UJ 

UJ 

z 

0 

44 

u 

44 

1 

£ 

44 

—t 

O 

44 

3 

44 

44 

> 

3 

44 

0 

3 

44 

O  -H  O 

►-* 

44 

Q  •£  0 

u 

E 

44 

O  ►=  O 

44 

0-00 

0 

UJ  0 

44 

UJ 

-  *  O  K  * 

1  9 

44 

3 

»  ♦  K  + 

0 

K  Z 

44 

0 

-  £  O  O  £ 

*  *”• 

44 

<1 

-  E  0  0  E 

E  UJ  <X 

44 

44 

44 

K 

•8  •£  K  *  ’  K 

♦*  K  V  K 

£  > 

44 

K 

O  <1 

44  O 

O 

£ 

44  CC 

E 

£ 

O 

0 

44  U 

K  0  Q 

U 

K 

0 

U  CJ  0  U  U  0  Q 

Q  UJ 

44  <X 

UJ  K  Z 

<1 

UJ 

£ 

£  U  Q  £  U  Q  Z 

UI  £  Z  <X  0  Q  Z 

3 

UJ  E 

44  E 

0  £  UJ 

E 

0 

O 

«  u.  U.  «  U.  U.  UJ 

0  O  UJ  E  T  £  LU 

£  n 

44 

O 

UJ 

44 

Z 

3 

>  > 

44 

£ 

UJ  4 

C. 

Z  0 

44  0 

5 

UJ 

J  £ 

£ 

0 

44  K 

£ 

£ 

u 

44  <X 

UJ 

UJ 

E 

d  ~ 

44  4 

4  44  44  « 

4  44  £ 

£ 

44  1 

K 

K  44  Q 

£ 

UJ 

3  U  £ 
d  £ 

e  £  □ 

O  0  v 
£  Z 
£  UJ  O 
_ J 

k  a  k 
u  <r  3 
0  -  £ 
£  £  K 

^d  D 
>  O 


3 

£ 

K 

3 

I  U  Z  ® 

•-  -  CD  D 

'  £  3  £  0 

UJ  £  □ 
E  £  “ 


0 


2§fe 

£  U  K  ~ 
O  O  0  0 
£  K  d 

0  0^0 
UJ  K  O 
U  Z  K  UJ 
d  -  > 
3  O  A  « 
£  £  I  0 


d 

£ 

Q 
K  UJ 
O  U  0 
0  UJ  0 
O  £  UJ 
0  -<  U 
Q  U 
£  <1 

O  > 

0  Ui 

0  a 


o  i  ~-CMCMo«*CMCMrMrMCMCMCMrMrMrv« 


ui 

.5 


z  a 
□  Z 


UJ 

0 

<r 

£ 


♦*3  0 


_  0 
<!£*-« 
0 


0300000O0000000fflff|mX)«» 

£OErrrEOErrEErEErta* 

OUJ£££££UJ££££££££££UJ«* 

4* 


0  UJ  0  D  UJ 
u  UJ  0 

0  4ZU14 

£3hK1 
Ui  £  K  > 

■  UIDOh 
£  O  U 

£  CM  UJ 
UJ  0  £ 

^£3>- 
£  <1  0  0  Q 


8 


O 


-o 

S 


o 

o 

o 

o 


O  -  (N  *  >0 

o  o  o  o  o 
Q  o  o  o  5 
o  o  o  o  o 


<i  g  <t  ^  ui  o  cm  *  o  m 

6006600000 
o 000000000 


24 

204 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


►  o 
'  z 

►  <r 

► 

►  0  l 
■  01  . 

►  UJ  ■ 

■  0 

■  Q 

►  o 

►  <1 


r 

0 

0 

D 

<1 

0 

K 

0 

0 

0 

-J 

Q 

B 

U 

Q 

<r 

<1 

X 

> 

0 

0 

> 

0 

-i 

X 

X 

-1 

<t 

<t 

X 

«* 

u 

<t 

n 

<1 

z 

O 

m 

0 

h- 

I 

m 

Q 

H 

h 

m 

Q  O 

h- 

0 

— 

0 

m  X 

0  O 

0 

3 

0 

»  O 

O 

0 

<1  -J  0  K 

*-<  CD  D  <X 

0Z<»H>h.Z> 
«  0  *  0  _J  CN  >  . 

>  —  #00#h  — 

Ife 


D 
»  x 
<x  . 


II 

D  - 

K  CO 


«  <1 

«•  a. 

**  0 


»  Ui 

Zti 

«  <r 


:  q 
0 


5  <1  Vi.  q.  x  UJ  Q.  Ul  Q  H  <X  <1 

£O(OO[LlJJtJ0CQUhC(JK*Z  Cl(tx><l(i.o<iM5£L0><rj 

0  3U0E00000Q_J<ICDUJ<X»<I  ZEdlQhQEUQIQClijQQQ. 

o(Offiaiuffij<[ZJjUQ:j(Dirtt  dDnJui  job  jujuS  jjb 

•  u  n  n 


>  <X  <X  x 


2  * 
U^n 

O  z  0 

0  0  «t 


&c 

3 


0 

z 

-J 

a 

<i 

Q 

0 

t- 

0 

D 

O 

0 

_J 

h 

3 

H 

<1 

0 

I 

X  X 

> 

> 

> 

Z 

U  > 

U  H 

0 

0  OQ 

— 

K  0 

K  0 

¥ 

r 

Q 

<1 

<1  0 

<1 

0  0 

Z 

0 

e  m 

E  0 

0 

0 

<1 

<1 

0  oq 

O 

O 

O  0 

I 

-  <t 

0  0 

0 

E 

O  0 

H 

0  Z 

H 

0 

Z 

0 

0 

0 

0 

K  <1 

O  0 

0 

« 

0 

<X  — 

0  0 

0 

O  K 

M 

-J 

X 

Q  K 

o 

CJ 

^  Z  - 

—  •  h 

0 

0 

iC  K 

» 

0 

H 

O  D 

0  0 

— 

U  x 

M 

> 

«I 

O  O  0 

0  0 

¥ 

0 

2  44? 

«» 

<1 

E 

J  0  - 

>  0 

0 

0 

ffl  z 

«* 

0 

0  0- 
♦+  x  CJ  >  u  ♦  U 
w  w  -  0  >  x  H-  .10  .*100X0 
0mO  .  ..u  —  x  —  .  x  .  .  x 
<X  v  •-»  O  O  O  -I  I  UJ  I  *  0  O  O  0 

o 

H 

<1  <1 


<1 

>  z 

5^ 


►  u 

t  0 

»  x 
M  0 


Cl  0 

•f  U  >  0  u 

X  H  +  0  >  -  X  rv  Cl  X  0 

.  U  x  x  .  *  ... 

O  _J  .0  —  l  0*000 


>  >  <1  X  X 

<I<I<I.J<I<ICDO<X<tx04 

QQCOCl00QZ00J— 

jo  j»  j  j  ja  j  juur^ 


x 

0  (N 
M  X 


>  Ol  1!  «  cc  111 

-  0 

-J  X  A  0  UJ  Z 

u 

Q  Z 

<1  0  X  »  X  M  O 

- 

x  O 

5  H 

<1 

Z  0  0  0 

0 

O0I000h-<X 

0 

0  G 

—  00  —  0000 

0 

rn  0 

0Q0QZffiffiOi 

I 

CD  CD 

0 

U 

0 


Cl 

U 

0 


0 

X 

Cl 

x  X 
0  CL 


N  O  <1  0  CD  0  — 
Q  ^  0  O  h  O  N 


>0^-0 
U  O  0 


Qomr^-u-CDooou 

0CDrsjCN0(NK)**W0 


o  <i 


(M8QU.H«inND(Ml)QU.Omfi 

oooooooooooooooo 


LL 

c^«*-^roo«i0N00ffi<ou  oinou^0*r0Qm*r 

NL.0C0U.h.K)NO0(DIi.  CD  0  0  U.  f\J  K»  CD  N  00  0  0 

Q0O«O  —  r^NJCD-O  —  NOO^  *00>0<X  —  —  >0*  0  000' 
o><i-<i«(N<x(N«mcN-«CN<iN<iCNKiKi0mK>ro<iK) 

>o®<ia0-winrvO'CDaocN*'Om<iu0ocN*m<iu 

ffi0ffiffifflUUUCJUCJUQOQQOQQQ000000 

OOOOOOOOOOOOOOOOOOOOOOOOOO 


Q  0  O 
0  CN  CM 


ou.-if)inN> 

0000000 


o  r» 

0  CN 


0  CD  Q 
0  0  0 


oooocoo  ooo 


0  0 

SPACE  FOR  TABLE 

0  Z 

E  O 

0 

<1  - 

O 

Z  H 

<1 

0 

Q  (J 

K 

Z  O 

O 

ij 

-1 

?  >  > 

0 

O  -  CD 

> 

CJ  D 

<t 

G  0 

0 

0  0  — 

-1 

O 

Z  0 
0  □  _J 

<Z  X  »- 

»-  u 
O  0 


O  0 


i^x 

—  0  H- 

<x  a 

K  O  O  : 

Z  U  H  0 

o  Z  X  X 
u  X  -  0  0  X 
-  10  0 
O  0  0  :  O  _J 
X  0 

0  I-  —  O 
0  XX 
<l  a  >-  u 
X  z  Z  <1 
<r  0  z 


0 

a 


5!S 


O  0  H 

O  A  4 
—  A  4 

»  o  •  *  < 


0 

> 

X  <1 
0  X 
0 

0  _l 

Sd 

~  3 

I 

:  a  x 
:  0  0 

Q  0 
O  E 
u  D  * 
z  o 

-  I  X 
—  Z  0 
U  o  N 


0 

0 

K 

o 

K 

0 

0 

Q 

z 

X 

K 

K 

Q 

3 

0 

0 

* 

1- 

□ 

> 

2 

0 

0 

E 

II 

Z 

0 

U 

CD 

h- 

5 

0 

0 

<1 

* 

I- 

Q 

u 

□ 

— 

I 

K  % 

H 

o 

0 

3 

u 

Z 

u 

—  o 

-J 

<1 

0 

# 

□ 

<1 

0  H 

E 

S 

CD 

_J 

Q 

3 

<r 

y- 

-  <1 

o 

E 

I- 

z 

z 

0 

Q 

z 

□ 

i 

X 

Q  -J 

□ 

M 

E 

0 

o  > 

0 

z 

Z 

<1 

_J 

K 

0 

D 

0 

O 

0 

5 

I 

<r 

0 

0 

<1 

Z 

0 

1-  E 

1- 

Z  »-* 

u 

»- 

0  3 

> 

D 

E 

O 

0 

<1 

Z  D 

0 

0  Q 

u 

0  <1 

o 

h 

X 

D 

o 

<1 

o 

I 

0  U 

0 

«•  m 

1- 

<1 

r- 

5 

o 

0 

Z 

K 

X 

1- 

U 

E  U 

— 

0 

Z 

0 

i  □ 

f- 

0 

0 

0 

CJ 

0  <r 

CD 

-J 

0  0 

0  — 

0 

® 

0  0 

CJ 

« 

H  K 

<1 

II 

0 

0 

0 

0 

U 

CD 

0  0 

0 

0 

0 

0 

E  Z 

Q 

0 

0 

« 

I- 

r 

> 

U  K 

0 

O 

D 

E  E 

E  Q 

8 

K  Q 

OC 

*» 

0  K 

h  O 

-J 

O 

X 

— 

3 

<1 

Z  0 

I 

□ 

O 

—  — 

-  Q 

K 

o 

0  z 

« 

3  E  • 

0  U 

O 

U 

H 

u 

X 

CD 

0 

-  0 

u 

>- 

Q 

»-  1- 

K  <1 

0 

z 

0  <1 

Q 

M 

Z  H  0 

> 

—  0  z 

1-0  0 

> 

<N 


CL 

o 

s: 

© 

•© 

Lt 

3 

3 

c 

o 


s?z 


K  H  0  H-  i 

0  0  0  0  4 

0  0  O  0  i 


0 

_  <1  o 

D  0 

1-0*1 
0  H  K  0 

0  1x00 
H  0  Z  _J 
0  K  0  U 
E  Z  _l 
D  0  Z 
Z  -I  -  <1  E 
H-  D 

0  Z 

J-  H 

0 


-J  K  H 

ffi  b  b 

ZOO  03 

XX0OE  E  >  00OO 
*  D  O'  D  .  .  .  #  X 

- *  <r  *  -  *  a 


.  .  —  -  _j  cr  _j 

O  Q  v  *  Z  *  Z  i 


0 

O  3 

•f  0  -  0  O 
0  O  -Z  0  X 
*tOK0. 


<L  0  <X  <1  >0  q.  _ _ _  _ 

00I0CDO0  —  <riUQ0  —  «J-I_J_JQ_I_JOUQ_J0CJ 
_J000O«JEX00ZQEX0O0OQ0OQQH00U 
(Jh(Lr10ffl(JffiJlLHJcj(Ii4(i:^0a«0550Ejii. 


0<I0<IQ0<I0<I  0 

JJJJOJJQUQJ0U 
ifi  n  rn  n  n  (n  n  o  u  m  r  i 


U 
0 
-  3 
0xo 
.  .1 
k>  a  a 


0  0 
H  -J  0  H 
0  D  >  <X 

K  0  0  0 


3 

O 

I 

a 


3 

o 


~  Z  0  0 
10  0  0 
0  U  _J 


U  0  h-  x  O  <1 

_  Z  X  D  0  u 

O  0  U  0 

►—  0  Z  o 

O  “ 


0 

1°  - 
-00 
K  E  0 

O  <X  > 
U  0  0 
0  3 

x  Z  O 
0  O  I 


0  O  K 


¥ 
0  u 
0  <X 
O  0 

0 

0  0 

$  ° 
I  0 


-cl 

ll*0ZQh>0i 
»  .D  #  0  .  *  D 
>  CN  0  #  0  —  CN  0 


U  0  <X  <1  >  0  «I 

»“<I00lO<xa0 
000EZ000 


n  o 
o  o 
9  ° 

K'  O  O 

O' 


9  ° 
o  o 
o  © 
o  o 


H(N«r-0  o 
O  —  NK>CNOCNfNO*0'0O  — 


K' 

N 

O'  N 

o  ©  «r  «i  in 

0  O  0  Q  O 

0 

<r 


K)  *0  CN 
*0  O'  0 


000*OOIO  —  CN  —  <tUU  —  CN(DO'CDO'K»0O'fflO'Q«rs*0aQinO' 
KtO'®CN(DCNKiKl>O0mCNyi*fin«t0in^000(N  —  ^-O-OKifN 

O  —  Nff'O(D<IU0OrH'CCDCUQ00©NK)^'O(DaL)0Kjff-O(D<I 
OOOOCOO  o  O  —  —  —  —  —  —  —  -  ^  —  CS<(NCNCNCNCNCNCN(NK>KtKiK<Ki 

OQOO  OOP  ‘0  0000000000000  oooooooooooo 


<r  ^ 

0  Q 

CN  —  Q0  —  CN  — 
•O  O  O  0  (N  -0  O 


CN  N)  -  >0  -  CN  >0 
K1  -  0  CN  K>  K)  - 


QKiinoo<IU0O 


oooooooo 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


25 

205 


of  page 


«  A 

«*  _J 
**  A 
»  A 

«  *-• 

«*  A 
_  »  <1 

g:> 

i  »  • 

>  •»  A 
K  *  A 
v  »  A  z 

:e° 

»  Z  UI 
»  Cfl 
cl  «•  Q:  uj 

£  •  o  a 

^  »  A  A 
»  x 
»  ¥  A 
»  U  A 
«*  A  D 
»  It/1 
«*  U 


i 

> 


cn 

£ 


u 

z 

Z) 

Ll 


A 

s 

5 

Z 

A 

il 

>S 

e* 

QCU 


o  . 

Z  t 


z 

§ 


Q 

z 

<x 

cn 

z 

o 


Q 

z 

o 

u 

I 

u 


to 


H  K  W  K 

U  UJ  h  u 

» »-  A  v  A  » 


tO  U 
7  *  A 

A  A  A  »h- 
x  A  O  x  Q  A 
»x  »  »  *  T 
“UJU^UJ 
v  cj  *  u  a 


KAUAUlhflClh  ja  Z 
UJinUAZAWAWDE  * 

Tnmr-Iir.  t-nfi  ^-0  i—i  n 


£ 

i 


K) 

<r 

A 


*  U  H  I  t-  A 


0 

O 

x  A 

g  0. 

5  ft 

*  s 

£  § 

D 


K 

Z 


S 


is: 


^8  TxKKx**,***MO 

*?**  »  •  »H  H  H  H  (fl 

^aoj-nqqxxxao 


H  A 

ism 


2gSS222fc!3ffgIy§si 

^®JJJJJ(JAWAJ(JJA' 


0 
h- 
►  A 


Ui 

§ 

z 

I 

t~ 

£ 


* 

S 

z 


Sts 

383 

A 

rS^S; 

a“fc«a 

5S5S5 

u.  I  a.  3  U. 


•  v  Q  V  o  J  !n 


z-z2* 

8*d*d- 


lihHiidi 


£ 

K 

0 

z 


A  O  Z  0 
A  v  A 


A  A 

<1  U 
A 


Ji 

*  V  ►- 


0  X 

AAA 
0  0  0 
I  r>  _j 


•  m  a 


0 

£  to  O  A  Q  N  N 

to 

Ch  A  O  0  AO  0 

0 

o  «r  q  -o  q  <r  m 

o 

CM  O'  CM  0-  K)  to 

Q 

A 

jL^MinNitHtta 

A 

CM 

A 

CM 

AffiffiAAACJUU 

tMN(M(M(MN(MCMCM 

O 

O 

ooooooooo 

n 

m 


«e 

-  A 
N 


CMAA*O®0UOUAAA0 

0  m 

_  CM  ® 

»§° 

feSSSSggfe£3SLj£gtZ 

gggggggg£ggg£gS 


3888!£R!ig22tf 


CM 

CM 


§ 


to 

Q  M” 
O'  to 

CM  * 

0  0  A 

&  CM 

O  O 

id 

GOO 

n  A  0  CM 
„  ^  -  °  ®  ^  O 

onooAomoA 

CM 
.  (M 


ft 

* 

O 

tO  Q 

m  0 


Q  O 
O'  tO 


ogggggggggg  BBS 


to  to 

o  o 


T3 

a> 


<i 

A 

A 


0 

■  -klA 

a  A  Z  0 
•  x  o  m 


A  A  y-  A 
0  0  J  A 
X  A  A  A 


■  Ui 

•  0  A  »  m 

■  Z  0  II  A  Z 

:  O  M  *  x  Q 


A 

v 

£ 


0 

.  -  A 
v  A  0 

*  X  M 


0 

3 


0 

0 

A 


u 

gg 

A  0 


•f 

0  I 


0 

A  A  0  A 
0  0“ 


0 

A  A 


£22g  £2 


a  <x 

0  A 
A  A 


0  A  0 

A  A  0  U  Q  A  Q 

0  0  -I  Z  K  0 

I  A  A  m  0  J 


Q  « 
0  A 


0  A 

gw 


0 

0 


0 

* 

I 

u 


0 

0 

A 

O 

A 

0 

IM 

o 


z 

A 

A 

0 


a 

1 


A 

0 

0 

A 

0 


CM 

A  0 
x  » (j 
0  CM  (J 


1  «  Q  0 

»  Z  0 

s;g 

»  A 

y  »  A  A  K) 
A  »  A  A  A 
•»  H-  A  A 
CJ  «  A  □  X 

U  •  A 
«*  > 

»  0  A 
»  ^  A 


8 

0 

I 


K 

A 

A  Z 

JHJ 

z23 

A 

I 

6 

g 

A 

_  A 

Q  Q  A 

g  |  > 

U 

m 

»  I 

«  K 

A  A  O 

A  CJ 

»  •“! 

«  3 

S  O  K)  N 

5*R*:J  :jg . . 

*-•  -  A^X0xx-  A' 
0  Q  v  t  x  >  0  -  0  a  »  x  . 


x  id  «  jg  *  *  S  z  tn  «  >  o  «  >  ui 

8185  3i:3S|33t!i!&igmmS8 

A  CJ  A  CJ  ®A^UA0AAAr)UA0AA3 


0 

A 


->  CM 

Zl 

m  x 
»  0 


CM  CM 

Si 

x  x 

«  0  A 


O 

0* 

CM 

A 


fv 

<1  CM 

«f  U  A 

0-oin 

^  o  o 

o  o  o 

O 

Q  Q  O 

QUO 

Q  N  O 

CM 

0  M  CM 

0  CM  M 

0  (M  CM 

A 

^  ^  to  « 

NNCMl 

Q  Q  A  ^ 

A 

o  o  o  o 

o  o  o  o 

O  O  O  «-• 

»-< 

CM  CM  CM  CM 

CM  (M  CM  CM 

N  N  N  CM 

O 

O  O  O  O 

O  O  O  o 

O  O  O  O 

0  - 

0  CM  *4 

•H 

'OOCMCBA  -  Ah 

O  O 

0  0 

0-00 

0 

(MONNONhu 

q  n  u 

Q  U 

Q  u  «r  A 

A  « 

Q^Q-«O^QK) 

0  cm  m 

0  0 

0  <t  Kj 

m  to 

0KjO'0CMK)00 

to  in  n 

0  A  <Z  U 

Q  IL  h  K) 

«r  in 

NO'fflQA^fOin 

NCMNCMCMCMCMCM 

oooooooo 


CM  M  N  M 
O  O  O  O 


CM  CM 
O  O 


OCJQ0^U'OCN<«tA 

ILCMNONOOIO05S 


•QtUMCMO 


r;  m  ru>(  r)  rj  r>  n  n  M  K)  K)  ^  <  «r  ^  t 

WS!)t)N!!NN'NnNNf,nNNNN 

ooooooooooooooooooo 


in 

to 

Q 

+ 

CM 

o 


0  o 
~  o 


q 

®  n 

A 

«r  in 

CM  CM 

o  o 


26 

206 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


0  H  O 
Z(-Z  -  I 
-J  CL  CL  ¥  ( 

Zh5  >ui 

0  (0  U  CM  v  ( 


C  »  J  h 

0  >  «  m  0  *-  > 

■  (CCtlEiriflIMCOliiHZ 
000_J_Jfflffl*--00*-i»3t- 
in  JUUJJO)  JTQ«  E 
»  cl  cc 


*  0  A 

»(0h 
»  UJ  CD 

*  CC  0  0) 

#£LOh 

»  X  Q.  H 
¥  »  0  0 

*  X  H  »  I  *- 
lUttUhl-Q 
oq3i»:h 

H  z  H  »  O  3  CL 

0  Ui  0  *  O 

*  V  V  »  H  .  0 

»  Z  0 
»  *-  0  H 

M  CC  Z  « 
UJ  «  CL  »-  E 

a  a;  a.  »  cl  cl 

UJ  0  E  »  HO 

I  n  o  «  t-  0  u. 

«  z 


D 

r  •.* 

6  £8 
£  85- 


H  E  -I 

cc  z  0  cr  d  a 

cl  u  h  a.  z  z  z 

>xQM0MXh0  » <0  >-  —  G 


"  Vt  J  UJ  U  jz  a.UHQ.ZZ 

Q.  O  J  h  •  (£  ►  U  D  *  (£  »L)0*-  a  ••0— J0Hffl0ffl»—  »  CL  ».  ll  fr 

*  •iLVtfl.HvICtiHvEtQ.HviKIOl.VdVtdHVtt. 


0  a  >  c  > 
ft  5  <i  (r  d  m  a  oc  i  a.  uj  <i  cc 

UJOK0EZ00QCEZ00 
i_j0*^um«jnfflu®_jn 


>  <i>  a:  qc<i> 

<icc<iduj«fl:ai<nnoa:u)(ccLui<iQ:a 

00o:EZ00KQ:ffi00m0EZ00Q: 


I  w  tu  WJ  UJ  UJ  IL 

l^_jnUtt_J^GQ 


O  ©O' 

ffi  >0 

K>  Q  UJ  N  N  5 

10  0  OU«TN0 

CM  0 

_  CM  «I 

Q^IlU-NOO-hQ 

0'K>*r)--«-K>0' 

ujujotin<ja-QoN« 

HHMNN(NNf'JK)K)IO 

kOK.K)K)K)K)K<K)K)K)W 

OOOOOOOOOOO 


mj  m 

W  Q 

O^NMONMlIOONNUNONljJ'roOOIllONNONMQ 

0«O-0NM&-NaiNK)5'N0NMa>WN-NI>H(MD(S|KiQ'N 

yyyS2!3f®Su!i!0[)i^,0®cuiuoNinNO'UiijON«r<i 

oooooooooooooooooooooooooooooo 


t-t 

> 

o 

0 

0 

a 

z 

0 

0 

0 

<x 

> 

z 

0 

3 

0 

E 

> 

Q 

_J 

0 

0 

H 

-1 

a 

0 

Z 

<X 

CL 

0 

0 

-J 

> 

0 

Z 

o 

> 

0 

0 

D 

z 

0 

0 

«I 

0 

0 

0 

0 

o 

o 

o 

E 

0 

-1 

-J 

U 

0 

H 

0  0 

0 

0 

0 

0 

I 

0 

0 

<t 

0 

_  Z 

0  D 

H 

0 

0  » 

H 

Z 

-J 

«  Q  0 

x  U 

U 

0 

M 

w 

0 

H 

0 

H  »  Z  0 

0  0 

z 

0 

> 

H  » 

H 

0 

0 

0  «»  <X  0 

0 

5 

<x 

<r 

0 

0  » 

0 

0 

0 

0 

0  *  0 

>  Z 

0 

E 

0 

0  ** 

0 

•  00 

H  0  - 

m 

*  UJ 
CL.  H  K> 

*  Cl  -J  CL 
»  x  D  x 

*  UJElU 


H 

<1 

0  0 

0 

0  0  0 

0  O 

0 

-00 

ffi  0 

E 

a  x  m 

-J  ffi 

n 

-j 

0 

0 

0 

w 

w 

0 

0 

X 

X 

0 

0 

0  0 
*  UJ  0 

0  0  K;  K> 

*  0  -0  >  0  0 

VXINXH  -  x 

’  -  0  i  0  a  o  0 


0  0 
0  0  q  a  0  a  «t 

0  0  H  0  0  H  0 

I  ffl  0  0  -J  0  A 


»  Z  0  —  X  -• 

ss^g-g 

**  H  Q  *-  ~ 

»  y  z  0  -  - 


u  «  z 

0  «  D 
-«*  0 
•>  o  « 

»  0 
W  0 
»  -J 
0  0  «  Q 
n:J»z 
0  D  »  <1 
I  0  «*  I 


<10  X 
0  O 
0I-0V 
D  0  <1 
Z  0  Q 
*-100 
E  0  0  -I 
-00 
>  I  I  <t 
0  I-  U 
<X  0 

Z  I  0  0 
D  H  H  H 


Q  Q 

Z  0 
Z  0  0 
0*00 


OH  —  0  Q  E3  U  » 
-0  ON0  0O>0» 

X  D  •  •  0  <11*-  -M0 

*XQ««0Q0GQQ»D 


0  0  0  0  a  a  0  000* 

l  0QXQ0_JOQOI0_J0_|»| 
0Q0QfflDQZH000fflD**l 
i  jd  j  JdcauuLiij  j  jq.*: 


0  »  0  o 

E  **  _J 


»  0  Q 
*  O  Z 
I  *  H  <1 
O  «  0 

♦  X  M  ¥ 

♦  >  «*  X  u 

0  H  «•  U  <1 


0  0  <X  ffi  Q  »3ZE0  Q  0 

00_Jl00m0«*O0<X00OQH 
0000_1_JDE«*I0000D0 
xmm0uU0n»  3  (9  z  f*  0  0 

«*  HO 

«  0  0  0 
»  M  ffl  0 


•  0 

■  D  0  <i  m  <i 
•  Z  0  0  E  0  CJ 

-  0  0  o  0  m 
E  x  n  u  z  0 


0 

>0 

>o  «t  m 

U 

U 

q  0  di  <r  <r  -o 

*0 

-  O  0 

CM 

O  N  0  O  0  0 

0 

Q  N  N 

0 

Q  Q  h*  H  Q  O 

in 

0  -  CM  0  O 

0  0  CM  -  0  CM 

K) 

MNMM)h0OON^<I(MSQQ 
mmminincQin'0<i-o>0'0'0'0>o<o 
NNNNN  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM 
ooooohoooooooooo 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


(N  CM 

K>  Q  W  -  U  <1 
CM  *  CM  O'  O' 

0'OO't'O— 00>Offl0^'O 
UOOOOOHUOCM0O0 


CM 

u«tuNinn«-a<rQoNin 

0K>CJ-K*Uffl0W0-*-K' 

0  n  r>  >o  0  co  0  o  to  in  0  <t  u  o  k> 
'O  NNHrvNN0CDGD(DCDCOO'O' 
CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  CM  C  M 

O  oooooooooooooo 


O  K>  *0  —  0 

O  0 

Q  O 

CM  0  O  0  K) 

•r  u 

0  c 

Q  1  t  0  0  N  0 

0  K) 

Q  Kl  O  CM 

0  CM  K)  <f  m  c  o 

-  <x 

O'  «r  in  0 

m  N  O'  ffl  U  Q  0 

-  -  K)  >0 

N  H  O'  <1  ffl 

O'  O'  O'  O'  O'  O'  O' 

<1  <1  <X  <1 

<X<X<I<I<I 

1  CM  CM  CM  CM  CM  CM  CM 

CM  CM  CM  CM 

CM  CM  CM  CM  CM 

o  o  o  o  o  o  o 

o  o  o  o 

o  o  o  o  o 

(continued  on  the  top  of  page  26)  I  (continued  on  the  next 


y  u  I-*  K 3.  ? 

2  ztcnzzhuij  w Z 

o.So.ouguo3ou.&sou.- 

m 

m 

slseslssssllsl^ 


f^aisui  t 

JljJHQdKff 
-*  0  k  1 

uj  k  a  > 

JZ1ZBUI 
«  W  >  -  I 
<c  C  Ui  OK 

8S3sestsi 

0  O  _J  0  UJ  5 

*  u-*<rgS£g 

o  g  2  S «,  ¥ 

W  Kill  »~*  l 

ScD°Sf 

I  ®  0  ►-.  o  x  ' 

ISO 


‘  a- 

o  g  UJ 

k  2q>z 

t  cjss 

g  glQu 

U.  hSnQ 
*  0  n  q  0 


esgg  I 

*  v  JL.  *  v 


Sq:xw 


« 

UJ  0  Ul 


2|zVw 

-  s  g  i  g  2 

*•  JU  JJ  I 


X  Q  Q  X  X  >  <r 

UJ  Q  K  Q  K  K  Ui 
1  -J  0  _j  0  0  u 


>  GO  >  N  »  m 
»>  X  CL  x  O  I  > 
0  ‘OOO  -  I  I 
HOli.  JU.  ♦ 


<X  ><  0  0  UJ  <X  0  <X 
UJQUJCZUJKO 

J-lfflUffl  JM  j 


0«rm«ro«ro«**um*0or) 

K)  Uj 

a  2  S  5  8  2  K  £  &  2  g  8  a  £  g 

??£S22222^'0'°'0>0'0 

SSSSSSSSSSSSSSS 


UJ 

UJ 

N 

O' 

ffl  0 
tO  X 

^  m  ffl 

0  «r  * 

O  U  CN 

0  *  O 

8 

Q  tO 
UJ  0 

Q  O 

O'  ~ 

N  O  U. 

—  CD  <1 

Q  Q  O 

O'  UJ  CN 

UJ 

O 

Q  O 
O'  CN 

O  <1  CN  UJ  CD  -O 
o  *  «r  «*  u  n 


<x 

UQUJU.  Oh 
CJ  UJ  ^  <x  K) 


oooSSSgggSgSSSSSSS^^^ 


CN0H*«fu.CNUJ<X 


3¥&mS* 

8§2*SS£!k 

OOOOOOOO 


0  UJ 

*» 

«» 

M 

b  0 

z  0 

-J 

0 

;J  Z 

M 

K  0 

-1  0 

h 

0  HH 

m 

O  X  Q  UJ 

0  Z 

u  0 

m 

0  0 

z  0 

•O 

V  V 

m 

m 

m 

-  V  >  X  (D 

N  0 

,  *§e 

U.  Cl  Z 

»  5  x  0 
o 

UJ  i 
0  0  UJ  h- 

*s3u 

i 

X 


»  0  r 

m  -•  UJ 

» x  tr 


o  •  o  0  » 


uj  o  » 

0:  >  O  Q  <x  « 

UJ  Q  Q  Q  CC  « 

I  -J  -J  «  CD  • 


)  (!)  UJ  UJ  K  K 

5  &N?  +  n  2f  2 


0 

0 

0 

0 

III 

0 

g 

D 

0  9 

UJ  c 

K 

5 

0 

z  z 

0 

•-«  0 

0  - 

K 

0  K 
<1 

¥  Z 

£ 

Z 

1  ICC  UJ 

0  K  0  5 


0  D  3 

•  oc  -  • 

t  O  K  £ 

z  0  z  z  Z 

0:  .  5  ~  — J 

>  Q  0  K)  0  *  -  K 

1  *  5  q.  5  k  *141 

»K>UXhU  0  O  #  0 


CD  UJ  CD  CC  m  f a  rn  ,n 

CDJoo:icnuja:cD<ricru<X(r!j¥ 

9?^l4!tn®Z0U000fflQ_]Dm 

j  il  cn  i  d  -Jfflnfflcoa.n_j_jua.cL 


0  0  0  (D  CD  X  CD  0 

X  ®  ^  «  0  I  X  I  <t  x  0  I  <1  0 

0  ffl  3  K  0  0  Q  CD  UJ  K  K0Offl 

a._ja.0KQ._jQ._jtD  0  a.  _j  _j 


Q  U 

Q  O  •*  U  W  ^ 

N  0 

WNON'04 

Q  UJ 

0  ^  rv  «o  N  0 

O'  0 

O'  to  •*  CN  K)  N 

ffl  <1 

u  u  uj  0  to  in  n 

N  fs 

N  S  N  ffl  (D  CD  0 

to  to 

to  to  to  to  to  to  to 

O  O 

0000000 

000 

A4 

8  F 

4  >0  CN 
4-  to  * 

U  K)  O 

U  UJ  CN 

UJ 

UJ 

O  «  Q 
^  to  uj 

Q  O  O  K)  D 

0  0  O-  O'  0“ 

tO  tO  tO  tO  K) 

OOOOO 


y  x;  w  3.  ^  1 *  ~  in  in  • 

NOOO«  ■ 


fsJyUlUJOKlinKOfflQu.K)nND*fflUJO(N<'Offl«l 

0*0'0'0'0'<i<i<i<i<i<i«<rfflfflmmfflSuuuuuui 

OOOOOOOOOOOOOOOOOOOOOOOOO* 


28 

208 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


QL 

X 

0  E 

Q 

E  QL 

®  3 

2 

Z 

D  K 

E  Z 

0 

H 

Z  0 

2u 

H 

0 

ff 

0  0 

Z 

0 

0 

I 

2  Z 

UJ  -H 

<X 

0 

3 

-«  •-  C 

Z  -1 

0. 

CL 

a 

-J  -J  Q 

H 

s 

Z 

_J  * 

Z 

Q 

o 

U,  -I  0 

V 

3 

»- 

0 

X 

Z 

0 

Q 

0 

>-< 

>  QhO  x 

0 

0 

-  u 

0 

0 

0  0 

J 

_  3 

Z 

Z  0  l 

0  0  p 

2  CD 

►-« 

**  i 

x  P  £ 

£ 

X 

I  O  0 

□  0  E 

=>  X 

F 

H*  X  Z 

Z  -J  z 

K  h- 

> 

O  U  •-*  1 
Z  0  -J 

2g  8 

S3 

l 

3  < 

-1  H  0  ! 

N  HZi 

- O  liN  J  Vi 


a 

»  X  X 

H  UJ 

*  v  x  O 


ill  1  11  |i 

■  I—  I—  >-  »—  J-  H  >  K>  -f  Si 

:  x  UJ  -111  x  UJ  -  Z  i 

>o:oir»hiN<it  >iL«ii< 


ii  q  o  •  UJ 

U  0  Z  »-•  (J  *  *  U 

H00¥H<X0  0  >  <X 

S|l|1.xIh30hhMh<  +  QO  U)  <*  » 0. 
33  *UJO«J*J«J>»J  -J  --I-U) 
vttOl>v0vtG*Ut0  ••  0  0  0  (N  0  I  V 


•0  # 

<X  0  0 


>  0 

<1  0.  K  <t  >  0 
KC0UJQC 
(OUffi  J  JO 


nr  cn  u  tn  ui 

►  ttlfllhltJQHlL 

►  AU0003»-<XE 

i  Joo.h'io.ioKn 


»  o.  -«  •»  is  uj  m 

•  _|<I*-«>>Q  >  >  (0  a  (0  «  >  x  0  <I<I<I  <X  >  >  > 

*  cn  h-r<ia.  —  Q.aiDa.M<ii<iQ.ujj<ii*  Q:dcia:o(Ea.ajio(Lo<iLacLUjCio^Q: 

«  111  UUffiUlCIEJOClUiGQCZDQltt  0UJ[U00UJ0CUJlU£ljJKtUJE2CUJUJ0 

**  *-«  z>-_i_ju®u®uju®_j£L-JuacL®»  »-)_j_ja.n®r)UCDUfflUffia)u®u®ua_j'o 

"  h-  -  « 


'O 

0* 

o 

N 

' 0 

0  o 

Q 

+ 

n«jnn®ij 

U  ^  O 

Q  O  *  0 

u  Q  *■  0  <r  «i 

m  0  0  o  u  m 

0  ^  ^ 

0  -  m  m 

0  ®  0  <1  0 

U  0 

AUK) 

<i  <i 

(N  <1  « 

SO0NO0 

n  tn  * 

Q  m  q  0 

Q  O  ~  O  N  O  K) 

1-NK)hO 

hNM 

0“  K)  0  O 

♦  -  W  ^  CM  -4  CM 

£  E  2  2  £  2 

CD  CD  CD  CO  CD  CD 

*  *  «r  «r  *■  * 

o  o  o  o  o  o 


OMIOMi-HttlU 

UUUUUQQQQ 

ooooooooo 


«tlO(NMQOOMK) 


ouion«<oQ(IU 

a  a  q  uj  uj  uj  uj  000000000 

*  *■  «*  *  <r  «r 

ooooooo  ooooooooo 


0®®O«U0<X>Om0m<rOOU*K>(N<l0O' 

MJUK)®li.SOltOO^H«O-UJlil’0O«N 

x  x 

Q-«O*,QNQ**N**N-*NN**NO'0ON-*Q 

0‘K)K)K)0'tM0'QD(N®fM®N<I®N^W^r4K)0' 

UJOfO'0®^UUJO(N^>0®^UUJOK)in®<Z(J 

Ii.OOOOOOQhhh^hhhh^nn(NNN 

<rnmmmmmntninmininmininmnmmir>n 

oooooooooooooooooooooo 


It-o  h- 

x  Q  I  z 

QL  0ZttU 
D0UlM»h 

o_  *-«  >  0  »  <r 


Z  QC 
-«  OC  UJ 

-J  UJ  J- 
*-  Z 
L LZ  ~ 
O  0  O 
O  z  Cl 


Q  0  QL 

0 

Z  3 

X 

0 

»- 

0  x  *- 

U 

2 

® 

U  0 

<x 

5 

0 

H  <1  ® 

H 

Q 

2  ►“ 

0 

z 

Z  0  > 

t|?g 

9  j  o  0 
€  UJ  O  UJ 
Ot  CL  QL 


“■5  >§ 

§z 


■USI 


-  3  *  HU.*® 

i  x  (j  >  Q  s  ►hvm*-' 

**  0 
«  ® 
«*  <r 

0  cn  ui  u  « 

!dK33tn®iS^ 

l0000Hfflr>«H 


n 

CL 

UJ  K 

-I  UJ  -  UJ 
»  0  s  -J 


UJ  CL  u  * 

£  0  t-  <i  i 

uj  ®  ®  cl  * 


»-  0 

Sir  z  ql  z  o 

I§ss  ip  £ 

>v.  a.v>u.0oo®< 


®  uj  or  ®®  0  0<i®  <x 

j<L®0<ri0ujaxaXQ:Q:a0a: 
3ZUJ®00aZQ0Q0JJKKCD 
(LOI  JoQ.  Jffl  Jfl.  JO.UOUW  J 


0  X  0  0  H  n 

DUO  >  Q  Z  0  « 
J-Q0Z  •0GC<XZ«* 

UJZiO0x  ^CCCLH« 

KUJI-I  -  -  K  3  O  U.  » 
*  V0GQQ0U0V» 


sf sSgfle^gs 

*ss?i«5Si* 


m 

0  X 

QL 

Ql  » 

ft  X  O  QL  U  X  0 

□  00 

E  « 

0  Q  0  0  U  Q  E 

0  a  z 

IjBnUjU 

CD  3  at 

® 

®  QhONO<0 

u  y 

O' 

u 

o 

K) 

o  u 

0  O' 

o  u 

NQOOON'O'O'O 

U  0  0  -•  <  N  O 

<r  m 

o 

0 

O0NO0*O*O 

^  o  q  m  0  m  m 

O  0 

N 

o 

m  0 

NQ^’N'OU^U^ 

K)  O'  0  M  «I  K)  K) 

N  o 

N 

K)  O 

^O'm*^W0K)0K) 

(>uujocN<romooj 

QQQUIUJUJUJUIU.lL 

K1K1K)K1KiKjK»K1K>K) 

oooooooooo 


«*■  «•  n  u. 
0  u.  u.  u 
K1  K)  K1  K» 
o  o  o  o 


-Mnn®  dun-mnNa-daiQo 

OOOOO OO Oh-h-hhh-n 

ooooooooooooooooo 


-  <1 

O  ffi 

KM)Q«r  •O^INhU 

m«r  uoM«f  <om 


Quou.mou.Nu 

(MjJhhK)U<IhO 

K)K)mMHQU.-K)4) 

NNNNNCNCNKlKlM 

oooooooooo 


®0O'r<4OON**NU 

<rO0‘O**oou.c,J 


UJNQ^-UJUNN^JU 

dNlMNddNHNO 

®®<IUlllO(N9-0(M& 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


29 

209 


(Continued  on  top  of  page  28)  I  (Continued  on  next  page) 


z 


z 

x  E 

0 

0  D 

E 

h  z 

0 

H 

0  O 

d 

o  z 

0  H 

0  0 

Q  0 

O 

z  - 

O  o  0  d 

0 

0  J  z 

o 

0  0  0 

O  0 

M  0  D  0 

1-1-0 

O  H  H 

0  M 

>  0  0  Z 

0  d 

Q  0  0 

0t-Z 

0  Z  ffl  o 

*  0  0  d  k 

o  _j  0  tn 

«toi- 
t  d  0  a. 

z  0  u  e 

~  H.^o 


D 

D 

D 

D 

m 

f- 

D  D 

• 

• 

« 

m 

z 

>  0 

H 

U 

0 

m 

0 

0  d 

H  Z* 

E 

z 

d 

M 

u 

0  0  > 

0  -1 

0 

> 

U  "  ~ 

Q 

0  0 

n  N  O  0  — 

0  0 

0 

0 

0 

Cl  "  h- 

Z 

»  » 

-  -  0  O  D 

O  O 

O 

o 

O 

0 

d 

04  O 

(OtQQja 

J  x  J  X 

_J  x 

-J  X 

_l  X  Q  «  <1 

0 

u 

0 

0 

a  z  z  0 

0 

U  D 

D  D 

0  • 

E 

i  ■ 

*5  *  -J 

0  0  0UH 
0  d  ®  0  0  0 

0*  0* 
d  o 
>  0 

»-  Q  I 

□  »-00  »h- 

0  ¥  A 

0  - 

•  d  d  U  ¥  0 

O  H  * 

-  Q  z  >  0  Q  UJ 
.  0  »0  0  I  0  *0 

j  H-  u  -  -  I  Du- 
JvUv  —  -  U  U  Q 


-r  K  li- 

Z  X  Z 

-J  Z  D  Ui 

Q  JQ0.J-f.fH_i 
Z  HZ  »  H  >  x  x  h 

-  lL  >  0  Ll  O  0  -  *H  0 


0  Q  0  0  0  0  0  0  0  *»0_J  X  D0>£<X  £tm>0  fft  m  2  I,  ,rx  rr  ,rx  ^ 

esiii»iSaEEdhilHE£H  iSliliiaiSEia 


NU>0  — 

0  O  * 

uom'OmKiooujocjOdoooin 


HK)OIO0n0*U<r0<*0«-0»*0 

N5Q-<ninN«u(iiO|N«r'C(ri<ru 

h-^NNNNN(NNWK)MK)K)KjM 

'€-O>O'O'O'O'4'O'O'O'O'0'C'O'O'O'O 

ooooooooooooooooo 


0  <1  O'  CD 

O  U  0  «*  U  —  0 

K)  O'  n 

>  2  S  ®  P  U  H.  O'OWIliOOOM^-MNNU 

100UN0U.  ^•^■fO0O4UOON'Od»*O0 

u.  h 

d  04 

.iLKllNQHfs^QQ^^^HQ^QUQOinO 
«  —  MK)(hK)^<^UJUi0  —  KiK)0'K>0*UJUi  —  M  — 

?££2££|n2o'®Qli*fvi«i-NO'CDQ0~<r>o 
t^^^lo,r,,n,n^,n«|^'0'0'0'0'0'0»oNrsrv 
j'C'O'O'O'O'O'O-O'O'O'O'O'O-O'O'O'O'O'O'O'O  Cf 
>000000000000000000000  w 

_  m 


g;  in 

10  > 0 

owoMii«t«rootN 
NIlNh  0  0  O  d  0  <f  0 


tN«r>OMJO'Ol 

fD^K)CM^d(Md< 

dU0-K)'O0d( 

NNN00000( 

'O'O-OOvO'O-O'O- 

oooooooo< 


Z  0 

d  uj 

D  H 

o  z 


*  U  U.  z  «  0 

0  K  _l  _J  «  O 

-□-000- h0>  »  z 

*0  JU  .»  Ill  .  .  «  UJ 

tvOvttO^N  »  — 

»  0 


>  0  N 

-  » z 

O  o  0 


d  H  O  U  » 

O  >  -  Q  K>  0  2  -C  I  D  ONdnfflO.*. 

--Z  -Z0NZ  Z  *  O  -z  «#  z  .«*  . 

*Q1>£Lv«Cl  CL*vOtQ.ffit(L>» 

»  t 


2  0  0  0«Q  0  CD  d  ®  d  0  O  >  0 

0  d  0  d  d  d  d  d  H  »  Z  x  I  0  u  -I  -I  x  0  Q  _l  E  E  Q  d  X 

0000O00Hd»d  Q0Q0OO00  Q  0  O  O  Q  0  0 

j^0f)jj0jtn0i  -J  <l  _j  q  0  ®  0  h  j  0  u  U  d  j  a. 

m-  r 


0  0  0  0  0  0  1 
Q0UJ0d0  0_j0Ud0-jQ.a0dd_j< 
Q0Z000D0OUQ0DE0000D< 
_J_l0K0'-30000_irj0U0HO00< 


t-  E  0 

Z  D  U 

U  ♦  Z  d 

O  -f  H  0 

*  -J  >  0  0 

•  0  *0  V  O 

I- 

Z 


0  0  a  0  0  0  _j  i 

Q  K  Q  0  0  _l  _j  H 

_j  0  _i  0  n  u  d  < 


®0<rQ*0O4*N 

OfsQfv,OMU,ON 

^QOOM'OOWN 

0ChtN0K)0CNK)d 

lllON«<OOCUlilO 

NIOniOMIOMlOK)^ 

mnniotoioioininin 

OOOOOOOOOO 


-  d  u 

o  o  u 

04  —  H  O  0  >0  0-*<*0040'04d 

O  UJO  O  fO  O  000040^00 


UJ^'OdO‘O‘Q0 

mMUin^in-- 

—  «■  O  0  O'  d  ®  U 

ininminminmio 

oooooooo 


lOa-OHOCDONO 

OO4NOOOChK)0d 


UdMK)K)^«t  UN-O0OOOd4l^-flQin^N0dO« 
0  N  *  10  U  K>  M  U-04-  04  0‘UNinr'4GDO‘K>UN-CD04n 

0  o  C4  ro  *  n  00-K)nN00QUor4'r'O©duwo 

«•  in  r)  n  m  n  m  in  m  >0  >o  >o  >o  >o  *o -o -o  n  h  h  h  n  n  h  h  ® 

m  m  n  to  in  in  io  mmnininininininminininininin^ttin 

0000000  0000000000000000000 


—  T-1  O'  0 

o  *■  <1  ®  k 


•o  n  u  a  q  0 
u  0  0  m  ^  m 

04  +  >0  0  d  U 
0  0  0  0  0  0 
in  m  m  to  10  m 

■C-  C-  w  W  ^  w 


l 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


0  ~  0 
Ui  JO 
4-  0 

zuil 

m5oi 

StDDO 

Q  0  Ui  UJ 
Z  Z  -I 
UJ  •"*  o 
CL  4-  0 
0  4-  - 

4-0  4- 

2q5§ 

ii8E 


x  D  5 

•4-  3  0  0 
-•  x  •-<  •  - 
I  4-  X  *  N 


X  Q 

a  x  x  Q  CD 
0  4-  4-  Q  D 
JOllfljUl 


2  0  2  K  Q  i 

s 

9  a  ^  >  3 

r  gggy  | 

°  1 


)  a  a 

•  3  O  x  >  x  0  i 

•  -  *  *  i  i  *i 

-  x  •  o  •  *o  I 


:g£2£i; 

1-10-100) 


^itot 

3SJu. 

!  feiSa 

*  h  a  z 

j  >  a  o  0  x 

)  UJ  CD  O  O 
:  4-  i- 

*  0  O  O  0 

ifhfN 

:  a  0  0  z  z  a. 

4-  4-  «-«  -< 

i  55gg 


0 

+  4- 

X  >  (I)  K 
>  •  *0): 


0  x  i 

=!2?*3: 

0.  _J  0  U  A  i 


a.  o.  0  0  _i 

O  O  40 

X  >  K  Z  4- 

»»•*«*  0 


0  0 

0  0  O 

fcE 

if5i 


10  0  0 
•  »  *  (N  * 
'im- 


0 

0  0  Z  X  0  4- 
»  » »-i  |  — «  ■.  UJ 

in  o  *r  o  0 

3 


:00UO00000<I04-_|  CZ 
IOOUQOOOO-0Z00  OO 
I00A00000  -I  A  4-  A  U  U 


X 

*■«  K> 

- 

o 

0  *  0  *  N  O 
-4U4  40 

Q 

O' 

*A*0Q*CMCM*N 

*<I*UO0<I000 

0  y 

o 

CM 

O  O  O  *  ©  O  CM 
**  ©  <1  0  0  *«  O' 

a  o  o  m  <i  cm  *<  ri'O 

NWOO-OO-O  *0  >0 

CM  CM  *  O 
©00** 

40 

0 

OIL0UMO 

ixiciiKh 

N 

CM 

OO00'ON<0NOrN 

*-4o5«©«<i<i**cm 

n 

40 

m  >o  n  u  m  m  o 

40  <1  <X  «  CM  40  CM 

NQ0'O'O*4O'O,O'O'O 

4O00>O'ON0*m>O'O 

OOO^; 

40N*ON 

40  40 

*  in 

10  10  N  ^  U  111 
0*  O'  O'  O'  O'  O' 
'C  o  O  «0  'C  43 
o  o  o  o  o  o 

CM 

<1 

>0 

o 

*NO'A0OCM*«OO' 

<X<X<I<X<IAAAAA 

>0O>0-O'0J3>0>0'0J3 

oooooooooo 

06BB 

Q  0  **  40  m  N  O' 

A  A  U  U  U  U  U 
<0-0'04<0<04 

o  o  o  o  o  o  o 

ffiQ0CN*>OOO<lAUU 

uuuaoaooooo 

4)  <0  <0  4  <0  <0  >0  -0  41  <0  O 

ooooooooooo 

O  CM  *  >0 
0  0  0  0 
■4  M)  'O  O 
OOOO 

06EB 

06E9 

—14-0—1 

SD  -J 
0 


D  >  4-  W 

tl, 

O  0  2 

D  -N 

0  0  4- 

«» 

0  0 

4“  *  3  40  4- 

CL  4- 

*  s  4-2 

4-  N  (N  h 

*0  D 

«* 

0  1-  >  >0 

0^0-0 

4-  O 

=  -  CL  D 

0  CM  *  4- 

-•  #  O 

«* 

0  *  *3 

(L  1  V  *  0 

0  Z 

**00 

0**0 

*  *  V 

»  . 

>CN0>O<IOU 

0 

<X 

0  A  U  > 

•  0  0  0 


i  U.  •  U  *  ML  I 

«  0  *  v  0  O  N  0 


<1  <10 
G0  0  0  04-4- 
0  O  0  E  Z  0  <t 
A  J  n  U  A  4-  CL 


I  0  0  (J  O  <10  i 
A0Z4-4-A<I4-<I004-< 
IQ0A<I0Q00Q0-J<I< 
_jA_104-_lA4-_|'-3  U0  i 


10  0  ix  0  0 

:>0-jcx0>qoz0<i0_i<i<z00 

1Q0DQ0-JQQ0A0Q0DK00E 

.JA0J0UJJfflJfflJO0IDjiIlp] 


0  J  ►«  -J  _J00  0  CD  U  > 

000000000  *0  *000 
- o  o  - o  -o  *o  o  o  o  •  «o 

N0  J4  J-0  JB  JH  JQHtQ  J 


0  0  U  0 
QOQQQQQQOQQ_J<ZO0Q_J 
Q0*-QKQKQKQI-D020i-D 
JO0  J0  J0  J0  J00  J<II-00 


0  0  0a* 
<1  40  N  O  0 


N'OQh'OQ 

NIO-CDM^- 

0  -H  40  n  N  O'  <i 
0  O'  O'  O'  O'  O'  O' 

m  m  in  m  w  m  in 
o  o  o  o  o  o  o 


a 

O(N0O<rN4N4NQO00NNNLMI 

N-OfflP)«O«4«H0«MNO«<(hQ. 


me  p 

N  <1  <1  N 

>0  Q  O  40  4Qlt  *  O  Q  m  >0  *  0  O  U  N  O  Q  *0  Q  m  N  N  Q  0 

U  0  **  UN  00**  W-OMiKUnijjNHOoaKHMOO 

AK)inNAU*'O0ON*m  >O0AQ0^K)in0«UON*-O0<IU0 

0<I<1<I<I<IAAAUUUU  UUUUyQQQQOQ00000000 

inknminnmmninninuiir)  nininnKinininininininininininintnin 

ooooooooooooo  ooooooooooooooooooo 


DID  CD  <t  <  o  U  0  UJ  <1  0  <1  1  ts  m  CD  <0 
«C^*-O*«O*>O*'OUO'O0O*O 

UNQUQUOUQUQinNU0Qin 
III  N  111  ID  DJ  111  111  111  111  111  llJ  K)  K)  H  H  UJ  n 

ON*>O0<rU0ON*NOAQ0^ 

0000000000000000** 

mnink-)inii-iinin'0>o>o^>oo>o>0'0 

ooooooooooooooooo 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


( Continued  on  top  of  page  30)  I  (Continued  on  next  page) 


S.  B.  Tiny  Basic  for  6809’s  <co„«nued)  Dr.  Dobb’s  Clinic 


uOt*UOt00UOt00UOt«uot®UOt*UOt»UOT00U 

a0000-ff^r(r(NNni»imwUUUUQQQQliJUiiJiiJu.itu.it 

O  -  —  —  —  —  —  —  —  “  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  —  — 

xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 


NfN^Ni-NnNm«mN(nN(*ip(p.N(fi«mNi*iN(*iN(nNmN 

I  F—  ^  PO  r—  r"  r—  W  F"  f—  r—  r—  r—  F—  »—  r*  f“  F—  f—  Q  O  ^  F—  f—  O  ^  r—  r—  O 


«ff\m9\iAaiirt9iQaiQa\Q0>QaiuI0\t9ilU»UJ9>Q0iQ0\QaQ» 

r»viF-in<Fii/,tF-irtr»irtF-w-tr-'<o.-«nt/"iQmu.v^Q^<jv>Q*tOviQ,'i<J 

•xxxxxxxxxxxxxxxxxxxxxxxxxxxxxxxx 


>DUUKN-(-  u  3 

QO-i-iUZZiu  a  O’cocommmmcocDOQCQCDmcommcQcommmcQaQmcQcomcommcQmm 

IUJ««Q-.<flC  k.  UJQQQQQQQCJQQQaQQQQQQQQQQQQQQCJQQQQQ 


0  ~  Q 

5S51 


>00  f.  >  cd  in  cd  a 

q  T  a  m 


cd  cn  CD  q: 
-  -  -u 
in  in  o  z 


»  i*i 


CD  CD  CD  CD  CD  CD 

oootto 


x  a  a  a;  cd  q  ama 

JjJ«IlUQ32QjUQ:(rfflQjU£tQ:iSQxQxQ(D 
CllOOlilZQOwKiflUJJDHOJUjJDKQQhHK 
a><i<r_jflG<xw<xcn<xcDcj(Jcncn<xflD(jcjcncn.j_JcncnQ: 


o£  3 

o  3  h- 

»  -  ffl  «*  0 


O  E  X  25  Z 
©  CL  CL  ID  © 


z 

0  0 

©  <x 

K  K  CL 

x  dfi 

►  H  Q  UI 


o  >0  n  u.  m  ^ 

Il’O'OnlLO 


<1  ©  O'  O  *0  K) 
CN  <1  -O  f)  CN  UJ 

UHJONf-fl 

«r  »r  m  m  in  m 

N  fx  N  N  N  N 

O  O  O  O  O  O 


in  in  o  >o 
■O  -O  lil  o 


*  +  <T  «*  f  -h 
UJ  UJ  UJ  NJ  O  UJ 


O0«ru.U.K)Q0«tU.U.K)QUJUU.QO' 

©o(N*m<x©.o(N«rin<i©<i©<T©K> 

0<£ULUU.O(N<'O0O'<IUUJOrN«t'O 

nmininr)-0'0>0'0>0'0-oN3mrvNNN 

nnnnnnnnnnnnnnnnnn 

oooooooooooooooooo 


QIDCD<0  1iIU.m«  UJ^NfN|i|<im^-N^<|CNNmOKlF^ljLUO<''OQ 

NKi^am'OOO'  lLO(MiOfitlOfflNDaiHS|iiOdlIi(DOOOg 
<^K)K)0'0^^cNmK)in>oinF^rscN'0>o^ooN 
oooooooo  ooooooooooooooooooooooo 

CL  h-  (L  ►-  ClLl- 

Ul  «r  Z  Z  QC  CL  Z  CN  D  Zd  H  UJ  3zx 

U.^CCUKiCCUW-IttUJ^-J  hQl  JI  <1  UJ-I  Z  D  Z  Ki 
j>>uio.a.QK  i-wap  t  xrE'0OHu5«r>  nw 

QC*-«i-,xxx_jO  UlOZiOMLJJdZQIffDhjCNi-'hHlDxdd. 
(JOQUJUJUJU.Ii  Q(9HHjl2ZlLlL|[lL|lOQ;01(J)(l)0IKh>x 

So  <o  <0  K)  ii  u  ^  -oycNi>oy:ocNyu.^iL®<iyinQ'rQ>0'Ors<iQ 
cn  k>  u  m  «r  in  cd  Nt2Nyoo<-inN^oNK)3ucNujinooNU<- 

OOOOOOOO  OOOOOOOOOOOOOOOOOOOOOU.O 

_l  *  h-  Z  -J  Cl  Z  Z 

o  crujK)  jEO'O  o  <r  0  z  0  0  -« 

►-«  m  o  n  cl  ©  cn  ©  ©  _i  hhu  «  3  k  z  mao* 

¥>>a:CLCLZQ:  OC  O  Z  CL  XXKtl-OF.K)hZOWJC-hQ:N 

i-.~clxx,~,o  o_j0Q.o^ujuJDZOccD>-uj3i-*H»-zx«a. 
(jQouiujujiiu.  u.0--_jEzzoa.o.£LQ.aa:a:000i-i->x 

a)  (N  CD  U  CD  (MB  ffi  <ItOM«X)UJ<tsOOUUinujNOM'0-Ki<lai 
^U.nUJQrNK(UJ  artNUOO-fl'OF.Ou^mdDMUOOlHDNM 
ocnnio^cnf**  ^in^noK)N^CNinnK)J5inF^K)^<oo«r^NCN 
oooooooo  ooooooooooooooooooooooo 

a*-  -  K-  y  _J  — J  — J  CD 

UJ  U  CL  CN  x  z  in  H  H  E  a  ©  O  o 

u.©*oucrzffi  •-«  ►-  a  id  dii)>Jo  O' 

u.cl>cl©(lzc>  cl*  pk^fcxujna-Mi-FHizi-cN^cLzcrcN 
dhmq:xxh2  ojH(LO(DuujZzoQ:Q:K3Diiii-hr>u)i 
fflOQUlUJlUUU.  Ii0hnjj2ZO(LIL(L(LOO1C(J1(J)(OI'|>3x 

O  U.  Ui  li  111  MS  ^  ItmMB^CD^'OUJD'NOQN'O^CD'H'OlUDCN 

<iCNuj«iu.o-0'0K'inN«r©>0QCNu.^0'0'n^Ki 

OfflNffl^tN^^-  «nn(NrtrtON^<iininNin-^K)<i>ciHOF.Nn 
OOOOOOOO  OOOOOOOOOOOOOOOOOOOOOOO 

a  cl  gc  0  >  -J  0 

zw  u.  cn  z  -J  ¥  «  *  »-Q:x_i»-uj3in 

©  <X  K>  U  QC  -1  N  _  CD  >  m  0  CL  ZU.  CL  J  O  M 

UI-XLUlCi  hS  CCM3CNH10K  (N  0  CN  I-  O  Z  I-  <X  ffl  X  CN  (N 
D«Il-<Oxx«Z  OJHCLlilOUlULZZttaUlSDlJKh^XJll 
QQQUJUJUJU.U  UUl«JJZZO(LlU£LOO(i:(fl(D(DI-|-3x 

U-CNUJK)OQ'O©O©'r0QOfflQONOCNF^Uffl'OCNO'<I<la'UQ© 
uoniODiDuQ  <io^D'ffl^u«roin©'05rtNch(N^N0'®0'O^FH 
cnon^fhfh«}-<  «rinoK)*^o>o^-oininMin^inKiQ^'0'O^NCNCN 

oooooooo  oooooooooooooooooooooooo 


© 

_J 

IL  (N  ©  K)  O  Q  <0 

© 

A 

ffi 

(j  o  m  in  Q  ©  u. 

Q 

0 

<1 

N  O  N  H  H  H 

< 

H 

OOOOOOOO 

OL 

O 

-1 

Z  H  ¥ 

CL 

□ 

0  Z  X  -FH 

Z 

CL 

A 

mOCNUUI 

-1 

© 

E 

0  £  >  Q  ©  U 

s 

O 

> 

0 

K-  3  Z  x  x 

<1  U  Q  ©  ©  ©  © 

z 

© 

lOK)F^O>O^OininK)^^|OKjQ^-0'OFHNCNCN 

>0000000000000000000000 

5-J  z 

0  Z  UJ  ©  0 

<x  a.  H  K  Z  z  ?  i-  z  o  y  uj  >  ►-  © 


z 

©  UJ  0 

Q  U  ©  >  *-  CD 

©<t»t_ll-W^© 

©CLh-KUlZd© 

(I)  (Jl  ID  (0  I-  D  x  N 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


33 

213 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


§  s, 


e  »- 

Z  O 

—  <x 


S 


<1  uj  ►— 


<x  o: 

UJ  I— 
CC  X 

o 

uj  CO 


a:  u. 

oc 

—  u. 
o  o 


<Z  <X  U.  to 
h-  *:  Of-! 

co  Q;  CO 

C  O  z 
X  at  OC  a:  fr¬ 
ee  CC,  UJ  =>  UJ 

Z  U.  C  N  K  w 


co  o 

*—  t— 
fr-1  UJ 
3  cr> 


0-  o 

OC  UJ 
fr—  - 
:  CO  <1  : 


UJ  CC 
3  I  W  t  I 


J  a:  C  in 


<r  co  <r  <r  z 


■  u  a:  u  a  i 


;  _i  a.  x  »  M  *  « 

X  X  O  CD  Z  =>  I— 

i  in  (J  o  s  -)  m  id 


O  O  2  UJ 

Z  a.  o  oc 


i  x  a.  a:  •  -  l 


(Nin-ocoo-ucu. 

uuuuuuou 

uuuuuuuu 


u  n  n  a  u  n  « 
n  »  N  «  o  o 

Q  Q  u  Cl  C  C  UJ 

u  U  U  U  (J  u  u 


-^inaio-cciUJi 

UJ  UJ  UJ  UJ  UJ  UJ  UJ  UJ  l 

UUUUUUUUI 


c=t  —  rv.  O' 
MU  K  O 

p«j  m  in 
u.  u.  u.  u. 
u  u  u  u 


—  r. 


rvODcoouju. 
u.  u_  u.  u.  u_  u. 
u  u  u  u  u  u 


in  -o  r,  co  o-  o  ^  r  j  n 
O-  O'O'O'O'  oooo 
pj  pj  p-j  pj 


»  in  ■<)  r.  cd  »-  o  -  rj  m  » 

OOCDCDOO  —  — 

PJ  PJ  P'1  pj  P-J  PJ  P-J  CNJ  P-J  PJ  P-J 


*-*  o  <r  =>  x  UJ 

«  =►  =»  u.  uj  <r  t- 

i  —J  «  HUJ  ►  » 

o  <n  a  £  i  ^  a.  &  i 


x  CC  o  x  oc 
uj  K  b  u.  in  fr— 


fr-  o  O  —I  »—  Ox 

<X  ►  r  -  «  ►— <  » 

z  <r  d  c  x  o  <r  : 


I  o*  <x  <r 

!  Q  X  O  BJ  CB  LO 


■»  *»r  a.  a.  tr 


S 


h  n  a.  Q.  h  t-  c_jtnco_jf— .  iXjZ>_i 

u-*ooz>uj  =d  zd  x  x  <r  o  <x 

t->-5ft.a.*cc  -  ol.  q.  j  j  a  c  u 


*-<  O 
oc  oc 
a.  <c 


<_>  c_j 

u.  u. 
o  m  o 
—  o  »— 
-o  c_>  <r 


o  p-j  in 
ro  m  r-D 
u  u  a 


Hi  O-  <C  U  U.  O 
i*)  n  ro  n  rj  ▼ 
u  u  u  o  u  u 


«o  t*i  in  n 

in  co  o  ♦ 

<r  <r  co  <i  ca  r  j 

o  u  b  u  u  a 

•c  O'  o  c  o  n 

»  ♦  »  »  in  in 

u  u  u  u  u  u 


n  u  n  rj 


in  cd  o 
«o  -o 
u  u  u 


<i  u  u.  o  -  ro 

-o  -o  -o  r-'  r.  Tv 

u  u  u  u  u  u 


»  in  •«  O'  o  ca  t 
N  f'  r\  k  k  i 
u  a  u  u  u  u  i 


bo 

<3 

CX 

o 

cx 

2 

c 

o 

"a 

3 

C 


IT!  Q  oc  »- 
—  UJ  <Z  u- 
v  k  I  ix; 

X  u  D 
u_  <r 

=»  oc  X 
ZOO 
>-  O  *-1  CC 
ca  oc  <r 
X  Z  CL.  UJ 
«  «  CO 


•-»  z 

x  <r 
fr-  3  I 


S 


w  Z> 

X  o  lx 
CO  X  h 


*-i  tn 
►—  ►-» 
CO  o 


oa  *-!  uj  uj 


C 

O 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


35 

215 


QC  UJ 

>- 

QC  ui 


<r  x 
5  S  c 


*-•  co 

in  c 


:  *-  -•  O 


Q  D  CD  r 


s  ~  s: 


I  H  O  UJ  •— I  ( 


C  £t  c  UJ  UJ  Lt 

=  •“  X  »  a:  i- 

a.  ►-  q  u.  a. 

3>  «r  ui 

<n  in  k  o  u.  a: 


CO  Or  uj  oc 
U)  K  o  H 
UJ  a.  Q  Q. 


:  x  e.  <r  ©  X  * 


a_ 


•  r-j 


o  <r 

ir> 


o  o  m  »  u.  o- 

u->  —  o©  ^ 

—  uj  ©  ro  uj  co  eci  ao  au 

—  ©  <_>  cj  »  *  ♦  ▼  ♦ 

—  "TOO'  CJ  U_  O'  UJ  <t 

N  N  N  N  r\  N  CD  O'  <X 

oooo  o  ©  o  o  © 

iO'0-rin*in'ON«0'0^nn»in 

■r-(NfMMNNiN(MnNfjnnioror»n 


«r>  — 


—  «-  —  © 

©  ©  ©  © 

•-  m 

o  u.  ©  o 

«  O  «  -  O' 

N  CJ  PJ  ©  © 


UUUOQ 
©  ©  ©  ©  © 


?  a  °  ~  r,i  n  ^  ^  <1  ^  03  ( 
1  ^  l*^  Irt  'O  'O  -O  <C  -O  <C  'O  * 


T3 

V 

3 

e 

■c 

c 

o 

U 

£ 

* 

S 

o 

•  mat 

c 

eS 

2 

X 

w 


an 


!KI 


i  *, 

ui  \  ( 

_j  a.  : 


UHZaruji 


a 

c 

►-I 

T? 

c 

ft 

5 


lit 

O  Q 


O  -J 

to  5 


h  m  i-  h  «  i 


X  X  O 
<r  uj  m 

a:  x  « 

CD  • 


<r 

in 

»-•  z  >- 
I  a  a 
*—  oc  o 
CD  Z 
CD  O  UJ 


O  t- 
l-l  » 
»-«  C 


3  Q 
u  t-t  * 
HI  1C  £ 


QJ  O 

H  III  _  _ 

■0  05  >.  *  V-  91 

c  <c  «.  o 

ft  n  n  v  Ut 

T3  -O  <r  -j 

m  r  — 

a.  - 


1  ai 


_ 

*;  •  «%»♦*. 

C  z  o  c 

o 

•ft  mi  U 

5*  O 

^  H  O  M 

«->  ft  ©  ♦»  ♦*  ■ 


tl  £  t  3  III 


O  ft 


xinujKoinin 


Id  — ■  «X  O  ►—  I 


U  19  I 
z  o  . 
=3  QC  • 

:  u.  a.  i 


a.  cd 
\ 
•  -o 
CD  — 

"N* 

*  04 

X  o 


*  *  *  * 


Of  !-*+•. 


"D 

ft 

o 


i  •  ft  ti  ♦*  3 

:  jz  —  e 

o  o  o  c 

:  o  ♦>  u»  o  >. 

l  —  c  o  u  e 

l  o  O  U-  ft 


fS 

OX) 

s 

n 

3 


¥ 

«t  tn 


X  K  u  u 

£  .-SS 

Ui 

uj  at  in  m 
g  u.  to  to 

U.  o  O  O 


<Z  c/> 
*-  X 

5.. 


5 

s=5 


:££ 


OC  I 

«  I 

s, 


<r  x 

Z  3 

o  z 


O  3  CO  UJ 

UiU.DC 
®  «  o  u.  cm  cm 


a.  a.  a.  t—  : 


<r  3 

z  o 

O  CJ 


»-Nr)  ♦  i 


o  -  n  m  ♦  i 


Qc  0.  Ci  > 

X  ►-  z  •  • 

o  uj  O' 

CO  Ui  QC  UJ  < 

-j  a;  cb  i 


►-  cj  _J  u.  CO 
O 

o  o  u.  ■ 


X  — i  CO 

oc  j  a: 

5<t  — 

«->  u. 


=*  u.  uj  »-i  3  uj 

X  =>  _J  U.  a  oc 

oc  — ,  u  a 


X  -J  -J 

(J  OC,  1X1  I 

IP  u  u 
©  m  ©  u.  u. 


3  3  3  D 


in  il  u_ 
OC  O  h  u.  u  I 
i  a.  co  ©  z  z  cn  i 


it  n  ii  n  ii  ii  ii  ii  n  ii 

o  in  u  in  u  O'  u.  o  <r 

©  O  ITS  ■«  f*v  O  ©  —  —  — 

©  ©  ©  ©  ©  ©  ©  ©  ©  © 

©  ©  o  ©  o  ©  ©  ©  ©  © 


36 

216 


Di.  Dobb’s  Journal,  Issue  55,  May  1981 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


37 

217 


QJ 


I  Lfl  LTl  Lfl  LTl  L 

■  r-  r-  r-  c-  c 

■  f-  r-  r-  r-  r 


■  co  co  CO  h- 

»  •  CO 

>  CD  CD  ■  t- 

\  \  cd  ui  < 

:  k  h  \  o 


J  UE  l 

>  ■>  x  : 

h-  Ct:  ► 

j  UJ  O 

:  co  — • »—  cd  c 

-  ID  L*  CO  LTl  l 
-«  CO 

>  z :  co 

«  <E  .1  U  O  ' 


Lfl  CD  CD  iD  CD  CD 
*-•  LTl  LTl  LTl  LTl  LD 
CO  i7)  CO  CO  CO 

Ul  CD  O  O  O  O 


O  Mr  Mr  CO  U- 
CD  CM  *-«  CO  Mr  * 
CO  CO  CD  CJ  O  CM 


>  Ul  CD  u'l  CD  * 
•  ’f*  Ul  U'l  CO  C 
-  C-  C-  I-  £-  £ 


>  u'l  CD  U'l  CD 

>  CO  CO  CO  CD 
-  C-  £-  C-  CO 


Ul  J  ul  U  ul  U  ul  *. 

CD  —  —  CM  CM  CO  CO  • 
CO  CO  CO  CO  CO  CO  CO  < 


1  CD  -0  CD  -'I  CD  u'l  CD  u'l  CD  Ui  CD  U'l  CD  Ui  CD  U'l  CD  u'l  CD  Ui  ■ 

-  u'i  Ui  CO  CO  £■-  £  —  CO  CO  CO  CO  CD  CD  ■— «  — «  CM  CM  CO  CO  v  tt  , 

)  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  CO  • 


•ID  U'l  -ID  u'l  i~i 

j  u'l  CD  u'l  CD  Ul  CD  u'i  CD  Ul  CD  CD  — •  »-•  '£ 

-i  u'l  CD  CO  C  -  i  -  CO  CO  CO  CO  CD  ‘ID  ‘ID  'ID  LJ 

>  CO  CO  CO  CO  CO  CO  CO  CO  CO  — 1  — '  Cu 


ul  CL  O  Q  Z> 

o  o  o 

ul  ul  •— *  •  Z 

o  o  a;  cn  -x 


-«  CO  \  CO 

(VI  CO  00  CM  Z 

cm  co  co  in 


>  Z  X  Z  Z  X  Cu  _J 
|m,Ihm|EDC 

:  z  z  t-  z  z  co  o 


A*  A*  ^  '■*  ^  =*  =*  A*  &  <-• 


ezeezzzeezzzzzzzzzzzzzz: 

l.l  l.l  l.l  l.l  l.J  1 ,1  1,1  LJ  U  LI  1,1  LJ  LI  LlI  LJ  U  Lil  U  LJ  LJ  LJ  L.J  L.J  L 

XiXiXXiXXiXiXoioiaiaiuiLtiiXjiuruiXLtruruiu:; 

CO  CD  u'l  CD  U’l  CD  u'l  ‘3  U'l  CD  U'l  CD  U'i  CD  Ul  CD  ul  <3  ul  >ID  Ul  -3  Ui  CD  > 
U-.  OD  D  — •  ^  CM  CM  CO  CO  'f  M-  Ul  Ui  CO  CO  f-  £-  CO  CO  CO  CO  CD  CD  «-<  • 


i  CD  Ui  CD  Ui  CD  ul 
>  t  ’T  U'i  Ui  CO  CO 
i  CM  CM  CM  CM  CM  CM 


‘ID  Ui  ‘ID  Ui  ‘ID  Ui  ‘ID  u'i  'ID  Ui  CD  Ul  CD  Ui  CD  u 

£  -  £  -  CO  CO  CO  CO  CD  CD  •  CM  CM  CO  CO  ' 

CM  CM  CM  CM  CM  CM  CO  CO  CO  CO  CO  CO  CO  CO  CO  ( 


CD  U'i  CD  Ul  CD  Ui  CD 
U'i  U'l  CO  CO  £'—  £  -  CO 
CO  CO  CO  CO  CO  CO  CO 


Dr.  Dobb's  Journal,  Issue  55,  May  1981 


39 

219 


(Continued  on  top  of  page  38) 


Software  Review 


SCRIBE  IX 

Published  by  Friedman  Ads/Promotions 

P.O.  Box  234,  Shiba 

Tokyo,  Japan  105-91 
Price:  $200 

Reviewed  by  Gene  Head 

Well  friends,  the  software  from  Japan 
is  here!  I  don’t  know  if  the  package  I  re¬ 
ceived  is  representative  of  a  coming  trend, 
but  if  it  is,  all  micro  enthusiasts  stand  to 
benefit  greatly. 

SCRIBE  IX,  (I  presume  pronounced 
scribe-nine)  is  the  Asian  answer  to  the 
Electric  Pencil.  From  my  experience  with 
an  older  version  of  Pencil,  I  can  say 
SCRIBE  IX  is  a  direct  replacement  with 
added  features,  at  less  than  two- thirds 
the  price  of  Pencil,  and  is  delivered  as  a 
SOURCE  file.  This  source  file  is  intended 
to  be  assembled  with  a  CP/M  assembler 
and  operated  in  the  CP/M  environment. 
While  certain  modifications  to  the  source 
code  would  allow  operation  on  other  host 
systems,  I  doubt  if  this  would  be  within 
the  realm  of  most  programmers. 

Dave  Friedman,  whose  article  on  a 
video  slot  machine  you  may  have  read  in 
the  November/ December  issue  of  DDJ,  is 
the  author  of  this  fine  package.  Frankly,  I 
question  Mr.  Friedman’s  decision  to  sup¬ 
ply  the  source  code  for  this  sophisticated 
program  at  such  a  low  price.  I  would  sus¬ 
pect  the  unscrupulous  might  steal  his 
product  and  re-sell  it.  There  is  no  need  to 
even  sign  a  license  agreement  to  secure 
the  source  disk!  However,  the  price  is 
quite  reasonable  and  this  may  encourage 
others  to  follow  suit  if  Friedman  doesn’t 
get  swindled  out  of  business  before  the 
idea  catches  on.  I  can  only  imagine  the 
chagrin  of  established  software  producers 
when  they  witness  the  action  taken  by 
Mr.  Friedman. 

An  Overview 

SCRIBE  IX  is  a  complete  word  pro¬ 
cessing  package  with  features  built  in  to 
enable  extensive  mailing  list  functions. 
These  mailing  functions  include  selected 
auto  insert  from  appended  files,  complete 
with  letter  salutation  and  other  keyed- 
text  insertions.  There  are  two  subsystems, 
one  for  printing  and  one  for  disk  activi¬ 
ties.  The  screen  editing  mode  has  all  the 
features  expected  in  a  high-quality,  pro¬ 
fessional  word  processor.  The  command 
mode  functions  similarly  to  the  ED  editor 
supplied  with  CP/M. 

The  manual  is  complete  and  clear.  I 
It  took  more  than  one  reading  to  compre¬ 
hend  some  of  the  more  sophisticated  fea¬ 


40 

220 


tures,  but  I  can  not  imagine  the  manual 
being  written  any  better.  Best  of  all,  it  is 
printed  and  shipped  as  a  document.  Some 
software  I  have  reviewed  is  documented 
on  the  disk  and  the  end  user  is  to  use  the 
system  printer  to  generate  a  hard  copy. 
Another  little  extra  touch  is  the  inclusion 
of  a  summary  card.  On  one  side  are  the 
basic  editing  commands  and  the  other 
side  has  the  print  formatting  commands. 
Once  the  system  is  learned  it  is  easy  to  re¬ 
call  a  seldom-used  command  without  re¬ 
ferring  to  the  manual.  This  handy  card  is 
the  same  size  as  a  disk  and  fits  neatly  into 
the  disk  jacket. 

Screen  Editing 

The  top  line  of  the  screen  always  dis¬ 
plays  the  TAB  stop  positions.  These  are 
easily  cleared  and  selectively  reset  or  set 
to  a  default  value  of  one  tab  every  five 
spaces.  Forward  and  backward  scrolling 
occurs  between  this  static  line  and  the 
bottom  of  the  screen.  All  the  expected 
cursor  controls  are  available.  As  a  matter 
of  fact,  all  but  two  control  characters 
operate  exactly  the  same  as  in  the  Elec¬ 
tric  Pencil.  Control-H  is  a  BACKSPACE 
and  control-0  is  the  block  copy  com¬ 
mand.  Exiting  the  system  is  accomplished 
in  the  Disk  sub-system 

There  is  a  special  user-defined  key, 
@,  that  when  defined  will  output  any 
ASCII  character.  If  left  undefined  its  val¬ 
ue  defaults  to  64  decimal,  or  @.  If  de¬ 
fined  with  a  new  decimal  value,  that 
value  will  be  substituted.  This  will  be  es¬ 
pecially  helpful  for  printers  requiring  spe¬ 
cial  characters  for  custom  operation. 

The  search  mode  provides  another 
feature  not  found  on  my  early  version  of 
Pencil.  The  SEARCH  command  can  be 
initiated  as  expected  with  the  standard 
search,  or  search  and  replace.  Control-C 
is  used  to  continue  additional  searching 
after  a  string  is  located.  However,  here  is 
where  SCRIBE  IX  begins  to  show  real 
secretary-type  know-how! 

There  are  five  sub-commands  avail¬ 
able  in  the  search  mode.  A  brief  descrip¬ 
tion  follows.  I  didn’t  appreciate  the  value 
of  these  when  I  read  their  description  in 
the  manual.  It’s  one  of  those  operations 
you  have  to  experience  first  hand  to  fully 
appreciate. 

U  This  command  toggles  the  search 
mode  from  precision  to  non- precision. 
In  non- precision,  no  distinction  is 
made  between  upper-  and  lower-case 
characters.  Wild-card,  or  don’t-care 
characters  are  valid  and  held  by  the 
sign  #. 


C  This  is  the  command  to  continue  a 
search. 

R  This  is  the  REPLACE  command.  Typ¬ 
ing  this  will  allow  selective  use  of  the 
search  and  replace  function.  Upon 
viewing  each  occurrence  of  the 
searched-for  string,  individual  deci¬ 
sions  can  be  made  to  replace  or  leave 
the  existing  string  intact. 

D  This  command  will  delete  the  original 
string.  Again,  this  is  a  selective  func¬ 
tion  as  strings  are  found. 

T  This  is  a  tabulated  activity  report!  This 
will  display  all  locations,  replacements 
and  deletions  issued  in  this  edit  ses¬ 
sion. 

ESCape  can  be  issued  at  any  time,  return¬ 
ing  to  the  screen  edit  mode. 

There  is  less  than  one  page  in  the 
manual  to  describe  these  functions.  After 
several  weeks  of  using  SCRIBE  IX  to 
write  reports,  articles,  and  source  code,  I 
am  very  impressed  with  this  unique  fea¬ 
ture. 

Two  additional  features,  which  I  can 
not  take  advantage  of  due  to  the  antique 
nature  of  my  selectric  printer,  are  BOLD 
MARKING  and  UNDERLINING.  Special 
characters  in  the  text  command  the  print¬ 
er  to  perform  underlining  and  bold  typ¬ 
ing  when  hard  copy  is  finally  issued 
through  the  print  sub-system. 

One  final  note  about  the  screen  edit¬ 
ing.  When  the  control-N  command  is  is¬ 
sued  to  place  the  cursor  at  the  end  of  the 
current  file,  the  screen  is  cleared  except 
for  the  last  line  of  text  in  the  file.  This 
last  text  line  becomes  the  first  line  on  the 
display  with  the  cursor  in  the  home  posi¬ 
tion.  When  using  Pencil  this  last  line  is 
not  displayed  and  that  has  always  made 
me  a  bit  nervous.  In  fact,  I  habitually  had 
to  scroll  back  down  a  few  lines  to  main¬ 
tain  my  train  of  thought  when  using  Pen¬ 
cil. 

Printing  Sub-System 

The  most  obvious  improvement  in 
printing  is  the  ability  to  dynamically 
change  formatting  parameters  while  print¬ 
ing.  Essentially,  any  record  (a  record  is 
defined  as  all  the  characters  between  line 
feed  characters)  that  begins  with  a  period 
is  not  printed  through  the  print  sub¬ 
system.  These  records  can  contain  non¬ 
printing  comments  as  well  as  recognizable 
commands.  Basic  commands  found  on 
most  quality  formatters  are  available,  and 
then  some.  For  example  the  entire 
operations  manual  is  printed  using  the 
OUTDENTING  function.  Instead  of  each 
record  (paragraph)  being  indented  on  the 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 


first  line  it  is  outdented.  I  found  this  a  bad  disk  (wrong  density,  wrong  format,  ment  can  be  generated  by  stringing  to- 

format  visually  pleasing.  The  Emit  com-  no  disk)  is  interrogated.  This  causes  a  gether  specific  records  with  very  simple 

mand  allows  any  ASCII  decimal  value  to  CP/M  system  error  and  returns  to  CP/M  commands.  The  manual  has  step-by-step 

be  sent  to  the  printer.  I  use  this  to  ring  when  it  is  corrected.  This  mistake  will  de-  instructions  for  generating  standardized 

the  bell  several  times  when  a  page  of  copy  stroy  your  current  efforts  that  have  not  mailings  and  even  has  a  sample  file,  writ- 

is  finished  printing.  Auto  insert  will  be  been  previously  committed  to  disk.  I  ten  to  demonstrate  the  capabilities.  It  was 

outlined  later  in  the  mail  list  description,  think  there  may  be  a  way  around  this  po-  very  easy  to  follow. 

Parameters  may  be  strung  together  to  tential  problem,  but  I  have  not  researched  Second,  lists  of  names  and  addresses 

present  a  MACRO  command  list  that  can  it  yet.  I  guess  I  will  wait  until  I  lose  a  can  be  generated  and  coded  to  provide 

be  saved  as  a  file  for  standard  operations,  thirty-page  manuscript  before  I  try  to  selective  processing.  Up  to  99  different 

Page  look  ahead  allows  new  pages  to  be  find  a  solution.  codes  can  be  spread  throughout  a  file  and 

started  if  a  complete  record,  or  optional-  Files  are  saved  and  loaded  from  this  selectively  pulled  for  printing.  This  is  not 

ly,  any  number  of  lines  of  a  record,  can-  sub-system  and  can  be  destroyed  with  a  sophisticated  mailing  list  program  with 
not  fit  on  the  current  page.  Form  stops  the  Kill  command  to  reclaim  needed  sorts  and  searches  and  the  like,  but  it  is  a 

are  set  or  re-set  depending  on  continuous-  space  when  required.  Since  .PCL  is  the  solid  system  linked  to  a  remarkable  word 

fed  paper  or  individual  sheets.  only  valid  file  extension  recognized,  exist-  processor  that  will  meet  the  needs  of 

There  are  driver  routines  for  standard  ing  files  written  with  Pencil  can  be  loaded  small-  to  medium-sized  lists,  say  400  to 

ASCII  teletype  type  printers,  Qume  and  saved  with  no  conversion  or  re-  600  names.  With  the  search  and  replace 

Sprint  5,  two  versions  of  NEC  Spin-  naming  required.  However,  I  have  found  function  City,  State,  and  Zip  can  be  a 

writers  and  two  versions  of  Diablo  Hy-  that  into  a  long  edit  session,  I  want  to  single  character  when  entering  a  number 

Term.  The  source  code  for  these  routines  permanently  keep  everything  up  to  a  of  names  and  quickly  replaced  when  the 

are  very  complete  and  are  all  present  in  certain  point.  I  can  save  the  existing  file  job  is  completed  by  the  actual  string 

the  assembled  object  module.  They  can  and  use  the  Rename  command  to  protect  prior  to  printing.  This  can  conserve  a  lot 

be  selected  through  a  printer  ID  com-  it  from  further  tampering  by  careless  of  disk  space.  Memory  size  is  important 

mand  in  the  print  sub-system.  If  your  saves  and  loads.  I  wish  the  Save  command  in  this  area,  as  inserted  names  and  ad- 

printer  supports  proportional  spacing  this  would  first  issue  a  control- B  to  put  the  dresses  must  be  appended  at  the  end  of 

value  is  also  dynamically  selectable.  cursor  at  the  beginning  of  the  text  the  form  letter.  They  are  not  retrieved 

The  nicest  feature  of  the  printing  BEFORE  EVERY  SAVE  command.  More  from  disk  as  needed,  but  rather  reside  in 

sub-system  that  my  Pencil  lacks  is  the  than  once  I  have  Saved  before  homing  the  memory  at  the  end  of  the  standard  text, 

ability  to  view  on  the  screen  exactly  what  cursor  to  the  beginning  of  text.  I  have 

will  be  sent  to  the  printer.  This  view  fea-  never  lost  anything  because  I  have  always  What  About  This  Source  Code? 

ture  saves  paper  and  frustration.  noticed  the  mistake  early  enough  to  fix  There  were  only  two  lines  of  code 

With  my  old  Selectric  it  is  impossible  the  damage.  My  pilot  friends  tell  me  there  that  needed  to  be  adjusted  (*)  to  make 

to  properly  comment  on  the  printing  are  two  types  of- retractable  gear  flyers:  the  object  work  on  my  machine.  The 

capabilities  of  the  sub-system.  When  those  who  have  landed  with  their  gear  up  code  looks  something  like  Figure  1 . 

combined  with  one  of  the  many  newer  and  those  who  are  going  to.  I  suspect  an  Of  the  three  screen  sizes,  only  one 

printers  SCRIBE  IX  supports,  I  can  only  applicable  corollary  exists  here.  can  be  selected  TRUE.  Second,  the 

imagine  (dream?)  the  full  capacity  of  Clearing  the  text  buffer  and  clearing  VIDEO  SCREEN  ADDRESS  equate  had 

SCRIBE  IX.  before  and  after  the  cursor  are  both  sub-  to  be  set  to  0F00H  for  my  IMSAI  VIO-C 

system  commands.  The  “X”  command  card.  These  values  are  tested  during  con- 
Disk  File  Sub-System  begins  an  exit  to  CP/M  with  the  prompt  ditional  assembly  and  the  proper  object 

Control-K  exits  the  screen  editor  and  “All  text  saved  ?  (Y/N)  ”,  Fortunately,  code  is  generated,  depending  on  the 

enters  the  disk  sub-system.  An  ESCape  I’ve  never  missed  here.  It  seems  fool-  system  configuration.  The  code  assem- 

will  return  to  the  screen  editor.  In  the  proof.  bled  flawlessly  and  the  object  module 

sub-system,  several  functions  are  avail-  _  ...  worked  the  first  time  out. 

able  and  two  important  parameters  are  Supporting  A  Mailing  List  There  is  a  second  source  file  to  make 

displayed.  Both  the  percent  of  disk  space  Using  the  auto  insert  command,  two  the  Northstar  Horizon  vector  interrupts 

currently  used  by  existing  files  and  the  functions  are  available  that  will  make  operate  the  SCRIBE  IX  at  maximum 

percent  of  RAM  buffer  currently  occu-  standardized  letters  and  mass  mailings  speed.  My  non-Horizon  Northstar  system 

pied  by  text  is  displayed.  This  lets  you  quite  easy.  uses  an  old  George  .Risk  keyboard  and  a 

know  when  your  disk  is  filling  up  and  First,  standard  records  or  paragraphs  very  slow  strobe,  and  I  see  no  sacrifice  in 

when  you  are  running  out  of  RAM  for  can  be  given  pseudo  names.  Then  a  com-  speed  without  the  interrupt  feature.  May- 

the  current  file.  My  54K  CP/M  system  plete  customized  letter  or  other  docu-  be  if  I  were  to  use  a  system  with  an  inter- 

used  only  31  percent  of  the  available 
space  for  this  entire  article.  Figure  1 

Control- D  displays  the  directory, 

listing  only  files  with  the  .PCL  extension.  *  VID8024  EQU  TRU  ;SET  TRUE  FOR  80  X  24  SCREEN 

In  addition,  the  disk  usage  parameter  is  VID6420  EQU  FLASE  ;SET  TRUE  FOR  64  X  20  SCREEN 

updated.  Disks  can  be  loaded  and  ex-  VID6416  EQU  FLASE  ;SET  TRUE  FOR  64  X  1 6  SCREEN 

changed  without  any  problems.  The  only  *  VIDADD  EQU  0F00H  ;VIDEO  SCREEN  ADDRESS 

possible  exception  is  operator  error  when 


42 


Di.  Dobb’s  Journal,  Issue  55,  May  1981 

221 


rupted  keyboard  I  would  notice  a  change 
in  speed.  However,  the  keyboard  buffer¬ 
ing  is  such  that  I  never  lose  characters, 
even  on  the  longest  of  wrap-around 
words  being  copied  to  the  next  line.  I  al¬ 
ways  had  to  wait  with  the  Pencil,  and  had 
to  frequently  backspace  over  mistakes. 
The  program,  by  the  way,  was  delivered 
to  operate  without  modification  on  a 
Horizon  II  DD  system. 

Delivering  source  is  the  best  thing 
that  an  experimenter/hacker  could  hope 
for.  It  took  several  weeks  to  locate  the 
line  feed  followed  by  a  carriage  return  in 
Pencil  and  swap  these  two  characters  to 
drive  my  selectric  without  a  lot  of  I/O 
handling  in  CP/M.  With  SCRIBE  IX,  the 
CR  and  LF  are  defined  in  the  first  ten 
lines  of  code.  Locating  the  LF  followed 
by  CR  routines  was  simple.  Customizing 
specific  areas  should  prove  relatively  sim¬ 
ple  for  those  with  special  needs.  While  the 
code  is  not  commented,  the  labels  and  de¬ 
fined  equates  are  very  easy  to  follow  and 
seem  quite  logical.  Modules  can  be  spot¬ 
ted  and  understood  as  to  function  with¬ 
out  much  head  scratching.  I  have  written 
to  Mr.  Friedman  twice  and  received 
prompt  replies  both  times.  I  suspect  it  is 
his  intention  to  keep  the  customers  sup¬ 
plied  with  whatever  information  they 
seek.  His  licensing  agreement  is  quite 
liberal.  It  basically  says  not  to  rip  him  off 
and  sell  the  program,  or  make  money  off 
it  by  putting  it  in  a  product  you  do  sell. 
Pretty  simple.  You  don’t  sign  anything, 
you  agree  to  abide  by  the  agreement 
when  you  accept  the  software. 

Conclusion 

There  is  not  enough  room  to  expand 
properly  about  the  features  of  SCRIBE 
IX.  I  am  no  expert.  I  have  used  Pencil 
extensively,  and  have  researched  every 
word  processor  article  and  advertisement 
during  1980  in  most  of  the  computer 
mags.  Twice  I  asked  the  folks  at  Pencil 
for  information  and  never  heard  from 
them.  Basically,  SCRIBE  IX  delivers  a 
product  superior  to  Pencil  at  less  than 
two- thirds  the  cost.  I  can’t  directly  com¬ 
pare  with  Word  Pro  and  the  other  higher- 
priced  packages.  However,  from  the  arti¬ 
cles  and  the  ads  I  am  confident  SCRIBE 
IX  will  hold  its  own,  especially  in  the 
basic  screen  editing  functions  and  disk 
I/O.  The  auto  inserting  for  mailing  is  a  bit 
primitive  by  some  standards,  but  for  over¬ 
all  operation  and  comparative  cost  the 
buyer  of  SCRIBE  IX  is  getting  a  bargain. 


Dr.  Dobb’s  Journal,  Issue  55,  May  1981 
222 


For  Your  Personal 


REFERENCE 

COLLECTION 


Thousands  of  dollars’  worth  of 
microcomputer  information  and  listings! 


Dl  DuHHS  llX  HNAI  W 

i  COM  P U  T  L R 


Me? 


q  . — -  I  ' ■  I  Convenient  Volumes 

1 1  containing  everything  from  the  ground-breaking  originals 

Dr.  Dobb’s  Journal  Vol>  V  -  All  the  ground-breaking  issues  from  1980  in  one  volume!  Sys¬ 
tems  software  reached  a  new  level  with  the  advent  of  CP/M,  chronicled  herein  by  Gary  Kildall  and  others 
( DDJ's  all-CP/M  issue  sold  out  within  weeks  of  publication).  Software  portability  became  a  topic  of  great¬ 
er  import,  and  DDJ  published  Ron  Cain’s  immediately  famous  Small- C  compiler  -  reprinted  here  in  full! 

Contents  include:  The  Evolution  of  CP/M,  a  CP/M-Flavored  C  Interpreter,  Ron  Cain’s  C  Compiler  for  the 
8080,  Further  with  Tiny  BASIC,  a  Syntax -Oriented  Compiler  Writing  Language,  CP/M  to  UCSD  Pascal 
File  Conversion,  Runtime  Library  for  the  Small-C  Compiler,  and,  as  always,  even  more! 


Dr.  Dobb's  Journal  Vol.  I  -  The  material  brought  to¬ 
gether  in  this  volume  chronicles  the  development  in  1976 
of  Tiny  BASIC  as  an  alternative  to  the  “finger  blistering” 
front-panel  machine -language  programming  which  was 
then  the  only  way  to  do  things.  This  is  always  pertinent 
for  bit  crunching  and  byte  saving,  language  design  theory, 
homebrew  computer  construction  and  the  technical 
history  of  personal  computing. 

Topics  include:  Tiny  BASIC,  the  (very)  first  word  on 
CP/M,  Speech  Synthesis,  Floating  Point  Routines,  Timer 
Routines,  Building  an  IMSA1,  and  more. 


Dr.  Dobb's  Journal  Vol.  II  -  1977  found  DDJ  still 
on  the  forefront.  These  issues  offer  refinements  of  Tiny 
BASIC,  plus  then  state-of-the-art  utilities,  the  advent  of 
PILOT  for  microcomputers  and  a  great  deal  of  material 
centering  around  the  Intel  8080,  including  a  complete 
operating  system.  Products  just  becoming  available  for 
reviews  were  the  H-8,  KIM-1,  MITS  BASIC,  Poly  Basic 
and  NIBL. 

Articles  about  Lawrence  Livermore  Lab’s  BASIC.  Alpha- 
Micro,  String  Handling,  Cyphers,  High  Speed  Interaction, 
I/O,  Tiny  Pilot  &  Turtle  Graphics,  many  utilities,  and 
even  more. 


Dr.  Dobb's  Journal  Vol.  Ill  -  The  microcomputer  in¬ 
dustry  entered  its  adolescence  in  1978.  This  volume  brings 
together  the  issues  which  began  dealing  with  the  6502,  with 
mass-market  machines  and  languages  to  match.  The  authors 
began  speaking  more  in  terms  of  technique,  rather  than  of 
specific  implementations,  because  of  this  they  were  able 
to  continue  laying  the  groundwork  industry  would  follow. 
These  articles  relate  very  closely  to  what  is  generally 
available  today. 

Languages  covered  in  depth  were  SAM76,  Pilot,  Pascal  and 
Lisp,  in  addition  to  RAM  Testers,  S-100  Bus  Standard 
Proposal,  Disassemblers,  Editors  and  much,  much  more. 


Dr.  Dobb's  Journal  Vol.  IV  -  This  volume  heralds  a 
wider  interest  in  telecommunications,  in  algorithms,  and  in 
faster,  more  powerful  utilities  and  languages.  Innovation  is 
still  present  in  every  page,  and  more  attention  is  paid  to  the 
best  ways  to  use  processors  which  have  proven  longevity  - 
primarily  the  8080/ Z80,  6502,  and  6800.  The  subject 
matter  is  invaluable  both  as  a  learning  tool  and  as  a  fre¬ 
quent  source  of  reference. 

Main  subjects  include:  Programming  Problems/ Solutions, 
Pascal,  Information  Network  Proposal,  Floating  Point 
Arithmetic,  8-bit  to  16-bit  conversion.  Pseudorandom 
Sequences,  and  Interfacing  a  Micro  to  a  Mainframe  - 
more  than  ever! 


YPQI  □  Please  send  me  the  following  Volumes  of  Dr  Dobb’s  Journal  for  S20.75  each. 
■  ""Oi  □  ALL  5  for  ONLY  $88,  a  savings  of  over  15%! 


Please  charge  my  DVisa 

I  enclose  □  Check/money  order 


□  MasterCard 


-Expiration  Date_ 


□  American  Express 


Prices  subject  to  change. 

Mail  to:  Dr.  Dobb’s  Journal.  P.O.  Box  E,  Menlo  Park,  CA  94025 

Allow  6-9  weeks  for  delivery. 


>1.  I _ x  S20.75  * _ 

•III _ x  S20. 75  ■  - 

>L  III _ x  S20.75  * - 

>1 IV _ x  $20.75  « - 

>1.  V _ x  $20.75  “  - 

-L  5  - x  $88  00  = - 

Sub-total  S - 

Postage  &  Handling  - 

Must  be  included  with  order. 

Please  add  $1.25  per  book  in  U.S. 
($1.75  each  outside  U.S.) 


( Continued  from  page  6) 

*BM-CSbb  t Zbt Z  (remove  multiple 
blanks) 

*B#Sb  t  Z  t  L  tl  t  Lbbt  Z 

(blanks  to  form-feed, 
tab,  form-feed, 

2  blanks) 

*E  (end  edit  and  close 

file) 

Now  use  PIP  as  follows: 

A>  PIP 

*  CON:=FILE.TXT[P2T255  ] 

At  9600  baud,  the  [P2T255]  modifi¬ 
er  causes  single  word  display  at  the  top  of 
the  screen  at  a  rate  of  over  200  words  per 
minute.  Halving  the  tab  expansion  modi¬ 
fier  roughly  doubles  the  word  rate,  e.g. 
A>  PIP 

*  CON:=FILE.TXT[P2T128] 

.  .  .  displays  words  at  about  400  words 
per  minute. 


One  can  continue  to  speed  up  the 
display  rate  by  making  the  tab  expansion 
modifier  smaller,  until  the  display  capa¬ 
bilities  of  the  terminal  are  exceeded. 

Note  that  if  the  baud  rate  is  less  than 
9600,  the  speed  of  word  display  is 
proportionately  less.  But  even  when  using 
this  scheme  with  a  low  baud  rate  terminal 
respectable  speeds  can  be  achieved  by 
using  lower  values  for  the  tab  expansion 
modifier. 

Finally,  if  the  flashing  cursor  is  a 
distraction,  a  cardboard  or  tape  mask 
could  be  fashioned  to  cover  the  portion 
of  the  video  screen  where  this  appears. 

David  Ecklein 
Tesseract  Associates 
Stinson  Lake  Road 
Rumriey,  NH  03266 


Datalyzer  Users  Unite! 

Dear  DDJ, 

A  couple  of  years  ago,  I  purchased  a 
S-100  logic  analyzer  called  “Datalyzer.” 
It  was  made  by  Databyte  of  Middleton, 
WI,  who  went  out  of  business  about  6 
months  later. 

I  have  been  trying  to  modify  the 
Datalyzer’s  software  to  work  under  CP/M 
with  a  couple  of  extra  commands  added, 
but  have  only  had  limited  success.  Could 
you  please  publish  this  letter  with  the 
hope  that  those  who  read  it  and  have  a 
Datalyzer  might  drop  me  a  line  about 
their  experience?  I’d  be  glad  to  compile  a 
Datalyzer  user  group  list  if  I  get  enough 
responses. 

Bob  Marsolais 

16121  Atglen  St. 

Hacienda  Hts.,  CA  91745 


Santa  Barbara  Tiny  Basic 

(continued  from  page  23) 

BASIC.  The  statement  with  the  error  is  printed  out  with  a  ques- 
tin  mark  inserted  at  the  point  where  the  error  is  detected. 

(1)  WHAT?  means  it  does  not  understand  you.  Example: 
WHAT? 

2 1 0  P?TINT  “THIS”  where  PRINT  is  mistyped 

WHAT? 

260  LET  A=B+3,  C=(3+4?,  X=4 

(2)  HOW?  means  it  understands  you  but  does  not  know  | 
how  to  do  it. 

HOW? 

310  LET  A=B*C?  +  2  where  B*C  is  greater  than  32767 
HOW? 

380  GOT  412?  where  412  does  not  exist 

(3)  SORRY  means  it  understands  you  and  knows  how  to 
do  it  but  there  is  not  enough  memory  to  do  it. 

Error  Corrections.  If  you  notice  an  error  in  typing  before  | 
you  hit  the  CR,  you  can  delete  the  last  character  by  the  Rub-  j 
Out  key  or  delete  the  entire  line  by  the  Alt-Mode  key.  Tiny 
BASIC  will  echo  a  back-slash  for  each  Rub-Out.  Echo  for  Alt- 
Mode  consists  of  a  LF,  a  CR,  and  an  up-arrow. 

To  correct  a  statement,  you  can  retype  the  statement  num¬ 
ber  and  the  correct  commands.  Tiny  BASIC  will  replace  the  old 
statement  with  the  new  one. 

To  delete  a  statement,  type  the  statement  number  and  a  CR 
only. 

Verify  the  corrections  by  “LIST  nnnn”  and  hit  the  Control- 
C  key  while  the  line  is  being  printed. 


Engineers 

Scientists 

Systems  Programmers 
Business  Owners 

All  these  read  Dr.  Dobb ’s  Journal. 
Reach  them  with  cost-effective  advertising. 
(415)  323-31  11. 


I)r.  Dobb’s  Journal.  Issue  55.  \1a>  1981 


45 

223 


ESI 


$2.50  ($3.00  In  Canada) 


Dr.  Dobb  s  Journal  of 

COMPUTER  Calisthenics  &  Orthodontia 

FOR  USERS  OF  SMALL  COMPUTER  SYSTEMS  I 

Number  56  June  1981  Volume  6,  Issue  6 


A  Cross-Assembler  for  the  8080/Z80 

by  Jonathan  Mills 

Comal-80:  A  New  Language? 

by  Susan  Sonderstrup  and  Mogens  Pelle 

A  Tiny  File  System 

by  William  A.  Gale 

Re-Thinking  Program  Editors 

by  William  B.  Brogden 

H8  Text  Editor  to  CP/M  File  Conversion 

by  Jim  Scott 

....  and  even  more  than  before! 


Kg 


P.O.  Box  E 
Menlo  Park,  CA 
94025 


Dr.  Dobb’s  Journal  of 

COMPUTER  Calisthenics  &  Orthodontia 


Volume  6,  Issue  6 
Number  56 
June  1981 


Contents 


Articles 


Cross  Assembler  for  the  8080  or  Z80 . 9 

by  Jonathan  Mills 

Comal-80,  A  New  Language? .  14 

by  Susan  Sonderstrup,  Mogens  Pelle 

H8  Text  Editor  to  CP/M  File  Conversion .  18 

by  Jim  Scott 

A  Tiny  File  System . 20 

by  William  A.  Gale 

Installing  a  Printer  Toggle  in  North  Star 

DOS  5.2 . 50 

by  Bert  Smart 

Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per 
year  by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real, 
Menlo  Park,  CA  94025.  Second  class  postage  paid  at  Menlo  Park, 
California  94025  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  94025. 

©  1981  by  People’s  Computer  Company  unless  otherwise  noted  on 
specific  articles.  All  rights  reserved. 


Departments 

Letters . 4 

Guest  Essay .  16 

Book  Reviews . 48 

Dr.  Dobb’s  Clinic . 52 

Of  Interest . 56 


Publisher 
Michael  Madaj 
Editor 

Marlin  Ouverson 
Contributing  Editors 
Dave  Caulkins 
Dave  Cortesi 
Business  Manager 
Maureen  Christine 


Art  Director 
Clifford  West 
Artist 

Barbara  Ruzgerian 
Typesetters 
Renny  Wiggins 
Michelle  Moonstone 
Proofreader 
Nancy  Heubach 


Marketing  Director 
Craig  S.  Harper 
Advertising  Sales 
Kent  Safford 
Circulation  Manager 
Peter  Clark 
Circulation  Assistant 
Leah  Dansby 


Editorial 


The  6th  West  Coast  Computer  Faire  is  over  (sigh  of  re¬ 
lief  and  aching  feet).  Director  Jim  Warren’s  roller  skates 
have  been  hung  up  for  another  year,  or  at  least  until  his  ru¬ 
moured  mini-faires  get  under  way.  This  year’s  was  even  big¬ 
ger  than  expected,  as  the  thirty  thousand  nametags  were 
exhausted  even  before  the  exhibitors. 

Perhaps  the  biggest  surprise  to  commercial  concerns 
was  the  profile  of  the  “average”  attendee.  All  the  sales 
people  had  been  coached  well  in  advance  on  how  to  spill 
forth  a  technical-sounding  pitch;  none  seemed  able  to  an¬ 
swer  basic  questions  like,  “Why  should  I  have  a  computer?” 
“What  can  I  use  it  for?”  “I  don’t  know  anything  about 
computers  —  where  do  I  start?”  Would-be  consumers  wan¬ 
dered  from  booth  to  booth  in  search  of  someone  who  could 
still  remember  how  to  speak  their  lingo  and  give  a  down-to- 
earth  reply.  They  filled  halls  designated  for  “introductory” 
sessions,  and  then  expressed  frustration  when  they 
couldn’t  understand  the  speakers. 

Of  the  hundreds  of  booths,  only  a  small  handful  really 
stood  out  in  terms  of  newsworthiness.  The  star  of  the  show 
was  the  Osborne  1  computer,  which  DDJ  will  be  reviewing 
in  an  upcoming  issue.  Its  dual  floppies,  5”  monitor  and  full- 
size  keyboard  comes  in  one  case  which  will  fit  under  an 
airplane  seat  -  but  the  real  breakthrough  is  the  price.  It 
lists  for  $1795  including  CP/M,  Wordstar,  Supercalc, 
CBASIC,  and  MBASIC. 

Less  of  a  crowdstopper,  but  nonetheless  important, 
was  the  Stratos  by  Symbiotic  Systems,  Inc.  Two  things 


stand  out  that  set  it  apart  from  other  CP/M  compatible  sys¬ 
tems.  First,  a  clock/calendar  is  not  only  integrated  into  the 
hardware,  but  into  the  CP/M  system  as  well,  allowing 
REMINDER  to  call  and  execute  any  program  at  the  speci¬ 
fied,  appropriate  time.  Second,  the  BIOS  (vendor-written 
hardware  support  code)  makes  use  of  bank-switched  memo¬ 
ry  to  do  full-track  disk  buffering,  which  has  to  make  a 
significant  performance  improvement. 

Two  other  booths  at  the  Faire  should  be  noted  as 
among  the  Most  Popular.  Epson  printers  sold  out  every¬ 
where,  receiving  general,  deserved  acceptance  as  a  good 
quality  dot  matrix  printer  at  a  reasonable  price.  The  Sin¬ 
clair  booth  was  also  well  populated.  All  those  computer 
consumers  were  there,  wanting  to  know  more  about  this 
less-than-$200  computer  and  what  it  can  do  for  them. 

If  this  year’s  Faire  is  a  valid  indicator,  and  I  believe  it 
is,  then  all  the  prophecies  of  the  original  homebraumeisters, 
of  the  ComputerTown,  USA!  folks  and  of  others  involved 
in  computer  literacy,  are  coming  true.  It  appears  the  circle 
of  microcomputerists  is  opening  outward  to  include  not 
only  technicians  and  hobbyists,  but  result-oriented  applica¬ 
tion-minded  laymen  as  well. 

Marlin  Ouverson 
Editor 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


Letters 


Mincemeat 
And  Minced  Words 

Dear  Mr.  Ouverson, 

Sigh.  I  apologize  to  all  readers  who 
will  advise  me  to  get  a  copy  of  Harbrace 
or  Turabian  and  read  it.  I  have  copies  of 
them  already,  and  I  have  read  them,  but  I 
just  didn’t  take  too  much  time  when  I 
wrote  the  article.  I  don’t  usually  nest 
parentheses  unless  I’m  writing  LISP  code. 

The  most  glaring  errors  are  in  the  de¬ 
scription  of  the  command  set  for  MINCE. 
I  made  two  big  blunders,  one  in  the  in¬ 
clusion  of  some  EMACS  commands  that 
are  not  existent  in  MINCE,  and  in  an¬ 
other  place  an  entire  sentence  is  missing, 
and  the  one  that  should  follow  it  is  sim¬ 
ply  wrong. 

My  keyboard  does  not  generate  Meta 
characters.  Mark  of  the  Unicorn’s  does.  It 
is  a  custom  one  off  design.  That’s  a  Mode 
Line  at  the  bottom  of  the  screen,  not  a 
Model  Line.  C-X  K  prompts  you  for  a 
buffer  name,  and  does  not  kill  the  current 
one  by  default. 

There  are  now  plans  in  the  wings  for 
a  user’s  group  of  some  sort  for  Amethyst. 
I  hear  that  there  is  already  a  C  mode 
floating  about  someplace.  I  will  advise 
DDJ  as  soon  as  something  materializes. 

I  apologize  to  anyone  who  feels  that 
I  severely  maligned  his  editor  or  text  pro¬ 
cessor.  Send  me  a  copy  and  I  will  review 
it  too,  and  will  try  to  be  as  objective  as  I 
can.  It’s  hard  for  me  to  be  objective  when 
I  love  a  product  as  much  as  I  do  MINCE. 

Yours, 

Barry  A.  Dobyns 
1635  Royal  Crest  #1128 
Austin,  TX  78741 

FCTNMC 

To  the  Editor: 

The  modifications  to  the  CP/M 
DUMP  utility  proposed  by  Tom  Cage 
(. DDJ  #53)  kept  me  busy  a  whole  Sun¬ 
day.  While  his  algorithm  was  fairly  sim¬ 
ple,  implementation  with  such  fictional 
mnemonics  as  DCR  LX,  DCR  HX,  MVI 
LX, data,  or  MVI  HX.data  was  naturally 
impossible. 

One  possible  alternative  is  figure  1 
where  [*]  is  used  in  the  comment  field  to 
indicate  new  lines  of  source  code  to  insert 
in  the  original  DUMP.ASM  file. 

Since  most  DUMPs  are  of  .COM  files, 
I  also  suggest  that  the  LXI  H,0  line  in 
OPENOK:  be  changed  to  LXI  H,0100H. 
This  way  the  DUMP  listing  shows  the  ac¬ 
tual  addresses  for  each  line. 


And  finally,  for  those  whose  DUMP 
fails  to  display  a  sign-on  line  even  though 
it  is  included  in  the  .ASM  source  file,  add 
the  following  code  immediately  following 
the  File  Control  Block  definitions: 

LXI  D,SIGNON;[*] 

CALL  ERR  ;[*] 

CALL  CRLF  ;[*] 


The  net  result  of  these  changes  will 
be  figure  2. 

Sincerely, 

Robert  G.  Savage 
98-719  Iho  Place  #1101 
Aiea,  Hawaii  96701 


Figure  1. 

OPENOK: 

MVI 

A, 8  OH 

STA 

IBP  ;set  buffer  pointer  to  80H 

LXI 

B,204H 

[  *  ]  set  up  byte  counters 

GLOOP: 

PUSH 

H 

save  line  position 

JC 

FINIS  ;carry  set  by  GNB  if  end  file 

PUSH 

B 

[*]  save  byte  counters 

CALL 

PHEX 

MVI 

A,” 

[*]  dbl  space  after  line  number 

CALL 

PCHAR 

[*] 

NONUM: 

INX 

H  ;to  next  line  number 

POP 

B 

[*]  restore  byte  counters 

DCR 

C 

[*)  decrement  4th  byte  counter 

JNZ 

GLOOP 

[*] 

MVI 

A,” 

[*]  dbl  space  after  bytes  4  &  12 

CALL 

PCHAR 

[*] 

MVI 

C,4 

[*]  restore  4th  byte 

DCR 

B 

[  *]  decrement  8th  byte  counter 

JNZ 

GLOOP 

[*] 

MVI 

A,‘  ’ 

[ *]  triple  space  after  8th  byte 

CALL 

PCHAR 

[*] 

MVI 

B,2 

[*]  restore  8th  byte 

Figure  2. 

A  >  FILEDUMP  TEST.  1 23 
FILEDUMP  VERSION  1.5 


0100 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

0110 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

0120 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

0130 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

0140 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

0150 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

0160 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

0170 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

00 

01 

02 

03 

A> 


4 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

227 


Figure  3. 


/  *  return  current  literal  char  &  bump  lptr  */ 
litchar()  [ 
int  i,  oct; 

if((ch()!  =  92) !  (nch()==0))  return  gch(); 
gch(); 

if(ch()==‘n’)  [++lptr;  return  13;]  /*  CR  */ 
if(ch()==‘t’)  [++lptr;  return  9;]  /*  HT  */ 
if(ch()==‘b’)  [++lptr;  return  8;]  /*  BS  */ 
if (ch( )==  ‘f’)  [++lptr;  return  12;]  /*  FF  */ 
i=3;  oct=0; 

while(((i~)>0)&(ch()>  =  ‘0’)&(ch()<=‘7’))  oct=(oct«3)+gch()-‘0’; 
if(i==2)  return  gch();  else  return  oct; 

] 


Brace  Yourself 

Dear  DDJ, 

I  first  read  your  magazine  in  my  or¬ 
thodontist’s  office  in  Singapore.  I  don’t 
wear  braces  any  more. 

Brad  Rubenstein 
2415  Dwight  Way  #4 
Berkeley,  CA  94704 

Small-c  Compiler 

Dear  DDJ , 

This  note  is  to  report  two  bug  fixes 
and  an  enhancement  to  the  small-c  com¬ 
piler.  The  first  fix  has  to  do  wtih  the  way 
small-c  handles  comments  in  the  form: 

/* 

**  comment 

*/ 

The  problem  is  that  the  comment 
terminator  “*/”  being  at  the  beginning  of 
the  line  is  not  recognized  because  the 
function  “inchar”  (used  to  skip  over  com¬ 
ment  characters)  always  calls  “gch”  after 
acquiring  a  new  line.  “Gch”  bumps  “lptr” 
causing  it  to  point  to  the  second  charac¬ 
ter.  Since  “inchar”  is  only  used  by  “pre- 
process”  while  skipping  over  comments 
and  only  one  of  its  calls  requires  the  full 
features  of  “inchar.”  I  chose  to  delete 
“inchar”  and  modify  the  part  of  “pre- 
process”  which  handles  comments  as  in¬ 
dicated  below: 

else  if ((ch()==7’)&(nch( )==’*’)) 
[lptr=lptr+2; 

while(((ch()==‘*’)&(nch()==7’))==0) 
(if(ch()==0)  inline();  else  lptr++; 
if  (eof)  break; 

] 

lptr=lptr+2; 

] 

The  second  bug  is  a  problem  in  P.  L. 
Woods’  patch  reported  in  DDJ  #52.  His 
fix  will  not  handle  the  following  code 
properly : 

func(a,  b,  c)  int  b,  a ;  int  c ;  ( 

The  problem  is  that  the  arguments  are 
typed  in  two  statements  rather  than  one. 
The  culprit  is  the  location  of  the  state¬ 
ment  “argtop=argstk;”  in  “getarg.”  That 
statement  should  be  moved  from 
“getarg”  to  “newfunc”  just  before  the 
statement  “while(argstk) . . . .”  Doing 
that  involves  deleting  the  “argtop”  de¬ 
claration  in  “getarg”  and  declaring  it  as 
an  external  variable  at  the  beginning  of 
the  program. 

Then  enhancement  implements  the 
backslash  escape  sequences  for  character 


and  string  literals.  I  find  that  these  are 
very  handy.  This  is  easy  to  install  by  de¬ 
fining  a  new  function  “litchar”  in  figure 
3. 

The  statement  “litq[litptr++]  = 
gch();”  in  “qstr”  should  be  changed  to 
“litq[litptr++]  =litchar();”.  The  function 
“pstr”  should  be  modified  as  indicated 
below: 
pstr(val) 
int  val[]  ; 

[int  k; 
k=0 

if  (match(“’”)==0)  return  0; 
while(ch()!=39) 

k=(k&255)*256  +  (litchaK  )&  1 27); 
++lptr; 
val[0]=k; 
return  1; 

] 

Finally  “preprocess”  must  be  modi¬ 
fied  to  permit  \”  and  V  sequences. 
Change  “while(ch(  )!  =  “”)”  to  “while 
((ch()!=‘”’)i  ((line [lptr-1  ]==92)&(line 
[lptr— 2]  !=92)))”  and  change  “while 
(ch( )!  =  39)”  to  “while((ch()!=39) !  ((line 
[lptr-1]  ==92)&(line[lptr-2]  !  =  92)))”. 

I  hope  this  information  will  be  help¬ 
ful  to  the  small-c  enthusiasts  among  your 
readers. 

Sincerely, 

J.  E.  Hendrix 
Rt.  1,  Box  74-B-l 
Oxford,  MS  38655 

Not  Complaining? 

Dear  Mr.  Ouverson, 

Your  new  “Ex  Machina”  column  is  a 
long  awaited,  sorely  needed  and  very  wel¬ 
come  addition  to  Dr.  Dobb’s.  It’s  high 
time  someone  stepped  in  to  protect  us, 
the  home  computer  hobbyists,  from  the 
high-handed  and  (sometimes)  dishonest 


treatment  of  manufacturers  and  vendors. 

A  case  in  point  is  my  Heathkit  H-19 
terminal.  This  terminal  has  a  front  panel 
cutout  which  accepts  a  5.25”  disk  drive. 
(The  cabinet  is  the  same  as  in  the  H-89 
“all-in-one”  computer.)  All  that  is  need¬ 
ed  for  the  installation  are  a  few  bucks’ 
worth  of  hardware  parts:  sheet  metal 
brackets  and  the  like.  Imagine  my  sur¬ 
prise  when  the  local  Heath  Center  could 
not  provide  the  part  numbers  of  the  re¬ 
quired  components  ....  Imagine  my  fur¬ 
ther  surprise  when,  over  a  call  to  the  fac¬ 
tory,  they  refused  to  sell  me  the  parts! 

Why  does  Heath  behave  like  that?  I 
do  not  know.  Perhaps  they  simply  can’t 
be  bothered  with  little  me.  Even  with 
their  inflated  price  structure,  the  parts 
could  not  be  more  than  $20. 

This  is  not  a  complaint.  Heath  is  free 
to  sell  or  not  to  sell  spare  parts.  I  feel, 
however,  that  anyone  contemplating  a 
Heath  product  should  be  aware  of  the 
quality  of  their  so-called  service.  I  have 
told  this  story  to  anyone  who  would  lis¬ 
ten,  and  have  been  successful  in  prevent¬ 
ing  the  purchase  of  a  printer.  Not  much,  I 
agree,  but  I  feel  I  have  done  my  little 
something  to  improve  this  world  .... 

Sincerely  yours, 

R.  A.  Hoffman 
9  Greenway  Court 
Brookline,  MA  02146 


A  Poke  at  MIT  BASIC 

Dr.  Dobbs: 

I,  too,  ran  into  the  problem  of  not 
being  able  to  PEEK  or  POKE  above 
32767  (7FFFH)  in  the  old  MITS  BASICS, 
8K  3.1  and  8K  3.2. 

May  I  offer  a  much  more  simple 
patch  which,  however,  doesn’t  allow 


6 

228 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


using  positive  numbers  as  does  T.  J.  Van 
Iderstine’s  patch  in  volume  52? 

8K  3.1  addr  646  was  “JM  FCERR” 
change  to  NOP  NOP  NOP 
8K  3.2  addr  649  was  “JM  FCERR” 
change  to  NOP  NOP  NOP 
To  compute  the  proper  address,  use 
x-65536,  or  just  directly  compute  it: 
A  VDM  or  VTI  or  VIO  (etc.)  at  FOOOH  is 
at  address  -4096.  Just  say  VB=-4096, 
then  forget  negative  numbers,  just  refer¬ 
encing  VB+nn  for  your  poke/peek  ad¬ 
dresses. 

Ward  Christensen 
Dolton,  IL 


Coming  to  Terms 

Dear  Doctor  Dobb 's  Journal, 

I  read  with  interest  the  letter  from 
reader  Langdon  Procter  of  Pasadena,  CA. 
After  giving  the  matter  some  thought  I 
think  that  Mr.  Procter  and  myself  can 
agree  on  the  following  points  on  the  Sin¬ 
clair  ZX80. 

The  ZX80  has  educational  value  for 
everyone.  It  is  an  engineering  feat  both  in 
hardware  and  software.  No  doubt  it  is  an 
excellent  choice  for  someone  who  has 
had  no  prior  training.  And  even  seasoned 
professionals  wonder  at  the  power  of  this 
little  machine. 

The  video  quality  of  the  ZX80  is  satis¬ 
factory  for  its  purpose.  You  need  a  good 
quality  Monochrome  Television  set  of  re¬ 
cent  design.  There  are  some  TV  sets  that 
do  not  perform  good  with  any  VHF  video 
computer. 

Cassette  tapes  made  on  any  ZX80 
should  play  back  on  any  other  ZX80. 
For  best  results  both  cassette  machines 
must  be  in  good  repair.  A  few  cassette 
machines  may  not  work  if  poor  cassette 
tape  is  used. 

If  you  wish  to  expand  your  ZX80, 
use  only  the  items  recommended  by  Sin¬ 
clair.  Do  not  try  to  modify  the  ZX80. 
The  printed  circuit  card  was  not  built  for 
user  experimentation. 

I  do  not  wish  to  go  into  any  more  de¬ 
tail  about  a  few  other  topics  mention., 
by  Mr.  Proctor  in  his  letter.  Instead  I 
would  like  to  draw  attention  to  a  very  im¬ 
portant  point  that  has  not  yet  been  men¬ 
tioned. 

Many  vendors  of  new  items  expect  the 
consumer  to  inform  them  if  any  problems 
appear  after  the  consumer  has  used  the 
product  for  a  time.  If  we  consumers  will 
write  or  call  either  the  vendor  or  maker 
we  may  expect  help.  We  should  not  try 


to  repair  new  equipment  ourselves.  Nei¬ 
ther  should  we  suppose  a  product  is  per¬ 
fect  only  because  it  is  new. 

Any  owners  of  the  ZX80  who  are  hav¬ 
ing  trouble  with  the  video  display,  cas¬ 
sette  interface,  power  supply  or  any 
other  feature  should  not  suppose  that 
something  must  be  wrong  with  the  TV 
set,  the  cassette  recorder  or  the  electric 
company.  Read  the  manual  over  again.  If 
that  does  not  help,  then  contact  Sinclair 
Research.  Their  address  is  given  as: 
Sinclair  Research 
50  Stanford  Street 
Boston,  MA  02114 
If  your  ZX80  is  healthy  and  happy, 
but  you  wish  to  learn  more  about  it  you 
should  also  consider  a  subscription  to 
SYNC.  Their  address  is: 

SYNC 

39  East  Hanover  Avenue 
Morris  Plains,  NJ  07950 
I  hope  this  letter  will  be  helpful  to 
future  ZX80  owners,  or  any  present  own¬ 
ers  who  may  have  had  some  problems 
with  this  very  delightful  and  very,  very 
small  personal  computer. 

John  B.  Palmer 
PO  Box  23 
Boonville,  CA  95415 


Why  wait 
to  start 

increasing  your  sales? 
Call  now 
to  reserve 
advertising  space 
in  the  next 
Dr.  Dobb’s  Journal 
(415)  323-31  11 


YOU  CAN  HELP  YOUR  COMMUNITY 
LEARN  ABOUT  COMPUTERS _ 

SUPPORT 

(^mputerjown™ 

ComputerTown ,  a  computer  literacy  project  sponsored  by  People’s  Computer  Company  and  later  funded  by  the 
National  Science  Foundation,  began  operations  in  1979.  The  project’s  ongoing  goal  is  to  design,  publish  and  dis¬ 
seminate  materials  for  the  development  of  community -based  computer  literacy  projects  around  the  world. 

You  too  can  help!  Your  tax -deductible  donations  of  new  and  used  computer  hardware  and  software  will  enable 
us  to  bring  “hands-on  ’  experience  to  people  everywhere.  These  items  can  mean  the  difference  between  a  person 
just  hearing  about  computer  technology  and  actually  being  able  to  sit  down  and  use  it.  A  ComputerTown  can 
be  set  up  in  a  public  library,  museum,  school,  business  or  a  number  of  other  places.  What’s  needed,  along  with 
the  information,  resources  and  experience  we  provide,  is  just  a  few  machines  and  some  software  to  get  started. 

Already  there  are  more  than  eighty  ComputerTowns  in  the  U.S.,  Canada,  England  and  other  countries.  Your 
generous  donations  can  help  this  number  grow. 

For  more  information  about  ComputerTown,  and  for  details  on  how  to  make  contributions,  contact: 


Fritzi  Lareau,  c/o  ComputerTown 
1263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  CA  94025 
(415) 323-3111 


J 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


7 

229 


The  Z88  Project 

Cross  Assembler  for  8080  or  Z80 


I  n  this  article,  which  may  be  the  first  in  a  series,  you  will 
find  a  major  piece  of  software  and  a  new  central  processing 
unit  (CPU)  card  described.  The  first  installment  of  the  soft¬ 
ware  source  listing  is  offered. 

Although  most  magazines  publish  software  tid-bits,  large 
software  packages  are  seldom  seen.  Exceptions  exist.  Dr. 
Dobb’s  several  version  of  Tiny  BASIC  are  notable. 

This  condition  exists  for  several  reasons.  First,  relatively 
few  hobbyists  write  complex  systems  software.  Most  computer 
enthusiasts  today  expect  to  find  the  systems  software  as  a  re¬ 
liable  part  of  the  package.  Next,  those  who  do  write  this  type 
of  software  intend  to  sell  it.  I  am  no  stranger  to  these  motives, 
but  have  another  one,  too.  Some  form  of  low-cost  develop¬ 
ment  tool  is  needed  to  get  the  16-bit  hobbyist  market  off  the 
ground.  I  hope  that  XASM-86  will  become  that  tool.  Finally, 
large  complex  software  tends  to  be  difficult  to  design  and  de¬ 
bug.  A  commitment  to  completion  and  unflagging  enthusiasm 
are  sine  qua  non  software! 

XASM-86  bridges  the  gap  between  the  popular  8080/Z80 
and  the  powerful  new  8086.  XASM-86  will  run  on  an  8080  or 
Z80  CPU,  but  since  it  is  a  cross-assembler,  it  will  generate 
object  code  for  any  8086  or  8088  processor.  XASM-86  is  fast, 
efficient,  and  innovative.  Techniques  used  in  compiler  design 
have  been  applied  to  create  a  reliable,  state-of-the-art  pro¬ 
gram.  The  source  listing  is  fully  documented.  It  requires  over 
500,000  bytes  on  disk,  and  lists  on  almost  200  pages. 

XASM-86  was  a  natural  outgrowth  of  the  Z-88  project 
begun  in  1979.  Yet  unnamed,  the  project  was  a  response  to 
the  spate  of  announcements  of  16- bit  microprocessors  that  oc¬ 
curred  in  1978  through  1979.  Examination  of  these  machines 
led  me  to  suspect  that  the  16-bit  macroprocessor  market 
would  be  a  new  one,  or  at  least  a  slowly  developing  one  for 
hobbyist  retrofits.  Then  Intel  announced  a  clever  product, 
the  8088.  Essentially  an  8086  with  an  8-bit  bus  interface  unit, 
the  8088  looked  like  an  excellent  product  for  an  S- 100  (IEEE- 
696)  CPU. 

Thus  in  September  1971,  the  Z-88  project  began.  It  had 
one  objective: 

“Upgrade  existing  S-100  computer  systems  to 
16-bit  capability  without  causing  hardware  ob¬ 
solescence,  or  hardware  or  software  incompati¬ 
bilities.” 

The  target  device  to  meet  this  objective  was  a  special  CPU. 
There  were  seven  requirements  that  it  had  to  meet.  They  were: 

1.  Meet  the  (then  preliminary)  IEEE-696  S- 100  bus  standard, 

2.  Be  selectable  for  non-IEEE-696  S-100  buses  (Altair  or 
IMSAI), 

3.  Maintain  compatibility  with  8-bit  peripherals  in  use  on  the 
bus  selected, 

4.  Develop  all  timing  using  logical  combinations  of  existing 
signals  instead  of  monostable  pulse  generators  (one-shots), 

5.  Include  provision  for  multi-tasking,  i.e,  priority  vectored 
interrupts, 

_ by  Jonathan  Mills _ 

Jonathan  W.  Mills,  President  of  Programmers  Publishing  Co., 
Box  2571,  Kalamazoo,  MI  49003 
©  1981  by  Programmers  Publishing  Company 


6.  Accept  all  8080/8085/Z80  software,  with  the  exception  of 
that  software  using  RIM  or  SIM  instructions  on  the  8085, 
or  that  used  software  to  generate  highly  critical  timing 
loops  that  could  not  be  modified, 

7.  Provide  for  an  Altair  or  IMSAI  front  panel,  and  use  as  many 
of  the  front  panel  control  functions  for  each  processor  as 
possible. 

As  became  obvious,  this  special  CPU  used  two  processors: 
a  Z80A  and  an  8088.  A  8259A  priority  interrupt  controller 
was  added  as  the  heart  of  a  circuit  that  generated  Z80  mode  2 
or  8088  interrupt  vectors,  based  on  the  active  processor.  A 
special  control  circuit  was  developed  to  allow  control  to  be 
handed  back  and  forth  between  processors  in  any  of  several 
ways.  (See  Figure  1.) 

On  November  30,  1979,  the  Z-88  passed  its  final  tests, 
and  was  put  into  action  as  the  heart  of  the  Z-88  project’s  de¬ 
velopment  system.  It  has  since  completed  over  1,500  hours  of 
operation  without  error. 

Attempts  were  made  to  market  the  Z-88,  but  met  with 
lukewarm  results.  In  one  instance,  perhaps  the  most  surprising, 
a  case  of  parallel  development  was  uncovered.  Mark  Garetz, 
working  for  Bill  Godbout,  had  independently  come  to  the 
same  conclusions,  but  selected  an  8085/8088  processor  com¬ 
bination.  Godbout  is  marketing  this  CPU  with,  I  hope,  great 
success.  A  press  release  on  the  Z-88  directed  to  BYTE  maga¬ 
zine  popped  up  in  their  August  1980  issue.  This  caused  a 
deluge  of  several  thousand  requests  for  information.  To  those 
of  you  who  did  write,  please  contact  Brent  Olsen  of  SSM  (for¬ 
merly  Solid  State  Music),  and  tell  him  how  much  you  want  a 
Z-88.  Brent  came  closest  to  closing  a  manufacturing  agree¬ 
ment  with  us.  He  is  a  great  guy,  and  a  hard-headed  realist. 

However,  no  matter  what  a  great  CPU  the  Z-88  was,  it 
suffered  from  a  simple  problem.  To  quote  an  unnamed 
marketing  vice-president,  “Who  cares  what  kind  of  a  CPU 
is  in  there?  It  could  be  a  chipmunk,  as  long  as  it  works.”  This 
inspired  the  observation  on  my  part,  that  a  16-bit  CPU  with  no 
software  was  a  dead  chipmunk.  Phase  two  of  the  Z-88  project 
was  to  begin. 

Phase  two,  later  named  XASM-86,  had  as  its  objective  to, 
“Design,  program,  and  debug  a  software  tool  for  the  8086.” 
After  deciding  on  a  cross-assembler,  which  suited  the  Z-88 
CPU  well,  nine  requirements  were  established  for  it.  They 
were: 

1.  Run  on  8080,  8085,  or  Z80  CPUs  and  produce  8086/8088 
object  code, 

2.  Operate  on  disk  files  to  produce  disk  files  (disk-to-disk), 

3.  Use  consistent  and  rational  syntax  and  mnemonics  for 
8086/8088  source  code  (not  necessarily  matching  Intel’s), 

4.  Encourage  documentation  and  structured  design  practices, 

5.  Attempt  to  be  independent  of  any  operating  system, 

6.  Assemble  mnemonics  for  AMD  95  1 1  Arithmetic  Processor 
(this  was  decided  before  the  8087  coprocessor  was  an¬ 
nounced), 

7.  Use  a  modular  design  to  allow  maintainability  and  relia¬ 
bility, 

8.  Provide  for  future  enhancements,  and 

9.  Provide  fast  cross-assembly. 

The  first  version  of  XASM-86  met  these  goals  by  cross¬ 
assembling  300  lines  of  8086  source  mnemonics  to  8086 
object  code,  disk-to-disk,  in  55  seconds.  The  system  is,  of 
course,  limited  by  the  speed  of  the  floppy  disk  drive. 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 
230 


9 


Figure  1. 


8088 

16-BIT 

MICROPROCESSOR 


Z80A 

MICROPROCESSOR 


TIMING 

LOGIC 


RESET 

LOGIC 


02 

CLK  (2  MHZ) 


POC* 

RESET* 

SLVCLR* 


INTERNAL  DATA  BUST 


S-100 

CONTROL 

SIGNALS 


PSYNC 

PWR* 

PDBIN 

PHLDA 

PSTVAL* 


INTERNAL  CONTROL  BUS 


S-100 

STATUS 

SIGNALS 


SMEMR 

SWO* 

SHALT 

SINTA 

SINP 

SOUT 

SXTRQ* 

SMI 


AD0-AD7 

ADDRESS 

DEMULTI¬ 

PLEXER 


A20-A23 

ADDRESS 

LATCH 


PROCESSOR 

CONTROL 

TRANSFER 

LOGIC 


RDY 

XRDY 

HOLD* 

SDSB* 

CDSB* 

ADSB* 

DODSB* 

RUN 

ss 

SSW  DSBL* 


SYSTEM 

LOGIC 


INT* 

TEST* 

MWRT 

PHANTOM* 


10 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

231 


Some  of  the  exciting  features  of  XASM-86  will  be  de¬ 
scribed  below.  The  mnemonic  set  and  syntax  will  be  exam¬ 
ined,  and  the  subroutine  library  will  be  outlined. 

XASM-86  is  approximately  17,000  bytes  long,  excluding 
the  symbol  table.  It  is  written  in  structured  assembly  language 
accompanied  by  extensive  internal  documentation.  Two  utility 
programs  are  provided  with  XASM-86:  a  relocating  loader, 
and  a  symbol  table  compiler.  It  is  possible  to  reconfigure  the 
symbol  table  to  allow  XASM-86  to  produce  6800,  6502,  Z80 
or  other  machine’s  object  code.  It  is  not  a  project  for  the 
beginner,  though. 

High-level,  application-oriented  input-output  routines  are 
a  part  of  XASM-86.  These  routines  should  make  it  easy  to 
“hook”  the  program  into  any  operating  system.  Since  all 
XASM-86  input-output  (I/O)  is  done  by  transferring  records 
between  devices,  all  the  user  need  do  is  change  those  routines 
or  addresses  of  routines  that  read  or  write  a  character  from  or 
to  a  specific  device. 

XASM-86  mnemonics  are  loosely  based  on  those  provided 
by  Intel  for  the  8086,  but  are  structured  to  resemble  those  of 
the  DEC  LSI- 1 1  in  their  syntax.  For  example,  to  move  a  byte 
from  memory  to  the  BH  register: 

Intel  mnemonics:  MOV  BH, LOCATION 

XASM-86  mnemonics:  MOVB  LOCATION, BH 
XASM-86  specifies  in  the  opcode  whether  or  not  a  byte  is  the 
operand,  and  also  (finally)  uses  a  logical  left-to-right  orienta¬ 
tion  for  source- to- destination  ordering  of  the  operands.  This 
is  consistent,  always. 

XASM-86  addressing  modes  are  also  similar  in  syntax  to 
the  LSI-11.  The  25  possible  16-bit  source/destination 
operands  are  in  Table  1. 


As  may  be  noted,  the  variable  names  in  XASM-86  are  not 
limited  to  six  letters  in  length.  In  fact,  they  may  be  over  200 
characters  long,  although  only  15  will  be  printed  on  a  listing. 
The  rest  are  stored  in  the  symbol  table,  and  differentiate  the 
more  lengthy  names  selected. 

Fourteen  pseudo- operations  are  included  in  XASM-86. 
One  of  them,  the  “ditto”  operator  (”)  serves  to  reduce  repeat¬ 
ed  use  of  the  same  pseudo-operation  to  a  simple  double  quote. 
Since  the  psuedo- operations  are  all  descriptive  (i.e.,  BYTE  in¬ 
stead  of  DB,  ALLOCATE  instead  of  DS),  the  ditto  operator 
increases  programmer  effectiveness  and  program  readability 
at  the  same  time. 

Two  kinds  of  macro  definitions  are  included  in  XASM-86. 
The  first  is  the  simple  macro  that  is  expanded  into  several 
XASM-86  mnemonics.  The  second  is  of  some  interest.  Invok¬ 
ing  the  OPMACRO  pseudo- operation  associates  a  name  with 
an  operand  expression.  An  example  would  be: 
ACCOUNTBALANCE  OPMACRO  ACCOUNTOFFSET@BX 
In  use,  a  program  could  say: 

LABEL:  ADD  CX, ACCOUNTBALANCE  instead  of 
ADD  CX,ACCOUNTOFFSET@BX. 

Listing  I  on  page  22  shows  the  XASM-86  mnemonics, 
operands,  and  pseudo-operations.  It  also  includes  the  AMD 
95 1 1  Arithmetic  Processor  mnemonics  assembled  by  this  pro¬ 
gram. 

Borrowing  from  compiler  design,  XASM-86  uses  exten¬ 
sive  table-driven  routines  to  accomplish  expression  parsing, 
expression  evaluation,  and  to  implement  an  internal  interpret¬ 
er  which  reduces  each  type  of  assembly  for  any  8086  instruc¬ 
tion  to  a  single  function.  These  innovative  methods  allow  for 
speed  and  flexibility.  An  added  benefit  is  the  ease  with  which 


Table  1. 

16-bit  Registers: 

AX  CX  DX  BX 

SP  BP  SI  DI 

Example: 

MOV  AX.SP 

Indirect: 

@SI  @DI  00000H@BP  *  @BX  MOV  AX,@DI 

*  The  @BP  operand  must  be  given  an  offset  of  0  to  avoid  generating  the  opcode  for  effective  address  equal  to  the  offset  alone. 

Direct  (Effective  Address  equals  Offset): 

03EF2H  LABEL  DISPLACEMENT 

MOV  AX, RESULT 

Based: 

DISPLACEMENT@BX 

DISPLACEMENT@BP 

MOV  AX,EMPLOYEENO@BX 

Indexed: 

DISPLACEMENT@SI 

DISPLACEMENT@DI 

MOV  AX,STARTARRAY@SI 

Base  Indexed: 

@BX+SI  @BX+DI 

@BP+SI  @BP+DI 

MOV  AX,@BX+SI 

Base  Indexed  Displaced: 

DISPLACEMENT@BX+SI 
DISPLACEMENT@BP+  SI 

DISPLACEMENT@BX+  DI 
DISPLACEMENT@BP+  DI 

MOV  AX,PARAMETERS@BX+SI 

Dr.  Dobb’s  Journal,  Number  56,  June  1981 
232 


a  fix  may  be  made  to  any  incorrectly  assembled  instruction: 
simply  change  the  assembly  function! 

At  the  heart  of  the  process  is  a  symbol  table  based  on  the 
binary  tree  organization.  Although  not  as  fast  as  hashing 
(generating  a  unique  code  and  thus  an  address  based  on  some 
function  of  the  symbol’s  text,  the  binary  tree  is  simple  to  im¬ 
plement,  and  has  the  added  benefit  of  producing  ordered  out¬ 
put  on  completion  by  simply  traversing  it. 

A  subroutine  library  is  used  to  keep  the  general  purpose 
routines  that  comprise  or  are  used  by  the  various  XASM-86 
modules.  Extensive  documentation  allows  new  modules  to  be 
written  in  terms  of  these  “primitives”  in  a  fairly  short  time. 
Figure  2  lists  the  routines  in  the  library. 


In  closing  the  description  of  XASM-86,  I  would  like  to 
say  that  it  is  a  virtually  “bullet-proof’  piece  of  software.  Over 
100  error  messages,  stored  internally  as  text,  signal  conditions 
that  range  from  I/O  errors  to  “OPCODE  IS  INVALID  OR 
INCORRECTLY  SPELLED”.  In  fact,  there  are  even  messages 
that  signify  that  XASM-86  has  reached  a  “should -never- get - 
here”  part  of  the  code!  Even  on  the  first  run,  it  was  possible  to 
debug  XASM-86  by  observing  the  error  messages  it  produced. 
Only  once  did  it  crash  the  system  —  and  that  was  due  to  my 
failure  to  include  a  necessary  module.  Listing  II  includes  the 
current  version’s  error  messages. 

Finally,  for  all  the  hackers  who  will  write  in  to  tell  me 
how  this  or  that  portion  of  a  module  or  routine  could  be  re- 


Figure  2. 

Routines  included  in  the  XASM-86  subroutine  library.  Some  of  these  routines  are  listed  in  this  installment  in  Listing  3. 

XASM-86  Utility  Routines 

Data  Conversion 

Logical  Input/Output  (Record-oriented  I/O) 

Convert  ASCII  field  into  binary  (hexadecimal  inter- 

Transfer  logical  record 

pretation) 

Convert  ASCII  field  into  binary  (decimal  interpreta- 

Create  logical  file 

tion) 

Delete  logical  file 

Convert  binary  field  into  ASCII  (hexidecimal  inter- 

Open  logical  file 

pretation) 

Close  logical  file 

Binary  Tree  Manipulation  (Symbol  Table  Utilities) 

Search  tree  for  record 

Parameter  Manipulation 

Extract  nibble  from  byte  parameter 

Load  logical  I/O  parameters 

Insert  record  at  root 

Save  operand  parameters 

Insert  record  at  left  child 

Load  operand  parameters 

Insert  record  at  right  child 

Sort  records  in  tree  (pre- order  traversal) 

Table  and  Array  Manipulation 

Symbol  Table  Record  Manipulation 

Calculate  entry  pointer  =  Table  base  address  + 

Set  record  index  to  symbol  (count, type) 

Set  record  index  to  value  (count, type) 

(  index  *  items  per  entry) 

Arithmetic 

Set  record  index  to  left  child  pointer 

Set  record  index  to  right  child  pointer 

Subtract  two  words  in  CPU  registers 

Set  record  index  to  symbol  text 

Compare  two  words  in  CPU  registers 

Set  record  index  to  value 

Set  zero  and  carry  flags  based  on  word  add  or  sub- 

Text  Manipulation 

Find  field  of  variable  length 

Move  field  of  variable  length 

tract 

Physical  Input/Output  (Character-oriented  I/O) 

Read  (disk,  modem,  terminal,  memory) 

Move  word  (2- byte  field) 

Write  (disk,  modem,  terminal,  memory,  printer) 

Compare  field  of  variable  length 

Open  (disk,  modem,  terminal,  memory,  printer) 

Fill  field  with  blanks  (ASCII  20H) 

Close  (disk,  modem,  terminal,  memory,  printer) 

Fill  field  with  8086  NOPs  (ASCII  90H) 

Create  (disk,  modem,  terminal,  memory,  printer) 

Fill  field  with  any  character 

Delete  (disk,  modem,  terminal,  memory,  printer) 

Program  Execution  Control 

NOTE:  Some  operations  may  be  a  “no-operation” 

Case  of  condition  code  (JMPXI) 

for  a  specific  device,  but  are  listed  to 
preserve  orthagonality  of  the  application 

Execute  indirect  subroutine  (CALLI) 

I/O  system. 

12 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

233 


written  to  be: 


A.  faster,  or 

B.  shorter,  or 

C.  cryptically  clever, 

I  would  like  to  say  that  the  rules  of  my  design  process  are 
totally  at  odds  with  those  of  the  person  who  counts  bytes  and 
clock  cycles.  If  it  pleases  you  to  do  so,  go  ahead.  That  might 
be  a  contributing  factor  to  a  possible  dearth  of  software 
productivity  on  your  part. 

Harsh  words,  to  be  sure,  but  they  are  in  keeping  with  one 
unyielding  fact: 

“Reliable  hardware  is  cheap  and  easy  to  design, 

reliable  software  is  expensive  and  hard  to  design.” 

The  Z-88  CPU  was  complete  in  three  months,  but  the  soft¬ 
ware  took  over  four  times  as  long.  XASM-86  is  still  being  im¬ 
proved  and  extended!  Of  course,  there  are  a  host  of  corollaries 
to  this  one  fact.  Here  are  four: 


JON  A  THAN  MILLS  is  a  renaissance  man  who  completed 
his  B.A.  in  Latin,  chemistry,  and  mathematics.  He  has  at  vari- 
our  times  been  an  officer  in  the  U.S.  Army,  artist,  publisher, 
DP  manager  of  an  IBM  shop,  and  is  currently  wearing  two 
hats,  one  as  an  instructor  of  data  processing  at  the  local  com¬ 
munity  college,  the  other  as  president  of  Programmers  Publish¬ 
ing  Company. 

Rumor  has  it  that  the  prototype  Z-88  was  developed  with 
only  two  tools:  a  volt-ohm  meter  and  Jonathan’s  grey  matter; 
and  that  it  checked  out  afterward  on  an  oscilliscope  well 
within  specifications. 

Mr.  Mills  lives  and  works  in  Kalamazoo,  Michigan,  camou¬ 
flaging  a  128,000  byte  Z-88  development  system  amidst  the 
colorful  orchids  in  his  den. 


1 .  Spend  time  on  program  optimization  only  when 
necessary. 

If  the  program  is  limited  by  the  speed  of  a  disk  interface,  it  is 
stupid  to  spend  three  days  to  make  a  table  look-up  routine  10 
microseconds  faster. 

2.  Optimize  only  when  you  know  where  to  do  so. 

So  the  program  is  limited  by  the  disk?  Then  work  on  the  I/O 
routines.  Try  to  decrease  the  number  of  bytes  in  disk  records. 
Optimize  where  it  will  do  some  good. 

3.  Clarity  is  more  important  than  cryptic  optimization. 

If  you  can’t  understand  the  code,  you  can’t  fix  it,  revise  it,  up¬ 
grade  it,  add  to  it,  or  modify  it ...  so  why  bother  to  write  it? 
If  you  do  have  extra  time,  spend  it  on  better  documentation, 
not  on  expunging  a  clock  cycle. 

4.  Don’t  tempt  Murphy. 

Basically,  if  it  works,  leave  it  alone.  This  is  the  hardest  one  for 
me  to  apply.  However,  if  you  think  you  have  found  a  better 
way  to  do  something,  write  it  down  and  describe  all  the  par¬ 
ticulars.  Let  it  set  for  at  least  24  hours  before  you  change  any¬ 
thing.  Then,  look  at  the  change.  Reconsider  it.  Can  you  detect 
any  unwanted  side-effects?  No?  Okay,  go  ahead  and  try  it. 
Run  it  in'  parallel  with  your  old  version  for  a  while.  Does  the 
new  model  work  after  tests?  After  daily  use?  Then  you  have 
made  a  successful  change!  But,  if  it  does  not,  return  to  the 
original  (you  did  save  it,  didn’t  you?)  and  go  back  to  the  draw¬ 
ing  board  with  the  modification. 

These  rules,  among  others,  have  fostered  the  relatively 
rapid  development  of  XASM-86.  If  the  design  had  not  been 
made  in  a  structured  fashion,  50%  of  the  development  time 
could  have  been  expected  to  be  spent  on  testing  and  debug¬ 
ging.  This  would  correspond  to  a  matching  800  hours  for  the 
time  used  to  analyze,  document,  design  and  code  XASM-86. 
Instead,  only  60  hours  were  spent  debugging  XASM-86.  That 
is  about  90  percent  decrease  from  the  number  of  hours  ex¬ 
pected!  Thus,  XASM-86  is  presented  to  you  in  1981  instead 
of  1982.  It  may  not  be  optimized,  it  may  be  somewhat  redun¬ 
dant  internally,  but  it  is  fast,  it  works,  and  it  may  be  fool¬ 
proof  (depending  on  the  fool). 

I  hope  you  enjoy  it.  If  you  would  like  to  see  the  entire 
package  here,  in  installments,  write  to  the  editor.  ■  ■ 

LISTING  ON  PAGE  22 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 
234 


13 


COMAL-80 
A  New  Language? 


the  years,  various  magazines 
have  published  articles  on  the  advantages 
and  disadvantages  of  different  languages. 

BASIC  has  been  the  subject  of  many 
articles  indicating  its  limitations,  and 
pointing  out  that  even  a  simple  program 
seems  rather  difficult  to  read  and  under¬ 
stand. 

The  articles  often  conclude  by  ex¬ 
pressing  the  need  for  a  language  which 
makes  it  natural  to  build  up  a  program  of 
smaller,  logically  linked  parts,  which  can 
be  called  one  by  one  in  an  orderly  way. 

One  such  language  is  Pascal,  fre¬ 
quently  mentioned  in  contrast  to  BASIC, 
and  just  as  often  described  in  emotional 
terms. 

The  silent  war  between  Pascal  and 
BASIC  fans  will  probably  never  find  its 
end,  as  some  believe  that  Pascal  does  not 
have  proper  editing  facilities  (due  to  the 
construction  as  a  compiler)  and  is  too 
difficult  to  learn. 

At  this  point  it  will  be  suitable  to 
add  that  most  persons  taking  part  in  the 
continuing  discussions  are  EDP  teachers 
showing  an  ever  increasing  interest  for 
Pascal  to  match  their  higher  levels. 

Even  before  this  war  was  started,  an 
attempt  to  build  a  bridge  took  its  start  in 
Denmark.  The  teachers  expressed  their 
dissatisfaction  with  the  possibilities  at 
hand,  and  as  constuctive  criticism  always 
leads  forward,  a  new  language  was  imple¬ 
mented:  COMAL-80. 

This  language  has  its  family  connec¬ 
tions  to  both  Pascal  and  BASIC,  as  it  is 
believed  to  contain  the  best  parts  from 
both. 

As  mentioned  above,  the  demand 
came  from  the  educational  sector  asking 
for  a  better  language,  which  is  the  reason 
for  COMAL-80  having  built-in  program¬ 
ming  support,  and  by  its  structure,  facili¬ 
tates  a  possible  transition  to  more  scien¬ 
tific  languages.  However,  this  does  not 
mean  that  COMAL-80  is  for  education 
only,  as  it  has  proved  valuable  for  admini¬ 
strative  as  well  as  controlling  jobs,  too. 

It  takes  an  extended  BASIC  and  a 
good  Pascal.  Stir  well  and  you  get 
COMAL-80.  At  least,  that  is  the  way  it 
may  look  to  the  users,  but  it  certainly 
takes  a  lot  more  to  take  up  the  competi- 

by  Susan  Sonderstrup 
and  Mogens  Pelle 


tion  with  established  languages,  benefit¬ 
ing  from  many  years  of  adjustments  to 
fit  the  market. 

Rather,  it  takes  a  lot  of  planning, 
hard  work,  and  precision  to  avoid  loose 
ends  to  implement  the  language,  meeting 
the  high  expectations  shown  in  the  pre¬ 
liminary  specifications. 

That  the  results  far  exceeded  the  ex¬ 
pectations  is  proven  by  the  fantastic  re¬ 
sponse  received  from  the  more  than  100 
test-installations  having  been  in  use  for 
about  one  year,  before  the  current  lead 
on  the  educational  market  in  this  coun¬ 
try.  The  good  results  have  spread  the 
knowledge  of  COMAL-80  across  the 
borders,  and  what  seemed  to  be  pioneer 
work  within  Denmark  has  led  to  many  a 
plan  for  other  high-level  languages. 

A  Bit  of  History 

The  idea  behind  this  language  is  not 
new.  It  started  back  in  1973  when  Mr. 
Borge  Christensen,  assistant  professor  at 
the  teachers  college  in  Tondem,  achieved 
daily  access  to  a  computer  equipped  with 
a  BASIC  -  at  the  time  apparently  a  good 
one. 

Pretty  soon  he  found  several  prob¬ 
lems  in  running  this  BASIC.  First  of  all, 
the  students  often  had  problems  reading 
programs  they  had  written  themselves 
some  time  earlier.  Among  the  reasons, 
Mr.  Christensen  found  the  awkward  and 
unnecessary  limitations  for  variable 
names,  which  was  quite  normal  for 
BASICs  at  that  time.  Also,  he  found  that 
in  BASIC  it  is  extremely  difficult  to  write 
structured  programs. 

Mr.  Christensen  not  only  had  the  tal¬ 
ent,  but  also  the  touch  of  luck  needed  to 
make  the  ideas  come  true.  Acquiring  the 
source-code  was  one  thing,  but  having 
two  excellent  people  in  the  area,  Per 
Christiansen  and  Knud  Christensen,  who 
were  able  to  improve  the  code,  was  just 
what  he  needed  to  get  rid  of  the  most  ob¬ 
vious  weaknesses. 

The  result  was  instant  -  students 
found  it  a  lot  easier  to  understand  and 
work  with  this  improved  BASIC,  and  in 
the  years  following  it  was  distributed  to 
colleges  and  high  schools  teaching  EDP. 

In  1978  low-cost  microcomputers 
really  entered  the  market  and  EDP  spread 
into  grammar  schools.  However,  the 
micros  all  had  BASIC  -  and  now  the 
teachers  had  the  knowledge  of  the  im¬ 
proved  BASIC. 

The  demand  for  better  language  on 
micros  became  so  heavy  that  the  imple¬ 


mentation  of  a  new  language  took  its 
start  in  the  summer  of  1978.  The  first 
version  was  released  for  use  on  the 
COMET,  marketed  by  International  Com¬ 
puters  Limited  in  March  1979. 

Through  the  spring  and  summer  this 
version  was  tested  by  more  than  100 
teachers  and  their  students,  whose  com¬ 
ments  and  suggestions  mostly  turned 
into  implemented  improvements.  Most  of 
this  work  was  done  by  Arne  Christensen, 
a  student  of  the  Copenhagen  University 
for  Data  Science,  in  close  cooperation 
with  Borge  Christensen.  (At  this  point  it 
is  worth  mentioning  that  despite  the  simi¬ 
larity  of  their  last  names,  the  four  gents 
are  in  no  way  related.)  The  product  re¬ 
sulting  from  this  work  is  marketed  under 
the  trade  name  of  COMAL-80. 

But  What  Is  The  Difference? 

As  described  above,  COMAL-80  ap¬ 
pears  as  an  improvement  of  BASIC.  The 
most  important  aspect  is  that  it  works  as 
an  interpreter.  Among  the  many  impor¬ 
tant  reasons  for  this,  you  will  find  that 
program  errors  can  be  dealt  with  very  ef¬ 
ficiently. 

When  a  line  is  finished  and  the 
return-key  is  pressed,  the  error-message 
appears  instantly.  To  continue  the  pro¬ 
program,  the  error  must  be  corrected. 
The  cursor  indicates  the  error- point  and 
in  many  cases  COMAL-80  suggests  what 
needs  to  be  done. 

An  example  to  this  important  feature 
is  found  in  figure  1. 

From  BASIC  another  feature  is  in¬ 
herited:  the  line  numbers.  It  is  incorpo¬ 
rated  in  COMAL-80  because  the  basic 
idea  is  to  be  able  to  run  any  BASIC  pro¬ 
gram,  too. 

It  may  seem  strange  to  incorporate 
a  full  extended  BASIC  in  a  new  language 
—  rather  like  putting  a  Ford-T  engine  in 
an  MG-sport  -  but  the  intention  is  very 
clear.  Even  programmers  are  slaves  of 
routine  and  on  numerous  occasions  it 
has  proven  extremely  difficult  to  make 
them  start  all  over  on  a  new  language. 
That  is  why  COMAL-80  offers  the  pro¬ 
grammer  a  chance  to  work  as  if  it  was  the 
good  old  BASIC,  and  slowly  move  to  the 
expanded  facilities  when  the  need  occurs. 
Not  only  can  one  still  be  a  BASIC-freak 
and  run  COMAL-80,  but  even  the  valua¬ 
ble  programs  already  made  in  BASIC  can 
run  in  COMAL-80.  For  the  sake  of  hon¬ 
esty,  BASIC  has  a  lot  of  dialects  and 
some  of  them  are  in  fact  contradictive; 
therefore  some  minor  editorial  correc- 


14 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

235 


tions  may  be  needed,  but  certainly  no 
routines  need  reprogramming. 

Though  the  line-numbers  are  incor¬ 
porated  there  is  no  need  to  use  them,  as 
all  references  to  a  program  can  be  done 
by  labels.  There  is  no  need  to  keep  track 
of  absolute  references  such  as 

30  GOTO  5000 

although  it  can  be  done,  it  could  as  well 
be 

30  GOTO  start 

for  which  “start”  has  been  defined  in 
another  line,  such  as 

100  LABEL  start 

Another  significant  difference  which 
actually  makes  this  language  so  powerful 
is  the  structured  part  which,  as  already 
mentioned,  is  taken  in  from  Pascal. 

First  of  all  the  procedure  concept: 
this  instruction  is  roughly  an  expansion 
of  GOSUB  in  BASIC,  but  significantly 
more  powerful.  The  instruction  has  the 
form  of: 

PROC  name 

ENDPROC  name 

name  which  may  be  called  from  any  part 
of  the  program  by  the  instruction 

EXEC  name 

Parameters  may  be  transferred  to  a 
procedure,  which  may  even  be  declared 
closed.  This  gives  the  advantage  of  allow¬ 
ing  the  same  variable  names  to  be  used 
both  inside  and  outside  a  procedure.  Such 
closing  may  again  be  opened  by  using  the 
GLOBAL-instruction.  Obscure  procedure 
names  are  no  longer  needed,  as  all  names 
may  include  up  to  16  characters.  Mean¬ 
ingful  names  improve  the  readability  and 
the  understanding  of  a  program. 

COMAL-80  includes  conditional  in¬ 
structions.  The  BASIC  instruction  IF  . . . 
THEN  is  of  course  included,  but  it  has 
been  heavily  expanded  to  the  combined 
IF-instruction: 

IF  . . .  (THEN)  . .  .  (ELIF) .  . . 

(ELSE) . . .  (ENDIF) 

In  the  same  way 

ON  i  GOTO  k,l,m 

may  be  used  or  substituted  by  a  stronger 
term: 

CASE  . . .  (OF) . . .  WHEN  , . . 

(OTHERWISE) . . .  ENDCASE 
Repeating  instructions  known  from 
BASIC: 

FOR  . . . TO . . .  NEXT 
may  even  be  used  backwards  in  COMAL- 
80,  replacing  TO  by  DOWNTO.  Further 
it  includes  3  powerful  instructions: 

WHILE  .  . .  ENDWHILE 


REPEAT  . . .  UNTIL 

LOOP  . . .  EXIT  . . .  ENDLOOP 

-  instructions  which  certainly  make 
working  a  lot  easier  to  the  programmer. 

The  above  examples  can  give  but  an 
impression  of  the  significant  benefits 
included  in  COMAL-80.  Hopefully,  the 
program  in  Figure  2  will  prove  more  than 
this  brief  description. 

However,  one  more  advantage  de¬ 
serves  mentioning:  the  PRINT  USING 
function  has  been  expanded  to  have  a  cer¬ 
tain  resemblance  to  the  FORMAT- 
instruction  used  in  other  languages,  and  it 
is  allowed  to  write: 

100  a$:=“ ##.###” 

200  PRINT  USING  a$ :  variable 

How  Does  It  Work? 

As  mentioned  COMAL-80  has  been 
implemented  as  an  interpreter,  the  advan¬ 
tages  of  which  are  numerous,  but  leaving 
us  with  the  drawback  of  lower  speed. 
However,  there  are  ways  to  compensate 
for  this  and  increase  the  speed. 

This  program  has  been  divided  into 
three  parts,  each  doing  its  own  job. 

Part  one  consists  of  two  sub-modules: 
the  editor  and  the  syntax  control  working 
while  keying  in  the  program.  The  editor 
allows  writing,  deleting  and  inserting  any¬ 
where  on  the  line,  and  upon  completion, 
indicated  by  pressing  RETURN,  the  line 
is  transferred  to  the  syntax -control, 
which  checks  the  line  against  COMAL-80 
specifications.  If  a  syntax-error  is  found, 
the  line  is  redisplayed,  the  cursor  indicat¬ 
ing  the  error-location.  Also,  an  ereor-code 
and  one  of  more  than  200  error-messages, 
which  include  over  3,000  letters,  explains 
what  is  wrong.  At  the  same  time  it  re¬ 
turns  to  the  edit-mode,  ready  for  correc¬ 
tions.  This  repeats  until  the  line  is  accept¬ 
ed,  upon  which  the  line  is  transferred  to 
internal  format,  ready  for  later  execution. 

Module  2  —  the  prepass  -  takes  over 
when  the  program  is  to  be  executed.  This 
module  concludes  the  translation  into  in¬ 
ternal  format.  Among  others,  it  extends 
referring  lines  by  the  absolute  memory 
address  for  the  line  referred  to. 

The  program  is  now  brought  to  a  for¬ 
mat  in  which  the  3rd  module  can  work 
very  rapidly.  In  fact,  the  runtime  module 
of  COMAL-80  has  proved  in  several 
cases  to  be  faster  than  BASIC  on  a  16 -bit 
minicomputer. 


Availability 

In  March  1981,  COMAL-80  was 
known  to  be  available  for  different 
micros  running  the  CP/M  operating  sys¬ 
tem,  and  by  now  it  is  probably  available 
for  other  systems  too. 

Conclusion 

The  implementation  of  COMAL-80 
has  demonstrated  that  a  great  idea  may  as 
well  come  from  a  small  country,  and  that 
even  the  complicated  task  it  is  to  turn  the 
idea  into  a  new  EDP-language  can  be 
done  to  the  extent  of  gaining  internation¬ 
al  recognition. 

For  readers  wanting  further  details 
on  COMAL-80,  they  should  contact 
Metanic  ApS,  Kongevejen  177,  DK-2830 
Virum,  Denmark. 

■  ■ 

LISTING  ON  PAGE  46 


This  publication 
is  available 
in  microform. 


University  Microfilms 
International 


300  North  Zeeb  Road 
Dept.  PR. 

Ann  Arbor,  Mi.  48106 
U.SA. 

30-32  Mortimer  Street 
Dept.  P.R. 

London  WIN  7RA 
England 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

236 


15 


Guest  Essay 

Re -Thinking  Program  Editors 


The  Problem 

It  seems  to  me  that  a  great  obstacle 
to  better  programming  is  the  lack  of  an 
editor  that  is  as  well  adapted  to  its  pur¬ 
pose  as  VisiCalc  is  adapted  to  calculation 
in  rows  and  columns.  We  are  writing  pro¬ 
grams,  essentially,  in  the  order  and  style 
required  by  a  compiler  or  interpreter,  not 
that  best  adapted  to  thinking  about  pro¬ 
grams.  This  is,  I  think,  the  root  of  many 
objections  to  Pascal  and  FORTH  (for  in¬ 
stance  DDJ  #48,  #5  1  letters.) 

The  order  in  which  the  programs 
have  to  be  written  does  not  seem  to  suit 
the  way  in  which  people  think  about  pro¬ 
gramming.  I  don’t  propose  to  change  the 
way  the  languages  work,  but  the  way  we 
edit  programs.  If  you  will  bear  with  me 


by  William  B.  Brogden 

William  B.  Brogden,  c/o  Island  Cybernet¬ 
ics,  P.  O.  Box  208,  Port  Aransas,  TX 
78373. 


for  a  little  hand  waving,  perhaps  I  can  ex¬ 
plain  what  I  mean. 

Possible  Solution 

Suppose  we  have  an  “electronic 
blackboard,”  a  two  dimensional  surface 
about  which  we  could  move  freely.  On 
this  surface  we  can  create  and  modify 
“text  boxes”  which  have  labels  and  text 
inside.  On  the  extreme  right  we  may  have 
a  set  of  boxes  representing  the  primitive 
operators  of  the  language  we  are  using. 
Progressively  higher-order  routines  go 
across  with  the  final  main  program  on  the 
extreme  left.  The  rule  would  be  that  a 
routine  can  only  refer  to  itself  or  to  a 
routine/box/operator  to  the  right.  This  is 
similar  to  the  Warnier-Orr  diagramming 
technique. 

Now  for  the  third  dimension.  At  the 
closest  level  of  approach,  we  would  just 
“see”  and  work  in  one  “text  box.”  It 
would  look  just  like  a  regular  editor.  If 


we  “back  off’  one  step,  the  display 
would  show  two  or  three  adjacent  boxes, 
each  with  a  label  and  the  first  few  lines  of 
text  (Figure  1).  Backing  off  another  step 
might  show  only  the  labels  (Figure  2), 
and  a  third  would  just  show  a  dot  for 
each  box  (Figure  3).  It  would  be  like  a 
variable  zoom;  we  could  zoom  back, 
move  over  to  a  new  text  box,  zoom  in 
and  work  on  it. 

We  could  also  move  directly  to  an¬ 
other  text  box  by  name.  Naturally,  the 
name  of  each  box  is  the  name  of  the  sub¬ 
routine,  or  whatever,  inside  it. 

Whenever  we  wanted  to  compile  the 
program,  the  editor  would  know  how  to 
“unravel”  the  two-dimensional  layout 
into  the  linear  file  required  by  the  com¬ 
piler  or  interpreter.  Furthermore,  the 
editor  would  be  able  to  check  each  text 
box  on  demand  to  ensure  that  all  routines 
or  variables  or  operators  called  for  exist 
as  labels  of  boxes  to  the  right. 


FIGURE  1.  Editor  display,  one  “step  back.”  This  is 
not  intended  to  be  a  specific  language. 

1 

: 

:  *  MAIN - • 

s  *  CALL  I!TIT  : 

:  :  CALL  OPFN  : 

:  :  WHITE  NOT(  FOUND  )  : 

:  s  CALL  READ  j 

:  :  CALL  SEARCH  : 

:  :  (VEND  : 

:  :  CALL  OUTPUT  : 

s  :  (etc)  s 

.  *_ _ _ _ * 

: 

:  CALL  GFT.  FILE.  TJ.V'E  s 
t  (etc)  : 

t  : 

: 

*  READ  #1  IV $ 

:  if  fcf  Tim:  found  - 
t  (etc) 

*  (etc.  off  screen 

FIGURE  2.  Editor  display,  two  “steps  back.” 


*  MAIN 


*  IN  IT - ’ 

*  opr'i - 

*  READ - 

*  SEARCH - ' 

*  OUTPUT  - 


*  INS - • 

(other  variables) 
(  etc.) 


FIGURE  3.  Editor  display,  three  “steps  back.” 


Dr.  Dobb ’s  readers  have  been  aiding  the  growth 
and  development  of  the  micro  field  for  years. 
If  you  would  like  to  make  a  contribution, 
contact  us  at : 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


16 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

237 


The  editing  program  would  only 
need  to  keep  in  memory  a  list  of  the 
boxes  and  some  buffers  for  the  current 
and  recently  active  boxes.  The  actual  text 
content  of  most  boxes  would  be  out  on 
disk  storage.  This  would  mean  that 
working  on  the  largest  program  would 
not  slow  down  editing.  Compare  that 
with  the  problems  of  moving  back¬ 
ward  and  forward  long  distances  with  a 
linear  editor.  It  might  be  feasible  to  have 
a  split  screen  showing  the  text  of  two 
boxes  at  once,  depending  on  the  “width” 
of  the  boxes. 

The  Hardware 

Certainly  this  editor  would  require  a 
fairly  fast  disk  and  a  rather  large  amount 
of  memory.  It  is  also  obvious  that  only 
high-speed  terminals  with  cursor  address¬ 
ing  or  memory-mapped  displays  could  be 
used,  but  I  don’t  think  there  are  too 
many  people  doing  serious  programming 


on  teletypes  anymore. 

The  Advantages 

Now,  what  do  we  gain  by  this?  Main¬ 
ly,  the  order  which  the  language  wants  no 
longer  dominates  the  order  of  program 
writing.  The  overall  structure  of  the  pro¬ 
gram  can  be  created  first,  as  a  layout  of 
boxes  (with  comments),  in  a  direct  paral¬ 
lel  with  a  Warnier-Orr  diagram.  Without 
changing  technique,  we  can  start  to  code, 
at  any  “level”  in  the  program.  If  we  want 
to  check  (for  instance)  how  parameters 
are  passed  to  a  subroutine,  we  can  jump 
right  to  it.  Anytime  we  want  an  overview 
of  the  program,  just  zoom  back  one  or 
two  steps  and  there  you  are. 

The  References 

Precedents  for  this  sort  of  editor 
would  appear  to  be  some  of  the  “actor” 
languages  and  two-dimensional  data  base 
layouts.  The  “screen”  editor  of  FORTH 


is  close  but  is  not  flexible  enough.  The 
article  which  most  served  to  crystallize 
my  thoughts  on  this,  and  which  I  recom¬ 
mend  to  all,  was  “Interactive  Systems  & 
Virtuality”  by  Ted  Nelson,  in  Creative 
Computing,  Nov.  &  Dec.,  1980.  Warnier- 
Orr  diagrams  are  described  in  BYTE,  Dec. 
1977  &  Jan.  1978. 

The  Next  Step 

By  presenting  this  idea  in  its  present, 
half-baked  form,  I  hope  to  stimulate  the 
brilliant/unconventional/hardworking  Dr. 
Dobb’s  community  to  start  thinking  in 
the  direction  of  what  a  really  good  pro¬ 
gram  editor  should  do. 

If  you  come  up  with  something 
good,  please  write. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Each  issue  includes: 

•  valuable  software  tools 

•  algorithms  &  problem  solving 

•  industry  news 

•  important  product  reviews 

With  in-depth  coverage  of: 

•  telecommunications 

•  systems  programming 

•  language  development 

•  machine  independent 

programs 

and  much,  much  more ! 


Yes !  Please  enter  my  subscription  for 

□  1  yr.  (12  issues)  $25  □  2  yrs.  $47  (save  $13  off  newsstand) 

□  Please  bill  me  □  I  enclose  check  /  money  order 

Name _ 

Address  _ 

City _ State _ Zip - 


Dr.  Dobb’s  Journal,  A  Publication  of  People’s  Computer  Company 
1263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  CA  94025 


Are  you  ready? 

DDJ,  the  world’s  foremost  microcomputer 
publication,  has  been  working  for  years  to  pre¬ 
pare  its  readers  to  be  innovators,  to  lead  the 
wave  of  breakthroughs  in  our  changing  tech¬ 
nology. 

Every  issue  of  Dr.  Dobb’s  Journal  helps 
one  to  understand  the  nuts  and  bolts  of  small 
computer  systems.  We  offer  entire  listings  of 
valuable  software:  our  pages  have  included 
compilers,  cross-assemblers,  editors,  new  lan¬ 
guages,  hardware  interfaces  and  more  —  usually 
before  anyone  else  thinks  of  them ! 


Even  more  Important! 

Our  subscribers  share  insights,  correspond, 
and  contribute  to  one  another’s  work,  more 
than  any  other  group  we  know.  They  treat 
Dr.  Dobb's  Journal  as  a  “hands-on”  publication. 

This  warm  cooperation  has  done  more  to 
refine  software  products,  and  generally  to 
advance  the  state  of  microcomputer  techno¬ 
logy,  than  perhaps  any  other  resource.  And  it  is 
available  to  you  through  our  pages ! 

For  the  straig  ht  facts . 

If  you  are  a  serious  computing  professional 
or  enthusiast,  then  you  should  take  a  very  close 
look  at  what  DDJ  offers  you.  We’ve  been  on 
the  cutting  edge  since  1976. 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 
238 


17 


H8  Text  Editor 
to  CP/M  File  Conversion 


F 

JL  or  almost  three  years  after  I  got  my 
H8  computer  I  put  up  with  the  increas¬ 
ingly  frustrating  vicissitudes  of  cassette 
I/O.  During  this  time  I  built  up  a  large 
collection  of  tape  files:  assembler  source, 
Tiny  Pascal  source,  and  general  data,  as 
well  as  BASIC  source  and  “memory 
image”  (load- execute)  files.  When  I  final¬ 
ly  bought  two  disk  drives  and  CP/M,  I 
wanted  to  be  able  to  transfer  some  of 
these  files  to  disk  without  having  to  key 
them  in  by  hand. 

I  wrote  the  TAPECOPY  program, 
whose  source  is  included  here,  to  do  this 
job  for  me.  In  planning  the  program,  I 
realized  that  I  really  only  needed  to  con¬ 
vert  files  which  had  been  created  by  the 
Text  Editor  (TED-8).  This  included  as¬ 
sembler  source,  Pascal  source,  and  data 
files.  Converting  BASIC  source  and  mem¬ 
ory  image  files  involves  special  problems, 
and  I  did  not  feel  that  I  needed  this  capa¬ 
bility.  (I  was  not  planning  to  get  a  disk 
BASIC.)  So  TAPECOPY  converts  only 
Text  Editor  files.  Anyone  interested  in 
converting  other  file  types  should  study 
the  “Tape  Files”  section  in  the  H8 
“Software  Reference  Manual,”  and  use 
TAPECOPY  as  a  basis  for  their  own  pro¬ 
gram. 

Instructions  for  the  use  of  the  pro¬ 
gram  are  included  in  the  initial  comments 
in  the  source.  The  program  has  the  option 
of  viewing  the  data  on  the  screen  as  it  is 
being  transferred.  This  can  be  helpful 
since  there  is  no  indicator  of  the  progress 
of  the  conversion  other  than  the  move¬ 
ment  of  the  tape,  but  it  can  slow  down 
execution,  particularly  if  your  screen  has 
a  low  baud  rate. 

If  the  disk  file  specified  already 
exists,  you  are  given  the  chance  to  erase 
the  file  or  abort  the  program.  In  the  latter 
case,  you  would  simply  rerun  the  pro¬ 
gram,  specifying  a  different,  non-existing 
file  name. 

In  opening  the  tape  file,  the  program 
checks  the  first  complete  record  to  see  if 
it  is  a  TED-8  file  with  record  sequence 
number  zero.  If  both  of  these  conditions 
are  not  true,  it  is  assumed  that  you  posi¬ 
tioned  the  tape  in  the  recorder  ahead  of 
the  desired  file;  the  tape  is  then  searched 
for  the  first  occurrence  of  the  correct 

by  Jim  Scott 

Jim  Scott,  1724  Blakemore  Road, 
Richmond,  VA  23225. 


record  type. 

If  successive  records  do  not  increase 
in  sequence  number  by  1  until  the  end  of 
the  file  is  reached  (the  last  record  has  the 
EOF  bit  on),  the  program  terminates  with 
the  message  “Tape  Sequence  Error.” 
Other  error  messages  which  can  occur 
have  to  do  with  disk  problems,  and  are 
mostly  self-explanatory. 

As  mentioned  in  the  program  com¬ 
ments,  a  checksum  error  in  a  tape  record 
will  cause  the  program  to  stop  with 
no  message.  The  only  indication  of  a 
problem  will  be  when  you  eventually 
notice  that  the  recorder  is  not  moving 
and  no  other  activity  is  taking  place.  I 
have  not  attempted  to  fix  this  inconven¬ 
ient  characteristic  of  the  program,  mainly 
because  I  consider  it  a  temporary  utility; 
I  will  not  be  using  cassette  much  after  I 
get  my  files  converted.  However,  the  fol¬ 
lowing  comments  may  be  of  help  to  any¬ 
one  who  is  inclined  to  try  to  clean  up  this 
detail:  routines  in  the  Panel  Monitor 
(PAM -8)  ROM  are  invoked  to  find  the 
beginning  of  a  record,  to  read  the  next 
byte  from  tape,  and  to  verify  the  tape 
checksum.  The  PAM-8  code  would  ordi¬ 
narily  sound  the  H8  audible  alarm  when  a 
checksum  error  is  detected;  however,  the 
code  to  do  this  depends  on  the  2mS  clock 
interrupt.  CP/M  seems  to  run  with  inter¬ 
rupts  disabled  much  of  the  time,  so  the 
error  routine  probably  gets  into  an  end¬ 
less  “disabled”  loop.  The  problem  could 
probably  be  eliminated  by  replacing  the 
PAM -8  routines  with  your  own  similar 
routines  which  could  assure  that  inter¬ 
rupts  are  enabled  at  the  proper  times 
by  using  the  El  (Enable  Interrupts)  and 
DI  (Disable  Interrupts)  instructions.  The 
source  for  PAM-8  is  in  the  H8  “Software 
Reference  Manual.” 

The  main  loop  of  the  program  sim¬ 
ply  calls  GETCHAR  and  PUTCHAR  re¬ 
peatedly  until  the  tape  file  is  finished. 
The  first  time  GETCHAR  is  called,  it 
finds  the  beginning  of  the  tape  file  and 
reads  the  header  record  and  the  first  data 
record.  Each  time  it  is  called,  it  returns 
the  next  data  byte  from  the  input  buffer, 
and  it  reads  a  new  record  into  the  buffer 
whenever  the  previous  record  is  exhaust¬ 
ed.  In  two  cases  (see  below),  the  byte  re¬ 
turned  is  a  translation  of,  not  identical  to, 
what  was  on  the  tape.  The  first  time 
PUTCHAR  is  called,  it  opens  the  disk 
file.  Each  time  it  is  called,  it  adds  the  new 
byte  to  the  output  buffer  and,  when 
necessary,  writes  a  disk  record  and  clears 
the  output  buffer. 


The  tape  record  format  is  described  in 
the  “Tape  Files”  section  of  the  H8  “Soft¬ 
ware  Reference  Manual,”  which  refers  to 
the  TED-8  format  as  “compressed  text.” 
Each  string  of  spaces  is  compressed  by 
TED-8  into  a  single  byte  consisting  of  the 
hex  value  80  plus  n,  where  n  is  the  num¬ 
ber  of  spaces.  Also,  there  are  no  carriage 
return  or  line- feed  characters  in  the  tape 
records;  the  end  of  each  line  is  represent¬ 
ed  by  a  byte  with  a  value  of  zero.  TAPE- 
COPY  expands  bytes  of  hex  value  8 1  and 
higher  into  spaces,  and  it  expands  a  zero 
byte  into  a  carriage  retum/line-feed  pair. 

This  program  was  developed  under 
CP/M  for  Heath  H8,  Version  1.43.  For 
Standard  CP/M  (zero  origin),  change  the 
BASE  EQU  from  4200H  to  OH.  I  later 
installed  Heath’s  “Extended  Configura¬ 
tion”  option.  I  found  that  the  program 
did  not  work.  I  have  not  yet  determined 
why  this  is  true,  but  I  was  able  to  fix  the 
problem  by  copying  the  needed  routines 
from  the  Panel  Monitor  into  my  source 
program.  This  also  eliminated  the  prob¬ 
lem  of  system  death  when  a  checksum 
error  occurs  on  the  input  tape. 

The  details  of  the  fix  are  as  follows: 

1.  Copy  the  routines  CTC,  SRS,  RNP, 
RNB,  and  CRC. 

2.  Drop  the  equates  for  CTC,  SRS,  and 
RNB  in  the  original  TAPECOPY. 

3.  Add  equates  for  ASYN,  ASTX, 
UCIRO,  UCIER,  UCIRE,  USRRXR, 
IPTPD,  and  IPTPC. 

4.  In  CTC,  change  the  MVI  A,1  instruc¬ 
tion  to: 

XRA  A 

OUT  OPTPC  ;TURN  OFF  TAPE. 
CALL  MSGOUT 
DB  ‘TAPE  CHECKSUM 
ERROR’  ,CR,LF,0 
JMP  BOOT 

5.  In  RNB,  change  the  CALL  TPXIT  in¬ 
struction  to: 

IN  IPTPC 

6.  Include  the  following  DS: 

CRCSUM  DS  2  ;CRC-16 

CHECKSUM 

7.  Change  JE  and  JNE  opcodes  to  JZ  and 
JNZ,  respectively,  in  the  SRS  routine. 
Otherwise,  the  CP/M  assembler  will  do 
terrible  things. 

(Continued  on  page  50) 

(LISTING  ON  PAGE  40) 


18 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

239 


A  Tiny  File  System 


IJ 

JL  Aow  can  we  describe  the  machine- 
dependent  parts  of  a  portable  system? 
I’ve  been  working  on  a  portable  operating 
system  which  now  includes  a  small  editor, 
a  small  compiler,  and  a  compiler  genera¬ 
tor  based  on  Metall.  But  they  all  rest  on 
file  input  and  output  which  is  very 
machine- dependent.  This  is  an  attempt  to 
specify  a  simple  file  system  that  I  hope  I 
can  replicate  on  my  next  computer.  It 
works  on  my  current  Apple  II  and  has 
supported  further  development  of  a  single 
user  bootstrap  operating  system. 

This  “tiny”  file  system  is  to  a  com¬ 
plete  file  system  as  tiny  BASIC  is  to 
BASIC.  That  is,  it  is  severly  truncated. 
Space  allocation  is  sequential,  which  is 
too  simple  for  a  complete  file  system.  Di¬ 
rectory  maintenance,  along  with  file 
entry  and  removal,  rest  entirely  in  human 
hands.  However,  these  minimal  files  can 
be  used  to  implement  a  more  elaborate 
file  system  which  need  not  see  the  ma¬ 
chine  dependencies  of  this  tiny  file  sys¬ 
tem. 

Since  the  file  system  is  much  simpler 
than  Apple’s  DOS,  one  might  ask  why  I 
went  to  the  trouble.  First,  my  intention 
was  to  provide  a  basis  for  portability  to 
future  machines  I  might  have.  So  I  didn’t 
want  to  tie  into  DOS  except  possibly  at  a 
buried  level.  Second,  I’d  rather  not  have 
to  pay  the  space  penalty  for  the  entire 
DOS.  This  simple  file  system  used  only 
Apple’s  RWTS  routine  (Read  Write  Track 
Sector)  from  DOS  and  leaves  a  net  gain  of 
8K  bytes.  Using  the  entire  resources  of  a 
small  computer  one  always  faces  a  trade¬ 
off  between  complexity  in  one  part  of  a 
system  for  complexity  in  other  parts.  A 
choice  in  complexity  and  size  of  file  sys¬ 
tem  is  worth  having.  Third,  the  buffer 
sizes  required  by  this  file  system  are  half 
the  size  required  by  Apple’s  file  format.  I 
have  sketches  for  (machine  independent) 
assignment  programs,  and  for  a  portable 
directory  system  that  extends  this  sys¬ 
tem. 


by  William  A.  Gale 


William  A.  Gale,  439  S.  Orange  Ave.,  S. 
Orange,  NJ  07079. 

The  Author  works  in  statistics  and  econo¬ 
mics  at  Bell  Telephone  Laboratories. 
©1981  by  William  A.  Gale. 

All  Rights  Reserved. 


In  planning  for  an  assembly  language 
version  of  this  simple  file  system,  I 
thought  about  it  by  writing  high  level 
“programs.”  These  are  not  in  any  known 
programming  language,  but  tend  to  use  C 
lexical  conventions  and  should  be  easily 
readable.  Writing  these  high  level  specs  let 
me  identify  precisely  what  I  wanted  the 
outside  to  look  like  and  let  me  define  a 
set  of  internal  variables  and  procedures  to 
accomplish  that.  Having  it  written  prob¬ 
ably  eased  the  assembly  langauge  pro¬ 
gramming.  I  found  when  I  was  done  that 
I  had  made  my  usual  error  per  twenty 
assembly  lines,  but  only  one  error  at  the 
high  level,  so  I  didn’t  have  any  massive  re¬ 
visions  to  carry  out.  I  expect  a  third  bene¬ 
fit  that  lies  in  the  future  when  I  do  it 
again  on  another  machine.  I  hope  it 
makes  the  assembly  language  program¬ 
ming  easier  there.  This  basic  file  system 
represents  about  80%  of  the  machine 
language  support  for  the  portable  code, 
so  easing  it  means  easing  a  hard  part  of 
transporting  my  code. 

My  goal  was  to  write  simple  and  easi¬ 
ly  repaired  code.  Since  input  and  output 
take  a  lot  of  time,  I  was  not  worried 
about  time  very  much.  As  it  works  out, 
the  system  charges  an  overhead  of  about 
170  microseconds  per  byte  read  with 
this  code.  That  corresponds  to  about  2 
seconds  in  reading  the  entire  disk,  or 
about  6%  overhead  on  the  30  seconds  this 
seems  to  take  on  an  Apple. 

The  description  has  three  levels  of  in¬ 
creasing  machine  dependence.  The  outer¬ 
most  layer  is  as  machine  independent  as 
possible.  It  embodies  the  purpose  of  this 
software,  to  provide  sequential  files  with 
single  character  access.  At  this  level,  the 
storage  device  consists  of  a  numbered 
sequence  of  abstract  BUCKETS  (sectors, 
blocks, .  . .),  numbered  from  zero  to 
MAXBUCK.  MAXBUCK  is  a  necessary, 
machine-dependent  parameter.  Each 
bucket  can  store  MAXCHAR  characters, 
after  allowing  for  a  little  overhead  for 
lower  level  variables,  each  field  that  is 
opened  requires  the  assignment  of  a 
BUFFER,  which  holds  the  data,  some 
lower-level  variables,  and  any  machine- 
dependent  data  required.  The  size  of  this 
buffer  is  thus  machine-dependent.  The 
system  returns  an  error  code  to  the  spe¬ 
cial  location  ER  along  with  each  opera¬ 
tion.  The  values  that  ER  can  take  are 

0  no  error 

1  end  of  file  or  end  of  medium 

2  bad  transaction  requested 

3  hardware  error 


When  end  of  file  is  encountered  on  read¬ 
ing,  the  character  EOF  is  returned. 

In  thinking  about  the  scale  of  the 
parameters  MAXBUCK  and  MAXCHAR, 
I  had  in  mind  three  possible  storage  con¬ 
figurations  for  an  Apple : 

1.  The  single  disk  I  now  have.  It  has  35 
tracks  of  13  sectors,  each  with  256 
characters. 

2.  Four  Apple  disks  as  a  unit.  Two  slots, 
two  drives,  35  tracks,  13  or  16  sectors, 
256  characters. 


3.  A  hard  disk  holding  30  megabytes  in 
60K  sectors  of  5 1 2  bytes  each. 


For  these  I  planned  on 

1 

2 

3 

MAXBUCK 

454 

1819 

60000 

MAXCHAR 

252 

252 

508 

buffersize 

175 

275 

? 

The  specific  operations  the  file  sys¬ 
tem  supports  are: 

OPEN  a  BUFFER  for  READ  or 
WRITE  at  a  given  BUCKET.  The  file  ex¬ 
tends  from  a  given  bucket  onward. 

CLOSE  a  BUFFER.  If  writing  the 
buffer  will  be  flushed  and  the  last  bucket 
marked  as  the  end  of  the  file. 

PUT  a  character  into  a  BUFFER. 
The  buffer  is  emptied  to  disk  automa¬ 
tically  when  it  is  full  of  data. 

GET  a  character  from  a  BUFFER. 
The  buffer  is  everflowing,  being  refilled 
from  hardware  as  required. 

It  turns  out  that  it  might  as  well  sup¬ 
port  the  more  primitive 

READ  a  BUCKET  into  BUFFER. 
WRITE  a  BUFFER  into  BUCKET, 
since  PUT  and  GET  need  them.  Also, 
they  look  useful  for  implementing  ran¬ 
dom  access  files,  including  directories. 

The  second  layer  of  the  interface 
adopts  a  particular  means  of  supporting 
the  outer  layer,  by  describing  the  buffer 
contents.  The  buffer  contains,  in  the  first 
place,  the  image  of  a  bucket,  with  data 
from  the  zeroth  to  MAXCHAR  positions, 
followed  by  BYTESPRESENT  and 
NEXTBUCK.  BYTESPRESENT  is  a  vari¬ 
able  which  shows  the  number  of  charac¬ 
ters  entered  in  the  bucket.  To  accommo¬ 
date  a  possible  508  MAXCHAR  bucket, 
I  made  it  two  bytes.  NEXTBUCK  is  a  var¬ 
iable  which  contains  the  bucket  number 
of  the  next  following  bucket  in  the  file. 
Here  this  is  just  the  current  bucket  +1, 
but  a  more  elaborate  assignment  system 
will  need  to  record  the  bucket.  To  accom¬ 
modate  even  455  buckets,  it  needs  to  be 
two  bytes,  which  is  also  enough  for  the 
30  megabyte  disk.  The  last  bucket  in  a 
file  is  shown  by  setting  NEXTBUCK  to 


20 

240 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


zero. 

The  buffer  also  contains  space  be¬ 
yond  the  bucket  image  for 

CURRBUCK  -  the  bucket  from 
which  the  data  was  read  or  to  which  it 
will  be  written. 

NEXTCHAR  -  the  next  character  to 
be  read  or  written. 

TRANSACT  -  the  purpose  for 
which  the  buffer  may  be  used.  It  has 
values 

CLOSED 

OPENREAD 

OPENWR1TE 

Finally,  the  buffer  has  space  for  any 
machine -dependent  variables  required 
(Apple’s  IOB  table  in  my  case). 

The  innermost  layer  of  the  file  system 
gives  the  mapping  from  buckets  to  local 
coordinates  —  blocks  or  sectors  or  what 
have  you.  The  mapping  should  make  the 
“next”  sequential  bucket  an  easy  one  to 
get  from  the  previous  one.  For  one  Apple 
drive,  I  specified 
Slot  =  6 
Drive  =  1 

Track  =  Bucket/ 13 
Sector  =  Bucket  mod  13. 

If  Apple  had  not  interleaved  the  sectors 
of  a  track  already,  this  would  have  been 
a  good  place  to  do  so.  This  layer  also 
contains  the  details  of  transferring  a 
bucket  image  form  memory  to  the  hard¬ 
ware.  I  used  Apple’s  RWTS  routine.  This 
is  the  fundamental  capability  that  the 
high  level  routines  assume.  It  seems  rea¬ 
sonable  to  stop  here,  because  any  further 
down  is  hopelessly  machine- dependent. 

High  Level  Specs 

Open  BUFFER  for  TRANS  at  BUCKET 
ER=0 

if  (TRANSACT  !=CLOSED) 

{ER=2;  return) 

TR  ANS  ACT=  OPEN-TRANS 
CURRBUCK= BUCKET 
NEXTBUCK=0 
NEXTCHAR=0 
B YTESPRESENT =  0 
fill  data  space  with  EOF 

Close  BUFFER 
ER=0 

if(TRANSACT==CLOSED) 

-[ER=2;  return) 

if  (TRANS  ACT== OPENWRITE) 
-[NEXTBUCK=0 
write  BUFFER 
] 

TRANSACT=CLOSED 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


Read  BUFFER 
ER=0 

if  (TRANSACT !  =  OPENREAD) 
-[ER=2;  return) 
if(CURRBUCK=0) 

)ER=  1;  return) 

input  bucket  image  from  CURRBUCK 
if  (read  error) 

-[ER=3;  return) 

CURRBUCK= NEXTBUCK 
NEXTCHAR=0 


Get  CHAR  from  BUFFER 
ER=0 

if(TRANSACT!  =  OPENREAD) 
-(ER=2;  return) 

if  (NEXTCHAR=  =  B  YTESPRESENT) 
(if(CURRBUCK=0) 

)CHAR=EOF;  ER=  1 ;  return) 
else 

read  BUFFER 

) 

if(ER  !=0)  return; 

CHAR=  BUFFER!  NEXTCHAR] 
NEXTCHAR++ 

Write  BUFFER 
ER=0 

if  (TRANSACT  !=OPENWRITE) 
-{ER=2;  return) 
if  (CURRBUCK  >  M  AXBUCK 
or  NEXTBUCK  >M AXBUCK) 
iER=  1 ;  return) 

transfer  bucket  image  to  CURRBUCK 
on  hardware 
BYTESPRESENT=0 
NEXTCHAR=0 
fill  data  space  with  EOF 

Put  CHAR  into  BUFFER 
ER=0 

if  (TRANSACT  != OPEN  WRITE) 
)ER=2;  return) 
if(NEXTCHAR==MAXCHAR) 
■[assign  NEXTBUCK 

(=CURRBUCK+  1) 
write  BUFFER 
CURRBUCK= NEXTBUCK 
) 

if (ER !  =  0)  return 

BUFFER!  NEXTCHAR]  =CHAR 

NEXTCHAR++ 

BYTESPRESENT=  NEXTCHAR 

(LISTING  ON  PAGE  40) 


21 

241 


* 

TO  T  lu  co 

ii  £!* 


o  o  o  o  o 
o  o  o  o  o 

®  ffioS  « 

SSS8  g 

n  3  Sa  J 


_  fl?  aa 

Ifii 


!*£ 


r££  (OU.  aS  m  m  m 

\n  li  s**l  ggil  ?  i®  §  s 

•111 1111 llll ||S| sSBSBsfciRf is?!? 


f  a;S£  £££  SS  £5^5  8gSg  § 

>oooc*OoooOoooOoooOooooooo<=o  -  _  _  _  _  _ 

SSS!S§==gS5SS5gs§sgSSS§2SjBgg|jBgfeg§; 


§  l 


o 

O 

o 

o 

o  O  O 

O 

O  o 

O  o 

o 

UJ 

fctS  (bin 

8 

si 

i r> 

o 

s 

O  -H 
O  O  QQ 

o 

00 

o  o 
— •  o 

00  00 

o 

o 

& 

Cu 

—  —<<=•  O 
o  o  O  o 

Sffi  s  $ 

o 

8 

BBOO 

2202 

2202 

2202 

2302 

0102 

9202 

8002 

2302 

0102 

9202 

8002 

^  i$i  CD 

§m  s 

O  O  o  O  O  o  O 

v£  N  00  OS  o  ^  (S| 

*  ^  ▼  ♦  m  ir>  tr> 


Ssl  £ 

o  o  o  o  o 


kH 

3 

O 

a 

5  c 

CO 

<D 

°  t 

-C 

<u  cd 

+-» 

3  £ 

cd  4_, 
•*-*  CO 

9  5  « 

Ops 

u  Er 

0J  w  <o 
z  0)  -O 

^  r-  CO 

Si-  2 


¥h£ 

—  GO  H  —  CO 
Cl 

O  UJ  •  0) 

»_  o:i  »-i »-  co 
tWw  w  CO 

f8  SB 

3  cl  -  UJ  X 

O  Cl  UJ  LL  a 

Q  h-  Ct 

S  8  s  8  = 

CO  CO  °  o 

•-it  fc  li. 

£  .2*8 

iin§2£ 

K  X  I  Jf 
* 

£  □  fi  X  ^  I 

C«4  O  □  O 

N  I  gi 

i  sSalls 

O  |  *-i  I  U 

io°i 

8™  fc  ►“  UJ  £ 

^  O  >  «J 

H-  „  UJ  U.  CD  O 

S?*ijij! 

U  N  h  H  UJ  Ll 

I  ,  ,  1x1  _  Ll_  •— • 

nti^i 
*  *******; 
OOOoOoC’CO' 
—  <MK)5«n^N®CT' 
OOOOOOOOO. 
OOOO  c-o  O  ©  ©  < 


O  «  X 

*  .  K  •" 

_  o  a  i- 

iP  §  s 

e  m  *  ^ 

.  ^  *— 

^  -  J  S  d 

5  jcoa  Ll 

S  '  ^  c,  w 

.  w  u.  x  “ 

£81*88  h 
<r  f  jhu  j  >-i 

********* 

ooooooooo 

OOOOOOOOO 


JT  .  .  U  S  0*J  ffi 

CO  UJ  ►—  ►—<  O  m 

>  X  9  a  X  flt  I 

co  P  ZoPi  ft 

********* 

OOOOOOOOO 

rpas°^(S4*o-.inVft 

i<S£*K)K>E»oSroPS 

OOOOOOOOO 


©OOOOOOoOoOoO 

ssssssslsssls 


22 

242 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


£  I 
**  t  2 

35  |  i 

h  ►-  0  *-• 

CO  M  V  V 

P?  ^  »-  b- 

*?  |  g 

is  s  § 


**“  £&&& 
J5  5a!5a! 

^  SS£S 

5  S  »"  HH  h- 

5fc 


ii  ills  s 


A  A 

•H  ^  K 


3  a  «■  cl  & 

:  is  skis 


m  &  m  & 
2  2 
88  S  8 

g 

n-i  '— *  *— •  rr 

:>  z>  :>  s 

S  2  S  2 

A  £ 

1*18 

W  w  3  5 

=  =  «  £ 


o 

o 

£ 

2900 

2800 

8128 

8028 

1900 

1800 

8118 

8018 

s§ 

tB 

F718 

F618 

3900 

3800 

8138 

8038 

o  o  m  CD 
M  CM  CS  CM 

*4  rw  V|5 

u.  U.  U.  u. 

S 

s 

8 

U.  U.  u.  £ 

S 

gss 

o  ® 

K.  sD 

U.  U. 

D120 

D020 

O  o 
CM  (SI 

o 
O  A 

o 

8 

0088 

ooaa 

2302 

0102 

9202 

8002 

2302 

0102 

9202 

8002 

2801 

0801 

2801 

0801 

2302 

0102 

9202 

8002 

§  3 

is 

2801 

0801 

2801 

0801 

o 

O 

s 

2B01 

0801 

2801 

0801 

0088 

0088 

0088 

2801 

0801 

SS 

»* 

2802 

0602 

1  11  slii  ilsl  si  **  ilsi  11  sili  1  ill!  l*s  si  u  *; 

o  ooooooOoooOoOoooOooeooooOQOoooooooooOo  0<=0<=000<=0®0=>0<= 

R  S3  53  33S3&3SSs:RBSRKfc£esS8  8X8*t8  8SStf8XK*  is  II  si is  ill  sis 


'(NNNiN(NN(M(N(NN(N 


o  2  &  05  aj  of)  S 


S22Sfi3fc 


a!  d  i  ai  i  5  5  S 


Ci 

2fip&&w5&2  ;  £  co  co  m  (O 

Jlffiifiili®!;  »**  t-  uj  o  crt  o  « 

>ooooooooooc*ooooooooo®ooo 

!gS58SS£8&$£SSggS8£fe£$SS& 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


23 

243 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


I  * 

Im  Si 
££££  8 
W  S  U  K 
4  O  >  O.  to 
r  at  01  o 


&  §  i*i  &  §  Hi  £  & 


«K  228  tfe&  28 


o  o  O  o  O  O  o  o  O  O  o  o 

©  O  ©  o  ®  ©  ®  ©  ©  ©o© 

SmflQmCC.  aim  op  06  m  m  m 

GO  00  00  UJ  Lu  CD  ui  Sj  CD  QQ  CD 


i 8 z ft s  SS  5g  111  IS 

<EJ— IUJ&  U.  U.  Li.  li-  OOO  CL 
O  O  O  ®  ©  ©  O  O  ©  ©0©©0©®0 


o  o  o  o  o  © 

sc  °  r  ^  ^  t 

ro  er  a  <j\  <j\  <T‘ 
M  n  n  n  n  n 


a.  a.  xxx  a.  t  ft  «  *  * 

ooo  ooooooooooo- 

n  n  k>  n  ro  n  ■*■*•*•*■  *■  *•  ^  - 


:  8  8  *  8  8  £ 


(J  ut 

5S8! 

£  q2«|! 

h-  «  u3  8  O  Q  i 


OOOOOO®®©©© 
<N  K>  m  \0  N.  GO  <T-  ®  —  N 

(NAifi 


ft  o  > 
Z  iii  uj 

<r  oi 

ft  vO 
At  A 

H  ©  K  O 

i>  iz 

LU  03  u  M 
8  £  a  £ 
5^5> 

<2S  £2 

OHOt 

V  Z  V  — > 

•—  u» 


A-  A  A 

^ ..  5 1 

LU  £  UJ  — 

ioi£ 
a  Ks!ul 
|q25 

©  H-  t-i  t 

viv5 

tota 


o  r  «  ^  w 

£!*!!*&  3  g 5 LH 

h  t  h  Cj  «  li  S  ui 

^£§5  °ep? 

_i  —i  — i  _i  a,  a.  | 

55^  Mi 


Ui  M  UJ 

*£*!£, 


8  ui 

a  Q;  o  x 

jsiiti 

o  •-•  <r 

Ct  h-  Q:  ® 

flSSgS£2 

li.  li.  u.  li_  Lu  u.  u. 


5  ,  >H 

rfpicoiStSz 

5oUi  jjaUo 

OUJUJUJWI-H. 

UJ  _J  — J  5i  ©  Cl  C*  01 

SSSSSSSS 


I  a! 

UJ  _• 

Q. 

g  *  g 

&fcfeg 

UJ  U  UJ  >  •- 

r  j  ►=:  »-  yj  uj  ►-  k 

®  cl  2 

ft—  UJ  UJ  O  O  fit  0  * 

§  8  8  *  £  £  £ 


LlU-LlU.U.U-UjU.  U-U.U.U.U-UU-  U-U_U.LlU-U-U.Ll  U-U.uU-U.Ll  u. 


iiiii 


ml 

£a  So1 

O'  KJJ  CO  01 

DDdS 

V  V  s/  v 

to  o  cd  m 


A  A  A  A 

K  2  K  z 

£  Z  H  Z 

CO  &  CO  w 

Sc  Sc 

V  V  V  s/ 

ffi  &  CD  CO 


i  UJ  g  ££ 

j  ui  uj  uj  uj 

ssss 

J  -J  ^  J  2! 

5  co  co  co  <J  > 

^  S  ©  S  S 

/  v  V  v  v 

'j  2d  Zd  CD 


/\  •'■  /N  A 

:KhHht 
|  uj  lu  UJ  LU  UJ 

it  kj  <x <r 

oJ  2l  Sl  k  CL 

01  co  01  CO  01 

S  Cl  Q  G  S 

s/  V  V  V  V 


:  z  2  z  z 

j  uj  LU  uj  UJ 

1  8  U  £  S 


>  ®  ©  £j  Ct 

'  V  V  V  V 

1  ©  2d  cl  ld 


©  00  o  00 

s s  2  E  s  E  at st  Gass*  s  p  *  £  *  s  j? 


RefeKfceicR  iceitRfcfes 


o  S  o i ;  S  S  S  S  ofoSo  SoSoSoSo  3 " o  S  o  S  o  0SSS0SS3  SSSSSSS 

88  S  £  £  S  $88*8  8888*88$  $8$$$$$  $$$$$$$*  $$$$$$$ 


O  O  J  J  J  J  <!>  (J)  li  CO  OI  ►—  ui  ui  O  ui  LJ  01 

PP  Wri%Sfcoo  NSiiitS  5!  IK »  HI  a:  £  e 

CO  to  0000  *-;*->*->*->  5  a:  a  il  m  ^hhncjRn^  >->  f£j  ^  *->  •“>►->  t-,  £>»->  R  *“-»”>»■■>  R  »— >  *— >  »— >  »->  »— >  »-> 

®©©©©©®©©®©©©®©®©®©©©©©©©©©©©©©o©©©®  ooo®©©©©©©©®©©©©© 

$Ski$££££;?IC£fc£aiSS8J8Sfe8iSSS83!IS!*&*$§  S88S8«fe8S2  =  22222^ 

innnncmw(ncmin(mc^(mnn^nmno<nmcIic:jnnn(Si(mmn.nnnninm  m  w  mo  n  m  m  w  m  m  k)  n  m  m  m  K)  m 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


25 

245 


"O 
0 > 
3 

.£ 

*-C 

c 

o 

U 


E 


Q. 

oo 


c. 

UJ 

t 

o 


a!  £ 


o  J 

fcf*8 

E°g| 

O  W  £l  -J  O' 
w  M  co  O  N 


>  00 
CJ  to 

ft1 


U  g  e 

Ills! 


a  s  2  S  *  a 

+  Bat 

n  R  P  P  S  to  w 

. *  |5g 

a 


a  ® ' 

sdHls&r 


|s|il|j  |§i  ggjggggj  Erl? 


O'  fe&f 
to  5  S  a  2 

£&&&& 

isis^ 


*§ 

IgllEg 


a.  o 

£  •- 
•H  = 


i.  — . 

2  '£ 

&  *-■ 


iiiS  1115  °  ‘“sillllllllllilgii  Slllllli  ssss 


a 

T 


*2 
c-  £ 
o 


0  0  t-1 

*s 

&  _l 

UJ  _J 

r-  t 


dl 


y-  .j  _i 

ns  ss 

UJ  UJ  K  b- 
O  '  O  _j  _ i 


XX  I  I 

►r  tr  k  P 

O  Cl  o 


00 

N 


S83S  SSSS 

m  ^  Trt  ^  ro  m  n  r 

g  g  g  g  g  g  g  ! 


CM 

O 

* 

<0 


O  S  S  5  8  S  feg  £  2  M  ♦  10  X>  *■  ®  -IO  -  (V  ro  •«-  IT.  KD  rv  m 

jssiigsiiisEiiiiiiii  ilillllf 


mmrnnimMmjmwmmmiiimii §§  il §§ i 


CM  b) 

?  ° 

N  N 

to  - 


58 

*S? 


00 

o 

00 

a ; 


u 

£ 

u. 


E 

QJ 

ifi 

C/3 

< 

C/3 

C/3 

© 

U 

u 


c 

a> 


W 

0>  -=J 

<->  'J 
£  - 
3  x 
P 

*3 

UJ  IX  >  h-  C. 
L^J  UJ  ^  LlJ  Ly 


u.  u  i  u.  u.  2 


SSSS^g 


-J  x  a  2 
“*  uj  3  m 
u  h  5  j 


UJ  Cl  _l  K  £>  ; 

>  X 
00  Q_ 

OOOOOOOT-OOO 
K»  y  m  r>-  oo  cr-  o  ^  <N  m 
n  w  k* 


00 

c 
•  ■■ 

■4— 

C/3 

IM 

u 


'  qj 

S  £ 

to 

<  >» 

X 

a>  QJ 

£  -£ 
H  eg 


~  QJ 

£  :2 
a> 

M  « 
C/5  C/5 

<  « 

3  -a 

o  o 

U  E 

VO  £ 
00  Jp 

o  H 


00 


00 


5  c  s 


s 

N  o 

^  •£  a 
oo  £* 

™  T3  M 
<,  <D  <U 

xi’S 

£.5  -9 

o  g  if 
*-• 

X) 

E 


c 

a)  «S 


QJ  - 

oo  2 
<W  C 


OS  ^  QJ 

«».g 
.5  6- 


>* 

QJ 

-C 


.  « 
£9 

2  c 

.-2  73 

-1  o 

g-s  a 

ig  8  '8 

e  C  « 

«  -O  4) 

J3  2  J5  • 

k.  g  -M  VO 

o/*  >,00 

g  °  -°  s 

°?  O  3  < 

s  &■§£ 
2  tS  £  0 
<  .b  „  >» 
Xt  |S 

43  E 

■*-»  QJ 
9  V5 
r/)  CO 

»5 
os  H  *■> 

°  =  >.  o 

o<S  sr 


s  6!tt!  I  6 
-,  w  a.  -S  4< 


S2  O  ~ 
;2  t  C 
^  «  « 
U  2- 
43  \o  ST 
H  00  w 


■3-5 
c  -S 

03  X3 

E  » 
x 

CO  -w 

p:^ 


* 

# 

* 

* 

* 

* 

* 

# 

* 

* 


i  - 


i  00 

t  l 

*  r. 

* 

* 

# 

* 

*  » 


©  o 
o  ^ 

©  o 
©  © 


OC' 


GO 

UJ 


•H  L  i  E  >  lu 

t  _  UJ  _J  in  UJ 

|  8 1 E  S  5 

— ,  U  t  UJ  o-'  ID 

p  u:  to  uj 

UJ  Ul  CO  5-  cn 


Q:  ' 

Ct  O  ' 


3  fc  S  6  w 

3  I  UJ  UJ 

oc2£“  W 

UJ  H-  P 


o 

:o  ji 
a  Qj  u  3 
o  ix  Ul  a.  i 

bs*;**i 

_  I  K  O  | 

z  w  o)  f 

*  b  UJ 


X  P 

tz  £ 
di 
wss 


E? 

“b 

c. 

>  2 
UJ 

gi 


d  ~ 

O  CO 


UJ 

Q. 

X 

UJ 

to 

* 


(J 

§ 

£ 


s- 

d  + 


9 

s 


p+l 

j  jZUJ 
-  Oj  P  |( 


UJ  UJ  UJ  ^ 
M  H  ||  II 


eaes 


CO 

s 

Cl 

QC 


CO 

£ 


CO 

& 

e 

to 


to 

<0 


**#####*  ****«-»**#***•* 


©  ©  ©  ©  © 

S8SS8 

©  ©  ©  ©  © 


©  ©  ©  ©  O  ©  ©  o  o 
©  o  o 

©o©  o  ©  o  ©  ©  o 


©  © 
'O  N 


©  ©  ©  ©  ©  © 

00^  O  H  CJM 

■*+"*+  CM  CM  CM  CM 

©  O  ©  ©  ©  © 


******* 

©o©oo©o© 

?ip^fs-ooa\©.H 

SSSSSSSS 


26 

246 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


_J  ll 
•-  LiJ  Lt  L_  t 
U.  _j  _< 

•—  lu  iu  • 
LU  U.  K  p  l 

St  uj  O  : 

aS  1  ,  : 

I  (0  > 

P‘,  I  c  I 


LU  LU  Cl  I 

d  d  g  £  ; 
u-u-££l 

LU  LU  3  0-  I 
-j  -J  C  b 

ddJc'i 


LU 

— J  it 
LU  0? 

j  li  m  \ 
*-  LU  LU 


9  C  E  E 

<_■  o 

11.3 


\  \  LU  in 

LU  LU  v  _j  _j 

j  JLUhh 

i  mh  Jku. 
I  li-  Lt-  • 
i  Ul  »“  LU 

■  S  IS  *  ti  &E 

ill  Cl  Cl  5  5 

;£8i£S 

o  <6 

I  ,  1  ' 

i  s  s  I  -  ^ 

1  ►-<»—«  o  c  c 

•  Ci  Ci 

,  .  1  '  • 

Ci.  £  CL 

:  Cl  £  O  O  O 

:  1 1 1 £  £ 
I  LU  LU 


ft  fcS  p 

*-•  t-l 

c.  c.  > 

x  lu 

I  I  X  f— 


iggg! 

5  d  d  d ! 


f £ £f ££ ££££ 


I  I  I  X  I 
HKh-KK 
C  Cl  Ci  c  Cl 


XXXxxXXXXXXXXXXXXxXXXxXxxxXxXXXXXxX 

►“  tr  ^  kH'Pl— h-P>— hS— h  P  k  h  ►—  P  h 

UuCiUCicCluUuClUClUQUUuOUClUUUUCUuO^UGuUU 


K»jir*^r>-00aNo^c*ih)^- 

o  o  o  ®  O  O  ©  «-*  —  «-« 

CO0&Co0&l»a.®W®C0®00 


2  on-a-in^r^ascc  —  cMf0'»(pM.',r^0DCr=  —  h  m  »  in  N  oo  o 

(T  <T  'T'  <?•  <?'  Q-,  &■■<?•  <?■  (J->  O'.  <j\  &■.  &>  (J-.  (J-.  (?.  *?>  iT<  O'  &>  9s  &'&'(?•  &■  (T-  <?•  CT-  <J-  <?>  <?  (J-.  (J.  (T-  (T--  (T--  0s-  <T-  <T> 

rjE^rli:Ei:EErrit8EESl22ElEti!crrlci:itirirrt| 


OOoOoOOOOOOO  OOOOOOOOOOOOOOOOOOOOOOOOOOOOOOC-C-COCOOOOOO 
cr  o  —  inki  t  in  <<in  go  os  o  ^<Nh'‘)^iO‘sC'KOCi|T'0^-4iNr'^^ir'vur^op(7so^(NK'^-ir’sufv-oj(T'o^r-^^'.,Triri'ur-o:''T'0^- 
k>  *■*•*■*•**■  m  mmmiT'ioinioLnin  vu  so  vu  vu  sg  'J^^'XtNNNNNNNNNNo&ooaicc'a-ooo&floaia)  <r> 


X  2  S  rU  2S 

11  *Sk 


2?l.i 


£  § 

cc 

i 

PSU 

H 

ql  <r 

X 

a,  cu 

2  ►— 

oT  n 

2 

f- 

o  © 

•-H  (f, 

CJ  o 

Crt 

CL  0. 

o  ©  ©  ©  o  © 

SSSgSP; 

oooooo 


oooooooo  OOOOOO  OOOOOOOOOOOOOOOOO 
ooa'&«-iCi'iro^rifl  vo  r-_  oo  cr'  o  <n  k>  ♦  it  ^  n  ooT-o^c^n^invoNoo 

58  ss  ssss  *s  ss  es  s eesesesssssssggs 


O  OOOOOO 
ITS  O  _«  (S4  W  ^  JO 

■u  n-  r  .  r-  n 
©  o  ©  ©.  ©  o  © 


o  o  o  o 

f sfc??£ 
0-000 


O  —  fN 

o  o  o 

O  T->  *-« 

co  u}  CO 


OOOOOO 

o  ^  CS|  ro  5T  IQ 

88  88  88 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


27 

247 


(Continued  on  top  of  page  26)  I  (Continued  on  next  page) 


28 

248 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


D  ip  ip  ffi  ip  ffi 

O  —  CM  M  ♦ 


333333333383 

UJUJUJUJUJUJUJUJUJUJUJUJ 


;s£5iei&8 

SaSSSSSSa 


33333333 

UJQjUJUJUlUilAJlij 


£££ 

080 


H  UJ  y  |  UJUJUUUJ  UJ  I  ^  UJ 

SSSS8S88S£  =  CJ2i 

ssassasssaaasa 


:£tiS 

-  lx  Q:  Cl  CL 


UJ  UJ  UJ 
®  CO  ® 

sil 


UL  U.U.U.LLU.ILL1U.U. 

UJ  UIUJUJUJUJUJUJUJUJ 

1  1  1T1  1  1  T  1  x  - 

5  S8S8S8S82-2 

5c  ^'’ScX^CX^'^'x^'Sc^ 


!3  33333333333333  i  33333333333 

I  UJ  UJUJUJUJUJUJUJUJUJUJ  UJUJUJUJ  UJ  UJUJUiUJUJUJUJUlUJllJUJ 


;£-£t22!2^££?3F3  SSSSS888 


8O-M(NK)tm^NC0-K) 

inminioinininininioinin 

UJUJUJUJUJUJUJUJUJUJUJUJ 


VJj»Xiv£>vDv^sDv£,sD 

III  111  111  UJ  LiJ  III  III  III 


CM  tO 
OOO 


S88S888§£2=£££  S 

ooooooooooooooooo&ooooooooo;'  cr. 

UJ  UJ  UJ  UJ  UJ  UJ  UJ  UJ  UJ  UJ  iii  ill  LiJ  in  UJ 


ooS8S«8^°rt<N 

O-  O'  O-  O'-  O'-  O'  O'-  O-  O-  O'  O- 

UJ  UJ  UJ  UJ  UJ  UJ  UJ  UJ  UJ  UJ  UJ 

OOOOOO  00000 

S  8  g  fc  8  £  §  S  2  8  S 

MWMIOMn 


8  3  S  8  8  8  8  SS8  SS8S8£888££8h-£  S88S8888£2  =  ££££££££ 

vC  ^  ^  m?  c-  r*-  00  00  oj  oo  o?  oo  ot  ex*  co  co  co  co  o?  <z  <r,  ov  <7*.  ^  -?•  on  on  0s  on  O'  on  <J-  o  -on  on  o'  on  O'  O'  O'  a--  0s  on  O'  cr-  cr- 


2322222  232  22212223222323  22323222222222223222222222 


NM  J^T  N.  O'  £  £2  ^  £  £  ?  £  ^OOao-CMK.^  -  CJ  M  t  (D  ^  N  05  ^  O  -  N  Kl  t  ID  ^  N  OJ  ^  o  -  ^  Ki  ^  ID  vi' 

OOOOOO  C-  0  0-0  OO'OOOO  O  O  O'  M-I  M-.  -*  OOOOOOOO'  O  w  h  (N  O'i  Ol  CJ  CM  cm 

vc  -x.  vl1  ^  u?  v$  u)  r_  r--  r-  co  co  co  go  oc*  oo  co  oo  go  oo  co  go  co  co  cr  a-  <r  <r-  o-  o-  o-  o-  o'  o-  o-  o>  o-o-  o-  o-  o-  o-  o-  o-  o ■  o-  o  o-  o  o. 

X  x  X  x  x  x  x  XXX  XXX  XXX  xxxxxxxx  xxxxxxxx  xxxxxx  xxxxxx  xxxxxx 

o  O  O  O  O  O  O  o  O  O  O  o  <“ 1 ■  O  o.  ea  o  *=.  r>oc.r.  /-.mni-!  t-\  /—.  r-.  r->  r-.  /—.  i—-  .— .  ,—.  ,— . 

IT'  s£  r-  00  O'  o  ^  (SI  K.'  IP  v£* 

v  *-  -<r  in  ip  ip  iri  m  IP  ft 

<N  CM  CM  CM  CM  C4  CM  (M  CM  IN  CM  CM 


OOO  OOOOOO  0-000  O'  o  o  O  O  O  o  o  O'  OOO  O  OOOOOO-  OOO  O  O  O'  OOOOOO®  o  ©  © 
O  ^  <M  K.'  *  IT*  v£»  IM  00  <T>  o  ^  (M  K-  ♦  y:<  •Xi  N  CO  (T'  C  ^  (N  ^  jfMD  N  CO  cr  ®  —  CM  K>  tT  IP  vCi  r-  00  cr-  <=•  ~  Cm  M>  |P  •■£>  l- 

m  ip  in  iri  in  in  it-  ip  ir-  ip  M>  u?  v£i  si:-  ^  -Z.  m>  so  vo  r-  r*-  r^  K  r-  n-  n-  co  oo  co  oo  oo  oo  oJ.  go  oo  a-  o  o-  o-  g%  cr  J-.  a-- 

N  CM  Cm  N  CM  CM  CM  (M  fM  CM  N  ^  CM  P i  iN  CM  CM  CM  CM  (M  CM  CM  CM  CM  CM  <M  <M  CM  CM  <M  CM  CM  CM  CM  (M  CM  CM  N  CM  PJ  <M  CM  CM  PI  Cm  PJ  •'  i  <N 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


29 

249 


(Continued  on  top  of  page  28)  I  (Continued  on  next  page) 


I 

i 

o 

£ 

►- 

S' 


I 

£ 


& 
i— ■ 

£ 


a: 

2 


UJ 

i 


X 

2 


X 

P 

h- 

£ 


CD 

Cj 

UJ 


p 

1° 

°£ 

|  ^ 

UJ  OX 

I-  ►—  UJ 


g  =  g 


£5 


fc  U 

_J 

SPj 

kSS 

LU  05 

ps 

H  W  S 
* 

(J  X  o 

So  II 
to  o 


S  Kt 

M  n  Z  LJ 

ot  •-.  x  o 
o  o 
£  1  °  o 

££fc- 

5Sx£ 

Cu  f;  h 

<o  J  5  £ 


2  _i  i 


I  UJ 

is 


Ct 

O 


£ 

X 

2 

E 

UJ 


UJ 

it 

o 


x 

o 


> 

Cu 


CM 

X 

p 


£ 

X 


£ 

8 

1 

£ 

s 

2 

u 


CL 

o 


* 

* 

I 

* 

* 

1 

* 

4 

I 

* 

i 

* 

I 

4 

* 


•O 

a> 

3 

C 


X  -J 

©  UJ 


at  i 

H  Its 

xeS 


£  ii  £&g 


CM 

© 

s 

Kj 

x 

h- 

_J 

3 

2  5 

O  5 
t  R 

ag 

UJ 

X  X 

X 

(DO  3  QC 

£m 

O  *“> 

S  t  pg 
-J  0  »-> 

X 

2 

*S«sg 

(J  x  . 


X  X  o 


X  X  o 


K) 

X  X  o 


X  X  O 


iSiii*  m-g  iigg  *l|g  glgg 


o 

U 


00 

N 

u< 

© 

O 

00 

o 

00 

© 


u 

u 

© 


s 

© 

C/5 

C/5 

C/5 

C/5 

2 

u 

< 


(M 

£ 

a 


>  ©  ©  © 

I  0s-  o 

:8  S« 


to 

£ 

a 

K 

B 

O  © 
CM  K> 


©  ©  © 


?2-206oo°  ©  ©  ©  ©  © 
r-_  oc.  rr»  «  —  ,Vj  fO  in  %Ci  rv  00  (js  o 
fs-P'-^rL© 
®  o  ©  ©  ©  o  ©  2 


33$ 


© 

© 

- 

© 

K 

K 

»- 

•< 

g 

0) 

E 

5? 

* 

©  ©  ©  © 
-•  <M  K>  * 

8S8S 


to 

£ 


w 

— 1 
CO 

s 


©  o  o  o  ©  ©  ©  ©  ©  ©  . 


iilillllliiiliilillllllt: 


CD 


UJ  UJ  ip  UJ  UJ 
w  i  If)  i  r!- 


ISIMi 


-Q-Eslliss,. 

UJUJUJUJUJUJUIUJUJUJUJi 

mmVfmmmmmmmmirn 


ill?!  I 

K2S5!B!S«®« 


§gg§gg§8gg|SS8SSS833|38SiSgSS8§3g8S3g3 


llllllll§!lllllll|g|§|||lll§|||||||||||| 


OX) 

B 

**— 

C/3 

13 


4 

* 

* 

4 

4 

4 

4 

* 

4 

4 

i 

* 


4 

* 

* 

| 

* 

* 

* 

* 

4 

* 

4 

4 

4 


2 

UJ 

a 


H 

CL 

►— 

<S) 

I 

ff> 

x 

a 


I 


05  X 


i  -s* 


4 

5 

4 

4 

4 

4 

4 

4 

J 

*  • 


1 1 

to 

aa 

Is 

2  2 

UJ  uj 

g? 

S  X 
*  4  # 


©  ©  ©  o  © 

O  H  iNM  ♦ 

JK  ©  ©  ©  O  © 

«©©©©© 


30 

250 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


ih  Ct 

z  2 

lu  Ct 

Is®  . 

O  CJ  07 

teu&s 

*-•  cl 
~  >  O 

ui  >-  ^ 


o"fca 

^KgiS 

si:* 


£SiE  I  Is 

h  Ll  ^  CG  »“>  "w 

*******  ***** 

ooooooo  oooooo 
^  (N  K)  ^  ir»  v£»  r-  ooa^o^fsiK) 

~  -h  -m  —  —  —  <N  (M  C4  (SI 


s  s!  1 5  uj 

5  »->  z 

z  *-• 

07  •—  -■  -K 

UJ  3  S  S  d 

Ct  O  LL  ft  Ct 

C1200 

I  LU  w  K 

UJ  UJ 

CL  Ct  Ct  Cl 


<r  o  E 

^  liJ  Ci  Q  O  UJ 


j  w 

xtii 


illilllli 


OOOOOOOOOOOOOO 

SK<NC4c3KSp7piR  !oR  $  K> 


>  Cl  _j 
UJ  Gj 
1!  h  UJ  I 

•  S£- 

•  O:  I  Z  1 

UJ  I  —  - 

J  u.  CJ  = 

:  u.  1  ct 

-  “  >  -  UJ 

GQ  Qj  ro  K 

•  J  £  <r 

:z.rS=  S' 

»  I  M  (A  c 
I  I  Ct  •-  J 
Jpih  _J 

-  O  07  07  O 

:  CL  Ct  u. 

'IS  £  »  e  07 
J  I  □  O  O  h 

!§84 1  $ 


*8  *  ui D  * 

IOlJ« 

V  it  UJ  S 
5'  I  ll  I  H 
UJilLh  h 

*  -  p  S  3  5 

>  07  O  »-• 

i  07  <T  O  ttJ 

j075~g° 

UJ  07  Vg 

\*mu 

'  K  K  y  u  i  UJ 

! "  “  "  S  rf 


* 

*  uj  s  =  — I  Z  o 

*  L  —Co. 
******** 


>00000 
'  (NK7  *  in 
•*■•*■*■  TT  *> 


ct 

Ct  1 

UJ 

UJ  I 

07 

h- 

K  1 

07 

cr 

<r  1 

UJ 

Uj 

UJ  1 

_1 

Cl 

Cl  1 

C- 

ID  1 

t  1*1  a  a 

Ct  V  II  a 

1  4  4  4 

********** 

00  oooooo  00 
<X>  N  CD  ^  o  *H  (N  K«  IP 
IT<  IO  IT»  IO  lT»  U7 


l  £¥ 

8  Cu, 

i  8> 


ZUih  XX 

-  f  S  £  £ 

M  M  r  (/)  VV 

—I  -•  ~ 

07  —I  z  Z 

K  Ct  ■•-  Z  tz 
X  UJ  *-H 

UJ  h-  UJ  ct  ct 
K  o  “  Ct  UJ  UJ 
CC  UJ  »-  V- 

ntm 

K  0  5  i  i  f 
^hjx 

di  <r«  1  cc 


UJ  /-s 

K-4 

KU 

U.  UJ  Cl  UJ 

□  it  <E  07 

C  Ct 

Cl  UJ  07  UJ 

l*es« 

z  <-•  £  z 

H  —  T  £  •-* 

2  W  |  U  I 
M  CC  “ 

=  iai* 


u  oz  +  o 
xoc'Tjli- 

5  8  0 . 8 

CL  £  «  «> 

a 


Ct  ►-  07  07 

O  Z  O  UJ  UJ 

U.  W  Cl)  h  h  t 

8  8  fc  <*  5  5 

h  I  W  mm 

»-  t  2:  F 

e  g  w  <r  u  £ 

n  z  z  p  uj 

'"'  v  1-1  S  n  '-1 

o  0  o 

r-,  O  "Kl- 


5£i££i 

o  o  o  o  o  < 


u 

UJ 

2 

Q 

5 

ct 

0 

3 

3 

c 

u 

\— 

K 

K 

r-i 

« 

r— 1 

5 

5 

s 

2  0 

0  0 

(SI 

K 

^  0 

E  K 

UJ 

t 

8  ^ 

1— 1  00 

Q  _J 

LU  S 

&  i 

its 

x«:S 

«  «;  U 

N 

;  I  N 
£  0 

IIS 

jOf, 

£x 

s 

1 

Cl 

£ 

5 

Is 

h 

IS 

s 

8 

h- 

h- 

1 

K 

00  000- 

S  o  2  ^  Cj 1 

00  o  o  o  1 


*********** 

>00000000000 
i-ir*  Mjf'-a70'io~-.(Nro’*-ir> 

-  MM(\|f\|f\|(NiNCM 

>00000000000 


00  ooooooo 
Mll^OOtf.  0^(S|K7^ 

cjmnNmmmkik) 
00  oooooo  o 


w  •_> 

OOOOOOOOOOOOOOOOOOO 

888SSSSSSSSSS  1516888 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


31 

251 


0540  I  NX  H  ;  POINT  TO  NEXT  CHfiRRCTER  1560  * 

055  0  DOR  C  ;  DECREMENT  CHfiPfICTEF  COUNT  1570  *  COMPSTRINGS  EXPECTS:  B  =  BUFFER  STRING  COUNT  <  DE) 

0560  TNZ  GET0KEN1  ; CONTINUE  SERPCH  FOP  TOKEN  1580  *  C  =  IN-MEMORY  STRING  COUNT  <HL> 

057  0  MU  I  R.04H  ;C=0  BEFORE  TOKEN  FOUND  1590  *  DE  =  BUFFER  STRING  POINTER 


'O 

<u 

3 

C 

•■a 

c 

o 

O 


a 

P 

t 

to 

W 

H 

a! 

C/7 

p 

a 


* 

* 
ft 
* 

| 

* 

* 
f 
I 

# 

* 

*  *  *  * 

®  ©  ©  o  o 


CO 


0 c 
UJ 
K 
2 

O 

CL 

5 
*— « 
K 

5 
*— > 
»- 

C/7 

5? 


CL 

K 

Cl 

h— 

07 

g- 


— J  Qr; 


CO 


— .  w  w  w  w  0©0©0®©© 

^  u?  -x.  ®  ♦tf? 

CN  M  $  CM  <$  N<^CN<NC^CNr^fN 


# 

* 

* 

{ 

* 

* 

* 

* 

* 

* 

* 

i 

* 

* 

* 

* 

* 

* 

* 

# 

* 

* 

* 

* 

§ 

* 

{ 

* 

* 

: 

# 

* 

* 


o c 
P 

CL 

CO 

a 

N 

2 

CO 


X 

UJ 

8 

§ 

h- 

£ 

»- 

07 

a 

K 

8 


£ 

0- 

K 

CO 

X: 


2s5  55 

_J  *— #  ►*  t— « 


£2 


a 


CO 

CL  CC 

u  <fc 

|e 


3.“" 


i 

UJ 

£> 


O  C  C 
-J  -J  -J 
UJ  UJ  UJ 

Ll  Ul  IT 
UJ  U  UJ 

££% 

ESS 

CO  co  co 


@  g  353 

w  o;  oujujuj 

2  to  8  to  to  to 

CL  CL  UJ  UJ  UJ 
uj  co  UJ  07  ©  S  £ 
Jr  Cl  L-  (l 

fir" 


8i 

Is  I'm 

-  z  n  n  ii  ii 
00  (J  S  i 


CO 

* 

UJ  05 

UJ 

5 

1 

* 

* 

-  * 

ft  * 

ES 

!*J  “ 

K 

s 

*-« 

0) 

i  f 

Se 

2 

GO  OOOOOOOC 

vo  n  oo  <r>  ©  •*+ 
n  K  go  50 

CM  CM  CM  CM 


I 

•w 

O 


<r 

©  z  © 
§8* 


ilaSsliiSIfi 


o  O 
o 

RR 


©  ©  O  ©  O  O  oo 

mgms 


OOOO  OOOOO 

ssss se s&8 

m  m  mm  m  r?  to  to  to 


Ct 

-J 

UJ 


OOOO 
g  Oh  m 

w  ro  to  ^ 


K 

Uj 

CL 


********* 

OOOOOO  ooo 
©  <N  K7  ^  IO  <ANC0 
<X»  vX  *-0  'O  vX  vX  vjQ  ^ 


$ 

K 

5 

UJ 


& 

CO 

o 


to 

CL 

p 


S 

z 

M 

£ 

a 


f 

i 

5 


S 

04 

£ 

S£ 

UJ 


K 

07 


CL 

UJ 

►— 

i 

CL 


K  K  u 

hi-  ^ 

s  a 

s 

a 

a 

ill;: 

Qj  O  U  X  T 

2  2  o 

is  IS 

ii 

j 

ii 

2 

n 

± 

07 

s 


o  : 

x 


CL 

H 

CO 


8? 

UJ 


Q 

a 

UJ 


<r 

u 

6 


i 

a 

UJ 


* 

* 

* 

§ 

* 

* 

* 

* 

i 

I 

* 

* 

* 

* 

i 

* 

* 

* 

* 

* 

1 

# 

# 

* 

* 

§ 

* 


OOOO  OOOO©  OOOOOO  OOOOOO 

^nnnnnICJvn  SSSSSSJSoBfeSS' 


UJ 

Q 


UJ  P 
(JL  <H  O'.' 

S  UJ  07 

585 

Z 

a 

0 

O  07 

£  1 

-J  u  o 

<r 

s 

o  UJ 

(M 

CL 

<r 

* 

* 

* 

* 

| 

CL 

K 

CL 

K 

07 

X 

* 

'w 

N  (J  £ 

*~>  ►“> 

X 

z 

*8 

*  %% 

g 

8  N 

2 

2» 

* 

* 

* 

* 

UJ 

07 


07 

2 


07  3l 


OOOOOoOOO 

o  ^  (n  r  t  in  vx  k  go 

(JS  (?.  <7S  <r>  <Tk  Vs  CT* 


^  I 


CO  •-  z 


ir>  im 
CM  to  I  I 

■*■  NX 


*  *  *  *  * 

OOOOOOOC 

O  -  C4  «  t  IT'  ^  N 

OO  OOOOOO 
CM  CM  <N  CM  04  CM  CM  CM 


***** 


OOOOO 
CM  CM  C4  CM  CM 


32 

252 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


3130  I  NX 


X 

W 


2  h- 
O  Q 
uj  2 


W 

ui 


C  N 
c  *-> 


Cx 

g 

LU 

lT 

w 


8*  5 


o  o  o  o  o  o  o 
■<r  in  vu  o-  oo  <x.  o 

n  n  K)K)K)K)S 


_l 

LU 


1 

— 

5  6 

X 

X 

k- 

5 

CO  X 
o 

X 

G 

X 

o 

■r 

c 

k- 

k- 

II  £ 

Ur 

fi ( 

0 

k—  c- 

G 

O 

co 

Z  CO 

to 

CO 

L*i 

II 

G 

U> 

K 

/V 

A 

11 

X 

Cl 

cZi 

D 

UJ 

G 

G 

k- 

k— 

&  = 

X 

X 

7 

CO 

CO  2 

»— < 

G 

UJ 

X 

X 

k— 

Ci 

X  k- 

h 

k— 

CD 

hS 

□  G 

<0 

CO 

X 

G 

X 
*— « 

a 

s 

O') 

LU 

Cj 


C> 

G 

LU 

£ 

£ 


I 


Ct 

c 


£u 

LU 


k-  O 
Cl  Cl  CO 

X  CD  Cl 
O  LU  X 
O'-  iZ,  G 

* 

M  3 


Cl 

O 


e* 

CO 


II 

SSiS 


+  04  Cl 
k — 

Cl  -f  CL 
k—  K 
Cl  X  CD 
LU  I-  LU 

y  u.  lj 

5Sfc 

Sgt 

■  ••  a 
a^e 


s 

% 


£ 


o 

x 


******** 


o  o  o  o  o  o  ©  goo 

-  (N  K)  ip  v£)  N  CO  O  '  © 

04  CM  CM  04  04  CM  04  04  CM  K> 

K)K)MMWK)K)  WWW 


5  <r 
£  o  £  o  x 


j«  JXXK 

I  6  6  2  z  ■ 


i  g 


o  o  o  o  •=•  o  <=•  o  O  o  o  © 

-«  04  K*  ^  IP  Vi  N  CO  a-'  O  -  CM 

ro  ro  k<  r  o  n  k.  k-  m  k*  *■  t 

M  ►**!  K.  M  K.  M  »?.  »/■» 


o  ©  o  o  o  o  o 
K»  no  vj:*  N  oo  a- 

+  rt  *  Tf  rt  +■ 


CD  _J  LU 

X  X 

iZ.  G  k- 
LU 

uTSe  - 

— •  —  LU 
<_•  K  X  G 

^  c  ~  x 

55  it  h  5 

CD  I'  S 
LU  3  C1  LU 

2  CO  Cl  CO 

^  W  {3  ^ 
O  g 

LL  1“ 

£<r 

CO' 

CO 

<r  x 

oS 

a  LU 
“  u_ 


LU  -I 
Cl  -I 
Z  X 


£  x 


u:<  g 

is 


* 

* 

* 

* 

* 

* 

* 

* 

* 

$ 

* 

* 

* 

*  * 


G  it 

5:  a! 

u 


2D 


u  '-• 

*  * 


o:- 

co 

LU 

CL 

1 


G 

Cl 

LU 

CO 


* 

X 

G  1 

G 

-j 

* 

c- 

X  X 

G 

* 

X 

t— i 

G 

X 

* 

ZE 

X 

X 

G  1 

h— 

X 

k- 

* 

* 

2 1 

> 

X 

£ 

* 

G 

G 

* 

X 

* 

k- 

^  1 

h— 

1- 

* 

G 

CO  ■ 

X 

X 

* 

* 

a 

5 ! 

u 

X 

o 

X 

£ 

* 

k-  < 

r 

UJ 

* 

C 

i 

u 

X 

X 

* 

X 

55 

E 

-- 

k- 

_J  CO 

X  x 
G  ~ 


! 


c 

o 

"3 

<u 

3 

•S 

c 

o 


*-  •  Z  •—  O') 


LU 

£ 


2 

£ 


*— •  k—  •  ix  *-• 


*  *  *  *  *  *  * 

0  G  0  C  0  O  0  O  O  G  0 

—  04  K>  M-  IT'  V0  r  -  00  CT.  ©  — 

id  in  in  m  in  in  in  in  in  n'.  u"’ 


C 

£ 


t  t  i 


© 

CJ 


c- 

Cu 

o  x 


o 

o 


:  z 

c' 


C  Q 

lol 


|  di 
£  £ c-  £ 
I-  >  C 

CO  LU  CO  I —  LU 

S^XI-S 


X 

k- 

X 

k— 

o'-  a- 

a  ^  c  ci  g 


i  S  X  £  ft  t 

_j  X  _J  0  u.  5. 


£ 

CO 


c- 

X 


5 
►— < 
I- 

0'* 

d 


o 

Cu 

X 

> 


X 

X 


h 


o 

X 


X 

k- 

X 


o:>  e  <=•  a- 

a^LUGOLUOG 


illiliiki 


LU 

£ 


LU  CL  111 

X  k—  X 

x 

k-  k~  X' 

o:- 

i-  UJ 

Z  ^  $o 

C  C,  2 

-  a?  5 

—i  r*  x 

G  LU 

lu  x  r 

5  °a 

0-4  k-  u 

2  X 

+  UJ  X 

£ 

K 

X  Z»  CO 

►-  c.  0) 

CD  LU  LU 

LU  X 

e  ^ 

II 

CO  j- 

£  - 1 

CO  I 


******* 


G 

* 

X 

* 

CO 

y 

* 

* 

04 

* 

k— 

Z 

X 

* 

X 

* 

* 

X 

CO 

* 

* 

G 

* 

CO 

CO 

— 1 

* 

5 

E 

> 

* 

* 

* 

f 

X 

* 

* 

* 

CO 

X 

X 

* 

* 

* 

0‘) 

* 

X 

^■ 

* 

X 

X 

* 

+ 

X 

* 

A 

* 

H- < 

o 

* 

X 

* 

CO 

X 

* 

04 

X 

* 

* 

♦ 

* 

*  * 

* 

CO 

* 

* 

* 

* 

CO 

*  * 

* 

* 

* 

* 

*  * 

* 

O  0 

0 

0 

o  o 

0  0 

o 

o 

O 

0 

O 

o 

o 

n 

0  O 

O  0 

O 

O 

O  0 

o  o 

G  O 

o 

0 

o 

o 

O  ® 

o 

0  — < 

04 

K» 

io 

\£)  r  - 

a- 

a- 

O 

04 

to 

3J-  in 

o- 

GO  O' 

0 

*4 

CM  K) 

3*  m 

sO  0- 

00  <T> 

o 

.—a 

04  K> 

Cm  cm 

CM 

04 

04  CM 

04  04 

0-4 

H 

K4 

K> 

K' 

K> 

Ki 

»o 

kO  K> 

K.  kO 

^■ 

3j- 

Tt  ^r 

♦  ♦ 

3J-  ^ 

rt 

in 

R 

in  in 

in 

CM  CM 

04 

CM 

04  CM 

04  04 

CM 

CM 

CM 

<N 

04 

04 

04 

04  04 

04  04 

CM 

CM 

CM  04 

CM  CM 

CM  04 

04 

04 

04 

C  M  CM 

04 

CN 


& 

Ci. 

o 

Ci. 

o 

V* 

c 

o 

"O 

<u 

3 

•S 

c 

<3 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


33 

253 


34 

254 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


Crt  K» 

a  ~ 

&  P  S 

O  OCi 

z  £  b  ^  S 


eekoij 
^  iS  5  2  ? 

*u  J2H 
Jill  CG  G 

x  o  5  uj  i*j 
w  ~  c'  8  c. 

ft;  o  Ul  £  •-■ 

Hl&f  0|S 


Cfc  oc 

a  a* 

SB  |S 

2  K  Z  Li. 
O  £  OK 

a*  as 

go  g  ~ 
K  5  t  I 

sS  g£ 


00  — 
U  N 

^  I  ^  n  (N 
X  x  x  X  X 

£ U!  $ 

Uj  M  H  H  II  M 
—I  O 

IT  O  O 

5  o  o  o 

O  O  O  O 

r  o  o  o  o  o 

aaa  aaa 


w  u  n  (_) 

as  a  a 

IJ  J.ai 


^  in 

a  a 

Cj  UJ 


'  X  -  x 

<r  [j  cc  uj 


n  CO  UJ  00  <r 


.Aim 


&iss8«  ami  il  il  ill  s! 


222222 


o  o  o  ® 
<n  ro  *■  ir> 


o  o  o  O  o  o 

N  00  0>  O  -  M 
-  -  -  NN  (N 

m  m  in  in  m  m 


o  o  o  o  c 
ro^-m^N 

N  (N  N  N  N 
IP  If)  If)  If)  IP 


OO  OOOOOOOO  OOOOOOO 

oc.  £  oo  0^  o  —  (N  k>  t 

SaKKKBKBBB  SKSKSSS 


8  .fx  t 

_'  *  D  ^  CO  Cl. 

2  o  z  *■  uj 

_  =  ^  K 

ui  ii  u)  cr  o  5 

»  X  -*>  X  jB 


x  *•- x  ?  s  |  a  3 

LSvjoii 

ojkoc^Su-St- 

—  & 

jozozwzJ 

* ^a^asas 

HHhH^lilhO 


X  UJ  o 

UJ  _J  i- 


K  X 

OK  Ct 

X  'J?  UJ 

ct  Z  CO 


O  LI'  X  K 

"sas 


|8kS  i§  ? 

OWJ2  K  3  K 

aas§  S5  § 


J  Agi£lHgL  £ 


9  I 


OB  00  O  I  I  I  I  (O  21  O  ' 


X  X 

a  a 

UJ  UJ 


cm  •-•  <ys 

—  x  -  x 

X  UJ  X  UJ  XX 


8  b  l&s&sfcsfcli  Iliiiilimi  2 1  ll  ii 


I  _l  UJ  - 
(f>  o  = 

M  W  UJ  o 

:g3®\ 

|saa 

!**i 


O  o  o  o 

CM  K)  If) 


©  ®  o  o 
^  N  flOff' 


©  ©  ©  ©  ©  © 
c  j  K)  u)  vo  r  - 

?????? 


*  OK 

*  a~ 

i  ££ 

*  H 

5  *  *  * 

O  O  ©  O 
O  »h  M  hO 
IP  IP  IT1  IP 

Tt-  ^ 


i  o  Z  -J 
x  Ct  5  X 

X  UJ  o 

sa?a 


■«■  IP  *0  N 
in  in  m  in 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


35 

255 


4580  ♦ 

4590  *  MRKEDEC  EXPECTS:  CSOUPCEPTP)  =  ASCII  STRING 

4600  *  S0UPCECNT  =  STRING  LENGTH  (BUT  HOT 

4610  *  STRING  TO  CONSIST  OF  0, 1,2, 3, 4,5,6, 7,8 

4620  *  OUT  NO  OTHER  CHARACTERS 


X 

D 

CC 

ce 

X 

CJ 

CLi 

CO 

D 

D 

D 

X 

< 

> 

o 

X 

ce 

x 

m 

D 

< 

X 

D 

< 

X 

►H 

E-  E- 

E- 

X 

E- 

O 

CO 

O 

< 

X 

z 

ce 

CJ 

cj 

CJ 

CJ 

cc 

e- 

X 

X 

X 

hH 

D 

X 

z 

cc 

CO 

ce 

X 

< 

X 

o 

Ufa 

Ufa 

II 

X 

X 

*H 

X 

Q 

u 

o 

e- 

z 

o 

ce 

ac 

X 

o 

X 

a 

CL 

Z 

CO 

o 

H 

M 

ce 

S3 

Cb 

X 

r> 

X 

X 

»H 

CJ 

X 

X 

X 

X 

> 

< 

CO 

H 

ce 

o 

o 

II 

X 

N 

X 

X 

II 

3 

X 

CJ 

X 

z 

in 

hH 

X 

< 

CO 

2 

X 

z 

x 

X 

X 

< 

X 

X 

X 

<  CJ 

»H 

cc 

D 

X 

CC 

»H 

X 

D 

2 

o 

X 

X 

1 

ce 

z 

E- 

o 

CO 

X 

CO 

ce 

ce 

x 

cc 

E- 

Z 

O 

►H 

•  • 

< 

2 

1 

E-  U5 

X 

E-fa 

CC 

cc 

CO 

a 

E- 

o 

o 

»H 

X 

X 

< 

X 

X 

E-i 

O 

E- 

* 

a: 

o 

CJ 

o 

CL 

o 

►H 

X 

X 

X 

X 

m 

II 

II 

X 

X 

CJ 

E- 

X 

ce 

X 

X 

CO 

CO 

E- 

E- 

< 

X 

o 

X 

o 

X 

m 

X 

E- 

►H 

CO 

CO 

X 

X 

X 

X 

o 

•• 

•  • 

X 

X 

X 

E-i 

X 

X 

X 

X 

a 

a 

a 

3 

X 

X 

X 

X 

X 

z 

z 

X 

X 

cc 

X 

CO 

X 

•* 

m 

Eh 

E- 

CO 

o 

o 

< 

* 

* 

* 

»H 

►H 

o 

rH 

X 

-r^fa 

X 

cj 

o 

X 

fa-^. 

N 

rH 

rH 

rH 

CO 

X 

X 

X 

X 

X 

+ 

+ 

+ 

x 

-1 

a 

a: 

3 

X 

X 

a 

cj 

in 

X 

m 

a 

m 

X 

X 

X 

X 

X  x 

X 

X 

S3 

E- 

X 

X 

X 

Q 

< 

uJ 

ce 

E- 

t- 

X 

E- 

X 

< 

X 

< 

X 

< 

X 

X 

X 

X 

CJ 

c; 

VC 

o 

> 

CO 

X 

X 

z 

X 

M 

a 

O 

r—i 

C  (N 

X 

O 

S3 

z 

S3 

x  </> 

X 

X 

X 

< 

< 

X 

=? 

CJ  CJ  CJ 

CJ 

</> 

X 

rH 

ce 

rH 

n 

S3 

3 

E-i 

'  ' 

CO 

** 

z 

s*tr 

z  •= 

z 

** 

** 

mr 

** 

■  ' 

1 

X 

X 

X 

< 

< 

m  m 

< 

< 

X 

a 

** 

< 

< 

X 

< 

ce 

in 

CL 

CO 

< 

CO 

X 

w  <  05 

X 

X 

< 

in 

< 

X 

X  <  < 

< 

X 

< 

X 

X 

< 

m 

< 

>H 

< 

>« 

>H 

X 

>• 

< 

< 

< 

< 

< 

< 

< 

<  < 

< 

E- 

in 

H 

Z 

z 

D 

H 

z 

z. 

D  E-* 

z 

z 

Q 

E- 

D 

E- 

a 

D 

(- 

D 

X  E-« 

X 

z 

E-  E- 

C-. 

E-I 

E- 

z 

E-> 

E-*  E-*  E-> 

E- 

E- 

a 

E- 

D 

E- 

D 

E- 

O  E-i 

E-* 

in 

*-) 

CC 

CJ 

X 

X 

ce 

cj 

X 

X  CC 

D 

X 

X 

CC 

X 

CC 

X 

X 

X 

->  D 

m 

D 

X 

in 

ce 

X 

X 

X 

W 

X 

ce 

C/5  C/5 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

a 

ce 

2 

X 

X 

a 

X 

o 

H 

E- 

H 

X 

X 

ce 

e- 

u 

O 

O 

O 

IH 

X 

X 

D 

x 

Z 

z 

Z 

u. 

X 

X 

X 

SI 

© 

© 

S3 

SI 

S3 

S3 

Si 

S3 

©  S3 

© 

S3 

© 

S3 

© 

SI 

S3 

s 

© 

S3 

S3 

S3 

S3 

is 

S3 

Si 

S3 

s 

S3 

S3 

s> 

s 

«S  is 

S3 

S3 

s> 

s 

s 

S3 

S3 

s 

s 

© 

© 

© 

f-H 

(N 

co 

in 

VC 

X 

03  © 

rH 

CM 

CO 

*T 

m 

vc 

CO 

03 

© 

rH 

CM 

CO 

m 

VC 

r- 

X 

03 

S 

rH 

CM 

X 

X 

vr 

X 

03 

CM 

CO 

TT 

X 

03 

03  03  03 

03 

ON 

03 

03 

03 

03  S 

s 

S3 

© 

SI 

© 

s> 

© 

S3 

s 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

CM 

CM 

CM 

CM  CM 

CM 

CM 

CM 

CM 

CM 

ro 

X 

X 

CO 

CO 

ro 

rH 

rH 

rH 

*H 

rH 

H 

*H 

rH 

rH 

rH  CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM  CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

rH 

rH  rH 

rH 

rH 

03 

05  05 

03 

03 

CO 

Q 

CM 

co 

rH 

CO 

CM 

VC 

CO 

© 

cj 

S3 

X 

X 

X 

X 

X 

X 

X 

X 

<  05  *— 1 

S 

<s 

X 

rH 

vc 

Q 

IS 

in 

CM 

© 

VC 

D 

S3 

S3 

a 

S3 

S3 

CJ 

S) 

© 

S 

X 

SI 

© 

X 

S3 

Ufa 

S3 

S3 

S3 

if) 

X 

cj  o  m 

X 

vc 

CO 

S3 

CJ 

S3 

in 

© 

in 

in 

rH 

© 

S3 

03 

§ 

03 

S3 

03 

S 

05  s> 

03 

03 

© 

03 

S3 

S3  03 

rH 

03 

X 

rH 

CO 

s 

rH 

S) 

in 

X 

X 

■^r 

S3 

UQt 

X 

03 

o 

03 

D 

03 

X 

03 

X 

X 

03 

CM 

VC 

CJ 

O 

< 

VC 

cj 

<  5C' 

cj 

5 

<  in 

< 

VC 

< 

<  a\ 

<  00  05  00 

D 

03 

VC 

X 

X 

X 

CJ 

X 

vc 

X  X 

X 

X 

< 

X 

< 

X 

< 

X 

<  00 

X 

X 

rH 

1 

KT 

in 

1 

r- 

1 

03 

1 

X 

1 

o 

1 

CO 

1  1 
Si  CM 

1 

CO 

i 

m 

1  1  1 
o.  < 

1 

CJ 

i  i 
a  cn 

rH 

1  1  1 
co  m  vc 

1 

X 

1 

03 

1 

X 

1 

a 

X 

SI 

1 

CM 

1 

1  1 
x  r- 

1  1 
X  X 

X 

S 

1 

CM 

KT 

r- 

03 

CJ 

X 

S3 

l 

CM 

1 

** 

LO 

ID 

in 

in 

m 

in 

in 

in 

VC  VC 

VC 

VC 

VC 

VC 

vc 

vc 

VC 

VC 

r-  r- 

r- 

r- 

X 

X 

X 

X 

X 

X  X 

X 

03 

03 

03 

03 

03 

03 

03 

< 

< 

< 

rH 

rH 

H 

rH 

*— i 

H 

rH 

rH 

rH 

rH  rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

*H 

•H 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH  rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

03 

03 

ON  ON 

o> 

03 

03 

03 

03  03  03  03 

03 

03 

03 

03 

03 

03 

03 

03 

03  03  03 

03  03 

03 

03 

03 

03 

03 

03 

03  03 

03  03 

03 

03 

03 

03 

03 

03 

Os 

OS 

o> 

03 

X 

X 

X 

X 

03  X 

X 

CM 

<5>  far  CD  Ufa 

CM 

C  ts 

© 

vc 

r- 

CM 

CM 

CO 

in 

in  in  x  X 

X 

rH  ro  03 

X 

CJ 

D  O 

rH 

O' 

rH 

<r>  <j>  v>  u>  v> 

CM 

rH 

rH  </>  </> 

X 

X 

</>  X 

X 

o 

• 

o  o  o  o  o  o 

cy  o  o  o  ce 

< 

o  o  o 

X 

X 

X 

X  X  x  x 

X 

X 

X  X  o 

tfa 

X 

X 

X 

• 

X 

• 

• 

•  •  r  • 

• 

• 

•  •  • 

• 

• 

• 

• 

CJ 

CO 

D 

j  j  > 

X 

X 

X 

X 

ce 

X  H 

Z 

CJ  X  H  X  CJ  X 

E-I 

Ufa 

ce 

z 

<  2 

E- 

CJ300X<CC2 

X 

Is 

ce 

X 

Z  C/5 

X 

«C  <  W  U5 

z 

CO 

co  ce 

© 

© 

© 

© 

© 

© 

© 

©  ©  ©  © 

© 

© 

s  s  s 

© 

© 

rH 

CM 

ro 

VC 

h  CO  03  s 

rH 

CM 

ro  rr  m  it 

© 

© 

© 

© 

© 

© 

© 

©  ©  © 

rH 

rH 

rH  rH  rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

rH  rH  rH  rH 

rH 

rH 

rH  rH  rH 

rH 

cn 


X 

z 

o 

X 

a 

CJ 

o 

© 

X 

s  ^ 

< 

©  rH 

fa-fa 

z 

5 

— -  — ' 

(N 

X 

X 

- — 

CL 

X 

a  o 

z 

o 

J 

>H  J 

> 

•• 

M 

E-*  X 

ce 

rH 

X 

X  X 

c 

»H  hH 

m 

o 

« 

t-H 

ce 

cc 

w  >< 

o 

X 

N  •• 

cc 

cc 

<r«.  r—». 

fa-fa 

C/5  iJ 

X 

Ufa  Z  C/5  Ufa  X 

U.  X  Ce  >  <  X  0. 

X  9-  X 

U5  X 

os  u  o  m  y 

m  o  o  c/5  xx  o 

o  r> 

>  3 

Ufa  a,  j  o  r 

g  H  J  a  8  CC  <Hh 

CM  CC 

rH  ^  X  ^ 

ce  < 

m  o  D  ce  o 

3ac/)o*u  —»z 

X 

—  X  ^ 

D  fa-fa 

CL  m  Qfa  CU  Qu 

aaxc<<>'CQ-u: 

<<05<I<X<< 

X  <  < 

z  z  z  z  z 

ZZU5E-iDE-<DZZ 

Q  E-  El 

QEhZOE- 

Z  O  Eh 

nbifam 

15  i-)  0)  JW  H  J  U  D 

J  115  K 

i-5  05  h  *-5  05 

H  J  Oi 

Ufa  Qfa  U  O  E-| 

X  Eh  Z 

a 

m  o  cj  ce  o 

2  Qfa  u 

o 

o  o  o  o  o 

O  O  Q, 

Eh 

E-iE-iE-E-E-E-EiO 

z 

<S>Sl®K>®IK®IS)<S<S>IS]<SIGllS<S5i<S>IS®!S><SISCSIS>KlK)KI<S 


c 

z 

1  1  1 

vr  cm 

1  1 

cj  vr 

* 

05 

CJ  o  a 

©  CJ 

Lag 

< 

©  ©  © 

© 

©  ©  © 

©  © 

I  I  I  I  I 
Q  N  51  C 

®  in  in  in  oo 

S  5  S  O  U 
IS  IS  ®  IS  U< 


I  I  I  I  I 
bUUQOI 
[fa  Cl  O  5  Q 
Q  S  ®  ®  ^ 

IS  s  s  s  s 


05C535O5®O5O5C5G5O5 


a\ 


oour-fcipUvDDininscD 

oot^QCjEicsminuss) 


<tHinND  <h 

in  s  s  s  is  is 


it  Ci-.  cc  nr 

in  mm  CJ  in 


uouuuuuusDaiiiiooHai 

^r«a,^T»s,Tr^r'T'S,njoo<oo<mcj 


SOllOOOiHOOQ 

C«t®vr<05CJ< 


rl  05  Q  H  00 

05  CJ  <  05  cj 


I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  1  1  1  I  1 

njin®mwJHfalpr-<Ocl-Hn)^vc'oo<UDtI4r'^uo^oomp 

iCJCJCJCJCJQOOQOQWWWWWMWMWUfaUfaCnQfaOHkfaUfa 

I888B8B88SB8SB88B88BS8BSS88B 


36 

256 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


X 

Eh 

P 

X 

>< 

CD 

X 

2 

£ 

u 

S) 

o 

X 

II 

O 

i-l 

o 

iC 

X 

u 

CC 

X 

D 

X 

o 

X 

x 

u 

O 

2 

03 

2 

D 

> 

Cl] 

CxJ 

S' 

o 

Eh 

X 

2 

M 

X 

X 

CJ 

<■ 

X 

Q 

l-l 

CC 

CJ 

o 

X 

X 

X 

PH 

< 

o 

uJ 

►H 

X 

2 

> 

SC 

CJ 

PH 

X 

X 

Eh 

D 

a 

>H 

X 

X 

X 

Eh 

X 

X 

X 

< 

IH 

X 

* 

* 

r-H 

r-H 

r—1 

s 

cc 

+ 

+ 

+ 

X 

X-) 

X 

X 

X 

a 

> 

p 

D 

Eh  U 

X 

x 

X 

> 

CO 

[L. 

X 

CL 

X 

E-*  SI 

X 

X 

X 

X 

2 

PH 

CJ  cj 

2 

CJ  CO 

X 

x 

X 

cc 

< 

CC 

X 

o 

CM 

X 

X 

SJ 

X 

< 

< 

X 

E- 

a 

cj  a; 

Eh 

w  < 

r) 

< 

r> 

si 

a 

si 

IS 

S 

(S 

SJ 

SI 

SI 

SI 

r—1 

Ex* 

SI 

< 

r—1 

CM 

CC 

r—1 

< 

CM 

X  X- 

X 

X 

X 

cc 

SJ 

X 

ph 

C  E- 

X 

x 

CD 

< 

CO 

< 

IS 

CC 

' 

s 

Si 

S 

SJ 

SI 

s> 

S) 

vc 

<s 

X 

4k 

' — ' 

4k 

£ 

4k 

X 

— ' 

=»  U3  * 

4k 

£ 

4k 

<  a 

<  < 

<  <  <  < 

>  3* 

>< 

c n 

CO  < 

>< 

< 

x 

CO 

c/3 

c n 

cn 

cn 

cn 

C/3 

C/3 

cc 

X 

<  Ou  o  < 

< 

X 

X 

< 

X 

w  < 

>« 

<  X  < 

cc 

x  < 

X 

a  p 

Q 

e-  a 

Eh 

Q 

2 

Eh 

Eh 

X  Q 

2 

Eh 

X 

X 

X 

* 

X 

X 

X 

X 

ae 

D 

D 

r 

X 

Q 

Eh 

E-  D 

Q 

S' 

2 

D 

a 

Eh 

2 

Eh 

in 

a 

>H 

x  n 

P  c/3 

X 

CD 

X 

x 

x 

ph  CD 

os 

• 

X 

PH 

c n 

• 

• 

• 

• 

• 

• 

• 

• 

• 

J 

J  CJ 

X 

u 

X 

CC 

u 

CJ 

X 

X 

X 

X 

M 

X 

n 

X 

Eh 

E- 

CO 

X 

Eh 

eJ 

X 

X 

Eh 

> 

X 

a 

Eh 

O 

> 

CJ 

CJ 

X 

X 

X 

X 

eJ 

cc 

o 

o 

D 

X 

a 

cc 

x 

CJ 

CJ 

X 

X 

cn 

n 

X 

X 

x 

a 

E - 

x 

X 

X 

2 

2 

cc 

CC 

CJ 

3 

X 

S 

IS 

s  IS 

sj 

s 

IS 

s 

si 

s 

IS 

SI 

Si 

Cl 

IS 

IS 

SI 

Si 

SI 

SI 

s> 

s> 

SI 

SJ 

IS 

SI 

SI 

SJ 

SJ 

SJ 

SJ 

<s 

SJ 

SJ 

SJ 

SJ 

SJ 

SJ 

SJ 

SJ 

SJ 

SJ 

SI 

SJ 

SI 

vr 

00  ON 

«s 

r-H 

CM 

ro 

•^r 

m 

vc 

r- 

00 

ON 

IS 

r-n 

CM 

CO 

m 

VC 

CO 

ON 

SI 

r—1 

CM 

CO 

m 

vc 

CO 

ON 

S) 

r—1 

CM 

m 

m  vr 

r- 

CO 

ON 

SJ 

ro 

ro 

ro  m 

KT 

in 

m 

m 

in 

in 

m 

in 

m 

m 

m 

VC 

VC 

VC 

VC 

vc 

vc 

vr 

vc 

vc 

vr 

r- 

r* 

r- 

r- 

h 

r- 

CO 

CM 

CM 

CM  CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CN 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CO 

r-H 

• — 1 

r-H 

r—1 

m 

X 

on 

ON 

ON 

ON 

ON 

ro 

*T 

is  r- 

CM 

00 

U 

Du 

in 

X 

X 

U 

SI 

r—1 

in 

CM 

X 

CJ 

CM 

u 

SJ 

X 

X 

X 

vc 

SJ 

in 

00 

m  o 

in  o 

Si 

in 

IS 

m 

u 

IS 

SJ 

in 

SI 

s> 

SJ 

s: 

SJ 

in 

SJ 

S) 

(S 

bL. 

Si 

SJ 

SJ 

SJ 

in 

s> 

in  D  in 

D  in 

in 

00 

IS 

Si 

Q 

00 

r-H 

<S 

<s 

IS 

IS 

s> 

q 

«s 

is 

r—1 

S) 

SI 

r—1 

ON 

SJ 

ON 

m 

SJ 

SJ 

r—1 

ON 

g 

ON 

SJ 

r—1 

CO 

r—1 

SJ 

IS 

CO 

00 

CM 

<  00  <  00  < 

00  < 

CJ  00 

VC 

IS 

CJ 

ON 

s 

SI 

S) 

Si 

SI 

SJ 

SJ 

VC 

IS 

CM  < 

X 

CJ  tu 

< 

CO 

vr  < 

X 

u 

< 

< 

ON  CJ  ON 

CM 

<  ON 

1 

vr 

1 

00 

1  1 
9  9 

l 

Si 

CM 

in 

I 

ON 

1 

CD 

1 

CJ 

1 

x 

x 

IS 

1 

CO 

1 

TT 

1 

VC 

1 

00 

ON 

1 

< 

1 

X 

1 

CJ 

p 

1 

w 

1 

Cl, 

CM 

1 

^3* 

1 

vr 

1 

CO 

1 

< 

l 

l 

X 

1 

X 

r—1 

1 

m 

1 

in 

1 

1 

ON 

1 

X 

Q 

X 

1 

S> 

1 

ro 

1 

in 

<  < 

<  < 

CD 

CO 

CD 

OQ 

CO 

CD 

CD 

CD 

X 

CJ 

o 

CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

u 

CJ 

CJ  Q  D 

D 

a 

D 

o 

D  D 

X 

X 

X 

X 

X 

X 

X 

X 

Cb 

X 

X 

f—t 

r-H 

r-H  t— 1 

H 

r— 1 

r-H 

r-H 

r-H 

r—1 

r-H 

r—1 

r-H 

r-H 

rH 

•—1 

r~1 

•—1 

r—1 

*— l 

*-H 

r-H 

r—1 

*-H 

r—1 

rH 

r—1 

r—1 

r—1 

rH 

r—1 

r—1 

r—1 

rH 

rH 

rH 

r—1 

r—1 

r—1 

r—1 

r-H 

r-H 

ON 

ON 

ON  ON 

ON 

ON  ON 

ON 

ON  ON  ON 

ON  ON  ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON  ON 

ON  ON  ON 

ON  ON  ON 

ON 

ON  ON  ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

in 

r-H 

vr 

- - - 

r-H 

r* 

CO 

s 

E- 

E- 

E- 

- - - 

r-H 

r-H 

II 

r> 

X 

> 

- - 

- - 

X 

cc 

CM 

a 

X 

X 

CC 

X 

X 

X 

< 

rH  9-i 

E- 

a 

1 

1 

O 

in 

vr 

CO 

ON 

D 

2 

— ' 

3 

3 

E- 

X 

X 

2 

CO 

^T" 

- - - 

1 — 1 

' 

M 

CJ 

D  O 

O 

CJ 

E- 

u 

CJ 

PH 

r 

E- 

X 

04 

04 

a 

C/3 

a: 

P 

s; 

CC 

CJ 

2 

X 

X 

CJ 

E^ 

E- 

X 

X 

3 

O 

X 

CJ 

cc 

X 

X 

X 

O 

cc 

X 

CJ 

CJ 

CD 

2 

P 

u 

X  ro 

E- 

a: 

cc 

o 

> 

E - 

X 

Q 

O 

X 

X 

3 

2 

PH 

r-H 

r-H 

X 

E- 

X 

cc 

CD 

X 

X 

X 

X 

X 

X 

X 

u 

— ' 

— ' 

2 

X 

D 

ZD 

X 

M 

w 

►H 

PH 

PH 

PH 

03 

2 

T. 

O 

CJ 

U 

O 

P 

D 

X 

> 

> 

>H 

>« 

> 

P 

X 

>H 

< 

O 

> 

>H 

> 

X 

>< 

•» 

% 

X 

u 

H— t 

P 

s: 

2 

r-H 

03 

03 

r-H 

03 

X 

_ _ _ 

X 

X 

X 

03 

P 

03 

X 

X 

+ 

X 

3 

X 

r-H 

X 

03 

X 

X 

X 

X 

X 

X 

X 

X 

E-  X 

E- 

X 

P 

X 

X 

X 

X 

X 

O 

X 

>  X 

l-H 

PH 

E-« 

X 

> 

X 

X 

X 

2 

X 

X 

SJ 

X 

r> 

CJ 

3 

CJ  3 

y 

o 

U 

o 

X 

=> 

X 

3 

o 

X 

3 

X 

n 

cc 

X 

X 

3 

X 

<s  < 

s>  < 

< 

X  < 

p 

< 

D  < 

< 

< 

< 

< 

P 

ts>  < 

a  < 

X 

< 

D 

< 

CJ 

< 

CJ 

< 

</>  X 

X 

4k 

p 

" — 

in 

at 

X 

'  * 

X 

' 

4k 

w 

o 

cc 

— ' 

CC 

X 

X 

4k 

4k 

<  < 

X 

< 

< 

>H  <  < 

<  < 

X 

<  < 

X 

< 

< 

X 

< 

<  > 

X 

<  < 

X  <  < 

X 

>H 

>H 

< 

< 

>H 

< 

< 

>H 

< 

<  >H 

<  < 

Sh  <  «c 

a  e- 

2 

a 

E- 

2  Q  E-<  2 

Q 

E- 

2 

O  P 

2 

Q 

E- 

2 

D 

E-  2 

2 

Q 

E- 

2 

D 

E- 

2 

2 

2 

a 

E- 

2 

Q 

E- 

2 

a 

E-  2 

a 

E- 

Q 

a 

E- 

X  X 

t-H 

j 

X 

»H  X  X  M 

X 

X 

i-i 

X 

X 

1-1 

X 

X 

r-H 

X 

X  ph 

M 

X 

X 

PH 

X 

X 

l-H 

PH 

PH 

X 

X 

PH 

P 

X 

PH 

X 

X  ph 

X 

X 

X 

X 

X 

! 


x 


a 


a 

o 


•a 

a 

a 


a 

o 


'O 

<N0 


<L) 

I 

Cl 


O 


a. 

O 


a 

o 


•a 

a 

a 


a 


SJ 

SJ 

SJ 

SJ 

SJ 

s 

SJ 

SJ 

ca 

<s  <s> 

S 

SI 

SI 

SJ 

Si 

SJ 

SJ 

S) 

s 

SJ 

SJ 

s 

<S 

S 

SI 

SJ 

<s 

S 

S) 

S 

SJ 

S> 

SI 

SJ 

S 

SJ 

SJ 

SI 

S 

SJ 

if)  vr 

CO 

ON 

SI 

r-H 

CM 

CO 

tt  in 

vr 

r- 

CO 

ON 

Si 

r-H 

CM 

CO 

x  vr 

r- 

CO 

ON  SI 

r-H 

CM 

CO 

*3* 

in 

vr 

r-" 

CO 

ON 

s 

r—1 

CM 

CO 

in 

vo 

CO 

ON 

rr 

rr 

rr 

in 

m 

in 

in 

in  if) 

in 

m 

in 

m 

vr 

vr 

vr 

vr 

vr 

vr 

vr 

vr 

vr 

vr 

r- 

h 

r- 

r- 

r" 

r- 

r* 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

•-H 

r-H 

r-H 

r-H  r-H 

r—1 

»-H 

*-H 

*-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

»-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

r-H 

rH 

r-H 

CO 

r-H 

r-H 

r-H 

r-H 

ON 

On 

ON 

ON 

ON 

ON 

ON 

Si 

r- 

CO 

*3* 

vr  TT 

CO 

*3* 

X 

X 

S 

*3* 

in 

D 

X 

ON 

<  *3* 

X 

SI 

X 

SJ 

in 

CJ 

in 

CJ 

m 

cj  in 

on  in 

s 

in 

s 

in 

s 

in 

CJ  in 

CJ 

in 

CJ 

in 

CJ 

m 

CJ  in 

X 

s> 

s> 

ON 

»-H 

CO 

Q 

r-H 

CO 

9 

r-H 

CO 

ON  r-H 

CO 

ON 

r-H 

CO 

in 

r-H 

CO 

in 

r-H 

CO 

CO 

ON 

r-H 

CO 

a  ^ 

CO 

CO 

CO 

Q 

r-H 

CO 

Q 

r-H 

CO 

o 

<-H  CO 

Q 

r-H 

s 

ON 

r-H 

00 

<  ON 

CJ 

< 

ON 

CJ 

< 

ONCJ<ONCJ<ONCJ< 

03  CJ  < 

ON 

CJ 

O 

<  03 

CJ  <  03 

CJ 

CJ 

CJ 

< 

ON  CJ 

< 

ON 

CJ 

< 

ON  CJ 

< 

ON 

< 

<  03 

CJ 

1 

X 

Si 

CM 

CO 

vr 

1 

CO 

i 

ON 

1 

CJ 

X 

1 

1 

ro 

1 

1 

vr 

1 

CO 

I 

O' 

1 

X 

1 

o 

X 

s 

1 

CM 

ro 

1 

vr 

1 

CO 

i 

ON 

CJ 

1 

X 

1 

X 

1 

Si 

1 

r-H 

1 

vr 

1 

< 

1 

CJ 

Q 

1 

S) 

CM 

co 

1 

VO 

1 

CO 

< 

1 

CJ 

X 

X 

s 

S) 

(S 

s 

SI 

SJ 

SJ 

SJ 

S  r-H 

r—1 

r-H 

r-H 

•-H 

r-H 

r-H 

r-H 

»-H 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

(M 

CO 

ro 

CO 

ro 

ro 

ro 

ro 

ro 

•^r 

■^T 

•^r 

r-H 

r-H 

r-H 

r-H 

•-H 

r-H 

r-H 

r-H 

r-H  r-H 

r-H 

r-H 

r-H 

r-H 

rH 

r-H 

r-H 

•-H 

r-H 

H 

r-H 

r-H 

r-H 

r-H 

•-H 

•-H 

r-H 

*-H 

H 

»“H 

r-H 

r-H 

*-H 

r-H 

»-H 

r-H 

r-H 

r-H 

r-H 

r-H 

*-H 

r-H 

r-H 

r-H 

ON  ON 

ON  ON 

ON 

ON  ON 

ON  ON  ON  ON 

ON  ON  ON 

ON  ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON  ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON  ON 

ON 

ON  ON 

ON  ON  ON 

ON 

ON 

ON 

ON 

ON 

Dr.  Dobb’s  Journal,  Number  56,  June  1981 


37 

257 


D 

cc 

r 

X 

2 

a 

2 

E-1 

DC 

ZD 

* 

CJ 

X 

< 

T. 

x 

X 

CJ 

X 

X 

H 

o 

2 

X 

X 

X 

h-t 

CJ 

X 

E- 

m 

Fh 

X 

P 

ZD 

X 

< 

CJ 

X 

X 

X 

X 

>H 

X 

< 

X 

m 

r 

2 

ro 

E-* 

»H 

00 

X 

2 

X 

>H 

X 

X 

X 

X 

2 

CJ 

X 

O 

X 

CL 

cj 

E- 

CL 

Q 

A 

II 

V 

Eh 

DC 

X 

X 

S 

CJ 

2 

ZD 

X 

2 

2 

X 

X 

X 

X 

X 

D 

Z 

< 

< 

< 

X 

O 

u 

o 

o 

>H 

E- 

CO 

ii 

X 

s 

*■ 

CL 

2 

o 

X 

CJ 

< 

E- 

CS 

< 

2 

O 

X 

2 

>H 

2 

>< 

o 

o 

2 

o 

CJ 

CL 

CC 

2 

X 

X 

X 

•H 

IS 

•H 

2 

o 

X 

Q 

•• 

S 

— - 

H 

CL 

CC 

< 

ce 

z 

< 

| 

< 

X 

X 

z 

< 

X 

X 

u 

X 

< 

Q 

.i 

X 

X 

X 

X 

Eh 

CC 

rr 

H 

X 

X 

X 

V 

o 

x 

X 

3E 

2 

o 

CQ 

u 

CJ 

< 

X 

Eh 

X 

X 

E- 

►H 

2 

X 

z 

CC 

T. 

o 

X 

t—l 

2 

X 

X 

CC 

X 

X 

Fh 

X 

o 

o 

bC 

►H 

< 

X 

o 

X 

< 

p 

E-* 

X 

E- 

X 

> 

o 

< 

a 

Eh 

< 

X 

u 

X 

X 

X 

|| 

X 

CC 

X 

2 

u 

X 

X 

X 

X 

z 

X 

X 

X 

D 

X 

X 

X 

r 

2 

< 

u 

X 

CJ 

>-» 

< 

H 

< 

X 

2 

*H 

o 

< 

CC 

X 

< 

*H 

►H 

X 

o 

2 

>• 

2^ 

X 

CJ 

X 

X 

X 

z 

o 

X 

u 

X 

X 

CJ 

CJ 

II 

X 

H 

2 

CL 

x 

— * 

E- 

o 

X 

CJ 

rH 

rH 

»H 

o 

< 

X 

< 

< 

c; 

< 

< 

CJ 

< 

o 

o 

CJ 

X 

IS 

X 

E-1 

+ 

+ 

+ 

X 

< 

X 

X 

X 

E- 

X 

X 

is 

t- 

Eh 

X 

X 

a 

D 

a 

Fh 

o 

a 

X 

a 

X 

>H 

X 

X 

X 

X 

CC 

E-* 

X 

X 

X 

x 

(N 

2 

x 

2 

IS 

2 

X 

is 

PC 

o 

CC 

z 

2 

z 

X 

z 

z 

a 

X 

X 

z 

CL 

X 

X 

< 

ro 

X 

X 

CC 

x 

< 

X 

CC 

rH 

< 

</> 

X 

< 

</> 

X 

rH 

cc 

X 

E- 

H 

Eh 

Q 

Eh 

Eh 

X 

X 

•H 

cry 

Eh 

n 

X 

2 

2 

2 

2 

2 

T. 

2 

=*fc 

w 

** 

CJ 

**= 

CJ 

=**- 

X 

** 

X 

SC 

X 

X 

s< 

X 

ce 

< 

** 

mr 

X 

< 

< 

u 

\ 

CJ 

0 

** 

CJ 

CJ 

CJ 

CJ 

CJ 

< 

< 

< 

< 

CO 

< 

CL 

CL 

>< 

< 

a 

X 

< 

< 

< 

< 

< 

X 

< 

>< 

CC 

►H 

< 

X 

o» 

►H 

< 

c  n 

< 

X 

< 

►H 

X 

< 

< 

2 

X 

< 

X 

X 

< 

CC 

Q 

E-* 

X 

X 

E-* 

O 

Q 

2 

z 

2 

Q 

2 

z 

a 

H 

X 

X 

a 

Eh 

Eh 

Eh 

o 

r 

D 

IF 

X 

T 

n 

Eh 

Q 

Eh 

n 

r 

X 

E- 

D 

X 

X 

a 

2 

Q 

Q 

X 

v 

fH 

CO 

2 

CL 

Uh 

>-3 

i-J 

O 

X 

b—t 

X 

CJ 

X 

X 

X 

CL 

CL 

X 

ce 

X 

X 

X 

X 

X 

CJ 

X 

X 

X 

DC 

□ 

CC 

X 

X 

X 

X 

X 

X 

X 

*-> 

X 

X 

X 

*-) 

X 

CC 

cc 

E H 

CL 

X 

O 

H 

X 

X 

H 

r 

X 

X 

X 

CL 

X 

X 

X 

DC 

m 

X 

X 

X 

X 

X 

X 

2 

2 

X 

Q 

X 

n 

X 

X 

a 

2 

2 

2 

o 

CJ 

CJ 

CJ 

Eh 

< 

DC 

< 

X 

CJ 

CJ 

CJ 

CJ 

is 

is 

IS 

<S 

S3 

ISt 

IS 

s> 

is 

IS 

IS 

IS 

IS 

is 

IS 

S3 

IS 

s 

s> 

IS 

IS 

IS 

is 

IS 

IS 

IS 

IS 

IS 

s 

IS 

IS 

IS 

IS 

IS 

S 

IS 

IS 

s 

IS 

IS 

s 

IS 

00 

OS 

is 

rH 

CM 

CO 

in 

vc 

r- 

X 

Os 

IS 

*H 

CM 

X 

m 

X 

X 

OS 

IS 

*H 

CM 

X 

X 

VC 

CO 

o 

IS 

•H 

CM 

ro 

^y 

X 

vr 

r- 

r- 

00 

00 

CO 

X 

X 

X 

X 

X 

X 

X 

Os 

ov 

OS 

ov 

os 

os 

os 

os 

Os 

Os 

is 

IS 

IS 

IS 

IS 

IS 

IS 

s 

s 

co 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

X 

X 

CO 

X 

X 

X 

X 

CO 

X 

X 

CO 

CO 

CO 

TT 

•*y 

^y 

^y 

^y 

^y 

^y 

^y 

^y 

^y 

^y 

^y 

*sy 

^y 

^y 

^y 

X 

CM 

CM 

ro 

CM 

o 

O 

O 

o 

os 

<N 

CO 

rH 

IS 

2 

IS 

IS 

»H 

X 

X 

CM 

CO 

X 

X 

CM 

CO 

rr 

CO 

H 

X 

CM 

vr 

X 

o 

X 

< 

X 

S3 

(Si 

<— 1 

in 

sj 

X 

in 

IS 

X 

IS 

IS 

X 

m 

in 

X 

s: 

in 

in 

IS 

IS 

IS 

X 

X 

h 

X 

IS 

IS 

0 

s 

IS 

X 

X 

IS 

u 

8 

u 

OS 

m 

00 

00 

IS) 

is 

rH 

OS 

s 

X 

*H 

Os 

s 

OV 

in 

X 

X 

OV 

IS 

X 

in 

is 

in 

X 

IS 

IS 

Os 

S 

os 

is 

X 

IS 

s 

D 

<J5 

IS 

s 

o 

CJ 

s 

CJ 

< 

00 

VO 

ID 

VO 

< 

CO 

CJ 

a 

cj 

X 

CJ 

Q 

< 

X 

vr 

VC 

< 

X 

X 

X 

TT 

CO 

< 

CJ 

X 

CO 

< 

vc 

< 

VO 

< 

X 

•H 

X 

< 

CM 

rH 

< 

< 

< 

CN 

CO 

VO 

1 

X 

is 

1 

CM 

1 

CO 

1 

1 

in 

1 

r* 

Os 

l 

X 

1 

Q 

CL 

IS 

CM 

1 

vc 

I 

X 

Os 

1 

< 

CJ 

1 

p 

1 

X 

1 

CO 

in 

1 

r-* 

1 

OS 

1 

X 

1 

a 

X 

1 

s 

1 

CM 

1 

CO 

X 

r- 

1 

o 

1 

CJ 

1 

X 

1 

1 

CO 

X 

1 

< 

1 

X 

< 

CO 

CO 

CQ 

CO 

CO 

00 

CO 

X 

X 

X 

CJ 

u 

CJ 

a 

u 

CJ 

CJ 

CJ 

0 

CJ 

D 

Q 

a 

a 

a 

D 

a 

D 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

s 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CO 

co 

Os 

Os 

Os 

OS 

os 

OV 

OS 

CT5 

os 

os 

OS 

Os 

OS 

OS 

OS 

Os 

Os 

OS 

OS 

Os 

Os 

OS 

ov 

OS 

Os 

os 

OS 

OS 

OS 

Os 

Os 

os 

OS 

OS 

Os 

OS 

os 

Os 

Os 

Os 

OS 

OS 

OS 

Os 

os 

Os 

c n  x: 

Eh  n 

z  ce 

2  < 

CD  O 

cc 

CL  E" 

X 

CD 

O  < 

CJ 

CD  C/3 

ce 

2 

W3Q 

O  CD 

Id 

X 

n  cd 

<  a. 

O 

E-i 

<  X  c/3 

CD  o 

CD 

x 

CJ  <  o 

ce 

X 

IDE  J 

se 

2 

CD  CJ 

Eh  0 

CJ 

C/3  CD 

CD 

2 

>  JD 

CD  Z 

X 

O  >h 

X 

L* 

'  CC 

Eh  CJ  CJ 

X  * 

3 

i— I  —  < 

rH 

r-»  X 

C 

+  ID  E 

o 

+ 

X 

CD  + 

CD  C/3 

Eh  a 

Cd  CC 

•J  1-J  C/3  E- 

X  X 

C/3  CD 

c 

C/3  <  CN 

o 

CD  X 

X  X  Eh  CD 

X  < 

<  X 

o 

<ISH 

rH  X 

xsxxsonce 

</>  X 

X  < 

u 

in  h* 

=*=  CJ 

CJ  oc 

<  <  CC  CC  CD 

—  X 

2 

X 

E- 

X 

Eh 

X 

X 

u 

2 

X 

CJ 

CJ 

X 

X 

2 

CC 

2 

2 

II 

D 

X 

2 

0H 

X 

Eh 

Z 

2 

2 

CJ 

X 

< 

2 

2 

CJ 

D 

2 

IS 

o 

CJ 

2 

X 

II 

r 

E- 

E-i 

CJ 

2 

X 

2 

2 

O 

O 

X 

2 

< 

E- 

J 

w 

2 

IH 

2 

2 

2 

CD 

X 

> 

2 

O 

2 

3 

CJ 

CJ 

X 

M 

O 

X 

CC 

X 

pH 

E-»  >« 

> 

X 

a 

>H 

a 

> 

E-*  X 

>< 

X 

X  * 

* 

X 

z 

ft. 

X  - 

X 

X  ^ 

2 

< 

- — »  iH 

O  r- 

X 

X 

X 

CD 

X 

X 

X 

X 

X 

X 

Eh 

X 

> 

X  X 

X 

X 

X  E-* 

X  < 

< 

rH 

<  X  X 

< 

cc 

<  X 

r*  2 

2 

E-*  O 

rH  X 

X 

IS 

*H 

X 

X  *H 

X 

a 

X  < 

iH  •< 

< 

Q  rH  X 

cc 

** 

— ' 

cc 

—  X 

X  x 

CJ  <  >H 

X 

X 

2 

2 

2 

>1 

<  cc 

o 

< 

< 

X 

>-  < 

X  X 

H 

2 

Eh  D 

E- 

a 

X 

X 

X 

a 

a 

X 

CJ 

a 

E-* 

E- 

a 

a 

<  2 

E 

M 

03  J 

2 

X 

2 

2 

2 

J  r> 

X 

X 

X 

2 

X 

X 

E-*  M 

X 

X 

H 

X 

z 

X 

a 

2 

D 

X 

a 

2 

T  ^ 

S3 

IS)  IS) 

IS 

IS 

IS 

IS 

IS) 

S 

IS 

S3 

S3 

S3 

S3 

S3 

S3 

S3 

(S3  *S3 

QJ 


>  <  < 


Q  2 


O  E-*  X  X 
*J  CQ  O  £-• 


s  S  IS  s  s 


-H(Nco^ymvcr^xcT>(S)'HCMro^yLnvrr^xo'*SJ'"HrNjrr>,:J,LQ 

00Q000C00000C00000(T\CT>CTtCT>C^<T>(T>(T>O>CT»'s's'S!'Sl!Scs 

CMCMCMCMCMCMCMfvlCMCMCM<NCMCMCMCMCMCMCMr^r,’'rr)rr)rr>m 


CM  CM  CM 
Os  Os  (J\ 


ro 

is 


X  X  CJ 

Si  S  IS 


HSunUM’inounrocQ  cow 

S<CDfr)lDi^D(S(SS  X  <S> 


X  X  CM  Dl} 

s  S  H  s 


x 

o 


c 


kCHQQ(NQQISM'l/1SlQ(^ 

XOV<IT<CMCMCM<<CMOV< 

I  I  I  I  I  I  I  I  I  I  I  I  I 
vox'<CjpxcMinx<cjx.H 
XXXXXX<SS3S>SsS3S)rH 
HHHHHHCMCMCMCMCMCMCM 
OSOsOSOsOsOsOsOsOSOSOsOsCS 


m  S  IS  rH 

x  vr  <  x  <cjcau,‘^^0000^ 

I  I  I  I  I  I  I  I  I  I  I  I  I 
mm  ko  oo  <cbUu®cMM'invc 
hhhhhhhhcmcmcmcmcm 

CMCMCMCMCMCM^MCNCMCMCMCMCM 

ososososososososososososos 


<SH<<SH<<X< 

DQHQDE-'QZE-' 

J  JW  J  J(/l  Jhbi 


cjcn>*<xx<>'<a:x< 

UHDD<ZD<X»)DD 

DK  J  JhH  J  j 

cc 

a 


s 

S3 

S3 

IS 

S3 

S 

S3 

IS 

S3 

S3 

S3 

S3 

S3 

S3 

S3 

S3 

S3 

S3 

S3 

S3 

2 

X 

OS 

S3 

rH 

CM 

CO 

•^y 

X 

vr 

2 

X 

Os 

S3 

rH 

CM 

ro 

5J* 

UO 

vr 

2 

S 

S3 

S3 

*H 

<H 

•H 

*H 

rH 

*H 

<H 

rH 

rH 

rH 

CM 

CM 

CN 

CM 

CM 

CM 

CM 

CM 

co 

ro 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

co 

ro 

co 

CO 

CO 

CO 

CO 

ro 

*H 

•H 

rH 

rH 

Os 

av 

Os 

Os 

IS 

X 

X 

a 

X 

X 

X 

X 

X 

<H 

^y 

X 

rH 

X 

s 

S3 

S3 

CJ  S3 

IS 

CJ 

S3 

S3 

rH 

in 

in 

X 

S3 

X 

Os 

S3 

•H 

D 

IS 

*H 

Q 

00 

rH 

VO 

S3 

IS 

*H 

<  00 

•H 

X 

<  IS) 

S3 

a 

< 

<  03  < 

< 

Os 

< 

U  <y» 

CJ  vc 

< 

X 

<  CJ 

co  <  ro 

CM 

<  < 

i  i 
00  < 

1 

CJ 

1 

X 

1 

•H 

1 

CO 

1 

X 

i 

X 

1 

Os 

l 

X 

1 

D 

1 

X 

IS 

CM 

ro 

1 

1 

X 

X 

X 

i 

Q 

CM 

CM 

CM 

CM 

CO 

CO 

CO 

CO 

ro 

X 

co 

CO 

^y 

^y 

*y 

*y 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

CM 

O 

O 

O 

O 

O 

O 

O  Os 

Os 

OS 

OS 

Os  Os  Os 

OS 

os 

OS 

OS 

os 

OS  Os 

38 

258 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


4210  WRBF  LDX  #2  TO  CHECK  WRITE  OPEN 


<L 

! 


D-. 

ffl 

X 

X 

X 

a 

X 

CD 

o 

u 

X 

D 

a 

m 

c 

3 

3 

00 

D 

X 

X  X 

z 

c 

CD 

m 

X 

< 

X 

cj  z 

CL 

M 

o 

Cl) 

DC 

cc 

z 

3  II 

X 

*T3 

cn 

CC 

a 

X 

CO 

X 

ffl  X 

cc 

DC 

3 

Cl) 

3 

u 

cj 

E- 

o 

X 

E-  CJ 

X 

< 

2 

!C 

cn 

CJ 

3 

>H 

< 

a. 

l-l 

< 

X  3 

CJ 

X 

.C 

cj  DC 

3 

>« 

<  U 

m 

W 

ffl  ffl 

si 

CJ 

3  W 

X 

cn 

E-* 

X 

2 

z 

cn 

E- 

D 

z  cc 

II 

X 

O 

CD  H 

D 

cj 

2 

Z  3 

X 

u 

»H 

M 

cn 

X 

a 

X 

cc 

cc 

X 

ffl 

DC  < 

r 

tH 

M 

M 

Cl) 

3 

< 

X 

2 

cj 

CC  3 

< 

M 

z 

DC  J 

T. 

X 

O 

z 

CD 

2 

X 

X 

3 

ffl  CJ 

X 

X 

o 

3 

w 

X 

X  E- 

E- 

CJ 

CJ 

o 

2 

m 

> 

u 

a  cc 

CJ 

CJ 

2 

X 

X 

3 

H 

5 

X 

a 

o 

X 

E- 

_  ><  o 

DC 

X 

X 

3  X 

o 

X 

u 

>H 

X 

CO 

j 

Eh 

X 

CJ  X 

>H  Eh 

X 

O 

3 

!5  *  ffl 

O 

X 

m  o 

J 

ffl 

z 

ffl 

X 

X 

M 

3 

ffl  - 

*  X 

ffl 

X 

a 

O  — 

Cl, 

X 

u 

5 

o 

rH 

CC 

CJ  -1 

X  _ 

^  X 

rH 

uJ  i_3 

_) 

O 

3 

X 

X 

x 

►H 

o 

+ 

s 

+ 

ffl 

X  z 

X 

+ 

CL 

X  J 

X 

X 

M 

o  r 

w 

X 

.J  o 

X 

X 

X 

.J 

r 

X 

X 

■j 

X  E-* 

ffl  ffl 

X 

X 

X 

u  X 

CJ 

ffl 

O 

t-  3  sc 

X 

X 

X 

J  w 

X 

< 

X  M 

< 

Cl) 

a. 

X 

Xhffl 

x  to 

X  < 

41  *H 

<  X 

V 

cc 

X 

h  c  y 

< 

o 

X 

</> 

X 

CD  X 

X 

X 

X  S  3 

3  2  X  n 

CC  »"H  < 

m  m 

X 

X  »H 

Si  X 

<  M 

H 

ffl 

CM 

CJ 

4fc  DO 

m 

CJ 

4fc 

z 

2 

CJ  C C  < 

<  cc  2 

** 

U  4k  ffl 

Z  “ 

2 

' - - 

X  X 

CL 

CD 

** 

cc 

>•  <  < 

X 

X 

<  <  X 

<  cc 

X 

< 

<  X  X 

<  <  X 

< 

X 

a 

< 

X  DC  o  < 

<cn  x  cj  <  < 

< 

><<>*<<UXM 

X  cc 

X 

U) 

O  Q  E- 

<  z 

a  e-  < 

X  w 

D 

a 

E-  <  Z 

a 

^  < 

X 

X 

x  a 

Q 

cn  cj  a 

E-t-  Q  z 

D  E- 

Q 

ZHDOHWfflh 

Eh 

ffl  D 

D  J(0 

E- 

M 

J  W  H 

E-"  3 

.J 

CD  E-<  t— i 

►j 

cn  E- 

X  X 

X 

X 

X  X 

X 

Wtt  J  H 

ffl  ffl 

X 

m  W  X 

J  X  D  *-)  CC 

X 

f- 

cn 


x 

CJ 

E- 

x 


<S  (S  IS  s 


s 

(S 

Si 

S) 

SI 

s 

s 

SJ 

S) 

s 

S) 

s 

s 

s 

S 

SI 

s 

Si 

Si 

s 

s 

s  s  s 

s 

Si 

s 

Si 

Si 

s 

S  Si 

Si 

Si 

Si 

Sl 

Si 

Si 

vr 

X 

Si 

CM 

cn 

lH  VC 

X 

ov 

s> 

rH 

CM 

cn 

in  vo 

X 

H 

CM 

cn 

*y 

in 

VO 

X 

ov  Si 

rH 

CM 

cn 

m  vo 

CM 

CM 

CN 

CM 

cn 

cn 

cn 

m 

cn 

cn 

cn 

cn 

X 

cn 

KT 

■^y 

^5* 

in  m 

in 

in 

in 

in 

in 

in 

in  vo 

VO 

VO 

VC 

vo 

vo 

CN  rH  rH  CN  rH  H  CN  CN  Cn  rH  *H  -H  CO  rH 

ON  ON  ON  ON  <j\  ON  ON  S3  ON  ON  ON  ON  ON 


CM 

IS 

»H 

^y 

CT. 

^y 

< 

ON 

x 

X 

X 

X 

CJ 

ON 

X 

in 

*y 

ON 

in 

X 

X 

rH 

X 

X 

X 

CJ 

X 

X 

s 

X 

X 

O 

*y 

X 

CM 

s 

< 

rH 

in 

CJ 

m 

CJ 

X 

X 

s 

CJ 

Si 

CJ 

X 

X 

in 

in 

a 

SJ 

Si 

Si 

rH 

S3 

CJ 

s 

CJ 

Si 

S3 

SJ 

SJ 

S3 

vo 

U 

r- 

s 

CN 

Si 

Si 

rH 

a 

< 

X 

rH 

Q 

X 

< 

s 

S) 

rH 

a 

< 

X 

rH 

D 

X 

< 

s 

s 

in 

*y 

Si 

Si 

ON 

in 

IS 

Si 

VO 

Q 

rH 

D 

X 

rH 

s 

ON 

rH 

vo 

Si 

S3 

X 

SJ 

CM 

< 

CN 

< 

X 

X 

< 

o 

X 

X 

< 

X 

CM 

< 

X 

X 

< 

CJ 

X 

X 

< 

X 

CN 

CM 

< 

< 

CN 

ON 

< 

X 

vo 

< 

X 

2 

ON 

2 

CJ 

ON 

< 

< 

ON 

CJ 

CM 

VO 

X 

CM 

< 

1 

VO 

1 

X 

1 

X 

1 

Q 

i 

X 

i 

<N 

1 

X 

1 

■*y 

1 

VC 

I 

<T» 

1 

< 

1 

X 

1 

X 

1 

A 

i 

CM 

1 

in 

vo 

1 

r* 

ON 

1 

o 

1 

a 

X 

rH 

i 

^y 

vo 

1 

X 

1 

X 

1 

O 

1 

X 

1 

rH 

1 

CM 

1 

*y 

i 

vo 

1 

ON 

X 

1 

X 

X 

1 

rH 

1 

X 

1 

m 

r* 

1 

ON 

1 

CJ 

1 

a 

S3 

1 

X 

s 

Si 

Si 

Si 

Si 

rH 

rH 

rH 

rH 

rH 

rH 

rH 

•H 

CN 

CN 

CM 

CN 

CN 

CN 

CN 

CN 

CN 

X 

X 

X 

X 

X 

X 

X 

^y 

^y 

<<y 

^y 

^y 

*y 

■*y 

^y 

m 

in 

in 

in 

in 

in 

in 

VO 

vo 

cn 

cn 

cn 

cn 

cn 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

(Ts 

CTv 

<JS 

<7> 

av 

ON 

ON 

<y> 

<y> 

o\ 

a\ 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

Eh 

a 

a 

X 

z 

2 

X 

o 

< 

D 

< 

o 

X 

< 

ffl 

< 

X 

CJ 

CC 

cc 

ffl 

2 

cc 

ffl 

+ 

cc 

X 

cc 

+ 

Eh 

E- 

CC 

X 

X 

z 

ffl 

< 

cn 

o 

X 

cc 

X 

o 

u 

< 

ffl 

X 

=> 

o 

X 

=> 

> 

X 

X 

E- 

X 

ao 

ffl 

X 

o 

2 

DC 

< 

ffl 

CJ 

Eh 

CM 

cc 

X 

X 

ffl 

2 

< 

E- 

> 

X 

O 

X 

X 

< 

cc 

X 

X 

X 

ffl 

X 

rH 

0 

X 

CL 

K 

X 

a 

X 

CJ 

ffl 

E- 

2 

II 

cc 

ffl 

CJ 

CC 

o 

>H 

«c 

z 

X 

3 

CJ 

D 

o 

X 

E-* 

< 

X 

X 

T 

E-> 

2 

CL 

T. 

> 

>• 

>H 

> 

Eh 

CJ 

X 

>H 

X 

> 

2 

X 

X 

X 

Y 

Y 

Y 

Eh 

z 

O 

CJ  > 

* 

* 

* 

* 

X 

ffl 

ffl 

u 

ffl 

O 

2 

ffl 

*  *  * 

< 

ffl  * 

o 

z 

cn 

rH 

z 

(■  ^  - 

X 

X 

H  ^ 

X 

X 

X 

X 

E- 

X 

2 

X 

E- 

+ 

ffl  ffl  +  ffl 

Eh 

cc 

X 

X  Eh 

X 

> 

X 

X 

X 

E- 

X 

X 

CL 

X  CJ 

x 

X 

X 

ffl  DC 

u 

cn  cn  co  cn 

CC 

x 

3  X 

> 

cc 

=5 

CJ 

3 

CJ 

rs 

CC 

O  H 

3 

X 

<  O  ffl 

CC 

o  z 

cn 

f—i 

<  <  cn  < 

2 

E- 

CM  3 

<  cn 

cc 

a 

< 

£ 

< 

ffl 

< 

X 

rH 

2  rH 

< 

z 

CO  E->  -C 

a 

CC 

E-  O 

< 

r~\ 

CD  CQ  <  m 

Q 

2 

IS 

CC 

rH  < 

— '  cc 

D 

cc 

Eh 

w 

ffl 

■  ' 

X 

** 

CJ 

—  o 

CJ 

cc 

ffl  o  JT 

CD 

4k 

w  4fc  -  X 

r 

w 

** 

X 

<  < 

>H 

< 

< 

< 

>H 

><  < 

< 

>« 

< 

< 

X 

cc 

X 

CC 

> 

< 

>« 

ffl  ffl  X 

CC  <  O  ffl 

CJ 

X 

<XCJCJ<CJ<X< 

X 

X 

<  < 

>4  < 

Eh  Eh 

2 

a 

Eh 

Eh 

2 

2 

a 

Eh 

z 

a 

E-  E- 

X 

Q 

X 

a 

Q 

a 

r  z 

X 

ffl  Q 

X  E 

z 

Q 

D<fflQE-UX<Q 

2 

E-* 

Q 

Eh 

Q  Q 

cn  x 

»H 

X 

X 

X 

M 

M 

X 

X 

M 

ffl 

X 

CC 

X 

*-) 

X 

J 

ffl 

CJ  00  3 

3 

X 

ffl  »"3 

l-l 

ffl 

fflE-CJ<WDE-E-'ffl 

X 

X 

X 

X  X 

Eh  a 


X 

o 

E- 

o 


o 

Eh 

o 


CL 

O 

X 

O 


s 

IS 

s 

s 

IS 

IS 

S3 

s 

Si 

S3 

Si 

S3 

S3 

Si 

S3 

s 

S3 

s 

S 

S3 

s 

Si 

s 

s 

Si 

S3 

Si 

S 

s 

Si 

Si 

S3 

S3 

s 

Si 

S3 

Si 

IS 

S3 

IS 

S3 

IS 

IS 

IS 

IS 

S3 

00 

ON 

SJ 

rH 

CM 

m 

X 

vo 

r* 

00 

ON 

S3 

rH 

CN 

cn 

^y 

X 

VC 

00 

ON 

s 

rH 

CN 

cn 

*y 

X 

vo 

00 

ON 

S3 

rH 

CM 

cn 

^y 

X 

vo 

00 

ON 

s 

rH 

CM 

cn 

CM 

CM 

m 

m 

m 

m 

cn 

m 

cn 

cn 

cn 

cn 

*y 

*y 

^y 

*y 

^y 

^y 

■<y 

^y 

*y 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

VC 

vo 

vo 

vo 

vo 

vo 

VC 

VC 

X 

X 

r- 

r- 

m 

m 

m 

m 

m 

m 

m 

m 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

cn 

rH 

rH 

rH 

rH 

rH 

»H 

CN 

CN 

»H 

cn 

cn 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

*y 

D 

VC 

X 

*y 

r- 

^y 

00 

^y 

X 

rH 

s 

ffl 

CJ 

X 

a 

X 

p 

ffl 

cn 

< 

X 

ffl 

X 

X 

X 

X 

< 

Q 

s 

ffl 

CJ 

Q 

X 

X 

CJ 

CJ 

CJ 

X 

CJ 

X 

u 

X 

S3 

< 

is 

X 

X 

s 

Si 

ffl 

X 

Si 

IS 

u 

S3 

s 

s> 

s 

Si 

S3 

S3 

u 

s 

IS 

is 

s 

X 

S3 

is 

rH 

D 

00 

Q 

a 

rH 

00 

00 

Q 

rH 

00 

g 

rH 

IS 

s 

CN 

s 

S3 

rH 

S3 

rH 

s 

S 

S3 

X 

SJ 

CJ 

X 

Si 

rH 

< 

00 

ON 

rH 

vc 

< 

00 

rH 

CJ 

vo 

ON 

X 

s 

X 

IS 

ON 

00 

CJ 

< 

00 

ON 

CJ 

CJ 

< 

ON 

CJ 

< 

ON 

vo 

CN 

< 

CM 

< 

ffl 

< 

a 

a 

CN 

CM 

< 

ib 

*y 

X 

< 

ffl 

< 

»H 

vr 

ON 

CJ 

00 

< 

ffl 

*y 

00 

< 

00 

< 

ffl 

CJ 

X 

1 

Si 

1 

CM 

X 

VO 

1 

ON 

1 

CJ 

X 

1 

X 

1 

S 

1 

cn 

1 

X 

VO 

1 

ON 

ffl 

1 

CJ 

1 

X 

rH 

^y 

1 

vo 

1 

00 

1 

< 

CJ 

1 

X 

1 

rH 

I 

^y 

vo 

1 

00 

ffl 

D 

1 

X 

rH 

1 

CN 

l 

cn 

X 

1 

1 

ON 

l 

< 

1 

ffl 

a 

1 

S3 

CM 

1 

*y 

X 

00 

< 

CJ 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

VC 

VO 

X 

vo 

vo 

VO 

r» 

r- 

h 

00 

00 

00 

00 

00 

00 

00 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

< 

< 

< 

< 

< 

< 

< 

CM 

CM 

CN 

CM 

CN 

CM 

CN 

CN 

CN 

CN 

CN 

CM 

CN 

CM 

CN 

CM 

CN 

CN 

CM 

CM 

CN 

CN 

CM 

CN 

CM 

CM 

CN 

CN 

CN 

CM 

CN 

CN 

CM 

CN 

CN 

CN 

CM 

CN 

CN 

CN 

CN 

CM 

CN 

CM 

CN 

CN 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

ON 

Oo 

I 

Q. 

© 

CL 


C 

O 

^3 

2 

•S 

Cl 

s: 

s3 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


39 

259 


U.  UJ 

UJ  ¥ 


Sj  >  K  UJ  X 

Sou  > 

***!*!£ 

in  uj  ^  k  I 

JsL 


<r  o  ~ 

«“  i 


>  n  &  ^  s 

M uj  . m  .a 

5  pass 

i& ±££212 

:  '  in  S  in 

I  in  £  *-<  o 

M5 1/)  >  i  k 

J|- 

;  rp  x  I  in 
l(N£ii-  ll  uj 
uj  fc  o 

mh( 

)  c,  w  I-  h- 


?i  iiSSHHi  i 


S'  °  ^ 

5  uj  uj 
-J  u 

.'E# 

l?!!s 

5  &  ix 

-J  UJ 

*M  UJ  h-  . 

U.  X  h-  s 
h  uj  r 

ibil 

i|M 

a  O  uj 

WHh 

UltSa 


§*21 

C  in  -j 
in  ~  ^  uj 


ujSSS 

2?  UJ  K  UJ 
-I  Jl 

oEBS 

K  a  <J  U. 


?5,  pi 

o  >  <t 

8SLB 

>S“Ha 
l!  <r  z  uj  3 


2K0  W 

iJjea 

O  •%  IL 

s^y 

K  UJ  -J 
(T  Z  U  > 

K  S  Uj  Ll  ^ 

*  2  H  o 

SdSS^ 

lOhSl 

o  >  z 
(*-  in  o  a 

Sfc  **«  k 

uj  ^  > 
a  Il“  jJ 
b-  ~  in  Cl 

l/l  u.  •' 
U1  >  2  ~ 

W  U.  UJ  (-  > 

WMJy  lu 


oo¥SS 

hKhllU 


¥  in  o 
»-  in  k  cl 

m 

slag 

"aS# 

/;:*r 

E  Z  Z' 


U  Ll  UL  2  O 

8  =  C3li! 

uj?  ittui 

jjjieidl 

U1  O  UJ  3  K 
t-  i  — 

JggajS11- 

»- 1-  u  2  m 

Iht* 

’  “f  ,s 

O  H  p  3  UJ 

►;S%u, 

D  •“>  a  »-  X 

g|slx^ 

iPl 


UJ 

5  £ 

in  £ 

s  gg 

J  X  !£  h- 

J!t£  QQ 


3  - 

1/1  UJ  l!  t  Mr  S 
m  x  in  z  o  uj 


y  5hu,>I 

in  w  h  *  *-t 
Ul  Z  -I  ""I 
t  ~-JZt/H- 
OC  I  M  M 
U  K  3  _l  u. 

1  Sd*r 

**  in  1 1  r  cl 

l 

2l  ~  t  jn  in 

8  g|acs_, 

inUJE  K 

P  SK*gS 


in  si*“^2 
a  isiSws 

r 

in  hk  u 

^  2§i«$£ 

K  htlUIh 


i£s 

6 1  £  3 

»2nl 

£S£> 

sss| 

i  e  8  £ 

h-  ►—  O 
x  •■*  i  in 

¥ 


S  S  i  S  i 

UJ  UJ  UJ  UJ  c 


UJ  UJ  Z 

•w  D  uj 

§1*  I  I 

_  Ll  Z  O  r- 
O  —  UJ  L) 
H  UJ  U  1^ 

£8^  S  | 
Ld  ^  S  2  .jg 

JO  .MUJtfUJ 
Q  U  UJ  UJ  JO  J 
W  N  _J  UJ  -•  U  •*■• 
r  o-hm  JU.UJU. 
Oh  JU.H  S 

u  x  u.  UJ  UJ 
UJ  *-•  UJ  K  UJ  K 

"hhO"  JHUJ 

^SdCbjsg 


^  K  >  S 

uph  in 

o  in  Sj  u  in 

s§:s  1 

KJXh  I 

>S!J!k  k 

u.  p  uj 
H7p  Ll 

fill  i 


u  5  ® 


SSSSSSiS 

UJUiUJUJUJUJUlUJ 


r  t 

\  u  u  uj  uj  X 

b  # 


£333 

| 

Ul  UJ  UJ  UJ 

UJ 

£ 

_J 

•M 

ll 

•% 

II  II  ll  ll  ll  ll  II  II 

«m  in  o  ©  *«  jo  in  uj 


jES£g; 

8888 


DO 

U  E-I 

oc 

E-1 

E- 

Ou  X 

QC  QC 

X 

X 

X 

Uj  W 

cc 

z>  a. 

w 

X 

w 

n  2 

< 

CJ  n 

2 

X 

2 

CO  || 

X 

II  CJ 

»H 

lJ 

o 

X 

00 

o 

CO  _) 

+ 

X 

X  cc 

E-* 

E- 

E-  CC 

X 

X  X 

X 

> 

>< 

a  => 

> 

X 

w 

w  - 

X  CJ 

2 

^ — ' 

2  —. 

Ul 

lJ 

X 

J 

Cx3 

xJ 

u 

DJ 

w 

X 

CJ 

X  X 

CJ 

CQ 

X  Ct, 

CD 

Ul  w 

cn 

CD 

*— i 

X 

x  o  r~  n 

•c-  c_.  . 

Cl, 

< 

00  x  Cu 

< 

oo  u 

< 

<  X 

•2  *  — 


CO  i-l  <  OQ 
—  dfc  CO  — 


03  + 

co  w  s<c 

<  CO  O 

00  <  cc  H 

— '  CQ  (O  CL 


X 

2 

X 

u 

X 

X 

E- 

CJ 

X 

< 

E-1 

E- 

u 

X 

l-H 

X 

CJ 

a 

u 

u 

§ 

2 

E- 

E- 

II 

> 

X 

u 

X 

CD 

u 

>  + 

CL 

2 

<  + 

u 

h-i 

2  cc 

E-> 

X 

X 

< 

X 

o 

X  X 

CO 

u 

u 

<  u 

2 

r  e-> 

M 

X 

X  X 

X 

X 

E-*  X 

u 

u  - 

h. 

E-  - 

D 

<->  2  — 

rH 

. _ , 

CO  ^ 

2 

+  w 

u  + 

x  w 

CD  CO 

M 

u  CO 

tn  u 

CJ  X 

CD 

CO  I-l  < 

<  CO 

X  < 

< 

<  CO 

^  m  <  x  m 

is  X 

X  *te 

^2QQ2t<XMtHMQuiE:zOQ<:^Q^“°h2oSx< 


ISlSlSlSiSilSllSlSlSlSlSlSlSlSlSlSlSlSlSllSlSlSJlSlSSSlSlSlSlISJlSlSlSlSlSJlSJlSSllSSllSJlSlSlSlSSllS 
ts-©(^isHCNjmrfin'Drs'X^<siHCNn5Tini£)(^x^iSHf'jmTTiniD[^x(^sHfNifnt)'iniDi^xcyiis,-<f^(n 
ioiCLDr^r-r-r-i^r-r^[^r-r-oooocooooocoooooooooc^<^a^c^c^a>c^c^a^a^is5iS5Siisiiscsissjisis5— '— *-J— ' 


oo  a» 

id  1C  VD 


in  in  id  m 


®  ffi  u  n  h 
<  s  m  tu  n  h  m 


HUtoisoj^tumcuu 

isCutssiHinCuisisCuQ 


W  CM  Cl.  w 
®  H  S  55 


UCuCQcnC&JCQW 

OlSSlSCJlSSiCS 


HUlLUU 
5)  IS  IS  Ui  5) 


'-H<T»lS5lS)*-H00aN®'-«^®'-,lS)r-HQ®i-«<CX)f-HlSLO^H<00»HlX>iniS5CJVriS5*-»<00^'-HVOIS)f-H00<nrH<CX) 

CQUO<CD*HVC<<T»<<t^<<T>CN<CD<CJCQ<Cx3<Ti0000<T»U<Cn,^,U<cO<'-HVr<T»U<ONCJ<a>00< 


I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I 
inx<uuscN^int^c^cDQUHmLnx<UQUisfN^ricr^x<UCij®^inr^a\<cDQUHninxx<cD 
iDvcirir>iDr^r^i^i^r^r^r^c^r^ooooooooooooooooaN<T»aN(^<^a>(T»cT»(T»<<<<<<<<<aQcQCQcQCDCQCQ 
rocorococorororororocorncocncocococococoi^rnrnrncocorocococo^cororofororococorocococococorDco 
(T»CT»0>CT'CT>CT»G>G^C7>CT'CT'0>CTiCTN^CTi<TiCT>CT><Ti^CTiCT>CT'CTiCTiGN0>iCTi<T'CJN(Ti(T»cr'lT«CT»(T'CT»  (Js(T\(Js(J\<J\<J^O^O><J^ 


40 

260 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


S  8 

.ffi  .v 

JPJ 


iiii 


Si8  £ 
82:  ° 


Sf  Sjt!  s  s® 

is  ,'c  *  "!fi 

K  g  Z  Z  ^  -  > 

jil  ^  EL  ||\i 


o  o  UJ 

t  cj  & 

8  S 

«  J  UJ 
Q  Ui  E.  K 
Z  H  Ui  UJ 
•"•  K  S  -J 

z  W 

B  £  is 

£  O  ®  A 

»  r;gg 

UJ  K  2-  U, 

£  §£5& 

H  111  •*  *% 

K  Z 

s  UJ  O 

l5S*5§S 

.Sss^ils 


3  * 


§§§§  §  iSgg^SeiS^gfc  §2l  §8  §1^88^8  2K  ^  jj§§c^8fe 


N  2  h- 

J  f  « 
fi£Bu  ..  S 


M  k  It  ii 

BftS  <t 


10 

w 

r.  -t)  & 

8^sD 

2 

re  35 

22£ 

822 

P) 

W 

O 

©  in 

uj  K)  r- 

H  M  O  II  * 

SS2 

II  MU® 

m 

SSs  sSS 

*  *  *  IT  * 


Rsmsn 


N  W  *  N  MUMfN 

sS  S  22  2222 

8P>  «s  is&Sssi 
|8  ii  nnm 

IMr  If*  IMrttMMT  V 


I  01  CL  H 


.  cn 

i  E- 
OS 
:  z 

2S  s 
s  s 

cl  co  cn 

•  Z  X  X 

I  1"3  •  • 


®  s  ®  s  s 
tj*  in  vc  r'-  oo 
H  H  »"H  H  H 

m  m  m  in  in 


m  m 

<T\  <y» 


q  </>  ic  r'  oo 

s 

s  <  </>  </>  </> 

E- 

c/iwx><a,<<t/3 

5C  H  h  I  J  h  H 

•  ui  (fltn  a  a  in  s 

e- 
m  ix 

Eh  z 


SSSSSSSS 

oisHNnvinic 

i— l(N(N<N(N(NCNfNl 

inmininmininm 


tru< 

USO 


in  vc  r~ 

^  ^ 


§HUsssoomiC']'ooa>uiis 
OUfSSSlQOOOOIDSlCCOlC 

I  I  I  I  I  I  I  I  I  I  I  I  I  I 
U6u'-HrrmvO(j\<cjCdis^HrsiTr 
amiuuuuuuuuDDQD 
foronrororonrorororompon 
OlOlU'OlU'U'OlOIO'OIOlCTlUlOl 


_ s- _  HDhJfnUHQ,. - -  _ 

lt<U300  HMHK0gt3O0.2SU(IlU)OSZ 
S2wsjj2swooooooooap:cxw2EH 
aSmwuiUHOintthftHE'ttEtE'E'hSsjjx 

I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I 
uoiaininiuuD(7\iu(Noouui<TiiiHM£i(MlKr'!N 
nQOlilUllIIISSDmOOUOQUQUSVQDUl 
po  —i  -j  m—t  re  irei  fM  re  re  re  re  irei  irei  <— i  ro  pn  < — i  re 


:  u  m  ui  o 


I  i  I  l  i  l  I  l  i  I  I  I  I  I  I  I  I  I  I  i  i  I  I  in  is 

WffiooroinUtCJQaititrMooWinTj'DD^ii^iOfMiiLii^rsi  ^  -q  5- 
nQOtninfflissQODOUUUDUQUSifQQin  U,  s  ^ 
(MnHHHHBBiNBssassssHnriHSis  „  m  ^ 
OIQOIOlOlOllSBfflOIO'tJlff'O'OlO'OlOlIJ'OllTISia  ••  , .  , , 


V  Eh 

Q|XX>EtOIDaXEJIua:3D.Z>USXIi.X>E'  Eh 
‘^2£l::?SS?SZCJ!lfia‘:SfcEHOwwuu0(nZB:mo'o;i-i 
^*U0HuJ»-4222z5222200C^Cl<CLCCcCXttCCXlX 


I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  |  |  |  |  I  I  I  I 

icumtfmuMB<ooi£i<0(<iQMn'»DnQinuiih(!)A 
r~icooooWQ006KUOvoini£>WQCJUin<EisOr-tooO 
HCIINCDlNINHr'lBHHHHHBIsnrilrilnHCtHINOJBH 
oiuioitiOio\®oiQ^o>oiaioia\o\oiaioioioio\uio\uiQoi 


jxsHjusJcotittiurtxxoQwouEHWtncQw  j 

OlCVlXtOXXhlllliJUIiIUJJOKDOHXu  Gu  J 
UO'-J=><UUDti-222222222UUa:Oa(iL<M 
<<<<CDCDaJCQ0D<JUUOOUOOUOQQWWfc<6Li 

I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I  I 
sOiSHTWCCTiaowinCTiKirocoiniSHrQCuvcmEiicaicQ 
inQWinsc_>c_>oot--cocococn&L,<s<cQCiuuu&jtsCJio 

QfMINBSHHHHMIvlINNNntMMtMHrOHBSSH 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


41 

261 


(Continued  on  next  page) 


g 

UJ 

g 

X 

g 

UJ 

£$ 

-« z 

z 

2  x 

K 

►4 

UJ 

ft3 

i 

k_ 

g 

O  K 

i 

K 

4 

-1 

O 

K 

0 t 

g 

g 

ft 

g 

i 

£ 

•* 

ft  * 

£  4 

iff 

4 

K 

ft  4 

fc  t 

il 

g  ft 

SxS 

f£ 

XRfl 

OUT 

hi 

3^4 

g 

ft 


t  s 

ft  4 

tX  -J 

zzSiauz 


h- 

m 


i 

i 

IT 


o 

£ 


4 

I 

I 

5 
* 
i 

4 


| 

s 

1— 

in 


ft 

or 


I 

s 

ft 

ft 

it 

**4 

£ 

K 

H 


UJ 


i 


in 

UJ 


ft 

S 

»*4 

Cl' 

r 

in 


4 

►■4 

UJ 

i 


•s 


s 


UJ 


H 


3 


8kB8  8 

C3  N  M  N  o 

N  in  u)  n  g 

Nr w  N  N  N 

m?  ? 


8  4§ 


?? 


ft 

? 


T) 

<u 

3 

4C 

3 

O 

u 

J- 

O 


4 


o 

p 

2 


2 


ic  * 

■“>  u. 

it  ~ 

a  4 

H-  h- 

4  5 

'UO 


f- 

4 

*-* 

g 

H 

in 

I 

ft 

X 

ft 

I 

t 

4 


4 

*•4 

g 

K 

in 

s 

z 

g 

s 

8 


r- 

4 

CL 
P 
in 

g 
-j 
i 

CL  g 
CJ  K 
in 

g 

ft  2 
2 

8  c 

t 

4 


4  ¥ 


8 

8 


C  cl 

ii:  Ui 

UJ  I- 

M-  W 


Q 

4 

£j 

Dl 

z 


g 

o 

§  .  fc 

~  g  g 

UJ  UJ 
W  g  Ul 

r  £  s 

tor 

?  £  ~ 


2  8 
a  *  8 


«  4 


x 


ft 

g 

o 


4  4 

ft  g 


a  |  a  4 

ii  v>  u.  o 

2  4  £ 

go  o  g  o 


|  fc  |  fc  §  |  & 

a  i 

J  a  a 

4.4  ft  ft 

«m  g  O  UJ  g  UJ 


z 

o 


a 


4  ft 

«ir  Ul 


I  i 


X 

b~ 


Q 

4 


4 

K 

4 


o 

4  . 

it 

>  O 
K 

\  g 

ft  it 

IT? 

/N  /*\ 

UJ  g 


O 

4 


ft 

4 


B  5 


6- 

/*\ 

10 

11 


x 

o 


o 

ft  4 

UJ 

CO 
G 


I 

X 


0- 

/\ 

o 


o 

4 


u 

4 


4 

F 

Z 


G 

8  . 


g  ^ 

1  I  SX 


G  I  UJ  UJ  UJ  u 

«ltn5  ccS  Ul 


W 

Jo 

3SiS( 

UJ  JOU 

Wi 

j 

i 

j 

84 

UJ  o 

CPI 

JNC 

n 

g  N 

O  *"5 

h- 

4 

¥ 

H 

1 

(J 

K 

ft 

i 

K- 

ft 

K 

in 

ft  4  uj 

-l 

s 

H 

r-  m 

5  S 

N  ^ 

x  i 

N  tf 

I  I 

N  K) 

S  S 

N  ^ 

ir  y 

u  $ 

l 

n  y 

s  § 

y 

y 

y 

H  O 

y 

y 

o  u 

G  U 

UJ  g 
g  O 

00 

ii  S  8  3 

MOO 

gN  A 
fO  QQ  O 

g  n  Hi 

MfflU 

S  a  5 

8 

S  Si  u 

2 

II  O 

CO  & 
u 

g  G 

O 

X 

O  ©  r  tr 

»tr  tr  tr 

NflCfl) 

^  ^  K> 

ui  «m  <N 

ir  v 

88$ 

m 

y  y  y 

W 

w 

y 

sO  ^  g 

wsw 

y  y  y 

y  y 

O  iN 

ft  ft 

y  y 

in  n 

ftft 

y  y 

g 

ft 

y 

t  m  mi  m  » 


N 

y 


It  8ft 

g  sO  (N  g  ^  UJ  IN 


N 

y 


S  w 

00  t  ft  ft  0i 


O  MJ  10  N  UJ  U.  (J  r-IBO  10  (J 

)  UJ  «Nt  4  £  OQ  UJm 

I  0  +4  H  +1  H  <H  «H  44  *4  (N 

?  m?  m  ?? 


42 

262 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


h  p ••  oE  $ 

-J  HI  2  £  U. 

u.  5  z  w 

Llh-QHO 

X  LOO 

I  -J 

Kzyj 
•-«  5  -v  in 

12 


IS  1 


B  S 

E  § 

in  5 


8  “■  2 
S8  I 


a 

Ll  U. 

sH 

*  a:  o  to 


•  o  in 

CL  h-  ►* 

U  2  d  p- 


>  z  p 

r  g  | 


;£  u.  § 

)  U-  **•  UJ 


(■■■  o  fc 

5  d  |2! 


H-  K 
U.  Up 

-  aS. 


I  i  1  |  ll 


i  3  S  ^  B  f 

i  OS  in  *S  in  in 


§  858B  g  §Kl*  |i  IirS  j  l^s(  J  §  £518  ffl  58 


n  r-  ft  p- 

i~i*  j 

S  S  S  n  n  s 

MqKMJC'M 


8 

u  to 
li  no 

n 

p- 

S£g 

U  <N  U  to 

n  n  n  (j 

p. 

5  j 

p-  n  u  to¬ 
il  to  n  n  o 

P- 

S§ 

U  N  to 

ii  n  k>o 

U)  ©  P4 

5^5 
B  ?  K-' 

ll  SJu 

to  to.  to 
poo 

tr  *■  ▼ 

O 

i 

uurn 

me 

*■*■*■*• 

sisif 

TT  rr  rt  Tf  Tf 

ff  If 
tr  ^ 

+*  **  +  c 

v  *■  v 

r-r-  in  r-  to  n  it* 

v  ir  v  v  *r  *  v 

so  ®  in  6  m  to  t 


iNCNt  top-  (N 

Ki  Kl  to  O  n  to  o 


to  5  to. 
no  o 


gSS  fc|£  I 

in  in  in  in  in  in  in  in  ip 


Ls 

^ISS 

5SSS 

•H  Z  O 
O  <^  *■*  *** 


SCE3S 

iiil 

-al  S  2 

wwww 

iiii 


§§££££ 
u  OS  in  in  in  in 


8  .B 

Mi 

£>H¥ 

yju.lL. 

t  £<5£ 


Q  a  '  o  'in  u  'in^to  2 

5  !i  £  S  22  ?  S*  2 

*»  4  *'  •*  •*  •»  *1  •*  •'  •'  *%  •«  u 

„  Be  Bo  £  s  „  3  ? 

S  A  I  W  Sw  S  5  E5  $  8j 

QIL  Ox  £  o  ao  hi  -o  k o  ~B  £ 

it 8 uj  £ 2 n s  BcuisB  S*j2o«^B  •it-  £ 

i£s  i£S£  5118k  iiSgfcs*  §5£  5 

i 


E  £ 

\  f 

£  £ 
O  to 

B  S 


.I  i 

si  3 


P-  IN.  N  N 

SSJ2 

NNflfJN 
II  On  IO  IO  10  10 

oo  a  u  u.  a  c 

1*5  ^  ft  JJs  i  5? 


ll  K)  ^ 

P-  ©  U 
to  ua  u  S3 

P-  u  u.  o 

P-  ^  P- 

*  *  * 

L*«si 

n  Ps  25  o  m 

N  ^  N 

5  5 1  to  S 

Q  ip  P-  u  N 

too«N<^unK) 
<NP-toOOto©U 

pw 

*1 2> 

H  §  M 

N 

tr 

« 

P- 

i 

N  V 

s  s 

ii  S  n  S  5 

26 

222647 

t  riNto 
K)  K)  K)  K) 

???? 

?*??? 

NtotoouP^nm 

{» 

trir 

SI 

T 

© 

1 

rr 

n  io  u  p-  to 

^  U)  O  to  to 

ttHv 

to  o 

to  to 
?* 

Dr.  Dobb’s  Journal,  Number  56,  June  1981 


43 

263 


(Continued  on  top  of  page  42)  \  (Continued  on  next  page) 


IL 


X 


r  ih  Mi 


tD5  S  ig  S  Ss  S  ££ 

gjJjH  O  V)  g  <*>  UJ  to  U  to  to 

*-*■&:  2 :  to  z  z  to  u.  z  tou 

uj  to  E  uj  E  o  £  S 

k  •  to  be  k  •  to  t  >*-  •  in  h 

*SSi  BfijS"  ms  HI 

•%  •%  *5  *%  2  *%  •<*  •*  »t  •* 


S  $  ui  §  id  e  g  §  id  E  g  it*  S:  ld  £  "^  £ 

k8©£  mSi 


i£b%v  §S^sl§S^sliS  ^gsls'^l 


CJ  sD 

2§g$ 

uj  5  U  iN  ^ 

Suli(j(J 

i  U.  N  t  N 
CJ  CJ  IO  M  K> 

$  $  $  $  $ 


CJ  CJ 

in  ir* 

Ll  Ll 

If  If 

)  to  CJ  M  to  to  IN  Cj 

;sss  Siisfis  u. 

)  uj  in  B  ©  &  uj  it*  B  ll 

j  5  in  k>  uj  Cj  to  in  k«  uj 

»  (J  if  u  ll  HOu’ifU  II  L_ 


CN 

i0 

li. 

tr 

to  to  cj  ©  cj 

SS2SS 


05  054  astaCiLfJin^jf  t 
K)  K)  n  fO  tf  in  IT-  IT*  IT*  to  to  0)  CO  © 

totototototototototototototo 

tftfTr^-trtrtrtrtrtrtrtrtftr 


UJ  »■ 

K  o  . 

X  _l  to 


p  H 

i§  ll 


<r  «j 

i/i  k.O- 
l/l  X  S  K  t 

UJ  UJ 

$ 

ism  “ 

.J  E  fc-  £  in 

K  tfl  Si  K  3  D 
SmS  S 
.  £ 


Pi  t 

*  U  § 

x«*a:®£Sx£«*x 


to  to  to 

Tf  V  V 

»  UJ  Q 


Skill.  UJ 

«m  uj  uj  3!  5  w  K'  fo  O'. 

UJ  II  N  IL  u  O  (N  (J  ll  Cj  UJ 

©  «h  «h  Cj  tf  C-  £  ©  Ld  UJ  U. 

UJUJUJUJUJUJUJUJUJUJUJ 


*XtoflOUJOEflOtoX 


;  3S!&2**»& 

l  * 

s  S 


if'  in  in  il  uj  S  +*  ~  ^  ^ 
i  wtooinSootowo 


©©**fJK>trtofrCC©0 


sL  ; 

U.  Ll  g  m  £ 


!P  IS  U 

•t  •«  •% 

UJ  UJ 

O  ^  UJ  ^ 


VI  '  >  h-  S  VI 

i-  '  J  ■-'  11 

Bk  g^St-Sg 

ji  W  t—  S  01  S£  uS  •;  _ 

|| 

j  uj  '  12 

C  to  ' : 

H-  O  fc  K  n  , 

g  uj  h  3-  Eg  2 

OJ,  J  t  WQ' C 
u  •-■•  Cki  Ol  t  O  □_□*•£ 

•  ^  ^gBSseifiz 


® 

5  k 

8  J 

O  ' 

^  es 


m  32^SS!  liiw  52  ft  2S 


8  3li»  Sefisl  5c 

a  i  i  l  l 

t  1  s1  Is 

S  ?.  2  I 


-J  bJ 

§g  ^ 


r.  n  cj  in 

tr  -»r  tf 

to  u  in  u.  v 

•m  J)  ~*g  u_  * 

r-  cj  ^  ui  E  u  tf 

ll  to  K)  hOUIlU 

in  in  to  to  o  uj  ^  ip 

HMM  H  ^  H  (,‘J  N 

¥?¥  ??¥?? 


in  N  in 

■v  TT  IT 

«  uj  5  uj  £ 

-Suiu 

8ft?IW8 

s??«s 


tN  iN  r-  N 

v  ?  v  _  2 

N  S  &  5  &  $ 

-h  vo  -<  N  m  "i 

M  ri  iN  IN  10  IO 

K>  to  to  to  UI  to 

r)  n  r>  k«  Ki  tr 

m  in  in  in  m  in 

tf  tr  tt  TT  Tf  Tf 


to  <j  ©  to  Cj  in  to  to  in 

Stf  CJ  Tf  V  Tf  B  tf 

to  cj  lj  to  to  o  to  to  g  u. 

«  iEsSIssPi 

u  II  O  t  f  ll  O  II  u  li.  U  u  O  (J  ll 

K»  Tf  tr  r.  U.  Ll  L.  CJ  tr  r.  to  U  U.  KJ  to 

tf  tr  tf  tf  to  N  N  Lj  lj  to  to  to  to  to  to 

in  inminininininininir'inmin  £ 
tr  ^  tr  tr ’T  tr  tr  tr  tr  tr  tr  tr  tr  tr  tr 


$  £ 
9  ¥ 


sm 

S|)Sn 
i  o  tf  Bo 

)  in  in  in  In 


>*.■  r  i 

8  ¥ 

IIO  CJ 

SS  § 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


QJ 


fefi  . 

lL  UJ  U. 

IIP 


E  uj 


KggOt 

$  £  o  5 1 
£  In  Ui  i  ’ 


S£k  £ 
■JS  / 
s-'Sfe 
iit*. 

ibi 

l-'i* 


CL  CL  • 
u  uj  cl  .  . 

a.  U.  UJ  CL  CL 

l  U  2l  £  h-  Z  Z 

<H555~~ 

]  O  O  CL  UJ 

5  t  £>  UJ  h- 

jgsssta 

~  uj  h  z  f  a: 

>  K  L.  Jr  H 

;fe^y«62 

JtKWOhh 
jWXUhXW 
:  E  uj  h-  u  t  . 
.rz>w2Jtt 
■i  5  ^  uj  uj 

Z  O  KOkL 
H  U  J'  H  O  U 
)  uj  o  m  5 

jJ  il'  , 

.  z  u  d  x  uj  in 

!«£**£££ 


CO 

o 

mdx 

<r  -j 

X  XX 

rm 

iLjS 

c\i  <\<  ~  (N  <n  n  « 


3  §32^  ^ OHZZhSj 

,  kj  Ki7ii7i^33CEuju.  JU4:ujE 

Cl  Z  y*i  W  ^  5  v*  *?  ^  !£  ^  CJ  x  I  X  x 

2  £  &  2  -J  £  U.  Q  5  C  ^  ^  ^  K  H-  H  K 

S»  E&8£S5$3£!§5££££ 


r-i  If  1 

OG 

inininujS^*^^^ 

ll  UJ&O&vJO&UJO 

.  0)uG 

li  N  m  (J 

X>  lf>  05  U.  N  r-  0)  U,  U)  X* 
N^o^aa-^u-XKMj 

£>  Cj  UJ  Ul  0  C*  IT'  ^  N  X' 
U.LlLlU.X*X0XiOO 
V)yO^*NNNNNN 

SftSB 

r.  r.  n  n 

u  Cl  UJ  It  O  ^  N  K)  If! 

r.  r-  r-  r-  n  r-  r-  r-  n  r- 

^  N 

r-  n 

M-  M- 

n  %  n  \  \  r.  n  n  r.  n  r-  r-  rv.  r-  r.  r. 

2  E 
§*  * 


i  s  w 

HH  *~( 

fc  5  a! 


2  £  «  £ 

*s  •*  •%  S  •%  •« 

Ckl  H  h-  X  h- 

t-  z  z  x  IL  k  z 

CL  O  CJ  UJ  Ll  0.  05  o 

U  CJ  O  K  SuNU 

li  u  i  im 


%i  «  i 
i  £§  b® 

£  in  r  2  3  x  u '  3 

in  a:  S  x i£  Jl  t:  ¥:  \  *  £ 


:  o  w  £  o 

'  cj  uj  X  o 

!  S  >  o  £ 
VSK  t 
f 

JZhH  K 

lo||  8 

UJ  liJ 
J  X  i.  X  H 

>  t  u  O  £ 

12^3  $ 


!  g  83, 

>  O  »m  U.U 

:  X  CO  d  4  *  ci  <J  C 


I  3S28!  £  §£  Sitssfes^aS&S 


5  5  CL  N 

UJ  -J  0  *"> 


5:8  SS^b^  8  BxSB  p 

«j  £  uj  £  •-  S  ^  o  uj  jcu  a 


i'-j  r- 
Z  5-  v 


V  ■*  * 

Irbs 

^nijN 

CM  <N  K)  fO 


U.  CM  M  M)  N  IDOfJ  If) 

k  us 

,T5r^r,«r  ir  1 1  irt  v 


r-  u>  m>  sj 

t  w  ir 

N  JN  OO 

J  r.  £  S  —  in  r-  y  E  -■  ffv 

MttlONMLNOS  II  li-O 


r-  c  &  w  ~  in  10  v  r-  ®  C  tt  a  ®  uj  ® 

U.IlU.U.GC'0£i&iju&  o  o  o  H 

ir»inir>inu)u)u)s0'ii'!pu)'n 

t  tr  m- rr  5r  tr  tr  ^  ^  ?  rr  ^  ^  ^ 


<£  M)  'N  M 

X  NX  ^  °  ^ 

VL'  K)  tn  <N  uj  ^  UJ  £  ^ 

II  to  'N  O  U  o  ll  «-«  O  (J  u 

“  SSSS  ft 

vjC*  'JT*  '•£'  'X'  SO  v?  ^0  U?  U>  U<  ‘JD 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


45 

265 


WRITE  fiN  OUTPUT  RECORD, 


z 

CD 

Ld 

(- 

cc 

o 

Ll 

cn 

z 

Ld 


iB 

Ll 


IS 

I 


IS 


is 
o  a 
ii  i- 
..  u 
cc 

*  -i 

*-<  |  u 

o 

i-  >  cr 

x  J  CL 

id  O  Q 

Z  0-  z 

Ld 

o  o  o 

oo  cn  O 

-0  O  N 

o  o  o 


Ld 


cn 

- 

CL 

Z  - 

Ld 

Id  : 

-L 

p-  /N 

P- 

Q  iB 

O 

cc  is  a 

iB 

z 

Ll 

►  *.  Ll 

*  a  ii 

Z  -- 

cc 

CD  Cl 

CD  CQ 

z 

in  Ll 

=  Ll 

Ld 

II  •- 

-  Z 

X 

/"v  = 

Ld 

1- 

a 

_J  LB  x  X 

II  ■■ 

□  -  UL- 

O 

•-  a 

cl  a 

II 

Z  : 

r  a  o 

IS 

CD 

-J  Z  II 

Ll 

cn  p- 

a  i-  u.  a  a: 

iB 

z 

is 

I 

a 

ii 

IS 


CCl 

+ 


z 

Ld 

X 


IS  3  II  Ll  ||  Ll  11  Ll  *-*  Ld 
L)  O  £L  ••  i— i  >•  »— i  O'  (f) 

ojz(illejijilj 

QC  CD  i-i  li.  w  Ld  Ld  Ld 
CL 


x 

a 

z 

Ll 

II 

x 

Ll 

Z 

..  Ld 

IN  I 


Z 

Ld 

X 


o  ts  o 
a:  t-  a  x 

Ll  Ll  a  Ll 
—■  Ul  II 
Ll  O  a.  ••  Ll 
HZldlM 
Id  00 


X 

Ll 


X 

II 


IS 


X  Ll 
Ld  ll  • 


cn  ~ 
a.  = 

Ld  •> 
^  X 

Ll 

a  •- 
I  s 
iS  w 
w 

cn  = 
oq  •- 

a  x 


cj  > 

Ld  _j 
cn  o 
o  a. 

_i  o 

CJ  -  CN 

a  * 

O  I-I  QC  Ll 

iraao 

CC 

XCJO!_JWI- 

o  >  a  a  a 


ii 


a  _i  oo 

id 


cn  «  a  h  z  »  k  is  Ld 

JCZI-wOlLQOxiL 

id  uzitoqo  jhlj 

DILaZICOQD: 

Ld  CL 


cc  = 

a : 

I-  II 

cn  * 
=  a 
ii 

i- 

3  i- 

a.  3 
z  _J 
*-> cn 


a 

3 

CL 

O 

X 

a 

TO 

Pit 

„ 

o 

- 

CD 

z 

: 

QJ  ■■ 

z  ~ 

1*0. 

Ld  * 

i-  a  Ld 

i  a  _j 

p- 

P-  -•  L-. 

=  _j  cn 

-J  p-  =  a  =  =  - 
=  ii  ii 

3  >  '"IIL-«.. 

_J  II  (-•(*•■  3  Cl  0-  Id 
cn  ••  3  <r  _j  a.  i-cn 
a  a.  HziLtn 
Ll  QC  Z  Ll 
i-i  Ll 


h  w  h  Ld 


a 

Ii 

a 

> 

ii 

■■  lL 

CL  t-H 

i-  a  Ld 
cn  z  cn 

Ld  _J 
Ld 


o  o  o  ©  o  o 

-I  <N  m  in  i) 
N  N  N  N  N  N 
O  ©  O  O  O  O 


■  O  O  O  O  O  O 


O  O 


'iMIwMIMMMIMMMMMnmr-m 


« I 


■u 

ai 

♦> 

o 

HI 

a 


x 

& 

+> 

u 

li 

a 


>- 

<r 

cc 

LZ 


<q 


2 

id 


TO 

CD 

-P> 

0 

Ol 

CL 


A 

I 

C  X 

Cr  | 

Ixr 

01  K 

Ld 

ID  ,01-1 

I  no  - 

Oi  *■  \  « 

H 

_l 

J-  ^h| 

t~  tH 

rlQH 

~ 

H 

0; 

01 

r  <r 

^  >- 

Ll  Ldl 

1  a  Ld  -  Ld 

a  Li 

*  Lii  Ld  Ui 

:  <r 

:  JO  _l  :  JOJ 

r  _i  CC  _l 

CC 

H 

H  H 

H 

H  H 

♦♦  iL 

..  Li_| 

♦  •  Li  ♦♦  i; 

♦♦  L. 

♦♦  L  ♦♦  L 

r  <r 

z 

o 

G 

G 

^  G 

H 

Ld 

3 

N 

2 

N 

2 

N 

N  Z  N  z  r  z 

X 

U- 

Ld 

Ld  Ld 

Ld 

Id  Ld 

CC  H 

o 

CC  Cl 

CC  Cl  CC  Cl 

wL. 

CC  Cl  CC  Cl 

3  C 

G  O  O  O  O  C 

O  O  O  O  G  O 

CC 

O 

cc 

CC  CC 

CC 

CC  CC 

■z.  O 

n 

|cc  o 

i  oi  c 

i X  o 

uc:  o  cc:  o 

!  j !  tH 

* 

Ld  CN 

LiJ  CM  U  CM 

Ld  CN 

Li  CM  U  CM 

•5 


» 

in 

o 

CD 

•• 

II 

O 

o  cn  -i 

CC 

no  a.  i 

* 

a. 

cn  id 

CL 

>- 

o 

•• 

••  _i 

cc 

s 

1  r  Q 

0 

CL 

■  ■ 

t-4  ■■  i^i 

ll> 

X 

H  7  H  .. 

o 

a 

Ll 

\  O 

II 

cc 

O  : 

z 

N  JlLO 

a 

CD 

IS 

t— 1  1—4 

■n  hoih 

a 

o  a 

*  :  a 

a 

=  a  a 

in 

o  o 

II  cc 

a  a  a  =  i- 

L— 

Q  Q  CL  CL 

>  CL  «  o 

cc  II 

■■  Q_ 

OZZQQLd 

Id  □□  HU! 

Z  Ld  CD  - 

■■ 

>  r 

CC  m  i— i  3  3  CC 

CC 

cc  cc  >  > 

>  :  O  Q 

■"  Q 

CL  :  :  = 

-1  cc  z 

o  z 

OPh 

U  U 

u 

u  '  u 

O  1-  a.  i-i 

II  >-l 

Q-  a  3 

Id  Z  Id  Z  Id  Z 

Ld 

Z  Id  Z  Ld 

CL  3 

•• 

Ld  a 

IS)  Ld  x  Id  x  Ld 

X 

Id  x  Ld  x 

CL  X  X 

#  1- 

i-  a.  z 

d  X  Ld  X  Id  X 

Ld 

I  Ld  X  Id 

x  Z  *-•  i-i 

(raaidH 

U  3  3  3 

3  3 

V  I-I  Q  Q 

a  r 

X  01 

O  O  O  O 

o  o 

o  o  o 

O  O  O  O  O  O 

O 

Q  ,-i 

-■  <N  n 

in  >o 

f'-  co  cn 

o  —  cn  pj  in 

>0 

Mi3  Ul  5 

o  o  o  o 

O  O 

O  o  o 

tH  H  H  rH  H  H 

H 

H  H  H 

o  o  o  o 

o  o  o  o  o 

o  OO  o  OO 

o 

o  o  o  o 

46 

266 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


* 

CM 

it 

II 


c 

OJ 


II 

CL 

J— 

cn 


o 

Q 

CL 

h* 

cn 

a. 

UJ 

i— 

cn  x 

_i  a 
<->  z 

I-  Ll 

o  r 


* 

CL 

cd 


o 

Q 


z 

3 

O  x 

o  * 


a  = 
cc  .► 

u.  X 
ii 

••  J-  x 

■■  Ll  x  z 

JH  -I  J- 

hq  a  o:  x 

K  Z  O  CL  UJ 
UJ  U.  Z 


a 

cc 

Ll 

II 


a  i- 
3  3 
0-  _j 

o  c n 

i 

_i 
_j  >-< 
LU  I- 
1X1  z 
a:  3 


a  > 

cc  _j 

m  x  o 
>  x  a. 

a  a  _j 
o  z  a 

CL  Ll  Hi 

cl  a 

a  u.  j 
Z  LU  CD 
lu  a 


X  I 

*  * 

cc  cc 
CD  CD 
x  II 
> 

-J  * 

o  >-< 

CL 

II  cc 

o 

>  Ll 


* 

on 

a  a 

LU 

cn  ► 
o  > 
_j  _i 
a  u  o 
z  CL 
u.  u. 

>->  _i 

u.  a  a 
UJ  OJ 
QUO 

uizaa  j 

ZIlZICO 
LU  CL 


* 

>i  > 

II 

J— 

X  <x 


I 

* 


> 

-I 

□ 

CL 


O  x 

Q 

I 

~  * 
l-H 

O  X 
J—  > 

Z  _l 
3  O 
O  CL 
~  Q  II 
t 

CC  * 

CD  QC  it 
CD 

>  II  •- 
_l  "■  -rH  * 
O  *  it  »-• 
0.  >->  II 
II  ••  I- 
K  MX 
H  O  it  UJ 

it  u.  z 


CM 

x 


O 

II 


* 

CC 

a  a 

UJ 

U)  . 

o  > 

Ll _ I  _J 

►1  u  o 

Q  CL 

a 

U  >  _J 

o  it  a 

CC  GG 

a.  u  o 
Q  o  _j 
Z  CL  CD 
uj  a. 


*  I- 
CC  z 
CD  >-< 
cc 
Ll  a. 


o 

CL 

II 

u 


* 

cc 

CD 


Z  II 
UJ 

I  Q 

i~  a 
cc 
>N  CD 


tH 

a 

a: 

rH 

-•  Q 

s 

X 

> 

CM 

CM 

-J 

\ 

z 

O  Q 

A 

AN 

a  o 

AN 

A 

II 

II  cc 

Q 

Q 

■■ 

w 

v 

CM 

CQ  Z 

CC 

CC 

X 

U  LU 

z  a 

a 

•-  *  Z  CD 

lu  cn 

cn 

H 

Aauiz 

x  + 

i 

X  H 

CM  *  X  >-< 

1-  GCi 

GG 

\  X 

•3 
>  I 
_J  GG 

o  * 

CL  ffi 
UJ  II  II 

cn 

j  a  q 

UJ 


O  J— 

X  Z 
Q  11 
cc 

U.  CL 
►H  Ul 


o  - 


a  = 


X  II 

GO 


Ll  X  _| 


II 

Ul  ■■ 

cn  -i 

X 

UJ 


Ll  u 
►1  II 
Q 

Z  CM 
LU  x 


Z  IL 

►-H  l-H 

CC  Q 

a  z 

LU 


a 

> 

u 

Ll  O 
i-h  CC 
Q  CL 
Z  Q 
UJ  z 
LU 


'  o  o 


O  O  O  O  O  O1  O*  O  O  O  O  O1  O  O  O  O  O  O'  O  O  O  O  O  O  O  O  O  O  O  O  O  iD>  O  iD  a  a  /~'t  a  a 

uT-or^oocnor4C'4K)<tin-;qi>aDgio-'C^n^in>or^coor!oS.cQn^iniDr^d6orio^c^Ki^in-ohim 
1  ^  ^  W  CM  CM  CM  iM  «.M  CM  K)  K)  Kj  K)  K«  K)  10  K)  K)  K)  ^  ^  ^  in  Ifi  ID  in  in  in  in  ll 1  Ul 

^  ^  ^  ^  ^  ^  ^  ^  rH  tH  rH  tH  tM  rM  rH  »H  tM  rM  rH  tH  .  j  i  j  .  _•  .  .  ,  .  .  . 


> 

+ 

Q 

O 

CC 

* 

x 

II 


X 

1 

1 

X 

X 

o 

1 

o 

•V 

o 

x 

Vi 

1 

Q 

X 

X 

CD 

Vi 

* : 

1 

II 

CD 

o 

o 

P— ! 

t—4 

■  ■ 

o 

r- 

Q 

Q 

j  y—i 

1 

.^i 

Cl 

> 

■  ■ 

1  1 

Q 

It 

-J 

o 

o 

5 

O 

O 

P-H 

t-H 

X 

Q 

o 

# 

s 

1  > 

Ct 

1- 

V 

1 

a 

X 

CL 

o 

AN  AN 

o 

■  ■ 

1  -J 

z 

> 

o 

CD 

h- 

*  * 

b- 

1  o 

Q 

3 

h- 

it 

*■ 

z 

1— 1  l-H 

£- 

& 

1  x 

UJ 

O 

o 

X 

Q 

> 

z 

p— . 

■» 

■■ 

3 

"w1  — 

CL 

3 

1 

AN 

cn 

a: 

Q 

X 

CD 

UJ 

_j 

3 

Q 

cc 

r 

o 

5 

Q  Q 

CD 

O 

Z 

i  - 

o 

CD 

=  A 

cn 

o 

O 

C 

CD 

Z 

LU 

CD 

Q 

Z  Z 

Q 

a 

P-H 

i 

_i 

rH 

■  v 

■  V 

t-H 

X 

o 

X 

c 

z 

x 

Z 

Z 

cn 

CD 

l-H  1— 1 

UJ 

V. 

CD 

V 

u 

.1-. 

1 

/A 

r, 

1 

UJ 

_i 

t-H 

UJ 

h- 1 

II 

o 

p> 

Q 

♦ 

Z 

II 

o 

cn 

> 

* 

Z 

> 

1  h- 

> 

# 

IT 

h-  w 

z 

u 

it 

|| 

=  z  = 

:  I 

•* 

_i 

Q 

a  *  cl 

■  ■  ■■ 

II 

Q  O 

_J 

X 

t—i 

-J 

i  cn 

cc 

_J  X 

X 

P-H 

cn  > 

X 

Q 

it  X 

>  x  ll 

Ll 

aauii- 

CD  U 

Z 

CL  CL  ID 

cn 

Z  AN 

■■ 

z  _l 

O 

CD 

cn 

O 

i  UJ 

Q  Ul  O  CD  CD 

.-N 

UJ  -J 

o 

X 

Z 

X 

CD 

►-H  CD  t—4 

t— t 

>  >  cn  o 

o 

i— i 

CD  CD 

II 

Z) 

=  * 

AN 

l-H  u 

X 

ii 

ZD 

X 

1  X 

3  Z 

X 

-w- 

II 

> 

# 

x  □ 

I 

a 

t-H 

o 

II 

it 

uj  X  Q  Q 

it  it  M  Z 

uj  x 

Q 

= 

ii 

>— 4 

* 

tH 

■■ 

It 

z  z 

CC 

> 

X 

=  X 

h- 

CL 

t— ■ 

~  - 

=  3 

cn  a  z 

_l 

* 

i- 

h-  - 

P-H 

1 

U  Q 

-J 

* 

h* 

H 

P-H 

U  O 

_J 

_J 

# 

a 

P-H 

CD 

u 

Ul 

«J 

CD  it 

U 

U 

u  cc  a  a; 

i— i 

a 

1-  * 

►— « 

Z  X  > 

W 

O  3 

a 

P-H 

Z 

Z 

1-  1- 

O  X 

cc  o 

l-H 

X 

h-  h- 

h-  o 

X 

a 

|| 

P— 4 

> 

ZLUZUJZLULUQUJ 

GG 

3  CL 

UH 

CL  _l  J-  > 

CC 

is 

p—i 

P-H 

t-  z  z  z 

CC 

GG 

X 

ii 

> 

z  z  z  cc 

X 

UJ  X  UJ 

X 

UJ  X  I  \ 

Q 

P-H 

U 

O 

a.  O  CL 

cr 

Z  O  X  _J 

CL  U 

□ 

X 

X 

X 

X 

P-H  P—4 

P-H 

cl  u 

o 

ll 

X 

X 

-J 

P-H  P—4 

P—4 

X 

M 

CD 

it  X 

c 

X  UJ  X  UJ 

X  UJ  1—  X  Z  J— 

O 

_J 

ztro 

X 

hILUIQCiO 

-i 

o 

X 

X  UJ  X  X 

X 

a  o 

3 

Q 

> 

LU  □  CC  CC  CC  Q  O 

_i 

x  a 

Q 

3  3 

3  O 

lu  z  cc 

CD 

P-H 

CD  Ll 

Z  0- 

Z  X 

CD 

X 

Z  X  X 

X 

z  cc 

ID  x 

X 

Z  CL 

CL  CL  CL  Z 

X 

n  n  ii 

XI 

a. 

Ul  X 

LU  CL 

UJ 

X 

o  o  O 

o 

o  o  o  o 

o 

o 

© 

O 

O 

O 

o 

o 

o  o 

o 

o 

o  o 

O 

o 

Q 

Q 

o  o 

Q 

Q 

Q 

Q 

o 

r., 

r.t 

-i  CM  Pi 

in  >o  n  co  in  o 

t-4 

CM 

pi  •!»  in 

-o  n  ca 

cn 

o 

<SI 

n 

in 

■n 

co  cn 

o 

—  (M  Pi 

in 

jo 

1^ 

CO 

an  o 

tH 

CM 

K> 

in  o 

CM  CM  CM 

CM 

CM  CM  CM  CM  CM  Pi  Pi 

Pi 

f-i  pi 

Pi 

Pi  Pi  Pi  Pi 

<r  <r  iii  uj  ui  in  bi  ui 

bi  bi  bi  bi  -0  Mi  MJ 

sO 

>0 

nD  >n 

•-C 

O  O  O 

O 

O  O  O  O  O  O 

O 

O 

o  o  o 

OOOOOOO 

o 

o 

o 

o 

o  o 

o 

O  O 

o 

o 

o 

l^l 

o*  o 

o 

o 

Dr.  Dobb’s  Journal,  Number  56,  June  1981 


47 

267 


Book  Reviews 


Computer  Consciousness: 

Surviving  the  Automated  80’s 
By  H.  Dominic  Cowey/ 

Neil  Harding  McAlister 
Published  by  Addison- Wesley  Publ.  Co. 
$5.95,  212  pages 
Reviewed  by  Joseph  B.  Rothstein 

The  choice  of  the  title  is  a  curious 
and  somewhat  inappropriate  one.  It  raises 
the  expectation  that  this  volume  will 
clarify  the  impact  of  the  computer  on 
lives  during  the  coming  decade  —  an 
expectation  that  is  heightened  early  on 
when  the  authors  emphatically  state 
“Survival  on  the  job,  survival  in  the 
classroom,  and  survival  in  society  depends 
on  it.”  The  computer  is  an  agent  of 
change,”  they  add.  “Its  uncontrolled  ap¬ 
plication  may  metamorphose  our  institu¬ 
tions  —  not  in  beneficial  ways  that  cor¬ 
rect  existing  problems,  but  in  ways  that 
we  do  not  intend.” 

These  are  powerful  ideas,  deserving 
of  analysis,  thoughtful  speculation,  and 
orderly  examination.  At  first  blush,  Com¬ 
puter  Consciousness:  Surviving  the  Auto¬ 
mated  80’s  might  seem  to  be  an  attempt 
at  coming  to  grips  with  these  social, 
political  and  personal  winds  of  change. 

But  such  is  not  the  case,  for  what  we 
find  instead  is  a  guide  to  evaluating  and 
purchasing  a  computer  system,  albeit  a 
well- organized  and  systematic  guide.  This 
particular  case  of  false  advertising  may  be 
forgiven,  for  it  would  take  far  more  than 
this  one  slim  volume  to  fully  evaluate  or 
forecast  the  changes  which  our  society 
will  undergo  during  the  coming  decade  as 
a  result  of  the  spread  of  automation  and 
machine  intelligence  -  and  also  to  pro¬ 
vide  a  tutorial  approach  to  computer 
hardware,  software  and  systems  integra¬ 
tion. 

The  authors  have  pursued  the  second 
course,  and  the  tutorial  approach  is  the 
strength  of  this  text.  There  is  no  fat  in 
this  volume,  and  the  novice  reader  may 
soon  find  himself  or  herself  overwhelmed 
by  the  sheer  quantity  of  information. 
Apparently  mindful  of  this  possibility, 
the  authors  have  thoughtfully  provided, 
at  the  end  of  each  chapter,  a  list  of  new 
words  encountered  in  the  chapter,  as  well 
as  an  index  and  brief  glossary  at  the  end 
of  the  book. 

While  first-time  buyers  of  an  appli¬ 
ance  computer  intended  primarily  for 
games,  children’s  education  or  household 
use  might  find  more  in  this  book  than 
they  can  or  want  to  handle,  professionals 
or  institutions  contemplating  a  big-ticket 


purchase  would  do  well  to  arm  them¬ 
selves  with  the  knowledge  this  book  pro¬ 
vides  and  points  to.  Even  a  computerist 
with  some  years  of  experience  may  find 
this  text  useful  as  a  brush-up  reference, 
including  as  it  does  capsule  definitions 
and  descriptions  of  a  wide  variety  of 
hardware  devices,  software  tools,  and  sys¬ 
tems  options. 

The  authors  have  done  a  creditable 
job  of  organizing  such  an  encyclopedic 
body  of  information.  A  brief  introduc¬ 
tion  describes  the  book  as  an  attempt  to 
compile  a  large  amount  of  general  intro¬ 
ductory  material  from  widely  dispersed 
sources,  and  offers  a  quick,  descriptive 
overview  of  hardware  and  software,  and 
their  place  in  a  computer  system. 

Subsequent  chapters  examine  func¬ 
tional  aspects  of  these  large  divisions. 
First,  hardware  -  ranging  from  input  and 
output  devices  to  memory  devices,  CPU’s 
and  telecommunications  options,  and 
closing  with  considerations  for  the  hard¬ 
ware  shopper.  Next,  software  is  examined 
from  the  ground  up  -  machine  language, 
assemblers,  operating  systems,  high-level 
languages  and  applications  packages,  and 
how  to  choose  software.  Finally,  the 
computer  system  as  a  whole  is  briefly  dis¬ 
cussed,  including  real-life  problems  and 
considerations,  personal  requirements  and 
potential  difficulties,  and  considerations 
in  selecting  a  vendor. 

The  emphasis  is  on  breadth,  not 
depth,  and  the  business  person  or  depart¬ 
ment  head  would  be  foolish  to  think  that 
any  one  book  can  provide  a  thorough 
basis  for  evaluating  increasingly  complex 
alternatives  of  hardware,  software,  and 
human  systems.  But  as  a  place  to  start, 
this  slim  volume  covers  most  of  the  con¬ 
cepts,  options  and  jargon  that  the  system 
user  or  automation- minded  manager 
would  be  likely  to  encounter.  It  may  not 
answer  —  or  even  ask  -  the  larger  ques¬ 
tions  implicit  in  its  title,  but  if  survival  is 
the  goal,  then  a  catalogue  of  the  arma¬ 
ments  and  combatants  is  a  good  place  to 
start. 

The  MC6809  Cookbook 
By  Carl  D.  Warren 

Published  by  TAB 

$6.95, 176  pages 

Reviewed  by  Richard  L.  Lozes 

Recently  we  have  seen  the  introduc¬ 
tion  of  a  few  microprocessors  which  have 
been  hailed  as  interim  processors  between 
the  8-bit  and  16-bit  designs.  Perhaps  it  is 
better  to  view  these  processors  as  more 
balanced  and  better  designed  versions  of 


their  ancestors.  Certainly,  their  instruc¬ 
tion  sets  reflect  the  awareness  that  soft¬ 
ware  has  to  be  written  for  these  chips, 
and  that  the  early  microprocessor  instruc¬ 
tion  sets  made  that  task  more  difficult 
than  necessary. 

The  MC6809  is  a  good  example  of 
these  mature  8-bit  microprocessors.  Con¬ 
tinuing  in  the  style  of  previous  “cook¬ 
books,”  Carl  Warren  discourses  on  the 
6809  function. 

I  was  disappointed  by  Mr.  WarTen’s 
treatment  of  the  topic.  While  the  chapter 
on  the  instruction  set  certainly  has  much 
to  recommend  it  on  the  basis  of  regular¬ 
ity  of  format  of  the  information  on  each 
instruction,  those  aspects  of  the  book 
which  are  less  mechanical  to  produce  did 
not  fare  as  well.  Even  the  spelling  and 
grammar  reveal  poor  editing  despite  the 
fact  that  the  book  was  typed  originally 
on  magnetic  media. 

On  to  specifics  .  . . 

The  timing  diagrams  are  few  and 
cramped.  I  know,  from  other  Motorola 
data  sheets,  that  the  information  neces¬ 
sary  to  design  a  system  around  a  CPU 
chip  is  nearly  all  on  the  sheets.  Certainly 
this  part  of  the  book  must  be  supple¬ 
mented. 

Chapter  three  on  addressing  modes  is 
too  brief,  and  poorly  written.  “I’m  rea¬ 
sonably  sure  that  on  this  first  reading  you 
haven’t  grasped  everything  that  was  pre¬ 
sented,”  says  Mr.  Warren.  Apparently  he 
was  too  interested  in  seeing  an  early 
publication  date  to  rewrite  the  chapter  in 
order  to  make  it  understandable.  After 
all,  what  is  the  point  of  authorship? 

One  may  as  well  not  bother  with  the 
six  pages  devoted  to  the  MEK6809EA 
assembler.  Again,  other  sources  must  be 
consulted.  Apparently,  the  author’s  pet 
version  of  bastard  BASIC  (VTL-09)  took 
precedence,  even  though  it  is  so  cramped 
as  to  be  nearly  useless. 

In  closing,  I  would  suggest  that  one 
browse  through  this  book  rather  carefully 
to  first  ascertain  whether  it  contains  the 
information  desired  before  parting  with 
$6.95  to  buy  it.  I  would  not  spend  my 
money  on  it. 

Microcomputer  Interfacing  Handbook 

A/D  &  D/A 
By  Joseph  J.  Carr 

Published  by  TAB 

$8.95,  350  pages 

Reviewed  by  Richard  L.  Lozes 

“We  hope  that  most  copies  sold 
will  become  shop  tools  in  laboratories 
and  other  facilities  -  a  well-worn  shop 


48 

268 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


tool.”  Indeed  they  will!  Mr.  Carr  has 
penned  an  excellent  book.  It  is  thorough, 
well -organized,  and  carefully  edited. 

Although  interfacing,  the  titular  top¬ 
ic,  is  not  mentioned  explicitly  until  page 
270,  the  first  269  pages  are  indeed  essen¬ 
tial.  After  reading  them,  one  knows  not 
only  how  A/D  and  D/A  converters  work, 
but  also  how  to  select  devices  for  an  ap¬ 
plication,  and  how  to  avoid  pitfalls  in  de¬ 
signing  a  conversion  system. 

It  is  not  as  simple  as  picking  up  a 
chip  or  two  at  the  local  electronics  store 
and  wiring  it  onto  the  microcomputer 
bus.  To  design  a  workable  system  of  mod¬ 
est  expense,  one  needs  to  consider  such 
things  as  how  many  signals  will  be  mea¬ 
sured  (generated)  simultaneously,  how 
often,  how  accurately,  what  sort  of  buf¬ 
fering,  level  shifting  or  filtering  might  be 
required,  etc.  With  these  parameters 
established,  one  can  begin  to  apportion 
the  tasks  among  various  pieces  of  hard¬ 
ware  and  software,  and  then  specify  com¬ 
ponents.  For  example,  a  cheap  and  slow- 
running  conversion  system  could  utilize 
spare  CPU  cycles  to  do  much  of  the  con¬ 
version  work  (assuming  a  cheap  program¬ 
mer  were  available),  while  a  system 
operating  in  the  MHz  range  would  almost 
certainly  require  a  pipeline  of  high  speed 
hardware. 

This  book  is  well  rounded.  It  left  me 
with  an  appreciation  of  the  finer  details 
of  conversion  as  well  as  of  the  systems 
view.  I  was  particularly  pleased  by  the 
latter,  since  it  is  the  general  structure 
which  is  most  difficult  to  conceive  and 
which  determines  most  of  the  crucial 
parameters,  such  as  cost  and  reliability, 
in  any  design  endeavor.  (That  recogni¬ 
tion,  incidentally,  is  what  engendered 
“structured  design”  in  computer  soft¬ 
ware.)  It  is  also  rather  self-contained,  in¬ 
cluding  ancillary  material  such  as  a  chap¬ 
ter  on  analog  filters. 

The  author  has  wisely  chosen  to  in¬ 
clude  only  such  theory  as  necessary  for 
the  reader  to  parametrize  his  converter  by 
analogy  to  the  explicitly  solved  examples 
in  the  text.  It  helps  if  the  reader  knows 
Ohm’s  law,  the  formulas  for  series  and 
parallel  resistances,  and  similar  simple 
electrical  relations.  It  also  might  help  to 
be  able  to  recognize  the  simple  integral 
occurring  in  RC  circuit  behavior  theory. 
Other  required  background  is  minimal. 

With  this  book,  one  may  not  be  able 
to  design  cutting  edge  applications,  but 
the  vast  majority  of  A/D  and  D/A  conver¬ 
sions  will  be  within  one’s  reach.  ■  ■ 


You  Read 

Dr.  Dobb's  Journal 

And  You  Don’t 
Subscribe?! 


Save  $13 

off  newsstand  prices  for  2  yrs. 
Save  $5  for  1  yr. 


Can  you  afford  to  miss  an  issue  with 
information  vital  to  your  interests?  As  a 
subscriber  you  can  look  forward  to 
articles  on  Small-C,  FORTH,  CP/M,  S-100, 
Compiler  optimization,  Concurrent  Pro¬ 
gramming  and  more,  delivered  right  to 
your  door.  And  you’ll  never  miss  the 
issue  that  covers  your  project. 


DR.  DOBB’S  JOURNAL 
P.O.  Box  E 

Menlo  Park,  CA  94025 


Yes! 


Sign  me  up  for 
_  2  yrs.  $47 


1  yr.  $25 


_ I  enclose  a  check/money  order 

_ Charge  my  Visa,  MasterCard, 

American  Express 
_ Please  bill  me  later 

Name _ 

Address _ 


- Zip - 

Credit  Card  _ Exp.  date 

Account  No. _ 

Signature _ 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


49 

269 


Installing  a  Printer  Toggle 
in  North  Star  DOS  5. 2 


l.t  was  not  long  after  purchasing  CP/M 
1.44  a  few  years  ago.  I  discovered  one  of 
the  great  features  supplied  with  CP/M 
was  the  ability  to  toggle  the  printer  on  so 
that  I  could  print  out  simultaneously 
with  the  console  output.  This  was  done 
by  typing  control  P  (tP).  Another  very 
handy  feature  was  being  able  to  stop 
screen  paging  by  typing  control  S  ( t  S). 

So  at  that  time  I  implemented  in  the 
North  Star  DOS  5.0  the  control  P  for  the 
printer  toggle  and  space  bar  to  stop  pag¬ 
ing. 

Now  with  North  Star  DOS  5.2  avail¬ 
able  at  100  hex,  the  need  to  redo  the 
DOS  drivers  was  mandatory.  Since  I  did 
not  have  the  parity  option  on  my  North 
Star  dynamic  memory  boards,  I  decided 
to  use  that  space  in  the  DOS  drivers  to 
hold  the  necessary  changes  for  the  imple¬ 
mentation  of  control  P  for  the  printer 
toggle  and  space  bar  for  stopping  paging. 

To  do  this,  do  the  following: 

1.  Insert  the  copy  of  your  new  North 
Star  DOS  5.2  disk  and  boot  up. 

2.  Load  a  copy  of  DOS  at  4000H  by 
typing  +LF  DOS  4000  (CR). 

3.  Load  your  monitor  so  the  necessary 
changes  can  be  made  in  the  DOS  image 


by  Bert  Smart 


Bert  Smart,  639  Norvell  St.,  El  Cerrito, 
CA  94530. 


4. 


5. 

6. 


at  4000H.  Type  +GO  M0E00  (CR). 
The  monitor  will  respond  with  a  > 
prompt. 

Type  >DOS  4859  (CR).  The  monitor 
will  respond  with  the  hex  address  and 
the  existing  byte.  Change  the  next 
four  bytes  to  be  as  follows:  C3  01  0A 
C9  (CR). 

Type  >DS  48E7  (CR).  Change  the 
next  four  bytes  to  be:  C3  15  0A  C9 
(CR). 

Type  >DS  48FC  (CR).  Change  the 
next  four  bytes  to  be:  C3  29  0A  C9 
(CR). _ 

? 

+LF  DOS  4000 
+GO  M0E00 
MONITOR  5.2 
>DH  4859,4 
4859  C3  01  0AC9 
>DH  48E7.4 
48E7  C3  15  0AC9 
>DH  48FC.4 
48  FC  C3  29  0A  C9 

>DH  4800,34 


4800 

C9  DB  02  E6 

7F  FE 

10  CA 

4810 

34  0A  C3  4E 

0A  78 

D3  02 

4820 

78  C9  3E  01 

CD  DA  0A  78 

4830 

0A  C9  00  00 

>OS 

+SF  DOS  4000 


7.  Type  >DS  4800  (CR).  Change  the 
next  thirty-four  bytes  to  be:  C9  DB 
02  E6  7F  FE  10  CA  0B  0A  C9  3A  34 
0A  2F  32  34  0A  C3  4E  0A  78  D3  02 
3A  34  0A  FE  FF  CA  22  0A  78  C9  3E 
01  CD  DA  0A  78  C9  FE  03  37  FE  20 
CAF9  0AC9  00  00  (CR). 

8.  Now  exit  the  monitor  by  typing:  >  OS 
(CR). 

9.  Now  save  the  changed  DOS  to  your 
disk  by  typing:  +SF  DOS  4000  (CR). 

The  above  changes  have  done  the  fol¬ 
lowing:  changed  the  code  at  0A59  to  a 
jump  to  0A10,  at  0AE7  to  a  jump  to 
0A15  and  at  0AFC  to  a  jump  to  0A29. 
The  code  previously  resident  at  the  fore¬ 
going  addresses  was  relocated  to  the  ad¬ 
dress  OAOO  along  with  the  new  code  for 
the  control  P  printer  toggle  and  the  code 
for  the  space  bar  to  stop  the  paging.  If 
you  have  very  carefully  followed  the 
above  changes  and  your  system  is  config¬ 
ured  in  the  standard  North  Star  DOS,  it 
will  work  just  fine.  As  always,  a  word  of 
caution:  be  sure  that  you  are  working  on 
a  copy  of  the  original  and  not  on  the  only 
master  you  have.  ■  m 


0B  0A  C9  3A 
3A  34  0A  FE 
C9  FE  03  37 


34  0A  2F  32 
FF  CA  22  0A 
FE  20  CA  F9 


+ 


? 


+ 


H8  Text  Editor 

(Continued  from  page  18) 


Also,  I  have  noticed  two  minor  bugs: 

1.  The  input  data  buffer,  DATABUF,  is 
too  short.  It  probably  should  be  about 
1000  bytes  long,  instead  of  128.  How¬ 
ever,  being  at  the  end  of  the  program, 
it  is  not  likely  to  make  any  difference. 

2.  After  the  BADTAPE  label,  the  follow¬ 
ing  instructions  should  be  inserted,  to 
turn  off  the  tape  in  the  event  of  a  tape 
sequence  error: 

XRA  A 

OUT  OPTPC  ;TURN  OFF  TAPE. 

After  you  have  converted  your  files, 
don’t  forget  they  may  need  some  modifi¬ 
cation  with  the  CP/M  text  editor.  In  par¬ 
ticular,  there  are  some  minor  differences 
between  the  format  used  by  the  Heath 
assembler  and  that  used  by  the  CP/M  as¬ 


sembler.  Also,  the  converted  file  may 
take  up  slightly  more  space  than  neces¬ 
sary,  because  it  will  take  advantage  of 
neither  Heath’s  space  compression  nor 
CP/M’s  convention  of  storing  uncon¬ 
verted  Tab  characters  (control  I)  on  disk. 
■  ■ 

(LISTING  ON  PAGE  40) 


Why  wait 
to  start 

increasing  your  sales? 
Call  now 
to  reserve 
advertising  space 
in  the  next 
Dr.  Dobb ’s  Journal 
(415)323-3111 


50 

270 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


Dr.  Dobbs  Clinic 


by  D.  E.  Cortesi,  Resident  Intern 


T 

X.  his  is  the  second  appearance  of  Dr. 
Dobb 's  Clinic ,  which  is  a  place  for  the  dis¬ 
play  of  techniques,  discoveries,  and  pit- 
falls.  We  want  to  cover  any  sort  of 
method  or  trick  you’ve  found  in  your  ex¬ 
ploration  of  any  sort  of  personal  com¬ 
puter  software.  The  Clinic  is  the  place  to 
expose  errors  in  published  documenta¬ 
tion,  to  warn  others  away  from  pitfalls, 
and  above  all  to  show  off  those  eureka! 
moments  that  make  systems  work  so  re¬ 
warding. 

The  first  Clinic  used  up  all  the  mater¬ 
ial  we  had  on  hand.  We  scrambled  to  find 
some  more  for  this  one  (and  it’s  pretty 
thin,  too).  The  Clinic  needs  material,  or 
it  will  have  to  be  dropped.  Where  will 
that  material  come  from?  From  you,  the 
readers,  or  not  at  all.  The  requirements 
are  very  simple,  much  easier  than  those 
for  an  article. 

Write  to  us.  Describe  your  discovery 
or  technique  in  a  couple  of  pages,  in  any 
format  you  like  so  long  as  we  can  read  it. 
Don’t  worry  about  being  “literary.” 
Don’t  bother  with  a  tutorial  introduction 
for  the  novice  reader;  this  isn’t  a  column 
for  novices.  Do  include  a  daytime  phone 
number  so  that  if  we  have  questions  we 
can  call  you. 

Special  note  to  OEMs:  if  you  have 
any  interesting  application  notes  or  user 
tips  that  you  feel  deserve  wider  circula¬ 
tion,  send  them  to  the  Clinic.  If  they’re 
of  general  interest,  we  can  use  them. 

A  Small  Discovery 

We  were  working  on  a  game  program, 
using  Microsoft  Disk  BASIC  5.0  on  a 
CP/M  system.  In  this  game,  as  in  many 
others,  the  program  needed  to  spin  along 
updating  a  simulation,  while  simultane¬ 
ously  watching  the  keyboard.  As  soon  as 
the  player  pressed  a  key  the  program  was 
to  respond,  then  go  back  to  its  work. 

The  INKEYS  function  was  designed 
to  solve  just  such  problems.  It  shows  up 
at  the  heart  of  most  games  for  the  TRS- 
80  and  PET.  But  we  weren’t  sure  -  did 
this  big,  business-like  BASIC  for  CP/M 
have  INKEYS?  After  all,  the  interface  to 
the  keyboard  of  a  CP/M  terminal  isn’t 
anything  like  that  of  the  smaller  ma¬ 
chines.  A  quick  search  of  the  Microsoft 
manual  confirmed  our  suspicions: 
INKEYS  isn’t  listed,  and  therefore 
doesn’t  exist. 

Hours  of  labor  went  into  proving 
that  this  particular  game  could  not  be 


52 


made  playable  without  something  like 
INKEYS.  At  last,  in  a  fit  of  flakey  frus¬ 
tration,  we  coded  it  anyway  and  typed 
“RUN”.  And  it  ran!  Disk  BASIC  5.0  for 
CP/M  does  indeed  have  a  perfectly  good, 
working,  INKEYS  function.  It  just  didn’t 
make  it  into  the  manual,  that’s  all. 

The  Lost  Chord 

It  is  often  useful  to  know  when  a 
binary  integer  contains  only  a  single 
1-bit;  that  is,  when  it  represents  an  inte¬ 
ger  power  of  2.  Suppose  you  were  work¬ 
ing  on  a  binary  division  or  multiplication 
routine.  If  you  knew  in  advance  that  the 
multiplier  or  divisor  had  only  a  single  1  - 
bit,  you  could  perform  the  operation  en¬ 
tirely  with  shifts  and  gain  a  lot  of  speed. 
Of  course,  the  test  for  a  power  of  two 
would  have  to  be  very  short,  or  you 
couldn’t  afford  to  test  every  divisor  or 
multiplier. 

Some  years  ago,  we  saw  the  code  for 
just  such  a  test.  It  did  not  loop;  it  was  a 
short  piece  of  straight-line  assembly  code 
(the  machine  was  an  IBM  370,  but  that 
shouldn’t  make  any  difference).  It  used 
an  exclusive- or,  or  perhaps  more  than 
one.  We  recall  thinking  at  the  time  “Gee, 
that’s  clever;  have  to  remember  that 
one.”  Recently  we  needed  it  and  of 
course  can’t  remember  it  any  more. 

Can  a  reader  re-invent  that  clever 
test?  The  code  should  accept  a  16- bit 
integer  and  return  a  suitable  signal  (may¬ 
be  a  flag  setting)  when  the  integer  con¬ 
tains  exactly  15  0-bits  and  a  single  1-bit. 
Express  the  solution  in  any  common  as¬ 
sembly  language.  We’ll  find  some  suitable 
prize  for  the  best  one(s). 

Decimated 

It’s  long  bothered  this  writer  that, 
while  it  is  very  easy  to  multiply  a  binary 
number  by  10,  it  is  very  difficult  to 
divide  one  by  10.  The  multiplication 
algorithm,  as  most  every  programmer 
knows,  is  based  on  the  relationship 
between  multiplication  and  addition. 
That  is, 

N  *  10 

can  be  factored  out  to 

N+N+N+N+N+N+N+N+N+N 
and  that  in  turn  factors  to 

2  *  (  (  4  *  N  )  +  N  ) 

In  binary,  once  you  have  all  the  factors 
down  to  integer  powers  of  two,  you  have 
the  problem  licked.  The  last  expression 
becomes  (using  the  C  notation  for  a  left 
shift) 


(  (  N  «  2  )  +  N  )  «  1 
and  Bob’s  your  uncle.  If  the  universe  had 
one  jot  of  fairness,  division  by  10  would 
be  as  simple.  Something  using  right  shifts 
and  subtracts  would  do  nicely.  The  uni¬ 
verse  persists  in  paying  no  attention  to 
the  needs  of  programmers;  division  by  10 
seems  to  require  the  use  of  a  complete, 
tedious  binary  division  routine. 

The  problem  is,  programs  convert 
decimal  digits  to  binary  only  once  in  a 
while,  and  almost  never  in  a  central  pro¬ 
cessing  loop  where  time  counts.  They 
convert  from  binary  to  decimal  for  out¬ 
put  much  more  frequently,  and  division 
by  10  is  the  central  feature  of  binary-to- 
decimal  conversion. 

It  is  possible  to  write  a  divide-by-10 
routine  that  is  faster  than  the  usual  16- 
bit  divide  function.  Such  a  routine  can 
take  advantage  of  its  knowledge  that  10 
is  the  only  divisor.  Rather  than  a  full 
16-into-16  or  8-into-16  division  it  can 
divide  the  16-bit  dividend  by  a  5 -bit  divi¬ 
sor.  This  allows  it  to  get  away  with  only 
12  iterations  rather  than  16,  and  to  use 
byte  rather  than  word  arithmetic.  Listing 
1  shows  such  a  routine.  It  requires  just 
over  1000  clock  periods  on  an  8080.  The 
16-into-32  bit  routine  in  [1]  uses  over 
1500  Z80  clock  periods;  the  16-into-16 
bit  routine  in  [2]  takes  2300  clocks. 

Listing  2  shows  a  binary  to  decimal 
conversion  routine  that  calls  the  routine 
in  Listing  1 . 

Still,  there  ought  to  be  something  bet¬ 
ter.  Numerical  analysis  is  called  for  here. 
It  is  possible  to  represent  a  binary  num¬ 
ber  in  a  generalized  way  as  a  polynomial. 
For  instance,  this: 

f(X)  ::  aX7  +  bX6  +. .  ,+  fX2  +  gX  +  h 
stands  for  any  8 -bit  number  (given  that 
X=2).  The  coefficients  a,  b,  . . .,  h  are 
either  1  or  0;  evaluate  f(X)  to  get  the 
value  of  the  number.  It  takes  a  certain 
shift  of  vision  to  see  it,  but  in  fact  a  byte 
in  your  computer  doesn’t  contain  bits,  it 
contains  one  set  of  eight  coefficients  for 
that  expression. 

When  the  coefficients  are  known,  all 
the  zero  terms  can  be  dropped  out.  Ten 
is  1010  binary,  so  the  polynomial  for  ten 
is  just 

t(X)  ::  X3  +  X 

and  binary  division  by  ten  can  be  stated 
in  general  terms  as  f(X)/t(X).  That  divi¬ 
sion  can  be  carried  out  in  symbolic  form 
by  anyone  masochistic  enough  to  do  so. 
The  result  for  the  symbolic  quotient  is: 

q(X)  : :  aX4  +  bX3  +  (c-a)X2  + 
(d-b)X  +  (e-c+a) 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

271 


and  the  symbolic  remainder  is: 

r(X)  ::  (f-d+b)X2  +  (g-e+c-a)X  +  h 
Frankly,  it  doesn’t  give  much  help.  The 
expressions  are  true  enough.  Check  them 
yourself.  Pick  a  binary  number  and  sub¬ 
stitute  its  bits  7  ...  0  for  the  letters  a  . . . 


h  respectively.  Substitute  2  for  X  and 
evaluate;  you’ll  find  that  q(X)  is  the  quo¬ 
tient  of  division  by  10  and  r(X)  the  re¬ 
mainder.  But  it  doesn’t  suggest  any 
clever,  non-looping  algorithm  —  or  is  that 
just  a  failure  of  imagination? 


Perhaps  a  reader  can  find  a  better 
analysis  of  the  problem  than  we  can, 
perhaps  one  knows  a  better  cut-and- 
algorithm  than  the  one  in  Listing  1 .  If 
share  it  with  us,  please!  ■  ■ 


Listing  1  —  Fast  Divide-by 

-10  routine. 

fast  — 

divide  -  by  - 

ten  routine 

A  version  of  the  standard  1 6  by  8  bit  divide  which 

performs  a  division  by  ten,  most  useful  in  converting 

binary  to  decimal  (or  BCD).  Takes  advantage  of  the 

fact  that  10  is  a  four- bit  value,  effectively  divides 

a  5-bit  signed  value  10  into  a  16-bit  signed  number. 

Handles  case  of  8000h  as  32768  —  not  strictly  true, 

but  that  ambiguous  value  has  to  be  handled  somehow. 

Input:  HL  = 

number  to  be  divided  —  must  be  in 

range  of  0  . . 

32768  (0000  to  80000). 

Output:  HL  = 

quotient  (input/ 1 0) 

A  = 

remainder  (input  mode  10) 

BC  and  DE  preserved;  flags  unpredictable. 

FASTDIV10: 

PUSH 

D 

save  2  work  registers 

PUSH 

B 

MVI 

E,0 

clear  start  of  quotient 

MVI 

C,12 

iteration  count 

MVI 

B,50H 

5 -bit  divisor  ( 1 0  shl  3) 

FASTDIV1 : 

MOV 

A,H 

see  if  high  5  bits  of 

SUB 

B 

.  .dividend  exceed  10. 

JC 

FASTDIV2 

MOV 

H,A 

they  did,  update  dividend 

INX 

D 

.  .and  insert  1- bit  in  quotient. 

FASTDIV2: 

DCR 

C 

are  we  done? 

JZ 

FASTDIV3 

XCHG 

no,  shift  quotient  left  1 

DAD 

H 

XCHG 

DAD 

H 

.  .and  shift  the  dividend. 

JMP 

FASTDIV1 

FASTDIV3: 

MOV 

A,H 

remainder  is  in  high  5  bits 

RRC 

of  the  old  dividend  - 

RRC 

.  .right-justify  it  in 

RRC 

.  .the  a-reg. 

XCHG 

restore  quotient  to  HL, 

POP 

B 

.  .all  set  for  next  call. 

POP 

D 

RET 

References:  [1]  Barden,  William  Jr.,  The  Z-80  Microcomputer 
Handbook,  Howard  W.  Sams  Inc.,  1979. 

(21  8080/8085  Assembly  Language  Programming,  Intel 
Corporation  manual  number  9800949,  1979. 


Listing  2:  Binary -to -decimal  conversion  routine. 

binary  to  decimal- character  routine: 

Stores  the  decimal  representation  of  number  in  HL 
in  the  six  bytes  at  ( DE+] .  The  output  field  should 
have  been  blanked  first,  for  only  as  many  bytes  are 

written  as  are  necessary. 

FastdivlO  produces  the  digits  in  reverse  order,  most 
significant  last.  Call  it  until  HL  has  been  reduced 

to  zero,  stacking  digits  and  counting  them.  Then  pop 
and  store  them,  thus  getting  them  high-  to  low-order. 

Input  = 

HL:  the  number  to  be  converted 

DE  ->  the  first  byte  of  the  field 

Output  = 

DE  advanced  to  byte  following  last 
digit.  Field  has  blank/minus,  digits. 

A,  flags  unpredictable.  HL,  BC  preserved. 

CVTDECIMAL 

PUSH 

H 

;  save  working  registers 

PUSH 

B 

MOV 

A,H 

;  check  sign 

ORA 

A 

MVI 

A, BLANK 

; .  .assume  it’s  positive 

JP 

CVTDEC2 

;  (it  is) 

MOV 

A,L  !  CMA  ! 

MOV  L,A  ;  it  isn’t. . 

MOV 

A,H  !  CMA  ! 

MOV  H,A 

INX 

H 

; .  .form  two’s-complement 

MVI 

A.MINUS 

;  set  up  negative  sign 

CVTDEC2: 

STAX 

D 

;  store  the  sign  character 

INX 

D 

MVI 

C,0 

;  C  will  count  digits  pushed 

CVTDEC3 : 

CALL 

FASTDIV10 

;  A  < —  low -order  digit 

PUSH 

PSW 

; .  .save  it  on  stack 

INR 

C 

; .  .and  count  it. 

MOV 

A,L 

ORA 

H 

;  quotient  reduced  to  zero? 

JNZ 

CVTDEC3 

; .  .no,  repeat. 

CVTDEC4:  ; 

there  are  now  [C]  digits  on  the  stack. 

POP 

PSW 

ORI 

‘0’ 

;  get  digit,  make  printable 

STAX 

D 

;  store  it  down 

INX 

D 

DCR 

C 

;  count  it  off 

JNZ 

CVTDEC4 

;  repeat  1  to  5  times. 

POP 

B 

POP 

H 

RET 

54 

272 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


Of  Interest 


by  Dave  Cortesi 


r> 

Ue  glad  you  don’t  know  the  hordes 
of  vendors  that  are  clamoring  for  your  at¬ 
tention.  Nearly  a  bushel  of  press  releases 
was  winnowed  to  arrive  at  this  month’s 
selection.  A  number  of  good  items  went 
to  the  round  file  because  they  brought 
time- dependent  information  too  late. 
DDJ  has  one  of  the  shortest  publishing 
cycles  in  the  field,  but  even  we  can’t 
help  the  publicist  for  a  May  event  who 
mails  his  releases  in  March.  Three  months 
is  the  minimum  lead-time  for  any  an¬ 
nouncement;  four  is  better. 

One  Fantastic  Weekend 

One  event  that  got  its  material  out  in 
good  time  is  PACIFICON,  the  Seventh 
Annual  Wargaming  Convention.  It  will  be 
held  in  San  Mateo,  California  on  July  3- 
5.  “Fantasy  and  science  fiction  games, 
tournaments  and  demonstrations  will  oc¬ 
cur  around  the  clock,”  we  are  told.  Not 
strictly  a  computer  event,  but  how  could 
any  Adventure  player  resist? 

The  Spring  Lists 

The  major  publishers  are  out  with 
their  spring  lists,  and  several  titles  are 
worth  noting.  We  won’t  list  “contact 
points”  for  publishers;  look  for  these 
books  at  your  usual  bookstore. 

Addison-Wesley  has  released  the  sec¬ 
ond  edition  of  Donald  Knuth’s  Seminu- 
merical  Algorithms,  Volume  2  of  that 
author’s  Art  of  Computer  Programming. 
Any  reader  of  this  magazine  should  be 
familiar  with  that  excellent  series,  distin¬ 
guished  among  textbooks  by  the  author’s 
wit,  erudition,  and  graceful  prose.  This 
new  edition  is  the  first  book  prepared 
with  Knuth’s  TEX  and  METAFONT  pro¬ 
grams,  described  in  this  magazine  a  few 
issues  back. 

McGraw-Hill  has  Digital  Harmony  by 
John  Whitney.  Whitney,  it  seems,  is  work¬ 
ing  toward  the  synthesis  of  computer 
graphics  and  computer  sound  into  a  single 
new  medium  of  artistic  expression.  The 
book  is  said  to  describe  his  computer, 
peripherals,  and  film  techniques,”  and  to 
contain  many  color  plates;  the  price  is 
$21.95. 

The  same  publisher  has  what  sounds 
like  a  gem:  The  Devil’s  DP  Dictionary  by 
Stan  Kelly- Bootle,  “a  spoof  dictionary 
modeled  on  Ambrose  Bierce’s  classic, 
The  Devil’s  Dictionary."  It  defines  com¬ 
puter  science  as  “a  study  akin  to  numero¬ 
logy  and  astrology,  lacking  the  precision 


of  the  former  and  the  success  of  the 
latter,”  and  a  random  file  as  “one  in 
which  records  may  be  lost  in  any  order.” 
160  pages  of  this  costs  $7.95 ;  buy  a  copy 
before  anyone  else  and  build  your  repu¬ 
tation  as  a  wit. 

Osborne  McGraw-Hill  has  released 
the  Apple  II  User’s  Guide  by  Poole, 
McNiff,  and  Cook  ($15),  and  claim  it  is 
“the  definitive  guide  to  the  Apple  II  and 
Apple  II  Plus  computers.”  That  word 
“definitive”  is  hard  to  swallow,  but  the 
list  of  topics  sounds  comprehensive. 
Osborne  has  also  brought  out  6809 
Assembly  Language  Programming  by 
Leventhal  ($17),  a  timely  addition  to 
their  series  of  such  books.  Now,  when  can 
we  have  one  for  the  8086? 

A  Mainframe  Item 

In  the  world  of  gigabytes  and  mega¬ 
flops,  there  are  several  publishers  who  sell 
large  libraries  of  FORTRAN  subroutines. 
IMSL,  Inc.  is  one  such.  They  wrote  to 
tell  us  that  they’ve  released  Edition  8 
of  their  library,  with  over  500  math  and 
statistical  subroutines,  well-tested  and 
predictably  accurate.  They’re  proud  of 
the  fact  that  they  have  1 100  installations. 
We  wonder  if  they  can  conceive  of  the 
size  of  market  that  awaits  a  personal- 
computer  edition  of  such  a  library. 

A  FORTRAN  Daisy-Driver 

Escape,  Ltd.  has  prepared  a  library 
of  plotting  subroutines  in  FORTRAN. 
This  library  is  designed  for  personal  ma¬ 
chines,  having  been  prepared  under 
Microsoft  FORTRAN  and  then  tested  on 
a  larger  machine  to  verify  ANSI  compati¬ 
bility.  The  subroutines  are  designed  to 
make  it  easy  to  build  line  and  bar  graphs 
from  a  FORTRAN  program,  merge  the 
graphs  with  text,  and  output  the  whole 
on  a  Diablo/Xerox  daisy  printer.  The 
package,  including  source  code,  costs 
$600. 

A  FORTH  for  OSI 

The  spread  of  FORTH  is  beginning 
to  remind  us  of  the  inexorable  growth  of 
some  jungle  vine.  An  outfit  called 
FORTH  Tools  has  prepared  a  fig-FORTH 
implementation  for  the  OSI  Cl,  C2,  and 
C4  systems  with  5”  disks.  The  system 
runs  stand-alone,  but  uses  the  OS-65D 
disk  format.  They  claim  strict  compati¬ 
bility  with  the  FORTH  Interest  Group 
model  of  the  language,  including  disk 
words.  A  6502  macro  assembler  is  part  of 


the  $50  package. 

Bisynch  for  Oasis 

Phase  One  has  prepared  a  Bisynch 
communications  line  driver  for  their  Oasis 
operating  system.  The  package  is  said  to 
provide  exact  emulation  of  the  IBM 
2780/3780  terminals,  and  costs  $450. 
Phase  One  didn’t  note  it,  but  we  will:  this 
opens  the  way  to  inserting  an  Oasis- 
controlled  system  into  an  IBM-based  Re¬ 
mote  Job  Entry  network.  IBM’s  RJE  net¬ 
working  protocols  allow  job  sharing  and 
load  balancing  to  be  done  across  many 
CPUs.  Sticking  in  a  micro  opens  a  lot  of 
interesting  possibilities  for  synergism  be¬ 
tween  the  small  and  large  machines.  Go 
for  it,  Phase  One:  build  a  SNA  driver. 

Two  for  the  North  Star 

What  is  it  about  North  Star  BASIC 
that  makes  people  want  to  compile  it? 
DATEK  is  the  latest  company  to  an¬ 
nounce  a  compiler  for  that  dialect.  Theirs 
compiles  to  relocatable  modules  of  8080 
code.  Assembler  statements  may  be  in¬ 
serted  in  the  BASIC  source  as  REM  state¬ 
ments.  An  assembler  is  included,  from 
which  we  deduce  that  the  compiler  pro¬ 
duces  assembler  source  rather  than  gene¬ 
rating  the  object  code  directly.  The 
package  required  double  or  quad  density 
disks,  supports  DOS  5.2DQ,  and  costs 
$400. 

The  same  company  has  what  they  be¬ 
lieve  to  be  a  superlative  word  processing 
system  for  the  North  Star.  It  includes 
full-screen  editing  capability  for  many 
terminals,  and  support  for  Diablo  and 
NEC  daisies.  No  mention  here  of  propor¬ 
tional  spacing,  but  most  useful  formatting 
options  are  available  in  the  $495  price. 

Bargains  for  CP/M 

The  Software  Toolworks  has  several 
CP/M  programs  for  sale  at  very  attractive 
prices.  They  offer  C/80,  a  compiler  for  a 
subset  of  the  C  programming  language, 
an  implementation  of  LISP  called  LISP/ 
80,  and  a  RATFOR  preprocessor  whose 
output  is  acceptable  to  Microsoft  FOR¬ 
TRAN.  These  and  other  programs  are 
“priced  in  the  $20- $40  range.”  Right 
on. 

Those  who  make  extensive  use  of 
MAC  and  RMAC  might  like  a  product 
from  Spun  Software.  RLIST  is  a  listing 
formatter  that  converts  the  .PRN  and 
.SYM  files  written  by  those  assemblers 
into  a  more  handsome  .LST  file.  The  out- 


56 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 

273 


put  includes  a  true  cross-reference;  print¬ 
ing  can  be  suppressed  for  portions  of  the 
file  such  as  unproductive  sequences  of 
macro  statements.  The  price  is  $35. 

Elliam  Associates  have  a  text  retriev¬ 
al  system  they  call  Information  Master, 
and  sell  it  at  the  reasonable  price  of 
$37.50.  They  have  a  pre-indexed  file  of 
magazine  articles  to  go  under  it  for  $10, 
and  have  now  added  a  file  indexing  all  the 
programs  available  on  the  CP/M  Users 
Group  diskettes  for  $15  ($20  separately). 

TRS-80  Secure  from  Prying  Eyes, 

The  Locker  is  a  software  extension 
to  TRSDOS  2.0  that  makes  the  LIST  and 
LLIST  commands  ineffective.  The  objec¬ 
tive  is  to  make  your  proprietary  BASIC 
programs  runable  but  un-viewable. 
Management  sell  it  for  $25,  and  claim 
that  it  goes  in  simply  and  is  trouble-free. 

.  .  .  Gets  Analog  Input, 

Connecticut  microcomputer,  who 
make  a  line  of  analog  input  devices  for 
small  machines,  have  added  the  TRS-80 
to  the  list  of  machines  they  serve.  They 
have  a  unit  that  connects  their  analog  de¬ 
vices  to  the  TRS-80’s  expansion  or  print¬ 
er  port  for  $60.  Into  it  they  want  you  to 
plug  their  16-channel  analog  input  mod¬ 
ule,  or  their  driver  for  the  BSR  X-10 
home  controller. 

. . .  Goes  on  the  Air 

A  ham  possessed  of  a  TRS-80  can 
put  the  machine  on  the  air  as  an  auto¬ 
mated  mailbox  with  the  M8300  RTTY 
software  package  from  Macrotronics.  The 
System  stores  and  forwards  messages  and 
can  be  used  with  a  ham  repeater.  Mes¬ 
sages  sent  or  received  can  be  accessed 
from  disk  with  any  of  the  common  text 
editors.  I/O  can  go  via  the  same  com¬ 
pany’s  ham  interface  hardware  or  through 
the  machine’s  RS232  board  and  a 
modem. 

. .  .  With  Either  of  Two  Modems 

Speaking  of  modems,  we’ve  had  an¬ 
nouncements  of  two  new  ones.  Hayes 
have  announced  what  they  call  the  Smart- 
modem,  a  direct  connect  modem  that  is 
controlled  by  commands  expressed  as 
strings  of  ASCII  characters  so  that  it  may 
be  driven  easily  from  a  program  in  a  high- 
level  language.  It  responds  to  the  com¬ 
mands  with  result  codes  that  may  be 
either  decimal  numbers  or  English  words. 
The  Smartmodem  has  both  auto-answer 


The  Hayss  "Smartmodem" 


and  auto-dial  features,  and  can  dial  with 
either  pulses  or  tones,  at  program  com¬ 
mand.  The  $280  price  includes  a  power 
pack  and  a  telephone  cable. 

The  Microperipheral  Corp.  wants  you 
to  know  about  its  Microconnection  de¬ 
vices,  direct  connect  modems  for  the 
Atari  400  and  800  and  for  all  TRS-80 
models.  All  units  have  provision  for  con¬ 
necting  a  cassette  recorder  to  the  modem 
for  recording  the  on-line  conversation. 
The  Atari  version  does  not  require  the  use 
of  Atari’s  RS232  peripheral  unit,  and 
does  contain  a  serial  printer  interface  al¬ 

WINTEK’s  single-board  computer. 


lowing  hardcopy  of  the  communication. 
The  TRS-80  units  cost  $200;  that  for  the 
Atari  is  priced  at  $250.  An  auto-dial, 
auto-answer  option  is  $80. 

Boards  for  the  SS-50  Bus 

Two  companies  have  popped  out 
with  new  hardware  for  systems  built 
around  the  68xx  CPUs  and  the  SS-50 
bus.  Gimix,  who’ve  been  at  it  for  a  while, 
are  offering  a  choice  of  three  different 
disk  controller  boards.  Their  fanciest  one 
uses  DMA  for  data  transfers  and  supports 
any  mix  of  drive  diameters  and  densities. 
It’s  priced  at  $550;  less  competent  boards 
are  available  at  $350  and  $230  for  vari¬ 
ous  hardware  configurations.  Gimix  sup¬ 
plies  its  version  of  FLEX  for  the  6809 
with  each. 

Percom  have  prepared  a  two-channel 
serial  I/O  card  for  SS-50  machines.  They 
claim  it  will  work  with  all  versions  of  the 
SS-30  (I/O  portion  of  the  SS-50)  bus. 
The  card  can  have  its  own  bit  rate  genera¬ 
tor,  which  would  apparently  otherwise 
require  a  card  of  its  own.  No  price  was 
given  in  Percom’s  release.  ■  ■ 


58 

274 


Dr.  Dobb’s  Journal,  Number  56,  June  1981 


D[\  Tf  ($3.00  in  Canada 

R.  UOBB'S  IOURNAL 

For  Users  of  Small  Computer  Systems  W 

Number  57  July  1981  Volume  6,  Issue  7 


Pidgin  —  A  Systems  Programming  Language 

William  A.  Gale 


Time  on  the  Horizon 

D.  J.  Yates 

BASIC  Rubik’s  —  A  Cube  Simulator 

J.  W.  Pehoushek 


For  Rubikubists 
an  Ally  in  BASIC 

Moving  Toward 

Hardware 

Independence 


The  Doctor’s 

Problems 

Minimized! 


....and  much  more! 


Dr.  Dobbs  Journal 

For  Users  of  Small  Computer  Systems  m 


July  1981  Volume  6,  Issue  7,  Number  57 


Contents 

Articles 

Publisher 

Art  Director 

Marketing  Director 

Pidgin  —  A  Systems  Programming  Language  . . 

.  10 

Michael  Madaj 

Clifford  West 

Craig  S.  Harper 

by  William  A.  Gale 

Editor 

Artist 

Advertising  Sales 

Time  on  the  Horizon . 

.  15 

Marlin  Ouverson 

Barbara  Ruzgerian 

Kent  Safford 

by  D.  J.  Yates 

Assistant  Editor 

Typesetter 

Circulation  Manager 

BASIC  Rubik’s  -  A  Cube  Simulator . 

.  19 

Julie  Anton 

Michelle  Moonstone 

Peter  Clark 

by  J.  W.  Pehoushek 

Contributing  Editors  Proofreader 

Circulation  Assistant 

Dave  Caulkins 

Nancy  Heubach 

Leah  Dansby 

Departments 

Dave  Cortesi 

Business  Manager 

Maureen  Christine 

Letters . 

.  4 

Of  Interest . 

.  38 

Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per 
year  by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real, 

Clinic . 

.  40 

Menlo  Park,  CA 

94025.  Second  class  postage  paid  at  Menlo  Park, 

Book  Reviews . 

.  43 

California  9402  5 

and  additional  entry  points.  Address  correction 

requested.  Postmaster:  send  form  3579  to 

Box  E,  Menlo  Park, 

California  9402  5. 

©  1981  by  People’s  Computer  Company  unless  otherwise  noted  on 

1  specific  articles.  All  rights  reserved. 

Editorial 


First  things  first.  Our  cover  has  changed  in  order  to 
reflect  a  new  approach  to  the  magazine  publishing  business. 
We  are  not  selling  out  to  the  highest  bidder;  DDJ  has  always 
been  at  the  cutting  edge  and  is  staying  that  way.  Doc  won’t 
settle  for  less! 

The  real  change  has  been  in  the  computer  hobbyist 
market.  No  longer  a  group  of  bleary-eyed  hackers,  we  have 
acquired  importance  by  filling  people’s  needs.  Those  needs 
have  grown  along  with  the  numbers  of  small  computers  and 
their  owners,  who  need  to  know  where  they  can  get  an¬ 
swers  and  inspiration.  We  hope  more  folks  will  pick  up  this 
journal,  learn  from  it  and  contribute  to  it.  Ours  is  an  impor¬ 
tant  work  and  if  we  can  further  it  by  cleaning  house  a  bit, 
then  ’tis  done. 

DDT s  new  cover  answers  one  more  need.  We  got  plain 
tired  of  answering  mail  from  orthodontists  and  dentists 
who  were  inquiring  about  application  software  for  members 
of  their  profession!  Doc,  as  you  know,  is  very  much  a  gen¬ 
eral  practitioner  when  it  comes  to  computers. 

Next  point:  while  every  other  magazine  has  been  talk¬ 
ing  about  ways  to  produce  a  customized  publication  for 
subscribers,  Dr.  Dobb’s  has  been  just  that  since  the  begin¬ 
ning.  All  articles,  reviews,  essays  and  programs  are  re¬ 
searched  and  written  by  readers,  not  by  professional  journa¬ 
lists.  The  contents  are  determined  by  what  our  readers  ex¬ 


press  to  us.  The  rapid  turn-around  time  from  our  receipt  of 
an  article  to  its  publication  is  so  short  (sometimes  a  matter 
of  weeks)  that  it  can  be  dizzying.  But  it  enables  us  to  be 
very  responsive  to  our  subscribers. 

We  would  like  to  hear  from  some  more  potential  book 
reviewers.  If  you  would  like  to  help  Doc  and  get  your  liter¬ 
ary  feet  wet  at  the  same  time,  send  a  stamped,  self-ad¬ 
dressed  envelope  with  your  request  for  writer’s  guidelines. 
Don’t  be  shy  —  and  don’t  underestimate  the  importance  of 
good  book  reviewers.  In  a  field  with  so  many  new  titles 
coming  out  daily,  someone  needs  to  sort  through  and  eval¬ 
uate  each  for  accuracy,  relevance  and  significance.  Let  us 
know  your  background,  interests,  hardware  and  software 
experience.  We’ll  try  to  find  something  to  intrigue  you! 


'jfy— 


Marlin  Ouverson 
Editor 


276 


Letters 


Still  Alive  and  Well .  .  . 

Dear  Marlin, 

I  cannot  allow  Mr.  Bill  Bolton’s 
letter  to  DDJ  in  the  May  1 98 1  issue  to  go 
unanswered.  He  was  writing  in  response 
to  the  review  of  our  software  package, 
ZDM,  which  was  published  in  your  Feb¬ 
ruary  1981  issue.  Mr.  Bolton  seemed  to 
imply  that  a  Z-80  debugger  (ZDM)  is  use¬ 
less  unless  it  displays  Zilog  mnemonics 
and  states  that  “new  Z-80  software 
should  be  using  Zilog  mnemonics,  not 
mnemonic  sets  from  companies  long  out 
of  business”. 

First,  let  me  state  that  TDL  software 
is  far  from  “out  of  business”.  It  is  very 
much  alive  under  the  name  of  CDL  — 
Computer  Design  Laboratories.  Second, 
there  are  a  large  group  of  Z-80  users  out 
there  who  grew  up  on  the  Intel  8080  and 
still  prefer  an  extended  8080  set  to  the 
logical,  but  yet  often  confusing,  Zilog 
mnemonics. 

RD  SOFTWARE  recognizes  that  the 
marketplace  can  support  both  Zilog  and 
extended  8080  mnemonics.  Accordingly, 
since  December  1980,  we  have  been  of¬ 
fering  both  versions  on  a  single  disk  i.e., 
ZDM  (extended  8080,  and  ZDMZ  (100% 
Zilog). 

Obviously,  Mr.  Bolton  was  not  aware 
of  this  due  to  the  time  lag  from  software 
submittal  to  review  publication. 

The  point  is  that  there  is  still  a  mar¬ 
ket  for  Z-80  programs  employing  an  ex¬ 
tended  8080  mnemonic  set  as  well  as 
standard  Zilog. 

Very  truly  yours, 

R.  F.  Doolittle 
RD  SOFTWARE 
1290  Monument  Street 
Pacific  Palisades,  CA  90272 

Lingua  Franca 

Dear  Marlin: 

Dobb’s  ex  machina  vincit  omnia! 
With  a  hearty  hi-ho  Silver!  Etc.,  etc.  Re¬ 
ceived  today  one  complete  package  free- 
fer-nothin’  of  PET  service  kit.  I  enclose  a 
copy  of  Commodore’s  letter  and  my  t.u. 
letter.  Thank  you,  DDJ,  and  if  you  can 
get  IMSAI/Fischer-Freitas  to  get  off  the 
stack  as  well  .  .  .  what  can  I  say?  Many, 
many  thanks,  from  your .  . . 

Faithful  servant  and  friend  and 
fan,  etc., 

John  Thayer  Jensen 
P.  O.  Box  358  Yap 
Caroline  Islands  96943 


Small-C:  Bug-Fix  Bug 

Dear  DDJ: 

Bravo  for  your  recent  series  of  arti¬ 
cles  on  Small-C.  While  implementing  the 
formal  parameter  correction  suggested  by 
P.  L.  Woods  {DDJ  #52),  an  error  in  the 
bug  fix  was  discovered.  The  error  had  the 
effect  of  causing  incorrect  relative  stack 
offsets  to  be  calculated  if  the  declarations 
for  formal  parameters  were  done  with 
more  than  one  type  declaration  state¬ 
ment.  To  correct  this,  the  following 
changes  should  be  made  to  the  “NEW- 
FUNC”  and  “GETARG”  routines  that 
were  presented. 

Changes  to  “NEWFUNC”: 

Add  a  local  declaration  “INT 
ARGTOP;”. 

Add  the  statement  “ARGTOP= 
ARGSTK;”  between  the  “SP=0;” 
and  “WHILE  (ARGSTK)”  state¬ 
ments. 

Add  a  second  formal  parameter 
(“ARGTOP”),  to  all  calls  to 
“GETARG”.  Ie.  change  “GE¬ 
TARG  (CCHAR);”  to  “GETARG 
(CCHAR, ARGTOP) and  change 
“GETARG  (CINT)  to  “GE¬ 
TARG  (CINT, ARGTOP) 

Changes  to  “GETARG”: 

Change  the  function  header  from 
“GETARG(T)”  to  “GETARG 
(T,  ARGTOP)”. 

Add  the  formal  parameter  declar¬ 
ation  “INT  ARGTOP 
Delete  the  “ARGTOP= 

ARGSTK  statement. 

Additional  note,  a  descendent  of 
Small-C  called  Small  C  Plus  is  available 
from  Alpha  Omega  Computer  Systems, 
Inc.,  for  $55  on  8”  CP/M  compatible 
diskette.  This  version  adds  the  following 
features  to  Small-C: 

— argv/argc  command  line  parame¬ 
ter  parsing  (allows  compiles  to 
be  done  from  CP/M  submit 
files). 

—the  addition  of  “for”  and  “do- 
while”  loops. 

—the  “switch-case-default”  state¬ 
ment. 

—extensions  to  the  compiler  to  al¬ 
low  separate  compilation  of 
function  modules  in  conjunction 
with  Microsoft’s  M80  assembler. 

—numerous  bugs  have  been  fixed. 

CP/M  is  a  trademark  of  Digital  Re¬ 


search,  Inc. 

Yours  truly, 

Kirk  Bailey 

Alpha  Omega  Computer  Systems, 
Inc. 

P.  O.  Box  U 
Corvallis,  OR  97330 

Dear  Sirs, 

We  would  like  to  bring  to  your  at¬ 
tention  a  bug  in  the  code  submitted  by 
P.  L.  Woods  in  your  February  issue. 

The  correction  is  rather  simple,  yet 
the  error  is  serious.  Mr.  Woods  assigns 
ARGTOP  =  ARGSTK  in  the  function  ge- 
targ  ();  since  ARGSTK  is  being  decremen¬ 
ted  in  the  very  same  function,  ARGTOP 
will  change  also!  It  only  happens  that  the 
example  Mr.  Woods  tried  works. 

The  simplest  way  to  fix  the  problem 
would  be  to  assign  a  global  variable  to 
ARGSTK  before  the  first  call  to  getarg 
(),  then  use  that  global  variable  rather 
than  ARGTOP  to  correct  the  stack  off¬ 
set. 

Another  solution  (shown  below)  is 
to  pass  an  extra  parameter  to  getargO,  so 
the  calling  sequence  would  pass  ARGTOP 
into  a  local  variable  in  getarg  (). 

In  the  listing  below,  there  are  some 
differences  in  the  label  names  and  a  few 
function  names.  These  differences  should 
not  detract  from  the  corrections. 

If  anyone  out  there  would  be  interes¬ 
ted  in  a  working  version  of  the  small  c 
compiler  (with  extensions  such  as  for 
(;;)  loops,  do  .  .  .  until  loops,  switch  (or 
‘case’)  statements,  nested  levels  of  inclu¬ 
sion,  octal  and  hex  constants,  more  expli¬ 
cit  error  messages,  and  other  improve¬ 
ments,  they  should  get  in  touch  with  In- 
tersoft  Unlimited,  30  Jills  Court,  Barrie, 
Ontario,  L4M  4L7,  Canada. 

The  compiler  currently  runs  on  the 
TRS-80  Model  I  and  Model  III,  producing 
assembler  code  as  output  that  is  directly 
compatible  with  Microsoft’s  popular  M80 
assembler.  An  Edtasm-compatible  version 
should  be  available  soon. 

Work  is  progressing  well  on  a  version 
for  CP/M,  as  well  as  a  6809  version  to  run 
under  Flex  and  OS-9.  The  price  is  $60 
U.S.,  and  includes  source  code  for  the 
support  package  on  diskette  and  a  com¬ 
prehensive  Users  Manual,  as  well  as  the 
compiler  itself. 

Mr.  Cain  did  a  remarkable  job  on  the 
original  Small-C  compiler,  and  it  is  en¬ 
couraging  to  see  people  like  Mr.  Woods 
continuing  to  work  on  the  language. 


4 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 

277 


Small-C  is  an  excellent  language  for  a 
variety  of  systems-type  applications,  and 
with  a  little  luck  and  a  lot  of  work,  its 
use  should  become  widespread  through¬ 
out  the  hobbyist-computer  world. 

Sincerely, 

Mike  Gore, 

Bernie  Roehl 

#301-137  University  Ave.  W. 
Waterloo,  ON  N2L  3E6 
Canada 

“Waiter,  there’s  a  .  . 

Dear  Sirs, 

When  I  responded  to  your  subscrip¬ 
tion  offer  I  intended  to  get  the  trial  issue 
and  then  cancel.  I  haven’t  enough  time  to 
read  the  three  magazines  I  already  re¬ 
ceived,  so  I  felt  I  could  ill  afford  another. 
But,  like  a  fly  in  the  soup,  I  am  caught. 
Your  high  editorial  standards  are  to 
blame ;  it  is  a  joy  to  see  that  one  can  dis¬ 
cuss  such  a  technical  subject  without 
lapsing  into  semi-literacy  or  a  forest  of 
jargon. 

I  also  enjoy  DDJ  for  its  content.  I 
found  the  Pythagorean  approximation 
(Dr.  Dobb’s  Clinic,  May  ’81)  very  clever. 
The  purists  might  be  interested  that, 
at  the  expense  of  an  additional  four 
shifts  and  a  subtraction,  its  accuracy  can 
be  nearly  doubled.  Thus, 

dapprox=(l  -  1/16)  max  (dh,dv) 
+  min  dh,dv)/2 

has  a  minimum  error  of  6.3%.  And 

dapprox=0.96  max  (dh,dv)  + 
0.4  min  (dh,dv) 

is  accurate  to  within  4%,  which  is  probab¬ 
ly  good  enough  to  use  in  coordinate  rota¬ 
tions  for  video  graphics. 

Sincerely, 

Robert  S.  Stephenson 
244  Littleton  St.,  Apt.  3 
W.  Lafayette,  IN  47906 

Robust  Programs? 

Dear  Sir, 

Please  find  enclosed  a  banker’s 
draft  for  $88.00  for  a  2  year’s  subscrip¬ 
tion  to  Dr.  Dobb’s  Journal. 

As  an  aside  I  would  like  to  see  the 
following  change  in  content  in  DDJ. 
Since  the  advent  of  good  portable  operat¬ 
ing  systems  like  the  UCSD  p-system,  in 
the  wake  of  CP/M,  microcomputer  users, 
like  myself,  need  more  high  level  language 
tools  to  help  us  develop  good  software.  1 
feel  that  Dr.  Dobbs  is  losing  ground  in 
this  respect.  The  quality  of  the  articles 
carried  is  excellent;  but  I  think  the  days 


Small  -  C  Bug  Fix 
by  Mike  Gore  and  Bernie  Roehl 
/* 

*  Declare  argument  TYPES 

* 

*  Called  from  newfuncr  this  routine  modifies  the  symbol 

*  table  entry  created  in  newfunct)  to  agree  with  the 

*  actual  order  of  declared  arguments, 

*  Mike  Gore  -  March  1981 
*/ 

cetargl  t»  top)  /*  t  :  C'CHAR  or  CINT  */ 

int  tr  top;  /*  top  :  stack  offset  */ 

< 

char  n[  NAMESIZE  ],  *argptr; 
int  jr  locadd-; 

/*  top  tells  how  many  arguments  newfunc  found 

*  while  scaning  arguments.  From  this  we  can 

*  calculate  the  actual  stack  offset  and  stuff 

*  it  back  into  the  symtol  table. 

•/ 

whilel  1  ) 

( 

iff  matchl  )  ) 

j  «  pointer; 

else 

j  =  variable; 

iftsymnameC  n  )  )  ( 

/*  if  it’s  a  pointer  skip  stuff  between  []  */ 

i f  <  matchl  >  )  ( 

whilel  i nby  t  e  l  )  ! =  • ] •  ) 
i f  l  e  nds  t  l  )  ) 
break; 

j  =  pointer;  /•  mark  as  POINTER  */ 

)  /*  end  if  "["  */ 

/*  if  non  zero  we  found  the  entry  !  */ 

if  (argptr  *  finctoc  l n) >  { 

/*  stuff  away  type  info  that  we  just  found  ♦/ 

argptrCIDENT]  *  j; 
a  rgpt  r[ TYPE  3  =  t  ; 

/*  reverse  stacking  offset  */ 

/*  the  runtime  lib.  does  not  sign  extend  !  */ 

locaddr  =  top  -  l a rgp t r [ OF F S E T  ♦  13  <<  8) 

-  argptrCOFFSETj ; 

/*  replace  with  reversed  offset  */ 

a rqp t r [ 0 F F S E T 3  =  locaddr! 
a rgp t r [0 FF SE T  ♦  1]  :  locaddr  >>  8! 

)  I*  end  if  findloc  *  / 

else 

error!"  in  yetarg:  expecting  argument  name”); 

}  / •  end  i  f  symname  */ 
else 

i l l name  1 ) ; 

arqstk  =  arqstk  -  2  ; 
i f l  ends  t (  )  ) 
return! 

if!  matchl  )  = =  0  ) 

error! "in  qet  a  rg:  failed  to  find  comma"); 

(Listing  continued  on  page  6) 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 
278 


5 


Small  -  C  Bug  Fix  ( Continued ) 

By  Mike  Gore  and  Bemie  Roehl 

>  /»  end  while  1  »/ 

>  /*  end  pf  qetarqO  */ 

/  » 

*  Begin  a  FUNCTION 

*  % 

*  Called  from  parse/  this  routine  tries  to  make  a  FUNCTION 

*  out  of  what  follows. 

*/ 

newfuncl  ) 

( 

char  nC  NAMESIZE  3/  *ptr<' 
in  t  a  r  g  top; 

if(  symnamef  n  )  0  ) 

C 

errorC'in  newfunc;  illegal  function  name  or  declaration"); 
killl  );  /*  invalidate  line  */ 

r  e  t  urn ; 

> 


/*  See  if  the  function  name  is  in  the  symbol  table  */ 
if(  ptr  =  findglbl  n  )  )  { 

/*  If  the  ident  field  isn't  a  function  it's  a  variable; 
thus  the  function  name  is  mu  1 1  i  d  ef  i  n  ed  .  */ 

i f (  ptrCIDENT]  !*  FUNCTION  )  C 
mu  1 1  i  ife  f  (  n  )  ; 

> 

else  < 

/*  If  we  have  marked  the  offset  field  as  a  function/ 
we  have  a  multidefined  function  name  */ 

iff  ptrCOFFSET]  ==  FUNCTION  ) 
multi de  f  C  n  ); 

el  se 

/*  Now  we  mark  the  offset  field  we  just  tested  as  a 
function/  since  the  name  is  not  multidefined.  The 
compiler  may  see  a  reference  to  a  function  oefore 
its  definition;  this  is  the  reason  for  the 
apparent  redundancy  in  the  code  used  above.  */ 

ptrCOFFSET]  =  F  UNCTION ; 

} 

> 

else  /*  if  not  in  table/  define  as  FUNCTION  now  */ 
addglbf  n,  FUNCTION/  CINTz  FUNCTION); 

/»  we  had  better  see  open  paren  for  args  */ 

if  (matchf  "("  )  ==  0) 

errorC'in  newfunc:  missing  opening  parenthesis"); 
globalf  n  );  /•  output  FUNCTION  N  ANE  */ 

nl  (  >  ; 


/*  clear  local  stack  ptr  »/ 
locotr  =  STARTLOC; 

/*  reset  arqument  count  */ 
argstk  =  0 

/•  count  arguments  between 
whilef  matchf  ")"  )  ==  0  )  f 


f )  •  / 

(Listing  continued  on  page  8) 


of  long  Assembly  language  programs  are 
limited.  They  lack  the  robustness  and 
maintainability  needed,  whereas  a  good 
high  level  language  (e.g.  Pascal)  can  yield 
these  features. 

Nevertheless  keep  up  the  good  work. 

I  am  particularly  enamoured  with  the 
new  format.  Still  great  value  for  the  mon¬ 
ey. 

Yours  faithfully, 

Mark  Dawson 
58,  Newbridge  Hill, 

Bath, 

Avon  BAI  3PU,  England 
Dear  Mark, 

Thanks  for  your  subscription,  and 
even  more  thanks  for  your  encouraging 
words.  We  try  to  keep  DDJ  oriented 
toward  systems  programming.  That  is,  we 
aim  it  at  the  tool-makers  rather  than  the 
tool-users.  Assembly  language  is  (unfor¬ 
tunately)  still  the  tool-maker’s  main  tool. 
Although  Pascal  and  C  can  often  replace 
it,  our  contributors  haven’t  always 
learned  that.  We  can  only  print  the  arti¬ 
cles  we  receive. 

We’d  be  delighted  to  receive  contri¬ 
butions  from  you  or  anyone  else,  demon¬ 
strating  solutions  to  systems-type  prob¬ 
lems  in  Pascal  or  C. 

-The  Editors 

Errata 

A  DDJ  #55  software  review  mis¬ 
takenly  spoke  of  “Scribe  IX.”  The  cor¬ 
rect,  copyrighted  name  is  “Scribewriter 
IX,”  available  from  Friedman  Ads/ Pro¬ 
motions. 

About  the  Motorola  6809 

This  note  is  an  initial  reaction  to 
Lance  Leventhal’s  new  book,  6809 
Assembly  Language  Programming  (OS- 
BO  RNE/McGraw-Hill,  Berkeley,  1981). 
He  sent  me  a  complimentary  copy, 
without  explaining  why.  My  guess  is  that 
he  felt  I  didn’t  know  enough  about  this 
microprocessor  —  a  correct  inference 
from  my  inexact,  casual  references  to  it 
in  DDJ  #49.  I  shall  not  here  try  to  re¬ 
view  the  book,  other  than  to  say  that  it 
strikes  me  as  excellent  (and  ought  to  have 
been  published  sooner!).  My  intent  is  to 
correct  earlier  comments  on  the  6809 
multi-byte  opcodes. 

The  6809  does  indeed  have  2-byte 
(and  even  3-byte)  opcodes,  and  2  “lead¬ 
ing-byte”  codes  ($10  and  $11).  However 
—  unlike  the  Z80  —  the  leading-byte 
mode  is  not  the  major  enhancement  and 


6 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 

279 


Small  -  C  Bug  Fix  ( Continued ) 
by  Mike  Gore  and  Bemie  Roehl 

/*  any  legal  NAME  Dumps  argstk  (keeps  track  pf  arg  count)  ♦/ 

if(  symnameC  n  )  )  { 

if  (  findloc*(n)) 
multi def(n)  ; 
else  ( 

/*  add  local  symbol  to  be  processed  */ 

/*  later  by  getargt)  */ 

addlocfn*  0*  0*  argstk); 
arqstk  =  argstk  e  2t 
>  /*  end  else  if  findloc  */ 

>  /*  end  if  symname  ♦/ 
else  ( 

errorC'in  newfunc:  illegal  argument  name"); 
j  un  k  (  ) ; 

)  /*  end  else  if  symname  */ 
blanks(  )>' 

/*  if  not  closing  paren*  should  be  comma  */ 

if(  streqC  ?lineClptr]*  ")"  )  =  =  0  )  { 
i f  <  match(  "  *  "  )  ==  0  ) 

errorC'in  newfunc:  expected  comma  in  p a r a  me t ? r - l  i  s t " )  ; 

>  /*  end  if  streq  ...  */ 
i f (  end  s  t  (  >  ) 

break; 

>  /*  end  while  ">"  *  / 

/*  Set  argtop  to  the  current  offset.  We  will 

pass  this  to  getargf)  so  the  the  stacking  offsets 
can  be  reversed  *  / 

argtop  =  argstk; 
wh i l e (  argstk)  { 

/♦  Now  let  user  declare  what  TYPES  those  arguments 
were  *  / 

if(  amatchl  "char"*  4  )  )  { 

getargf  CCHAR*  argtop); 
ns  ( )  ; 
cont  inue; 

)  /  *  end  if  "char"  */ 
if(  amatchl  " i n t " *  3  )  )  { 

getarg(  CINT*  argtop); 
n  s  ( )  ; 
cont  inue; 

}  /  *  end  if  "int"  *  / 

errorC'in  newfunc:  wrong  tyoe  or  number  of  arguments"); 
break; 

)  /*  end  while  argstk  */ 

stkptr  =0;  /‘preset  stack  POINTER  » / 

/*  Dp  a  statement  but  i  f  it  is  a  return*  skip 
and  clean  up  the  stack  */ 

iff  statement (  )  !  =  STRETURN  ) 

C 

modstk(  0  ); 
r  e  t  (  ) ; 

> 

stkptr  =  0; 

Ipcotr  =  STARTLOC; 


/*  reset  stack  otr  again  */ 

/*  deallocate  all  locals  *  / 

end 


does  not  completely  redefine  the  follow¬ 
ing  opcode.  The  $  10  changes  15  of  the  16 
normal  program-counter-relative  branch 
codes  from  “short”  (one  offset  byte, 
range  —128  to  +127)  to  “long”  (two 
offset  bytes,  range  -32768  to  +32767.) 
Only  the  LBRA  (unconditional  long 
branch)  instruction  was  considered  im¬ 
portant  enough  to  be  assigned  a  one-byte 
code,  since  it  is  likely  to  replace  the  JMP 
in  most  programs. 

The  $11  redefines  the  on-chip  16-bit 
register  to  be  used  by  the  following  op¬ 
code  (e.g.,  the  one-byte  code  $FE  speci¬ 
fies  stack-register  U,  while  $  1 1 FE  alters 
this  to  stack -register  S.)  Both  leading- 
bytes  are  also  used  to  create  2  new  soft¬ 
ware-interrupt  instructions  from  the  one- 
byte  $3F  interrupt  code.  All  this  is  use¬ 
ful,  but  the  expectation  is  that  the  lead¬ 
ing-byte  mode  will  not  be  used  very  fre¬ 
quently,  whereas  nearly  all  of  the  Z80  en¬ 
hancements  rely  on  leading-bytes. 

In  fact,  the  Z80  influence  is  negligi¬ 
ble,  though  there  is  a  new  16-bit  Y  index- 
register  (with  some  coding  less  efficient 
than  the  otherwise  similar  X,  because  of 
the  shortage  of  one-byte  codes  and  per¬ 
haps  the  desire  to  keep  some  free  for  later 
upgrading).  The  influence  I  now  see  (I 
hope  not  again  mistakenly!)  is  more  that 
of  the  Signetics  2650,  that  extends  its 
opcodes  by  using  the  3  high-order  bits  of 
the  1-byte  address  to  specify  the  addres¬ 
sing  mode.  The  6809  “opcode-extension” 
is  a  full  8-bit  “post-byte”  that  defines  a 
great  variety  of  addressing  modes.  The  ex¬ 
tension  is  required  by  56  opcodes  (8  of 
which  also  have  a  leading-byte)  and  al¬ 
lows  14  major  addressing  variants.  Nine 
of  these  require  no  additional  addressing 
information.  Two  require  one  additional 
byte  that  specifies  an  8-bit  offset,  two  re¬ 
quire  two  additional  bytes  (16-bit  offset), 
and  one  has  two  additional  bytes  that  are 
the  actual  address  of  memory  locations 
where  the  “true”  address  has  been 
stored  (“indirect”  addressing.)  These  ef¬ 
fectively  2-  or  3-byte  opcodes  are  the 
most  spectacular,  complex  enhancements 
created  for  the  6809.  There  are  other  re¬ 
markable  ones,  defined  by  one-byte  op¬ 
codes,  but  those  who  want  details  must 
read  the  Leventhal  book.  The  6809  is 
too  complex  to  be  described  even  in  a 
long  article! 

A  few  thoughts  on  the  impact  of 
the  6809.  Only  the  TRS-80  Model  III  has 
so  far  adopted  it  (again  proving  the  acu¬ 
men  of  Radio  Shack  executives)  though 
other  mass-market  systems  may.  Even 


8 

280 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


Synertek  —  long  dedicated  to  the  6502  — 
has  designed  a  new  6809-based  SYM 

SBC.  Although  the  brand-new  Osborne- 1 
system  is  Z80-based,  the  only  possible 
rationale  for  that  is  the  existence  of  much 
complex,  tested  Z80  software;  my  guess 
is  that  the  Osbome-2  will  bypass  the 
6809  level  and  upgrade  either  to  the 
68000  or  the  coming  32-bit  Intel  proces¬ 
sor  (again  depending  on  the  availability  of 
software).  No  older  processor  can  com¬ 
pete  in  performance  with  the  6809.  Its 
problems  are  lack  of  software,  reluctance 
of  owners  of  working  systems  to  upgrade 
it  (partly  because  of  the  software  cost), 
and  the  possibility  that  more  powerful 
processors  may  attain  a  superior  price/ 
performance  ratio. 

It  must  be  the  difficulty  of  equalling 
the  performance  of  the  6809  that  has  al¬ 
ready  aborted  the  projected  6516  up¬ 
grade  of  the  6502  (and  no  doubt  other 
upgrades  or  new  designs).  This  leaves  the 
field  wide-open  to  Japanese  designers, 
who  are  unwisely  scorned  by  some  nota¬ 
ble  Americans.  American  companies  may 
be  unwilling  to  gamble,  compete  with 
Motorola  (at  this  level),  or  learn  how  to 
handle  designers  of  genius.  The  Japanese 
may. 

My  personal  reaction  —  significant 
only  to  the  extent  that  it  may  prove  typi¬ 
cal  of  6502  aficionados  —  is  that  there’s 
no  need  for  a  rush  move  to  the  6809.  It 
should  be  6800  system  users  who  adopt 
it  first,  do  the  spadework,  and  prove  its 
programming  speed,  efficiency,  and  ele¬ 
gance.  It  will  surely  excel,  but  by  what 
margin?  Even  6800  users  have  not  stam¬ 
peded  to  its  upgrade,  proving  that  the 
machine-code-compatibility  (with  the 
older  design)  played  a  major  role  in  the 
quick  adoption  of  the  Z80  —  however 
grotesque  it  may  seem  to  a  logical  mind. 
The  Motorola  6809  assembler  can  “trans¬ 
late”  6800  assembly-language  into  the 
6809  equivalents,  and  similar  translators 
could  be  written  for  other  micro  assem¬ 
bly-languages.  However,  this  is  not  likely 
to  yield  optimal  code,  using  the  full  pow¬ 
er  of  the  6809.  Only  the  human  mind  can 
do  that.  Although  I  do  not  admire  the 
6800  set,  regret  that  so  much  of  it  was  re¬ 
tained,  and  (as  a  first  impression)  feel 
that  not  all  the  6809  innovations  are 
ideal,  its  overall  superiority  is  so  great 
that  I  intend  to  get  the  SYM  version. 

H.  T.  Gordon 

College  of  Natural  Resources 

U.  C.  Berkeley,  Berkeley,  CA  94702 


More  on  N-Logs 

Dear  Editor, 

The  comments  of  Mr.  Mikes  in  DDJ 
#52  regarding  my  article  on  N-Logs  were 
greatly  appreciated.  His  criticisms  fall  in¬ 
to  two  groups,  the  first  relating  to  histo¬ 
ry,  the  second  having  to  do  with  the 


meaning  of  words  and  symbols.  I  will  try 
to  respond. 

His  remarks  as  to  the  origin  of  ‘e’, 
the  base  of  what  are  now  called  ‘Natural’ 
or  ‘Naperian’  logarithms  are  quite  correct. 
I  was  deceived  by  the  all-too-common 
( Continued  on  page  22) 


Our  high-quality  editorial 
and 

your  high-quality  products 
are  made  for  each  other! 

Call  (415)  323-3 1 1 1  to  reserve  your  space 
in  the  next  Dr  Dobb ’s  Journal. 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


9 

281 


Pidgin-A  Systems 
Programming  Language 


DDJ  is  pleased  to  present  the  first  of  two  articles  by  Dr. 
William  Gale  ( the  second  article  will  appear  next  month).  In 
these  articles  Dr.  Gale  describes  three  unusual  pieces  of  soft¬ 
ware:  Tincmp,  a  clever  macro  processor;  Pidgin,  a  systems 
programming  language;  and  Meta4,  a  compiler-compiler. 

Dr.  Gale  calls  Pidgin  a  "low-level  language.’’  This  is  only 
justified  by  its  small  number  of  data  types  (bytes,  words,  and 
vectors  of  bytes  or  words).  Pidgin’s  assortment  of  control 
statements  is  as  good  as  that  of  many  high-level  languages. 
Despite  this,  Pidgin  is  simple  enough  that  it  can  be  fully  imple¬ 
mented  as  a  set  of  Tincmp  macros. 

Tincmp,  the  macro  processor,  is  the  key  to  the  series.  Dr. 
Gale  illustrates  its  power  by  using  it  as  a  translator  from  Pidgin 
source  code  to  6502  machine  language.  We’re  sure  that  isn’t 
the  end  of  its  uses.  Tincmp  is  given  here  as  a  program  written 
in  Pidgin.  The  bootstrap  procedure  is  to  paraphrase  that  listing 
in  BASIC  or  Pascal,  feed  the  Pidgin  macros  and  the  Tincmp 
source  program  to  that  program,  and  receive  a  machine- 
language  version  of  Tincmp  as  output. 

Next  month  DDJ  will  publish  Dr.  Gale’s  description  of 
Meta4,  a  compiler-compiler  (  a  program  that  takes  a  formal 
language  definition  as  input  and  delivers  a  compiler  for  that 
language  as  output).  Meta4  is  a  development  of  Meta  II,  de¬ 
scribed  in  DDJ  #44.  The  source  for  Meta4  will  be  given  in  Pid¬ 
gin.  Those  readers  who’ve  brought  up  Tincmp  by  then  will  be 
able  to  implement  Meta4  at  once. 

We  hope  DDJ’s  readers  will  be  as  excited  by  Tincmp, 
Pidgin,  and  Meta4  as  we  are.  DDJ  welcomes  contributions 
based  on  Dr.  Gale’s  articles.  Some  possibilities:  a  listing  of 
Tincmp  in  BASIC  or  Pascal,  or  Tincmp  macros  to  translate 
Pidgin  to  another  machine  language  or  to  another  program¬ 
ming  language,  or  reports  of  your  application  of  any  of  the 
three  programs  to  other  problems. 

Pidgin  is  a  low-level,  machine-independent  programming 
language.  Because  it  is  easily  compiled,  it  is  suitable  for 
systems  programming  applications  where  portability  is 
the  foremost  requirement.  The  original  design  purpose  was 
cross-time  portability,  so  work  done  on  my  current  machine 
could  be  cumulative  for  my  next  machine.  But  it  should  also 
be  suitable  for  describing  to  a  Z80  what  I’ve  done  on  my 
6502.  People  with  a  homebrew  system  that  nobody  else  writes 
software  for  may  be  particularly  interested  in  a  pool  of  ma¬ 
chine-independent  software. 

Pidgin  can  be  compiled  by  a  macro  processor  that  recog¬ 
nizes  nine  paramenters  each  of  length  one.  Such  a  macro  pro¬ 
cessor  is  easy  to  write,  the  more  difficult  part  being  to  write 
the  macros  for  the  80  statements  of  Pidgin.  A  macro  processor 
written  in  Pidgin  is  included  with  this  article.  It  takes  500  lines 
with  8000  characters  including  comments,  and  compiles  into 
3.5  kilobytes  (with  another  5  kilobytes  for  macro  storage). 

Next  month  another  Pidgin  program  will  be  described,  the 
Meta4  compiler  generator.  A  compiler  generator  is  a  program 
that  makes  it  easier  to  write  a  compiler.  Meta4  will  thus  allow 
defining  more  powerful  languages  than  Pidgin,  with  a  machine- 
independent  compiler.  It  is  my  hope  in  presenting  Pidgin  and 

©1981  by  William  A.  Gale.  All  rights  reserved. 

by  William  A.  Gale 


10 

282 


these  programs  that  some  of  you  Z80  and  6800  users  will 
write  and  publish  Pidgin  programs  that  I  can  use  on  my  6502. 
Microcomputers  are  software  limited,  and  the  bigger  the  pool 
of  users  and  writers,  the  bigger  our  pool  of  software  will  be. 

Brief  Description  of  Pidgin 

The  80  statements  of  Pidgin  can  be  seen  from  the  tem¬ 
plates  in  either  the  first  or  second  macro  sets  included.  The 
discussion  of  Tincmp,  later  in  this  article,  will  clarify  how 
these  macros  are  to  be  read.  The  templates  start  with  six  dec¬ 
laration  statements.  The  declarations  set  aside  storage  loca¬ 
tions  for  each  of  the  two  data  types  and  the  four  combinations 
of  vector  types.  For  the  vectors,  the  declarations  give  the 
length  of  storage  to  reserve.  Indexing  is  from  zero,  so  the  max¬ 
imum  index  is  one  less  than  the  reserved  spaces.  BYTE  varia¬ 
bles  allow  indexing  BYTE  vectors  from  0  to  255,  or  INT  vec¬ 
tors  from  0  to  1 27.  INT  variables  allow  indexing  at  least  from 
0  to  32000. 

The  macros  continue  with  fifteen  data  transfer  state¬ 
ments.  The  transfer  statements  give  the  means  for  storing  and 
retrieving  in  each  of  the  four  vector  types.  They  also  give  the 
means  for  translating  from  BYTE  to  INT  and  vice  versa.  The 
BYTE  translation  of  an  INT  is  the  low  order  bits  of  the  INT. 
The  transfer  statements  also  include  statements  for  setting 
BYTE  and  INT  variables  to  a  constant  number,  and  for  setting 
a  BYTE  variable  to  a  character  constant.  (The  statement  XX= 
‘2’  will  set  XX  to  the  constant  50  if  ASCII  is  used  internally.) 
Two  other  transfers  got  added  late,  and  are  at  the  end  of  the 
macros.  PACK  and  UNPACK  are  abbreviations  that  are  rather 
ugly,  but  I  finally  decided  I  didn’t  want  to  be  without  them 
when  they  are  so  easy  to  do  for  a  micro.  UNPACK  moves  the 
lowest  byte  in  the  named  INT  to  the  third  argument,  and  the 
second  lowest  byte  to  the  second  argument.  PACK  copies  the 
third  argument  into  the  lowest  byte  of  the  named  INT  and  the 
second  argument  into  the  next  lowest  byte.  If  the  INT  is  larger 
than  2  bytes,  the  remainder  is  zero  filled. 

Following  the  bulk  of  the  transfer  statements  are  the 
eleven  arithmetic  statements.  The  arithmetic  statements  in¬ 
clude  the  usual  four  binary  operations  for  integer  variables, 
and  addition  and  subtraction  for  BYTE  variables.  They  also 
include  increment  and  decrement  operations  for  both  types. 
Addition  and  subtraction  are  modulo  some  constant,  so  that 
(0-1)+  1=0. 

There  follow  eleven  statements  to  generate  and  manipu¬ 
late  logical  values  for  byte  variables.  The  logical  statements 
include  eight  comparisons  and  three  Boolean  algebra  state¬ 
ments.  The  eight  comparisons  each  set  a  BYTE  variable  after 
comparing  two  variables  of  the  same  type  for  equality  (=), 
inequality  (!=),  strictly  less  (<!),  and  less  or  equal  (<=).  The 
BYTE  variable  is  set  to  zero  if  the  relation  is  false.  If  it  is  true, 
the  byte  will  be  set  with  at  least  one  particular  bit  non-zero. 
(This  allows  the  boolean  operations  to  be  done  on  bytes 
defined  by  comparisons.)  The  three  Boolean  operations  form 
the  Boolean  and  (&),  or  (?),  and  not  (!)  for  BYTE  variables. 
For  INT  variables  0- 1  <0,  while  for  BYTE  variables  0  <  0 
—  1.  That  is,  under  comparison,  INT  acts  as  if  it  holds  posi¬ 
tive  and  negative  numbers  for  some  range,  while  BYTE  acts  as 
if  it  holds  only  positive  numbers. 

The  following  25  statements  are  control  statements  of 
various  types.  I  will  discuss  them  in  groups  that  are  not  in  the 
same  order  as  the  macros. 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


The  assembler  control  statements  will  be  highly  machine 
dependent,  and  should  occur  first  in  the  program.  Then  they 
can  be  changed  easily  for  a  different  machine.  They  allow  defi¬ 
nition  of  where  to  assemble  the  program  (LOMEM),  and 
where  to  keep  the  variables  (REGISTER  and  HIMEM).  If  you 
need  something  more  here,  don’t  hesitate  to  add  it.  TOP  can 
also  be  used  to  set  up  assembler  conditions. 

The  program  control  statements  are  the  most  varied.  The 
main  program  is  marked  off  by  BEGINMAIN  and  ENDMAIN. 
Subroutines  are  marked  by  SUB  $$  and  ENDSUB.  On  encoun¬ 
tering  a  GOSUB  $$  statement,  control  passes  to  the  statement 
following  the  corresponding  SUB  $$  statement.  Here  the  two 
characters  can  be  any  two  alphanumeric  symbols.  On  finding 
a  RETURN  or  ENDSUB,  control  passes  to  the  statement  fol¬ 
lowing  the  calling  GOSUB  $$  statement.  When  a  GOTO  $$  is 
encountered,  control  passes  to  the  corresponding  LOC  $$ 
statement.  Only  decimal  digits  are  legal  for  the  parameters  in 
LOC  and  GOTO  pairs.  This  restriction  to  100  labels  is  not  a 
problem  because  of  the  remaining  control  statements. 

The  IF  $$  statement  specifies  a  BYTE  variable  with  the 
two  parameter  characters.  If  the  named  BYTE  variable  is  non¬ 
zero,  control  continues  with  the  next  following  statement. 
Otherwise  control  passes  to  the  statement  beyond  the  next 
unmatched  ELSE  or  ENDIF.  Unmatched  means  that,  for  in¬ 
stance,  between  an  IF  and  ELSE,  you  can  put  other  complete 
sets  of  IF—  (ELSE)  —ENDIF  statements. 

The  ON  $$  statement  also  specifies  a  BYTE  variable.  If 
the  named  variable  is  nonzero,  execution  continues  with  the 
following  statement.  Otherwise,  control  passes  to  the  state¬ 
ment  beyond  the  next  unmatched  ENDWHILE  statement. 
When  an  ENDWHILE  is  encountered,  control  passes  to  the 
first  previous  unmatched  WHILE.  So  WHILE-ON-ENDWHILE 
is  the  form  for  all  loops  in  Pidgin. 

The  CHOOSE  ON  sequence  is  a  choice  among  variables, 
not  among  constants.  The  CHOOSE  ON  $$  statement  speci¬ 
fies  a  BYTE  variable,  as  does  the  CASE  $$  statement.  When  a 
CHOOSE  ON  statement  is  encountered,  control  passes  to  the 
next  CASE  statement  for  which  the  two  variables  are  equal,  or 
else  to  the  DEFAULT  if  there  is  one,  or  the  statement  follow¬ 
ing  the  ENDCHOOSE  if  there  is  no  DEFAULT.  After  match¬ 
ing  a  CASE  variable,  when  a  CASE,  DEFAULT,  or  END¬ 
CHOOSE  statement  is  encountered,  control  passes  to  the  state¬ 
ment  following  the  next  ENDCHOOSE.  (In  the  above  specifi¬ 
cation,  words  specifying  the  nesting  of  CHOOSE’s  are  omitted. 
I  think  that  makes  the  explanation  clearer.  But  the  CHOOSE, 
like  IF  and  WHILE  can  be  nested.) 

STOP  $  terminates  execution  of  the  program,  and  makes 
the  digit  specified  available  to  any  supervisory  program.  A 
zero  is  interpreted  as  a  normal  end,  any  other  digit  is  an  error 
condition. 

Two  specific  control  statements  are  designed  to  let  Pidgin 
programs  speak  to  another  one.  BEGINMAIN  specifies  a 
BYTE  variable  AC  and  a  BYTE  indexed  INT  vector,  IAV.  AC 
(Argument  Count)  can  be  used  to  give  the  number  of  entries 
to  be  found  in  IAV.  The  key  point  is  that  these  are  special  lo¬ 
cations,  known  to  all  Pidgin  programs.  They  are  particularly 
useful  for  passing  file  references,  or  program  addresses  be¬ 
tween  programs.  CALL  IS  $  is  a  kluge  that  will  be  recognized 
by  BASIC  users.  It  will  make  a  subroutine  call  to  the  absolute 
location  stored  in  the  INT  variable  named. 

The  final  group  of  statements  has  the  input-output  state¬ 


ments.  Pidgin  is  designed  so  that  input  and  output  is  usually 
character  by  character.  WRITE  $$  will  output  the  named  byte 
to  the  terminal.  READ  $$  will  get  one  character  from  the  ter¬ 
minal  and  set  the  named  BYTE  variable  equal  to  it.  The  com¬ 
mon  exception  to  single-character  input  and  output  is  MS, 
which  will  output  the  nine  specified  characters  to  the  terminal. 
The  single  quote  character  (’)  should  not  occur  among  the  pa¬ 
rameters  of  MS.  The  remaining  input-output  statements  deal 
with  files. 

The  first  statement  to  use  is  OPEN  $$  FOR  $$  AT  I$$. 
The  first  two  parameters  specify  an  INT  indexed  BYTE  vector 
to  be  used  for  a  buffer.  The  third  and  fourth  parameters  spe¬ 
cify  a  BYTE  variable  that  contains  either  ‘R’,  for  read,  or  ‘W’ 
for  write.  The  fifth  and  sixth  parameters  name  an  INT  variable 
that  gives  a  “block  number”.  The  specification  of  a  buffer,  and 
allocation  of  space  means  that  any  number  of  files  can  be 
open,  so  long  as  one  buffer  per  file  is  allocated.  The  compiler 
only  uses  two  buffers.  The  operations  recognized  by  Pidgin  are 
limited  to  read  and  write,  but  there  are  useful  extensions  (ap¬ 
pend,  read  or  write).  The  block  number  is  the  key  to  a  rudi¬ 
mentary  file  system  as  described  in  DDJ  #56.  This  simple  file 
system  will  allow  programs  to  be  written  in  Pidgin  that  give 
named  files  and  other  nice  features.  In  this  way  a  rather  ma¬ 
chine-independent  operating  system  is  possible.  The  block 
number  is  a  number  from  one  through  some  maximum  that 
specifies  a  unique  external  place  to  put  the  data  contents  of 
one  buffer.  This  avoids  dependence  on  a  particular  machine 
by  pushing  the  translation  from  block  number  to  drive,  track, 
sector,  or  what  have  you,  down  to  assembly-language  support 
programs.  The  translation  is  responsible  for  setting  a  reasona¬ 
ble  sequence  for  speed  of  access.  But  all  that  is  required  is  a 
unique  map  between  disk  sectors  (or  whatever)  and  block 
number. 

The  file  input-output  statements  all  return  an  error  code 
in  the  specially  designated  BYTE  variable  ER.  Error  code 
zero  indicates  all  normal;  one  indicates  end  of  file  or  end  of 
medium;  two  indicates  illegal  operation;  and  three  indicates  all 
other  problems. 

OPEN  returns  error  code  two  if  the  buffer  was  already 
open,  zero  otherwise.  This  indicates  that  the  “buffer”  will 
contain  at  least  some  information  beyond  the  file  contents. 
(The  Apple  requires  a  17-byte  table  to  control  disk  input- 
output,  which  is  included  in  the  space  allocated  for  the  buffer, 
for  instance.)  For  this  reason,  the  declared  lengths  of  the  buf¬ 
fers  will  be  machine  dependent. 

CLOSE  $$  specifies  a  buffer.  It  returns  ER=2  if  the  buffer 
was  already  closed.  It  marks  the  buffer  closed.  If  the  buffer 
was  open  to  write,  then  CLOSE  will  flush  the  buffer,  writing 
the  last  block  of  data,  and  making  any  closed  file  marks. 

READ  $$  FROM  $$  specifies  a  BYTE  variable  with  the 
first  two  parameters  and  a  buffer  with  the  last  two.  This  state¬ 
ment  reads  one  character  from  the  specified  buffer  until  it 
has  read  all  of  the  characters  in  the  buffer.  Then  it  refills  the 
buffer  by  getting  the  next  sequential  block  number  of  data 
from  the  external  medium.  When  end  of  file  is  reached,  it 
returns  both  ER=1  and  the  character  0—1. 

WRITE  $$  INTO  $$  is  the  converse.  It  will  write  one  spe¬ 
cified  character  into  the  specified  buffer  until  the  buffer  is 
full.  It  then  writes  the  buffer  onto  the  external  medium  and 
prepares  to  receive  more  data  from  the  program.  It  keeps 
track  of  the  block  number  to  write  on  next,  writing  on  se- 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


11 

283 


quentially  incremented  blocks.  It  returns  ER=1  if  the  block 
number  is  greater  than  the  maximum  allowed,  or  zero. 

READBUF  $$  and  WRITEBUF  $$  give  an  access  to  the 
low-level  programs  that  read  and  write  one  buffer  of  data  from 
the  external  medium.  They  will  be  useful  for  programs  that 
implement  directory  files  or  random-access  files,  but  they 
are  not  used  in  the  compiler.  Programming  the  subroutines 
to  support  these  file  input-output  statements  took  a  substan¬ 
tial  fraction  of  the  time  to  make  the  compiler,  perhaps  a  third. 

The  last  “statement”  in  the  macros  is  the  null  macro.  It 
allows  any  line  started  with  the  end-line  symbol  to  be  ignored; 
that  is,  it  allows  line-long  comments. 

Implementing  Tincmp,  a  compiler  for  Pidgin 

In  hopes  of  getting  back  a  return  of  portable  programs,  I 
offer  a  compiler  to  translate  Pidgin  to  6502.  The  compiler  is 
in  two  parts,  a  macro  processor  (Tincmp)  written  in  Pidgin, 
and  two  sets  of  macros.  I  term  these  tools  a  compiler  because 
they  can  generate  machine  code  from  Pidgin  language.  Others 
might  feel  that  with  no  more  error  checking  than  it  has,  it 
couldn’t  be  so  dignified. 

The  value  of  the  Pidgin  listing  of  the  Tincmp  macro  pro¬ 
cessor  when  you  don’t  yet  have  a  Pidgin  compiler  is  this:  you 
can  easily  translate  Pidgin  to  your  local  Basic.  If  you  translate 
Tincmp  to  Basic,  then  you  can  use  the  macros  provided  to 
form  a  compiler  from  Pidgin  to  6502  in  Basic.  Feed  that  com¬ 
piler  the  Pidgin  code  for  Tincmp  and  you  will  nave  a  compiler 
from  Pidgin  to  6502  in  6502.  It  runs  much  faster.  This  is 
a  reasonable  way  to  get  started  because  the  macros  are  the 
hard  part,  and  can  be  used  with  two  versions  of  the  macro 
processor.  I  have  written  several  versions  of  Tincmp,  and 
find  it  takes  a  few  days  to  get  the  macro  processor  working. 
The  macros  on  the  other  hand  took  several  weekends.  When  I 
add  macros,  I  find  I  can  add  about  20  in  a  weekend. 

So  to  implement  this  Pidgin  compiler  you  need  to  trans¬ 
late  Tincmp  to  some  language  you  now  have.  To  help  in  that 
let  me  first  explain  what  Tincmp  does,  then  how  it  does  it. 

Tincmp  has  two  inputs  -  a  set  of  macros,  and  an  input 
text.  Each  macro  consists  of  a  template  and  a  replacement. 
Templates  start  with  a  special  begin-template  character  and 
end  with  the  special  end-line  character.  Between  these  two 
characters  there  can  be  up  to  nine  parameter  flags  and  any 
number  of  other  characters  besides  these  three  or  newline. 
The  end-line  character  can  be  followed  by  any  characters  at 
all,  then  a  newline.  All  the  characters  after  the  end-line  are 
ignored,  so  they  can  and  should  be  used  for  comments. 

To  summarize,  a  template  consists  of 

1 .  begin-template  character 

2.  zero  or  more  ordinary  characters  or  zero  through  nine  pa¬ 
rameter  flags  in  any  order 

3.  end-line  character 

4.  zero  or  more  comment  characters 

5.  newline 

If  the  end-line  character  is  omitted,  it  will  be  assumed  at  the 
first  newline.  The  macros  attached  show  many  examples 
using  ‘ :’  as  the  begin-template  character,  as  the  end-line 
character  and  '$’  as  the  parameter  flag. 

The  replacement  consists  of  zero  or  more  lines.  Each  re¬ 
placement  line  may  have 

1.  zero  or  more  ordinary  characters  or  “operation  codes” 


2.  an  optional  end-line  character  followed  by  zero  or  more 
comment  characters 

3.  newline 

The  power  of  Tincmp  lies  in  its  operation  codes.  It  can  be 
thought  of  an  as  interpreter  for  a  very  simple  machine  lan¬ 
guage.  The  simplicity  is  that  there  are  no  branching  or  repe¬ 
tition  codes.  The  operation  codes  basically  move  data  be¬ 
tween  ten  registers,  a  stack,  and  the  output. 

The  first  line  of  the  macros  gives  copies  of  the  changeable 
special  characters.  If  the  first  character  is  ‘X’,  no  newlines  will 
be  put  into  the  output.  This  is  required  to  generate  code  at 
times,  and  text  at  other  times.  The  second  character  is  a  copy 
of  the  begin-template  character.  The  third  character  is  a  copy 
of  the  end-line  character.  The  fourth  character  is  a  copy  of  the 
parameter  flag.  The  fifth  is  a  copy  of  the  operation  code  char¬ 
acter.  The  sixth  is  an  “ignore”  character  (set  to  tab,  but  invisi¬ 
ble  in  the  listings).  The  ignore  character  is  ignored  wherever  it 
occurs  in  the  macros.  Its  purpose  is  to  help  make  the  macros 
more  readable.  The  first  line  must  consist  of  exactly  six  char¬ 
acters  and  a  newline.  Otherwise  an  error  is  noted,  and  proces¬ 
sing  stops.  With  all  these  special  characters,  a  way  around  them 
when  necessary  is  available.  The  character  is  a  (fixed)  es¬ 
cape  character.  Any  one  character  (including  newline  and  @) 
following  the  @  will  be  accepted  as  part  of  the  macros.  You 
will  see  it  used  heavily  in  the  second  macro  set,  because  the 
definitions  of  the  labels  created  might  be  special  characters, 
just  by  chance. 

An  important  link  between  the  template  and  the  operation 
codes  takes  place  while  Tincmp  is  matching  the  templates 

Table  1 

Fetch  Operations 

P  Parameter  Fetch  the  value  of  the  parameter  specified  by 
the  index  code. 

V  conVert  Fetch  the  value  of  the  parameter  specified  by 
the  index  code.  Subtract  the  character  code  for 
zero.  If  the  result  is  not  between  zero  and  nine, 
set  it  to  zero. 

L  Literal  Fetch  the  index  code  as  a  character. 

N  Number  Fetch  the  index  code  converted  as  a  digit. 

!  pop  Fetch  the  top  of  the  stack,  decrementing  the 

stack  pointer. 

S  Stack  Fetch  the  top  of  the  stack. 

U  Unique  Fetch  a  unique  number.  The  numbers  start  at 
100,  and  increase  sequentially.  (Default). 

H  Hex  Fetch  the  index  code  and  the  dispose  code, 

interpreted  as  hexadecimal  digits.  Set  the  dis¬ 
pose  code  to  ‘C’. 


T  Trace  Set  the  trace  mode  on  for  the  remainder  of  the 

macro.  Skip  the  dispose  section. 


12 

284 


Dr.  Dobb’s  Journal,  Number  57,  July  198  1 


against  input  text.  A  line  of  input  text  matches  a  template  if  it 
is  the  same  length  as  the  template  and  if  each  ordinary  charac¬ 
ter  in  the  template  is  matched  exactly.  Any  single  character 
matches  a  parameter  flag  AND  the  character  matched  by  the 
n’th  parameter  flag  is  placed  in  the  n’th  register,  n=l,  .  .  .,9. 
Thus  the  operation  codes  can  manipulate  the  parameters 
found. 

When  a  template  has  been  matched,  ordinary  characters  in 
the  replacement  are  output  without  change.  The  end-line  sym¬ 
bol  causes  the  output  of  a  newline.  Any  comments  and  the 
newline  are  ignored.  Each  operation  code  consists  of  four 
characters,  the  operation  code  flag,  the  fetch  code,  the  index 
code,  and  the  dispose  code.  Table  1  gives  the  fetch  codes  and 
Table  2  gives  the  dispose  codes.  The  index  code  may  modify 
the  fetch  code  or  the  dispose  code  (or  both).  Let  me  comment 
on  them  briefly. 

The  value  placed  in  the  register  is  the  internal  machine 
representation  of  the  character  matched.  The  P  fetch  gets  this 
value.  If  some  other  number  has  been  stored  in  a  register  since 
the  matching,  of  course  P  will  now  get  that  number.  The  regis¬ 
ters  hold  integer  numbers.  If  the  parameter  should  be  a  digit, 
the  V  fetch  gets  a  number  from  zero  through  nine.  Notice  that 
any  non-digit  is  coerced  to  zero.  The  register  is  selected  for 
these  two  fetches  by  the  index  code,  and  register  zero  can  be 
selected.  Since  it  cannot  be  disturbed  by  parameters,  it  can  be 
used  for  a  counter.  The  L  and  N  fetches  get  data  from  the 
index  code.  L  gets  the  internal  machine  representation  of  any 
character  while  N  coerces  it  to  a  digit.  The  number  on  top  of 
the  stack  can  be  fetched  either  with  (!)  or  without  (S)  popping 
the  stack.  The  fetch  code  H  interprets  both  the  index  code  and 
the  dispose  code  and  the  hexadecimal  representation  of  a  byte 
and  outputs  it.  The  fetch  code  U  allows  generating  ten  sym¬ 
bols  unique  to  a  given  macro.  Tincmp  keeps  a  symbol  counter 
which  starts  at  100.  During  a  macro,  the  U  fetch  adds  the  in¬ 
dex  code  to  the  current  symbol  counter  to  return  a  symbol. 
Only  at  the  end  of  the  macro  is  the  symbol  counter  increased, 


Table  2 
Dispose  Codes 


and  then  by  the  maximum  index  used  during  the  macro, 
plus  one.  This  means  that  references  to  symbol  ‘0’  during  one 
macro  will  return  the  same  number.  It  is  intended  to  be  used 
for  generating  labels. 

Tincmp  requires  three  parameters  to  be  provided  in  IAV, 
the  global  vector  mentioned  above  in  describing  BEGINMAIN. 
These  give  the  starting  blocks  for  the  files  to  hold  (1)  the  mac¬ 
ros,  (2)  the  input  text,  (3)  the  output  text. 

That’s  what  Tincmp  does.  This  is  how  it  does  it:  the  sub¬ 
routine  IN  reads  the  flag  line  and  initializes  constants  and  vari¬ 
ables.  The  subroutine  RM  reads  the  macro  file,  loading  an  ar¬ 
ray  with  information.  The  information  is  stored  as  shown  in 
Table  3.  After  reading  the  macros,  the  input  is  read.  Each  line 
is  compared  to  each  template  in  turn  until  a  match  is  found,  or 
until  all  templates  have  been  checked.  If  no  match  is  found, 
the  line  is  written  out  unchanged.  If  a  match  is  found,  then  the 
subroutine  DM  interprets  the  replacement  text.  When  an  oper¬ 
ation  code  is  found,  the  next  three  characters  are  picked  up.  A 
branch  on  the  first  character  does  the  fetch  and  a  branch  on 
the  third  does  the  dispose. 

Tincmp  can  be  used  in  two  functionally  different  ways  to 
compile  Pidgin.  One  way  is  to  use  it  as  a  preprocessor  to  gener¬ 
ate  code  for  an  assembler.  The  other  way  is  to  run  it  three 
times  and  let  it  do  its  own  assembly.  The  first  way  may  have 
the  advantage  that  an  assembler  will  check  the  code  for  mis¬ 
sing  variables,  twice-defined  labels,  etc.  It  also  leads  to  simpler 
macros.  However,  I  found  when  I  tried  it  with  the  SCII  assem¬ 
bler  I  use,  that  it  was  slow  to  transfer  the  output  file  from 
Tincmp  into  the  assembler.  Also,  even  as  small  a  program  as 
Tincmp  expanded  into  23K  bytes  of  standard  assembler  code. 


Tahle  3 

Storage  of  Macros 

storage  of 

:T1;  COMMENTS 
Rl;  ALL 
:T2$;  ARE 
R2  PIC;  IGNORED 


P  Parameter 

Set  the  value  of  the  parameter  specified  by  the 

index 

ILP 

index 

LS 

index  code  to  the  fetched. 

0 

0 

0 

T 

1 

6 

1 

1 

S  Stack 

Increment  the  stack  pointer  and  store  the 

2 

17 

2 

fetched  on  the  stack. 

3 

A 

R 

1 

C  Character 

Write  the  low  byte  of  the  fetched. 

4 

5 

I 

6 

T 

H  High 

Write  the  high  byte  of  the  fetched. 

7 

2 

8 

$ 

N  Number 

Write  the  fetched  in  decimal  characters  without 

9 

leading  zeros.  (Default.) 

10 

R 

11 

2 

+  add 

Add  the  fetched  to  the  top  of  the  stack. 

12 

13 

P 

—  subtract 

Subtract  the  fetched  from  the  top  of  the  stack. 

14 

1 

15 

C 

*  multiply 

Multiply  the  top  of  the  stack  by  ten,  then  add 
the  fetched. 

16 

; 

Dr.  Dobb’s  Journal,  Number  57,  July  1981 


13 

285 


The  assembler  swallowed  this  (slowly),  but  a  slightly  larger 
file  would  have  to  be  cut  into  chunks,  which  would  be  quite 
cumbersome.  This  was  too  bad,  because  once  inside,  it  assem¬ 
bled  in  about  ten  seconds. 

The  other  way  requires  macros  that  are  difficult  to  under¬ 
stand,  but  it  gets  the  job  done  faster  for  me.  The  first  set  of 
macros  produces  an  intermediate  file  in  which  all  6502  instruc¬ 
tions  have  been  coded,  but  with  all  operands  left  on  single 
lines  following  the  instruction  codes.  The  first  set  of  macros  is 
thus  rather  like  machine  code.  The  second  set  of  macros  pro¬ 
duces  a  file  which  is  a  third  set  of  macros.  This  set  of  macros  is 
simpler  than  the  first,  because  its  most  frequent  task  is  just  to 
count  the  program  bytes.  The  third  set  of  macros  contains  the 
definitions  for  all  labels  and  variables.  When  the  third  set  of 
macros  is  used  on  the  intermediate  file,  the  completed  6502 
code  is  output.  I  have  included  macros  for  this  method  since  I 
have  found  it  more  useful. 

Using  the  macros  and  Tincmp  shown  here,  Tincmp  com¬ 
piles  itself  in  2  minutes  10  seconds  on  my  Apple  II.  This  is  50, 


Dti  Drag's  Journal 


Back 

Issues 

Available  for  $3.50 

IBM  PC,  it’s 
still  hot  news 


CP/M-86  vs.  MSDOS:  A  Technical  Comparison 

Our  author  sets  the  two  operating  systems  for  the  IBM 
Personal  Computer  head-to-head,  to  see  which  comes  out 
the  winner ! 

Word  Processors  for  the  IBM  Personal  Computer 

Reviewers  sample  some  of  the  latest  releases  in  this  ever- 
popular  application  of  computing  power. 

Video  Graphics  for  the  IBM  PC 
One  of  our  popular  writers  delves  into  the  details  (some 
not  clearly  documented  elsewhere)  of  high-resolution 
graphics.  This  advanced  material  is  carefully  introduced 
so  less  experienced  readers  won’t  be  lost. 

This  and  other  back  issues  are  available  for  $3.50 
from: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 


35,  and  45  seconds  for  the  three  passes.  The  disk  is  continu¬ 
ously  on  during  this  time,  so  I  believe  the  processing  time 
roughly  balances  the  input/output  time.  When  compiled,  the 
code  occupies  3.5K  bytes.  It  uses  4.7K  bytes  to  store  the  first 
and  larger  macro  set,  and  another  thousand  or  so  bytes  for 
buffers,  variables,  etc. 

In  making  these  macros  I  originally  tried  a  method  I’ve 
since  abandoned,  and  about  which  you  might  profit  by  a  warn¬ 
ing.  One  of  the  problems  with  having  two  sets  of  macros  is 
to  keep  the  same  targets  in  each,  with  compatible  definitions. 

I  thought  it  might  be  a  good  idea  to  start  from  a  single  file  and 
produce  these  two  sets  of  macros  from  it  by  using  two  other 
sets  of  macros.  It  worked,  but  had  two  problems  worse  than 
the  one  it  solved.  First,  it  was  confusing  keeping  several  dif¬ 
ferent  sets  of  special  characters  in  mind.  Second,  I  kept  having 
to  change  two  sets  of  macros  anyhow,  because  another  macro 
would  usually  bring  in  a  new  concept  and  therefore  a  new 
command.  The  macros  shown  here  evolved  from  such  a  pro¬ 
cess,  however,  and  have  some  traces  of  that  mechanical  pro¬ 
duction  remaining. 

In  my  view  macros  should  use  every  byte-saving  or  micro¬ 
second-saving  trick  known  to  programmers.  When  faced  with 
a  choice  of  time  or  space,  I’ve  usually  chosen  the  faster,  more 
space-consuming  macro.  If  you  can  code  any  of  the  Pidgin 
statements  with  a  saving  in  either  space  or  time  and  not  wor¬ 
sen  the  other,  I  would  be  glad  to  hear  about  it. 

Genealogy 

Tincmp’s  immediate  parent  is  SIMCMP,  described  by  W. 
Waite  in  Implementing  Software  for  Non-Numeric  Applica¬ 
tions.  SIMCMP  is  even  simpler  than  Tincmp,  having  in  essence 
exactly  three  kind  of  operation  codes  (UnN,  PnC,  VnN). 
With  these  much  simpler  codes,  Waite  defines  the  First  Lan¬ 
guage  Under  Bootstrap  (FLUB),  a  simpler  language  than  Pid¬ 
gin,  having  about  30  statements.  I  liked  the  approach  of 
SIMCMP  very  much,  but  FLUB  was  very  hard  to  write,  and  it 
seemed  that  I  would  need  to  write  a  variety  of  programs  in  the 
first  language  before  I  could  move  on  to  the  second.  (Like  an 
editor,  and  some  kind  of  executive.)  Pidgin  has  proved  conven¬ 
ient  enough  that  I  haven’t  yet  felt  like  I  had  to  get  a  better  lan¬ 
guage  going,  but  maybe  soon. 

Availability  in  Machine-Readable  Form 

The  program  and  macros  published  here  and  last  month 
give  you  a  long  start  in  implementing  Pidgin  on  your  system. 
If  you  want  to  save  yourself  some  typing,  and  can  transfer 
files  from  an  Apple  near  you,  you  may  be  interested  in  the 
following  offer.  An  experimental  operating  system  written  in 
Pidgin  is  available  from  the  author  for  software  experimenters. 
It  includes  Pidgin  and  6502  versions  of  Tincmp,  an  editor,  a 
tiny  executive,  some  utilities,  and  Pidgin  test  programs.  It  can 
now  be  run  on  Apple,  and  can  be  configured  for  1  through  4 
floppy  disk  drives,  using  13-  or  16-sector  disks.  It  requires 
a  16K  memory  board  or  an  Apple  II  (not  plus).  Two  disks 
and  documentation  are  available  for  $20.  A  third  disk  with 
Meta4,  the  compiler  generator  to  be  described  next  month, 
is  available  for  an  additional  $10.  If  you  are  reading  this  after 
1981,  better  write  to  check  availability.  You  can  write  me  at 
439  S.  Orange  Ave.,  S.  Orange,  NJ  07079.  ■  ■ 

LISTING  ON  PAGE  24 


14 

286 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


Time  on  the  Horizon 


Having  used  microcomputers  heavi¬ 
ly  for  over  three  years  now,  I 
am  firmly  of  the  opinion  that 
they  are  the  solutions  to  many  problems 
yet  to  be  posed.  With  respect  to  both 
hardware  and  software,  their  versatility 
is  Limited  only  by  the  mind  of  the  user. 
The  ability  to  interface  a  microcomputer 
to  the  outside  world  through  more  con¬ 
ventional  instrumentation  makes  them 
particularly  useful  experimental  tools.  In 
my  own  teaching  and  research,  interfaces 
to  measuring  instruments  are  particular¬ 
ly  important  in  the  study  of  biological 
and  related  physical  processes. 

Most  of  the  instrumentation  used 
produces  potentiometric  output  in  vari¬ 
ous  millivolt  ranges  up  to  about  one  volt, 
although  some  digital  signals  are  also  pro¬ 
duced.  In  addition,  in  some  circumstances 
there  is  the  need  to  control  experimental 
conditions  with  analog  or  digital  output 
from  the  microcomputer. 

One  of  the  commonest  requirements 
of  a  system  when  measurement  and  con¬ 
trol  are  required  is  for  a  means  of  time¬ 
keeping.  Sampling  and  or  control  is  usu¬ 
ally  on  the  basis  of  either  time  of  day  or 
of  time  elapsed  since  a  particular  event. 
This  requires  either  a  peripheral  or  in¬ 
built  clock  to  which  the  software  has  ac¬ 
cess  in  one  way  or  another.  In  some  ap¬ 
plications  this  may  in  fact  be  in  the  meas¬ 
uring  instrument  itself.  Generally,  how¬ 
ever,  such  is  not  the  case  and  the  micro¬ 
computer  must  provide  its  own  time  base. 
This  article  describes  a  simple  “software” 
clock  for  use  in  a  microcomputer  with 
the  most  elementary  internal  clock. 

Peripherals  are  available  for  many  of 
the  popular  microcomputers  to  provide 
them  with  a  real-time  clock  and  perhaps 
even  a  calendar  as  well.  Most  microcom¬ 
puters  include  their  own  “clock”  which  is 
available  to  the  programmer.  This  clock 
varies  in  sophistication  from  a  simple  flag 
which  is  set  by  hardware  at  a  predeter¬ 
mined  interval  after  being  reset,  to  a  soft¬ 
ware  function  which  returns  time  of  day 
(hours,  minutes,  seconds  and  perhaps 
fractions  of  a  second)  when  accessed  any 
time  after  initialization  at  power-on.  This 
latter  type  of  clock  is  clearly  the  most 


by  D.  J.  Yates 


Dr.  D.  J.  Yates,  Botany  Department,  Uni¬ 
versity  of  Queensland,  St.  Lucia  4067, 
Queensland,  A  ustralia. 


generally  useful,  particularly  if  it  pro¬ 
vides  1/10  second  accuracy  or  better  (e.g. 
the  PET  T1  and  TI$  facilities).  It  would 
seem  that  such  a  feature  should  be  a  ba¬ 
sic  requirement  in  an  operating  system 
and  higher  level  languages.  Apparently 
this  type  of  ‘software-accessible-time-of- 
day-clock’  is  not  yet  available  in  many 
microcomputers  as  a  standard  feature, 
although  a  number  possess  more  primi¬ 
tive  ‘clocks’.  The  most  primitive  compo¬ 
nent  of  a  clock  is  hardware  and  obvious¬ 
ly  the  diversity  of  hardware  implementa¬ 
tions  precludes  simple  standardization  of 
the  software  clock.  On  the  other  hand, 
with  many  of  the  larger  microcompu¬ 
ters  being  used  in  business  applications,  it 
would  seem  that  such  a  software  clock 
would  be  fairly  high  on  a  priority  list  of 
the  users. 

In  the  North  Star  Horizon,  the  clock 
consists  of  a  flag  which  goes  “high”  at  a 
specified  interval  after  being  reset.  This 
interval  is  under  hardware  “control.” 
That  is,  a  header  on  the  motherboard 
may  be  jumpered  to  provide  one  of  a 
selection  of  clock  intervals  between 
3.328  milliseconds  and  3.328  x  213 
milliseconds  (about  27  seconds).  The 
state  of  the  clock  flag  may  be  read  as 
the  second  bit  of  the  motherboard 
status  byte.  Implementation  of  a  time 
function  in  machine  code  on  the  Horizon 
would  not  be  particularly  difficult  and  it 
is  a  little  surprising  that  North  Star  have 
not  done  so,  particularly  considering  the 
general  excellence  of  the  hardware  and 
software  they  provide. 

The  task  of  writing  a  BASIC  routine 
or  function  to  keep  track  of  either 
elapsed  time  or  time  of  day  is  a  simple 
matter  and  Listing  1  is  that  of  a  program 
including  a  subroutine  which  returns  the 
time  of  day  (since  midnight)  in  hours, 
minutes  and  (whole)  seconds  and  also  as 
total  elapsed  seconds  since  initialization. 

Statements  370-410  of  the  main  pro¬ 
gram  calculate  the  time  interval  to  be 
used  in  calculations.  It  is  based  on  the 
product  of  the  primary  clock  interval 
(3.328  milliseconds)  and  a  power  of  two 
which  depends  upon  the  value  J.  The  val¬ 
ue  of  J  is  equal  to  the  pin  number  to 
which  the  clock  is  jumpered  on  the 
Clock  Rate  header  on  the  Horizon  moth¬ 
erboard.  Obviously,  this  value  is  fixed 
once  the  header  is  wired.  The  input  of 
time  in  line  450  allows  time  keeping  from 
the  time  of  running  the  program.  Imme¬ 
diately  the  time  is  entered,  the  clock 
flag  is  reset  by  the  OUT  6,  80  instruction 


(statement  460). 

The  time  subroutine  (statements 
570-770)  returns  with  Z9  =  0  if  the  clock 
flag  is  not  set.  If  the  clock  flag  is  set  then 
T9  is  incremented  by  the  clock  interval 
and  on  the  basis  of  T9,  the  time  of  day  is 
calculated  with  seconds  being  rounded  to 
the  nearest  whole  second.  On  return  to 
the  main  program,  the  time  is  printed. 
Such  a  program  could  test  the  value  of 
Z9  (or  H,  M  or  S)  and  at  the  appropriate 
item  execute  relevant  code.  In  the  exam¬ 
ple,  statement  510  causes  a  transfer  back 
to  the  call  to  the  time  subroutine.  Numer¬ 
ous  variations  are  possible.  For  example, 
the  major  portion  of  the  program  may  be 
executed  only  after  a  specified  period 
(e.g.,  10  seconds  or  3  minutes)  had 
elapsed. 

In  the  field  of  biology  it  is  often  dif¬ 
ficult  to  automate  measurements  of  the 
various  parameters  which  may  be  of  in¬ 
terest.  In  the  case  of  the  measurement 
of  the  growth  of  grass  leaves  it  is  some¬ 
times  possible  to  use  a  Unear  variable  dis¬ 
placement  transformer  (LVDT)  to  trans¬ 
form  the  vertical  movement  of  a  leaf  tip 
as  it  grows  into  a  DC  voltage  which  may 
be  monitored  by  a  computer.  Clearly 
there  must  be  a  time  base  if  growth  rate 
is  to  be  calculated  from  changes  in  leaf 
length. 

Figure  1  represents  the  basic  flow 
chart  of  a  program  which  uses  a  timing 
routine  similar  to  that  in  Listing  1.  The 
experimental  set-up  consisted  of  an 
LVDT  connected  by  way  of  a  beam  and 
knife-edge  pivot  to  a  young  maize  leaf 
tip.  When  the  leaf  grew  (upwards)  the 
core  of  the  LVDT  moved  down  through 
the  body  of  the  LVFT  and  the  resulting 
DC  signal  was  monitored  via  an  A-to-D 
converter  by  the  computer.  Reading  of 
the  analog  signal  occurred  only  after  the 
clock  flag  had  been  set.  Under  normal 
conditions,  growth  rate  was  calculated 
and  appropriate  output  performed  before 
returning  to  the  call  to  the  clock  routine. 

The  software  and  hardware  included 
provision  for  handhng  both  positive  and 
negative  over-range  signals.  In  the  case  of 
a  signal  being  too  high  (i.e.  the  leaf  had 
not  grown  sufficiently  for  the  signal  to 
come  on  to  scale)  the  program  looped 
back  to  the  caU  to  the  clock  routine  until 
the  voltage  had  decreased  to  within  al¬ 
lowable  Umits.  If  this  did  not  occur  with¬ 
in  a  reasonable  time  (e.g.,  10  minutes), 
then  the  program  would  abort  with  ap¬ 
propriate  output.  If  on  the  other  hand 
the  leaf  grew  to  such  an  extent  that  the 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


15 

287 


Dr.  Dobb’s  Journal,  Number  57,  July  198 1 


other  limit  of  the  LVDT  was  reached,  the 
software  actuated  a  stepping  motor  at¬ 
tached  to  a  micrometer  head  which  re¬ 
positioned  the  pivot  point  of  the  beam 
and  in  so  doing,  raised  the  core  of  the 
LVDT  to  the  other  end  of  its  range. 
After  re-adjustment  to  a  preset  limit, 
control  returned  to  the  main  program. 

In  this  application,  the  clock  period 
used  was  about  13.63  seconds  (actually 
13.631488  seconds!)  over  which  time 
measurable  growth  of  a  young  maize  leaf 
occurred.  This  period  was,  in  fact,  the 
period  after  which  measurement  of 
leaf  growth  was  made,  although  measure¬ 
ments  could  be  performed  after  some 
other  period  had  elapsed  merely  by  loop¬ 
ing  until  the  period  had  passed. 

In  using  the  approach  outlined  here 
to  provide  a  BASIC  program  with  a  tim¬ 
ing  facility,  one  potential  problem  soon 


becomes  apparent.  If  the  code  to  be  exe¬ 
cuted  after  a  specified  time  always  (or 
worse,  sometimes)  takes  longer  to  exe¬ 
cute  than  the  clock  interval,  then  the 
timekeeping  ability  of  the  software  is  en¬ 
tirely  lost.  This  is  because  the  software 
cannot  know  when  the  clock  flag  was  set, 
but  just  if  it  is  set;  and  unless  it  looks  at 
the  clock  flag  immediately  after  it  is  set 
(i.e.,  before  it  would  be  set  again)  it  loses 
track  of  time.  (This  indicates  too,  that 
the  loop  which  examines  the  clock  flag 
should  be  fairly  “tight”  and  should  be  at 
low-line  numbers  so  that  there  is  the  min¬ 
imum  of  time  wasted  by  GOTO’s.)  It 
is  essential  in  writing  the  software  and,  in 
the  case  of  the  Horizon,  in  hardwiring  the 
clock  header,  that  the  longest  interval 
between  any  successive  “looks”  at  the 
clock  flag  is  less  than  the  clock  interval. 
This  of  course  means  that  the  minimum 


time  resolution  is  the  clock  period  and 
that  any  shorter  periods  are  not  resolva¬ 
ble. 

A  further  problem  is  that,  at  the 
least,  a  program  has  to  explicitly  call  a 
subroutine  in  order  to  keep  the  clock  on 
time.  In  addition,  every  program  must 
re-initialize  the  clock  and  contain  a  sub¬ 
routine  such  as  that  in  Listing  1 .  On  the 
other  hand,  there  are  many  uses  for  such 
a  simple  software  clock  and  in  some  situ¬ 
ations  (e.g.,  timing  of  users’  response  to 
questions)  it  may  only  require  intervals 
to  be  timed  and  thus  require  no  initiali¬ 
zation  other  than  an  initial  reset  of  the 
clock  flag. 

It  may  seem  a  relatively  simple  task 
for  a  user  to  write  a  machine-code  routine 
to  perform  the  clock  functions  and  to 
keep  a  log  of  current  time  in  (say)  several 
spare  memory  locations.  In  the  North 
Star  DOS  (and  BASIC)  this  could  be  done 
perhaps  by  having  the  routine  called  from 
the  character-in,  character-out  and  con- 
trol-C  routines.  Such  a  scheme  works 
because  the  largest  delays  in  the  execu¬ 
tion  of  a  program  occur  when  it  is  waiting 
for  keyboard  input  or  waiting  for  an  out¬ 
put  or  waiting  for  an  output  device  to 
accept  output  data.  As  the  control-C 
routine  is  called  after  executing  every 
BASIC  statement,  placing  a  call  to  a  time 
routine  within  it  will  ensure  frequent 
calls.  For  a  program  without  disk  access, 
this  is  probably  satisfactory  as  long  as  in¬ 
dividual  statements  do  not  take  exces¬ 
sively  long  periods  to  execute  (for  exam¬ 
ple,  calls  to  other  user  machine  code  rou¬ 
tines).  However,  when  disk  activity  is 
involved,  considerable  periods  (e.g.,  from 
tenths  of  seconds  to  several  seconds)  may 
be  involved  while  buffers  are  filled  or 
emptied.  To  overcome  such  a  problem 
involves  placing  calls  to  the  time  routine 
within  the  more  primitive  disk  access 
routines  of  the  DOS.  I  have  not  attemp¬ 
ted  to  do  this  but  the  OFTEN  routine 
which  is  now  provided  for  in  the  North 
Star  DOS  would  appear  the  logical  place 
to  start.  Perhaps  North  Star  Computers 
themselves  will  provide  a  good  clock  for 
their  future  software  releases  for  the  Hor¬ 
izon.  The  hardware  component  could 
conceivably  even  be  included  on  the  disk 
controller  board  and  thus  be  available  to 
all  (future)  North  Star  users.  In  the  mean¬ 
time,  someone  else  might  like  to  put 
these  ideas  into  practice  and  publish  them 
in  these  pages.  ■  ■ 

LISTING  ON  PAGE  18 


‘‘The  system  statistics  show  ...  6%  accounts  receivable,  23%  inventory 
control  and  71%  Star  Trek!” 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


17 

289 


TIME  ON  THE  HORIZON 


10  REM 
20  REM 
30  REM 

40  REM  This  Program  and  Subroutine  allow  real  timing  using  the 
50  REM  HORIZON  Real  Time  CLOCK  and  the  Motherboard  Status  Byte. 

60  REM 

70  REM  The  program  first  sets  the  motherboard  CLOCK  FLAG  then  cycles 
80  REM  until  it  is  set  again.  The  CLOCK  interval  is  set  according  to 
90  REM  the  instructions  on  Page  75  of  the  HORIZON  construction  manual. 

100REM 

110REM 

120REM  BY  Dr.  David  Yates 

130REM  Botany  Department, 

140REM  University  of  Queensland, 

150REM  St  Lucia,  4067 

160REM  QUEENSIAND,  Australia. 

170REM 

180REM  Initially,  period  is  1.7039  seconds  (i.e.J=5) 

190REM  and  changes  require  both  jumper  and  software  modification. 

200 REM  H  IS  HOURS 

210REM  M  IS  MINUTES 

220REM  S  IS  SECONDS 

230REM  T9  IS  TOTAL  SECONDS  SINCE  12  O'CLOCK 
240  REM 

250REM  V  is  CLOCK  interval  set  according  to  HORIZON  Manual  (p  75) 

260REM  J  is  pin  jumpered  to  pin  13  on  the  14  pin  DIP  header  at  location  10A 
270REM  on  the  HORIZON  Motherboard. 

280 REM  R  is  the  power  of  2  used  in  calculating  the  clock  interval 

290REM 

300REM 

310  REM 

320  DEF  FNB(B,P)=INT(B/2"P)/2<>INT(IOT(B/2*P)/2)  \REM  Returns  Pth  bit  of  B 

330  REM 

340REM 

350REM 

360REM 

370  J=5  \REM  Set  pin  no.  ***N0TE  For  most  applications  this  will  be  1,2, 3, 4,  or  5  *** 
380  V=3.328  \REM  Basic  CLOCK  interval  in  milliseconds 
390  IF  J>11  THEN  450  \REM  J=12  (Cannot  be  13) 

400  R=14-J  \FEM  Power  of  2 
410  V=V*2"R  \REM  Calculate  V 
420 REM 

430REM*** **************** ************************* 

440REM 

450  INPUT  WHAT  IS  TIME  (H,M,S)  ?  ",H,M,S 

460  OUT  6,80 

470  GOSUB  570  \REM  CALL  TIME  ROUTINE 

480  IF  Z9=l  THEN  PRINT  "  TIME  IS  ",  H,"  HRS",M,"  MINS",S,"  SEC" 

490REM  Place  program  here 
500REM  Place  program  here 
510  QOT0470 
520  END 
530REM 

540REM******************************************** 

550REM 

560REM 

570REM  Routine  checks  CLOCK  flag  and  increments  time  if  high 

580REM 

590REM 

600  Z9=0  \REM  Z9  returned  as  0  if  flag  is  low 
610  IF  FNB(INP(6)  ,2)=0  THEM  RETURN  \REM  Flag  low 
620  OUT  6,80 

630  Z9=l  \REM  Flag  was  high 
640  T9=T9+V/1C00 
650  M=IOT(T9/60) 

660  H=INT(T9/36C0) 

670  M=IOT ( ( T9-H*  3600 ) /60 ) 

680  S=T9-H*360C-M*60 
690  S=INT ( S+ . 5 ) 

700  RETURN 
710  END 


18 

290 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


BASIC  Rubik’s 
A  Cube  Simulator 


Magic  Cubes,  also  known  as  Rubik’s 
Cubes,  have  become  the  hottest 
plastic  toy  since  the  “Hula  — 
Hoop”  of  the  60’s.  The  cube,  Buvos 
Kocka  in  the  Hungarian  of  its  inventor,  is 
more  than  a  toy,  however.  Mathemati¬ 
cians,  computer  scientists  and  artificial 
intelligence  students  the  world  over  have 
taken  to  “The  Cube”  as  an  example  of  a 
basic  mathematical  problem,  an  exercise 
in  group  theory,  and  even  as  a  parallel  to 
particle  physics.  For  those  readers  not  yet 
smitten  by  “cubitis,”  I  suggest  reading 
Douglas  Hofstadter’s  “Metamagical  The- 
mas”  column  in  Scientific  American, 
March  1981.  Although  claiming  to  be  a 
mere  “cubist,”  Hofstadter  presents  a 
thorough  description  of  both  the  mech¬ 
anical  inner-workings  of  the  cube  and  the 
logic  fundamentals  involved  in  any  seri¬ 
ous  discussion  of  the  subject.  David 
Singmaster,  an  acclaimed  “cubemeister” 
and  professor  of  mathematical  sciences 
and  computing  at  the  Polytechnic  of  the 
South  Bank  in  London,  has  studied  the 
cube  thoroughly  and  is  the  author  of 
Notes  on  Rubik’s  Magic  Cube,  available 
soon  from  Enslow  Publishers  of  Hill¬ 
side,  N.J.,  at  $5.95. 

Having  been  introduced  to  the  cube 
by  my  son,  a  Stanford  computer  science 
student,  1  quickly  discovered  the  fasci¬ 
nation  with  the  device  which  has  led  to 
formation  of  Cubie  Clubs  at  several  uni¬ 
versities.  Further  thought  on  the  matter 
led  me  to  conclude  that  before  attacking 
the  various  theories  involved  in  solving 
the  cube  problem,  a  tool  for  exploring 
moves  would  be  convenient.  A  few  hours 
with  the  home  computer  resulted  in  cre¬ 
ation  of  the  program  BASIC  RUBIK’S, 
a  cube  simulator.  The  program  should 
run  on  any  computer  handling  simple 
Basic  statements,  requiring  only  that 
you  adapt  the  printer  output  routine  to 
your  particular  system.  Should  you  use  a 
printer  as  the  console  output  device, 
even  this  requirement  could  be  elimina¬ 
ted,  although  you  may  wish  to  lay  in  a 
good  supply  of  printer  paper.  You  will, 
no  doubt,  suffer  a  severe  case  of  at 
least  third  degree  cubitis,  and  soon  be 
swamped  in  printout. 


by  J.  W.  Pehoushek 


J.  W.  Pehoushek,  6038  Crittenden  Dr., 
Cincinnati,  OH  45244 


I  have  chosen  to  follow  the  sugges¬ 
tions  of  Hofstadter  and  Singmaster  in 
using  the  notation  Left,  Right,  Front, 
Back,  Up  and  Down  to  identify  the  six 
faces.  The  center  facelets  in  each  face  are 
labeled  L,  R,  F,  B,  U  and  D.  On  the  actu¬ 
al  cube  these  center  facelets  remain  in  a 
fixed  position  relative  to  each  other.  Sim¬ 
ilarly,  in  BASIC  RUBIK’S  the  center 
facelets  are  fixed  and  the  representation 
of  the  patterns  are  keyed  to  these  posi¬ 
tions.  Since  it  is  not  possible  to  clearly 
show  the  position  of  each  facelet  in  a  sin¬ 
gle  two-dimensional  printed  image,  I’ve 
chosen  to  use  the  two  views  shown  in  Fig. 
1.  You  may  either  let  the  computer  ar¬ 
range  the  starting  position  as  shown  in 
Fig.  1 ,  or  you  may  enter  your  own  begin¬ 
ning  arrangement. 

I  make  no  claims  to  elegance  in  pro¬ 
gramming,  and  as  an  engineer  am  more 
interested  in  the  utility  of  the  result. 
The  basic  principle  of  the  simulator, 
however,  may  be  of  interest  to  you.  At 
line  1590  a  square  matrix  of  size  5x5  is 


created  for  each  face.  The  center  3x3 
sub-matrix  represents  the  actual  nine 
facelets  of  any  given  face.  The  remaining 
border  elements  (row  1,  row  5,  column  1 
and  column  5)  represent  the  edges  of  the 
face  plane  located  on  adjacent  faces,  ig¬ 
noring  the  matrix  comers. 

Stored  in  each  element  of  a  face  ar¬ 
ray  during  initialization  are  the  ASCII 
numeric  value  of  the  letter  for  that  face- 
let.  Rotations  of  a  face  are  simply  ac¬ 
complished  by  performing  two  sequen¬ 
tial  matrix  operations,  a  transpose  and  a 
column  switch.  A  transpose  of  a  matrix 
is  performed  by  moving  all  elements  in 
row  1  to  column  1,  all  elements  in  row 
2  to  column  2,  etc.  The  column  switch 
operation  is  performed  by  swapping  col¬ 
umn  1  with  column  5,  column  2  with 
column  4,  and  leaving  column  3  un¬ 
touched.  Performing  a  transpose  followed 
by  column  switch  rotates  the  matrix  90 
degrees  CW,  and  a  column  switch  fol¬ 
lowed  by  transpose  rotates  CCW.  These 
routines  are  at  lines  3940  and  4000,  and 


Dr.  Dobb’s  Journal,  Number  57,  July  198  1 


19 

291 


have  been  combined  into  one  FOR  -  -  - 
NEXT  loop  for  each. 

The  program  allows  users  to  enter 
commands  which  rotate  an  entire  face 
by  90  degrees.  Clockwise  rotations  are 
prefixed  with  a  “+”  sign.  Commands  are 
prompted  by  the  phrase: 

COMMAND =? 

Commands  must  be  entered  one  at  a 
time,  although  since  each  command  re¬ 
quires  a  second  or  two  to  execute,  you 
may  type  in  several  commands  each  fol¬ 
lowed  by  a  carriage  return,  if  your  com¬ 
puter  has  a  large  enough  type-ahead  buf¬ 
fer.  A  command  “+F”,  followed  by 
L”,  would  result  in  the  positions 
shown  in  Fig.  2. 


The  commands  “V”  and  “P”  causes 
display  of  cube  positions  on  your  video 
or  printer  device.  When  the  “P”  com¬ 
mand  is  selected,  a  list  of  all  previous 
commands  executed  since  the  last  print¬ 
out  is  also  printed.  Additionally,  this  list 
is  printed  along  with  a  view  of  cube  posi¬ 
tions  after  every  tenth  command.  This  al¬ 
lows  you  to  keep  track  of  how  you  ar¬ 
rived  at  each  position.  You  will  find  this 
feature  handy  as  you  wend  your  way 
through  Rubik’s  intricacies.  It  is  simply 
not  possible  to  keep  track  of  all  the 
possible  moves. 

The  commands  “M”  and  “R”  are 
used  to  memorize  and  recall  arrange¬ 
ments  from  memory.  At  any  time,  when 
command  M  is  entered,  a  snapshot  of 
the  current  arrangement  is  saved,  over¬ 
writing  any  previously  saved  arrange¬ 


ment.  When  this  is  done,  all  moves  since 
the  last  printout  and  a  view  of  the  ar¬ 
rangements  are  printed.  When  command 
R  is  entered  the  saved  arrangement  is 
recovered  and  becomes  the  new  current 
position.  Moves  since  last  printout  are 
lost.  This  memory  recall  feature  lets  you 
explore  moves  “safely.” 


LISTING  ON  PAGE  34 


20 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


Moves  since  last  printout: 


u 

u 

u 

u 

u 

u 

u 

U 

u 

u 

U 

u 

u 

u 

u 

u 

u 

u 

1  1 

1 

f 

f 

f  r 

r 

r 

r 

r 

r 

b 

b 

b 

1 

1 

1 

1  L 

1 

f 

F 

f  r 

R 

r 

r 

R 

r 

b 

B 

b 

1 

L 

1 

1  1 

1 

f 

f 

f  r 

r 

r 

r 

r 

r 

b 

b 

b 

1 

1 

1 

d 

d 

d 

d 

d 

d 

d 

D 

d 

d 

D 

d 

d 

d 

d 

d 

d 

d 

Moves  since  last  printout: 

3R  - 

L  +U 

-D  +F  +F  -B  -B  +L 

-D 

1 

b 

b 

b 

b 

1 

u 

U 

u 

u 

U 

u 

1 

b 

b 

b 

b 

1 

u  r 

u 

b 

r 

r  d 

b 

d 

d 

b 

d 

1 

1 

f 

u 

r 

u 

f  L 

f 

u 

F 

d  1 

R 

1 

1 

R 

1 

u 

B 

d 

f 

L 

f 

u  r 

u 

b 

r 

r  d 

b 

d 

d 

b 

d 

1 

1 

f 

u 

r 

u 

r 

f 

f 

f 

f 

r 

d 

D 

d 

d 

D 

d 

r 

f 

f 

f 

f 

r 

Moves  since  last  printout: 

+B  +F 

d 

1 

f 

u 

f 

r 

u 

U 

u 

u 

U 

u 

r 

f 

u 

f 

1 

d 

b  r 

f 

d 

u 

b  1 

b 

r 

1 

b 

r 

u 

u 

1 

b 

r 

f 

b  L 

d 

b 

F 

r  b 

R 

d 

b 

R 

d 

r 

B 

1 

b 

L 

d 

1  r 

f 

d 

d 

r  b 

1 

r 

b 

1 

r 

u 

d 

f 

1 

r 

f 

1 

1 

d 

b 

f 

u 

f 

D 

f 

f 

D 

f 

u 

f 

b 

d 

1 

1 

The  arrangement  above  has  been  saved. 

Moves  since  last  printout: 

+D  -B  +U 

-L 

1 

u 

u 

b 

u 

1 

b 

U 

b 

b 

U 

b 

1 

u 

b 

u 

u 

1 

b  d 

f 

u 

b 

d  1 

1 

r 

1 

1 

r 

b 

r 

u 

b 

d 

f 

u  L 

d 

f 

F 

r  b 

R 

1 

b 

R 

1 

u 

B 

f 

u 

L 

d 

d  f 

d 

r 

r 

f  d 

d 

f 

d 

d 

f 

u 

r 

r 

d 

f 

d 

b 

f 

1 

r 

d 

f 

1 

D 

1 

1 

D 

1 

f 

d 

r 

1 

f 

b 

The  following  arrangement  has  been  restored. 

Moves  since  last  printout: 

d 

1 

f 

u 

f 

r 

u 

U 

u 

u 

U 

u 

r 

f 

u 

f 

1 

d 

b  r 

f 

d 

u 

b  1 

b 

r 

1 

b 

r 

u 

u 

1 

b 

r 

f 

b  L 

d 

b 

F 

r  b 

R 

d 

b 

R 

d 

r 

B 

1 

b 

L 

d 

1  r 

f 

d 

d 

r  b 

1 

r 

b 

1 

r 

u 

d 

f 

1 

r 

f 

1 

1 

d 

b 

f 

u 

f 

D 

f 

f 

D 

f 

u 

f 

b 

d 

1 

1 

This  publication 
is  available 
in  microform. 


■»  .  IH«  IW  tk-i  11  1l 

■in  M3  m  .1 

■  iHMin  MWUB 


University  Microfilms 
International 


Please  send  additional  information 
for _ 

Name _ 


Institution 
Street _ 


City _ 

State _ Zip 


300  North  Zeeb  Road  30-32  Mortimer  Street 
Dept.  PR.  Dept.  PR. 

Ann  Arbor.  Mi.  48106  London  WIN  7RA 
U.SA.  England 


Dr.  Dobb’s  Journal,  Number  57,  July  198  1 


21 

293 


j.7/0,  me  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 

Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 

Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


r 

YES!  Enter  my  subscription  to  Dr.  Dobb's  Jour¬ 
nal  and  bill  me  later. 

$25 

name 

one  year  subscription 

12  issues 

address 

saves  $5  off  the  newsstand  price 

city  state  zip 

Mail  to:  DDJ,  P.O.  Box  E., 

Menlo  Park,  CA  94025 

Why  wait 
to  start 

increasing  your  sales? 
Call  now 
to  reserve 
advertising  space 
in  the  next 
Dr  Dobb’s  Journal 
(415)323-3111 


Letters  (Continued  from  page  9) 

human  custom  of  naming  something  after 
a  man  who  did  not  invent  it.  There  are,  as 
far  as  I  know,  three  kinds  of  logarithms: 
Naperian,  Briggsian,  and  Gaussian.  Of  the 
three  only  the  second  bears  the  inventor’s 
name. 

I  can’t  agree  with  his  remarks  about 
the  use  of  e  in  computation.  The  fact 
that  ln(-l)  =  i*7r  is  certainly  remarkable, 
but  has  nothing  to  do  with  the  argument. 
Any  compendium  of  mathematical  series 
(e.g.  Ref.  1)  will  show  a  number  of  series 
used  for  computing  logarithms,  and  invar¬ 
iably  the  result  is  the  Naperian  variety. 
(That  reference  calls  it  the  ‘log’.)  The 
algorithm  used  for  computing  logarithms 
in  the  HP  calculators  (see  Ref.  2)  and,  I 
suspect,  in  most  computer  programs,  is 
based  on  ‘e’;  in  fact,  I  don’t  know  that 
there  is  any  other  way  to  accomplish  this 
computation. 

To  attempt  to  find  the  ‘true’  mean¬ 
ing  of  many  technical  words  and  symbols 
is  a  hopeless  effort.  It  often  doesn’t  exist! 
The  late  Dr.  Percy  Bridgman  of  Harvard  is 
quoted  as  having  said,  “For  of  course 
the  true  meaning  of  a  word  is  to  be  found 
by  observing  what  a  man  does  with  it,  not 
what  he  says  about  it.”  If  we  try  to  apply 
this  principle  to  find  the  “true”  meaning 
of  abbreviations  like  LOG,  LN,  EXP  and 
so  on,  we  find  that  there  is  none!  Every¬ 
one  has  his  own  preference!  The  BASIC 
program  on  my  computer  uses  LOG  to 
mean  the  natural  logarithm,  my  HP  calcu¬ 
lator  calls  this  LN,  and  uses  LOG  to  mean 
“log-to-the-base-10”,  the  TI  calculator 
uses  “lnx”  and  “log”  respectively  to 
mean  the  same  things!  All  this  confusion 
makes  it  necessary  for  any  conscientious 
author  who  uses  such  abbreviations  to  de¬ 
fine  them  in  the  book  or  article  he  writes. 
This  is  the  only  way  to  make  sure  that 
the  reader  knows  the  meaning  that  is  in¬ 
tended. 

As  regards  the  Decibel,  I  am  con¬ 
vinced  that  very  few  worthwhile  concepts 
have  ever  been  so  completely  misunder¬ 
stood,  misused  and  generally  maltreated. 
For  more  than  fifteen  years  I  have  been 
trying  to  find  some  way  to  help  this  situ¬ 
ation.  I  have  written  a  book  (unpub¬ 
lished)  and  no  less  than  ten  articles  (some 
published,  see  Ref.  3  and  4),  N-Logs 
being  my  latest  in  this  long  history  of 
“Windmill-Tilting.”  The  reader  would  run 
out  of  patience,  and  the  editor  out  of 
space  if  I  attempted  to  list  here  all  of  the 
horrible  sins  that  are  committed  in  the 
use  of  decibels,  logarithms  and  expo¬ 


nents.  Perhaps  a  few  final  comments 
would  be  in  order. 

One  usage  that  is  particularly  annoy¬ 
ing  is  the  use  by  computer  engineers  of 
the  words  “characteristic”  and  “mantis¬ 
sa.”  For  several  hundred  years  these 
words  have  been  used  to  denote  the 
part  of  a  logarithm  to  the  left,  and  to  the 
right  of  the  decimal.  With  all  the  words  in 
the  world  to  choose  from  why  must  we 
redefine  them  as  parts  of  an  exponential 
number?  As  if  this  weren’t  bad  enough, 
the  experts  don’t  agree.  Peter  Stark  says 
(in  Ref.  5),  “Each  number  in  a  computer 
must  be  divided  into  two  parts:  one  part 
(called  the  mantissa)  which  gives  the  di¬ 
gits  in  the  number,  and  a  second  part 
(called  the  characteristic  or  exponent) 
which  provides  information  about  the 
number’s  relative  size.”  Rodney  Zaks,  in 
Ref.  6,  referring  to  the  number  1.0E+2 
says,  “1.0  is  called  the  mantissa  or  charac¬ 
teristic,  and  the  number  following  the  E 
is  called  the  exponent.”  I  suggest  we  call 
the  first  part  the  multiplier,  and  the  ex¬ 
ponent  just  that,  then  we’ll  understand 
each  other  a  little  better,  besides  agree¬ 
ing  with  Noah  Webster  and  several  thou¬ 
sand  mathematics  textbooks! 

Finally  I’d  like  to  put  the  blame  for 
all  this  confusion  about  logarithms  right 
where  I  think  it  belongs  —  in  the  class¬ 
room.  Almost  everyone  who  suffered 
through  the  standard  course  in  Trigo¬ 
nometry,  which,  for  no  earthly  reason, 
always  included  Logarithms,  finished 
with  the  confirmed  conclusion  that  the 
whole  mess  was  too  complicated  to  bo¬ 
ther  with,  and  forgot  about  it  as  soon  af¬ 
ter  the  final  exam  as  possible! 

Kenneth  A.  Simons 
2035  Willowbrook  Drive 
Huntingdon  Valley,  PA  19006 

■  ■ 

References: 

1  B.  O.  Pierce,  “A  Short  Table  of  Integrals”, 
Third  Ed.,  pp.  90-91. 

2  William  E.  Egbert,  “Personal  Calculator  Algo¬ 
rithm  IV:  Logarithmic  Functions”,  In  Hew¬ 
lett-Packard  Journal,  April  1978 

3  K.  A.  Simons,  “The  dB  Anything”,  Proc. 
IEEE(Lett.),  Vol.  61,  pp.  495496 

4  Comments  following  Chester  H.  Page,  “Loga¬ 
rithmic  Quantities  and  Units”,  Proc.  IEEE 
(Lett.),  Oct.  1973,  pp.  1516-1517 

5  Peter  A.  Stark,  “Computer  Programming 
Handbook”,  TAB  Books,  No.  752,  p.  319 

6  Rodnay  Zaks,  “Introduction  to  PASCAL”, 
Sybex,  Second  Edition,  p.  35 


22 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 

295 


(Text  on  pages  10-14) 


CJ  CJ  CJ 

VC  rsl 

a  a  a 

•«■<  - . . 

it.  cj  it,  cj  «s  rs  <n  tu  vr  c 

<  CO  CJ  m  b_.  B  <  [l  CO  H 

xxxxxxxxxx 


•»<U.<ncji/iflJ®<isocH 
<^xxxaxaxxxxxrv 
VH  <<<<<(«/»<  , 


f^DuiriCJVClcjSOJCsiBJVCCJ 

•k<x<mcjmoK5<isoo.-i 

<^>xxxxxxxxxxxx 

vm  <<<•<<<<<(  < 


%  •*  •» <  •«<  .*  .«  «%  •«  ,, ,  t%  ,  # 

}  s  in  CJ  in  CJ  ts  cm  CM  U.  vr  cj  </>  cm  s'  s  < 
:®  <  in  0  co  o  is  <  u,  co  </>  <  I  5  S 

rxxxxxxxxxxx  *— *  x  x  x  x 


^  U  m  u 
w  in  oo  h 

x  a  x  a 


„ 

CJ  CJ 

CM  CM 

CJ 

cj 

CM 

a 

a 

CJ  CJ 

•*■  < 

CJ 

VC  CJ 

u  n  s  m  [j  q, 

•—* 

CJ  ^ 

X  <  c  s  Il'( 

X 

a 

x  a 

X  X  X  X  «-< 

* 

<  »J  «  <  <  X 

O'SQdBmufl, 

<  ®  CJ<  C  ®  o  < 

xxx»-xxxt-»: 

<«<  •-)<<<  X  < 


CJ  CJ  CJ  CJ 

*  co  •-  f— (  .»  •«  .»  n  «k  r— t 

ixoxoisoxox 
i  <  co  <  <  s  u<  ac  < 

:»-<ih-.xxx*-«x^ 

J<  J<  <  <  x  <  x 


CJ  CJ  CJ 

•*■  •*  co  •«  •*  in  f-H  •«  i 

</>QaxoaoaQ 

</><<  >— <  vr  <  cc  <  << 

^X^XX^X^Xi 
4-  <  i-3  <  <  J(  U  < 


CJ 

•«* 

CJ 

vo 

CJ 

•» 

10 

a 

cj 

a 

< 

a 

CM 

< 

CJ 

< 

a 

•*  CJ 

in 

.kCJ  •* 

•»  < 

ps  -sin 

a  o.  m  <  m  cj 

«  £  Q,SCOh 

m  x  <  x  x  a 

j  <  ij  <  <  < 


i  a  <  <  o 

1 «  <£  <  < 

1  *-*  X  X  X 

wJ  <  <  < 


CJ 

•k 

c; 

a 

a 

•* 

io 

CJ 

vo 

CJ 

< 

CJ 

cj 

CJ 

a 

CM 

CJ 

•*  cj 

•k 

« 

a 

a 

•*  *k  .» rr 

•»  DO  «k  >k  CO 

•k  co 

. co 

X 

a. 

a 

CJ 

< 

CJ 

<  cc  O',  a. 

m  co  cc  o  a 

m  to 

s  H  H  (/] 

o  a 

CDS  [T 

.<  « 

•*  »k  < 

•*  .k  *k  m 

.kCJ  •% 

•k  m 

•k  cj 

«  CM  *f  00  i-h  V£  < 
MXXXXXt- 
X  <  <  <  «  <  ■_] 


—  -h.  V  —  '  H  [U  «.  OM  03  [L  s 

xmxx*-'xxxxxxx>-'xxz 


.»  <  r,  <  in  ov  h 

<s>  x  a  x  a  x  x 


-fccoa— >  —<  x  a  x  ^ 
®<<<  o  x  cj  <  <  ova 

>  X  X  X  *-■  X  <  X  X  '  x  < 

*  <  <  J<  H<  <  X  <  *-l 


$ 

o 

k 

s 

£ 

2  V. 

ii  = 


o  cj  in  to  o  x 
<:  o  x  is  <  o 
x  cl  x  a  x  a 


CL  Z  .*  > 

I  <  ^  < 

it.  If)  </>  c/5  CO 
x  ®  </>  o  m 
x  a  </>  a.  > 
«  <  ^  <  < 


CJ  +  CJ  +  *  .*  * 

5i*H  S  H  PS  HT  p-k 

cl  z  x  z  </>  >  </>  > 

•*  •*<  <  •«  •*(  (  (/>  <  </>  <  .k 

CL(J)uinw<MirM/5v>(/)c/;avM/]wcL  ocji 

0<OX®<ox®</)Omo</>Oroo-  <pn< 

~xxxxxxxx<nx>~</>x>~  xa: 


> 

u 

« 

IS 

VO 

— 

> 

* 

« 

in 

m 

•k 

•k 

> 

> 

CJ 

CJ 

<  •* 

< 

CM 

CM 

♦  cj 

« 

X 

X 

TT  CM 

^T 

< 

< 

>  a 

> 

CJ 

CJ 

•k<  •«<  .« 

< 

•k  H  •  k 

•k  *k  pH 

o  c/5  in  cj  •»  o 

X 

O  X  o  x  O  X 

<  m  cc  >->  </>  < 

m 

X  <  < 

5S  X  < 

X  >  x  a  </>  X 

> 

X  H-  X 

—  X  M 

u  co 

E-  E-  t- 

>  Z  >< 

X  *-•  X 


24 

296 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


cj  z 

•*iTi  •*.  •«  •*  •*  .«  •«.<  •» 

o'asfsMtttswc 
D  <  Ct,lS<tt,OOrH®OC 
Xt-'XXXXXXZX 

<  1-3  <<<<<<<  < 


a  u  u 

CJ  </>  CM  X  ®  --t  CT>  a.  cr>  CL  s  f\  (N 

h  V>  <  [l  <  ®  ffi  (  C<  X  «S>  < 

a^xxxxxt-'xt-'xxx 

<  !!<<<<<  J<  J<  <  < 


Z  Q-  cj  cj 

*  •*(  —  <  •*  •*  •»  •»rr,  »*ir 

jsc/itf  uvi^tDaDa. 

JHS0CH<O<II<<<  CJ  < 

:xzxa»--xxxt-*x*H 
<  <  <  <  — •<<<  x<  X 

V 

if) 

</) 


cj  cj  u  cj 

—  lti  •«  •«  •«  —  •«  m  •«  —  •«  •«  co  in  —  —  •*■  — 

CQ.KOiSCDll.S^SCOC^O11'151'1^^ 

<  x  s  <  <  rH  ®  ro  <s  «r  <  CJ  <  <s  <  <s 

X»-,XXXXX>-,XXXXXMX'-,XXIX 
<  X  <  <  <  <  <  X  <  <  <  <  <  i_3  <  t-3  <  <  <  < 


CJ 

cj 

CJ 

CJ 

CJ 

CJ 

cj 

c; 

CJ 

CJ 

CJ  CJ 

CJ 

CJ 

rr 

VC 

CM 

TT 

VC 

CM 

VC 

CM 

CM 

■*r  vc 

CM 

CM 

•» 

•  * 

— 

•* 

— 

— 

— 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X  X 

X 

X  CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

< 

< 

< 

< 

< 

< 

< 

< 

< 

< 

<  ^ 

VC 

CM 

VC 

CM 

CJ 

CJ 

CJ 

CJ 

CJ 

u 

CJ  CJ 

CJ 

CJ 

CJ  CJ 

CJ 

CJ  X 

X 

X 

X 

X 

X 

X 

X 

—  ro 

—  in 

rH 

m  — 

rH  •*■ 

CO 

m 

ro  in 

< 

< 

< 

•»  <  •» 

•«.  < 

</> 

D  X  CD 

o  a  D 

X 

o 

X  D 

x  D 

X  </> 

<S  i-3 

X 

X  O 

X 

c; 

X  </> 

<s  > 

X  X 
<  < 

O  X 

CJ 

x  vn  CJ 

m 

cj  m 

CJ 

IT.  CJ 

m  cj  in  cj 

m  cj  O' 

X 

in 

CJ 

CM  K 

</> 

<  <  ro 

X  < 

X 

< 

<  <  X 

<  CD 

<  CO  CM  x 

< 

< 

CD 

< 

CD 

< 

</> 

CM  »_4 

00  < 

ac  <  <  co 

CM 

in 

00 

rH 

<  ro 

®  in  co 

rH 

<  ro  *r 

X  CD 

rH 

-  <  ® 

»H 

x  »H  X 

X  IH 

X 

*-* 

X 

*-*  X 

•H  X 

X  T 

h-> 

X 

►H 

X 

H-* 

X  D 

*->  »H 

X 

h-  —  x  X 

X 

X 

X 

X 

-XX 

XXX 

X 

XXX 

X 

X 

X 

07  X  X 

1 

<  J  < 

<  J 

< 

.-3  < 

X  < 

X  < 

X  * 

<  H 

i-3 

t-3 

-3  < 

X  \<  »H 

t-3  _3 

<  J< 

X  </>  <  < 

< 

< 

< 

< 

</>  <  < 

<  <  < 

< 

<  <  < 

< 

< 

< 

</>  <  < 

•» 

CJ 

CJ 

•« 

CJ 

u 

u 

CJ 

CJ 

u 

«ET 

TT 

•» 

CJ 

CM 

CM 

VC 

< 

CM 

X 

X 

CJ 

CM 

X 

X 

X 

X 

X 

1 

X 

< 

< 

VC 

X 

< 

< 

< 

< 

< 

CO 

< 

CJ 

— 

CJ 

X 

<  •* 

CJ 

CJ 

CJ 

-  CJ 

CJ 

z 

-  CJ  - 

—  ro 

•'7 

■<*.  ro 

—  < 

—  CJ  •«></> 

•*  ^  •* 

—  ro  •* 

*«  CD  •»  •«  rH  •«  x 

hcc  c  a  o®ua^uc'H<v>Qa1<<oatfcc<cooj| 
</>  <  cl  >— <  vr  <  cc  3  <  <  <  in  a  ®  h  <  (  s  <  <  <  cm  <  oo  •— i  vc  < 

v>x<  xx>h  x  <  x*-<xax<  xiix*hxxx»-xxxxxi 

||  <  X  <  <  X  <  J<  i-3  <  <<  J<  z^<  J<  (  <  X  <  <  <  <  <  I 


>  <  a\  VC  <  CO  < 

:  x  X  X  *h  x  ffl 

J  <  <  X  <  X 


!  0>  Q,  — •  LD  00 

<  S  CO  <  CJ  <  00 

X  X  X  *-•  X  X  X 

<  <  <  J<  •— 3  < 


CJ  CJ  CJ 

■c  vc  cm 

X  XX 

—  <  •*  •*.<  — < 
m  Qj  00  in  CJ  in  CJ 

<  fO  H  lO  00  rt 

.xxxxxxx 


CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

CJ 

— 

CJ 

— 

CJ 

CM 

CM 

■<T 

— 

CM 

CM 

— 

— 

— 

— 

CJ 

CM 

CJ 

CM 

CJ 

VC 

X 

X 

X 

CJ 

X 

X 

X 

X 

CJ 

CJ 

CJ 

CJ 

X 

■*T 

X 

X 

< 

< 

< 

CM 

< 

< 

< 

< 

VC 

CM 

VC 

X 

< 

X 

< 

X 

< 

CJ 

CJ 

CJ 

X 

CJ 

CJ 

CJ 

CJ 

X 

X 

X 

X 

< 

CJ 

< 

CJ 

< 

CJ 

)  C  X  &J  S  O  X  Q  Q.  in  U  CxOxOxOX  CJ  ^ 

)  oo  <  <  ts  co  <  <  <  ac  >—<  <  <  oc  <  <  <  oo  <  .*  <  in  co 

,X*HXXXM  XMXX  XH<X*HX»HX*H^XXX 

<  .-3  <  <  <  x  <  -3  <  «  —  <  J<  _)  <  X<  X  </>  <  <  < 

—  </>  </> 


<  •«  <  •»  —  <  •*  .*  •  «.  CJ  **H  •«.  CJ  •**  rH 

Uincj^ir.  u«tfaHmoxoOHncx 
naiH</)<ins<cDXCo<  ux  x®< 
XXXV>XXXXX<  X*-<XX<  X  H 

<  <  <  — •  <  <  <  <  <  H  <  J<  <  H  <  X 


•*  cj  i n  •'  Z  •* 

•»  O'  fO  ©  D  X  D  S  (J 

<->  <  X  H  VC  <  00  CD  < 

</>  X  <  x  X  »H  x  <  X 

co  <  X  <  <  X  <  wJ  < 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


25 

297 


+ 

+ 

+ 

+ 

+ 

+ 

+ 

+ 

+  CO 

+  + 

-4-  CO 

+  + 

+  CO 

+ 

+  </>  +  + 

+ 

+ 

+ 

+ 

+ 

+ 

+ 

+ 

+ 

+ 

+ 

CO 

+ 

+ 

+ 

CO 

+ 

+ 

+ 

1^ 

CM 

CM 

00 

ON 

O'  CO  CO  .—i  O' 

ON  CO 

<-•  ON 

ON  V/ 

O' 

co  on 

vc 

VC 

vc 

...  00 

•« 

vc 

vr 

•« 

00 

•« 

VC 

vc 

CO 

On  ON  H  CO  ON  ON 

•2 

— 

2 

2 

2 

2 

2 

2 

— 

2 

2  •-< 

2  2 

2  *- 

2  2 

2  M 

2 

2 

►“*  2  2 

•«. 

2 

•* 

2 

2  CO  X 

x  CO 

2 

2  CO 

2 

Z  <o 

2 

2 

H  2 

2 

2 

t— ' 

2 

2 

z 

< 

</> 

< 

< 

< 

< 

< 

< 

CO 

< 

<  + 

<  < 

<  1 

<  < 

<  « 

< 

< 

\  <  < 

CO 

< 

CO 

< 

< 

CO  < 

< 

CO 

< 

< 

CO  < 

< 

CO 

< 

< 

II 

< 

II 

< 

< 

</> 

co 

CO 

CO 

C/1 

co 

CO 

CO 

•k 

II 

II 

— • 

II 

— • 

II 

1 

•% 

•« 

p- 1 

CO 

</> 

CO 

CO 

i£ 

n* 

CO 

— • 

II 

V 

V 

CO 

CO 

co 

— 

— 

+ 

1 

1 

¥-> 

h-1 

t-1 

►— < 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

<A 

+ 

1 

+ 

l 

II 

II 

II 

II 

II 

CO 

CO 

— • 

CO 

CO 

CO 

CO 

t_l 

l_t 

II 

+ 

1 

</> 

</> 

CO 

c/> 

CO 

CO 

CO 

II 

II 

II 

II 

II 

II 

II 

II 

It 

CO 

CO 

</> 

CO 

co 

CO 

</> 

CO 

<o 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

M 

>-* 

*-• 

»-» 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

CO 

I 

cs 


X 

X 

X 

—  in 

♦ 

X 

Ik 

•k 

O' 

CJ  ON 

CJ  < 

•»  m 

«S 

CJ 

'■ — 

— • 

— 

cm  a 

CM  (S. 

— ■  > 

<N 

A 

CJ 

< 

< 

x  < 

X 

CJ  < 

< 

CJ 

X 

CM 

+ 

1 

<  cy. 

<  + 

CM  ♦ 

-f 

^r 

X 

•*  H 

CM 

CJ  cs. 

CJ 

X  •* 

fH 

X 

CJ 

o 

< 

U  2 

2 

>— *  CJ 

^  2 

•*<  U  > 

2 

•*<  •- 

r— 1 

u  < 

< 

X  ON 

X  < 

^  CJ  s  < 

< 

m  CJ  P 

X 

y 

r—l 

X  X 

CO 

<  X 

<  C/5 

coh  a  w  w 

+ 

CO 

<  CO  00 

< 

5 

X 

<  <s 

ON 

'  < 

I-*  ON 

co  a  <  on  m 

<s 

XXX 
<  <  < 

n 

< 

cs.  a 

X 

P  cs. 

X  X 

co  <  cs.  a  > 

2 

X 

X 

a 

— 

<S-  < 

•* 

< 

— .  cs. 

< 

— '  cs.  <  < 

< 

< 

CO 

CO 

co 

“O 

CO 

CO 

CO 

c 

<  u 
co  e- 

»-* 

o 

u 

t- 

o 

—  > 

2 

>* 

•* 

A 

..  X 

X 

U  >  2  7 

H  «.  <  <  < 

coaxxxx  +  x  +  x 

co  <  <  o>  r  <J\  ®  'T  K 

v)H®.a>-?aza 

*-»-<a<  <  «  <  <  <  < 

co 


t- 

2 


in  w  w 


UUUT 


'  ON  . 


ON 


CO 
CO 

coxxxxxxx 

</>  (J\  ro  (Jn  <  «  <  < 

v>  a  >  -  j  ®  x  <s. 

— •  c  «  < 

co 
co 


v>  i/:  k  a 

CO  ON  CO  O' 

v>  a  >  - 


2 


i 

o 


C/5 

a> 

so 

CQ 

a 

c 

o 

a> 


2 

«s 

x 


CJ 

ON 

X 

ax- 

— 

— 

•* 

< 

<  <  CO 

CJ 

CJ 

•k 

u 

•«*  u 

CJ  CJ  CO 

CJ 

-  CM 

in  oc 

X 

X 

CM 

X 

CO  a- 

X  X  O 

< 

< 

X 

.  <  •«. 

. 2 

•*  2 

co  .%•«.< 

<  <  E- 

-  CJ 

—  CJ 

i  CJ  vn 

;»S  n  [/  CJ5 

X  CJ  CS  U5 

X  X  co  S  O  CJ 

CJ  CJ  2 

ON  CO 

is  co 

vr  cj 

S  'T  (/I  <  w  k  ^ _ ^  . 

—  x  <  xxxsxxpxc 


s  ^  x  cs  —  cs®cocMX^^r'M<a<x<<-H 


—  x  <  d  u  - 


•  co  x  r  x  x  x 


••  < 

<  CJ  <  < 

<  C/5  <  < 

<  <  CJ 

■.  < 

<  CJ  < 

C/5  <  < 

t  CO  < 

t-<  <  < 

<  CO 

CO 

E- 

O 

CO 

CO 

CO 

P 

O 

CO 

P 

X 

CO 

u 

u 

< 

CJ 

- 

E- 

C/5 

X 

p 

►—1 

< 

W 

2 

CO 

a 

CJ 

P 

X 

F 

x  <  x  <  x  a 

P  <  X  < 


<s  x 

CM  CJ 

X  E- 


•- 

CJ  CJ 

CJ 

CJ 

u 

CM  CM 

CM 

CM 

CM 

X  X 

X 

X 

X 

<  < 

< 

■*  <  •»  •% 

—  CJ  —  CJ  —  —  —  — 

-  CJ  - 

CJ 

in  CJ  s  E- 

...  <7n  ,— <  ts  <  S  X  s  x 

S  ,-H  S 

<^cn  H«xa<a«No:(M(D.* 
*x  a  x  acox<  x<  x  x  x  a  co 
</><<<  ^  <  p  <  x  <  x  <  :?  co 

</>  £u 

CD  C*-< 

w  6T  x 

t-  E-  D 

a  a  w 

2  S  X 


<  a  <  x 
x  <  x  < 

<  p  <  x 


CJ 

CM 

a 

•»  <  •*  •*  •*  •* 

vr  cj  co  rsj  s  P 

X  H(/><  S  < 
X  X  X  X  X 
<  <  II  <  <  < 

V 
CO 
CO 

II 

CO 

CO 


CJ  CJ 

vc 

a  x 

«  < 

U  CJ 

if.  —  m 
a  P  a  < 
<  cj  <  • 

M  X  *-*  ! 
X  <  X  < 


.  in 


SOMSDDQ.KrfKXDQ.OaSNfMluXU 

I  Cl,  S3  CS;  <  <  h  s  x  B  <  (  CJ  <  O'  S  <£  [li  X  H 

:xxxxx*-jxxxxx*-,x*-<xxxxxx 

C<C<<X<<<<<P<J<<<<<< 


— 

CJ 

CJ 

CM 

CM 

X 

X 

< 

< 

CJ 

-  CJ 

—  t—i 

®  .-1 

P  X 

cm  a 

<  < 

-  x  < 

-  X  *-• 

CO  <  C/5  CO  <  p 

CO 

X 

CO 

t— < 

CO  x 

P 

p 

X  X 

p 

p  o 

< 

X  CJ 

u 

vr 

—  ON 

CJ  X 

CM  < 

a  m 

<  VC 

CJ  •*  X 

...  U3  ...  rH  —  U  < 

m  (/]  c  a  X3  u:  k 

00  <  <  <  OC  <  CM 

X  X  X  W  X  X  X 

<  _J  <  X  <  X  < 


u 

CM 

a 


••  •»  •*  cj  •- 

s;  s  cj  *-h  on 

vc  vc  a  < 

x  x  x  <  x 

<  <  •»<  X  <  < 


•« 

... 

CO 

•k  ik 

2 

X 

CO 

co  co 

X 

p 

CO 

p 

X 

O 

X 

E-* 

p 

E- 

CJ  o 

X 

2 

O 

O  E- 

X 

X 

O 

P  X 

26 

298 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


pic 


•*X 
«s 
cj  co 

CM  < 
a  cs. 
<  <Sj 

cj  o 

.%  .«  hS 

</>  +  +  +  +</>++  +  +  aw 

(/)0'^'0'rv</)ff'0'<j'rv  <  < 

h2ZZZh?Z7Z  W«- 

—  <<<<  II  <  <  <  <  ^  <2- 

V  V  •* 

if)  if)  if) 

if)  if)  if) 

*->  ¥-• 

II  II  x 

</></>  X 

</></>  co 


•*  x 
— -  <s 
CJ  co 

CM  « 

a  csl. 

<  <E 

+  +  +  +  +  +  a  co  + 

COCT'^J’  f— (  >-H  co  <  <  r- 

Z  •*  Z  Z  z  Z  Z  De  z 

</><</><<  <  <  •«.  <  ^  <SJ  < 


if) 

</> 

•» 

•% 

</> 

.* 

z 

X 

if) 

if) 

if) 

X 

X 

X 

if) 

X 

J 

X 

CO 

o 

a 

CO 

u 

s-* 

c 

fr* 

cj 

o 

a 

o 

< 

X 

z 

o 

c 

fr* 

o 

CJ 

CJ 

X 

X 

CJ 

_) 

CO 

x  ..OKUKt  CC  ...  CO  •«  IT. 

x-su:su]K  ..  s  —  s  —  ®  o 
<oE-X<X<X'~XCJX.-)XCO 
w5<  X  <  X  <  X  <  <<  0<  F 
- — -  IT.  S-  i_]  (S>  X  ®-  CxT  a  ®-  CJ  <B.  i— i 
x  <s  <s.  ^—  <sd  —  <s- 


to  >  «tf  ® 
<WO"C 
x  CL  X  X 
<  IT  <  < 


>  -  > 
<  •*</>< 
co  v>  </>  co 

.—4  </></>  f-4 

>  <A  II  > 


••  CJ . * 

x  <  <  x  > 

a  w  x  cc  w 

x  z  x  x  g- 


w>  cj  ®  cn  w  cj  ®  a 

<  rH  O  ®  CO  ® 

x  a  x  x  x  x  < 


•»«  •*  •*  •*  2 
w  U  is  n  c/;  u® 

<  h  d  s  s  (/3 

x  a  x  x  x  x  < 


</> 

<  </>  X  < 

< 

h-l  < 

<  CO  •*  < 

<  <  < 

<  < 

<  H  ( 

<  <  < 

<  <  <  5  X 

</> 

</>  x 

< 

z 

X 

n 

ii  e- 

r 

r 

•» 

•» 

•* 

*— 1 

r 

r  co 

c 

z 

< 

</> 

X 

•* 

X 

<J> 

X 

•»  X 

X  t-H 

E- 

z 

if) 

►— < 

X 

X 

if) 

a  2 

r  u 

E- 

CJ 

a 

o 

CO 

*— 1 

D 

O  M 

o  x 

O 

X 

z 

X 

z 

X 

X 

z 

z 

E-  X 

X  X 

X 

X 

X 

X 

X 

3 

o 

X 

•*Z  „ 
a  cj  ®  cl 

s  w  «s 
—  x  <  — 

<  <  5  < 


</>  ITI  CJ  IT) 
<  H00 

z  x  a  x 
o  <  <  < 


CO  CO  CJ 
E-*  ®  •— i  ^ 
?  X  X  X 
to  <  «  < 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


27 

299 


(Continued  on  page  26,  column  2) I  (Continued  on  page  26,  column  3) I  (Continued  on  page  26,  column  4)  I  (Continued  on  next  page) 


CD  CO 

cj 

O  CD 

< 

CL  O 

J 

X 

CD  CL  CO 

to 

u 

X 

►h  CD  CD 

E- 

X  r, 

Q  H-i  O 

co 

CJ  E- 

D  CL 

cj  X 

cl  Cb 

E-  CO 

X  CD 

<  CO 

O  CO 

CO  Cb 

O  — M 

U  1-3  h 

E-«  x  z 

X  CO 

e-  a 

<  (L  CO 

<  c  o 

CD  X 

X  cj 

X  5“ 

CL  CL  w 

2  O  < 

CJ  <  X  Z 

X  X  < 

x  x  x 

Q.  u  rr 

O  X  CL  CL 

rf  r  >  rr\  r.l 

E-1  X  O  O 

2  X 

CJ 

►-(  tO 

Q  Q 

u  uO 
X  D  Q  u 

O  O  O 

uuuu 

cc  z  x 

X  hh  I  X  o 

CD  -1  CJ  X  X 

:f  5  H  Q  x 

3  X  X  Z  *-H 

ZZU.HO 


ooouwm/ihH^ 
6-  >  E-  E-  X  X  Q  »-i 

tf^CCZUUUlL,  j 

a  cj  x  o  <  <  >  >« 

u<huaazJJu 

CLf-CJ  <  <  O  <  £1.  h 

oi/xfHiiuixHa 

a:  h  u  u  uhu 

oa<u  x  E ■*  x  r 

QOIhuUUhD^ 

<auD^o:iJrz 
<  o 

----uz---- 

+  —  CJ  >  X  CJ  X  _1  *  z 


Cb  U  (/^  b.  J  £ 

xjjjrsrr 

f«1  fiT  f.T  r«1  r.1  r.T 

HE-E-E-E-E- 
>>>>>.> 
£T  CC  CD  CD  CD  CD 


Q_J.~ic\ifr  <cDCQWUX_ijrz 

Z20000000000000 

uuuuuuuuuuuuuuu 

E-'E-'E-'E-*  E-*t-*E-* 

><><>«>«>*><>«><>«>«>«><>«>«>< 

CDCDCDCDCDCDCDCDCDCDCDCDCDCDCD 


x  E-  a  z  h  <  x  to 
hiczza,o  Ja  cj  3 
3  cj  cr  *-h  »-•  i  —  <cc 

a:  tr  h  d  e-q  ct  a  e- 
u-uhOHZzuh 
E-  X  E-  Z  X  O  E- 
u  U  (J  Z  H-t  H  z  o  u 

r  u^<  Ha,-hHha: 

<  3  CJ  -1  U  h  3  O  O 

XQ<xci:azE-xxz 

<  X  E"  X  U  t-»  »-HU 
aawwhzrE-sc  ^ 

U  Z  h  r  w  U  t; 

-  -  -  <  HU  o  (D  <DU 

x  i  wirouuDhaw 

-  -  -  E-*XcO--'XXE-3 

a-awHucuu-aao 

ooooxxq:xxe*3 

xxxxxxxxxxx 

E-E-E-t-E-E-E-E^E-e^E- 

>>♦><><>•>«>«>«>«><>< 

CDCDCDCDCCCDCDCDCDCDCD 


zofasH^sMccuo-DH^r 

D3DNSSSHHtf£j)cDD[i}H^J 
X  X  X  X 

><><>-:wZZZZZZZZZZZZZ 

ffiCDCDfflHHMMMMMMMMMMM 


3  X  > 
l/l  Q  C 
a  cl  cl 
x  cr  cj  x 
E-  X  <  E- 
Z  h  E  W 
*-<  Z  T 

2h  fc  < 

ooa 

-  CL  < 
—  a  cl 

SOU  H 

s  a:  (n  ^ 

s  u  e  <s 

-<  <  3  -h 

S  E  Z  ® 


E-*  E-*  E-*  E-1 

Z  Z  2  Z 


X 

CD 

CD 

X 

CD 

a  - 

CD  <  X  CD 

s 

00 

CO 

X 

00  <S  00 

CD 

X 

a 

CD 

a 

CL  Z  CD  X 

< 

< 

< 

<  IS  (  < 

•%2 

CD 

a 

—  2 

CD 

X  CD  (S.  X  •* 

w  <S 

s 

O' 

w2 

ts 

O'  <  &.  O  m 

z  cj 

O'  s 

3 

< 

< 

2  CJ 
s 

3 

< 

—  CJ  CJ  —  CD 

<  .  s  <  </> 

a  cd  + 

a  + 

a  + 

a  cd 

CL 

X  X  CD  X  CO 

ziaz-z 

<  2  <  «  < 


oc  ro  c  < 
~  Z  CJ  2 


•-or  o'  <  oo 

i  CO  — •  —  2  — 


CD  C 

CD  E- 

<d  +  +  Z  + 

V)  fl  O'  H  ^ 


r 

♦  -  +  +  +  +  O  + 

in  <d  in  in  .»  in  iTi  a;  O' 


+  K  +  +  + 

in  o  m  ^  O' 


+  -++CD  +  + 

r-  cd  in  in  cd  in  in 


CD  <  ( 

[  (3D  <  </>  < 

<  CD  < 

CD  ‘ 

< 

<  CD  <  1 

(  < 

•*  < 

<  < 

<  CD  < 

t->  <  < 

CD  « 

C 

CD 

CD 

CD 

X 

CD 

CD 

CD 

CD 

CD 

o 

CD 

X 

X 

CD 

CD 

CD 

X 

H-< 

X 

CD 

CO 

CO 

CO 

X 

X 

cj 

CJ 

E- 

E-1 

E- 

D 

Q 

O 

2 

CD 

< 

X 

c 

►— < 

M 

H-* 

< 

< 

< 

X 

o 

X 

CJ 

2 

CD 

X 

X 

X 

X 

X 

X 

X 

X 

2 

<■ 

CO 

r 

5 

5 

X 

X 

X 

o 

cj 

3 

X 

<S 

Si 

S 

S 

S 

S 

s 

S 

S 

S 

O' 

O' 

cr> 

cn 

Os 

Os 

Os 

<r> 

O' 

o 

Os 

Os 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

X 

2 

2 

(2. 

<2 

<2. 

<2 

(2 

<2 

(2 

2 

2 

2 

•-  <2 

<2. 

(2- 

.*<2 

•%  (2 

.*(2 

•k  2 

•  -  2 

2 

2 

s 

— '  m 

—  < 

— ■ 

X 

CM 

in 

CD 

X 

w  X 

—  i — i 

— '  N1 

r- 

IS 

>  CM 

CD 

X 

X  CJ 

z  c; 

X  CJ 

x  CJ 

X  CJ 

X  O 

X  c 

Q  D 

X 

x  X 

Hit* 

X 

X  X 

X  X 

o  x 

X  X  U  X  x  X 

U  X 

<  X 

< 

T  < 

c  < 

C 

< 

X  « 

X  < 

j  < 

D  < 

E-  < 

CL  < 

E-  < 

X  « 

<2- 

H-*  <2- 

H  Si  X 

<2. 

X  <3l!  c  <Sj  CJ  <2 

CL  2 

rn  2  2  <2 

X  2  CL  2 

2 

2 

^  C2J 

C2 

—  fflJ 

<2 

—  <2 

—  <2 

^  2 

—  2 

2 

— k2 

(N 

CM 

CM 

1-* 

•* 

»- ( 

•'  2 

si 

< 

2 

O 

o 

> 

> 

•» 

> 

CJ 

—  o 

2 

w  CJ 

3 

h-> 

CJ 

•»< 

■»  ( 

CD 

( 

u 

s 

— ’  s 

< 

>  o 

< 

< 

< 

CD  CD  CD  X  CD 

X 

< 

w  X 

>  X 

X 

X  X 

+ 

+ 

+ 

X 

+ 

X 

X 

X 

X 

CD  *"H  CD  i— l 

CD 

f—* 

■* — 

CJ  < 

<■  < 

Os 

X  < 

•a* 

r— ( 

cc 

CO 

o  < 

X 

X 

CD  >  CD  > 

II 

> 

z 

<  2 

t-1  2 

X  X  <2 

z 

z 

z 

Z 

M 

2 

CD  < 

CD  C 

X 

( 

M 

^  cs 

2  < 

—  2 

< 

•*< 

< 

< 

< 

« 

2 

< 

< 

CD 

CD 

X 

-< 

2 

II 

II 

Z 

T 

X 

o  z 

< 

X 

X 

X 

X 

H-* 

E-  h-< 

T 

X 

l— t 

X 

r 

r 

u 

E-  U 

a 

o 

X 

*-< 

o 

X 

O  X 

z 

X 

z 

p 

X 

_j 

X 

X  X 

X 

X 

X 

28 

300 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


z 
o 
c r. 


X 

E- 

u 

o 

< 

X 

E- 

z 

X 

X 

M 

z 

z 

z 

M 

z 

t— < 

o 

< 

X 

X 

z 

o 

Q 

1 

z 

u 

X 

X  X 

X 

< 

X 

X  X  ^ 

X 

X 

u 

X  3  X 

X 

X  X 

< 

X  X 

Q 

X 

X 

TOO 

Q  X 

X 

X  E-  m 

X 

<  < 

z  z 

z 

X  E- 

x 

x  3 

►— 1 

X 

Q  X 

X 

O 

>-l  h  QC 

u 

X  E-* 

X 

oxo 

< 

U  Z 

H 

o 

X  T.  E- 

z 

Z  m 

X 

X 

<  < 

— • 

O  X  X 

— • 

X 

z 

X 

E-*  <  X 

— 

x  o 

o 

M 

m  CL 

(j  a  x 
o  < 
n  ua  u 
II  Ju 
u 

UUQ 

ii  a  < 

<  o  u 

<  Z  CL. 

u  x 

»-  -J 


*  "  H  H  u  | 
^  U  -  I  CO  j  I 

:  cl  <  —  u  o>  < 

»  o  w  -•  M  m  u  I 

:  5  z  —  a 
-  •*  *-•  •*>*.-<  j  : 
:  >«  <  m  a  u  •  z  i 
:  x  r  -r  o  —  5 

I  H  z  H  U  b3  I 

m  +  -  -  -  e-  : 

l  t-  O  II  Ml 

:  z  x  j  x  x  x  ce  i 
'Hczrr  r  Ji 


X  Z 

z  x 

E<  X 
X  E- 

X  E-1  •* 

a  ih  jco  u 

X  zu®  wu 

E-  U  II  II  CO  X  II 

Z  U  —  —  V0  X  ^ 

m  CJ  X  <  _]  X 

o  c  u  x  <  co  + 

X  <  II  II  II  X  ^  + 

u  <  cq  <  j  u.  a 

XU  X<X<<MQCCC 

Xu  x 

X  II  2 


X  X  u  < 
15  -J  U  < 

D  M  II 

Z  X  <  Z 

K  o 


X  Q 

u 

Eh 

< 

O  X 

z 

X  < 

X 

o 

X 

Eh 

o  S 

<s 

r- 

u 

Eh  5J 

i 

<S 

X 

X  <s 

is 

Q  X 

O  + 

o 

+ 

<  X 

X  II 

Eh 

II 

X  x 

x  x 

O 

X 

x  .*u 

X 

z  z 

O 

z 

X  x 

z 

z  o 

X  II 

II 

II  Eh 

M  ^ 

V 

X  X 

X 

X  X  < 

£  x  + 

X 

X  X  < 

X 

O  —  + 

*• — 

II  II 

x 

Z  X  X  x 

X  <  X 

X 

X  CD  CD  CD 

X  <  hH 

X 

X  M  «S  w 
M  II  U  II 
D  X  II  i-j 

z  a  x  i-3 

X  M  X  M 


x 

X 

CD  <  X 

X 

X 

X  X 

X 

X 

X 

CO 

S 

00  IS 

X 

X 

IS  CD 

X 

OV 

X 

X 

X 

x  z  x 

X 

X 

X  X 

X 

X 

X 

< 

< 

<  CS  < 

< 

< 

<  < 

< 

< 

< 

X 

•» 

<£. 

X  CD  <S- 

X 

X 

•1  <S  X 

X 

X 

X 

is 

' — 

<Sj 

IS  <  <s. 

IS 

ov 

w  <a  <r 

IS 

«— 1 

O' 

X 

z 

U 

x  5  U 

X 

— • 

z  u  — 

X 

X 

— • 

< 

<T> 

s 

< 

< 

< 

IS  < 

</> 

< 

( 

< 

X 

+ 

X 

x 

XXX 

+ 

X 

+ 

X 

+ 

X  X  X  </> 

+ 

X 

X 

+ 

X 

X 

m 

< 

( 

x  <yv  < 

X 

m 

X 

m 

<  <  X 

X 

O' 

ro 

X 

— 

z 

M 

<s. 

—  (S, 

Z 

— 

z 

•'  — 

z 

5  ®  — 

z 

z 

— 

— 

z 

— 

u 

X 

X 

>h  x 

CL 

u 

r  u:  cl  x  x 
<  u  <  x  x 

’ 

Z  X 

H  Z 

Eh 

x  <  x  x 

o 

o 

X  M 

U 

<  Eh  U  Eh 

Eh 

M  o 

X  X 

o  u  z 

<  z 

XX  Eh  X 

X  E- 

uj  z 

?  M 

x  u 

U3  X  X 

u 

z  z 

e*  O 

H  m  w  — 

<  Eh 

IE  JXh 

<  M 

CL 

X 

O  M  M  Z  X 

CL  IS  K 

X 

Eh  Eh 

Eh  Eh  IS  Eh  U 

U  Eh 

CL  O  m  O 

><  IS  is 

X  CL 

z  z 

ZZvrZE 

z 

X  M  •«. 

X  Ol 

u  u 

<  < 

<  <  <  U 

Eh  < 

D  X  —  — 

X  Eh 

H  H 

Eh  Eh  Eh  Eh  <  X  Eh 

Eh  •*  o  vDi  vn 

u  -'^vc  jc  ^ 

-h  z  Z 

X  X 

X  X  X  X  CL 

x  x 

►— i  r- 

< 

<  <s.  <  < 

<  u:  < 

<  ^<£  < 

o  <  <  < 

<  •« 

Vi 

•« 

M 

w 

<r> 

u 

</> 

X 

X 

u 

</> 

•y 

o 

X 

M 

b 

o 

X 

X 

z 

z 

X 

< 

5 

o 

cc 

u 

u 

X  oc  VC  is  O  O 
rn  oo  ii  ^  j 
U  vc  vr  x  •■* 

Z  m  m  X  <  X 
M  ||  II  E-  <  X 
E-  T.  T  X 

X  X  H  X  X 

xj-fue-e- 

O  O  m  x  >*  >* 
E -  -1  X  X  X  X 


<S<MZZZZZZ<ZZ 
xXOOOOOOOXmO 
SXXUUUUUUU  u 

XXX<SMCMCO*roOOVU  X 

xxxuuuuuuuuu 

xxxxxxxxxxxx 

E-E-E-E-E-E-E-E-t-E-E-E- 

>*><>«>«><>«>«><>«>«>«>« 

xxxxxxxxxxxx 


OSQCNCN- 
M  H  Z  ®  ®  < 
OSXSS- 

U  X  X  M  CNJ  < 

a  o  x  x  x  x 

X  X  X  X  X  X 
E-*  E-*  E-*  E-*  E-1  E-* 
>  >*  >*  ><  >*  > 
X  X  X  X  X  X 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


o 

I— I 

o 


< 

f 

CJ 

X 

o 


c? 

D 


X 

x 


< 

< 

b* 

00 

x 

> 

Z 

o 

CJ 

o 

CJ 

CD 

3 

CD 


< 

< 


II 

< 

< 


Q  < 
Z  < 

cd  x 

1  d 

i  ii  »-« 

c  <  a 

2  <  ? 


< 

< 


2 

O 


X  X 
X  CD 
►h  CD 
X  X  Z) 
P  E-  CD 
'  Q 
:  2 


2  E-  1 

D  n  I 
2  X  l_ 
X  5  X 


<  a> 

<  CJ  CJ 

ii  ii  a 

V  V  iZ 

a  <  co  cd 

N  <  CO  CD 
II  II  II 
X  CJ  CO  X 
X  CJ  CD 


N 

I  2 

<  X 

<  3 

II  ^ 

<  X 

<  X 


CD 

< 

< 

< 

E» 

X 

X 

> 

z 

o  x 

CJ  > 

t-H 

X  E-* 
CJ  3 
CJ 
CD  X 
X  CD 
CD  2 
O 
CJ 

X 

X 

< 


E-> 

< 

X 


CD 

(b  S  3 
*-•  CJ  CD 
D  II  Q 
2  <  Z 
x  <  x 


X 

CD 

CD 


N 

I  2 

<  X 

<  X 

II 

O  X 

<  O'  <  X 

C  CJ  CJ 
II  II  CJ 
V  V  i* 

OC.  <  CD  CD 
t<  <  CD  CD 
II  II  II 
CD  CJ  CD  X 
X  CJ  X  h 


<  X 

<  X  CJ 
II  II  CJ 
V  V  i* 

X  <  <  CD  X 

H  x  <  in  x 

c  II  II  II 
2  X  CJ  X  X 

CO  CD  CJ  X  *-> 


<  X 

TV 

<  < 
«C  < 
II  II 
<  < 
<  < 


2 

X 

3 

E-* 

X 

X 


X 

< 

*-< 

2 


2  Si 
h-t  00 

I 

X 

X  X 

X  X 

X 

o 

2 

o 

X 

2 

U 

F 


S  Q  H  IS  O' 
N  IS)  S  H  IS 


X 

It  8  D 

h  CJ  X 
D  II  D 
2  <  2 
u  <  u 


CT\  SJ 
00  S 
<X  S 
+  + 
II  II 

r  s 

X  <s 


8  8  8 

8  8  8  8  H  fN  n 

8  8  8  8  8  8  8 

+  +  +  8  8  8  8 

II  II  II  +  +  +  + 

H  8  II  II  ||  || 

S  H  8  8  ^  (M  w 

M  M  M  CJ  U  CJ  CJ 


SC 

oo 

« 

a 

s 

o 

-w 

a* 


T3 

a> 

3 

#C 

c 

o 

o 

00 

G 

.2 


x 

2 

O 

M 

e- 

2 

X 

U 

Q 

X 

O 

a 

2 


X 

> 

< 

X 

E-1 

X 

CJ 

X 

< 

fr* 

u 

X 

b* 

Q 

2 

< 

X 

u 

X 

X 

3 

X 

X 

X  c 
E->  X 
X 
X 
6? 
o 

X 


IS 

>  < 


.  X 
•  > 


X 

X 

n  cj 

—  CJ 

•*  < 

X 

*0  CO 

X  CO 

CO  X 

X 

II 

M  II 

X  II 

o 

X 

V 

w  ii 

II 

4  X 

D 

X 

CD  < 

X  m 

<  5  < 

•* 

X 

X  < 

X  o 

<  < 

D 

II 

II  11 

II  II 

II  z 

X 

< 

<  <  m  m 

<  X  x 

M 

< 

<  < 

o  o 

<  X  »-• 

“• 

E-« 

V 

X 

Q 

s 

X 

< 

X 

U 

X 

< 

z 

II 

li 

M 

t-H 

< 

X 

X 

2 

X 

< 

X 

5 

O 

2 

o 

M 

X 

2 

< 

X 

X 

X 

o 

X 

CJ 

< 

r 

o 

D 

F 

O  i s 
s: 

CD 

3  O 
X  H 

o  o  — 

o  cj  — »-)  m 

X  »r)  x 

X  M  II 

'—w  II 
X  X  <  • 

X  CO  X  <  < 

X  II  II  II 
-J  <  X  <  I 

X  <  X  <  i 


u 

2 

►-t 

X 

cj 

b< 

< 

F 


CJ 

< 

X 

X 


F 

< 

X 

< 

X 

X 

E-* 

< 

X 

X 

F 


E-* 

)  O 

*  2 

> 

)  X 

X 

II 

X 
X  CD 
X  II 
X  < 
X  < 


a 

X 

X  X 
CJ  X 

<  X 

55 

m  X 
F  < 
•*  X 
s 

^  < 


< 

< 


X  II 

X  ^ 

^  <  X 

X  <  x 

- -  CD  II  ' 

ii  <  a 

O  X  «f  <  X 

o  X  X  <  >-<  hH 


O  X  + 


X 

E-* 

<  x 

X 

X  X 

HH  x 


O  Q  Q 
2  Z  2 
XXX 


+  + 
+  3 
X  r> 
X  ►-< 


c 

’6) 

"D 

■  ■H 

GL 


u  x 
II  X 
r  m 

z  5 

M  2 


< 


z 

o 


X 

o 


G 

z 


X 

E-* 

< 

X 

X 

F 

X 

H 


8 

X 


X 

5 


s 

_  CJ 

D  II 

2  X 

X  X 


F 

Z 


X  X 
X  D 
+  M  W 

II  II 

f  x  n 

Z  D  r> 


x  c^  o 

X  X  X  < 
X  CO  X  < 
II  II  II  II 
CJ  ^  <  < 


X 

o  CJ 
CD 

X  x 
<  E- 
w 

z  a 
x  x  3 

z  x 

II  E-* 


X 

F 


X 

CJ  o  <  < 

X  CJ 

X  E-* 

M  < 

X  F 

«S  X  < 

2 

CJ  x  < 

c  o 

II 

z  z 

XX  z 

X  •* 

X  5  o 

CJ 

o 

X 


30 

302 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


CJ 

X 

u 

2 

O  2 

CO 

CO 

CO 

3 

CD 

x  CO 

cj 

O 

O  CJ 

< 

CO 

2 

co  2 

u 

CD 

O 

CD  CO 

X 

t— i 

X 

cj 

2 

E-1 

2  a 

CO 

cj  < 

O 

(J 

O  CO 

2 

< 

t-t 

< 

m  CD 

D 

M 

u  x 

E- 

E* 

a 

u 

X 

< 

2 

<  2 

c 

2 

X 

t— « 

X  O  CO 

X 

X  O 

CO 

W  *-•  E-1 

cj  a 

o 

CO  *-• 

a 

E* 

a  h  h 

<  2 

E*  E-1 

o 

M 

o  <  X 

2  E-  < 

X 

o 

CO  < 

CJ 

X  s 

O  2  CD 

CO 

2 

2  X 

2 

►-H 

2  10 

H*  O  CO 

E- 

CO 

<  CO 

HH 

D 

h  a  q 

E-  ►-»  2  x 

CJ 

X  CL 

O  2 

X 

<  E«  O  < 

< 

D 

<  o 

X 

O 

X  < 

CJ 

2  <  X  CD 

X 

2 

X 

o 

E-* 

O  2 

E-1  E- 

CJ  2  t*« 

< 

< 

2 

E* 

E->  *-h  X 

X  CO 

X  H  CJ  >4 

X 

CO  O 

< 

X 

<  CJ 

a  Cl, 

CJ  CD  *-*  ^  ffl 

CJ 

E- 

E-  M 

2 

X  CO 

2  X  E- 

E- 

E-  CO  CD  CO 

2 

<  CD 

CJ 

CO  E- 

U  o  CO 

3  CJ 

CO  O  CO  CJ  50 

CO 

CO 

U  2 

E-  CO 

*— •  E-  lx- 

O  ^ 

X  D  X  CJ 

X 

x 

CJ 

2 

2 

S' 

2 

2  2 

c; 

2 

<  — 

X 

X  o 

X 

o 

o 

o  o 

n 

VC 

X  -1 

o 

co 

O  X 

X 

X 

X  X 

o 

3 

<  CJ 

X 

u 

X  X 

X 

X 

X 

X  X 

X 

X 

si 

a 

X 

f—i 

CM 

X 

X 

Si 

S 

s 

CJ  > 

X  ' — • 

>  X 

CM  < 

<s  II 

X 

CJ 

X  x 

II 

S 

SI  - 

-  -  - 

•  «— » 

„  <  - 

X 

<  - 

X  < 

-  s  -  — 

X 

X 

X  2 

-  II 

!5  ISOMS  X  <  S 
■  +II+-.--  -  + 

ll  vc  II  ii  H  ii  II  ll  n 

■cDMO.a>a;>-iU4<x 

JUhWUNICIIU 


<  ii  -  wz  ii  ■  x  : 

u  U  II  O  U  U  I  O  I 

“H^UOHhU' 


E*  s>  x  < 

-  +  -  <  P  P  P  P 
II  II  II  II  <  <  <  < 

hhffizuuuu 

OXXXXXXX 


wur  uu 

X  <  <  X  2  E- 

q  a  a  o  u  z 

<  <  *->  < 

a  i  a  ^  w  h 

X  CJ  CJ  co  to 

E-  E-  <  P  2 

co  to  a:  e-  o 

a.  co  to  io  cj 

<  <  >  CJ 

a  u  z  <  x 

C  W  O  O  E-1  CO 

a  co  cj  x  x  x 


X  X  <S-  > 


x  h  o  <  o 

XXXXJOXE-2 
hrt-OUKKU 
>  3  >*  <  ^  *- 

X  2  X  X  E-  >  •* 
CO  w  h  J  H 

s  o  o  e-  oatb 

CJ  <  <  CJ  O  <  >-• 

waatf^ahr 
x  co  co  cr  E-  u  O 
E-  E-  <  P  x  x  x 
xt-**-)XPX2x 
O  J  J  (j  <  w 

Cl  ••  •* 


Q  II  II  II 
2  CL  CO  C 
CO  O  O  O 


o  Z  J  u 

X  -  -  -  • 

U  II  II  II 

<  2  u  cj  < 

•*  O  O  O  < 


CM 

CJ 

2 

t-H 

X 

X 

X  CM 

X 

X  X 

O 

X 

X  o 

E-* 

X  E" 

2 

X  2 

*-H 

CJ 

u 

E-* 

o  u 

CJ 

2 

2  2 

X 

X 

X  X 

E"  + 

E- 

E-* 

M  + 

t-H 

X  X 

X 

>4  X 

5  X 

3 

u  s 

X 

2 

u 

O 

\  *  I 

V  X  S  3  >« 


XU  X  2 

g*  s  = 

Z  (L  2  Cl 
U  H  CO  H 


CO  CM 

o  Cl  (l  Z 

X  CO  CO  < 

g  CD  CD  2 
o  o  a 
2  u  U  2 

CO  CJ  CJ  CO 


X 
•— *  E-1 

S  t-i 

SI  1 

s 

s 

s 

N 

II 

f-H  Si 

s  to 

< 

+  II 

+ 

CJ  CJ 

CJ  u 

< 

II  X 

II 

S 

II 

II  >-* 

X  E-* 

X 

s 

D  X 

O  X 

2 

X  *-H 

X 

►-4 

2  D 

2  5 

O 

>4 

2  E-* 

u 

M 

2 

X  CJ 

O 

X  »-< 

< 

X  X  p 

X  < 

CJ 

H 

CM  II 

X 

h-t  X 

X 

+  — 

2 

CJ  X 

X 

<  D 

*-<  E- 

*-4 

<  2 

+ 

X 

P 

II 

II  w 

+ 

o 

< 

<  X 

P 

X 

X  X 

< 

<  D 

2 

X  o 

X 

X 

E-* 

U 

CJ 

X 

K4 

2 

X  E- 

3  X  •* 

O  X 
II  CD 
^  +  X 
X  P  P  X 

h  2  2  W 
P  w  II  P 
2  X  P  2 
CO  O  2  CO 


U  h  2  S 
<  a  ii  *-• 
E*  5  <  II 
CD  <  < 

oB"* 

CD  2 


Dr.  Dobb’s  Journal,  Number  57,  July  198 1 


31 

303 


x 

Eh 

> 

CD 


CL 

£ 


z 

o 

*-i 

x 

cc 

x 

> 

z 

o 

CJ 


x 

o 

Cl, 

C 

CJ 


CC 

c 

E-* 

< 

CJ 

Q 

z 


z 

o 

»-» 

< 

z 

►H 

E- 

X 

x 

D 


a 

£ 


HH 

CJ 


o 

a 

< 

x 

CJ 


z 

o 


> 

o 

CJ 


x  •« 


h  f\  rn 

o  o  o 

u  u  u 
E-  E-  E* 
mhh 
CC  CC  CC 
5  5  X 


IZ 

CJ  cc  o 

O  Cl  c 


X 

O  H 


£ 

< 
cc 
< 

“■ana 

a  a  a  < 


a. 

*  X  s 

CJ  -u 
<  W  II 
<  E-  C/J  V 


X 

CJ 

u, 

W  2 

X  X  ^ 

• 

x  a  x 
£  5  x 


E-1 

=3 

o 

X 

E-1 


U 

< 

x 


< 

E-* 

x 

z 

o 

CJ 

X 

X 

X 

CO 


^cot-«<co<wHa< 

H  >  II  *H  3  ||  ||  w  < 

x  z  <  ii  y.  d  a  o  H 


x 

i^s  5 

o  1C  o 

a  w  z  X  « 

Cl  X  <  CJ  < 

X  <  C 

•»XHXM£Drf.. 
•  CJ  II  CJ  o  3 
■  HDh" 


II  II 


♦  X<ffi<  +  XE- 
+  X<3<  +  X3 
^  ii  ii  w  if  a  ii 
r<NOurw[L 
h<OUQmOh 


Z  X 

o  - 

*-•  CJ  *-• 

^  u  r  «.  il 

<  CJ  H  X  H  <  H 

Z  X  X  Eh 

X  X  Cl  *-< 

X 

X 

<  o 

<  CJ 

X 

a 

X  o 

o 

o 

X 

X 

X  X 

o 

o 

*-•  O  X 

X 

X 

DOW 

X 

X 

X 

X 

Z  X  < 

< 

< 

X 

X 

X  CJ  u 

CJ 

CJ 

< 

CJ 

< 

CJ 

CD 

t— » 

X  ♦ 

CJ  < 

_  <  < 

^  CD  <  ►-<  M 

O  X  II  HO 

:  ii  on  co  o  m 

:  <  O  m  H  n 

«  <  CJ  *-*  o 


X 

CJ 

E- 


E-« 


X 

CJ 

E-1 


Q 

CJ 


CO 

O 

o 

£ 

CO 

CJ 

< 

X 


X 

E 

Z 


<  CN  <  ^ 

X  O  x  CM  CD  < 


^  2-  <=> 

<  O  ec  o 

^  <  <s>  x  ►_■  + 

-  «  u  O  D  II  z  +  u  II  + 

* »  X  3  X  II  h  3  3 

»^E-*-H<OE-XE-iWe-.o 
Jhj<Uh(h5[lmh 

£  i  £  ► 


< 

CJ 


x 

< 

cj 


< 

u 


3 

< 

Cl 


CO 

x 

o 

o 

X  f- 

a 3 

Z  Cl 
CO  ►-» 


3  X 

t- 

k-<  CD 
M  3 
H-.  W 

*-<  o 

►H  O 


D 

z 

x 


co 

z 


S 


8? 

a 


c 

o 


X 

<u 


£ 


c 

o 

o 


90 

J 


.9 


c 

’5) 

T3 

■  IB 

CL 


-i 

< 

CJ 


X 

o 

X 

CJ 

< 

£ 

o 

< 

CO 

X 

£ 

X 

X 

3 

x 


IS 

IS 


CO  CO 

z  z 

t-t  t-t 

u  u 

22 

z  z 

^  X 

Cl  m 


CO 

z 


CJ 

< 

J  rH 

Cl 


CJ 

O 

II 

<  X 

<  X 

N 

X  Cl 
X  m 


E 

CC 


Cl  IS 

CJ 
CJ  II 
CJ  II 
X 


X 

CJ 

z 

3 


CJ 

< 

X 

< 

X 

CJ 


z 

o 


H  *-1 
X  Cl 
CO 

z5 

X  X 
X  Cl 

E- 

CJ  r- 

CJ  CO  Q  O 

u  u  <  ^ 

CJ  X  O 
Z  <  X  CJ 

o  •* 

CO 
CO  o 

x 


+ 

+ 

5  J 

-  X 

u. 

O  X 

O  X 

II 

II 

O  2 

o 

<  II 

O  X 

CJ 

CJ 

cc  •*. 

X  E- 

x  < 

X  < 

3 

3 

X  CJ 

u 

CJ  II 

£  X 

«s  Z 

i-l  M 

is  s  r~ 

X  < 

CJ  CJ 

Cl  >-h 
X  M 
CO  >-> 

G  || 

<  f 

z 

Z  h-  -f 

M  ^  + 

cj  x  r 

CO  J  2 

X  H  H 

X 

X 

CO 

X 

< 

CJ 


CO 

x 

u 

x 


u 

X  U  < 

M  D  z  < 

Q  <  II 

z  w  <  x 

x  x  m 


is  X 
X  +  3 
>-<  H  X 
Q  3  Q 
Z  3  Z 
X  W  X 


Si  IS  (N 

H  U  H  u 

II  ii  ♦  u 

H  I  ||  H 

*-•  Z  £  X 

wnTJ 


< 

< 


Z 

o 


u 

X 

X 

E-* 

X 

< 

£ 

Q 

Z 

E-* 

< 

X 

> 

X 

E-* 

E-* 

Z 

X 

X 

X 

£ 

E-* 

£ 

X 

O 

o 

CJ 

X 

X 

CJ 

z 

X 

M 

z 

5 

1-H  X 

o 

•J  £ 

l] 

II 

^  U 

X  £ 

o  DC 

£  H  £ 

X  || 

£  X 

—  E- 

X  X  t-4 

V  •«. 

CC  CC  HH  + 

X  < 

O  O  »-»  + 

£  < 

ZZ-H  II 
CJ  CJ  X  H  <  X 
M  H  J  H  <  H 


u 

Z  X 

X  X 

X  w 


X 

X 

X 

o 

r 

z 

O 

CJ 

X 

M 

X 

X 

z 

* 

u 

N 

X 

u 

— • 

X 

CJ 

o 

Q 

CJ 

z 

o 

< 

II 

X 

E- 

X 

< 

H-t 

o 

X 

< 

CJ 

X 

CJ 

X 

z 

hH 

X  X 

<  X 

X  CJ 

X 

HH  X 

<  Z 

3  3 

X 

Q  M 

Q 

X 

Q 

Z  X 

z  z 

X  X 

X 

2 

X  5 

O  X 

M  H  [|] 

X 

•» 

DO 

E-* 

X 

3 

X 

< 

X 

X 

< 

X 

CJ 

Q 

32 

304 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


x 

co  a.  a 
co  a 
M  cc  co  co 
II  P  II  P 
D  w  DCO 

E-  o  E*  O 

*-•  CJ  KU 


l_.  u: 

II  E- 


e*  x 


x 


E- 
CJ 
-C 
ro  CC 
O  < 
X 
2  CJ 
O 

x8 
X  CO 
*-•  O  X 
D  O  CO 
2  X  < 
UUU 


CM  XL 
Cl4  CJ 
< 

O  E-1 
E-  CO 

z 

*-<  x 
x  a. 

<  E-  co 

<  n 

X  2  V 

E-*  x  o  ■'T 

►“*  E-  +  CJ 
II  »— •  E-  II 

<  a  x  a  < 

<  3  a  co  < 

CO 

o 


< 

CJ 


X 

X 

X 

>  P 
o  Z 

CO  CO 

'  £V 

co  x  a 

Z  £  CO 


x 

z 

< 

x 

3  C  D 
hah 

M  *-H 

II  o  II 
—  E-  ~ 
X  Z  CJ 
X  CO  H  o 

t— t  — ■  «— 

Q  to  Eh  x 

2  CO  13  X 
u  h  a,  h 


X 

CJ 

< 

E-1 

CO 


CJ—Z5<X  — 
tf  XhitfluX 
h  CO  H  h  CO 

CO  '  +  II  E-*  w 

CO  <  ^  CJ  CO 
O  CO  <  X  <  CO 
hHHtfiX  W 

II  II  — ■  E-*  II 
P  <  <  X  CO  < 

o  <  <  CO  X  < 

<  h  H  H  H 


X 

< 

X 

o 

o 

o 

X 

X 

X 

X 

X 

X 

< 

< 

< 

CJ 

CJ 

u 

Q 

P 

< 

a 

2 

< 

X 

CO 

< 

X 

> 

3  <  X  -K  D 

E-4  <  X  h  h 

H  H  ><  (/)  H  H 

I  II  P  *  + 

<  —  x  CO  <  < 

<  X  H  CO  <  < 

H  CO  h  H  H  H 

II  w  *J  II  II  II 

<  CO  X  <  <  < 

<wr  <<< 


x 

CO 

< 

CJ 


.  X  CM 
«  X  x 


< 

S' 

HH 

CJ 

x 

D 


u 
>« 

X  -  < 

<  o 

<  E- 
*  2 

X  *-< 

E-* 

KH  < 
w  < 


X 

<  cj 

<  M 
*-*  X 
II 

—  E- 
X  X 
CO  X 

—  E- 
X  X 

X  o 


'  X 
:  < 

E* 

X  z 
O  5 


CJ  x 
<  E-1 
X  KH 
Z  X 
3  2 


X  x 
E-  X 

X 

x  o 
5  CJ 


z 

o 

H- 1 

E- 

CJ 

x 

X 


x  o 


•- 

•«. 

X  ►-< 

X 

X 

E-« 

O  E-« 

II 

o 

p 

O  CJ 

p 

X  < 

< 

.H 1 

X 

< 

CJ 

< 

CJ 

X 

X 

P  X 

II 

II 

< 

X 

z  o  — 

X 

X 

CJ 

p 

X  X 

X 

X 

p  : 

2  I 
X  • 


o 

e- 

z 


< 

< 


X 

5 


o 

E- 

2 


X 

5 


-X  z 

X  X 

X  X  + 

X  P  P 

X 

M  x 

X 

*-!►-«  + 

X  II 

X 

p 

X 

P  P  X 

P  <  X 

p 

Z  X 

p 

z  z  z 

X  <  >-> 

X 

X  t-» 

X 

X  X  t— ( 

X 

s 

z 


o 

X 

CJ 

< 

z 

X 

o 

p 

z 

x 

E* 

< 

X 

CJ 

< 

X 

E- 

X 

X 

o 

z 

X 

X 

E-  r 
•*p 
s 

s,  x 
s  x 

+  X 

ii  a 

E-1  Z 
xxx 


5 

E- 

E-* 

o 


E-* 

X 

X 

z 


CJ  Z  X 

<  in 

z  x  X 

-  E-  X  X 

h-t 

HOO 

CJ 

M 

X  X  P  E- 

X 

CJ 

t-S 

Z  5  U  X 

z 

II 

— • 

o 

V 

►H 

1— 1 

z 

“ 

H 

*-<  + 

p  < 

X 

p 

CJ  *-< 

I—4  + 

»-*  < 

+ 

< 

CO  z 

— '  HH 

II 

p  + 

X 

1— 1  >-H 

X  M 

<  X 

Z 

X 

X 

p  t— 1 

<  w 

X  z  x 

E-*  X 

z 

o 


z 

< 

X 

X 

X 

c 

X 

u 

< 

z 

o 

p 


z 

o 


E- 

z 


X 

D 

o 

X 

CJ 

< 

z 

E- 

X 

X 

z 

X 

X 

E-* 

o 


D 

< 


<N 

& 

ft. 

o 

ft. 

o 

•b* 

ft 

o 

3 

.c 

ft 

<3 


X 

o 

o 

X 

CJ 

D 

2 

X 


X 

> 

X  < 

Q  X  — 
4 — i  X 


X 

5 

II 

II 

< 

< 

II 

< 

< 


a 

o 

CJ 

2 

o 

M 

E- 

< 

X 


X 

c 

E- 

< 

u 

p 

z 


z 

o 

X 

X 


+  X 
+  p 
X  II 


X 

X 

CM 

X 

X 

. 

V 

X 

U4 

5 

2. 

4-4 

o 

p 

E- 

o 

• 

O  X 

• 

• 

z 

p 

X 

o 

X 

< 

“ 

X 

• 

X  X 

M 

• 

z 

4 — 1 

l-4 

p 

p 

X 

t— 4 

< 

o 

• — ■ 

X 

p 

• 

z 

l-H 

X 

X 

H 

z 

II 

E-« 

II 

■v 

X 

p 

X 

E- 

CM 

o 

z 

p 

x  *-• 

M 

o 

p 

SI 

z 

< 

z 

< 

X 

p 

z 

X 

X 

z 

X 

CJ 

X 

X 

X 

X  X 

II 

X 

z 

M 

*— 1 

< 

p 

< 

X 

X 

w 

X 

X 

r—t 

■ 

p 

z 

E-  X 

p 

z 

CJ 

z 

z 

p 

X 

+ 

p 

II 

X 

> 

•—* 

HH 

< 

M 

X 

p 

z 

z 

z 

X 

< 

X 

►— 4 

z 

l“3 

X 

— • 

< 

• 

X 

o 

t-H 

X 

2 

z 

z 

z 

z 

X 

D 

p 

X 

CJ 

< 

X 

X 

t-4  a. 

l—4 

p 

►-< 

X 

•  X 

X 

►— 4  X 

z 

X 

X 

p 

►H 

+ 

l-4 

X 

< 

5 

CJ 

< 

t-H 

X 

II 

" 

z 

II 

“ 

II 

p 

-  — 

E- 

— • 

II 

p 

— 

II 

p 

- 

E- 

X 

II 

+ 

II 

p 

< 

p 

II 

p 

O  CJ 

II 

X 

p 

p 

X 

h-t 

X 

p 

X 

P  X 

l-4 

p 

X 

s: 

X 

z  < 

X 

z 

p 

X 

X 

X 

X 

X 

E- 

O  X  X 

X 

p 

E-*  O  X  E-1  O 

X  X  z 

z 

z 

p 

X 

z 

X 

c 

X 

u 

I-*  E- 

o 

t-t 

z 

t— 

CJ 

ZZ  3 

n 

•-*  o  z 

»-<  CJ 

Z  5  X 

HH 

*—> 

l-4 

2 

o 

Dr.  Dobb’s  Journal,  Number  57,  July  198 1 


33 

305 


BASIC  Rubik’s  Cube  (Text  on  pages  19-21) 


O 

V 


o  z  o  z 

b  o  o  {- 

o  u  to  —  U 

m  —  +  o  * 

n  a  h  n  »  ah 

n  u  x  u  m  , 

•  u  n  n  u 

-OP!Z530!Z' 

«  h  O  tfl  tfl  O  I 

VOkAOObA 

0  o  U  U  U  U  l 

b  W  *  «  »  ' 

Z  K  Z  Z  X 

i  u  O  w  u  u  O  w 

uXh3XXh-< 

4  h  a  h  h  H 

*.  —  -a  -  M  1 

Dm  n  u  **  o  a  ~  I 

a  ce  *  a  n  x  u 

Q  x  Q  0 

£  £  £  X  w  X  X  ! 

wwwwOnwwo~i 

KEKMk^HMUDl 


oo  oooooooooooo 

o  —  Nflvm^sa^OHNn 

n  n  cnnncnncnoencr*** 

CM  CM  CMCMcMCMNCMCMCMCMCMCMN 


M  -<  *•  O  — 

go  a  h  n  *  ah 

mux  u  M 

U  OB  OB  U1 

~oxz3Dxz 

4  h  o  tfi  tn  o 

*'OW~OOW~ 

oo  o  o  o  u 


oooooooooo 

nnnnnnnnnn 


Z  KZZ 

C  U  0  v  U  U  i 

0  x  h  a  X  I  I 

«  h  »  b  b 

oa  M  a  o  -  o 

a  X  *  a  ii  i 

Q  X  Q  Q 

£  X  -  i 

U  lii  O  N  U  b  I 

OC  H  U.  h  -  H  I 

O  O  O  O  O  O  I 

M5  P-  03  9*  O  —  I 

®  <4  M>  -4  P*  P-  I 

CM  (M  CM  CM  CM  CM  I 


I  w  >»>  w 

£  OB  OB  OB 

a  a  a 

*  ~  ~  ~ 

4  4>  CM  Yl 

C  ' 

CM  CM  CM 


4  OB  00  00  OB 
-  a  a  a  a 


£  -  CM  -  CM 

tu  w  w  w  w 

X  CC  3  J  It 


Z 

u 

>*  M 

£ 

M  Q 

M 

1 

M 

: 

OC  £ 

0 

W  Z 

_• 

Q 

CD 

0 

PC 

< 

OC 

W 

a 

tfl 

b 

£  £ 

0. 

u  x 

0. 

> 

* 

— 

Be 

M  0 

X 

< 

s 

OC 

W  > 

£ 

£  oc 

PC 

b  H 

V 

M 

u 

U 

o  b 

M 

w 

X 

V 

tfl 

*  u 

u 

OC  0. 

z 

> 

0 

; 

CM 

03 

Q 

< 

w  £ 

-  h 

tn 

•  — 

0 

w 

0 

Z 

Z 

Q  K 

OC 

* 

•  » 

w  os 

h  w 

< 

M 

Q 

w 

3  ♦ 

w 

X  CU 

Z  £ 

h  w 

: 

0 

OC 

h 

w  w 

Z  X 

*  Z 

*•* 

< 

*  1 

w 

X 

£  0 

z 

w  h 

M  (X  CC 

X  u  w 

u  H  h 

X  Z  Z 


393  X)  £  £  T3  U  T3 

3  3  3  £  D  XI  V  Q  V 


393  £  £  £  V  V  V 


h  h  h  h  h 

Sm55555j;£££££ZZ£ 

kkekekkuuuuuuuuu 

CUWCUCUQ«CUXXClSXaSXKXXK 

OOOOOOOOOOOOOOOO 

0*MpMPlVlrt>Of^®0-0»MN«,»4,in 

OOOOOOOOOO-M^-^-- 


-WWW  * 

b  a  b  ae  : 

-  -  Z  0-  w 
tfl  >  ~  : 

O  X  u 
CU  z  O.  OC  w 

O  <  U 

H  Z  < 

Z  >•  O  w  w 

w  *  n 

E  JH30: 

EEZUZl 
3  tfl  -  ~  : 

u  -  a  w  u 

a  a.  o  <  i 

>  w  I 

<  o  o  tn  ■ 

JHH)Z 

a.  mm 

tn  *-<  > 

b.  >  0.  >  M 

Q  o 

o 

?  es 


£  £  £  ££££££££ 

WWW  MMMUUUMU 

cc  x  x  eeeeeebe 

ooo  oooooooo 

•0(s®  J>O^Nn4lftM 

-NIMNCMNIMN 


h 

X 

Z 

<  b 

Z 

X 

M  M 

Pm 

X  U  tfl 
■<  <  >* 

h 

3  < 

tn 

~  a  x 

< 

<  X 

w 

w  <  tfl 

no  > 

M 

Z  >•  ^ 

0  u 

«4  <  x  x 

z  z 

0  X 

z 

•  tfl  £  < 

K  tfl 

0  U 

~  {-  w 

h 

— 

W  £  > 

tn  a 

H  Z 

-  J  X 

M 

w  w  w  < 

w  h 

a  w 

*  U  X  X 

tfl  3  M 

Z  N  tfl 

~  <  <  0 

0  U  M 

0  «  X 

W  X 

CU  U  Q 

U  J  w 

X 

-  -  £ 

ENZ 

<  h 

w 

Q  U  U 

3  u  m 

X  m  M  U 

Q 

*  «  -  b 

a. 

0  b  w  < 

M  Z 

~  CD  - 

tn  z  >e~Qoom~ 
JQ0)UBZZ<Q 
<ZmOOW-«£ZZ 

bbb  x  <  h  u*-*£ 

a  w  £  <  a  a  a  a  w  3 
u  Z  £  b  U  5  w 

333  TJ-OtB  flUOO-O-N^EOO 

3  O  U  OC  I  b  Z  E  U 

333  «-W«b  tJQTJ 


333  TJ  TJ  D 


cimmctttt 

muuwumuuuwumu 

ooooooooooooo 
t^«^o  —  Nncin'4N®0' 
(MfMNnn|,>,,>fl,'’p,,,'nrt 


tn  a  a  a 

M 

bl  •  •  Q 
CD  <  U 
«< 


miuitiitc 

MUMMWWWUUUWU 

KctKBitKttttleo;** 

oooooooooooo 

o  — 


3  oo  a 

~  U 

3  I  - 

*  O 

-  Z  I  - 

M  N 

-  Z  I  b 
X  - 

*  <  ~  ~ 

-  h 

Z  -  - 
-0-- 
w  u  m  h 


£££££££ 
W  U  u  U  U  M  w 

0C  SC  SC  X  00  cc  x 

o  o  o  o  o  o  o 

cm  co  «r  in  <  r*  o 

n  id  m  ti  m  M  ia 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


m  -  t 
Q  Q  Q 


m  m 
n  n  m 


**  w  n  n 
v  <r  in  w 


O  9 

v  n  n 


a  i 

«p  n  m  < 


n  pi  n  t  v  » 


non 

i  i  i 


oa  so  a  a 
■  «  a  « 


00  00  00 

•  ■  I 


i  oa  oa  a  c 

aoi 


N  V  N  • 

m  n  to  « 


i  n  irt  n 

IM- 


kJ  CC  J 

o  o  o 

o-  o  « 

n  ®  ® 

N  N  N 


K  J  K  Q 
o  o  o  o 


u  ae  9 

o  o  o 


•  -  Z 

•  -  a 

•  *  9 

>  ▼  b 

u 


2  2 
U  U 


JEJEQJEl£ 


I  N  N  N  N  < 


O  Z 
b 


-  i  H 

•  n  U  N 

«,  ui 
«  O  K  Z 
-HO" 
o  O  e  ~ 
K  o  u 
m  * 

•  2  E 

o  u  O  - 
«  X  h  u 
-  h  b 
e  -4  4N 

M  I  U 
I  00  * 

□  00 
2  oc  - 
U  U  O  N 
E  M  In  h 


o  o 
m  -* 
>  o 
«n  v 

00  00 
9  9 
oi  « 
o  o 
o  o 

z  z 

u  u 
X  X 
b  h 


E  0 

u 

h  « 
UNO  * 
ui  •  - 
O  2  •  - 
h  £  h 


U  h  4  N 
U  H  £  * 


sc  2  ~  - 

0*9 


E  E  E 

I  I  H 


a  a  a  a  9 


u  *  ~  ~ 

m  *  -  n  pi 

e  «  • 

h  -  o  -  - 

H  4  Ik  Ik 

-  I  *-  I  I 

I  *  U  «  « 

oo  u  v  «•» 

DO  00  2  -  * 

O  V  u  V  V 

'  E  Ik  DO  iJ  9 


•*  m 

n  w 


«•  n  n  n  v 

<r  <r  tn  *  m 


N  N  N  PI  PI  1 


Ik  Ik 
•  N 


IkIkIkIkIkIkIkIk 


O  O 
<  fs 


o  o  o  o  o  o 

a  »  o  h  n  pi 

0-0-0  0  0  0 

N  N  PI  P)  PI  P) 


o  o  o  o  o 

V  Iff  +  N  0 

o  o  o  o  o 

in  C*l  pi  tO  pi 


i  n  n 

:  j  bo 
i  o  o 


»  »  in  pi  n 

W  E  J  Q  00 

o  o  o  o  o 


►J  9  DO  j  00 


p)  w  PI  PI  p> 


o  o  o  o  o 
o*  o  **  m  pi 

*4  <M 

PiPJPiPIrtPiPiP) 


*4  *4  0-0 


I  I 

~  -  -  z 

m  m  <4  00 

...  9 

*  «  *  b  2  2 

V  -  «  u  u  u 

U  Q  E  E  E  E 

O  O  O  O  O  O 

vn-Of'cco- 

14  N  14  N  14  N 

PI  PI  PI  PI  PI  PI 


O  00 
h  o 

O  Ik 
O 

* 

2 

u  o 
X  h 
h 


I  oo 

a 

00 

I  Ik  o 


2 

O  tn 
o- 
h  n 

M 

U  00 
Z  9 
oi 
~  o 
u  o 

00  2 
-  u 
J  X 
B  H 

o  - 

•  B 

x  a 

(4  Ik 

H  ~ 


H 

m  m  C 

u  4 

O  Z  • 

o  h  xi 

o 


It  h  4 
U  N  C 
OD  U 

9  00  2  - 

01  O  in 

O  Ik  H 

O  U  m 
in  *  - 

2  co 
u  o  -  • 
X  b  ~  o 
b  h  4 
«  i  »* 
O  N  ~  J 
B  OO  U 

a 

e  e  r 

b  O  v  U 

H  u  J  E 


W  W 

a  a 


O 

h 

O 

O  01 
w 
o  9 
n  u 
o  < 
m  > 


■  -4 

~  I 

O  ~ 

‘  o 

*  00  * 
-  00 
0  9- 
b  Q 
*  •• 
NOV 
B  -  - 
U  B  - 


-  -  b 


ffl  u 

9  U 

01  < 

O  O  Ik  ~  B 
>  O  00  u  - 
WO  *  O 
OZNbE  * 


o  o  o  o 

PI  PI  PI  PI 
N  N  N  N 


O  0 
h  h 
•  0  o 
:  o  o 


o  o 
h  h 
0  o 
o  o 


o  o  o  o 

4)  (4  B  - 

•  *4  V  o  •* 


‘  i n  1 


Z  Z 


X 

i  oo  a  h 

•  9  9 

I  01  oi  s 

10  0  ♦ 
I  O  O  : 


00  00 

□  9  9 

Z  01  oi 
<00 
2  0  0 

2  a 

O  2  Z  2  2  - 


o  : 

I  Z 

O  o  - 

*  < 

_  •  o 

u  -  < 

X 

h  O  h 
h  9 
son. 
10  2 

B  Z 


IBBBBB  a  N 

010101010101  VO  ' 

u  •  o 

ZZZZZZ  -on 

UWMMWU  Z  »  4) 
XXXXXX  W  n 
hhhhhhowoo  * 
N  B  9  o 
::::::  a  j  01  m 
Q90bJEn  On 
::::::  ''On 

B  a  ■  B  B  B  o  N 

h  n  2  o 
O  -  w  n 


w 

•J 

a 

w 

K4 

w 

E 

E 

U 

w 

u 

u 

U 

•4 

•4 

X 

N 

. 

. 

. 

. 

o 

. 

4 

h 

s 

X  w 

V 

J 

w 

b 

: 

X 

X 

X 

X 

4 

4 

b  e 

. 

9 

• 

4* 

«» 

E  h 

N 

• 

44 

•A 

2 

h  < 

E 

H 

2 

b 

b 

h 

h 

4* 

«* 

0 

<• 

< 

< 

< 

< 

< 

< 

2  X 

A- 

n 

n 

►4 

b 

►4 

0  N 

H  O 

►4 

o  b 

< 

< 

44 

E 

< 

44 

44 

40 

44 

44 

44 

u 

U 

O 

00 

m 

• 

» 

E  9 

: 

r  h  o 

a 

W  N 

E 

' o  9 

z 

z 

: 

: 

44 

44 

1 

E 

O 

44 

«* 

** 

4» 

4* 

«* 

4* 

X 

♦ 

n 

9 

m 

m 

E 

E 

>* 

►4 

44 

9- 

2  ^ 

E 

•4  E  > 

2 

E 

E 

4* 

«• 

W 

m 

V 

h  H 

H 

H  h 

H  H 

4* 

01 

« 

— 

— 

2 

: 

2 

N 

N 

u 

V 

*  2 

z 

: 

: 

: 

H 

h 

44 

: 

N 

h 

X 

X 

X 

X 

X 

X 

< 

B 

0 

— 

•4 

»4 

►4 

H 

►4 

II 

44 

44 

u 

44 

It 

ii 

* 

B 

E 

E 

— 

44 

E 

o 

o 

o 

o 

o 

o 

o 

♦ 

04 

O 

E 

E 

b  b 

4> 

E 

o 

u 

m 

h  n 

«• 

«• 

W 

CJ 

b 

W 

t-t 

tK 

2  W 

< 

• 

H  9 

Z  9  W 

< 

< 

< 

< 

v4 

J 

J 

D  2 

0 

a 

E 

E 

E 

E 

E 

E 

0) 

u 

u 

01 

2 

2 

2 

*4 

z 

2  E 

E 

E 

X  01 

►4 

01  Z 

| 

►4 

h 

O 

B 

N 

►4 

►4 

>-< 

E 

►4 

E 

w 

O 

44 

w  o 

E 

0  - 

E 

E 

E 

E 

B 

E 

E 

E 

E 

0 

B 

4> 

E 

E 

E 

E 

E 

E 

E 

4» 

E  Z 

a 

a 

a 

E 

w 

E 

E 

E 

a 

2  O 

E 

O  kI 

** 

-* 

a 

** 

E 

o 

01 

< 

- 

- 

- 

- 

- 

- 

u 

- 

0 

o 

o 

o 

O 

o 

O 

o 

O 

O 

o 

o  o 

O 

o  o 

o 

O 

O 

O 

o 

O 

O 

O 

o 

o 

o 

o 

O 

o 

O 

O 

o 

O 

o 

o 

o 

o 

N 

o 

*4 

N 

n 

V 

m 

* 

N 

a 

0-  o 

•4 

n  n 

V 

m 

-0 

N 

® 

N 

o 

»4 

N 

n 

V 

in 

* 

N 

0 

9 

o 

04 

N 

n 

V 

m 

m 

>0 

* 

<0 

•o 

-0 

-« 

-o 

-« 

-0 

■43  N 

N 

P.  N 

f4 

N 

N 

N 

N 

N 

CO 

0 

0 

0 

0 

0 

to 

• 

a 

0 

9 

9 

9 

N 

o- 

N 

h  Q  2  2  2  2 

0  Z  u  w  w  u 

OUKEEE 

O  O  O  O  O  O 

>0  N  CO  P-  O  *4 

0>  N  O-  O-  O  o 

H  4  -  -  N  N 


o  oo 
b  O 
O  w 
o 

in 

Z 

u  o 
X  h 
h  ^ 

N  B 

b  a. 

a 

00 
w  O 


u  m  • 

o-  I 
h  n  ■ 

I  H 

W  00 

Z  9 
01 
-  o 
u  o 

GO  Z 
w  w 
Q  X 
B  h 

U  -4  I 

ac  a  i 

N  Ik 

h  - 


O 
O  b 


E  0 
u  < 

h  « 

M  C 

W  4  • 

Z  4 


u 

00 

9  E 

01  O 

O  Ik 

o 


b  4  « 
M  C 


z  -  - 


-4  N 

U  m  ■ 


ri  .  w  n  n 


2 

w  O 
X  h 
h 


-<  o 

H  4 


Ik  O 

•x  (k 


~  Q  ■ 
U  i 


E  2  ' 
W  w 
a  e  i 


a  a 

B  B 


ooooooooaoo 


Ci. 

o 


o 


3 

•S 

c 

<s 


»4  n  n  n  n  v 
Q  Q  □  Q  Q  Q 


Ik  E  Ik  ffl  Ik  1 


N  N  N  N  N  N 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


35 

307 


of  page  34)  I  (Continued  on  next  page) 


BASIC  Rubik’s  Cube 


X 

0> 


H3 

<L» 


C 

o 

o 

00 

G 

</> 

3 


<N 

i 

Ov 


1/5 

<L» 

00 

co 

Q. 

c 

O 


u  x  u  u 
*  X  *  * 


X  VC  VC 

x  h  x  x 
u  Z  u  u 


u 
•*  a. 


2  I 
~  h 
x 

0.  V 

I 

2  •< 
u 

X  K 

H  O 


h  h 
2  2 

X  X 
X  X 

2  2 
u  w 
X  X 
h  h 


u  2 
x  « 
01  X 


h 

2  2 
u 

X  X 

x  h 


-  x 


1  -  *  X 


u  * 


:  <  < 
I  X  X 


h 

2  ~ 

~  ~  O  ■*  w 

x  a  h  :  oo 

x  <  < 

h  «  :  h 

o  w  <  h  oc 

■  h  h  X  h  h 

H  <  h  2  2  2  h  2 

M  N  ~  «  X  ~  N  ~ 

UiXMXCOKUX 
2m2xxxxZx 


i  * 

X 
X  W 
X  Q 

h  - 

CO  • 
X 
N  X 

u 
o  •* 

h  S 


00  Q 
<  ~ 
H  • 


-  < 


h  x  «  x  h  *  : 

Z  u  *  u  z  i 

X  :  00  :  EH: 

X  <  X 

:  h  s  n  : 


I  * 

X 
X  V 
X  Q 

h  - 
•*  ffl  * 
-  X 

N  N  X 

*  o 

~  o  * 
00  h  : 
< 

h  *  : 


x  h 
2 


_  2 
>  x  H  h  x 
2HZ3 


O  X 

x  x 

ooooooooooooooo 

o-a-<Nn<T¥i'Cr>.«».o^Nn 


HHHHHXh  h 
HZ2ZZ2  2  H  2  t-- 

XKXoCKXOXXXOXXKXXU 

2xxxxxxx2xxx2xxxx 

ooooooooooooooooo 

fKl^NOlVO  -  Mr)VO'OP'«»-0 

r«r>N^r*>ivaoa>«>««««c««o> 


2  n 
X  N 
VC  Q 


3  3 

t0  (0 

o  o 
o  o 


X  Q 

2  X 

-  J 

h  x  • 

3  r 
o  < 
x  x 


V  X  - 
<M  9  « 

•  -  I 


a  a  ; 
a  a  i 
3  3  * 


o.  H  -  -  - 
2  x 


o  o  o  o 

n  o>  **  <*) 

<  9-  n  •« 

N  N  «•»  W 

2 

do  oo  n  oo  k 

3  3  3  3  3 

ffl  ffl  to  ffl  H  t  £ 

O  O  O  O  x  u  u 

O  O  O  O  X  X  X 


h  h 
Z  2 


:  x  x 
i  x  x 


h  H 
Z  2 


x  x 

X  X 


OOOOOOOOOOO 

VV'T'V'V'C'VVViniO 


O  O  O  O  O  O 

n  m  «r  *">  -c 

o  o  o  o  o  o 

n  n  n  n  n  n 


H  H 
2  2 


X  X 
X  x 


h  h  i 
Z  2 


X  X 
X  x 


H 

'  M  M  V 
X 

1-20 

•  =  •  H 

•*  u 

I  U  N 

*  H  o 

1  x  h  u 

•»  X 

:  =  2  X  : 

I  ~  O' 

-  X 

X  •  I 

<  V 

X  w 

U  U  o 

<  to  h 

X  < 

'  In 

-  M 

h  o  x 

2  * 

~  E  X 

X  ~  O 

xxx 


I  M  V  I  M 

X  X 

-20-2 

:  h  : 

*  U  *  U 

O  NO 

•*  h  h  *H 

X  N  U  X  N 

•«  X  «  X 

2  X  r  Z 

•  O  ~  •• 

-  X  ~ 

ffl  •  X  • 

<  V  < 

X  W  X  ~ 

u  u  o  u  u 

<  ffl  h  •<  cfl 

XX  X  < 
:  N  n  :  i 

~  I  ~ 

h  u  x  h  u 

2  *  2  * 

-  X  X  -  X 

x  -  o  X  ^ 

x  a  x  x  x 

OOOOOOOOOOO 

c09>O'*Nr>)Vrt'«r<<0 

mnniiDninmiAiniAn 


X 

N  v  -  m  -IrtN^NV  N«  [_ 

*  •  '  *  .  *  ion  n 

—  N  N  VVM1V)NN  U 

w  wws,  -  OZ  O 

X  XXX  XXX  XX  x  x  x  H-ooX 

. . nun  IN  OUW- 

—  —  —  —  ————  —  —  m  ^  >  o  — 

N  NNN  ^IrtN  N  V  ao  II  {-  PI  V  II 

*  ***  .  ..  NUN  O 

NV*<lrt  NNN  N  N  V  *  r*  «  U1  ffl  ffl 

X  ^  ^  -0XZ33X 

3  333  QQQ  03  3  □  Q  4  h  O  ffl  ffl  O 

.  ^  O  X  ^  O  0  x 

0O  UOO 

Nnr^io^irt^rtNNVNNWN^NNv  u  r>.  m 

.  2  X  2  2 

^-^NNn(nvv«^)HNNNnw»v»  i  u  O  v  u  u  o 

VN/WWVWS/V/WWWWWVVVWVWV  0  I  h  X  I  I  h 

xxxxxxxxxxxxxxxxxxxx  * h  Nhh 

N  I  N  n  II  N  N  I  N  H  N  I  N  II  I  I  N  N  N  N  »<  -  -  - 

Xn  M  o  -  O  I 

VNNVNVNVNVnNM^-m^MN^OC  llX*HNX 

. 3  Q  XQQ 

-<n-NNr)nv»nNiiNnNnNv^'r^iZSC  X  ^  X 
s/^Vwwwwvwwwww^v^v^w^uU1UWX0NXX0 

ffl3xaxmxfflxfflQxffl3xnxfflQxxxxx>-<xHMM^ 

OOOOOOOOOOOOOOQOOOOOOOOOOOOOOO 

©‘O^NNVn'0f^®^O-NNVlrt'«N«».O^NnVlrt'0N® 

NcnnnnncnnnNPincnncnnfflNNNNNNNrtNrtcoNN 


C  * 

•  - 

•  W 

£  X 


4  V 

£.  * 


*<  N  N 

EKE 

»  »  » 

n  m  -« 

3  3  3 


m------- 

vNFlfHD-D 


XXX 
I  I  N 


X  X 

N  N 


QQQ  03 


4XKKKEXE 
-  I  I  I  I  I  N  I 


»«  n  n  v  n  n 
v  v  m  irt  r>  n  n 


X  X  X  X  X  X  X 

N  II  I  N  N  N  I 


X  X  I 
I  I 


Z«4p)«4NN<nfn 

xx3nxfflxn 

OOOOOOOO 

O-NPIffkl^N 

NNNP.P«P*NN 

nneinBcinw 


v  n  v  n  n  «  m 

v  t  m  »  w  n  «n 

X  00  X  Q  00  X  3 

O  o  o  o  o  o  o 

CO  »•  O  **  N  «*)  V 

r*  as  cb  ®  ®  ® 

«  cn  N  f)  N  <*>  «•> 


ION1 

I  X  ffl  I 


I n  9 

0  a 


Z 

X 

3 

h  r  2 

u  uu 

xxx 


ooooooooo 

HSJNfflO'O^NN 

e000««®»-O'O'O' 


U  X 

z 

m  h 

h  x 

3  u 

0  Z 

X  M 

00  u 

3  0 
«  h  H 

X 

?  -  U 
O  H  Z 

U 

<  X  u 

X  o  ' 

X  x  X 

<  w 

H  N 

M  H 

H  O  « 

<  H  - 

h  k 

O  -  I 

x  ii  +  Z 

X  ♦  X 
U  3 

Ex-HE 

U  o  ^  u  X 

x  x  h  x  x 

o  o  o  o  o 

v  rt  •«  n  ® 

9>  9>  9>  »  »• 


35  Dr.  Dobb’s  Journal,  Number  57,  July  1981 

308 


« 

X  « 

« 

M  « 

— 

a 

« 

h  « 

n 

x 

« 

Z  « 

— 

u 

« 

—  « 

w 

A 

- 

• 

9 

X 

9 

« 

X  « 

9 

u  u 

Q 

< 

X 

h 

< 

« 

X  « 

X 

bl 

•* 

•* 

0 

•* 

« 

« 

X 

X  X 

> 

« 

0  « 

u 

v  V 

< 

h 

h 

z 

h 

« 

9  « 

9  Q 

a 

D 

D 

0 

9 

« 

9  « 

A 

a  a 

X 

X 

X 

X 

« 

« 

9 

z 

Z 

Z 

X 

*  t 

« 

a  « 

w 

u  u 

M 

— 

— 

~  Z 

« 

Q  « 

9 

•  . 

U 

bl 

— 

« 

—  « 

X 

X  X 

a 

bl 

bl 

U 

bl  X 

« 

« 

X 

z 

z 

z 

Z  x 

« 

9  « 

u 

—  — 

a 

— 

— 

bl 

—  •  • 

« 

« 

•» 

D  Q 

< 

u 

J 

D 

u  X 

bl  « 

•  « 

— 

X 

0 

z  « 

1  « 

n 

— 

•« 

X 

•• 

X  bl 

*  h 

—  « 

X  « 

NO 

u  u 

bl 

: 

: 

a 

X  H 

h 

« 

9 

> 

h 

h 

u 

D  u 

X  « 

X 

X  X 

0 

a 

M 

9 

a 

M  h 

9 

>  z 

0  h  D  « 

X 

9  W  W 

a 

bl 

u  Z 

X  0 

« 

u 

•J  X 

< 

— 

z  0 

— 

Z  bl 

0 

-  u 

■  Z  h  « 

•* 

9  0  1  a 

: 

h 

5 

x  h 

• 

D 

bl  « 

bi  <  Z  h  ~  ~ 

h 

-  u  *  u  u  *  h 

MU  MU  U.MUM 

a  - h  a  •Hu  ■  *  w 
UKMUBNhUKZ 
•»  bl  ••  bl  Q  •*  •• 

X  ■  Z  X  :  Z  x  :  ~ 

O  —  O'*  (1  o  «  * 

x  -  u.  ->  <  u.  < 

X  9  D  •  X  O  ~ 

9  <  9  <  9  U 

u  w  u  ~  u  u  w 

ouuouuuou< 
h<tflh<<tn<h<  ■ 

X  <  X  <  X  X  - 

m  :  a  M  :  ■  I  M  :  K 

a  -  »  ~  Q  a  i  Z 

X  h  u  x  h  u  x  h  >o  x 

Z  *  Z  *  Z  D 

X-XX-XXX-UhXX 

OBvOBvuOB^UUbl 

UUKUUSChBQSKE 


Z  *  X  u  u 
—  x  D  m  •  * 
h  h  i  X  X 
D  w  U  v  v 
O  X  -  - 

XU  x  a  x 
a  x  Z  O 


w  «*  o  «J  X 

£<Zh  •  i 

■*  X  -  - 

O  :  D  M  U  U 

h  hi** 
►  U  u  X  X 

bl  X  **  ~ 

■  U  X  u  X 

oxzo 


«  h  «  x 

h*  hi  HI 

bl  «  bl  «  D  U 

«  «  z  «  O  Z 

h  x 

h  Z  D 

miB-Hii 

blblblblOXblblbl 

xxxxxxxxx 


D  D 

t*i  a  -  - 

X 

U  D  bi  bi 

a  a 

X  u  u  X 

X 

X 

ax 

: 

h  9  *  * 

< 

X  0 

bl  :  h  9 

> 

x  X  h 

a 

X 

X  h 

:  0  -  ~  *  0 

0 

bl  O 

h  N 

Oh:  0 

0  D 

>  h  >•  B  bi  a 

9 

X  9 

bl 

h  D  h  h 

X  X 

a  a  z  0 

n 

h  a 

a  h 

a  X  X 

w  Z 

«*»  M  —  —  9 

m 

:  a 

bl  D 

bl  Z  -  M 

X  - 

^  a  u  u  u 

Z 

X  0  Z 

X  -  v  a 

•  X 
W  < 

Z  Z  X 
U  m  u  O 
X  J  -  X 


oooooooooooooooooooooo 

»OHNn«V14NB»OriNn«^<«M0>O 

^MMMNMnMMMMtninnMtnMnMMnv 

iflnominioirtinnirtrtiflbii(>ininnioirtnn« 


x  x  h  d  : 

:  -  v-  m  x  i 

j  -  -  u  o  i 

.  X  B  Z  O  < 

I  O  O  O  O  I 

•  «n  •*  r*  •  I 


h  x  x 
ZDD 
-  «  h  x  r 

KOUUU 
X  u  X  X  X 

O  O  O  O  o 

o  -  n  m  9 

n  mm  n  n 

m  m  m  m 


X 
h  D 

X  x  h  E  £ 

bl  0  bl  bl  bl 

X  X  X  x  x 

O  O  O  O  o 

m  9  >  to  > 

m  \n  <n  m  m 

m  id  w  n  m 


9  x  u  u  a  a  h 

w  <  *  *  h  D  D  Z 

ZZ  X  X  X  X  a  a  - 

UmuovvUOOX 
xu-xxazoox 

oooooooooo 

O-NIUMIUM^ 
9999999999 
m  iii  id  iii  in  id  n  m  n  m 


u  *  •*  u  •« 

x  ~  x  ~ 

a  n  9  a  <•> 

-  u  u  ~  u 

X  X  -  X 

9  a  a  9  a 


U  u  X  u  u 

*  •  X  *  * 

M  c*  U  M  M 


x  ~  ~  X  ~  ~ 

x  x  x  x  a  u 
u  ~  ~  u  ~  ~ 
•*  •  •  ••  •  •» 

x  XX:  XX 
XX  XX 

U  U  U  U 


XX  XX 

x  x  h  x  x  - 

u  u  Z  U  U  M 


<  X  u  a  Z 

X  o  -  o 

x  x  x  a  a 

<  ~  x 

a  m  x  a 

u  h  h  bl  bi 

h  0  ■  *  h  o  >  o  o 

<  h  —  bi  Z  'O  0  ■<  9 

h  az  -  «*»  E  -  a 

0  —  *••  X  m  :  v  m 

X  I  u  u  Z  a  Z 

xi  X  a  h  a  a  x 

<HD  DZDDD 

SZx«HHizza«aaHZi 

hlblOHblblUUUOKOOUhlbl 

XKXhZaXKKUXOUKXX 

oooooooooooooooo 
>o-Mi*)«rm-cr-ao>o-Nn9 
>0000000000  —  —  --  —  — 

c)9999999909990O9 


> 

9 

X 

h  -  • 

O  -  X 

a  -  9  X 

-  u 
h  ~  0  •« 

Z  «  h  s 

-  < 

X  h  «  * 


X  **  >*  >*  >*  W 

u  d  ax  x  a 

h  *■'  <  *■'  -  < 

*  a  9  h  9  •*  •  h 

-  x  x  «  x 
mmX  HXntH* 
9  u  Z  u  «  u  Z 

w  0  *  M  M  O 

■  h  =  x  s  a  :  x  h 

<  x  <  a 

h  9  x  •  x  h  s  m 


hhuh  huh  hhhhhu 
ZZ  ZhZ  ZhZZZZZ 
E--X-M-X-N----~X 
UXXOXbIXOXUXXKXXO 
XXXXXZXXXZXXXXXX 

oooooooooooooooo 
a9f>9*o-Mr)9r>9r'>«>*o 
—  -4  —  —  —  MMMNNMMMMMO 


X  -  X 
X  MMX  h  9  * 

U  9  U  Z 

•*  ~  O  •*  -00 

:  ah:  X  h  h 

<  x 

x  h  *  :  —  m 

u  1  u  1  a 
h  h  u  h  h  X  u 

ZhZ  ZhZ 
-N-X-K-XX 
XUXOXblKOO 
XZXXXZXXU 

OOOOOOOOO 
—  Mn9n9>a> 
MMMMMMMMM 


h  h  bl  h  h  ~  h 

z  z  x  z  z  u  z 

-  -  h  -  -  X  - 

xx  x  x  a  x 

x  x  9  x  x  a 

■  h 

z  z  x  z  z  z  z 

bl  bl  bl  U  -  bl 

X  X  X  X  X  X  X 

h  h  0  h  h  X  h 

-Nnn<0"< 

1  a  ■  1  1  1  h 

<<<<<H<hZ 

M  K  — 

xuxxxbixbix 

-H--HZ-ZX 

000000090 
o  —  m  n  9  a  9  n  « 


a  a  - 
h  <  u  a 
Z  < 
-  X  X 
X  O  O  X 
XXX  — 

0000 
n  o  >  « 
m  m  m  m 


Dr.  Dobb’s  Journal,  Number  57,  July  198  1 


(Continued  on  top  of  page  36) 


Of  Interest 


by  Dave  Cortesi 


SCRIBBLE  and  MINCE  Group 

Sounds  like  a  club  for  subway  van¬ 
dals,  doesn’t  it?  Or  possibly  one  for  cook¬ 
book  authors.  It’s  really  the  Amethyst 
Users  Group,  an  organization  for  those 
sharing  a  common  interest  in  the  Ame¬ 
thyst  editor-formatter  package  described 
so  enthusiastically  in  Dr.  Dobb's  Journal 
#54.  Annual  dues  are  $6,  which  is  also 
the  tentative  price  for  diskettes  of  club 
programs.  The  latter  will  be  made  availa¬ 
ble  in  a  number  of  formats. 

Plan  Well  Ahead 

Here  are  items  you  might  want  to 
write  into  your  calendar.  The  New  York 
Computer  Expo  (NYCE)  is  scheduled  for 
New  York  City,  August  12  to  15.  The  or¬ 
ganizers  (who  claim  credit  for  the  former 
National  Small  Computer  Show)  plan 
to  charge  $10  a  day,  or  $200  for  a  busi¬ 
ness  person’s  tutorial  and  five  day’s 
admission. 

The  IEEE  Computer  Society  will 
hold  its  COMPCON  ’81  September 
14-17  in  Washington,  DC.  Conference 
concerns  will  center  on  productivity  is¬ 
sues. 

Those  whose  concerns  center  more 
on  buying  and  selling  will  want  to  know 
about  the  second  annual  NJ  Micro  Show 
and  fleamarket.  That’s  to  be  held  at  the 
Holiday  Inn  (north)  Convention  Center, 
Newark  NJ  International  Airport,  on 
October  24th  and  25th.  Exhibit  space  is 
available;  $150  gets  you  a  booth,  elec¬ 
tricity,  a  table  and  two  chairs. 

The  ACM  and  the  US  Dept,  of 
Commerce  are  planning  what  sounds 
like  a  very  interesting  conference  in 
March  1982.  The  conference  title  is 
“Human  Factors  in  Computer  Systems” 
and  Michael  L.  Schneider,  program  chair¬ 
man,  is  looking  for  papers  now.  Two  of 
the  general  categories  are  “Human-Com¬ 
puter  Interface  Design”  and  “Impact  of 
Computers  on  Human  Behaviour.”  People 
who  work  with  personal  computers 
should  have  a  lot  to  say  under  those 
headings,  and  “papers  which  present 
practical  experience  .  .  .  will  be  consid¬ 
ered.” 

Settle  Down  for  a  Good  Read 

The  mail  brought  blurbs  for  several 
hardware  books  this  month.  One  is  PET 
Interfacing  by  Downey  and  Rogers  (262 
pp,  $17,  from  Group  Technology,  Ltd.). 
It  claims  to  cover  each  of  the  PET’s  inter¬ 


faces  —  user  port,  memory  expansion 
port,  and  IEEE-488  bus  port  —  in  detail, 
giving  a  breadboard  circuit  and  a  number 
of  experiments  for  each. 

Working  engineers  and  serious  hob¬ 
byists  may  want  the  Electronic  Circuits 
Notebook  from  McGraw-Hill  (344  pp, 
$32.50).  A  compilation  by  the  staff  of 
Electronics  magazine,  the  book  is  said  to 
contain  268  circuits  chosen  to  emphasize 
“fresh  ideas  and  new  approaches.” 

The  same  publisher  has  released  the 
User’s  Guidebook  to  Digital  CMOS  In¬ 
tegrated  Circuits  by  Eugene  R.  Hnatek 
(339  pp,  $24.50).  The  work  is  said  to 
cover  the  entire  CMOS  field  with  empha¬ 
sis  on  LSI  circuits,  to  be  practical  in  ap¬ 
proach,  and  to  give  specific  applications. 

RCA  has  what  should  be  a  good  com¬ 
panion  volume  to  the  one  above:  the  la¬ 
test  edition  of  688-page  COS/MOS  Inte¬ 
grated  Circuits  data  book.  SSD-250B  is 
their  order  number;  it  costs  just  $7. 

Settle  Down  for  a  Free  Read 

The  mail  also  brought  a  number  of 
offers  of  free  catalogs.  DEC  offers  engi¬ 
neers  their  Software  Referral  Catalog, 
listing  300  software  packages  from  inde¬ 
pendent  vendors.  The  COMAL  Informa¬ 
tion  Exchange  wants  to  send  you  an  in¬ 
formation  package  on  that  language,  cur¬ 
rently  all  the  rage  in  Europe.  ENTELEK 
(could  that  mean  “mind”  in  Esperanto?) 
is,  apparently,  a  book  dealer  specializing 
in  computer  books  and  computer  pro¬ 
grams.  They  offer  a  catalog  of  micro-ori¬ 
ented  books,  many  accompanied  by  pro¬ 
gram  disks  for  TRS-80  and  Apple. 

We  got  catalogs  from  two  dealers  in 
supplies  for  small  computers:  MISCO  and 
Inmac.  We  compared  prices  on  a  couple 
of  products;  MISCO’s  were  slightly  lower. 
On  the  other  hand,  Inmac  doesn’t  charge 
shipping  on  prepaid  orders.  Inmac  is  run¬ 
ning  a  contest  with  an  Apple  II  as  first 
prize. 

Two  Unusual  Periodicals 

We’ve  now  received  volume  1,  num¬ 
ber  1  of  Software  News,  a  monthly 
tabloid  devoted  to  computer  software 
($20  per  year).  It  certainly  wouldn’t  be 
fair  to  judge  a  periodical  on  the  content 
of  its  first  issue,  but  we  wonder  a  bit  at 
the  paper’s  format.  It  uses  five  columns 
on  newsprint,  resulting  in  the  dim  gray 
look  standardized  by  such  well-known  in¬ 
dustry  tabloids  as  Computer-world.  We’d 
hoped  for  something  more  attractive;  the 


recent  improvements  in  Info  World  show 
what  can  be  done  with  the  tabloid  for¬ 
mat. 

When  you  read  a  computer  maga¬ 
zine,  do  you  spend  more  time  on  the  dis¬ 
play  ads  than  you  do  on  the  articles? 
Don’t  blush,  many  do.  Gordon  Publica¬ 
tions  has  the  answer.  They  publish  Com¬ 
puter  Products,  a  bi-monthly  magazine 
that  eliminates  all  that  annoying  editorial 
matter;  it  contains  nothing  but  glossy  dis¬ 
play  ads,  page  after  slick,  11”  by  14” 
page  of  them.  $6  per  issue. 

TRS-80,  Speech  Impediment 
Removed  .  .  . 

A  package  from  Baysik  Speech  adds 
the  SAY  verb  to  TRS-80  BASIC.  Having 
loaded  it  (it’s  self-relocating  and  won’t 
disturb  any  other  special  drivers,  they 
claim)  users  of  the  Radio  Shack  voice 
synthesizer  can  code  SAY  much  the  way 
they  code  PRINT.  Coding  SAY  “7/4=”; 
7/4  is  supposed  to  produce  the  words 
“seven  divided  by  four  equals  one  point 
seven  five”  from  the  synthesizer.  The  pro¬ 
duct  allows  words  to  be  programmed 
with  English  letters  rather  than  special 
characters:  “BAYSIK”  instead  of 

“B”+CHR$(94)+“S#K”.  The  package 
costs  $125. 

. .  .  Writes  for  Other  CPUs  . . . 

Allen  Ashley  has  produced  a  set  of 
six  matched  cross-assemblers  for  the  TRS- 
80.  Each  package  lets  your  TRS-80  be¬ 
come  a  development  system  for  one  of: 
the  Intel  8048,  the  RCA  1802,  the  Na¬ 
tional  COP400,  the  Zilog  Z-8,  the  Fair- 
child  3870,  or  the  AMI  S2000.  Each  as¬ 
sembler  uses,  “with  minor  exceptions,” 
the  mnemonics  of  the  target  CPU,  and 
costs  $75  on  diskette  or  tape.  Once  a  pro¬ 
gram  is  assembled  it  must  be  sent  to  the 
target  machine.  Allen  Ashley  suggests 
sending  the  data  through  a  CPU  port  di¬ 
rect.  However . . . 

.  .  .  Burns  PROMs  for  Them,  Too 

.  .  .  Orion  Instruments  has  an  EP¬ 
ROM  programmer  for  the  TRS-80,  so  you 
could  put  the  cross-assembled  program 
right  onto  a  chip.  The  “Developmate 
81”  plugs  into  the  expansion  port,  can 
handle  just  about  any  current  chip,  and 
comes  with  software  for  $329.  The  same 
box  contains  a  Z80  in-circuit  emulator.  A 
40-pin  connector  mates  the  Z80  socket  of 
a  target  system  to  the  TRS-80  bus  so  that 
the  target  can  be  completely  controlled 


38 

310 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


and  checked  out  from  a  program  in  the 
TRS-80. 

Apple  II  Bus  Stretches  Out 

Great  ideas  are  always  simple,  yes? 
Our  vote  for  clever  product  of  the  month 
goes  to  Passport  Designs  for  the  Softbus. 
It’s  simply  an  Apple  II  bus  card  with 
nothing  on  it  but  the  heads  of  three  16- 
conductor  ribbon  cables.  The  three-foot 
cables  terminate  at  their  other  ends  in  16- 
pin  connectors  so  they  can  be  pushed  in¬ 
to  a  circuit  breadboard.  The  effect  is  to 
bring  one  position  on  the  Apple  bus  out 
to  the  top  of  the  bench  and  spread  it  on 
the  breadboard  where  you  can  build  cir¬ 
cuits  around  it. 

Oh  Boy,  A  New  Acronym 

Just  when  we  thought  we’d  figured 
out  the  difference  between  PROM,  EP¬ 
ROM,  and  EEPROM,  along  came  Xicor 
to  announce  NOVRAM.  That  stands  for 
“non-volatile  RAM.”  What  it  means  is  a 
single  chip  with  some  RAM  and  some 
EEPROM.  The  RAM  is  used  as  it  normal¬ 
ly  would  be,  but  on  receipt  of  a  TTL  sig¬ 
nal  the  chip  copies  the  contents  of  RAM 
into  the  EEPROM,  where  it  can  remain 
“indefinitely.”  A  different  signal  loads 
the  saved  data  back  to  the  RAM.  A  NOV¬ 
RAM  with  256  by  4  bits  is  to  be  in  pro¬ 
duction  this  month,  with  a  quantity  price 
of  $12. 

A  CP/M  Software  Index 

The  Small  Systems  Group  has  re¬ 
leased  its  second  Index  of  CP/M  Soft¬ 
ware,  listing  740  programs  from  248  ven¬ 
dors.  The  press  release  comments  that  the 
software  industry  must  be  fairly  healthy 
since  only  9  vendors  of  101  listed  in  the 
prior  Index  have  gone  out  of  business. 
The  index  can  be  had  for  $6,  or  $8  out¬ 
side  North  America. 


A  Diskette  Conversion  Service 

Prestige  Services  writes  to  tell  us  that 
they  are  prepared  to  move  data  between 
the  diskettes  used  by  any  pair  selected 
from  the  following:  IBM  3740,  Apple  II, 
DEC  RT-1 1,  TRS-80,  and  CP/M  exchange 
format.  They  don’t  indicate  what  the 
charge  would  be  nor  what  volume  they 
can  handle,  but  software  vendors  might 
like  to  check  them  out. 

MP/M-86  Is  Out 

Digital  Research  has  finally  dropped 


the  other  shoe,  announcing  MP/M-86  as 
a  companion  system  forCP/M-86.  We  ex¬ 
pected  that  the  two  dash-86  systems 
would  be  more  compatible  with  each 
other  than  were  CP/M  and  MP/M.  The 
8086  hardware  architecture  relieves  the 
restrictions  that  (we  thought)  forced 
MP/M  into  such  contorted  design  tricks  as 
page-relocation.  It  seems  that  this  will  be 
the  case,  for  the  release  claims  that 
“CP/M-86  programs  can  be  operated  im¬ 
mediately  under  MP/M-86,”  something 
no  one  could  have  said  about  the  8080 
systems. 

OASIS  Spreads  Out 

Phase  One  Systems  sent  us  releases 
announcing  that  they  now  have  versions 
of  OASIS  for  North  Star  machines  and 
for  the  Cromemco  System  3.  Owners  of 
those  machines  now  have  a  choice  of 
three  operating  systems  each:  the  manu¬ 
facturer’s  DOC,  CP/M,  and  OASIS.  Would 
someone  like  to  write  a  side-by-side-by- 
side  review  for  DDP. 


Engineers,  scientists,  systems  pro¬ 
grammers,  and  business  owners.. . 
All  these  read  Dr.  Dobb’s  Journal. 
Reach  them  with  cost-effective 
advertising.  (415)  323-31  1 1. 


Contact  Points 

Allen  Ashley,  395  Sierra  Madre  Villa,  Pasa¬ 
dena,  CA  91107; (213)  793-5748. 

Amethyst  Users  Group,  Barry  A.  Dobyns, 
POB  8173,  University  Station,  Austin,  TX 
78712;  (512)  441-9466. 

Baysik  Speech,  Suite  289,  1259  El  Camino 
Real,  Menlo  Park, CA  94025. 

COMAL  Information  Exchange,  5501 
Groveland  Terrace,  Madison,  WI  53716. 
COMPCON  ’81,  POB  639,  Silver  Spring, 
MD  20901;  (301)  589-3386. 

DEC  Engineering  Systems  Group,  MR1-1/ 
M75,  200  Forest  St.,  Marlboro,  Mass. 
01752,  attention  SRC  Manager. 

Digital  Research,  POB  579,  Pacific  Grove, 
CA  93950;  (408)  649-3896. 

ENTELEK,  Ward-Whidden  House,  The  Hill, 
POB  1303,  Portsmouth,  NH  03801, 

Gordon  Publications,  POB  2106R,  20  Com¬ 
munity  PI.,  Morristown,  NJ  07690;  (201) 
267-6040. 

Group  Technology,  Ltd.,  POB  87,  Check, 
VA  24072;  (703)  651-3153. 

Inmac  Department  10,  2465  Augustine 
Drive,  Santa  Clara,  CA  95051. 

Michael  L.  Schneider,  Program  Chairman, 


c/o  Sperry-Univac,  POB  200,  Blue  Bell,  PA 
19424;  (215)  542-5808. 

MISCO,  POB  399NR,  Holmdel,  NJ  07733; 
toll-free  800-631-2227  outside  NJ. 

NJ  Micro  Show,  c/o  Kengore  Corporation, 
3001  Route  27,  Franklin  Park,  NJ  08823; 
(201)  297-2526. 

NYCE,  110  Charlotte  Place,  Englewood 
CUffs,  NJ  07632;  (201)  569-8542. 

Orion  Instruments,  172  Otis  Ave.,  Wood- 
side,  CA  94062;  (415)  851-1172. 

Passport  Designs,  POB  478,  La  Honda,  CA 
94020. 

Phase  One  Systems,  7700  Edgewater  Drive 
Suite  830,  Oakland,  CA  94621;  (415) 
562-8085. 

Prestige  Services  Division,  909  N.  CoUseum 
Blvd.,  Fort  Wayne,  IN  46805;  (219)  423- 
1571. 

RCA  SoUd  State  Division,  POB  3200, 
Somerville,  NJ  08876;  (201)  685-6423. 
Small  Systems  Group  CP/M  Software  hi¬ 
des,  POB  5429,  Santa  Monica,  CA  90405; 
(2  1  3)  392-1234. 

Software  News,  Technical  PubUshing  Co., 
666  Fifth  Ave.,  NY,  NY  10103. 

Xicor  Inc.  -  only  a  phone  number  given: 
(408)  734-3041. 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


39 

311 


Dr.  Dobbs  Clinic 


by  D.  E.  Cortesi,  Resident  Intern 


The  Doctor  is  Overwhelmed 

The  first  Clinic  produced  a  very  grati¬ 
fying  response.  More  than  60  readers 
took  the  trouble  to  write,  and  PCC 
thanks  all  of  them.  We’re  obviously  onto 
something  good  with  the  Clinic  and  we’ll 
try  to  keep  it  going  (but  see  the  exhorta¬ 
tion  at  the  end). 

The  Most  and  the  Least 

Many  readers  sent  methods  of  defin¬ 
ing  MIN  and  MAX  in  BASIC.  Although 
there  were  variations  in  the  syntax  the  so¬ 
lutions  could  be  boiled  down  to  four,  two 
based  on  arithmetic  and  two  based  on 
boolean  operations.  We’ll  give  only  the 
MIN  solution  here;  MAX  falls  out  from 
MIN  in  each  case  by  changing  a  plus  to  a 
minus  or  vice  versa. 

The  popular  choice  was  an  expres¬ 
sion  that  was  explained  most  succinctly 
by  Philip  Bacon  of  Gainesville,  FL.  His 
letter,  in  full,  said  “The  minimum  of  A 
and  B  is  their  average  minus  half  the  dis¬ 
tance  between  them:” 

MIN(A,B)  =  (A+B  -  ABS(A  -  B))/2 

A  smaller  group  took  essentially  the  same 
route  but  using  SGN  rather  than  ABS: 

MIN(A,B)=  ((A+B)  — 

(A-B)*SGN(A— B))/2 

Several  correspondents  noted  that  such 
expressions  are  unreliable  when  the  dif¬ 
ference  between  A  and  B  is  near  the  limit 
of  precision  of  the  floating  point  repre¬ 
sentation  of  the  system. 

About  half  the  writers  made  use  of 
the  fact  that  a  relational  expression  re¬ 
turns  a  numeric  value.  In  most  Micro¬ 
soft  BASIC’s,  —  1  means  “true”  and  zero 
means  “false”.  Multiplying  by  a  relation¬ 
ship  is  a  way  of  selecting  or  not  selecting 
a  value  based  on  the  truth  of  the  relation¬ 
ship.  Therefore  we  have: 

MIN(A,B)  =  — A*(A  <  =B) 

-  B*(B<  A) 

The  minus  signs  adjust  for  “true”  being 
represented  as  - 1 ;  if  your  BASIC  returns 
positive  1  for  “true”,  change  both  minus¬ 
es  to  plusses.  Note  that  one  of  the  rela¬ 
tions  must  include  an  equal  sign.  If  it’s 
absent  the  expression  yields  zero  when 
A=B. 

Harry  Saal  of  Palo  Alto,  CA  and  Dale 
Schafer  of  Bryan,  TX  were  the  only  read¬ 


ers  to  come  up  with  this  elegant  use  of 
the  relational: 

MIN(A.B)  =  A  +  (A— B)*(A  >  B) 

This  again  assumes  that  “true”  is  —  1. 
Both  expressions  could  be  made  indepen¬ 
dent  of  the  truth  value  and  thus  fully 
portable,  but  only  at  some  cost  in  per¬ 
formance.  The  trick  is  to  use  the  value  to 
adjust  for  its  own  sign: 

MIN(A,B)  =  (1  =  1  )*A*(A  <  =B) 

+  (1  =  1)*B*(B  <  A) 

MIN(A,B)  =  A  +  ( — 1=1  )*(A —  B) 
*(A  >  B) 

Allen  Ashley  of  Pasadena,  CA  point¬ 
ed  out  that  if  MIN  is  limited  to  binary  in¬ 
tegers,  then  boolean  operations  can  re¬ 
place  the  arithmetic  ones: 

MIN(J,K)  =  J  AND  (J  <  K)  OR 
K  AND  (J=  >  K) 

Bob  Goodman  of  Dublin,  CA,  extended 
selection  by  truth  value  to  give  a  MIN 
function  for  character  variables!  Here  it 

is: 


MIN(A$,B$)  =  LEFTS  (AS,  ABS 
(AS  <  B$)  *LEN  (AS))  +  LEFTS 
(B$,ABS  (A$=  >  B$)  *LEN  (B$)) 

All  in  all,  the  Doctor’s  problems  have 
been  well  and  truly  minimized. 

The  Matter  of  CP/M  Comments 

We  stumbled  onto  the  fact  that  a 
CP/M  command  line  that  started  with  a 
colon  was  treated  as  a  comment  (to  give 
belated  credit  where  it’s  due,  we  first 
saw  that  use  of  the  colon  in  a  submit  file 
that’s  part  of  the  Pascal/Z  compiler  from 
Ithaca  Intersystems).  We  asked  if  that  was 
a  reliable  feature  of  CP/M  and  its  com¬ 
panion  systems. 

John  Pierce  of  Digital  Research 
wrote  to  us  as  follows: 

“In  fact,  CP/M  systems  consider 
(semicolon)  to  be  the  proper 
comment  delimiter  on  command 
lines.  This  not  only  holds  true  for 
all  existing  systems  (including  1.4, 
2.2,  MP/M,  and  CP/M-86),  but  will 
continue  to  be  supported  in  future 
versions.  The  present  CCP  ignores 
lines  that  start  with  most  termina¬ 
tors,  but  we  will  not  guarantee 
that  this  will  always  work.” 


Our  thanks  to  John  for  the  clarifi¬ 
cation,  and  apologies  to  readers  who’ve 
been  putting  colonized  comments  in  their 
submit  files.  We  hope  to  see  lots  more 
contributions  from  John  and  his  col¬ 
leagues  in  Pacific  Grove. 


Approximately  Right 

In  the  May  Clinic  we  gave  an  approx¬ 
imation  to  the  hypotenuse  of  a  right  tri¬ 
angle: 

happrox  =  max(dh.dv)  + 
min(dh,dv)/2 

or,  the  hypotenuse  is  approximately  the 
longer  side  plus  half  the  shorter.  Bob 
Hoolko  of  Grants  Pass,  OR  responded  as 
follows. 

I  have  seen  your  “max(dx,dy)  + 
min(dx,dy)/2”  handy  approxima¬ 
tion  for  SQR  (dx**2  +  dy*»2) 
used  in  digital  radar  signal  proces¬ 
sing  to  calculate  the  magnitude  of 
complex  numbers.  This  method  is 
easy  to  implement  in  high  speed 
hardware.  Unfortunately  if  you  use 
it  to  try  to  plot  a  circle,  you  get  an 
octagon  instead  of  a  circle.  The  two 
plots  of  lunar  craters  below  illus¬ 
trate  the  effects  of  using  the 
handy  approximation  (fig.  1)  and 
the  approximation  ‘dx  +dy— dx*dy/ 
(dx+dy+1)’  (fig.  2).  Figure  2  can  be 
derived  by  applying  one  iteration  of 
Newton’s  method  to  the  first  ap¬ 
proximation  dx+dy.  The  ‘+1’  in  the 
denominator  is  to  prevent  divi¬ 
sion  by  zero  when  both  dx  and  dy 
are  zero.  This  approximation  costs 
four  adds,  one  multiply,  and  one 
divide  which  is  usually  faster  than 
the  one  add,  two  multiplies,  and 
one  square  root  of  the  exact  meth¬ 
od.  And  if  you  are  willing  to  pay 
for  one  more  floating  multiply  ‘dx 
+  dy  -  1.17*dx*dy/(dx+dy+l)’ 
looks  even  better. 

Other  readers  improved  on  the  ap¬ 
proximation,  too.  For  simplicity,  assume 
that  dh>dv;  then  we  can  dispense  with 
max  and  min.  The  original  is  then 

(1)  happrox  =  dh  +  dv  *  .5 

Ed  Wilson  of  Greenbelt,  MD  derived  a 
much  more  accurate  formula: 


40 

312 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


r  =  dx+dy— dx*dy/(dx+dy+l ) 

Figure  2 


happrox  =  dh  +  (dv  *  dv)/(2  *  dh) 

and  justified  it  three  ways,  from  a  Taylor 
expansion,  a  geometric  argument,  and 
from  Newton’s  method.  In  a  postscript 
he  noted  that  using  .4142135  in  place  of 
.5  in  (1)  would  improve  it. 

Edmund  Butler  of  E.  Riverdale,  MD 
took  a  different  route  to  a  similar  num¬ 
ber.  He  generalized  ( 1 )  to  the  form 

happrox  =  dh  *  A  +  dv  *  B 

and,  converting  the  problem  to  polar  co¬ 
ordinates,  analyzed  it  to  find  the  A  and 
B  that  would  minimize  the  relative  error. 
The  worst  error  occurs  when  the  included 
angle  is  0  or  pi/4  (a  fact  also  noted  by 
M.  David  Leonard  of  Leverett,  MA).  But¬ 
ler’s  argument  led  him  to  best  values  of 
A=.9541  and  B=.4127. 

Gerald  Edgar  of  Columbus  OH  pro¬ 
posed  A=.960  and  B=.398.  In  an  informal 
bake-off,  Wilson’s  formula  showed  the 
smallest  error  by  far,  while  Butler’s 
choices  for  A  and  B  edged  out  Edgar’s  by 
a  nose.  The  best  balance  of  speed  and  ac¬ 
curacy  is  probably  Butler’s,  while  Wil¬ 
son’s  expression  would  be  preferable 
when  accuracy  is  important. 


2000  AD  is,  so,  a  Leap  Year 

All  centuries  divisible  by  400  are  leap 


years,  as  any  fool  knows.  Except  the  fool 
preparing  this  column,  and  then  only 
sometimes.  The  Intern’s  foolishness  was 
revealed  even  more  embarrasingly  on  the 
first  of  March  this  year.  On  that  date, 
users  of  a  certain  popular  APL  interpreter 
signed  on  to  their  systems  and  were  told 
that  the  date  was  3/0/81.  That  unique 
date  came  from  a  piece  of  code  that  the 
Intern  wrote  some  five  years  ago,  a  rou¬ 
tine  not  greatly  different  from  the  MP/M 
date  routine  presented  in  this  column. 
Let  this  be  a  warning  to  all  —  calendar 
routines  don’t  get  any  safer  with  age. 
Who’d  look  for  a  bug  to  turn  up  in  the 
month  after  February  in  the  year  after 
a  leap  year? 

L.  Barker  of  Chicago,  and  C.  T.  Mc¬ 
Daniel  of  Los  Gatos,  CA  both  have  the 
calendar  under  firm  control.  Both  sent 
programs  in  BASIC  that  can  handle  any 
reasonable  date  with  aplomb.  McDaniel 
sent  subroutines  in  North  Star  BASIC  for 
converting  Julian  dates  to  Gregorian,  and 
vice  versa  (Listing  1,  page  42).  Barker 
sent  a  delightful  program  that  prints  a 
month  calendar  for  any  chosen  month 
of  any  year  from  1900  to  2099  (Listing 
2,  page  42). 

The  Clinic  Needs  Sponses 

The  heavy  mail  after  the  first  clinic 
was  very  gratifying  to  everyone  on  the 


DDJ  staff,  as  we  said  above.  Unfortu¬ 
nately,  almost  all  the  letters  that  came  in 
were  responses  to  the  questions  posed. 
Those  are  certainly  good  —  what  would 
be  the  point  of  posing  questions  if  read¬ 
ers  didn’t  answer  them?  -  but  if  the  Clin¬ 
ic  is  to  be  healthy  it  must  have  more 
than  just  responses. 

What’s  needed  are  the  problems  and 
discoveries  that  any  serious  computist 
makes  weekly.  Anytime  a  computing 
problem  makes  you  think  hard  for  an 
hour  or  more,  that  problem  is  material 
for  the  Clinic.  Jot  it  down  and  send  it 
along,  even  if  you  don’t  have  the  perfect 
solution,  even  if  you  don’t  have  a  solu¬ 
tion  at  all.  As  should  be  clear  from  the 
material  above,  the  DDJ  readership  is 
capable  of  finding  not  one  but  several 
solutions  to  any  problem.  The  letters 
that  will  give  this  column  real  body  are 
the  ones  that  open  with  phrases  like: 

“It  isn’t  commonly  known  that  you 
can .  . .” 

“I  am  absolutely  stumped.  I  want 
to  . . .” 

“The  documentation  for  X  doesn’t 
say  so,  but . . .” 

“I  just  found  a  way  to  .  . .” 

Keep  the  sponses  and  responses 
coming.  ■  ■ 

LISTING  ON  PAGE  42 


Dr.  Dobb’s  Journal,  Number  57,  July  198  1 


41 

313 


LISTING  I  by  C.  T.  McDaniel  ( Text  on  page  41.) 

10000  REM  THIS  SUBROUTINE  COMPUTES  THE  GREGORIAN 
10050  REM  CALENDAR  DATE  CORRESPONDING  TO 
10100  REM  A  GIVEN  JULIAN  CALENDAR  DATE  'D' 

10200  REM 

10300  REM  FOR  EXAMPLE,  IF  THE  JULIAN  DATE  D  =  2440588, 

10400  REM  THE  YEAR  (I)  =  1970 

10500  REM  THE  MONTH  (J)  =  JANUARY  =  1 

10600  REM  THE  DAY  (K)  =  FIRST  OF  THE  MONTH  (1) 

10700  REM 
10800  REM 

10900  REM  BEGIN  COMPUTATION 
11000  REM 

11100  Cl=146097  \  C2-2447 
11200  L=D+68569 
11300  N=INT(4*L/C1) 

11400  L=L-INT( (Cl*N+3)/4) 

11500  I=INT(4000*  (L+D/1461001) 

11600  L=L-INT(1461*I/4)+3i 
11700  J=INT(80*L/C2) 

11800  K=L-INT(C2*J/80) 

11900  L=INT(J/11) 

12000  J=J+2-12*L 
12100  1=100* (N-49)  +I+L 
12200  L=D-7*INT(D/7) +1 
12300  RETURN 
20000  REM 

20100  REM  THIS  FUNCTION  DETERMINES  THE  DAY  NUMBER  D 
20150  REM  ON  THE  JULIAN  CALENDAR,  USING 
20200  REM  THE  FOLLOWING  GREGORIAN  INFORMATION 
20300  REM 

20400  REM  I  =  YEAR 
20500  REM  J  =  MONTH 
20600  REM  K  =  DAY  OF  MONTH 
20700  REM 

20800  REM  WHERE  I,J,K  ARE  GREGORIAN  DATES  AS  INTEGERS. 
20900  REM 

21000  REM  FOR  EXAMPLE,  IF 

21100  REM  I  =  1970,  J  =  1  (JANUARY)  AND  K  =  1  (FIRST) 
21200  REM  THEN  D  =  2440588 
21300  REM 

21400  REM  THE  INTERVAL  BETWEEN  TWO  GREGORIAN  DATES 
21500  REM  CAN  THUS  BE  COMPUTED  BY  SUBTRACTING 
21550  REM  THE  JULIAN  DATES  FOR  EACH. 

21600  REM  (NOTE:  NORTH  STAR  BASIC  MULTI-LINE  FUNCTION) 
21700  DEF  FNA  (I,J,K) 

21800  L=-INT ( (14-J) / 1 2 ) 

21900  D=K-32075+INT ( 146 1*INT (I+4800+L) /4) + 

INT ( 367*INT ( J-2-INT ( 12*L) )/12) 
22000  D=D-INT(3*INT(INT( ( I+4900+L) /100) /4) ) 

22100  RETURN  D 
22200  FNEND 


LISTING  II  by  L.  Barker  (Text  on  page  41.) 

10  REM  ZELLER'S  CONGRUENCE 
20  DEFINT  A-Y 
30  DEFSTR  Z 
40  INPUT’Month" ;M 
50  INPUT" Year" ; Y 

60  IF  Y  1900  OR  Y  2099  GOTO  40 

70  IF  M  1  OR  M  12  GOTO  40 

80  MONTH  =  M  :  YEAR  =  Y  :  GOSUB  280 

90  DAY  =  D  :  YEAR  =  Y  :  MONTH  =  M  +1 

100  IF  MONTH  13  GOTO  120  ELSE  MONTH  =  1 

110  YEAR  =  YEAR  +  1 

120  GOSUB  280 

130  D  =  28  +  D  -  DAY 

140  IF  D  28  THEN  D  =  D  +  7 

150  FOR  I  =  1  TO  M 

160  READ  ZMONTH 

170  NEXT 

180  LPRINT  "  ZMONTH;  TAB(25); 

190  LPRINT  USING  "#♦♦♦" ;Y 

200  LPRINT  "  Sun  Mon  Tue  Wed  Thu  Fri  Sat" 

210  LPRINT  TAB (DAY  *4+1); 

220  FOR  I  =  1  TO  D 


230  LPRINT  USING  ’  ##";I; 

240  IF  (I  +  DAY)  MOD  7=0  AND  I  D  THEN  LPRINT 
250  NEXT 
260  LPRINT 
270  END 

280  REM  Compute  the  day  of  the  week 
290  MONTH  =  MONTH  -  2 

300  IF  MONTH  0  GOTO  320  ELSE  MONTH  =  MONTH  +12 
310  YEAR  =  YEAR  -1 
320  CENTURY  =  YEAR\100 
330  YEAR  =  YEAR  MOD  100 

340  D= ( (13 ‘MONTH  -1)\5  +  5*YEAR\4  +  CENTURY\4  - 

2 ‘CENTURY  +1)  MOD  7 

350  RETURN 

360  DATA  January, February, March, April, May, June 
370  DATA  July, August, September , October 
380  DATA  November , December 


“This  will  never  do!  I  can  understand  every  single  word!” 


42 

314 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


Book  Reviews 


Programming  the  Z8000 
By  Richard  Mateosian 
Published  by  Sybex 
$15.95,297  pages 
Reviewed  by  Terry  R.  Dettmann 

Sybex  Books  has  gained  a  reputation 
for  putting  out  good  books  on  a  variety 
of  microcomputer-related  subjects.  This 
new  book  on  the  Z8000  processor  is  an¬ 
other  fine  addition  to  that  line. 

Mateosian  covers  all  the  essential  de¬ 
tails  of  the  Z8000  processor  for  people 
who  want  to  know  what  it  is  and  how  to 
use  it.  He  starts  out  with  a  chapter  on  ba¬ 
sic  concepts  dealing  with  programming, 
algorithms,  flowcharts,  and  representa¬ 
tions  of  information.  This  chapter  pro¬ 
ceeds  rapidly  from  bits  to  stacks  and 
makes  a  good  review  for  the  reader. 

Chapters  2,  4,  5,  and  7  provide  de¬ 
scriptive  information  about  the  processor 
itself  that  would  be  useful  to  a  design 
engineer  who  has  no  real  interest  in  pro¬ 
gramming.  Chapter  2  covers  the  architec¬ 
ture  of  the  Z8000.  If  you  haven’t  any 
prior  familiarity  with  microprocessors  at 
the  hardware  level,  this  chapter  can  be  a 
little  rough  going,  but  anyone  considering 
using  the  Z8000  should  at  least  scan  the 
chapter. 

Chapter  4  covers  the  Z8000  instruc¬ 
tion  set  in  detail.  The  first  part  of  the 
chapter  deals  with  topics  such  as  “Data 
Operations  and  Testing,”  “Data  Trans¬ 
fers,”  “Pointer  Setting,”  “Transfer  of 
Control,”  “Input/Output,”  “CPU  Con¬ 
trol,”  “Block  Operations,”  “Multi-Micro 
Synchronization,”  “Condition  Codes,” 
and  “Instruction  Formats.”  Part  2  of  this 
chapter  is  a  reference  manual  of  the  in¬ 
structions  themselves. 

Chapter  5  covers  Z8000  addressing 
modes  (8  pages)  and  Chapter  7  covers 
Z8000  peripheral  components  such  as  the 
memory  management  unit,  the  serial 
communication  controller  and  so  forth. 

The  other  chapters  of  this  book  are 
aimed  more  at  the  programmer.  Chapter 
3  covers  elementary  programming  tech¬ 
niques  by  developing  an  algorithm  to 
encrypt  text  and  programming  it  on  the 
Z8000. 

Chapter  6  covers  input/output  tech¬ 
niques.  Chapter  8  covers  a  variety  of  utili¬ 
ty  programming  examples  useful  for  the 
non-segmented  version  of  the  processor. 
Specifically,  routines  are  developed  and 
presented  for  an  I/O  initiator,  ring  buffer 
routines,  line  handling  routines,  transla¬ 
tion  routines,  a  terminal  interaction  pack¬ 
age,  input  decoding,  output  formatting, 


cursor  control,  and  bit  tables. 

Chapter  9  deals  with  a  variety  of  ad¬ 
vanced  programming  techniques  such  as 
storage  management,  timesharing,  and 
stack  management.  Finally  Chapter  10 
covers  the  use  of  various  program  de¬ 
velopment  tools  such  as  assemblers  and 
text  editors.  The  discussion  is  general  and 
not  specifically  related  to  one  or  another 
system. 

Five  appendices  are  provided:  A,  An¬ 
swers  to  selected  exercises;  B,  ASCII 
Character  Set;  C,  Encodings  for  instruc¬ 
tion  fields;  D,  Control  Register  Formats; 
and  E,  Layout  of  the  Program  Status 
Area. 

Spot  checking  the  book  against  Zi- 
log’s  Z8000  Product  Specification  and 
the  Z8000  Family  brochure  turned  up  no 
errors.  Overall  I  found  the  book  easy  to 
read  and  well  worth  the  effort  to  do  so. 

BASIC  Scientific  Subroutines  Vol.  I 
by  F.  R.  Ruckdeschel 
Published  by  McGraw-Hill 
$19.95,  317  pages 
Reviewed  by  Terry  R.  Dettmann 

Are  you  using  BASIC  in  your  scien¬ 
tific  work?  Have  you  ever  wanted  a  quick 
routine  to  do  a  little  task  such  as  plotting, 
complex  variables,  vector  or  matrix  oper¬ 
ations,  random  number  generation,  or  ser¬ 
ies  approximation?  Well,  this  could  be 
your  source. 

Ruckdeschel  has  compiled  a  series  of 
useful  routines  in  these  areas  for  people 
who  are  using  BASIC  for  their  scientific 
work.  This  book  is  the  first  of  a  promised 
series  of  books  that  will  compile  routines 
in  statistics,  mathematics,  engineering  and 
the  sciences  for  use  by  everyone  who  is 
applying  BASIC  to  computations  in  these 
fields. 

The  dialect  for  the  programs  is  close 
to  North  Star  BASIC  while  observing 
some  limits  over  what  is  possible  with  the 
language  to  make  these Toutlnes  compati¬ 
ble  with  more  BASIC’s.  In  addition,  a 
special  appendix  is  provided  that  covers 
translation  of  the  routines  to  other 
BASIC’s  as  well  as  a  complete  listing  of 
the  routines  in  Microsoft  BASIC. 

This  book  is  more  than  just  a  collec¬ 
tion  of  programs,  however.  It  covers  the 
routines,  how  to  use  them,  and  the  theo¬ 
ry  behind  them  in  a  clear  and  concise 
manner.  Admittedly,  someone  who  hasn’t 
had  any  exposure  to  some  of  the  tech¬ 
niques  might  be  taken  aback  by  the  dis¬ 
cussions. 

For  example,  in  talking  about  least 


squares  regressing,  Ruckdeschel  speaks 
about  obtaining  near  mini-max  approxi¬ 
mations  with  Chebyshev  polynomial  ex¬ 
pansions.  The  discussion  is  elementary 
to  someone  with  experience,  but  less 
clear  to  those  without.  Given  supplemen¬ 
tary  material  expanding  the  theoretical 
treatments,  even  novice  users  could 
understand  the  techniques. 

Even  without  understanding  them,  a 
novice  user  can  take  the  routines  and 
plug  them  into  his  programs  where 
needed  by  following  the  simple  instruc¬ 
tions  on  the  use  of  the  routines. 

The  text  identifies  the  variables  used 
by  the  subroutines  as  well  as  those  to  be 
passed  with  parameters.  All  of  the  sub¬ 
routines  are  given  unique  line  numbers  so 
that  a  complete  library  could  be  assem¬ 
bled  and  loaded  as  needed.  Users  with  the 
necessary  technical  knowledge  could 
write  their  own  loader  to  resolve  subrou¬ 
tine  calls  to  this  library  and  load  only 
those  routines  needed  for  a  program  they 
are  working  on. 

Since  receiving  the  book,  I’ve  tried  a 
number  of  the  routines  under  Microsoft 
BASIC  and  found  them  reliable  when 
used  according  to  the  instructions.  I  have 
trouble  in  general  using  libraries  such  as 
this  since  it  is  simply  more  fun  to  develop 
my  own  routines,  but  I’ve  found  myself 
going  to  this  book  despite  that  for  rou¬ 
tines  I’ve  needed  because  they  are  so  sim¬ 
ple  to  use  when  I  want  something  fast. 

I’m  looking  forward  to  seeing  Vol¬ 
ume  2  in  the  series. 

The  PLL  Synthesizer  Cookbook 
By  Harold  Kinley 

Published  by  TAB 

$7.95,279  pages 

Reviewed  by  Terry  R.  Dettmann 

Many  Microcomputer  hobbyists  are 
also  electronics  hobbyists.  In  fact,  that’s 
how  many  people  got  into  microcompu¬ 
ters  in  the  first  place.  This  book  is  for  the 
electronics  hobbyists  among  you. 

Anything  but  elementary,  this  book 
picks  up  with  an  explanation  of  how  PLL 
synthesizers  work  and  then  devotes  a 
chapter  each  to  10  popular  synthesizers. 
The  work  is  heavily  oriented  to  their  use 
in  CB  radios  and  uses  an  example  from 
CB  for  each  of  the  ten  synthesizers. 

There  is  enough  detail  here  to  satisfy 
the  potential  experimenter  on  how  to  de¬ 
velop  program  control  of  a  synthesizer, 
how  to  generate  desired  frequencies  from 
a  master  oscillator,  and  so  forth.  At  no 
point  in  the  book  does  the  explanation 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 


43 

315 


ever  get  low  enough  for  the  introduc¬ 
tory  student,  however. 

This  book  thoroughly  covers  the  top¬ 
ic  of  PLL  synthesizers.  It  provides  the 
kind  of  information  on  connections,  use 
and  troubleshooting  that  will  please  both 
professionals  and  hobbyists.  If  electronics 
is  your  business  or  your  hobby,  and  gene¬ 
ration  of  accurate  frequencies  is  necessary 
to  you,  then  I  recommend  this  book  as  a 
good  reference  for  your  shelf. 

Conversational  Languages 
By  I.  Kupka  and  N.  Wilsing 
Published  by  John  Wiley  &  Sons 
$27.75,  117  pages 
Reviewed  by  Doug  MacDonald 

Computers  are  not  friendly  creatures. 
Despite  the  incredible  technological  ad¬ 
vances  since  the  first  vacuum  tube  mon¬ 
sters,  the  man-machine  dialogue  is  still 
strained  at  best.  Computers  are  unfor¬ 
giving,  maddeningly  logical,  heartless 
creatures  with  whom  you  can’t  imagine 
(outside  of  Star  Wars )  having  a  friendly 
conversation.  (Of  course,  to  the  basement 
hacker  whose  first  programming  was  of 
the  “finger-blistering”  variety  on  a  front 
panel  of  binary  switches,  anything  is 
friendly!) 

Nevertheless,  a  number  of  attempts 
have  been  made  to  produce  conversa¬ 
tional  languages  -  languages  and  operat¬ 
ing  systems  that  provide  a  high  degree  of 
interaction  between  machine  and  user. 
The  fact  that  these  languages  are  not 
widely  known  or  used  is  only  an  indica¬ 
tion  of  how  difficult  the  problem  is. 

Two  German  authors,  Kupka  and 
Wilsing,  present  a  somewhat  thick  and 
scholastic  outline  of  some  of  these  con¬ 
versational  languages  and  the  problems  in 
developing  and  using  them.  The  book  is 
based  on  a  series  of  lectures  given  at  the 
University  of  Hamburg. 

The  authors  begin  by  making  the  dis¬ 
tinction  between  a  programming  language 
and  a  command  language.  The  various  so- 
called  high-level  languages  such  as  FOR¬ 
TRAN,  ALGOL  and  PL/1  are  notorious¬ 
ly  unfriendly,  demanding  of  syntax  and 
often  awkward.  But  even  when  the  neces¬ 
sary  program  has  been  designed  and  writ¬ 
ten,  there  is  still  the  business  of  getting 
it  into  the  computer,  compiling  or  inter¬ 
preting  it  into  machine  code  and  perform¬ 
ing  the  run. 

It  is  here  -  the  time  spent  while  the 
programmer  is  actually  squared  away  at 
the  CRT  keyboard  -  that  most  of  the  ef¬ 
fort  has  been  made  to  unfreeze  the  heart¬ 


less  computer. 

In  the  program-entry  stage,  various 
attempts  have  been  made  to  assist  the 
programmer  with  his  development.  The 
authors  use  ALGOL,  the  granddaddy  of 
Pascal,  as  an  example.  With  the  compu¬ 
ter’s  responses  italicized,  the  dialogue 
might  look  like: 
begin[ 

illegal  position  off’ 
ifa 

illegal  position  of  'a  ’ 
suggestion:  ’if’ OK? 
begin  real  array 

Efficient  perhaps,  but  definitely  not 
friendly  —  more  like  a  stern  old  school 
marm  ready  to  pounce  on  a  trembling 
child. 

One  step  up  would  be  a  computer- 
aided  program  development  system.  Sup¬ 
pose  the  user  has  a  light  pen  in  addition 
to  the  CRT  keyboard.  On  bringing  up  the 
editor,  he/ she  sees: 
program 

He  types  ‘fourier’,  giving  the  program  a 
name 

Then  appears: 

‘begin’  <declarations>  <statements> 
‘end’ 

The  user  points  with  the  light  pen  to  ‘dec¬ 
larations’.  The  machine  responds: 
<constant>  <variable>  <type> 

The  user  selects  Variable  and  the  machine 
awaits  a  variable  identifier.  The  dialogue 
might  continue: 

array  [charlie]  of  <simple  type>  <  set 
of>  <record>  <file  of> 

Here  we  have  an  “intelligent”  editor 
for  Pascal  which  checks  the  programmer’s 
syntax  and  helps  him  by  filling  in  expec¬ 
ted  words.  This  is  a  little  friendlier. 

The  authors  devote  only  a  few  para¬ 
graphs  to  examining  the  real  problems 
involved  in  getting  logical  machines  to 
understand  illogical  people.  If  the  compu¬ 
ter  responds  too  quickly,  the  user  is 
“stressed”;  if  it  responds  too  slowly,  the 
user  is  bored.  Can  a  machine  be  made  to 
understand  “The  man,  who  struck  the 
dog,  which  bit  the  cat,  with  the  stick, 
fell  down”? 

The  main  portion  of  the  book  is  ta¬ 
ken  up  in  describing  a  number  of  “desk 
calculator”  type  languages  which  are 
used  interactively,  most  of  them  obscure 
-  JOSS,  LCC,  PPL,  CPS  and  so  on.  There 
are  outlines  of  AMTRAN,  DIALOG  and 
VENUS.  Most  of  these  offbeat  languages 
were  developed  for  very  specific  tasks 
such  as  experimental  numerical  mathe¬ 
matics  or  simulation. 


There  are  short  outlines  of  BASIC 
and  APL,  the  two  most  widely-known  in¬ 
teractive  languages. 

The  final  chapters  are  comprehensi¬ 
ble  only  to  those  who  have  studied  the 
theory  of  formal  languages.  To  the  un¬ 
initiated,  it’s  all  page  after  page  of  chick¬ 
en  scratches  of  meta-language  sets,  lat¬ 
tices  of  equivalent  dialogue  systems  and 
other  arcane  symbols. 

Most  copies  of  this  book  will  likely 
end  up  on  the  shelves  of  those  dusty, 
cramped  little  offices  of  graduate  stu¬ 
dents  in  computing  science.  The  book  is 
definitely  not  for  the  novice.  However, 
if  you’re  a  serious  student  of  program¬ 
ming  language  design,  by  all  means  give 
it  a  read. 


If  you  want  to  present  your 
ground-breaking  work  to  some 
of  the  most  innovative  and 
influential  people  in  the  micro¬ 
computing  industry,  DDJ  can 
help.  Contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)  323-3111 


Dr.  Dobb’s  Journal,  Number  57,  July  1981 
316 


45 


OBB’S 


For  Users  of  Small  Computer  Systems 


Write  Your  Own  Compiler 
With  Meta4 

William  A.  Gale 

Some  Useful  C  Time  F  unctions 

Bill  Bolton 

The  Doctor’s  Clinic 

D.  E.  Cortesi 


A  Tool  for 

Writing 

Compilers 

About  C 


Card  Playing 
Permutations 


...  and  much  more! 


DrD 


OBB'S  loURNAL 


For  Users  of  Small  Computer  Systems 


August  1981  Volume  6,  Issue  8,  Number  58 


Contents 


Letters .  4 

Write  Your  Own  Compiler  With  Meta4 .  6 

Listing . 22 

by  William  A.  Gale 

Some  Useful  C  Time  Functions . 16 

Listing .  18 

by  Bill  Bolton 

Dr.  Dobb’s  Clinic . 40 

Of  Interest . 43 


©  1981  by  People’s  Computer  Company  unless  otherwise  noted  on 
specific  articles.  All  rights  reserved. 


Publisher 

Michael  Madaj 
Editor 

Marlin  Ouverson 
Assistant  Editor 
Julie  Anton 
Contributing  Editors 
Dave  Caulkins 
Dave  Cortesi 


Art  Director 

Clifford  West 
Artist 

Barbara  Ruzgerian 
Typesetter 
Renny  Wiggins 
Proofreader 
Nancy  Heubach 


Marketing  Director 
Craig  S.  Harper 
Advertising  Sales 
Kent  SafTord 
Circulation  Manager 
Peter  Clark 
Circulation  Assistant 
Leah  Dansby 
Business  Manager 
Maureen  Christine 


Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per 
year  by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real, 
Menlo  Park,  CA  94025.  Second  class  postage  paid  at  Menlo  Park, 
California  9402  5  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  94025. 


Editorial 


Planning  each  issue  of  DDJ  is  like  playing  a  game  of 
editorial  bingo.  We  sit  down  at  a  long  table  with  our  game 
card  and  pieces  of  corn  to  lay  on  the  squares.  Across  the 
top  of  the  card  are  the  column  labels  -  8080,  6502, 1802, 
6800,  etc.  The  horizontal  rows  are  categorized  into  algo¬ 
rithm,  languages,  hardware,  programming  problems,  and 
more.  Now  and  then  our  pieces  form  a  straight  line  and  we 
all  yell,  “Bingo!” 

That  kind  of  thing  happened  with  last  year’s  all-CP/M 
issue,  and  with  DDJ  #56,  which  featured  Jonathan  Mills’ 
cross-assembler  for  the  8080/Z80.  We  now  have  plans  to 
publish  the  complete  listing  of  the  cross-assembler  in  forth¬ 
coming  issues.  Also  coming  up  is  an  all-FORTH  issue,  for 
which  articles  and  too-rare  utilities  have  been  trickling  in. 

It  is  often  true  that  along  with  articles  of  major  import 
come  listings  of  considerable  length.  Dr.  Dobb’s  Journal 
traditionally  offers  useful  listings  in  their  entirety,  rather 
than  just  short  excerpts  as  illustrations  for  an  article.  Some¬ 
times  that  means  we  do  not  have  enough  space  to  present 
the  usual  variety  of  articles,  because  the  listings  in  a  particu¬ 
lar  issue  are  so  voluminous.  But  we  are  banking  on  the  fact 
that  the  usefulness  of  the  listings  will  more  than  compen¬ 
sate  for  those  occasional  times  when  the  number  of  articles 
is  fewer  than  normal. 


As  always  with  DDJ,  the  success  of  the  journal  depends 
on  the  responsive  readership.  So  contribute  an  article,  an 
idea  or  a  subscription!  Do  you  think  we  are  missing  the 
boat?  Is  there  a  subject  to  which  you  would  like  an  entire 
issue  devoted?  Have  you  a  piece  of  useful  software  you’d 
like  to  make  available  to  your  fellow  readers?  If  you  just 
have  an  opinion,  a  well -written  letter  to  the  editor  is  always 
welcome. 

There  are  other  ways  to  support  your  magazine,  of 
course.  Mention  us  to  your  local  bookstore,  give  a  gift  sub¬ 
scription  to  a  friend,  or  get  a  lifetime  subscription  for  your¬ 
self.  Why  not?  Ours  is  the  only  respected  computer  journal 
which  has  maintained  its  friendly  voice  over  the  years.  Our 
readers  are  more  important  to  us  than  any  other  resource, 
and  we  always  enjoy  hearing  from  you. 


Marlin  Ouverson 
Editor 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 
318 


3 


Letters 


When  Push  Comes  to  Shove  . . . 

Dear  Mr.  Ouverson: 

I  was  alarmed  by  Jonathan  Mills’  im¬ 
plication  that  Cross-Assembler  for  8080 
or  Z80  might  not  be  continued. 

The  contents  of  the  article  and  list¬ 
ings  not  only  provide  an  entree  to  8086 
projects  but  also  give  a  clear  example  of 
compiler  techniques.  Regardless  of  im¬ 
mediate  reader  response,  I  urge  you  to 
continue  this  series.  This  is  likely  to  be¬ 
come  one  of  the  most  widely  used  and 
referenced  articles  in  microcomputer 
literature. 

I  hope  that  Mr.  Mills  will  include  a 
(MAKETABLE)  listing  in  a  future  article 
and  identify  the  assembler  he  used. 

Sincerely, 

Don  Vickers 

P.  O.  Box  5 1 ,  Parnassus  Sta. 

New  Kensington,  PA  15068 

Dear  Marlin: 

It  has  been  several  months  of  wading 
through  issues  of  Byte,  Interface,  Kilo¬ 
baud,  Electronics,  Electronic  Design  et 
al.  before  I  accidentally  discovered 
Jonathan  Mills’  “A  Cross-Assembler  for 
the  8080/Z80”  in  your  June  1981  issue. 
This  series  of  upcoming  articles  on  a 
8080/8086  cross-assembler  looks  like  it 
could  be  one  of  the  best  ever  in  your 
magazine. 

Only  recently  I  began  to  question 
whether  I  should  have  renewed  my  sub¬ 
scription.  I’m  glad  I  did  because  other¬ 
wise  I  would  have  missed  this  one.  One 
of  the  most  unfortunate  aspects  about 
the  title  is  that  it  appears  to  be  another 
(ho-hum)  8080/Z80  cross-assembler. 
From  what  I  can  tell  it  looks  like  the  best 
thing  to  hit  the  microcomputer  software 
market  in  a  long  time. 

Bravo,  bravo  on  your  magazine 
which  has  been  able  to  attract  such  a 
talented  professional  as  Mr.  Mills.  I’m 
sure  his  contribution  to  the  world  of  pub¬ 
lic  domain  software  will  not  go  unre¬ 
warded. 

Anxiously  awaiting  my  next  issue  of 
DDJ, 

Yours, 

Tom  Sullivan 

6543  Girvin  Dr. 

Oakland,  CA  94611 

Dear  Mr.  Ouverson: 

It  was  with  great  delight  that  I  read 
the  article  on  the  Cross-Assembler  for  the 
8080  to  8086/8088.  I  do  hope  that  you 


will  publish  the  entire  listing. 

The  Z80/8088  CPU  outlined  in  the 
article  sounds  exciting  and  is  more  in  line 
with  the  requirements  that  I  had  outlined 
for  an  entry  into  the  8088  world  than 
any  of  the  other  CPU’s  offered  to  date. 
This  includes  single  processor  (8088  or 
8086)  or  the  dual  processor  boards.  I  had 
almost  given  up  hope  of  finding  a  board 
that  satisfied  my  needs. 

Sincerely, 

Larry  Hoffman 
10152  Oso  Ave. 

Chatsworth,  CA  91311 

Dr.  Dobb’s  Journal: 

I  have  just  finished  reading  the  first 
installment  of  the  Cross-Assembler  article 
by  Jonathan  Mills.  Apparently,  reader 
response  will  determine  whether  or  not 
you  print  the  remainder. 

This  is  a  response.  Please  print  it. 

Regards, 

R.  A.  Morton 
1 2603  Mistletoe  Trail 
Manchaca,  TX 


Editor's  Note:  We  had  hoped  for  this 
kind  of  response  to  Mr.  Mills’  work.  The 
above  letters  are  only  a  few  of  those  we 
received  asking  for  more  from  the  author. 
So,  stay  tuned  -  the  next  installment  is 
on  its  way  in  an  upcoming  issue.  The  size 
of  the  listing  prevents  us  putting  it  all 
into  one  issue,  but  if  your  letters  keep 
coming  in  like  this,  we’ll  publish  it  all! 


Beat  the  Odds 

Dear  People, 

Please  enter  a  new  subscription  to 
Dr.  Dobb’s  Journal  for  me  at  the  address 
given.  By  my  calculations,  Dr.  Dobb's 
Journal's  last  3  issues  have  contained 
more  useful  information  than  the  last  3 
years  of  Byte  magazine!  Byte  seems  to  be 
Vt.%  useful  information,  4 Vi%  general  news 
and  95%  advertising  —  94%  of  which  is 
useless  to  overseas  readers.  I  feel  guilty 
(and  light  of  pocket)  consuming  so  much 
American  paper  for  so  little  benefit!  I 
fully  endorse  and  heartily  commend 
DDJ’ s  advertisement  policies. 

Best  regards, 

C.  I.  Yandell 
3/8  Spray  St. 

Elwood,  3184  AUSTRALIA 


CP/M’s  ED 

Gents: 

Users  of  the  CP/M  standard  editor, 
“ED”  have  probably  noticed  that  ED 
interprets  an  ASCII  form  feed  <OC> 
as  an  imbedded  carriage  return.  This  is  an 
amazing  irritation  to  those  of  us  with 
normal,  form-feed-recognizing  line  print¬ 
ers. 

ED  may  be  altered  to  treat  form 
feeds  normally  provided  some  other  con¬ 
trol  character  is  substituted  for  control- L 
<OC>.  A  few  tedious  minutes  with  DDT 
revealed  the  following  locations  must  be 
changed  (addresses  in  hexadecimal): 

528  162E  1  Al  1  . 

I  have  named  the  result  “RALPH.” 
RALPH  interprets  a  control-N  <OC> 
as  an  imbedded  carriage  return. 

Sincerely, 

J.  Elliott  Smith 
6  Leslie  Road 
Belmont,  MA  02178 

A  DAL  Blurb 

Dear  Marlin : 

I  would  appreciate  it  if  you  would 
pass  the  following  information  on  to 
DDJ  readers: 

The  source  code  and  machine- 
readable  documentation  for  my  small  lan¬ 
guage  DAL  (Data  Acquisition  Language) 
is  now  available  on  an  8”  CP/M  or  ISIS 
diskette  for  a  $10.00  copying  charge.  It 
was  previously  only  available  on  9 -track 
tape.  Complete  assembly  listings  are  still 
available  for  $10.00,  the  cost  of  printing 
and  mailing.  The  user  manual  was  printed 
in  DDJ  Vol.  4,  No.  10  (Nov/  Dec  1979). 
DAL  is  written  in  6502  assembly  lan¬ 
guage  and  contains  many  interesting  fea¬ 
tures,  including  a  variable  precision  (to  64 
bytes)  arithmetic  package. 

Thank  you. 

Sincerely, 

Gregg  E.  Marshall 
P.  O.  Box  3282 
Walnut  Creek,  CA  94598 

Ergo,  I  Think! 

Dear  DDJ: 

This  letter  is  in  response  to  a  number 
of  letters  from  readers  inquiring  about 
the  particular  BASIC  used  in  the  ERGO 
thinking  program  {DDJ  #53,  Mar.  1981). 

The  program  was  written  in  Tym- 
share  SUPER- BASIC  in  1969.  Some 
readers  may  be  able  to  get  a  copy  of  a 
Tymshare  manual  for  SUPER-BASIC. 


4 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 

319 


There  are  also  similar  versions  of  SUPER- 
BASIC  offered  by  NCSS  and  UCS  on 
their  systems. 

ERGO  did  not  use  many  of  the  spe¬ 
cial  features  of  SUPER- BASIC.  I  will  try 
to  describe  those  few  that  it  does  use. 

All  the  variables  used  in  the  program 
are  declared  at  the  beginning.  This  is  not 
required,  but  it  is  helpful.  The  LOGICAL 
declaration  is  for  Boolean  variables, 
which  can  only  have  values  of  0  (false)  or 
1  (true).  These  can  be  used  in  conditions 
and  in  any  arithmetic  expressions. 

An  unusual  feature  is  the  “modifier” 
form  of  statement,  in  which  any  state¬ 
ment  (or  group  of  assignment  state¬ 
ments),  can  be  followed  by  IF,  UNLESS, 
FOR,  WHILE,  or  UNTIL.  IF  at  the  end 
of  a  statement  means  the  same  as  at  the 
beginning,  but  doesn’t  need  the  THEN 
keyword.  UNLESS  is  the  opposite  of  IF. 
FOR  does  a  normal  FOR  loop  without 
needing  a  NEXT  (same  as  the  FORTRAN 
implied  DO-loop).  WHILE  and  UNTIL 
are  loop  control  modifiers;  the  loop  re¬ 


peats  until  the  condition  is  false  (WHILE), 
or  true  (UNTIL). 

Assignment  statements,  separated  by 
commas,  can  be  executed  as  a  one-line 
compound  block. 

The  functions  are  all  pretty  standard. 
INDEX  is  a  string  function  that  returns 
the  position  of  the  second  string  argu¬ 
ment  within  the  first  string  argument. 
Later  versions  of  SUPER- BASIC  provid¬ 
ed  a  3 -argument  INDEX,  so  it  can  be 
given  a  starting  position  for  the  scan. 

The  data  file  used  by  ERGO  is  a  se¬ 
quential  file  with  very  simple  structure. 
The  “IS”  and  the  “HAS”  relations  are 
described  by  string  arrays,  with  two 
nouns  for  each  entry.  The  array  dimen¬ 
sions  of  each  category  are  at  the  begin¬ 
ning  of  the  file,  and  the  arrays  for  the  re¬ 
lations  are  then  dimensioned  5  times  big¬ 
ger  to  make  room  for  more  relations  de¬ 
duced  by  the  program,  or  told  to  it  by 
the  person  running  it. 

Scanning  these  relation  arrays  in 
memory  is  done  sequentially.  This  is  in¬ 


efficient,  and  an  indexing  or  hash-code 
arrangement  would  be  better  if  much 
larger  amounts  of  data  were  to  be  han¬ 
dled. 

Some  readers  objected  to  the  lack  of 
detailed  documentation  in  ERGO.  The 
purpose  of  the  listing  was  not  to  provide 
a  detailed  design  to  be  copied,  but  to  en¬ 
courage  readers  to  devise  their  own  ap¬ 
proaches.  The  real  value  of  this  program 
was  to  demonstrate  that  it  doesn’t  take 
a  lot  of  code  to  do  simple  thinking. 
Sincerely, 

Sylvan  Rubin 
Algorithmic  Engineering 
P.  O.  Box  3074 
Santa  Clara,  C A  95055 

Editor’s  Note:  Any  readers  who  have  arti¬ 
ficially  intelligent  programs  which  occupy 
a  reasonably  conservative  amount  of 
memory  (i.e.,  accessible  to  most  of  us 
homebodies)  are  hereby  officially  invited 
to  contribute  their  listings  and  articles  to 
DDJ  for  publication. 


If  you  think  you  have  an  idea  of  interest  to 
DDJ  readers,  we  would  like  to  discuss  it  with 
you.  Contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 
320 


5 


Write  Your  Own  Compiler 


Users  of  small  computer  systems  have  many  projects  for 
which  standard  computer  languages  are  not  well  adapted. 
Yet  writing  a  compiler  for  a  new  language  has  usually 
been  a  time-consuming  task,  even  using  a  large  computer.  This 
paper  describes  a  tool,  Meta4,  for  writing  compilers  for  small 
computers.  It  consists  of  a  specialized  interpreter  and  a  special¬ 
ized  language  for  writing  compilers.  A  language  is  completely 
specified,  both  syntactically  and  semantically,  by  a  program  in 
the  Meta4  language. 

Meta4  is  an  outgrowth  of  Meta  II,  first  described  in 
Schorre  (Proceedings  of  19th  National  Conference  of  the 
ACM,  1964),  reprinted  in  this  magazine  in  April  1980.  As  I 
looked  for  a  name,  I  found  articles  describing  a  Meta  3 
(Schneider  and  Johnson,  Proceedings  of  19th  National  Confer¬ 
ence  of  the  ACM,  1964),  and  a  Meta  5  (Oppenheim  and 
Haggerty,  Proceedings  of  the  21st  National  Conference  of 
ACM,  pp.  465-468).  Probably  there  was  a  Meta4  also,  but  I 
didn’t  find  a  description,  and  it’s  hard  to  pass  up  such  a  good 
word  play. 

The  reason  that  a  1964  compiler  writing  tool  is  interesting 
today  is  that  today’s  microcomputers  are  comparable  in  size 
and  speed  to  many  of  the  larger  1964  computers.  There  has 
been  progress  in  compiler  writing  tools,  of  course,  so  that 
better  tools  now  exist.  But  the  Meta’s  are  both  simple  enough 
for  a  hobbyist  to  understand  and  powerful  enough  to  be  use¬ 
ful.  An  important  point  for  me  was  that  Meta4  was  simple 
enough  to  use  Pidgin  to  implement  (see  DDJ  #57).  If  you 
want  to  pursue  recent  work,  a  good  place  to  start  is  a  four- 
article  review  contained  in  the  August  1980  issue  of  the 
IEEE’s  Computer.  It  thus  becomes  part  of  a  full  boot  strap 
operating  system. 

You  won’t  need  to  know  about  Meta  II  to  understand  this 
article.  But  if  you  decide  to  implement  Meta4,  an  understand¬ 
ing  of  Meta  II  will  be  useful.  Meta4  keeps  the  ways  that  Meta 
II  deals  with  lexical  analysis,  syntax  analysis,  and  output.  It 
provides  better  error  handling,  a  symbolic  memory  for  defin¬ 
ing  variables,  arithmetic  capabilities,  memory  stacks  so  code 
can  be  generated  for  machines  without  stacks,  and  facilities  for 
generating  machine  code  as  extensions  beyond  Meta  II. 

The  interpreter  for  Meta4  is  written  in  Pidgin.  The  reason 
in  a  nutshell  is  portability.  Pidgin,  described  in  last  month’s 
issue,  is  a  tiny  language  fairly  easy  to  compile  to  machine 
code.  In  using  Pidgin,  I  was  most  interested  in  cross- time  port¬ 
ability  for  myself  onto  my  next  machine.  But  I  also  think  that 
it  is  a  fine  means  for  describing  to  8080,  Z80,  or  6800  proces¬ 
sors  the  results  of  my  work  on  a  portable  operating  system. 

An  overview  of  how  Meta4  works  and  what  you  will  need 
to  do  in  order  to  implement  it  will  also  serve  to  name  the 
several  languages  and  programs  involved.  A  compiler  involves 
three  languages:  the  source  language  (what  it  translates  from), 
the  target  language  (what  it  translates  to),  and  the  coding  lan¬ 
guage  (what  it  itself  is  written  in).  To  use  Meta4,  you  need  to 
write  a  compiler  from  the  Userlang  source  language  to  the 


by  William  A.  Gale 


©1981  by  William  A.  Gale.  All  Rights  Reserved. 

The  author,  who  works  in  statistics  and  economics  at  Bell 
Telephone  Laboratories,  can  be  reached  at  439  S.  Orange  Ave., 
South  Orange,  NJ  07079. 


Targetlang  target  language,  in  the  Meta4  coding  language. 
This  program  is  shown  by  a  “T”  in  the  upper  left  of  Figure  1, 
the  diagram  coming  from  a  paper  by  Earley  and  Sturgis,  “A 
Formalism  for  Translator  Interactions,”  CACM,  p.  607,  1970. 
A  translator  is  shown  with  the  source  language  in  the  left  arm, 
the  target  language  in  the  right  arm,  and  the  coding  language  in 
the  base.  An  interpreter  is  shown  with  a  coding  language  on 
the  bottom  of  a  rectangle  and  the  interpreted  language  on  the 
top.  In  the  figures,  programs  provided  here  by  listing  have  an 
asterisk  in  the  center  of  their  figure. 


Use  of  Meta4  and  M4  Interpreter 
Figure  1 


Now  your  compiler  program  is  the  input  to  a  compiler 
with  source  language  Meta4,  a  target  language  called  M4,  and 
which  is  coded  in  M4.  This  compiler  program  is  provided  by  a 
listing  accompaying  this  article,  so  you  have  that  part.  M4  is 
executable  by  an  interpreter,  for  which  the  listing  in  Pidgin  is 
provided.  For  now,  suppose  you  have  the  interpreter  in  ma¬ 
chine  language.  Then  M4  is  executable,  and  you  can  run  the 
compiler  from  Meta4  to  M4.  When  you  input  your  compiler 
from  Userlang  to  Targetlang  written  in  Meta4,  the  output  is  a 
compiler  from  Userlang  to  Targetlang  written  in  M4.  But  M4  is 
executable  so  you  can  now  (as  shown  in  the  lower  right)  input 
your  program,  written  in  Userlang  and  get  as  output  your  pro¬ 
gram,  written  in  Targetlang. 

You  can  see  that  the  M4  interpreter  plays  a  key  role  in 
this  process,  because  it  is  used  once  when  you  translate  your 
compiler  from  Meta4  to  M4,  and  again  when  you  translate 
your  program  from  Userlang  to  Targetlang.  What  you  need  to 
do  to  get  Meta4  working  is  shown  in  Figure  2  —  the  listing  of 
M4  interpreter  in  Pidgin  is  provided.  You  need  a  translator 
from  Pidgin  to  your  machine  code  that  is  executable  on  your 
machine,  and  that’s  what  you  got  in  last  month’s  article. 

Since  the  key  program  in  Meta4  is  an  interpreter,  it  is  best 
termed  a  compiler  generator  interpreter.  That  is,  it  is  an 


6 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 

321 


interpreter  intended  to  both  generate  and  run  compilers. 

To  use  Meta4  you  have  to  understand  the  Meta4  language. 
So  the  next  section  gives  you  a  start  towards  understanding  it 
by  going  over  the  compiler  from  Meta4  to  M4  written  in 
Meta4.  This  is  the  first  listing  following  the  article  (see  page  22). 
It  defines  Meta4  exactly  in  terms  of  M4.  The  following  section 
has  some  thoughts  on  how  to  use  Meta4,  for  it  can  be  used 
many  ways.  To  implement  Meta4,  or  to  understand  complete¬ 
ly  the  definition  of  Meta4,  you  will  need  to  understand  M4, 
which  is  described  in  detail  next.  The  article  concludes  with 
some  help  for  the  implementor. 

Meta4  Language 

The  listing  of  the  compiler  from  Meta4  to  M4  in  Meta4 
shows  exactly  what  syntax  constructions  will  be  recognized, 
and  how  they  will  be  compiled  to  M4.  What  I  say  here  should 
be  taken  as  a  guide  to  that  listing.  It  may  sometimes  be  useful 
to  compare  parts  of  this  listing  with  its  translation  (which  is 
the  listing  of  the  Meta4  to  M4  compiler  in  M4).  The  top  line 
says  to  start  processing  with  the  subroutine  called 
“COMPILE”,  which  is  at  the  bottom  of  the  listing.  COMPILE 
says  to  look  first  for  the  exact  characters  ‘.SYN’,  and  then  for 
an  identifier  (.ID,  a  letter  followed  by  any  number  of  letters 
or  digits),  then  to  generate  a  mark  command  (.OUT  (‘XM;’)), 
a  subroutine  call  to  the  identifier  found  (.OUT  (‘G’*)),  and  a 
stop  command  (.OUT  (‘E’))  so  the  translation  of  this  top  line 
is 

XM; 

GCOMPILE 

E, 

as  can  be  seen  in  the  Meta4  to  M4  in  M4  listing.  The  com¬ 
mands  being  output  are  M4  commands,  explained  in  detail 
later.  The  syntax  description  then  consists  of  zero  or  more 
“DECLARE’s”  (SDECLARE)  followed  by  zero  or  more 
“STATEMENT’S”  (SSTATEMENT).  Let’s  check  out  the 
STATEMENTS,  first,  because  they  came  from  Meta  II,  and  are 
the  core  of  the  parser. 

Finding  the  subroutine  STATEMENT  just  above 
COMPILE,  you  see  that  a  STATEMENT  is 

(1)  An  identifier,  after  which  a  label  (.LAB  *)  with  the  sym¬ 
bolic  name  of  the  identifier  will  be  generated; 

(2)  The  exact  character  = 

(3)  A  PHRASE,  and 


(4)  The  exact  character  after  which  a  return  (‘R’)  will  be 

generated. 

A  PHRASE,  in  turn,  has  one  of  three  alternative  structures, 
which  are  written  separated  by  the  character  It  can  be  the 
exact  characters  ‘.PREP’  followed  by  zero  or  more  NOTSYN’s, 
followed  by  an  ALTS;  or  it  can  be  just  an  ALTS;  or  it  can  be 
one  NOTSYN  followed  by  zero  or  more  NOTSYN’s.  The  first 
alternative  that  is  satisfied  will  be  accepted  and  others  will  not 
be  checked.  This  is  accomplished  by  generating  a  jump  on  true 
before  each  alternative  as  shown  in  ALTS.  An  ALTS  is  a  SEQ 
followed  by  zero  or  more  alternatives,  each  of  which  starts 
with  the  exact  character at  which  point  we  generate  a  jump 
on  true  to  the  label  *1,  followed  by  another  SEQ.  After  all  the 
alternatives  we  define  the  label  *1  to  which  we  generated 
jumps. 

A  SEQ,  now,  consists  of  a  SYN  followed  immediately  by 
zero  or  more  SYbFs  or  NOTSYN’s.  If  the  first  SYN  is  not 
matched,  we  will  just  jump  to  the  end  of  the  SEQ  (.OUT  (‘F/’ 
*1))  but  if  any  following  SYN  returns  without  matching,  we 
have  an  error  (.OUT  (‘X’)).  For  following  NOTSYN’s  we  do 
not  generate  an  error  test. 

A  SYN  is  a  basic  syntactical  item,  for  which  it  can  be 
stated  that  one  does  or  one  does  not  occur  next  in  the  input. 
It  is  (1)  a  new  identifier,  whch  is  compiled  as  a  subroutine  call, 
or  (2)  a  single  quoted  string,  which  is  compiled  as  a  string  to 
match  exactly,  or  (3)  the  keyword  ‘.ID’  which  is  compiled  as  a 
lexical  search  for  an  identifier  or  (4)  the  keyword  ‘.NUM’ 
which  is  compiled  as  a  lexical  search  for  a  number  or  (5)  the 
keyword  ‘.STR’  followed  by  either  a  singly  or  doubly  quoted 
string  which  is  compiled  as  a  lexical  search  for  a  string  quoted 
by  the  first  character  of  the  string  given,  or  (6)  the  keyword 
‘.EMP’  which  compiles  as  a  command  to  set  the  flag,  or  (7)  a 
'$’  followed  by  a  SYN,  which  is  compiled  as  a  request  for  zero 
or  more  of  the  specified  SYN,  or  (8)  the  exact  character  ‘(’ 
followed  by  a  PHRASE  followed  by  the  exact  character  ‘)’. 
Any  of  these  may  be  followed  by  an  optional  error  message. 

These  subroutines  define  the  parsing  that  Meta4  allows, 
and  a  few  comments  on  their  use  may  be  worthwhile  here. 
This  is  called  recursive  descent  parsing,  and  it  requires  being 
able  to  tell  which  construct  is  to  be  chosen  (at  ALTS)  by  look¬ 
ing  just  at  the  next  input  symbol. 

It  works  like  this.  A  SYN  always  returns  true  or  false, 
along  with  its  specification.  If  the  first  SYN  in  a  SEQ  is  false, 
we  jump  over  the  rest  of  the  SEQ,  still  with  false.  If  it  is  true, 
we  go  into  the  SEQ.  If  a  SEQ  returns  false,  the  ALTS  specifies 
trying  the  next  alternative.  If  all  alternatives  return  false,  then 
an  ALTS  returns  false.  But  if  one  returned  true,  then  it  returns 
true. 

The  order  in  which  alternatives  are  listed  is  sometimes  im¬ 
portant.  This  is  not  good,  but  comes  from  choosing  simple  lex¬ 
ical  analysis  options.  Notice  that  .EMP  is  always  satisfied,  so 
it  must  be  last.  Any  alternatives  beyond  it  will  never  be  con¬ 
sidered.  If  one  keyword  is  contained  in  the  left  of  another 
keyword  (suppose  you  wanted  to  use  REAL  and  REALTWO), 
then  the  longer  one  must  be  tested  first.  You  will  notice  that 
all  keywords  in  Meta4  start  with  ‘.’;  this  means  they  cannot  be 
confused  with  identifiers  so  we  don’t  have  to  put  all  keywords 
first.  It  is  a  good  idea  to  put  the  most  common  alternatives 
first,  and  this  gives  the  flexibility  to  do  so. 

A  NOTSYN  is  an  action  not  involving  the  input.  In  Meta 
II  it  consisted  only  of  commands  to  generate  commands 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 
322 


7 


(‘.OUT’)  and  of  commands  to  generate  labels  (‘.LAB’).  A  com¬ 
mand  to  generate  commands  consists  of  the  keyword  ‘.OUT’, 
followed  by  a  *(’  followed  by  zero  or  more  AOUTs  followed 
by  a  *)’.  An  AOUT  is  exactly  the  characters  ‘T  or  ‘*2’  in 
which  case  the  first  or  second  label  numbers  for  the  current 
subroutine  will  be  concatenated  to  the  output  buffer  (and 
generated  if  need  be  —  see  the  discussion  later),  or  the  charac¬ 
ter  **’  in  which  case  the  input  buffer  will  be  concatenated  to 
the  output  buffer,  or  a  singly  quoted  string  which  will  be  con¬ 
catenated  to  the  output  buffer  or  a  RVALUE  which  will  be 
concatenated  to  the  output  as  a  decimal  number,  or  the  charac¬ 
ter  ‘.  ’  for  which  the  current  input  line  number  will  be  con¬ 
catenated  to  the  output.  After  the  *)’  is  found,  the  output 
buffer  will  be  dumped  to  the  output  file.  A  label  is  generated 
by  the  keyword  ‘.LAB’  followed  by  exactly  one  AOUT. 

The  most  important  NOTSYN  that  I  have  added  is  ‘.ACT. 
This  generates  instructions  to  the  compiler  generated  to  do 
something.  The  instructions  need  to  be  in  the  M4  language. 
The  instructions  in  an  ACT  are  for  the  M4  interpreter.  The 
instructions  in  an  OUT  are  for  the  target  machine.  In  this  ex¬ 
ample  the  target  is  M4,  but  usually  it  is  easier  to  tell  them 
apart.  Since  Meta  II  didn’t  have  anything  to  do  except  output, 
it  didn’t  need  this,  but  Meta4  needs  to  check  symbol  tables, 
assign  storage,  decide  between  alternatives,  etc.  An  ACT  is 
the  keyword  ‘.ACT’,  the  symbol  ‘(’,  and  zero  or  more  of  -{[a 
singly  or  doubly  quoted  string  (the  instruction  code)  followed 
by  ‘*1’  or  ‘*2’  or  nothing]  or  [a  comment  which  is  a  string 
quoted  by  *!’]  ]-.  ACT  essentially  allows  you  to  write  compiler 
instructions  in  M4  machine  code. 

I’ve  added  two  other  kinds  of  output.  ‘.CAT’  is  simply  an 
OUT  that  does  not  dump  the  output  buffer.  It  is  useful  for 
outputting  part  of  a  command,  doing  some  more  work,  then 
finishing  it.  ‘.ERMS’  is  designed  to  allow  putting  errdr  mes¬ 
sages  into  a  compiler  so  the  users  can  know  why  they  had  an 
error.  The  basic  error  message  that  the  M4  interpreter  provides 
identifies  the  line  and  symbol  number  where  it  detected  an 
error.  In  the  context  of  Meta4,  this  is  the  line  and  symbol 
number  of  the  first  symbol  in  a  statement  that  could  not  pos¬ 
sibly  be  legal  given  the  preceding  symbols.  This  is  quite  useful, 
but  any  other  help  you  can  give  yourself  will  be  repaid. 

The  most  frequent  ACT  is  to  transfer  a  number  from  one 
location  to  another.  Meta4  makes  these  programmable  in 
symbolic  terms  rather  than  having  to  use  the  machine  instruc¬ 
tions.  The  syntax  for  the  transfers  reflects  the  structure 
of  M4  transfer  commands  with  a  requirement  to  first 
specify  the  value  to  transfer  (RVALUE)  as  either  a  NAME 
identifier  (previously  defined  by  a  declaration),  or  a 
CONSTSIMP  or  an  EXPRESSION.  If  a  NAME  identifier  is 
specified,  it  may  also  have  appended  to  it  and  a  FIELD 
identifier.  The  value  in  the  field  of  the  symbolic  memory  in¬ 
dexed  by  the  place  named  will  be  taken  as  the  value.  The 
transfer  continues  with  the  exact  characters  '=:’  and  the 
NAME  of  a  place  optionally  followed  by  and  a  field  identi¬ 
fier,  which  will  be  used  to  store  the  fetched  value. 

EXPRESSION,  CONSTEXP,  and  CEXP  all  use  a  layering 
kind  of  structure  that  is  most  easily  understood  by  studying 
CONSTEXP.  The  four  subroutines  CONSTEXP,  CONSTTERM, 
CONSTFAC,  and  CONSTSIMP  should  be  examined  together. 
Start  at  the  top  line  of  CONSTSIMP,  which  says  that  a  number 
is  a  constant  factor,  and  to  put  it  on  the  stack.  Now  pass  up  to 
CONSTTERM.  It  says  to  look  for  a  CONSTFAC  (which  can 


be  satisfied  by  a  CONSTSIMP),  and  then  to  look  for  an  aster¬ 
isk  followed  by  another  CONSTFAC.  At  this  point  two  num¬ 
bers  are  on  the  stack.  The  action  is  to  pop  (!)  one  of  them  and 
multiply  (*)  that  times  what  is  on  the  stack.  This  will  be  done 
as  many  times  as  there  are  asterisks  in  the  input.  Now  look  at 
CONSTEXP.  That  says  to  look  for  a  CONSTTERM  (which  has 
any  number  of  multiplications  of  CONSTFACTORS)  and  then 
to  look  for  a  plus  or  a  minus.  If  either  is  found,  another 
CONSTTERM  will  be  sought  and  then  added  to  or  subtracted 
from  the  first.  The  result  of  this  layering  is  that  **’  binds  more 
tightly  than  *+’  or  so 

a*b+c  means  (a*b)+c 
not  a*(b+c). 

And  what  if  you  want  the  second  form?  Well,  look  again  at 
CONSTFAC.  Besides  CONSTSIMPS,  which  can  be  previously 
defined  constant  identifier  (stack  its  value),  a  single  quoted 
string  (stack  its  first  character),  a  minus  sign  and  any  other 
CONSTFAC  (take  the  negative  of  the  stack  top),  CONSTFAC 
can  be  an  open  parenthesis  and  any  CONSTEXP  then  a  close 
parenthesis.  The  last  alternative  lets  you  put  in  nested  paren¬ 
theses  to  get  your  meaning. 

One  point  about  EXPRESSION  is  worth  discussing. 
Notice  that  it  must  be  introduced  by  a  *+’  sign.  This  is  a  little 
ugly,  but  necessary  to  get  the  generality  of  expression  wanted. 
The  problem  is  that  *(’  has  already  been  used  in  SYN  to  indi¬ 
cate  a  new  PHRASE.  Without  the  introductory  *+’,  if  you 
tried  to  start  an  expression  with  (a+b),  then  you  would  start 
compiling  as  a  SYN  rather  than  as  an  EXPRESSION.  (Or,  per¬ 
haps  it  would  clobber  your  SYN’s,  depending  on  the  order.) 
This  was  not  obvious  to  me  until  it  happened,  and  it  represents 
a  distinct  limitation  on  the  kinds  of  languages  Meta4  can  com¬ 
pile. 

Another  main  NOTSYN  is  an  IF  statement  which  allows 
actions  built  of  NOTSYN’s  to  be  done  based  on  a  test.  In 
order  not  to  foul  up  the  recursive  descent  parsing,  only 
NOTSYN’s  are  allowed  in  the  selected  portions.  Also,  to  keep 
the  flag  in  shape  for  the  parsing,  it  is  set  true  by  an  IF  after 
using  it  to  make  the  branch.  The  IF  statement  also  refers  to  a 
CEXP,  a  conditional  expression.  CEXP,  CTERM,  and  CFAC 
form  another  layered  definition,  this  time  of  the  condition  ex¬ 
pression.  CFAC  shows  that  the  low  level  entities  are  two 
RVALUE’S  connected  by  one  of  six  relational  operators. 
These  can  be  qualified  by  ‘.NOT’,  joined  by  ‘.ANDIF’  and 
‘.ORIF’,  and  grouped  by  parentheses. 

NOTSYN’s  useful  together  with  an  IF  statement  are 
‘.ERROR’,  which  deliberately  flags  an  error,  and  ‘.RETURN’, 
which  returns  from  a  subroutine  before  the  end.  A  widely  use¬ 
ful  NOTSYN  is  to  define  a  string  quoted  by  ‘ !’  as  causing  no 
action,  so  it  becomes  a  comment.  The  most  common  transfer 
is  to  the  stack,  for  which  I  introduced  a  special  symbol  *]’. 
Finally,  the  symbol  ‘&’  followed  by  a  new  identifier  will  be 
compiled  as  a  subroutine  call.  This  is  the  same  action  as  the 
first  SYN,  but  does  not  generate  a  test.  It  should  be  used  if 
and  only  if  the  subroutine  consists  entirely  of  NOTSYN,  but 
there  is  no  test  for  this. 

Finally,  let’s  go  back  to  the  DECLARE’s.  These  allow  the 
user  to  define  an  identifier  as  a  FIELD,  a  NAME,  or  a 
CONSTANT.  FIELD’S  are  only  0-3  for  Meta4,  but  can  be  in¬ 
creased  if  needed  in  other  compilers.  NAME’S  are  limited  to 
ten  registers,  and  the  stacks.  CONSTANTS  can  be  any  con¬ 
stant  expression.  The  identifiers  for  these  can  be  any  length  up 


8 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 

323 


to  the  buffer  sizes  used  in  the  M4  interpreter  (80  bytes). 

Using  Meta4 

Schorre  apparently  conceived  of  using  Meta  II  to  generate 
code  for  an  interpreter,  not  for  direct  machine  execution.  At 
first  I  thought  this  was  a  lousy  idea,  because  interpreters  are 
slower  than  machine  code.  So  the  M4  H,  L,  and  OX  instruc¬ 
tions  let  it  put  out  machine  code.  But  after  experience  with 
the  M4  interpreter,  and  with  other  interpreters  derived  from  it, 
I  see  advantages  to  interpreters. 

The  big  advantage  is  ease  of  debugging.  Even  though  it  is 
not  interactive,  the  M4  code  can  be  read  easily  with  an  edit 
program.  If  not  understood,  output  commands  of  the  inter¬ 
preter  can  be  inserted,  and  the  bug  chased  down.  This  de¬ 
bugging  ease  comes  in  part  from  using  only  readable  and  partly 
meaningful  symbols  for  M4.  Somewhat  more  efficiency  in 
storage  and  speed  could  be  gained  by  sacrificing  it,  but  don’t 
be  tempted.  A  microcomputer  has  little  enough  help  for 
debugging,  on  which  most  of  your  time  is  spent. 

A  second  advantage  is  that  it  is  usually  easier  to  write  a 
compiler  for  an  interpreter,  because  the  interpreter  does  more 
work  per  instruction.  It  is  also  quite  reasonable  to  build  an 
interpreter  with  more  advanced  features,  such  as  stack  arith¬ 
metic  and  integers  to  make  compiler  writing  easier. 

Finally,  (do  I  protest  too  much?)  an  interpreter  is  a  par¬ 
ticularly  easy  form  of  program  to  debug  once  the  basic  pro¬ 
gram  loading  and  command  fetching  are  done.  This  is  because 
the  interpreter  exercises  a  command  if  and  only  if  you  tell  it 
to.  This  narrows  the  scope  for  bugs,  and  leads  to  finding  them 
faster. 

If  you  go  the  interpreter  route,  a  second  advantage  to  get¬ 
ting  the  M4  interpreter  running  is  that  it  becomes  a  base  you 


can  modify  to  make  other  interpreters  pointed  toward  your 
own  needs. 

Meta4  makes  a  powerful  system  for  defining  a  language. 
One  of  the  useful  features  is  that  a  Meta4  program  defines  not 
only  the  syntax  of  a  language  (the  rules  for  what  are  legal 
statements),  but  also  its  semantics  (what  these  statements 
mean).  Admittedly  the  syntax  is  laid  out  a  lot  more  clearly 
than  the  kinky,  as  it  grew,  means  for  dealing  with  semantics. 
Also,  it  is  quite  possible,  when  designing  a  compiler  for  a  given 
language  to  add  new  Meta  rules  by  augmenting  Meta4.  For  ex¬ 
ample,  a  sequence  of  SYN’s  separated  by  given  punctuation 
could  be  defined.  Two-level  means  of  defining  languages  have 
been  receiving  theoretical  attention  recently  (Cleveland  and 
Uzgalis,  Grammars  for  Programming  Languages ,  is  a  less  ab¬ 
stract  introduction).  They  are,  needless  to  say,  conceptually 
much  cleaner,  but  operationally  less  clear. 

Using  Meta4  in  a  two-level  manner,  it  becomes  a  fairly 
common  operation  to  bootstrap  a  larger  compiler.  Figure  3 
shows  the  operation.  It  can  be  done  in  two  steps,  but  it’s  wise 
to  make  a  third  to  be  sure  that  the  compiler  is  self- compiling. 
Start  reading  the  figure  at  the  lower  left.  You  write  a  Meta  5 
to  M4  compiler  in  the  Meta4  language.  You  compile  this  as 
usual  to  a  Meta  5  to  M4  compiler  written  in  M4.  Using  this 
compiler  you  can  translate  another  program  you  write  (but 
usually  similar  to  the  first,  and  sometimes  the  same)  which  is 
the  Meta  5  to  M4  compiler  written  in  Meta  5.  You  now  gene¬ 
rate  a  different  Meta  5  to  M4  compiler  written  in  M4.  You  can 
use  this  with  the  same  input  as  the  second  step  and  you  should 
get  the  same  output.  Since  that  doesn’t  usually  happen  the 
first  time,  it’s  wise  to  check  it. 

Figure  4  shows  a  similar  bootstrapping  process  if  you 
want  to  improve  the  M4  language  to  an  M5  language.  The  same 


Meta4  to  M5  compiler  in  Meta4  is  input  at  all  three  stages,  first 
producing  a  Meta4  to  M5  compiler  in  M4,  then  a  Meta4  to  M5 
compiler  in  M5.  In  the  third  step  the  coding  language  of  the 
compiler  running  differs,  but  the  source  language  and  target 
language  are  the  same,  and  the  input  is  the  same.  Therefore 
the  output  should  be  the  same.  Check  it. 

Writing  and  initial  debugging  for  a  compiler  written  in 
Meta4  take  about  as  long  as  other  programs  of  comparable  size 
in  characters.  But  debugging  the  language  -  making  sure  that 
what  you  want  to  mean  by  a  construct  is  what  gets  done  — 
takes  longer,  because  the  compiler  can  only  be  tested  by  com¬ 
piling  and  testing  programs.  Bugs  in  the  compiled  program 
may  be  due  either  to  a  bug  in  the  program  or  in  the  compiler.  I 
find  that  systematically  exercising  each  feature  in  turn,  by  arti¬ 
ficially  short  programs,  flushes  most  of  the  bugs  in  a  compiler, 
but  a  few  will  be  left  for  your  first  programs  to  point  out. 

The  M4  Language 

The  three  basic  functions  of  lexical  analysis,  parsing,  and 
output  are  handled  very  nearly  the  same  in  Meta4  as  they  are 
in  Meta  II.  Table  1  gives  the  commands  used  for  lexical  analy¬ 
sis.  The  first  five  are  very  similar  to  Meta  II,  and  each  returns 
either  “true”  or  “false”  by  setting  or  resetting  a  logical  flag. 

The  lexical  analysis  commands  are  both  powerful  and 
restrictive:  they  each  do  a  lot  for  one  command,  but  only  five 


kinds  of  strings  are  recognized.  Schorre  thought  out  the  kinds 
very  well,  however,  and  a  wide  class  of  languages  can  be  recog¬ 
nized.  I  added  only  the  recognition  of  a  hexadecimal  number. 
One  dead  end  I  followed  was  to  make  commands  for  simpler 
primitives,  like  an  alphabetic  symbol.  Using  them  slowed  the 
interpreter  down  a  lot  for  little  gain  in  flexibility.  The  use  of 
whitespace  is  particularly  likely  to  mismatch  a  pre-specified 
language  definition,  but  is  easy  to  change  by  changing  the 
interpreter.  Newlines  always  terminate  strings,  while  blanks  or 
tabs  will  also  terminate  identifiers  or  numbers.  Otherwise  these 
three  whitespace  characters  are  ignored,  and  can  and  should  be 
used  to  improve  readability  of  a  Meta4  program. 

The  purpose  of  the  fifth  command  is  to  allow  a  slight 
amount  of  backing  up.  After  giving  an  LI  command,  especial¬ 
ly,  if  an  identifier  has  been  found,  the  symbol  table  can  be 
consulted.  If  the  identifier  found  is  not  of  a  specified  type 
(such  as  that  representing  a  constant),  it  can  be  rejected  at  that 
point  and  tested  again  at  a  later  point.  It  makes  writing  a  syn¬ 
tax  easier.  The  Meta4  to  M4  compiler  listed  below  has  some 
examples  (see  IDNEW). 

The  commands  used  to  do  the  recursive  descent  parsing 
explained  before  are  just  the  flow  of  control  statements  given 
in  Table  2. 

The  third  core  function,  largely  taken  from  Meta  II,  is 
output.  The  M4  interpreter  has  an  output  buffer  to  which 


YOU  CAN  HELP  YOUR  COMMUNITY 
LEARN  ABOUT  COMPUTERS _ 

SUPPORT 

(omputerjow  n™ 

ComputerTown,  a  computer  literacy  project  sponsored  by  People’s  Computer  Company  and  later  funded  by  the 
National  Science  Foundation,  began  operations  in  1979.  The  project’s  ongoing  goal  is  to  design,  publish  and  dis¬ 
seminate  materials  for  the  development  of  community -based  computer  literacy  projects  around  the  world. 

You  too  can  help!  Your  tax-deductible  donations  of  new  and  used  computer  hardware  and  software  will  enable 
us  to  bring  “hands-on”  experience  to  people  everywhere.  These  items  can  mean  the  difference  between  a  person 
just  hearing  about  computer  technology  and  actually  being  able  to  sit  down  and  use  it.  A  ComputerTown  can 
be  set  up  in  a  public  library,  museum,  school,  business  or  a  number  of  other  places.  What’s  needed,  along  with 
the  information,  resources  and  experience  we  provide,  is  just  a  few  machines  and  some  software  to  get  started. 

Already  there  are  more  than  eighty  ComputerTowns  in  the  U.S.,  Canada,  England  and  other  countries.  Your 
generous  donations  can  help  this  number  grow. 

For  more  information  about  ComputerTown,  and  for  details  on  how  to  make  contributions,  contact: 


Fritzi  Lareau,  c/o  ComputerTown 
1263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  CA  94025 
(415) 323-3111 


10 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 

325 


various  strings  are  concatenated,  and  which  is  dumped  to  the 
output  file  on  command.  Table  3  describes  the  output  options. 
Among  them  is  the  option  to  generate  and  use  one  or  two 
labels  per  subroutine.  The  two  are  required,  for  instance,  to 
build  a  loop  construct,  with  one  label  at  the  top  to  repeat 
from,  and  one  label  at  the  bottom  to  exit  to.  It  has  turned  out 
that  only  two  labels  has  not  been  an  impediment  because  it  is 


Table  1 

Lexical  Commands 

LI 

An  Identifier  is  a  string  starting 
with  an  alpha  symbol  and  continu¬ 
ing  with  alpha  or  digits.  The  com¬ 
mand  returns  false  and  does  not 
change  the  input  buffer  if  no  identi¬ 
fier  is  in  the  input  stream.  Other¬ 
wise  it  returns  true  and  moves  the 
identifier  to  the  input  buffer.  If  the 
identifier  is  not  in  symbolic  mem¬ 
ory,  it  is  entered.  Register  zero 
points  to  the  memory  cell. 

LN 

A  Number  is  a  sequence  of  digits. 

The  command  returns  false  if  no 
digit  is  in  the  input  stream.  Other¬ 
wise  it  returns  true  and  places  the 
value  of  the  number  in  register 
zero. 

LH 

A  Hex  number  is  a  sequence  of 
hexadecimal  digits.  The  command 
returns  false  if  no  hex  it  is  in  the 
input  stream.  Otherwise  it  returns 
true  and  places  the  value  of  the 
number  in  register  zero. 

LQchar 

A  Quoted  string  is  composed  of  a 
quoting  character,  any  string  of 
characters  except  newline  or  the 
quoting  character,  and  a  closing 
quoting  character  or  newline.  The 
command  returns  false  if  the  input 
stream  does  not  contain  a  string 
quoted  by  the  character  given. 
Otherwise  it  returns  true  and  places 
the  string,  without  its  quotes,  in  the 
input  buffer. 

LMchar . 

.  char  A  Literal  string  is  any  string  of 
characters  except  a  newline.  The 
command  returns  true  if  and  only  if 
the  input  stream  matches  the  literal 
string.  The  input  buffer  is  not 
changed. 

L 

If  the  flag  is  set,  the  symbol  found 
in  the  input  stream  is  accepted. 
Otherwise,  it  is  rejected  and  be¬ 
comes  the  next  string  of  characters 
in  the  input  stream  again.  This 
modest  1  symbol  backup  makes  dif¬ 
ferent  types  of  identifiers  feasible. 

Dr.  Dobb’s  Journal,  Number  58,  August  1981 


Table  2 

Control  Commands 

S 

Set  the  flag  true. 

SF 

Set  the  flag  false. 

SC 

Set  the  flag  changed  (true  if  it  was 
false,  and  vice  versa). 

.number 

.identifier 

Identify  the  next  operational  com¬ 
mand  as  the  place  associated  with 
this  number  or  identifier. 

J/number 

Jump:  Transfer  control  to  the  place 
associated  with  the  number. 

F/number 

False  jump:  If  the  flag  is  false, 
transfer  control  to  the  place  associ¬ 
ated  with  the  number,  otherwise 
continue  to  the  next  command. 

T/number 

True  jump:  If  the  flag  is  true,  trans¬ 
fer  control  to  the  place  associated 
with  the  number,  otherwise,  con¬ 
tinue  to  the  next  command. 

Gidentifier 

Go  to  a  subroutine.  Stack  the  next 
command  location,  and  two  zero 
label  numbers,  then  transfer  control 
to  the  place  associated  with  the 
identifier. 

R 

Return  from  subroutine.  Unstack 
two  label  numbers  and  a  command 
location.  Transfer  control  to  the 
command  location  unstacked. 

E 

End.  Stop  processing. 

two  labels  per  subroutine  call.  Two  labels  are  a  marvelous 
encouragement  to  keep  your  subroutines  small  and  intelligible, 
and  to  segregate  concepts  by  level. 

M4  has  several  ways  to  store  numbers.  The  simplest  are 
ten  registers,  each  identified  by  a  digit.  The  ‘Y’  stack  allows 
stacking  a  number,  reading  its  top  entry,  or  unstacking  a  num¬ 
ber.  The  ‘Z’  stack  allows  stacking  or  unstacking  a  number. 
Memory  ‘cells’,  described  soon,  can  also  store  numbers. 
Table  4  shows  the  direct  Fetches  that  are  possible  in  M4. 

Why  a  stack?  Meta  II  can  only  compile  code  for  a  stack 
machine.  By  giving  M4  a  stack,  operations  can  be  stacked  by 
the  compiler,  then  output  in  the  required  order  for  a  register 
machine.  The  second  stack  allows  putting  loop  labels  and  if 
labels  on  different  stacks,  so  that  ‘break’  and  ‘continue’  kinds 
of  statements  can  be  compiled.  If  the  operations  get  hairy, 
with  types  for  each  variable,  go  to  the  stack  of  memory  cells 
(Table  5). 

The  symbolic  memory  stores  identifiers  together  with  a 
memory  cell.  The  cell  consists  of  N=1  to  5  integers  (known  as 
0  to  N-l)  and  N  byte  (known  as  N  to  2N-1)  storage  locations. 

The  symbolic  memory  is  layered  with  all  entries  made  in 
the  top  layer.  The  ‘LI’  command  automatically  searches  the 
symbolic  memory  from  the  top  layer  down.  If  identifiers  with 
the  same  name  are  in  different  levels,  the  top  one  will  be 
found.  This  structure  will  allow  defining  variables  with  a  local 
scope.  Table  5  gives  the  commands  for  manipulating  memory. 


11 


326 


The  last  two  commands  use  the  space  at  the  top  of  the  sym¬ 
bolic  memory  vectors  to  contain  a  stack  of  memory  cells. 

The  contents  of  a  memory  cell  are  fetched  by  an  indirect 
Fetch.  Indirect  Fetches  also  allow  getting  the  contents  of  the  in¬ 
put  buffer,  and  the  registers.  They  are  summarized  in  Table  6. 

The  direct  and  indirect  fetches  can  be  used  for  output 
with  ‘C’  and  ‘L’,  and  ‘H’  as  shown  in  Table  3.  There  are  several 
other  disposal  options  shown  in  Table  7.  The  general  form  of  a 
number  manipulation  is 

[Fetch]  [dispose] 
while  a  fetch  can  be  either 

[directFetch] 

or 

[directFetch]  [directFetch]  [indirectFetch] 

A  final  group  of  commands  are  useful  for  doing  something 
about  errors.  Table  8  shows  them.  The  ‘XM’  command  essen¬ 
tially  defines  a  place  in  the  syntax  to  return  to  after  finding  an 
error.  The  ‘XO’  command  is  of  some  use  for  remarking  which 
error  was  made,  but  of  much  greater  use,  I  find,  for  debugging. 


Table  3 

Normal  Output  Options 

o 

Out:  Dump  the  output  buffer  to 
the  output  file  with  a  newline,  and 
reset  it  to  the  null  string. 

OX 

Same  as  Out  except  no  newline 
written. 

P  specified 

Concatenate  the  specified  string  to 

string 

the  output  buffer. 

C 

Concatenate  the  input  buffer  to  the 
output  buffer. 

Fetch  C 

(See  Tables  4  and  6  for  Fetches.) 
Convert  the  number  fetched  to  a 
decimal  string  and  concatenate  to 
the  output  buffer. 

Fetch  L 

Concatenate  the  low  byte  of  the 
fetched  to  the  output  buffer. 

Fetch  H 

Concatenate  the  low  byte  of  the 
fetched  to  the  output  buffer  as  two 
hexadecimal  digits. 

U 

If  the  first  label  number  stacked  is 
zero,  substitute  the  symbol  gener¬ 
ator  and  then  increment  the  sym¬ 
bol  generator.  Convert  the  first 
label  number  stacked  to  a  digital 
string  and  concatenate  to  the  out¬ 
put  buffer.  Also  store  the  number 
in  the  zero  register. 

V 

If  the  second  label  number  stacked 
is  zero,  substitute  the  symbol  gener¬ 
ator  and  then  increment  the  symbol 
generator.  Convert  the  second  label 
number  stacked  to  a  digital  string 
and  concatenate  to  the  output  buf¬ 
fer.  Also  store  the  number  in  the 
zero  register. 

It  is  easy  to  use  an  editor  to  insert  output  commands  and  an 
‘XO’  command  to  trace  the  operation  of  a  troublesome  pro¬ 
gram  so  as  to  see  what  is  going  wrong.  These  are  pretty  crude 
aids  by  modern  standards,  but  they  let  you  skip  over  a  bug 
you  don’t  understand  and  work  on  others,  because  it  will  find 
a  bug  per  statement. 

Implementing  Meta4 

The  listing  for  the  M4  interpreter  in  Pidgin  gives  detailed 


Table  4 

Direct  Fetches 

Y 

Fetch  the  number  stacked  on  the  Y 
stack,  without  popping. 

f 

Fetch  the  number  stacked  on  the  Y 
stack,  and  pop. 

Z 

Fetch  the  number  stacked  on  the  Z 
stack,  and  pop. 

H 

Fetch  the  high  byte  of  the  Y  stack, 
without  popping. 

Digit 

Fetch  the  contents  of  the  register 
indexed. 

N/number 

Fetch  the  number  specified. 

B 

Fetch  the  breadth  of  the  input 
string. 

U 

Fetch  the  first  number  label  with¬ 
out  altering. 

V 

Fetch  the  second  number  label 
without  altering. 

Table  5 

Memory  Commands 

MI  digit 

Initialize  memory,  and  set  cell  size 
to  the  digit  (1 -5);  default  size  is  2. 

ME 

Enter  the  input  buffer  into  the  top 
layer  of  memory’.  Return  the  index 
pointing  to  the  memory  cell  to 
register  zero,  and  zero  the  memory 
cell. 

MS 

Stack  memory  —  seal  off  the  previ¬ 
ous  top  layer  and  open  a  new  layer. 

MP 

Pop  memory  —  delete  all  entries  in 
current  top  layer  and  reopen  the 
next  lower  layer. 

MC 

Create  a  memory  cell  in  the  cell 
stack.  Return  the  index  to  register 
zero,  and  zero  the  cell. 

MD 

Destroy  the  top  memory  cell  on  the 
cell  stack.  That  is,  pop  this  stack. 

MQ 

Query  the  entire  memory  using  the 
input  buffer.  Return  an  index  to 
the  memory  cell  found  (or  zero)  to 
register  to  zero. 

12 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 

327 


Table  6 

Indirect  Fetches 

M  digit  If  digit  is  not  in  the  range  of  mem¬ 

ory  cell  indexes  (0  to  2  N-l),  use 
zero.  Fetch  the  contents  of  the 
digit’th  storage  location  of  the  cell 
indexed  by  the  direct  Fetch. 

S  If  the  direct  Fetch  is  less  than  the 

input  string  length,  fetch  the 
direct’th  character  from  the  input 
buffer.  Default  to  the  zeroth  char¬ 
acter. 


Table  7 

Non -Output  Dispose  Options 

Y 

Stack  the  Fetched  on  the  Y  stack. 

Z 

Stack  the  Fetched  on  the  Z  stack. 

+ 

Pop  the  Y  stack,  add  the  result  to 
the  fetched,  and  stack  the  result  on 

Y. 

Pop  the  Y  stack,  subtract  the 
fetched  from  the  popped,  and  stack 
the  result  on  Y. 

* 

Pop  the  Y  stack,  multiply  the  result 
times  the  fetched,  and  stack  the  re¬ 
sult  on  Y. 

> 

Pop  the  Y  stack,  set  the  flag  if  the 
fetched  was  greater  than  the 
popped,  else  reset  the  flag. 

< 

Pop  the  Y  stack,  set  the  flag  if  the 
fetched  was  less  than  the  popped, 
else  reset  the  flag. 

Pop  the  Y  stack,  set  the  flag  if  the 
fetched  was  equal  to  the  popped, 
else  reset  the  flag. 

digit 

Store  the  fetched  in  the  digit’th 
register. 

I [loc]  [direct]  Store  the  fetched  indirect  to  mem- 

ory,  in  the  loc’th  location  of  the 
memory  cell  indexed  by  the  re¬ 
sult  of  this  direct  fetch. 

A 

Append  low  byte  of  fetched  to 
input  register. 

B 

Set  length  of  string  in  input  register 
(especially  shorter)  from  the 
fetched. 

G 

Set  the  symbol  generator  from  the 
fetched. 

U 

Store  the  fetched  as  the  first  label 
number. 

V 

Store  the  fetched  as  the  second 
label  number. 

D 

Dump  the  fetched  -  do  nothing. 

Dr.  Dobb’s  Journal,  Number  58,  August  1981 


Table  8 

Error  Handling  Commands 

XM  character  Save  the  current  code  position, 
stack  depth  and  the  mask  charac¬ 
ter. 

X  If  flag  is  true,  do  nothing.  If  false 

print  the  line  and  symbol  number; 
discard  characters  from  the  input 
until  find  the  mask  character  or 
end  of  file.  Reset  the  code  pointer 
and  stack  depth  to  saved  values. 

XN  Copy  the  line  number  to  the  out¬ 

put  buffer. 

XO  Dump  the  output  buffer  to  the 

terminal. 


You  Read  Dr.  Dobb’s  Journal 
And  You  Don’t  Subscribe?! 

Save  $13  off  newsstand  prices  for  2  yrs. 
Save  $5  for  1  yr. 

Can  you  afford  to  miss  an  issue  with  information  vital 
to  your  interests?  As  a  subscriber  you  can  look  for¬ 
ward  to  articles  on  Small-C,  FORTH,  CP/M,  S- 100, 
Compiler  optimization,  Concurrent  Programming  and 
more,  delivered  right  to  your  door.  And  you’ll  never 
miss  the  issue  that  covers  your  project. 

DR.  DOBB’S  JOURNAL 
P.O.  Box  E 

Menlo  Park,  CA  94025 


Yes!  Sign  me  up  for  _ 2  yrs.  $47  _ 1  yr.  $25 

_  I  enclose  a  check/money  order 

_  Charge  my  Visa,  MasterCard,  American  Express 

_  Please  bill  me  later 

Name  _ 

Address  _ 


Credit  Card _  Exp.  date 

Acct  No.  - 

Signature - 


13 


328 


algorithms  for  implementing  an  M4  interpreter.  You  also  need 
the  Meta4  to  M4  compiler  in  M4  to  get  started,  once  the  M4 
interpreter  is  debugged.  A  good  test  of  your  M4  interpreter  is 
to  recompile  it  from  the  Meta4  listing. 

The  M4  interpreter  compiles  into  9056  program  bytes  of 
6502  code  using  the  compiler  described  last  month.  It  also 
uses  memory  for  label  index  table,  interpretive  code,  subrou¬ 
tine  stack,  and  symbolic  memory.  I  have  set  aside  2K,  10K, 
IK,  and  9K  bytes  respecitvely  for  these.  To  compile  the  Meta4 
syntax  only  takes  1/2K,  3K,  1/1  OK,  and  1/2K  of  this  working 
space.  It  takes  my  Apple  II  about  60  seconds  for  this  compila¬ 
tion. 

The  following  brief  description  of  the  algorithms  and 
methods  of  the  M4  interpreter  may  also  help  in  implementing. 
And  don’t  overlook  the  comments  within  the  program. 

The  first  phase  of  the  M4  interpreter  is  to  initialize  con¬ 
stants,  etc.,  then  to  load  and  compact  its  program.  The  sym¬ 
bolic  memory  is  used  in  this  phase  to  compile  the  symbolic 
subroutine  calls  to  show  the  location  in  the  interpretive  code 
referenced.  Numbers  preceded  by  a  7’  are  compiled  into  two- 
byte  binary  representations  from  a  decimal  representation. 
Number  labels  are  entered  in  the  numeric  label  table  (they 
could  also  be  compiled  at  this  time  and  save  the  table  space  at 
a  cost  of  more  program  to  compile).  In  the  interpretive  code 
space  each  instruction  is  represented  by  a  byte  showing  how 
many  other  bytes  follow,  then  by  the  bytes  of  command,  as 
compacted.  This  phase  is  accomplished  about  as  fast  as  Apple 
can  read  the  disk.  At  the  end  of  this  phase,  the  M4  interpreter 
notifies  the  user  of  how  many  instruction  bytes  were  used, 
how  many  labels,  and  how  many  subroutines.  For  each  sub¬ 
routine  call  made  to  a  subroutine  never  defined,  a  message  is 
output.  The  name  is  not  easily  reconstructed  at  this  point,  but 
the  last  of  the  characters  printed  are  the  last  characters  of  the 
name  of  subroutine  called.  Since  the  error  is  not  necessarily 
fatal,  the  program  continues.  But  it’s  usually  a  bad  sign. 

The  main  body  of  the  M4  interpreter  is  a  loop  that  fetches 
the  next  instruction,  then  chooses  a  sequence  of  actions  as  de¬ 
scribed  before  from  the  command  characters.  They  are  or¬ 
dered  so  the  most  frequently  used  in  the  Meta4  to  M4  compil¬ 
er  are  first.  When  it  is  through  it  prints  the  maximum  amount 
of  symbolic  memory  that  was  used. 

The  registers  and  stack  are  integer  vectors.  Each  stack 
operation  is  checked  for  overflowing  or  underflowing  the 
space  allocated.  If  you  change  a  dimension  statement,  be  sure 
to  change  the  corresponding  initialization  statement. 

The  symbolic  memory  is  constructed  for  digital  searching 
(Knuth,  Art  of  Computer  Programming ,  Vol.  Ill  sorting  and 
search,  section  6.3).  Knuth  shows  that  this  requires  on  average 
only  log2  N  search  steps  if  the  input  data  is  random,  so  it  is 
usually  an  efficient  system.  It  is  also  easy  to  program.  Two 
vectors  are  used  to  make  a  binary  tree  holding  a  level  of  the 
symbol  table.  One  vector  holds  characters,  the  other  integers 
which  index  an  alternate  place  in  the  tree.  In  searching,  the 
first  character  of  memory  is  compared  to  the  first  character  of 
the  symbol.  When  a  match  is  found,  if  it  is  a  match  on  the  end 
of  string  character  (zero),  the  memory  cell  for  the  symbol 
begins  at  the  next  index.  If  a  pair  of  characters  matches,  but  is 
not  the  end  of  string  character,  the  next  character  in  memory 
will  be  compared  to  the  next  character  in  the  symbol.  When¬ 
ever  the  character  in  memory  does  not  match,  but  there  is 
another  alternative  (the  alternative  index  is  not  zero),  the  cur¬ 


rent  character  of  the  symbol  will  be  compared  to  the  alterna¬ 
tive  character  in  memory.  If  there  is  no  alternative,  then  the 
search  has  failed  —  the  symbol  has  not  been  entered  into  that 
level  of  memory. 

Table  9  shows  the  representation  from  entering  HAD, 
HAVE,  HE,  HER,  in  that  order,  and  reserving  memory  cells  of 
size  2. 

Availability  in  Machine  Readable  Form 

With  the  listings  of  the  M4  interpreter  and  Meta4  provided 
here,  you  can  get  Meta4  working.  If  you  want  to  save  yourself 
the  typing,  and  can  transfer  files  from  an  Apple  near  you,  you 
may  be  interested  in  the  following  offer.  A  version  of  the  M4 
interpreter  in  an  experimental  operating  system  is  available 
from  the  author.  It  includes  the  listings  here,  and  machine  lan¬ 
guage  versions  of  the  M4  interpreter,  the  Tincmp  compiler, 
and  an  editor.  It  will  run  on  an  Apple,  configured  for  1  to  4 
floppy  disk  drives.  It  requires  a  16K  memory  card  or  an 
Apple  II  (not  plus).  Two  disks  and  documentation  are  avail¬ 
able  for  $20.  A  third  disk  with  Pidgin  listings  for  the  operating 
system  programs  is  available  for  $10.  If  you  are  reading  this 
after  1981,  better  write  to  ask  about  availability. 


Table  9 

Representation  in 

Symbolic  Memory 

Index 

Choice 

Alt. 

Notes 

1 

H 

0 

No  alt  to  H 

2 

A 

12 

Alt  to  ‘A’  is  ‘E’  starting  at 

12 

3 

D 

7 

Alt  to  ‘D’  is  ‘V  starting  at 

7 

4 

0 

0 

end  of  word  HAD 

5 

M2 

M0 

Memory  cell  for  HAD 

6 

M3 

Ml 

7 

V 

0 

8 

E 

0 

9 

0 

0 

10 

M2 

M0 

Memory  cell  for  HAVE 

11 

M3 

Ml 

12 

E 

0 

No  alt  to  ‘HE’ 

13 

0 

16 

But  there  is  an  alt  to 
*HE[end]  ’ 

14 

M2 

M0 

Memory  cell  for  HE 

15 

M3 

Ml 

16 

R 

0 

17 

0 

0 

18 

M2 

M0 

Memory  cell  for  HER 

19 

M3 

Ml 

20 

Free  memory  starts 

14 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 

329 


Some  Useful  C  Time  Functions 


Rather  than  show  why  you  should 
use  a  programming  language  (in  this 
case  C),  this  article  endeavours  to 
show  why  I  have  used  it.  An  example 
program  demonstrates  some  aspects  of 
the  language  and  is  directly  useful  to 
owners  of  the  Mountain  Hardware 
100,000  day  clock  board,  as  well  as  being 
generally  useful  to  others  with  real  time 
clock  facilities  in  their  systems.  A  basic 
knowledge  of  C  will  be  required  to 
understand  the  example  program;  it  is 
structured  and  commented,  and  brief 
extra  descriptions  of  the  functions  are 
given. 

Why  C? 

While  I  have  admired  the  C  language 
from  afar  for  a  long  time,  only  relatively 
recently  have  I  discovered  its  true  de¬ 
lights.  Because  Pascal  was  supposed  to  be 
the  language  for  structured  programming 
and  there  was  a  need  for  more  structure 
in  my  programming  efforts,  I  had  given 
Pascal  a  good  try.  The  system  utilities 
which  I  was  interested  in  writing  just 
would  not  come  together  properly  under 
Pascal;  I  had  the  distinct  feeling  the  lan¬ 
guage  was  fighting  me  rather  than  helping  | 
my  programming  efforts.  My  problems 
with  Pascal  were  not  limited  to  one  im¬ 
plementation.  Pascal/ M,  Pascal  MT+, 
Pascal/ Z  and  UCSD  Pascal  all  presented 
similar  generic  problems.  Before  the 
Pascal  phreaks  rise  up  again,  let  me  stress 
that  there  are  a  lot  of  things  about  Pascal 
which  seem  very  worthwhile,  but  I 
couldn’t  get  it  to  do  the  things  that  I 
need  done,  in  a  way  I  could  grasp. 

So  for  a  time  I  retreated  to  assembler 
and  FORTRAN  for  the  serious  stuff  and 
to  BASIC  for  the  quickies.  I  found  it  was 
possible  to  write  reasonably  structured 
programs  in  BASIC-801  and  FORTRAN 
80  if  a  moderate  amount  of  care  was 
taken,  but  assembler  was  still  the  main¬ 
stay.  A  brief  flirtation  with  FORTH  fol¬ 
lowed.  FORTH  showed  great  promise 
but  the  temptation  to  produce  code 
which  even  I  couldn’t  understand  a  week 
later  was  too  great.  Still,  the  idea  of  an 
extensible  language  is  fascinating! 

In  the  meantime,  I  had  been  reading 
“The  C  Programming  Language”2  and  it 
was  clear  that  C  was  a  language  which  was 


by  Bill  Bolton 


Bill  Bolton,  Software  Tools,  P.O.  Box  80, 
Newport  Beach,  NSW,  2106,  Australia. 


structured  but  not  too  verbose  or  inflexi¬ 
ble  (my  major  problems  with  Pascal).  It 
also  appeared  to  have  an  extensible  as¬ 
pect  in  that  the  overhead  in  writing, 
maintaining  and  using  a  library  of  func¬ 
tions  was  quite  small. 

At  about  this  time,  a  major  software 
project  of  the  AWA  Data  Group  was 
started  in  C.  I  was  able  to  look  over  the 
programmer’s  shoulder  as  the  project  pro¬ 
gressed  and  I  liked  what  I  saw.  What’s 
more,  when  the  project  finished  the  pro¬ 
grammers  involved  still  seemed  sane.  I 
had  a  chance  to  see  a  working  C  compiler 
(Whitesmith’s  for  the  PDP-11)  in  action 
and  to  study  the  documentation.  While 
the  Whitesmith  compiler  was  out  of  my 
financial  range  for  starters,  Leor  Zolman 
had  his  BDS  C  compiler  available  at  a 
very  reasonable  price  (on  reflection  I’d 
say  it’s  an  absolute  steal),  so  that  was  my 
choice. 

As  soon  as  the  compiler  arrived,  I 
was  thrown  into  the  situation  that  forced 
me  to  jump  in  at  the  deep  end  and  use  it 
for  a  commercial  project.  I  had  quoted  a 
client  four  hours  to  write  a  file  conver¬ 
sion  program  in  assembler.  It  soon  be¬ 
came  obvious  that  I  had  made  a  major 
error  with  my  time  prediction,  so  I  de¬ 
cided  to  try  and  salvage  the  situation  by 
writing  the  program  in  C.  This  first  pro¬ 
gramming  effort  in  C  went  so  smoothly 
that  the  project  was  finished  within  the 
budgeted  time  and  the  client  got  a  prod¬ 
uct  with  error  handling  an  order  of 
magnitude  better  than  he  would  have  re¬ 
ceived  from  an  assembler  program.  Since 
then  I  have  abandoned  BASIC  almost  en¬ 
tirely,  only  use  FORTRAN  for  mainte¬ 
nance,  and  have  greatly  reduced  the 
amount  of  assembler  programming.  The 
description  of  C  as  “a  Pascal  that’s  not 
afraid  to  get  its  hands  dirty”3  is  very, 
very  apt. 

If  there  is  one  single  thing  that  de¬ 
layed  my  entry  in  the  world  of  C  it  is 
probably  the  sparcity  of  references  to  C 
in  the  microcomputer  journals.  There 
have  been  only  a  handful  of  programs 
published  and  often  they  are  examples 
that  don’t  really  do  anything  useful 
(Small  C  in  an  obvious  exception).  Fol¬ 
lowing  is  one  small  effort  to  correct  this 
situation. 

The  Program 

DATEDEMO  is  a  collection  of  C 
functions  which  will  format  a  string  with 
the  current  date  and  current  time  fetched 
from  a  Mountain  Hardware  100,000  day 


clock  S- 100  board.  Several  date  and  time 
formats  are  available  by  specification  as 
one  of  the  arguments  to  the  primary 
functions. 

The  date  formats  are  those  used  by 
the  nearly  all  “Western”  countries  outside 
North  America  (this  is  an  appropriate 
point  to  complain  loudly  about  software 
packages  that  lock  the  user  into  MM/DD/ 
YY  date  formats!!!)  but  are  coded  in  a 
very  general  manner  so  that  nearly  any 
imaginable  date  format  could  be  easily 
generated  and  extra  formats  are  easily 
added.  Time  formats  are  somewhat  ar¬ 
bitrary  and  only  support  24-hour  types 
(perhaps  if  someone  is  keen  they  will  do 
an  AM/PM  12-hour  type  and  contribute 
it  to  DDJ). 

In  practice  I  use  the  functions  to  put 
date  and  time  in  the  page  headings  of 
hardcopy  output  and  in  some  business 
packages.  The  functions  live  in  my  stan¬ 
dard  C  function  library  and  are  linked  in 
at  compile  time.  Normally  the  “#define” 
statements  are  loaded  from  a  header  file 
CLOCK. H  but  they  are  listed  in  full  here. 
While  the  program  is  written  for  compila¬ 
tion  with  the  BDS  C  compiler  (Version 
1.4X),  it  should  also  compile  with  the 
other  C  compilers.  The  only  non-standard 
library  function  is  ‘initw’  which  is  the 
BDS  kludge  to  allow  array  initialization, 
as  BDS  C  does  not  support  initializers.  As 
far  as  I  know,  all  other  library  functions 
are  supported  by  other  C  compilers  (may¬ 
be  not  Small  C). 

The  Functions 


‘main’  Is  simply  an  executable 

demonstration  program 
to  tie  the  actual  working 
functions  together,  all 
the  presently  supported 
formats  are  displayed 
and  a  typical  use  of  the 
formatted  strings  is 
shown  on  the  last  line 
displayed. 


‘date’  Attempts  to  get  basic 

data  to  format  a  data 
string  form  the  clock;  if 
this  fails  an  error  message 
is  displayed,  else  the 
month  and  week  name 
are  determined  and  the 
string  formatted. 

‘get  date’  Tests  if  the  clock  board  is 
in  the  system.  Then  col- 


16 

330 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


lects  digits  from  the 
clock  to  get  the  number 
of  days  since  31/ Dec/ 
1977  (N.  B.  this  day  was 
a  Saturday,  so  a  simple 
MOD  7  on  the  total  num¬ 
ber  of  days  since  then 
makes  Sunday  day  1). 
This  value  is  then  turned 
into  the  year,  month  and 
day  of  the  month. 

‘month_day’ 

Uses  an  initialized  array 
to  determine  month  and 
day  of  the  month  from 
year  and  day  of  the  year. 

‘ndays’ 

Returns  number  of  days 
in  the  specified  year. 

‘leap’ 

Thorough  test  for  leap 
years. 

‘namemonth’  Fills  a  string  with  a  month 
name  given  the  number 
of  the  month  in  range  1 
to  12. 

‘name_week’ 

Fills  a  string  with  day  of 
the  week  name  given  the 
number  of  the  day  in 
range  0  to  6. 

‘time’ 

As  for  ‘date’  except  that 
time  needs  much  less 
processing. 

‘read_clock’ 

Tests  if  clock  is  in  system 
(this  test  must  be  dupli¬ 
cated  from  ‘get_date’  as 
the  date  and  time  func¬ 
tions  may  be  used  sepa¬ 
rately),  then  fetches  dig¬ 
its  from  the  clock  and 
puts  them  straight  into 
an  integer  array. 

The  Hardware 

The  MH  board  occupies  a  block  of 
16  I/O  ports.  The  values  returned  from 
each  port  are  shown  at  the  head  of  the 
listing.  Each  value  is  in  the  form  of  a 
BCD  number  and  for  the  purposes  of  this 
program  the  high  nybble  of  the  port  can 
be  ignored.  A  simple  test  for  presence  of 
the  board  in  the  bus  can  be  made  by 
looking  at  the  base  port.  An  FF  hex  will 
indicate  that  the  board  is  missing.  An  on¬ 
board  battery  keeps  the  clock  running  all 
the  time,  so  I  only  need  to  reset  time  for 

Daylight  saving  and  usually  do  it  using 
DDT’s  inline  assembler.  The  board  has 
been  super  reliable  and  functions  well  in  a 
system  set  up  to  IEEE  696  standards. 

The  rest  of  the  system  is  a  North  Star 
Horizon  mainframe  with  a  Morrow  De¬ 
signs  “Wunderbuss”  12  slot  motherboard 
(Yes  it  is  possible  to  get  another  mother¬ 
board  into  an  Horizon,  and  attacking 
your  computer  with  a  hammer  can  be  a 
very  therapeutic  experience,  but  that  is  a 
story  for  another  time),  Godbout  Z-80 
CPU,  Morrow  SuperRam  memory, 
Morrow  Disk  Jockey  2D  controller  and 
Godbout  Interfacer  I  Serial  I/O. 


Program  Availability 

This  program  will  be  available  from 
the  BDS  C  User’s  Group,  409  E.  Kansas, 
Yates  Centre,  KS  66783.  Membership  in 
the  group  is  $10.00  a  year  (US$20.00  a 
year  foreign)  and  numerous  disks  of  C 
software  are  available  from  the  group  for 
nominal  copying  charges.  Among  the 
software  available  is  Ron  Cain’s  Small-C 
Compiler  and  Run  Time  Library  previous¬ 
ly  published  in  DDJ,  and  W.  C.  Colley’s 
6800  &  1802  cross-assemblers  previously 
described  in  DDJ.  SSj 


References: 

•See  CPMLABLE.BAS  on  CP/M  User's  Group 
Disk  46,  one  of  my  efforts  at  structure  in 
BASIC  80. 

2“The  C  Programming  Language”  by  Brian  W. 
Kernighan  and  Dennis  M.  Ritchie,  published 
by  Prentice-Hall  1978,  ISBN  0-13-110163-3. 
This  is  the  “bible”  of  C  and  essential  to  any 
study  of  the  language. 

^From  “C  Notes”  by  C.  T.  Zahn,  published  by 
Yourdon  Press  1979,  ISBN  0-917072-13-8. 
The  only  other  readily  available  work  on  C;  in¬ 
teresting  as  it  was  written  by  someone  outside 
Bell  Labs  and  who  has  a  slightly  different  per¬ 
spective  on  the  language. 


The  Author 

Bill  Bolton  is  employed  as  Senior 
Technical  Officer  at  Multicultural  Televi¬ 
sion  Channel  0/28,  involved  in  the  main¬ 
tenance  of  both  mini  and  microcomputer 
systems  as  well  as  video  systems.  BASIC 
and  FORTRAN  were  learned  as  part  of  a 
college  course  in  1975  and  that  was 
where  he  became  interested  in  computers. 
Present  activities  include  consulting  work 
for  CP/M  system  users,  coordinating 
80 AT  (the  Australian  8080/Z80  User’s 
Group)  and  writing  a  regular  CP/M  col¬ 
umn  in  a  local  microcomputer  journal 
“Your  Computer.  ” 


C  Functions  Demo 

A>DATEDEMO 

Demonstration  of  'C'  functions  for  the  Mountain  Hardware  100,000  day  clock. 

By  Bill  Bolton,  Software  Tools 
P.0.  Box  80, 

Newport  Beach, 

NSW,  2106,  AUSTRALIA 

Date  format  0  is  May  20,  1981 

Date  format  1  is  Wednesday,  May  20,  1981 

Date  format  2  is  20/5/1981 

Date  format  3  is  Wednesday,  20/5/1981 

Date  format  argument  ERROR  ! 

Time  of  day  format  0  *  0940:22 
Time  of  day  format  1  *  09:40:22 
Time  of  day  format  2  =  09:40 
Time  of  day  format  argument  ERROR  ! 

Printed  at  0940:23  Hours  on  Wednesday,  May  20,  1981  for  Dr. Dobbs  Journal. 
A> 


Dj.  Dobb’s  Journal,  Number  58,  August  1981 


17 

331 


C  Time  Functions 


u  c 

C  u 
-4  3 


X 

O 


X 

<D 

5s 


>1 

X 

O 

E 


0) 

E 

X 

C 

E 


W 

«P 


4->  •» 

w  — . 


4J  C 
C  U 
•h  3 
U  4-1 

a,  a) 

to  u. 


JZ 

4J 

c 

o 

E 


>i 

<0 

TJ 

E 


T5 

dP 

\ 


-h  3 
U  4J 

a  a) 


<u 

w 


X 

O 


0) 

w 


x 

o 


c 

o 

E 


>, 

X 

O 

E 


4) 

E 

X 

C 

5 


T3 


\ 

n 

dP 


a 

o 

a 

a: 

u 


c 

4) 

E 


3 

O' 


X 


4J 

X 

E 

u 


O 


a> 

4J 

X 

Q 

• 


C 

•U  U 
C  3 

•H  4J 

u  a> 

a  u 


d) 

•o 


4J  0) 
4-»  (/) 
<0  3 

E 


*  \ 

\  jC  * 

\«  4-)  -* 

*  c  a> 
•coo 
»-  4J  6  i 
<0  c 

11  o  {I  o 

><  E  jC  -C 

4J  4J 

4-1  4J 

C  C  <44  *4-1 

O  II  o  o 

L,  U 

*-  ^  >S  >, 

3  3  (0  flj 

O  O  -a  T3 


a>  a>  a)  a> 

4-1  4J  *J  4-1 

c  c  c  c 


X  C  4) 
a>  -h  3 
N  k<  H 


H  4J  >,  >, 

X  C  HJ  X 

4)  O  -D  T3 

XE  E  ) 


«J  «|iw 
’0  4-10 

I  <0 

4-1  *0  4-1 


I 

45 

£ 

oo 

co 

a 

c 

o 

— 

X 

u 

H 


o  o  «  o 

a  a 

01  \  4J 

**  4J  «  k-.  4J 

5  0  -4  \ 

5  o'  a  o'  « 

TJ-H  u  \ 

■»  'O  \  4J  « 


a- 


•o  4J 


O'  w 
•h  X) 
i-  u  •**  TJ  C 
-4  0  0'  O 
^  U  -H  Ifl  o 
•*-»  4)  X3  TJ  4) 
C  (/)  C  </) 
3  O  W  O  -4 
O  Lt  T3  O  <-4 
S  O  C  4)  -4 
•H  O  U)  -H 
*-  E  O  -4  E 
O  HI 


i  w  , 


I  o 


a 

*4  O 

o  4-i  a*j 

a-.  --H 

O'  4J  ^ 
4-1  — •  .-s 

"4  'O  O'X) 

"4  w  T3  w) 
X3  TJ  a) 
C  W 

W  O  4)  3 

-n  O  *J  c 

a>  3 


\  4-1 

«  k-  \  • 
O  *  I 

4-i  a 

k-  4-1 

O  U  4 

a-s  o 

o'  a 

4-1  -C 
■H  TJ  4J 
O'  -H 
■4  1/1  O' 

-0^.-4 

3  XJ 


Q-  oi'« 
4J  XJ 


>, 

<0 

O'-O 


\  0) 

3 


•H  >i  m  x 

3  dnj  c 


w 


X 


o  - 
a_* 


0  T)  '4  «w  X 

0-41  E  O  Jl 

u  kj 

<D  X3  4J  W)  X) 
W  C  -4  c  C 
<03003 


O  W  -4 

o 

4)  ‘ 


o  e  o 


k-  -C  W 
3  >, 

o 

-C  O  xi 


-4  C  ■-*  c  ■ 

c  a»  c  qi 

3  H  3  £  : 


>4'M  O  3 
X  O  O 
tf)  £ 
W  X  +J 

44  73  c 

o  41  mu 

k-  W  O 
MX  3 

c  C  O  c 
a»  3  £  a/ 
H  X  H  e 4 


Q..Q 


\NW\\\\; 


x  * 

o  c 

-Q  O 


-kC  E 

O  -*4 
0  4J 
fH 

O  XJ 

c 

>1  (Q 


4)  X 
U  X3 


0  i 
>,  o  I 
X  H  I 


U  S)  L.  4J  /  * 

C  (S  X  L,  c  c 

3  Q  >  o  /  / 

**-<  ‘4J  a<  c 

SU  )  H  / 

-  S  o  41  ^  HI 

U  -4  W  2  <  <*> 

-  4J  a 

41  -  /  H  l/l 

**  k-  c  C  W  -F4 

0X0/3) 

3  -  <  CS 


c 

/ 


X 

H 

CN 

• 

+ 

+ 

sc 

X  1C 

SC 

U 

u  u 

u 

O 

O  O 

o 

J 

IN  J  J 

u 

u 

m  U  u 

<3 

U 

(S 

<-4 

u  u  u 

u 

o  uu 

u 

Juiw 

w 

4) 

u  =)  z 

T. 

T> 

4)  4)  4) 

4) 

3 

c  c  C 

C 

0 

>44  »44  V44 

V44  ' 

c 

4)  4)  4) 

4) 

•H  \ 

'OX3T3 

T3  1 

.  »  * 

»  afc  Pfc 

«fc 

+  +  + 


»  u  o 
I  O  o 


SHMn'Tin 
OO'HHHHHH 
-f  +  +  +  -*--f  +  +tL. 

uuuuq 

oooooooo® 

UUUUUUUUiS 


C  C  C  C  C 


is  ic  a. 

\  ^  o  S  1C  (S  u 

;D3>>>>c>,201 

'00<<  <<<••- 4 

:xxQQQQau2 

414)4)414)4)4)4) 

cccccccc 


U4  U4  44  U-l  u_4  M 


2222222*«-8S-S$S5555 


o  a  4) 

SEC 


E  k- 
X  O'  4) 
k-  O  JC 
O'  kj  4J 

o  a 

k-  O' 

a  c  c 

4)  X  >i 
'HEX 

a  -4 
e  w  a 

X  -H  (fl 

x  r.  -h 

CO  H  XJ 


w  cn 

I  I 

4)  4) 


Wi  c  n 
a  -H  -s 
W  X  X 
C  4J 

o  c  : 

E  3  c 


kO  X  4J 

X  Q  E  X 

O  *h  k-i  •»  E  •» 

CO  <N  o  -s  U 

^  H  O/N 
•  s  s  V*4  s 
O  2  4)  k4  u 


6  •*  f 

O  rn  ( 


a  z 

*J  4J 

•// 


Q  lx  |x  |x 

/  4)  Q  4)  Q  4)  Q 

*  4->  •  4->  *  *J  * 

"  — •  X  X  ' —  x  — ■ 

t  >44  -U  k*4  XJ  »*4  -O  V*4 
)  4J  ^  4-)  4J  4J 

:  c  4)  C  4)  c  4)  c 


18 

332 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


4J  -U  OJ  -U 

w  w  e  w 
I  H  I 
ai  41  h  41 
•u  e «  e 

<T3  --H 

■o  iiU  iJ 
^  ^  AJ 
0)  0)  C  D 
4J  e  ■-<  g 
flj  hJ 
•o  *J  O*  -U 


41  4J  41  4-1  4 

E  W  E  W  t 

E-.  41  H  01  < 

*  E  •  E  * 

- - -  -r4  I 

44  4J  U  44  4 

4J  — '  4J  ' 

C  0)  c  o>  c 

*  E  -r*  E  * 


00  >i  \ 

(Ti  (0  ■  <-* 

■H  I  H  H 
00 

-  -  (T>  ‘ 

>,  >, 
•H  *0  \  <0 
T3  ifi  13 
>.  C  \  C 
i4  OH  O 
£  r  hi 

I  t  B  ■ 


4J  4J  *->  4J 
flj  <0  <0  10 

E  E  E  E 

hi  hi  hi  u 

O  O  O  O 

144  44  U-4  44 


V  hi 

4J  flj  4J 

<0  -C  C 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


19 

333 


s  °  C  Time  Functions  (Listing  continued,  text  on  pages  16-17) 


strcpy (mname," February" ) ;  return  (0 ) ; 

return (0 ) ;  case  1 : 


>*  c  >*  c 

a  u  aw. 

0  3  0  3 

U  4J  U  4-» 

iJ  II  4-»  0) 

v)  u  co  k-i 


>  c 

CL  k- 
O  3 

U  4-1 
4J  0) 
CO  U 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


21 

335 


(Continued  on  top  of  page  20)  I  End  Listing 


-  \ 
w  Uu 

E-*  - 
ZD  w 
O  E-. 
•  D 
O 

^  CO  • 

-  CJ 

>  <• 

-  bJ  ^ 
w  CL  - 
E-  O 

D  fr-  CL 
O  X 
•  -  CO 
..  <j 
CO  II 


)  CC  bJ  w 

-  E-«  -  <  to  - 
•  co  — >  r> 

••  a  J- 

<  Cli 

\  ^N-  >  M 

—  CC  . 


-  3  - 
CO  -  O  m 

co  Q  <  < 
*-J  2  </>*-!■ 

CO  CO  -  o  . 
•  •  E-  -  z* 

-  “  <  w  O  • 
'  \  CJ  -  CJ  • 


0  w  Cl, 

E-  CO  E-  E- 
d  -  d  :=> 
-0^00 

?  -B  *  ' 

•o^g* 

co  z  a:  - 

:  CO  -  DD-. 
)  U  J  h  h  * 

:  u  »h  co 

:  3  <  -  cc  cc 

1  (A  b  4  •  E-. 

•  •  •  -  -  CO 

,\\\\\ 


—  a 

r  ^  ^  ^  z 

“  •  A  •  < 

II  ~  V  ^  A  ~  . 


><  — 

H-  t-  -  E-  .  E-.  - 

—  D  —  s  —t* 

-ot.O(,o  o  S 
’  "3  *3  •  E~  "HO 
5  o  o  X  X  • 

•CO  •  CO  •  CO  O  CO  O 

<  n  <  n  < .  <  -  j 
•>V>A>V>A«: 
u-cc-  cc-  a.  5 

-  N  s  \  \a  . 


<S  CO  CO 

F  Q 

CO  CO  4!  >J 
D  ZD  2  CO 
M  bJ  M 
Ou  rf  E-  Ci4 
F  >  2  J 
O  <  M 


E-*  CL  -  c/5 

<  f  co 

u  co  a*  e-*  cc 

<■*  •  f  <  cl 

H(J  x 

co  \  co  .co 

r  e- 

II  <  c/5 


<  M 

2  CJ 

2 

2 

+ 

CO 

D  E-  < 

< 

co  O 

O 

CO 

•J  CO  > 

CO  E-> 

D  M 

U 

CO 

co  z  < 

•-  F  CO 

•b  bJ 

\ 

\ 

•k  CC 

W  O 

< 

< 

a 

Ck4  U 

2 

> 

X 

•  • 

• 

CC 

CO 

N 
2 
ZD  - 
O  w 
•  E- 

D  ^  ^ 

a  o  -  - 

o  •  o  >  > 

CC  E-  —  N  x 

ou--- 
E-.  <  vr  w  w 
CJ  CO  in  E-.  E-  -  E- 
<  N  D  D  D 
U4  -  -  O  O  in  O 

*  -  •  •  cm  • 

II  -  \  <#> 


E-*  C14  co  *-b 

WDd- 

Z  H  J  >i 

-  Z5  <  - 

—  -  >  —  ~ 

"  •  "  ••  h  -  ^ 

\  -  C  D  N  - 

2  2  w  m  O  — •  >« 

O  -  -  •  -  s 

»H  CO  ^ 

C/5fr*F  -  —  -  - 

(/5  D  <  ^  CL  D  \  I 

COOzE-^Czn 

a  •  e-  <  co  . .  . 


a 

n  <  u 

•  w  ^ 

> 

<r  cl.  q 

►H  E-* 

</> 

X 

CL  CJ  • 

\  CC  E-  E^ 

•  •  4b 

2  0^*-' 

Cl-  CO 

co 

F  J5 

ODD 

o  - 

Dm  > 

•  2 

m 

M 

E-  O  O 

H.  bJ 

m  CL  < 

-  o 

CO 

" 

CO  CO 

CJ  •  • 

— • 

-  F  CO 

CJ 

— b  TE 

' 

E-  F 

< 

II  - 

II  ..  CO 

< 

“ 

CO  < 

Cl. 

— • 

_  • 

z 

II 

Z  2 

- 

co  E-* 

u 

CO 

CC 

O  D 

| 

F  U 

CJ 

CC 

o 

c_ 

CJ  »— i 

\  V 

” 

<  < 

< 

< 

q  co 

M  D 

>  bJ 

<  < 

CO  >  co 

••  ••  a 

ii  a  >< 

D  M  E- 

*-<  >  .. 

<  o 

£  W  H 

co  ..  > 

2  CL  II  <  < 

a  x  x  c/5 

HCOU  ••  • 
^  <  II 
w  CO  E-  CO 
Z  CO  F 


22 

336 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


CONSTANT'  $  (IDNEW  ID=:SAVID  CFAC  =  RVALUE  CRIGHT 

CONSTEXP  /'.NOT'  CFAC  .OUT('SC') 

CONSTANTS  SAVID:  TYPE  /'('  CEXP  *)' 

UNSTACK=: SAVID: VALUE  /'&'  IDNEW  .OUT('G'  *) 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


23 

337 


( Continued  on  top  of  page  22)  I  (End  Listing  I.  Listing  II  begins  on  next  page.) 


00  P  . 

•  00  P  i 

00  CN  <  0> 

>00  •  00  >  00 

■  >  x  •  \  a  \  o 

1  U-  Q<  U  O  •  E-«  U  X  a  O 


x 

•  ZD  I 

>  p  • 

(NX  Si  < 

•  oo  •  <y>  > 

•  \r  \a  x 

•  HJJfcUXQ-O 


*  00  •  O'  2 

•\r  \x 

J  JU.Q.O 


•  •  OV  — '  •  U  O'*  »— v  •  OV  •  CTv 

■r\r  •  <  \  2  «\*\ 

•  P  P  X  P  P  X  •  u  h  Ul  x  J  J  X  •  E-*  P  P  X 


•  b*  < 

•  D 

•  O 

a  < 

x  o  u  x 


X 

cl  in 
i  >  r-  r- 
E-  ^ 

:  O  r-  •  • 


®  c/3 

•  00  hH 

•  \  CJ  O 
•Wh®  0.X 


:  \ 3 
I  J(L  0.0 


1  VC  I  VC  O 

\r  \u 

F  J  J  o-u  : 


m  h  . 

VT  IT,  l 

««T  VT  2 

•  VC  ^  VT  O 

•sr  \  cj  r 

•  fr^PPXCJXPPX 


•  h\  u  j;  ii  < 

•  J  U.  r  S  N  J  CC 


(N  CN  ro 

(N 

cn  in 

vc  r- 

CO  *  00 

•  0C  * 

oo  • 

x  -  oo  • 

\  r  \  > 

_  *\r 

NO  \  . 

\  o  \ 

E-«  P  ->  X  X  O  •  fr-  P  P 

x  x  o  • 

E1  J  JX  • 

E-  P  P  X 

Q 

x 

J 

C/3 

r 

CD 

2 

< 

»-« 

O 

2 

X 

X  CD 

CJ 

D 

CL  00  CT> 

P  X 

S  r-H  O 

X  cn  ro 

*-H  tN 

>h  vo  vc 

*“*  N  >< 

r-  C'  h  n 

>«  r-  r- 

E-  oo 

E-  S 

E-  CN 

•  .-H 

P  vc  •  • 

•  m  q  r- 

•  .  .  CN 

( T\  •  \ 

H  \  • 

•  \M  \ 

.  . 

P  N  X  *2 

U  X  •  •  X 

•  Z  O  X 

•  •  OL  .  ^ 

ox  •  •  1 

2 

X 

O 

X 

O 

►-H 

r 

E- 

C/3 

t-i 

CD  Q 

CJ 

C/3 

C/3 

u  r  p 

< 

X 

»H  H 

co 

r  <  x 

in 

X 

X 

CN  (/) 

CN 

<  Z  *-H 

CN 

i-H  X 

CN  2  cn 

fs  2  vr  h  in  x 

CJ 

• 

w  CN  X 

^  •  CN  O  CM  \ 

• 

CN  D  CN  <  ••  CN  Q 

si  . 

• 

r  \u 

r  •  \  U  \  2  CJ 

> 

• 

\h\u  r  \ m 

T 

T  • 

• 

P  p  X  o  X 

PPX  •  E-*  O  X  X  — 

X 

O  • 

E-'UXOPPXcjX 

X 

S)  • 

X 

p  o  < 

si  H 

(N  00  U 

•  CN  I  CN  <  N  \  >(  | 

•  \  T  Ml  —  2  S  N 

•  HPPXUXXoXcLOXO 


r 

x 

x  I 

e 

U  X  X  O 


T 

X  X 

X 

CD  O 

in 

o 

VC 

E-  E-1 

•— i 

e* 

f-i  VC 

U 

VC  CJ 

oc  m 

•  < 

i— <  • 

♦  rH  <  ♦ 

•  H  \  H  CN 

•  X 

\  • 

T  \X  - 

•  \r  \r 

•  u 

X  • 

P  p  X  o  x  X  o 

•  H  P  P  X  P 

i  a>  vr 

»  -h  >  \  in  i 

\  X  2  ™ 

ipxaoxxoxo 


X 

p 

X 

p 

X 

D 

p 

<  X 

r 

P 

M 

>  r 

< 

X 

CO 

X 

X 

z 

r 

2 

E-* 

X  u 

•-o 

•  C  rH 

<  •• 

CN  p  Si 

•  m 

'T  •  • 

r  cj 

•  W  \  U  T 

\h  r  t 

•  \ 

\  •  • 

x  o  x 

•  UXUPPXUXX® 

•  E- 

C/3  X  •  • 

c/3 

E- 

1  C/3  ' 

2 

•  in  O  vc  \ 

•  \U\2  U 

•  E-  O  X  X  —  X 


.  m  +  x 

•\S  NW 

.  H  P  P  X  U  X  X 


'  T. 

si  x 

•  +  HU 

•r  \h 

•  J  J  tL  o  X  I 


•\E  \ 

.  E-  P  J  X 


24 

338 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


rH  Q  rH  rH  H  t  j  y 

•H  V£>  Z  rH  <  OD  H  {h  O'  .H  o  IS  rH 

•  ^  w  *-»  •  r-  u  5^«  r^  cj  cm  rH  cm 

•  ’  C*  J  C*  *  rrs  **  .  ON  *  rH  '  *  O  »—4  ^  •  ON  •  r-4  *  rH  >T 

•  •  \  r  \  •  m  ••  •  \  s;  \  r  •  <  \  *r  i\r  \  r  v  ^ 

J  X  Or  >  O  *h  JJfcO-DOQ-O  •  •  X  •  E-.-J*Jbr_3.JX  •  O  E-*  C/3  X  _3  J  X  »H  JJfc  J  Jfcai 


■  a  d 

.  z  o  Or  o  &*  o 


u 

z> 

IS  1-3 

r-  »h  *t 

ON  •—  rH  > 

\r  \a 

E-  J  U  br  to 


(S  w 

CJ 

rH 

co  2 

U 

rH  3 

< 

rH 

rH  £ 

w 

»H  iJ  H 

J 

rH  br 

CM 

Dr 

h  wn 

_) 

r*  <  rH  ** 

Dr 

r*  ih 

rH 

X 

1-  *H 

u 

•  ON  >  rH  II 

O 

•  ON  • 

rH  w 

u 

\ 

•  O  rH 

• 

•\a\x 

E- 

•  \  X 

CJ 

X 

br 

•  Z  N 

X 

•fr-Ob-J.JXOXO  >H  JJI 


ijxe>xjjxa=>o 


O  H  •  rH  \  • 

2  N  X  \  r>  •  w 

o^,wxjjfc-a>oa.ooa.o 


vc  E-  i 

ON  CJ  I 

vc  r-  <  oo 

ON  •  ON  •  ON 

\o  *\r  \r 

In  Or  o  •  E-  *-J  -)  In  J  _3  x 


»\o  \ 

•h  J  Jb 


•\  r  s  •  \  x  \  • ' 

•hu  J  Jbs  j  Jfc.>  *1 


•  \o  \ 

•  ^  J  J  u. 


IS 

r-  cm 

ONSTTERM 

TFAC 

*T 

o 

< 

in  vc 

CO  1" 

Or 

X 

M 

If) 

If) 

g 

00 

C/3 

z 

CM 

in 

m 

U  If) 

m 

If) 

in  in 

m  in 

CJ 

in 

o 

VC 

>*  VC 

VC 

On  M  IS  ><  ON  rH  in  on  X  CN 

•  IT  Q  VC  ®  •  ID  -  VC  IS  •  in  •  VC 

S*\H\r  • \ O  \ \ * \ x  \i 

•  e-«  o  ®  -h  j  Jhz  .e-jju-jj  xi 


E-«  co  r 

if)  m  * 

Z  CN) 

O  4S  rH 

CN  CJ  *H  \ 

®  13  X  — *  Z 


z 

u 

X 

X 

X 

<c 

Or 

t* 

cr 

CL 

CL 

E- 

X 

C/3 

U3 

U 

b) 

w 

b3  CM 

Z 

fr* 

H 

E- 

ON 

z 

*r 

2 

9-.  CO 

in  vc 

CO 

00 

o 

E* 

00 

E-  on 

E* 

CO 

o 

s 

C/3  »h 

CO 

CJ 

C/3 

^T 

C/3 

C/3 

oo  CJ  co 

2  in 

z 

CM 

*T 

5 

ON  2 

IS 

rH  2 

• 

co  • 

• 

D 

O  CM 

IS 

•  • 

*r 

• 

• 

• 

O  *r 

• 

+  ST  O 

m  i 

in  O 

• 

\  X  \ 

• 

►h  \  CM 

CJ  \ 

»H 

•  • 

\ 

X 

• 

• 

• 

U  \ 

• 

X  \u  +  • 

\  X 

\CJ 

• 

HjJb 

• 

Ob-® 

0X2 

— 

•  • 

h  W  X 

J  *J 

X  • 

• 

o:  • 

O  br 

• 

J  J  Ctr  O  X  -*  . 

t-  J  J  u.  o 

u 

b3 

b3 

u 

X 

CJ 

CL 

z 

< 

< 

< 

Or 

< 

z 

*-3  C3 

u 

□ 

Q 

X 

CL 

E* 

a  U  J 

X 

CJ 

t-3 

u 

br 

CM 

w 

< 

OX  b3 

IS 

CM  rH 

<  ON  CO 

UJ 

b3 

in  5 

E-* 

X 

CO  VO 

r- 

X 

K  5 

CJ 

t~>  <  M 

CO 

CO  CO 

2  CN  CO 

a 

IH 

CO  jy 

C/3 

CJ 

IH  co 

CO 

™  < 

[J 

>? 

2  ON  S>  br 

CJ 

rH 

CM 

E- 

br 

2  NT 

Z 

u 

CM 

in 

00  Z  ON 

Z  *H 

•  IS 

•  Q  CM  ••  CO  Q 

IS 

•  CO 

CO  •  • 

• 

• 

CO  •  Q  CO 

o 

x 

K)  CO  • 

•  co  — 

•  co  •  CO 

•  O  ^r 

•  X  »J 

•  H  \  CM  X  \  M 

M  X 

•  \ 

\  •  • 

®  CJ  •  • 

• 

X 

\  *H\CM 

u 

CJ 

H  \  * 

•  \  X 

•  \  X  \ 

•  IH  \ 

•  s  — 

CL  •Obr'SiJi-JbrOXOrlS 

•  E- 

C/3  br  •  • 

X  CM  o  •  • 

CL  • 

J  J  b-  •  o  br  ®  o 

X  o  ®  z  • 

•HflXJJX 

•  H  j  Jbr 

•  C23  br 

Dr.  Dobb’s  Journal,  Number  58,  August  1981 


25 

339 


( Continued  on  top  of  page  24)  I  (Continued  on  next 


CO 


in  — i  ®  i 
H  i 


l  ®  W  CM  ■— l  { 
O'  H  O'  | 
1  <—i  O  — •  •  i 

\zn  • ; 

•  E-*  O  Cu  •  ( 


CO  VT 

•  O'  in  o' 

)  — i  in  <  vc  — «  r- 

O'  o'  .  a:  on  o' 

•  r*  , ,  *  ^  '  11  sc  i-*  •  — < 

•  *■«  >  w  •  \  •  T  0u  t  x  a  \  •  \ 

•  J  cl  _j  r  •fc.auoJjxoxJ-JxaojJu,  •  t-  in 


•  T  \ 

'J  JCu  J 


IS  O' 

i  oo  r* 

I  ®  .— I  rH 


in  \  x 
o  cju  a  o 


i  x  cl  =>  o 


oo  o 

1  \  H  \  CO 

•S’  \  E-  W 

•Juck.aooL'»x 


•  \  :h  II  \  • 

.E-wxr3«sHa=50w 


I  H  W  O' 

>  E-*  oo 

I  .0-1 

.  •  z  \ 

•  •  u  E-  W  X 


\  •  in 

l  b-  CU  D  O  O 


E-  w 

x  a  s  o  a  o 


co 

in 

O'  < 
vr  a 

rH  X  — * 

\  a  t 


•  \  r  \a  r  .\r  \j  j 
.Hu-JCnoxuax  .h  j  JhQ,oao 


•  \  \ 

•  H  W  bu 


CO  l 

3  ( 

in  »-J 

"  < 

— «  >  u 

\  :*  a  a  cn 

Jtaouxaoao 


)  CO  l 

>  O  ( 

I  CM  1C  *J  * 

m  m  < 

•—IV  —l  > 

•  \  T  \  >•  a:  A 

•  hd  jfcaooxbo 


co  ( 

D  I 

r~  j 

m  < 

— i  ^ 

;  \  >  x  v 

Idb-aouxo-o 


r 

X  Cl. 

CO  O'  H 

E-  n  Q 

o  U  oo  -i  Z 

<  co  < 

•  Cl.  »— 4  •  • 

•  U  V.  •  SF 

:  .ot«-  •  »J 


S3  —I 

S3  U  — i  — «  O' 

<  m 

— •  \  Cl.  •  •  -H 

\  CL  U  •  •  \ 

d&.a>oux  . 


cm  r-  m 

— •  •  O'  —  — i 

\a:  *\o  \ 

UbuQuO  •  H  J  J  Cl 


H  co  <  mum  < 

•II— i  ^  •  — i  “•  — i  U  • 

•  r  \  ><  x  ii  *\r  x  n  in  • 

•  ddfc-aouxbo  iHdoiLboox  boao  * 


CO 

D 

CM  TT  »J 

m  ii  m  < 

rH  V  —I  >  U 

\  F  \  >•  x  v  w 
hjjclclOuxclocli 


< 

in 

D 

in 

CO 

co 

X 

CO 

CM 

S3 

r 

o 

m 

u 

VC 

CM 

CM 

(N 

x 

CM 

X 

CM 

u 

»-H 

—1 

— 1 

O 

— • 

cc  m 

—i 

Z5 

vn  — i 

< 

• 

. 

r-  x  cm 

r-  co  cm 

r-  in 

CM 

r-  Cl, 

, 

, 

, 

•  • 

• 

O'  •  — «  Cl, 

• 

O'  • 

— i  • 

O'  • 

CL  > 

, 

• 

o 

in 

•  • 

\w\ 

• 

\  r  \cn 

• 

\  T 

\in 

\  £ 

aoao 

• 

• 

X  CL 

0 

p 

0 

p 

u 

0 

• 

H  O  J  b.  b  o 

___ 

E-  J 

J  b  b  o  • 

E-«  J 

i  5 

l  00  CO 

r-  cm  z 

•  O'  o  j  — •  Q 

•  \  r  \  m  o 

•  t*  J  JIlUXU. 


Dt.  Dobb’s  Journal,  Number  58,  August  1981 


CO  *•  I 

is  u  i 

<N  E-*  CO  < 

<  K 

•  E-  CM 

•  to  \ 

X  •  O  E-*  to  X 


w 
CM  X 
SJ  < 

cm  j  cm 

CJ  IS 
•*  •  W  CM 

_  w  f  •  o  v 
OOD-OX  •  U  E-  to 


to 

to 

OS 

X 

w 

x 

w 

u 

E-« 

CD 

< 

E-h 

c? 

F 

to 

CO 

z 

D 

• 

u 

t-H 

Z 

< 

OS 

• 

w 

E- 

X 

s 

to 

o 

to 

w 

w 

f-H 

3 

E-* 

O  u  u 

00 

Q 

p 

a.  «  o  a.  z 

w 

Q 

X 

w  z  s.  x  i-h 

X 

-H  ®  K) 

h 

n  O  E-*  E-*  Z 

< 

S'  IS 

j 

3 

E-  CJ 

^  Os  CC 

O 

O 

x  a  x  x  x 

O  to 

CJ  </>  </> 

u 

— 

w  x  w  w  w  x 

a  w 

X 

o 

to 

cj 

X 

w 

w 

> 

CD 

F 

X 

5 

w 

z 

E-* 

to 

cj 

o 

X 

< 

z 

F  W 

X 

M 

3  CJ 

o  < 

E-1 

r>  < 

Z  X 

M 

X 

h-4  U 

X 

W  Cfl 

D 

^  CO  CO  CE  CO  CD  Z  _  _  .  _ _ _ 

SIIIS55  ’.VAv’.'+g*  5-,g-  2  £S5S££££S 
<  5  S  “  £  si  5*”**“  V.. s  *9. 

^Hf!?®“^fl30SlM(Nno'cDUDUUJrG.OWh3>XQrr;UH(NJl/jHJU^Z 

woe  it  iiE-^cocnuuuuuuuuuuucjouuucjcjuDQwwc^wxjjrzz 

f  ><  f  f  to 

•*XWWt-iWWWC*3WWWWWWWWWWWWWWWWWWWWWWWWWWWWWW 

|H.*XJOeffJCDCOCOCOCDCDCOflOfflfl3CDCDCOfllCQCO®CDCDCOflDCDOQflDCDCOCDOQCDCOCOCOCD 


O  CO  U  X 

O  w  w  w 

U  CO 

-----  -  z-  co-r- 

•\AV  |  +1-1*  <11  Z)  ■ 

......  to  -  E-  -  Z  ■ 


w  <  > 

*J  >«  z  o  x 

x  <  a  o  j  o 

OS  w  x  O  h  T 
w  6u  r  E-  to  w 
W  W  Q  W  O  Z  F 

w  Z>  Z  F  3  »H  l 

=>  CO  <  X  X  CJ  i 

CO  FHOhi 

E-<  W  <  to  Q  w  i 

E-  3  =>  os  z  o 

D  o<  DS  U  h  I  m  i 

a-  E-  x  O  E-*  F  I 

z  n  os  w  u  >«  I 

h  O  OS  &  O  Z  (/}  I 

.%  •*  O  •%  co  •«. 

in  in  is  E-*  is  i 

r*  r**  O  is  u  w  s»  i 

CM  CM  <  IS  Z  Z  is  : 

S  S  J  K  K  H  n  I 

K  8  II  h  j  j  s: 


•  F 

w  •  to  x  {j 
IF  •KO.Ofl.oi 


cj  x 

(Moon  <u  h  ^  vo  r-  oo  m  X  cs  x 

*r  rn  *r  X  id  X  *r  E-<  *r  ^  x  F  in  h  f: 

Hm  o  vo  cj  ld  r-  x  >— 1  ld  oow  --1  .-h  CJ  qs  •— 1  os  rH  os 

<^rM^ZTT<  ^  ^  X  ^^z  w-M-Oin  x 

...  •  >  f-H  OS  •  f-i  *  rHW  CJ  •  -1  — '  -H  W  ^  *H  J)  r-l  5  •  •  •  H  -I  •  •  H  \  E- 

•  •  •  »x\cj  •  \  f  \  u  to  «\f  \  cj  f  *\r  o  •  •  •  cj  \  «r  \  e-  cj 

>Oto  •  •  •  x  •uwox  •e-wjwoxclo  •e-wwwoxjjx  •e^wwwuxcloo  •  •  os  •  o  w  •  j  w  x  x  x  o  e>  * 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


27 

341 


28 

342 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


-ao 
-j  2  o  x 
a  ii  ii  x 


-  _  ~  a 

d  jx  «  +<  <  o  o  S°“ 

2  S  a  N  •— I  <  <J  <2  OuSlII  OX 

S  —  S  <  CJ  <  m  M  ^  w  ®  ••  W  m 

X  IS  W  CD  BHnHmw|ia(NWlSU<Ol 
uss  2  ^  +lllllDJ^hUZ  +  U<UJ 
X  is>  IS  n  W  «  <BI<WHB||JV  I  I  I 
•*®  +  WUO<J<III<OIU  #‘H  U  o<  t 
X  +  II  JUUC  (khhhu  j-oa  UO-CM 
X  II  <  HH  DflCX  H 

•J  <  x  2  2x0 

u  t  h  5  o  U  h  u  D 

w  w 

<  < 

cj  u 


<  w  cj  cj  <  o 
->  zoy  <  a 

ii  ii  ii  n  — '  ,  w,  — 

xxcj<x«c<wqoxxcj 
3 Jucuurf oiu j'y 
w  m  own 


O  X  x  <  2 
a  +  o  x  x  n 
w  +  w  H  II 


s 

♦  *-H 
+  II 

z  r 

<  X  W  X 

<  HH 


♦  + 

II  II 

X 

W  O 

X  2 

x  x 


U  h  ^ 

CJ  O  2 
2  W 

W  X  W 
E-  5-*  »  E-*  O 
X  M  »-)  O 

o  x  w  x  s 
<  5  2  5  cj 
u*  a 

S  £ 


X 

X  X 
2 
E-  3 
x  3 
x 

x  s 

o  w  C*i 

S  <  o 

•*  X  E-1 

Du  •*  X  OX 
H  X  X  X  U  H 

Q  X  W  O 

2  X  X  2 

X  X  H  x  x 

w 
< 
cj 


E- 

2  V 

t-H  CO 

X  -H  CD 

as  ii 

•*  «  K  <  < 

X  +  x  .<  *c 

X  II  M 

XX  2 

w  m  5  O 

c n 
< 
u 


CJ 

X 

<c 

w 

< 

U 

w 

X 

X 

w 

X 

2 

X 

> 

•J 

Eh 

►H 

X 

X 

X 

X 

tJ 

w 

o 

u 

X 

X 

2 

o 

M 

<  J 

X 

CJ 

M 

o 

£ 

X 

•J  X 

o  r 

X  x 

> 

> 

H  X 

>« 

u 

X 

O  |H 

X 

E-« 

X  X 

U  2 

X 

2 

<  X 

CJ 

r  2 

X 

9 

X  _] 

X 

X 

(_  x 

< 

Eh 

X 

X 

>  X 

2 

X 

W  X 

Eh 

o  o 

2 

E- 

r  t- 

X 

X 

£ 

1 

w 

2  CJ 

l-H 

o 

o  2 

X  X 

X 

D 

x  5 

< 

X 

o 

2  X 

X 

*c 

U 

2  2 

X 

X  Q  W 

XX  2  X 

0  3  t-i  X 

X  U  m  fr- 

r  >*  w 

x  x  m  x  r 

h  jo  o  < 

3  co  x  a  r  x 

x  <  2  w  < 

2  E-*  X  <  X  F  X 

0-<  M  X  X 

X  2  D  U  D  (J  J  X 

mX0222m<X 
O  m  m  kh  J  u  E-. 
O  E-  X  0  0  2 
£-«X<XOXCDX3 
2  W  CJ  W  X  F  O 

MC0O<2X><XU 
r  x  co  o  x  w  o 
1  X  X  •«.  M  •» 


I2^>W 
«  <S  X  2 

:  x  sj  o  x 

'2srr 

)  *-*  r-i  X  »-l 

<  x  s  t  a 


><  X  X  | 

asxn 
O  IS  X 

r  ®  r  x  i 

x  m  3  <  < 

r  <s  2  t  i 


x 

O  X  c 

E-«  hi  ► 

<  2  ; 

X  <  « 

2  r  : 

x 

o  x  c 

X  c 

X  x  c 

°  3T  J 

x  3  : 

r  2  ; 

>  x 
wool 

2  <  4 

1  m  E-  ► 

I  X  W  C 

d  : 

x  o  >*  C 

HOC®  [ 

2  O  CD  C 


0X2HXQX*HJx:HXNJOXXE-'2rE-O 

oxjjrrrrrs'2r22Xxxxo:wwE- 

i  *— •  •— *  *— »  i— i  »— «  »— »  >— i  »— * »— i  *— i  »— 1 1— i  »— i  »—•  •— » •— i  *— i  *— *  •— «  *— •  •— *  •— « 

E-E-6-E-E-E-E-^E-E-iE-E-t-E-E-E-iE-E-E-E-e-E-i 

2222222222222222222222 


!  •*  X  *  — •  E-*  »-i  X 
1  • — ■  O  (j  ~  I  ffi  J 

:®x<«uo\< 
;oox^«hhu 
i  IS  X  2  —  X  • 

»  •*  M  ■»  ^  <  X  ! 
»  W  E-*  <  IS  X  U  •  2  i 
i  n  N  T  h  O  w  5 

IHH2BU  XI 

-f  •  •  *  E^  ! 
'HhO  II  mi 

:22X_3WWWXi 

*MMX22rr5' 


x 

)  < 

•  CJ 

:  o  m  * 

1  cj  x  ( 

]  is  u 

‘IS  2  X 

<  ®  h- 1  IS  O  I 

Is  O  U  J  I 

s  S  w  w  X 
i  +  ®  x  h  w  . 

>ii  o  x  o  x  . 

>  u  cj  w  n  o  w 

>  x  o  o  cj  x  < 

>  M  J  u  CJ  u  u 


r  x 

X  X 

ii  o  — 

I  X  X  2  M 

I  U  X  H  o  CJ 

w  o  j  ^ 

X  2  •«.  »-« 

X  XXX 
W  II 
X  CJ 
X  CJ 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


29 

343 


SC 

£ 

so 

§. 

c 

o 

X 

HI 


•a 

0> 

3 

C 

e 

o 

u 


I 

K 

Cb  t-< 
M  II 

§£ 

X  » 


H  CJ 
X  II 

X  II 


•*M  < 
x  a  < 
x  II 
<  X 
X  <  M 

w 

< 

cj 


x 

2 

< 

X 

u 

cj  H 
x 

—  z  x 

HO'* 
U  X 
~X  X 
M  CO 

as  o  x 

HOW 
CJ  X  < 
WOOD 
x 
•J 
x 


Q 

X 

CJ 

z 

£ 

cj 

H 

S  U  [l 

<s  x  I 

+  UUE- 
II  X  II  J 
_J  J  o 
bUb.< 
X  X 

<  CO 

CJ  Q 


X 

O 

as 

os 

X 

u 
H  Z 

X  X 
WWW 
-HO 
»H  O 
wax 
r  5  o 


Q 

co 

X 

cj 

< 

H 

W 

a 

z 

< 


H 

< 

a 

CO 

z 

CO 

CJ 

a 

co 

x 


Cb 

o 

H 

o 

u 


o 

o 


z 

D 

O 

H 

W 

H 

Z 


H 

X 

os 

>« 

X 

X 

X 

X  z 

X 

O  »H 

X 

Z  Q 

X 

X  X 

o 

H 

H  J 

Z  X 

Z  M 

M 

X  x 

T 

OS 

OS  o 

or  os 

X  os 

x  x 

X  X 

CJ  > 

T 

X 

X  X 

X  z 

Z  CJ 

X 

X 

H 

H  X 

X 

X  X 

•*  *-* 

»-< 

H  X 

<  •—* 
<  <s 


Z 

Q  O-i 
Z  X  •*  CJ 

CO  h  p  || 

a  x  n 

Z  M 
co  co  a 
w  II 
<  < 
o  < 


z  Ha 

CO  Q.  •% 

X  H  + 

H  II  + 

•-  <  <  IS 

<  <  <  -H 

<  H  H 


H  v  + 
W  CD  => 
*-•  CD  <  3 
II  M  <  t-i 
X  II 
X  <  X 


X  < 
X  < 

►-<  h-f 

II 

X  H 
X  w 


<  as  < 
c  5 
»-•  —  x 
II  Z  *-« 

CD  —•  ^  CN 

X®  X  CN 
tb  H  U  X  H 

M  II  ^  X  X  O 

Q  <  a  W  H  H 

—  "  ~  “  O  Cb 


a 

co 

x 


a 

co 

x 

i 

z 


CO 

H 

< 

a 

co 

z 

CO 

cj 

o 

H 


JH 

X 

O  is 
a  <s 


o  —  u 

x  x  o 

—  CD  || 


X 

X 

II 


W  X 

ox. 

II  —  + 


CO 

s 


+  J  z 

—  ..  7  +  H  3 

<S5CO<<CJOXXX 


X 

H 

z 

I  CO 

cj  x 


■**•"*•  w  w  uj  tu  »*-  •*  y  a;  h  -f  +  X 
<<CJXXx2>  II  H  II  +  +  o  o  o 
55:  ii  ~«t«c<E-nE- 

~  '-'<<<<  O  •'  O 

X  <  w  »-«  m  CJ  X  CJ 


CO 

X 

o 

z 

X 

Q 

z 

o 

cj 

CO 

X 

o 

H 

X 

2s 

H 

<  CO 

<  X 

M 

•*< 

<S  (N 
H  H  IN 
X 


•  <  »— • 

X  H  H  CJ  X 

CJ  H  X 

CJ 

X 

D  X 

o 

u 

z  < 

hJ 

X 

X  CJ 

§ 


z 

U  CO  _ 

X  II 
<  <  X 
CJ  <  *-* 


00 

e 


X 

3 


£ 

O 


c 

o 


H 

CJ 

< 

a 

< 

X 

cj 

-2 

< 

H 

cj 

X 

X 


o 

H 

z 


o 

H 

z 


X 

£ 

X 


^  u 

X 

•D  < 

X  CJ 

a 

X 

CJ 

u 

CO  II 

-• 

X 

u 

z 

as  H 

w 

V 

'-*■ 

f— 1 

Ohm 

M  X 

X 

H  X 

o 

X 

X 

o 

X 

OS  CJ  X  »J 

OS  CL 

+ 

X  S  x 

X  + 

H 

R 

H 

os  ii  n  x 

II  ^  + 

♦ 

O  <s  II 

H 

M 

M 

II 

M 

X  II  •« 

CJ  O  x 

X  X 

•*  ®  X  < 

<  a  x 

OS 

X 

<s 

M  < 

as 

X  •**  M  <  X 

CJ  X  Q* 

X 

5 

0+ J<<UX J 

CJ 

X  <  5 

M  X  X  <  M 

8 

X  H  m 

8 

II 

II 

Q  X  II 

z 

X  X 

z 

z 

X 

<  X 

Z  <  X 

X 

x  x  5 

o 

X 

X 

<  !-• 

X  X  <  *-< 

X 

X 

h  r 

<  X 

z  o 

a  x 

ox  z  £  2  x 

qszz5.>«£clcj 
a  h  u  wx 
x  *J  M  x  »-  co  x 


o 

H 

X 

a 

< 

x 

5 

CJ 

o 

z 

< 

—  X 
J  N 
X  II 


--IIX 
W  CD  <  X 


8 


II  X  H 
<  X  hi 


-J  X  CJ 
z  2  CJ 
II  II 
X  X  CJ  < 
H  J  CJ  < 

»-l  h-l 

a  i 
3  5 


< 

u 


OS 

X 

H 

CJ 

< 

OS 

< 

< 

X 

z 

CJ 

CJ 

*-« 

-1 

X 

< 

OS  1-* 

X 

<  CJ 

X 

X  X 

as  x 

X 

X  co 

as 

OS  X 

< 

X 

o  =>  a 

X 

o 

£  < 

CJ 

CJ  X 

Q 

x  z  OS 

X 

z 

Z  *H 

•J 

X 

O  OS  H 

w 

X  X 

X  - 

Q 

<s 

Q  O 

X 

z 

<s 

<  o  o 

X  u 

< 

<s 

x  z 

O  W 

<s 

os  <  X 

X 

Si  J 

<s 

-  •*> 

D  O 

CJ  X  z 

■f  + 

<  X  < 

z 

II  X  II 

■f  II 

I-J  U  x 

X  Q 

—  c«  II 

Z  £ 

Ik 

«S  z 

CM 

CJ  <  CJ  <  J  X 

X  X  X  X  CJ  X  X 

CJ  <  CJ  <  M  M 

M  D  D  J 

II  o  - 

o 

II  II  II 

D  X  X  W 

II  •*. 

H 

X  <  <  <  X 

z  o  o  x 

CJ  CO  x 

o 

X  <  <  <  <-• 

X  CJ  CJ  5  CJ  X  £ 

CJ 

z 

z 

X  x 

o 

X 

X  M 

a 

x 

H 

X 

< 


X 

N 

X 

X 

H 

a 

z 

o 

>« 

X 

X 

g 

o 

£ 


X 

u 

< 

X 

X 

X 

H 

M 

X 

5 

>4 

z 

< 

X 

X 


H 

< 


X 


8 


:  x  z 

i  J  x 


X  X  X  X 
*-•  X  X  3 

a  x  x  x 
z  o  o  o 

X  CJ  cj  cj 


30 

344 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


;  x  &  a  b  u  ii  c 

>  s:  o  t:  w  r  ^ : 

i  a  a  c 

*  CD  •-  CD  CD  U 
l  D  CL  D  W  D 

:  V)  x  w  x  co  &  : 
o  o  ocl 
i  o  w  o  w  o  *-i  c 

i  C/3  C/3  C 

!  <  <  * 

cj  u  c 


t"  c  ff  <  h  x  u<j  coe-  rua: 

<  1-4  E-  H  E-  I  3E  2  *  rn  CO  O 

CiJUllCOQllt-'OJZ  (J  CN  ►-  JD  <COI  XZ)  [l, 

aj-UF^ZUN  f)  ri  T.  0  2  <  _J  I  <  ;r 

u  s  d  ®  h  -  n  IT  ru  x 

CD  u  •»  CD  U  •*  H  CD  <  u:  X  Cl.  CO  h  U  ^  rHCMcO^Q  h  N  •*  7  T  J  O  E-  m  H 

y3~g  =  “-  a:  =  crus'MS^-  s-  o  =>  uoje-z  &,  u.  r  £  x  z  o  ®  t.  c*  w 

XlDffXfflBX  I  M  U1  Q  U)  J  MOO  —— MJU  T  <  <s  U 

oo-  o  a-  o  o  &•  ■-)  z  o  3  <n  a  s  •*  m  m  —  m  •*  uumozu  •»  smmffiu) 

uo  —  uumkioom  b)  uocrSuo  e:  ce  x  n  w  u  gi  ii  s  •  h  ^  h  +  d  d  =  o  « 

w)  CO  W  U,  OX®  II  HOC)XmOO«CO)  hOJC  I  ididuiOS^ 

<  <  <  W  2  tN  <  (D  <  Q.  <NiJfcji<oWfft-'3<NMOOOI  O' 

u  o  u  o  w  u  <ffiQ.HU  uuMoariwc  o  o  0  o  y  o 

£8  £8  £8  IS8 


»-H  <N  ffl  •  Q 

U  U  J  E-  2 

w  w  *-•  iJ  U 
H  H  ^  H  •* 

CO  x  *  II  u 


r  U  X 

^  <n  •*  z  ar  -i  o 

bbl  S.XZ  O 

TE  <  «S>  J 

UUHffil  u 

(/>  CD  II  X  -  E-  E- 


E-  h  E-. 

K:  Cl.  Cl  CO 
(S  u 

®  CD  CD  CO  CO 
+  X  X  X  O  « 


X 

O 

X 

o 

X 

X 

E- 

Q 

< 

w 

X 

o 

E- 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


31 

345 


(Continued  on  top  of  page  30)  (Continued  on  next 


X  fcn 

u  x 

^  a 

Cd  ►-< 

<  h  O  b.  2l 

<  •»  a  •*»-. 

II  X  H  p  II 

3  X  3  X  <  oo 
H  H  < 
hUhuh 

x  x  r> 

<  <  o 

o  cj  -J 


<  Q 

rsg 

wu 
e-cof- 
in  x  cl 

-f  H  •*  H 

+  ii  >  n 

<  3  x  < 

<  ^  < 

M  *->  Cd  *-• 

x 

< 

u 


X  ®  O  *J  ^  irj 

u  x  u  z  < 

x  i  u  <  CD 

§z  u  »-<  Cd  5  3 

N  V  -  ^  u  cc  x 

m  n  »-»n  a  w  h 

t  _  <  WMH-mWDk 

+  ot*  3<<[drJ<Hno** 

<  fr-  ->  X  X  Q  3  O  X 

<  O  3  O  Id  J  Z  l-«  X  3 

HU<  UH  Ed  fa3  •  c>  c/3 

u.  q  a 

b3  Z  Z 

D  u  U 


_  J"4  CO  *4-  •  CdC3 

®*“l  X  ^  +  £L  +  J  •* 

I  ’ll  £  ri  *c  2  <  ~  *  2  *  s 

2  gg 

^  J  -  3  O  U  u 


)  ®  5 

5  53 
<S  53 
5  5  5  5  5 

55555-------. 

®  ®  ®  +  }5II1UDut‘Ui 

M  n  ii  u  H  ii  n  li  *n  "ii  "ii  "ii  Ii 

xaa,NN<iiiuDUb.ni 

N>«NMt-tXXXXXXXX 


M  *->  X  .J  T 

ii  ii  ii  Ii  "ii 

*-•  1-3  X  J  T 


t*  Z  J 

Z  X  CL  Z 

i  «C  CD  *H 

)  u  M  X  Cd 

-  II  3  t-  CL 

•  <  X  M  O  X 

:  < 

:«<.I[!mU5Xwx 

D  O 

:uj  z  z 

:  m  td  u 


<  5  >4  CD 

<  -»  >«  X 

►-»  H  H  H  < 

-  \  *  I  5  4! 

V  -C  S3  <  X  X  II 

®  <  -h  <  >«  X  +  ~ 

5  H  H  H  M  X  <  Q  [d 

M  . I  H  <  Z  +  J 


a  x 

u  u 

Z  h 

*-•  Id 

Id 

>  •*> 

.  E  * 

I  X 

*  Id  3 

•%  M  X 


<  H  < 

<  <  «  < 
M  <  CD  M 


®  C  "  >*  CD  X  «C  II  II  —  +  M  I  •. 

®  H®  ®u<<>*iiiX<<t<(nQi  cjai 

I  <  V Si  JL?m 

X  bu  <  <  Q  CD  Q  X  Z  ZbQQ3 

UCD^^'^ZClU2;-5  °  Cd  M  Z  Z  X 

CO  D  II  X  QW»D 

JZCfciJ  Z  X  O  Z 

Cd  Cd  <  ^  Cd  Cd  D  z  Cd 


II 

x 

O  II 

x 

<  tla 

Z  <  Id 

a 

<  M 

cd 

Id  <  »— i 

Cd 

>< 

5 

X 

X 

u  o 

1 

u  F 

M  Z 

u 

Cd 

O  N 

v 

—  z  r 

fl  f-A 

M  O  •* 

M  X  < 

X  H 

o  g 

■f  X  3  < 

X  Cd 

— '  [d  5? 

+  H  X 

X  O 

M  X 

HUOId 

J  o 

o:  o  u  ou  u  h 

Cd  td 

M  CJ  x  < 
ouuu 


32 

346 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


CJMTMS  H  CN  n  Si 

. . . . CO 

ZOd.OffWhD>2X><N®H(Srr^®5ISHSKBl  —  *  I  +  A  II  V  B 


mmmmmmmmmmmmmmmmmm  +  +  -f-f-f+-~  -  -  -  -  -  -  + 

II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  II  ||  II  II  ||  ||  || 

zoaoa:(/5f-D>jx><NSHNr1(jia>8HNn[Dxwro.oD>JO 

XXXXXXXXXXXXXXXXXXCJUUUUCJUUOUUUUCJW 


\  .  - 

II  II  II  II 

t-  W  Q  O 

uuuu 


s  m  h  8  ^  h  ^  O  s  s  S  is  h  g 

51  s  s  H  H  O  U  Cb  S  S3  Si  S  Si  Si 

SSSSS**^^  S3  ss  sss 

SSSSS<^>U-<NSSSSSSSSSSS 
s  s  s  s  s  r-  <  Cusssssssssss 
+  +  +  +  +SHW  B88  +  8+  +  S  +  +  + 

ii  ii  ii  ii  ii  +  ii  cn  25  +  +  +  ii  +  ii  ii  +  ii  ii  ii 

s  m  ,-H  s  vr  11  x  o  W  II  II  II  U  II  ^  ID  II  D  Z  r 

SSSHHZfflJO.JHffO.OC-JZDJW 

HHHHHrHUOtOiO-HaHHaHHH 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


33 

347 


(Continued  on  top  of  page  32)  I  (Continued  on  next  page) 


3 

2 

X 

e* 


o 

2 

< 

U 

£ 


s 

oo 

CO 

a 

c 

o 

X 

a> 


■8 

3 

#C 

%-* 

S 

o 

o 


s  s  s 
K  S  S 

s  s  s 

S  S  ro 

s  s  s 
+  +  + 
II  II  II 
CO  £  Q 

rrr 


r 

< 

2  cl 
o  < 

H  0u  Q 
X  2 
2-10 
W  <  U 
£  u  co 
HOW 
D  U 

x 

I-*  Du  »-» 

<  o 

b 

Q-  a  r 

O  CO  M 
E-*  CO 

h  5  h 

CL  2  X 

<  -OS  -1 

t-HHF 

X  S  b 

A**® 

Q  S3  co  co 

r®Hf 

+  M 

II  II  CO  II 

f-  u  r  b. 

IThT 


(S3 

(S3 


+  ^ 


O  II 
II  ^ 
^  b 

b  f 


II 

X  »-• 

r  r 


CJ  ST 


CO 

a 

2 

CO 

2 

a 

co 

E- 

< 

a 

f 

X  CO 

CJ  F 

a 

<  2 
CO  Hh 
CO 

CL 

-J  < 

CO  X 

>  o 

CO 

-3 

•-  CO 

j  a: 
F  *-< 
b 

CQ  ... 

3  J 
CO  F 

*“•  M 

£  + 

x 

m  f 

x  »- 

co  II 

Q  co 

2  CO 

CO  M 


X 

< 

X 

U  CL 
< 
2  X 
CL  O 
U 


fc  ££ 


(S3 

(S3  co 

+  u 

ii  h-i 
CO  X 
m  5 


<  F 
a  — 

—  CD  Q 

x  co  o 

X  M  II 

^  ii 
co  cj  u 

?TV 

CJ  Q  CO 
U  Q  CO 


u 

o 

x 

5 

CO 

(J 

M 

X 

I- 

CO  X 

o  < 
o  r « 

2  co  ► 
CJ  CO  x 

2  •*  »H 
HSU 

*  U  2 

y  !!  * 

<  CJ  co 


00  w  II  F  CJ 
w  ^  ii  •*  ¥ 


CO  co  b 

b  CO  H 


+ 

CD  r» 

co  r» 

M 

II  o 

<  E-* 

<  O  b 

H(J  H 

a 

2 

CO 


Q 

< 

O 

X 

—  b 
CD  X  O 
X  F  S3  l" 

*“•  h  q  (s 
o  —  II  2  M 

u  m  h  u  n  o 

<->  r  <  •'  <  h 

+  +  <  II  h  CO  h  rn  - 

X  +  b  <  II 

X  CD  •“  <  CO  b 

H  CQ  U  H  u  h  CO 

x 

•J 

CO 


X 

CO 

X 

X 

< 

F 

CO 

CO 

X 

b 


u 

CO 


Qffi  x 

2  X  b  X 


8 

u 

b 

X 

S 

o 

>< 

g 

£ 

F 

g 

b 

X 

CJ 

CO 

X 

CJ 

o' 


8* 
X  F 


a  ..  „ 

2  CO  co  X 


£ 


CO  CO  co 


X 

.  r*  x 
X  ii  co 
a  <  o  a 

2  2  <  5  2 

O  CO  M  J  u 


£ 

b 

O 

h  2 

X  co 
O  CO 

-  f-  X 
M  O 


b 

£ 


Q 

to 

X 

X 


X 

o 

h 

CO 


X 

< 

F 

CO 

X 

h 

X 


x 


u 

s 

CO 

u 

< 

X 

o 

a 

a 

F 


F  <  X  X  E-  b 


•  5  £  2  X  ! 


<  b 


£ 

s* 

II 

Sfc 


£  O 
M  F 
II 

£  X 
£  b  3 
hh  W 
Q  Q 
Z  2 
CO  x 


00 

C 


CO 

3 


£ 

o 


c 

5 

O 


Q 

< 

co 

X 

< 


X 

o 

b 


CO 

X 

< 

X 

CO 


CO 

u 

< 

X 

X 

CO 

E» 


< 


>« 

g 


X 

CO 

u 

X 

o 

b 


(S3 


CO 

N 

M 

U 

< 

M 


s  H-4 
(S  CM  £ 

S  S  X 

+  (Si  x  o 
II  +  3  X 
U  H  X  O 
2X02 
h  F  CJ  CO 


X  X 

w  2 

■ig 

X 
X  < 
=3  F 
X  •*. 


2 

£  Si 

!!  v 

+ 

n  n 

+ 

X 

J  <  X 

X 

b  3 

X  <  X 

X 

X 

M  co 

II 

X 

O  Q 

<  b 

u 

2  2 

<  M 

X 

X  X 

X 

3 

S 

o 

£ 

X 

M 

X 

E- 


co 


_] 

*(f 


X 

Z 

Q 

X 

< 

CJ 

X 

w 

D 

D 

Z 

«c 


X 

u 

X 

3 

X 


£ 

X 
II 

u 

X 

II 

CO  <  < 
J  <  < 


s 

X 

b  S3 

CJ 
CJ  II 
CJ 


X 

£ 


Si 

s 

IS 

+ 


CJ  2 


cj  : 


N 

^11  II  + 
X<UbF£<£  £  b  CO 
Qco<Uhq,x<Xu&ihJ 
<11  Qwll  X  Q  m  x 

CO<b  2x<b  J  2X3 

X<m  U  Z  <  H  X  CO^x 

Q  D 
2  2 
CO  co 


2  S3 

£  CJ  CJ 


II 

V 


V 

J5 


S  53  S 

s  s  s 


x  x  < 

X  co  < 
■■  II  II 


5 

X 

b  CJ 
CJ 
CJ  II 
CJ  — 


CO 

3 


Q  m  +  j 

. .  <  w  +  M  X 

SSSX<O<<C0XXXO 


II  . 
£  3  X  X 

x  x  x  5 


5 

o 


5  Q 
2  2 
CO  CO 


u 

2 

II 

II 


s 

s 

s 

s 

s 

+  + 
+  II 
2  £ 


X  E-* 

u  m  o  m 

II  X  II  X 
II  II 


±  v 

X  X  <  b 
2  j  <  *-• 

II  M 

o  x 

O  5 


<  M  »_» 


0<*JXb0<0< 

"  ~"svm 

2  CD  <  OD  «£ 
K  CO  <  CD  «t 


34 

348 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


s 

X 

X 

Si 

X 

X 

M 

CJ  II 

3 

M 

jifci 

X 

X 

XXX 

X 

X 

M 

M  x  M 

X 

o 

II 

II  M 

II 

X 

X  W  M 

X 

X 

X  U  X  X 

3 

o 

M  W 

M  Z  M  M 

X 

x 

X 

D 

D 

P 

z 

Z 

X 

W 

w 

w 

o 

X 

w 

w 

>4 

CJ 

3 

X 

o 

o 

o 

D  P 

X 

E- 

w 

W 

X  r 

p 

w 

X 

> 

IhO 

X 

X 

X 

< 

w 

CJ  X  E- 

> 

w 

X 

p 

H  W  E- 

w 

<< 

E* 

<  z  o 

p 

z 

E- 

< 

X  X 

o 

M 

z 

X 

X 

X 

o 

w 

X 

E-  O  E- 

o 

w 

X 

X 

CJ 

0X0 

E" 

to 

X 

X 

z  **z 

•* 

X 

3 

< 

o 

to 

> 

CJ 

w 

Si  X  *S1 

E* 

X 

X 

X 

S)  z 

w 

w 

M  M  M 

X 

X 

> 

p 

II  w  II  O 

CJ 

3 

w 

< 

X 

ii  m  —  a 

< 

X 

X 

X 

<  X  X  t* 

X 

X 

X 

•*  CD<HrU  W  •*  X 

X  Dm  It  MW  P  to  Si 

x  (D  n  co  ii  ii  m  z  cd  s 

MuourQuuins  «s 

IUUUmOUUJHw  + 

to  m  D  CD  D  II  I 

X  X  Z  Z  X  Z  CD  i 

m3  o  w  M  w  CD  I 


*  CJ  II 

*  II  — 

-  — *  Q 

v  q  o  n 

CD  Q  M  +  W  X 

CD  +  M  w  +  P  •* 
II  <f  — '  M  O  m  CD 

W<X<<CJXOX3 

j<oj^i:mm  jw 


w 

o 

X 

CJ 

X 

X 

< 

X 

3 

E-* 

w 

z 

X 

z 

w 

>« 

< 

E- 

M 

X 

p 

X 

o 

p 

5 

X 

• 

w 

•* 

X 

E- 

z 

>< 

w 

X 

X 

X 

E 

o 

X 

CJ 

z 

g 

M 

g 

<< 

< 

3 

— • 

D  < 

5 

E*  p 

X 

V 

z  < 

X 

X  z 

s 

SZ  ®  c/3  W  w  CD 

II  M  I  o  E*  P  CJ 

CD  II  I  II  M  M  CD 

XWX<<D<XXW3 

CD  M  P  M  D 

OX  Z  Z  X  Z 

0  2  O  w  3  W 


o  >*  W  •— «  S) 

n  -  e-  o  + 

II  M  ¥  II  CD 

x  <  x  x  x  p  w  d 

>«  <  x  3  x  w  m  i  w 

II  DIO 

Z  X  Z 

<  m  W  ><  W 


CD  CD  W  CD 

D  Z  P  »J 

CD  II  M  CD 

2  0  U  x  CD  D 

O  CJ  2  3  X 

a  cd  o 
z  z  o  z 

o  wow 


W  P  Q 

D  W  W  Z 

-  -  E-  E-  •* 

m  Z  CD 

;  CD  CD  X  W  m  3 

:  X  X  5  M  II  CD 

Q  <  Q 

<  Z  <  Z 

<  W  M  w 


I  Z  II  W  2 

x  —  x  ► 

•  D  X  M  ' 

E-  X  ► 
:  w  w  w  m  w  o  2 
i  w  x  m  ^  p  x  > 

Q  M  M 

l  W  Z  X  X 

I  M  W  M  2 


P  w 

W  X 

w 

>  < 

to 

W  X 

M 

p 

X 

p 

h 

w 

< 

3  z 

CJ 

M 

w  w 

<< 

E" 

X 

Z  X 

X 

M 

< 

X 

X 

z 

Eh 

<  3 

M 

X 

u 

X 

X 

< 

> 

o 

X  o 

X 

x 

E- 

X  E- 

< 

o 

X 

X 

X 

p 

3  H 

w 

X 

x  z 

p 

X 

•*  M 

< 

•* 

X 

X  o 

p 

M 

o 

X  X 

o 

X 

X 

•* 

p 

x  ^ 

CD  X 

•*  (S 

X 

X 

D  3  x 

P  s 

3 

X  X 

D  X  m 

X  ®  M 

X 

X  — '  M  W 

•*.  CD  W  +  O  to  T 

+  O  P  X  X  XXX** 
+  I  HJIXI  X 

SXCJXmmZmXXD 
x  U  3  II  II  II  II  3  D  CD 
0<<QXXX0 
Z  Z<<<<DXOOZ 

O  WMMMMOUW 


II  m  o  II 

—  +  II 

X  X  bu  ^  [&4 

X  X  X  X  X  X 

M  M  M  X  M  3 

^  II  II  M  X 

HXlK^HQ 

X  X  X  O  X  z 

M  M  M  JE  M  W 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


35 

349 


C/5 

O 

00 

03 

a 

c 

o 

x 

a> 


o 

3 

C 


CD 


X  q; 

8  JL 

k.1  8 

M  M 

Q  Jint- 
2  O  ^  (/] 
co  <  * 

X  cj 

ss 


CO  co 

C/5  X 

+  O  U 

+  o  < 

1-3  X  to  CO 


< 

a 

x 


Q 

CO 

z 

►H 

Cl. 

CO 

Q 

E- 

Z 

CO 

a: 

co 

h 

< 

X 

E-* 


X 

o 

o 

CO 


k_ 

w  J  ^  J  DC 

ZZu  I 
CO  £  >  I 

Q  <  O 
Z  X  £ 
CO  •«.  k-4 


o  -  - 
x  a  • 
a  <  x 
w  to  Q 
X  z 
2  < 

<  H  T  J 
2  r  2 

'H  '<  O  -i 

u  o  u  o  u 

II  2  •  “  (h  Cb  )>  H  f)  df*  irl 

«  **  mo  rffcu  SS  V 

B?rr jmESi ,?,}“< 

Ji  ^  oqxBi»6<H 

5  “  2J|BL02<r* 

*  1-1 _ WUmOO"«5j  I 


CJ  X  yi 
■  r  x  f. , 


kJ 

kJ 

< 

X  SI 


D 

Z 

< 

r 

S 

cj 

CO 

X 


£  -Sr 


< 
< 

V  M 

<  — 

<  C/5 

M  X 

II 

!  j 


H  CD  J 

+  ffl  2 

<  H  II 

<  w  II 
w  C/5  C 

H  X  < 

CD  II  II 

ffl  <  < 


O 

z 

< 

T 


E- 

X 

cj 

M 

X  cc 

cj 

E-*  co 
<  X 
X  E* 

CJ  CO 
Z  X 
s  O 
o 

CO  05 
CO  to 
z  X 

sg 

05  H 
O  ~ 

CJ  X 

x  + 

m  + 
•*  w  X 

<  X  X 

<  X  M 


z 

Cl. 

CO 

a 

o 

E-* 

X 

CO 

a 

z 


X 


X 

X 


< 

*  <  ^ 


< 

z 


z 


CO 

5 

£ 

X 


Q 

CO 

Z 

M 

X 

CO 

a 

X 

s 

co 

z 

X 

< 

:* 

6) 

X  H 
D  M 
X  I 

Z 


z 

X 


u 

cj 


X  -f  X 
X  +  ^ 

II  x  II 

<  X  X 

<  M  X 


-  Z  M  CO  X 
Z  X  CJ  X  M 
X  w  ||  H  II 
M  — '  —  •*  O 

^  CJ  CD  <  CJ 

^  r  x  <  m 
O  II  II 
<  m  <  x 

X  X  < 


cj 

CJ  X 
M  X 

CJ  co 

T** 


Cl. 

CO 

Q 


co  <  <  m  x 

uJ  <  <  X  Z 


x 

=5 

X 

CO 

X 

E-« 

Cl. 

O 

z 

o 

M 

< 


U 

< 


X 

X 


+  X  X  •_] 
♦  *J  U  X  2 
CJ  w  o 
CJ  X  U  05  U 
HJH-  h 


X 

m  e- 

►H 

U 

CJ  X 
M  x 

-  o 
—  E- 
ffl  X 
X 

*o 
<  z 
~  <  < 
Z  »  •* 
x  cj  m 

w  CJ  X 
II 


J  ^  ‘  E-  H  wjl 

D  M  m  r  bC  rr 


z  a  x  x  x 

X  5  F  5  M 

a 

z 

X 


F  SO  X 
M  u  X  I 
II  <H  I 
CJ  Q<  w  x 
CJ  Z  XX 
m  3  u:  m 


O 

u 


00 

#c 

■*— 

X 

J 


E 

o 


c 

% 

O 


h 

X 

X 

M 

X 

X 

X 

X 

< 


X 
J  X 
X  Q 

X  z 

5  M 

u 

<  z 

x  w 

X  x 

U  E-. 

<  X 

Q  O 

<  h 

X 

X 

-  X 

<  m 

a  < 
u 
X 

X  X 
O  CJ 

u  u 

II  «H 
E-1  ^  s 
X  'Sj  S) 
X  O  -f 
M  w  I, 
X  x  o 
.^O  0. 


5 

X 

X 


X 

X 

5 

Z 

X 

o 

< 

X 

a 

u 

< 

x 

X  X 
X  X 
X  E-t 
X  M 
X  X 

E-*  X 
•J 


<  <  Z  o 

UNXNO 

cj  •-  c'* 

_  X  C  CD  < 

5  ^  ^  ^  < 

-f  X  II  X  II 

X  X  O  Q  O  <  , 

x  x  u  Q  o  <  < 


X 

a 

z 

< 

r 


x 

z 


CJ  X 

II  D 

—  i-J 

O  X  E-  Z 

X  +  J  <  II 

^  -f  M  X  II 

C/5  Q  X  cj  < 

Z  Z  <  X 
X  **•  <  M 


5 

X 

X  kJ 

z 

U  II 

u  « 

u  X 

Do  J 

<  fl  M 

X  X  <  <  x 

X 
x  5 

X 
•J 
X 


Q 

C 

X 

X 

£ 

CD 

D 

X 


=  ffl 

gz  X  3 
X  h  x 
Q  O 

z  z 

X  X 


X 

o 

X  Q 
a  x 
M  z 
x 
E-  X 

<  o 

X  x 
X  u 
X 

—  X  = 

H  O  CJ  H  «s 

Cj  X  -‘®  (S 

•H  w  X  si  s 

X  >  H  CJ  is  s  ® 

<  x  S)  IS  s 

X  M  CD  -f 

M  n  Z  D  II  T 

O  x  X  X  CJ  II  Xm  cj 

dxxoxuxx  o 

UmOUmJhJ  j 


X 

X 


u 

X 


D 

<  m 


ffl  +  ®  -f  X  X  I 
“  "  II  J  X 


55 


X 

8 

u 

o 

X 

X  M 
X  X 
ffl 

15 

z  x 

CJ  X 
X  - 

\  CJ 

§*..° 
X  Q 

x  u  c 

X  X 
O  X  X 
O  X 
X  < 

CJ  u 


X 

X 

ffl 

F 

D 

Z 

z 

e> 

Q 

M 

C 

X 

X 

H 

X 

X 

z 

X  M 


X 

X 

ffl 

i 

z 


ffl 

ffl 


ss 

<  X 
O  X 
X 

z  CJ 
F  CJ 
CJ  X 

it  m  a 

II 

CJ  <  X 

v<a 

<  X 

<  M 


Q 

z 

< 

i 

X  1^ 
m  ro 

I  z 

HO  N 
Z  E-« 

x  o  x  x 

M  O  M  O 
O  X 

z  o 

X  U 


Q 

< 

X 

X 

z 

X 

ffl 

D 

x  r- 

<  O  rn 

<  u 

o 

X  o 

M  J 


< 

< 


z  < 

X  < 


X  CJ 
CJ  X  + 

<  M  +  + 

o-  ^  O  -f 
z  x  a.  x 

D^WJ 


z 

o 


36 

350 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


CO  + 

M  < 

w  p  < 
CO  X  J  h 
SC  w  II  II 
P  CD  < 
Z  CO  < 


co  -h  r 

CO  SJ 

MM  X 

+  +  o 

<  <  x 

<  •* 

M  M  X  X  Z 

II  II  P  T.  CJ  X 

<  <  M  0< 


X  ><  M 

X 

X  Z  X 

X 

c 

p 

p  r 

rf 

- 

-  — 

X  P  o 

z 

X  X 

<s 

CO 

X  M 

X  <  X 

X 

£ 

X  E- 

P  CJ  < 

z 

>« 

•<  b 

X  co  U  N 

O  N 

X 

P  o 

M  CJ 

E- 

z 

z  a 

p 

p  X  <  O  X  X 

p 

p  x 

r  5.  x 

z 

p  p  <  n  m  p 

r 

z 

p  z  x 

X  E-  <  X 

P  X 

CJ 

M  X 

zaxc/i 

X 

P  X  X  CD  o  x 

z  o 

- 

II  P 

-  ii  p  - 

t-  x  a  p  a  u  *-• 

x  O 

<  CO 

<  X 

M  Q  M  »— t 

to 

<  o 

X  <  o  x 

X 

Z  XX 

T 

M  o 

r hut  Su  “5 

X 

- 

p 

X 

p 

X 

T 

X 

X  X 

p 

P 

X 

c  ><  p 

X 

z 

< 

P  CD  P 

z 

p 

°  £ 

M 

X 

p 

<  r  > 

X  x 

p 

X 

< 

o 

p 

x  X 

X  X 

X 

X 

X 

M 

z 

X 

x  r  x 

pp 

X 

r 

X 

X 

X 

p  > 

X 

< 

p 

•« 

X 

< 

<C  z  c 

X 

p 

z 

z 

|F 

M 

p 

CJ  X 

X  x 

X 

«S1  <  O 

•* 

P  X  •* 

<x 

X 

p 

M  c  CD 

p 

< 

<  <  p 

r  ^ 

X 

<  p 

X 

M  M  X 

z 

X 

X  XX 

•» 

X 

X  X 

p 

si  *  +  Z 

II 

X 

X  X  M 

M  E- 

T 

X  M 

X  ts 

X  Z  Z  CJ  N 

— • 

p 

—  II 

CJ  Z 

P 

•*  II 

IS 

1  oxxu 

CJ 

X 

< 

<u  W- 

II  P 

Z 

z  ^ 

SI 

UUMM  X 

V 

p 

CD  II  r  < 

—  o 

•* 

CD  Z 

y  (1  II  II  P  P 

m  z  es  <  <  u  Z  ici  a:  co 

v  io:cDioofliM<  •»  q:  co  +  co  m  d 

■  <  5  P  DO.D-M+D  +  P  'CO  ..  _ 

QhUW^WHw •  +  f-  U  j  50  h  Q  ZM 

zzxooxoitcjzcdozopz  ocx 


o  x  x  p  e>  o 


»  <  z  z  <  x 
uu<cd:d:uo< 

JUmMmCCU^ 


z  o  p  z  x  x 


o 

co 

h 

x  e?  p 

><  z  x 

M  z 

p  z  M 

CD  CD  X 

Z  <  CD 

M  ^  Q 

Cl. 


5 

U 

X  Pm 

X  E-* 

X 

P 

p 

Z 

P  M  Cb 

P  X 

< 

X 

Z 

p 

M 

M 

<  5  x 

X 

5 

X 

< 

o 

z 

X 

p 

E-  — 

- 

r 

X 

z 

P  X  — 

O  P 

u 

< 

JC 

M 

r 

<  *-<  — 

z  z 

X 

< 

o 

p 

u 

© 

X  X  <  <s 

•»  II 

II 

- 

X 

m 

X 

CJ 

X 

X 

X 

X  H  C  ® 

<  — 

_ _ _ 

z  < 

X 

X 

X 

m 

CJ 

X 

X 

X 

S3  *  —  t — «  | — l 

<c  u 

CJ 

X  «< 

X 

II 

CJ 

II 

X 

< 

p 

<  CJ  X  '—  || 

M  X 

X 

M  || 

II 

II 

O 

m 

O  P 

p 

X 

ro 

E- 

cj 

x  ii  r  m  ii 

II  M 

M 

u 

II 

E- 

G  . 

ro 

p 

SJ 

ro 

f  1 

<  s> 

CJ 

—  r  z 

z  — 

X  CJ 

u 

CL+  U  CJ  <  OX  x  +  CJ 

m+  +  uo:<uum  •-<  +  +  u  o 

w  y  +  n  11  co  P  ^  y  +  H  H 

coa  juccl  J  z  x  a  j  u  o 


wa juca J 

*:  H  _j  o;  <  H  CD 


X  X  +  CJ  Pll  -  CJ  X  P  I  CJ  X  O  X  M  X  << 

m  m  +  +  CJ  O  Z  ^  CJ  •  II  P  Z  I  O  O  Cb  II  Q  D  O,  D  II  h  < 

p  w  y  +  n  H  u  ja  -ii  coiiyE-  E-*  mu  <  co  ^  co  z  11 
z  m  ajuofc  **aM  +  ®  -*j<ouao  oa'»j<wocnoa<a 

U  U  SC  mPOCUmPnII  +  uPP<OXmocdOmuP<XoOO>-,'<m 

co  O  z  w  p  y  ii  o  ii  co  p  x  ii 

P  Z  CO  a  Ii  P  <  Cb  P2«£Cb 


XOXMXCXCO  WU.  +  ua  +  Q.+nj 

pDa^iiM<MscuscM  +  <H  +  M  +  uzo  o 
c  co  ^  co  z  ii  co  P  y  a  ^  y  ^  n  ii  ii  h  e- 

x  o  x  o  x  <  x  p  zazcoacoapuo  o 

a  ooo  H  <  h  cd  cDM^^M^Mjtruuu 


Z  co  a  cl  p  <  cx-. 

CDCDZMMJ[D<m 
CO  CO 

<  < 

C J  CJ 


Z  <  Cb 

CD  CD  4:  M 
CO 
< 

CJ 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


37 

351 


(Continued  on  top  of  page  36)  |  (Continued  on  next  page) 


C/3 

0/ 

00 

CO 

Q. 

C 

O 

■w 

X 

0> 


TJ 

o 

3 

C 


X 

3 

CD 

E- 

3 

o 


X 

CO 

X 

r 

X 

3 

o 

z 

u 

X 

J 

CJ 

3 

< 

Z 

E- 

1 

X 

1 

E-* 

D 

*-< 

Z 

o 

X 

CJ 

r 

CO  P- 

OV  3 

X  X 

m  c 

+  •* 
<c  <  o 


co  *-« 

H  u  u 

X 

X 

< 

< 

cj 

cj 

X 

co 


co 

> 

CD 

8 

u 


co 

E'¬ 


er: 

5  3  < 
•*  H  < 

X  ^  II 
X  II  3 
<  E-* 

CO  <  h-. 

CD 

< 

CJ 


E- 

t-l 

E-* 

X 

fr*  X 

u 

X 

m  o 

X 

co 

X  x 

X 

co  x 

X 

X  CO 

CJ 

8 

co  x 

X 

bJ 

E-*  O 

t-4 


VC  VC  CD  XX 

CD  £  CO 

cn  ~* 

\*  i  x  x  jr  z 

=>«=  3  3  =  on 

h  <  h  «c  m  z  ~ 

HHH<gOg  •*>-.«< 
II  II  II  HDHDhaD^ 
<  m  in  ii  03  n  tn  ,j  ii  to 
CXXCJ0CJ03CJ0X 
hhm(jUUU<(joh 

X 

u 

o 


o 

E- 


E- 

»-i 

X 

co 

X 


X 

o 

CD 


CO 

n 

X 

5 


IS) 

u 

X 

u 

1 

bJ 

CJ 

y 

»-• 

n 

< 

X 

<  X 

r 

co 


2 


CO  IS 

tv 


X  < 
5  c 


X 

E-* 


<  CO  I 
X  <  c/} 
v—*  '  O 

D  X  O 

Z  X  2 

z 

b3 


X 

X 

3 

CD 


IS 

<  <* 

X 

x  cj 

CJ 

Ov 

+ 

♦  1 

1 

CJ 

CJ 

u  cj 

CJ 

V 

V 

vv 

V 

u  < 

CJ 

O  CJ 

u 

V  * 

cj  co 

U  CJ 

CJ 

II 

X 

<  X 

u 

<  ►-(  CO 


X 

co 

X 

bu 

X 

X 

e 

o 


o 


5 


Z 


co 

H 

H 

X 

5 


X 

X 


s 


o 

if 


V 

is 

IS 


xx  § 
h  a  +  (d 
o  w  4-  Q 
Z  O  X  z 

X  X  X  w 


§ 


X 
CO  x 

_J  M 


X  M 
o  S 
CJ  X 


a 

s 


c 

o 

o 


00 

#c 

■*— 

.M 


c 

o 


X 

CO 

X 

r 

3 

z 

< 


CO 

X 

o 

X 


CJ 

X 

CJ 

X 

—  z 

CO 

3 

o 

u 

X 

o 

►H 

X 

W  w 

X 

3 

VH  X 

5 

X 

+  X  o 

D 

o 

+  II  o 

z 

z 

H  u  x 

CO 

CO 

o  CJ  u 

X 

CJ 

rf 

E- 

X 

X 

> 

II 

V 

c 

+  X 

X 

+  II 
X  < 

w  < 

X 

< 

u 

X 

o 

E- 


u 

3 

X 

X 

X 

X 

CO 

X  CO 

>  ij 

3  CJ  > 

O  Z  IS 

H  <  O 

IS 

^  E->  X 

>  CO  D  IS 

II  CD  N  N 

-  E-  X  + 

—  II 

M  II  II 

X  N  V 

<  X  X  X  J 

x  ><  o  <  x 

<  r  5  >«  x 

M  ^  N  +  x  <  T 

D  X  X  +  || 

X 

Z  ><  n-  <  fc 

*-•  CO  H  [O  N  c  H 


< 

CJ 


bJ 

z 


3 
E- 

®  l-l 


CO  Q  S 

E-  X  +  — 

h-t  II  II  X 

a  x  j  x  n 

5  N  X  M 

Q  CD 

Z  N 

CO  *-< 


CD 


01  5 

O  X 

6-  X 


>« 

•J 

X 


30 

cj 

c 

X 


h 

Q 

X 

iJ 

X 

Q 

—  3  <  3 

—  3  <  3 

3 

< 

—  3 

o 

< 

xE-i«cxxE-<rx 

E- 

< 

X  E-* 

H 

(S 

X 

X 

>•  H  H 

>«  M  M  >. 

M 

H-t 

>  M 

s 

•b 

£ 

w  +  II  - 

w  1  II  - 

* 

II 

«S 

s 

> 

+ 

X  <  ~  1 

X  <  *  X 

< 

A  X  V 

■f 

+ 

X 

v  X 

• 

>«  <  X  - 

>«  rf  X  -  > 

< 

X 

II 

II 

-  >< 

•* 

>* 

‘  » — <  >-*  •-  H-I 

>-* 

>« 

H  4! 

<  J 

bJ 

X  X 

M 

X 

II  II  — 

II  II  ^-X  II 

|| 

O  II  *-• 

«<  X 

W  X  H  3 

*-J  II 

CJ  <  <  X  CJ 

<  <  X  CJ  < 

< 

X  U  <  II 

CM 

X 

O  X  CJ  4 

<  <  >* 

«C  <  > 

< 

> 

<  -t 

rH  [l, 

bJ 

z  o 

c 

CO 

M  t-1  »-«  U 

H  M  H  [O  H 

M 

►H 

u  *-«  < 

M 

u 

co  CJ 

CO  M 

X 

X 

X 

X 

CJ 

X 

< 

< 

< 

< 

O 

< 

CJ 

U 

u 

u 

•J 

u 

< 

< 


v  (N  || 

3  ^  - 


—  < 

X  < 

>«  M 
— *  II 
CD  M  CM 
>«  X  ^ 


E-«  **H  (H 

M  O  3  II  M  O 
II  H  CJ  C  II  H 
<  O  <  <  O 
*:  cj  co  m  *c  cj 
x 
< 

CJ 


38 

352 


Di.  Dobb’s  Journal,  Number  58,  August  1981 


00 

s 


3 


T3 

C 


W 


x 

c 

x 

Z 

hh 

X 


CO 

x 


I 

CO 


E- 

M 

X 

x 

X 


— 

Eh 

X 

X 

r. 

> 

z 

X 

< 

o 

X 

X 

X 

CJ 

X 

X 

> 

p 

E 

< 

2 

2 

E- 

*£ 

CM 

X 

X 

HH 

w 

E- 

X 

CJ 

O 

X 

CJ 

CJ 

2 

E-h 

u 

M 

X 

< 

CM 

> 

X 

CM 

X 

X 

z* 

CM 

X 

X 

< 

X 

X 

a  < 

p 

CM 

p 

«c 

X 

p 

2  II 

X 

X 

X  X  ® 

X 

2 

CD 

> 

>  <  CJ 

O' 

1  2  CJ  X  1  r-i 

+  2 

o  z 

CD  X 

X 

«< 

CJ  u 

CJ  X  cm  CJ 

X 

X 

CJX  U  X  X  Us  U  X 

2  U 

1  D  X  + 

X 

X 

V  v'L 

II  x  •«*  || 

II 

X 

UP  II  II  X  CJ  + 

U  3 

1  II  ^  + 

hh  CD 

1 

1  v 

V  US  x  V 

V 

c» 

HE-  V  V  c8  Mil 

n  e- 

CO  X 

Q  <  O  X 

X 

P 

CJ 

M  < 

X  <  P  ts 

u 

<  < 

UXX<U<<UC0 

u  x 

X  W  P 

2  «£  X  X 

1 

X 

v 

X 

X  <  CD  X 

CJ 

<  < 

U  X  h  x  u  <  u  co 

u  CC 

M  X 

o 

p 

II 

II  II 

II  II  p  II 

II 

II 

p  II  II  II 

P  *4!  P 

2 

z 

< 

X  < 

X  <  2  < 

X 

c  X 

2  <  X  <  X 

z  <  z 

X 

X 

<  X  < 

X  <  X  < 

X 

HH 

X  <  X  <  H 

X  X 

a\  O' 

®  U  UU  CD 
X  U  II  II  CD 

I  I  V  V  c«  CD 

u  <  cd  *c  x 

CJ  X  <  CD  <  CO 

II  II  II  II  II  o 

<  CO  <  CD  <  Z 

<  cd  <  co  <  x 


x 

CJ 

< 

CL 

CO 

x 

E- 

HH 

X 

s 

CO 

HH 


CO 

2 

HH 

X 

2 

CO 

2 


5  X 

N  2 

See 

< 

3  ffl  Eh 


CO  E-  X 
u  u  cd  z  cd 
ii  n  m  n  co 
ii  ii  n  (v.  cd  r 
cj  cj  <  cj  <  P  o 

vvifvfg!: 

<  CD  <  X  <  2  o 


Qo 


ex. 


ex. 

o 


X 

P 

CO 


X 

P 

X 

E- 

P 

o 


X 

CO 

Cl, 

Cl. 

X 

co 

o 

2 

HH 

X 

E- 

co 


r 

x 


E- 

3 

O 

E-1 

< 

CJ 

P 

z 

< 

u 

z 


o 

E- 

z 


Q 

CO 

X 

CJ 

E- 

co 

X 

X 

o 


o 

E- 


X 

CJ 

E- 


X 

X 

X 

X 

p 

CO 

cd 

2 

HH 

X 

E- 

co 


X 

X 

X 

£ 

P 


£ 

E- 

E- 

X 

X 

2 

“ 

■ 

< 

X 

>H 

X 

o 

o 

O 

X 

X 

<  < 

X 

E-* 

X 

E- 

M 

X 

X 

M  C 

o 

1 

X 

< 

u 

p  p 

p 

X 

■f  II 

E- 

z 

o 

E- 

X 

< 

E- 

2 

2 

E- 

>-• 

P  — 

CO 

o 

u 

CJ 

X 

E- 

U 

»-l 

M 

V-l 

II 

X 

X 

E-  X  C 

H 

E- 

u 

2 

2 

X 

p 

X 

<s> 

X 

-f 

X 

£ 

X 

M  X  < 

X 

p 

X 

X 

E- 

X 

X 

p 

Eh  2 

s 

< 

< 

r 

— • 

II 

II  HH 

o 

X 

X 

2 

X 

CD 

E-i 

HH 

HH 

1 

< 

u 

K 

X 

X 

< 

2 

i 

V 

<£ 

<  II  — 

> 

E- 

< 

X 

< 

Q 

CS3 

X 

II 

p 

HH 

E- 

2 

u 

X 

X  X 

cs 

£ 

X 

»-* 

X 

X 

X 

<  < 

<  <  CJ 

o 

X 

2 

z 

< 

X 

-j: 

u 

E- 

u 

E-* 

X 

2 

o 

p 

X 

N 

y 

“ 

-  E- 

•f 

•— 

II 

II 

H— ' ' 

P 

X 

X 

<  M 

M  <  £ 

X 

CD 

M 

O 

p 

5  X 

II 

X 

ii 

II 

X 

II 

X 

P 

HH 

E- 

< 

M 

E- 

II 

m 

M 

It 

V 

< 

< 

hH 

E- 

II 

ii 

X 

P 

u 

E- 

3  P 

< 

p 

CD 

p 

X 

X 

X 

< 

** 

HH 

hh 

X  P 

X  < 

X 

*— 1 

X 

X  X 

X 

X 

X 

<  c 

rf 

T 

X 

X  < 

X 

X 

2 

X 

M 

X 

•* 

E-  X 

•» 

E-  O 

o 

E-  O 

HH 

+ 

HH 

HH 

+  X 

II 

♦  p  c 

p  < 

X 

X 

r 

r  5 

X 

►H 

X 

-c  *-• 

M 

>-( 

X 

X 

X 

< 

X 

X 

u 

II 

p 

X 

M  X 

+ 

< 

»-* 

X 

+ 

X 

X 

»-< 

X 

CD 

II 

II 

+ 

X 

+  II 

X 

+  X  II 

X 

CD  U 

p 

II 

X 

P 

X 

<  X 

X 

II 

+ 

X 

II 

+ 

X 

II 

X 

p 

X 

<  <T> 

< 

E- 

*-H  P 

X 

»-<  o  u 

O  X 

X  o 

2 

< 

X 

_] 

z 

<  o 

<  O  X 

< 

X 

o 

X 

O 

X 

p 

<  CO 

«£ 

X 

XOD 

M 

u1  U  U  u  H 

X 

u 

X  < 

*-• 

X 

X 

X 

X 

<  X 

X 

X 

<  o 

X 

o 

X 

X 

o 

X 

HH 

X 

HH 

HH 

HH 

CJ 


X 

< 


X  CJ 

<  o 

CJ  x 


c 

o 

3 

•S 

5 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


39 

353 


Ur.  Dobbs  Clinic 


We’re  Going  to  Answer  Our  Mail . . . 

The  Clinic  continues  to  receive  a 
gratifying  flow  of  mail.  Many  of  the  let¬ 
ters  reflect  hours  of  work  and  thought. 
That  isn’t  a  requirement,  by  the  way;  we 
don’t  have  space  to  do  justice  to  all  the 
beautiful  analyses  we’re  getting,  while  a 
good  problem  or  discovery  dashed  off  in 
ten  minutes  is  very  useful. 

Decimation  Delayed 

Dennis  Allison  politely  points  out 
that  he  described  two  solutions  to  the 
problem  of  dividing  by  ten  in  an  article 
in  DDJ  #42.  Readers  have  already  pro¬ 
duced  yet  a  third  class  of  solutions.  We’ll 
display  the  best  algorithms  for  binary-to- 
decimal  conversion  in  the  next  issue.  If 
you’re  thinking  about  writing,  read 
Dennis’  article  first. 

Beyond  MAX 

The  solutions  to  MIN  and  MAX  re¬ 
volved  around  using  the  relational  func¬ 
tions  of  BASIC  to  select  one  of  two 
values.  Michael  Wochnik  of  St.  Louis, 
MO  extended  that  general  principle  to 
other  functions.  For  example,  suppose 
you  wanted  to  examine  bytes,  filtering 
out  ASCII  control  characters  but  keeping 
the  printable  ones.  For  simplicity,  assume 
the  bytes  are  carried  as  numbers.  Then 
this  function  would  do  it: 

DEF  FNAS(X,C)  = 

— ( (3 1  < X)  AND  (X<127))*X 
~((X<32)OR(127<X))*C 
If  X  is  a  valid,  printable  ASCII  byte,  it  is 
returned  by  the  function;  if  it  isn’t,  the 
replacement  character  C  is  returned. 
Change  the  minuses  to  pluses  if  “true”  is 
+  1  in  your  BASIC. 

Suppose  that  you  are  using  an  un¬ 
dependable  value  (user  input)  to  select 
the  target  of  an  ON-GOTO.  Bad  input 
will  cause  an  error  and  stop  the  program. 
This  function  will  produce  either  the 
input  number  plus  one,  or  an  error  num¬ 
ber  of  1 : 

DEF  FNON(S,K)  = 

S*(S>0)*(S<=K)+1 
where  S  is  the  goto  index  and  K  is  the 
number  of  valid  alternatives.  FNON 
would  be  used  in  code  like  this: 

1000  ..  .  INPUT  ACODE  .  .  . 

1010  ON  FNON(ACODE,3) 

GOTO  1020,2000,3000, 

4000 

1020  PRINT  “from  1  to  3, 
please”  :  GOTO  1000 
FNON  is  an  interesting  demonstration 


that  logical  “and”  and  arithmetical  “mul¬ 
tiply”  are  closely  related.  It’s  also  inter¬ 
esting  in  that  it  works  correctly  regardless 
of  whether  “true”  is  -1  or+1,  although 
that  isn’t  immediately  apparent. 

One  More  Flea-Hop 

Several  late  responses  came  in  re¬ 
garding  what  John  H.  Martin  of  Cam¬ 
bridge,  MA  chose  to  call  the  “Cortesian” 
approximation,  a  groaner  if  there  ever 
was  one.  Martin’s  letter  makes  it  clear 
that  the  Intern  was  altogether  too  hasty 
in  saying  Edmund  Butler’s  choice  of  con¬ 
stants  was  “probably  the  most  accurate,” 
and  also  explains  why  different  readers’ 
analyses  of  the  problem  produced  differ¬ 
ent  “best”  constants. 

For  those  who  just  tuned  in,  we  pro¬ 
posed  an  approximation  to  the  hypote¬ 
nuse  of  a  right  triangle  that  can  be  stated 
as 

happrox  =  x  +  y/2 

where  x  and  y  are  the  lengths  of  the  sides 
and  x  is  greater  than  y.  Several  readers 
generalized  it  to 

happrox  =  A*x  +  B*y 
(our  approximation  falling  out  as  A=l, 
B=0.5),  and  proposed  “best”  values  for 
A  and  B,  “best”  meaning  “least  error.” 
Martin  points  out  that  there  are  three 
different  kinds  of  errors  that  one  could 
consider,  and  that  different  values  of  A 
and  B  minimize  different  measures  of 
error.  He  proposes  three  solutions: 

.9285x  +  3978y  (a) 

.9412x  +  4 1 0 1  y  (b) 

,9605x  +  3978y  (c) 

Where  (a)  minimizes  the  average  absolute- 
value  fractional  error,  (b)  minimizes  the 
root -mean -square  fractional  error,  and 
(c)  minimizes  the  worst-case  fractional 
error.  “I  found  most  of  these  solutions  by 
analysis,”  he  writes,  “but  it  might  be  an 
interesting  exercise  for  your  readers  to 
look  for  them  by  computer.  I  considered 
writing  an  article  on  how  one  finds  such 
solutions,  but  it  will  have  to  take  a  back 
seat  to  other  work  right  now.”  All  who 
want  to  read  (or  write!)  an  article  on 
finding  computer  approximations  raise 
their  hands.  An  article  is  what  it  will  be, 
because  the  Intern’s  math  phobia  is  only 
barely  under  control  now. 

Russel  Brown  of  Holland  Patent,  NY 
noted  that  the  hypotenuse  approximation 
implies  a  use  of  MIN  and  MAX,  but  a 
combined  function  could  do  it  all  at 
once.  Readers  with  a  strong  liking  for  al¬ 
gebra  might  like  to  verify  that  if 


happrox  =  A*MAX(ABS(X),ABS(Y))  + 
B*MIN(ABS(X),ABS(Y)) 
(choosing  A  and  B  from  Martin’s  list), 
then  if  you  pre-calculate  constants 
A2  =  (A+B)  /  2 
B2  =  (A-B)/  2 

you  could  define  a  hypotenuse  function 
this  way: 

DEF  FNHYP(X.Y)  =  A2*(ABS(X)+ 
ABS(Y))+  B2*ABS(ABS(X)- 
ABS(Y)) 

A  System  Solution  for  Apple 

We  descend  from  the  rarified  air  of 
mathematics  to  find  a  letter  from  J.  G. 
Wendel  of  the  University  of  Michigan.  He 
writes  of  a  discovery  he  made  about 
MBASIC  running  on  the  Apple  with  a 
Z80  Softcard.  Suppose  you’re  working  on 
a  program  that  does  lots  of  printing.  Dur¬ 
ing  development  you  have  it  print  to  the 
screen,  but  for  the  production  version 
you  want  all  the  PRINTS  to  go  to  the 
hard-copy  printer.  Wendel  says  “In 
Applesoft  you  could  add  a  line  PRINT 
D$“PR#1”  (where  D$  =  ctrl-D)  at  the 
start  of  the  program,  and  .  .  .#0  at  the 
end.” 

Not  so  under  MBASIC  which  doesn’t 
recognize  the  execution  of  DOS  com¬ 
mands  through  PRINT  statements.  How¬ 
ever,  “In  Z80  MBASIC  add  POKE  3,150 
at  the  beginning  and  POKE  3,149  at  the 
end.  This  in  effect  converts  all  PRINTS  to 
LPRINTs.  Note:  if  you  forget  the  final 
POKE  your  keyboard  will  be  locked 
out!” 

A  Glitch  in  the  Z80  CPU 

Wayne  Farmer  of  San  Diego,  CA 
passed  on  an  item  from  UZER,  the  Zilog 
User’s  Group  newsletter.  It  describes  the 
kind  of  subtle  hardware  problem  that 
could  give  fits  to  someone  trying  to  im¬ 
plement  MP/M  or  another  multi-tasking 
operating  system  on  the  Z80.  Critical 
code  in  such  a  system  might  need  to  pre¬ 
serve  the  state  of  the  system,  including 
the  state  of  the  interrupt-enable  flag  in 
the  CPU.  The  usual  method  to  read  that 
flag  is  to  execute  either  the  “LD  A, I”  or 
the  “LD  A,R”  instruction;  both  set  the 
carry  flag  to  the  value  of  the  interrupt- 
enable  latch. 

According  the  UZER ,  there  is  one 
rare  condition  under  which  that  isn’t 
true.  If  interrupts  are  enabled  when  the 
instruction  is  done,  and  if  an  interrupt 
occurs  at  just  that  instant,  the  carry  flag 
is  set  falsely.  Solutions  are  given  in  the 


40 

354 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


newsletter;  they  entail  using  the  stack  to 
detect  that  an  interrupt  happened  at  the 
crucial  moment.  The  one  programmer  in 
the  thousand  who  gets  hit  by  this  might 
spend  weeks  trying  to  fix  an  unrepro- 
ducible  system  hang. 

Two  Calls  for  Help 

Turner  Caldwell  of  Burgess,  VA 
writes  of  a  problem  with  the  popular  MX- 
80  printer.  Caldwell  says  the  printer  is,  in 
general,  an  excellent  piece  of  gear.  Un- 
fortuantely,  it  may  be  a  bit  too  smart  for 
its  own  good  -  or  does  it  have  a  bug?  He 
notes  that  many  of  the  machine’s  features 
are  switched  on  and  off  by  sending  it  con¬ 
trol  codes.  “There  is  a  catch,  however.  To 
speed  up  printing,  the  control  logic  is  bi¬ 
directional  and  seeks  the  shortest  way  to 
print  a  line.  The  CR  code  tells  the  printer 
to  print  the  data  in  the  buffer.  Thus  a 
control  code  embedded  in  the  text  may 
be  recognized  or  not,  depending  on  the 
direction  the  print  head  is  directed  to 
go.” 

We  assume  Caldwell  is  talking  about 
situations  where  some  control  change  (to 
wide  characters,  for  example)  is  triggered 
by  a  control  code  leading  the  data.  If  the 
printer  is  going  right  to  left,  what  was  a 
leading  control  sequence  is  read  as  a  trail¬ 
ing  one  and  affects  the  wrong  characters 
or  no  characters  at  all.  “There  is  no  way 
of  casually  determining  this  during  entry 
of  data  with  a  word  processor,”  he  writes, 
“so  except  for  special  situations  many  of 
the  features  of  the  printer  seem  unuse- 
able.”  Can  this  be  true?  Is  it  true  of  other 
printers  with  clever  internal  logic?  Is 
there  an  easy  solution? 

Meanwhile,  J.  R.  Snow  of  San  Fran¬ 
cisco,  CA  wants  to  decode  Touch-Tone 
pulses  from  a  phone  line  in  order  to  drive 
a  single-board  computer  from,  say,  a  pay 
phone.  The  problem  is  to  keep  the  cost 
down;  Touch-Tone  decoders  run  close  to 
$200,  it  seems  and  the  decoder  still  has  to 
be  interfaced  after  that.  An  experienced 
homebrewer  might  have  found  something 
clever  along  these  lines.  A  solution  might 
fit  the  Clinic,  or  it  might  well  justify  a 
full  article. 

Cut  The  Cards 

We  have  a  number  of  Atari  game 
tapes  around,  including  three  card  games: 
Stud  Poker1 ,  Bridge  2.02  and  Casino 
Blackjack3.  We  were  poking  around  in 
the  code  of  the  games  and  noticed 
something  odd  about  the  way  they 


Listing  I 

-[  Pascal  fragment  illustrating  card  shuffling  as  done  in  Dynacomp’s 
STUD  POKER  for  Atari  Y 

type  card  =  1.  .52; 

var  deck:  array  [card]  of  boolean; 

procedure  shuffle; 
var  r:  card; 
begin 

for  r:=l  to  52  do 
deck[r]  :=  true 
end  -[shuffle]-  ; 

function  deal_a_card :  card; 
var  r:  card; 
begin 

repeat 

r  :=  fnrandi(5  2) 

until  deck[r] ;  -[ unpredictable !}- 
deck[r]  :=  false; 
deal_a_card  :=  r 
end  -[deal_a  card]- ; 


Listing  2 

-[Pascal  fragment  illustrating  card  shuffling  as  done  in  Manhatten  Software’s 
CASINO  BLACKJACK  for  Atari.  In  Blackjack  suits  are  ignored.  The  original 
code  handles  1,  2,  or  4  decks.  This  fragment  assumes  a  2-deck  pack.  ]- 

const  ndecks  =  2; 

decksize=  104;  -{52*ndecks}- 
cards_of_a_rank  =  8  ;-{decksize/  131- 

type  card  =  1.  .13; 

var  ranks:  array[card]  of  0.  .cards_of_a_rank; 
deck:  array]  1.  .decksize]  of  card; 

procedure  shuffle; 

var  r:  card;  j:  1.  .decksize; 
begin 

for  r:=l  to  13  do 

ranks[r]  :=  cards_of_a_rank; 
for  j  :=1  to  decksize  do 
begin 

repeat 

r  :=  fnrandi(13) 

until  ranks! r]  >0; -[unpredictablelL 
ranks]  r]  :=  ranks[r] -1 ; 
deck[ j]  :=  r 

end 

end  -[shuffle}-; 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


41 

355 


shuffle  their  simulated  decks. 

We’ve  known  fanatic  cribbage  players 
who  swore  that  using  a  cribbage  deck  for 
any  other  game  “spoiled  the  deck”  for 
many  hands  afterward.  There  may  be  a 
grain  of  truth  to  this;  some  order  will  be 
preserved  when  the  deck  is  gathered  in  at 
the  end  of  any  card  game.  Card  shuffling 
is  not  a  random  process;  it  can  be  seen  as 
the  systematic  permutation  of  a  starting 
sequence  to  an  ending  sequence.  The  end¬ 
ing  sequence  retains  a  “memory”  of  the 
original  sequence;  the  permutation  can  be 
inverted,  at  least  in  principle. 

Two  of  the  three  games  do  not  treat 
the  simulated  deck  as  a  sequence  to  be 
permuted.  We’ve  recast  the  logic  of  the 
three  games  into  Pascal  fragments,  just 
for  a  change.  In  all  listings,  “fnrandi(j)”  is 
some  Pascal  equivalent  of  the  BASIC 
expression 

INT(RND(0)*J)+1 

Listing  1  (page  4 1 )  abstracts  the  logic 
used  in  Stud  Poker,  a  “shuffle”  resets  a 


vector  of  flags  that  indicate  whether  a 
card  has  been  dealt  or  not.  To  deal  a  card, 
the  game  generates  random  integers  un¬ 
til  it  finds  a  card  it  hasn’t  dealt  before. 
That  takes  an  unpredictable  number  of 
iterations,  but  Stud  Poker  never  deals 
more  than  10  cards  before  shuffling  so 
the  odds  are  good  that  it  will  only  loop 
once  before  finding  a  card. 

Casino  Blackjack  has  to  deal  out  an 
entire  pack  of  cards  before  shuffling,  yet 
it  uses  a  variant  of  the  same  logic  (Listing 
2,  page  41).  Suits  are  ignored  in  black¬ 
jack,  so  Casino  Blackjack  works  with  a 
deck  that  contains  multiple  occurrences 
of  each  rank  rather  than  unique  card 
values.  The  boolean  vector  of  Stud  Poker 
is  replaced  with  a  vector  that  counts  the 
number  of  each  rank  that  have  been 
dispensed  to  the  new  deck.  Like  Stud 
Poker,  the  game  picks  random  integers 
until  it  finds  a  rank  that  hasn’t  been 
exhausted.  All  the  cards  must  be  picked. 
In  execution  it  is  clear  that  the  program 
“sticks”  in  the  random-choice  loop  for 


several  seconds  near  the  end  of  the 
shuffle. 

Bridge  2.0  does  treat  a  deck  as  a  per¬ 
mutation  sequence.  The  resulting  algo¬ 
rithm  (Listing  3,  below)  has  two  advan¬ 
tages.  It  has  a  predictable  execution  time 
and,  since  the  next  deal  is  a  permutation 
of  the  prior  one,  it  may  produce  hands 
that  are  more  realistic.  The  use  of  a  de¬ 
scending  index  to  limit  the  range  of  the 
random  choice  is  especially  clever.  The 
loop  invariant  assertion  is  “all  cards  j  +  1 
to  end  are  shuffled,  all  cards  1 ...  j  are  un¬ 
shuffled.”  Comments  on  card-shuffling, 
and  on  the  difficulty  of  coding  “fnrandi” 
in  Pascal,  are  welcome.  ••] 

Footnotes 

1  STUD  POKER  by  Jerry  White,  published  by 
Dynacomp  Inc.,  Rochester,  NY. 

2  BRIDGE  2.0  (author  unknown),  published  by 
Dynacomp  Inc.,  Rochester,  NY. 

3  CASINO  BLACKJACK  by  S.  Silverman,  pub¬ 
lished  by  Manhatten  Software,  Pacific  Palisades, 
CA. 


Listing  3 

-(Pascal  fragment  illustrating  card  shuffling  as  done  in  Dyna- 
comp’s  BRIDGE  2.0  for  Atari.  A  deck  is  permuted  by 
sweeping  from  high  end  to  low,  swapping  the  rightmost 
unshuffled  card  with  a  random  lower  unshuffled  card.  )- 

type  card  =  1.  .52; 

deck  =  array  [card]  of  card; 

procedure  shuffle(  var  d:deck  ); 

DDJ’s  responsive  readership 
can  give  you  invaluable  feedback 

procedure  swap(  var  a,b  :  card  ); 

on  your  ideas  and  innovations. 

Find  out  how  you  can  reach  them 

var  t:  card; 

by  contacting  us  at: 

begin 

Dr.  Dobb’s  Journal 

t  :=a;a  :=b;  b  :=t 

P.O.  Box  E 

end  -(swap)- ; 

Menlo  Park,  CA  94025 

var  r,j  :  card; 
begin  -[  shuffle }- 

for  j  :=52  downto  1  do 
begin 

r:=fnrandi(j);-[note  declining  limit} 
swap(deck[r]  ,deck[j] ) 

end 

end  -[shuffle]- ; 

(415)323-3111 

42 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


Of  Interest 


by  Dave  Cortesi 


Two  Useful  Workshops 

.  . .  which  might  interest  a  few  read¬ 
ers.  The  National  Bureau  of  Standards 
will  hold  a  three-day  working  seminar  on 
the  measurement  of  electromagnetic 
interference  in  Boulder,  Colorado  August 
25-27.  The  seminar  appears  to  address 
the  measurement  methods  needed  to  cer¬ 
tify  a  new  computer  to  the  FCC.  To  regis¬ 
ter  at  this  late  date,  you’d  better  call  the 
organizer,  M.  Gerald  Arthur. 

You’ve  more  time  to  prepare  for 
what  Virginia  Tech  claim  to  be  very  pop¬ 
ular  workshops  on  microcomputer  inter¬ 
facing.  Each  three-day  workshop  has  the 
participants  designing  and  testing  actual 
hardware.  The  titles  and  dates  are:  Digital 
Electronics  for  Automation  and  Instru¬ 
mentation,  Oct.  26-28;  Microcomputer 
Interfacing  and  Programming  with  the 
Z80/8085,  Oct.  29-31;  and  Scientific 
Instrument  Automation  and  Interfacing 
with  the  TRS-80,  Nov.  2-4. 

MUMPS  for  8080  and  Apple 

It  took  heroic  restraint  to  make  a 
straight  headline  out  of  the  acronym 
MUMPS,  but  the  product  is  earnest 
enough.  MUMPS  is  a  language  and  operat¬ 
ing  system  that  began  life  as  one  of  the 
earliest  serious  applications  of  minicom¬ 
puters  (remember  them?).  The  national 
MUMPS  Users’  Group  claims  that  since 
the  language  was  made  an  ANSI  standard 
in  1977  it  “has  been  used  for  virtually 
all  types  of  decision  support . .  .  and  in¬ 
formation  systems,”  although  its  heaviest 
use  remains  in  the  medical  arena  where  it 
began. 


The  School  of  Medicine  at  UC  Davis 
has  been  distributing  successive  versions  of 
an  ANSI-standard  implementation  of 
MUMPS  for  the  8080  CPU  and  CP/M  for 
some  time  now.  They  sent  us  a  compari¬ 
son  chart  that  shows  the  latest  version 
running  two  orders  of  magnitude  faster 
than  the  first  version,  so  they  are  working 
hard.  Now  they  have  set  up  a  Users’ 
Group  for  8080  MUMPS.  Members  will 
get  automatic  updates  of  the  system  and 
a  newsletter  for  $93  a  year.  To  join,  con¬ 
tact  Richard  F.  Walters,  Ph.D. 

The  same  developers  have  prepared  a 
version  of  8080  MUMPS  on  Apple  disks, 
for  use  with  an  Apple  with  Z80  Softcard. 
Larry  L.  Stonebumer,  M.D.  is  handling 
the  distribution  of  this  version. 

Small  David  Selects  Stones, 

Eyes  Giant 

That’s  the  image  that  entered  our 
mind  on  reading  a  release  from  Tandy 
Corporation.  They’ve  announced  three 
software  products  that  place  the  TRS-80 
Model  II  in  head-on  competition  with 
products  of  IBM’s  Data  Processing  Divi¬ 
sion.  The  least  is  a  diskette  reformatter 
that  lets  the  Model  II  work  with  diskettes 
formatted  for  IBM’s  3741,  which  “in 
essence  . . .  delivers  the  . .  .  equivalent  of 
an  IBM  workstation  for  substantially  less 
than  the  cost  of  IBM  equipment.” 

The  second  product  is  a  communica¬ 
tions  program  which  provides  Binary  Syn¬ 
chronous  Communications  using  the 
protocol  of  the  IBM  2780  and  3780  re¬ 
mote  batch  workstations.  That  protocol 
is  something  of  a  de  facto  standard,  being 


supported  by  DEC  (and  by  OASIS;  see 
last  issue)  as  well  as  by  IBM’s  batch  oper¬ 
ating  systems.  The  real  zinger  is  a  second 
communications  package  that  lets  the 
Model  II  emulate  the  IBM  327x  display 
terminal  and  so  hook  up  to  any  of  those 
famous  initials  TSO,  CICS,  IMS,  VSPC, 
and  VM/370. 

All  three  products  are  to  be  sold 
under  a  site  license  that  allows  free  dupli¬ 
cation  within  an  installation.  This  sug¬ 
gests  that  Tandy  are  thinking  of  corpo¬ 
rate  customers  that  might  buy  truckloads 
of  Model  II  machines.  The  whole  an¬ 
nouncement  presents  an  interesting  chal¬ 
lenge  not  only  to  IBM  but  to  a  number  of 
companies  that  make  327x  look-alike 
terminals.  Interesting  times. 

HP  and  the  68000 

Hewlett-Packard  has  announced  a 
new  desk-top  computer,  the  9826,  which 
is  the  first  commercial  product  we’ve 
seen  to  use  the  M68000  CPU  chip.  The 
machine  resembles  the  80  series  in  size 
and  styling,  with  a  5”  diskette  drive  in 
place  of  the  tape  unit.  The  CPU  is  an 
M68000  operating  at  8MHz;  storage  starts 
at  64KB  and  can  go  to  512KB.  Your 
choice  of  BASIC,  Pascal,  or  something 
called  HPL  is  built  in.  The  7-inch  CRT 
has  graphics  resolution  of  400  by  300 
pixels.  The  diskette  holds  264  KB,  and 
that’s  unique:  the  mass  storage  might  be 
smaller  than  the  RAM!  A  number  of 
interface  cards  are  to  be  available.  The 
system  costs  around  $9000,  depending  on 
options. 

Some  Information  Sources 

Press  releases  told  us  of  a  few  unique 
sources  of  information  this  month.  We 
hold  back  only  the  title  of  the  book  that 
claims  to  show  us  how  astrology  can  di¬ 
rect  our  financial  decisions;  after  we’ve 
raided  the  stock  market  under  its  guid¬ 
ance  we’ll  let  you  in  on  it. 

Datapro  have  surveyed  4200  comput¬ 
er  users  to  find  out,  in  detail,  how  they 
like  their  systems.  The  report  includes  re¬ 
sponses  on  micro-based  systems  and  it  is 
interesting  to  compare  the  responses  of 
micro  users  to  those  of  minicomputer  and 
mainframe  users.  Here’s  a  quote  from  the 
report:  “We  asked  the  users,  ‘Have  you 
integrated  word  processing  functions  on 
this  computer?’  A  surprising  55%  of  the 
. . .  personal . . .  computer  users  said 
‘yes.’  Twenty- five  percent  of  the  mini¬ 
computer  users  indicated  that  they  had 


Hewlett -Packard’s  9826  uses  the  M68000  CPU. 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


43 

357 


integrated  word  processing  functions  on 
their  system,  as  did  1 1  percent  of  the 
mainframe  users.”  Many  other  illuminat¬ 
ing  differences  can  be  found;  anyone  en¬ 
gaged  professionally  with  micros  might 
find  the  report  worth  its  $25  price. 

InfoPro  Systems  publishes  “the  only 
industry-wide  directory  of  UNIX  and  C 
products.”  The  sample  they  sent  us  lists 
thirty-odd  contact  points  for  suppliers 
and  user  groups,  each  annotated  with 
comments  having  a  tone  not  unlike  that 
used  in  this  column.  Clearly  an  outstand-j| 
ing  buy  at  $18  for  a  year’s  subscription. 
Only  thing,  the  release  neglects  to  state 
how  many  issues  a  year’s  subscription 
includes. 

An  organization  called  Associated 
Technology,  in  an  admirably  succinct 
release,  offers  a  free,  7-page  report  on 
careers  in  consulting  for  engineers  and 
computer  scientists.  The  report  is  said  to 
be  “devoted  to  dispelling  common  mis¬ 
conceptions  and  identifying  successful 
career  paths.” 

The  IEEE  Computer  Society  has  re¬ 
leased  a  catalog  of  the  300  books  and  re¬ 
ports  they  publish.  The  catalog  displays 
a  feast  of  technical  know-how;  it’s  great 
reading  for  catalog  lovers.  Write  to  the 
Computer  Society  Press  and  request  the 
“1981  Pubs  Catalog.” 

Books  on  the  68xx  Machines  .  .  . 

Group  Technology,  Ltd.  have  pub¬ 
lished  three  books  by  Andrew  Staugaard, 
Jr.,  a  man  who  certainly  must  know  the 
6800  series  of  chips  very  well  indeed. 
The  three  titles  (with  order  numbers  and 
prices  in  parens)  are;  6809  Microcomput¬ 
er  Programming  and  Interfacing  With  Ex¬ 
periments  (21798,  $13.95),  6801,  68701, 
6803  Microcomputer  Programming  and 
Interfacing  (21726,  $13.95),  and  How  to 
Program  and  Interface  the  6800  (21684, 
$15.95). 

. .  .  and  Hardware  for  Them 

A  very  satisfying  number  of  an¬ 
nouncements  relating  to  6800  systems 
and  the  SS-50  bus  came  in  this  month  (so 
how  come  nobody  submits  articles  on 
these  fine  machines?).  Aside  from  the 
books  mentioned  above,  we  heard  of  a 
color  graphics  board,  a  universal  inter¬ 
face,  and  a  64K  RAM  card. 

Percom  have  produced  a  color  video 
display  generator  for  SS-50  and  SS-50C 
systems.  The  card  is  memory-mapped,  so 
they  call  it  the  ColoRAMa;  we’ll  forgive 


them  for  that  because  it  sounds  like  a 
very  capable  device.  It  is  claimed  to  sup¬ 
port  1 1  different  display  formats  yield¬ 
ing  resolutions  from  64x64  to  256x192 
pixels.  It  can  be  mapped  to  any  address 


The  Percom  “ColoRAMa”  color  graphics  board 
for  SS-50  systems. 

space  bank,  has  provision  for  a  TV  modu¬ 
lator,  a  cassette  interface  (!),  and  a  2K 
EPROM.  The  manual  includes  both  6800 
and  6809  listings  of  a  “display  operating 
system.”  The  package  is  priced  at  $219 
with  1KB  of  display  memory. 

The  “Universal  Interface  Card”  is 
aimed  at  homebrewers.  It  is  a  bare  I/O 
card  designed  for  the  SS-50C  I/O  bus, 
with  circuit  pads  provided  for  an  on-card 
voltage  regulator,  connectors,  and  two 
ACIA  or  one  PIA  chip.  The  board  with  a 
set  of  bus  connectors  costs  $17  from 
Quality  Research. 

Gimix  have  added  an  unusual  64KB 
RAM  board  to  their  line  of  SS-50C  prod¬ 
ucts.  The  board  uses  very  low-power 
CMOS  chips  and  contains  a  battery  for 
backup  so  that  data  is  retained  when  the 
system  is  powered  down.  The  board  is 
claimed  to  be  capable  of  operation  at 
2MHz  with  no  wait  states.  It  can  be  write- 
protected  by  a  switch  and  so  used  to 
emulate  a  PROM  in  development.  The 
price  is  $1088,  quite  reasonable  for  64K 
of  static  storage. 

Software  for  OASIS  . .  . 

Phase  One  Systems  who  have  been 
cranking  out  new  products  monthly  for 
so  long  it’s  getting  indecent,  have  added 
FORTH  to  the  line  of  languages  support¬ 
ed  by  OASIS.  They  claim  that  their  ver¬ 
sion  is  based  on  FIG  standards,  and  the 
“data  management  functions  can  be 
handled  at  the  operating  system  level.” 
They  do  not  say  that  the  dictionary  is 
sharable  and  re-entrant,  so  presumably 
each  user  has  his  or  her  own  copy,  a 
minor  disadvantage. 


Phase  One  also  wrote  to  tell  us  that, 
“avoiding  possible  confusion  with  a  main¬ 
frame  package  of  the  same  title,”  their 
relational  database  system  has  been  re¬ 
named  from  RDBMS  to  CONTROL. 
Then  Quaydata  wrote  to  tell  us  that  they 
produce  CONTROL,  and  that  they’ve 
added  a  COBOL  Program  Generator  to 
fthe  BASIC  Program  Generator  it  already 
had.  With  the  package,  they  claim,  “a 
typical  application  requires  about  40  min¬ 
utes  from  screen  design  to  compiled  and 
running  object  code.”  Bet  it  isn’t  the  Last 
One,  either. 

Finally,  the  OASIS  Users’  Group  no¬ 
tified  us  that  they’ve  compiled  their  first 
volume  of  public  domain  software.  Mem¬ 
bership  is  $35  a  year. 

. .  .  And  for  Five  Other  Systems 

For  Hewlett-Packard  desktop  ma¬ 
chines:  Structured  Software  Systems  has 
a  line  of  BASIC  enhancers  for  the  various 
9835  and  9845  models,  including  a  CRT 
to  printer  dump,  a  cross  referencer,  a 
memory  mapper,  and  others.  Prices  range 
from  $150  to  $300. 

For  CP/M  systems:  there  are  several 
un-eraser  programs  available,  including 
one  from  EUiam  Associates.  But  that  or¬ 
ganization  has  thought  into  the  problem 
more  deeply  and  has  come  up  with 
CONFLICT,  which  checks  out  the 
present  state  of  all  disk  blocks  of  an 
erased  file,  reporting  where  the  erased 
space  is  now  part  of  an  active  file  and 
where  it  has  been  part  of  another  erased 
file.  CONFLICT  is  $35,  or  $60  with 
Elliam’s  UNERA  command. 

For  TRSDOS:  Allen  Ashley  says  his 
PDS  assembly  language  development  sys¬ 
tem  is  now  complete.  It  includes  a  relo¬ 
cating  macro  assembler,  a  linkage  editor, 
an  editor,  a  trace  and  debug  monitor,  and 
a  number  of  utilities.  One  caution:  Allen 
has  plumped  for  extended  Intel  mnemon¬ 
ics  rather  than  Zilog  ones.  Some  people 
care  about  that,  others  don’t.  The  whole 
package  seems  reasonably  priced  at  $99. 

For  OSI  and  the  OS65D3  system: 
FBASIC  compiles  an  integer  subset  of  the 
OSI- Microsoft  BASIC  language  to  true 
6502  machine  code.  Pegasus  Software,  its 
developers,  call  it  the  “first  true  compil¬ 
er”  for  the  OSI  systems.  The  compiler  is 
disk -based  and  can  compile  programs 
larger  than  the  available  storage.  It  is  said 
to  support  WHILE  loops,  and  GOTOs  and 
GOSUBs  to  absolute  addresses,  an  idea 
we  find  repulsive.  Anyway,  the  compiler 
costs  $155. 


44 

358 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


For  Your  Personal 


REFERENCE 

COLLECTION 


Thousands  of  dollars’  worth  of 
microcomputer  information  and  listings! 


Dr.  Dobb’s  Journal  Vol.  V  -  All  the  ground-breaking  issues  from  1980  in  one  volume!  Sys¬ 
tems  software  reached  a  new  level  with  the  advent  of  CP/M,  chronicled  herein  by  Gary  Kildall  and  others 
( DDJ's  all-CP/M  issue  sold  out  within  weeks  of  publication).  Software  portability  became  a  topic  of  great¬ 
er  import,  and  DDJ  published  Ron  Cain’s  immediately  famous  Small- C  compiler  —  reprinted  here  in  full! 

Contents  include:  The  Evolution  of  CP/M,  a  CP/M-Flavored  C  Interpreter,  Ron  Cain’s  C  Compiler  for  the 
8080,  Further  with  Tiny  BASIC,  a  Syntax- Oriented  Compiler  Writing  Language,  CP/M  to  UCSD  Pascal 
File  Conversion,  Runtime  Library  for  the  Small-C  Compiler,  and,  as  always,  even  more ! 


For  Heath/Zenith  H/Z-89  systems: 
Zenith  sent  us  two  releases.  In  the  first, 
they  said  that  the  price  of  the  Zenith 
Electronic  Typing  word  processing  pack¬ 
age  was  to  be  reduced  from  $395  to 
$295.  In  the  second,  they  announced  that 
both  Zenith  and  Heath  would  be  market¬ 
ing  MicroPro’s  WordStar  for  the  x89.  The 
rest  of  the  MicroPro  line  -  MailMerge, 
DataStar,  SuperSort  —  will  also  be  avail¬ 
able  from  Heath  and  Zenith  later  this 
year.  BSj 


Contact  Points 

M.  Gerald  Arthur,  Electromagnetic  Fields 
Division,  National  Bureau  of  Standards, 
Boulder,  CO  80303 ;  (303)  497  -  3603 . 

Allen  Ashley,  395  Sierra  Madre  Villa,  Pasa¬ 
dena  CA  91107;  (213)  793-5748. 

Associated  Technology,  POB  19,  Manches¬ 
ter,  TN  37355; (205) 837-4718. 

Computer  Society  Press,  POB  639,  Silver 
Springs,  MD  20901. 

Datapro  Research  Corp.,  1805  Underwood 
Blvd.,  Delran,  NJ  08075. 

EUiam  Associates,  24000  Bessemer  Street, 
Woodlands  Hills,  CA  91367. 

Gimix,  Inc.,  1337  West  37th  Place,  Chicago, 
IL  60609;  (312)  927-5510. 

Group  Technology,  Ltd.,  POB  87,  Check, 
VA  24072;  (703)  651-3153. 

InfoPro  Systems,  POB  33,  East  Hanover, 
NJ  07936; (201)  625-2925. 

MUMPS  Users’  Group,  1001  Connecticut 
Ave.  N.,  Suite  800,  Washington,  DC  20036. 
OASIS  Users’  Group,  POB  2400,  Santa  Bar¬ 
bara,  CA  93 1 20 ;  (805)  965  -0265 . 

Pegasus  Software,  POB  10014,  Honolulu, 
Hawaii  96816. 

Percom  Data  Company,  211  N.  Kirby,  Gar¬ 
land,  TX  75042;  (214)  272-3421 ;  toll  free 
orders  to  800-527-1592. 

Phase  One  Systems,  7700  Edgewater  Drive, 
Suite  830,  Oakland,  CA  94621;  (415)  562- 
8085. 

Quality  Research  Company,  POB  7202, 
Spokane,  WA  99207. 

Quaydata  Inc.,  2415  15th  Street,  Suite  301, 
Denver,  CO  80202;  (303)  433-5476. 

Larry  L.  Stonebumer,  M.D.,  280  Hospital 
Circle  #202,  Westminster,  CA  92683. 
Structured  Software  Systems,  Inc.,  Box 
1072  Irick  Road,  Mt.  Holly,  NJ  08060; 
(609)  267-1616. 

Dr.  Lindy  Leffel,  C.E.C.,  Virginia  Tech, 
Blacksburg,  VA  24061 ;  (703)  961  -5241 . 
Richard  F.  Walters,  PhJD.,  Department  of 
Community  Health,  University  of  Califor¬ 
nia,  Davis,  CA  95616. 

Zenith  Data  Systems,  1000  Milwaukee  Ave¬ 
nue,  Glenview,  IL  60025;  (312)  391-8181. 


Dr.  Dobb's  Journal  Vol.  I  -  The  material  brought  to¬ 
gether  in  this  volume  chronicles  the  development  in  1976 
of  Tiny  BASIC  as  an  alternative  to  the  “finger  blistering" 
front-panel  machine-language  programming  which  was 
then  the  only  way  to  do  things.  This  is  always  pertinent 
for  bit  crunching  and  byte  saving,  language  design  theory, 
homebrew  computer  construction  and  the  technical 
history  of  personal  computing. 

Topics  include:  Tiny  BASIC,  the  (very)  first  word  on 
CP/M.  Speech  Synthesis,  Floating  Point  Routines,  Timer 
Routines,  Building  an  IMSAl,  and  more. 


Dr.  Dobb's  Journal  Vol.  Ill  -  The  microcomputer  in¬ 
dustry  entered  its  adolescence  in  1978.  This  volume  bnngs 
together  the  issues  which  began  dealing  with  the  6502,  with 
mass-market  machines  and  languages  to  match.  The  authors 
began  speaking  more  in  terms  of  technique,  rather  than  of 
specific  implementations,  because  of  this  they  were  able 
to  continue  laying  the  groundwork  industry  would  follow. 
These  articles  relate  very  closely  to  what  is  generally 
available  today. 

Languages  covered  in  depth  were  SAM76.  Pilot,  Pascal  and 
Lisp,  in  addition  to  RAM  Testers,  S-100  Bus  Standard 
Proposal,  Disassemblers,  Editors  and  much,  much  more. 


Dr.  Dobb's  Journal  Vol.  II  -  1977  found  DDJ  still 
on  the  forefront.  These  issues  offer  refinements  of  Tiny 
BASIC,  plus  then  state-of-the-art  utilities,  the  advent  of 
PILOT  for  microcomputers  and  a  great  deal  of  material 
centenng  around  the  Intel  8080,  including  a  complete 
operating  system.  Products  just  becoming  available  for 
reviews  were  the  H-8,  KIM- 1,  MITS  BASIC,  Poly  Basic 
and  NIBL. 

Articles  about  Lawrence  Livermore  Lab’s  BASIC,  Alpha- 
Micro,  String  Handling,  Cyphers,  High  Speed  Interaction, 
I/O,  Tiny  Pilot  &  Turtle  Graphics,  many  utilities,  and 
even  more. 


Dr.  Dobb's  Journal  Vol.  IV  -  This  volume  heralds  a 
wider  interest  in  telecommunications,  in  algorithms,  and  in 
faster,  more  powerful  utilities  and  languages,  innovation  is 
still  present  in  every  page,  and  more  attention  is  paid  to  the 
best  ways  to  use  processors  which  have  proven  longevity  - 
primarily  the  8080/ Z80,  6502,  and  6800.  The  subject 
matter  is  invaluable  both  as  a  learning  tool  and  as  a  fre¬ 
quent  source  of  reference. 

Main  subjects  include:  Programming  Problems/Solutions, 
Pascal,  Information  Network  Proposal,  Floating  Point 
Arithmetic,  8-bit  to  16-bit  conversion.  Pseudorandom 
Sequences,  and  Interfacing  a  Micro  to  a  Mainframe  - 
more  than  ever! 


YES!  □  Please  send  me  the  following  Volumes  of  Dr  Dobb's  Journal  for  $20.75  each. 


□  ALL  5  for  ONLY  $88.  a  savings  of  over  1 5  % ! 


Please  charge  my  □  Visa 

I  enclose  □  Check/money  order 

Card  # _ 


□  MasterCard  □  American  Express 

_ Expiration  Date _ 


Signature  . 

Name _ 

City _ 


.  Address  _ 


-  Zip  - 


Prices  subject  to  change. 

Mail  to:  Dr.  Dobb's  Journal,  P.O.  Box  E,  Menlo  Park,  CA  94025 

Allow  6-9  weeks  for  delivery 


Vol.  I__ 
Vol  II  _ 
Vol.  Ill  _ 
Vol  IV_ 
Vol.  V_ 
ALL  5  _ 


.  x  $20.75  =  _ 
_  x  $20.75  =  _ 
_  x  $20.75  =  _ 
_  x  $20.75  =  _ 

-  x  $20.75  =  - 

-  x  $88.00  =  - 
Sub-total  $_ 


Postage  &  Handling  _ 

Must  be  included  with  order. 

Please  add  SI. 25  per  book  in  U.S. 
($1.75  each  outside  U.S.) 

TOTAL  $ _ 


Dr.  Dobb’s  Journal,  Number  58,  August  1981 


45 

359 


DrD 


For  Users  of  Small  Computer  Systems 

Number  59  September  1981  Volume  6,  Issue  9 


} 


$2.50 

($3.00  in  Canada) 


OBB'S  JOURNAL 


Special 
FORTH  Issue! 


Utilities  & 

T  utorials 

Software  Tools 


i 

i, .  .JR-k  -  *■  ■■ 

The  FORTH  Philosophy 

Kim  Harris 


A  FORTH  Assembler  for  the  6502 

William  F.  Ragsdale 

A  Screen-Oriented  Editor  in  FORTH 

Henry  Laxen 


plus: 

FORTH  Data  Base  Design, 
a  Decompiler...and  even  more! 


Dr.  Dobb  s  Journal 

For  Users  of  Small  Computer  Systems  W 


September  1981  Volume  6,  Issue  9,  Number  59 


CONTENTS 


The  FORTH  Philosophy .  6 

by  Kim  Harris 

A  FORTH  Assembler  for  the  6502 .  12 

by  William  F.  Ragsdale 

Sallying  FORTH  to  Battle . 25 

by  R.  G.  Loeliger 

A  Screen -Oriented  Editor  in  FORTH . 27 

by  Henry  Laxen 

Elements  of  a  FORTH  Data  Base  Design . 42 

by  Glen  B.  Haydon 


A  FORTH  Decompiler . 48 

by  Ray  Duncan 

The  FORTH  Alternative . 57 

by  Mitchell  E.  Timin 

Letters .  4 

Of  Interest . 54 

Dr.  Dobb’s  Clinic . 60 


Publisher 
Michael  Madaj 
Editor 

Marlin  Ouverson 
Assistant  Editor 
Julie  Anton 
Contributing  Editors 
Dave  Caulkins 
Dave  Cortesi 
Kim  Harris 


Art  Director 
Clifford  West 
Artist 

Barbara  Ruzgerian 
Typesetter 
Renny  Wiggins 
Proofreader 
Nancy  Heubach 


Marketing  Director 
Craig  S.  Harper 
Advertising  Sales 
Kent  Safford 
Circulation  Manager 
Peter  Clark 
Circulation  Assistant 
Leah  Dansby 
Business  Manager 
Maureen  Christine 


editorial: 


Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per 
year  by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real, 
Menlo  Park,  CA  94025.  Second  class  postage  paid  at  Menlo  Park, 
California  94025  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  94025. 


©1981  by  People’s  Computer  Company  unless  otherwise  noted  on 
specific  articles.  All  rights  reserved. 


Dr.  Dobb’s  is  pleased  to  present  this  all- FORTH  issue. 
The  material  should  prove  of  interest  both  to  FORTH  fol¬ 
lowers  and  to  the  uninitiated.  We  believe  it  presents  a  round¬ 
ed  viewpoint,  although  as  one  of  our  frequent  contributors 
noted,  those  who  do  not  like  the  language  lose  interest  quick¬ 
ly,  also  losing  the  desire  to  express  any  opinion  on  it. 

Not  so  the  FORTH  fans!  During  early  planning  stages, 
we  noted  that  many  FORTH  people  possess  a  trait  in  com¬ 
mon:  they  proselytize.  They  are  fanatic,  born-again  program¬ 
mers.  As  work  progressed  it  became  clear  that  these  folks 
realize  their  own  addiction. 

Is  this  attitude,  this  conviction  of  rightness,  a  defense 
mechanism  for  the  benefit  of  members  of  the  C,  Pascal,  or 
other  language  community?  Or  is  it  the  natural  result  of  being 
in  on  a  good  thing?  To  answer  that  question  would  be  an  invita¬ 
tion  to  mayhem.  Study  this  issue  well  and  decide  for  yourself ! 

I  mention  all  this  merely  to  outline  the  peculiar  emo¬ 
tional  tone  of  the  FORTH  movement.  It  is  something  which 
inspires  strong  feelings  for  or  against.  There  will  be  many 


more  important  articles  to  come  on  the  topic.  Some  will  em¬ 
phasize  the  strengths,  and  others  the  weaknesses,  of  FORTH. 
Each  will  shed  a  little  more  light  for  the  reader  to  more  clear¬ 
ly  discern  his  own  interest,  to  better  understand  the  utility 
of  software  written  in  FORTH. 

There  has  always  been  a  plethora  of  voices  willing  to 
criticize  what  they  feel  is  wrong  with  other  people’s  thoughts 
on  FORTH,  but  very  few  who,  as  Doc  sometimes  says,  are 
willing  to  “put  their  foot  where  their  mouth  is.”  Critics 
abound,  while  competent  authors  such  as  this  month’s  con¬ 
tributors  come  only  in  small  handfuls.  We  do  not  claim  this 
material  is  a  definitive  study  of  FORTH,  for  there  is  no  uni¬ 
fied,  definitive  opinion  of  the  language.  Some,  in  fact,  do  not 
even  believe  it  is  a  language! 

A  few  excellent  articles  were  received  which  are  not  in¬ 
cluded  in  this  issue  simply  because  space  did  not  allow  it. 
We  will  be  using  them  as  “seed”  material  in  what  we  hope 
will  become  an  ongoing  dialogue  and  exploration  of  FORTH. 
The  subject  is  not  closed!  -  MDO 


Subscription  Rates:  $25  per  year  within  the 
United  States;  $44  for  first  class  to  Canada  and 
Mexico;  $62  for  airmail  to  other  countries. 
Payment  must  be  in  U.S.  dollars,  drawn  on  a 
U.S.  bank. 

Writer’s  Guidelines:  All  items  should  be  typed, 
double-spaced  on  white  paper.  Listings  should 
be  produced  by  the  computer,  using  a  fresh, 
dark  ribbon  on  continuous  white  paper.  Please 
avoid  printing  on  perforations.  Payment  is  in 
contributor’s  copies.  Requests  to  review  galleys 
must  accompany  the  manuscript  when  it  is 
first  submitted.  Authors  may  receive  a  copy  of 
the  complete  writer’s  guidelines  by  sending  a 
self-addressed,  stamped  envelope. 


Donating  Subscribers  Contributing  Sub¬ 
scriber:  $50/year  ($25  tax  deductible).  Retain¬ 
ing  Subscriber:  $75/year  ($50  tax  deductible). 
Sustaining  Subscriber:  $  100/year  ($75  tax  de¬ 
ductible).  Lifetime  Subscriber:  $1000  ($800 
tax  deductible).  Corporate  Subscriber:  $500/ 
year  ($400  tax  deductible,  receives  five  one- 
year  subscriptions). 

Contributing  Subscribers:  Eric  H.  Johnson, 
Jerry  Horn,  Edward  W.  Carr,  Steven  Fisher, 
Thomas  H.  Grohne,  G.  V.  Elkins,  Robert  M. 
Connors,  William  J.  McEown,  Robert  C. 
Luckey,  Kim  Leary,  Robert  N.  Stabler,  DeWitt 
S.  Brown,  John  B.  Palmer,  E.  Glion  Curtis,  Jack 
Miller,  Burks  A.  Smith,  Transdata  Corporation, 
Mark  Ketter,  John  W.  Campbell,  Friden  Mail¬ 


ing  Equipment,  Howard  E.  Decker,  Jim  Wilson, 
Frank  Lawyer.  Retaining  Subscribers:  Osamu 
Shimizu,  Scott  B.  Guthery,  Robert  L.  Edens, 
Titus  Purdin.  Sustaining  Subscriber:  Gordon 
Eubanks,  Jr.  Lifetime:  Michael  S.  Zick. 

Foreign  Distributors  UK  &  Europe:  LP  En¬ 
terprises,  8/1 1  Cambridge  House,  Cambridge 
Road,  Barking,  Essex,  1G11  8NT,  England 
(Tel.  01-591-6511,  TLX  892395).  Hofacker- 
Verlag,  Tegernseer  Strass  18,  D-8150  Holz- 
kirchen,  West  Germany.  Asia  &  Australia: 
Computer  Store,  POB  31-261,  22B  Milford 
Road,  Milford,  Auckland  9,  New  Zealand. 
ASCII  Publishing  Co.,  Ltd.,  Aoyama  Building 
5F,  5-16-1  Minami  Aoyama,  Minato-ku, 
Tokyo  107,  Japan.  _ 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 
362 


3 


THE  FORTH  PHILOSOPHY 


The  Abstract 

FORTH  is  an  unconventional  software  package  which  is 
easily  misunderstood.  That  is  because  it  is  based  on  a  philoso¬ 
phy  which  is  moderately  different  from  that  of  traditional 
programming  systems.  This  article  describes  a  set  of  goals, 
assumptions,  and  techniques  which  are  practiced  by  most  ex¬ 
perienced  FORTH  programmers.  Part  I  discusses  the  philoso¬ 
phy  and  part  II  (to  be  published  in  a  following  issue  of  DDJ) 
relates  FORTH’s  implementation  of  this  philosophy.  FORTH 
is  described  as  a  unified  approach  to  programming  which  pro¬ 
vides  a  complete  environment  for  the  execution  or  the  devel¬ 
opment  of  programs.  Its  goals  are  high  quality,  simple,  and 
general  software  systems  which  can  solve  a  wide  range  of  sys¬ 
tems  and  applications  problems. 

The  Introduction 

FORTH,  another  computer  software  package,  has  recent¬ 
ly  come  to  the  attention  of  the  small  computer  industry.  DDJ 
has  published  many  articles  in  the  last  two  years,  and  there 
was  a  big  “splash”  in  the  August  1980  issue  of  Byte  magazine. 
A  steady  stream  of  articles  has  followed  in  several  magazines. 
Software  products  are  available  for  a  large  number  of  hardware 
processors  from  a  variety  of  vendors.  They  range  from  cheap, 
hobby-grade  systems  to  sophisticated,  professional  systems. 
It  is  quite  unconventional  and  therefore  easily  misunderstood. 
Outrageous  claims  have  been  made  about  FORTH: 

Ten  times  better  programmer  productivity  compared 
to  conventional  software  systems 
Fast  execution:  90%  to  50%  of  machine  language 
Small  programs:  memory  size  is  1/2  that  required  by 
equivalent  assembly  language  programs 
Programs  are  transportable,  independent  of  the  hard¬ 
ware  processor 

FORTH  has  been  called  many  things: 

A  language  (both  high  and  low  level) 

An  operating  system 
An  interpreter  and  a  compiler 
A  religion,  a  cult,  and  an  addiction 
Unreadable,  hard  to  learn,  and  only  for  geniuses 
A  quantum  jump  in  software  evolution,  and  a  mistake 

It  can  be  all  of  these  things!  This  article  will  attempt  to 
explain  this  enigma  called  FORTH  in  terms  of  its  goals,  trade¬ 
offs,  and  achievements.  Many  statements  are  the  opinion  of 
the  author;  they  describe  his  current  view  of  FORTH. 

FORTH  was  invented  in  the  late  1960’s  by  Charles  Moore, 
who  was  trying  to  increase  his  own  productivity  as  an  applica¬ 
tions  programmer.1  It  evolved  out  of  his  dissatisfaction  with 
conventional  approaches.  It  is  a  unified  approach  to  develop¬ 
ing  software  which  solves  practical  problems.  Its  “rules”  are 
few  and  are  applied  uniformly  throughout  the  system.  An  ex¬ 
ample  of  the  unified  aspect  of  FORTH  is  its  use  of  a  single  lan¬ 
guage  to  bridge  the  gap  between  some  hardware  and  an  appli¬ 
cation.  The  conventional  approach  is  to  use  several  languages 
which  each  span  a  small  portion  of  the  gap  (see  Figure  1). 

A  FORTH  software  system  also  supplies  the  total  environ¬ 
ment  to  develop  or  execute  programs.  It  contains  its  own 

by  Kim  Harris 

Kim  Harris,  Forthright  Enterprises,  P.  O.  Box  50911,  Palo 
Alto,  CA  94303. 


I 


hardware 


LANGUAGE  LEVEL 

LOW  HIGH 

assembly 

language 

( . ) 

systems 

languages 

( . ) 

(e.g.,  C,  PL/M) 

general  programming 
languages 

( . . ) 

(e  g.,  FORTRAN,  PASCAL) 

application 

specific 

languages 

( . ) 

(e.g.,  APT,  PERT) 

FORTH 

( . )( . ) 

FORTH’s  FORTH’s 

assembly  high-level 

language  language 


I 

!  application 


I 


I 


Figure  1  -  The  Software  Gap 


operating  system,  interpreter  for  interactive  execution,  com¬ 
piler,  assembler,  editor,  and  utilities.  All  these  parts  are  nor¬ 
mally  resident  in  a  development  system,  and  are  written  in 
FORTH’s  own  language.  FORTH  is  both  a  usable  system  and 
a  meta  system  (i.e. ,  it  describes  itself). 

Mr.  Moore  wanted  a  simple,  general,  and  frugal  software 
system  which  would  allow  him  to  implement  a  program  in  a 
direct  way  and  would  execute  it  efficiently.  After  continuous 
refinements  during  the  last  decade,  FORTH  has  developed  a 
set  of  tradeoffs  which  benefit  a  wide  range  of  applications 
areas.  Here  is  a  list  of  areas  in  which  FORTH  has  been  used: 
Mathematical,  numerical  applications 
Systems  programs,  compilers,  operating  systems 
Scientific,  simulation  problems 
Real-time  acquisition  and  control,  robotics 
Business,  accounting 

Information  processing,  data  base  systems 
Communications,  networks 
Graphics,  image,  and  speech  processing 
Art,  music 

Because  the  system  is  “extensible”  (i.e.,  any  part  of  it 
may  be  modified),  FORTH  continues  to  evolve.  Many  varia¬ 
tions  have  been  tried.  The  better  results  are  adopted  by  the 
FORTH  community  voluntarily,  based  on  merit.  This  is 
“natural  selection”  applied  to  software.  A  voluntary  standard 
has  helped  achieve  substantial  uniformity  at  the  applications 
program  level  across  different  FORTH  implementations.2 

The  Elements  of  FORTH 

To  understand  FORTH,  one  must  look  at  two  comple¬ 
mentary  aspects.  FORTH  is  a  philosophy  and  an  implementa¬ 
tion  of  that  philosophy.  The  philosophy  gives  the  goals  and 
the  techniques  used  in  the  implementation.  It  is  easier  to  de¬ 
scribe  an  implementation  than  a  philosophy,  so  most  previous 
articles  on  FORTH  have  concentrated  on  implementation  de¬ 
tails.  But  that  is  like  knowing  how  to  build  a  clock,  and  not 
understanding  the  concept  of  time;  or  learning  what  a  needle 
and  thread  are  for,  but  not  knowing  how  to  sew.  The  philo¬ 
sophy  gives  the  “rules  of  usage”  for  FORTH,  and  it  explains 
the  rationale  behind  its  structure.  The  philosophy  applies  to 
technical  activites  (e.g.,  program  organization,  style)  and  to 


6 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 

363 


the  management  of  projects. 

Basic  Assumptions 

The  origins  of  FORTH  philosophy  are  the  Scientific 
Method  and  some  human  factors.  The  Scientific  Method  is  a 
technique  for  understanding  complex  natural  systems.  It  has 
been  used  for  hundreds  of  years,  and  a  key  element  was  a 
belief  of  ancient  Greek  philosophers.  The  method  is  iterative: 
it  is  a  never-ending  cycle  of  discovery  and  refinement.  A 
diagram  of  the  method  is  shown  in  Figure  2. 


It  first  studies  a  natural  system  and  gathers  observations 
about  its  behavior.  Then  the  observations  are  modeled  to  pro¬ 
duce  a  theory  about  the  natural  system.  Next,  analysis  tools 
are  applied  to  the  model  which  produces  predictions  about  the 
real  system’s  behavior.  Experiments  are  devised  to  com¬ 
pare  actual  behavior  to  the  predicted  behavior.  The  natural 
system  is  again  studied,  and  the  model  is  revised.  The  goal  of 
the  method  is  to  produce  a  model  which  accurately  predicts 
all  observable  behavior  of  the  natural  system.  But  it  is  likely 
that  several  different  models  will  meet  the  goal.  Which  model 
should  be  chosen?  The  answer  has  always  been,  “Choose  the 
simplest!”  This  is  the  principle  of  “parsimony”: 

Given  two  adequate  theories, 
the  “correct”  one  is  the  simpler. 

This  principle  is  at  the  heart  of  FORTH’s  philosophy.  From 
the  Scientific  Method,  FORTH  has  borrowed  the  following 
concepts: 

Specialized  tools 

Modeling  to  understand  complex  systems 
Simplicity  to  guide  decisions 
Repetition  to  achieve  goals. 

A  software  development  project  attempts  to  solve  a  prob¬ 
lem  by  producing  a  solution  which  includes  a  software  system. 
Any  acceptable  solution  must  meet  a  set  of  functional  require¬ 
ments  and  a  set  of  constraints.  Constraints  are  negative  re¬ 
quirements  (e.g.,  compatibility,  performance,  interface  specifi¬ 
cations).  The  more  requirements  a  project  has,  the  more  diffi¬ 
cult  it  will  be  to  meet  them  all. 

A  particular  problem  has  some  fixed  requirements  and 
many  flexible  ones  (i.e,,  unspecified  or  loosely  specified). 
When  a  system  gets  designed  for  execution  on  a  computer, 
additional  constraints  must  be  imposed  (e.g.,  sequential  execu¬ 
tion,  control  structures).  Additional  constraints  are  imposed 
when  it  is  implemented  (e.g.,  finite  resources,  discrete  arith¬ 
metic).  These  constraints  are  “artificial”  in  that  they  did  not 
come  with  the  original  problem. 

It  is  important  not  to  impose  any  more  artificial  con¬ 


straints  than  necessary  in  order  to  aid  productivity.  Then  more 
room  is  left  for  tradeoffs  which  can  produce  a  more  desirable 
result.  These  views  come  directly  from  the  belief  that  simpli¬ 
city  is  better  than  complexity.  A  FORTH  development  system 
has  a  minimum  of  rules  (e.g.,  almost  no  syntax,  universal  con¬ 
trol  interfaces  for  executing  procedures,  general  data  interfaces 
between  procedures),  and  minimum  restrictions  (e.g.,  no  pro¬ 
hibitions,  no  impenetrable  boundaries,  little  built-in  error 
checking).  The  result  of  this  unconventional  approach  is  maxi¬ 
mum  control  by  the  programmer,  extensibility  (i.e.,  the  ability 
to  change,  add  to,  or  remove  any  part  of  the  system),  and 
transportability  (i.e.,  programs  are  independent  of  the  hard¬ 
ware,  except  for  resource  needs). 

During  a  development  project,  many  decisions  must  be 
made  (e.g.,  tradeoffs  between  speed  and  size,  the  user’s  inter¬ 
face,  robustness).  Wiser  decisions  can  be  made  if  we  could 
know  the  relative  costs  of  each  solution.  Software  develop¬ 
ment  in  FORTH  seeks  first  to  find  the  “simplest  solution  to  a 
given  problem.”  This  is  done  by  implementing  selected  parts 
of  the  problem  separately  and  by  ignoring  as  many  constraints 
as  possible.  Then  one  or  a  few  constraints  are  imposed  and  the 
program  is  modified.  Comparing  the  modified  program  with 
the  original  provides  an  easy  measure  of  the  cost  of  those  con¬ 
straints  or  tradeoffs.  For  example,  in  a  data  base  storage-and- 
retrieval  application,  if  a  particular  user  interface  (i.e.,  com¬ 
mand  language)  “costs”  10%  more  than  the  simplest  solution, 
it  may  be  worth  the  price.  But  if  it  costs  200%  more,  a  wise 
manager  may  look  for  a  less  costly  alternative.  In  traditional 
software  development,  the  result  is  usually  the  prototype  — 
the  first  and  only  system  produced.  No  cost  tradeoffs  are 
available,  so  poor  decisions  are  unknowingly  but  routinely 
made. 

Considering  human  factors,  the  faster  the  repetition,  the 
faster  we  learn.  In  a  programming  project,  many  small  deci¬ 
sions  must  be  made.  If  you  could  quickly  determine  how  good 
each  was,  you  could  make  better  decisions  and  be  more  pro¬ 
ductive.  The  army  discovered  this  applied  to  rifle  training.  If  a 
soldier  shot  many  rounds  at  a  target  before  seeing  the  results, 
he  would  improve  slowly.  But  if  the  result  of  each  shot  was 
visible  immediately,  he  could  achieve  better  accuracy  than 
before  and  do  it  in  less  time.  FORTH  applies  this  principle  by 
providing  a  very  fast  development  cycle.  The  time  to  correct, 
compile,  and  test  a  module  is  typically  less  than  a  minute. 

Software  Development  Methodology 

The  software  development  cycle  is  similar  to  the  Scien¬ 
tific  Method  (see  Figure  3). 

1 .  A  problem  is  analyzed  to  determine  what  functions 
are  required  in  the  solution. 


implementation 


Figure  3 

The  Software  Development  Cycle 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 
364 


7 


2.  Decisions  are  made  about  how  to  achieve  those 
functions  with  the  available  resources. 

3.  A  program  is  written  which  attempts  to  implement 
the  design. 

4.  The  program  is  tested  to  determine  if  the  functions 
were  implemented  correctly. 

The  analysis  and  design  steps  are  applied  in  “top-down” 
order:  the  system  is  decomposed  into  inner  modules  starting 
with  the  problem  as  a  whole.  This  is  common  to  both  FORTH 
and  modern  industry  practice.  However,  FORTH  departs  from 
the  norm  for  the  implementation  and  testing  steps.  FORTH 
performs  these  in  “bottom-up”  order:  the  lowest  level 
modules  are  written  and  tested  first;  the  top  level  modules  are 
last.  This  order  has  been  demonstrated  to  be  superior  to  the 
traditional  top-down  order.  Top-down  implementation  and 
testing  requires  a  lot  of  retesting  which  wastes  time  and 
lowers  productivity.  In  order  to  test  a  top  level  module  be¬ 
fore  lower  modules  are  implemented,  “stubs”  must  be  sup¬ 
plied  for  them.  Stubs  are  modules  which  do  nothing  when 
executed.  A  previously  tested  top  level  module  must  be  retest¬ 
ed  when  stubs  are  replaced  by  fully-implemented  modules. 
With  bottom-up  order,  no  stubs  are  needed,  only  implemented 
modules  are  tested,  and  each  module  needs  to  be  verified  once. 

Another  departure  FORTH  makes  in  software  develop¬ 
ment  concerns  the  number  of  times  the  software  development 
cycle  is  followed.  Traditionally,  the  cycle  is  used  only  once,  as 
shown  in  Figure  4a.  FORTH  applies  these  iteratively,  as  shown 
in  Figure  4b. 


Schedule  Time 
4b.  Iterative  Order 


Figure  4 

Stepping  Through  the  Software  Development  Cycle 


The  technique  is  to  separate  the  required  functions  and 
constraints  of  a  problem  into  several  groups.  Each  of  the 
groups  will  be  processed  by  making  another  pass  through  the 
development  cycle.  FORTH  typically  applies  the  development 
in  three  major  stages: 

1.  Familiarization  —  select  a  small  set  of  requirements 
which  defines  a  “skeleton  problem;”  ignore  con¬ 
straints.  Consider  alternative  approaches;  select  the 
m.ost  promising.  Solve  this  skeleton  problem  to  de¬ 
termine  the  feasibility  and  difficulty  of  the  original 
problem.  An  entire  cycle  should  be  used;  the  result 
will  be  an  executable  solution.  Schedule  and  budget 


estimates  can  be  made  now. 

2.  Expansion  —  repeat  the  development  cycle  for  each 
remaining  group  of  functions  and  constraints  until 
the  whole  problem  is  solved.  Each  group  is  added  by 
modifying  the  previous  implementation;  after  each 
cycle,  the  result  is  executable. 

3.  Reduction  —  reorganize  the  solution  to  achieve  a 
higher  quality  result.  Finally,  add  initiation  and  ter¬ 
mination  functions. 

System  Structure 

Another  part  of  FORTH’S  philosophy  guides  the  structure 
of  software  systems.  It  is  a  technique  for  organizing  the  com¬ 
ponents  of  a  complicated  model.  A  complex  system  should  be 
decomposed  into  simpler  systems.  The  components  of  a  model 
or  program  are  called  “modules.”  Each  module  should  consist 
of  smaller,  simpler  modules  (down  to  some  limit).  Thus,  a  sys¬ 
tem  is  a  hierarchical  collection  of  modules.  This  process  of  de¬ 
composition  is  common  practice  in  the  computing  industry, 
but  there  are  wide  differences  in  the  organization  of  the 
modules,  the  size  of  each  module,  the  interfaces  between 
modules,  and  the  limit  of  modularization.  FORTH  has  chosen 
a  structure  (see  Figure  5)  which  has  the  following  properties: 

1.  Each  module  should  contain  a  single  function. 


Figure  5  b 


8 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 

365 


You  Read 


2.  Each  module  should  have  a  simple  interface  to 
others. 

3.  The  modules  should  be  grouped  into  “layers”  of 
equal  complexity  (see  Figure  5b). 

4.  The  layers  should  be  ordered  by  complexity  such 
that  the  bottom  layer  contains  the  simplest  func¬ 
tions  and  the  top  would  have  the  most  complex. 

5.  Modules  should  be  small,  generally  not  referencing 
more  than  9  others. 

The  fifth  property  limits  the  size  of  each  module  to 
approximately  9  components.  This  comes  from  considering 
some  human  factors.  Psychologists  have  observed  that  all  peo¬ 
ple  have  a  limit  to  the  number  of  concepts  that  can  be  under¬ 
stood  at  once.  The  “psychological  juggling  limit”  is  7  ±  2  con¬ 
cepts  (for  most  people).3  This  is  the  maximum  number  of 
things  we  can  simultaneously  analyze,  trade-off,  or  optimize. 
If  software  modules  obey  this  limit,  they  will  be  simpler  and 
easier  to  understand.  In  FORTH’s  source  langauge,  this  limit 
can  be  stated  as,  “Definitions  should  be  1  to  3  lines  long.” 

This  is  in  sharp  contrast  to  modules  in  other  languages, 
which  are  typically  one  to  several  pages  long.  FORTH  occa¬ 
sionally  has  longer  modules,  but  the  longest  is  around  1 0  lines. 
A  result  of  having  small  modules  is  that  there  must  be  a  lot  of 
them  to  build  a  large,  complex  system.  A  FORTH  program 
typically  will  have  as  many  module  names  as  other  languages 
would  have  labels. 

One  benefit  of  this  structure  is  that  every  module  can  be 
defined  in  terms  of  lower-level  modules  and  ultimately  in 
terms  of  a  few  primitive  operations.  Hence  FORTH’s  compiler 
supports  this  practice  efficiently  and  directly.  FORTH  calls  a 
module  a  “word.”  Every  word  has  a  name  and  a  “definition.” 
The  lowest  words  are  called  “primitives;”  all  others  are  “secon¬ 
daries.”  The  collection  of  all  executable  words  is  called  the 
“dictionary.”  A  new  word  is  added  to  the  dictionary  by  com¬ 
piling  its  definition.  All  secondary  words’  definitions  contain 
references  to  numbers  and  previously  defined  words  only.  For 
this  to  be  practical,  the  execution  of  words  and  the  passing  of 
data  between  them  must  be  efficient  and  uniform. 

A  FORTH  development  system  has  six  major  layers  (see 
Figure  6).  These  separate  major  functional  capabilities.  Each 
layer  has  many  smaller,  internal  layers. 

1.  The  innermost  layer  is  the  available  hardware  pro¬ 
cessor. 

2.  The  nucleus  layer  implements  FORTH’s  “virtual 
machine.”  This  provides  an  environment  for  the 
execution  of  secondary  FORTH  words  (e.g.,  the 
rest  of  the  FORTH  system  and  application  pro¬ 
grams).  This  environment  is  independent  of  the 
hardware  processor.  The  nucleus  is  implemented  in 
the  instruction  set  of  the  processor.  It  is  also  possi¬ 
ble  to  implement  the  nucleus  in  microcode  or  in 
hardware. 

3.  The  interactive  layer  supports  terminal-based  activi¬ 
ties  between  the  system  and  users.  This  includes 
character  string  processing  and  a  FORTH  language 
interpreter  (called  the  “text  interpreter”). 

4.  The  extensible  layer  supports  the  addition,  modifi¬ 
cation,  or  removal  of  application  and  system  func¬ 
tions.  This  includes  FORTH  language  compilers  and 
assemblers. 


Dr.  Dobb's  Journal 

And  You  Don’t 
Subscribe?! 

Save  $13 

off  newsstand  prices  for  2  yrs. 
Save  $5  for  1  yr. 

Can  you  afford  to  miss  an  issue  with 
information  vital  to  your  interests?  As  a 
subscriber  you  can  look  forward  to 
articles  on  Small-C,  FORTH,  CP/M,  S-100, 
Compiler  optimization,  Concurrent  Pro¬ 
gramming  and  more,  delivered  right  to 
your  door.  And  you’ll  never  miss  the 
issue  that  covers  your  project. 


DR.  DOBB’S  JOURNAL 
P.O.  Box  E 

Menlo  Park,  CA  94025 


Yes!  Sign  me  up  for 

_ 2  yrs.  $47 


1  yr.  $25 


I  enclose  a  check/money  order 
Charge  my  Visa,  MasterCard, 
American  Express 
Please  bill  me  later 


Name _ 

Address. 


Credit  Card 
Account  No.. 
Signature _ 


Exp.  date 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 
366 


9 


Application  Layer(s) 


5.  The  devices  layer  supports  the  use  of  peripheral  de¬ 
vices.  Serial  devices  (e.g.,  terminals  and  printers) 
and  mass  storage  devices  (e.g.,  disks  and  tapes)  are 
supported.  FORTH  uses  a  “virtual  memory  manage¬ 
ment”  scheme  for  mass  memory  transfers. 

6.  The  application  layer(s)  contain  user  programs,  utili¬ 
ties,  tools,  etc. 

Software  Quality 

Another  important  aspect  of  FORTH’s  philosophy  is  an 
emphasis  on  quality.4  It  is  common  for  a  FORTH  programmer 
to  set  some  quality  standards  and  then  evaluate  all  programs 
against  them.  The  programs  are  revised  or  rewritten  until  the 
desired  level  of  quality  is  reached. 

For  every  problem  to  be  solved,  there  is  a  set  of  require¬ 
ments  which  any  “acceptable”  solution  must  satisfy.  There 
are  always  many  possible  solutions  which  satisfy  the  mini¬ 
mum  requirements  and  are  therefore  “acceptable.”  But  all  are 
not  equal.  One  may  be  fastest,  another  smallest,  and  yet 
another  most  understandable.  How  do  we  make  the  best 
choice?  We  evaluate  the  quality  of  each  solution  and  make 
decisions  accordingly.  The  criteria  used  to  judge  the  quality  of 
a  solution  depends  on  the  problem.  The  quality  of  a  wine,  a 
machined  part,  and  a  computer  program  have  different  mea¬ 
surement  criteria.  Computer  software  quality  criteria  is  made 
of  the  following: 

Correctness:  complete,  contained,  consistent,  and  veri¬ 
fiable. 

Performance:  execution  time,  memory  size,  compile 
time,  development  time  and  cost,  accuracy,  and 
reliability. 

Suitability:  appropriate,  usable,  and  understandable. 

Modifiability:  maintainable  and  changeable. 

The  overall  quality  of  an  entire  application  program  (or 
one  internal  module)  is  determined  by  measuring  each  cri¬ 
terion,  assigning  to  each  a  relative  importance  (i.e.,  weighting 
factor),  and  then  combining  them  like  a  “weighted  average.” 
Although  several  criteria  can  be  objectively  measured,  a  quali¬ 
ty  assessment  is  always  partly  subjective.  For  example,  an  in¬ 
terrupt  routine  usually  emphasizes  minimum  execution  time 
but  it  sacrifices  transportability,  development  time,  and  modi¬ 
fiability.  On  the  other  hand,  a  business  data  processing  applica¬ 
tion  strives  for  good  usability,  modifiability,  and  convenience, 
and  it  trades  these  for  increased  development  time,  execution 


time,  and  memory  size.  Therefore,  to  get  a  quality  software 
product,  we  must  produce  an  acceptable  solution,  judge  its 
quality,  then  repeat  this  process  until  we  produce  a  good 
product. 

Software  Tools 

Related  to  FORTH’s  emphasis  on  quality  is  its  emphasis 
on  software  tools.  A  tool  is  a  special  technique  which  performs 
a  desired  operation  on  some  material  or  information.  In  wood¬ 
working,  there  are  kinds  of  cutting  tools  (e.g.,  circular  table 
saw,  jig  saw,  router,  chisel).  Each  is  designed  for  a  particular 
combination  of  cutting  requirements.  Similarly,  many  special- 
purpose  measuring  tools  exist  (e.g.,  tape  measure,  vernier  cali¬ 
per).  In  software,  a  compiler  is  a  tool  which  translates  a  source 
language  into  an  object  langauge.  Tools  can  be  used  in  both 
the  production  and  judging  activities  of  problem  solving. 

A  tool  is  selected  to  improve  the  quality  of  the  result.  The 
more  useful  a  tool  is,  the  better.  For  one  specific  problem,  the 
most  useful  tool  will  be  one  that  closely  matches  the  problem 
and  the  desired  goal.  So  a  tool  should  be  special  purpose,  not 
general  purpose.  Tools  in  other  disciplines  are  specialized  (e.g., 
dental  instruments,  wrenches,  cooking  utensils).  Specialization 
in  software  means  that  a  tool  either  acts  on  selected  parts  of  a 
system  (not  affecting  the  rest)  or  it  acts  on  selected  properties 
of  the  system.  For  example,  data  flow  analysis  and  diagram¬ 
ming  highlight  the  complexity  of  the  interfaces  between 
modules,  but  hides  their  internals.  On  the  other  hand,  control 
flow  analysis  (i.e.,  flow  charting)  details  the  internal  structure 
of  a  module,  but  it  does  not  show  interfaces. 

It  is  likely  that  many  tools  well  be  developed  for  and  used 
solely  for  one  project.  FORTH  efficiently  supports  the  making 
and  using  of  tools  during  the  development  of  a  software  sys¬ 
tem.  Tools  also  share  some  common  properties.  They  are  built 
out  of  general  purpose  parts  or  utilities.  For  instance,  there 
are  thousands  of  different  kinds  of  screwdrivers,  but  they  are 
all  built  around  the  same  general  purpose  “simple  machines,” 
namely  the  wedge  and  the  lever.  A  tool  must  be  “more  power¬ 
ful”  than  the  stuff  it  is  used  on.  A  saw  must  be  harder  than  the 
material  it  is  trying  to  cut.  For  software  tools,  this  means 
tools  must  be  “higher  level”  than  the  software  they  are  applied 
to.  It  also  requires  that  tools  have  unrestricted  access  to  and 
control  of  the  environment  surrounding  the  solution  (e.g., 
computer  hardware,  operating  system,  language).  The  quality 
of  a  tool  limits  the  quality  of  the  result  (see  Figure  7).  For 
example,  a  lathe  must  have  been  made  to  ten  times  better  pre¬ 
cision  than  that  required  of  its  products. 

How  do  we  decide  when  a  tool  should  be  used  and  what 
the  tool  should  do?  A  good,  experienced  woodworker  wisely 
chooses  the  right  tool  for  each  task.  His  experience  was 
achieved  after  a  lot  of  experiments  during  his  entire  career.  He 
tries  to  solve  a  problem  one  way  using  a  set  of  tools.  Then  he 
determines  the  quality  of  the  result.  If  it  does  not  meet  his 
“standards,”  or  if  he  predicts  that  he  can  do  better,  he  tries 
another  solution  using  different  tools  and  techniques.  So,  if 
you  fail  to  produce  a  good  quality  product,  you  take  the  time 
required  to  develop  a  tool  which  will  allow  you  to  produce  a 
better  product.  It  is  important  that  individual  programmers  (as 
well  as  programming  departments)  establish  quality  standards 
and  refine  them  as  experience  is  gained.  The  standards  should 
include  both  the  quality  requirements  and  the  ways  they  will 
be  measured. 


10 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 

367 


You  Read 


The  Summary 

FORTH  is  an  unconventional  software  package.  It  is  a  uni¬ 
fied  approach  to  computer  programming.  It  provides  a  com¬ 
plete  programming  environment:  an  operating  system,  an  in¬ 
terpreter  for  interactive  execution,  a  compiler,  an  assembler, 
an  editor,  and  utilities.  These  are  all  written  in  the  FORTH 
language; it  is  both  a  system  and  a  meta  system. 

FORTH  is  a  philosophy  and  an  implementation  of  that 
philosophy.  The  philosophy  provides  the  goals  and  techniques 
used  in  the  implementation.  The  origins  of  the  philosophy  are 
the  Scientific  Method  and  human  factors.  FORTH  uses  model¬ 
ing  and  specialized  tools  to  understand  complex  systems. 
Decisions  are  based  on  the  goals  of  simplicity  and  generality, 
and  all  results  are  improved  using  rapid  repetition.  Program¬ 
ming  projects  use  several  passes  through  the  software  develop¬ 
ment  cycle  (i.e.,  analysis,  design,  implementation,  and  testing). 
This  technique  allows  problems  to  be  solved  incrementally, 
and  the  result  of  each  pass  is  executable  software.  FORTH 
performs  the  analysis  and  design  steps  using  top-down  prob¬ 
lem  decomposition,  but  the  implementation  and  testing  steps 
are  done  in  bottom-up  order. 

The  decomposition  separates  a  complex  system  into  a 
hierarchy  of  simpler  systems  (i.e.,  modules).  Each  module 
should  be  small  (containing  a  single  function)  and  should  have 
a  simple  interface  to  others.  All  modules  of  similar  complexity 
are  grouped  into  layers,  and  the  layers  are  ordered  so  that  the 
simplest  is  on  the  bottom  and  the  most  complex  is  on  top. 
FORTH  provides  incentives  to  produce  high  quality  results. 
Quality  standards  and  measures  should  be  assigned  to  each 
project,  and  they  should  guide  the  decisions  made  during 
development.  High  quality  tools  aid  in  the  development  of 
quality  software.  FORTH  aids  the  development  and  use  of 
specialized  software  tools. 

References 

1  Moore,  Charles  H.,  “The  Evolution  of  FORTH,  An  Unusual  Lan¬ 

guage,”  Byte,  Volume  5,  Number  8,  August  1980. 

2  FORTH-79  Standard,  produced  by  Forth  Standards  Team,  distribut¬ 

ed  by  Forth  Interest  Group. 

3  Miller,  G.  A.,  “Some  Limits  on  Our  Capacity  for  Processing  Informa¬ 

tion,”  Psychological  Review,  Volume  63, 1956. 

4  Harris,  Kim  R.,  “Software  Quality  and  Forth  Programs,”  Proceedings 

of  the  6  th  West  Coast  Computer  Faire,  April  1981. 


Dr.  Dobb  s  Journal 

And  You  Don’t 
Subscribe?! 


Save  $13 

off  newsstand  prices  for  2  yrs. 
Save  $5  for  1  yr. 


Can  you  afford  to  miss  an  issue  with 
information  vital  to  your  interests?  As  a 
subscriber  you  can  look  forward  to 
articles  on  Small-C,  FORTH,  CP/M,  S-100, 
Compiler  optimization,  Concurrent  Pro¬ 
gramming  and  more,  delivered  right  to 
your  door.  And  you’ll  never  miss  the 
issue  that  covers  your  project. 


DR.  DOBB’S  JOURNAL 
P.O.  Box  E 

Menlo  Park,  CA  94025 


Yes!  Sign  me  up  for 
_ 2  yrs.  $47 


1  yr.  $25 


I  enclose  a  check/money  order 
Charge  my  Visa,  MasterCard, 
American  Express 
Please  bill  me  later 


Name _ 

Address. 


Credit  Card 
Account  No. 
Signature _ 


Exp.  date 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 
368 


A  FORTH  Assembler 
for  the  6502 


Introduction 

This  article  should  further  polarize  the  attitudes  of  those 
outside  the  growing  community  of  FORTH  users.  Some  will 
be  fascinated  by  a  label- less  macro- assembler  whose  source 
code  is  only  96  lines  long!  Others  will  be  repelled  by  reverse 
Polish  syntax  and  the  absence  of  labels. 

The  author  immodestly  claims  that  this  is  the  best 
FORTH  assembler  ever  distributed.  It  is  the  only  such  assem¬ 
bler  that  detects  all  errors  in  op-code  generation  and  condi¬ 
tional  structuring.  It  is  released  to  the  public  domain  as  a  de¬ 
fense  mechanism:  three  good  6502  assemblers  were  submitted 
to  the  FORTH  Interest  Group  but  each  had  some  lack.  Rather 
than  merge  and  edit  for  publication,  I  chose  to  publish  mine 
with  all  the  submitted  features  plus  several  more. 

Imagine  having  an  assembler  in  1300  bytes  of  object  code 
with: 

1 .  User  macros  (like  IF,  UNTIL)  definable  at  any  time. 

2.  Literal  values  expressed  in  any  numeric  base,  altera¬ 
ble  at  any  time. 

3.  Expressions  using  any  resident  computation  capa¬ 
bility. 

4.  Nested  control  structures  without  labels,  with  error 
control. 

5.  Assembler  source  itself  in  a  portable  high  level 
language. 

Overview 

FORTH  is  provided  with  a  machine- language  assembler  to 
create  execution  procedures  that  would  be  time  inefficient,  if 
written  as  colon -definitions.  It  is  intended  that  “code”  be 
written  similarly  to  high-level,  for  clarity  of  expression.  Func¬ 
tions  may  be  written  first  in  high-level,  tested,  and  then  re¬ 
coded  into  assembly,  with  a  minimum  of  restructuring. 


The  Assembly  Process 

Code  assembly  just  consists  of  interpreting  with  the  AS¬ 
SEMBLER  vocabulary  as  CONTEXT.  Thus,  each  word  in  the 
input  stream  will  be  matched  according  to  the  FORTH  prac¬ 
tice  of  searching  CONTEXT  first  then  CURRENT. 


ASSEMBLER 
FORTH 
user’s  vocab 
FORTH 


(now  CONTEXT) 

(chained  to  ASSEMBLER) 
(CURRENT  if  one  exits) 
(chained  to  user’s  vocab) 


try  for  literal  number 


else,  do  error  abort 


The  above  sequence  is  the  usual  action  of  FORTH’s  text 
interpreter,  which  remains  in  control  during  assembly. 

During  assembly  of  CODE  definitions,  FORTH  continues 
interpretation  of  each  word  encountered  in  the  input  stream 
(not  in  the  compile  mode).  These  assembler  words  specify 
operands,  address  modes,  and  op-codes.  At  the  conclusion  of 
the  CODE  definition  a  final  error  check  verifies  correct  com¬ 
pletion  by  “unsmudging”  the  definitions  name,  to  make  it 
available  for  dictionary  searches. 


by  William  F.  Ragsdale 


William  F.  Ragsdale,  P.  O.  Box  3628,  Hayward,  CA  94540. 


Run-Time,  Assembly-Time 

One  must  be  careful  to  understand  at  what  time  a  particu¬ 
lar  word  definition  executes.  During  assembly,  each  assembler 
word  interpreted  executes.  Its  function  at  that  instant  is  called 
“assembling”  or  “assembly- time.”  This  function  may  involve 
op-code  generation,  address  calculation,  mode  selection,  etc. 

The  later  execution  of  the  generated  code  is  called  “run¬ 
time.”  This  distinction  is  particularly  important  with  the  con¬ 
ditionals.  At  assembly  time  each  such  word  (i.e.,  IF,  UNTIL, 
BEGIN,  etc.)  itself  “runs”  to  produce  machine  code  which  will 
later  execute  at  what  is  labeled  “run-time”  when  its  named 
code  definition  is  used. 

An  Example 

As  a  practical  example,  here’s  a  simple  call  to  the  system 
monitor,  via  the  NMI  address  vector  (using  the  BRK  opcode). 

CODE  MON  (  exit  to  monitor  ) 

BRK,  NEXT  JMP,  END-CODE 

The  word  CODE  is  first  encountered,  and  executed  by 
FORTH.  CODE  builds  the  following  name  “MON”  into  a 
dictionary  header  and  calls  ASSEMBLER  as  the  CONTEXT 
vocabulary. 

The  “(”  is  next  found  in  FORTH  and  executed  to  skip  till 
“)”.  This  method  skips  over  comments.  Note  that  the  name 
after  CODE  and  the  “)”  after  “(”  must  be  on  the  same  text 
line. 

Op  -codes 

BRK,  is  next  found  in  the  assembler  as  the  op-code.  When 
BRK,  executes,  it  assembles  the  byte  value  00  into  the  dic¬ 
tionary  as  the  op-code  for  “break  to  monitor  via  NMI.” 

Many  assembler  word  names  end  in  The  significance 
of  this  is: 

1 .  The  comma  shows  the  conclusion  of  a  logical  group¬ 
ing  that  would  be  one  line  of  classical  assembly 
source  code. 

2.  compiles  into  the  dictionary;  thus  a  comma  im¬ 
plies  the  point  at  which  code  is  generated. 

3.  The  distinguishes  op-codes  from  possible  hex 
numbers  ADC  and  ADD. 


NEXT 

FORTH  executes  your  word  definitions  under  control  of 
the  address  interpreter,  named  NEXT.  This  short  code  routine 
moves  execution  from  one  definition  to  the  next.  At  the  end 
of  your  code  definition,  you  must  return  control  to  NEXT  or 
else  to  code  which  returns  to  NEXT. 


Return  of  Control 

Most  6502  systems  can  resume  execution  after  a  break, 
since  the  monitor  saves  the  CPU  register  contents.  Therefore, 
we  must  return  control  to  FORTH  after  a  return  from  the 
monitor.  NEXT  is  a  constant  that  specifies  the  machine  ad¬ 
dress  of  FORTH’s  address  interpreter  (say  $0242).  Here  it  is 
the  operand  for  JMP,.  As  JMP,  executes,  it  assembles  a  ma¬ 
chine  code  jump  to  the  address  of  NEXT  from  the  assembly 
time  stack  value. 


12 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 

369 


Security 

Numerous  tests  are  made  within  the  assembler  for  user 
errors: 

1 .  All  parameters  used  in  CODE  definition  must  be  re¬ 
moved. 

2.  Conditionals  must  be  properly  nested  and  paired. 

3.  Address  modes  and  operands  must  be  allowable  for 
the  op-codes. 

These  tests  are  accomplished  by  checking  the  stack  posi¬ 
tion  (in  CSP),  as  the  “smudged”  creation  of  the  definition 
name  remains  in  the  “smudged”  condition  and  will  not  be 
found  during  dictionary  searches. 

The  user  should  be  aware  that  one  error  not  trapped  is 
referencing  a  definition  in  the  wrong  vocabulary: 

i.e.,  0=  of  ASSEMBLER  when  you  want 
0=  of  FORTH 


Summary 

The  object  code  of  our  example  is: 


3059  83  4D  4F  CE 
305D  4D  30 
305F  61  30 

3061  00 

3062  4C  42  02 


CODE  MON 
link  field 
code  field 
BRK 

JMP  NEXT 


Op -codes,  revisited 

The  bulk  of  the  assembler  consists  of  dictionary  entries 
for  each  op-code.  The  6502  one  mode  opcodes  are: 


BRK, 

CLC, 

CLD, 

CLI, 

CLV, 

DEX, 

DEY, 

INX, 

INY, 

NOP, 

PHA, 

PHP, 

PLA, 

PLP, 

RTI, 

RTS, 

SEC, 

SED, 

SEI, 

TAX, 

TAY, 

TSX, 

TXS, 

TXA, 

TYA, 

When  any  of  these  are  executed,  the  corresponding  op¬ 
code  byte  is  assembled  into  the  dictionary. 

The  multi-mode  op-codes  are: 

ADC,  AND,  CMP,  EOR,  LDA,  ORA,  SBC,  STA, 

ASL,  DEC,  INC,  LSR,  ROL,  ROR,  STX,  CPX, 

CPY,  LDX,  LDY,  STY,  JSR,  JMP,  BIT, 


These  usually  take  an  operand,  which  must  already  be  on 

the  stack. 

An  address  mode  may  also  be  specified.  If  none  is 

given,  the  op-code  uses  z-page 
dress  modes  are  determined  by: 

or  absolute  addressing.  The  ad- 

SYMBOL 

MODE 

OPERAND 

.A 

accumulator 

none 

# 

immediate 

8  bits  only 

,x 

indexed  X 

z-page  or  absolute 

,Y 

indexed  Y 

z-page  or  absolute 

X) 

indexed  indirect  X 

z-page  only 

)Y 

indirect  indexed  Y 

z-page  only 

) 

indirect 

absolute  only 

none 

memory 

z-page  or  absolute 

Examples 

Here  are  examples  of  FORTH  vs.  conventional  assembler. 
Note  that  the  operand  comes  first,  followed  by  any  mode 
modifier,  and  then  the  op-code  mnemonic.  This  makes  best 
use  of  the  stack  at  assembly  time.  Also,  each  assembler  word  is 
set  off  by  blanks,  as  is  required  for  all  FORTH  source  text. 


.A  ROL, 
1  I  LDY, 
DATA  ,X  STA, 
DATA  , Y  CMP, 
6  X)  ADC, 
POINT  )Y  STA, 
VECTOR  )  JMP, 


ROL  A  (.A  distinguishes  from 

LDY  #1  hex  number  0A) 

STA  DATA , X 
CMP  DATA.Y 
ADC  (06, X) 

STA  (POINT) ,Y 
JMP  (VF.CTOR) 


The  words  DATA  and  VECTOR  specify  machine  ad¬ 
dresses.  In  the  case  of  “6  X)  ADC,”  the  operand  memory  ad¬ 
dress  $0006  was  given  directly.  This  is  occasionally  done  if  the 
usage  of  a  value  doesn’t  justify  devoting  the  dictionary  space 
to  a  symbolic  value. 


6502  Conventions 

Stack  Addressing 

The  data  stack  is  located  in  z-page,  usually  addressed  by 
“Z-PAGE,X”.  The  stack  starts  near  $009E  and  grows  down¬ 
ward.  The  X  index  register  is  the  data  stack  pointer.  Thus,  in¬ 
crementing  X  by  two  removes  a  data  stack  value;  decrementing 
X  twice  makes  room  for  one  new  data  stack  value. 

Sixteen- bit  values  are  placed  on  the  stack  according  to  the 
6502  convention;  the  low  byte  is  at  low  memory,  with  the 
high  byte  following.  This  allows  “indexed,  indirect  X”  directly 
off  a  stack  value. 

The  bottom  and  second  stack  values  are  referenced  often 
enough  that  the  support  words  BOT  and  SEC  are  included. 
Using 

BOT  LDA,  assembles  LDA  (0,X) 

SEC  ADC,  assembles  ADC  (2,X) 

BOT  leaves  0  on  the  stack  and  sets  the  address  mode  to 
,X.  SEC  leaves  2  on  the  stack,  also  setting  the  address  mode  to 
,X. 

Here  is  a  pictorial  representation  of  the  stack  in  z-page: 


sec  high 
sec  low 
bot  high 
bot  low 


<==  X  offset 
above  $0000 


The  0  or  2  left  by  BOT  or  SEC  is  the  base  address  above 
which  the  X  register  indexes.  You  may  further  modify  this  at 
assembly  time  to  address  at  any  byte  in  the  data  stack. 

Here  is  an  example  of  code  to  “or”  to  the  accumulator 
four  bytes  on  the  stack: 

BOT  LDA,  LDA  (0,X) 

BOT  1*  ORA,  ORA  ( 1 , X) 

SEC  ORA,  ORA  (2,X) 

SEC  1*  ORA,  ORA  (3,X) 


To  obtain  the  14th  byte  on  the  stack:  BOT  13  +  LDA, 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 
370 


13 


Return  Stack 

The  FORTH  Return  Stack  is  located  in  the  6502  machine 
stack  in  Page  1.  It  starts  at  $01 FE  and  builds  downward.  No 
lower  bound  is  set  or  checked  as  Page  1  has  sufficient  capacity 
for  all  (non-recursive)  applications. 

By  6502  convention  the  CPU’s  S  register  points  to  the 
next  free  byte  below  the  bottom  of  the  Return  Stack.  The 
byte  order  follows  the  convention  of  low  significance  byte  at 
the  lower  address. 

Return  stack  values  may  be  obtained  by:  PLA,  PLA, 
which  will  pull  the  low  byte,  then  the  high  byte  from  the  re¬ 
turn  stack.  To  operate  on  arbitrary  bytes,  the  method  is: 

1 .  save  X  in  XSAVE 

2.  execute  TSX,  to  bring  the  S  register  to  X. 

3.  use  RP)  to  address  the  lowest  byte  of  the  return 
stack.  Offset  the  value  to  address  higher  bytes.  (Ad¬ 
dress  mode  is  automatically  set  to  ,X.) 

4.  restore  X  from  XSAVE. 

As  an  example,  this  definition  non- destructively  tests  that 
the  second  item  on  the  return  stack  (also  the  machine  stack)  is 
zero. 


CODE  IS-1T  (  zero  ?  ) 

XSAVE  STX,  TSX,  (  setup  for  return  stack  ) 

RP)  2+  LDA,  RP)  3  ♦  ORA,  (  or  2nd  item's  two  bvtes  together) 
0-  IF,  INY,  THEN,  (  if  zero,  bump  Y  to  one  ) 

TYA,  PHA,  XSAVE  LDX,  (  save  low  byte,  restore  data  stack) 

PUSH  JMP ,  END-CODE  (  push  boolean  ) 


Return  Stack 

hi  byte  second  item 

lo  byte 

hi  byte  bottom  item 

RP)  =$0101,X  — >  lobyte 

S  — >  free  byte 


FORTH  Registers 

Several  FORTH  registers  are  available  only  at  the  assem¬ 
bly  level  and  have  been  given  names  that  return  their  memory 
addresses.  These  are: 

IP  address  of  the  Interpretive  Pointer,  specifying  the 
next  FORTH  address  which  will  be  interpreted  by 
NEXT. 

W  address  of  the  pointer  to  the  code  field  of  the  dic¬ 
tionary  definition  just  interpreted  by  NEXT.  W-l 
contains  $6C,  the  op-code  for  indirect  jump. 
Therefore,  jumping  to  W- 1  will  indirectly  jump  via 
W  to  the  machine  code  for  the  definition. 

UP  User  Pointer  containing  address  of  the  base  of  the 
user  area. 

N  a  utility  area  in  z-page  from  N-  1  through  N+7. 


CPU  Registers 

When  FORTH  execution  leaves  NEXT  to  execute  a  CODE 
definition,  the  following  conventions  apply: 

1 .  The  Y  index  register  is  zero.  It  may  be  freely  used. 

2.  The  X  index  register  defines  the  low  byte  of  the 
bottom  data  stack  item  relative  to  machine  address 
$0000. 

3.  The  CPU  stack  pointer  S  points  one  byte  below  the 
low  byte  of  the  bottom  return  stack  item.  Execut¬ 
ing  PLA,  will  pull  this  byte  to  the  accumulator. 

4.  The  accumulator  may  be  freely  used. 

5.  The  processor  is  in  the  binary  mode  and  must  be 
returned  in  that  mode. 

XSAVE 

XSAVE  is  a  byte  buffer  in  z-page,  for  temporary  storage 
of  the  X  register.  Typical  usage,  with  a  call  which  will  change 
X,  is: 

CODE  DEMO 

XSAVE  STX,  USER'S  JSR,  (  which  will  change  X  1 
XSAVE  LDX,  NEXT  JMP,  END-CODE 

N  Area 

When  absolute  memory  registers  are  required,  use  the  “N 
Area”  in  the  base  page.  These  registers  may  be  used  as  pointers 
for  indexed/indirect  addressing  or  for  temporary  values.  As  an 
example  of  use,  see  CMOVE  in  the  system  source  code. 

The  assembler  word  N  returns  the  base  address  (usually 
$00D1).  The  N  area  spans  9  bytes,  from  N-l  through  N+7. 
Conventionally,  N-l  holds  one  byte  and  N,  N+2,  N+4,  N+6 
are  pairs  which  may  hold  16-bit  values.  See  SETUP  for  help 
on  moving  values  to  the  N  Area. 

It  is  very  important  to  note  that  many  FORTH  proce¬ 
dures  use  N.  Thus  N  may  only  be  used  within  a  single  code 
definition.  Never  expect  that  a  value  will  remain  there,  outside 
a  single  definition! 

CODE  DEMO  HEX 

6  *  LDA,  N  1  -  STA,  (  setup  a  counter  ) 

BEGIN,  8001  BIT,  (  tickle  a  port  ) 

N  1  -  DEC,  (  decrement  the  counter  ) 

0<  UNTIL,  NEXT  JMP,  END-CODE  (  loop  till  negative  ) 


SETUP 

Often  we  wish  to  move  stack  values  to  the  N  area.  The 
sub-routine  SETUP  has  been  provided  for  this  purpose.  Upon 
entering  SETUP  the  accumulator  specifies  the  quantity  of  16- 
bit  stack  values  to  be  moved  to  the  N  area.  That  is,  A  may  be 
1,  2,  3,  or  4  only: 

3  «  LDA,  SETUP  JSR, 

stack  before  N  after  stack  after 

H  high  H 

G_low  bot  — >  G_ 

F  F 

E_  E_ 

D  D 

sec  — >  C_  C_ 

B  B 

bot— >  A_  N  ->  A_ 


14 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 

371 


Control  Flow 

FORTH  discards  the  usual  convention  of  assembler  labels. 
Instead,  two  replacements  are  used.  First,  each  FORTH  defini¬ 
tion  name  is  permanently  included  in  the  dictionary.  This  al¬ 
lows  procedures  to  be  located  and  executed  by  name  at  any 
time  as  well  as  be  compiled  within  other  definitions. 

Secondly,  within  a  code  definition,  execution  flow  is  con¬ 
trolled  by  label-less  branching  according  to  “structured  pro¬ 
gramming.”  This  method  is  identical  to  the  form  used  in 
colon- definitions.  Branch  calculations  are  done  at  assembly 
time  by  temporary  stack  values  placed  by  the  control  words: 

BEGIN,  UNTIL,  IF,  ELSE,  THEN, 

Here  again,  the  assembler  words  end  with  a  comma,  to 
indicate  that  code  is  being  produced  and  to  clearly  differenti¬ 
ate  from  the  high-level  form. 

One  major  difference  occurs!  High-level  flow  is  controlled 
by  run-time  boolean  values  on  the  data  stack.  Assembly  flow 
is  instead  controlled  by  processor  status  bits.  The  programmer 
must  indicate  which  status  bit  to  test,  just  before  a  conditional 
branching  word  (IF,  and  UNTIL,). 

Examples  are: 

PORT  I.DA,  0-  IF,  <a>  THEN, 

(read  port,  if  equal  to  zero  do  <a>  ) 

PORT  LDA,  0*  NOT  IF,  <a>  THEN, 

(read  port,  if  not  equal  to  zero  do  <a>  ) 

The  conditional  specifiers  for  6502  are; 

CS  test  carry  set  C  =  1  in  processor  status 

0<  byte  less  than  zero  N=1 

0=  equal  to  zero  Z  =  1 

CS  NOT  test  carry  clear  C  =  0 

0<  NOT  test  positive  N=0 

0=  NOT  test  not  equal  zero  Z=0 

The  overflow  status  bit  is  so  rarely  used,  that  it  is  not  in¬ 
cluded.  If  it  is  desired,  compile: 

ASSEMBLER  DEFINITIONS  HEX 

50  CONSTANT  VS  (  test  overflow  set  ) 

Conditional  Looping 

A  conditional  loop  is  formed  at  assembler  level  by  placing 
the  portion  to  be  repeated  between  BEGIN,  and  UNTIL,: 

6  *  LDA,  N  STA,  (  define  loop  counter  in  N  ) 

BEGIN,  PORT  DEC,  (  repeated  action  ) 

N  DEC,  0=  UNTIL,  (  \  reaches  zero  ) 

First,  the  byte  at  address  N  is  loaded  with  the  value  6.  The 
beginning  of  the  loop  is  marked  (at  assembly  time)  by  BEGIN. 
Memory  at  PORT  is  decremented,  then  the  loop  counter  in  N 
is  decremented.  Of  course,  the  CPU  updates  its  status  register 
as  N  is  decremented.  Finally,  a  test  for  Z=  1  is  made;  if  N 
hasn’t  reached  zero,  execution  returns  to  BEGIN,.  When  N 
reaches  zero  (after  executing  PORT  DEC,  6  times)  execution 
continues  ahead  after  UNTIL,.  Note  that  BEGIN,  generates  no 
machine  code,  but  is  only  an  assembly  time  locator. 

Conditional  Execution 

Paths  of  execution  may  be  chosen  at  assembly  in  a  similar 
fashion  as  done  in  colon- definitions.  In  this  case  the  branch  is 
chosen  based  on  a  processor  status  condition  code. 

PORT  LDA,  0=  IF,  <for  zero  set>  THEN,  Continuing  code> 


In  this  example,  the  accumulator  is  loaded  from  PORT. 
The  zero  status  is  tested  if  set  (Z=  1).  If  so,  the  code  <for  zero 
set>  is  executed.  Whether  the  zero  status  is  set  or  not,  execu¬ 
tion  will  resume  at  THEN,. 

The  conditional  branching  also  allows  a  specific  action  for 
the  false  case.  Here  we  see  the  addition  of  the  ELSE,  part, 

PORT  LDA,  0=  IF,  <for  zero  sct> 

ELSE,  <for  zero  clcar> 

THEN,  <continuing  code> 

The  test  of  PORT  will  select  one  of  two  execution  paths, 
before  resuming  execution  after  THEN,.  The  next  example 
increments  N  based  on  bit  D7  of  a  port: 

PORT  LDA,  (  fetch  one  byte  ) 

0<  IF,  N  DEC,  (  if  D7*l,  decrement  N  ) 

ELSE,  N  INC,  (  if  D7=0,  increment  N  ) 

THEN,  (  continue  ahead  ) 

Conditional  Nesting 

Conditionals  may  be  nested,  according  to  the  conventions 
of  structured  programming.  That  is,  each  conditional  sequence 
begun  (IF,  BEGIN,)  must  be  terminated  (THEN,  UNTIL,)  be¬ 
fore  the  next  earlier  conditional  is  terminated.  An  ELSE,  must 
pair  with  the  immediately  proceeding  IF,. 

BEGIN,  <codc  always  executed> 

CS  IF,  <code  if  carry  set> 

ELSE,  <code  if  carry  clear>  THEN, 

0«  NOT  until,  (  loop  till  condition  flag  is  non-zero  ) 
<code  that  continues  onward> 


Next  is  an  error  that  the  assembler  security  will  reveal. 

BEGIN,  PORT  LDA, 

0-  IF,  BOT  INC, 

0=  UNTIL,  THEN, 

The  UNTIL,  will  not  complete  the  pending  BEGIN,  since 
the  immediately  preceding  IF,  is  not  completed.  An  error 
trap  will  occur  at  UNTIL,  saying  “conditionals  not  paired.” 

Return  of  Control,  revisited 

When  concluding  a  code  definition,  several  common  stack 
manipulations  often  are  needed.  These  functions  are  already  in 
the  nucleus,  so  we  may  share  their  use  just  by  knowing  their 
return  points.  Each  of  these  returns  control  to  NEXT. 

POP  POPTWO  Remove  one  or  two  16-bit  stack  values. 

PUSH  Add  two  bytes  to  the  data  stack. 

PUT  Write  two  bytes  to  the  data  stack,  over  the 

present  bottom  of  the  stack. 

Our  next  example  complements  a  byte  in  memory.  The 
byte’s  address  is  on  the  stack  when  INVERT  is  executed. 

CODE  INVERT  (  a  memory  byte  )  HEX 

BOT  X)  LDA,  (  fetch  byte  addressed  by  stack  ) 

FF  #  EOR,  (  complement  accumulator  ) 

BOT  X)  STA,  (  replace  in  memory  ) 

POP  JMP,  END-CODE  (  discard  pointer  from  stack,  return  to  NEXT  ) 

A  new  stack  value  may  result  from  a  code  definition.  We 
could  program  placing  it  on  the  stack  by: 

CODE  ONE  (  put  1  on  the  stack  ) 

DEX,  DEX,  (  make  room  on  the  data  stack  ) 

1  *  LDA,  BOT  STA,  (  store  low  byte  ) 

BOT  1+  STY,  (  hi  byte  stored  from  Y  since  =  zero  ) 
NEXT  JMP,  END-CODE 

(Continued) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 
372 


15 


A  simpler  version  could  use  PUSH: 

CODE  ONE 

1  #  LDA,  PHA,  (  push  low  byte  to  machine  stack  ) 

TYA,  PUSH  JMP ,  (  high  byte  to  accumulator,  push  to  data  stack  ) 

END-CODE 

The  convention  for  PUSH  and  PUT  is: 

1.  push  the  low  byte  onto  the  machine  stack. 

2.  leave  the  high  byte  in  the  accumulator. 

3.  jump  to  PUSH  or  PUT. 

PUSH  will  place  the  two  bytes  as  the  new  bottom  of  the 
data  stack.  PUT  will  over-write  the  present  bottom  of  the 
stack  with  the  two  bytes.  Failure  to  push  exactly  one  byte 
on  the  machine  stack  will  disrupt  execution  upon  usage! 


Bibliography 

1.  Ragsdale,  William  F.,  fig-FORTH  Installation  Manual  and  Model, 
$10.00  USA,  $13.00  overseas.  FORTH  Interest  Group,  P.  O.  Box 
1105,  San  Carlos,  CA  94070. 

2.  Feierbach,  Gary,  “FORTH,  The  Language  of  Machine  Indepen¬ 
dence,”  Computer  Design,  June  1981.  An  excellent  article  with  an 
8080  Assembler. 

3.  Ting,  Dr.  C.  H.,  Systems  Guide  to  fig-FORTH,  Mountain  View 
Press,  P.  O.  Box  4656,  Mountain  View,  CA  94040. 


Fooling  Security 

Occasionally  we  wish  to  generate  unstructured  code.  To 
accomplish  this  we  can  control  the  assembly  time  security 
checks,  to  our  purpose.  First,  we  must  note  the  parameters 
utilized  by  the  control  structures  at  assembly  time.  The  nota¬ 
tion  below  is  taken  from  the  assembler  glossary.  The  —  in¬ 
dicates  assembly  time  execution,  and  separates  input  stack 
values  from  the  output  stack  values  of  the  words’  execution. 


BEGIN, 

UNTIL, 

II  II 

II  II 

V  V 

addrB 

1 

—  addrB 

cc  — 

IF, 

ELSE, 

==> 

==> 

addrl 

2 

cc  —  addrl 
—  addrE 

THEN, 

==> 

addrl 

2 

--- 

or 

addrE 

2 

— 

The  address  values  indicate  the  machine  location  of  the 
corresponding  ‘B’EGIN,  TF,  or  ‘E’LSE,.  cc  represents  the 
condition  code  to  select  the  processor  status  bit  referenced. 
The  digit  1  or  2  is  tested  for  conditional  pairing. 

The  general  method  of  security  control  is  to  drop  off  the 
check  digit  and  manipulate  the  addresses  at  assembly  time. 
The  security  against  errors  is  less,  but  the  programmer  is  usual¬ 
ly  paying  intense  attention  to  detail  during  this  effort. 

To  generate  the  equivalent  of  the  high  level: 

BEGIN  <a>  WHILE  <b>  REPEAT 

we  write  in  assembly: 

BEGIN,  DROP  (  the  check  digit  1,  leaving  addrB) 

<a> 

CS  IF,  (  leaves  addrl  and  digit  2  ) 

<b> 

ROT  (  bring  addrB  to  bottom  )  JMP,  f  to  addrB  of  BEGIN,  ) 
THEN,  (  complete  false  forward  branch  from  IF,  ) 

It  is  essential  to  write  the  assembly  time  stack  on  paper, 
and  run  through  the  assembly  steps,  to  be  sure  that  the  check 
digits  are  dropped  and  re-inserted  at  the  correct  points  and  ad¬ 
dresses  are  correctly  available.  **j 


NOTE:  See  page  18  for  Assembler  Glossary. 


LISTING  ON  PAGE  23. 


16 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 

373 


A  FORTH  Assembler  (Text  on  pages  12-16) 


ASSEMBLER  GLOSSARY 


it 

Specify  'immediate'  addressing  mode  for  the  next  op-code  generated. 
)Y 

Specify  'indirect  indexed  Y'  addressing  mode  for  the  next  op-code 
generated. 

,X 

Specify  'indexed  X'  addressing  mode  for  the  next  op-code  generated. 
,Y 

Specify  'indexed  Y'  addressing  mode  for  the  next  op-code  generated. 
.A 

Specify  accumulator  addressing  mode  for  the  next  op— code  generated. 

0<  -  cc  (assembling) 

Specify  that  the  immediately  following  conditional  will  branch 
based  on  the  processor  status  bit  being  negative  (Z=l),  i.e. 
less  than  zero.  The  flag  cc  is  left  at  assembly  time;  there  is 
no  run-time  effect  on  the  stack. 

0=  -  cc  (assembling) 

Specify  that  the  immediately  following  conditional  will  branch 
based  on  the  processor  status  bit  being  equal  zero  (Z=l). 

The  flag  cc  is  left  at  assembly  time;  there  is  no  run-time  effect 
on  the  stack. 

;  CODE 

Used  to  conclude  a  colon-definition  in  the  form: 

:  <name>  .  .  .  ;C0DE  <assembly  code>  END-CODE 
Stop  compilation  and  terminate  a  new  defining  word  <name>.  Set 
the  CONTEXT  vocabulary  to  ASSEMBLER,  assembling  to  machine  code 
the  following  mnemonics.  An  existing  defining  word  must  exist  in 
<name>  prior  to  ;C0DE. 

When  <narae>  later  executes  in  the  form: 

<name>  <namex> 

the  definition  <namex>  will  be  created  with  its  execution 
proceedure  given  by  the  machine  code  following  <name>.  That  is, 
when  <namex>  is  executed,  the  address  interpreter  jumps  to  the  code 
following  ,C0DE  in  <name>. 

ASSEMBLER  in  FORTH 

Make  ASSEMBLER  the  CONTEXT  vocabulary.  It  will  be  searched  first 
when  the  input  stream  is  interpreted. 

BEGIN,  -  addr  1  (assembling) 

-  (run-time) 

Occurs  in  a  CODE  definition  in  the  form: 

BEGIN,  ...  cc  UNTIL, 

At  run-time,  BEGIN,  marks  the  start  of  an  assembly  sequence 


18 

374 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


BOT 


CODE 


CPU 


CS 


ELSE, 


END-CODE 


repeatedly  executed.  It  serves  as  the  return  point  for  the  corr¬ 
esponding  UNTIL,.  When  reaching  UNTIL,  a  branch  to  BEGIN,  will 
occur  if  the  processor  status  bit  given  by  cc  is  false;  other¬ 
wise  execution  continues  ahead. 

At  assembly  time,  BEGIN,  leaves  the  dictionary  pointer  address 
addr  and  the  value  1  for  later  testing  of  conditionary  pairing 
by  UNTIL,. 


-  n  (assembling) 

Used  during  code  assembly  in  the  form: 

BOT  LDA,  or  BOT  1+  X)  STA, 

Addresses  the  bottom  of  the  data  stack  (containing  the  low  byte)  by 
selecting  the  ,X  mode  and  leaving  n=0,  at  assembly  time.  This 
value  of  n  may  be  modified  to  another  byte  offset  into  the 
data  stack.  Must  be  followed  by  a  multi-mode  op-code  mnemonic. 


A  defining  word  used  in  the  form: 

CODE  <name>  ....  END-CODE 

to  create  a  dictionary  entry  for  <name>  in  the  CURRENT  vocabulary. 
<name>'s  code  field  contains  the  address  of  its 

parameter  field.  When  <name>  is  later  executed,  the  machine  code 
in  this  parameter  field  will  execute.  The  CONTEXT  vocabulary  is 
made  ASSEMBLER,  to  make  available  the  op-code  nmemonics. 

n  -  (compiling  assembler) 

An  assembler  defining  word  used  to  create  assembler  nmemonics 
that  have  only  one  addressing  mode: 

EA  CPU  NOP, 

CPU  creates  the  word  NOP,  with  its  op-code  EA  as  a  parameter. 
When  NOP,  later  executes,  it  assembles  EA  as  a  one  byte  op-code. 

-  cc  (assembling) 

Specify  that  the  immediately  following  conditional  will  branch 
based  on  the  processor  carry  is  set  (C=l).  The  flag  cc  is  left  at 
assembly  time;  there  is  no  run-time  effect  on  the  stack. 

-  (run-time) 

addrl  2  -  addr2  2  (assembling) 

Occurs  within  a  cpde  definition  in  the  form: 

cc  IF,  <true  part>  ELSE,  <false  part>  THEN, 

At  run-time,  if  the  condition  code  specified  by  cc  is  false, 
execution  will  skip  to  the  machine  code  following  ELSE,. 

At  assembly  time  ELSE,  assembles  a  forward  jump  to  just  after 
THEN,  and  resolves  a  pending  forward  branch  from  IF.  The  values 
2  are  used  for  error  checking  of  conditional  pairing. 


An  error  check  word  marking  the  end  of  a  CODE  definition. 

Successful  execution  to  and  including  END-CODE  will  unsmudge  the 
most  recent  CURRENT  vocabulary  definition,  making  it  available 
for  execution.  END-CODE  also  exits  the  ASSEMBLER  making  CONTEXT  the 
same  as  CURRENT.  This  word  previously  was  named  C; 

(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


19 

375 


A  FORTH  Assembler 


(Glossary  continued,  text  on  pages  12-16) 


IF,  cc  -  addr  2  (assembly- time  ) 

-  addr  2  (assembly-time) 

Occurs  within  a  code  definition  in  the  form: 

cc  IF,  ctrue  part>  ELSE,  <false  part>  THEN, 

At  run  time,  IF,  branches  based  on  the  condition  code  cc, 

(0<  or  0=  or  CS).  If  the  specif ed  processor  status  is  true, 
execution  continues  ahead,  otherwise  branching  occurs  to  just 
after  ELSE,  (or  THEN,  when  ELSE,  is  not  present). 

At  ELSE,  execution  resumes  at  the  corresponding  THEN,. 

When  assembling,  IF,  creates  an  unresolved  forward  branch  based 
on  the  condition  code  cc,  and  leaves  addr  and  2  for  resolution 
of  the  branch  by  the  corresponding  ELSE,  or  THEN,.  Conditionals 
may  be  nested. 

INDEX  -  addr  (assembling) 

An  array  used  within  the  assembler,  which  holds  bit  patterns  of 
allowable  addressing  modes. 

IP  -  addr  (assembling) 

Used  in  a  code  definition  in  the  form: 

IP  STA,  or  IP  ) Y  LDA, 

A  constant  which  leaves  at  assembly  time  the  address  of  the  pointer 
to  the  next  Forth  execution  address  in  a  colon-definition  to  be 
interpreted. 

At  run-time,  NEXT  moves  IP  ahead  within  a  colon-definition. 
Therefore,  IP  points  just  after  the  execution  address  being 
interpreted.  If  an  in-line  data  structure  has  been  compiled  (i.e. 
a  character  string),  indexing  ahead  by  IP  can  access  this  data: 

IP  STA,  or  IP  ) Y  LDA, 

loads  the  third  byte  ahead  in  the  colon-definition  being  interpreted. 

M/CPU  nl  n2  -  (compiling  assembler) 

An  assembler  defining  word  used  to  create  assembler  nmemonics  that 
have  multiple  address  modes: 

1C6E  60  M/CU  ADC, 

M/CPU  creates  the  word  ADC,  with  two  parameters.  When  ADC,  later 
executes,  it  uses  these  parameters,  along  with  stack  values  and  the 
contents  of  MODE  to  calculate  and  assemble  the  correct  op-code 
and  operand. 

MEM  Used  within  the  assembler  to  set  MODE  to  the  default  value  for 

direct  memory  addressing,  z-page. 

MODE  —  addr 

A  variable  used  within  the  assembler,  which  holds  a  flag  indicating 
the  addressing  mode  of  the  op-code  being  generated. 

N  -  addr  (assembling) 

Used  in  a  code  definition  in  the  form: 

N  1  -  STA,  or  N  2+  )Y  ADC, 


20 

376 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


NEXT 


NOT 


POP 


POPTWO 


PUSH 


PUT 


RP) 


SEC 


THEN, 


A  constant  which  leaves  the  address  of  a  9  byte  workspace  in 
z-page.  Within  a  single  code  definition,  free  use  may  be  made 
over  the  range  N-l  thru  N+7.  See  SETUP. 

-  addr  (assembling) 

A  constant  which  leaves  the  machine  address  of  the  Forth  address 
interpreter.  All  code  definitions  must  return  execution  to  NEXT, 
or  code  that  returns  to  NEXT  (i.e.  PUSH,  PUT,  POP,  POPTWO). 

ccl  -  cc2  (assembly-time) 

When  assembling,  reverse  the  condition  code  for  the  following 
conditional.  For  example: 

0=  NOT  IF,  <true  part>  THEN, 
will  branch  based  on  'not  equal  to  zero'. 

-  addr  (assembling) 

n  -  (run-time) 

A  constant  which  leaves  (during  assembly)  the  machine  address  of 

the  return  point  which,  at  run-time,  will  pop  a  16-bit  value  from  the 

data  stack  and  continue  interpretation. 

-  addr  (assembling) 

nl  n2  -  (run-time) 

A  constant  which  leaves  (during  assembly)  the  machine  address  of 

the  return  point  which,  at  run-time,  will  pop  two  16-bit  values  from 

the  data  stack  and  continue  interpretation. 

-  addr  (assembling) 

-  n  (run-time) 

A  constant  which  leaves  (during  assembly)  the  machine  address  of 
the  return  point  which,  at  run-time,  will  add  the  accumulator 
(as  high-byte)  and  the  bottom  machine  stack  byte  (as  low-byte) 
to  the  data  stack. 

-  addr  (assembling) 

nl  -  n2  (run-time) 

A  constant  which  leaves  (during  assembly)  the  machine  address  of 
the  return  point  which,  at  run-time,  will  write  the  accumulator 
(as  high-byte)  and  the  bottom  machine  stack  byte(as  low-byte)  over 
the  existing  data  stack  16-bit  value  (nl). 

-  (assembly-time) 

Used  in  a  code  definition  in  the  form: 

RP)  LDA,  or  RP)  3+  STA, 

Address  the  bottom  byte  of  the  return  stack  (containing  the  low  byte) 
by  selecting  the  ,X  mode  and  leaving  n=$101.  n  may  be  modified 
to  another  byte  offset.  Before  operating  on  the  return  stack 
the  X  register  must  be  saved  in  XSAVE  and  TSX,  be  executed; 
before  returning  to  NEXT,  the  X  register  must  be  restored. 

-  n  (assembling) 

Identical  to  BOT,  execpt  that  n=2.  Addresses  the  low  byte  of 
the  second  16-bit  data  stack  value  (third  byte  on  the  data  stack). 

-  (run-time) 

(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


21 

377 


A  FORTH  Assembler 


(Glossary  continued,  text  on  pages  12-16) 


addr  2  -  (assembly-time) 

Occurs  in  a  code  definition  in  the  form: 

cc  IF,  ctrue  part>  ELSE,  <false  part>  THEN, 

At  run-time  THEN,  marks  the  conclusion  of  a  conditional  structure. 
Execution  of  either  the  true  part  or  false  part  resumes  following 
THEN,.  When  assembling  addr  and  2  are  used  to  resolve  the 
pending  forward  branch  to  THEN,. 

UNTIL,  -  (run-time) 

addr  1  cc  -  (assembling) 

Occurs  in  a  CODE  definition  in  the  form: 

BEGIN,  .  .  .  cc  UNTIL, 

At  run-time,  UNTIL,  controls  the  conditional  branching  back  to 
BEGIN,.  If  the  processor  status  bit  specified  by  cc  is  false, 
execution  returns  to  BEGIN,;  otherwise  execution  continues  ahead. 

At  assembly  time,  UNTIL,  assembles  a  conditional  relative  branch 
to  addr  based  on  the  condition  code  cc.  The  number  1  is  used  for 
error  checking. 

UP  -  addr  (assembling) 

Used  in  a  code  definition  in  the  form: 

UP  LDA,  or  UP  )Y  STA, 

A  constant  leaving  at  assembly  time  the  address  of  the  pointer  to 
the  base  of  the  user  area.  i.e. 

HEX  12  #  LDY ,  UP  )Y  LDA, 

load  the  low  byte  of  the  sixth  user  variable,  DP. 

UPMODE  addr  f  -  addr  f 

Used  within  the  assembler  to  adjust  the  addressing  mode  based  on 
the  operand  size  and  opcode  type. 

W  -  addr  (assembling) 

Used  in  a  code  definition  in  the  form: 

W  1+  STA,  or  W  1  -  JMP,  or  W  )Y  ADC, 

A  constant  which  leaves  at  assembly  time  the  address  of  the  pointer 
to  the  code  field  (execution  address)  of  the  Forth  dictionary  word 
being  executed.  Indexing  relative  to  W  can  yield  any  byte  in  the 
definitions  parameter  field,  i.e. 

2  //  LDY,  W  ) Y  LDA, 

fetches  the  first  byte  of  the  parameter  field. 

X) 

Specify  'indexed  indirect  X'  addressing  mode  for  the  next  op-code 
generated. 

XSAVE  -  addr  (assembling) 

Used  in  a  code  definition  in  the  form: 

XSAVE  STX,  or  XSAVE  LDX, 

A  constant  which  leaves  the  address  at  assembly  time  of  a  temporary 
buffer  for  saving  the  X  register.  Since  the  X  register  indexes 
to  the  data  stack  in  z-page,  it  must  be  saved  and  restored  when 
used  for  other  purposes. 


22 

378 


Dt.  Dobb’s  Journal,  Number  59,  September  1981 


A  FORTH  Assembler  (Listing) 


FORTH  Assembler 

SCR  #  81 

0  (  FORTH-65 

1  HEX 

2  VOCABULARY 


6502 


ASSEMBLER 


F.  Ragsdale 


July 


1980 


WFR- 7  9 JUNO  3 


ASSEMBLER  IMMEDIATE 


ASSEMBLER  DEFINITIONS 


REGISTER  ASSIGNMENT  SPECIFIC 


IMPLEMENTATION 


5 

EO 

CONSTANT  XSAVE 

DC  CONSTANT 

W  DE  CONSTANT 

UP 

6 

“7 

D  9 

CONSTANT  IP 

D 1  CONSTANT 

N 

7 

8 

( 

NUCLEUS  LOCATIONS 

ARE 

IMPLEMENTATION 

SPECIFIC 

) 

9 

* 

(DO) 

OE  +  CONSTANT  POP 

10 

* 

(DO) 

OC  +  CONSTANT  POPTWO 

1  1 

* 

LIT 

13  +  CONSTANT 

PUT 

12 

* 

LIT 

11  +  CONSTANT 

PUSH 

13 

* 

LIT 

18  +  CONSTANT 

NEXT 

14 

* 

EXECUTE  NFA  11 

- 

CONSTANT  SETUP 

15 

CR 

it 

82 

0 

( 

ASSEMBLER,  CONT 

• 

WFR- 7  8  OCT  0  3 

) 

1 

0 

VARIABLE  INDEX 

-2  ALLOT 

2 

0909  , 

1505  ,  0115  , 

8011  ,  8009  ,  1D0D 

,  8019  , 

8080  , 

3 

0080  , 

1404  ,  8014  , 

8080  ,  8080  ,  1C0C 

,  8  0 1  C  , 

2C80  , 

4 

5 

2 

VARIABLE  MODE 

6 

.A 

0  MODE  !  ; 

:  # 

1  MODE  !  ; 

:  MEM 

2  MODE  I  ; 

7 

• 

• 

,x 

3  MODE  !  ; 

•  9 

Y  4  MODE  !  ; 

:  X) 

5  MODE  I  ; 

8 

q 

• 

• 

)  Y 

6  MODE  !  ; 

:  ) 

F  MODE  !  ; 

10 

• 

• 

BOT 

,X  0 

) 

(  ADDRESS  THE  BOTTOM 

OF  THE  STACK 

*) 

1  1 

• 

• 

SEC 

,X  2 

9 

(  ADDRESS 

SECOND  ITEM  ON  STACK 

*) 

12 

• 

RP) 

,X  101 

9 

(  ADDRESS  BOTTOM  OF 

RETURN  STACK 

*) 

it  8  3 

(  UPMODE,  CPU 


WFR- 7  80CT2  3  ) 


UPMODE  IF  MODE  @  8  AND  0=  IF  8  MODE  +!  THEN  THEN 
1  MODE  @  OF  AND  -DUP  IF  0  DO  DUP  +  LOOP  THEN 
OVER  1+  @  AND  0=  ; 


<B  U ILD  S  C,  DOES>  C@ 


00  CPU  BRK, 
B 8  CPU  CL V , 
C  8  CPU  INY, 
68  CPU  PLA, 
38  CPU  SEC, 
A8  CPU  TAY, 
98  CPU  TYA, 


18  CPU  CLC , 
CA  CPU  DEX, 
EA  CPU  NOP, 
28  CPU  PLP , 
F  8  CPU  SED, 
BA  CPU  TSX, 


C,  MEM  ; 

D  8  CPU  CLD, 
88  CPU  DEY, 
48  CPU  PHA, 
40  CPU  RTI, 
78  CPU  SEI, 
8 A  CPU  TXA , 


58  CPU  CLI, 
E  8  CPU  INX , 
08  CPU  PHP , 
60  CPU  RTS, 
AA  CPU  TAX, 
9 A  CPU  TXS, 


(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


23 

379 


A  FORTH  Assembler 


(Listing  continued,  text  on  pages  12-16) 


SCR  #  84 

0  (  M/CPU,  MULTI-MODE  OP-CODES  WFR-79MAR26 

1  :  M/CPU  <BUILDS  C,  ,  DOES> 

2  DUP  1+  @  80  AND  IF  10  MODE  +!  THEN  OVER 

3  FF00  AND  UPMODE  UPMODE  IF  MEM  CR  LATEST  ID. 

4  3  ERROR  THEN  C@  MODE  C@ 

5  INDEX  +  C@  +  C,  MODE  C@  7  AND  IF  MODE  C@ 

6  OF  AND  7  <  IF  C,  ELSE  ,  THEN  THEN  MEM  ; 

7 

8  1C6E  60  M/CPU  ADC,  1C6E  20  M/CPU  AND,  1C6E  CO  M/CPU  CMP, 

9  1C6E  40  M/CPU  EOR ,  1C6E  AO  M/CPU  LDA ,  1C6E  00  M/CPU  ORA, 

10  1 C 6 E  EO  M/CPU  SBC,  1C6C  80  M/CPU  STA,  ODOD  01  M/CPU  ASL, 

11  OCOC  Cl  M/CPU  DEC,  OCOC  El  M/CPU  INC,  ODOD  41  M/CPU  LSR, 

12  ODOD  21  M/CPU  ROL,  ODOD  61  M/CPU  ROR,  0414  81  M/CPU  STX, 

13  0486  EO  M/CPU  CPX,  0486  CO  M/CPU  CPY,  1496  A2  M/CPU  LDX , 

14  0C8E  AO  M/CPU  LDY,  048C  80  M/CPU  STY,  0480  14  M/CPU  JSR, 

15  8480  40  M/CPU  JMP ,  0484  20  M/CPU  BIT, 


) 


SCR  #  85 

0  (  ASSEMBLER  CONDITIONALS  WFR- 7  9MAR26  ) 

1  :  BEGIN,  HERE  1  ;  IMMEDIATE 

2  :  UNTIL,  ?EXEC  >R  1  7PAIRS  R>  C,  HERE  1+  -  C,  ;  IMMEDIATE 

3  :  IF,  C,  HERE  0  C,  2  ;  IMMEDIATE 

4  :  THEN,  7EXEC  2  7PAIRS  HERE  OVER  C@ 

5  IF  SWAP  !  ELSE  OVER  1+  -  SWAP  C!  THEN  ;  IMMEDIATE 

6  :  ELSE,  2  ?  P  A I RS  HERE  1+  1  JMP, 

7  SWAP  HERE  OVER  1+  -  SWAP  C!  2  ;  IMMEDIATE 


8 

: 

NOT  20 

+  ; 

(  REVERSE  ASSEMBLY 

TEST 

) 

9 

90 

CONSTANT 

cs 

(  ASSEMBLE  TEST  FOR  CARRY 

SET 

) 

10 

DO 

CONSTANT 

0* 

(  ASSEMBLER  TEST  FOR  EQUAL 

ZERO 

) 

1  1 

10 

CONSTANT 

0< 

(  ASSEMBLE  TEST  FOR  LESS  THAN 

ZERO 

) 

12 

90 

CONSTANT 

>  = 

(  ASSEMBLE  TEST  FOR  GREATER  OR  EQUAL 

ZERO 

) 

13  (  >=  IS  ONLY  CORRECT  AFTER  SUB,  OR  CMP,  ) 

14 
1  5 


SCR  #  86 

0  (  USE  OF  ASSEMBLER  WFR- 7 9 APR 2  8  ) 

1  :  END-CODE  (  END  OF  CODE  DEFINITION  *) 

2  CURRENT  @  CONTEXT  !  ?EXEC  ?CSP  SMUDGE  ;  IMMEDIATE 

3 

4  FORTH  DEFINITIONS  DECIMAL 

5  :  CODE  (  CREATE  WORD  AT  ASSEMBLY  CODE  LEVEL  *) 

6  ?  EXEC  CREATE  [COMPILE]  ASSEMBLER 

7  ASSEMBLER  MEM  1CSP  ;  IMMEDIATE 

8 

9  (  LOCK  ASSEMBLER  INTO  SYSTEM  ) 


10 

'  ASSEMBLER 

CFA 

; CODE  8  +  1 

(  OVER-WRITE  SMUDGE  ) 

1  1 

LATEST 

12 

♦ORIGIN  ! 

(  TOP  NFA  ) 

12 

HERE 

28 

♦ORIGIN  1 

(  FENCE  ) 

13 

HERE 

30 

♦ORIGIN  ! 

(  DP  ) 

14  '  ASSEMBLER  6  +  32  +ORIGIN  l  (  VOC-LINK  ) 

15  HERE  FENCE  1 

End  Listing 


24 

380 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


Sallying  FORTH  to  Battle 


As  most  Dr.  Dobb’s  readers  are  a- 
ware,  there  has  been  a  rash  of  ac¬ 
tivity  on  the  FORTH  front  of  late. 
Minor  skirmishes,  thrusts  and  parries,  and 
assorted  small  sorties  have  been  appearing 
in  print.  Fortunately  there  has  been  no 
reported  blood-letting.  Not  being  one  to 
avoid  such  nonsense,  I  too  take  sword  in 
hand  (well,  at  least  a  pen)  and  whiffle  off 
to  battle. 

What  is  FORTH  and  why  all  the 
furor?  FORTH  is  after  all  only  a  comput¬ 
er  language  —  right?  Well,  maybe!  The 
jury  is  still  out  on  the  language  issue  in 
most  respects.  FORTH  is  a  threaded  lan¬ 
guage  certainly,  but  it  is  just  as  helpful  to 
consider  it  an  environment  as  a  language. 
Hopefully  this  and  several  other  attri¬ 
butes  of  FORTH  will  become  more  evi¬ 
dent  in  the  following. 

The  essential  idea  behind  FORTH  or 
any  other  threaded  language  is  to  create 
a  pseudo-machine  from  a  real  machine 
(or  computer).  The  heart  of  the  psuedo- 
machine  is  called  the  inner  interpreter.  It 
controls  the  environment  for  “instruc¬ 
tion”  execution  on  a  dual  stack  psuedo- 
machine.  The  instructions  the  psuedo- 
machine  recognizes  are  primitives  (or 
zero  address  machine  operations)  and 
secondaries.  The  primitives  always  ma¬ 
nipulate  data  relative  to  the  stacks  and 
are  real-machine  specific.  That  is,  the  pri¬ 
mitives  (and  the  inner  interpreter)  must 
be  coded  in  the  machine  instructions  of 
the  computer  at  hand.  Except  for  the 
input/output  driver  routines,  which  are 
always  machine  specific,  no  other 
machine-specific  code  is  necessary  to  im¬ 
plement  a  threaded  language.  We  shall 
leave  open  the  question  of  which  primi¬ 
tives  constitute  a  sufficient  set  to  assure 
construction  of  the  threaded  language. 

Secondaries  are  lists  of  “instruction” 
addresses  where  each  instruction  address 
is  the  address  of  a  primitive  or  the  address 
of  a  previously  defined  secondary.  Only 
the  primitive  code  sequences  are  ever 
actually  executed,  as  well  as  inner  inter¬ 
preter  code.  A  secondary  as  an  “instruc¬ 
tion”  is  simply  equivalent  to  a  subrou¬ 
tine  call.  The  secondaries  are  internal 


by  R.  G.  Loeliger 


Mr.  Loeliger  is  the  author  of  the  book. 
Threaded  Interpretive  Languages.  R.  G. 
Loeliger,  c/o  Logicon,  Inc.,  Kittyhawk 
Office  Center,  5717  Huberville  Ave., 
Suite  300,  Dayton,  OH  45431. 


nodes  of  a  tree  structure,  the  end  nodes 
of  which  are  primitives.  The  inner  inter¬ 
preter  simply  walks  the  tree  looking  for 
end  nodes  to  execute.  The  dual  stack  is 
necessary  so  that  one  stack  can  be  used 
for  data  storage  and  the  other  can  be  used 
for  tree  walk  node  address  storage. 

The  primitives  are  somewhat  analo¬ 
gous  to  the  pure  instructions  of  the 
psuedo-machine  (the  machine  code  of 
a  real  computer).  They  always  cause  a  spe¬ 
cific  machine  state  change  to  occur.  A 
secondary  is  more  like  a  macro-instruction. 
When  primitives  and  secondaries  are 
strung  together  in  a  proper  sequence,  a 
program  can  result.  The  program  is  it¬ 
self  only  a  single  psuedo-machine  instruc¬ 
tion  since  it  is  itself  a  secondary.  Does 
this  make  FORTH  a  pseudo-machine  or 
a  language?  Unfortunately  the  answer  is 
not  clear. 

There  has  been  a  recent  flurry  of  ac¬ 
tivity  to  standardize  FORTH.  The  most 
obvious  and  well-founded  example  is 
FORTH-79  (Ref.  1).  This  standard  does 
not  address  the  issue  of  the  pseudo¬ 
machine  itself  but  attempts  to  control  the 
result  (the  machine  state  change)  for  each 
keyword  in  the  language.  The  FORTH- 
79  nucleus  words  are  not  defined  as  the 
allowable  primitives  for  example.  The 
problem  is  that  there  are  not  rules  for  the 
division  of  the  language  between  primi¬ 
tives  and  secondaries.  Any  secondary  can 
be  written  as  a  primitive.  Not  all  primi¬ 
tives  can  be  written  as  secondaries,  but 
some  can  be.  There  are  advantages  in  pri¬ 
mitive  definitions  over  secondaries  in  that 
a  primitive  never  executes  inner  interpret¬ 
er  code. 

There  is  not  one  syntax  diagram  in 
the  FORTH-79  standard.  The  same  can 
be  said  of  the  C  programming  language 
standard  (Ref.  2)  although  the  latter  does 
make  a  non-rigorous  (read  vague)  at¬ 
tempt  to  outline  a  syntax.  So  what’s  the 
difference?  The  FORTH-79  language 
standard  is  more  like  an  Instruction  Set 
Architecture  (ISA)  standard  than  a  lan¬ 
guage  standard;  i.e.,  a  recipe  for  building 
a  computer  rather  than  a  language.  It 
comes  complete  with  machine  state 
change  diagrams. 

FORTH  does  have  a  syntax  though, 
in  much  the  manner  that  assembly  lan¬ 
guage  has  a  syntax.  The  syntax  is  much 
more  apparent  than  real.  Nothing  in  the 
“language”  really  signifies  the  expected 
machine  state  change.  It  is  common 
practice  to  choose  keyword  names  that 
allow  easy  recall  of  the  associated  action 


(e.g.,  DROP  drops  a  data  value  from  the 
data  stack).  Because  of  the  machine  state 
change  implied  by  every  keyword,  it  can 
be  extremely  difficult  to  decode  a  given 
secondary  based  only  on  its  formal  de¬ 
finition  without  a  definitive  definition  of 
initial  input  stack  data  parameters.  If  all 
this  sounds  vaguely  like  assembly  lan¬ 
guage,  you’re  getting  close. 

All  of  this  is  further  complicated  by 
the  extensibility  of  FORTH.  In  FORTH 
it  is  possible  to  interactively  extend  the 
keyword  definitions  by  adding  (or  as  it  is 
called,  compiling)  new  secondaries  or  by 
coding  new  primitives.  The  pseudo¬ 
machine  is  thus  not  a  static  environment 
in  the  FORTH  environment.  This  flexi¬ 
bility  is  an  advantage  and  a  potential 
hazard.  Since  the  environment  can  be 
easily  changed,  almost  any  keyword  or 
program  can  be  emulated  by  making  an 
associated  pseudo-machine  instruction  (a 
keyword)  equivalent  to  the  “program” 
action.  Conversely  a  slip  of  the  hand  or 
mind  while  constructing  the  instruction 
tree  can  send  the  pseudo-machine  into 
never-never  land.  A  system  reload  is  then 
necessary  to  re-establish  the  pseudo¬ 
machine  in  its  pristine  state. 

Is  FORTH  then  a  language?  In  a 
classic  computer  language  sense,  probably 
not  a  higher  order  language.  A  language? 
Only  if  one  believes  in  Santa  Claus  and 
assembly  language.  Is  it  the  end-all  of 
microcomputer  languages?  We  shall  dis¬ 
cuss  this  further. 

Computer  languages  almost  always 
arise  for  practical  purposes.  A  problem  is 
at  hand  that  begs  for  a  solution  and  that 
cannot  be  easily  solved  using  an  existing 
language.  Consider  the  following: 


Language 

Original  Purpose 

BASIC 

Introductory  teaching  lan¬ 
guage 

FORTRAN 

Engineering  and  scientific 
problems 

COBOL 

Business  problems 

LISP 

List  processing 

Pascal 

Computer  Science  instruc¬ 
tion 

C 

Systems  programming 

SAIL 

Artificial  intelligence  re¬ 
search 

XPL 

Compiler  writing 

Ada 

Embedded  avionics  (real¬ 
time)  systems 

ALGOL  60 

Algorithms 

ALGOL  68 

Everything  in  the  world 

Almost  all  of  these  languages  can  be  and 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


25 

381 


are  used  for  purposes  far  beyond  their 
original  intent,  i.e.,  bent  to  fill  a  far  dif¬ 
ferent  goal  than  their  designer  envisioned. 

I  have,  as  an  obvious  example,  a  Pascal 
compiler  written  in  BASIC.  The  simple 
fact  that  some  language  is  misapplied  suc¬ 
cessfully  is  not  proof  that  it  is  ideally 
suited  for  the  application. 

So  why  in  the  world  did  Charles 
Moore  of  FORTH,  Inc.  ever  invent 
FORTH?  For  a  practical  reason,  of 
course!  He  was  faced  with  a  difficult 
real-time  control  problem  and  a  small 
computer.  The  compilers  available  for  the 
machine  churned  out  dismal  code  and 
were  very  large,  unwieldy,  inefficient  and 
not  very  user-friendly.  His  solution 
(FORTH)  is  small,  relatively  efficient, 
very  user-friendly  and  quite  capable  of 
real-time  control.  FORTH  did  not  spring 
forth  in  full  bloom  overnight  but  evolved 
over  a  period  of  some  years.  It  retains  all 
of  the  good  features  of  its  original 
design  goal  and  most  of  its  original  faults. 

For  a  constrained  environment  such 
as  its  design  point  problem,  FORTH  is  an 
ideal  solution.  In  a  typically  constrained 
environment  such  as  a  personal  computer, 
it  is  a  reasonable  solution.  It  is  not  the 
answer  to  all  problems  and  was  never 
meant  to  be. 

One  of  the  very  nice  features  about 
FORTH  or  any  other  threaded  language  is 
that  the  system  is  very  memory  conser¬ 
vative.  An  8K  threaded  language  has 
many  powerful  capabilities  and  about 
150  to  200  user- available  commands  plus 
assembler  commands.  New  keywords  can 
be  easily  compiled  or  assembled  and  test¬ 
ed  easily.  The  typical  claim  that  FORTH 
definitions  take  less  space  than  assembly 
langauge  definitions  is,  of  course,  non¬ 
sense.  The  FORTH  definition  is  a  delta  to 
the  core  machine  definitions  and  depends 
on  the  core  definitions.  The  assembly  lan¬ 
guage  program  is  stand-alone.  For  all 
that,  a  very  small  FORTH  machine  can  be 
extremely  versatile  and  a  good  bit  of  fun. 

FORTH  is  an  interactive  environ¬ 
ment.  The  entire  machine  state  is  avail¬ 
able  to  the  programmer  at  all  times.  Com¬ 
pilation  is  direct  and  rapid.  This  makes 
the  user  interface  very  friendly.  It  also 
makes  the  pseudo-machine  very  vulner¬ 
able.  In  a  multi-user  environment,  it  is 
next  to  impossible  to  protect  the  system 
from  the  vagrancies  of  the  users.  There  is 
just  not  a  convenient,  reliable  way  to 
limit  the  “system  command”  as  with  a 
more  conventional  environment.  In  a 
single-user  case,  this  is  not  usually  a 


problem.  System  re-loading  is  not  all  that 
time  consuming.  Crashing  a  multi-user 
system  is  dangerous  to  one’s  health  rather 
than  simply  irritating. 

Program  testing  in  FORTH  is  ex¬ 
tremely  easy.  Since  test  values  can  be 
easily  placed  on  the  stack,  the  keyword 
executed,  and  the  results  displayed,  a 
separate  testing  environment  is  never 
needed.  Although  programming  per  se 
is  more  difficult  in  FORTH  than  in  a 
higher  order  language,  program  develop¬ 
ment  is  faster  because  of  the  ease  of  pro¬ 
gram  testing.  Designing  the  testing  pro¬ 
gram  itself  is  difficult  in  any  event.  A 
badly  designed  test  program  will  not  be 
improved  simply  by  using  FORTH. 

FORTH  does  have  its  problems.  The 
most  damning  of  these  are  in  readability 
and  ease  of  documentation.  It  is  almost 
impossible  to  read  a  FORTH  definition 
and  know  what  it  is  doing  without  re¬ 
sorting  to  a  pencil.  The  pencil  is  necessary 
to  keep  track  of  the  data  stack  at  each 
keyword  completion  within  the  defini¬ 
tion  of  a  secondary  or  to  decode  a  primi¬ 
tive  machine  or  assembly  language  defi¬ 
nition.  Even  if  the  keyword  is  defined  on 
a  screen  as  source  text,  the  comments  re¬ 
quired  to  fully  explain  the  action  usually 
exceed  the  code  by  an  order  of  magni¬ 
tude.  Documenting  FORTH  code  is  worse 
than  documenting  assembly  language 
code  in  my  opinion.  I  often  do  the  docu¬ 
mentation  off-line  and  have  been  known 
to  lose  the  laundry  ticket  on  which  my 
latest  and  most  clever  routine  was  noted. 

I  have  also  lost  unbound  documentation 
to  my  crayon-crazed  three-year-old.  Off¬ 
line  documentation  is  not  foolproof. 

The  documentation  of  code  on  a 
screen  is  not  too  neat  either.  The  screen  is 
a  IK  block  of  mass  storage  which  is 
mapped  to  a  64-character  by  16-line 
monitor  display.  Since  it  is  a  one-for-one 
mapping,  one  can  not  take  advantage  of 
control  codes  (e.g.,  tabs,  etc.)  to  compact 
the  lines  and  increase  the  density  of  the 
source  code.  The  screen,  for  all  its  simpli¬ 
city,  is  not  very  efficient  for  documenta¬ 
tion.  As  a  matter  of  fact,  it  isn’t  very 
efficient  even  for  uncommented  source 
code.  Usable  is  the  best  adjective  to  de¬ 
scribe  the  screen  concept. 

Because  of  the  difficulty  of  docu¬ 
menting  FORTH,  it  is  non-optional  for 
use  in  a  production  environment.  If  more 
than  two  programmers  are  involved,  or  if 
the  program  has  a  long  life  cycle,  I  would 
not  use  FORTH.  Modifying  even  a  well- 
documented  program  two  years  after  the 


original  programmer  quit  is  bad  enough. 
It  is  not  impossible  to  use  FORTH,  only 
dicey.  The  coding  and  testing  will  go 
quickly  but  so  might  any  chance  for  later 
modification  and  expansion. 

FORTH  is  in  reality  an  entire  operat¬ 
ing  system  environment.  In  its  standard 
form  it  is  not  compatible  with  an  operat¬ 
ing  system  (OS),  it  is  the  OS!  This  is  not 
to  imply  that  it  can’t  be  made  to  operate 
under  an  OS  such  as  Digital  Research’s 
CP/M,  only  that  FORTH’S  virtual  mem¬ 
ory  system  as  defined  is  incommensurate 
with  an  OS. 

The  basic  method  of  accessing  mass 
storage  data  in  FORTH  is  in  IK  units 
known  as  blocks.  A  block  or  a  screen  are 
equivalent  in  storage  capacity.  When 
FORTH  is  used  under  an  OS  environ¬ 
ment,  there  is  a  required  translation  from 
a  block  number  to  a  file  structure  refer¬ 
ence.  In  FORTH  there  is  no  direct  multi¬ 
block  file  structure.  This  forces  all  block 
references  to  the  file  structure  to  be  han¬ 
dled  at  the  IK  unit  level  regardless  of  the 
OS  capability.  As  an  OS  environment, 
FORTH  is  primitive.  Hiding  FORTH 
under  even  a  modestly  sophisticated  OS  is 
somewhat  like  mounting  a  Model  T  Ford 
body  on  a  Porsche  chassis  . .  .  not  unusa¬ 
ble,  but  decidedly  weird. 

As  a  stand-alone  operating  system 
environment,  FORTH  is  not  weird,  only 
primitive.  One  disadvantage  of  its  sim¬ 
plicity  is  that  there  is  no  directory  struc¬ 
ture.  As  a  result  there  are  keywords  in 
most  FORTH  dialects  to  list  the  first  line 
of  (successive)  FORTH  screens.  Com¬ 
ments  can  be  placed  on  the  first  screen 
line  to  identify  the  screen  contents  in 
place  of  a  true  directory.  There  are  two 
disadvantages  to  this.  For  starters  there  is 
no  way  to  limit  the  search  to  a  named  file 
or  group  of  files.  At  IK  per  file  there  can 
be  a  lot  of  file  scanning  before  the  correct 
screen  is  located.  Next  (and  last),  the 
need  for  the  identification  comment  in 
the  screen  further  limits  the  amount  of 
data  one  can  squeeze  on  a  screen.  C’est  la 
vie. 

There  are  other  problems  in  FORTH 
but  most  of  the  remaining  are  simply  ir¬ 
ritating  rather  than  limiting.  Contrary  to 
the  bad  press  Reverse  Polish  Notation 
(RPM)  often  receives,  I  personally  prefer 
RPN  to  algebraic  notation.  FORTH’S  use 
of  RPN  is  not  only  natural  but  pleasing. 
From  a  pure  mathematics  point  of  view, 
FORTH  is  easy  to  decode.  It  is  only  when 

(Continued  on  page  48) 


26 

382 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


Screen-Oriented  Editor 
in  FORTH 


Much  has  been  said  about  FORTH 
in  the  past,  but  unfortunately  very 
few  real  life  applications  have  ever 
been  presented.  The  following  Screen- 
Oriented  Editor  is  an  attempt  to  alleviate 
this  deficiency.  The  code  more  or  less 
stands  by  itself,  and  has  been  written 
with  transportability  and  modifiability  in 
mind.  It  is  entirely  in  high  level  FORTH, 
however  to  increase  performance,  one 
optional  code  word  has  been  included. 
There  are  extensive  comments  on  both 
what  is  going  on  line-by-line,  and  de¬ 
scriptive  paragraphs  explaining  the  func¬ 
tion  of  each  word. 

I  would  like  to  say  a  few  words 
about  my  experience  in  implementing 
this  editor.  I  had  been  using  FORTH  for 

by  Henry  Laxen 

Henry  Laxen,  1259  Cornell  Ave.,  Berke¬ 
ley,  CA  94706. 


about  12  months,  and  considered  myself 
quite  fluent  in  it.  I  had  just  completed 
writing  a  little  editor  for  the  Quasar/ 
Panasonic  Hand  Held  Computer,  and  thus 
had  a  pretty  good  idea  of  what  was  in¬ 
volved  in  writing  one.  I  sketched  out  a  de¬ 
sign  top  down,  and  proceeded  to  imple¬ 
ment  bottom  up.  I  started  about  10:00 
AM  on  a  Sunday  morning,  and  had  a 
working  version,  very  similar  to  what  is 
presented  in  this  article,  only  14  hours 
later.  It  included  all  of  the  features  cur¬ 
rently  present  with  the  exception  of  the 
automatic  line  0  updating  and  a  few 
minor  enhancements  I  have  since  added.  I 
was  truly  amazed  at  how  easy  the  task 
was.  It  was  quite  difficult  to  write  words 
that  had  bugs  in  them  due  to  the  usually 
trivial  nature  of  the  definitions.  I  esti¬ 
mate  that  if  I  had  written  an  equivalent 
editor  in  Pascal,  it  would  have  taken  me 
at  least  3  days;  had  I  tried  to  write  it  in 
assembly  language,  it  would  have  required 


a  week  or  two. 

This  editor,  as  it  stands,  has  been  im¬ 
plemented  on  several  different  CPU’s 
with  absolutely  no  modification  whatso¬ 
ever.  These  include  such  diverse  proces¬ 
sors  as  the  Zilog  Z-80  and  a  DEC  PDP- 
11.  Furthermore,  it  has  been  modified 
to  run  with  many  different  types  of  ter¬ 
minals,  as  well  as  memory -mapped  video 
boards.  It  stands  as  a  testimonial  to  the 
extreme  transportability  of  FORTH. 

I  hope  those  of  you  who  bother  to 
implement  this  editor  on  your  system  will 
find  it  useful  and  productive.  I  estimate 
it  has  improved  my  efficiency  in  editing 
source  screens  by  a  factor  of  two  or  so 
over  the  line-oriented  editor  supplied 
with  the  FIG  model.  I  hope  your  experi¬ 
ences  with  FORTH  are  as  pleasant  as 
mine,  and  may  the  FORTH  be  with  you. 

•»J 

LISTING  ON  PAGE  28. 


Don’t  let  your  hot  utilities  or  computing  ideas 
sit  on  the  shelf.  DDJ  is  a  great  place  for  bright 
authors  to  get  a  start.  Contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


27 

383 


Screen  Oriented  Editor  (Text  on  page  27) 


10  11 
0  (  ACKNOWLEDGEMENTS  26APR9iHHL  (  LOAD  SCREEN  FOR  SYSTEM  GENERATION  27APRBIHHL 

1  )  10  LIST  11  LOAD  ;S  ) 

2 


3  Welcome  to  the  world  of  Full  Screen  Editing  in  Forth.  There 

4  is  documentation  on  how  to  use  this  editor  on  screens  12-23. 

5  Furthermore,  there  are  some  modification  notes  on  screens 

6  42-44.  I  hope  you  will  have  no  problems  using  this  editor. 

7  IF  you  have  any  questions  or  comments,  please  contact  me  at 

8  the  address  below.  By  the  way,  this  takes  a  long  time  to 

9  load,  so  please  be  patient.  May  the  Forth  be  with  you. 

10 


11  Henry  Laxen 

12  1259  Cornell  Ave. 

13  Berkeley,  California 

14  94706 

15  (415)  525-8582 


This  editor  is  in  the  public 
domain,  and  may  be  distributed 
Further  with  the  inclusion 
of  this  notice. 


24  LOAD  (  LOAD  GENERAL  PURPOSE  STUFF  i 
38  LOAD  (  LOAD  THE  EDITOR  ) 


(  NOTE1!,  THIS  EDITOR  ASSUMES  THAT  BLOCKS  ARE  1024  BYTES 
IN  LENGTH,  AND  THAT  THE  FIG  FORTH  ENCLOSE  BUG  HAS  BEEN 
FIXED.  IF  THIS  IS  NOT  THE  CASE,  IT  WILL  REQUIRE  MODIFICATION 
IN  SEVERAL  PLACES,  MOST  NOTABLY  IN: 

E-INIT 

E-UPDATE 

E-EXIT,  E-SCRATCH 

) 


12  13 


0  FORTH  Development  System  Documentation  18SEP80DRB 

1 

n 

L 

3  The  FORTH  editor  is  easy  to  learn  and  to  use.  It  consists  of 

CURSOR  MOVEMENT 

COMMANDS 

18SEP80DRB 

Command 

Function 

Description 

4  control  key  commands  that  allow  cursor  movement  and  text  entry 

5  and  deletion  so  that  editing  can  be  done  quickly  and  smoothly, 
i 

AE 

cursor  up 
a  line 

Moves  cursor  up  to  the  same 
position  in  the  preceding  line. 

7 

8  CURSOR  MOVEMENT 

9 

10  You  can  place  the  cursor  anywhere  on  the  screen  by  using  a 

11  Few  editing  commands. 

12 

AX 

cursor  down 

a  line 

Moves  cursor  down  to  the  same 
position  in  the  next  line. 

tAR 

cursor  up 

Four  lines 

Moves  cursor  to  the  same 
position  four  lines  up. 

13  The  Following  table  describes  the  commands  that  are  relevant 

14  to  cursor  movement. 

t'C 

cursor  down 

Four  lines 

Moves  cursor  to  the  same 
position  Four  lines  down. 

15 


14 

0  CURSOR  MOVEMENT  COMMANDS 
1 


15 

18SEP80DRB  CURSOR  MOVEMENT  COMMANDS 


14 

15 


AA 


cursor  left 


18SEP80DRB 

Moves  cursor  back  to  the  First 


2 

AS 

cursor  left 

Moves  cursor  to  the 

a  word 

letter  of  the  previous  word 

3 

AH 

one  character 

previous  character  or 

going  to  the  end  of  the  previous 

4 

delete 

space. 

line  if  at  the  beginning  of  the 

5 

current  line. 

6 

AD 

cursor  right 

Moves  cursor  to  the  next 

7 

one  character 

character  or  space. 

AI 

tab 

Moves  the  cursor  to  the  next  tab 

8 

TAB 

stop  on  the  line  going  to  the 

9 

AF 

cursor  right 

Moves  cursor  Forward  to  the 

next  line  if  at  the  end  of  the 

10 

a  word 

First  letter  of  the  next  word 

current  line. 

11 

going  to  the  beginning  of  the 

t  The  position 

of  the  cursor 

will  differ  depending  on  the  number 

12 

next  line  if  at  the  end  dF  the 

of  intervening  lines  between  the  top  and  the  bottom  of  the 

13 

current  line. 

screen.  IF  you 

enter  AR  when 

the  cursor  is  less  than  Four  lines 

down  From  the  top  of  the  screen,  the  cursor  moves  to  the  First 
space  on  the  First  line. 


28 

384 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


16 

17 

0  CURSOR  HINTS 

18SEP80DRB  TEXT  ENTRY  AND  DELETION 

18SEP80DRB 

1 

I  Similarly 

,  if  the  cursor  is 

less  than  four  lines  uo  from  the 

With  special 

editing  commands,  you  can  enter  additional  text 

3  bottom  of 

the  screen,  AC  moves  it  to  the  last  space  on  the 

or  take  out  existing  text  in 

your  FORTH  screens.  The  following 

4  bottom  line. 

tables  describe 

the  commands  that  are  relevant  to  text  entry 

C 

J 

and  deletion. 

6  Using  these  commands  singly  or  in  combinations,  you  can  move 

7  the  cursor  wherever  you  want 

:  it.  If,  for  instance,  you  want  to 

TEXT 

ENTRY 

8  move  the 

cursor  to  the  end  of  the  current  line,  you  enter  the 

9  following 
1 f, 

combination: 

Command 

Function 

Description 

i v 

u 

<cr) 

carriage  return 

*AV 

insertion 

Types  over  characters  when  OFF 

12 

AA 

off t on 

and  inserts  character  when  ON. 

13 

When  on,  INSERT  ON  appears  in 

14  When  the  cursor  is  anywhere  in  the  last  line,  you  can  move 

the  top  (status)  line.  AV  is  a 

15  it  to  the  beginning  of  that 

line  by  entering  a  carriage  return. 

toggle  that  turns  insert  off 

18 

19 

0  SPEADING 

LINES 

18SEP80DRB  TEXT  DELETION 

18SEP80DRB 

1 

when  it  is  on  and  on  when  it  is 

2 

7 

off. 

Command 

Function 

Description 

4  AN 

insert 

Inserts  a  carriage  return  at  the 

AG 

delete 

Deletes  the  character  under 

5 

carriage 

cursor  pcstion,  and  leaves 

character 

the  cursor  and  moves  everything 

6 

return 

cursor  unmoved.  All  text  to  the 

right 

to  the  right  of  it  left  one 

7 

right  of  and  below  cursor  moves 

character. 

8 

down  one  line,  but  only  if  the 

9 

last  line  is  blank.  Text  in  the 

AT 

delete 

Deletes  word  containing  the 

10 

last  line  disables  this  command. 

word  right 

cursor,  specifically  the 

11 

character  under  the  cursor  and 

12  t  A  carriage  return  has  the 

same  effect  on  the  text  whether  AV 

the  characters  to  the  right  of 

13  (insert  mode)  is  on  or  off. 

In  other  words,  pressing  carriage 

it  to  the  end  of  the  line. 

14  return  while  insert  is  on  will  not  result  in  inserting  a 

15  carriage 

return. 

20 

21 

0  DELETING  TEXT 

4 

25APR81HHL  EXITING  FROM  THE  EDITOR 

18SEP80DRB 

1 

2  AB 

delete  line 

Deletes  the  text  in  the  current 

AZ 

abandon 

Exits  from  the  editor.  The 

7 

J 

contents 

line  without  deleting  the  line 

screen 

block  is  not  marked  as  updated. 

4 

(leaves  a  blank  line). 

Hence,  typing  EMPTY-BUFFERS  at 

5 

this  point  will  allow  you  to 

6  AY 

delete  line 

Deletes  the  current  line  and 

retrieve  the  contents  of  the 

7 

moves  the  lines  under  it  up 

screen  as  it  was  before  any 

8 

thereby  shrinking  the  screen. 

editing  took  place.  If  you 

9 

re-enter  the  editor  before 

10  AK 

delete 

Deletes  contents  of  the  entire 

typing  EMPTY-BUFFERS,  you  will 

11 

(kill) 

screen. 

get  the  edited  version  of  the 

12 

screen 

screen. 

13 

14 


(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


29 

385 


Screen  Oriented  Editor 


(Listing  continued,  text  on  page  27) 


22 

0  EXITING  FROM  THE  EDITOR 
1 


2  ESC 

3 

4 

5 

6 

7 

8 
9 

10 

11 

12 

13 

14 


exit 

editor 


15 


23 

18SEP80BRB  CURSOR  POSITIONING  WORDS  18SEP80DRB 

Exits  the  editor  and  writes  the  At  the  end  oF  the  editor  you  will  Find  the  cursor  positioning 
screen  back  to  disk  iF  it  was  routines  required  For  some  currently  available  terminals. 
modiFied.  The  used  ID  is  auto-  Load  the  screen  that  corresponds  to  your  terminal.  IF  it  isn’t 

matically  inserted  in  the  right-  there,  you  will  have  to  write  your  own  routines.  This  is  easy 

most  10  characters  oF  line  0.  and  you  can  use  the  ones  provided  as  a  model. 

Good  luck,  and  may  the  FORTH  be  with  you. 


24 


25 

(S 


(P 


0  (  \  COMMENT  TO  END  OF  LINE  25APR81HHL  \ 

1  ) 

2  :  (S 

3  :  \  (  —  >  41  WORD  ; 

4  IN  i  C/L  /  1+  C/L  I  IN  !  ;  IMMEDIATE 

5  IMMEDIATE 

6 

7  (  THIS  IS  THE  COMMENT  CHARACTER  WHICH  SHOULD  ONLY  BE  USED 

8  INSIDE  OF  SCREENS.  IT  WILL  CAUSE  ALL  SUBSEQUENT  CHARACTERS 

9  ON  ITS  LINE  TO  BE  IGNORED.  INTERPRETATION  WILL  BEGIN  ON  THE  :  iP  ( 

10  FOLLOWING  LINE.  NOTE  THAT  \  MUST  BE  FOLLOWED  IMMEDIATELY  BY  41  WORD  ; 

11  A  SPACE.  )  IMMEDIATE 

12 


DOCUMENTATION  WORDS 


26APRB1HHL 


(  —  ) 


\  SKIP  TO  ) 


(  iS  IS  USED  FOR  STACK  COMMENTS.  A  UTILITY  MAY  BE  WRITTEN 
LATER  TO  EXTRACT  THESE  ) 


—  ) 


\  SKIP  TO  ) 


13  ~> 

14 

15 


<  IP  IS  USED  FOR  DESCRIPTIVE  COMMENTS.  A  UTILITY  MAY  BE 
WRITTEN  LATER  TO  EXTRACT  THESE  ) 

— > 


26  27 

0  \  DEPTH  RETURN  DEPTH  OF  STACK  25APR81HHL  \  L  INTELLIGENT  SCREEN  LISTS  25APR81HHL 

1 


2  :  DEPTH  (S  —  N  )  :  L  (S  INI  —  ) 

3  SP8  SO  8  SWAP  -2/0  MAX  ;  DEPTH  IF 

4  DUP  SCR  ' 

5  !P  RETURNS  THE  CURRENT  DEPTH  OF  THE  STACK.  THIS  WORD  MAY  NEED  ELSE 

6  TO  BE  REDEFINED  WHEN  RUNNING  ON  OTHER  SYSTEMS,  AS  IT  USES  A  SCR  8 

7  COMPUTER  DEPENDENT  WORD  CALLED  SO,  WHICH  CONTAINS  THE  STARTING  ENDIF 

8  ADDRESS  OF  THE  STACK.  )  LIST  ; 


\  IS  THERE  ANYTHING  THERE 
\  YES,  REMEMBER  IT 

\  NO,  RETRIEVE  LAST  ONE 

\  AND  LIST  IT 


9 

10  --> 
11 
12 
13 


(P  L  WILL  LIST  THE  SPECIFIED  SCREEN  AND  REMEMBER 
WHAT  IS  WAS.  IF  THE  DEPTH  OF  THE  STACK  IS  ZERO,  IT  WILL 
LIST  THE  LAST  SCREEN  PREVIOUS  LISTED.  IT  MAKES  USE  OF 
THE  USER  VARIABLE  SCR.  ) 


14 

15 


30 

386 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


DO  LOOP  SETUP 


25APR81HHL 


28 

0  \  2DR0P  2t  BEEP  25APR81HHL 

1 

2  :  2DR0P  (S  N1  N2  —  ) 

3  DROP  DROP  ; 

4  ip  2DROP  DROPS  2  ITEMS  OFF  OF  THE  PARAMETER  STACK.  ) 

5 

6  :  2*  (S  N  —  2tN  ) 

7  DUP  +  ; 

8  (P  2t  SIMPLY  DOUBLES  THE  ITEM  ON  THE  TOP  OF  THE  STACK  ) 

9 

10  :  BEEP  (S  —  ) 

11  7  EMIT  ; 

12  (P  RING  THE  BELL  ON  THE  TERMINAL.  USUALLY  AFTER  AN  ERROR  ) 

13 

14  --> 

15 


29 

\  BOUNDS 

:  BOUNDS  (S  ADDR  LEN  —  ADDR+LEN  ADDR  ) 

OVER  +  SNAP  ; 

(P  BOUNDS  IS  A  COMMON  DO  LOOP  SETUP  NORD.  IT  ASSUMES  THERE  IS 
AN  ADDRESS  AND  A  LENGTH  ON  THE  STACK.  BOUNDS  CONVERTS  THIS 
INTO  A  HIGH  ADDRESS  AND  A  LON  ADDRESS.  THE  I  INDEX  OF  A  DO 
LOOP  NILL  THEN  RUN  THROUGH  THIS  RANGE  OF  VALUES  NHILE  EXECUTING 
) 

— > 


30 

31 

0 

\  BMOVE 

8080 

CODE  VERSION  OF  BMOVE 

27APR81HHL  \  BMOVE 

CONTD. 

1 

—  > 

\  REMOVE  THIS  ARRON  TO  USE 

THIS 

NORD  --> 

\  REMOVE  THIS  ~>  TO  USE  THIS  NORD 

2 

CODE  BMOVE 

(  FROM  TO  LEN  —  ) 

BEGIN 

3 

C  L  MOV 

B  A  MOV 

\  LEN  IS  IN  (BC) 

4 

B  H  MOV 

\ 

(HL) 

<-  (IP) 

C  ORA 

\  SEE  IF  16  BIT  0 

5 

B  POP 

\ 

(BC) 

<-  LEN 

NHILE  JZ 

\  LOOP  NHILE  NOT  0 

6 

D  POP 

\ 

(DE) 

<-  TO 

M  A  MOV 

\  FETCH  BYTE 

1 

/ 

XTHL 

\ 

(HL) 

<-  FROM 

H  DCX 

\  FROM  =  FROM  -  1 

8 

B  DAD 

\ 

(HL) 

<-  FROM+LEN 

D  STAX 

\  STORE  BYTE 

9 

H  DCX 

\ 

(HL) 

<-  FROM’ 

D  DCX 

\  TO  =  TO  -  1 

10 

XCHG 

\ 

(HL) 

<-  TO,  (DE)  <-  FROM’ 

B  DCX 

\  DECREMENT  COUNT 

11 

B  DAD 

\ 

(HL) 

<-  TO+LEN 

REPEAT  JMP 

\  DO  IT  AGAIN 

12 

H  DCX 

\ 

(HL) 

<-  TO’ 

B  POP 

\  RESTORE  IP 

13 

XCHG 

\ 

(HL) 

<-  FROM',  (DE)  <- 

TO1, 

(BC)  <-  LEN  NEXT  JMP 

\  AND  RETURN 

14  ™>  C; 

15  \  THE  ABOVE  SETS  UP  FOR  THE  LOOP  THAT  IS  TO  FOLLOW  --> 


27APR81HHL 


32  3^ 

0  \  BMQVE  HIGH  LEVEL  27APR81HHL  \  MOVE  WORKS  IN  EITHER  DIRECTION  25APR81HHL 

1  \  «>  \  REMOVE  THE  FIRST  \  IF  THE  CODE  VERSION  IS  USED 


3  :  BMOVE  (S  FROM  TO  LEN  —  ) 

4  -DUP  IF  \  ANYTHING  TO  MOVE? 

5  >R  R  +  1  -  SNAP  1  -  \  YES,  MOVE  FROM  HIGH 

6  R>  BOUNDS  SNAP  DO  \  MEMORY  TO  LON  MEMORY 

7  I  CJ  OVER  C!  \  t 

8  1  -  -1  \  t 

9  +LOOP  DROP 

10  ELSE 

11  2BRQP  \  NOTHING  TO  DO,  SO  FORGET  IT 

12  END  IF  ; 

13  IP  BMOVE  IS  IDENTICAL  TO  CMOVE  EXCEPT  IT  MOVES 

14  CHARACTERS  IN  THE  OTHER  DIRECTION.  > 

15  --> 


:  MOVE  (S  FROM  TO  LEN  —  ) 

ROT  ROT  2DUP  U<  IF 
ROT  BMOVE 
ELSE 

ROT  CMOVE 
ENDIF  j 

(P  MOVE  NILL  MOVE  LEN  BYTES  FROM  ADDRESS  FROM  TO  ADDRESS  TO 
AND  NILL  NOT  OVERLAP  THEM,  NO  MATTER  NHAT  THE  RELATIVE  VALUES 
OF  FROM  TO  AND  LEN  ARE,  MOVE  SHOULD  ALNAYS  BE  USED  NHENEVER 
THERE  IS  DANGER  OF  OVERLAPPING  FIELDS  i 


(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


31 

387 


Screen  Oriented  Editor 


(Listing  continued,  text  on  page  27) 


34 

0  \  1-  2-  DECREMENT 

1 

2:1-  (S  N  —  N-i  ) 

3  1  -  ; 

4 

5:2-  iS  N  —  N-2  ) 

6  2  -  ; 

7 

8  -> 

9 

10 

11 

12 

13 

14 

15 


25APRB1HHL  \  >=  <>  <=  U>  CONDITIONALS  25APR81HHL 

:  >=  (S  N1  N2  —  BOOL  i 
<  0=  ; 

:  <>  IS  N1  N2  —  BOOL  I 
=  0=  ; 

:  <=  (S  N1  N2  —  BOOL  ) 

>  0=  ; 

:  U>  (S  N1  N2  —  BOOL  ) 

SNAP  U<  ; 


36  37 

0  \  RE-FORTH  RE-ENTER  FORTH  FOR  1  LINE  25APR81HHL  \  ?DUP  SAME  AS  -DUP  FOR  FORTH-79  21APR81HHL 

1 


4 

5 

6 

7 

8 

9 

10 
11 
12 

13 

14 


RE-FORTH 
IN  3  >R 
BLK  3  >R 
0  IN  !  0  BLK  ! 
QUERY  INTERPRET 
R)  BLK  1 
R>  IN  i  ; 


IS  —  ??? 


\  SAVE  INPUT  BUFFER  POINTER 
\  SAVE  BLOCK  NUMBER 
\  RESET  FOR  TERMINAL  INPUT 
\  SET  1  LINE  FROM  TERMINAL 
\  RESTORE  BLOCK  NUMBER 
\  RESTORE  INPUT  BUFFER  POINTER 


!P  RE-FORTH  REENTERS  THE  FORTH  INTERPRETER  FROM  THE  TERMINAL 
AND  ALLOWS  THE  USER  TO  ENTER  i  LINE  OF  VALID  FORTH  COMMANDS. 
THIS  IS  A  SIMPLE  WAY  TO  PROMPT  FOR  TERMINAL  MESSAGES  WHILE 
IN  THE  MIDDLE  OF  LOADING.  ) 


— > 


:  ?DUP  iS  N  —  INI  N  ) 

-DUP  ; 

(P  DUPLICATES  THE  TOP  OF  THE  STACK  IF  THE  TOP  IS 
NONZERO.  IF  THE  TOP  IS  ZERO,  THEN  IT  IS  NOT  DUPLICATED. 
THIS  IS  DEFINED  PRIMARILY  FOR  FORTH-79  COMPATIBILITY  ) 


38 

0  \  CASE: 

1 

2  :  CASE:  (S  N  —  ) 

3  < BUILDS  I  SMUDGE 

4  DOES) 

5  SWAP  2t  +  3 

6  EXECUTE  ; 


39 

25APR81HHL  \  -TIDY  21APR81HHL 

:  -TIDY  !S  ADDR  LEN  —  j 

BOUNDS  DO  \  RUN  THROUGH  THE  STRING 

I  C3  BL  <  IF  \  IS  IT  A  CONTROL  CHAR7 

BL  I  C!  \  YES,  REPLACE  IT  WITH  A  BLANK 

ENDIF 


7 

8  (P  CASE:  IS  A  POOR  MAN'S  CASE  STATEMENT.  AT  COMPILE  TIME,  IT 

9  SIMPLY  COMPILES  CODE  FIELD  ADDRESS  AS  DOES  :  AT  RUN  TIME,  IT 

10  EXPECTS  AN  INDEX  ON  THE  STACK,  AND  SIMPLY  INDEXES  INTO  THE 

11  DEFINED  WORDS  AND  EXECUTES  IT.  ) 

12 

13  -> 


LOOP  ; 

(P  -TIDY  REPLACES  ALL  CONTROL  CHARACTERS  IN  A  SPECIFIED 
RANGE  WITH  BLANKS  ) 


14 

15 


32 

388 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


40 

0  \  VARIABLE  AND  CONSTANT  DEFINITIONS  21APR81HHI 

1  VOCABULARY  EDITOR  IMMEDIATE  EDITOR  DEFINITIONS 

2  0  VARIABLE  {.MODE  \  CURRENT  MODE  i  OVERSTRIKE  DR  INSERT 

3  0  VARIABLE  ^CURSOR  \  CURSOR  POSITION 

4  0  VARIABLE  S.OLD-MODE  \  PREVIOUS  NODE 

5  0  VARIABLE  {.UPDATE  \  UPDATE  FLAG 

6  0  VARIABLE  &BUF-ADR  \  ADDRESS  OF  CURRENT  BUFFER 

7  0  VARIABLE  teE-ID  \  DATE  AND  USER  ID  LAST  MODIFIED 

8  12  ALLOT 

9  &E-ID  14  BLANKS  \  INITIALIZE  TO  BLANKS 

10 

11  5  CONSTANT  XX-OFF  \  X  OFFSET  FOR  CURSOR  POSITIONING 

12  2  CONSTANT  XY-OFF  \  Y  OFFSET  FOR  CURSOR  POSITIONING 

13  B/SCR  B/8UF  I  CONSTANT  C/SCR  \  CHARACTER  PER  SCREEN 

14  C/SCR  C/L  /  CONSTANT  L/SCR  \  LINES  PER  SCREEN 

15  ~> 

42 

0  \  DESCRIPTION  OF  CURSOR  COMMANDS  25APR81HHL 

1  --> 

2  The  CRTXY  command  must  position  the  cursor  at  the  X  and  Y 

3  co-ordinates  given  on  the  stack.  If  your  terminal  does  not 

4  support  cursor  positioning,  give  up. 

C 

J 

6  The  CRTCLR-SCR  should  clear  the  entire  screen  and  home  the 

7  cursor.  If  such  a  command  is  not  available,  output  a  sufficient 

3  number  of  line-feeds  to  clear  the  screen  via  scrolling,  and  then 

9  call  CRTXY  with  0  0. 

10 

11  The  CRTCLR-EOL  command  should  dear  the  line  from  its  current 

12  location  to  the  end  o*  the  line.  The  following  will  always 

13  work,  but  if  your  terminal  supports  something  more  sophisticated 

14  you  rhoul d  use  it. 

15  C/L  MOD  C/L  SWAP  -  SPACES 

44 

0  \  DESCRIPTION  OF  CURSOR  POSITIONING  COMMANDS  26APR81HHL 

4 
1 

2  --> 

3 

4  If  you  would  like  to  see  how  some  sample  cursor  positioning 

5  routines  were  written,  take  a  look  at  screens  90-91.  Note 

6  that  you  may  write  your  own  routines  even  after  the  complete 

7  editor  has  been  loaded.  All  you  need  do  is  patch  the  execute 

8  vectors  for  vour  particular  terminal.  Good  luck. 

9 

10 
11 
12 

13 

14 

15 


41 

\  CURSOR  POSITIONING  VECTORS  25APR81HHL 

0  VARIABLE  ’CRTXY  \  CFA  OF  ROUTINE  THAT  MOVES  CURSOR 

0  VARIABLE  ’CRTCLR-SCR  \  CFA  OF  ROUTINE  THAT  CLEARS  SCREEN 

0  VARIABLE  ’CLEAR-TO-EOL  \  CFA  OF  ROUTINE  THAT  CLEARS  TO  EOL 

:  CRTXY  (S  X  Y  —  ) 

’CRTXY  i  EXECUTE  ; 

:  CRTCLR-SCR  (S  —  ) 

’CRTCLR-SCR  J  EXECUTE  ; 

:  CLEAR-TO-EOL  (S  ---  ) 

’CLEAR-TO-EOL  i  EXECUTE  ; 

--> 


43 

\  DESCRIPTION  OF  CURSOR  POSITIONING  COMMANDS  25APR81HHL 

--> 

NOTE" 

The  CLEAR-TO-EOL  command  is  ALWAYS  called  with  the  cursor 
positioned  at  the  correct  place  on  the  screen.  Hence  if 
your  terminal  supports  a  clear  to  end  of  line  command,  the 
position  passed  can  fie  simply  dropped  and  the  terminal 
commend  issued.  If  the  terminal  does  not  support  such  a 
command,  you  must  blank  out  the  remainder  of  the  line  based 
on  the  cursor  position  that  was  passed. 


45 

\  CURPOS  +CURP0S  MOVE-CURSOR  25APR81HHL 

:  CURPOS  (S  —  POS  ) 

{.CURSOR  i  ;  \  RETURN  CURRENT  CURSOR  POSITION 

:  +CURP0S  (S  N  —  ) 

{.CURSOR  ♦! 

CURPOS  0  MAX  \  AND  DO  BOUNDS  CHECKING 

t  C/SCR  1-  1  LITERAL  \  CHAR  PER  SCREEN  -  1 
MIN  {.CURSOR  1  j  \  ALWAY  VALID 

:  MOVE-CURSOR  iS  N  —  ) 

+CURP0S  \  MOVE  THE  CURSOR 

CURPOS  C/L  ./MOD  \  RAW  X  Y 

XY-OFF  +  SWAP  \  ADD  IN  Y  OFFSET 

XX-OFF  +  SWAP  \  ADD  IN  X  OFFSET 

CRTXY  ;  -->  \  AND  MOVE  THERE 

(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


33 

389 


Screen  Oriented  Editor 


(Listing  continued,  text  on  page  27) 


46 

0  \  BUF-ADR  BUFPOS 
1 

2  :  BUF-ADR  (S  PQS  —  ADDR  ) 

3  &BUF-ADR  i  +  ; 

4 

5  (P  BUF-ADR  CONVERTS  THE  CURSOR  POSITION  IT  IS  CALLED  WITH 

6  TO  THE  ADDRESS  WITHIN  THE  DISK  BUFFER  WHICH  CORRESPONDS 

7  TO  THAT  POSITION  ) 

B 

9  :  BUFPOS  (S  —  ADDR  ) 

10  CURPOS  BUF-ADR  •, 

11 

12  (P  BUFPOS  RETURNS  THE  ADDRESS  IN  THE  DISK  BUFFER  OF  THE 

13  CURRENT  CHARACTER  ) 

14 

15  --> 


25APR81HHL 

:  E-UPDATE  (S  —  ) 

1  tcUPDATE  !  ;  \  SET  UPDATE  FLAG 

(P  E-UPDATE  IS  CALLED  WHENEVER  THE  CONTENTS  OF  THE  BUFFER 
HAS  CHANGED.  IT  SETS  AN  THE  UPDATE  FLAG.  ) 

--> 


47 

25APR81HHL  \  E-UPDATE 


48  49 

0  \  BUF-MOVE  25APR81HHL  \  7PRINTABLE  25APR81HHL 

1 


2  :  BUF-HuVE  (S  FROM  TO  LEN  —  ) 

3  ROT  BUF-ADR 

4  ROT  BUF-ADR 

5  ROT  MOVE 

6  E-UPDATE  ; 

7 

3  (P  BUF-MOVE  PERFORMS  A  MOVE  OPERATION  ON  THE  CHARACTERS  IN  THE 

9  DISK  BUFFER  CORRESPONDING  TO  THE  GIVEN  CURSOR  POSITIONS.  ) 

10 

11  ~> 


:  7PRINTABLE  IS  CHAR  —  BOOL  i 
DUP  32  < 

SWAP  126  > 

OR  0=  | 

(P  ’PRINTABLE  RETURNS  A  TRUE  FLAG  IF  THE  CHARACTER  IS  PRINTABLE. 
OTHERWISE  IT  RETURNS  A  FALSE  FLAG  1 

--> 


12 


13 

14 


50 

0  \  5LINEI  LINE*) 

1 

2  :  >LINE*  (S  POS  —  LINE*  ) 

3  C/L  /  ; 

4 

5  (P  CONVERT  A  CHARACTER  POSITION  TO  A  LINE  NUMBER  ) 

6 

7  :  LINE*)  !S  LINE*  —  POS  i 

8  C/L  t  ; 

9 

10  (P  CONVERT  A  LINE  NUMBER  TO  A  CHARACTER  POSITION  i 

11 

12  --) 

13 

14 

15 


51 

25APR81HHL  \  CHARS-TO-EOL  25APR81HHL 

:  CHARS-TO-EOL  (S  POS  —  N  ) 

C/L  MOD 
C/L  SWAP  -  ; 

(P  CHARS-TO-EOL  RETURNS  THE  NUMBER  OF  CHARACTERS  LEFT  ON  THE 
LINE  GIVEN  THE  CURRENT  CHARACTER  POSITION  ) 


34 

390 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


\  DISPLAY-TO-EOL 


25APRS1HHL  \  ?EHPTY-LINE 


25APR81HHL 


DISPLAY-TO-EOL  iS  POS  — 


DUP  BUF-ADR 
OVER  CHARS-TO-EOL 
-TRAILING 
ROT  OVER  +  >R 
TYPE 

R>  CLEAR-TO-EOL 


\  GET  ADDRESS  IN  BUFFER 
\  REST  OF  LINE 
\  IGNORE  BLANKS 

\  SAVE  RESULTANT  CURSOR  POSITION 
\  DISPLAY  WHATS  THERE 
\  AND  REMOVE  THE  REST 


’EMPTY-LINE  (S  LINE!  —  BOOL  ) 

LINE#)  BUF-ADR  C/L  \  ADDR  LEN 

-TRAILING  \  REMOVE  TRAILING  BLANKS 

SWAP  DROP  0=  \  REPORT  SUCCESS  IF  ALL  BLANKS 


(P  ’EMPTY-LINE  RETURNS  TRUE  IF  THE  SPECIFIED  LINE  NUMBER  IS 
COMPLETELY  BLANK.  OTHERWISE  IT  RETURNS  FALSE.  ) 


(P  DISPLAY-TO-EOL  DISPLAYS  THE  REST  OF  THE  LINE  STARTING  FROM 
THE  CURRENT  CURSOR  POSITION.  IT  ASSUMES  THAT  THE  TERMINAL 
CURSOR  IS  PROPERLY  POSITIONED  BEFORE  IT  EXECUTES.  ) 


0  \  DISPLAY-TO-EOS  25APR 

1 

2  :  DISPLAY-TO-EOS  (S  LINE#  —  ) 

3  CURPOS  SWAP  \  SAVE  CURRENT  CURSOR  POSITIO 

4  L/SCR  SWAP  DO  \  RUN  THROUGH  REST  OF  SCREEN 

5  I  LINE#) 

6  DUP  &CURSOR  1  \  SET  CURSOR  POSITION 

7  0  MOVE-CURSOR 

8  DISPLAY-TO-EOL  \  AND  DISPLAY  LINE  FROM  THERE 

9  LOOP 

10  CURSOR  1  \  RESTORE  CURSOR  POSITION 

11  0  MOVE-CURSOR  ; 

12  (P  DISPLAY  THE  ENTIRE  SCREEN  FROM  THE  GIVEN  LINE  NUMBER  TO 

13  THE  END  OF  THE  SCREEN.  THIS  IS  USED  WHEN  A  LINE  IS 

14  INSERTED  OR  DELETED  FROM  THE  MIDDLE  OF  THE  SCREEN  i 

15  --) 


25APR81HHL  \  EXPAND 


25APR81HHL 


\  SAVE  CURRENT  CURSOR  POSITION 
\  RUN  THROUGH  REST  OF  SCREEN 

\  SET  CURSOR  POSITION 

\  AND  DISPLAY  LINE  FROM  THERE 

\  RESTORE  CURSOR  POSITION 


EXPAND  iS  POS  —  ) 
DUP  DUP 
C/L  + 

C/SCR  OVER  - 
BUF-MOVE 

BUF-ADR  C/L  BLANKS 
E-UPDATE  ; 


\  P  P  P 
\  P  FROM  TO 
\  P  FROM  TO  LEN 
\  TEXT  MOVED  IN  BUFFER 
\  INSERT  BLANK  LINE 


(P  EXPAND  MOVES  ALL  OF  THE  LINES  DOWN  BY  ONE  AND  INSERTS 
A  BLANK  LINE  AT  THE  SPECIFED  POSITION.  ) 


56 

\  SHRINK 


25APR81HHL  \  INSERT-LINE 


25APR81HHL 


SHRINK  (S  POS  —  ) 

DUP  \  POS  POS 

C/L  +  SWAP  \  FROM  TO 

OVER  C/SCR  SWAP  -  \  FROM  TO  LEN 

BUF-MOVE  \  MOVE  IT 

[  L/SCR  1-  3  LITERAL  \  INSERT  A  BLANK  LINE 

LINE#)  BUF-ADR  C/L  BLANKS  \  AT  THE  BOTTOM  OF  THE  SCREEN 

E-UPDATE  ; 


INSERT-LINE  (S  POS  —  ) 
[  L/SCR  1-  3  LITERAL 
’EMPTY-LINE  IF 
DUP  EXPAND 

>LINE#  DISPLAY-TO-EOS 
ELSE 
BEEP 
ENDIF  ; 


\  LAST  LINE  NUMBER 
\  IS  IT  EMPTY? 

\  YES,  EXPAND  THE  BUFFER 
\  AND  REDISPLAY  THE  SCREEN 

\  NO,  WARN  USER 


(P  SHRINK  DELETES  THE  SPECIFIED  LINE  IN  THE  DISK  BUFFER  AND 
REPLACES  THE  LAST  LINE  OF  THE  SCREEN  WITH  A  BLANK  LINE  ) 


IP  INSERT-LINE  CHECKS  TO  SEE  THAT  THERE  IS  NO  TEXT  ON  THE 
LAST  LINE  OF  THE  SCREEN.  IF  THERE  IS  NONE,  IT  EXPANDS  THE 
SCREEN  AT  THE  GIVEN  CURSOR  POSITION  AND  RE-DISPLAYS  THE 
ALTERED  SCREEN  > 


(Continued  on  next  page ) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


35 

391 


Screen  Oriented  Editor 


(Listing  continued,  text  on  page  27) 


58 

DELETE-LINE 

DELETE-LINE  (S  POS  —  ) 
>LINE#  DUP  LINE#)  SHRINK 
DISPLAY-TO-EOS  ; 


(P  DELETE-LINE  REMOVE  THE  LINE  THE  CURSOR  IS  ON  AND  RE-DISPLAYS 
THE  RESULTING  SCREEN  ) 


25APR81HHL  \  INS-CHAR 


25APR81HHL 


INS-CHAR  iS  CHAR  POS  —  ) 
DUP  DUP  1+ 

over  chars-to-eol  i-  ' 

BUF-NOVE 

BUF-ADR  C!  ;  ' 


\  CHAR  POS  FROM  TO 
\  CHAR  POS  FROM  TO  LEN 
\  MOVE  IT 

\  AND  STICK  IN  CHAR 


IP  INS-CHAR  INSERTS  THE  GIVEN  CHARACTER  INTO  THE  DISK  BUFFER. 
NOTE  THAT  CHARACTERS  FALLING  OFF  THE  RIGHT  END  OF  THE  LINE 
ARE  LOST  IF  CAUTION  IS  NOT  USED.  ) 


\  DEL-CHAR 

:  DEL-CHAR  (S  POS  —  ) 
DUP  DUP  1+  SNAP 
OVER  CHARS-TO-EOL 
BUF-MOVE 

DUP  CHARS-TO-EOL  +  1- 
BUF-ADR  BL  SNAP  Cl  ; 


\  POS  FROM  TO 
\  POS  FROM  TO  LEN 
\  MOVE  IT 
\  POSITION  AT  EOL 
\  AND  STICK  IN  A  BLANK 


(P  DEL-CHAR  DELETES  THE  CHARACTER  AT  THE  SPECIFIED  CURSOR 
POSITION  ) 


25APR81HHL  \  ARROW  COMMANDS 

:  R-ARROW  IS  — 
1  +CURPOS  : 


:  L-ARRON  (S  —  ) 

-1  +CURPOS  ; 

:  U-ARROW  (S  —  ) 
C/L  MINUS  +CURPOS  ; 

:  D-ARRON  (S  —  ) 
C/L  +CURPOS  ; 


25APR81HHL 


\  MOVE  RIGHT  BY  ONE 


\  MOVE  LEFT  BY  ONE 


\  MOVE  UP  BY  ONE 


MOVE  DOWN  BY  ONE 


I-LINE  D-LINE  D-CHAR  INSERT-MODE 

I-LINE  (S  —  ) 

CURPOS  INSERT-LINE  ; 

D-LINE  (S  —  ) 

CURPOS  DELETE-LINE  ; 

D-CHAR  (S  —  ) 

CURPOS  DEL-CHAR 
CURPOS  DISPLAY-TO-EOL  ; 


25APR81HHL  \  RETURN  EXIT-EDIT 


RETURN  (S  —  ) 

CURPOS  >LINE# 

1  + 

t  L/SCR  I-  I  LITERAL  MIN 
LINE#)  CURSOR  I  ; 


21 APR81HHL 


\  SET  LINE  NUMBER  OF  CURRENT  LIN 
\  INCREMENT  BY  ONE 
\  DON’T  MOVE  BELOW  BOTTOM 
\  AND  MOVE  THERE 


(P  RETURN  IS  EXECUTED  WHENEVER  THE  CARRIAGE  RETURN  KEY 
IS  PRESSED.  IT  MOVES  THE  CURSOR  TO  THE  BEGINNING  OF  THE 
NEXT  LINE.  IF  THE  CURSOR  IS  AT  THE  BOTTOM  OF  THE  SCREEN, 
IT  REMAINS  THERE.  ) 


INSERT-MODE  (S  —  i 
&M0DE  1  TOGGLE  ; 


:  EXIT-EDIT  IS  —  ) 

CR  R>  DROP  R>  DROP  R)  DROP  R>  DROP  R>  DROP  ; 

(P  GET  OUT  OF  THE  EDITOR  AND  RETURN  TO  PREVIOUS  ACTIVITY 


36 

392 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


64 

0  \  EXIT-UPDATE  25APR81HHL 

1 

2  :  EXIT-UPDATE  (S  —  ) 

3  C/SCR  MOVE-CURSOR  \  GET  TO  BOTTOM  OF  SCREEN 

4  CR  CR  \  SKIP  TWO  LINES 

5  SCR  J  .  \  TELL  USER  SCREEN  NUMBER 

6  &UPDATE  i  IF  \  HAS  IT  CHANGED'5 

7  K-ID  \  FROM 

8  I  C/L  10  -  ]  LITERAL  \  Tu 

9  BUF-ADR  10  CMOVE  \  INDICATE  BLOCK  CHANGED 

10  .*  Modified-  UPDATE  FLUSH  \  YES,  TELL  USER 

11  ELSE  Unmodi F i edH  ENDIF  \  NO,  LET  HIM  KNOW 

12  EXIT-EDIT  ;  \  GET  OUT  OF  EDITOR 

13  (P  EXIT-UPDATE  LEAVES  THE  EDITOR  AND  RETURNS  TO  FORTH.  IF 

14  THE  SCREEN  HAS  BEEN  MODIFIED,  THE  USER  ID  IS  INSERTED  ON  LINE 

15  0  IN  THE  RIGHT  HAND  CORNER  )  -> 

66 

0  \  E-TAB  25APR81HHL 

1 

2  :  E-TAB  IS  —  ) 

3  8  CURPOS  8  MOD  - 

4  +CURPOS  ; 

5 

6  (P  MOVE  THE  CURSOR  TO  THE  NEXT  TAB  STOP.  TABS  ARE  CURRENTLY 

7  DEFINED  AS  BEING  8  APART,  CAN  BE  BE  RE-DEFINED  BY  SIMPLY 

8  ALTERING  E-TAB  ) 

9 

10  --> 

11 

12 

13 

14 

15 


65 

\  EXIT-SCRATCH  25APR81HHL 

:  EXIT-SCRATCH  (S  —  ) 

C/SCR  MOVE-CURSOR  \  GET  TO  BOTTOM  OF  SCREEN 

CR  CR  \  SKIP  TWO  LINES 

SCR  ?  \  TELL  USER  SCREEN  NUMBER 

Abandoned"  \  AND  WARN  ABOUT  STATUS 

EXIT-EDIT  ;  \  GET  OUT  OF  EDITOR 

IP  EXIT-SCRATCH  HILL  LEAVE  THE  EDITOR  AND  NOT  FLUSH  THE 
SCREEN  TO  DISK.  THE  SCREEN  IS  NOT  MARKED  AS  UPDATED,  BUT 
THIS  CAN  BE  DONE  MANUALLY  HITH  THE  UPDATE  COMMAND.  IT  MAY  THEN 
BE  FLUSHED  HITH  THE  FLUSH  COMMAND,  OR  ERASED  HITH  THE 
EMPTY-BUFFERS  COMMAND  ) 

—  > 

67 

\  SCAN+=  25APR81HHL 

:  SCAN+=  (S  CHAR  ADR1  ADR2  —  N  ) 

2DUP  =  IF  \  RETURN  ZERO  IF  THERE 

DROP  2DR0P  0  \  IS  NOTHING  TO  SEARCH 

ELSE 

0  ROT  ROT  DO  \  OTHERHISE  RUN  THROUGH  MEMORY 
OVER  I  Ci  =  IF  \  FROM  LOH  TO  HIGH 
LEAVE  \  LOOKING  FOR  THE  SPECIFIED  CHARACTER 

ELSE  1+  ENDIF 
LOOP 

SNAP  DROP  \  RETURN  RESULT 

ENDIF  ; 

IP  SCANS  THROUGH  MEMORY  STARTING  AT  ADR2  TO  ADR1  AND 
INCREMENTING  BY  +1  LOOKING  FOR  THE  SPECIFIED  CHARACTER. 

RETURNS  THE  NUMBER  OF  CHARACTERS  SCANNED  UNTIL  SUCCESS  ) 

— > 


6B  69 

0  \  SCAN+O  25APR81HHL  \  SCAN-=  25APR81HHL 


1  :  SCAN+O  (S  CHAR  ADR1  ADR2  —  N  ) 

2  20UP  =  IF  \  RETURN  ZERO  IF  THERE 

3  DROP  2DR0P  0  \  IS  NOTHING  TO  SEARCH 

4  ELSE 

5  0  ROT  ROT  DO  \  OTHERHISE  RUN  THROUGH  MEMORY 

6  OVER  I  Ci  <>  IF  \  FROM  LOH  TO  HIGH 

7  LEAVE  \  UNTIL  ANY  CHARACTER  BUT  THE 

8  ELSE  1+  ENDIF  \  SPECIFIED  ONE  IS  SEEN 

9  LOOP 

10  SHAP  DROP  \  RETURN  RESULT 

11  ENDIF  ; 

12  (P  SCANS  THROUGH  MEMORY  STARTING  AT  ADR2  TO  ADR1  AND 

13  INCREMENTING  BY  +1  UNTIL  ANY  CHARACTER  NOT  MATCHING  THE  ONE 

14  SPECIFIED  IS  FOUND.  RETURNS  COUNT  OF  CHARACTERS  SCANNED  ) 

15  -> 


:  SCAN-=  (S  CHAR  ADR1  ADR2  —  N  ) 

2DUP  =  IF  \  RETURN  ZERO  IF  THERE 

DROP  2DR0P  0  \  IS  NOTHING  TO  SEARCH 

ELSE 

0  ROT  ROT  DO  \  OTHERHISE  RUN  THROUGH  MEMORY 
OVER  I  Ci  =  IF  \  FROM  HIGH  TO  LOH 
LEAVE  \  LOOKING  FOR  THE  SPECIFIED  CHARACTER 

ELSE  1-  ENDIF 
-1  +LOOP 

SHAP  DROP  \  RETURN  RESULT 

ENDIF  j 

(P  SCANS  THROUGH  MEMORY  STARTING  AT  ADR2  TO  ADR1  AND 
DECREMENTING  BY  -1  LOOKING  FOR  THE  SPECIFIED  CHARACTER. 

RETURNS  THE  NUMBER  OF  CHARACTERS  SCANNED  UNTIL  SUCESS  j 

(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


37 

393 


Screen  Oriented  Editor 


(Listing  continued,  text  on  page  27) 


70 

0  \  SCAN-O  25APR81HHL 

1  :  SCAN-O  IS  CHAR  ADR1  ADR2  —  N  ) 

2  2DUP  =  IF  \  RETURN  ZERO  IF  THERE 

3  DROP  2DR0P  0  \  IS  NOTHING  TO  SEARCH 

4  ELSE 

5  0  ROT  ROT  DO  \  OTHERWISE  RUN  THROUGH  MEMORY 

6  OVER  I  C3  <>  IF  \  FROM  HIGH  TO  LOW 

7  LEAVE  \  UNTIL  ANY  CHARACTER  BUT  THE 

8  ELSE  1-  ENDIF  \  SPECIFIED  ONE  IS  SEEN 

9  -1  +L00P 

10  SWAP  DROP  \  RETURN  RESULT 

11  ENDIF  ; 

12  IP  SCANS  THROUGH  MEMORY  STARTING  AT  ADR2  TO  ADR1  AND 

13  DECREMENTING  BY  -1  UNTIL  ANY  CHARACTER  NOT  MATCHING  THE 

14  SPECIFIED  ONE  IS  FOUND.  RETURNS  COUNT  OF  CHARACTERS  SCANNED  i 

15  --> 


71 

\  MOVE-LEFT-WORD 
:  MOVE-LEFT-WORD  IS  - 
BL  0  BUF-ADR  BUFPOS 
SCAN-=  >R 

BL  0  BUF-ADR  BUFPOS 
SCAN-O  R>  +  >R 
BL  0  BUF-ADR  BUFPOS 
SCAN-=  R>  + 

DUP  BUFPOS  +  Ci  BL  = 
1  + 

ENDIF  ; 

IP  RETURNS  THE  NUMBER  OF 
MOVE  TO  THE  BEGINNING  OF 
CURRENT  CURSOR  POSITION. 
THAN  OR  EQUAL  TO  ZERO  ) 
--> 


25APR81HHL 


N  ) 


\  SCAN  BACKWARDS  FOR  THE 
\  FIRST  BLANK 

R  +  \  NOW  SCAN  BACKWARDS  FOR  THE 

\  FIRST  NON  BLANK 

R  +  \  FINALLY  LOOK  FOR  THE  FIRST 

\  BLANK  AGAIN. 

IF  \  CORRECT  FOR  THE  POSSIBILITY 
\  THAT  BLANK  WAS  NOT  FOUND 
\  AT  THE  BEGINNING  OF  THE  SCREEN 
CHARACTERS  THAT  MUST  BE  SKIPPED  TO 
THE  PREVIOUS  WORD.  RELATIVE  TO  THE 
THE  NUMBER  RETURNED  IS  ALWAYS  LESS 


72 

0  \  MOVE-RIGHT-WORD 
1 

2  :  MOVE-RIGHT-WORD  IS  —  N  ) 

3  BL  I  C/SCR  1-  ]  LITERAL  BUF-ADR 

4  BUFPOS  SCAN+-  >R 

5  BL  I  C/SCR  1-  I  LITERAL  BUF-ADR 

6  BUFPOS  R  + 

7  SCAN+O  R>  +  ; 

8 

9  IP  RETURNS  THE  NUMBER  OF  CHARACTERS  THAT  MUST  BE  SKIPPED  TO 

10  MOVE  TO  THE  BEGINNING  OF  THE  NEXT  WORD  RELATIVE  TO  THE  CURRENT 

11  CURSOR  POSITION.  ) 

12 

13  ~> 

14 

15 


25APR81HHL 

:  R-WORD  IS  —  ) 

MOVE-RIGHT-WORD  \  MOVE  FORWARD  1  WORD 

+CURPOS  ;  \  AND  UPDATE  CURSOR 

IP  R-WORD  MOVES  THE  CURSOR  RIGHT  1  WORD.  THE  CURSOR  IS  LEFT 
AT  THE  BEGINNING  OF  THE  WORD.  IF  THERE  ISN’T  ANY,  THE  CURSOR 
MOVES  TO  THE  END  OF  THE  SCREEN  ) 

:  L-WORD  IS  —  ) 

MOVE-LEFT-WORD  \  MOVE  BACKWARDS  1  WORD 

+CURP0S  ;  \  AND  UPDATE  CURSOR 

IP  L-WORD  MOVES  THE  CURSOR  LEFT  1  WORD.  THE  CURSOR  IS  LEFT 
AT  THE  END  OF  THE  PREVIOUS  WORD.  IF  THERE  ISN’T  ANY,  THE 
CURSOR  MOVE  TO  THE  BEGINNING  OF  THE  SCREEN  ) 

--> 


73 

25APR81HHL  \  R-WORD  L-WORD 


74 

\  DEL-CHARS 


25APR81HHL 


2 

3 

4 

5 

6 

7 

8 
9 

10 

11 

12 

13 

14 

15 


DEL-CHARS 


IS  N  POS  —  ) 


2DUP  +  OVER 
DUP  CHARS-TO-EOL 
BUF-MOVE 

DUP  CHARS-TO-EOL  + 
OVER  -  BUF-ADR 
SWAP  BLANKS  : 


\  N  P  FROM  P 
\  N  P  F  P  L 
\  N  P 
\  N  EOL 
\  N  EOL-N 

\  FILL  END  WITH  BLANKS 


(P  DEL-CHARS  DELETES  N  CHARACTERS  STARTING  AT  POSITION  POS. 
THIS  IS  USED  MAINLY  FOR  DELETING  ENTIRE  WORDS  AT  ONE  TIME. 
IT  IS  MUCH  FASTER  THAN  CALLING  DEL-CHAR  N  TIMES  FOR  MOST 
WORDS  ) 


75 

\  D-WORD 


25APR81HHL 


D-WORD  IS  —  ) 
MOVE-RI6HT-WORD 
CURPOS  BUF-ADR 
CURPOS  CHARS-TO-EOL 
-TRAILING  SWAP  DROP 
MIN  CURPOS  DEL-CHARS 
CURPOS  DISPLAY-TO-EOL  ; 


\  MOVE  OVER  1  WORD 
\  BUT  LESS  THAN  LAST  BLANK 
\  ON  THE  CURRENT  LINE 
\  FOR  SPEED 
\  AND  DELETE  TEXT 
\  AND  SHOW  RESULT 


IP  D-WORD  DELETES  THE  NEXT  WORD  IN  THE  INPUT  STREAM.  NOTE 
THAT  CHARACTER  AND  WORD  DELETION  AFFECT  ONLY  THE  CURRENT 
LINE  ) 


-> 


38 

394 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


76 

0  \  U-TAB  D-TAB  CRL-SCREEN 
1  :  U-TAB  (S  —  ) 


2  4  C/L  I 

3  MINUS  +CURPOS  ; 

4 

5  :  D-TAB  (S  —  ) 

6  4  C/L  t 

7  +CURPQS  ; 

8 

9  :  CLR-SCREEN  (S  — 

10  0  {.CURSOR  ! 

11  CURPOS  BUF-ADR 

12  C/SCR  BLANKS 

13  0  DI3PLAY-T0-E0S 

14  E-UPDATE  ; 

15  --> 


\  MOVE  UP  4  LINES 


\  MOVE  DOWN  4  LINES 


\  RESET  CURSOR 
\  SET  BUFFER  ADDRESS 
\  AND  SET  ALL  TO  BLANKS 
\  AND  RE  DISPLAY 
\  INDCATE  SCREEN  CHANGED 


77 

25APR81HHL  \  DISPLAY-STATUS 

:  DISPLAY-STATUS  (S  — 
RHODE  3  (.OLD-MODE  3  (> 
40  0  CRTXY 
RHODE  3  IF 
Insert  QN“ 

ELSE 

9  SPACES 
END  IF 

{.MODE  3  {.OLD-MODE  ! 
ENDIF 

CURPOS  C/L  / HOD 
35  0  CRTXY  2  .R 
28  0  CRTXY  2  .R  ; 


21APR81HHL 

) 

IF  \  HAS  MODE  CHANGED? 

\  MOVE  CURSOR 
\  1= INSERT  0=0VERSTR IKE 
\  DISPLAY  MESSAGE  ON  THE 
\  STATUS  LINE 


\  RESET  OLD  MODE 

\  CHAR  POS,  LINE! 
\  DISPLAY  LINE# 

\  DISPLAY  CHARI 


78  79 

0  \  CLR-LINE  25APR81HHL  \  GET-USER-ID  25APR81HHL 


1 

2  :  CLR-LINE  iS  —  ) 

3  CURPOS  DUP  \  SAVE  CURRENT  CURSOR  POSITION 

4  >L INE#  LINED  {.CURSOR  I  \  GET  TO  BEGINNING  OF  LINE 

5  CURPOS  BUF-ADR  \  BUFFER  ADDRESS  OF  BOL 

6  C/L  BLANKS  \  BLANK  IT  OUT 

7  E-UF'DATE  \  INDICATE  TEXT  HAS  CHANGED 

8  0  MOVE-CURSOR  \  GET  TO  BEGINNING 

9  CURPOS  CLEAR-TO-EOL  \  AND  CLEAR  THE  LINE 

10  {.CURSOR  1  ;  \  RESTORE  THE  CURSOR 

11 

12  IP  CLR-LINE  SETS  THE  CURRENT  LINE  TO  BLANKS  ) 

13 

14  --> 

15 


:  GET-USER-ID  (S  —  ) 

{.E-ID  10  -TRAILING  0=  IF  \  IS  USER  ID  BLANK7 
CR  Enter  Your  ID:  ’  \  PROMPT  USER 

10  0  DO  46  (  .  )  EMIT  LOOP  \  DISPLAY  FIELD  LENGTH 

10  0  DO  8  (  BS  )  EMIT  LOOP  \  AND  BACK  UP 

10  EXPECT  \  LET  THE  USER  ENTER  IT 

{.E-ID  10  -TIDY  \  REPLACE  CONTROL  CHARS  WITH  BLK 

ELSE  \  ALREADY  ENTERED  USER  ID 

DROP  \  IF  HERE 

ENDIF  ; 

(P  GET-USER-ID  CHECKS  TO  SEE  IF  THE  USER’S  ID  HAS  BEEN  SET,  AND 
IF  NOT,  PROMPTS  HIM  FOR  IT  AND  SAVES  IT  ) 

-> 


80  81 
0  \  CONTROL  CHARACTER  DEFINITIONS  21APR81HHL  \  CONTROL  CHARACTER  DEFINITIONS  21 APR81HHL 

1 


2  CASE:  (CONTROL-CHAR)  (S  N  —  ) 

BEEP 

\  10:  AJ 

—  ERROR 

3 

CLR-SCREEN 

\  11:  AK 

—  CLEAR  SCREEN 

4 

BEEP 

\ 

0:  A3  —  ERROR 

BEEP 

\  12:  AL 

—  ERROR 

5 

L-WORD 

\ 

1:  AA  —  LEFT  WORD 

RETURN 

\  13:  AH 

—  CARRIAGE  RETURN 

6 

CLR-LINE 

\ 

2:  AB  —  CLEAR  LINE 

1-LINE 

\  14:  AN 

—  INSERT  LINE 

7 

D-TAB 

\ 

3:  AC  —  DOWN  4  LINES 

BEEP 

\  15:  A0 

—  ERROR 

8 

R-ARROW 

\ 

4:  AD  —  RIGHT  ARROW 

BEEP 

\  16:  AP 

—  ERROR 

9 

U-ARRQW 

\ 

5:  AE  —  UP  ARROW 

BEEP 

\  17:  AS 

—  ERROR 

10 

R-WORD 

\ 

6:  AF  —  RIGHT  WORD 

U-TAB 

\  18:  AR 

—  UP  4  LINES 

11 

D-CHAR 

\ 

7:  A6  —  DELETE  CHAR 

L-ARROW 

\  19:  AS 

—  LEFT  ARROW 

12 

L-ARROW 

\ 

8:  AH  —  LEFT  ARROW 

— > 

13 

E-TAB 

\ 

9:  AI  —  TAB  TO  NEXT  COLUMN 

14  ~> 

15 

(Continued  on  next  page) 


Di.  Dobb’s  Journal,  Number  59,  September  1981 


39 

395 


Screen  Oriented  Editor 


(Listing  continued,  text  on  page  27) 


CONTROL  CHARACTER  DEFINITIONS 


25APR81HHL  \  CONTROL-CHAR 


25APR81HHL 


D-WORD  \  20:  AT 
BEEP  \  21:  AU 
INSERT-MODE  \  22:  AV 
BEEP  \  23:  AW 
D-ARROW  \  24:  AX 
D-LINE  \  25:  AY 
EXIT-SCRATCH  \  26:  A2 


DELETE  WORD 
ERROR 

TOGGLE  INSERT  MODE 
ERROR 

DOWN  ARROW 
DELETE  LINE 
ABANDON  SCREEN 


EXIT-UPDATE  \  27:  ESC  -  EXIT  EDITOR  NORMALLY 


CONTROL-CHAR  !S  CHAR  —  ) 


DUP  127  =  IF 
DROP  8 
ENDIF 

DUF  28  <  IF 
(CONTROL-CHAR) 
ELSE 

DROP  BEEP 
ENDIF  : 


\  IF  ITS  A  DELETE 
\  THEN  TURN  IT  INTO 
\  A  BACKSPACE 
\  MIGHT  IT  BE  VALID? 
\  YES,  SO  GO  DO  IT 

\  NO,  COMPLAIN 


(P  PROCESS  A  CONTROL  CHARACTER.  IF  THE  CHARACTER  IS  A  DELETE, 
IT  IS  CHANGED  INTO  A  BACKSPACE.  IF  IT  IS  LESS  THAN  OR  EQUAL  TO 
AN  ESCAPE,  IT  IS  EXECUTED,  OTHERWISE  WE  BEEP.  ) 


0  \  E-OVERSTRIKE  2 

1 

2  :  E-OVERSTRIKE  (S  —  i 

3  KEY  DUP  \  GET  NEXT  KEYSTROKE 

4  ’PRINTABLE  IF  \  IF  ITS  PRINTABLE 

5  DUP  EMIT  \  SHOW  IT  ON  THE  SCREEN 

6  BUFPOS  C!  \  STICK  IT  IN  THE  BUFFER 

7  E-UF'DATE  \  BUFFER  HAS  CHANGED 

B  1  +CURPOS  \  AND  MOVE  THE  CURSOR 

9  ELSE 

10  CONTROL-CHAR  \  ELSE  PROCESS  IT  AS  A  COMMAND 

11  ENDIF  ; 

12  (P  E-OVERSTRIKE  IS  CALLED  WHENEVER  THE  EDITOR  IS  IN 

13  OVERSTRIKE  MODE.  NOTE  THAT  ONLY  A  SINGLE  CHARACTER  IS 

14  PROCESSED,  AND  CONTROL  IS  ALWAYS  RETURNED  TO  THE  MAIN 

15  PROCESSING  LOOP  i  -> 


25APR81HHL  \  E-INSERT 


25APRS1HHL 


E-INSERT  (S  —  ) 

KEY  DUP 
?PR INTABLE  IF 
CURPOS  INS-CHAR 
CURF'OS  DISPLAY-TO-EOL 
1  +CURPOS 
ELSE 

CONTROL-CHAR 
ENDIF  : 


\  GET  THE  NEXT  CHARACTER 
\  CHECK  IF  ITS  PRINTABLE 
\  IF  SO,  INSERT  IT  HERE 
\  RE-DISPLAY  THE  LINE 
\  AND  MOVE  OVER  1 

\  ELSE  PROCESS  THE  COMMAND 


(P  E-INSERT  IS  CALLED  WHENEVER  THE  EDITOR  IS  IN  INSERT  MODE. 
NOTE  THAT  ONLY  A  SINGLE  CHARACTER  IS  PROCESSED  AND  CONTROL  IS 
RETURNED  IMMEDIATELY  TO  THE  CALLING  ROUTINE.  ) 


86 

E-INIT 

E-INIT  (S  INI  —  ) 
DEPTH  IF  SCR  !  ENDIF 
SCR  4  BLOCK  J.BUF-ADR  I 
GET-USER-ID  CRTCLR-SCR 
0  {.MODE  1  0  {.CURSOR  ! 

0  {.UPDATE  1 
0  XY-OFF  CRTXY 
L/SCR  0  DO 
I  3  ,R  CR 
LOOP 

10  0  CRTXY 

Scr :  11  SCR  i  4  ,R  6 
0  BISPLAY-TQ-EQS  ; 


21APR81HHL 


\  EDIT  LAST  SCREEN  IF  STACK  EMPTY 
\  SAVE  THE  BUFFER  ADDRESS 
\  GET  DATE  AND  NAME  i  CLEAR  SCREEN 
\  INIT  VARIABLES 
\  NOT  MODIFIED 
\  MOVE  CURSOR  TO  START 
\  DISPLAY  LINE  NUMBERS  FOR  USER 


\  MOVE  TO  STATUS  LINE 
SPACES  ,n  X-  Y=‘ 

\  SHOW  THE  SCREEN 


\  E  25APR81HHL 

FORTH  DEFINITIONS 
:  E  !S  INI  —  i 

EDITOR  \  LOOK  THROUGH  THE  EDITOR  VOCABULARY 

E-INIT  \  INITIALIZE  THE  SCREEN 

BEGIN  \  THIS  IS  THE  ONLY  LOOP  IN  THE  EDITOR 

DISPLAY-STATUS  \  DISPLAY  THE  STATUS  ON  LINE  0 

0  MOVE-CURSOR  \  MOVE  THE  CURSOR  TO  WHERE  IT  SHOULD  BE 

{.MODE  4  IF  \  CHECK  THE  MODE,  1=INSERT  0=0VERSTRIKE 

E-INSERT 
ELSE 

E-OVERSTRIKE 
ENDIF 
AGAIN  ; 

(p  USED  TO  INVOKE  THE  EDITOR.  SCREEN  NUMBER  SHOULD  BE  ON  STK  i 


40 

396 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


\  ASK  USER  ABOUT  HIS  TERMINAL 


26APR31HHL  \  NO  SUCH  TERMINAL 


26APR81HHL 


CR  ."  It  your  terminal  is  one  oP  the  ones  listed  helot*' 

CR  just  enter  the  corresponding  number.  It  not,  you' 

CR  will  have  to  write  your  own  cursor  addressing  routines" 

CR  CR 

CR  0  =  None  ot  the  below'1 
CR  1  -  Perkin  Elmer  Bantam” 

CR  2  =  Lear  Ziegler  ADM3“ 

CR  CR 

CR  Enter  your  Terminal  number  please  "  RE-FORTH 


Well,  take  a  look  at  SCREENS  42  -  44  " 
to  see  how  to  proceed" 

It  you  would  like  me  to  include  your  terminal  routines" 
in  the  next  release  of  this  editor,  please  send  me" 
the  code  you  wrote  to  drive  your  terminal.  Thanks." 
Good  luck,  and  may  the  FORTH  be  with  you" 


EDITOR  DEFINITIONS  89  +  LOAD  FORTH  DEFINITIONS 
CR  ."  Ready  to  Edit1  CR  CR 


0  \  PERKIN-ELMER  CURSOR  ROUTINES 
1 

2  :  PE-CRTXY  (S  X  Y  —  ) 

3  32+88  27  EMIT  EMIT  EMIT 

4  32+89  27  EMIT  EMIT  EMIT  ; 


19SEP80HHL  \  ABM-3  CURSOR  ROUTINES 

:  ADH3-CRTXY  IS  X  Y  —  ) 
27  EMIT  61  EMIT  (  ESC  =  ) 
32  +  EMIT  32  +  EMIT  ; 


19SEP80HHL 


PE-CRTCLR-SCR  (S  —  ) 
75  27  EMIT  EMIT 
10  0  DO  0  EMIT  LOOP  ; 


:  ADM3-CRTCLR-SCR  (S  — 
26  EMIT  (  AZ  ) 

10  0  DO  0  EMIT  LOOP  ; 


PE-CRTCLR-EOL  (S  N  —  ) 
DROP  73  27  EMIT  EMIT  ; 


:  ADM3-CRTCLR-E0L  (S  N  — 
C/L  MOD  C/L  SWAP  -  SPACES  j 


PE-CRTXY  CFA  ’CRTXY  ! 

PE-CRTCLR-SCR  CFA  ’CRTCLR-SCR  1 

PE-CRTCLR-EOL  CFA  T  CLEAR-TO-EOL  1 


’  ADM3-CRTXY  CFA  ’CRTXY  1 

’  ADM3-CRTCLR-SCR  CFA  ’CRTCLR-SCR  ! 

’  ADM3-CRTCLR-E0L  CFA  ’CLEAR-TO-EOL  1 


PERKIN-ELMER  CURSOR  ROUTINES 


19SEP80HHL  \ 


The  Rest  is  Silence 


25JAN81HHL 


L  \ 

PE-CRTXY  (S  X 

Y  — 

-  ) 

j 

32  +  88  27  EMIT 

EMIT 

EMIT 

4 

32  +  89  27  EMIT 

EMIT 

EMIT  ; 

6  : 

PE-CRTCLR-SCR 

(S  — 

■  ! 

7 

75  27  EMIT  EMIT 

d 

10  0  DO  0  EMIT 

LOOP  : 

V-j  : 

PE-CRTCLR-EOL 

(S  N  - 

—  ) 

•  t 

i  i 

DROP  73  27  EMIT 

EMIT 

5 

1  i 

13  : 

!  PE-CRTXY 

CFA 

’CRTXY  1 

14  ' 

PE-CRTCLR-SCR 

CFA 

CRTCLR-SCR  : 

15  : 

:  PE-CRTCLR-EOL 

CFA 

’CLEAR-TO-EOL 

mmmtmumtmtmmmmmmmttmum 

» 

i  Please  direct  ail  questions,  comments,  and 
X  misc.  personal  abuse  to: 

X 

X  Henry  Laxen 

X  1259  Cornell  Ave. 

X  Berkeley,  California 

X  96706 

X 

X  (415)  525-8582 

X 

ixtxxtxxxxktxxxixtxtxixxxtxxxxxixxixxxxxxxxtixxxxixixt 


End  Listing 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


41 

397 


Elements  of  a  FORTH 
Data  Base  Design 


In  the  spirit  of  the  FORTH  Interest 
Group,  this  discussion  and  the  FORTH 
screens  are  placed  in  the  public  domain. 
However,  further  distribution  must  in¬ 
clude  this  notice  and  an  appropriate 
acknowledgment. 

In  this  day  and  age,  data  base  design  and 
manipulation  is  one  of  the  major  activi¬ 
ties  best  accomplished  with  computers. 
In  practice,  FORTH  proves  to  be  an  ideal 
language  for  developing  and  using  custom 
data  bases.  By  comparison  with  other 
languages,  high  or  low  level,  FORTH  is  a 
winner.  It  meets  the  requirements  of  be¬ 
ing  interactive  and  providing  documenta¬ 
tion  as  identified  by  Fred  Brooks  in  his 
The  Mythical  Man-Month  as  ideal  for  the 
development  of  new  systems.  The  amaz¬ 
ing  speed  and  ease  with  which  custom 
data  bases  can  be  developed  more  than 
justifies  the  effort  required  to  learn 
FORTH. 

I  have  developed  a  number  of  small 
data  bases  of  up  to  800  records  contain¬ 
ing  128  bytes  each  to  serve  my  specific 
needs.  I  have  also  initialized,  with  simple 
formatted  input  and  output  routines,  a 
custom  data  base  for  inventory  control  in 
a  few  hours  one  evening.  Having  used  lan¬ 
guages  other  than  FORTH  for  similar 
work,  it  is  highly  unlikely  I  will  ever  go 
back  to  them. 

This  discussion  presents  a  group  of 
utility  FORTH  word  definitions  which 
facilitate  the  development  of  custom  data 
bases  and  a  sample  application  using 
utilities  to  define  a  small  file.  A  number 
of  techniques  available  in  FORTH  are  il¬ 
lustrated. 

Some  months  ago,  at  a  regular 
monthly  meeting  of  the  FORTH  Interest 
Group  in  Hayward,  California,  the  prime 
mover  of  the  group  distributed  and  dis¬ 
cussed  several  FORTH  screens  which  pro¬ 
vided  the  foundation  for  beginning  the 
definition  of  a  data  base  file.  I  have  modi¬ 
fied  his  screens  slightly  and  expanded 
them  to  provide  a  general  framework 
with  which  to  define  custom  accounting 
data  bases.  I  will  assume  that  the  reader 


by  Glen  B.  Haydon 


Glen  B.  Haydon,  Haydon  Enterprises, 
Box  429  Route  2,  La  Honda  CA  94020. 

Copyright  ©  1 981  by  Haydon  Enterprises. 
All  Rights  Reserved. 


has  some  knowledge  of  the  fig-FORTH 
Model  and  proceed  with  the  examination 
of  screens  developed  from  it.  In  this  dis¬ 
cussion,  FORTH  words  are  in  all  capital 
letters  to  set  them  apart  from  the  English 
words  in  the  text. 

The  first  two  screens  provide  eight 
utility  FORTH  words  for  developing  a 
data  base  file.  The  comments  included 
within  parentheses  in  the  screens  should, 
combined  with  the  mnemonic  nature  of 
the  words,  give  you  a  clue  to  what  is  hap¬ 
pening.  The  first  two  words  are  variables 
used  in  manipulating  the  file,  REC#and 
OPEN.  2@  is  a  FORTH  word,  and  abas 
for  D@,  which  fetches  the  next  two  val¬ 
ues  beginning  with  the  address  on  the  top 
of  the  stack  and  places  them  on  the  stack. 
The  word,  LAYOUT,  places  two  para¬ 
meters  of  the  new  definition  of  a  file  on 
the  stack  for  subsequent  use.  READ  is 
the  first  word  one  will  have  occasion  to 
use  in  routine  manipulating  records  in  the 
data  base.  It  takes  the  number  of  the  de¬ 
sired  record  from  the  top  of  the  stack 
and,  after  checking  to  see  that  it  is  a  valid 
record,  places  its  value  in  the  variable 
REC#  which  is  used  to  identify  the 
record  then  under  consideration.  The 
word  RECORD  takes  the  value  for  a  rec¬ 
ord  number  from  the  stack  and  returns  its 
address  to  the  stack.  Finally,  ADDRESS 
takes  the  record  number  at  the  variable 
REC#  and  using  RECORD  leaves  the  ad¬ 
dress  of  that  record  on  the  top  of  the 
stack.  With  only  these  eight  FORTH 
words:  two  variables,  one  utility  word, 
and  four  basic  words  for  file  reference, 
we  can  proceed  to  the  definition  of  three 
defining  words  in  the  next  screen. 

The  three  words  on  the  next  screen 
are  called  defining  words  because  they  are 
used  to  define  new  FORTH  words  as  the 
names  of  fields  in  our  record  and  to  de¬ 
fine  the  name  for  the  file  we  are  defining, 
each  with  specific  properties.  These 
words  utilize  the  combination  of  the 
FORTH  primitives  <  BUILDS  and 
DOES>  which  are  present  in  the  model. 
It  may  take  some  time  to  fully  appreciate 
what  these  primitive  words  accomplish 
and  the  way  they  work.  Perhaps  an  ex¬ 
amination  of  what  they  are  doing  in  this 
screen  will  help  you  understand  their 
function. 

Two  types  of  record  fields  are  distin¬ 
guished  and  defined  with  separate  words, 
a  numerical  or  data  field  and  a  text  field. 
The  first  word,  DFIELD,  is  used  to  add 
to  a  record  being  defined,  a  field  contain¬ 
ing  the  number  of  bytes  given  on  the  top 


of  the  stack  and  gives  that  field  a  name. 
In  subsequent  use,  that  newly  defined 
word  (data  field  name)  will  cause  the  ad¬ 
dress  of  that  field  in  the  record  whose 
value  is  currently  in  the  variable  REC# 
to  be  left  on  the  stack.  This  word  is  used 
to  identify  the  location  in  a  record  where 
a  numerical  value  is  to  be  stored  in  a  bi¬ 
nary  form.  I  call  it  a  “data  field,”  in  con¬ 
trast  with  a  “text  field”  in  which  the 
length  of  the  field  should  also  be  immedi¬ 
ately  available.  Thus  TFIELD  is  used  to 
define  a  “text  field”  which  will  identify  a 
field  in  the  new  record  with  a  length 
equal  to  the  number  of  bytes  given  on  the 
top  of  the  stack,  and  gives  that  field  a 
name.  In  subsequent  use,  that  newly  de¬ 
fined  word  (text  field  name)  will  cause 
not  only  the  address  of  that  text  field  in 
the  record  whose  value  is  currently  in  the 
variable  REC#  to  be  left  on  the  stack, 
but  also  the  length  of  that  field.  The 
length  is  convenient  when  the  primitive 
word  TYPE  is  used  to  print  the  character 
string  in  that  field.  Obviously,  the  length 
is  not  needed  in  a  data  field.  Thus  provi¬ 
sions  are  made  for  defining  two  types  of 
fields  in  a  record.  As  new  fields  are  added 
to  a  record  in  the  course  of  its  definition, 
the  current  length  of  the  record  is  main¬ 
tained  on  the  top  of  the  stack. 

Once  the  definition  of  the  fields  in  a 
record  is  completed,  the  value  of  the  rec¬ 
ord  length  remains  on  the  stack.  To  this 
we  need  to  add  values  for  the  number  of 
records  we  wish  to  include  and  finally  the 
block  number  in  which  the  records  are  to 
start,  before  we  can  use  the  defining  word 
FILE  to  give  the  file  a  name.  Later  when 
the  new  file  name  is  used,  the  address  of 
the  necessary  file  parameters  is  placed  in 
the  recently  defined  variables  OPEN  as 
required  for  access  to  any  given  record 
with  the  words  defined  in  the  first  screen. 

With  these  two  screens  we  have  the 
file  utilities  necessary  to  define  a  new  file. 
However,  several  characteristics  of  the 
particular  implementation  of  FORTH 
which  is  being  used  are  important.  Most 
systems  created  under  the  model  have 
128  bytes  per  block  although  any  multi¬ 
ple  of  128  can  be  used.  In  these  systems 
then,  the  largest  record  length  can  be  no 
longer  than  128  bytes,  but  with  a  larger 
block  size,  larger  records  can  be  used.  In 
order  to  take  maximum  advantage  of  the 
block  size,  it  should  be  very  nearly  equal 
to  a  multiple  of  the  record  length.  For  ex¬ 
ample,  a  record  length  of  70  bytes  would 
not  leave  enough  room  in  a  128  byte 
block  for  a  second  record  and  in  this  case 


42 

398 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


58  bytes  of  space  would  be  wasted.  If 
need  be,  such  a  designed  file  would  work, 
but  at  the  expense  of  memory  space. 
Also,  the  initial  block  to  be  used  in  the 
definition  created  by  the  word  FILE 
must  be  chosen  according  to  the  block 
size  for  the  particular  implementation. 
For  example,  block  400  in  an  implemen¬ 
tation  with  128  bytes  per  block  would  be 
block  50  in  an  implementation  with  1024 
bytes  per  block.  Although  I  find  a  block 
size  of  1024  to  be  more  efficient  and  use 
it  routinely,  the  screens  presented  here 
have  been  written  for  and  tested  on  an 
implementation  with  128  bytes  per 
block. 

Before  starting  with  a  discussion  of 
an  example  of  the  application  of  these 
file  development  utilities,  several  screens 
of  utilities  for  use  in  the  input  and  out¬ 
put  of  numerical  data  will  prove  to  be 
most  helpful.  These  include  a  group  of 
double  precision  utilities,  date  compres¬ 
sion  and  expansion  routines,  and  numeri¬ 
cal  routines  for  handling  dollar  amounts 
and  storing  them  as  double  precision  inte¬ 
gers. 

The  double  precision  integer  utilities 
are  used  in  date  compression  and  expan¬ 
sion  as  well  as  in  the  double  precision 
integer  operations  for  dollar  amounts. 
These  are  simple  extensions  from  the 
limited  double  precision  words  found  in 
the  model  and  should  require  no  further 
explanation.  The  input  on  the  stack  be¬ 
fore  executing  the  word  and  the  output 
left  on  the  stack  afterwards  are  indicated 
in  the  format  used  in  the  fig-FORTH 
Glossary.  You  will  note  that  several  of 
these  are  mixed  double  and  single  preci¬ 
sion  operations  which  are  sufficient  for 
the  requirements  of  this  program. 

The  date  compression  routine  is  real¬ 
ly  simple.  When  I  find  the  time  I  will 
develop  an  algorithm  to  convert  the  date 
to  a  true  Julian  day  and  store  the  least 
significant  value.  This  would  make  calcu¬ 
lation  of  the  time  between  two  given 
dates  easy.  In  the  meantime,  the  present 
routine  allows  one  to  enter  the  date  as 
numerical  values  separated  by  slashes,  a 
commonly  used  format,  and  reduce  the 
value  to  a  single  16-bit  integer  requiring 
only  two  bytes  for  storage.  The  routine 
provides  an  example  of  using  a  delimiter 
other  than  a  space  to  parse  WORD  and 
the  use  of  NUMBER  to  interpret  a 
numerical  value  without  searching  the 
dictionary.  After  the  parsing  of  the  input, 
three  double  precision  numbers  are  left 
on  the  stack.  The  word  DATEBIT  defines 


a  simple  algorithm  which  is  applied  to 
reduce  these  three  double  precision  values 
to  16  bits.  The  execution  of  7DATE  first 
prompts  with  the  format  to  be  used,  then 
waits  for  the  value  to  be  entered.  The 
value  is  then  converted  to  the  16  bits  and 
left  on  the  stack  for  storage.  Since  .  is 
used  to  connote  “print”  in  FORTH, 
.DATE  is  defined  to  print  a  properly 
formatted  date  from  a  16-bit  integer  on 
the  stack.  This  routine  is  useful  as  an 
example  of  conversion  of  a  binary  value 
to  a  text  string  for  printing. 

Finally,  we  have  a  screen  to  define 
some  FORTH  words  used  to  input  and 
output  dollar  amounts  and  convert  them 
to  and  from  double  precision,  32-bit 
integers  with  the  necessary  scaling  for  the 
location  of  the  decimal  point.  In  FORTH, 
the  use  of  a  decimal  point  forces  an  input 
number  to  a  double  precision  integer 
which  takes  four  bytes.  A  convenient 
FORTH  primitive  word,  DPL  for  decimal 
point  locator,  keeps  a  count  on  the  num¬ 
ber  of  digits  entered  following  the  deci¬ 
mal  point.  Utilizing  this  value  as  an  input 
for  a  case  type  word,  the  numerical  value 
entered  can  be  scaled  properly,  regardless 
of  how  many  digits  are  entered  to  the 
right  of  the  decimal,  if  any.  This  method 
of  executing  a  case-like  routine  is  straight¬ 
forward.  First,  the  action  to  be  taken  in 
each  case  is  defined.  0SCALE  means  that 
there  were  no  digits  to  the  right  of  the 
decimal,  which  requires  that  the  entered 
double  precision  integer  must  be  multi¬ 
plied  by  100.  In  a  similar  manner 
1  SCALE  is  used  meaning  that  there  was 
only  one  digit  entered  following  the  deci¬ 
mal  point  and  the  entered  double  preci¬ 
sion  integer  must  be  multiplied  by  10. 
2SCALE  doe  nothing,  since  no  scaling  is 
needed.  Finally,  if  more  than  2  digits  are 
entered,  an  error  must  have  been  made 
and  an  appropriate  error  message  is  given. 
Once  each  of  these  cases  is  defined,  their 
code  filed  addresses,  CFA,  can  be  stored 
beginning  with  the  address  of  a  defined 
variable  NSCALE  and  extending  into  the 
allotted  space.  The  word  SCALE  then 
finds  the  value  of  the  variable  DPL  and 
counts  over  to  the  proper  code  field 
address  which  is  then  placed  on  the  stack 
and  the  selected  word  is  executed. 

After  this  scaling  operation,  the  word 
to  input  a  dollar  amount  ?$ AMOUNT  is 
defined,  which  leaves  the  scaled  double 
precision  integer  on  the  stack  ready  to 
be  stored.  Finally,  a  routine  defined  by 
the  word  .SAMOUNT  connoting  “print 
dollar  amount,”  will  print  the  double 


precision  integer  on  the  top  of  the  stack 
as  a  dollar  value  right  justified  in  eight 
spaces. 

There  are  certainly  other  and  probab¬ 
ly  better  ways  to  accomplish  the  work 
done  by  these  three  screens  of  utilities, 
but  they  work.  The  way  they  work  pro¬ 
vides  some  examples  of  the  beauty  of 
FORTH  as  it  exists  in  the  model. 

With  these  five  screens,  we  can  very 
quickly  define  a  record  for  a  data  base 
with  custom  selected  fields  and  then  the 
associated  file  characteristics.  In  the  past, 
I  have  several  times  included  in  a  data 
base  values  calculated  from  other  values 
in  the  base.  On  occasion,  it  has  been 
necessary  to  change  one  of  the  original 
values.  This  has  always  required  that  the 
calculated  fields  be  re-done  too.  I  now 
find  that  it  is  more  convenient  to  enter 
only  the  basic  data.  All  calculations  can 
be  made  while  the  output  is  being  for¬ 
matted  and  printed  with  no  significant 
loss  of  time.  The  slowest  part  of  print¬ 
ing  the  formatted  result  is  the  delay  in 
the  output  device. 

As  an  example  of  the  definition  of  a 
new  data  base,  I  have  chosen  one  in 
which  each  record  would  be  allotted  4 
fields  for  a  two  byte  tag,  a  30  byte  stock 
name,  a  two  byte  date,  and  a  4  byte  stock 
price.  Though  little  could  be  done  with 
this  as  a  data  base,  it  does  provide  an  ex¬ 
ample  of  each  type  of  input.  Finally,  a 
simple  set  of  routines  is  given  to  clear  the 
records,  input  new  records,  and  print  out 
a  list  of  the  records  in  the  file. 

As  a  matter  of  convention,  I  give 
each  field  a  name  with  no  prefix.  Thus  a 
data  field  name  will  leave  an  address  on 
the  stack  and  a  text  field  name  will  leave 
an  address  and  count  on  the  stack.  By 
using  the  FORTH  connotations  of  !  for 
store  and  .  for  print,  I  define  some  utili¬ 
ties  for  inputting  data  and  text,  and  for 
printing  out  the  respective  fields.  From 
these  utilities  I  can  assemble  an  input  for¬ 
mat  and  an  output  format  as  desired.  I 
have  not  included  routines  for  error 
checking,  which  would  be  most  desirable 
especially  in  a  hostile  environment. 

Now  to  examine  the  actual  example 
of  the  definition  of  a  file  which  we  will 
call  DEMO.  Each  record  will  begin  with 
zero  offset  from  the  record  address  and  a 
0  is  entered  followed  by  2  for  a  two-byte 
length  of  a  data  field  to  be  named  TAG. 
Many  occasions  in  later  manipulation  of 
records  make  it  desirable  to  have  such  a 
field  for  adding  flags,  etc.  Following  this 
definition  the  length  value  of  2  is  left  on 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


43 

399 


the  stack  so  that  for  the  next  field  only 
its  length  need  be  entered.  In  this  case  a 
text  field  of  30  bytes  which  is  given  the 
name  NAME  which  then  leaves  the  value 
of  32  (the  length  of  the  TAG  field  plus 
the  NAME  field)  on  the  stack.  Then  a 
two- byte  data  field,  DAY,  is  reserved  for 
a  16-bit  compressed  date  and  then  a  four- 
byte  data  field  DOLLAR,  for  a  double 
precision  integer  value  of  a  dollar  a- 
mount.  With  this,  the  4  fields  within  the 
record  of  a  new  file  are  defined.  Next  we 
will  define  the  file  name.  According  to 
the  utility  for  generating  a  new  file,  we 
must  first  add  to  the  value  of  the  record 
length  remaining  on  the  stack,  a  value  for 
the  number  of  records  we  plan  to  include 
in  the  file  and  then  the  first  block  num¬ 
ber  to  be  used  as  determined  by  the 
FORTH  implementation  in  use.  Then,  we 
use  the  word  FILE  to  create  a  file  with 
these  parameters  and  give  it  the  name 
DEMO.  The  data  base  file  is  now  defined. 
For  the  record  number  whose  value  is  in 
the  variable  REC#,  we  can  place  the 
value  of  the  address  of  the  data  fields, 
the  address  and  count  of  the  text  fields 
on  the  stack  by  simply  entering  the  field 
name.  Next  a  few  simple  utilities  will 
make  accessing  these  new  fields  easier. 

Remembering  the  connotations  asso¬ 
ciated  with  the  FORTH  words  !  and  .  we 
will  define  words  to  input  data  or  text 
to  the  appropriate  fields  of  that  record 
whose  value  is  currently  in  the  variable 
REC#.  These  are  simple  file  primitives 
which  will  then  be  available  for  routines 
to  format  input  and  output  as  desired. 
The  field  TAG  is  not  used  at  this  time 
and  specific  routines  are  not  defined.  To 
store  a  name  in  the  name  field  we  define 
the  word  !NAME.  This  routine  first  fills 
the  existing  field  with  blanks,  ASCII  32 
(decimal)  and  then  pauses  for  input  from 
the  keyboard.  The  input  text  is  truncated 
to  the  maximum  length  of  the  text  field 
if  necessary  and  then  moved  to  that  field. 
In  order  to  output  the  name  in  the  field 
we  define  the  word  .NAME.  In  a  similar 
manner  we  define  !DAY  to  store  a  16- 
bit  integer  value  of  a  date  which  has  been 
compressed  into  that  field.  In  the  earlier 
utilities  we  have  already  defined  7DATE 
which  waits  for  a  date  to  be  input  and 
leaves  the  compressed  value  on  the 
stack.  All  that  is  necessary  is  to  put 
the  address  of  the  field  on  the  stack 
with  DAY  and  then  store  the  encoded 
date  there.  We  then  define  .DAY  to  out¬ 
put  the  date  stored  in  the  DAY  field.  We 
get  the  16-bit  value  stored  there  to  the 


top  of  the  stack  and  use  the  previously 
defined  word  .DATE  to  output  it  in  the 
proper  format.  Finally  we  define 
[DOLLAR  to  parse  a  dollar  value  input 
with  a  decimal  point  in  any  location  and 
scaled  to  a  double  precision  number 
which  is  then  stored  in  the  proper  field. 
In  a  similar  manner,  .DOLLAR  is  defined 
to  format  the  stored  double  precision 
integer  to  a  right  justified  eight-digit 
number  preceded  by  a  dollar  sign.  With 
these  definitions,  we  have  completed  a  set 
of  FORTH  words  to  input  and  output 
data  from  records  in  our  data  base. 

Immediately  after  putting  data  into 
a  record,  it  is  often  desirable  to  see  what 
is  actually  present  in  that  record.  The 
values  in  each  byte  of  a  record  can  be  dis¬ 
played  using  a  dump  routine.  Simply 
place  the  desired  record  address  on  the 
top  of  the  stack  by  entering  the  record 
number  followed  by  our  file  utility  word 
READ  and  ADDRESS  followed  by  the 
length  of  the  record  and  the  word  for 
your  dump  routine.  But  the  byte  values 
printed  out  in  hex  or  decimal  are  not 
really  all  that  helpful.  It  is  hard  to  inter¬ 
pret  the  numerical  value  in  their  byte  pat¬ 
tern.  A  convenient  word  .REC  is  defined 
to  print  out  the  current  record  number 
followed  by  the  formatted  output  of  the 
value  in  each  field  using  the  above  utili¬ 
ties  and  an  appropriate  number  of  spaces 
and  carriage  returns.  This  is  the  most 
rudimentary  form  of  a  formatted  output. 
If  desired,  the  output  could  be  presented 
in  reverse  video  by  a  slight  modification 
of  this  routine.  It  could  also  be  placed 
anywhere  on  the  screen. 

Finally,  a  few  examples  of  format¬ 
ting  input  and  output  routines  are  shown 
on  the  last  screen.  First,  it  is  desirable  to 
clear  all  data  in  a  file  with  a  word 
CLEAR. DATA  before  entering  new  data. 
This  particular  definition  clears  only  the 
first  block,  all  that  is  necessary  in  this  ap¬ 
plication.  You  should  be  able  to  modify 
the  definition  of  this  word  to  meet  the 
requirements  of  your  application  and  par¬ 
ticular  implementation  of  FORTH. 

I  use  the  0  record  in  a  file  for  a  vari¬ 
ety  of  information  about  the  file,  which 
I  can  address  directly  from  the  address 
of  its  first  byte  without  using  the  field 
definitions,  or  I  can  use  specific  bytes  or 
fields  in  ways  other  than  I  have  defined 
them.  In  this  example  I  use  the  value  in 
the  integer  at  the  field  TAG  in  the  0  rec¬ 
ord  to  keep  track  of  the  last  record  cur¬ 
rently  in  the  file.  When  this  record  is 
cleared  with  CLEAR.DATA,  a  value  of  0 


is  present  in  the  location  of  TAG  which 
means  that  there  are  no  records  present. 

0  READ  places  the  value  of  0  in  the  vari¬ 
able  REC#  and  then  TAG  places  the  ad¬ 
dress  on  the  top  of  the  stack  and  @  gets 
that  value,  the  last  record  number  used  in 
the  file.  To  add  a  new  record,  this  value  is 
incremented  and  then  duplicated  on  the 
stack.  The  top  copy  is  stored  back  in  the 
field  of  TAG  in  the  0  record  which  is  up¬ 
dated.  Then  the  second  copy  is  placed  in 
the  variable  REC#  and  we  are  ready  to 
fill  in  the  information  for  the  next 
record. 

A  series  of  prompts  can  be  formatted 
on  the  screen  in  any  convenient  arrange¬ 
ment  as  in  this  example.  Following  the 
desired  prompt  for  each  field,  the  previ¬ 
ously  defined  word  is  used  to  get  the  in¬ 
formation  for  the  field  and  store  it  there. 
After  entering  a  record,  it  is  always  nice 
to  see  the  data  you  actually  put  in.  This 
is  done  with  the  word  .REC  followed  by 
the  FORTH  primitive  UPDATE  to  flag 
the  buffer  as  altered  and  FLUSH  to  save 
the  new  record  on  the  disk  in  the  file. 
This  assures  that  the  image  of  the  record 
which  is  displayed  is  the  version  saved  on 
the  disk. 

An  output  format  can  be  developed 
in  a  similar  manner.  In  this  example  I 
have  included  a  check  to  see  if  there  are 
any  records  in  a  file  because  the  DO  .  . . 
LOOP  will  always  print  one  loop  and  pe¬ 
culiar  output  is  generated  if  the  bytes  in 
the  fields  are  all  set  to  zero.  This  output 
routine  presents  a  simple  list  of  the  rec¬ 
ord  numbers  and  the  formatted  content 
of  the  fields. 

In  conclusion,  I  find  this  approach 
to  file  definition  is  time  saving  and  hope 
that  you  will  find  it  useful.  The  discus¬ 
sion  of  the  FORTH  utilities  used  to  de¬ 
fine  a  new  data  base  field  and  the  exam¬ 
ple  of  handling  data,  provides  some 
elaboration  of  the  information  included 
on  the  screens.  This  will  be  a  review  for 
one  who  already  has  learned  the  primi¬ 
tives  in  the  FORTH  model  and  who  un¬ 
derstands  how  the  language  works,  but 
perhaps  the  discussion  of  these  screens 
will  help  those  less  experienced.  There  is 
nothing  sacred  about  the  techniques  used 
here.  Modify  the  various  words  to  suit 
your  particular  needs.  It  is  easy  enough  to 
develop  new  formats  interactively.  How¬ 
ever,  I  would  encourage  you  to  utilize 
and  build  on  the  standards  of  the  fig- 
FORTH  model.  When  the  79  Standards 
become  generally  available,  it  should  be 
relatively  easy  to  update  your  screens 


44 

400 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


without  changing  the  format  of  the 
record  file.  The  importance  of  utilizing  an 
accepted  standard  in  developing  programs 
for  ultimate  use  in  a  wide  variety  of 
implementations  of  FORTH  cannot  be 
over- emphasized. 

I  wish  to  thank  Bill  Ragsdale  for  his 
encouragement  to  write  this  discussion 
based  on  his  presentation  to  the  FORTH 
Interest  Group  at  one  of  their  monthly 
meetings  last  year. 

Application  Note: 

These  FORTH  routines  have  been 
developed  on  a  FORTH  Operating  Sys¬ 
tem  for  the  Heathkit  H89.  This  system  is 
available  from  the  Mountain  View  Press, 
Box  4656,  Mountain  View,  CA  94040. 
The  compiled  FORTH  program  image  can 
be  saved  on  disk  and  will  be  up  and  run¬ 
ning  in  less  than  four  seconds  from  a  cold 
boot.  The  system  has  1024  byte  blocks 


which  also  increases  the  speed  of  opera¬ 
tion. 

However,  after  development,  the 
screens  were  loaded  on  a  FORTH  imple¬ 
mentation  derived  from  the  fig-FORTH 
for  8080  Assembly  Source  Listing  which 
is  available  from  the  FORTH  Interest 
Group,  Box  1 105,  San  Carlos,  C A  94070 
in  printed  form  and  already  on  disk  also 
from  the  Mountain  View  Press.  This 
version  has  128  byte  blocks  and  operates 
in  conjunction  with  CP/M.  To  this  has 
been  added  the  fig-EDITOR  from  the 
fig-FORTH  Installation  Manual  and  a 
single  extension,  DUMP,  used  to  illustrate 
the  appearance  of  the  records  as  stored  in 
a  block. 

The  printed  session  illustrated  was 
made  using  the  CP/M  control  P  to  echo 
the  output  on  the  printer.  The  session 
starts  with  CP/M  loaded  and  its  usual 
prompt.  The  CP/M  file,  FORTH60.COM, 
is  the  object  module  of  the  fig-FORTH 


model.  The  warning  messages  are  not  on 
screens  4  and  5  and  the  warning  flag  is 
turned  off.  Then  the  screens  for  the  fig- 
EDITOR  and  a  good  dump  routine  are 
loaded.  Finally,  the  screens  discussed  are 
loaded.  The  file  DEMO  is  called  and  the 
application  of  some  of  the  file  utilities 
is  illustrated.  This  presentation  will 
hopefully  assure  that  there  are  no  errors 
in  the  printed  screens.  SSj 

LISTING  ON  PAGE  47 


Bibliography 

Brooks,  F.  P.,  Jr.,  The  Mythical  Man-Month , 
Addison-Wesley  Publishing  Company,  1975. 
- ,  fig-FORTH  Installation  Manual,  Glos¬ 
sary,  Model,  Forth  Interest  Group,  Box  1105, 
San  Carlos,  CA  94070. 

- ,  fig-FORTH  for  8080  Assembly  Source 

Listing,  Forth  Interest  Group,  Box  1105,  San 
Carlos,  CA  94070. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Each  issue  includes: 

•  valuable  software  tools 

•  algorithms  &  problem  solving 

•  industry  news 

•  important  product  reviews 

With  in-depth  coverage  of: 

•  telecommunications 

•  systems  programming 

•  language  development 

•  machine  independent 

programs 

and  much,  much  more ! 


Yes!  Please  enter  my  subscription  for 

□  1  yr.  (12  issues)  $25  □  2  yrs.  $47  (save  $13  off  newsstand) 

□  Please  bill  me  □  I  enclose  check/money  order 

Name _ _ _ 

Address  _ 

City - State _ Zip _ 


Dr.  Dobb’s  Journal,  A  Publication  of  People’s  Computer  Company 
1263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  CA  94025 


Are  you  ready? 

DDJ,  the  world’s  foremost  microcomputer 
publication,  has  been  working  for  years  to  pre¬ 
pare  its  readers  to  be  innovators,  to  lead  the 
wave  of  breakthroughs  in  our  changing  tech¬ 
nology. 

Every  issue  of  Dr.  Dobb’s  Journal  helps 
one  to  understand  the  nuts  and  bolts  of  small 
computer  systems.  We  offer  entire  listings  of 
valuable  software:  our  pages  have  included 
compilers,  cross-assemblers,  editors,  new  lan¬ 
guages,  hardware  interfaces  and  more  —  usually 
before  anyone  else  thinks  of  them ! 


Even  more  important! 

Our  subscribers  share  insights,  correspond, 
and  contribute  to  one  another’s  work,  more 
than  any  other  group  we  know.  They  treat 
Dr.  Dobb ’s  Journal  as  a  “hands-on”  publication. 

This  warm  cooperation  has  done  more  to 
refine  software  products,  and  generally  to 
advance  the  state  of  microcomputer  techno¬ 
logy,  than  perhaps  any  other  resource.  And  it  is 
available  to  you  through  our  pages ! 

For  the  straight  facts . 

If  you  are  a  serious  computing  professional 
or  enthusiast,  then  you  should  take  a  very  close 
look  at  what  DDJ  offers  you.  We’ve  been  on 
the  cutting  edge  since  1976. 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


45 

401 


FORTH  Data  Base  Design 

SCR  #  21 

0  (  SCREEN  21:  COMMENTS  AND  LOAD  FOR  DEMO  DATA  FILE  ) 

1  27  EMIT  69  EMIT  CR  CR  CR  CR  CR 

2  This  demonstration  data  system  provides  a  pattern  for  the" 

3  CR  further  development  of  any  type  of  data  base.  The  basic" 

4  CR  ."  file  formating  definitions  are  on  Screens  22  and  23.  Some" 

5  CR  ."  utilities  are  on  24,  25,  and  26.  Ttie  demo  file  " 

6  CR  ."  definitions  are  on  27.  Elementary  file  manipulation  " 

7  CR  ."  utilities  are  on  28.  TTiis  model  should  get  you  started." 

8  :  FROCEDE  CR  CR  ."  ENTER  'Y '  TO  LOAD  SCREENS  "  KEY  89  =  IF 

9  29  22  DO  I  LOAD  LOOP  ENDIF  ; 


10 

FROCEDE 

11 

;S 

12 

13 

14 

15 

SCR 

#  22 

0  CR  ."  SCREEN  22:  FILE  DEVELOPMENT  " 

1  0  VARIABLE  REC#  (  holds  the  current  record  number  ) 

2  0  VARIABLE  OFEN  (  points  to  current  file  descriptor  ) 

3 

4  :  2@  DUP  2+  @  SWAP  0  ;  (  double  fetch  ) 

5 

6  :  LAYOUT  (  leave  bytes/ record- 2,  and  bytes/b lock-1  ) 

7  OPEN  0  4  +  20  ; 

8  :  READ  (  n-th  record,  on  stack,  is  made  current  ) 

9  0  MAX  DUP  OPEN  @  2+  @  <  0= 

10  IF  ."  FILE  ERROR  "  QUIT  THEN  REC#  !  ; 

11  :  RECORD  (  leave  address  of  n-th  record  ) 

12  LAYOUT  */MOD  OFEN  0  @  +  BLOCK  +  ; 

13  :  ADDRESS  (  leave  address  of  the  current  record  ) 

14  REC#  0  RECORD  ; 

15  ;S 


SCR 
0 
1 
2 

3 

4 

5 

6 

7 

8 
9 

10 

11 

12 

13 

14 

15  ;S 


#  23 

CR  ."  SCREEN  23:  FILE  DEVELOPMENT  -  2  " 

:  TFIELD  <BUILD6  (  create  a  text  field  ) 

OVER  ,  DUP  ,  +  (  leaves  file  count  for  this  definition  ) 
DOES>  (  leaves:  addr,  count  ) 

2@  ADDRESS  +  SWAP  ; 

:  DFIELD  <BUILDS  (  create  a  data  field  ) 

OVER  ,  +  (  leaves  file  count  for  this  definition  ) 

DOES>  (  leaves  address  ) 


0  ADDRESS 
FILE 
< BUILDS 
1+  , 


(  create  a  named  storage  allocation  ) 
(  origin  block  ) 

(  number  of  records  in  file  ) 

DUP  B/BUF  OVER  /  *  ,  (  #  bytes  per  block  ) 

,  (  #  bytes  per  record  ) 

DOES>  OFEN  !  ;  (  when  file  name  used,  point  to  ) 

(  its  descriptor  parameters.  ) 


MSG  #  15 
OK 


SCR  #  24 

0  CR  ."  SCREEN  24:  DOUBLE  PRECISION  ARITHMETIC  " 


1 

:  D/ 

(  d,  u - d 

) 

2 

SWAP  OVER  /MOD  >R 

SWAP  U/  SWAP  DROP  R>  ; 

3 

:  D* 

(  d,  u - d 

) 

4 

DUP 

ROT  *  ROT  ROT 

U*  ROT  +  ; 

5 

D/MOD 

(  d,  u - r, 

q  )  U/  ; 

6 

D@ 

(  addr - d 

)  DUP  2  +  @  SWAP 

0 

7 

D! 

(  d,  addr  - 

)  DUP  ROT  SWAP  !  2 

+ 

8 

DDUP 

(  d - d,  d 

)  2D  UP  ; 

9 

DSWAP 

(  dl,  d2,  - 

d2,  dl  )  ROT  >R  ROT 

R> 

10 

11 

DCROP 

;S 

(  dl,  d2  - 

)  DROP  CROP  ; 

12 

13 

14 

15 

SCR  #  25 

0  CR  ."  SCREEN  25:  DATE  C  CM  SESSION  AND  EXPANSION  " 

1  :  DATEBIT  (  converts  date  input  to  2  bytes  ) 

2  32  D*  D+  13  D*  D+  DROP  ; 

3  :  7DATE  ."  (  MM/DD/YY  )  " 

4  QUERY  47  WORD  HERE  NUMBER  47  WORD  HERE  NUMBER  BL  WORD 

5  HERE  NUMBER  DATEBIT  ; 

6  :  .DATE  (  formats  2  byte  date  code  and  prints  ) 

7  0  13  U/  32  /MOD  ROT  100  *  ROT  +  0  100  D*  ROT  0  D+ 

8  <#  #  #  47  HOLD  #  #  47  HOLD  #  #  #>  TYPE  ; 

9  ;S 
10 

11 

12 

13 

14 

15 

SCR  #  26 

0  CR  ."  SCREEN  26:  ?$AMOUtJT  AND  .  SAMOUNT  " 


1  (  define  action  for  each  scale  case  ) 

2  :  0SCALE  100  D*  ;  :  1SCALE  10  D*  ;  :  2SCALE  ; 

3  :  3SCALE  ."  INPUT  ERROR  "  CR  ; 

4  (  define  scale  case  and  extend  for  each  with  'CFA'  ) 

5  '  0SCALE  CFA  VARIABLE  N SCALE  '  1SCALE  CFA  ,  '  2SCALE  CFA  , 

6  '  3 SCALE  CFA  , 

7  (  scale  double  precision  value  according  to  'DPL'  ) 

8  :  SCALE  DPL  @  3  MIN  2  *  N SCALE  +  @  EXECUTE  ; 

9  (  v^it  for  decimal  value  and  scale  it  -  leave  value  on  stack  ) 

10  :  ?$AMOUUr  QUERY  BL  WORD  HERE  NUMBER  SCALE  ; 

11  (  print  d  from  stack  as  $  and  right  justify  in  8  spaces  ) 

12  :  .SAMOUNT 

13  DUP  ROT  ROT  DABS  <#  #  #  46  HOLD  #S  SIGN  #> 

14  36  EMIT  DUP  8  SWAP  -  SPACES  TYPE  ; 

15  ;S 

MSG  #  15 
OK 

SCR  #  27 

0  CR  ."  SCREEN  27:  DEMO  FILE  -  RECORD  GENERATION  " 

10  2  DFIELD  TAG  (  a  tag  ) 

2  30  TFIELD  NAME  (  itan  name  ) 

3  2  DFIELD  CAY  (  the  date  ) 

4  4  DFIELD  DOLLAR  (  a  dollar  amount  ) 

5  200  (  number  of  records  )  400  (  starting  block  ) 

6  FILE  DEMO 

7  :  !NAME  (  wait  for  name  then  store  it  in  record  ) 

8  NAME  DROP  30  32  FILL  QUERY  1  TEXT  PAD  COUNT 

9  NAME  ROT  MIN  CMOVE  UPCATE  ; 

10  :  .NAME  (  print  name  field  )  NAME  TYPE  ; 

11  (  the  rest  follow  in  the  same  way  ) 

12  :  !DAY  7DATE  DAY  !  UPDATE  ;  :  .DAY  CAY  @  .CATE  ; 

13  :  !  DOLLAR  ?$AMOUNT  DOLLAR  D!  UPDATE  ; 

14  :  .DOLLAR  DOLLAR  D0  .SAMOUNT  ; 

15  :  .REC  CR  REC#  0  3  .R  2  SPACES  .NAME  .CAY  2  SPACES  .DOLLAR  ; 

SCR  #  28 

0  CR  ."  SCREEN  28:  DEMO  FILE  -  CLEAR. DATA,  INPUT,  OUTPUT  " 

1  (  clear  especially  tag  in  the  0  record  in  file  ) 

2  :  CLEAR. DATA  0  READ  TAG  128  0  FILL  UPCATE  ; 

3  (  example  of  formatting  for  input  ) 

4  :  INPUT  0  READ  TAG  0  1+  UPCATE  DUP  TAG  !  READ 

5  CR  CR  ."  ENTER  NAME  — >  "  'NAME 

6  CR  ."  ENTER  CATE  — >  "  !DAY  (  has  a  format  prompt  ) 

CR  ."  ENTER  AMOUNT  — >  "  IDOLLAR 

8  .REC  FLUSH  ;  (  save  this  record  on  disk  ) 

9  (  list  files  1  through  the  number  in  TAG  of  0  record  ) 

10  :  OUTPUT  0  READ  TAG  0  DUP  0=  IF  CR  CR  ."  EMPTY  FILE  " 

11  DROP  ELSE  1-*-  1  DO  FORTH  I  READ  .REC  LOOP  ENDIF  CR  CR  ; 

12  ;S 
•13 

14 

15 

SCR  #  29 
0 
1 
2 

3 

4 

5 

6 

7 

8 
9 

10 

11 

12 

13 

14 

15 

MSG  #  15 
OK 

A> 

A>FORTH60  (  f ig-FCRTH  Model  ) 

8080  fig-FORTH  1.1 
OK 
OK 

0  WARNING  !  (  Warning  messages  not  on  Screens  4  &  5  ) 

OK 

OK 

OK 

47  LOAD  (  fig-EDITOR  ) 

R  MSG  #  4  I  MSG  #  4 
FLUSH  MSG  #  4  OK 
OK 
OK 
OK 

49  LOAD  (  My  version  of  a  good  dump  ) 

SCREEN  49:  GOOD  DUMP 
OK 
OK 
OK 

21  LOAD  (  Loads  Screens  discussed  ) 

(LISTING  CONTINUED  ON  PAGE  56) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 
402 


47 


Forth  Decompiler 


Dr.  Dobb’s  readers 
have  been  aiding 
the  growth  and  development 
of  the  micro  field 
for  years. 

If  you  would  like 
to  make  a  contribution, 
contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415) 323-3111 


The  FORTH  Decompiler  utility  pro¬ 
gram  will  decode  and  list  the  “top 
layer”  of  any  “high  level  defined” 
word  in  the  glossary.  This  capability  is 
useful  when  developing  applications  inter¬ 
actively  at  the  keyboard;  the  final  version 
of  a  definition  can  be  listed  on  the  ter¬ 
minal  or  line  printer  for  later  editing  into 
the  screen  file.  It  is  also  instructive  for  a 
new  FORTH  programmer  to  decompile 
the  various  FORTH  interpreter/compiler 
system  words,  both  to  see  how  they  work 
and  to  learn  programming  style  by  the 
implementor’s  example. 

The  Decompiler  is  written  in  stan¬ 
dard  fig-FORTH  and  has  been  tested  on 
8080  FORTH  and  Z-80  FORTH.  It  should 
be  directly  portable  to  any  fig-FORTH 
system  with  a  “post -incrementing”  inner 
interpreter.  The  branch  address  decoder 
assumes  a  compiled  in-line  offset,  this 
word  will  have  to  be  modified  for  other 
systems  that  compile  an  absolute  target 
address. 

Screen  #30  contains  the  definition 
of  a  CASE  control  structure  that  was 
written  by  Charles  Eaker.  This  structure 
essentially  allows  the  programmer  to 
write  a  convenient  multiway  branch  with¬ 
out  a  lot  of  confusing  nested  IF’s  and 
ELSE’s.  The  operation  of  the  CASE  con¬ 
struct  is  beyond  the  scope  of  this  article, 
but  a  detailed  explanation  by  its  author 
may  be  found  in  FORTH  Dimensions, 
Volume  II,  Number  3,  page  37. 

Screen  #31  finds  the  addresses  of 
the  run-time  code  for  each  of  the  defin¬ 
ing  words  such  as  VARIABLE,  CON¬ 
STANT,  and  USER,  as  well  as  various  in¬ 
terpreter  controlling  routines.  Each  ad¬ 
dress  is  turned  into  a  constant,  which  is 
used  later  in  the  main  program  to  trap  de- 
compilation  of  these  definitions  and  to 
print  special  identifying  messages. 

Screens  #32-34  contain  a  number  of 
colon -definitions  of  the  form  xxxx.DSP, 
which  are  called  by  the  main  decompila¬ 
tion  program  to  display  each  of  the  vo¬ 
cabulary  word  types  and  update  the 
pseudo-code  pointer  appropriately. 

Screens  #34-38  are  source  text  for 
the  main  control  routine  of  the  Decom¬ 
piler.  First  the  dictionary  is  searched  for 


by  Ray  Duncan 


Ray  Duncan,  Laboratory  Microsystems, 
4147  Beethoven  Street,  Los  Angeles, 
CA  90066. 


the  input  word,  and  if  no  match  is  found 
an  error  message  is  printed.  If  a  match  is 
found,  the  value  of  the  Code  Field  Ad¬ 
dress  is  checked  for  equality  with  the 
Parameter  Field  Address;  if  true  this  im¬ 
plies  that  the  definition  is  a  machine 
code  primitive  and  no  further  decom¬ 
pilation  is  attempted.  If  the  Code  Field 
Address  points  to  the  run-time  routine 
for  a  defining  word,  an  identifying  mes¬ 
sage  and  the  value  of  the  parameter  field 
are  displayed.  Otherwise,  the  program 
enters  a  loop  which  successively  decodes 
each  pseudo-code  address  in  the  para¬ 
meter  field  and  prints  its  name  or  value 
until  a  “;”  or  one  of  its  derivatives  is 
encountered.  Execution  of  the  Decom¬ 
piler  can  be  aborted  by  pushing  any  key 
on  the  terminal.  Examples  of  decompila¬ 
tion  of  various  vocabulary  word  types  are 
shown. 

Abbreviations  used:  NFA  =  name 
field  address,  CFA  =  code  field  address, 
PFA  =  parameter  field  address,  fig- 
FORTH  =  implementation  of  FORTH  fol¬ 
lowing  the  Forth  Interest  Group  model. 

LISTING  ON  PAGE  50. 


Sallying  FORTH  to  Battle 

(Continued  from  page  26) 

something  other  than  numbers  and  arith¬ 
metic  operators  are  involved  that  the 
stack  contents  can  become  somewhat 
unclear. 

Am  I  an  opponent  of  FORTH?  Abso¬ 
lutely  not.  FORTH  or  any  other  threaded 
language  is  both  usable  and  fun  on  a  small 
machine.  I  use  my  own  version  (ZIPD) 
fairly  often.  I  don’t  use  it  for  everything, 
only  when  it  makes  sense.  Would  I  recom¬ 
mend  FORTH  on  a  personal  computer? 
Again,  yes.  I  would  also  recommend 
other  langauges,  dependent  on  the  appli¬ 
cation  and  the  environment.  **j 


References 

1  FORTH -79  STANDARD,  FORTH  Interest 
Group,  P.  O.  Box  1105,  San  Carlos,  CA 
94070,  Oct.  1980. 

2Kernighan,  B.  W.  and  Ritchie,  D.  M.,  The  C 
Programming  Language,  Prentice  Hall,  Inc., 
Englewood  Cliffs,  NJ  07632,1978. 


48 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 

403 


FORTH  Decompiler  (Text  on  page  48) 

Screen  #  30 

O  (  fig-FORTH  Decompiler  ) 

1  (  CASE  control  statement  by  Charles  E.  Eaker  ) 

2  (  published  in  FORTH  Dimensions  II/3  page  37  ) 

-  3  FORTH  DEFINITIONS  DECIMAL 

4  :  CASE  7C0MP  CSP  @  ! CSP  4  ;  IMMEDIATE 

5  :  OF  4  7PAIRS 


6 

7 

8 

9  :  ENDOF 
10 
1 1 

12  :  ENDCASE 

13 

14 

15 


COMPILE  OVER  COMPILE  = 

COMPILE  OBRANCH  HERE  0  , 

COMPILE  DROP  5  ;  IMMEDIATE 
5  7PAIRS 

COMPILE  BRANCH  HERE  O  , 

SWAP  2  CCOMPILED  END IF  4  ;  IMMEDIATE 
4  7PAIRS  COMPILE  DROP 
BEGIN  SP@  CSP  @  =  0= 

WHILE  2  CCOMPILED  ENDIF  REPEAT 
CSP  !  i  IMMEDIATE  — > 


Screen  #  31 

0  (  fig-FORTH  Decompiler  ) 

1  0  VARIABLE  QUIT.  FLAG  0  VARIABLE  WORD  PTR 

2  <  find  run-time  addresses  of  each  vocabulary  word  type  ) 

3  '  (LOOP)  2  -  CONSTANT  LOOP. ADR 

4  '  LIT  2  -  CONSTANT  LIT. ADR 

5  '  :  2  -  @  CONSTANT  DOCOL. ADR 

6  '  OBRANCH  2  -  CONSTANT  OBRANCH. ADR 

7  '  BRANCH  2  -  CONSTANT  BRANCH. ADR 

8  '  ( +LOOP )  2  -  CONSTANT  PLOOP. ADR 

9  '  (.  " )  2  -  CONSTANT  PDOTQ.  ADR 

10  '  C/L  2  -  e  CONSTANT  CONST. ADR 

1 1  '  BASE  2  -  @  CONSTANT  USERV. ADR 

12  '  USE  2  -  ®  CONSTANT  VAR. ADR 

13  '  (iCODE)  2  -  CONSTANT  PSCODE.  ADR 

14  — > 

15 


Screen  #  32 

0  (  fig-FORTH  Decompiler  ) 

1 

2  :  N.  (  print  a  number  in  decimal  and  hex  ) 

3  DUP  DECIMAL  .  SPACE 

4  HEX  0  .  "  (  "  D.  .  "  H  )  "  DECIMAL  i 

5 

6  :  PDOTQ. DSP  (  display  a  compiled  text  string  ) 

7  WORD. PTR  @  2+  DUP  >R  DUP 

8  Ce  +  1  -  WORD. PTR  !  (  update  PFA  pointer  ) 

9  R>  COUNT  TYPE  ; 


10 

11  WORD.  DSP  <  given  CFA,  display  the  glossary  name  ) 

12  3  - 1  TRAVERSE  DUP  1+  C@  59  = 

13  IF  1  QUIT.  FLAG  !  ENDIF  (  if  "i  "  we  are  done  ) 

14  DUP  C@  160  AND  128  =  (  make  sure  legal  NFA  ) 

15  '  IF  ID.  ELSE  1  QUIT.  FLAG  !  ENDIF  ;  — > 


50 

404 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


Screen  #  33 

O  (  fig-FORTH  Decompiler  ) 
1 


BRANCH.  DSP 


(  get  branch  offset,  calculate  the  ) 

(  actual  branch  address,  and  display  it  ) 

.  "  to  " 

WORD.  PTR  @  2+  DUP  WORD.  PTR  !  <  update  PFA  ptr  ) 

DUP  @  +  <  offset  +  PFA  =  actual  target  addr  ) 
0  HEX  D.  DECIMAL  (  print  it  )  ; 


USERV.  DSP  (  display  a  user  variable  ) 

. "  User  variable,  current  value  =  " 

WORD. PTR  @  2+  (  calculate  PFA  ) 

C@  38  +ORIGIN  @  +  <  then  user  area  address  ) 

@  N.  <  fetch  and  print  contents  ) 

1  QUIT.  FLAG  !  (  done,  set  flag  )  . 


Screen 
0  ( 

1 


#  34 

fig-FORTH  Decompiler  ) 


VAR.  DSP 


<  display  a  variable  ) 

. "  Variable,  current  value  =  " 

WORD. PTR  @  2+  (  calculate  PFA  ) 

@  N.  (  fetch  and  print  contents  ) 

1  QUIT. FLAG  !  <  all  done,  set  flag  ) 


CONST. DSP  (  display  a  compiled  constant  ) 

.  "  Constant,  value  =  " 

WORD.  PTR  @  2+  (  calculate  PFA  ) 

@  N.  (  fetch  and  print  contents  ) 

1  QUIT. FLAG  !  (  all  done,  set  flag  ) 


Screen  #  35 

0  (  f i g-FORTH  ,Dec omp i 1 er  ) 

1  :  DIS 

2  -FIND  0=  (  is  input  uiord  in  dictionary?  ) 

3  IF  3  SPACES  .  "  ?  not  in  glossary  "  CR  <  no,  quit  ) 

4  ELSE  DROP  DUP  DUP  2  -  (  yes,  calculate  CFA  ) 

5  @  =  (if  contents  of  CFA  =  PFA  then  its  a  primitive  ) 

6  IF  .  "  <primitive>  "  CR  (  so  print  message  and  quit  ) 

7  ELSE  (  otherwise  it's  high  level  FORTH  so  decode  it  ) 

8  0  QUIT. FLAG  !  (  initialize  done  flag  ) 

9  2  -  WORD. PTR  !  <  initialize  pseudocode  pointer  ) 


10 

CR  CR 

( 

print  some  blank  lines  ) 

1 1 

BEGIN 

( 

now  list  the  compiled  pseudocode  ) 

12 

WORD.  PTR 

@  DUP 

( 

fetch  current  pseudocode  pointer  ) 

13 

0  HEX  D. 

SPACE 

DECIMAL  (  print  value  of  pointer  ) 

14 

e 

( 

fetch  current  pseudocode  word  ) 

15 

— > 

(Continued  on  next  page) 

Dr.  Dobb’s  Journal,  Number  59,  September  1981  51 

405 


FORTH  Decompiler 


(Listing  continued,  text  on  page  48) 


Screen  #  36 

0  <  fig-FORTH  Decompiler  ) 

1  CASE  (  now  de 

2  LIT. ADR  OF  (  compil 

3  WORD.  PTR 

4  DOCOL. ADR  OF  (  :  poin 

5 

6  OBRANCH.  ADR  OF  (  condit 

7  . "  Branc 

8  BRANCH. ADR  OF  (  uncond 

9  .  "  Branc 

10  LOOP. ADR  OF  (  end  of 

11  .  "  Loop 

12  PLOOP. ADR  OF  (  end  of 

13  .  "  +Loop 

14  — > 

15 


code  any  special  word  types  ) 
ed  literal,  print  its  value  ) 

©  2+  DUP  WORD.  PTR  !  ©  N.  ENDOF 
ts  to  the  nesting  routine  ) 

ENDOF  (  so  just  print  a  colon 
ional  branch  with  in-line  offset  ) 
h  if  zero  "  BRANCH. DSP  ENDOF 
itional  branch  with  in-line  offset 
h  "  BRANCH. DSP  ENDOF 
a  DO.  .  .  LOOP  structure  ) 

"  BRANCH. DSP  ENDOF 
a  DO.  .  .  +LOOP  structure  ) 

"  BRANCH. DSP  ENDOF 


•een  #  37 

>  (  fig-FORTH  Decompiler 


PDOTG.  ADR 


USERV.  ADR 


VAR.  ADR 


CONST.  ADR 


PSCODE. ADR 


(  display  compiled  text  string  ) 

.  "  Print  text:  "  PDOTQ.  DSP  ENDOF 
<  display  a  user  variable  ) 

USERV.  DSP  ENDOF 
(  display  a  global  variable  ) 

VAR.  DSP  ENDOF 

(  display  a  compiled  constant  ) 
CONST.  DSP  ENDOF 
(  display  ; CODE  and  quit  ) 

WORD.  PTR  ©  ©  WORD.  DSP 
1  QUIT.  FLAG  !  ENDOF 


Screen  #  38 

0  (  fig-FORTH  Decompiler 
1 
2 

3  DUP  WORD.  DSP 

4 

5  ENDCASE  CR 

6  2  WORD.  PTR  +! 

7  QUIT. FLAG  © 

8  7TERMINAL  OR 

9  UNTIL 

10  END IF  END IF  CR  ; 

1 1 
12 

13 

14 

15 


(  all  special  word  types  checked,  ) 

(  if  word  did  not  match  any  cases  ) 

(  just  print  its  name  ) 

(  done  decoding  word  type  ) 

(  update  pseudocode  pointer  ) 

(  check  if  finished  flag  set  or  if  ) 
(  interruption  from  terminal  ) 

(  otherwise  display  another  word  ) 

(  all  done  now  ) 


End  Listing 


52 

406 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


Sample  Run 


OK 

30  LOAD  OK 

DIS  XXX  ?  not  in  glossary 
OK 

DIS  DUF'  <  primitives- 
OK 

DIS  C/L 

704  Constant,  value  =  64  (  40  H  ) 

OK 

DIS  BASE 

800  User  variable,  current  value  =  10 
OK 

DIS  WORD. PTR 

1F89  Variable,  current  value  =  8073  < 

OK 

DIS  TRIAD 
1 DD9  : 

1 DDB  12  (  C  H  ) 

1DDF  EMIT 
1DE1  3  (  3  H  ) 

1DE5  / 

1 DE7  3  <  3  H  ) 

1  DEB  * 

1 DED  3  (  3  H  ) 

IDF  1  OVER 
1 DF3  + 

1DF5  SWAP 
1 DF7  <D0) 

1 DF9  CR 

1DFB  I 

1 DFD  LIST 

1 DFF  7TERMINAL 

1E01  Branch  i -f  zero  to  1E07 

1E05  LEAVE 

1E07  Loop  to  1 DF9 

1 EOB  CR 

1E0D  15  (  F  H  ) 

IE 11  MESSAGE 
1 E 1 3  CR 
1E15  ;  S 

OK 


End 


(AH) 


1F89  H  ) 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


53 

407 


OF  INTEREST 


by  Dave  Cortesi 


Two  Products  Step  FORTH 

We  found  two  FORTH  announce¬ 
ments  to  open  the  column  in  this  special 
issue.  MicroMotion  have  produced  what 
they  claim  to  be  “the  first  FORTH  for 
the  Apple  that  meets  the  international 
standards  established  by  the  FORTH 
standards  ‘team  in  October  80.”  The 
package  is  said  to  include  a  “professional¬ 
ly  written”  manual.  That  might  mean 
that  they  hired  a  technical  writer  to  do 
the  manual,  a  wise  move  in  the  light  of 
some  of  the  comments  we  have  heard 
about  FORTH  manuals.  FORTH-79  can 
handle  disks  with  either  13  or  16  sectors, 
although  its  files  are  not  compatible  with 
those  of  APPLE  DOS.  The  price  is  $90. 

Timin  Engineering  have  enhanced 
their  FIG-FORTH  implementation  for 
CP/M  with  a  floating  point  arithmetic 
feature.  The  feature  extends  a  standard 
Timin  FORTH  so  that  it  can  handle  arith¬ 
metic  on,  and  comparison  of,  single  pre¬ 
cision  (6+  decimal  digits)  floating  point 
numbers.  The  feature  costs  $100. 

Note:  Just  before  press  time  we  re¬ 
ceived  a  call  informing  us  that  FORTH, 
Inc.  has  been  acquired  and/or  merged 
with  Technology  Industries,  Inc.  Said 
caller  stated  the  staff  will  remain  the 
same,  but  T.I.  resources  will  be  boost¬ 
ing  more  language  development  —  possi¬ 
bly  looking  for  the  El  Dorado  of 
“programmer- less  programming”? 

North  Star,  Meet  CP/M 

Is  North  Star  BASIC  superior  to  the 
usual  CP/M  ones?  Allen  Ashley  thinks  so, 
but  then  he  makes  COMSTAR,  a  compil¬ 
er  for  North  Star  BASIC.  He  wrote  to  tell 
us  that  owners  of  COMSTAR  may  buy  a 
CP/M  run-time  library  for  the  compiler 
so  that  their  programs  can  run  under 
CP/M.  The  feature  costs  $75,  and  in¬ 
cludes  a  North  Star-to-CP/M  transfer 


utility. 

Those  who’ll  continue  to  use  their 
Microsoft  compilers  might  like  to  know 
that  Westico  is  selling  what  they  think  is  a 
greatly  improved  linking  loader  for  Micro¬ 
soft  relocatable  files.  The  main  features 
claimed  for  LYNX  are  its  friendly  com¬ 
mands  and  its  ability  to  construct  overlay 
segments.  We  remember  overlay  seg¬ 
ments;  if  you  don’t  know  what  an  overlay 
is,  you’re  better  off. 

Getting  Serious  About  Atari 

The  PCC  staff  is  trying  to  get  serious 
about  the  house  Atari  800.  The  Star 
Raiders  cartridge  has  been  locked  in  the 
publisher’s  desk  and  the  typesetter  is 
writing  a  dull  old  invoice  program.  Opti¬ 
mized  Systems  Software  is  another  seri¬ 
ous  group;  they’re  dedicated,  they  say,  to 
promoting  “total  access”  to  the  800’s 
abilities.  To  that  end  they’ve  created  an 
enhanced  BASIC  and  a  better  disk  operat¬ 
ing  system.  The  BASIC  contains  Atari 
BASIC  as  a  subset  but  adds  more  power¬ 
ful  graphics  commands,  PRINT  USING, 
and  better  string  handling.  The  operating 
system,  OS/A+,  contains  disk  utilities  and 
an  assembler;  it  supports  batched  com¬ 
mands  as  well  as  interactive  ones.  Each 
package  costs  $80. 

Mosaic  Electronics  has  a  serious  sug¬ 
gestion  for  those  who’d  like  to  use  either 
Atari  machine  for  hardware  experiments. 
Their  $18  I/O  Package  consists  of  connec¬ 
tors  and  ribbon  cables  with  which  the  ex¬ 
perimenter  can  lead  the  four  game  jacks 
on  the  front  of  the  console  out  to  a 
breadboard  where  they  effectively  form  a 
parallel  port.  Anything  at  all  can  happen 
from  there  on  out;  the  documentation  is 
said  to  contain  a  number  of  examples. 

Minority  Computerists,  Unite! 

An  Atari  isn’t  really  meant  to  be  a 


POINT  PEN  TO  CORRECT  ANSWER 


WHERE  IS  MT.  ST  HELENS? 


OREGON  ■ 
WASHINGTON  ■ 
MONTANA  ■ 


The  3G  Company’s  light  pen  for  the  TRS-80 


costs  $40. 


hardware  hacker’s  machine,  but  the 
Heath  ET-3400  was  designed  for  exactly 
that.  Now,  at  last,  there  is  an  ET-3400 
User’s  Group.  We  received  the  Group’s 
first  newsletter.  It  consists  mostly  of  re¬ 
prints,  but  the  long-neglected  owners  of 
this  fine  little  machine  could  turn  that 
around  by  joining.  There’s  no  set  mem¬ 
bership  fee;  send  a  reasonable  donation. 

Another  set  of  owners  who  must  feel 
a  bit  neglected  are  those  who  bought 
Processor  Technology  SOL  machines. 
Proteus  is  a  group  of  SOL  owners  work¬ 
ing  to  keep  their  machines  alive  and  sup¬ 
plied  with  software.  The  club  now  has 
access  to  the  assembly  source  code  for  all 
the  Processor  Technology  systems  soft¬ 
ware.  Source  code,  object  code,  and  re¬ 
printed  manuals  are  available,  as  well  as 
60  diskettes  of  public  domain  software. 

An  Abundance  of  Information 

Ever  feel  as  if  there’s  just  too  much 
information  flooding  in  for  you  to  han¬ 
dle?  Well,  you  aren’t  alone;  anyone  who 
tries  to  keep  up  with  the  computer  field 
is  drinking  from  a  firehose.  Here  are  a  few 
new  compendia  that  might  help  organize 
your  knowledge. 

Elliam  Associates  have  indexed  a 
couple  of  hundred  articles  about  CP/M 
on  diskette,  to  be  retrieved  with  the  IRS 
retrieval  system  from  Island  Cybernetics. 
The  articles  were  published  in  1979  and 
1980;  the  index  fills  two  disks.  The  index 
alone  costs  $35;  IRS  is  another  $38. 

Rather  than  indexing  articles,  Im¬ 
print  Software  indexes  programs.  Their 
$29  catalog  lists  “thousands”  of  pro¬ 
grams,  organizing  them  three  different 
ways:  by  subject,  by  required  system,  and 
by  publisher.  They  claim  to  have  listings 
for  all  major  computer  systems,  and  for 
programs  for  all  countries,  not  just  the 
USA. 


The  Vista  Type-Ahead  buffer  lets  you  get  40 
keystrokes  ahead  of  your  Apple. 


54 

408 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


INMAC  is  a  retailer  of  computer  sup¬ 
plies  and  support  equipment.  They’re  the 
first  such,  they  claim,  to  publish  a  catalog 
specifically  for  personal  machines.  Their 
Microcomputer  User’s  Idea  Book  is  or¬ 
ganized  by  machine  type  and  lists  disk¬ 
ettes,  ribbons,  cables,  furniture,  and  ac¬ 
cessories. 

We  received  the  Robotics  Industry 
Directory  prepared  by  Robotics  Age 
magazine.  It  costs  $25;  it  contains  60- 
odd  pages  of  spec  sheets  for  industrial 
robots  with  profiles  of  their  makers,  and 
a  directory  of  robotics  consultants. 


Lowering  the  Price  of  Words 

The  flood  of  words  rolls  on,  and 
somehow  it  all  has  to  be  set  in  type.  Jim 
Warren  published  a  diatribe  against  the 
makers  of  typesetting  equipment  in  the 
Silicon  Gulch  Gazette  distributed  at  the 
Faire.  Shape  up,  he  warned  them,  or  the 
micros  will  take  over  your  front-end 
sales.  Type  Share  was  already  ahead  of 
him.  They’ve  built  a  computerized  type¬ 
setting  system,  based  on  the  Commodore 
VIC,  that  they’re  ready  to  sell  for  “less 
than  $500.”  The  user  of  the  system  pre¬ 
pares  the  copy  to  be  typeset  on  the  VIC 
and  records  it  on  cassette  tape.  The  cas¬ 
sette  is  sent  to  a  Type  Share  center  to  set 
on  a  phototypesetter;  galleys  are  returned 
to  the  user,  ready  for  paste-up,  at  “a  frac¬ 
tion”  of  the  conventional  price.  The  com¬ 
pany  also  sell  a  more  elaborate  system 
based  on  the  Commodore  8002;  it  can 
deliver  its  copy  on  diskette  or  over  a 
phone  line. 

Many  micro  users  prepare  documents 
with  a  daisy- wheel  printer.  The  cost  of 
ribbons  is  the  heaviest  operating  expense 
of  these  printers,  and  the  best  print  quali¬ 
ty  comes  from  the  expensive  film  rib¬ 
bons.  Torres  Ribbon  Service  aims  to  cut 
the  cost  for  you;  they  reload  film  ribbon 


The  whole  Wintek  line  of  micro  modules  has 
been  reduced  in  price  30%. 


cartridges  for  almost  any  daisy  printer. 
They  will  refill  your  cartridges  for  $2.50 
each,  well  under  half  the  price  of  a  new 
ribbon.  It  was  only  at  the  recent  Comput¬ 
er  Faire  that  we  learned  that  it  was  possi¬ 
ble  to  reload  a  ribbon  cartridge;  we  tried 
the  services  of  American  Ink  Products 
with  good  results.  We  suspect  most  major 
cities  harbor  such  a  service. 

Lower  the  Price  of  Hardware 

Wintek  wrote  to  tell  us  that  they 
have  cut  30%  from  the  price  of  all  items 
in  their  line  of  6800-based  modules.  If 
you  buy  100  of  them,  you  can  have  a 
single-board  computer  for  $82. 

Several  other  bits  of  useful,  inex¬ 
pensive  hardware  emerged  from  this 
month’s  heap.  The  neatest  one  is  the 
Apple  Type-Ahead  Buffer  from  Vista 
Computer  Co.  It’s  an  elegant  little  circuit 
board  that  buffers  up  to  40  keystrokes. 
With  it  installed  —  and  installation  re¬ 
quires  only  a  phillips  screwdriver  —  you 
can  type  the  next  command  while  your 
Apple’s  still  working  on  the  last  one. 
Anyone  with  more  than  a  few  hours  of 
computer  use  will  appreciate  the  pleasure 
of  that. 

Light  pens  aren’t  new,  but  the  3G 
Company  has  what  looks  like  a  nice  one 
for  the  TRS-80.  It  comes  with  a  demon¬ 
stration  cassette  and  a  “complete  pro¬ 
gramming  booklet”  for  $40. 

Radio  Shack  notified  us  that  they 
now  carry  part  number  271-1705,  a  com¬ 
plete  joystick  assembly,  for  just  $5.  The 
stick  swings  in  a  30-degree  arc  in  either 
dimension  to  control  two,  100K  ohm  lin¬ 
ear  pots.  The  applications  to  which  really 
cheap  joysticks  could  be  put  are  endless. 


tie  16-megabyte  tape  cartridges;  we  first 
met  them  in  the  IBM  5110  desktop  ma¬ 
chine  and  they  are  often  used  now  for 
hard  disk  backup.  MCS  has  put  together 
a  comprehensive  software  and  hardware 
package  to  control  a  cartridge  drive  under 
CP/M.  It  will  keep  track  of  21,000  files 
per  cartridge  by  name,  with  date  and  time 
of  recording,  and  will  move  files  between 
cartridge  and  disk.  If  you  already  have  a 
cartridge  drive,  the  software  costs  $300. 
Adding  an  S-100  controller  and  a  drive 
brings  the  price  to  $5000. 

IBM  Dips  Toe  in  Market 

There  has  been  a  wave  of  speculation 
about  IBM’s  expected  entry  into  the 
desktop  computer  market.  Just  as  this  is¬ 
sue  went  to  press  we  received  an  announce¬ 
ment  from  the  IBM  General  Systems  Divi¬ 
sion,  describing  in  general  terms  the  IBM 
System  23  Datamaster,  “a  low-cost,  desk¬ 
top  computer  that  can  combine  word 
processing  with  data  processing  in  a  single 
system  designed  for  first-time  users.” 

The  only  surprise  in  the  announce¬ 
ment  was  that  “Datamaster  can  include 
two  computer  workstations  which  permit 
two  operators  to  use  it  simultaneously.” 
We  couldn’t  figure  out  what  that  might 
mean:  multiprogramming?  Or  dual  proces¬ 
sors?  So  we  called  our  local  IBM  office. 
“The  Datamaster  has  an  optional  second 
processor;  the  two  processors  can  share 
files,”  an  IBM  rep  told  us.  Is  it  available 
now?  “We  have  stock  in  the  office,  ready 
to  go,”  he  said. 

Datamaster  can  have  up  to  128  KB 
of  storage  (split  64-64  between  two  CPUs, 
we  assume)  and  1-4  diskette  drives.  A  set 
of  business  accounting  programs,  written 
in  BASIC,  is  available  now;  word  process- 


3M  Cartridge  Control  for  CP/M 

You  may  have  seen  the  handsome  lit- 


Radio  Shack’s  joystick  is  part 
costs  just  $5. 


This  is  what  half  a  megabyte  of  RAM  looks 
like;  it  costs  $  12/kilobyte. 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


55 

409 


A  FORTH  Data  Base  Design 

(continued  from  page  47) 


Ttiis  dononstration  data  system  provides  a  pattern  for  the 
further  development  of  any  type  of  data  base.  TTie  basic 
file  formating  definitions  are  on  Screens  22  and  23.  Some 
utilities  are  on  24,  25,  and  26.  The  deno  file 

_  definitions  are  on  27.  Elementary  file  manipulation 

utilities  are  on  28.  This  model  should  get  you  started. 

ing  software  will  be  available  in  Septem¬ 
ber.  And  the  price?  Well,  the  price  is  gen¬ 
uine  IBM:  “A  complete  system  is  just  un¬ 
der  10  thousand,”  we  were  told.  “If  you 
can  do  without  a  printer  you  can  get  it 
into  the  7  thousand  range.”  That  rushing 
sound  you  hear  is  an  entire  industry  sigh¬ 
ing  in  relief. 


ENTER  'Y'  TO  LOAD  SCREENS 
SCREEN  22:  FILE  DEVELOEMENT  2@  MSG  #  4 
SCREEN  23:  FILE  DEVELOEMENT  -  2 
SCREEN  24:  DOUBLE  FRECISION  ARITHMETIC 
SCREEN  25:  DATE  CCMERESSION  AND  EXPANSION 
SCREEN  26:  ?$AMOUNT  AND  .SAMOUNT 
SCREEN  27:  DEMO  FILE  -  RECORD  GENERATION 
SCREEN  28:  DEMO  FILE  -  CLEAR. EATA,  INPUT,  OUTPUT  OK 
OK 
OK 
OK 


Contact  Points 

3G  Company,  Rt.  3  Box  28a,  Gaston,  OR 
971 19;  (503)  662-4492. 

Allen  Ashley,  395  Sierra  Madre  Villa,  Pasa¬ 
dena,  CA  91 107; (213)  793-5748. 

American  Ink  Products,  527  Howard  Street, 
San  Francisco,  CA  94105. 

Elliam  Associates,  24000  Bessemer  St., 
Woodland  Hills,  CA  91367;  (213)  348- 
4278. 

ET-3400  User’s  Group,  c/o  Charles  Van 
Dyke,  11231  Oak  St.,  El  Monte,  CA  91731. 
Eventide  Clockworks,  265  West  54th  Street, 
New  York,  NY  10019;  (212)  581-9290. 
Imprint  Software  USA:  420  South  Howes, 
Ft.  Collins,  CO  80521;  (303)  482-5574. 
UK:  16  Milton  Ave.,  Highgate,  London  N6; 
01-348-3998. 

INMAC,  2465  Augustine  Drive,  POB  4780, 
Santa  Clara,  CA  95051 ;  (408)  727-1970. 
MCS  8308  Juniper,  Ft.  Worth,  TX  76180; 
(817)498-6390. 

MicroMotion,  12077  Wilshire  Boulevard 
#506,  Los  Angeles,  CA  90025;  (213)  821  - 
4340. 

Mosaic  Electronics,  POB  748,  Oregon  City, 
OR  97045. 

Optimized  Systems  Software,  10379  Lands- 
dale  Ave.,  Cupertino,  CA  95014;  (408) 
446-3099. 

Proteus,  1690  Woodside  Road,  Suite  219, 
Redwood  City,  CA  94061. 

Robotics  Age,  POB  725,  La  Canada,  CA 
91011; (213)  352-7937. 

SIG/M,  POB  97,  Iselin,  NJ  08830. 

Timin  Engineering,  9575  Genesee  Avenue, 
Suite  E-2,  San  Diego,  CA  92121;  (714) 
455-9008. 

Tones  Ribbon  Service,  11154  South  Mt. 
Vernon  Avenue,  Colton,  CA  92324;  (714) 
792-0831. 

Type  Share,  8315  Firestone  Blvd.,  Downey, 
CA  90241;  (213)  923-9361. 

Vista  Computer  Co.,  1317  E.  Edinger  Ave¬ 
nue,  Santa  Ana,  CA  92705;  (714)  953- 
0523. 

Westico,  25  Van  Zant,  Norwalk,  CT  06855; 
(203)  853-6880. 

Wintek,  1801  South  Street,  Lafayette,  IN 
47904;  (317)  742-8428. 


DEMO  OK 
CLEAR.  EATA  OK 
OUTPUT 

EMPTY  FILE 

OK 

INPUT 


ENTER  NAME 
ENTER  DATE 
ENTER  AMOUNT 
1  ZENITH 
OK 

INPUT 


— >  ZENITH 
MM/DD/YY  )  4/21/81 
— >  18.50 

04/21/81  S  18.50OK 


ENTER  NAME 
ENTER  DATE  — > 

ENTER  AMOUNT 
2  IBM 

OK 

INPUT 


—>  IBM 

(  MM/DD/YY  )  4/21/81 
— >  60. 

04/21/81  $  60.00OK 


ENTER  NAME 
ENTER  CATE 
ENTER  AMOUNT 
3  DEC 
OK 
OK 

0  READ  ADDRESS  HEX  80  DUMP  DECIMAL 


58CA 

3 

0 

0 

0 

0 

0 

0 

0 

0 

0 

0 

0 

0 

0 

0 

0  . 

58DA 

0 

0 

0 

0 

0 

0  0 

0 

0 

0 

0 

0 

0 

0 

0 

0  . 

58EA 

0 

0 

0 

0 

0 

0 

0 

0 

5A 

45 

4B 

49 

54 

48 

20 

20  . 

.  .ZENITH 

58FA 

20 

20 

20 

20 

20 

20  20 

20 

20 

20 

20 

20 

20 

20 

20 

20 

59  0A 

20 

20 

20 

20 

20 

20  B5 

84 

0 

0 

3A 

7 

0 

0 

49 

42 

591A 

4D 

20 

20 

20 

20 

20  20 

20 

20 

20 

20 

20 

20 

20 

20 

20  M 

592A 

20 

20 

20 

20 

20 

20  20 

20 

20 

20 

20 

20 

B5 

84 

0 

0 

59  3A 

70 

17 

0 

0 

0 

0  0 

0 

0 

0 

0 

0 

0 

0 

0 

0  p - 

OK 

OK 

OK 


OUTPUT 

1  ZENITH  04/21/81  S  18.50 

2  IBM  04/21/81  $  60.00 

3  DEC  04/21/81  $  103.50 


— >  DEC 

— >  (  MM/DD/YY  )  4/21/81 

— >  103.5 

04/21/81  S  103.50OK 


OK 

OK 


:  STATEMENT  CR  CR  20  SPACES  . "  STATEMENT  "  CR  CR  OUTPUT 

CR  CR  ."  TOTAL  VALUE  ”  33  SPACES  0  0  0  READ  TAG  @  1+  1 

DO  I  READ  COLLAR  D@  D+  LOOP  .SAMOUNT  CR  CR  CR  ;  OK 
OK 
OK 

STATEMENT 


STATEMENT 


1  ZENITH 

2  IBM 

3  DEC 


04/21/81  S  18.50 
04/21/81  S  60.00 
04/21/81  $  103.50 


TOTAL  VALUE 


$  182.00 


OK 


End  Listing 


56 

410 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


The  FORTH  Alternative 


There  is  a  new  way  of  using  a  com¬ 
puter  that  is  still  unfamiliar  to  most 
computer  people.  It  is  known  as 
FORTH.  Although  many  have  heard  of 
FORTH,  relatively  few  understand  just 
what  it  is.  The  purpose  of  this  article  is  to 
describe  FORTH. 

A  Computer  Utilization  System 

FORTH  is  a  computer  utilization  sys¬ 
tem,  not  just  a  language.  FORTH  is  a  lan¬ 
guage,  but  it  also  includes  the  capabilities 
of  an  operating  system,  a  text  editor,  an 
assembler,  and  a  monitor.  It  is  a  complete 
system  for  making  use  of  a  computer. 
With  FORTH  all  of  these  facilities  are 
memory  resident,  and  hence  available  for 
immediate  use.  This  is  in  contrast  to  con¬ 
ventional  systems,  where  the  editor,  lan¬ 
guage  compiler,  etc.  are  separate  utilities 
needing  to  be  loaded  into  memory  from 
disk  each  time  they  are  used. 

The  customary  way  of  using  a  com¬ 
puter  is  by  means  of  an  operating  system 
and  various  program  files.  The  operating 
system  maintains  a  dialogue  with  the 
user,  servicing  the  user’s  requrests.  When 
the  execution  of  a  program  is  requested, 
then  this  dialogue  is  suspended  until  the 
program  execution  is  finished.  With 
FORTH  there  is  no  separation  of  the  soft¬ 
ware  into  operating  system  and  utilities. 
The  operating  system  commands  are  re¬ 
placed  by  a  complete  language  which  eli¬ 
minates  the  need  for  separate  program¬ 
ming  languages.  The  FORTH  language  is 
therefore  an  operating  system  and  a  pro¬ 
gramming  language  at  one  and  the  same 
time. 

BASIC  is  another  language  that  is  of¬ 
ten  implemented  in  an  interactive  man¬ 
ner;  this  is  one  of  the  reasons  for  its  pop¬ 
ularity.  This  form  of  BASIC  also  has  a 
memory-resident  editor  and  can  edit  and 
run  without  loading  from  disk.  Unfor¬ 
tunately,  interactive  BASIC  has  many 
shortcomings  which  cause  considerable 
difficulty  when  it  is  used  for  medium  size 
and  larger  projects.  Chief  among  these  is 
its  lack  of  a  satisfactory  subroutining 
mechanism  and  severe  restrictions  on  the 
naming  of  variables.  Furthermore,  BASIC 
is  unsatisfactory  for  real-time  systems 


by  Mitchell  E.  Timin 


Dr.  Mitchell  E.  Timin,  c/o  Timin  Engi¬ 
neering  Co.,  9575  Genesee  Rd.,  Suite  E2, 
San  Diego,  CA  92121. 


programming  due  to  its  slow  execution 
speed  and  lack  of  bit  and  byte  manipula¬ 
tion  primitives.  In  contrast,  FORTH 
gives  the  user  immediate  access  to  all 
capabilities  of  his  computer. 

FORTH  Words 

FORTH  consists  primarily  of  a  dic¬ 
tionary  of  words.  These  FORTH  words 
are  conceptually  similar  to  English  lan¬ 
guage  words  in  that  they  each  have  a  cer¬ 
tain  spelling,  a  definition,  and  rules  for 
usage.  An  example  of  a  FORTH  word  is 
TYPE,  which,  when  given  a  starting  ad- 
ress  and  a  count,  will  find  some  charac¬ 
ters  in  memory  and  display  them  on  the 
console.  A  second  example  is  MAX, 
which  will  select  the  largest  of  a  group  of 
numbers.  The  common  numerical  opera¬ 
tors,  +  -  *  and  /,  are  FORTH  words 
whose  “spelling”  is  just  one  character. 
Several  of  the  most  commonly  used 
FORTH  words  are  also  spelled  with  one 
character. 

FORTH  words  may  be  used  as  direct 
commands  to  the  computer  from  the 
operator.  One  or  more  FORTH  words, 
when  typed  at  the  console,  will  cause 
their  particular  actions  to  occur.  For  ex¬ 
ample,  typing  VLIST  (a  FORTH  word) 
followed  by  the  return  key,  will  result  in 
the  display  of  all  of  the  FORTH  words, 
since  that  is  the  function  of  VLIST. 
FORTH  comes  with  a  vocabulary  of  over 
one  hundred  words  that  are  likely  to  be 
used  by  the  user.  This  does  not  count  the 
assembler  vocabulary  nor  many  internal 
system  words.  The  total  vocabulary  is 
usually  several  hundred  words. 


Programming  in  FORTH 

The  FORTH  user  is  not  limited  to 
the  built-in  FORTH  words!  Programming 
in  FORTH  consists  of  defining  new  words 
in  terms  of  existing  words.  In  this  manner 
the  vocabulary  of  available  FORTH 
words  can  grow  indefinitely.  FORTH  is 
very  similar  in  this  respect  to  a  natural 
language.  English  is  continually  adding 
new  words;  each  of  them  is  defined  in 
terms  of  the  old  ones. 

Thus  we  see  that  FORTH  words 
function  both  as  programming  elements 
and  as  direct  commands  to  the  computer. 
A  FORTH  word  is  conceptually  similar 
to  the  subroutine  or  subprogram  in  other 
languages,  however  the  usage  rules  and  in¬ 
ternal  implementation  are  unique  to 
FORTH. 


A  FORTH  user  creating  new  defini¬ 
tions  may  use  the  EDITOR  commands 
to  write  these  onto  disk,  thus  creating 
a  library  of  application  software.  Note 
that  EDITOR  commands  are  FORTH 
words.  The  EDITOR  is  not  a  separate 
utility,  it  is  just  a  group  of  FORTH 
words,  all  of  which  are  available  at  any 
time.  The  word  LOAD  is  used  to  add 
these  newly  created  definitions  to  the  dic¬ 
tionary,  in  memory.  The  user  also  has  the 
option  of  entering  new  definitions  di¬ 
rectly  into  the  dictionary,  with  no  disk 
record.  This  is  done  when  experimenting 
or  for  one  time  use  of  a  definition. 

After  the  dictionary  has  been  en¬ 
larged,  by  either  of  the  above  methods, 
the  user  may  create  another  version  of 
FORTH  which  includes  this  enlarged 
dictionary.  Any  number  of  special  pur¬ 
pose  versions  may  thus  be  created,  if 
desired.  These  “customized”  FORTH  ver¬ 
sions  may  restrict  the  user  to  a  limited 
vocabulary,  if  desired.  This  permits  the 
use  of  the  special  application  software, 
while  denying  direct  use  of  other  parts  of 
the  FORTH  system. 

The  Stack 

Most  FORTH  words  require  some 
data  to  operate  on;  most  also  produce 
some  data  that  may  in  turn  be  used  by 
another  FORTH  word.  The  primary 
method  used  by  FORTH  to  pass  data  to 
and  from  FORTH  words  is  the  data  stack. 
The  data  stack  is  a  region  in  memory 
where  the  user  can  easily  store  and  re¬ 
trieve  data.  For  instance,  if  the  user  types 
1234  at  his  terminal,  followed  by  carriage 
return,  the  number  1234  will  be  put  on 
the  data  stack.  In  general,  FORTH  words 
take  whatever  data  they  need  from  the 
top  of  the  stack,  and  leave  whatever  re¬ 
sults  they  produce  on  the  stack.  Named 
variables,  arrays,  direct  memory  address¬ 
ing  and  CPU  registers  are  available  as  al¬ 
ternate  data  handling  mechanisms. 

Using  the  stack  in  this  manner  leads 
to  the  requirement  that  operands  precede 
operators  when  writing  FORTH.  To  illu¬ 
strate,  if  it  is  desired  to  add  45  and  54, 
and  then  print  the  result,  type: 

45  54  +  . 

When  the  user  hits  RETURN  after  the 
above  line  the  following  sequence  of 
events  will  occur: 

—  the  number  45  is  put  on  the  data  stack. 

—  the  number  54  is  put  on  the  data  stack. 

—  the  FORTH  word  “+”  begins  to  exe¬ 
cute,  doing  the  following: 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


57 

411 


—  the  number  54  is  removed  from  the 
stack. 

—  the  number  45  is  removed  from  the 
stack. 

—  these  two  numbers  are  added,  pro¬ 
ducing  the  sum,  99. 

—  the  number  99  is  put  on  the  stack.. 

—  the  FORTH  word  begins  to  exe¬ 
cute,  doing  the  following: 

—  the  number  99  is  removed  from  the 
stack. 

—  it  is  tranlated  from  binary  form  to  a 
sequence  of  ASCII  codes. 

—  these  are  sent  to  the  terminal,  caus¬ 
ing  99  to  appear. 

-  control  returns  to  the  FORTH  execu¬ 
tive  which  types  OK. 

The  practice  of  entering  operands 
prior  to  operators  is  also  used  on  the 
highly  successful  Hewlett-Packard  calcu¬ 
lators.  (Mathematicians  call  this  reverse 
Polish  notation.)  The  H-P  calculators  also 
use  a  data  stack;  reverse  Polish  notation 
is  the  natural  way  to  communicate  with 
a  stack  machine.  Use  of  a  data  stack  is  the 
most  efficient  way  of  passing  data  be¬ 
tween  routines,  which  is  the  reason  for  its 
use  in  FORTH. 

Defining  Words 

Programming  in  FORTH  makes  use 
of  special  FORTH  words  called  defining 
words.  Here  is  an  example;  we  will  define 
a  new  FORTH  word  called  ADD3  which 
will  compute  the  sum  of  three  numbers 
from  the  stack  and  display  the  result: 

;  ADD3  +  +  .  ; 

The  defining  word  is  Its  use  causes 
ADD3  to  be  created  and  compiled  into 
the  dictionary.  ends  the  definition. 
Later,  if  ADD3  is  used  it  will  execute 
+  +  .  which  will  add  the  top  three  stack 
items  and  display  the  result.  The  first 
will  replace  the  top  two  stack  items  with 
their  sum.  The  second  +  will  add  that  sum 
to  the  last  stack  item,  leaving  only  the 
sum  of  the  original  three.  Finally  the  . 
prints  the  result. 

The  only  other  frequently  used  de¬ 
fining  words  are  VARIABLE  and  CON¬ 
STANT.  The  defining  word  CODE  is  used 
with  the  Assembler.  The  advanced 
FORTH  programmer  may  easily  create 
new  defining  words,  but  this  is  unneces¬ 
sary  for  the  vast  majority  of  applications. 

Hardware  Access 

The  FORTH  user  has  complete  ac¬ 
cess  to  all  I/O  ports  and  memory  loca¬ 
tions.  Data  can  be  read  from  or  written 


to  any  device  or  memory  location,  either 
directly  by  the  user’s  command,  or  during 
the  execution  of  FORTH  routines  written 
by  the  user.  This  makes  FORTH  ideal  for 
control  or  testing  of  hardware.  FORTH 
can  use  any  number  base  also,  so  binary, 
hex,  or  octal  may  be  used  when  appropri¬ 
ate.  For  example,  suppose  bit  0  of  output 
port  AO  controls  a  motor.  To  turn  on  a 
motor  the  user  types: 

HEX  1  AO  P! 

The  word  HEX  is  used  to  switch  to  hexa¬ 
decimal  for  terminal  I/O.  It  need  only  be 
used  once,  until  another  number  base  is 
desired.  P!  is  the  word  which  sends  data 
to  a  port,  in  this  case  the  port  is  AO  and 
the  data  is  1 . 

Now  suppose  we  wish  to  have  the 
computer  turn  the  motor  on  and  off  at 
periodic  intervals,  so  that  we  may  test  its 
temperature  rise.  We  will  define  the  word 
MOTOR-ON-OFF  to  do  this,  as  follows: 

:  MOTOR-ON-OFF  BEGIN 

1  AO  P!  WAIT  0  AO  P!  WAIT 

7TERMINAL  UNTIL  ; 

Here,  MOTOR-ON-OFF  is  the  new 
FORTH  word  which  we  are  creating. 
BEGIN  and  7TERMINAL  UNTIL  create 
a  loop  which  repeats  indefinitely  until  a 
key  is  hit  on  the  console.  WAIT  is  a  word 
which  we  must  have  defined  previously ;  it 
is  a  software  delay  of  an  appropriate  in¬ 
terval.  Now,  whenever  we  type  MOTOR- 
ON-OFF  and  return,  the  motor  will  begin 
to  turn  on  and  off  until  a  key  is  hit  at  the 
terminal.  The  definition  of  WAIT  may  be 
as  simple  as: 

:  WAIT  7FFF  0  DO  LOOP  ; 
which  causes  a  brief  delay  by  repeating  an 
empty  loop  32,000  times.  (7FFF  hex  = 
32,767  decimal) 

Using  Disk  Storage 

FORTH  makes  use  of  disk  storage  by 
considering  the  disk  to  consist  of  blocks. 
Each  disk  block  has  1024  bytes.  The 
blocks  are  referred  to  by  number,  starting 
with  number  1.  Disk  blocks  are  used 
when  FORTH  software  is  created  using 
the  editor.  They  are  also  used  for  any 
data  storage  operation.  Individual  blocks 
may  always  be  accessed  by  number,  but 
the  programmer  may  create  a  naming 
system  to  suit  specific  needs. 

An  important  feature  of  FORTH 
disk  utilization  is  virtual  memory.  By  this 
term  we  mean  that  images  of  some  disk 
blocks  may  be  in  memory  at  any  time, 
and  that  these  are  available  without  disk 


access.  The  number  of  blocks  which  may 
be  in  memory  simultaneously  depends  on 
the  implementation,  but  eight  is  a  typical 
value.  Typically,  these  will  be  the  eight 
most  recently  referenced  blocks.  Any  of 
these  may  be  read  or  written  to  without 
the  delay  of  disk  I/O.  When  another 
block  is  called  for  it  will  automatically  re¬ 
place  the  oldest  of  those  in  memory.  That 
one,  if  it  has  been  modified,  will  be  up¬ 
dated  by  writing  onto  the  disk  the  copy 
in  memory. 

Assembly  Language  Modules 

The  FORTH  Assembler  is  used  to 
create  a  FORTH  word  that  consists  of 
executable  machine  code.  The  more  com¬ 
mon  FORTH  words,  as  in  the  examples 
above,  are  compiled  into  lists  of  addresses 
of  other  FORTH  words.  Use  of  the  As¬ 
sembler,  and  of  the  defining  word  CODE, 
allows  writing  instructions  in  assembly 
language  which  are  then  assembled  into 
machine  code  within  the  dictionary.  This 
is  done  when  maximum  execution  speed 
is  needed.  FORTH  written  without  the 
assembler  does  not  execute  as  fast  as  as¬ 
sembly  code,  nor  as  fast  as  fully  compiled 
languages  such  as  FORTRAN.  FORTH 
programmers  usually  complete  an  applica¬ 
tion  program  without  using  the  assem¬ 
bler.  Then,  if  there  is  a  speed  problem, 
one  or  more  “bottleneck”  words  will  be 
redefined  using  the  assembler.  In  most  in¬ 
stances  90%  of  the  execution  time  is  used 
by  only  10%  of  the  code,  so  most  code 
may  remain  in  high  level  FORTH. 

Structured  Programming 

The  concepts  of  top  down  and  struc¬ 
tured  programming,  which  have  gained 
wide  acceptance  in  recent  years,  are  fully 
realizable  with  FORTH.  FORTH  pro¬ 
gramming  is  structured  programming. 
FORTH  does  not  use  a  “GO  TO”  state¬ 
ment;  instead  there  is  a  small  group  of 
FORTH  words  that  implement  control 
structures.  IF  .  . .  ELSE  . .  .  ENDIF  is  the 
two-path  test  and  branch,  while  CASE: 
implements  a  multi-path  test  and  branch. 
DO  .  .  .  LOOP,  BEGIN  .  .  .  UNTIL,  and 
BEGIN  .  . .  WHILE  . .  .  REPEAT  imple¬ 
ment  looping  structures.  All  FORTH  con¬ 
trol  structures  have  one  entry  path  and 
one  exit  path. 

The  top  down  approach  to  program 
creation  is  facilitated  because  each 
FORTH  word  is  a  clearly  defined  module 
which  is  constructed  from  other  FORTH 
words.  With  FORTH  there  is  no  limit  to 


58 

412 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


the  depth  of  this  nesting.  Hence  the  pro¬ 
grammer  begins  his  efforts  by  choosing 
one  name  to  represent  the  final  result 
which  he  plans  to  achieve.  Next  he  would 
analyze  the  task  and  break  it  down  into 
a  small  number  of  sub-tasks;  for  each  of 
these  he  chooses  the  name  of  a  FORTH 
word.  He  proceeds  in  this  manner  until 
reaching  the  level  of  the  original  FORTH 
vocabulary.  The  input  and  output  data 
for  each  word  must  be  specified  as  part  of 
this  design  process.  For  example,  a  pro¬ 
grammer  creating  an  automatic  testing 
program  might  name  the  program  TEST. 
This  would  become  a  FORTH  word 
which  performs  a  complex  sequence  of 
operations.  He  then  might  conclude  that 
the  basic  components  of  the  task  are  to 
initialize  the  hardware,  exercise  the  hard¬ 
ware,  and  deactivate  the  hardware.  He 
then  chooses  the  names  INIT,  EXER,  and 
OFF  for  those  modules.  The  EXER 
module  is  then  broken  down  into  TESTA, 
TESTB,  TESTC,  and  so  on. 

After  the  initial  design  procedure  is 
done,  coding  and  testing  of  modules  pro¬ 
ceeds  from  the  bottom  up.  The  top  down 
design  procedure  results  in  specifications 
for  the  many  FORTH  words  which  will 
build  the  final  result.  Each  of  these  is 
created  using  the  appropriate  defining 
word  (usually  “ :  ”)  and  is  tested  immedi¬ 
ately  upon  creation.  Testing  a  FORTH 
word  consists  of  typing  a  command  line 
which  puts  appropriate  data  on  the  stack 
and  invokes  the  new  word.  If  necessary, 
a  loop  or  other  structure  can  be  used 
to  invoke  the  new  FORTH  word  many 
times  under  varying  conditions.  It  is  also 
a  common  practice  to  define  a  dummy 
version  of  a  middle-level  word  so  that 
the  top-level  definitions  may  be  tested 
prior  to  completion  of  the  bottom-level 
words. 

Advantages  of  FORTH 

There  are  two  important  benefits  re¬ 
sulting  from  the  use  of  FORTH  instead  of 
other  computer  languages: 

1)  Total  software  development  time  is 
greatly  reduced. 

2)  Memory  requirements  are  greatly  re¬ 
duced. 

This  has  been  demonstrated  by  the  exper¬ 
ience  of  those  who  have  used  FORTH  for 
major  projects.  The  reduction  in  program¬ 
ming  time  is  due  partly  to  the  extreme 
modularity  of  FORTH.  On  a  large  project 
the  programmers  accumulate  a  special  vo¬ 
cabulary  of  FORTH  words  which  are  very 
appropriate  to  their  application.  These 


very-high-level  routines  are  just  as  easy 
to  use  as  the  simplest  FORTH  primitives. 
FORTH  projects  do  not  experience  the 
bogged- down  situation,  which  is  common 
on  large  projects  using  other  languages. 
This  is  directly  due  to  the  fact  that  the 
very-high-level  FORTH  construct  be¬ 
comes  a  primitive  as  soon  as  it  has  been 
defined.  Hence,  the  primitives  of  the  lan¬ 
guage  become  more  and  more  powerful  as 
the  project  progresses.  The  second  reason 
for  the  high  production  rate  of  FORTH  is 
its  interactive  nature.  With  conventional 
programming  systems  the  user  experi¬ 
ences  frequent  waiting  while  the  editor, 
compiler,  linker,  and  application  load  and 
execute.  This  is  especially  true  on  floppy 
disk  systems,  but  is  also  true  on  multi¬ 
tasking  minis  when  there  are  many  users. 
With  FORTH  all  of  this  is  memory  resi¬ 
dent  so  these  waits  do  not  occur. 

The  unique  internal  structure  of 
FORTH  produces  remarkably  compact 
code;  our  version  of  FORTH  is  about  1 1 
kilobytes.  These  11K  bytes  include  the 
language  compiler  and  interpreter,  operat¬ 
ing  system,  editor,  assembler,  and  debug¬ 
ger.  Application  software  developed  by 
the  user  may  either  be  disk  resident,  load¬ 
ed  by  FORTH  as  needed,  or  it  may  be 
added  to  the  1 1 K  package  and  become 
memory  resident.  Also,  if  memory  is 
limited,  the  application  software  may  re¬ 
place  the  editor,  assembler  and  other 
parts  of  FORTH.  In  this  manner  a  custom 
FORTH  implementation  may  be  created 
occupying  as  little  as  8K  bytes.  (The 
above  byte  counts  refer  to  code  space. 
Full  Timin  FORTH  also  requires  8K 
bytes  for  disk  buffers  and  another  K  for 
stack  space  and  the  BIOS  portion  of 
CP/M.  The  custom  application  may  or 
may  not  need  this.) 

A  Little  History 

FORTH  was  invented  by  Charles 
Moore  in  1969.  He  was  then  with  the 
National  Radio  Astronomy  Laboratory, 
which  resulted  in  FORTH  coming  into 
wide  use  within  the  astronomical  commu¬ 
nity  for  observatory  automation. 

In  1978  a  group  of  experienced 
FORTH  programmers  formed  the 
FORTH  Interest  Group  (FIG)  in  order  to 
make  the  language  more  widely  available. 
There  is  also  a  European  FORTH  user’s 
group. 

There  is  now  a  FORTH  standard 
known  as  FORTH- 79.  This  was  created 
by  the  FORTH  Standards  Team  on  which 
FIG  and  the  Europeans  are  well  repre¬ 


sented.  Although  an  exact  implementa¬ 
tion  of  FORTH- 79  is  not  yet  available, 
FIG  FORTH  is  very  close. 


FORTH  by  Timin  Engineering 

Our  version  of  FOR  TH  is  based  upon 
FIG  FORTH.  Timin  Engineering  Co.  has 
added  the  interleaved  disk  format,  the 
Z-  80/8080  assembler  vocabulary,  and  sever¬ 
al  FORTH  words  including  SAVE,  DUMP 
and  CASE:.  The  Editor  is  based  upon  the 
FIG  model,  but  a  string  search  module  was 
implemented  using  assembly  language  for 
quick  response. 

In  order  to  achieve  the  fastest  pos¬ 
sible  disk  I/O,  the  physical  sectors  that 
make  up  a  FOR  TH  disk  block  are  always  on 
the  same  track.  They  are  distributed  on  the 
track  so  that  all  can  be  read  in  one  revolu¬ 
tion  of  the  disk. 

The  FORTH  Assembler  supplied  with 
Timin  FORTH  will  assemble  all  8080  or 
Z-80  machine  instructions.  The  mnemonic 
system  used  follows  INTEL ’s  8080  assembly 
language,  extended  to  include  the  special 
Z-80  instructions. 

Timin  FORTH  will  run  on  any  8080/ 
8085/Z-80  system  with  CP/M  and  at  least 
24K  of  memory.  It  is  available  on  most 
diskette  formats. 


This  publication 
is  available 
in  microform. 


University  Microfilms 
International 


300  North  Zeeb  Road 
Dept.  RR. 

Ann  Arbor,  Mi.  48106 
U.SA. 


30-32  Mortimer  Street 
Dept.  P.R. 

London  WIN  7RA 
England 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


59 

413 


■-rn.  l/UDD  O  CLINIC 


by  Dave  Cortesi,  Resident  Intern 


DUPDUPNEG  AND  = 

That’s  one  solution,  expressed  in 
FORTH  by  Mitchell  Stanek  and  Dean 
Vieau  of  Detroit,  MI,  to  the  “Lost 
Chord”  problem  we  presented  in  June. 
The  problem  was  to  re-invent  a  simple 
test  that  would  tell  if  a  binary  integer 
contained  only  a  single  1-bit.  The  NEG 
(two’s  complement)  word  isn’t  in  fig- 
FORTH,  but  it’s  easily  created. 

Readers  provided  two  different  solu¬ 
tions.  The  test  used  by  Stanek  and  Vieau 
can  be  expressed  more  conventionally 
(but  less  succinctly)  as: 

(  N  and  (-N) )  =  N 

Thomas  E.  Carr  explained  it  this  way: 
“The  only  bit  that  is  set  in  both  a  number 
and  its  two’s  complement  is  the  least  sig¬ 
nificant  one.  Therefore,  if  a  number  is 
ANDed  with  its  complement,  the  result 
is  only  the  least  significant  bit  of  the  ori¬ 
ginal  number.  If  that  bit  also  happens  to 
be  the  only  bit  set  in  the  original,  then 
the  two  numbers  (the  original  and  the  re¬ 
sult  of  the  AND)  are  equal.  Voila!”  Both 
this  test  and  the  next  one  will  pass  a 
quantity  of  N=0;  all  respondents  noted 
that  that  case  must  be  filtered  out  first. 

Dan  Bates  of  Johnson  City,  TN  com¬ 
mented  on  how  the  test  on  a  16-bit  inte¬ 
ger  could  be  folded  into  an  8-bit  register. 
He  wrote,  “If  X=2**n  then  the  high  byte 
of  X,  XHI,  and  the  low  byte  of  X,  XLO, 
cannot  be  equal.  This  test  also  eliminates 
X=0.  If  X<>2**n,  and  XHIOXLO, 
then  the  result  of  XHI  OR  XLO  will  have 
2  bits  set.  If  X=2**n  then  XHI  OR  XLO 
will  have  one  bit  set.  So  to  turn  the  16- 
bit  problem  into  8  bits: 

If  XHI=XLO  Then  false,  return. 

Let  T  :=  XHI  OR  XLO 

If  (T  AND  -T)=T,  Then  true,  return 
Else  false,  return 

A  larger  number  of  readers  favored  a 
test  that  can  be  expressed  this  way: 

(  N  and  (N-l) )  =  0 

Georges  A.  Becus  of  the  University  of 
Cincinatti  said  of  this  test:  “It  is  based  on 
Peter  Wegner’s  method  for  counting  ones 
in  a  binary  number  ( Comm.  ACM,  May 
1960,  p.  322;  see  also  Lewis  and  Doerr, 
Minicomputers:  Structure  and  Program¬ 
ming ,  Hayden,  1976,  pp.  156-157).  The 
method  consists  of  subtracting  one  from 
the  binary  number  N  and  ANDing  the  re¬ 
sult  with  N.  The  process  is  repeated  until 
a  zero  result  is  obtained.  The  number  of 
times  the  process  is  repeated  is  the  num¬ 
ber  of  ones  in  N.  Since  we  are  trying  to 
determine  if  the  number  N  has  a  single 
one  we  need  only  go  through  the  process 


once.  If  the  result  is  zero  then  N  has  a 
single  one.” 

Most  writers  presented  their  tests  in 
pseudo-code  or  in  C,  providing  assembly 
language  routines  only  after  the  algorithm 
had  been  justified  at  a  higher  level.  That’s 
a  healthy  attitude,  and  we’U  avoid  asking 
for  assembly  language  solutions  in  the 
future.  The  elements  of  a  problem  might 
be  bits  or  binary  integers,  but  C,  Pascal, 
even  BASIC  can  be  used  to  manipulate 
them. 

Shifty  Coding 

There  are  still  things  to  be  learned 
about  bit  manipulation  and  binary  arith¬ 
metic.  Eveyone  knows  that  it’s  good  to 
implement  multiplication  and  division  by 
a  power  of  2  as  a  series  of  shifts,  right? 
That  was  the  implicit  point  behind  “The 
Lost  Chord.”  In  his  response,  Norman 
Crowfoot  of  Flagstaff,  AZ,  pointed  out 
that  it  isn’t  always  a  good  idea.  “One 
thing  that  many  people  don’t  know  is  the 
fact  that  a  right  shift  of  an  odd  negative 
number  is  not  dividing  by  two.  If  you 
work  out  the  math  with  the  bits  you  find 
that  -5  shifted  right  one  place,  with  sign 
propogation,  is  -3.  The  fix  is  that  when¬ 
ever  you  shift  a  bit  out  the  right  of  a 
negative  number,  one  must  be  added  to 
the  value.”  Multiplication  of  a  two’s  com¬ 
plement  negative  number  by  shifting  it 
left  isn’t  reliable,  either.  Perhaps  someone 
will  analyze  these  things? 

The  Switch 

William  A.  McWorter  of  Columbus, 
OH,  is  our  kind  of  reader:  he  sent  us  two 
“sponses”  just  when  we  needed  them. 
Most  everyone  knows  the  old  trick  for 
swapping  two  binary  values  A  and  B  with¬ 
out  the  use  of  a  temporary  variable: 

A  :=  A  xor  B 

B  :=  A  xor  B 

A  :=  A  xor  B 

Reader  McWorter  writes,  “First  ‘sponse’ 
for  the  Clinic.  What  if  xor  is  not  feasible? 


Are  there  other  ways?  I  submit 
A  :=  A  -  B 
B  :=  A  +  B 
A  :=  B  -  A  ” 

The  trick  works,  and  it’s  fascinating.  It 
may  be  a  little  easier  to  follow  if  you  re¬ 
cast  it  to  eliminate  the  mid-stream  as¬ 
signments,  thus: 

B'  :=  (A  -  B)  +  B 

A'  :=  ( (A  -  B)  +  B)  -  (A  -  B) 

By  one  of  those  eerie  little  coincidences 
that  make  magazine  work  interesting,  it 
was  just  24  hours  earlier  that  we  had  re¬ 
ceived  a  note  from  Michael  Driscoll  of 
Sterling,  VA,  in  which  he  claimed  that 
this  sequence  would  swap  two  variables: 

A  :=  A  +  B 
B  :=  A  -  B 
A  :=  A  -  B 

That  can  be  rewritten  in  an  assignment- 
free  way: 

B'  :=  (A  +  B)  -  B 

A'  :=  (A  +  B)  -  ( (A  +  B)  -  B) 

Both  methods  clearly  work.  What’s  more, 
while  the  xor- trick  works  only  for  binary 
values,  these  arithmetic  tricks  should 
work  with  numbers  stored  in  any  base. 
Are  they  safe  with  floating  point  values? 
Or  rather,  when  are  they  dangerous? 

Separate  But  Equal 

Reader  McWorter’s  letter  continues, 
“  ‘Sponse’  two  is  a  computing  problem 
that  made  me  think  hard.  How  do  you 
implement  coroutines?  I  offer  the  8080 
code  in  Listing  I. 

We  managed  to  dredge  up  a  memory  of 
what  coroutines  are:  independent  mod¬ 
ules  that,  from  one  point  of  view,  call 
each  other  as  subroutines.  From  another 
point  of  view  coroutines  are  equal  pro¬ 
grams  that  exchange  control  between 
themselves  in  an  orderly  way  (as  opposed 
to  unrelated  programs  time-sliced  by  a 
higher  mechanism).  Algorithms  for  some 
problems  fall  out  very  neatly  when  or¬ 
ganized  as  coroutines.  With  further 
thought,  we  worked  out  what  the  LINK 


Listing  I. 

LINK:  LXI  H,0 

Get  caller’s 

DAD  SP 

.  .stack  pointer 

XCHG 

.  .and  save  it. 

LHLD  SAVEDSP 

Swap  coroutine’s 

SPHL 

.  .stack  pointer 

XCHG 

.  .with  that  of 

SHLD  SAVEDSP 

.  .the  caller. 

RET 

Resume  coroutine 

60 

414 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


fragment  accomplishes.  It’s  easier  to  ex¬ 
press  as  a  picture  (figure  1).  Routines  A 
and  B  have  their  own  stacks;  they  may 
or  may  not  have  variables  in  common. 
The  diagram  shows  the  state  of  the  pro¬ 
gram  just  after  Routine  A  has  called 
LINK. 


McWorter  goes  on,  “[Coroutines] 
simplified  the  writing  of  a  printer  driver 
for  my  digital  plotter.  LINK  connects 
only  two  coroutines.  How  can  the  linkage 
be  written  for  three  coroutines  interact¬ 
ing  in  all  possible  ways?  Can  versions  of 
BASIC  or  Pascal  support  coroutine  struc¬ 


tures  or  is  SIMULA  the  only  lucky  one?” 

Submitting  to  CP/M 

Working  with  CP/M  is  such  an  adven¬ 
ture.  One  just  never  knows  what  sort  of 
undocumented  bonus  feature  will  turn 
up  around  the  next  corner.  We  stumbled 
onto  the  fact  that  the  CCP  treated  colons 
as  delimiters  (May  Clinic).  Then  John 
Pierce  of  Digital  Research  told  us  that  the 
semicolon  was  the  proper  delimiter 
(July). 

Now  we’ve  received  a  letter  from 
Steve  Pritchard  of  Willowdale,  Ontario, 
Canada.  He  says  “I  too  had  stumbled  into 
the  use  of  semicolons  to  comment  out 
statements.  I  use  them  to  kill  statements 
in  the  middle  of  a  submit  file.  For  exam¬ 
ple  if  we  have  a  SUB  file  called  X: 

LIB  OBJ=OBJ<$l  >  ;LIB  combines 

RELs 

$2  ERA  Sl.REL  ; optional  erase 

Thus  ‘SUBMIT  X  ABC’  will  add  ABC.REL 
to  OBJ.REL  and  then  erase  ABC.REL, 
while  ‘SUBMIT  X  ABC  ;’  will  add 
ABC.REL  to  OBJ.REL  only.  As  you  can 
see,  this  gives  a  very  primitive  statement 
selection  capability,  but  since  it  is  unad¬ 
vertised  we  cannot  complain.  [  Yes  we 
can!  DEC]  I  was  also  toying  with  the 
idea  of  writing  an  IF  processor  which 
would  not  be  too  hard  to  implement.” 

Pritchard  has  found  an  effect  we 
would  never  have  anticipated.  After  all, 
if  the  semicolon  is  a  delimiter,  why 
wouldn’t  it  delimit  the  parameter  list  of  a 
SUBMIT  command?  We  experimented. 
SUBMIT  treates  a  semicolon  just  like  any 
other  character;  one  can  appear  at  any 
point  in  the  parameter  list.  Parameters 
following  a  semicolon  are  still  visible  and 
are  handled  normally.  So  a  semicolon  is  a 
delimiter  only  to  a  program  that  wants  to 
treat  it  as  one;  the  CCP  does,  and 
SUBMIT  doesn’t. 

Delayed  Again 

We  have  several  nice  division  and 
decimal- output  routines  to  display,  but 
the  listings  are  fairly  bulky.  In  order  to 
do  them  justice,  we  will  devote  the  next 
Clinic  to  that  problem.  In  the  following 
(November)  Clinic  we  will  turn  to  the 
many  sponses  and  responses  that  will 
have  arrived  in  the  meantime.  Won’t 
they? 


Our  high-quality  editorial 
and 

your  high-quality  products 
are  made  for  each  other! 

Call  (415)  323-31 1 1  to  reserve  your  space 
in  the  next  Dr.  Dobb’s  Journal. 


Dr.  Dobb’s  Journal,  Number  59,  September  1981 


61 

415 


$2.50 

($3.00  in  Canada) 


R. 


For  Users  of  Small  Computer  Systems 

Number  60  October  1981  Volume  6,  Issue  10 


OBB’S  lOURNAL 


How  to  Run 
Tektronix 
Software 
on  Micros . . . 

. . .  a  Poor 
Man’s  FORTH 
Computer . . . 


TEK4010:  A  Tektronix  Simulator 

Anthony  B.  Skjellum 

BASIC— FORTH 

C.H.  Ting 


and 

Telecom¬ 

munications 

News! 


The  Conference  Tree 

John  S.  James 


Dr.  Dobb  s  Journal 

For  Users  of  Small  Computer  Systems  / 


October  1981  Volume  6,  Issue  10,  Number  60 


CONTENTS 

TEK4010:  A  Tektronix  4010  Simulator 

by  Anthony  Skjellum 

BASIC-FORTH . 

by  C.  H.  Ting 

The  Conference  Tree . 

by  John  S.  James 


8  Letters .  4 

Dr.  Dobb’s  Clinic .  7 

12  Of  Interest . 44 


14 


Cover  Illustration:  Al  McCahon 


Publisher 

Michael  Madaj 

Editor 

Marlin  Ouverson 
Assistant  Editor 
Julie  Anton 
Contributing  Editors 

Dave  Caulkins 
Dave  Cortesi 


Art  Director 

Clifford  West 

Artist 

Barbara  Ruzgerian 
Typesetter 
Renny  Wiggins 
Business  Manager 
Maureen  Christine 


Marketing  Director 
Craig  S.  Harper 
Advertising  Sales 
Kent  Safford 
Circulation  Manager 
Peter  Clark 
Circulation  Assistant 
Leah  Dansby 


Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per 
year  by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real, 
Menlo  Park,  CA  94025.  Second  class  postage  paid  at  Menlo  Park, 
California  94025  and  additional  entry  points.  Address  correction 
requested.  Postmaster:  send  form  3579  to  Box  E,  Menlo  Park, 
California  94025. 


©  1981  by  People’s  Computer  Company  unless  otherwise  noted  on 
specific  articles.  All  rights  reserved. 


DITORIAL 


We  are  pleased  to  present  BASIC-FORTH  in  this 
month’s  menu  of  articles.  For  those  who  were  fascinated  by 
September’s  all- FORTH  issue,  but  do  not  yet  have  the  lan¬ 
guage,  this  is,  in  the  author’s  words,  “a  poor  man’s  FORTH 
machine.”  We  were  tempted  to  call  it  hors  d’forth  because 
it  is  just  enough  to  whet  the  appetite  and  raise  some  inter¬ 
esting  possibilities. 

There  is  much  important  work  to  be  done  in  the  pages 
of  DDJ.  New  machines  are  in  production,  and  more  soft¬ 
ware  is  being  written  than  you  can  shake  a  stick  at.  They 
deserve  the  strong,  objective  reviews  only  this  journal  can 
provide.  And  our  loyal  authors  and  contributors  are  making 
exciting  advances  which  could  fill  three  of  our  magazines! 
We  are  looking  forward  to  publishing  soon  a  mass  of 
groundbreaking  work  in  the  fields  of  telecommunications, 
artificial  intelligence,  small-c,  and  other  crucial  topics 
which  are  begging  for  the  kind  of  coverage  DDJ  readers  like 
to  get  -  and  give. 

In  other  words,  Dr.  Dobb’s  Journal  must  expand  to 
provide  you  with  more  pages  of  solid,  useful  software  and 
systems  tools.  But  we  need  your  help  to  do  this.  Ours  is  a 
small,  friendly  company  that  depends  on  your  subscrip¬ 
tion  to  pay  the  bills.  (We  don’t  have  a  big  corporate  purse 
string  to  pull,  or  to  influence  us,  either.)  Please  take  the 


time  to  look  at  the  categories  of  Donating  Subscribers  here. 
Your  contribution  of  fifty  dollars,  or  one  hundred  or  one 
thousand  dollars  will  go  a  long  way  toward  helping  Dr. 
Dobb’s  finest  to  expand  its  practice. 


Donating  Subscribers 

Contributing  Subscriber:  $50/year  ($25  tax  deducti¬ 
ble).  Retaining  Subscriber:  $75/year  ($50  tax  deduc¬ 
tible).  Sustaining  Subscriber:  $100/year  ($75  tax 
deductible).  Lifetime  Subscriber:  $1000  ($800  tax 
deductible).  Corporate  Subscriber:  $500/  year  ($400 
tax  deductible,  receives  five  one -year  subscriptions). 


DDJ  does  a  lot  of  things  very  well,  but  needs  to  do 
even  more.  We  list  the  names  of  our  Donating  Subscribers 
in  each  issue  because  they  are  as  important  as  the  people 
who  put  this  journal  together.  Won’t  you  join  us? 

Marlin  Ouverson 
Editor 


Subscription  Rates:  $25  per  year  within  the 
United  States ;  $44  for  first  class  to  Canada  and 
Mexico;  $62  for  airmail  to  other  countries. 
Payment  must  be  in  U.S.  dollars,  drawn  on  a 
U.S.  bank. 

Writer’s  Guidelines:  All  items  should  be  typed, 
double-spaced  on  white  paper.  Listings  should 
be  produced  by  the  computer,  using  a  fresh, 
dark  ribbon  on  continuous  white  paper.  Please 
avoid  printing  on  perforations.  Payment  is  in 
contributor’s  copies.  Requests  to  review  galleys 
must  accompany  the  manuscript  when  it  is 
first  submitted.  Authors  may  receive  a  copy  of 


the  complete  writer’s  guidelines  by  sending  a 
self-addressed,  stamped  envelope. 

Contributing  Subscribers:  Eric  H.  Johnson, 
Jerry  Horn,  Edward  W.  Carr,  Steven  Fisher, 
Thomas  H.  Grohne,  G.  V.  Elkins,  Robert  M. 
Connors,  William  J.  McEown,  Robert  C. 
Luckey,  Kim  Leary,  Robert  N.  Stabler,  DeWitt 
S.  Brown,  John  B.  Palmer,  E.  Glion  Curtis,  Jack 
Miller,  Burks  A.  Smith,  Transdata  Corporation, 
Mark  Ketter,  John  W.  Campbell,  Friden  Mail¬ 
ing  Equipment,  Howard  E.  Decker,  Jim  Wilson, 
Frank  Lawyer.  Retaining  Subscribers:  Osamu 
Shimizu,  Scott  B.  Guthery,  Robert  L.  Edens, 


Titus  Purdin.  Sustaining  Subscriber:  Gordon 
Eubanks,  Jr.  Lifetime:  Michael  S.  Zick. 

Foreign  Distributors  UK&  Europe:  LP  En¬ 
terprises,  8/11  Cambridge  House,  Cambridge 
Road,  Barking,  Essex,  1G11  8NT,  England 
(Tel.  01-591-6511,  TLX  892395).  Hofacker- 
Verlag,  Tegernseer  Strass  18,  D-8150  Holz- 
kirchen,  West  Germany,  Asia  &  Australia: 
Computer  Store,  POB  31-261,  22B  Milford 
Road,  Milford,  Auckland  9,  New  Zealand. 
ASCII  Publishing  Co.,  Ltd.,  Aoyama  Building 
5F,  5-16-1  Minami  Aoyama,  Minato-ku, 
Tokyo  107,  Japan. 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

418 


3 


LETTERS 


Bugs  Found  in  Santa  Barbara 

Dear  PCC: 

In  issue  55,  May  ’81  ...  there  is  a 
(untested?)  listing  of  SBTB  for  the  6809 
processor.  There  are  many  bugs  in  the 
code.  Several  of  them  have  been  fixed, 
but  it  requires  reassembly.  Reassembly  is 
no  problem,  since  I  have  thrown  out  the 
macros  and  built  the  keyword  tables.  If 
anyone  would  like  the  current  version 
that  I  have  get  in  touch  with  me.  It  has 
been  modified  somewhat  to  fit  my 
system. 

The  bugs  (were)  are  as  follows: 

*#’  did  not  work  ...  a  patch  here  is  an 

ok  fix. 

patch  $0007  with  $23  (#) 
patch  $0FD  with  $26  (BNE  ONE) 

If  the  program  following  is  used  the 
errors  can  be  found: 

10  FOR  A=  -1  TO  1 
20  FOR  B=  -1  TO  1 
30  PRINT  #1,  A,  <’,  B,  ;  IF  A < B 
PRINT  ‘TRUE’, 

40  PRINT 
50  NEXT 
60  NEXT 

You  will  see  that  -1  cannot  occur 
with  ‘Unary’  the  way  it  is.  Nor  will  *<’ 
test  properly,  the  instruction  at  *<’  is 
BLS  which  is  an  »>  UNSIGNED<<< 
test.  The  possible  condition  codes  at  this 
point  can  be  zero,  minus,  overflow  and 
carry  (borrow). 

‘Unary’  was  fixed  thus: 

UNARY  JSR  <  EXPR 
COMA 
COMB 
ADDB  #1 
ADCA  #2 

JMP  <TVHOW  ;  but  of 
course  this  requires  reassembly.  .  . 

If  the  area  between  $00A0  and 
$00FF  is  empty,  then  at  ‘Unary’  a  JUMP 
or  LBRA  can  be  patched  in.  JUMP  to 
$00A0  and  patch  in: 

00A0  43 

00A1  53 

00A2  C801 

00A4  8900 

00A6  0E38  *  JMP  <TVHOW 

Paul  T.  Barton 
1412  N.  E.  46th  Ave. 

Portland,  OR  97213 


Micro  AI? 

Dear  Sir: 

Re  your  forthcoming  issue  on  artifi¬ 
cial  intelligence,  the  problem  of  explain¬ 


ing  AI  ideas  to  a  general  audience  has 
been  a  primary  interest  of  mine  for  some 
time.  It’s  important. 

Some  caveats,  however.  AI  and  small 
home  computers  are  mostly  incompati¬ 
ble.  AI  requires  a  certain  critical  mass  of 
hardware  and  software  facilities  (at  least 
1000K  main  storage  for  one  thing)  that 
are  likely  to  be  well  beyond  the  home 
system.  Programs  that  seem  clever  can  be 
written  for  small  computers  -  it’s  just 
that  they  can’t  demonstrate  sufficient 
flexibility  to  deserve  the  title  of  “intelli¬ 
gent.” 

However,  there’s  a  certain  creative 
and  educational  value  in  building  “toy” 
systems  that  use  ideas  extracted  from 
more  complicated  AI  systems.  For 
instance,  representing  structures  of  facts 
in  the  computer  and  answering  questions 
about  them,  as  per  my  article  in  Creative 
Computing,  October  1980.  I’ll  think 
about  writing  a  short  article  for  you  on 
this,  more  on  implementational  consider¬ 
ations  than  the  C.  C.  article. 

Another  interesting  area  is  produc¬ 
tion  (or  rule-based)  systems.  Sequential- 
flow  programming  languages  have  so 
biased  the  way  programmers  tend  to  pro¬ 
gram  that  just  seeing  a  few  simple  exam¬ 
ples  of  a  control  structure  in  which  a 
global  ordering  is  not  specified,  yet  it’s 
clear  what  is  going  on  from  strict  con¬ 
straints  on  productions,  might  be  very  ex¬ 
citing  for  your  readers.  Having  been  at 
Stanford,  medical  diagnosis  programs 
spring  immediately  to  mind  (perhaps 
someone  could  write  an  interactive  pro¬ 
gram  for  common  home  ailments),  but 
some  of  the  complex  Adventure-style 
games  also  use  these  production  systems 
ideas,  and  they  might  be  an  easy  way  to 
convey  sophisticated  ideas  to  a  general 
audience. 

Language  understanding  is  another 
possible  area.  Certain  kinds  of  activities 
have  very  limited  vocabulary  and  syntax 
in  their  description,  and  it  might  not  be 
hard  to  write  a  program  to  converse 
about  them.  However,  such  programs  are 
not  AI  unless  they  embody  some  general 
underlying  principles,  and  are  not  just  ad 
hoc. 


Language  production  (to  either  writ¬ 
ing  or  speech)  is  not  really  an  AI  issue, 
since  there’s  a  rather  straightforward  algo¬ 
rithm  to  do  it.  Thus  articles  about  it  are 
probably  not  appropriate  for  your  issue. 
Similarly  with  robots.  Actually  being  able 
to  move  around  in  a  human-like  way  to 
some  extent  is  just  a  gimmick,  and  it  is  al¬ 
most  never  necessary  for  computers  to  be 
able  to  do  intelligent  things.  Thus  with 
the  exception  of  a  few  narrow  kinds  of 
jobs,  AI  researchers  have  been  quite  un¬ 
interested  in  robots. 

Sincerely, 

Neil  C.  Rowe 

787  E.  Illinois 

Lake  Forest,  IL  60045 


Malpractice? 

To  the  Editor: 

I  am  a  longtime  reader  and  find  the 
contents  of  Dr.  Dobb’s  superior  in  quali¬ 
ty.  It  makes  a  bright  spot  in  the  month’s 
mail.  I  wish  to  make  two  comments. 

Issue  fifty  six  (56)  contained 
Jonathan  Mill’s  first  installment  of  the 
Z80  to  8086  Cross  Assembler.  I  would 
enjoy  further  segments  of  this  useful 
series. 

Two  letters  in  issue  fifty  seven  (57) 
concerning  Small-C  bug  fix  included 
statements  concerning  the  availability  of 
the  “improved”  compiler  at  substantial 
cost  (approximately  $60.00).  This  is  an 
objectionable  practice  and  should  not  be 
condoned  by  DDJ.  Mr.  Cain  was  kind 
enough  to  publish  Small-C  for  anyone  to 
use  and  Mr.  Woods  provided  corrections 
and  enhancements.  These  actions  have 
done  substantial  service  to  the  use  of  high 
level  languages  for  systems  programming. 
The  availability  of  the  Compiler  for  user 
modification  encourages  use  and  improve¬ 
ment.  I  do  not  object  to  the  sale  of  an 
improved  version  if  Mr.  Cain  chose  to  al¬ 
low  it.  I  do  object  to  the  practice  of  “Let¬ 
ter  Advertising.”  If  you  plan  on  selling 
a  product  through  DDJ  at  least  pay  the 
minimal  cost  of  buying  space.  Additional¬ 
ly  I  have  not  seen  a  single  article  pub- 


4 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

419 


lished  which  used  the  C- language,  though 
the  algorithm  section  has  been  utilizing  it 
for  some  time.  Could  we  encourage  devel¬ 
opment  of  the  language  through  use? 

I  could  foresee  an  issue  devoted  to 
the  program  developed  with  the  Small-C 
compiler  (hopefully  not  entirely  product 
reviews).  Remember  that  DDJ's  main 
reason  for  existence  is  to  publish  useful 
programs. 

I  would  appreciate  publication  of 
this  letter,  the  editor’s  and  any  reader’s 
response  to  it. 

Sincerely, 

Herb  Calhoun 
414  Norman 
Euless,  TX  76039 

Dear  Herb: 

Thanks  for  bringing  the  subject  up. 
The  gray  line  between  providing  infor¬ 
mation  versus  “ letter  advertising ”  is  a 
topic  which  recurs  frequently  at  our  of¬ 
fices.  Whether  it  is  in  a  letter  or  an  article, 
each  commercial  reference  is  weighed 
carefully  against  the  value  of  the  informa¬ 
tion  which  goes  along  with  it.  We  want 
readers  to  have  the  information;  we  don’t 
want  to  subject  them  to  sales  pitches 
disguised  as  helpful  hints.  If  we  slip  too 
far  out  of  that  gray  area  -  into  the  white 
or  the  black  -  /  know  our  readers  will 
send  along  a  friendly  reminder  like  yours 
to  let  us  know. 

About  development  of  the  Small-C 
language  through  use  .  .  .  yes,  yes!  If 
enough  of  DDJ’s  faithful  authors  produce 
useful  and  de-bugged  programs,  Doc  says 
he  will  even  consider  a  special  issue.  And 
getting  Doc  to  approve  a  theme  issue  on 
just  one  subject  is  like  -  well,  you’d  have 
to  be  there  to  see  it!  -  MDO 

Dear  Mr.  Ouverson: 

Herewith  my  note  for  continuation 
of  J.  Mills’  article  pursuant  to  a  “Cross- 
Assembler  for  the  8080  or  Z80.” 

For  me,  these  types  of  articles  — 
along  with  those  of  Dr.  Dobb’s  Clinic  - 
are  of  the  greater  interest.  Good  substan¬ 
tial  programs  along  with  the  tools  needed 
in  software  creation,  i.e.,  proven  algo¬ 
rithms,  are  a  joy  to  find  -  especially 
when  I  perceive  my  subscription  cost  has 
returned  to  me  something  of  benefit.  I 
may  immediately  use  or  save  for  use  in 
the  future  more  of  your  articles  than 
others. 

In  another  vein:  I’m  not  perturbed 
with  your  policy  of  paid  advertisement.  If 


reviews  can  be  objective  along  with  adver¬ 
tisers’  pressure  then  do  it. 

J.  Sloane 

RD#  1  Box  HF-17 
New  Freedom,  PA  17349 


Stay  Tuned  .  .  . 

Dear  Sir, 

I  read  with  interest  Jonathan  Mills’ 
article  on  his  Z88  Cross- Assember  in 
Volume  6,  Issue  6. 

I  am  a  keen  reader  of  your  magazine 
but  it  is  not  often  that  code  of  the  size 
and  usefulness  of  XASM-86  is  published 
in  the  public  domain.  I  for  one  would 
appreciate  your  publishing  the  entire 
package  in  installments. 

Yours  faithfully, 

W.  Dickson 
1 9  Grove  Road 
Mt.  Albert, 

Auckland, 

NEW  ZEALAND 


I’m  OK,  Heath  OK 

Dear  Mr.  Ouverson: 

I  would  like  to  respond  to  the  letter 
of  complaint  by  Mr.  Hoffman  in  issue  56. 
He  made  the  comment  that  Heath  would 
not  sell  the  hardware  required  to  install  a 
5)4”  disk  drive  in  a  Heath  H17,  and  that 
there  was  no  record  of  the  part  numbers 
needed  for  such  an  installation. 

I  can  only  offer  personal  experiences 
to  refute  his  statements,  but  I  have  dealt 
on  a  routine  basis  with  the  Heathkit  Cen¬ 
ters  in  Seattle,  Kansas  City  and  Alexan¬ 
dria  (Washington,  DC)  and  feel  that  Mr. 
Hoffman  must  have  stumbled  across  an 
uncooperative  salesman  in  his  efforts.  The 
Alexandria  store  stocks  the  required 
brackets  in  large  numbers,  as  this  has 
proved  to  be  a  popular  modification.  For 
his,  and  other  readers’  benefit,  the  re¬ 
quired  parts  are: 


Heath  #  Description 

206-1331  Mu-Metal  Shield 

204-2420  Top  Floppy  Bracket 

204- 2421  Bottom  Floppy  Bracket 

205- 1804  Support  Bracket 

255-47  3/8”  Spacer 


I  have  a  great  many  friends  in  the 
Blacksburg  area  who  own  other  than 
Heath  computers,  and  I  unhesitatingly 


match  Heath’s  customer  support  against 
that  of  any  other  maker.  Some  of  the  tales 
they  could  tell  of  poor  or  non-existent 
support  would  stand  your  hair  on  end. 

Parenthetically,  I  should  add  that 
when  I  spoke  to  the  folks  at  the  Alexan¬ 
dria  store  (and  there  are  few  more  help¬ 
ful,  understanding  computer  dealers 
around)  I  learned  that  Heath  is  reware¬ 
housing  their  parts  activity,  with  a  re¬ 
sulting  slow-up  of  parts  shipments.  I 
was  told  that  this  was  nearly  complete, 
and  that  parts  are  again  flowing.  Case  in 
point:  Heath  now  has  a  very  quiet  muffin 
fan  you  can  use  to  replace  the  older, 
noisy  unit  in  the  H89  and  H17-3.  Made 
in  France,  I  understand.  Must  be  a  moral 
there  somewhere. 

Sincerely, 

D.  C.  Shoemaker 
2000  A.  Foxridge 
Blacksburg,  VA  24060 


Ill-Timed 

Dear  Marlin: 

I  have  noticed  a  small  error  in  Mr. 
Knippenberg’s  program  CAD  for  Time 
Delay  Circuits  (Volume  6,  Issue  5). 
According  to  the  Signetics  integrated  cir¬ 
cuits  handbook,  the  formula  for  calculat¬ 
ing  output  pulse  width  for  the  74123  is: 
Tw  =  0.32  Rt  Cext  (1  +  0.7/Rt) 
Where:  Tw  is  in  nanoseconds 
Rt  is  in  K  ohms 
Cext  is  in  picofarads 
In  line  915  of  his  program,  Mr. 
Knippenberg  has  changed  the  formula 
to  read: 

T=  0.32  *  R  *C  *  (1  +0.7/R) 
Where:  T  is  in  microseconds 
R  is  in  ohms 
C  is  in  microfarads 

The  obvious  error  is  that  he  is  multi¬ 
plying  the  product  of  the  RC  constant 
by  1  plus  ,7/(R *  1 000)  instead  of  1  plus 
,7/R.  This  can  be  corrected  by  changing 
line  9  15  to  read: 

T  =  0.32  *  R  *  C  *  (1  + 

0.7/(R/ 1 000) ) 

Likewise,  line  920  should  be  changed 
to: 

T=  0.31  *  R  *  C  *  (1  + 
0.7/(R/1000)) 

Sincerely, 

Andrew  P.  Beck 
P.  O.  Box  571 
Jackson,  NJ  08527 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 
420 


5 


Any  Takers? 

Dear  DDJ, 

Almost  three  years  ago,  I  submitted 
two  short  pieces  of  code  along  with  a 
challenge  to  your  readers,  and  the  letter 
was  published  in  DDJ  # 29.  The  challenge 
concerned  code  for  saving  and  restoring 
8080  registers.  Since  then,  fourteen  re¬ 
sponses  have  appeared  in  your  Letters  de¬ 
partment  (at  last  count,  which  was  up  to 
and  including  DDJ  #56),  and  an  un¬ 
known  number  of  other  letters  have  been 
sent  in  by  readers  but  not  published.  The 
thread  connecting  all  of  these  letters  has 
obviously  become  tangled  and  confused, 
so  here’s  an  attempt  to  review  and  con¬ 
solidate  everything  that  has  appeared. 

It  all  started  because  an  office  mate 
and  I  began  discussing  the  idiosyncrasies 
of  various  instruction  sets.  I  mentioned 
puzzles  I  had  seen  from  time  to  time  for 
various  computers  that  were  designed  to 
test  a  programmer’s  ability  to  fathom  the 
tricks  and  subtleties  possible  in  machine 
and  assembly  language.  For  example,  how 
can  a  program  for  the  6800  clear  ALL  of 
memory,  including  the  program  itself? 
(Again  see  DDJ  #29,  page  43.) 

In  an  attempt  to  create  a  puzzle  for 
the  8080,  I  thought  for  a  few  minutes 
and  invented  the  problem  of  devising  re¬ 
entrant  subroutines  for  pushing  and  pull¬ 
ing  all  registers,  using  as  few  bytes  of 
code  as  possible.  In  a  little  while,  I  had 
a  proposed  solution  (for  an  admittedly 
poorly  stated  puzzle,  since  I  neglected  to 
mention  all  registers  except  SP  were  sup¬ 
posed  to  be  stacked  and  yet  left  unmodi¬ 
fied,  although  it’s  obvious  my  proposed 
solution  was  trying  hard  to  do  just  that). 
I  typed  it  into  a  system,  assembled  it, 
listed  it,  and  sent  it  to  DDJ. 

The  first  published  response,  from 
William  Moss  in  DDJ  #33,  is  in  fact  NOT 
reentrant  because  of  his  use  of  SHLD  and 
LHLD.  The  next  response,  from  Robert 
Minnihan  in  DDJ  #35,  destroys  HL. 

Charles  Marvin’s  response  appears  on 
the  same  page,  and  he  points  out  both  the 
reentrancy  problem  in  Moss’  code  and  a 
problem  with  the  carry  bit  in  my  original 
solution.  The  DAD  instruction  does  not 
always  “destroy”  (as  in  “complement  the 
previous  state  of’)  the  carry  bit  as  Marvin 
states,  but  it  does  always  either  set  or 
clear  it  (contrary  to  the  claims  made  in 
the  comments  of  my  solution),  so  the 
longer  18-byte  alternate  code  I  proposed 
in  comment  form  in  my  solution  does 
appear  necessary.  But  Marvin  goes  on  to 


give  a  better  16- byte  version  for  the  push 
routine  and  a  byte-saving  6- byte  pull 
routine,  thereby  supplying  the  best 
known  solution. 

Harry  Stewart  then  sent  in  a  6800 
solution  for  a  similar  problem  (DDJ  #37), 
but  I  have  not  inspected  it  closely,  and 
DDJ  #33  contained  three  letters  about 
the  puzzle.  John  Bockelmann  sent  in,  “as 
a  further  example  of  saving  machine 
status,”  non-reentrant  code  written  by 
Alex  Caemerer  that  saves  and  restores  all 
registers  and  the  stack  pointer.  Unfortu¬ 
nately,  there  was  no  reference  to  any  of 
the  previous  letters,  so  many  subsequent 
responses  began  to  address  the  problem 
of  saving  the  state  of  an  8080  without  re¬ 
gard  to  the  intentions  of  the  original  puz¬ 
zle.  On  the  next  page,  Bruce  Smith  has 
a  version  of  Moss’  code  that  is  not  only 
non- reentrant,  but  also  self-modifying. 

The  last  letter  in  DDJ  #38  about  the 
puzzle,  from  D.  C.  Sessions,  “is  hopefully 
the  last  echo  of  the  8080  register  storage/ 
recovery  question,”  but  Sessions’  pro¬ 
posed  solution  is  virtually  identical  to 
Minnihan’s  from  DDJ  #35  (no  doubt 
independently  arrived  at). 

In  DDJ  #40,  we  find  Jon  Bokelman 
(from  California)  responding  to  DDJ 
#38’s  John  Bockelman  (from  New  Jer¬ 
sey)  with  a  one-byte  routine!  Jon  reviews 
the  infamous  DAD  side  effects,  and  then 
goes  on  to  propose  a  completely  new 
save-the-state  problem,  with  the  promise 
of  a  solution.  On  the  next  page,  James 
Monagan  writes  that  Caemerer’s  routine 
falls  victim  to  the  DAD  effect. 

In  DDJ  #41,  Orv  Balcom  (“to  keep 
the  ol’  pusher-popper  controversy  going”) 
and  Chester  Quinn  both  point  out 
Bockelmann/Caemerer’s  DAD  bug,  and 
both  submit  code  to  fix  it.  The  followng 
page  contains  Bokelman’s  promised  solu¬ 
tion  to  his  earlier  stated  puzzle. 

That  brings  us  to  the  last  two  letters 
on  the  subject,  in  DDJ  #44.  First,  L. 
Barker  supplies  a  37-byte  solution  to 
Bokelman’s  problem,  but  the  code  is  not 
straightforward.  It  is  followed  by  a  letter 
from  Jim  Howell,  who,  thinking  that 
Balcom  and  Quinn  were  writing  about 
Bokelman  (they  were  actually  writing 
about  Bockelmann),  points  out  that  they 
use  the  stack  even  though  Bokelman’s 
problem  disallowed  it.  Howell  then  goes 
on  to  carefully  explain  his  21  bytes  of 
code  for  saving  registers.  He  leaves  HL 
and  SP  changed,  but  restoring  them 
should  only  add  four  bytes  to  his  code. 


Howell’s  letter  ends  with  “where  was 
the  original  statement  of  the  problem  and 
what  was  its  motivation?”.  I  think  this 
recap  answers  his  question,  but  I’ll  be 
surprised  if  it  can  be  published  without 
causing  another  response. 

Mike  Gabrielson 
Box  2692 

Stanford,  CA  94305 

Moment  of  Truth 

Gentlebeings: 

This  is  a  belated  reply  to  Ray 
Duncan’s  article  “Using  (and  misusing) 
the  Z-80  Microprocessor,”  in  DDJ  #55. 
There  is  an  enthymene  in  Duncan’s  article 
that  it  is  always  appropriate  to  optimize 
time  in  preference  to  space. 

That  isn’t,  in  my  experience,  univer¬ 
sally  true. 

It  probably  makes  sense  to  be  con¬ 
cerned  with  time  in  a  piece  of  code 
that  gets  executed  a  google  or  so  times, 
but  it  may  make  much  more  sense  to 
optimize  space  in  a  piece  of  code  that 
gets  executed  only  once  or  twice.  Some¬ 
where  in  the  middle  there’s  a  “moment 
of  truth”  where  a  decision  really  does 
have  to  be  made. 

There’s  another  place,  however, 
where  Duncan’s  second  enthymene  - 
that  no  one  uses  interrupts  —  is  probably 
more  serious.  The  use  of  the  EXX  instruc¬ 
tion  is  not  to  be  undertaken  lightly  in  an 
environment  where  some  part  of  the  sys¬ 
tem  is  interrupt-driven,  since  one  of  the 
purposes  of  the  EXX  instruction  is  to 
provide  a  set  of  working  registers  to  a 
process  that  may  go  visit  a  great-aunt  in 
Peoria  if  not  serviced  rapidly.  If  you,  as  a 
programmer,  have  used  the  EXX  instruc¬ 
tion  to  “make  a  hole”  for  a  subroutine, 
you  may  be  in  for  a  most  peculiar  shock 
when  you  get  back  from  the  subroutine 
and  discover  that  the  operating  system 
has  sliced  you  thin  and  warmed  you  over 
—  if  you  notice  anything  at  all.  (1  have 
this  image  of  trying  to  do  a  JP  (HL)  when 
(HL)  was  stuck  in  HL’  during  a  sub¬ 
routine  and  there  was  an  interrupt.  .  .  .) 

Sincerely  yours, 

Peter  Zilahy  Ingerman 
40  Needlepoint  Lane 
Willingboro,  NJ  08046 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

421 


uk.  UUBB’S  CLINIC 


by  D.  E.  Cortesi,  Resident  Intern 

Binary  to  Decimal 

In  the  June  “Clinic”  (DDJ  #56)  we 
presented  FASTDIV10,  an  8080  assem¬ 
bler  routine  to  divide  by  10.  It  was  speci¬ 
fied  thus: 

Input:  HL  =  n,0<n  <32767 

Output:  HL  =  quotient(n/10) 

A  =  remainder(n/10). 

Such  a  routine,  we  supposed,  had  to  be  at 
the  center  of  any  binary-to-decimal  con¬ 
version  routine.  We  moaned  a  bit  about 
how  there  didn’t  seem  to  be  any  faster 
way  to  do  it.  And,  of  course,  readers  re¬ 
sponded  with  a  variety  of  improvements. 
Some  took  on  the  overall  task  of  convert¬ 
ing  a  binary  integer  to  decimal.  Others 
concentrated  on  the  problem  of  dividing 
a  16-bit  number  by  10  or  any  other  small 
integer.  We’ll  examine  the  latter  first. 

One  warning:  only  a  few  of  these 
routines  have  been  tested  by  us,  and  all  of 
them  are  subject  to  typesetting  errors. 
Don’t  use  one  until  you  understand  it 
well  enough  to  verify  it,  or  else  test  it 
thoroughly. 

Shifts  and  Adds 

Shortly  after  our  wish  for  a  divide 
routine  that  used  shifts  and  subtracts 
went  to  the  printer,  a  review  copy  of 
Donald  Knuth’s  Seminumerical  Algo¬ 
rithms  (Addison- Wesley,  2nd  ed.  1981, 
highly  recommended)  came  into  the 
office.  In  it  we  found  Knuth’s  exercise 
4.4.9,  which  revealed  just  what  we’d  been 
asking  for:  division  by  ten  using  shifts 
and  adds.  With  some  labor  we  worked  it 
up  as  Z80  code  (Listing  1,  p.  36). 

No  sooner  had  we  done  that,  than 
Dennis  Allison  wrote,  pointing  out  that 
he’d  described  that  solution  in  a  prior 
article  (“Converting  Binary  to  Decimal,” 
DDJ  #42).  Dennis  presented  the  algo¬ 
rithm  of  Listing  1  in  C  with  a  clear  expla¬ 
nation.  Then  reader  Robert  Martin  of 
Northbrook,  IL  sent  us  a  similar  routine 
in  C.  Charles  Rockwell  of  Guildford,  CT 
knew  of  the  same  idea;  his  explanation 
serves  nicely  to  describe  Listing  1 : 

“Get  an  approximation  for  HL/ 

10  by  doing  an  in-line  multiply 
by  0.1  (=0.1999  hex).  Save  this 
approximation.  Multiply  it  by 
10  and  subtract  from  the  origi¬ 
nal  to  find  a  trial  remainder.  If 
the  remainder  is  10  or  larger  the 
approximation  must  be  correct¬ 
ed  (by  incrementing)  and  the  re¬ 
mainder  must  be  corrected  (by 
subtracting  10).” 


Faster,  Smaller  Division 

Two  readers,  John  Morgan  of  Belling¬ 
ham,  WA  and  L.  Barker,  sent  near¬ 
identical  algorithms  for  doing  an  8-bit- 
into- 16-bit  divide.  Listing  2  is  Barker’s. 
Note  that  it  can  be  adapted  to  any  divisor 
3  .  .  255  by  changing  two  equates. 
DIVISR  is  equated  to  the  divisor. 
UNDR16  is  set  true  if  the  divisor  occu¬ 
pies  four  or  fewer  bits;  Farmer  takes 
advantage  of  that  knowledge  to  “unroll” 
some  unproductive  shifts  from  the  main 
loop. 

Even  Faster,  But  Only  Smaller 

Allan  Ashley  of  Pasadena,  CA  sent 
in  what  is  certainly  the  most  unique  divi¬ 
sion  algorithm  we’ve  seen.  It  can  handle 
only  numbers  less  than  2560,  for  reasons 
that  will  become  clear  as  you  study  the 
code.  It’s  very  quick,  and  could  be  useful 
as  in-line  code  in  certain  special  applica¬ 
tions.  Ashley’s  analysis  runs  thus:  given 
0  <  HL  <  2560, 

256  *(H  L/ 1 0)  =  25*HL  +  (6*HL)/10 

=  25*HL  +  HL/2  +  HL/10 
and  his  code  to  generate  the  latter  expres¬ 
sion  is  an  education  (Listing  3,  p.  36). 

The  code  sent  by  Morgan  and  Barker 
will  perform  division  by  1  0  in  just  under 
700,  Z80  clock  periods,  less  than  75%  of 
the  time  taken  by  FASTDIV10.  The 
shift-and-add  routine  of  Listing  1  takes 
about  725  clocks  and  is  quite  a  bit  larger; 
as  noted  in  the  code  it  could  go  faster  at 
the  cost  of  more  storage.  Ashley’s  routine 
takes  only  226,  8080  clock  periods,  but 
its  input  range  is  limited. 

Bulky  Conversion  to  Decimal 
(BCD) 

Several  readers  undertook  to  convert 
binary  to  decimal  without  the  bother  of  a 


divide  —  the  kind  of  lateral  thinking  we 
should  do  more  of.  The  first  to  respond 
was  Richard  Greenlaw  of  Gahanna,  OH. 
He  says: 

“My  approach  uses  lots  of  code, 
but  as  you  said,  this  function  is 
used  a  lot.  The  general  idea  is  to 
build  the  resulting  ASCII  string 
representing  the  decimal  value 
one  bit  at  a  time,  starting  with 
the  bit  representing  the  most 
value  and  working  down.  By  us¬ 
ing  a  macro  to  generate  the  re¬ 
peating  code  groups  I  was  able 
to  write  a  program  that  ran  cor¬ 
rectly  as  soon  as  I  got  the  com¬ 
mas  into  the  macro  parameters 
correctly.” 

Greenlaw’s  routine  (Listing  4,  p.  37),  al¬ 
though  bulky,  isn’t  much  slower  than 
other  methods.  His  approach  is  original, 
and  there’s  a  good  lesson  in  his  use  of 
macros  to  get  the  routine  up  quickly. 

Decimals,  Always  Adding  (DAA) 

Charles  Rockwell  described  a  good 
method  of  converting  binary  to  decimal, 
given  the  usual  architecture  of  micro 
CPUs: 

“Tabb  and  Roginsky1  suggest  an 
even  faster  binary  to  BCD  rou¬ 
tine.  A  binary  number  can  be 
considered  as: 

(,..(dl5)*2  +  dl4)*2+dl3)...+d0 

and  an  inner  loop  to  convert  bi¬ 
nary  to  BCD  using  the  DAA  in¬ 
struction  looks  like: 


L:  DAD  H  ;  next  digit  to  carry 
ADC  A  ;  A  gets  2A+Carry 
DAA  ;  convert  to  decimal 
JNC  L  ;  loop  if  <99 

A  carry  indicates  that  A  is  larger 
than  99,  so  that  this  loop  can  be 
considered  a  divide  by  100.” 

Wayne  Farmer,  Robert  Lurie,  Martin 
Manay  and  Matt  Asay  all  sent  conversion 
routines  based  on  this  idea.  Farmer’s  was 
the  most  complete;  it  appears  in  Listing 
5,  p.  39.  He  estimates  its  execution  time 
as  less  than  1900  clocks  for  most  input 
values.  A  conversion  routine  based  on  the 
best  of  the  divide  routines  would  con¬ 
sume  about  1000  clocks  for  each  non¬ 
zero  digit  in  the  result. 

In  an  example  of  the  kind  of  syn- 
choronicity  that  plagues  all  periodicals,  a 

(Continued  on  page  43) 

(LISTING  ON  PAGE  36) 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 
422 


7 


TEK4010 

A  Tektronix  4010  Simulator 


Editor’s  note: 

We  liked  Mr.  Skjellum ’s  article  when 
we  first  received  it.  However,  its  length 
and  subject  matter  prompted  us  to  ask 
the  author  about  the  significance  of  the 
piece.  This  is,  in  part,  his  reply: 

hy  do  users  want  to  have  a 
Tektronix  simulator?  First, 
there  is  a  tremendous  base 
of  software  written  to  Tektronix  termi¬ 
nals  on  large  computers.  Some  of  this 
software  (written  in  BASIC,  FORTRAN 
or  perhaps  C)  could  be  directly  on 
small  computers  with  the  appropriate 
graphics  hardware  and  simulator  soft¬ 
ware.  Inexpensive  educational  software 
(e.g.  for  physics  and  chemistry)  is  readi¬ 
ly  available  for  use  on  large  systems, 
and  there  is  no  reason  why  this  software 
could  not  be  downloaded  to  microcom¬ 
puters.  However,  we  are  not  limited  to 
this.  As  configured,  TEK4010  turns  the 
target  system  (i.e.  the  microcomputer) 
into  a  terminal  which  can  communicate 
with  larger  computers. 

“The  above  is  certainly  a  justification 
for  industrial,  scientific  or  educational 
use.  But  I  also  believe  that  personal  com¬ 
puter  users  can  benefit  from  my  program. 
For  example,  home  users  could  run  Tek¬ 
tronix  software  on  a  remote  computer 
with  the  use  of  a  modem.  Software  nets 
(and  CBBS  systems)  could  provide  Tek- 
tronix-compatible  software  for  users  to 
download  as  well.  This  would  allow  home 
users  to  run  quality  software  even  if  they 
just  use  their  systems  as  a  remote  graphics 
terminal. 

“I  also  believe  that  it  would  be  very 
worthwhile  for  graphics  software  devel¬ 
oped  in  the  microcomputer  community 
to  follow  the  Tektronix  graphics  stan¬ 
dard.  This  would  afford  portability  of 
graphics  application  software  written  in 
high  level  languages  and  further  encour¬ 
age  the  use  of  high-density  graphics  on 
micros.  As  of  now,  application  software 
written  for  any  high-density  hardware 
tends  to  be  quite  system  dependent  and  is 
generally  difficult  to  transport  from  sys¬ 
tem  to  system. 

Allow  me  to  summarize.  First,  a 
significant  number  of  machines  support 
high-density  graphics  and  can  run 
TEK40 1 0.  Second,  there  is  a  large  base  of 
Tektronix  software  which  could  be  used 


by  Anthony  Skjellum 

Copyright  ©  1981  by  Anthony  Skjellum. 
All  rights  reserved. 


with  microcomputers  which  could  not  be 
used  without  the  simulator.  Third,  cost- 
effective  systems  which  use  my  software 
could  readily  be  configured  once  the  soft¬ 
ware  is  altered  to  meet  hardware  require¬ 
ments.  This  would  be  useful  in  industry, 
education  and  to  the  hobbyist.  Fourth, 
the  promulgation  of  the  Tektronix  stan¬ 
dard  would  only  help  software  portabili¬ 
ty  in  the  microcomputer  community.” 


This  article  presents  a  program  which 
simulates  a  Tektronix  4010  graphics 
terminal  on  a  Z80  [footnote  1]  micro¬ 
computer  system.  This  simulator  was 
written  to  allow  applications  programs 
written  on  a  VAX-1 1/780  [footnote  2] 
(for  use  with  a  standard  4010  terminal) 
to  run  unmodified  with  the  Z80  compu¬ 
ter  system  acting  as  the  graphics  terminal. 

While  software  of  this  type  is  usually 
system  dependent,  this  implementation  is 
likely  to  be  useful  to  others  planning  to 
write  Tektronix  simulators  for  their  own 
hardware  configuration.  Even  though  the 
software  depends  on  the  setup  of  the 
development  system,  it  could  well  be 
modified  for  other  graphics  environ¬ 
ments.  The  code  was  designed  for  use  in 
a  read-only  memory  and  is  therefore 
ROMable. 

Included  in  this  article  is  information 
about  the  use  of  the  system  including  a 
discussion  of  its  capabilities.  A  section  is 
devoted  to  the  explanation  of  the  exter¬ 
nal  subroutine  package  used  by  this  pro¬ 
gram.  The  development  machine  is  out¬ 
lined  and  motivations  behind  this  imple¬ 
mentation  are  discussed. 

Introduction 

The  predecessor  of  this  program, 
TEK4006,  was  written  by  Mark  Bartelt  at 
the  California  Institute  of  Technology  for 
use  in  conjunction  with  the  Z80  micro¬ 
computer  systems  developed  by  Profes¬ 
sors  Dr.  R.  Gomez  and  Dr.  J.  Pine  (for 
whom  TEK4010  was  written)  of  the  Phy¬ 
sics  Department.  TEK4010  is  a  major 
revision  of  TEK4006  and  includes  the  ad¬ 
ditional  cross-hair  cursor  capability  and 
associated  features.  The  cross-hair  cursor 
does  not  require  analog  inputs  to  the  Z80 
system  since  it  uses  control  characters  to 
move  the  cursor. 

Motivations 

A  set  of  working  physics  programs 
was  obtained  and  modified  for  use  on 
Caltech’s  Computer  Center  Timesharing 
VAX-11/780.  However,  there  are  only 


two  Tektronix  4010  terminals  on  which 
the  programs  could  be  run.  This  presen¬ 
ted  a  problem  since  the  ultimate  goal  is 
to  have  wide  usage  of  this  and  other  in¬ 
structional  software.  Fortunately,  seven 
microcomputer  setups  are  available  in  the 
physics  department  for  use  in  the  sopho¬ 
more  physics  laboratory  and  lecture  hall. 
This  software  was  created  to  allow  the 
use  of  these  computers  with  the  instruc¬ 
tional  software. 

Operation 

TEK4010  handles  all  communication 
with  the  remote  computer.  Via  a  buf¬ 
fered,  interrupt-driven  input  scheme,  data 
is  accepted  from  the  remote  line.  The 
program  recognizes  Tektronix  graphics 
commands  and  escape  sequences  and  key¬ 
board  input  is  routed  to  the  remote  com¬ 
puter.  It  is  well  to  note  that  TEK4010 
does  not  support  the  Tektronix  margin  1 
(starting  at  column  40).  Instead,  scrolling 
is  supported  since  this  was  considered 
more  useful. 

When  an  ESC  SUB  (1BH  1  AH)  is 
sent  by  the  remote  computer,  a  Tektron¬ 
ix  4010  terminal  enters  the  graphic  input 
mode  where  a  cross-hair  cursor  is  used  to 
return  a  value  to  the  computer  on-line. 
Normally,  the  user  positions  the  cursor 
with  “thumbwheels”  (potentiometers)  on 
the  terminal  and  then  presses  one  of  sev¬ 
eral  keys.  Depressing  any  key  causes  a 
multi-byte  cursor  code  to  be  transmitted 
by  the  terminal  (see  Table  I).  This  se¬ 
quence  always  includes  the  current  cursor 
address  and  input  character  and  may  in¬ 
clude  a  postamble  depending  on  how  a 
stappable  option  is  set  for  the  terminal. 
Most  applications  programs  which  use 
this  feature  only  require  the  use  of  a  few 
characters  to  return  the  cursor  address. 
It  was  felt  that  little  generality  would  be 
lost  if  certain  codes  were  intercepted  and 
used  as  command  indicators  by  TEK- 
4010.  The  “/”  key  is  the  only  non¬ 
control  character  used  as  a  command  and 
this  can  be  changed  if  necessary.  Also, 
note  that  A  C  and  A  Y  are  transmitted 
without  the  cursor  address  by  TEK4010. 
This  permits  the  user  to  terminate  the 
program  without  getting  spurious  plotting 
on  the  display  (at  least  for  the  VAX/ 
VMS  operating  system). 

The  cross-hair  cursor  is  displayed  as  a 
large  plus  sign  by  TEK4010.  It  is  moved 
around  by  depressing  a  set  of  control 
keys  at  the  keyboard.  (See  Table  II.)  For 
example,  typing  a  A  D  moves  the  cursor 
down  XOFF  points  where  XOFF  is  the 


8 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

423 


Table  I 

Multi-byte  Cursor  Code 

bvte  1 : 

char  input 

byte  2: 

thigh  order  of  X..-- 

byte  3: 

<low  order  of  X> 

(two  five  bit  coordinates i 

byte  4: 

thigh  order  of  Y';- 

byte  5: 

flow  order  of  t 

{o&tional : 

three  cases  1)  none,  2)  CR,  3)  C 

(,  EOT  > 

byte  6: 

none !  CR 

byte  7: 

none IE01 

D: 

Table  II 

Cursor  Controls  in  Cross-hair  Mode 

Cursor  down  Cxoffll  points. 

L: 

Cursor  left 

Cxoffll  points. 

R: 

Cursor  right 

Cxoff]  points. 

U: 

Cursor  up 

Cxoff]  points. 

H: 

Hone  cursor. 

Table  III 

Other  Cross-hair  Functions 

Address  cursor  to  <x>,  'y>.  Enter  A  followed  by  two 
three  digit  decinal  lumbers  separated  by  any  delimiter. 
Leading  zeroes  required. 

B  oft  set  : 

Set  Cxoff 1  to  input  value.  Enter  one  three-digit  number 
with  leading  zeroes  as  required. 

C: 

Sent  as  is. 

LF: 

Move  cursor  near  start  of  current  line. 

"N: 

Toggle  display  of  current  cursor  location.  Display  is 
m  lower  left  of  screen. 

Y : 

Sent  as  is. 

Z: 

Reset  Cxoff 1  to  the  default  value  of  fifty. 

/  digit): 

Enter  a  digit  0 ! 1 . . . ;  ? .  0  represents  a  division 

bv  ten.  Cxoff]  will  not  net  smaller  than  one. 

current  step  size.  The  default  size  for 
XOFF  is  the  current  step  size.  The  de¬ 
fault  size  for  XOFF  is  fifty  and  its  value 
(  A  B)  or  by  division  with  the  ‘/’  operator. 
Division  is  by  a  single  digit  0-9  where  0 
denotes  a  division  by  10.  The  AZ  com¬ 
mand  resets  XOFF  to  its  default  value. 
The  cursor  may  also  be  addressed  abso¬ 
lutely  via  decimal  input  (A  A)  and  a  dyna¬ 
mic  display  of  the  cursor  coordinates  may 
also  be  selected  ( A  N).  The  LF  function 
moves  the  cursor  near  the  beginning  of 
the  current  line.  This  is  useful  for  moving 
to  menus  located  on  the  left  side  of  the 
display.  Functions  such  as  AN,  A  A  and 
LF  were  added  for  the  benefit  of  lec¬ 
turers  who  would  prepare  demonstra¬ 
tions  with  the  simulator.  See  Table  III 
for  a  description  of  these  commands. 

Since  TEK4010  has  occasion  to  do 
its  own  output,  a  rarely  used  portion  of 
the  screen  was  selected.  This  is  the  lower 
left  corner.  Commands  like  AV  (scaling) 
and  A  N  (display  address  toggle)  use  this 
region.  Again,  this  was  possible  since  the 
software  we  use  does  not  display  any¬ 
thing  on  this  part  of  the  screen. 

Several  other  commands  are  availa¬ 
ble.  AE  dumps  the  contents  of  the  dis¬ 
play  to  the  Axiom  820  microplotter- 
printer.  A  S  does  a  temporary  transmis¬ 
sion  halt  and  A  Q  resumes  transmission 
while  A  F  provides  a  local  screen  clear. 

The  current  hardware  provides  graph¬ 
ics  resolution  which  is  5/8  of  the  standard 
Tektronix  terminal  (resolution  is  640x 
480;  a  4010  has  768  vertical  points  for 
plotting  and  it  seems  possible  to  write 
additional  text  above  this).  Some  of  our 
applications  programs  do  use  more  than 
768  vertical  dots  (actual  Tek  coordinate). 
Therefore,  both  Vi  and  5/8  vertical  scaling 
is  provided.  This  feature  is  operator  selec¬ 
table  but  scaling  is  always  5/8  in  the  X- 
direction.  This  feature  is  selected  with 
AV  .  (See  Table  IV.) 

Hardware 

As  configured,  the  computer  systems 
provide  64K  of  user,  random-access 
memory.  It  provides  display  resolutions 
of  320x240  and  640x480  as  noted  above. 
640x480  is  the  high  density  mode  which 
consumes  about  two-thirds  of  the  ran¬ 
dom-access  memory.  This  is  no  problem 
since  the  Z80  is  used  only  as  a  terminal 
in  this  mode. 

A  lower-density  mode  is  also  sup¬ 
ported  by  the  system  (320x240)  and 
this  is  the  standard  display  state.  This 
resolution  is  adequate  for  most  programs 


Table  IV 
Other  Functions 

E:  Dump  screen  to  printer  (it  selected  at  assembly-tine) 

F:  Local  dear-screen. 

0 :  Resume  Iransfussion. 

S:  Halt  transdission. 

V:  Set  vertical  scaling.  Valid  entries  are  H  (half)  and 

F  (full). 


Table  V 

Switch-Selectable  Options 

The 

following  options  are  -witch  selected  before  e 

'.edition  of  IEK4010: 

black -on-wifite/white- on-blacl- 

1  o  w  -  r  e  s  o  1  u  t  :i  o  n  /  h  i  g  h  -  r  e  so  1 1 1 1 1  o  n 

3. 

big  characters'  'standard  charac  tens 

running  directly  on  the  Z80  system.  Con¬ 
sequently,  TEK4010  is  presently  the  only 
program  on  the  system  which  utilizes 
the  high-density  mode  graphics.  The  cur¬ 
rent  system  uses  6K  of  read-only  memo¬ 
ry.  TEK4010  resides  in  a  2K  PROM  at 
E800H  and  the  monitor  and  graphics 
drivers  reside  in  two  2K  PROMs  starting 
at  0F00H.  Conveniently,  the  PROMs  may 
be  switched  out  to  allow  new  versions 
of  TEK4010  and  the  system  software  to 
be  tested  in  RAM  before  they  are  com¬ 
mitted  to  read-only  memory. 

Runtime  Options 

TEK4010  has  certain  initial  condi¬ 
tions  which  are  set  by  a  six-bit  dip- 
switch  input.  These  functions  are  de¬ 
scribed  in  Table  V.  Systems  which  do 
not  have  a  dip-switch  input  port  could 
read  the  parameters  off  a  command  line 
to  get  the  proper  options.  Of  course, 
options  available  will  also  be  a  function 
of  the  graphics  hardware. 

Also,  the  system  will  run  in  the  low- 
density  mode  (240x320)  but  the  cross¬ 
hair  cursor  capabilities  will  not  scale 
themselves  properly.  There  is  no  inten¬ 
tion  to  use  low-density  Tektronix  mode 
for  the  present  application,  so  providing 
the  option  of  low-density,  cross-hair  ad¬ 
dressing  was  considered  unnecessary. 

The  system  software  also  does  soft¬ 
ware  character  generation. This  makes  it 
possible  to  have  more  than  one  charac¬ 
ter  size.  A  switchable  option  is  available 
to  choose  between  standard  and  big  char¬ 
acters.  However,  this  option  cannot  be 
used  when  using  the  simulator  with  stan¬ 
dard  software  as  we  do. 

Interfacing 

The  development  system  provides  a 
series  of  graphics  routines  which  serve 
as  the  primitive  functions  for  all  graphics- 
bound  programs  written  for  these  sys¬ 
tems.  Several  routines  are  used  by  TEK- 
4010  in  order  to  emulate  the  4010 
terminal.  For  example,  GDRAW  draws  a 
line  between  two  points.  Other  functions 
manipulate  point  graphics.  These  func¬ 
tions  will  have  to  be  developed  for  your 
specific  hardware  environment.  Table 
VI  (page  16)  lists  the  requirements  of  the 
actual  external  routines  as  well  as  their 
functions  and  attributes  (i.e.  how  they 
affect  registers,  etc.).  The  routines  RE¬ 
SCALE,  HSCALE,  COORDS  and 
HOORDS  inside  TEK4010  will  also  have 
to  be  changed  to  reflect  the  resolution 
of  the  graphics  hardware  available. 


In  implementing  this  software  for 
other  systems,  I  recommend  that  a  com¬ 
prehensive  package  be  developed  which 
allows  TEK4010  to  remain  relatively  un¬ 
changed.  Certain  routines  that  write  di¬ 
rectly  into  the  display  memory  (e.g. 
BLOCK)  will  still  have  to  be  altered. 
However,  the  overall  task  will  be  simpler 
if  routines  are  added  which  align  the  con¬ 
ventions  of  TEK4010  to  your  system. 
While  this  will  be  slightly  less  efficient,  it 
will  save  a  major  programming  task  and 
still  result  in  useful  graphics  software. 

Assembly-time  Options 

On  a  Tektronix  terminal,  there  are 
three  possible  straps  for  selecting  the 
postamble  for  graphic  input  mode  in¬ 
formation.  They  are  :  no  postamble,  CR, 
or  CR  and  EOT.  Three  conditional- 
assembly  options  permit  TEK4010  to 
provide  these  three  conditions  as  well 
(see  Table  I). 

Another  assembly-time  option  is  the 
printer  dump  command  (A  E).  Most  of 
the  Z80  systems  we  use  have  Axiom  820 
microplotters  for  displaying  graphics  (see 
illustration).  This  software  will  need  al¬ 
teration  for  whatever  graphics  output  de¬ 
vice  may  be  available  on  your  system.  If 
none  is  available,  the  command  should  be 
disabled  by  conditional  assembly  (as  in 


Listing  I). 

Conclusion 

The  complete  TEK4010  package  is 
included  in  Listing  I  (page  18).  Listing  II 
(page  32)  contains  SUPPORT.  LIB  which  is 
a  macro/equate  library  used  by  the  simu¬ 
lator  and  the  symbol  table  is  presented 
in  Listing  III  (page  35). 

This  package  provides  a  cost-effective 
way  to  run  Tektronix -compatible  soft¬ 
ware  on  hardware  which  already  exists  in 
the  Physics  department  at  Caltech.  Dedi¬ 
cated  systems  using  TEK4010  could 
provide  relatively  inexpensive  graphics 
terminals  for  all  sorts  of  applications.  »»j 

Note 

This  software  is  provided  for  non-com¬ 
mercial  use  only.  Any  commercial  use,  without 
the  author’s  written  permission,  is  prohibited. 

Reference 

1.  Tektronix  4010  -  4010-1  Users’  Manual. 
Footnotes 

1 Z80  is  a  trademark  of  Zilog. 

2 

VAX  is  a  trademark  of  Digital  Equipment 
Corporation  (DEC). 

3VAX/VMS  is  a  trademark  of  DEC. 


10 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

425 


This  output  was  produced  by  the  program  BWIRES.BAS  by 
R.  M.  Grant  and  S.  C.  Wheeler,  Dept,  of  Physics,  Denison 
University,  Granville,  OH  43023.  The  program  runs  under 
PDP-11  BASIC  +  2  on  the  VAX-11/780, 
nb:  PDP,  VAX,  BASIC  +  2  are  trademarks  of  DEC. 


Influence  the  Future!  Join  (omputerTown 

The  future  in  microcomputer  technology  is  very  exciting.  The  potential  is  enormous.  We  want  to  ensure  that  everyone  has  an  opportunity 
to  learn  about  the  options  and  share  in  the  benefits  that  personal  computing  offers.  Please  join  us  in  a  partnership  to  make  this  possible. 


WHAT  IS  COMPUTERTOWN*? 

A  ComputerTown  is  a  place  where  people  of  all  ages  have  access  to  com¬ 
puters.  Its  goal  is  to  offer  everyone  an  opportunity  to  become  “com¬ 
puter  literate”  in  an  informal  educational  setting.  The  present  organi¬ 
zation  serves  as  a  link  between  more  than  120  ComputerTown  sites 
worldwide  and  as  an  information  network  between  people  with  an  in¬ 
terest  in  the  growth  of  computer  literacy  on  an  international  scale. 

DDJ  READERS  MAKE  A  DIFFERENCE! 

Always  on  the  cutting  edge,  DDJ  readers  have  the  knowledge  and 
influence  to  blaze  a  trail  for  computer  literacy.  Share  your  expertise 
or  spread  the  word  to  your  associates.  As  a  member  you  become  part 
of  our  internationally  distributed  resource  list. 

ComputerTown  is  entering  a  new  stage  of  development,  gearing  up, 
not  only  for  increased  membership,  but  for  increased  products  and 
services  you  can  take  part  in.  The  first  books  in  the  ComputerTown 
series  will  be  available  this  winter  and  spring.  In  addition,  work  has 
already  begun  on  a  series  of  informative  booklets  covering  a  wide 
range  of  topics  such  as  selecting  hardware  and  software,  exemplary 
educational  software,  exemplary  educational  software  by  age  group, 
staff  training,  funding  information,  micros  in  special  education 
and  more.  We  are  also  developing  courseware,  tutorials,  and  teaching 
materials  for  a  variety  of  computer  literacy  classes. 


MEMBERSHIP  BENEFITS 

Alt  members  receive: 

•  ComputerTown  News  Bulletin.  As  a  member,  you  get  a  free  sub¬ 
scription  to  this  newsletter  which  covers  the  growth  of  computer 
use  in  schools,  libraries  and  homes  around  the  country. 

•  ComputerTown  Publication  Discounts.  Members  get  a  special  price 
on  all  ComputerTown  publications  including:  ComputerTown 
Book  Series,  Special  Report  Booklets,  Bulletin  Back  Issues  and 
Bound  Volumes.  In  the  future  we  will  offer  discounts  on  various 
computer  magazine  subscriptions  and  courseware  materials. 

•  Seminar  Discounts.  You  are  entitled  to  discounts  on  selected 
ComputerTown-sponsored  conferences  and  seminars  in  several 
cities. 

•  Support  Services.  Our  staff  provides  services  such  as  resource 
referral  and  site- development  troubleshooting  (depending  on 
membership  category).  These  services  are  designed  to  adapt  to 
your  needs. 

•  Membership  Certificate.  This  certificate  displays  your  affiliation 
with  a  worldwide  network  promoting  computer  literacy. 

Leader,  Group  and  Commercial  Memberships  receive: 

•  Free  Implementation  Package.  This  manuscript  details  over  two 
years  of  research  and  development  on  public  microcomputer 
access  and  serves  as  a  guide  to  developing  your  own  computer 
literacy  activities. 


For  more  information,  circle  reader  service  no.  46,  or  write:  Fritzi  Lareau,  Membership  Services. 

•A  Project  of  People’s  Computer  Company  1 263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  California  94025  (415)  323-3111 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

426 


1  1 


BASIC-FORTH 

A  poor  man’s  FORTH  computer, 
and  an  invitation  to  FORTH  language 


My  favorite  definition  of  the 
FORTH  language  is  “a  program¬ 
ming  language  by  which  a  pro¬ 
grammer  creates  a  set  of  instructions  as 
the  solution  of  his  programming  prob¬ 
lem.”  The  fact  that  FORTH  allows  and 
encourages  the  programmer  to  extend 
and  modify  its  instruction  set  makes  this 
language  unique  and  exciting,  and  con¬ 
sequently  attracts  a  host  of  religiously  de¬ 
voted  followers.  However,  there  are  still 
two  factors  impeding  FORTH’s  even 
wider  growth  and  dissemination;  the 
peculiar  syntax  using  postfix  (reverse 
Polish)  notation,  and  the  expense  of  a 
computer  which  can  host  a  FORTH 
operating  system  (above  $2000).  Such  a 
computer  must  have  at  least  one  diskette 
drive  for  bootstrapping  and  program  stor¬ 
age. 

There  are  more  than  300,000  small 
BASIC  computers  in  this  country  with 
about  8K  bytes  of  RAM  memory  and  cas¬ 
sette  recorder  as  the  only  means  for  pro¬ 
gram  and  data  storage.  Obviously,  a 
FORTH  system  written  entirely  in  the 
BASIC  language  would  have  definite  ap¬ 
peal  to  owners  of  these  BASIC  comput¬ 
ers.  BASIC-FORTH  is  designed  for  these 
computers  with  minimum  resources.  It 
fully  utilizes  the  facilities  already  resident 
in  the  BASIC  operating  system  to  convert 
the  BASIC  computer  into  a  dictionary- 
based  FORTH  stack  computer.  BASIC- 
FORTH’s  vocabulary  includes  12  regular 
FORTH  stack  instructions,  and  17  BASIC 
functions  converted  into  FORTH  instruc¬ 
tions.  In  addition,  the  control  structure 
instructions  such  as  IF,  ELSE,  THEN, 
BEGIN,  UNTIL,  DO,  and  LOOP  are  also 
included.  These  instructions  and  their 
stack  effects  are  listed  in  Table  1. 

The  bulkiest  part  of  this  program  is 
the  NUCLEUS  which  contains  the  DIC¬ 
TIONARY,  a  linked  list  of  primitive 
FORTH  instructions  coded  in  BASIC 
(lines  900  to  1522).  At  the  end  of  the 
dictionary  is  the  number  conversion  rou¬ 
tine  (lines  1600  to  1608).  The  operating 
system  of  this  FORTH  system  is  the 
TEXT  INTERPRETER  (lines  30  to  138), 
which  parses  lines  of  input  as  instruc¬ 
tions,  and  executes  the  instructions  in 
sequence  by  first  searching  the  diction- 


by  C.H.  Ting 


C.  H.  Ting,  c/o  NDT  Technology  Labora¬ 
tory,  P.  O.  Box  504,  Sunnyvale,  CA 
94086. 


ary.  An  instruction  found  in  the  dic¬ 
tionary  is  immediately  executed.  If  the 
instruction  cannot  be  located  in  the  dic¬ 
tionary,  an  attempt  is  made  to  convert  it 
into  a  number  and  the  resulting  number  is 


pushed  onto  the  data  stack  S.  If  the  in¬ 
struction  is  neither  a  member  of  the  dic¬ 
tionary  nor  a  number,  an  error  condition 
is  generated,  forcing  the  execution  of  line 
29.  This  action  aborts  the  current  line  of 


Table  1 

BASIC-FORTH  Instructions 

Stack  Instructions 

R? 

Type  out  all  stack  data. 

(n  — ) 

Type  out  the  top  number  on  stack  and 
remove  it. 

DUP 

(n  — n  n) 

Duplicate  top  of  stack. 

DROP 

(n— ) 

Discard  top  of  stack. 

SWAP 

(nl  n2— n2  nl) 

Exchange  top  two  stack  items. 

OVER 

(nl  n2— nl  n2  nl) 

Make  copy  of  second  item  on  top. 

ROT 

(nl  n2  n3— n2  n3  nl) 

Rotate  third  item  to  top. 

PICK 

(nl  --n2) 

Copy  nlth  item  to  top.  1  PICK  =  DUP, 

2  PICK=OVER. 

ROLL 

(n~) 

Rotate  nth  item  to  top.  2  ROLL=SWAP 

R@ 

(-n) 

Copy  top  of  return  stack  to  data  stack. 

>  R 

(n-) 

Move  top  item  to  return  stack. 

R  > 

(-n) 

Retrieve  item  from  return  stack. 

Arithmetic,  Logical,  and  Functional  Instructions 

* 

(nl  n2— prod) 

Multiply. 

/ 

(nl  n2— quot) 

Divide. 

+ 

(nl  n2— sum) 

Add. 

- 

(nl  n2— diff) 

Subtract. 

ABS 

(n  —  1  n  | ) 

Absolute  value  of  n. 

ATN 

(n— arctan  n) 

Arctangent  of  n. 

COS 

(n— cos  n) 

Cosine  of  n. 

EXP 

(n— exp  n) 

e  to  the  nth  power. 

INT 

(n— integer  n) 

Integer  part  of  n. 

LOG 

(n--ln  n) 

Natural  logarithm  of  n. 

RND 

(-n) 

Leave  a  random  number  between  0  and  1. 

SGN 

(n-sign) 

Leave  1 , 0,  or  -1  depending  on  sign  of  n. 

SIN 

(n--sin  n) 

Sine  of  n. 

SQR 

(n— v/n) 

Square  root  of  n. 

TAN 

(n— tan  n) 

Tangent  of  n. 

t 

(nl  n2— n3) 

Exponentiation. 

= 

(nl  n2— n3) 

True  if  nl  is  equal  to  n2. 

> 

(nl  n2— n3) 

True  if  nl  is  greater  than  n2. 

< 

(nl  n2— n3) 

True  if  nl  is  less  than  n2. 

Control  Instructions 

IF 

(n-) 

If  n  is  true,  continue  execution.  Otherwise, 
skip  to  ELSE  or  THEN. 

ELSE 

Skip  to  THEN. 

THEN 

Continue  execution. 

BEGIN 

Save  instruction  pointer  on  return  stack. 

UNTIL 

(n~) 

Branch  to  BEGIN  if  n  is  false;  otherwise 
continue. 

DO 

(nl  n2— ) 

Save  instruction  pointer,  loop  limit  nl,  and 
loop  counter  n2  on  return  stack. 

LOOP 

Increment  loop  counter,  if  equal  or  greater 
than  loop  limit,  branch  back  to  DO.  Other¬ 
wise,  discard  three  items  on  return  stack  and 
continue. 

12 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

427 


For  Your  Personal 


REFERENCE 

COLLECTION 


Thousands  of  dollars’  worth  of 
microcomputer  information  and  listings! 


Dr.  Dobb’s  Journal  Vol.  V  -  All  the  ground-breaking  issues  from  1980  in  one  volume!  Sys¬ 
tems  software  reached  a  new  level  with  the  advent  of  CP/M,  chronicled  herein  by  Gary  Kildall  and  others 
(DDJ's  all-CP/M  issue  sold  out  within  weeks  of  publication).  Software  portability  became  a  topic  of  great¬ 
er  import,  and  DDJ  published  Ron  Cain’s  immediately  famous  Small-C  compiler  —  reprinted  here  in  full! 

Contents  include:  The  Evolution  of  CP/M,  a  CP/M-Flavored  C  Interpreter,  Ron  Cain’s  C  Compiler  for  the 
8080,  Further  with  Tiny  BASIC,  a  Syntax- Oriented  Compiler  Writing  Language,  CP/M  to  UCSD  Pascal 
File  Conversion,  Runtime  Library  for  the  Small-C  Compiler,  and,  as  always,  even  more ! 


instructions,  prints  out  the  offending  in¬ 
struction,  and  restarts  the  text  interpreter 
from  line  30. 

It  is  difficult  to  implement  the  colon 
definitions  or  other  high-level  FORTH 
instructions,  because  the  text  interpreter 
cannot  easily  extend  the  dictionary.  Be¬ 
tween  lines  300  and  900,  some  simulated 
high-level  FORTH  instructions  are  coded 
as  examples.  The  equivalent  FORTH  in¬ 
structions  are: 

:  SQUARE  DUP  *  ; 

: CUBE  DUP  SQUARE  *  ; 

The  content  of  a  colon  instruction,  that 
is,  the  names  of  other  predefined  instruc¬ 
tions  in  the  dictionary,  is  implemented  as 
a  string  B$,  which  is  concatenated  to  the 
calling  string  1$  currently  under  interpre¬ 
tation.  The  nesting  level  pointer  K  is  in¬ 
cremented  to  save  the  current  interpre¬ 
tative  pointer  L(K)  in  the  calling  string. 
L(K)  will  be  the  point  of  return  when  the 
called  instruction  is  completely  executed. 
Since  L(n)  is  defined  as  an  array  of  di¬ 
mension  10,  this  program  allows  ten 
levels  of  nesting  within  high-level 
FORTH  instructions.  The  depth  of  nest¬ 
ing  can  be  increased  by  re-dimensioning 
L  and  L0. 

The  data  stack  S(n)  can  hold  40 
numbers,  and  the  return  stack  R(n)  can 
hold  20  numbers.  The  dimensions  of 
these  stacks  can  also  be  modified.  The 
return  stack  is  used  only  by  the  following 
instructions:  >R,  R>,  R@,  BEGIN, 

UNTIL,  DO,  and  LOOP.  The  loop  in¬ 
structions  use  the  return  stack  to  hold 
pointers  for  backward  branchings.  The 
functions  served  by  the  return  stack  in 
these  loop  instructions  are  different  from 
that  of  regular  FORTH.  The  user  must 
exercise  caution  in  using  the  return  stack. 

All  instructions  are  interpreted  and 
immediately  executed  without  exception. 
The  IF-ELSE-THEN  construct  is  of  some 
interest  in  its  implementation.  IF  exam¬ 
ines  the  top  of  the  data  stack.  If  the  num¬ 
ber  is  true,  execution  continues  to  ELSE. 
ELSE  skips  all  instructions  up  to  THEN, 
and  continues  execution  after  THEN.  If 
the  number  is  false,  IF  continues  execu¬ 
tion  after  the  next  ELSE  or  THEN  - 
whichever  is  encountered  first.  With  this 
scheme,  unlike  regular  FORTH,  IF-ELSE- 
THEN  structures  cannot  be  nested  into 
each  other.  However,  IF-ELSE-THEN 
structures  can  be  nested  into  other  loop 
structures. 

(Continued  on  page  43) 

(LISTING  ON  PAGE  40) 


Dr.  Dobb's  Journal  Vol.  I  -  The  material  brought  to¬ 
gether  in  this  volume  chronicles  the  development  in  1976 
of  Tiny  BASIC  as  an  alternative  to  the  “finger  blistering” 
front-panel  machine -language  programming  which  was 
then  the  only  way  to  do  things.  This  is  always  pertinent 
for  bit  crunching  and  byte  saving,  language  design  theory, 
homebrew  computer  construction  and  the  technical 
history  of  personal  computing. 

Topics  include  Tiny  BASIC,  the  (very)  first  word  on 
CP/M,  Speech  Synthesis,  Floating  Point  Routines,  Timer 
Routines,  Building  an  IMSAI,  and  more. 


Dr.  Dobb's  Journal  Vol.  Ill  The  microcomputer  in¬ 
dustry  entered  its  adolescence  in  1978.  This  volume  brings 
together  the  issues  which  began  dealing  with  the  6502,  with 
mass- market  machines  and  languages  to  match.  The  authors 
began  speak  mg  more  in  terms  of  technique,  rather  than  of 
specific  implementations,  because  of  this  they  were  able 
to  continue  laying  the  groundwork  industry  would  follow. 
These  articles  relate  very  closely  to  what  is  generally 
available  today. 

Languages  covered  in  depth  were  SAM76.  Pilot.  Pascal  and 
Lisp,  in  addition  to  RAM  Testers,  S-100  Bus  Standard 
Proposal,  Disassemblers,  Editors  and  much,  much  more. 


Dr.  Dobb's  Journal  Vol.  II  -  1977  found  DDJ  still 
on  the  forefront.  These  issues  offer  refinements  of  Tiny 
BASIC,  plus  then  state-of-the-art  utilities,  the  advent  of 
PILOT  for  microcomputers  and  a  great  deal  of  matenal 
centering  around  the  Intel  8080,  including  a  complete 
operating  system.  Products  just  becoming  available  for 
reviews  were  the  H-8,  KIM-1,  MITS  BASIC,  Poly  Basic 
and  NIBL. 

Articles  about  Lawrence  Livermore  Lab’s  BASIC,  Alpha- 
Micro.  String  Handling,  Cyphers.  High  Speed  Interaction, 
I/O.  Tiny  Pilot  &  Turtle  Graphics,  many  utilities,  and 
even  more. 


Dr.  Dobb's  Journal  Vol.  IV  -  This  volume  heralds  a 
wider  interest  in  telecommunications,  in  algorithms,  and  in 
faster,  more  powerful  utilities  and  languages.  Innovation  is 
still  present  in  every  page,  and  more  attention  is  paid  to  the 
best  ways  to  use  processors  which  have  proven  longevity  - 
primarily  the  8080/ Z80,  6502,  and  6800.  The  subject 
matter  is  invaluable  both  as  a  learning  tool  and  as  a  fre¬ 
quent  source  of  reference. 

Mam  subjects  include  Programming  Problems/ Solutions, 
Pascal,  Information  Network  Proposal,  Floating  Point 
Arithmetic,  8-bit  to  16-bit  conversion,  Pseudorandom 
Sequences,  and  Interfacing  a  Micro  to  a  Mainframe  - 
more  than  ever! 


□  Please  send  me  the  following  Volumes  of  Dr  Dobb's  Journal  for  S20.75  each. 
■  □  ALL  5  for  ONLY  S88.  a  savings  of  over  15%! 


Please  charge  my  DVisa 
I  enclose  □  Check/money  order 


□  MasterCard 


-Expiration  Date_ 


□  American  Express 


.  x  $20.75  =  . 
.  x  $20.75  *  . 
.  x  $20.75  =  . 
.  x  $20.75  =  - 
.  x  $20.75  =  - 
.  x  $88.00  = 


Prices  subject  to  change. 

Mail  to:  Dr.  Dobb’s  Journal,  P.O.  Box  E.  Menlo  Park,  CA  94025 

Allow  6-9  weeks  for  delivery 


Postage  &  Handling  - 

Must  be  included  with  order. 

Please  add  SI. 2 5  per  book  in  U.S. 
($1.75  each  outside  U.S.) 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

428 


13 


The  Conference  Tree 

Computer  Conferencing  on  Personal  Computers 


Abstract 

Computer  Conferencing  allows  group 
meetings  which  are  non-simultaneous  in 
both  time  and  place.  A  typical  conference 
may  run  24  hours  a  day  and  last  for 
months,  with  individuals  interacting  at 
their  convenience,  using  a  terminal  and 
the  telephone.  The  Conference  Tree,  a 
system  now  available  on  the  Apple, 
allows  such  meetings  on  a  small  com¬ 
puter. 

The  Conference  Tree  program  was 
originally  designed  for  the  personal  use 
of  the  author,  who  was  swamped  by  ques¬ 
tions  about  FORTH.  Most  of  the  queries 
needed  a  search  through  books  and 
papers,  for  information  the  requestor  had 
no  other  practical  way  to  get.  It  would 
be  easier  to  give  a  phone  number  to  a 
FORTH  computer  conference  (e.g.,  415- 
538-3580),  with  instructions  to  type  two 
carriage  returns,  and  suggest  leaving  a 
query  on  the  computer  if  the  information 
wasn’t  there  already. 

The  existing  computerized  bulletin 
boards  would  not  have  handled  this  job 
very  well.  They  store  messages  linearly 
with  all  subjects  together,  not  by  related 
groups.  It  can  be  hard  to  find  comments, 
answers  or  other  references  to  a  given 
message.  Their  numbering  of  messages 
and  use  of  many  single-letter  commands 
make  the  systems  harder  to  learn  for 
those  who  have  never  used  any  computer. 

The  Conference  Tree  is  a  hierarchical 
(tree-structured)  database  of  messages, 
designed  to  be  accessed  by  telephone, 
with  categories  and  sub-categories  deter¬ 
mined  entirely  by  the  users.  After  it  was 
made  available  to  the  public  as  a  test  sys¬ 
tem  (February  1981),  many  new  uses 
were  suggested,  some  not  imagined  by  the 
designer.  The  same  software  could  be  an 
on-line  newsletter,  a  technical  meeting  or 
journal  with  immediate  feedback,  a  movie 
or  restaurant  guide,  a  tool  for  decentral¬ 
ized  political  action  or  for  a  private  busi¬ 
ness  team,  or  a  way  for  retired  executives 
to  keep  in  touch.  In  short,  it  would  be 
a  general-purpose  tool.  The  system  was 
productized  and  documented,  and  re¬ 
leased  in  July  1981. 

Overview 

All  data  in  The  Conference  Tree  con- 


by  John  S.  James 


John  S.  James ,  c/o  CommuniTree  Group, 
P.  O.  Box  348,  Berkeley,  CA  94701. 


sists  of  MESSAGES.  Each  message  has  a 
name  of  up  to  20  characters,  and  a  text 
of  up  to  fifty  80-character  lines. 

Every  message  except  one  is  attached 
to  one  other  message,  sometimes  called 
its  parent.  (Similarly  we  can  speak  of 
child  and  sibling  messages).  A  message 
may  have  any  number  of  siblings,  or 
children  and  grandchildren  etc.  to  any 
practical  depth. 

The  single  message  which  does  not 
have  a  parent  is  the  first  one  in  the  data¬ 
base;  it  is  the  origin  of  the  tree,  called  the 
“root.”  In  the  Conference  Tree,  the  name 
of  the  root  is  usually  ‘CONFERENCES’. 
Naturally  ‘CONFERENCES’  (and  several 
other  messages,  such  as  a  ‘HELP’  subtree) 
are  normally  added  before  the  system  is 
put  on-line  for  the  public. 

There  are  nine  commands  in  The 
Conference  Tree,  but  only  four  of  them 
are  commonly  used,  and  a  single  com¬ 
mand  (‘READ’)  is  enough  for  beginners. 
‘READ  <name>’,  where  <name>  is  the 
name  of  any  message,  will  print  its  text, 
and  then  list  the  names  of  any  submes¬ 
sages  (children).  These  of  course  may  be 
read  in  turn  if  the  user  is  interested. 

This  simple  mechanism  allows  great 
flexibility.  ‘CONFERENCES’  itself  is 
usually  a  very  short  message,  e.g.,  “The 
conferences  now  going  are:”.  To  start 
a  new  conference,  the  user  can  simply 
add  a  message  describing  the  subject  to 
‘CONFERENCES’  -  although  any  mes¬ 
sage  in  the  database  can  in  effect  become 
the  start  of  a  new  conference. 

‘HELP’  is  a  one-screen  summary  of 
commands  and  options  available  to  the 
user.  Its  children  and  their  descendents 
are  the  on-line  user  documentation.  A 
first-time  user  need  only  type  two  car¬ 
riage  returns  to  start,  and  then  the  wel¬ 
come  message  will  suggest  typing  ‘READ 
CONFERENCES’  or  ‘READ  HELP’. 
From  this  point,  the  system  is  self- 
instructing. 

Often  a  ‘USERS’  message  is  also 
attached  to  ‘CONFERENCES’;  it  suggests 
that  users  may  attach  a  description  of 
themselves  and  their  interests  to  it.  Then 
mail  may  be  attached  to  these  user  de¬ 
scription  messages  —  although  The  Con¬ 
ference  Tree  is  primarily  designed  for 
public  conferencing,  not  electronic  mes¬ 
sages  to  individuals. 

In  practice,  most  messages  are  com¬ 
ments  on,  or  criticisms  or  continuations 
of,  their  parent  message,  or  invitations  to 
organize  new  subconferences  and  break 
up  a  discussion  topic  in  certain  ways. 


There  are  four  special  message  names 
in  the  system;  ‘CONFERENCES’  and 
‘HELP’,  which  have  been  described,  and 
‘PRIVATE’  and  ‘GUEST’  (‘HELP’  is  spe¬ 
cial  only  because  the  software  suggests 
that  the  user  read  it  at  any  sign  of  diffi¬ 
culty).  ‘PRIVATE’  is  optional;  if  any 
message  with  that  name  exists,  it  will 
not  allow  ‘READ’  or  any  other  command 
to  report  the  names  of  its  submessages 
(children).  This  facility  allows  private 
conferencing  without  use  of  a  password 
mechanism,  because  subtrees  under 
‘PRIVATE’  cannot  be  discovered  by  any 
user  who  does  not  already  know  at  least 
one  of  the  names  they  use. 

‘GUEST’  is  only  needed  for  special 
conferences  which  are  set  up  as  read¬ 
only,  i.e.,  which  require  the  system  pass¬ 
word  to  add  new  messages.  If  ‘GUEST’ 
exists  in  such  a  conference,  it  allows  an 
exception,  as  messages  may  be  added  to  it 
without  the  password. 

Besides  these  four  special  messages, 
all  names  are  freely  available  to  the  users. 
Names  need  not  be  unique,  although  they 
may  not  be  duplicated  among  a  parent 
and  its  (immediate)  children.  ‘READ’  can 
reach  any  message  in  the  conference,  not 
only  children  of  the  last-accessed  message 
(although  these  are  checked  first). 

Other  Commands,  and  Options 

Besides  ‘READ’,  other  commands 
will  print  the  first  line  only  of  messages 
(‘BROWSE’),  or  an  indented  index  show¬ 
ing  the  names  of  all  descendents  of  a 
given  message  (‘INDEX’).  ‘ADDTO’  in¬ 
vokes  an  editor  for  entering  new  mes¬ 
sages.  These  four  commands  are  the  ones 
frequently  used. 

Less-common  commands  will  set 
‘TERMINAL’  options,  ‘EXILE’  or 
‘UNEXILE’  messages  (a  kind  of  soft  de¬ 
letion  or  “soft  censorship”  which  lets  the 
reader  make  the  ultimate  decision  wheth¬ 
er  to  see  the  material  in  question),  and 
print  the  system’s  ‘SERIAL’  number 
(mainly  for  protection  against  software 
piracy).  ‘+ADDTO’  allows  moving  and 
changing  of  messages.  All  command 
names  except  the  latter  may  be  abbreviat¬ 
ed  to  their  first  letters. 

Various  options  will  modify  the  re¬ 
trieval  commands  (‘READ’,  ‘BROWSE’, 
and  ‘INDEX’).  ‘COMPLETE’  will  cause 
examination  of  an  entire  subtree,  not  just 
the  message  names;  e.g.,  ‘READ 
CONFERENCES  COMPLETE’  will  print 
everything  in  the  database  (except  for 
private  conferences).  Any  subtree  can  be 


14 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 

429 


bince  1976,  the  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Dr.  Dobbs  Journal 

For  Users  of  Small  Computer  Systems 


B  Trse  ISAM 
Concepts 


CP/M  BOOS 
and  BIOS  Calls 
lot  C 


IBM  PC: 

Printing  Graphics 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 


Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


1 

YES!  Enter  my  subscription  to  Dr.  Dobb's  Jour¬ 
nal  and  bill  me  later. 

$25 

name 

one  year  subscription 

12  issues 

address 

saves  $5  off  the  newsstand  price 

city  state  zip 

Mail  to:  DDJ,  P.O.  Box  E., 

Menlo  Park,  CA  94025 

searched  ‘STARTING’  at  a  given  creation 
data,  and/or  ‘BEYOND’  a  message  name 
(in  case  a  previous  printout  was  interrupt¬ 
ed),  and/or  to  ‘FIND’  all  occurrences  of  a 
given  string.  ‘EXILED’  and  ‘ONLYEX- 
ILED’  allow  readers  to  see  the  soft- 
censored  messages  if  they  want  to. 

There  is  no  logon  or  logoff  procedure 
(users  just  hang  up).  There  is  no  per-user 
or  per-message  password,  but  there  is  a 
master  system  password.  It  is  usually 
given  to  conference  editors  (called  “fair- 
witnesses”),  allowing  them  to  exile,  un¬ 
exile  and  modify  messages. 

Robustness 

The  Conference  Tree  is  designed  for 
unattended  operation,  even  for  weeks  at  a 
time,  24  hours  a  day.  Naturally  the  pro¬ 
gram  needs  good  recovery  from  data 
transmission  errors,  disk  errors,  and  mali¬ 
cious  users. 

We  know  of  no  way  for  data  errors 
or  a  malicious  user  to  crash  the  system 
or  break  through  its  security.  Disk  error 
recovery  is  good  enough  that  even  if  all 
the  disks  are  removed  while  the  program 
is  running,  and  the  drives  left  empty  or 
filled  with  unreadable  or  garbage-data 
disks,  the  program  keeps  running  proper¬ 
ly  although  its  usefulness  is  of  course  im¬ 
paired;  and  if  the  correct  disks  are  rein¬ 
serted  later,  the  system  recovers  and 
starts  working  normally.  This  error  re¬ 
covery  needs  a  paper  by  itself;  we  will 
outline  it. 

The  program  treats  the  user  as  two 
files  (one  input,  the  other  output).  Every 
command  line  is  parsed,  and  any  unrecog¬ 
nized  input  is  echoed  as  an  error;  the  line 
is  not  processed  further.  Only  the  legal 
commands  and  options  can  be  executed, 
and  with  a  small  number  of  them,  a  well- 
designed  system  can  allow  high  confi¬ 
dence  that  no  possible  combination  can 
cause  problems. 

On  the  disks,  the  message  texts  are 
stored  continguously ;  any  single  error 
will  make  only  one  or  at  most  a  few 
messages  inaccessible.  An  index  to  the 
messages  is  stored  separately,  and  it  is 
critical.  However,  no  disk  error  to  the  in¬ 
dex  can  stop  the  program  once  it  is  run¬ 
ning,  because  the  entire  index  is  kept  in 
memory  and  never  read  except  at  pro¬ 
gram  start-up,  when  an  operator  is 
present.  It  is  completely  rewritten  to  disk 
whenever  it  is  changed.  Therefore  any 
write  error  will  be  harmless  unless  it  hap¬ 
pens  on  the  last  write  before  the  system  is 
taken  down.  In  this  worst  possible  case 


the  operator  will  have  to  use  a  backup 
next  time,  but  still  the  system  has  not 
failed  while  unattended. 

The  data  on  the  disk  is  always  co¬ 
herent  except  while  a  write  is  actually 
occurring,  perhaps  five  minutes  out  of  a 
day  of  normal  use.  At  all  other  times  the 
computer  can  be  stopped  abruptly  with 
no  damage  to  the  data. 

If  a  disk  is  damaged,  it  can  often  be 
repaired  automatically  with  a  special 
backup  which  is  supplied.  The  backup 
does  a  straight  disk  copy,  except  that  any 
erroneous  blocks  on  the  disk  are  not  writ¬ 
ten  at  all,  leaving  “holes”  where  the  pre¬ 
vious  data  shows  through.  Since  messages 
once  written  to  disk  are  never  moved  ex¬ 
cept  at  compaction  (an  off-line  proce¬ 
dure),  the  backup  disk  will  be  largely 
identical  to  the  defective  one.  The  back¬ 
up  can  be  copied  first  onto  a  new  disk, 
then  the  running  disk  copied  on  top  of  it, 
letting  the  usually-identical  backup  data 
show  through  the  holes.  An  alternative 
procedure  is  to  copy  the  defective  disk 
over  and  over  again  onto  the  same  new 
disk;  if  every  point  can  be  read  without 
error  at  some  time  or  other,  the  data  is 
fixed.  If  these  steps  fail,  the  backup  disk 
can  of  course  be  used  conventionally. 

Turing  Test 

To  protect  against  the  possibility  of 
advertising  junk  messages  being  auto¬ 
matically  transmitted  to  a  large  number 
of  Conference  Tree  systems,  an  optional 
“Turing  test”  can  filter  out  automatic 
dial-ins,  making  sure  a  warm  body  is  at 
the  originating  terminal.  This  test  is  mere¬ 
ly  an  operator-set  question  and  answer. 
A  simple,  unambiguous  question  like 
“What  day  of  the  week  comes  after  Mon¬ 
day?”  will  filter  quite  well.  The  test  could 
also  be  used  to  admit  only  those  know¬ 
ledgeable  on  the  subject  of  a  conference 
—  or  concerned  enough  to  look  up  an 
answer. 

It  is  also  possible  to  require  the 
master  password  for  any  access,  to  run  an 
entirely  private  conference. 

Limitations 

On  a  48K  Apple,  the  Conference 
Tree  only  allows  321  messages  at  any  one 
time,  regardless  of  total  length,  since  the 
entire  message  index  is  kept  in  memory. 
Each  additional  12K  of  RAM  could  pro¬ 
vide  for  another  321  messages,  however. 

The  current  program  is  single-user. 
Multi-user  would  be  difficult  with  Apples 


because  the  minifloppy  I/O  is  not  inter- 
ruptable. 

Eventually  we  may  develop  larger 
systems  which  overcome  these  limita¬ 
tions,  but  that  is  a  low  priority  because 
our  philosophy  is  decentralized  communi¬ 
cation.  When  a  conference  disk  or  disks 
get  full,  it  can  divide  like  an  amoeba,  with 
certain  subjects  or  subtopics  going  off  to 
another  computer.  This  is  how  we  want 
our  system  to  grow. 

Another  kind  of  limitation  is  that 
after  a  message  has  been  saved  as  perma¬ 
nent,  if  it  is  re-edited  it  must  be  saved  as 
a  new  copy  without  its  descendents,  and 
if  it  is  permanently  deleted,  all  its  descen¬ 
dents  will  be  removed  too.  Such  opera¬ 
tions  usually  require  the  system  pass¬ 
word;  there  is  no  per-message  password, 
so  users  may  not  come  back  later  and 
change  or  delete  their  messages  without 
the  system  operator’s  cooperation.  These 
limitations  were  deliberately  designed, 
since  changing  or  removing  a  parent  mes¬ 
sage  would  change  the  context  of  descen¬ 
dents  later  added  by  others,  an  editorial 
unfairness  which  sometimes  might  not  be 
obvious  to  those  making  the  changes. 
Users  are  given  every  opportunity  to  re¬ 
work  or  scratch  their  messages  before 
making  them  permanent,  and  they  can 
make  them  anonymously.  Sometimes 
new  users  are  queasy,  but  in  practice  the 
system  has  been  well  accepted.  It  only 
highlights  the  fact  that  use  of  a  public 
message  system  is  a  form  of  publication, 
and  there  is  no  certainty  that  any  com¬ 
munication  can  be  entirely  taken  back. 

Proprietary  vs.  Public  Domain 

Part  of  the  source  code  will  be  pub¬ 
lished  and  made  public  domain  —  probab¬ 
ly  enough  to  run  conferences  with  the 
real  data  disks.  Other  software  such  as 
disk  compaction  and  backup  will  be 
retained  as  proprietary,  and  the  object 
program  disk  will  be  protected  as  these 
are  integral  parts  of  it.  We  hope  this  mid¬ 
dle  ground  will  enable  us  to  sell  and 
profit  from  our  work,  and  at  the  same 
time  encourage  development  of  related 
systems.  We  believe  that  The  Conference 
Tree  has  applications  well  beyond  what 
we  ourselves  will  ever  be  able  to  develop. 

We  have  no  proprietary  claim  to  the 
command  and  option  name  sets,  or  to 
the  name  “The  Conference  Tree,”  which 
we  want  to  be  generic  for  systems  of  this 
type. 

(Continued  on  page  45) 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


15 

431 


16 

432 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


17 

433 


(Continued  on  top  of  page  16) 


18 

434 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


FLAG  ;*  INITIALIZATION  SECTION 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


19 

435 


(Continued  on  page  18,  column  2)  I  (Continued  on  page  18,  column  3)  |  (Continued  on  next  page) 


20 

436 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


(Continued  on  page  20,  column  2)  I  (Continued  on  page  20,  column  3)  I  (Continued  on  next  page) 


22 

438 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


23 

439 


(Continued  on  page  22,  column  2)  |  (Continued  on  page  22,  column  3)\  (Continued  on  next  page) 


TEK4010 

(Listing  continued,  text  begins  on  page  8) 


24 

440 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


25 

441 


(Continued  on  page  24,  column  2)  I  (Continued  on  page  24,  column  3)  I  (Continued  on  next  page) 


26 

442 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


27 

443 


(Continued  on  page  26,  column  2)  I  (Continued  on  page  26,  column  3)  I  (Continued  on  next  page) 


*s  TEK4010 

(Listing  continued,  text  begins  on  page  8) 


NOU  SEND  XY  POSITION 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


29 

445 


30 

446 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


RETURNS:  FUNCTION  COMPLETE.  JR  PIOSTX 

CONSUMES:  AF,DE,HL  EBE3+ 1 804 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


31 

447 


u.  O  >-  ! 


O  ►-  Z  => 

CJ  0  3  O 

UJ  O  O 
CC  (-  ae  u 

'  *-•  3  W  3  •!  O 

O  3  c  UJ  —• 

'  ■>  2  >-  _<  u.  x  ■ 


s s x £ s s  8  s  s  s  g  s :  '  g  :  gggfessg 


y  ^  — 1  3  x  o  «  x 

*  W  I  •  -  Z  I_J_| 

LlIUJIiIIOI-QQQj 

—  ^  3  _ 1  z  U  u  !j  m 

<r  <L  <r  o  i  O  iu  UJ  uj  5 

co  u)  tn  u  !  l_i  c^.  .v  .-■-  i _ 


T3 

C 

UJ 


U-  H-  cn  H-  Ut  *— 

►  O  •.  »  O  >-  CD 

■**  <*  — >  «  <r  i  x  <r  i  «  3  . 


l  i—  00 
CD  - 

<x  a:  c 


X  *  LJ  CJ  X  C  a 


CO  >—•->. 


Q-  CJ  •— <  i=.  — i  CD 


HI  r-j 

cnuncn*— «ctza_1i_a- 

—3  3  3  X  t_J  CC  CD  CD  CD  I 
i  o  - >0-0.0.! 


<Z  <r  I— 
Lt  I—  LU 

X  U)  Ct  I 


CO  — 
UJ  X 
2  — 


x  x 

:  3  •» 

!  O  O 


Ll  U  —  t-i 

it;  *“  x 

O  o  O'  £l  Q 

^  <r  -i  2 

•-  *—  X  ui 

UJ  U)  o  CO 


to  o 
UJ  CO 
*-  20  _• 


i  o  O  z  ►-  z  u.  i 

UJ  CO  UJ  <Z  l-i  i  iii  i.i  i.  i,i 

*—  u.  co  n  a)  ai  co  o  w  o  a 


i=i  CD 
CM 
Z*  CD 


O  UJ 
(J  X 

•  CD 

UJ  2  X 


X  3  cn 

z  uj  o 

UJ  cc  u 


U-  iD-  r  : 


u_  1 —  c  j  <r 
-CD  -  - 

<r  <r  <x  aci 


:  co  ul. 

3  o 
1  Cl.  a. 


3  0  * 

Or—  * 

* 

*  #■  *  * 


00 

4J 

00 

CO 

a 


c 

o 


</J 

c 


00 

&> 

X) 


o 

* 

LU 


X 

Q> 


T3 

O 


c 

o 

o 


00 

#C 


C/D 


CO 

<r 

x 

X  3 

UJ  •  Li  UJ 

to  OC  UJ  l— 

UJ  cc.  CO 

1 —  X  X  UJ  UJ 

*—  uj  :>  =d 

X  O  X  -  3 

CD  2  UJ  UJ  UJ 

3  <r  oc  3  oc 


CO  UJ 

UJ  CO 


to 


CD 

2  <r 


X  O  *— i 


lu  >—o 

»—  uj  a.  <r  it 

•—  X  3  X  3  •• 
UJ  UJ  «  D  i  V 

to  z  to  ill  3  O 


h-  UJ 

to  ! — 
3  <r 


<r  3 


o 

o 

CD 


CO 

i=i  —I  CO 
u-  X  C3 
>—  _l 
tO  CJ  CC 
3  •  1— 

<r  <r  c_i 


o  o  o 

o  ro  u_  o 

3  »—  CJ  i_J 

r-j  uj  cm  <t 

ro  ro  ro  cm 


o  o 

UJ  CD 
CJ  t_> 
ro  cj  r-  — 
cm  cm  au  — 


o 
c- 1 
UJ 
UJ 


ro  -o  co  >xi 

cm  cm  c-4  <M 

UJ  UJ  UJ  UJ 

Ul  UJ  UJ  UJ 


UJ  Ll.  O  rO  *T 

CM  c  j  ro  ro  ro 

iii  i.i  i.i  i.i  i.i 

i .  i  i  ■  i  1 1 1  1 1 1  i .  i 


o  o 

iM  O  O 

UD  O  CJ 

3  0—  CJ 

lu  o  r-J  c-j 

4- 

r%.  o-  x  o 

ro  ro  ro  ro 

LU  LU  LU  LU 

LU  UJ  LU  UJ 


32 

448 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


33 

449 


(Continued  on  page  32,  column  2)  I  (Continued  on  page  32,  column  3)  \  (Continued  on  next  page) 


34 

450 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


O  Cl  U )  'It  'X'  it  -r-  -3 

0  •=•  *-*  -z.  a:  3  >-  '•!  uj  uj  "2.  ct  jo  tr>  x  uj  os  co  o_  .  o 

■j  j  -i  j  _i  j  to  o  ^  y)  oi  h  <r  ct  «  u  ^  -  -c  o  lsj  ct  j  — 

J  it  |V  Ct  !>:  Lt  i  u  X  <X  1.'  ti!  I  _■  i  I-  O  i!  x  n  o  co  o  0  _■ 

^  U  I-  O  Iji  >:  ,v  ^.o  o  u  0  UJ  C  '-0  — •  3  _i  a-  o  <T  3 

UuUuuuOJfilP!JuJu.OOoa(fl!DlH-)^jcx: 

d  o-  «r  o  uj  r-4  r  .  <x  ro  m  u-1  o  oo  *»-  o  u.  co  —  m  o  a  in  rv  c_i  ij-i 
o  co  o  o  o  —  »—  d  u.  o  r-4  j_*  r-  oo  c  ui  r--  co  a  cd  <i  ^  >x>  —  cc 

o  »  o  o  o  o  o  —  <r  o  co  i>-  cl  ao  ao  co  ck  eo  to  —  o  ao  Co  o  .=. 

O0OO  OOOO0O0  0  000  0  000  OO000O0 


(M 


uQf'J^'i'oaftaT  ~J  cci  o  -«  **-»  0  r  -  d  ir>  —  oo  -o  i>  u  O  —• 

i_j  uo  u"'  o  —  m  0  l*j  o  c.,  m  cj  o  *  d  o  « —  cj  o  m  r-n  0  —  u_>  co  uj 

—  d  O  <r  o  i_i  o-  oo  o  oo  o  uj  o  o-  co  >do  cj  <x  o  d  o-  co  d  _j  n  — 

0UJ0UI0UJUIU10ii.0UJ  -O  0  uj  u  hi  iii  o  i.i  ’.I  i.i  .  ■  i  i.i  — . 


cn  u_  cn  >=i 

•—  o5cjxc®=»x  —  z 

OOJJJJJI/IOUJ  cO 

-ijctctoc^ctixuzi-u 

cut—  ►—  ►—  i—  c-  ►—  3  0  o  o  lo  0 

0  >._)  UJ  CJ  0  C_J  0  U  d  Cj  UJ  UJ  0 

oo  in  r«5  oo  d  0  -o  co  0  c-i  -X  0 

o  i>  oooo»—  a  uj  »  o  a  o 

a  »  O  O  O  -  O  •-  <X  «X  O  0-  0 

00OOOOOO00O0O 


|X  d  d  _J  <  3  SC  d  iJC  _J 

>-  3  •<  LiJ  O  I  CO  <tUJO*— 

in  <i  cn  >  i:  u.  r  0  d  _j  o 

x  iz  cc  o  0  x.  —  u:  <r  u_  ic 

i/n  0  d  uj  c  co  •— <  z  »-  oo  o  cn  co 

U.  O  CD  C5  '  J  O  X  «  M  ^  I  I  -c 

o  Cl  OCi  r->.  O'  d  CJ  o  «r  <x  d  *—  r~- 

-  <r  k  os  m  co  o  «  o  n  in  o  w 

ocooooocoaooooooooo® 
ou_u_u.u_u_ooou_u.oo 


I —  I—  >-  U_  H  X  Ct 

uj  uj  cn  ii:  -  cc  u.  u  (/■<  x  •'J 

C  CO  a  K-  dOO  —  "0X4. 

t—  0  X>  Z  CZ»—  »—  OOd«CiZ 

x  0  0  C£  ®  0  0  0  *-*  •-«  Z  I—  »— 

7.  o  u_  u.  a  cn  co  .n  cri  cn  v/i  cn  i/i 

<r  0  0  O  ®  d  r--  <x  o  <r  -o  O  u. 

C_J  rO  d  O  O  «■  <t  d  O  O  UJ  O  0 

-  d  -  O  OO  U  O'  *  O  UJ  03  O  u. 

O  UJ  O  O  UJ  UJ  Ui  UJ  O  UJ  UJ  —  .  X. 


Oda->—  x  0  on  c-  o  o  x  x 

—  itz<ru:*—  x  o  o  a_  •— «  0  x 

dt—  cn  d  i—  ►— «  CC  0  0  _l  iZ  2>  O 

•x  cooa.cjxuixx  x  x  x  *- 

t—  h-  t—  x»  o-  3  x  «  x  x  x  x  x 

'>  o  u_  c_j  uj  ao  <r  uj  ui  uj  c  j  c  i  o 

O  d  -O  U-  C  J  OO  C|  C  l  Ll  'i  Ui  UJ  o 

d  ao  OO  d  <X  I_J  r_)  O  OO  'X>  d  0  00 

UJ  UJ  U-  UJ  UJ  UJ  UJ  UJ  UJ  uj  UJ  UJ  u. 


CO 

x:  ®  cj  z  *  d  0  ac  ld 

»—  O  d  CO  _l  l3  x»  r-U  -X>  0  UJ  I —  3  I  0  _J  0  _J  0  M  il 

O  0  — l_J  _J_J  — I  lO  I  l/J  U  c£  cn  «  I/)  Q  it  O  <1  X  0  3 

jJiKiKixacacacuoouujMzci'aouou  <_j  >-  d 

u-  i —  i —  i —  i —  *—  •—  i —  uj  *— •  z  cjn  d  _ i<_iduj  c  cn  i j  cn  x  d  u_  o  o  o 

l_Jl__ll_>OC_JC_)C_)l_>ddUJUJU_U-CX)CDOLDcX)X  X*— <d_l  IXZ 

co  -c  c-j  r-^  i_i  ^  un  <r  in  <r  un  o  co  d  u~i  o  u_  —  <r  j  o  •<»-  co  <x  u.  «r 
CXidOOO  —  —  —  UJOOOU  OCJ«rn*-lt-OOa3i'n  -O  O  —  O  O  U  O 
d  >  O  O  O  O  O  O  -«X  -X  O  O-  d  d  oo  oo  •»  o  oo  <x  <r  O  00  o  —  o  oo 

UJ  uJ  O  O  O  O’  O  -O  UJ  UJ  O  UJ  UJ  UJ  U_  U_  U.  O  U_  UJ  UJ  O  U-  O  O  O  UJ 


nn  —  ct' 

w  •/>  i —  -i  <x  cn  o  <x  *i  —  <r  «_■  uj  uj  3  •—  o  x  —  •_> 

tnixcna_<xuj_j  dxu.  j_  =>  •i'  z>  d  i —  cjou_ooo_u-*— 

u.  X)  o  un  X  i —  i —  o  0  u.  jc  d  i;  —  0  ui  >— •  »—  d  1  1  .•*-  — »  1  ■  1  ■  1 

u.  0  uj  uj  uj  0  <r  uj  i-c  t;  uj  ix  »"  X  x  x  x  x  o  cji 

oa.a_ctincn(ncnu>cntnij)i —  •—  ►—  0  0  3  3  x  k  x  x  x  xia.> 

0-  0  0-  O  O  O  d  U_  O'  —  f~-J  u_  0-  0  •>  u_  O  d  m  UJ  •>  «  <r  «  o 

ui  d  UJ  O'  d  o&  o  o  0  o  cn  u_  o  O  C-'  0  u_  d  o--  --  —  o  m  d  d 

d  »—  d  d  0  O  <X  O  —  OO  U.  O  —  O  «X  U.  0  0  d  d  i>  d  d  -  d 

0  O  0  0  '-U  0  0  O  O  OO  -1_  O  O  UJ  1.1  1 1  11J  I.I  1.1  i.i  I.I  1.1  I.I  I.I 


tnct  *—  0  h-  eg  0  d  b-  tn  d 

dX<X0ulCl_C->-  0  0  .X  •  >— •  >—  Z  Z  lC  O. 

cc  0 '000000  000t—  xuno:-_i0  0  0  <x  0 

00000000  r»00i— •  0  x  0  0  d  0  1—  *-xxco 

0  1—001—  00000cncnx0OO0Ctn<x0Zd0oz 

CJ0C_)00000ddd000O_OOO0XXi— 'iX0_i:C 
C_  -O  —  O  d  o  O'  C|  rn  d  O  c.  O'  O  0  0  0  d  —  <T  >0  C.  Cl  C  J  — 

mcoooo  —  —  —  O»OOC'IO0d  —  or-^o  —  0OICIO  —  dd 

<r  o  0  o»  -O  0  o  o»  o  <r  0  o-  d  d  -o  -o  0  -00—  =>  cr>  on  0  —  — 

UJ  ti!  O  2  00000  '0!  JJ  O  UJ  UJ  UJ  UJ  0  UJ  o  c-  O  U_  UJ  u_  o  o 


►—  03000  0  d  0  0  0  z  0 

cj  ci  0  0  0  0  o  z  i—  0  00  z  3  x  —  000  UJ  id 

0co0co0<r0000X>  1/50  0  1  0^.  z0O00d<r 

CO00OIJ5X000OO  0  0  0  1 —  cn  0>-d  1  10301 — 

d  0  0000001— <1—1  O  —  3  UJ  IJ5  r>  0  0  X  X  X  X  X  X  z  0 

z  o  o  0  0  0  cn  cn  ’/5  uo  05  0  cn  cn  0  0  0  x)  3  3  x  x  x  »<  x  x  cj 

0  d  d  d  d  d  O  G>  —  OO  Cl  0  ll“l  'X  O  0  0  OO  Cl  0  C-J  d  -O  O  0 

O-  111  d  d  O  O  UI  C_1  O  0  f~-~  O  '3>  -O  —  O  O-  |~'J  r-n  —  -O  C-J  0  d 

dd«d0  0OO«OO  —  •OC'  —  <r>COOOOOO>d0iiXidi>-dd  —  ■=• 
UJ  UJ  '0'  UJ  -UJ  0'  U_  UJ  '0  O  O  O  O  O  UJ  0  0  O  '0'  0  10'  UJ  0'  0'  uj  o  '0! 


0) 
CO 
CD  2 
2  to 
2  g_| 

4->  IX) 

cd  — i 
co  x 
Q 
-  2 
LT)  Q 
in 

IN  4-> 

•  <D 

•  co 

m 

E  in 

O  -i 


u 

in 

n 

O 

to 


> 

•H  »H 

>  T3 

•H 

'O  in 
M 
4-> 

c  . 

cd  x 
n  co 
cd  M 
in  > 
in  m 
•n  q 
03 

CD 

CO  2 

m 
n  a 
O  (31 
In  a; 


4J 

00 

50 

a 

s 

o 

C/5 

c 

*00 

0> 

X) 

X 

0/ 

H 


o 


o 

</) 

CQ 

CQ 

O 

D 

■ 

cc 

Q 


w 

co 

1-3 

< 

In 

O 

2 


W 

2 

X  o 

Eh  2 


co 


in 


2 

CO 

2 

> 

M 

Q 

+ 

in 

in 

CN 

* 

Eh 

2 

D 

O 

U 

u  u 

CQ  CQ  <C 


2 

2 

2 

2 

Ph 

M 

X 

X 

X 

X 

US 

< 

v. 

C/D 

2 

2 

2 

2 

V 

X 

X 

X 

2 

u  u 

2  2  2  2 
a  o  a  o 

W  W  W  W 


in 

—i 

X 

Q 


W 


in  2 
-I  co 

co  w  x  m 
2  2  a  > 

PC  2 


2 

D 

D  W 

DOW 

O  M 

W  X 

W  Q 

fa 

2 

2 

M 

W 

W 

X 

CO 

2 

X 


in 

— i 
2 
Q 
2 
2 

In 


Q  <  Q  <  O 
O  2  Q  2  Q 
<  2  <  2  < 


m 

X  X  2 
0  2  2 


a, 

o 

o  u 
2  2 


N 

2  2  Eh 
2  0  2 
a  2  2 


< 

■  2  Eh 


2  Q 


Eh 

2 

2 

O 

U 


Eh 

2 

2 

O 

U 


X 

•  • 

X 

00 

c 

o 

M 

*Z 

o 

2 

C/5 

2 

X 

□ 

cd 

c 

•rH 

4J 

3 

0 

X 

c 

c 

•rH 

CO 


CL) 

3 

tr 

•H 

c 

2 


>1 

0) 

2 

X 

CO 

< 


n 

CD 

Co 

CD 

4J 

C 


>i 

n 

c 


CD 

> 


00  o 
0  m 
CD  in 

CN 

(0 

c 

CO  co 

c  x 

■H  4J 

ra 

2  CO 
C  CO 
O  CD 
O  2 


Ln 

2 

'D 

CD 

2 

•H 

> 

■n 

2 


3 

CD 

c 


CD 

X 

2 

CO 

C 

•H 

it! 

2 

C 

O 

O 


2 

0 

i — 1 
i — 1 

X 

bri 

mh 

•  • 

CO 

•  • 

Eh 

X 

Eh 

D 

X 

D 

X 

w 

X 

Eh 

Eh 

2 

D 

2 

M 

•s  ■  V 

O 

IK  «w  • 

< 

n 

co 

c 

•H 

2 

o 

2  (D 
X 

>i  2 
2 


>i 

2 

• 

C02 
C  CO 
•H  E 
>i-n 
2  U 
O-  CD 
•n  >o 
2 


C  3  • 

O  E  O 

O 

2 
CD  O 
X 

2  2 
0 


O 

2 

2 

CO 


CD  X  CD 


2 


2 

CD 


E  rH 
U 


X 

c 


n 

CD 

CO 

CD 

2 

C 


CD 

> 


CO 

o 


< 

c 


CO 

•rH 

2 

a 

u 

cc 

CD 

i — ! 

Co 
2  C 
X  -h 
CO 

c  — 

•rH 

n 

2  CD 
C  2 
CD  C 

•H  *rH 

2  CO 

C  E 

CD 


CO 

n 

(D 

2 

CO 

•rH 

co 

CD 

n 

.Y 

n 

0 

S 

CD 

> 

CO 

CO 


n 

CD 

2 

CO 


n 

O 


co 

n 

X 

co 


CD 

2 

3 

cd 

E 


X 

CD 

n  >i  2  2 


2 

C 

CD 


2 

— 1 

2 

00 

o 

KJ  W- 

m-h  0 

a>  0/  -u 

X 

u 

To 

u 

u 

H 

2 

2  2  D 

c 

2 

2 

2 

• 

C  n 

0  0  D1 

<D  —i 

(/) 

CO 

rH 

CO 

CO 

CD  CD 

3  3 

TJ 

CD 

o 

2  -n  X 

O1  (31  2 

•H  H 

> 

> 

> 

> 

H 

-H 

3  2  2 

o 

>  2 

•rH 

2 

\ 

O.  0  0 

■K  * 

•rH  (/) 

+ 

+ 

2 

+ 

CO 

2 

C  3  C 

>1 

o 

3 

•n  tr  <o 

cn  'f  CL 

D 

> 

> 

CD 

> 

> 

CD 

0 

M-H 

C 

II  CD  CD 

II  II  0 

>  II 

II 

II 

U-l 

II 

II 

•rH 

>  > 

- - 

CD 

" — 

W  CO  co 

2  2 

CO  > 

> 

> 

- ' 

> 

> 

U 

D  10  CO 

X  X 

0 

•  «•. 

•  *» 

•- 

0 

CO 

n 

CD 

X 

2 

o 


2 

CO 


n 

X 


n 

X 


N' 

n 

X 


X  o 


2 

n 

X 


222  COX  co  2  2  2  C02222222  CO 


2 


CD 


2 

C 


2X2222 


CD  2 


iD 

CD 

Cm 

cr  n 

-C  rC  rC  f - !  jC  1 - 1 

2  2 

2 

rH 

•rH  C 

2  2 

2 

C 

II 

II 

CO 

CO  CO  CO  2  CO  2 

D.CD 

CO  2 

CD  03 

CO 

> 

■rH 

CD  "D  2 

4J  -H 

CD  CO  10  rQ 

iD 

CD 

•* 

2 

0 

(D 

3  3  3  CO  3  CO 

0  co 

3  CO 

C  co 

3 

0 

> 

0  CO  CO 

0  co 

0  3  3  co 

CO 

0 

o 

•H 

> 

CX  a  CD  O  CD  0 

ara 

CD  O 

CD'U 

CD 

E 

E 

Dill  o 

3  E 

CD  CD  CD  CD 

T3 

CD 

CO  2 


CT  CD 


Eh 

C  D 

2 

3 

CD 

o 

W 

•H  (Q 

3 

CD 

CO 

— 1 

n 

00 

M 

co  n 

CD. 

2 

CD 

Eh 

CD 

c 

X 

3  2 

C 

3 

u 

W 

2  2 

C/5 

X 

•  *.  •  V  1 

M 

1 S.  •  V  • 

o 

«.  •  V  •  v 

X 

•  •  V.  1 

M 

X 
■'  X 

X  2 

36 

452 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


o 

— 1 

• 

\ 

<  X 

XI 

o 

CD 

S3 

VD 

c  c o 

LD 

•rH 

+ 

04 

4J 

V 

4J  *H 

04 

04 

X 

•rH 

X 

\ 

\ 

X 

cr. 

X 

X 

•rH 

cd 

S3 

S3 

c 

'C  X 

O 

—  <d 

X 

+ 

X  + 

<U  X 

rH 

\ 

cn  £ 

(0 

CO 

XI 

X 

X  X 

T3 

E 

to  • 

S3 

S3 

S3  X 

3  O 

•H 

X  CD 

•K 

* 

■K 

X  X 

o 

3 

LO 

in 

X  LO 

\ 

cd 

rH 

CN 

04 

3  0-1 

1-1  X 

rc 

T>  (0 

0 

CD  X 

(0  > 

ii 

ii 

X  II 

X 

X 

CD 

<o 

X  II 

0 

u  CD 

XI 

X 

X 

<0 

X  T! 

S3 

S3 

Li  X 

—  X 

X 

CO  3 

0 

•H 

4J 

•** 

• 

0  w» 

•  •*  •  •* 

X 

<C  X 

V 

c 

ID 

CD 

cn  cn 

X  X  CN 

X 

(0  CJ 

CO 

X  O  LO 

LO  X  X 

C 

C  fO 

«■  X 

w 

V 

-  W  04 

X  -  - 

0 

x  E 

X)  O  S3 

cC  (0 

x  co 

U  X 

cd  "c  \  ts 

X  XT!  dlXX'O 

e 

TJ 

3  cn 

X 

rH 

co  C 

X 

•rH 

0)  -H 

* 

3 

(0  c 

rH 

LD 

rH 

X 

•H 

> 

> 

i — i 

m 

> 

lx 

> 

> 

ix 

> 

TS 

> 

•rH 

•  T 

X 

X 

i — 1 

> 

>  T 

T 

t 

X 

CO 

c 

0 

co 

Ll 

0 

03 

0 

0 

03 

0 

(0 

O 

> 

lo  co 

c 

CD 

(0 

o 

o  ca 

CO 

CO 

a) 

0 

lx 

E 

E 

E 

o 

0 

E 

lx 

E 

E 

jx 

E 

T 

E 

E 

cn  ra 

•rH 

l-i 

u 

E 

E  T 

T 

T 

i-i 

X 

(V 

CD 

4J  1-1 

O  co 

£  U-H  II 


o 

•• 

oo  o  cn 

-H 

w 

in  •• 

c  ca  a1  x 

a 

Q 

04  m 

X  E  i-i  X 

X 

X  X 

C/5 

X 

•  H. 

X  X 

X  . 

X 

•  • 


CD 

X 

CD 

E 

X 

> 

•rH 

3 

X 

CO  0 

X 

CO 

X 

CD  CD  CO 

CD 

Cn  3  x 

X 

X 

l-i 

•rH 

X  X 

X 

o 

CD 

tO  -  x 

Cn 

CO 

CD 

£ 

>  X  X 

•H 

CD 

X 

X 

X 

• 

CD 

X 

•rH 

E  cnx 

X 

S 

X 

Cn  0  x  x 

•rH 

X 

CD 

X 

•rH 

Li  CD  3  X 

•H 

X 

0 

T  X  £  CO 

cn 

CO 

* 

CD 

X 

•rH 

X 

X 

X 

X  II  L-l 

i — i 

T3 

X 

•rH 

4J 

O  A 

3 

* 

, _ - 

Cn 

CD 

X 

■  rH 

CO  X 

CO 

X 

•rH 

3 

XJ 

L-I  CD  0 

CD 

4J 

■rH 

CD 

cn  co 

X  3 

L-I 

•rH 

X 

5 

X 

•rH 

X  X  X  X 

.Q 

X 

C 

X 

jC 

3  CO  X 

Li 

1 — 1 

•rH 

3 

X 

w 

w  >  cn  co 

r — 1 

X 

cn 

•rH 

CD 

X 

CO 

■H 

• — 

X 

-H 

•**  QJ  rH 

in 

T 

0 

— ' 

s 

O 

X 

- 

CD 

s — 

CD 

-H 

— - 

X 

C 

X 

1 

C  V 

T 

— " 

X 

•rH 

0  X 

«» 

0 

C 

0 

X 

T3 

cn 

X 

X  rc  CD 

CO 

b 

b 

c 

•rH 

3 

CD 

rH 

CD 

S 

03 

3 

0 

rH 

S>  rH 

L-I 

03 

CD 

CO 

o 

O  X 

•rH 

T  cn. 

> 

X  TJ 

•rH 

ca 

0 

X 

X 

CO  u  C 

X  CO 

c 

E 

rH 

rH 

CO  -xx 

CD 

X  rc 

CO 

03 

C 

Li 

•rH 

0 

X 

CD 

ca 

X 

T 

X 

E 

CO 

0  0 

1 - 1 

CO 

CD 

CD 

CD 

•H 

E 

Li 

Li 

C 

O 

.Q 

•  «. 

•  V 

T 

! 


o 

n 

3 

•S 


o 


X 

CO 

-H 

— 

c 

U 

S3 

CD 

X 

CD 

0  CO 

>i 

a 

•rH 

C 

X 

CO 

X 

C  TJ 

« 

r- 

X  X 

CD 

CO 

ca 

0 

•H  C 

P3 

rH 

VD 

X  c  0 

•rH 

•rH 

Li  C 

U 

-H 

rH  03 

— 

rH 

C  CD  3 

X 

Cn. 

O  CO 

X 

CD 

1 

CO  • 

CN 

(D  x  cn 

0 

CD 

rH 

X 

c  CO 

0  0 

E  Ll 

CO 

x  x  "fc  Li 

3 

u 

CN  O 

3 

C  X 

•H  0) 

o 

CO  CD 

0 

X  0  O  CD 

u 

cn 

\  — | 

CO 

•rH 

X 

•rH 

E 

0 

0  3  X  -D 

CD 

X 

-H 

a 

CO 

X 

CO  >, 

C 

>l  Ll 

o 

3  tJ'  II  C 

ca 

ii 

u 

U 

Jx 

X 

E 

c 

X  x 

>1  o 

C  CO 

cn  w  x 

c 

0 

X  CD 

0 

a 

CD 

X 

li  e 

CO  fn 

c 

*  a  co 

•rH 

X 

5 

> 

CO 

c 

lx 

•rH 

•H  O 

Li  <D 

•H 

*  E 

ca 

S3 

c  o 

3 

X 

X  CO 

CO  C 

lx  • 

O  *  CD 

E 

CD 

•H 

0  X 

X 

0 

(0 

O  E 

0  s 

LO  X  X  Li 

CD 

C 

u 

CD 

CD 

•rH 

a 

3 

X 

' — ■ 

CD 

3 

>H 

U 

0 

CD  3 

C 

a 

tJ1 

<D  3 

• 

ix  cn 

> 

cn 

II  II  Xi  II 

3 

X 

E  x 

0 

X 

IH 

X  0 

CO 

CO  O 

o  X 

CD  — 

c 

n 

X 

CO 

•H  (T3 

0 

lx 

•rH 

lx 

na 

X  x 

T3 

<D  rH 

— 1 

4J  O 

X  X  X  x 

CD 

CD 

X  > 

X 

lx 

X 

0 

c 

CO 

O 

rH  *H 

CD 

C  X 

S3  K  II  S3 

< 

u 

u 

•H 

CD 

a 

u 

CO 

O' 

•rH 

o  CS3 

>iTJ 

•H  \ 

X 

CD  CO 

C  X 

lx 

X  0 

X 

•'  •'  S3  •' 

0 

0  *. 

C 

0k 

0  V 

0  V 

0^ 

•H  CO 

CD 

0*k  0 

O 

CL) 

O  CO 

•rH 

x  0 

Di 

CD 

>  — 

lx 

0K 

U 

X 

X  o 

TJ  Ll 

x  x 

CD 

CD 

3 

X 

•H  (L) 

X  c 

TJ 

•  > 

Di  TJ 

o 

>  X 

•H  (D 

c 

C  x 

0 

rH 

0 

X 

X  X 

•H  UH 

CO  X 

•rH 

c — 1 

0  rH 

-H 

1  3 

rH 

lx 

Jx  lx 

TJ  CO 

0  X 

CO 

M 

•rH  0) 

C 

O 

1  o 

o 

X 

X  X 

Di  0 

E 

Q 

X  X  ru 

CO 

X 

■o 

X 

X  ^ 

-H 

-H 

X 

s 

CO 

CO  CO 

a 

h 

rH 

3 

CD 

O 

X 

CO 

O 

CD  X' 

CO  O'  Ll 

CD  E 

cd  a 

in 

X  CD 

CJ 

LI  X 

C  T5 

-H 

co  cn 

II  II 

II 

CQ 

iH  HJ 

0 

•H  O 

co  CD 

cn  o 

0  x 

rH 

x  o 

X 

rH 

• — 1  rH 

Jx 

lx 

X  X 

X  X 

< 

•• 

ru  -u  X  X 

> 

Ci  a 

a 

a  Li 

•rH 

•rH 

X 

X 

3 

3 

rH 

rH  rH 

<0  CO 

03 

X 

c 

X  X 

CO 

CO  CO  (J  CO 

0 

a 

0 

0 

0 

X 

Pi 

o 

3 

c 

CD 

0  CD 

O 

03 

CO  co 

Jx  Jx 

lx 

CD 

03  -H 

CD 

'U  'O  X  -o 

E 

a. 

Di 

Di 

cc  cn 

c 

O 

lx 

CO 

•rH 

lx 

Li  X 

X 

o 

o  o 

0  Ll 

lx 

lx 

•  • 

> 

rH 

a 

X 

CO 

•  • 

•  •  4J 

Jx 

>i  co 

•rH 

X 

Q 

X  3 

CD 

rH 

X 

X  X 

CD 

jZ2 

H 

3  Di 

CO 

Di  CD 

0 

•H  4J 

> 

00 

0  0 

00 

00 

> 

D,  X 

CD 

DiX 

3 

X  -H 

03 

CO 

-H 

c 

H 

C  3 

Jx 

CO  X 

a1 

co  S 

CO 

Jx 

lx 

Jx 

Q 

X  O 

Si 

0 

0*.  0 

0  V 

0*.  0  V.  0« 

X 
•'  CO 

X 

CO 

X 

co 

I-J  • 

^  0  «.  0k.  0 

V  0  *»  0  «. 

vo 

& 

cx 

© 

cx 

© 

■*— 

s: 

o 


3 

•S 

C 

£ 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


37 

453 


•  w 

U-l 

X 

1 

X  X 

•H 

c 

-P 

•H  *rl 

X 

QJ 

X 

O  O' 

0) 

E 

O' 

•H  -H 

X 

a- 

•H 

x  x 

X  i-j 

rH 

U 

X 

c  qj 

a. 

• 

X  i — 1 

-P  " 

(0  > 

E 

cc 

qj  qj 

w  to 

c 

0 

vo  in 

4J  «H 

cc  3 

-  0 

o 

r-  ( u 

O,  X, 

• — 1  c 

>H  O 

CN  4J 

at 

•rH 

QJ 

w 

ro  > 

>  qj 

i-j  E 

0 

\ 

Xi 

c  X 

(b  \ 

0  O' 

CN 

4J 

0  x 

X  At 

-P 

C  vc 

u 

X  c 

4J 

c 

X 

(0  (0 

C  >H  O 

QJ 

m 

oj  o 

rH 

O'U  A 

o> 

-  OJ 

X 

0/  X 

•rH  Pj 

O  *H 

(b 

X 

cn  qj  EG 

c 

i  a 

0  X 

>i  - 

> 

w 

3 

x  >, 

X  CQ 

X  (0  X 

rH 

0  o 

X 

A^ 

CC  CQ  X 

QJ 

X  O 

U 

0  c 

0 

Q)  X 

X  rc 

X 

x  to 

1 — 1 

0)  to 

s  u 

X  X 

X 

X  >, 

3  X 

a) 

rH  > 

u  03 

C  X 

o  w 

X  o 

a-’  & 

C  05 

\  \  ^ 

h 

a 

1 

t>  i — 1 

QJ  <L) 

cc  X 

1  o 

rH  4-1  U 

^  *  v. 

C  05 

X  X 

> 

r  r  % 

X  (0  c 

a 

h 

a 

0 

X  X 

X  X 

u  x  • 

A 

cc  H 

3  X 

••  i 

at 

W  £5j  (1) 

X  W 

W  -h 

•H  4->  *H 

EC  o 

D  X 

X 

D  X 

3  3  3 

x  cn 

rH i 

X  0  X 

II 

II 

O  0'  0! 

x  3  o 

X  DjX  x 

O  4J 

at  a>  oj 

(0  di-n 

x  o> — i  * — i 

O  1)  U! 

X 

0X0 

4J 

3 

•  • 

OC  X  Ti 

a 

Du 

O 

a, 

X 

.*  cn 

QJ 

c 

3 

C  3  0 

X 

— 1  CN 

M 

o 

05  C  l-J 

X 

rH  *H  Qj 

> 

-  X  E  n 

•'  O 

cn  x 

W  X 

QJ  -H 

-  cc 

4J 

O' 

n  CD 

3 

c 

QJ 

X  X 

-  0 

a 

•rH 

> 

T  Ti  O  X 

X 

CC 

A? 

•rH 

05  1 

G 

c  cn 

-P 

VO 

c  • 

0)  0 

03  -P 

•iH 

c 

*H  ^ 

-P 

C 

rH  *r1 

DJ 

0  0 

X 

03  0 

4J 

X  O' 

0 

-H  4J 

>-1  X 

X  X 

a 

X  c 

nj  rc 

cn 

0  X 

03  -rH 

E 

x  U 

cn 

u 

cn 

c 

x  c 

0  - 

QJ 

QJ  X 

03 

*H  i—ZJ 

O  0 

x  a 

p 

N  QJ 

s 

X  ts 

QJ  X 

X 

AH 

cn 

X  X 

Q)  O 

X 

o  o 

X 

QJ  X 

ro 

> 

03 

X  03 

3 

X  1-4 

X  c 

03  X 

a 

a. 

QJ 

QJ  *H 

cn  o 

rH 

-  a 

c 

QJ  >  X  X 

03 

03 

X  3 

•H 

>  C 

O  cn 

x  a 

C 

cn 

CO  0 

01  Qj 

c  c 

•rH 

03  c 

X 

w  u 

Dj  X 

03  3 

X  0 

•rH 

•  V  Is. 

**• 

•  •*  IS 

•s 

•  *i  V 

•  s» 

c 

03 

AC 

AC  AC 

X 

o 

o 

u  ox 

X 

QJ 

03 

03  03  X 

0 

<c 

X 

o  ax 

Dj  QJ  D  ' 

LT>  l-i 

w  rH 

QJ  rH 

rH 

' — 1  w  c 

C  -  C  QJ 

-  X  QJ 

X 

X  X 

X  X 

X 

X  X  3  X 

3  X  3  X 

X  X  N 

03 

rC  rH 

X  X 

rH  rH 

rH 

rH  O 

cn  x 

Dj  CQ  X 

rH  rH 

Dj 

DjX  c 

3  cc 

0 

3  X  03  X 

03  x  o3  y. 

X  0  03 

0 

U  rH  X 

0-  o 

P-!  P;  rH  U  rH 

O  X  o  QJ 

X  Dj  O 

Dj 

X 

> 

-  u 

1  •* 

•- 

• 

cn 

cn 

X 

P 

0 

•rH 

QJ 

cn 

P 

0 

o 

A 

P 

QJ 

QJ 

X 

•rH 

cn 

0 

QJ 

N 

> 

X 

•H 

rH 

O' 

•H 

cn 

QJ 

O' 

4J 

•H 

X 

QJ 

X 

• 

X 

c 

•H 

3 

X 

X 

C 

c 

•rH 

cn 

E 

Dj 

3 

QJ 

0 

•r| 

X 

0 

X 

X 

X 

C 

03 

D  x 

3 

•rH 

0 

X 

QJ 

•rH 

0 

c 

QJ 

cn 

QJ 

rH 

QJ 

u 

ox 

C 

X 

0 

QJ 

03 

X 

X 

o 

cn 

X 

OX 

E 

C 

•rH 

ai 

i— ! 

X 

cc 

o 

w 

o 

X 

03 

•H 

QJ 

X 

X 

3 

X 

c 

03 

QJ 

cn 

cn 

X 

X 

c 

3 

X 

•H 

0 

X 

0 

0 

QJ 

z 

0) 

X 

1 

U 

a 

X 

QJ 

X 

Dj  0 
cn 

E 

03 

xs 

O 

00 

C3 

VO 

-H 

c 

4J 

03 

s. 

X 

0) 

X 

X 

P 

0) 

X 

D. 

0 

U 

QJ 

X 

M 

QJ 

0 

O 

s 

o 

4J 

P 

•rH 

cn 

QJ 

C 

4J 

03 

X 

Dj 

0 

cn 

C/D 

0) 

u 

QJ 

X 

0 

• 

u 

•rH 

(/) 

*00 

0) 

> 

c 

QJ 

> 

O 

3 

O 

X 

X 

QJ 

Dj 

X 

X 

0 

cn 

X 

•H 

cn 

QJ 

rH 

CD 

•*— 

0 

cn 

•H 

•rH 

03 

0 

X 

QJ 

X 

X 

3 

cn 

u 

0 

X 

c 

x: 

X 

QJ 

CD 

X 

E 

X 

o 

•H 

is 

0 

03 

0 

X 

u 

o 

0/ 

3 

3 

X3 

c 

QJ 

C 

• 

cn 

QJ 

QJ 

X 

X 

QJ 

X 

QJ 

•rH 

M 

QJ 

X 

X 

cn 

QJ 

X 

n 

c 

X 

W 

X 

3 

•rH 

QJ 

cn 

feHHBfl 

o 

3 

u 

X 

X 

> 

03 

X 

o 

0 

cm 

•rH 

x; 

u 

QJ 

0 

CC 

00 

_c 

w 

J2 

<c 

QJ 

0 

c 

o 

0 
i  QJ 

QJ 

cn 

u 

O 

X 

3 

0 

c 

03 

X 

QJ 

QJ 

•rH 

a 

J 

•  V  IS 

X 

•  s  < 

o 

IS  IS 

E 

•  s, 

0 

X 

X 

X 

cn 

X 

C 

•rH 

o  cn 

o 

■H  3 

•rH 

cn  c 

X 

•*H 

QJ  E 

> 

cn 

•h  a 

3 

X  3 

c 

•H  QJ 

•rH 

cn  >  x 

E 

0  X  QJ 

\  « 

Dj  x  cn 

X  W 

•H 

c  c 

qj  cn  - 

03 

E  C  qj 

X  w 

E3  D,  X 

X  X 

W  3 

c 

W  X  X 

QJ  QJ 

03  x  X 

>  E 

C 

•H  QJ 

•-  •-  CP 

QJ  l-i 

03 

O  O 

cn  E 

Qj  C 

O 

Vh  P  -rH 

'  QJ  QJ 

QJ 

fU  X 

O  0  *• 

X 

'  X  03  X 

QJ  X  U 

-  >  X 

X  QQ 

X  X 

03 

03  03  U  3 

03 

c  cn 

O 

H  Qj  s 

rH 

X  x 

cc 

X  >iK 

0 

QJ  X 

X  X 

c  cn 

••  cn  cn 

> 

03  x  - 

> 

O  X  QJ 

X  3  3 

0 

x  >  Dj  QJ 

0 

•H  *H  ^ 

03  CL  Pi 

E 

O  E  t-i  > 

E 

cn  cn  u 

E 

•rH 

QJ 

•rH 

X 

n  a  cn 

o 

cc 

i  Qj 

QJ 

O 

X  H  s-j 

X 

QJ 

EC  G  Dj 

X 

C 

> 

-  o 

•  V 

M 

M 

U 

cm 

< 

c 

o 

0 

•rH 

X 

cn 

X  o 

QJ 

QJ 

X  ro 

X  X 

X 

3 

X  *H 

X 

X  V 

X  X 

•rH 

ro 

X 

c  cn 

X  X 

3 

Ox 

m  cn  w 

Dj 

(C 

M  3  3 

X 

E  x 

C J  rrn 

3 

X 

cm  x  x 

0 

X  tJi 

<C  cc  CC 

O  x 

•  *» 

X 

X 

x  O 

o  o 

o  cn 

o  o 

•rH 

JC  o  o 

1 

X  - 

moo 

03  i — 1 

03  ^ 

co 

m  — i  — i 

—  — 

X  VO 

V  K  ^ 

X  cc 

rH  x:  03 

X 

x  or-' 

CC  X  o 

X  CN 

X  ro 

X  X 

X  V 

X  X 

X 

1-4 

i — 1  t — ! 

>  > 

03  >  X  -H 

CO 

X  OJ  QJ 

•rH  *H  tH 

0  0 

E  0  C  > 

X 

C  >  X 

>  D  D 

E  E 

u  e  -h  e 

cn 

x  C  3 

E  X  X 

•  • 

0  x 

CN 

O  x 

o 

c 

QJ 

S  o 

X 

O  CC 

X 

C  E 

> 

o 

is  •  •» 

38 

454 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


o  • 

P  c 

01  O' 

N  X 
I  CQ 

c 

o  c 

C  X 

X  4-1 

CO  3 

•  — H  Oi 

c 

p  01  *. 

3  p  X 

4-1  o  X 

0)  ip  O' 

p  0>  x 

XI  E 

C  A 

(D  I  •' 

X  XI 

-u  cn  co 

•'  ■'  3 

C 

•rl 

e 


o  Hi 

c  x  ^ 


4-1 

o 

4-1 

01 

01  E 

01 

P 

E  rH 

P 

u 

>4 

<z 

u 

U 

Xu  • 

^  • 

0J 

(0 

e  w 

p  X 

X 

0  >, 

4-> 

3 

Oi  E 

E 

i — i 

4J  in 

+ 

c  - 

X 

3 

(0 

in 

X 

Q 

E  xi 

C 

E 

X  rc 

>, 

3  O 

• 

•H 

•H  -  U 

KO 

H  - 

C 

a  r- 

o 

-0  rH 

-H 

m  u 

m 

O  VO 

a>  • 

io  ai 

4J 

c 

E  x 

CQ  r- 

ix  m 

><  E  x 

in 

■rl  C 

Q)  *rH 

CM 

U 

U  -r-i  4J 

o 

Xi  X 

C  X 

X  ro 

01  0 

to  u 

X 

H 

o 

•H  O 

X  N  X 

c  oi  ai 

hH 

E  m 

•rH  VD 

o 

C  X  (0 

■H  E  X  — 

<D 

0)  4-1 

CO  -H 

X  0 

3  X  X 

X  (OP 

D 

CD 

C  X 

C 

E  X 

0  no  3 

01  CPU 

c 

c 

O  O' 

3  C 

1 

U  -n  E 

X  x  o  03 

•rH  *H 

•H 

VD  O 

X  3 

x  x  a 

4J 

o 

m  e 

X 

O 

X  -H  u 

•H  3  0  C 

c 

4J 

c 

•H  ^0 

10  o 

•H  c  O 

X  0  P  x 

o 

3  rH 

X  Oi 

o 

X-H  IB 

wc 

o 

cc 

res 

1  *H 

c  o 

4-1  E 

LO  4H 

•H  o 

•rH  *rH 

— !  -H 

(0 

Oh 

•rl 

X  u 

X 

X  0) 

X 

i  a1 

co  m 

P  cr 

E 

no 

Q 

IT)  rO 

C  3 

0  c 

rH 

CJ 

-H 

•H  ‘1  1 

U  (0 

V 

5 

0 

X 

CQ 

E 

(0  1 

iH 

X 

-HO  - 

r 

e 

a 

a 

e 

(0  (0 

O  (0 

( c 

X 

-U  (U 

X  X 

w 

Q 

«*.  Qj 

rH  x  v. 

V  X 

X 

N 

in  ^ 

C  X 

ai 

i  uo 

h 

a 

a 

e 

(0 

io  E 

to  m 

o 

-Q  C 

u 

oi  u 

O  01 

ro 

>  (0 

o  X 

a  x 

U 

Oh 

C  D, 

CO 

c 

0 

X 

-  c 

o  in 

E 

U  X 

w 

E 

E  U  (0 

U  10 

o 

(0 

U  x 

1 

1  O 

II 

II 

<c 

E  E  E 

O  O  O  ID  O 

X) 

E  (0  TO 

E  rn 

io  e 

01  CX  01 

1 

1  4-J 

rH  rH  i — ! 

(OX  IBOX 

r-| 

10  >0)  X 

rH  rO  rH 

E  -x  p 

u  xt 

X 

4J 

3 

CO 

in 

QJ 

W  K 

3 

a, 

0) 

•  • 

•  • 

< 

P 

a 

X 

X 

o 

a 

pL| 

X  C 

c 

3 

rH 

ai 

rH 

tc  -H 

M 

o 

< 

E 

E 

D 

•  «*  •  • 

•  •  •*.  • 

■>»  • • 

rH 

*x: 

rH 

x: 

■  V 

•  X 

co 


•rH 

JD 

4J 


3 

m 

01 

u 

X 

ro 

O 

•rH 

ai 

cn 

X  X 

X 

•rH 

X  x 

•H 

E 

■H  x 

X 

U1 

X 

U>  X 

X 

3 

x  o  m 

m 

a 

x  a,  3 

3 

X 

cr  T-i 

•n 

3 

x  x  E 

E 

0 

E  x  (0 

10 

f0 

•  x 

to 

•  ^ 

E  •- 

C 

(0  o  o 

O 

o 

X 

IQ  X  O  O 

O 

o 

X  X 

3  E  O  O 

o 

o 

Cr  E 

O  ro  x  x 

— 1 

— 1 

•h  ro 

X  ».  •>  - 

w 

E  •> 

E 

E 

t 

a 

3 

2 

X 

o 

EE  (0 

(0 

01 

E 

X  XX 

X 

X 

01 

X  EE 

E 

E 

u 

X 

rH  rH 

rH 

rH 

X 

E 

10 

X 

E  X  X  -rH 

•H 

•rH 

fO 

X  C  x 

X 

c 

X  >  3  3 

3 

3 

X 

C  3  > 

m 

•H 

x  E  X  X 

X 

X 

CQ 

x  x  E 

3 

X 

E 

rH 

s 

•iH 

0 

3 

c 

X 

o  o 

o 

o 

X 

o  o 

o 

o 

E  O  O 

O 

O 

H  —1 

— 1 

X 

ro 

- 1 

H 

— 1 

— 1 

ro  cm 

— 1 

o 

(0 

ro 

(N 

-H 

o 

E 

E 

XI  X) 

jQ 

X 

X 

X 

X 

X 

rc  'O 

E 

"C 

HD 

rH  rH 

r — 1 

X  X 

rH 

rH 

rH 

• — 1 

X 

•H  «H 

•iH 

X  *i—l 

X 

•H 

•rH 

•H 

•H 

(0 

X 

D  3 

3 

3  CP 

> 

3 

3 

3 

3 

X 

C 

JO  X) 

X 

X  X 

E 

X 

X 

X 

X 

CO 

•H 

T5 


10 

c 

<D 

■U 


c 

• 

01  E 

0 

01 

X  0 

•iH 

c 

X  iH 

CO 

•rH 

X 

u 

X 

c 

0) 

3 

X  CO 

> 

0 

iH 

H 

P  0) 

E 

K  X 

Q 

H 

X 

Q 

01 

X  x 

X 

0  E 

01 

u 

-V 

(0 

C  01 

•rH 

u 

0  C 

rH 

(0 

•H  »H 

X 

X  X 

o» 

o 

(0  3 

X 

X  O  •• 

i — 1 

C  P  10 

0 

(0 

0)  >1 

X 

E 

CO  CO  (0 

•rH 

01  X  s 

•  ^ 

o 

P  X 

01 

D:E-|  O 

E 

01  S 

iH  4J 

X 

0 

•  • 

Ch 

X 

rH  i — i  C 

ro  X  X  X  — 1 

fD  +  H 

>i 

E  W 

(OcocnxoeE  XX 

u 

X  Q  VO 

ro  o  *— 1  m 

C  <D  =*= 


X 

X 

X 

X 

•rH 

E 

X 

E 

E 

E 

E 

CQ 

(0 

E 

rH 

l — 1 

X 

r— 1 

X 

01 

p 

X 

•rH 

•rl 

•H 

X 

(0 

X 

a.  o.  x 

1 

X 

CO 

p 

> 

3 

3 

3 

3 

X 

c 

01 

0  0  01 

1 

X 

01 

E 

JD 

J2 

X 

X 

CO 

•H 

c 

Qj  (X  P 

X 

c 

0 

u 

CO  >1  x 

CO 

E 

-  H 

01  X 

X 

>  P 

iH  4J 

•rl 

rH 

oo  Eh 

O  X  (0 

c 

rH 

E  > 

XXX 

3 

(0 

•■*3  O 

CO  CO  X 

H  -  . 

•t  •«.  •*. 

Q. 

© 

C 

O 

*© 

*> 

3 

•S 

© 

Cj 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


39 

455 


of  page  38)  I  (Continued  on  next  page) 


44 

> 

4f 

44 

3 

•34 

44 

44 

44 

CO 

44 

44 

»— i 

44 

44 

44 

44 

_l 

44 

*• 

44 

O 

a 

44 

ro  o 

2 

44 

CO 

<1 

:>  ^ 

•— < 

LL. 

X 

H 

Ld 

X 

h- 

h-  O 

CO 

Ld 

iX  H 

n 

X 

O  w 

X 

Li_  O 

* 

2 

X 

i  _J 

ro 

Ld 

CJ  » 

■ 

h- 

i—i  ^ 

i> 

Ll_  CN 

2 

CO  o 

x  r-i 

HH 

<r  th 

o 

a  <w 

~ 

co  o 

H* 

_i 

H 

n 

X 

»• 

X 

O  X 

Ld 

o 

IhO 

h- 

■«■  o 

Ll 

O  H- 

-*  r  j 

i 

-  CJ  CO 

W  CJ  LL.  f'-  44 

44  uZ  HC02Z  *• 

44  CO  Ld  LJ  ■  7^ 

*~o<ico:lio  -  *4 

44C*CO|Xii— 

o  <i  o  o  44  w  n 

«■  ~  t  ZuiUO  ti  ii  44  i< 
WtOwH  |V  00  i-  21  2  44  :*:  i-  . 

2  LJUOZ  ZD 

^  ^2ZHZ  h  H  h  h  £  h  Li.  I 

UHHiiuZZGiiLiJuJUUZi 
u^wuiliZOOGu _ i  _J  cc:  _j  HH  . 

h  r -j  n  <r  o  <r  <i  o  cs  o  c-j  o  o  r 'i  1 

o  o  o  o  r  j  c  i  a  a  c-i  ro  ro  in  o  sd  ■ 

OoOoOoOoOoOOqOi 
OOOoOoOOOoOCoOi 


:  2:  cj  w 

'  Ld  <r  _J 

>  X  O  K  O  ii 

J  H-  tH  co  ro  ^ 

rH  ■  o  2 

<  o  o  o 

i  V  H—  _J 

X  O  Z  o 
hHl-H 
IliOiZOLJ 

IH01O  j 

■  o  <r  no  co  o 
•  O  o  O  o  T-I 

!  hX  ■’“ >  rX  hX  H 

:  O  O  O  O  O 


~  2 
~  2  Ld 
2  ^  X 
w  Jh 

O  w 

_J  4*  ■  4fr 

A  M  «  • 

~  ii  -  ii  : 

2  &  ii  . 

v/  Ci  , 


L-  LJ  Ll.  Ld  l 
M  _J  w  _i  . 


G  S  S  “*  g° 

~  M  X  2  ZUi  2  N  ^  b 

i-i  r-  LiJ  O.  UJ  [3 

—  ■■  x  <r  x  o 

"DC  **“  H  ^  ►—  th  al  2 

©  44  Ld  *  C5  2  m 

— 1  7^  O  ■  CO  ■  H  Af  T- 

■?fO<I  tft  Ld  tft  i—  u_  xft  -jfK 

44  i>  3  u-  a  CO  a  £ 

-  X  *iC3Zl-  3  3*  Ld  O  -  £  . 

"*  44  O  O  44  O  CO  l— J  V*  1— i  O  CJ  LJ  44  l—i  O  H  W  ri  O  i  . 

1—1 1  -d  -^1  -W-  O  *  *  H 1  -f-  P**  ■  ■  ►— I  -A-  f\  ■  m  h—i  f\  4fa 

-  !i  i!'  -i  *  ro  A  Ii  ii  ii  o  A  ii  i!  ii  O  A  ii  II  5  S  *  A  Z 

!,  **  th  O  44  V  #  ii  O  V  *4  *4  ii  O  V  ^  f  O  *f  v  ii 

-  *“H  — I  44  ^  ill  H  iii  iS  H  y  *A  p*,  fa-1  y>  •--)  3T 

cd  <x  cd  <r  o<x  □  <j- 

"  r-  XX  H-  H"  H-  i—  • —  r—  f—  ( —  h  H  h  h  Z  I!  l_ 

■iLdLdOLdLdL-LdLdLdOLi_LdLdLdOLi_LdLdLdOLdUJL_Ld 

jJJ0Ll|Vhjjjghjjj0hjjj0|^|^hj 

i^SS°2^^s°SOrjc^c3O^^'00DOorjc- 

I  M  M  O  H  O  O  O  O  o  H  H  H  H  H  f'i  f.j  f.j  r.l  n  N"J  O  O  O 

'  o  ©  o  O  o  O  o  o  o  o  o  o>  O  O  O  O  o  O  CJ  o  o  o  o  O 


■P 

•rH 

-p 

<C  M 

■P  W 

0  *rl  CJ 

Di 

•rH 

■P  CT'-P  CD 

•H 

cn 

•rl  -H  ^ 

'O 

•H 

■P  'O  Cb 

(0  M 

TU 

P  -rH  0 

4J  M 

HJ 

<L»  HJ  nj  4J 

■H  u 

w 

4J 

>  -C 

cn  cd 

0 

9H 

C  CTi  0)  -P 

•H 

E 

01 

0  -rl  -P  P 

TJ 

■P 

rH 

o  p  ro  o 

L4 

s: 

rH  > 

Q  0 

cn 

4J 

TIH  o  C 

CJ  9h 

•H 

0) 

c  oi  w  o 

CQ 

JH 

CTl 

ro  tjr -h  o 

0> 

c 

Olj 

0  0 

Id 

•  ^ 

eg 

S  -H 

o 

4J  4J 

■p 

c 

ro 

4H 

W  c 

ro 

c 

C  -H 

•M 

•H  +J 

ai 

£■ 

0> 

ro  to 

4H 

42 

4J  0) 

ro 

C  TU 

S) 

X 

0  A 

A 

0> 

■w 

O  1 

1 

*> 

T3 

3 

CQ  K 

ffi 

fc, 

c 

II 

II 

<c 

rc< 

iH 

— 

4J 

V) 

9 

4J 

3 

U 

•  • 

3 

CL 

0) 

44 

oo 

c 

a 

V 

4H 

u 

•  w* 

c 

3 

1 - 1 

ro 

C/5 

H 

o 

< 

a 

J 

c 

•  «|  Is 

1 «.  •  *.  1 

•  *K  1 

•-  3 

C  X)  JC  N  H 

0  -  &H  -XX 

o  (0  o  re  w-  _£ 


to 

C  ip 

to 

-p 

0 

•p 

•rl  0 

01 

•rH 

■p 

ro 

-C 

p  - 

O'’ 

-P  u 

ro  c 

■P  -H 

0.  D 

•H  QJ 

D..  p 

•rl  rU 

cc 

C  CD 

S  43 

E  0) 

0" 

•r!  2! 

E 

0  N 

C  *P  i — 1 

c 

-P 

tO  3  • 

O 

p  j  ro  h 

•H 

P  'O 

0)  C  CQ 

-P 

3  -rf  ro 

ro  a; 

o 

L  g  C 
0  3  -P 
N  E 
•p  -o 
m  X  <D 


X 

rt5  <C  ro  ro  X  13  03  U-U 
H3UIjL(Li(5,CCiD'OC0) 

rl  Ll  L  L  L  Ur I  IQ  m  H  rl  L 


ro  crt  w  oi 


H  fD-H 

0  X  C  X  3 

>1  P  P  0. 

0 

CJ  S.  OH 

N  -P  O  0  C 

p  x  ro  c 

0 

CD  -H 

0  'V  0  X  -rH 

row  -h 

03 

<  c 

M  -H  rH  C  X 

C  CO  rH 

r— 1 

•  0) 

M  rc  C  0  -rl  c 

•H  rH  iH  -H 

Ph 

CJip  Cl 

U  0  0  0 

x  ro  0  ro 

C  CQ  to 

CD  X  X  •»  0-,  O 

Exp 

1 

•rH 

<C  -H  4J  44 

x  -h  o  x 

rO  9"i  to 

•*  •'  C  •'  •  - 

0 

•p  o  ro 

c 

ro  JD  -rH 

ro 

0 

X  0  P  c 

<c 

tu 

r— ! 

0 

i  03  ro  ro 

z 

h  oro 

0  X 

rH 

LD  X 

a 

-P  Ci 

U 

X 

X  — *  U  0 

w 

44  C 

0  r-r  — 

N 

x  C 

Eh 

c  roo  -h 

N  r-H  »-l 

*• 

ro  H  ro  -p 

ro  ro  E 

-  X  N  X  rH 

N 

U  0  U 

M 

rH  4J  ro 

ro  ^  c  ^  x  x 

c 

w  cd  x  ro 

CQ  c  X 

X  C  P  0 

•H  <L) 

P  —  0  X 

u 

1  0 

0  > 

CQ 

1  0:  0) 

>  0  C  X 

X! 

TU 

C  X  0  X 

•  • 

iC  T3 

rH  X  O  O 

X 

0  S’-  0  x 

CD 

Z  rl  o 

••  0;  0  tro  C  0 

0  0 

ox  & 

« 

<C  ro  -p 

44  U  P  rH  -rH  rD 

•n  u 

W 

»-3  *H 

c 

U  0  •  Q 

Eh 

CQ  9H  tO 

(0  •• 

W  >  — •  CD 

CD 

O  <b 

rH  Q-i 

> 

a  x  +  h 

w 

Cm  0  -P 

X  0 

0/j 

Z  ^  H 

0 

W  X  >1 

0  0 

c 

M  CO 

w 

N  -P  X 

JH  • — 1 

in 

cq  ro  1 — 1  x 

40 

456 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


* 


<L> 


o 


<0 


© 

© 

© 

© 

o 

o 

© 

© 

© 

© 

© 

bD 

<0 

!X 

CO 

O' 

o 

T-i 

r-4 

ro 

<r 

bO 

© 

o 

o 

© 

O' 

O' 

O' 

O' 

O' 

o 

© 

© 

o 

© 

© 

© 

!\ 

o 

r-4 

ro 

© 

o 

© 

© 

© 

T-i 

T— 1 

T-I 

T— i 

T-i 

T— f 

'O 

o 

CO 

o- 

O' 

O' 

© 

T-i 

o 

o 

o 

© 

CD 

CD 

CD 

CD 

CD 

o 

o 

o 

CD 

CD 

o 

T-i 

T— 1 

X 

X 

X 

X 

X 

i — 

X 

i— 

b- 

b- 

b- 

o 

sD 

o 

□ 

□ 

CD 

o 

CD 

CD 

CD 

CD 

O 

o 

CD 

o 

CD 

o 

b- 

CD 

o 

i— i 

Y— 

tH 

h- 

T-i 

i — 

T-i 

CD 

CD 

CD 

CD 

CD 

CD 

CD 

CD 

CD 

CD 

i— 

T-I 

o 

y~ 

CD 

O 

•b 

CD 

X 

z-' 

o 

-T- 

CD 

CD 

o 

~r 

CD 

z 

CD 

Z 

CD 

Z 

Z 

z 

z 

z 

Z 

z 

Z 

z 

z 

— - 

z 

z 

CD 

CD 

'— • 

x 

z 

u 

iz 

X 

z 

LJ 

z 

u 

z 

LJ 

z 

x 

X 

z 

X 

z 

X 

z 

X 

z 

z 

-T' 

CD 

CO 

Z 

CO 

Z 

CO 

Z 

CO 

_2 

z 

w 

X 

x 

T 

~r 

z 

T 

— 

Z 

00 

X 

T-i 

Z 

b- 

-t- 

X 

i 

LJ 

X 

44 

LJ 

-i_ 

X 

X 

CO 

i — 

CO 

1 — 

CO 

X 

CO 

X 

CO 

X 

CO 

X 

i 

i- 

CO 

h- 

3 

H* 

3’ 

p 

3 

LJ 

< 

►— 

k- 1 

LJ 

o 

CD 

Z 

b~ 

z 

X 

z 

X 

z 

■ 

05 

■ 

z 

■ 

CO 

• 

X 

■ 

X 

■ 

3 

■ 

© 

■ 

z 

■ 

z 

m 

■v; 

■ 

z 

H- 

z 

z 

j 

b- 

— . 

-w' 

CO 

£0 

z 

X 

CO 

CD 

X 

X 

X 

z 

CD 

O 

CCi 

z 

z 

CD 

z 

k- i 

X 

.3 

z 

<1 

■ 

z 

z 

CO 

■ 

CO 

* 

CO 

■ 

CO 

X 

<r 

X 

<1 

CD 

CJ 

X 

LJ 

z 

n 

CD 

X 

z 

X 

CD 

CO 

k— i 

00 

C3 

CO 

<r 

b- 

■ 

3 

o- 

n 

w 

m 

X 

-TN. 

i! 

o 

I 

T-i 

!i 

o 

T-i 

ii 

o  \ 

t— i 

!i 

o 

<r 

ii 

© 

<1 

ii 

© 

CD 

i! 

© 

LJ 

ii 

o 

r— 1 

ii 

o 

_ i 

ii 

o 

iX 

ii 

© 

CO 

ii 

© 

CO 

ii 

© 

is 

ii 

© 

b- 

ii 

© 

< 

ii 

o 

CO  b~ 

CO 

o 

, 

z 

© 

'''' 

o 

■ 

o 

■ 

i 

© 

• 

i 

© 

■ 

© 

■ 

o 

■ 

© 

■ 

o 

■ 

© 

■ 

© 

■ 

© 

© 

© 

■ 

© 

© 

i 

o 

m 

© 

B 

f— 

i 

o 

z 

T— 1 

Z 

z 

T-i 

Z 

z 

t— i 

Z 

z 

T—i 

Z 

T“ 1 

z 

T-i 

Z 

T-i 

Z 

T— 1 

Z 

T-i 

Z 

T-i 

z 

T— 1 

T— i 

z 

T-i 

z 

T— i 

z 

t— i 

X 

z 

TT 

T— i 

h- 

3 

x 

T—i 

o 

o 

1! 

w 

© 

ii 

w 

© 

w 

© 

V 

w 

o 

© 

V, 

© 

© 

_ 

© 

© 

o 

© 

o 

o 

© 

ii 

z 

h-i 

o 

T— i 

© 

CO 

44 

Z  CO 

4k  Z 

CO 

4k 

Z 

CO 

44 

CO 

44  CO 

CO 

44 

CO 

4+ 

CO 

44 

CO 

44 

3 

44 

CO 

44 

3 

44 

3 

44 

3 

44 

Z 

3 

44 

k-i 

i— 1 

44 

b- 

X 

o 

<r 

o 

<X 

o  <r 

o 

<r 

o 

<1 

CD 

<L 

CD 

<r 

CD 

<x 

o 

<r 

CD 

<T 

o 

<r 

o 

<r 

CD 

<1 

CD 

<1 

o 

<r 

o 

<L 

X 

b- 

CD 

<r 

z 

CD 

b- 

(— 

J— 

b- 

b~ 

■ 

r-  r— 

X 

X 

X 

i — 

X 

X 

X 

k— 

X 

b-  X 

b- 

i- 

i— 

b- 

K  h- 

i~ 

b- 

i— 

b- 

h- 

b- 

h- 

b- 

1- 

h- 

K 

uC 

X 

X 

b- 

k-i 

i— 

H- 

LiJ 

o 

XXX 

O  L  14 

UJ 

CD  Li. 

x 

LJ 

CD 

Li. 

Cl 

O 

X 

LJ  CD 

L_  LJ 

CD 

X 

LJ  O 

X 

LJ  CD 

X 

x  o 

LUO 

X 

X 

o 

X 

X 

CD 

X 

X 

o 

X 

X 

CD 

X 

X  X 

O 

X 

CD 

X 

CD 

x 

X  .V 

X 

O 

_ 1 

CD 

k- 1 

-J 

X 

CD 

n  _J 

_J 

CD  i— i 

X 

_J 

CD 

t— i 

-1 

CD 

!— i 

_J 

■-i 

CD 

i— i 

X 

CD 

k-i 

_J  CD 

H-i 

CD 

»-•  _l  CD 

H-i 

X 

CD 

1— i 

X 

CD 

H 

X  CD 

1— 1 

X 

CD 

l-t 

X 

X 

CD 

i-i 

X 

z 

CD 

»— i 

i— 1 

X 

X 

CD 

>0 

CO 

O  r-4 

«? 

>0 

o  r  -4 

<r 

sD  © 

r-4 

*0 

© 

r-4 

<r 

o  r  -4 

<r 

© 

r-4 

<r 

© 

r-4 

© 

r  -4 

o 

r-4 

<r 

©  r-4  <■ 

o 

r-4 

<- 

© 

r-4 

o 

r-4  <r 

© 

r-4 

<r 

o 

r-4 

>0 

o  r-j 

sO 

CD 

o 

th  r-j 

'O 

O 

o 

t-H 

tH 

t-i 

r-4  r-4 

r-4 

r-4  ro 

ro 

ro 

fO 

x 

<*■ 

<r 

b0  UD 

b0 

-O 

'O 

'O 

X 

iX  fX 

CO 

CO  CO 

O' 

O' 

O' 

o 

o  © 

T— 1 

T-i 

T— i 

r-4 

r-4  r-4 

ro 

ro  ri 

<r 

«r 

bO  ill  b0 

bO 

<3 

'O 

'O  O 

r\ 

rs 

r\ 

r\ 

O' 

O' 

O' 

O' 

O' 

O' 

O'  O' 

O' 

O'  O' 

O' 

O' 

O' 

O' 

O'- 

O' 

O'  O' 

O' 

O' 

O' 

o- 

O' 

O' 

O' 

O' 

O'  O' 

O' 

O' 

O' 

© 

©  o 

o 

© 

o 

© 

©  © 

© 

©  © 

© 

o 

o 

©  © 

o 

o 

O 

o 

o 

o 

O 

o 

o 

© 

o 

© 

o 

o  © 

o 

o 

O 

o  © 

© 

o 

o  o 

o 

© 

© 

© 

©  © 

© 

o 

© 

© 

o  © 

© 

o  © 

T-i 

T-i 

tH 

T-i 

T— i 

T-i 

T^ 

T“ i 

t-: 

T-i 

T-i 

T-: 

T— i 

t4 

T-: 

T-i 

T-i 

T-i 

-r-i 

H 

T-i 

T—i 

T—I 

cn 

2 

2 

on 

C  4J 

2 

2 

2 

2 

2 

2 

c 

•H  X 

K 

w 

W 

2 

Eh 

2  [H 

U  dJ 

E-i 

t-i 

Eh 

Eh 

■^r 

£2 

CJ 

2  2  2 

•S2 

4J  > 

2 

2 

2 

hH 

+ 

2 

< 

2  0  2 

mJ 

w  c 

■K 

M 

ro 

M 

CNJ 

M 

— \ 

M 

M 

CJ 

O 

2 

2  a  0 

CJ 

-a 

0  0) 

■K 

0 

0 

•K 

0 

* 

0 

u 

2 

CJ 

2 

<  CJ 

2 

2 

s 

4J  o  D 

O 

2 

* 

2 

* 

2 

4c 

2 

2 

M 

>  ' 

2  M 

M 

UJ 

D  i-1 

— H 

0 

O 

O 

< 

2 

2 

>4 

2  2 

Q  M 

2 

D.  0  (C 

O 

2 

0 

-H 

0 

— H 

u  < 

Eh 

CJ 

2 

2  2  0 

2  O 

Eh 

4-1  4-1  > 

K 

2 

2 

2 

2 

2 

2 

< 

2 

O  2  < 

E-i 

t-i  2 

2 

D 

U 

W 

2 

E-i 

M 

2 

M 

2 

M 

E 

M  O 

0 

2 

<C 

Cm2 

C 

C  C 

0  a-  >, 

hH 

2 

Eh 

2 

Eh 

2 

Eh 

2 

Eh 

2 

Eh 

2 

CJ 

2  2  2 

2 

2 

2 

a  v-i 

Q 

Q 

a 

s 

2 

t4 

M 

2 

Eh 

M  2 

E4 

m  2 

Eh 

< 

2 

2 

2  2 

M 

0  i — 1 

2 

2 

2 

2 

2 

2  2 

2 

3c  2 

2 

S  2 

2  2 

Eh 

2 

2 

P-i 

2 

2  O 

4J  (U  U 

<C 

< 

< 

u 

2 

W 

w 

K 

2 

2 

2 

2 

2 

Eh  M  2 

2 

2 

2 

>  0 

2 

O 

2 

u 

U 

2 

U  CJ 

2 

c;  U 

2 

Q 

2 

2 

Eh 

Eh 

U  2 

2 

2 

s-i  D. 

CO 

a 

tc 

O 

2 

2  0 

2 

2  O 

2 

2  O 

t—j- 

O 

Cam 

a 

2  Eh 

0 

a)  >  E 

D 

2 

2 

2 

2 

2 

2 

2 

2 

M 

a 

E-i 

2 

2 

2  2 

2 

O  2 

Eh 

4J  i-l  a 

<L> 

W 

w 

w 

< 

2 

2 

Q 

2 

2 

Q  2 

2 

Q  2 

2 

c 

< 

2 

< 

< 

Eh  c  2 

< 

Eh  D 

2 

C  ro  C-4 

r— ! 

> 

> 

> 

O 

< 

C 

< 

T 

2 

2 

PQ  2 

2  i-Q 

•H  C 

X! 

<c 

< 

< 

2 

O 

O 

O 

2 

2 

2 

2  2 

2  Q 

0  -H  | 

(0 

CD 

CD 

2 

2 

2 

2 

2 

CJ 

U 

2  2 

2  C 

PQ 

'C 

X) 

no 

4-1 

•*- 

i  i  < 

> 

> 

> 

•rH 

O 

CM 

2 

X 

X 

X 

■2 

O 

O 

O 

>4  >4  « 

0) 

cu 

cu 

(U 

O 

2 

O 

2 

O  2 

2 

< 

2 

-H 

c 

a  cl  w 

CO 

CO 

CO 

X 

O 

2 

O 

2 

O  2 

O  2 

2 

0  > 

O 

U  2 

&4  E-4  E-4 

(D 

aj 

a; 

a 

— H 

2 

- 1 

2 

— 1  2 

-4  2 

O 

PQ  M 

2 

2  O 

2  2  2 

X 

X 

X 

c 

> 

> 

'> 

'  > 

2  rn 

2 

'  Q 

> 

-  ro 

2 

W  W  M 

a 

a.  a 

D 

U 

W 

2 

u 

w 

2 

u 

M 

W 

O'  M 

W 

CJ  i— 4 

H 

a 

2 

2 

CJ 

2  - 

M 

2  - 

P 

CD 

2 

2 

2 

Q 

2 

2 

a 

Q 

2  Q 

Q 

2  C 

D 

< 

< 

2 

Q 

2 

< 

< 

H 

M 

A 

p 

2  c 

H  (L 

c; 

CD 

2 

CD 

Q  CE  < 

CD 

Q 

2 

< 

2 

2 

2 

2 

2 

Xs 

2 

CD 

2 

2 

2 

U 

2 

CJ 

2 

U 

2  CJ 

Q 

2 

2 

2 

E4 

2 

O  U 

a  a 

2 

2 

2 

2 

a 

< 

2 

Q 

< 

2 

Q  < 

2 

a  < 

2 

Q 

Q 

a 

0 

O 

O 

2 

O 

2 

CQ  2  2 

2 

a  p 

P 

2 

F-i 

2 

2 

2 

U 

M 

2 

u 

M 

2  CJ 

M 

2  CJ 

M 

2 

< 

2 

2 

2 

2 

2 

X 

O 

2  D  1 — t 

c  c 

2 

2 

2 

•  • 

•  • 

,, 

,, 

CL 

U 

CO 

— 1 

CM 

&4 

2 

2 

O 

O 

2 

Q 

2 

2 

2 

O 

2 

> 

> 

> 

M 

W 

M 

W 

*T  •  *- 

•  V 

• • 

'  2 

_ 

• 

•'  D 

a 

p 

Dr.  Dobb’s  Journal,  Number  60,  October  1981 


41 

457 


page) 


42 

458 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


Dr.  Dobb’s  Clinic 

(Continued  from  page  7) 

very  similar  algorithm  appeared  in  the 
August,  1981,  issue  of  Byte. 

Decimal,  Subtracting  Binary 
Conversion  (DSBC) 

M.  Patton  Davis  of  Ann  Arbor,  MI 
sent  a  simple  conversion  routine  that 
relies  on  the  Z80’s  16- bit  subtract  in¬ 
struction  (Listing  6,  p.  ).  Davis  de¬ 
scribes  it : 

“The  method  employed  is  to  re¬ 
peatedly  subtract  decreasing 
powers  of  10  starting  with  the 
largest  that  can  be  contained  in 
16  bits,  i.e.,  10,000.  The  number 
of  successive  subtracts  thus  re¬ 
presents  the  decimal  multiplier 
for  that  power  of  ten,  and  con¬ 
verting  to  ASCII  merely  involves 
adding  30H  and  storing.  The 
routine  occupies  only  55  bytes; 
execution  times  vary  from  about 


500  cycles  (HL  =  0000H)  to 
approximately  1350  (HL= 
FFFFH).” 

Actually,  its  time  is  proportional  to 
the  sum  of  the  digits  in  the  result;  it 
would  be  slower  at  producing  9999  (36 
subtracts)  than  at  producing  32767  (25 
subtracts). 

Summary 

It’s  a  great  pleasure  to  watch  our 
readers  pounce  on  a  problem;  the  variety 
of  the  solutions,  and  the  insightful  ex¬ 
planations  that  accompany  them,  demon¬ 
strate  what  a  powerful  brain  trust  you  all 
represent.  Think  of  the  Clinic  whenever 
you  meet  a  computing  problem.  Not  only 
can  your  fellow  readers  solve  it,  they’ll 
enjoy  doing  so. 

Next  month  we’ll  have  suggestions 
for  taming  the  MX-80,  more  about  calen¬ 
dars,  and  a  fast  integer  square- root  rou¬ 
tine.  In  the  meantime,  consider  this  ques¬ 
tion  from  Jerry  Throckmorton  of 


Fairborn,  OH: 

“I  am  developing  some  business 
application  programs  in  which  I 
want  to  use  a  check  digit  algo¬ 
rithm  to  detect  data  entry  er¬ 
rors.  My  problem  is  in  locating 
and  selecting  the  “best”  algo¬ 
rithms. 

“Should  I  use  Modulus  10  or 
Modulus  1  1  and  should  I  weight 
the  digits  based  upon  an  arith¬ 
metic  progression,  a  geometric 
progression,  or  some  other 
scheme?  What  algorithms  are 
used  in  credit  card  numbers, 
bank  account  numbers,  etc.?  I 
need  some  good  information 
upon  which  to  base  a  decision. 

Can  you  help?”  *»j 

1  Tab,  J.  A.  and  Roginsky,  M.  L.  “uP  Algo¬ 
rithms  Make  BCD-Binary  Conversions  Super 
Fast,”  EDN,  Jan  5,  1977,  p.  46. 

(LISTING  ON  PAGE  36) 


BASIC-FORTH 

(Continued  from  page  13) 

The  program  listings  are  shown  on 
page  40.  This  program  was  coded  in  the 
Extended  BASIC  on  a  NOVA-3  comput¬ 
er  made  by  Data  General  Co.  It  would  be 
very  easy  to  modify  this  program  for  exe¬ 
cution  on  small  BASIC  computers.  The 
only  problem  which  might  arise  is  in 
the  area  of  string  functions  used  to  imple¬ 
ment  the  text  interpreter.  Some  modifica¬ 
tion  may  be  needed  depending  on  how 
string  variables  are  handled  and  how  sub¬ 
strings  are  extracted  and  concatenated. 
The  program  can  be  extended  or  modi¬ 
fied  to  suit  specific  applications.  The  area 


between  line  300  and  900  is  reserved  for 
additional  high-level  or  low-level  instruc¬ 
tions.  The  FORTH  interpreter  runs  slow¬ 
ly  under  BASIC,  but  not  terribly  so.  Its 
advantage  over  regular  FORTH  systems  is 
that  all  numbers  are  floating-point  num¬ 
bers,  and  most  of  the  transcendental 
functions  in  BASIC  are  available  for  inter¬ 
active  execution. 

The  main  purpose  of  this  BASIC- 
FORTH  is  educational  -  to  demonstrate 
the  basic  principles  involved  in  a  virtual 
FORTH  computer  such  as  the  dictionary, 
the  stacks,  and  the  interpreter.  FORTH  as 


a  programming  language  can  be  imple¬ 
mented  on  different  computers,  even  on 
top  of  BASIC  as  in  this  case.  The  program 
itself  is  also  useful  to  BASIC  program¬ 
mers  designing  small  control  systems 
using  these  low-cost  BASIC  computers. 


(LISTING  ON  PAGE  40) 


DDJ’s  responsive  readership  can 
give  you  invaluable  feedback  on 
your  ideas  and  innovations.  Find 
out  how  you  can  reach  them  by 
contacting  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


43 

459 


Uh  INTEREST 


by  Dave  Cortesi 


New  Hardware:  Large,  Small, 
Distributed. 

We  heard  this  month  of  several  new 
hardware  systems,  ranging  from  the  very 
large  to  the  very  small.  The  largest  is  the 
DPS- 8000  from  Ithaca  Intersystems. 
That’s  a  multi-user  system  based  on  the 
S-100  bus  and  the  Z8002  16-bit  chip. 
Ithaca  have  opted  for  a  new  operating 
system  called  COHERENT;  it  is  claimed 
to  provide  “complete  C  language  source 
compatibility  with  Edition  Seven  of 
UNIX.”  So  why  not  UNIX?  Pascal  and  C 
compilers  and  “standard  commands  and 
utilities  of  UNIX”  are  included;  prices  be¬ 
gin  at  $20,000. 

MicroDaSys  wrote  to  say  that  they 
have  their  “68 K  MiniFrame”  in  full  pro¬ 
duction.  It  contains  two  M68000  chips 
and  an  M6809  to  handle  the  I/O  chores. 
MicroDaSys  went  for  real  UNIX  version 
7;  they  include  translators  for  C, 
FORTRAN-77,  and  BASIC.  Prices  start 
at  “under  $12,000;”  a  hard-disk  system 
able  to  handle  6  users  costs  “under 
$20,000.” 

While  the  micro  makers  scale  their 
machinery  up,  an  old  mini- maker  is  mov¬ 
ing  down  into  the  desktop  market.  Data 
General  has  prepared  a  new  model 
MPT/ 100,  a  handsome  unit  that  resem¬ 
bles  a  slightly  bloated  H89.  It  contains 
64K  RAM,  two  double-density  5”  drives, 
and  two  serial  ports.  Its  software  is  based 
on  a  multi-tasking  monitor  called  MP/OS 
and  includes  FORTRAN  IV,  BASIC, 
Pascal,  and  an  assembler.  The  CPU  is 
Data  General’s  16-bit  microNOVA;  the 
system  costs  $5400. 

Have  we  gotten  in  range  of  your 
pocketbook  yet?  No?  Well,  Radio  Shack 
have  gotten  around  to  making  a  complete 
system  out  of  their  Pocket  Computer. 
$150  gets  you  an  L-shaped  nest  into 
which  the  little  gem  nestles  beside  a  tiny 
matrix  printer  and  a  cassette  interface.  If 
you  toss  in  another  $15,  they’ll  give  you 
a  “plush- lined  softcase”  to  carry  it 
in.  Radio  Shack  also  announced  a 
16-line  telecommunications  multiplexer. 
Through  it,  a  TRS-80  II  can  supply  data 
to  16  Videotex  terminals  or  other  TRS- 
80’s.  This  box  opens  all  sorts  of  intriguing 
possibilities  for  local  networking,  espe¬ 
cially  in  light  of  the  fact  that  the  Model  II 
can  also  communicate  with  an  IBM  main¬ 
frame  (see  last  month). 

Two  Reports  for  Software  Sellers 

The  National  Bureau  of  Standards  has 


a  publication  on  “language- independent 
and  machine-independent  criteria  for 
assessing  the  quality  of  floating  point 
arithmetic  operations  and  functions.”  It 
sounds  like  a  must  read  for  compiler  de¬ 
signers;  order  stock  number  003-003- 
02324-8  from  the  Superintendent  of 
Documents;  it  costs  $2.75.  People  who 
sell  software  might  be  curious  about  a 
$20  report,  “How  to  Copyright  Comput¬ 
er  Software,”  from  SOFTPROTEX. 

Hard  and  Soft  Books 

Readers  deep  into  hardware  should 
be  interested  in  Intuitive  IC  Electronics 
by  T.  M.  Frederiksen  (McGraw-Hill, 
$18.50).  The  book  claims  to  have  “tho¬ 
rough  coverage  of  the  internal  mechan¬ 
isms  common  to  all  IC  devices,”  to  use 
“an  absolute  minimum”  of  mathematics, 
and  to  require  “no  prior  knowledge  of 
semiconductors.” 

Software  folks,  especially  those  in¬ 
volved  in  control  applications,  might  in¬ 
vestigate  Real  Time  Programming  by  C.  C. 
Foster  (Addison- Wesley,  $9.00).  It  pro¬ 
vides  “a  broad  survey  of  the  problems  in¬ 
volved  in  trying  to  connect  a  digital  com¬ 
puter  to  the  real  world,”  and  contains 
“practical  and  applied  exercises”  including 
a  barbershop  quartet  of  computers  (?!). 

Two  Compendia 

Those  indefatigable  compilers  at 
Datapro  have  collected  profiles  of  2,000 
software  products  and  1,000  vendors  in 
their  Directory  of  Microcomputer  Soft¬ 
ware.  Products  are  indexed  by  applica¬ 
tion  areas,  name,  system,  and  vendor; 
vendors  are  indexed  by  state  and  zip 
code.  User  ratings  of  the  products  have 
been  assembled  and  tabulated.  The  whole 
stupendous  compendium,  with  12  month¬ 
ly  supplements,  costs  $300.  If  we  ran  a 
computer  store  we’d  keep  one  of  these 
behind  the  counter. 

If  you  have  a  collection  of  magazine 
back-issues,  you  might  want  to  know  of 
yet  another  diskette-based  article  index. 
FYI  has  published  this  one;  it  contains 
984  entries  indexing  articles  from  Dr. 
Dobb’s  and  most  of  the  other  micro  jour¬ 
nals.  The  index  is  available  for  CP/ M  sys¬ 
tems  in  both  8”  and  5”  formats;  it’s  $30 
alone  or  $70  with  the  company’s  IC-IRS 
retrieval  software. 

Math  Libraries  for  All 

The  mail  brought  us  happy  news  of 
a  math  library  that  has  been  upgraded  for 
the  Cray-1.  We  can’t  imagine  why  they 
told  us,  but  we’re  happy  to  spread  the 


word.  If  your  Cray-1  has  been  gathering 
dust  in  the  bedroom  for  lack  of  a  math 
package,  call  us  for  details. 

On  the  other  hand,  you  might  have  a 
CP/M  system  that  needs  a  real  math  pack¬ 
age.  One  of  those  came  in  the  same  mail; 
the  Mathematical  Programming  System 
for  Micros  from  MPI.  MPSM  is  “capable 
of  solving  linear  and  separable  program¬ 
ming  problems,”  and  can  handle  “prob¬ 
lems  with  literally  thousands  of  variables 
and  constraints  using  a  64K  computer.” 
The  package  is  said  to  resemble  IBM’s 
package  MPSX;it  costs  $750. 

General  Software  for  CP/M 

At  this  year’s  Computer  Faire,  Gary 
Kildall  promised  a  sophisticated  program 
to  convert  8080  code  to  8086  code.  Now 
Digital  Research  has  announced  XLT86. 

It  reads  an  ASM  or  MAC  source  file  and 
writes  a  source  file  for  ASM-86,  the  as¬ 
sembler  in  CP/M-86.  The  program  is 
said  to  perform  “extensive  data  flow 
analysis  to  determine  register  usage 
throughout  the  original  program.  The  in¬ 
formation  collected  ...  is  used  during 
translation  to  eliminate  unnecessary  flag 
save  and  restore  operations.”  The  CP/M 
version  of  XLT86  is  priced  at  $  1 50;  a  ver¬ 
sion  to  run  on  the  DEC  VAX  series  (!) 
costs  $8000  (!!). 

Three  smaller  companies  turned  up 
with  CP/M  add-ons.  “Unica”  from 
Knowlogy  is  said  to  be  a  “package  of 
software  instruments”  (nice  phrasing, 
that)  which  brings  something  of  the  capa¬ 
bilities  of  UNIX  to  CP/M.  The  package 
contains  a  number  of  UNIX-like  com¬ 
mands  and  a  structured  assembler;  it  re¬ 
quires  a  Z80  and  CP/M  2.x  and  costs 
$200.  Ficomp  tells  us  of  some  nice 
directory  utilities,  the  most  interesting 
of  which  keeps  track  of  a  version  number 
for  each  file  on  a  disk.  And  Southern 
Computer  Systems  have  an  ISIS  disk  utili¬ 
ty  for  CP/M;  with  it  you  can  read  the 
disks  from  the  Intel  User  Library,  or 
write  files  to  be  read  by  an  ISIS  system. 

5  Compilers, 4  Systems,  3  Languages 

This,  it  seems,  is  a  good  month  for 
compilers.  We’ve  got  compilers  for 
BASIC,  COBOL,  and  Pascal  on  a  variety 
of  hardware  and  software  systems.  The 
first  notice  out  of  the  pile  came  from 
Radio  Shack.  It  announced  the  RSBASIC 
development  system  for  the  Models  I  and 
III.  Its  centerpiece  is  a  compiler  that  con¬ 
verts  a  program  in  a  “business-oriented 
BASIC”  -  not  compatible  with  normal 


44 

460 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


Contact  Points 

Dr.  Gary  Bitter,  Arizona  State  University, 
203  Payne,  Tempc,  AZ  85287;  (602)  965- 
3322. 

Data  General,  Route  9,  Westboro,  MA 
01581 ;  (617)  366-8911. 

Datapro  Research  Corporation,  1805  Under¬ 
wood  Blvd.,  Delran,  NJ  08075;  (609)  764- 
0100. 

Digital  Research,  POB  579.  Pacific  Grove, 
CA  93950;  (408)  649-3896. 

Ellis  Computing,  600  41st  Ave.,  San  Fran¬ 
cisco,  CA  94121 ;  (415)  751-1522. 

Ficomp,  Inc.,  3017  Talking  Rock  Drive, 
Fairfax,  VA  22031;  (703)  280-1394. 

FYI,  Inc.,  POB  10998  #615,  Austin,  TX 
78766. 

Ithaca  Intersystems,  1650  Hanshaw  Road, 
Ithaca,  NY  14850;  (607)  257-0190.  Or,  58 
Crouch  Hall  Road,  London  N8  8HG,  U.K. 
Knowlogy,  POB  283,  Wilsonville,  OR 
97070;  (503)  635-5701 . 


Micro-Ap,  7033  Village  Parkway,  Suite  206, 
Dublin,  CA  94566;  (415)  828-6697. 
MicroDaSys.  Inc.,  POB  36215,  Los  Anseles, 
CA  90036;  (213)  731-0876. 

MPI.  7602  Pin  Oak  Drive,  Humble,  TX 
77338. 

Osborne  Computer  Corporation,  26500 
Corporate  Ave.,  Hayward,  CA  94545;  (415) 
887-8080. 

Phase  One,  7700  Edgewater  Drive,  Suite 
830,  Oakland,  CA  94621;  (415)  562-8085. 
SOFTPROTEX,  POB  271,  Belmont,  CA 
94002. 

Southern  Computer  Systems,  POB  3373A, 
Birmingham,  AL;  (205)  933-1659. 
Superintendent  of  Documents,  U.S.  Govern¬ 
ment  Printing  Office,  Washington,  D.C. 
20402. 

TSC,  POB  2570,  West  Lafayette,  IN  47906; 
(317)  463-2502. 

Vancouver  Amateur  Digital  Communica¬ 
tions  Group:  contact  Hugh  Pctt  (VE3I  LL), 
36  Lismcr  Cr.,  Kanata,  ON  K2K  1A2. 


TRS-80  BASIC  —  into  a  p-code  repre¬ 
sentation.  A  run-time  interpreter  exe¬ 
cutes  the  compiled  code,  and  a  special 
purpose  program  editor  is  included  in  the 
SI 50  price. 

Then  we  heard  of  a  new  release  of 
S-BASIC  for  CP/M  systems  from  Micro- 
Ap.  This  $300  business  BASIC  has  been 
enhanced  with  a  set  of  “ALGOL-like” 
control  constructs;  While-Do,  Repeat- 
Until,  and  Case.  It  supports  nested  and 
recursive  functions  and  procedures;  it 
adds  fixed-point  BCD  numbers  to  the 
usual  complement  of  data  types;  and  it 
can  dynamically  assign  the  destination  of 
I/O  at  run  time. 

Ellis  Computing  chimed  in  with  Edi¬ 
tion  II  of  their  Nevada  COBOL  compiler. 
We  can’t  tell  which  of  the  features  listed 
in  the  press  release  are  new  to  this  Edi¬ 
tion,  but  in  sum  they  paint  a  picture  of  a 
very  complete  subset  of  ANSI  COBOL, 
especially  considering  the  $150  price. 

And  we  got  news  of  two  new  Pascal 
implementations.  One  is  an  addition  to 
OASIS  from  Phase  One;  it  claims  to  be 
modelled  on  UCSD  Pascal,  with  improve¬ 
ments.  One  improvement  that  caught  our 
eye  was  that  this  compiler  does  not  re¬ 
strict  the  order  of  declarations;  con¬ 
stants,  types,  variables  and  procedures 
may  be  grouped  in  any  order.  The  rigid 
sequence  imposed  by  one-pass  compiler 
design  irritates  us  every  time  we  use 
Pascal;  it’s  nice  to  find  an  implementation 
that  removes  it.  The  $450  compiler  pro¬ 
duces  linkable  machine  code. 

TSC  turned  up  with  another,  equally 
nice  Pascal  for  the  FLEX  and  UniFLEX 
operating  systems.  It  compiles  to  assem¬ 
bly  source  code  for  the  6809.  This  im¬ 
plementation  has  16-digit  numeric  pre¬ 
cision  and  distinguishes  names  as  long  as 
160  characters,  two  features  we  com¬ 
mend  to  other  designers.  TSC  chose  to 
implement  the  file  I/O  syntax  that  Wirth 
specified,  instead  of  making  random  ex¬ 
tensions  to  the  read  and  write  procedures 
in  the  name  of  “simplicity.”  Good  for 
them. 

Late  News  From  IBM 

On  August  12th,  IBM  announced  the 
IBM  Personal  Computer,  a  small  home 
machine.  It  will  be  sold,  IBM  announced, 
through  Computerland  stores  and  Sears 
Business  Machines  outlets.  The  machine 
consists  of  a  console  with  keyboard,  a 
separate  video  monitor  (which  may  be  a 
home  TV),  and  cassette  and  disk  units.  It 
uses  5-inch  disks;  it’s  apparently  limited 


to  having  only  two  of  them  as  the  maxi¬ 
mum  disk  storage  is  given  as  320  KB. 

We  weren’t  told  what  kind  of  CPU 
the  Personal  Computer  uses,  but  we  have 
several  clues  in  the  software  it  supports. 
The  machine  will  use  both  CP/M  and  the 
UCSD  Pascal  system.  Its  main  program¬ 
ming  language  is  Microsoft  BASIC,  en¬ 
hanced  with  statements  for  color  control. 
The  application  packages  available  initial¬ 
ly  include  accounting  software  from 
Peachtree,  VisiCalc  (tm)  from  Personal 
Software,  and  communications  software. 

The  prices  quoted  for  the  machine 
range  from  $1600  for  a  16K  starter  sys¬ 
tem  up  to  $6300  for  a  machine  with  two 
disks  and  256K  of  storage.  In  what 
we  suspect  will  prove  to  be  a  very  wise 
move,  the  company  will  sell  the  machine 
at  a  discount  to  its  employees.  That  will 
create  in  short  order  the  pool  of  exper¬ 
ienced,  talented  users  that  it  took  other 
makers  years  to  develop. 

This  machine,  not  the  System  23 
Datamaster  we  described  last  month,  is 
IBM’s  entry  into  the  personal  market.  Of 
the  Datamaster’s  $10,000  price  we  said, 
“that  rushing  sound  you  hear  is  an  in¬ 
dustry  sighing  in  relief.”  We  were  over- 
hasty  there;  that  red  glow  you  see  in  the 
west  is  us  blushing.  Even  so,  we’re  excited 
about  this  announcement.  IBM’s  presence 
in  the  market  will  intensify  competition; 
the  standards  of  support  and  documenta¬ 
tion  will  go  up  and  prices  will  go  down  as 
the  other  makers  prepare  to  meet  the 
challenge.  BSj 


The  Conference  Tree 

(Continued  from  page  15) 

Conclusion 

We  are  satisfied  that  The  Conference 
Tree  meets  its  major  design  goals  of  versa¬ 
tility,  low  cost,  and  ease  of  use.  Learning 
is  painless  enough  that  the  system  is  ac¬ 
ceptable  as  a  party  toy  for  people  who 
have  never  used  any  computer  before.  It 
works  equally  well  for  more  serious  uses, 
such  as  the  ongoing  public  computer  con¬ 
ference  run  by  the  FORTH  Interest  Group. 
A  conferencing  system  can  often  be  set  up 
to  use  a  computer’s  and  phone  line’s  idle 
time,  for  no  extra  cost  except  electricity. 
All  calls  at  the  computer  are  incoming. 

The  biggest  limitation  on  the  use  of 
this  and  other  telecommunications  for  the 
general  public  is  the  availability  of  termi¬ 
nals.  Most  people  will  not  invest  four  to 
five  hundred  dollars  or  more  on  unfamil¬ 
iar  equipment  with  unknown  usefulness  to 
them.  We  are  considering  renting  out  low- 
cost  terminals  to  allow  computer  commu¬ 
nication  with  a  low  entry  fee. 

The  two  original  Conference  Tree  sys¬ 
tems  run  by  CommuniTree  Group,  are  at 
(415)526-7733  and  (415)  928-0641 ;  these 
have  referrals  to  others.  The  FORTH  con¬ 
ference  is  at  (415)  538-3580.  Use  a  300 
or  110  baud  modem,  and  type  two  car¬ 
riage  returns  to  start;  then  the  system  is 
self-instructing.  Or  for  more  information 
contact  CommuniTree  Group,  470  Castro 
St.,  Suite  207-3002,  San  Francisco,  CA 
94114,  (415)474-0933  (voice). 


Dr.  Dobb’s  Journal,  Number  60,  October  1981 


45 

461 


IY, WAYOUT 
I X , FLAG 
HL,CODBUF+l 
A,  (HL) 


NZ , QWOP 
A, (LSTOBJ) 


DT^V  T  .SXOO.nCaS 

R.  UOBB’S  lOURNAL 

For  Users  of  Small  Computer  Systems  w 

Number  61  November  1981  Volume  6,  Issue  11 


A  Clinic  for 
Ailing 

Algorithms . . . 

and  Late- 
Breaking 
Product  News 


ADVEN80:  An  Advanced  System 
for  Developing  “Adventures” 

Peter  D.  Scargi/I 

North  Star  Terminal  Programs 

Richard  Blessing 

Small  VM:  Nucleus  of  a  Portable 
Software  Development  Environment 

J.  E.  Hendrix 

Small-c  Grows  Up 

Richard  Roth 

plus  more! 


DrD 


LyR.  LvOBB  S  IOURNAL 

For  Users  of  Small  Computer  Systems  / 


November  1981  Volume  6,  Issue  11,  Number  61 


CONTENTS 


ADVEN-80  —  An  Advanced  Adventure 

Development  System .  8 

by  Peter  D.  Scargill 

Terminal  Programs  for  North  Star . 28 

by  Richard  Blessing 

Small  VM,  Nucleus  of  a  Portable 

Software  Development  System . 34 

by  J.  E.  Hendrix 

Small-C  Grows  Up . 46 

by  Richard  Roth 


The  Hacker  Papers . 52 

by  “Gandalf"  and  others 

Letters .  4 

Of  Interest .  6 

Dr.  Dobb’s  Clinic . 58 


©  1981  by  People’s  Computer  Company  unless  otherwise  noted  on 
specific  articles.  All  rights  reserved. 


Editor,  Marlin  Ouverson 
Assistant  Editor,  Julie  Anton 
Contributing  Editors,  Dave  Caulkins 
and  Dave  Cortesi 


Marketing  Director,  Craig  S.  Harper 
Advertising  Sates,  Laird  Foshay 
Circulation  Manager,  Peter  Clark 
Circulation  Assistant,  Susan  Hinton 


Art  Director,  Clifford  West 
Artist,  Barbara  Ruzgerian 
Typesetter,  Renny  Wiggins 
Proofreader,  Nancy  Heubach 


Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per  year  by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real,  Menlo 
Park,  CA  9402 S.  Second  class  postage  paid  at  Menlo  Park,  California  94025  and  additional  entry  points.  Address  correction  requested.  Post¬ 
master:  send  form  3579  to  Box  E,  Menlo  Park,  California  94025. 


EDITORIAL 


People’s  Computer  Company  is  dedicated  to  computers 
(and  computing,  a  very  different  matter)  for  people.  The 
beneficial  result  of  this  credo  will  be  a  much  friendlier  and 
more  pleasant  future  than  that  formed  out  of  the  concept 
of  keeping  these  powerful  machines  reserved  for  companies. 
This  is  an  admitted  bias,  however,  and  we  must  not  allow  it 
to  prevent  us  from  taking  a  close  look  at  the  technological 
growing  pains  some  people  experience.  Are  they  brought 
about  by  computing?  Or  perhaps  these  are  personality- 
related  events  which  would  manifest  regardless  of  the  en¬ 
vironment.  What  the  technology-laden  future  holds  for  hu¬ 
manity  is  a  question  we  may  well  address. 

What,  specifically,  will  computers  do  for  people?  We 
suspect  their  potential  will  only  be  fully  maximized  when 
they  are  integrated  into  a  home  information/management/ 
entertainment  system.  So  we  assume  that  telecommunica¬ 
tions  research  and  the  issues  of  compatibility  (of  both  soft¬ 
ware  and  hardware)  are  of  prime  importance.  But  when 
these  are  realized,  will  it  isolate  individuals  from  contact 
with  one  another,  or  will  it  bring  families,  local  communi¬ 
ties  and  national  and  global  concerns  closer  together?  We 


believe  the  latter. 

What  about  the  research  currently  being  expended  into 
artificial  intelligence,  into  programs  to  analyze  personality 
or  to  be  used  as  “self  improvement”  tools.  Will  these  help 
people  to  relate  to  one  another  more  easily,  to  make  broad¬ 
er  social  and  personal  contacts,  or  will  it  merely  make  it 
simpler  to  relate  to  machines  than  to  humans? 

The  answers  to  these  issues  are  complex  and  vary  wide¬ 
ly  depending  upon  who  one  asks.  But,  all  theory  aside, 
what  will  happen  when  personal  computing  is  a  reality  for 
the  majority  of  our  population?  All  we  can  do  is  take  a 
glimpse  at  what  is  happening  now.  Whether  the  sampling 
available  today  is  indicative  of  tomorrow  is  itself  a  moot 
topic.  In  the  interests  of  those  who  feel  these  subjects  must 
be  addressed,  this  issue  includes  “The  Hacker  Papers.” 
First  published  in  Psychology  Today,  it  consists  of  an  on¬ 
line  dialogue  of  computer  hobbyists  and  students.  Because 
it  addresses  many  key  points  from  a  firsthand  view,  we  con¬ 
sider  it  very  worthy  of  publication  in  these  pages. 

May  it  inspire  much  thought  and  comment  on  the  part 
of  the  broad  DDJ  audience. . . .  -MDO 


Subscription  Rates:  $25  per  year  within  the 
United  States;  $44  for  first  class  to  Canada  and 
Mexico;  $62  for  airmail  to  other  countries. 
Payment  must  be  in  U.S.  dollars,  drawn  on  a 
U.S.  bank. 


Writer’s  Guidelines:  All  items  should  be  typed, 
double-spaced  on  white  paper.  Listings  should 
be  produced  by  the  computer,  using  a  fresh, 
dark  ribbon  on  continuous  white  paper.  Please 
avoid  printing  on  perforations.  Payment  is  in 
contributor’s  copies.  Requests  to  review  galleys 
must  accompany  the  manuscript  when  it  is 
first  submitted.  Authors  may  receive  a  copy 
of  the  complete  writer’s  guidelines  by  sending 
a  self-addressed,  stamped  envelope. 


Donating  Subscribers  Contributing  Sub¬ 
scriber:  $  50/year  ($25  tax  deductible).  Retain¬ 
ing  Subscriber:  $75/year  ($50  tax  deductible). 
Sustaining  Subscriber:  $1 00/year  ($75  tax  de¬ 
ductible).  Lifetime  Subscriber:  $1000  ($800 
tax  deductible).  Corporate  Subscriber:  $500/ 
year  ($400  tax  deductible,  receives  five  one- 
year  subscriptions). 

Contributing  Subscribers:  Eric  H.  Johnson, 
Jerry  Horn,  Edward  W.  Carr,  Steven  Fisher, 
Thomas  H.  Grohne,  G.  V.  Elkins,  Robert  M. 
Connors,  William  J.  McEown,  Robert  C. 
Luckey,  Kim  Leary,  Robert  N.  Stabler,  DeWitt 
S.  Brown,  John  B.  Palmer,  E.  Glion  Curtis,  Jack 
Miller,  Burks  A  Smith,  Transdata  Corporation, 
Mark  Ketter,  John  W.  Campbell,  Friden  Mail¬ 


ing  Equipment,  Howard  E.  Decker,  Jim  Wilson, 
Frank  Lawyer.  Retaining  Subscribers:  Osamu 
Shimizu,  Scott  B.  Guthery,  Robert  L.  Edens, 
Titus  Purdin.  Sustaining  Subscribers:  Gordon 
Eubanks,  Jr.  and  Pete  Roberts.  Lifetime: 
Michael  S.  Zick. 

Foreign  Distributors  UK  &  Europe:  lp  En¬ 
terprises,  8/1 1  Cambridge  House,  Cambridge 
Road,  Barking,  Essex,  1G11  8NT,  England 
(Tel.  01-591-6511,  TLX  892395).  Hofacker- 
Verlag,  Tegernseer  Strass  18,  D-8150  Holz- 
kirchen.  West  Germany.  Asia  &  Australia: 
Computer  Store,  POB  31-261,  22B  Milford 
Road,  Milford,  Auckland  9,  New  Zealand. 
ASCII  Publishing  Co.,  Ltd.,  Aoyama  Building 
5F,  5-16-1  Minami  Aoyama,  Minato-ku, 
Tokyo  107,  Japan. 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 
464 


3 


LETTERS 


Who’s  On  FORTH? 

Dear  Marlin: 

Congratulations  on  the  very  fine  spe¬ 
cial  FORTH  issue  of  DDJ.  It  was  refresh¬ 
ing  to  read  som  e  new  things  about  FORTH 
that  were  not  muddled  up  with  the  usual 
FORTH  Interest  Group  hyperbole.  I  am 
sure  that  the  articles  will  be  quoted  and 
reprinted  for  years  to  come. 

I  would  like  to  point  out  a  slight 
problem  with  the  FORTH  Decompiler 
listing  that  may  cause  trouble  for  some 
readers.  Somewhere  between  my  line 
printer  and  page  5 1  of  the  DDJ  final 
product,  a  smudge  appeared  to  the  right 
of  the  in  line  14  of  screen  35  that 
could  be  mistakenly  taken  for  an  apos¬ 
trophe  or  a  comma.  Either  one  is  a  legal 
operator  in  FORTH,  but  would  cause  the 
program  to  fail. 

Sincerely  yours, 

Ray  Duncan 

Laboratory  Microsystems 
4147  Beethoven  Street 
Los  Angeles,  CA  90066 

Dear  Sirs: 

The  design  of  FORTH  presents  vir¬ 
tues  and  vices  which  reflect  the  time  and 
place  when  it  sprung. 

1.  FORTH  provided  a  unique  solu¬ 
tion  to  the  dilemma  of  choosing  between 
an  inefficient  interpretive  language,  and 
the  alternative  of  compilers  and  assem¬ 
blers  which  seem  to  require  a  debugging 
cycle  of  significant  time  spent  in  editing, 
recompiling,  and  re-creating  the  test  en¬ 
vironment.  In  contrast,  FORTH  offers  an 
environment  allowing  editing,  deletion, 
and  recompilation  of  routines,  without 
disturbing  the  stack.  (Routines  will  only 
be  disturbed  if  they  were  defined  after 
the  one  which  one  desires  to  re-compile.) 
And  it  allows  direct  testing  of  routines  at 
all  levels,  using  parameters  which  may  be 
easily  set  up  on  the  stack. 

2.  Its  reverse  Polish  notation  is  prob¬ 
ably  primarily  a  reflection  of  the  needs 
for  compilation  in  minimum  memory  and 
minimum  time.  (1  do  not  regard  RPN  as 
a  handicap  to  the  professional  program¬ 
mer.  I  do  regard  it  as  a  significant  deter¬ 
rent  to  the  casual  amateur.) 

3.  Its  extreme  stack  orientation  sug¬ 
gests  strongly  that  the  PDP  machines  on 
which  it  was  developed  are  strongly  stack 
oriented,  and  it  was  developed  for  func¬ 
tions  which  are  particularly  suited  to 
stack  solutions. 

4.  It  was  developed  in  a  time  of  ex¬ 
pensive  memory  (by  today’s  standards), 


and  consequently  necessarily  generates 
very  compact  code. 

Its  stack  approach  is  fine  for  prob¬ 
lems  in  which  most  subroutines  functions 
will  be  using  only  results  placed  near  the 
top  of  the  stack.  My  experience  indicates 
that  for  systems  programming  and  com¬ 
mercial  data  processing  this  is  generally 
not  the  case.  My  experience  suggests  that 
we  will  often  want  to  use  a  few  variables 
which  cannot  conveniently  be  passed  on 
the  stack.  Well,  FORTH  does  provide 
named  variables.  But  I  find  locality  of  de¬ 
finition  and  dynamic  allocation  highly  de¬ 
sirable.  At  the  lowest  level,  variables  on 
the  stack  will  provide  locality  of  defini¬ 
tion  and  dynamic  allocation;  and  at  the 
highest  level  both  of  these  considerations 
lose  their  force,  but  I  think  there  is  a  sub¬ 
stantial  intermediate  area. 

I  think  the  stack  and  global  variable 
approach  also  leaves  much  to  be  desired 
in  terms  of  record  handling. 

I  don’t  believe  that  changes  provid¬ 
ing  improved  variable  handling,  and  for 
that  matter  an  optional  algebraic  passer, 
are  incompatible  with  the  essential  virtue 
of  FORTH,  which  is  its  easy  code-and- 
test  cycle. 

Bill  Bunn 

Sen.  Systems  Analyst 
P.  O.  Box  67 
Covelo,  CA  95428 

The  Little  Engine  That  Couldn't 

Sirs: 

I  need  help.  Nearly  three  years  ago, 
I  plunked  my  money  down  on  a  Western 
Digital  Pascal  MicroEngine.  When  it  final¬ 
ly  came,  it  did  not  work  right,  and  several 
trips  in  for  warranty  service,  and  several 
upgrades,  have  not  significantly  improved 
matters.  Mean  time  between  failures  is 
still  on  the  order  of  five  minutes. 

The  problem  is  somewhere  in  the 
disk  controller  DMA  path,  that  intermit¬ 
tently  trashes  the  data,  and  only  last 
month  did  I  finally  get  conclusive  proof 
that  it  was  a  hardware  problem,  not  en¬ 
vironmental. 

I  have  several  options:  I  can  send  it 
back  to  WD  for  yet  another  service  (this 
time  out  of  warranty,  so  at  much  bucks); 
maybe  this  time  they  will  fix  it,  and  may¬ 
be  it  will  refuse  to  fail  for  them.  Or  (may¬ 
be  and)  I  can  program  around  the  prob¬ 
lem.  Software  is  my  bag,  so  I  like  that 
option.  Unfortunately,  the  MicroEngine 
came  without  documentation  (no  source). 
1  sell  software  that  way  too,  but  $5  is  lots 
less  to  throw  away  if  it  does  not  work 


(however,  mine  works).  To  fix  the  soft¬ 
ware,  I  can: 

1.  Buy  the  source  for  $x,xxx.  Double  the 
cost  of  the  computer  to  make  it  run. 
Not  attractive. 

2.  Decompile  the  system.  Could  be  done, 
and  the  decompiler  would  be  (possibly) 
marketable,  but  lots  of  time.  In  the 
long  run,  probably  more  costly  than 
buying  source. 

3.  Rewrite  system  for  version  II  (I  have 
access  to  source).  Would  mean  trying 
to  figure  out  the  differences.  Less 
work,  but  still  a  pain.  It  would  be 
easier  if  I  had  help,  which  brings  me  to 

4.  Find  someone  who  has  paid  for  the 
source,  who  would  be  willing  to  re¬ 
compile  it  with  a  disk  driver  that  I 
write  (no  need  to  violate  nondisclo¬ 
sure;  just  give  me  the  compiled  object 
code). 

Any  takers?  I  would  be  happy  to  bar¬ 
ter  services  (ask  anyone  about  my  soft¬ 
ware  quality)  for  the  favor. 

Tom  Pittman 
P.  O.  Box  6539 
San  Jose,  CA  95  150 

Oh  Say,  Can  I  C! 

Dear  DDJ, 

Add  me  to  the  list  of  Small-c  users. 
I’m  lazy,  though,  and  didn’t  copy  it  from 
Ron  Cain’s  articles,  but  bought  object 
and  source  code  for  CP/M  from  the  Code 
Works  for  less  than  it  would  cost  me  to 
type  it  in. 

The  reason  I  am  writing  is  that  I 
want  to  share  with  your  readers  a  few 
simple  features  I  added.  As  1  modified 
the  compiler  to  handle  constant  evalua¬ 
tion,  multi-dimensional  arrays,  struc¬ 
tures,  and  more,  1  soon  filled  all  48K  of 
my  memory.  Since  I  have  more  addi¬ 
tions  planned,  I  either  had  to  do  a  major 
rewrite  (i.e.,  different  algorithms)  or  try 
to  compact  somewhere.  As  the  latter 
seemed  easiest  and  my  expected  additions 
won’t  need  a  lot  of  space.  I  opted  for  it. 
The  first  thing  I  did  was  write  a  program 
(in  Small-c,  of  course)  to  compress  the 
assembly  code  produced  by  the  compiler, 
removing  redundant  POPs  and  PUSHes, 
changing  certain  addition  operations  into 
simple  increments,  etc.  This  removed 
about  2K  from  the  compiler.  Next,  I 
reduced  the  size  of  the  literal  pool  storage 
by  dumping  the  pool  to  the  output  file  at 
the  end  of  each  function  and  then  re¬ 
initializing  it.  The  works  because  only 
code  generates  literals  and  code  occurs 
(Continued  on  page  51 J 


4 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 

465 


OF  INTEREST 


Pegasus  Not  Repulsive 

In  August  we  mentioned  a  BASIC 
compiler  for  OSI  systems  from  Pegasus 
Software.  It  allowed  coding  GOTOs  to 
absolute  addresses,  and  we  called  that  idea 
“repulsive.”  We  certainly  did  not  intend 
the  adjective  to  apply  to  either  the  entire 
product  or  to  its  publisher.  Reader  John 
Fuller  understood  that,  but  he  wrote  to 
defend  Pegasus’  product  anyway.  The 
OSI  software  environment  is  fairly  primi¬ 
tive,  he  pointed  out,  and  such  features  are 
necessary  in  it.  He  offers  the  testimonial 
that  “Pegasus  Software  is  the  main  reason 
I  have  held  onto  my  OSI  computer.” 

Input  on  Output 

Notices  have  come  to  us  of  several 
sources  that  could  help  readers  who  sell 
or  buy  professionally.  For  a  start,  Micro- 
Serve  produce  a  Software  Vendor  Direc¬ 
tory  of  200  pages,  said  to  list  1 000  ven¬ 
dors  and  4000  products.  Vendors  are 
cross-referenced  to  hardware  and  operat¬ 
ing  system  types.  The  single-copy  price  is 
$58;  a  subscription  covering  two  semi¬ 
annual  revisions  is  $  1 00. 

Commodore  is  now  preparing  the 
second  edition  of  their  Software  Encyclo¬ 
pedia,  a  listing  of  products  for  the  PET 
and  CBM  machines.  The  vendors  are  not 
charged  for  a  listing,  but  they  have  to 
satisfy  Commodore  of  the  suitability  of 
their  product. 

Irv  Brechner  of  Irv  Brechner  Enter¬ 
prises  sent  us  a  copy  of  his  report,  Com¬ 
puter  Store  Advertising.  The  $25  report 
discusses  how  a  computer  store  (or  any 
small  retail  shop)  can  go  about  making 
itself  known  effectively  and  economical¬ 
ly.  The  advice  in  it  struck  us  as  practical 
and  enlightening.  We  showed  it  to  a  com¬ 
puter  store  manager  of  our  acquaintance 
who  was  also  impressed.  The  report 
should  be  worth  its  $2.50-per-page  price, 
especially  to  beginning  entrepreneurs. 

General  Input 

Those  who  use  the  well-known 
Osborne/McGraw-Hill  business  software 
in  BASIC  should  welcome  news  of  the 
formation  of  an  Osborne  Business  Soft¬ 
ware  Users  Group.  The  Group’s  aim  is  to 
promote  the  use,  and  ease  the  implemen¬ 
tation,  of  those  pioneering  software  pack¬ 
ages.  Membership  is  $10  per  year  domes¬ 
tic  and  $20  outside  the  US. 

We  expect  that  quite  a  few  readers  of 
DDJ  are  interested  in  the  many  16-bit 


6 

466 


CPU  chips.  Group  Technology,  Ltd.  is  the 

publisher  of  The  16-bit  Microprocessor 
Handbook,  a  work  that  sounds  as  if  it 
should  answer  a  lot  of  questions.  The  $15 
book  has  a  chapter  on  each  of  the  8086, 
Z8000,  68000,  9900,  LSI- 11,  and  16032. 
Benchmark  programs  coded  in  each  ma¬ 
chine’s  language  are  included,  with  rela¬ 
tive  timings. 


A  Gallimaufry  of  Software 

A  swarm  of  software  notices  came  to 
us  this  month,  telling  of  packages  of 
every  conceivable  sort.  Two  Forth  items 
were  among  this  gallimaufry.  Colorware 
has  produced  a  Forth  implementation  for 
the  CompuColor  machine.  Their  release 
suggests  that  they  followed  the  FIG- 
Forth  standard.  The  first  copy  costs  $79, 
extra  diskettes  are  $69  (Ontario  residents 
add  7%  tax).  Timin  Engineering  has  pub¬ 
lished  a  diskette  of  sample  application 
programs  by  Scott  Pickett.  They  can  be 
used  with  Timin-  or  FIG-Forth.  The 
diskette  is  said  to  contain  100  screens 
each  of  documentation  and  of  code.  A 
standard  8”  diskette  costs  $75;  one  in 
another  diameter  is  $90. 

Apple  owners  now  have  yet  another 
choice  in  word  processing  packages. 
Westico  is  selling  WORD  ///  (three  slashes 
meaning  “3”,  a  logo  designed  to  confuse 
typesetters  nationwide).  It  is  a  full-screen 
editor  with  print  formatting  abilities.  The 
editor  includes  the  usual  operations  for 
scrolling,  moving,  and  deleting  text,  and 
the  less-common  ability  to  insert  or  ap¬ 
pend  text  from  other  files.  The  program’s 
formatting  abilities  are  also  conventional, 
if  complete,  except  for  one  feature  we’ve 
seen  claimed  by  no  other  program:  the 
ability  to  produce  output  in  a  two- 
column  format.  The  $195  package  can 
take  advantage  of  the  features  of  daisy 
and  tulip  printers. 

Here’s  news  of  yet  another  spelling 
corrector  (how  quickly  new  ideas  go  from 
being  marvels  to  being  standard  utilities!), 
this  one  for  Flex  and  MiniFlex  systems. 
Magic  Spell  (tm,  and  good  name,  guys) 
from  Star-Kits  is  the  usual  sort  of  marvel. 
It  runs  a  text  file  against  a  dictionary, 
noting  unfound  words  for  correction  or 
insertion  into  the  dictionary.  The  dic¬ 
tionary  file  can  be  edited  with  any  text 
editor.  That  surprises  us;  if  it  can  be 
edited  then  it  isn’t  an  ISAM  or  B-tree 
file.  How  do  they  get  quick  access  to  the 
dictionary  for  lookup?  The  program’s 


price  is  $60  until  November  10th,  $90 
thereafter.  The  number  listed  is  answered 
by  a  computer,  evenings;  tell  it  to  LIST 
MAGIC.DAT. 

BASEX  was  an  early,  and  fairly  suc¬ 
cessful,  attempt  at  a  simple  systems  pro¬ 
gramming  language  for  small  micros.  The 
BASEX  user  manual  seems  to  crop  up  in 
most  bookstores  that  carry  computer 
books.  Interactive  Microware  offers 
BASEX  on  cassette  and  diskette  for  sever¬ 
al  systems,  most  recently  for  the  Heath 
H8.  The  manual,  an  H8  addendum,  and 
a  cassette  cost  $33,  a  reasonable  price  for 
what  should  be  a  good  hobbyist  tool. 

The  Syntauri  Corporation  has  been 
selling  their  Apple -based  alphaSyntauri 
keyboard  synthesizer  for  some  time.  Now 
they’ve  bundled  all  the  supporting  soft¬ 
ware  into  what  appears  to  be  a  single, 
black-box  operating  system.  It’s  hard  to 
make  out  the  details  because  the  release 
was  written  to  be  read  by  musicians,  not 
computists.  But  it  seems  that  alphaPlus 
is  a  self-contained  control  program  for 
the  Syntauri-equipped  Apple.  The  user 
needs  to  learn  only  the  use  of  alphaPlus 
and  may  neglect  all  other  aspects  of  Ap¬ 
ple  software.  The  system  allows  full  con¬ 
trol  of  the  synthesizer’s  many  features, 
and  the  user  can  store  and  play  back  an 
album  of  pieces  from  a  single  drive.  The 
alphaPlus  software  costs  $35,  which  is 
less  than  2%  of  the  price  of  the  synthe¬ 
sizer.  Why  don’t  they  just  give  it  away? 

Microsoft  is  pleased  to  inform  us  that 
they  have  produced  Release  5.30  of  their 
BASIC  compiler.  It  includes  CHAIN  with 
COMMON,  so  that  overlays  can  commu¬ 
nicate  through  COMMON  variables.  The 
new  compiler  release  is  said  to  be  suitable 
for  Apple  II  Softcard  systems  as  well.  The 
link  command  can  link  programs  some 
16K  larger  than  previously.  Developers 
might  take  note  that  the  rules  for  royal¬ 
ties  on  products  developed  under  the 
compiler  have  been  eased. 

SupeiCalc  is  what  Sorcim  call  their 
spreadsheet  calculator  program  for  CP/M. 
After  being  previewed  on  several  makes 
of  hardware  at  industry  shows,  the  pack¬ 
age  is  now  available  for  general  release. 
We’ve  tried  it;  it  makes  a  v***C***  user 
feel  right  at  home.  A  variety  of  terminals 
are  supported,  and  SuperCalc  has  the 
ability  to  merge  part  or  all  of  a  filed 
worksheet  into  the  active  one. 


Build  Strong  Programs  3  Ways 

Three  notices  came  in  that  told  of 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


application  development  tools,  programs 
that  help  build  programs.  One  is  called 
Screenmaster,  from  Marketing  Essentials. 
It  is  a  file  of  code  that,  when  included  in 
a  CBASIC-2  program,  gives  the  program¬ 
mer  the  means  to  manage  a  pre-formatted 
screen  display.  Utilities  are  provided  to 
build  and  test  the  display  definitions. 
Screenmaster’s  “introductory”  price  is 
$  1 95 ;  a  demo  disk  can  be  had  for  $  1 0. 

Quic-n-Easy  from  Standard  Micro- 
Systems  goes  Screenmaster  one,  maybe 
two,  better.  Rather  than  building  the  ap¬ 
plication  program  in  another  language 
and  calling  on  the  display  handler  code, 
the  Quic-n-Easy  programmer  defines  the 
processing  cycle  as  part  of  the  definition 
of  each  display  field.  The  Quic-n-Easy  in¬ 
terpreter  translates  the  processing  state¬ 
ments  at  run  time,  managing  the  display, 
performing  calcuations,  and  accessing  in¬ 
dexed  sequential  files.  The  package  price 
has  been  set  at  $395. 

Finally,  RADAR  is  the  name  of  a 
system  that  makes  a  CP/M  system  into  a 
data  entry  station  and  a  suitable  replace¬ 
ment  for  a  keypunch  station  or  IBM  3741 
data  entry  station.  RADAR  is  said  to  pro¬ 
vide  check  digit  verification,  double  key 
verification,  and  a  number  of  other  fea¬ 
tures  that  make  it  easy  to  program  a  data 
entry  clerk.  Southern  Computer  Systems 
sells  it  for  $495. 


Percom  Takes  Aim 

Percom,  maker  of  diskette  drives  for 
SS-50  and  TRS-80  systems,  has  built  a 
mini-disk  system  for  the  AIM-65,  KIM, 
and  SYM  machines.  From  one  to  three 
drives  can  be  hung  on  an  AIM;  the  drives 
may  have  40  or  80  tracks  and  may  have 
the  “flippy”  option.  A  disk  operating 
system  is  provided.  The  price  of  a  1- 
drive  system  will  fall  around  the  $700 
mark. 


Model  III  and  CP/M 

A  complete,  origin-zero,  64K,  CP/M 
system  in  a  TRS-80  Model  III?  That’s 
what  Parasitic  Engineering  claims  that 
their  Shuffleboard  gives  you.  The  $500 
package  consists  of  a  circuit  board,  16K 
of  RAM,  2K  of  ROM,  and  those  marvel¬ 
lous  CP/M  manuals.  It  installs  by  plugging 
into  two  existing  sockets,  they  say,  so 
that  installation  requires  no  permanent 
changes  of  any  kind.  BBj 


Engineers 

Scientists 

Systems  Programmers 
Business  Owners 

All  these  read  Dr.  Dobb’s  Journal. 
Reach  them  with  cost-effective  advertising. 
(415)  323-31  11. 


Contact  Points 

Irv  Brechner  Enterprises,  POB  265WOB, 
West  Orange,  NJ  07052. 

Colorware,  POB  6733,  Station  J,  Ottawa, 
Ontario,  K2A  3Z4  Canada. 

Commodore,  300  Valley  Forge  Square,  681 
Moore  Road,  King  of  Prussia,  PA  19406; 
(215)  337-7100. 

Group  Technology,  Ltd.,  POB  87,  Check, 
VA  24072; (703) 651 -3153. 

Interactive  Microware,  POB  771,  State  Col¬ 
lege,  PA  16801 ;  (814)  238-8294. 

Marketing  Essentials,  Inc.,  161  West  75th 
St.,  New  York,  NY  10023;  (212)  580- 
3589. 

Micro-Serve,  250  Cedar  Hills  Avenue, 
Nyack,  NY  10960;  (914)  358-1340. 
Microsoft,  10800  N.E.  Eighth,  Suite  819, 
Bellevue,  WA  98004;  (206)  455-8080. 
Osborne  Business  Software  Users  Group, 
2256  Main  Street,  Suite  11,  Otay,  CA 
92011 ; (714) 423-0538. 


Parasitic  Engineering,  1101  Ninth  Ave., 
Oakland,  CA  94606;(415)  839-2636. 
Pegasus  Software,  POB  10014,  Honolulu, 
Hawaii  96816. 

Percom  Data  Company,  211  N.  Kirby, 
Garland,  TX  75042;  (214)  272-3421. 
Sorcim,  405  Aldo  Avenue,  Santa  Clara,  CA 
95050; (408)  727-7634. 

Southern  Computer  Systems,  POB  3373A, 
Birmingham,  AL  35255;  (205)  933- 1659. 
Standard  Microsystems,  136  Granite  Hill 
Court,  Langhorne,  PA  19047;  (215)  968- 
5966. 

Star-Kits,  POB  209,  Mt.  Kisco,  NY  10549; 
(914)  241-0287. 

Syntauri  Corporation,  3506  Waverly  Street, 
Palo  Alto,  CA  94306;  (415)494-1017. 
Timin  Engineering,  9575  Genesee  Ave., 
Suite  E-2,  San  Diego,  CA  92121;  (714) 
455-9008. 

Westico,  25  Van  Zant  St.,  Norwalk,  CT 
06855; (203  853-6880. 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


7 

467 


Adven-80 

An  Advanced  Adventure  Development  System 


For  those  not  familiar  with  Adventure,  it  is  a  game  which 
could  simply  not  have  existed  before  the  age  of  the  com¬ 
puter.  Imagine  reading  a  story  tale  where  you  follow  the 
hero  (or  heroine)  in  a  fantasy  world  where  anything  can  hap¬ 
pen.  The  difference  between  Adventure  and  a  simple  story 
book  is  that  you  can  be  the  hero  and  be  instrumental  in  affect¬ 
ing  the  outcome  of  the  story,  rather  than  being  simply  a  pas¬ 
sive  reader. 

More  specifically,  in  most  Adventures,  you  are  in  control 
of  an  “entity”  which  acts  as  your  eyes  and  ears  throughout  the 
story.  You  can  look,  listen,  manipulate  objects,  collect  trea¬ 
sures,  move  in  whatever  direction  you  want,  in  fact  do  any¬ 
thing  you  want  within  the  confines  of  a  limited  universe 
maintained  by  the  computer. 

Conceivably,  some  day,  3-dimensional  tactile  dream¬ 
worlds  will  become  possible  as  technology  progresses,  perhaps 
coupling  computer  technology  with  some  form  of  video 
disk  system;  but  for  the  present,  Adventure  and  similar  games 
provide  us  with  the  first  simple  examples  of  this  exciting  con¬ 
cept. 

This  article  is  probably  the  first  to  be  published  of  its 
kind,  in  that  it  provides  a  complete  package  for  creating  Ad¬ 
ventures.  The  code  presented  here  is  a  completely  general- 
purpose  adventure  “ interpreter ”  together  with  a  BASIC  pro¬ 
gram,  designed  to  allow  you,  the  reader,  to  create  a  database 
for  your  own  Adventures  with  only  the  vaguest  knowledge  of 
assembly  language  programming.  The  code  is  not  intended  to 
be  clever;  experienced  programmers  can  no  doubt  quite 
drastically  improve  upon  the  techniques  used  ;  however,  it  does 
work  quite  well  and  I  would  appreciate  any  feedback  on 
possible  improvements. 

In  Brief 

ADVEN-80  is  a  program  wherein  the  user  resides  in  one 
of  many  LOCATIONS.  A  LOCATION  may  have  the  property 
of  being  LIGHT  or  DARK,  and  usually  is  associated  with 
several  alternative  EXITS.  The  player  moves  from  one  LOCA¬ 
TION  to  another,  and  in  any  LOCATION  he  may  find  an 
OBJECT  or  OBJECTS.  Objects  have  DESCRIPTIONS,  and 
may  optionally  have  DETAILED  DESCRIPTIONS  as  well.  Un¬ 
less  specifically  mentioned  an  object  may  be  TAKEN  or 
DROPPED  or  LOOKED- AT  or  otherwise  manipulated  within 
the  confines  of  the  facilities  of  the  MATCHW  table.  Each  ob¬ 
ject  may  only  be  in  one  location  at  any  give  time  (or  may  be 
worn  or  carried  as  applicable).  The  object  of  the  game  is 
usually  to  obtain  some  form  of  TREASURE  or  achieve  a 
SCORE  or  so  many  points. 

Of  special  interest  is  the  LINE  PARSER,  whose  job  it  is  to 
take  in  whatever  the  player  enters  on  the  keyboard,  and  at¬ 
tempt  to  make  some  sense  out  of  it.  In  simplified  form,  the 
parser  in  ADVEN-80  takes  in  a  line  of  user  entry,  and  looks  at 
each  word  in  turn  to  see  if  that  is  a  known  word.  If  so,  a  token 
entry  (somewhat  like  the  one-byte  tokens  used  in  some 
BASICs)  is  made  in  a  separate  buffer;  if  not,  no  entry  is  made, 
and  the  next  word  is  checked.  When  the  entire  line  has  been 


by  Peter  D.  Scargill 


Peter  D.  Scargill,  24  Percy  Park,  Tynemouth,  Tyne  &  Wear, 
Great  Britain. 


checked  over,  the  token  buffer  is  scanned  for  words  such  as 
“THEN”  and  “AND”  and  if  found,  the  line  is  split,  leaving  all 
code  after  the  “AND”  for  the  next  time  round,  in  lieu  of  the 
player’s  next  entry.  This  allows  the  use  of  multiple  statement 
lines. 

Generally,  user  input  breaks  down  into  simple  two  word 
sequences  after  irrelevant  words  have  been  discarded.  A  sen¬ 
tence  such  as  “PLEASE  GET  THE  LAMP  AND  LIGHT  IT” 
breaks  down  into  two  operations,  “GET  LAMP"  and  “LIGHT 
LAMP.”  The  program  treats  “IT”  as  the  last  object  referred 
to.  A  table  is  scanned  for  such  word  sequences  and  appropriate 
action  is  taken,  scores  can  be  maintained,  and  the  program  has 
special  facilities  to  accommodate  scoring. 

Adventure-type  games  for  microcomputers  have  been 
around  for  some  time  and  several  Adventures  have  been  made 
available  for  the  more  popular  systems'  although  to  date,  very 
few  have  had  anywhere  near  the  capabilities  to  handle  user  in¬ 
put  as  had  the  original  “BIG  SYSTEMS"  Adventure  which 
many  of  the  major  Polytechnic  computers  have  access  to. 

The  Original  Adventure  for  these  systems  was  written  in 
Fortran  and  required  considerably  more  memory  than  that 
available  on  present-day  microcomputers,  and  the  program  it¬ 
self  was  inflexible  (i.e.,  the  creation  of  a  new  game  would  re¬ 
quire  the  re-writing  of  the  Fortran  program  as  the  database 
was  an  integral  part  of  the  overall  structure). 

ADVEN-80  is  a  new  Micro-Adventure  system,  written  in 
machine  language.  Consideration  has  been  given  as  to  obtain¬ 
ing  the  maximum  usage  out  of  the  limited  memory  capacity 
of  currently  available  small  computers. 

This  Adventure  system,  written  for  the  Z80  microproces¬ 
sor,  is  a  full-feature,  machine-code  Adventure  utilizing  the 
powerful  functions  of  the  above.  It  is  partly  because  of  this 
that  the  game  runs  at  very  high  speed,  with  a  minimum  mem¬ 
ory  requirement  (a  simple  Adventure  could  be  written  in  well 
under  16K). 

Because  of  the  speed  of  the  Z80,  it  was  possible  to  use  an 
extremely  simple  database  layout,  and  the  use  of  an  inter¬ 
mediate  translator  accounts  for  high  readability  of  the  source 
listing.  In  reading  the  following,  an  elemental  knowledge  of 
assembly  language  programming  in  Z80  microprocessor  is 
considered  useful  but  not  essential. 

Tables 

OBJLOC  The  format  of  this  table,  containing  < object  no./ 
location  >  pairs  is  simple.  The  pairs  are  contiguous  with  a 
zero  to  end  of  the  table.  Several  location  numbers  have  special 
meanings  and  these  are  listed  below. 

Loc.  255  Object  is  non-existent.  Cannot  be  found. 

Loc.  254  Object  is  currently  being  carried. 

Loc.  253  Object  is  currently  being  worn. 

Finally,  location  252  is  special  in  that  any  object  current¬ 
ly  in  this  location  is  one  of  a  pair  of  objects  which  together 
form  a  TWIN-STATE  object.  A  typical  example  of  this  is  a 
LAMP.  The  lamp  may  be  LIT  or  UNLIT  and  hence  it  is  neces¬ 
sary  to  have  two  versions  of  the  same  object. 

This  method  is  probably  the  simplest  way  of  implement¬ 
ing  a  twin-state  object,  and  in  the  table  these  two  forms 
should  always  be  concurrent.  In  the  example  of  the  lamp,  the 
two  states  could  be,  say,  LAMP  and  ULAMP.  If  the  word 
LAMP  is  made  accessible,  then  this  must  appear  FIRST  in  the 
table.  This  is  very  important,  first  in  ascending  order;  i.e.; 


8 

468 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


OBJLOC 
LAMP  45 
ULAMP252 

ENDTABLE 


/*  Table  name.  These  are  mandatory.  */ 

/*  object  34,  a  lit  lamp,  is  in  location  45  */ 

/*  object  35,  an  unlit  lamp,  is  hidden  from 
view.  */ 

/*  end  of  table  */ 


As  you  can  see  from  the  above  table,  if  the  scanner  be¬ 
gins  at  the  start  of  the  table,  and  then  finds  a  match  with  ob¬ 
ject  LAMP,  in  order  to  blow  out  the  lamp,  the  two  LOCA¬ 
TION  entries  in  the  table  are  simply  swapped  over. 

Object  ULAMP  was  equated  only  and  must  never  be 
found  by  the  user- input  encoding  section,  although  CONDI¬ 
TIONS  such  as  OC  or  OP  can  access  both  versions. 

If  a  user  says  GET  LAMP,  and  there  are  no  conditions, 
the  system  will  look  for  lamp.  If  this  is  at  location  252  then 
the  pointer  will  be  incremented  automatically  to  point  at  the 
ULAMP  entry.  Hence  the  user  will  be  given  whichever  version 
of  the  object  is  not  at  location  252.  (Assuming  that  the  other 
version  is  PRESENT  or  being  carried  or  whatever.) 

Inventories  simply  look  at  the  location  numbers  and  if  a 
match  is  found,  then  a  description  is  printed.  The  same  applies 
during  the  initial  description,  where  objects  contained  within 
the  current  location  are  described. 

OBJDES  This  table  containing  < object  no./ MSG  no.> 
pairs  is  closely  related  to  the  above  OBJLOC  table.  During 
“I  can  see  .  . .”  type  routines,  the  table  OBJLOC  is  scanned  in 
order  to  find  objects  contained  within  a  given  location,  be  it 
the  current  location  or  those  reserved  for  objects  being  carried 
or  worn  . .  . 

When  the  object  is  found,  the  number  of  the  object  is 
used  to  scan  through  the  left  side  of  OBJDES,  and  when  an 
object  match  is  found,  the  description  number,  which  refers  to 
an  entry  in  the  UMESS  table,  is  used  to  produce  a  descrip¬ 
tion  of  the  required  object.  The  OBJDES  table  need  be  in  no 
particular  order,  and  no  ZERO  terminator  is  required  as  we  are 
not  searching  for  a  non-existent  object.  In  the  sample  database 
the  ENDTABLE  macro  is  shown,  but  this  is  just  for  neatness, 
it  is  not  essential  here. 

OBPROP  This  table  describes  the  things  that  can  be  done  to 
an  object,  assuming  you  wish  to  limit  that  object  to  certain 
actions.  I.e.,  you  would  not  expect  the  player  to  be  able  to 
TAKE  THE  STATUE  if  the  statue  weighs  a  ton  .  .  . 

OBPROP 

STATUE  LOOK, LISTEN, FEEL 

DOOR  LOCK, UNLOCK, LOOK 

ENDTABLE 

Objects  not  in  the  table  are  considered  to  have  universal  at¬ 
tributes  (within  the  limitations  of  the  MATCHW  table). 
OBDSK  This  table  finds  use  for  those  objects  you  would  like 
to  enable  a  close  inspection  of.  Any  object  not  appearing  in 
the  table  will  be  described  as  ordinary  looking. 

OBJDSK 

LAMP  ’Looks  like  an  old  miner’s  lamp  to  me.’ 

ENDTABLE 

TABKEY  This  table  is  used  by  the  line  parser.  As  the  user  in¬ 
put  line  is  parsed,  4-byte  word  sections  are  put  into  a  tempo¬ 
rary  buffer.  (Words  shorter  than  4  characters  long  are  left- 
justified  and  padded  with  spaces.)  TABKEY  is  used  to  replace 
any  known  words  with  a  single  byte  code.  Unknown  words  are 
scrapped. 


TABKEY  is  composed  of  the  following.  The  first  byte  is 
KEY  number.  Following  that  are  groups  of  4  bytes  with  the 
last  4-byte  group  having  the  8th  bit  set  on  the  last  character. 
If  any  of  the  4-byte  groups  match  that  in  the  buffer,  then  the 
KEY  byte  is  put  into  a  buffer  for  later  use.  To  signify  the  end 
of  the  table,  ZERO  is  used  as  a  KEY  byte. 

When  the  sentence  has  been  completely  scanned,  a  buffer 
called  CODBUF  will  contain  the  single  byte  KEY  replacements 
to  all  the  words  in  the  user  input  that  were  matched  success¬ 
fully.  A  ZERO  will  indicate  the  end  of  this  buffer.  Hence  the 
sequence  N  “N  NORT”  will  allow  user  inputs  of  “N”  or  “GO 
NORTH”  to  be  placed  in  CODBUF  as  the  single  byte  repre¬ 
senting  the  key  N. 

A  special  byte  which  may  end  up  in  CODBUF  is  THEN. 
This  is  currently  set  at  250  decimal  and  is  used  for  batching  of 
commands,  so  that  the  user  may  say,  for  example  “GET  THE 
AXE  THEN  LOOK  AT  IT.”  The  IT  being  taken  care  of  auto¬ 
matically  by  a  section  of  code  that  converts  occurrences  of  IT 
into  the  last  mentioned  object. 

KEYSETS  are  actually  entered  in  macro  form;  i.e.: 

BEGIN  BEGISTAR’ 

Another  example  of  this  is  LOOK  “LOOKPERUEXAM” 
where  LOOK  is  the  word  that  will  be  equated,  and  will  match 
LOOK,  PERUSE  and  EXAMINE. 

MATCHW  This  table  is  the  one  that  looks  at  user  input  after 
it  has  been  encoded  into  a  byte  sequence.  The  table  is  scanned 
until  a  pair  of  bytes  corresponding  to  those  in  the  CODBUF 
area  are  found.  If  there  is  no  match  then  a  default  message  is 
printed  to  indicate  that  the  program  found  no  sensible 
matches.  Otherwise,  a  set  of  CONDITIONS  is  checked,  and  if 
all  of  these  are  TRUE,  then  a  set  of  actions  is  taken. 

The  format  is  as  follows: 

<2  byte  key  Xcond  ><255  >< actions >< 255  Xeither 
ZERO  or  more  keys> 

Where  cond  =  either  no  entry  or  any  amount  of  conditions  and 
arguments. 

Where  actions  =  any  amount  of  actions. 

Obviously  from  the  above,  255  is  used  as  a  delimiter  and 
so  must  not  occur  within  either  the  conditions  or  the  actions. 
However,  255  may  be  used  as  one  of  the  two  KEY  bytes  to 
tell  the  program  to  match  up  with  any  entry,  i.e.: 

<  23,255  >  If  CODBUF  contains  23  followed  by  anything 

then  the  set  will  be  accepted. 

<  34,0  >  In  this  case,  CODBUF  should  contain  34  ONLY. 

Again,  simple  equates  are  used  to  make  life  easy.  Typical 
table  entries  are  shown  below,  together  with  an  explanation 
of  each. 

MATCH  GET,  ANY 

TEST  OH,INP 

ACTION  TKE,INP,OK 

In  the  above  example,  if  the  user  enters,  say,  GET  LAMP, 
then  the  system  will  test  to  see  if  the  object  is  in  the  current 
location  (OH)  and  if  so,  will  allow  the  taking  of  the  LAMP  and 
will  then  print  an  OK  message  and  exit  the  table,  ready  for 
more  user  input. 

MATCH  LOOK,  NULL 

ACTION  LA,  EX 

If  and  only  if  the  user  enters  the  single  word  LOOK,  the 
system  will  unconditionally  Look  Around,  then  EXit  the 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


9 

469 


table. 

MATCH  ANY,  ANY 

ACTION  PRM,37,EX 

This  entry  should  be  put  at  the  end  of  the  MATCHW 
table.  This  will  match  ANY  user  input,  and  print  message  37 
from  the  MSG  table,  which  would  be,  for  example,  “I  don’t 
know  what  you  mean.” 

MATCH  ON,  LAMP 

TEST  OC,MATCH,OC,ULAMP 

ACTION  SWP,  LAMP, SWP, MATCH,  OK 

On  the  previous  page  we  have  a  more  complex  example.  If 
the  user  enters  ON  LAMP  or  LIGHT  THE  LAMP,  etc.,  and 
then  only  if  the  MATCH  and  the  ULAMP  (unlit  lamp)  are  be¬ 
ing  carried,  then  swap  the  MATCH  for  its  USED  partner,  and 
swap  the  ULAMP  with  its  LIT  partner. 

Notice  that  no  attempt  was  made  to  execute  the  instruc¬ 
tion  SWP, ULAMP.  This  would  have  been  disastrous  as  the 
ULAMP  is  the  SECOND  entry  in  the  table,  and  you  must  only 
SWAP  the  FIRST  entry  (i.e.,  the  main  entry),  as  the  command 
SWP  FRED  looks  for  the  entry  FRED  in  the  OBJLOC  table, 
and  swaps  its  location  with  that  of  the  next  entry  in  the  table. 
That  is  why  the  user -accessible  version  of  the  object  must 
be  entered  into  the  table  before  the  alternative  form. 

Messages 

MSG  This  is  a  general-purpose  message  table,  containing 
messages  such  as  “I  can  not  see  anything”  and  “ok.”.  These 
messages  include  directives  and  all  general  statements.  The  for¬ 
mat  is  extremely  simple: 

0  message  sequence  0  message  sequence  0 

The  sequence  is  that  of  a  zero  byte  followed  by  ASCII 
text  until  the  next  zero.  The  zero  then  acts  as  both  delimiter 
and  counter.  As  the  maximum  message  number  is  known  (i.e., 
there  is  no  search),  an  end-of-table  delimiter  is  not  required, 
other  than  the  zero  at  the  end  of  the  last  message. 

NOTE  that  the  first  20  messages  must  not  be  altered  in 
position  as  they  are  used  by  the  system  in  some  cases  auto¬ 
matically.  There  is  a  limit  of  255  messages,  but  this  is  far  more 
than  will  normally  be  required. 

In  macro  form,  simply  enter  the  message  number  and  the 
message,  i.e.: 

45  ’Hi  there,  this  is  a  message,  isn’t  it .  .%’ 

Note  that  the  standard  ’  symbol  cannot  be  used  within 
text  and  must  be  replaced  with  the  alternative  ‘  form.  You 
will  have  noticed  the  use  of  one  other  special  character,  the 
percentage  sign.  This  is  used  as  a  CRLF  and  hence  must  not  be 
used  for  its  original  purpose  (see  below). 

UMESS  This  table  contains  descriptions  of  objects  and  all 
general  messages  that  are  specific  to  a  particular  adventure. 

7  ’This  is  another  message’ 

PLEASE  NOTE:  To  make  assembly  listings  more  easily 
readable,  CRLF  sequence  will  be  sent  to  the  screen  on  encoun¬ 
tering  a  percentage  sign  in  the  text.  This  of  course  also 
saves  a  little  space  if  you’re  tight  with  your  bytes.  Normally, 
CRLF’s  are  not  required  in  bulk  text  as  the  system  automati¬ 
cally  inserts  these  depending  on  the  width  of  the  screen. 

It  must  also  be  noted  here  that  the  use  of  the  character 
“>”  anywhere  in  a  sentence  will  not  produce  any  output  but 


will  serve  to  destroy  any  pending  BATCHING  and  so  this  may 
be  used  freely  within  error  messages  and  any  message  which  re¬ 
quires  the  user’s  immediate  attention. 

A  final  point  concerning  messages.  It  is  possible  to  have 
conditional  sections  within  messages  (or  indeed  complete 
conditional  messages).  Flags  23  to  49  inclusive  have  been 
reserved  for  this  purpose.  These  may  be  tested  for  being  TRUE 
or  FALSE  only,  in  the  following  manner.  Anywhere  within  a 
string,  the  game  writer  may  insert  parentheses  as  follows: 

’This  is  a  bit  of  {  Auntidy  }  text  -[B  as  you  can-[C  easily)  see).’ 

To  explain.  If  flags  23  (i.e.,  A),  24  (i.e.,  B),  and  25  (i.e., 
C),  are  all  ZERO  then  the  output  of  the  message  would  be 
“This  is  a  bit  of  text.”;  however  if  one  were  to  set  flag  25  then 
the  output  would  be  “This  is  a  bit  of  untidy  text.” 

If  flag  24  was  set,  then  you  would  get  “This  is  a  bit  of 
text  as  you  can  see.”  It  is  obvious  that  if  flag  25  were  also  set 
then  the  word  “easily”  would  be  inserted.  Note,  however, 
that  this  would  not  apply  if  flag  24  were  reset,  whereby  all 
text  inside  the  matching  set  of  parentheses  would  be  ignored. 

Only  the  letters  A-Z  inclusive  and  the  “/”  character  may 
be  used  after  the  opening  parentheses  (A-Z  corresponding  to 
flags  24-49)  and  the  maximum  NESTING  depth  is  10,  al¬ 
though  as  many  NON-NESTED  sets  as  desired  may  be  put 
into  any  section  of  text.  The  character  “/”  may  be  used 
before  any  of  the  alpha  chars  A-Z  to  indicate  that  the  flag  has 
not  been  set,  i.e.,  is  ZERO.  The  system  flag  that  indicates  that 
the  “/”  char  is  in  use  is  only  set  and  reset  on  OPENING  braces 
so  do  not  try  any  fancy  multi-level  conditional  text  while 
using  this  form. 

In  this  version,  two  special  flags  have  been  reserved.  Flags 
21  and  22  corresponding  to  @  and  ?  are  automatically  set  by 
the  program  after  every  user  entry  to  be  always  opposite;  i.e., 
if  flag  21  is  “1”  then  flag  22  will  be  “0”  and  vice-versa,  but 
randomly  so.  Hence  it  is  possible  to  write  the  following  default 
message. 

44  ’-(@1  simply  don’t  understand  you.) -{?What  ????)-’ 

Whenever  this  message  is  called,  there  is  a  50-50  chance  of 
either  “What  ????”  or  “I  simply  don’t  understand  you.”  being 
output  by  the  program. 

These  conditional  facilities  find  their  main  use  in  circum¬ 
stances  where  you  want  the  program  to  differentiate  between 
LOOK  AT  THE  GLOBE  and,  say,  LOOK  AT  THE  GLOBE 
CAREFULLY.  Obviously  you  can  have  umpteen  levels  of 
description. 

The  facilities  may  be  used  anywhere  that  text  is  found, 
either  in  place  descriptions  or  in  object  descriptions,  or  even  in 
default  replies.  A  good  use  here  is  to  allow  for  either  random 
or  deliberate  variations  in,  say,  the  default  “CANT  HELP 
YOU”  message,  etc.  etc. 

Descriptions 

LOC  Place  descriptions  begin  with  zero,  a  number  255  to 

252  to  indicate  one  of  the  following: 

255  Normal  place,  full  exit  description 
254  Normal  place,  no  exit  description 

253  Dark  place,  full  exit  description  (if  lit  by  lamp) 

252  Dark  place,  no  exit  description 

In  high  level  form  the  following  words  have  the  same  effect  as 
the  numbers  above: 


10 

470 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


NORMAL,  NOEXIT,  DARK,  DARKNO 
MESSAGE  /  KEY  /  LOCATION  bytes,  255  to  indicate  end 
of  directions,  and  then  textual  description,  zero  being  the  text 
terminator. 

I.e.: 

0  254  02  01  02  255  <TEXT>  0  253  03  32  12  255 
<TEXT>  0 

In  macro  form,  a  typical  entry  may  be  as  follows: 

1  NOEXIT, 02, N, 2 

’I  am  in  a  small  room  with  no  furniture.  There  ’ 
’appears  to  be  nobody  around  at  the  moment. %' 

Again,  no  end  of  table  required  other  than  the  mandatory 
zero,  (or  ENDTABLE)  as  we  are  not  looking  for  locations 
which  do  not  exist.  In  the  above  example,  the  first  text  con¬ 
tains  only  one  sequence  of  exits,  (not  printed)  MSG2  being  the 
description,  i.e.,  NORTH.  This  corresponds  to  a  user  KEY 
code  of  01,  and  in  this  case,  if  a  match  for  the  key  is  found, 
the  player  will  be  transferred  to  location  number  03. 

In  the  second  example,  MSG3  prints  out  SOUTH;  if  the 
user  typed  in  GO  SOUTH,  or  SOUTH,  or  S  then  this  would  be 
converted  to  KEY  03  and  the  user  would  then  be  transferred 
to  location  12.  Meanwhile,  the  present  location  description  is 
printed  out,  and  any  attempt  to  LOOK  at  anything  will  pro¬ 
duce  the  response  “I  can’t  see  anything”  as  the  253  at  the  start 
of  the  sequence  dictates  that  this  is  a  dark  location.  (Of 
course,  if  the  user  has  a  LAMP,  then  that  is  a  different  matter. 
See  description  of  LAMP.) 

A  special  location  number  is  249  (RTN).  When  a  transfer 


You  Read 


Dr.  Dobb's  Journal 

And  You  Don’t 
Subscribe?! 


Save  $13 

off  newsstand  prices  for  2  yrs. 
Save  $5  for  1  yr. 


Can  you  afford  to  miss  an  issue  with 
information  vital  to  your  interests?  As  a 
subscriber  you  can  look  forward  to 
articles  on  Small-C,  FORTH,  CP/M,  S-100, 
Compiler  optimization,  Concurrent  Pro¬ 
gramming  and  more,  delivered  right  to 
your  door.  And  you’ll  never  miss  the 
issue  that  covers  your  project. 


Flag  Table 

This  is  a  255-byte  table  numbered  1  to  255,  zero 
not  being  used,  as  zero  is  used  as  a  delimiter.  Certain 
flags  have  special  uses. 

1  Dark  location  indicator ...  If  ZERO  then  dark. 

2  Number  of  items  carried. 

3  Maximum  permissible  items  to  be  carried. 

4  Counted  up  once  every  turn. 


Counted  down  once  every  turn  if  not  zero. 


Counted  down  if  dark,  lamp  ON,  every  turn. 


Present  score. 

Present  location. 

Store  FF  or  FE  (Internal). 

1  and  10  OR’d  together.  ZERO  means  can’t  see. 
Lamp  on/off.  Zero  when  ON.  1  when  OFF. 
Number  of  items  WORN. 

Number  of  items  HERE  (present  location). 

Store  of  last  location  number  (automatic). 

-22  Inclusive.  For  random  text  control  (automatic). 
-48  Inclusive.  Text  controls  A-Z. 

Flags  49  to  250  are  available  to  the  user. 


DR.  DOBB’S  JOURNAL 
P.O.  Box  E 

Menlo  Park,  CA  94025 


Yes!  Sign  me  up  for 

_ 2  yrs.  $47 


1  yr.  $25 


_ I  enclose  a  check/money  order 

_ Charge  my  Visa,  MasterCard, 

American  Express 
_ Please  bill  me  later 

Name _ 

Address _ 


Credit  Card 
Account  No. . 
Signature _ 


Exp.  date 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


11 

471 


request  to  this  location  is  selected,  the  program  will  treat  this 
in  a  special  manner  by  returning  the  user  to  the  previous  loca¬ 
tion.  Hence,  you  may  enter  a  LARGE  BOX  and  a  RTN  exit 
will  bring  you  out,  no  matter  where  the  box  is  situated.  This 
avoids  the  need  for  an  awful  lot  of  location  testing. 

The  macro  version  of  this  table  makes  life  very  simple  as 
can  be  seen  in  the  above  example.  No  delimiters  are  required, 
and  the  final  description  is  quite  readable. 


Assembly  Notes 

To  use  these  programs  you  will  need  access  to  the  follow¬ 
ing  utilities.  A  Z80  assembler  (Zilog  mnemonics)  with  condi¬ 
tional  assembly.  (If  your  assembler  does  not  support  the 
CONMSG  pseudo-op  and/or  conditional  assembly,  miss  out 
the  messages  and  only  select  the  sections  of  code  that  you 
require  for  your  application.) 

The  BASIC  used  for  the  converter  is  Microsoft  Version  5. 


Conditions/ Actions 

Here  are  the  conditions  and  actions  possible  togeth¬ 
er  with  explanations  for  each.  Those  shown  below  are  all 
available  to  the  Adventure  writer  and  there  is  no  limit  to 
the  amount  of  conditions  and/or  actions  that  you  may 
specify  in  any  set. 


Conditions 


CL 

XX 

Current  location  is  xx. 

NCL 

XX 

Current  location  is  NOT  xx. 

OP 

XX 

Object  xx  is  in  present  location  or  is 
worn  or  carried  (xx=00  means  obtain 
object  number  from  user  input). 

OC 

XX 

Object  is  being  carried. 

OW 

XX 

Object  is  being  worn. 

owe 

XX 

Object  is  worn  or  carried. 

OH 

XX 

Object  here  but  not  carried  or  worn. 

ONP 

XX 

Object  is  not  present. 

ONC 

XX 

Object  is  not  being  carried. 

ONW 

XX 

Object  is  not  being  worn. 

NWC 

XX 

Object  is  not  worn  and  not  carried. 

ONH 

XX 

Object  not  here,  but  MAY  be  worn 
or  carried. 

OE 

XX 

Object  exists  at  present. 

ONE 

XX 

Object  does  not  exist  at  present. 

@L 

XX 

yy 

Object  xx  is  at  location  yy. 

N@L 

XX 

yy 

Object  is  not  at  location  yy. 

RND 

XX 

Random  chance  0-254  .  .  .  Where 

254  is  dead  cert. 

TF 

XX 

yy 

Test  flag  No.  xx  for  value  yy. 

NTF 

XX 

yy 

Test  flag  No.  xx  for  NOT  value  yy. 

GE 

XX 

yy 

Flag  xx  greater  than  or  equal  to  value 

yy- 

LT 

XX 

yy 

Flag  xx  less  than  value  yy. 

C2 

XX 

Compare  2nd  word  with  xx. 

C3 

XX 

Compare  3rd  word  with  xx. 

NC2 

XX 

True  if  2nd  word  is  NOT  =  to  xx. 

NC3 

XX 

True  if  3rd  word  is  NOT  =  to  xx. 

Actions 

INV 

Print  an  inventory  of  carried  and 
worn  objects. 

TKE 

XX 

Get  object  to  carry  it. 

WR 

XX 

Get  object  and  wear  it. 

DR 

XX 

Drop  the  object. 

PR 

XX 

Print  message  number  xx  from 
UMESS  table. 

PRM 

XX 

Print  message  number  xx  from  MESS 
table. 

DL 

XX 

Describe  location. 

SF 

XX 

yy 

Set  flag  xx  to  value  yy. 

DSCOB 

XX 

Describe  the  object. 

SWP 

XX 

Swap  object  xx  with  object  xx+1. 

MV 

XX 

Move  to  location  xx. 

OK 

Say  ’OK’  and  exit  table. 

QT 

Quit. 

INF 

XX 

Increment  flag  xx. 

DEF 

XX 

Decrement  flag  xx. 

EX 

Exit  table. 

SC 

Print  current  score. 

PU 

XX 

yy 

Put  object  xx  into  location  yy. 

CR 

XX 

Create  object  xx  (Place  here). 

DES 

XX 

Destroy  object  xx. 

FLIP 

XX 

Flip  flag  xx  true  to  Zero  and  Vice 
Versa. 

LA 

XX 

Look  around  at  items. 

SMA 

XX 

Set  message  A  to  UMESS  number  xx. 

SMB 

XX 

Set  message  B  to  UMESS  number  xx. 

WT 

XX 

Wait  for  xx  seconds. 

PF 

XX 

Print  the  value  of  flag  No.  xx. 

ATF 

XX 

yy 

Add  yy  to  the  value  of  flag  xx.  If 
>  255  then  set  to  255. 

Make  yy=0. 

SFF 

XX 

yy 

Subtract  yy  from  flag  xx.  If  makes 
xx <0  then  set  xx  =  0. 

Make  yy=0. 

GRUN 

XX 

Print  description,  directions  etc.  & 
exit. 

The 

above 

conditions  and  actions  represent  all  of 

those  implemented  in  the  present  version  of  ADVEN-80, 

Flag 

This  table  is  simply  a  collection  of  pairs  of  flag  num¬ 
bers  and  their  corresponding  initial  data  values.  Entries 
must  be  contiguous. 

35  22  /*  means  flag  35  is  set  to  value  22  */ 

Certain  flags  are  controlled  automatically  by  the  pro¬ 
gram  and  may  be  viewed  only. 

TITL1 

This  final  message  is  that  which  will  be  presented  at 
the  start  of  any  game.  It  is  comprised  of  ASCII  text, 
with  a  ZERO  delimiter  at  the  end. 

CHR$(any  single  ASCII  number  you  like,  or  several  to 
clear  screen.) 

’any  title  message’ 

’blah  blah’ 

ENDTABLE 


12 

472 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


Peculiarities  of  this  BASIC  are  few,  the  most  important  one 
is  the  INSTR.  This  returns  a  value  of  the  1st  occurrence  of  one 
string  or  character  within  another  string: 

A=INSTR(Q$,“R”)  where  Q$=“ARE”,  A=2 

Only  sequential  disk  files  are  used,  read  line  by  line  from 
the  source  file  into  the  destination  file  in  a  single  pass.  The 
program  is  designed  to  allow  reasonably  free  format  of  the 
source  file. 

ADVEN-80  System  Overall  View 

ADVEN-80  was  a  development  of  an  original  BASIC  sys¬ 
tem6  which  relied  heavily  on  disk  storage.  The  BASIC  program 
itself  was  suggested  by  a  small  program  called  GROW3  (for 
those  interested,  the  BASIC  used  was  Microsoft  Disk  Extended 
Version  5.1  and  the  disks,  Micropolis  Metafloppy). 

Anyone  who  wants  to  attempt  to  write  their  own  Adven¬ 
tures  in  BASIC  would  be  advised  to  start  by  reading  Greg 
Hassett’s  article®  and  for  those  who  want  to  start  in  machine 
code  (any  processor)  and  are  capable  of  working  from  general¬ 
ized  macros,  a  good  starting  point  would  be  Ken  Reed’s  pro¬ 
gram4. 

Due  mainly  to  the  desire  to  re-do  the  system  from  scratch 
in  Assembler,  and  with  help  from  someone  already  familiar 
with  the  design  of  Adventure  systems4,  ADVEN-80  was  de¬ 
veloped.  The  present  version  has  several  outstanding  features, 
firstly  the  ability  to  handle  multiple  commands  (i.e.,  GET 
LAMP  THEN  LIGHT  IT).  This  example  shows  another  fea¬ 
ture,  the  system  assumes  that  when  you  say  “IT”  you  mean 
the  item  mentioned  last. 

ADVEN-80  is  fairly  flexible  when  it  comes  to  entering 
English,  (depending  on  the  database).  For  example,  you  may 
enter  GO  SOUTH  or  simply  S.  You  may  say  GET  LAMP  or 
TAKE  THAT  LAMP.  If,  for  example,  the  player  were  to  say 
RUB  THE  LAMP,  a  particular  effect  may  occur.  If  it  is  neces¬ 
sary  to  immediately  repeat  such  an  action,  he  may  either  re¬ 
enter  RUB  THE  LAMP,  or  if  preferred,  he  may  simply  en¬ 
ter  AGAIN.  The  idea  for  this  was  taken  from  a  magazine 
article  on  ZORK7.  On  long  inputs  this  can  save  a  small  amount 
of  key  pressing  and  so  was  considered  to  be  a  worthwhile  addi¬ 
tion  to  the  system. 

Due  to  a  potentially  fairly  massive  vocabulary,  the  system 
can  make  sense  out  of  many  sentences,  but  of  course  this  must 
not  be  confused  with  real  intelligence  (as  anyone  actually 
creating  the  database  could  not  fail  to  notice! !).  So  if  you  try 
to  confuse  the  program,  then  you  probably  will  succeed,  so 
be  sensible.  .  .  .  The  present  version  was  written  under  the  M80 
macro  pre- processor5  and  assembled  by  ASMB,  the  Cromem- 
co  macro-assembler.  The  listing  shown  here  has  already  been 
run  through  M80  and  is  suitable  for  most  Z80  assemblers.  (The 
macro  pre-pass  accounts  for  the  excess  labels.) 

Readers  who  wish  to  use  the  programs  in  this  article  to 
create  their  own  Adventures  may  find  database  construction 
made  considerably  easier  by  starting  off  with  a  very  large  piece 
of  paper,  drawing  out  all  the  locations  as  large  “molecules.” 
Connect  them  together,  then  make  a  list  of  all  the  inter¬ 
connections,  followed  by  all  the  items  in  the  game,  and  where 
they  are  going  to  be  at  the  start  of  the  game.  Finally,  work 
through  the  game  location  by  location,  armed  with  as  many 
sketches  as  possible,  preferably  with  a  friend  known  to  be  a 
whizz  at  finding  faults  in  other  people’s  programs  .  .  .  really, 


you  won’t  get  it  right  first  time;  you’ll  probably  be  able  to 
work  through  a  game  by  yourself  with  no  problems,  then 
along  comes  young  Johnny,  totally  unaware  that  you’re  not 
supposed  to  try  EATING  the  AXE.  Hey,  presto,  another  slight 
bug  in  your  database  discovered!  Spend  a  lot  of  time  thinking 
out  the  game,  and  twice  as  much  time  debugging  it;  but  most 
of  all,  enjoy  yourself. 

(LISTING  ON  PAGE  14) 

References 

1  Scott  Adams.  Adventures  available  for  TRS-80,  Sorcerer,  Apple,  etc. 
2Mostek  Z80  manual. 

3“Grow”  by  Jeff  Levinsky.  Creative  Computing  magazine. 

4  “Adventure  II”  by  K.  Reed.  Practical  Computing  (Aug.  1980). 

SML80:  A  Structured  Machine- Oriented  Microcomputer  Language. 
By  L.  R.  B.  Pedroso.  AD/A-010  055. 

6“Fantasia”  by  P.  Scargill.  A  BASIC  Adventure  system.  Creative 
Computing  (1981). 

7“How  To  Fit  a  Large  Program  Into  a  Small  Machine”  by  Marc  S. 
Blank  and  S.  W.  Galley.  Creative  Computing  (July  1980). 

®“How  To  Write  an  Adventure”  by  Gregg  Hassett.  Creative  Computing 
(July  1980). 


If  you  think  you  have  an  idea  that  would  be 
of  interest  to  DDJ  readers, 
we  would  like  to  discuss  it  with  you. 
Contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


13 

473 


Adven-80  (Text  begins  on  page  8) 
Listing  I 


ADVEN-80 

An  Advintur*  Gam*  System 
Dctignad  tor  and  1  mplamanttd  in  Z80  fiicroproca 
Assembly  Language.  AUGUST ’80  TO  APRIL’ 81 

Ra I aaiad  for  NON-COHMERC I AL  USE  ONLY 
1981  Peter  D.  Scargill 


ASSEMBLY  NOTES  i 

The  Assaablar  utad  to  product  the  objact  aodula  Mam  A SMB 
the  Cromamco  Macro  Assembler.  Tha  prcatnt  objact  aodula 
runs  to  undar  4K ,  and  may  be  onginatad  at  any  address 
in  systam  RAM  mamory. 


FL21  «  "M 


iStoraga  araas 


RANSEED 

CCOUNT 

SPEC 


This  program  warn  inspirad  by  Scott  Adams  Advantura  sanas 
and  tha  dasign  Mas  inf luancad  by  savaral  idaas  ganaratad 
with  tha  halp  of  K.  Raad  of  S.P.L.  Intarnational . 


* 

TRUE 

EQU 

FALSE 

EQU 

1 

CPM 

DL 

ORG 

lOOH 

{Chosen  for  CP/M  convenience. 

SPLIT 

JP 

RUNB 

(Skip  reserved  RAM  area. 

CECMO 

DL 

; 

MMAP 

DL 

{CONDITION  EQUATES 

(Must  not  be  changed  or  re-ordered) 

VDWIDE 

EQU 

1 

VDHT 

EQU 

CL 

EQU 

1 

{Currant  Location  xx 

ncl 

EQU 

2 

(Current  location  not  xx 

HEADLN 

EQU 

OP 

EQU 

3 

{Objact  xx  present  (carr i ad /worn  etc) 

CLEARS 

EQU 

oc 

EQU 

4 

1  Object  xx  carried 

HOME  UP 

EQU 

OW 

EQU 

3 

{Object  xx  worn 

HOMED* 

EQU 

owe 

EQU 

6 

lObject  xx  carried/worn 

HALFCL 

OH 

EQU 

7 

{Object  xx  here  but  not  carried/worn 

MEMTOP 

EQU 

ONP 

EQU 

8 

lObject  xx  not  present 

SYSRET 

EQU 

ONC 

EQU 

9 

{Object  xx  not  carried 

ONW 

EQU 

10 

lObject  xx  not  carried 

AGAIN 

EQU 

NWC 

EQU 

1 1 

lObject  xx  not  worn 

RTN 

EQU 

ONH 

EQU 

12 

lObject  xx  not  here,  maybe  carried/worn 

LINLEN 

EQU 

OE 

EQU 

13 

lObject  xx  exists 

THEN 

EQU 

ONE 

EQU 

14 

{Object  xx  does  not  exist 

8L 

EQU 

15 

{Object  xx  is  at  location  yy 

N9L 

EQU 

16 

lObject  xx  not  at  location  yy 

RND 

EQU 

17 

{Random  xx  where  xx  1  to  234  inclusive 

TF 

EQU 

IB 

(Flag  xx  -  yy 

LONMSG 

NTF 

EQU 

19 

|Flag  xx  yy 

CONMSG 

GC 

E.QU 

20 

(Flag  xx  >■  yy 

CONMSG 

LT 

EQU 

21 

(Flag  xx  <  yy 

C2 

EQU 

22 

1 2nd  word  ■  xx 

C3 

EQU 

23 

1 3rd  word  ■  xx 

I  Start 

Of  ADVCN- 

(sets  up  random 

NC2 

EQU 

24 

|2nd  word  not  ■  xx 

1 

NC3 

EQU 

23 

1 3rd  word  not  ■  xx 

» 

I  ACTION  EQUATES 

RUNB 

LD 

1 

CALL 

INV 

EQU 

1 

{Print  inventory  of  car r i ed /worn  items 

LD 

TKE 

EQU 

2 

{Get  xx  to  carry 

CALL 

WR 

EQU 

3 

{Get  xx  to  wear 

CALL 

DR 

EQU 

4 

{Drop  xx 

1 

PR 

EQU 

5 

iPrint  UMESS(xx) 

LD 

PRM 

EQU 

6 

{Print  MESS ( xx ) 

LD 

DL 

EQU 

7 

iDescnbe  the  location  xx 

LD 

SF 

EQU 

8 

(Set  flag  x x -  yy 

CALL 

D8C0B 

EQU 

9 

(Describe  the  object 

1 

SWP 

EQU 

10 

{Swap  object  xx  with  xx+1 

1 

MV 

EQU 

11 

(Go  to  location  xx 

{Main  program  1 

OK 

EQU 

12 

(Say  OK  and  leave  table 

I 

QT 

EQU 

13 

(Quit,  printing  present  score 

1 

INF 

EQU 

14 

1  Increment  flag  xx 

RUN 

CALL 

DEF 

EQU 

13 

(Decrement  flag  xx 

1 

EX 

EQU 

16 

{Exit  table 

AFTDK 

CALL 

SC 

EQU 

17 

{Print  current  score 

CALL 

PU 

EQU 

IB 

(Put  object  xx  into  location  yy 

JR 

CR 

EQU 

19 

1  Create  object  xx 

CALL 

DES 

EQU 

20 

(Destroy  object  xx 

GTENTR 

CALL 

FLIP 

EQU 

21 

LD 

LA 

EQU 

22 

(Look  around  at  items 

LD 

SMA 

EQU 

23 

(Set  up  message  xx 

1 

SMB 

EQU 

24 

l Set  up  message  yy 

8RT0UT 

LD 

WT 

EQU 

23 

(Wait  for  xx  seconds  ( 4MHZ ) 

LD 

PF 

EQU 

26 

(Print  decimal  value  of  f 1 ag  xx 

LD 

ATF 

EQU 

27 

(Add  to  flag  then  clear. 

LD 

SFF 

EQU 

28 

(Subtract  from  flag  then  clear. 

CP 

GRUN 

EQU 

29 

(Print  Place,  directions  etc. 

JR 

DEFB  OO  list  Optional  Massaga 

DEFB  OO  1 2nd  Optional  Massaga 

J  DEFB  00  iByta  rasarvtd  for  1 atast  objact  na me 

R  DEFS  60  1 60  Byta  Lin*  Buffar 

DEFS  04  | Tamporary  buffar 

F  DEFB  OO  j  Cod ad  text  stor*  V  batch  buffar 

DEFS  14 

DFFB  OO  | 2nd  Buffar  for  ’AGAIN’ 

DEFS  14 

T  DEFB  OO  {Tamporary  stor*  for  availabl*  ax  its. 

DEFS  30 

ED  DEFS  01  (Last  random  number  store 

T  DEFB  OO  {Character  count 

DEFB  OO  {Status  of  SPECIAL  text. 

DEFS  16  {STACK  for  ’SPECIAL’  aassage  systam. 

E  DEFS  4  {Temporary  stor*  for  BIN-A8CII 

DEFB  OO  {Temporary  stor* 

DEFB  OO  {Negation  flag  for  text 

ral  program  equates.  (Modify  for  different  systems) 


TRUE  | Terminal  currently  sat  up  for  CP/M. 
FALSE  | Spl i t— screen  system  Active. 

FALBE  {Echo  input  chars  on  screen. 

FALSE  {Using  a  memory-mapped  Device 

90  I  No.  characters  per  line  on  my  screen. 

24  {No.  lines  on  screen. 

VDWI DEtVDHT 

VDHT/2  {Lines  cleared  for  split  top  half. 

26  {Clear  Screen  on  TVI920C 

30  (Home  up  command  on  TVI920C 

31  {Internal  Memory  mapped  screen  handler. 

29  (  "M"  "  »  " 

OF BOOH  {For  memory  mapped  screens,  Top  left. 
OOOO  (Return  to  CP/M 

232  (DO  NOT  change.  For  repeat  line. 

249  (Special  place,  returns  last  location. 

VDWIDE-10  {Set  for  Maximum  line  length-10 

230  {Don’t  alter  this.  Duplicate  in 

I  database. 


ASSEMBLY-TIME  CONSOLE  MESSAGES 


Configuring  Adven-80  Adventure  system. 


A, CLEARS 

COUT 

HL.TITL1 

MPRINT 

CHRIN 

A,  R 

< RANSEED) , A 
A, CLEARS 
COUT 


(Initialise  screen. 

(Print  heading  blurb 
{Routine  to  do  the  hard  work 
{Wait  for  any  key 

{Completely  random  seed 
{Save  it  in  buffer 
{Clear  my  screen 


Main  program  loop.  Start  by  printing  location  description. 


I  These  GLOBALS  link  this  program  module  to  the  main  database 
* 

GLOBAL  OBJLOC  (Object  present  location  table. 

GLOBAL  OBJDES  (Simple  object  description  table. 
GLOBAL  MATCHW  | Keyword  match  pair/Action  table. 
GLOBAL  TITL1  (Database  title. 

GLOBAL  MSG  {Standard  system  messages. 

GLOBAL  UMESS  (Individual  database  messages. 

GLOBAL  TABKEY  { Keyword /substi tut*  table. 

GLOBAL  OBJDSK  (Object  special  descriptions. 

GLOBAL  OBPROP  (Properties  of  restricted  objects. 

GLOBAL  LOC  (Location  table. 

GLOBAL  FLAG  (Flag  table 

GLOBAL  FL14  (Refs  within  the  table 

GLOBAL  FL20  {  "" 


LD 

OR 

LD 

JP 

LD 

QNOP  DEC 
LD 
CP 
JR 

MOREDI  LD 
OR 
JR 
LD 
CP 
JR 
INC 


STABLE 

IBTCH 

Z , 8TENTR 

BEFA 

ENTRY 

A,  R 

(RANSEED) , A 

I Y, WAYOUT 
IX, FLAG 
HL.CODBUFM 

A,  <HL> 

251 

NZ.QWOP 
A, (LSTOBJ) 

A 

E,0 

Z , ENDMAT 
<HL) , A 
HL 

A,  (HL) 

13 

NC, XMATCH 
A, (IY+0) 

A 

Z, XMATCH 
A,  (IYM) 
(HL) 

Z , DFND 
IY 


(Describe  location  !■  ’can  see.. 

( Set  up  f 1 age 

(check  if  wa  are  batching 

(2nd  optional  message 
(Set  user  input. 

(Set  up  random  number. 


(Point  to  available  exits 
(Point  to  flags 

(Look  8  2nd  word  in  code  buffer 

(Look  for  the  code  for  ’IT* 

(If  found,  get  last  object 
(Test  Acc. 

(If  no  last  object.  Error, 
(otherwise  save  in  buffer. 
(Point  back  to  start  of  CODBUF 

(See  if  this  is  a  direction 

(Compare  with  available  exits 

(Found  a  direction  to  go  ??? 


(Skip  description  of  direction 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


INC 

IY 

INC 

IY 

JR 

HOREDI 

I  Look  for  anothar  ox  1 1 

DFND 

LD 

A, ( I Y+2) 

CP 

RTN 

1  Is  this  a  raturn 

JR 

NZ , BASL 

LD 

A, (IX+20) 

jlf  so,  ratnava  old  location 

BASL 

PUSH 

A F 

LD 

A, ( I X* 1 4 ) 

LD 

< I X+20) , A 

1  Do  a  Map . 

POP 

AF 

LD 

(IX+14)  ,A 

(Put  naw  location  in  FLAG  tabla 

, 

JP 

RUN 

land  go  to  it. 

1 

|  Look 

to  aaa  if 

m*  ara  in 

tha  aiddla  of  a  batch  of  coaaands 

1  and  : 

If  so,  sat 

Zaro  flag 

alsa  rasat  it. 

IBTCH 

PUSH 

HL 

|Sava  HL 

LD 

HL , CODBUF 

1  Point  to  start  of  buffar 

I BTPL 

LD 

A,  (HL) 

OR 

A 

I  If  you  hit  and,  than  no  batch. 

JR 

Z,  NBTCH 

CP 

THEN 

JR 

Z, ZBTCH 

1 I f  find  THEN,  is  batch  lina. 

INC 

HL 

JR 

I  BTPL 

ZBTCH 

LD 

A,  253 

*  Sat  or  Rasat  Zaro  flag  as 

NBTCH 

INC 

A 

1 naccassary. 

POP 

HL 

1  Rastora  HL 

RET 

I 


I  X MATCH 


|This  saction 

looks  at  CODBUF 

to  saa  if  any  sansa  can  ba  aada 

|of  tha  codas 

.  (This  is  AFTER 

diraction  chacks  hava  baan  aada.) 

| i f  no  sansa 

than  a  raquast  fo  ra-phrasaing  is  aada  alsa  action 

(is  takan. 

X MATCH  LD 

I X , CODBUF 

1  Point  IX  to  usar  input  aft ar 

EXX 

itraataant,  chocking  for 

LD 

HL , OBPROP 

llagality  in  tha  casa  of  an 

FLNA  INC 

HL 

lobjact.  (Chock  OBPROP). 

LD 

A, (HL) 

OR 

A 

JP 

Z.ENCHK 

(Not  a  apacial  objact  ??? 

CP 

(IX+1) 

JP 

Z , FNBYTE 

1  Got  as  aatch. 

FLNB  INC 

HL 

lOtharaisa  skip  to  naNt. 

LD 

A, (HL) 

OR 

A 

JP 

NZ , FLNB 

JP 

FLNA 

FNBYTE  INC 

HL 

LD 

A, (HL) 

OR 

A 

JP 

Z,  ILEQL 

CP 

(IX+O) 

iChack  is  lagal. 

JP 

Z , ENCHK 

JP 

FNBYTE 

ILEQL  EXX 

LD 

HL.MSG 

lothorwisa  say  not. 

LD 

B,  46 

JP 

HOPM 

ENCHK 

EXX 

1 

LD 

A,  (IX+l) 

(Sava  this  byta 

LD 

(SAVIX) , A 

LD 

I Y, HATCHW 

1  Sat  to  start  of  tabla. 

LD 

DC ,  00 

1 Rasat  pointars 

NEXTK 

LD 

A, (SAVIX) 

1  Gat  byta  back 

LD 

(IX-M) ,A 

LD 

A,  ( I Y+0) 

OR 

A 

JR 

NZ , NOTENDM 

1  If  not  and  than  skip. 

ENDMAT 

XOR 

A 

OR 

E 

iChack  valua  in  E. 

1 

IF 

SPLIT 

CONMSG 

Split  scraan 

configuration 

JP 

ENDIF 

NZ , RUN 

I  If  coaaand  undarstood,  siaply 

1 

IF 

NOT  SPLIT 

CONMSG 

Noraal  tarainal  configuration 

JP 

ENDIF 

NZ,  AFTDK 

1 Raturn  for  noxt  input 

1 

IF 

MMAP 

CONMSG 

ENDIF 

Maaor  y-aappad 

l  output  davico. 

1 

LD 

HL, CODBUF 

LD 

A, (HL) 

CP 

13 

1 Saa  if  this  was  a  diraction. 

LD 

HL, MSG 

JR 

NC, DNFOL 

LD 

B,  21 

|Print  "Not  valid  diraction" 

JP 

HOPM 

DNFOL 

LD 

B,  20 

I  "Don't  follow  you" 

HOPM 

CALL 

MFETCH 

HOMU 

1 

IF 

SPLIT 

JP 

ENDIF 

RUN 

1 

1 

I  First , 

IF 

JP 

ENDIF 

NOT  SPLIT 
AFTDK 

input  pair.  If 

aithar  is  233  than  this  is  troatad 

chock 

I  as  WILDCARD  It  paiscd .  Is  nacattary  for  certain  CONDITION/ 
I  ACT I ON  aata  that  oust  ba  run  a* tar  EVERY  input. 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


15 

475 


Adven-80  (Listing  continued,  text  begins  on  page  8) 


( 

LD 

B,  23 

NOTENDH 

LD 

A, < I Y+0) 

JP 

HOPH 

CP 

2S3 

(Check  1st  Char. 

OBFND 

INC 

HL 

JR 

Z, CHSND 

1 

CP 

<IX*0> 

Ilf  we 

JR 

NZ, FAILTHS 

( If  no  match  then  FAILED 

CHSND 

LD 

A, (IY+1) 

(in  the 

CP 

233 

(Another  WILDCARD  ??? 

JR 

Z, PASED 

LD 

A, ( IYM  > 

CP 

< IX^l > 

OR 

A 

JR 

Z, PASED 

JR 

NZ, ALAX 

i 

LD 

A, (HL) 

(This  section 

sets  the  IY  pointer  to  the  start  of  a  new  set  of 

CP 

( condi t ; 

i  ons/act i ons. 

JR 

NZ, ALAX 

i 

INC 

HL 

FAILTHS 

INC 

IY 

INC 

FA I LOOP 

INC 

IY 

LD 

A, <IY*0> 

ALA* 

LD 

D,  (HL ) 

CP 

233 

LD 

A,  ( IYrO) 

JR 

NZ  , FA I LOOP 

(Look  for  next  sect l on -ACT IONS 

FAILLX 

INC 

IY 

I  SOP 

CP 

OP 

LD 

A,  ( IY4-0) 

JR 

NZ.LB6 

CP 

233 

LD 

HL.FL14 

JR 

NZ, FAILLX 

(Look  for  new  set 

LD 

INC 

IY 

CP 

D 

JP 

NEXTK 

(Look  for  another  set  to  match 

JP 

Z.SKPi 

1 

LD 

A,  234 

(This  section 

looks  at  conditions  in  current  list  l  determines 

(whether  or  not  these  are  all 

valid. 

JP 

Z.SKPI 

1 

LD 

A,  233 

PASED 

LD 

E,  1 

(Hake  flag  non-iero 

HOPZ  1 

CP 

D 

SKP1 

INC 

IY 

(Skip  over  Key  set. 

JP 

HOPZ 

INC 

IY 

LD 

A,  CIY-K» 

LB6 

CP 

233  ( Chec  k 

in  case  there  are  no  more  conds. 

ISO C 

CP 

OC 

JP 

Z , ACTONI T 

(If  not,  go  to  action  section. 

JR 

NZ.LB7 

1 

LD 

A,  234 

(First  of  the 

conditions  as  outlined  in  the  EQUATES  section. 

JR 

HOPZ  1 

CP 

C2 

LB7 

JR 

NZ.LBO 

(Simple  coapar i sons 

I  SOW 

CP 

OW 

LD 

A,  <IYM> 

JR 

NZ.LB8 

CP 

<IX*1> 

LD 

A,  233 

HOPZ 

JR 

Z , SKP1 

(HOPZ  is  used  as  stepping  stone 

JR 

HOPZ  1 

JP 

FAILTHS 

(Saves  few  bytes  here  It  there. 

( 

LB8 

LBO 

(Forgive  the  excess  labels. 

ISOH 

CP 

OH 

(turned  out  by  the  Macro  Assm. 

JR 

NZ.LB9 

I  SC  3 

CP 

C3 

LD 

HL.FL14 

JR 

NZ.LBl 

LD 

A,  < HL > 

LD 

A,  (IYM) 

JR 

HOPZ  1 

CP 

< 1X^2) 

JR 

HOPZ 

(Just  saved  3  bytes  !  (Oee) 

LBV 

ISOWC 

CP 

owe 

LB1 

JR 

NZ , LBIO 

ISNC2 

CP 

NC2 

LD 

A,  234 

JR 

NZ.LB2 

CP 

D 

LD 

A,  <IY«-1> 

JP 

Z.SKPI 

DEC 

A 

CP 

(IX41) 

HOPNZ 

JR 

NZ.SKPl 

(Stepping  stone  for  a  different 

JP 

FAILTHS 

(condition. 

( 

JR 

HOPZ  1 

LB2 

ISNC3 

CP 

NC3 

LBIO 

JR 

NZ.LB3 

(All  comparisons.  No  actions. 

ISONP 

CP 

ONP 

LD 

A,  (IY-M) 

JR 

NZ.LB11 

CP 

<IX*2> 

LD 

HL , FL 1 4 

JR 

HOPNZ 

(Just  saved  another  3  bytes  1 

LD 

A, (HL) 

1 

CP 

D 

LB3 

JP 

NZ.SKPl 

ISCL 

CP 

CL 

LD 

A,  234 

JR 

NZ,LB4 

(Here  comparing  loc.  number  in 

CP 

D 

LD 

HL.FL14 

(pair  buffer  with  present  loc. 

JP 

NZ.SKPl 

LD 

A, (HL) 

HOPNZ 1 

CP 

D 

CP 

<IY*1 ) 

(stored  in  flag  14. 

JP 

HOPNZ 

JP 

HOPZ 

1 

1 

LB1 1 

LB4 

ISONC 

CP 

0NC 

ISNCL 

CP 

NCL 

JR 

NZ.LB12 

JR 

NZ , LBS 

(This  as  above  but  the  outcome 

LD 

A,  254 

LD 

HL.FL14 

(is  the  opposite. 

JP 

HOPNZ 1 

LD 

A, (HL) 

CP 

<IYM> 

LB12 

JP 

HOPNZ 

ISONW 

CP 

ONW 

I 

JR 

NZ.LB13 

LBS 

LD 

A,  253 

IBOPP 

CP 

RND 

(Are  we  talking  here  about 

JP 

HOPNZ 1 

JP 

NC, I8RND 

(objects,  or  should  we  skip 

t 

LD 

A, < I YM ) 

(the  next  few  comparisons. 

LB13 

OR 

A 

ISNWC 

CP 

NWC 

JR 

NZ , CHZR 

JR 

NZ.LB14 

LD 

A,  (IXM> 

(Check  if  the  user  actually 

LD 

A,  234 

OR 

A 

(did  enter  an  object  name. 

CP 

D 

JR 

NZ, NOTUSR 

JP 

NZ.SKPl 

LD 

HL , MSG 

(If  not,  send  a  nasty  message. 

DEC 

A 

LD 

B,  33 

JP 

HOPNZ 1 

JP 

HOP* 

| 

1 

LB1 4 

CHZR 

LD 

(IXM)  ,A 

(He  did,  eh,  let’s  go  find  it. 

ISONH 

CP 

ONH 

NOTUSR 

LD 

HL , OBJLOC 

JR 

NZ.LB13 

NTX 1 

LD 

A, (HL) 

LD 

HL.FL14 

OR 

A 

(If  we  reach  end  of  the  table 

LD 

A, (HL) 

JR 

Z , CNFND 

(then  no  object. 

JP 

HOPNZ 1 

CP 

<IXM> 

1 

JR 

Z , OBFND 

(Found  it  ! ' 

LB13 

ISOE 

CP 

OE 

INC 

HL 

JR 

NZ.LB16 

JR 

NTX  1 

LD 

A,  233 

CNFND 

LD 

HL.HSQ 

(Can’t  find  thing.  Tell  him. 

JP 

HOPNZ 1 

(Put  location  in  the  D  re g. 

bjoct  n«M  entered  by  liter ,  we 
his  is  correct  vertion  of  object 
ject  such  as  a  lamp. 

j Oat  user  input 

I  Is  it  non-SKistant  version  ? 

I  If  so,  go  to  sxisting  version. 

I Oat  ths  verb  back. 

(Continue  looking  as  before. 

| Is  it  here  ?? 

f Is  hs  carrying  it  ?? 

I  or  Nearing  i  t  ?? 


(Carrying  only  this  time. 


I  Wear i ng  perhaps  ??? 


(Is  objsct  worn.... 

| or  psrhaps  carried  ??? 


I  Now  for  opposites  to  above. 


(Exactly  as  above  but  opposite 
( resul t . 


(Is  objsct  NOT  carried  ?? 


( Is  it  NOT  worn  ?? 


(NOT  worn  or  carried  ?? 


(NOT  here  ?? 


(Does  it  even  EXIST  ???? 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


I 

LB16 


I 

LB26 


ISONE 

CP 

ONE 

ABMB 

CP 

SMB 

JR 

NZ.LB17 

l*nd  opposits  question. 

JR 

NZ.LB27 

(Set  2nd  optional  message  99 

LD 

A,  233 

JP 

HOPZ1 

LD 

A,  < IY+1) 

1 

LD 

(XBEFA) , A 

JR 

HOPC 

LB17 

IS9L 

CP 

9L 

LB27 

JR 

NZ.LB18 

»!•  anywhere  in  particular. 

AWT 

CP 

WT 

LD 

A, < IY+2) 

JR 

NZ.LB28 

(Wait  around,  perhaps  99 

CP 

D 

LD 

B,  <  I Ya- 1  > 

INC 

IV 

WTLP 

PUSH 

BC 

(A  really  simple  delay  loop. 

JP 

HOPZ 

LD 

B,  255 

i 

WTLP1 

PUSH 

BC 

LB  1 8 

LD 

B,  233 

ISN9L 

LD 

A, (IY+2) 

(Or  not. 

LZLO 

CP 

D 

PUSH 

AF 

(Clumsy  but  it  works. 

INC 

IY 

POP 

AF 

JP 

HOPNZ 

PUSH 

AF 

1 

POP 

AF 

ISRND 

CP 

RND 

DJNZ 

LZLO 

JR 

NZ.LB19 

1  Looking  for  a  random  chance  ?9 

POP 

BC 

RANDOM 

CALL 

RANH 

DJNZ 

WTLP1 

CP 

(IY-M) 

POP 

BC 

JP 

C.SKPl 

DJNZ 

WTLP 

JP 

FAILTHS 

JP 

HOPC 

LB19 

( 

LB28 

ISTF 

PUSH 

DE 

AINV 

CP 

INV 

LD 

HL,  FLAG 

JR 

NZ.LB29 

(An  inventory  perhaps  99 

LD 

E, (IY*1> 

LD 

C,0 

(Yes  99  Mel  1  print  carrying. 

D,  0 

CALL 

ICANC 

ADD 

HL ,  DE 

LD 

C,  1 

(Also  wearing. 

POP 

DE 

CALL 

ICANC 

t 

JP 

ACTONIT 

CP 

TF 

JR 

NZ.LB20 

1  Do  ms  want  to  test  a  flag  99 

LB29 

LD 

A, (HL) 

ALA 

CP 

LA 

CP 

<IY*2> 

JR 

NZ.LB30 

(A  look  around  maybe  99 

INC 

IY 

LD 

C,  2 

JP 

HOPZ 

CALL 

ICANC 

» 

JP 

ACTONIT 

LB20 

ISNTF 

CP 

NTF 

LB30 

JR 

NZ.LB21 

» Or  test  it  for  Not  a  value  ?? 

AEX 

CP 

EX 

LD 

A, (HL) 

JR 

NZ  , LB3 1 

lExit  the  table  maybe  99 

CP 

( IY>2) 

CALL 

IBTCH 

INC 

IV 

JP 

Z  ,  AF  TDK 

JP 

HOPNZ 

; 

IF 

SPLIT 

LB21 

JP 

RUN 

ISGE 

CP 

GE 

END  IF 

JR 

NZ.LB22 

(Greater  than  or  equal  test. 

LD 

A, (HL) 

IF  NOT 

SPLIT 

CP 

( I Y^2) 

JP 

AFTDK 

INC 

IY 

END  IF 

JP 

Z.SKPl 

JP 

NC.SKPl 

LB3 1 

JP 

FAILTHS 

; 

ACT 

CP 

QT 

LB22 

JR 

NZ.LB32 

1  Want  to  qui  t  ... 

LD 

HL  ,  MSG 

1 Qui ting  Mi th. . . 

LD 

B,  27 

IBLT 

CP 

LT 

CALL 

MFETCH 

JR 

NZ.LB23 

1  Less  than  test. 

PUSH 

IX 

LD 

A, (HL) 

LD 

IX,  FLAG-*- 1  3 

CP 

( IY+2) 

CALL 

PNUMBER 

1  decimal  number 

INC 

IY 

POP 

IX 

JP 

C,SKP1 

LD 

B,  2B 

JP 

FAILTHS 

CALL 

MFETCH 

1 poi nts. 

LB23 

JP 

SYSRET 

1  EXIT  HERE 

DANGER 

LD 

HL , MSG 

1  reserved  for  emergencies. ? 

1 

LD 

B,  26 

LB32 

CALL 

MFETCH 

land  print  an  error  message. 

AOK 

CP 

OK 

JP 

FAILTHS 

JR 

NZ.LB33 

(Print  OK  and  exit  99 

1 

CALL 

IBTCH 

I  This  is  ACTION  ssc t ion. 

This  only  reached  assuming  that 

JP 

Z,  AFTDK 

I«ll  ths  above 

condi ti ons 

(as  applicable)  have  been  met. 

LD 

HL, MSG 

1 

LD 

B,  29 

ACTON IT 

INC 

IY 

(Skip  over  the  delimiter. 

JP 

HOPM 

LD 

A, ( IY+O) 

CP 

233 

(Get  action  key-check  last  one. 

LB33 

JR 

NZ.ACTOl 

(Ok,  get  next  key  set. 

ASC 

CP 

SC 

INC 

IY 

JR 

NZ.LB34 

(Present  score  99 

JP 

NEXTK 

(Else  finish. 

LD 

HL , MSG 

1 

PUSH 

IX 

ACT01 

CP 

SMA 

PUSH 

IY 

JR 

NZ.LB24 

1  Set  1st  optional  message  '??? 

PU8H 

DE 

LD 

A, ( IY+1 ) 

LD 

B,  30 

LD 

(XNCO) , A 

CALL 

MFETCH 

HOPC 

INC 

IY 

POP 

DE 

JP 

AC TON IT 

POP 

IY 

; 

POP 

IX 

LB24 

PUSH 

IX 

CP 

OP  UN 

LD 

IX, FLAG* 13 

JR 

NZ.LB23 

CALL 

PNUMBER 

|Just  like  quiting  only 

JP 

RUN 

POP 

IX 

(different . 

1 

CALL 

CRLF 

LB2S 

JP 

ACTONIT 

APF 

CP 

PF 

» 

JR 

NZ.LB26 

(Print  a  flag  value  9? 

LB34 

PUSH 

HL 

AMV 

CP 

MV 

PUSH 

IX 

JR 

NZ.LB33 

1  change  locations,  perhaps  99 

LD 

Ev (IY+l) 

LD 

HL.FL14 

LD 

HL , FLAG 

LD 

A, (IY+1) 

LD 

D,  0 

CP 

RTN 

( Is  this  a  return  999 

ADD 

HL,  DE 

JR 

NZ, AMV1 

PUSH 

HL 

LD 

HL.FL20 

POP 

IX 

LD 

A, (HL) 

CALL 

PNUMBER 

(This  prints  the  decimal  value. 

AMV1 

PUSH 

AF 

POP 

IX 

LD 

HL.FL14 

POP 

HL 

LD 

A, (HL) 

JR 

HOPC 

LD 

HL.FL20 

Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


17 

477 


Adven-80  (Listing  continued,  text  begins  on  page  8) 


LD 

(HL) , A 

LD 

HL , FL  1 4 

POP 

AF 

LD 

(HL) , A 

JP 

RUN 

; 

LB35 


APR 

CP 

PR 

JR 

NZ.LB36 

LD 

HL , UMESS 

APRPL 

LD 

B,  <  IY-M  ) 

PUSH 

IX 

PUSH 

IY 

PUSH 

DE 

CALL 

MFETCH 

POP 

DE 

POP 

IY 

POP 

IX 

JP 

HOPC 

; 

LB36 


APRM 

CP 

PRM 

JR 

NZ.LB37 

LD 

HL, MSG 

JR 

APRPL 

I 

LB37 


AFLIP 

LD 

HL, FLAG 

PUSH 

DE 

LD 

D.O 

LD 

E, ( I Y+ 1 ) 

ADD 

HL,  DE 

POP 

DE 

* 

CP 

FLIP 

JR 

NZ.LB3B 

LD 

A, (HL) 

OR 

A 

JR 

NZ.MAKO 

LD 

A,  1 

JR 

MAK01 

MAKO 

XOR 

A 

MAK01 

LD 

(HL) ,A 

JP 

HOPC 

LB3B 


AIN 

CP 

INF 

JR 

NZ , LB39 

INC 

(HL) 

JP 

ACTONIT 

LB39 

ADEF 

CP 

DEF 

JR 

NZ.LB40 

DEC 

(HL) 

JP 

ACTONIT 

LB40 


ASF 

CP 

8F 

JR 

NZ.LB41 

LD 

A,  ( IY^2) 

LD 

(HL) ,A 

INC 

IY 

JP 

HOPC 

I 

LB41 


CP 

ATF 

JR 

NZ.LB42 

LD 

A, (IY*2) 

LD 

(IY+2) ,0 

ADD 

(HL) 

JR 

C(  BRBXA 

LD 

(HL)  ,  A 

JR 

BXRL 

BRBXA 

LD 

(HL) ,233 

BXRL 

INC 

IY 

JP 

HOPC 

; 

LB42 


CP 

SFF 

JR 

NZ.LB43 

LD 

A, (HL) 

SUB 

(IY^2> 

LD 

( 1 Y^2) , 0 

JR 

C, SEFAP 

LD 

(HL) ,A 

JR 

SAFAP 

SEFAP 

LD 

(HL) ,0 

SAFAP 

INC 

IY 

JP 

HOPC 

LB43 


ADL 

CP 

DL 

JR 

NZ.LB44 

LD 

HL.FL14 

LD 

B, (HL) 

LD 

HL, LOC 

PUSH 

IX 

PUSH 

IY 

PUSH 

DE 

CALL 

MFETCH 

POP 

DE 

POP 

IY 

POP 

IX 

JP 

ACTONIT 

; 

LB44 

ROBJ  LD 
OR 
JR 


A, (IY*1> 

A 

Z.BMISTHS 


(Simply  ant ar  up  naw  location. 


(Print  a  mass.  *  r  om  UfiESS  tabla 


; Or  fr om  MESS  tabla.  ! ! ' ' 


(Talking  about  FLAGS  now. 


I HL  points  to  ralavant  flag. 


(Flip  a  flag  7? 


I Incramant  it  77 


I  Or  dacra 


t  it  7777 


;Sat  to  a  naw  valua  7? 


i Add  to  flag 

(Wipaout  valua  ao  it  wont  ba 
lutad  again. 


I  If  >233  than  aaka  233 


(Subtract  froa  flag 


( If  <0  than  aaka  00 


( Datcnba  a  location. 


(PUT  OBJ.  NO.  INTO  (IX+1) 


LD 

( I X+ 1 > , A 

LD 

D,  A 

JR 

MISSTHS 

BMISTHS 

LD 

A, (IX+1 ) 

LD 

D,  A 

OR 

A 

JR 

NZ, MISSTHS 

LD 

HL , MSG 

LD 

B,  33 

JR 

AC  DAN  X 

MISSTHS 

LD 

HL, OBJ LOC 

MX5D 

LD 

A, (HL) 

OR 

A 

JP 

Z, ACDANGR 

CP 

D 

JR 

Z, FNDOBX 

INC 

HL 

INC 

HL 

JR 

MX5D 

FNDOBX 

LD 

A, (HL) 

LD 

(LSTOBJ ) , A 

INC 

HL 

(In  casa  of 

LD 

A, (IY-M) 

OR 

A 

JR 

NZ, ALAXZ 

LD 

A, (HL) 

CP 

232 

JR 

NZ, ALAXZ 

INC 

HL 

INC 

HL 

ALAXZ 

LD 

D, (HL) 

JP 

ANOTX 

AC  DANG R 

LD 

HL ,  MSG 

LD 

B,  31 

AC  DAN  X 

JP 

HOPH 

1 

ANOTX 

LD 

A, ( IY-*0) 

1 

CP 

DSCOB 

JR 

NZ.LB43 

LD 

HL ,  OBJ  D8K 

INC 

HL 

NOT  HR 

LD 

A, (HL) 

OR 

A 

JR 

Z , NODSC 

CP 

( IX  +  1 ) 

INC 

ML 

JP 

NZ , NOXR 

CALL 

MPRINT 

JP 

HOPC 

NOXR 

LD 

A,  (HL) 

INC 

HL 

OR 

A 

JR 

Z ,  NOT  HR 

JR 

NOXR 

NOD8C 

LD 

HL, MSG 

LD 

B,  43 

JP 

HOPH 

I 

LB43 


CP 

SWP 

JR 

NZ.LB46 

LD 

A, (HL) 

PUSH 

AF 

INC 

HL 

INC 

HL 

LD 

A, (HL) 

DEC 

HL 

DEC 

ML 

LD 

(HL) ,A 

INC 

HL 

INC 

HL 

POP 

AF 

LD 

(HL) , A 

DEC 

HL 

DEC 

HL 

JP 

HOPC 

LB46 


AGET 

CP 

TKE 

JR 

NZ.LB47 

CALL 

TOOHNY 

LD 

(HL) ,234 

BRTSB 

JP 

HOPC 

LB47 


AWR 

CP 

WR 

JR 

NZ.LB4S 

CALL 

TOOHNY 

LD 

(HL) ,233 

JR 

BRTSB 

LB48 


ADR 

CP 

DR 

JR 

NZ.LB49 

ADR1 

PUSH 

IX 

LD 

IX, FLAG 

LD 

A,  (IX-M4) 

LD 

(HL) ,A 

POP 

IX 

JR 

BRTSB 

I Pr oblaas  77  print  a  aassaga. 


(Can’t  find  objact  ???? 


(Sava  last  objact 


chack  for  tha  corract  variion. 


(If  not  corract ,  go  on  to 
(tha  naxt  ona. 


(Put  prasant  placa  in  D  rag. 

I Pr ob 1 aaa-at op  batching  fc  print 


(Daacriba  tha  objact. 
(Mias  1st  zaro 


(Wont  sat  flags 
(Print  ralavant  massaga 


(Swap  twin-stata  objacts  77 
(This  is  vary  clumsy. 


(Want  to  taka  an  objact  77? 
(Tast  to  «aa  if  ma  ara  carrying 
I  too  much  par haps. 


(Waar  an  itamy  mayba. . 
(Chack  again. 


(Drop  somathing,  thats  aasy. 


I 

LB49 


18 

478 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


RET 

Z 

(Return  if  no  message. 

LD 

HL.UMESS 

JP 

HFETCH 

OR 

A 

1 

JR 

Z , ENX  X 

I 

LD 

B,  A 

(This  routine  prints  out  a  decimal  number  pointed  to  by  IX.  The 

CALL 

HFETCH 

(range  if  0-233 

.  This  could 

probably  be  made  a  lot  shorter. 

JP 

ML  OOP 

(go  back  for  some  more 

ENX  X 

CALL 

CRLF 

(When  finished,  tidy  up 

EN1 

LD 

C,  2 

I 

CALL 

ICANC 

( I  can  see . 

PNUMBER 

PUSH 

IX 

CALL 

ONCO 

(1st  optional  messagei 

PUSH 

IY 

1 

LD 

I Y , NSTORE 

IF 

SPLIT 

LD 

<IY*0> ,0 

(put  zeros  in  buffer 

IF 

NOT  MHAP 

LD 

<IY+1> ,0 

LD 

A, HOME UP 

LD 

(IY+2)  ,0 

CALL 

COUT 

LD 

A, (IX+O) 

LD 

B, VDHT-2 

LD 

( I Y+3) , A 

RUNX2 

CALL 

CRLF 

BM1 

SUB 

lOO 

1  Hundreds 

DJNZ 

RUNX2 

JR 

C.BH2 

END  IF 

INC 

<IY*0) 

END  IF 

LD 

< I Y+3) , A 

1 

JR 

BM1 

IF 

SPLIT 

BM2 

LD 

A,  <IY-*-3> 

IF 

MMAP 

SUB 

10 

( tens 

LD 

A.HOMEDN 

JR 

C.BH3 

CALL 

COUT 

INC 

(IY-M) 

END  IF 

LD 

<IY*3> , A 

END  IF 

JR 

BM2 

1 

BM3 

LD 

A, ( IY+3) 

RET 

SUB 

01 

( units 

1 

JR 

C.BM4 

1  Hers  me  take 

user  input  and 

convert  into  single  byte  tokens. 

INC 

( IY+2) 

» 

i 

X 

0 

pi aced 

in  CODBUF. 

LD 

<  I Y+3)  f  A 

1 

JR 

BM3 

ENTRY 

LD 

HL.CODBUF 

(Look  first  in  case  t*e 

BM4 

LD 

A, ( IY+0) 

LD 

DE , CODBUF 

(are  in  the  middle  of  a  batch 

OR 

A 

LD 

A,  < HL ) 

(of  commands. 

JR 

Z.BM3 

OR 

A 

CALL 

CCOUT 

(print  with  leading  zero 

JR 

Z , ENTRX 

BH3 

LD 

A, (IY+1) 

(suppressed  on  1st  digit. 

BUFFZ 

LD 

A,  < HL ) 

CALL 

CCOUT 

INC 

HL 

BHA 

LD 

A, ( IY+2> 

OR 

A 

CALL 

CCOUT 

JR 

NZ, BUFFY 

POP 

IY 

LD 

HL.CODBUF 

POP 

IX 

LD 

(HL) , A 

RET 

JR 

ENTRY 

J 

BUFFY 

CP 

THEN 

CCOUT 

OR 

A 

(Simply  add  30  to  print. 

JR 

NZ, BUFFZ 

ADD 

A,  3 OH 

BUFFY1 

LD 

A, (HL) 

JP 

COUT 

INC 

HL 

1 

CP 

THEN 

1  Random 

number 

gen.  Nothing 

flash,  but  it  works.  Seeded  from 

JR 

Z , BUFFY 1 

xthe  refresh  rm 

rgister  at  the  start  of  the  game  and  each 

DEC 

HL 

(move  so  it  should  be  random. 

PUSH 

HL 

1 

LD 

BC , 000 1 

RANM 

LD 

A, (RANSEED) ; number  is  returned  in  Acc . 

XXLDR 

LD 

A, (HL) 

PUSH 

BC 

OR 

A 

Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


Adven-80  (Listing  continued,  text  begins  on  page  8) 


JR 

Z, XLDR 

CP 

(IX+3) 

INC 

HL 

JR 

NZ ,HISS 

INC 

BC 

JR 

X  XLDR 

XLDR 

POP 

HL 

LDIR 

GOTONE 

LD 

A,  C 

(Is  this  1st  word  77 

JP 

SRTOUT 

OR 

A 

I 

JR 

NZ , GHIR 

ENTRX 

CALL 

RANH 

1  Set  up  specials  (FL21  «.  22) 

LD 

A.B 

AND 

OlH 

|h«r».  Hake  comp  1  i  mantary 

1 

LD 

HL.FL21 

I  But  randoa. 

CP 

AGAIN 

LD 

(HL) , A 

JR 

NZ , LB32 

(Is  the  word  ’AGAIN’  7777 

XOR 

01 

LD 

HL.CODB2 

(If  so  then  retrieve  old  buffer 

INC 

HL 

LD 

DE, CODBUF 

(and  substitute  into  new  buffer 

LD 

(HL) ,A 

LD 

BC ,  0013 

(and  pretend  you’ve  Just  typed 

( 

LDIR 

(it  all  in  again  ! ! ! ! 

LD 

HL.CODBUF 

(Actual  start .  Zero  1st  byta 

( 

LB32 

XOR 

A 

(in  coda  butter. 

LD 

(HL) ,A 

8HIR 

LD 

(HL)  ,B 

(If  we  get  this  far,  success. 

LD 

HL, BUFFER 

(Point  to  antry  butter . 

INC 

HL 

LD 

BC,  0 

LD 

C,  1 

(Bet  flag  to  say  we  found 

CALL 

CRLF 

JP 

HORC 

(at  least  1  word. 

LD 

A,  ’  >* 

(Print  a  prompt. 

HISS 

LD 

A, (IY+3) 

(Check  end  of  this  block. 

CALL 

COUT 

INC 

IY 

ENT  1 

CALL 

CHRIN 

(Bat  a  character. 

INC 

IY 

CP 

ODH 

( End  of  line  77 

INC 

IY 

JR 

Z , END  I N 

INC 

IY 

CP 

7FH 

(Backspace  perhaps  77 

OR 

A 

JR 

Z, BACKS 

JP 

n,  xx 

CP 

3FH 

( BOTH  types. . 

JP 

horxx 

JR 

Z, BACKS 

ENDHESS 

LD 

(HL) ,0 

(Clear  last  3 

CP 

13H 

(CONT/U  to r  scrap  line. 

INC 

HL 

JR 

NZ, CONVUP 

LD 

(HL)  ,0 

LD 

A, ’  t’ 

INC 

HL 

CALL 

COUT 

LD 

(HL) ,0 

JR 

ENTRX 

(Try  again. 

LD 

A,  C 

CONVUP 

OR 

A 

OR 

A 

I 

JR 

NZ, GOTALOT 

IF 

CECHO 

LD 

HL, HSG 

CALL 

COUT 

(Not  to r  CPH 

LD 

B,  1 

END  IF 

CALL 

HFETCH 

(Select  1st  message  -  WHAT  ! 

* 

BIT 

6,  A 

IF 

SPLIT 

JP 

Z,  NOCONV 

(Check  for  upper  case 

CALL 

DESCR 

RES 

3,  A 

(If  not,  make  it  so. 

END  IF 

NOCONV 

CP 

20H 

1 

JR 

Z.HISTRP 

JP 

ENTRY 

(and  try  again 

CP 

'A* 

GOTALOT 

LD 

HL.CODBUF 

(Save  line  in  spare  buffer. 

JR 

C , ENT  1 

LD 

DE.C0DB2 

HISTRP 

LD 

(HL) , A 

(Save  a  good  character. 

LD 

BC, 0015 

INC 

HL 

LDIR 

INC 

B 

RET 

(else  return. 

LD 

A,  B 

( 

CP 

LINLEN 

(Get  present  count 

FIND18T 

LD 

A,  (DE) 

iGet  1st  4  latter*,  and  pad 

JR 

NC , END I N 

OR 

A 

•if  necessary. 

RET 

Z 

CP 

20H 

JR 

NZ , BRP 

JR 

ENT1 

(Bo  back  for  another. 

INC 

DE 

BACKS 

LD 

A,  B 

JR 

FIND  1ST 

OR 

A 

JR 

Z.ENT1 

DEC 

HL 

(or  perhaps  backup  one  char. 

DEC 

B 

1 

1 

BRP 

PU8H 

HL 

IF 

CECHO 

LD 

IX.BLK4 

LD 

A ,  06 

PUGH 

IX 

CALL 

COUT 

(Print  backspace. 

POP 

HL 

LD 

A,  20H 

LD 

(IX+O) ,20H 

(Firstly,  empty  buffer. 

CALL 

COUT 

LD 

( I  X-r  1 )  ,  20H 

LD 

A,oe 

LD 

(IX+2) , 20H 

CALL 

COUT 

LD 

( I X+3) , 20H 

END  IF 

LD 

B,  4 

(4  chars. 

1 

PRP 

LD 

A, (DE) 

JP 

ENT1 

OR 

A 

END  IN 

LD 

(HL) ,0 

(End  of  line. 

JR 

Z ,  FX 

CALL 

CRLF 

CP 

20H 

(If  space  or  zero,  quit. 

LD 

A,  B 

JR 

Z ,  FX 

OR 

A 

LD 

(HL)  ,  A 

JP 

NZ , CON 

INC 

HL 

1 

INC 

DE 

IF 

SPLIT 

DJNZ 

PRP 

CALL 

DEBCR 

BRT 

LD 

A, (DE) 

(Find  end  of  word  if  >  4  chars. 

END  IF 

OR 

A 

1 

JR 

Z ,  FX 

JP 

ENTRY 

CP 

20H 

1 

JR 

Z,FX 

|This 

is  where 

we  convert  from 

buffer  into  single  byte  tokens. 

INC 

DE 

1 

JR 

BRT 

CON 

LD 

DE, BUFFER 

1 Point  to  the  input  buffer 

FX 

CP 

OFFH 

(Zero  flag  must  not  be  set 

LD 

C,0 

POP 

HL 

1  on  return. 

LD 

HL.CODBUF 

(and  to  the  final  code  buffer. 

RET 

HORC 

LD 

I Y, TABKEY 

(Point  to  the  lookup  table. 

1 

HORX 

CALL 

FIND1ST 

(Character  I/O 

section. 

JP 

Z , ENDHESS 

1 

XX 

LD 

B,  (IY+O) 

CRLF 

EX 

AF ,  AF  • 

(Pretty  obviously  prints  a  CRLF 

INC 

IY 

XOR 

A 

( sequence. 

LD 

A.B 

LD 

(CCOUNT) , A 

(Also  zeroes  char,  count. 

OR 

A 

LD 

A,  ODH 

JP 

Z.HORC 

CALL 

COUT 

HORXX 

LD 

A,  (IX+O) 

LD 

A.OAH 

CP 

( I Y+0) 

(8tart  the  coeparison. 

CALL 

COUT 

JR 

NZ , MISS 

EX 

AF, AF’ 

LD 

A,  <IX+l> 

RET 

CP 

(IY+1) 

1 

JR 

NZ , MISS 

CHRIN 

LD 

A, ( IX+2) 

IF 

CPU 

(If  using  CP/H  then  will  do 

CP 

<IY*2> 

CONHSG 

This  program 

uses  CP/H  I/O 

JR 

NZ.MISS 

EXX 

LD 

A, <IY+3> 

LD 

C,  1 

AND 

7FH 

(Reset  8th  bit. 

CALL 

0005 

20 

480 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


EXX 

LD 

(VDMP)  ,  ML 

END  IF 

JR 

SPOOD 

1 

HMDN 

LD 

(HL>  ,  2 OH 

IF 

NOT  CPU 

JR 

SPORD 

CONMSG 

Non -CP /M  version 

(Custom 

I/O) 

1 

CINN 

IN 

A,  (00)  I 

i  Typical 

input  char  in  A. 

NLFC 

LD 

BC, VSIZE/2- 

AND 

02 

JR 

CLEARQQ 

JR 

Z  ,  CINN 

1 

IN 

A,  (01) 

CLEAR 

LD 

BC, VS1ZE-1 

AND 

7FH 

CLEARQQ 

LD 

HL ,  MEM  TOP 

END  IF 

LD 

(VDMP)  ,  HL 

1 

LD 

(HL) , 2 OH 

RET 

LD 

DE ,  MEMTOP* 1 

) 

LDIR 

COUT 

CALL 

CHROUT 

1  Print  char  in  Acc. 

XOR 

A 

OR 

A 

OUT 

( 0C8H ) , A 

PUSH 

A F 

JP 

SPEED 

LD 

A, (CCOUNT) 

1 

INC 

A 

line.  Char  count. 

VDMP 

DS 

02 

LD 

(CCOUNT) , A 

1 

CP 

LINLEN 

1  ••• 

END 

OF  HANDLER 

MM 

JR 

C,  BOX 

; 

POP 

A F 

END  IF 

PUSH 

A F 

1 

CP 

21H 

|8paca  char  ♦  1 

1  STABLE  i  This 

routina  sats 

up  tha  4  lags  par  tha  writ tan 

JR 

NC, BODX 

1 

spacif ication. 

CALL 

CRLF 

1 

BODX 

CP 

00 

1 Backapaca 

STABLE 

LD 

IX, FLAG 

(Point  to  flag  tabla. 

JP 

NZ , BOX 

INC 

( I  X*4 ) 

(Thasa  thraa  ara  aasy. 

LD 

A, (CCOUNT) 

INC 

<IX*5> 

DEC 

A 

INC 

(IX*6> 

DEC 

A 

LD 

HL,FLAG*6 

LD 

(CCOUNT) , A 

LD 

B,  3 

BOX 

POP 

AF 

STAB1 

INC 

HL 

RET 

LD 

A, (HL) 

1 

OR 

A 

CHROUT 

JR 

Z.STAB2 

IF 

CPM 

DEC 

(HL) 

PUSH 

AF 

8TAB2 

DJNZ 

8TAB1 

EXX 

I 

LD 

C,2 

LD 

A, ( IX*17) 

LD 

E,  A 

DEC 

A 

CALL 

0003 

AND 

(IX*10) 

EXX 

OR 

(  I  X  A  1  ) 

POP 

AF 

LD 

(IX-M6)  ,A 

(Sava  raal  light /dark. 

RET 

LD 

A, ( IX*17) 

END  IF 

DEC 

A 

1 

JR 

NZ, STABOW 

IF  NOT 

CPM 

LD 

HL,FLAG*9 

|  SCREEN. 

.  A  SIMPLE  SCREEN  HANDLER 

LD 

B,  2 

1 

ST  ABA 

INC 

HL 

EXX 

|Sava  all  tha  rag  1  stars 

LD 

A, (HL) 

PUSH 

AF 

OR 

A 

LD 

HL, (VDMP) 

1  Bat  currant  cursor  position. 

JR 

Z , 8TABAA 

CP 

20H 

(Miss  thasa  chacks  if  it's  a 

DEC 

(HL) 

JP 

NC, ORCHAR 

(printing  charactar... 

ST ABA A 

DJNZ 

ST  ABA 

CP 

ODH 

1  Was  input  a  C.R.  77 

STABOW 

LD 

A, < IX*10> 

JR 

Z , CHART 

OR 

A 

CP 

08 

I  or  «  BACKSPACE  7? 

JR 

NZ , BT  AB9 

JR 

Z , BKSP 

INC 

< IX*12> 

CP 

CLEARS 

I  or  a  CLEAR  SCREEN  77 

JR 

STAB3 

JR 

Z , CLEAR 

STAB9 

LD 

(IX*12> ,0 

CP 

HOME  UP  |  or  a  HOME  UP  "’7 

JR 

Z,  HMP 

STABS 

LD 

B,  234 

CP 

HOMEDN  |  or  a  HOME  DOWN  *>? 

CALL 

STABS 1 

JR 

Z , HMDN 

LD 

B,  2S3 

CP 

HALF CL  | or  a  HALF  SCREEN  CLEAR 

LD 

IX,  FLAG* 16 

JR 

Z.HLFC 

CALL 

STABS 1 

CP 

20H 

LD 

IX, FLAG*  14 

JR 

C, SPEED  |If  a  control  charactar  than 

LD 

B,  ( I X  *0 ) 

ORCHAR 

LD 

(HL) , A  (ignora  it  alsa  print  it. 

LD 

IX, FLAG* 1 7 

INC 

HL 

STABS 1 

LD 

(IX*2) ,0 

(Find  out  how  many  objacts  ara 

PTCOS 

LD 

(HL)  ,  OAOH  |  Incramant  pointar  t  placa 

LD 

HL, OBJLOC 

(carriad. 

JR 

LI NOV  (cursor  thara. 

INC 

HL 

(Can’t  say  OBJLOC* 1  ’causa  it’s 

BKSP 

LD 

(HL),20H  (For  BS  put  in  a  spaca  & 

STAB5A 

LD 

A, (HL) 

1  a  G1 obal . 

DEC 

HL  ( dacramant  tha  pointar. 

OR 

A 

JR 

PTCOS 

JR 

Z ,  BTAB6 

CHART 

LD 

(HL)  ,  2 OH 

INC 

HL 

LD 

A,  L 

INC 

HL 

AND 

OCOH 

CP 

B 

ADD 

AOH 

JR 

NZ , 8TAB5A 

LD 

L,  A 

INC 

( 1 X*2) 

LD 

A,  0 

JR 

STABSA 

ADC 

H 

STAB6 

LD 

IX, FLAG 

LD 

H,  A 

RET 

LI  NOV 

LD 

(VDMP) , HL 

1 

LD 

A,  L 

|  MFETCH  *  This 

routina  salacts  and  prints  a  nassaga.  HL  must 

AND 

3FH 

1 

point  to  tha  tabla, 

and  B  rag  contains  a  nunbar  1 

JR 

NZ, SPEED 

1 

to  2SS.  Tha  nassaga 

is  salactad  and  printad.  0  is 

LD 

A,  H 

1 

tha 

doll «i tar  and  *X 

’  will  acho  as  a  CRLF  saquanco. 

CP 

OFCH  (Naxt  paga  altar  scraan. 

1 

'  >' 

acts  to  tarmlnata  batchas  but  will  not  print. 

JR 

NZ, SPEED 

1 

ALSO 

HANDLES  DESCRIPTIONS,  STORING  DIRECTION  DATA. 

LD 

HL, MEMTOP* VDW IDE 

1 

LD 

DE , MEMTOP 

|  MPRINT  i  This 

may  bo  usad  as 

a  saparata  routina.  HL  points 

LD 

BC, V6I ZE-VDWIDE 

1 

to  first  byta.  dal imi tors  as  abova. 

LDIR 

1 

LD 

HL , MEMTOP* VS I ZE-VDW I DE 

MFETCH 

PUSH 

HL 

(Sava  ragistars 

LD 

(HL)  ,  2 OH 

PUSH 

AF 

LD 

DE, MEMTOP* VS I ZE-VDW IDE* 1 

LD 

A,  0 

(Load  Acc.  with  tarminator 

LD 

BC, VDWIDE-1 

LOOPF 

PUSH 

BC 

(Sava  tha  count 

LDIR 

LD 

BC , 0000 

| Up  to  64k  ! • • ! 

SPORD 

LD 

HL , MEMTOP* VS I ZE-VDW I DE 

CPIR 

(Look  for  zaros..FAST. 

SPOOD 

LD 

(VDMP) , HL 

POP 

BC 

(Gat  count  back. 

LD 

( HL )  ,  OAOH 

DJNZ 

LOOPF 

(Again  77? 

SPEED 

POP 

AF 

1 

EXX 

LD 

A, (HL) 

RET 

CP 

OFCH 

(Is  this  location  dascription. 

1 

JP 

C.MPRX 

(4  Diffarant  variatias. 

HMP 

LD 

(HL) , 2 OH 

CP 

OFEH 

1 233-normal ,  254-no  diractions 

LD 

HL, MEMTOP 

JR 

NC.MPML 

(233-dark 

Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


21 

481 


Adven-80 


(Listing  continued,  text  begins  on  page  8) 


INC 

A 

(232*dark  l>  no  directions  ever. 

LD 

B,A  (Set  no  of  levels  in  counter. 

LD 

HL , SPEC  (Set  HL  to  bottom  level -I. 

LD 

(IX+l) ,0 

(Save  either  dark.... 

LOOPQ 

INC 

HL 

JR 

MPM 

LD 

MPML 

LD 

<IX+1>, 1 

|or  light  status. 

PUSH 

MPM 

PUSH 

DE 

PUSH 

BC 

LD 

DE , WAY OUT- 1 

LD 

LD 

<  IX-M3)  ,  A 

|Store  SEE/NOT  SEE  directions 

LD 

B,  A 

LZL2 

(Get  LEVELS  parameter  from  A 

INC 

HL 

DJNZ 

LZL2  (Got  correct  flag  now. 

A, (HL)  (Hold  condition  in  A 

LD 

A, <HL> 

CP 

OFFH 

JR 

Z,BLTX 

LD 

( DE )  ,  A 

FOP 

BC 

JR 

BRPX 

POP 

HL 

BLTX 

PUSH 

AF 

OR 

A 

XOR 

A 

JR 

NZ, ARX 

LD 

(DE)  ,  A 

LD 

C.A  (If  Zero,  Kill  C. 

POP 

AF 

ARX 

DJNZ 

LOOPQ  (Outer  loop 

POP 

DE 

LD 

A, C  (Save  C. . . 

INC 

HL 

POP 

BC 

LD 

A, ( IX+17) 

POP 

HL  (End  outer  loop 

DEC 

A 

OR 

A  (Test  final  condition 

AND 

(IX-MO) 

JR 

NZ , LOVEL  X 

OR 

(IX*1> 

LD 

A,  (TEl)  (Check  negation  flag 

LD 

( I X+ 1 6 ) , A 

OR 

A 

JP 

Z , MPREND 

JR 

Z, LOVELY 

JR 

NPRX 

JR 

LOVEL 

; 

LOVEL X 

LD 

A,  (TEl  ) 

1  Standard  (well 

natrly)  HL-POI NT8-T0-ME8BAGE  typa  o 4  routina. 

OR 

A 

1 

JR 

Z , LOVEL 

HP* I NT 

PU8H 

HL 

1  Sava  Registers 

LOVELY 

POP 

AF  1  If  zero,  don’t  print. 

PUSH 

AF 

JP 

MPRX 

MPRX 

LD 

A, (HL) 

1  Get  a  character 

LOVEL 

POP 

AF 

OR 

A 

|Test  it 

MPRZA 

CALL 

COUT  (Actually  print  the  char. 

JP 

Z , MPREND 

1  No  more,  perhaps  7? 

JP 

MPRX  (then  back  for  more. 

INC 

HL 

(ready  for  next  char. 

MPREND 

POP 

AF 

; 

POP 

HL  1  Restore  registers 

CP 

3EH 

RET 

land  return. 

JR 

NZ.LB33 

I  ' >’  Terminate  batch  777 

1 

XOR 

A 

I  This 

sec  t i on 

deals  with  objects.  The  routine  ICANC  should  be 

LD 

(CODBUF) , A 

(entered  with 

the  C  register  containing  0,  1  or  2  l>  the  routine 

JR 

MPRX 

I  W  1  1  1 

; 

(All  registers 

are  returned  intact. 

LB53 

(The  display  will  insert  '  *<  ’  between  objects  if  more  than  1. 

CP 

25H 

( 

JR 

NZ.LB34 

1  *  X’  Looking  for  a  CRLF  77? 

(  Enter  with 

the  C  register  containing  x— 

CALL 

CRLF 

s 

JR 

MPRX 

(0  -  1 

am  carrying  the  following.... 

1 

(1  -  I 

am  wear i ng  the  following . 

LB34 

(2  -  I 

can  see 

the  foil owi ng . 

CP 

7BH 

: 

JR 

NZ.LB33 

1  ’(’Starting  new  conditional?? 

(If  no 

objects 

are  found  then  'nothing  special’  well  be  sent  out 

LD 

A, (HL) 

( 

CP 

• /■ 

(Negative  fore  77? 

ICANC 

EX 

AF , AF ’  (Save  all  registers. 

JR 

Z, FRTHR 

1 8ect i on  added  Feb 

LD 

A,  C 

XOR 

A 

I’Bl  for  negative 

EXX 

LD 

(TEl) , A 

|f lags. 

LD 

C.A 

JR 

FRTHR1 

PUSH 

IX 

FRTHR 

LD 

A,  1 

PUSH 

IY 

LD 

(TEl )  ,  A 

LD 

HL , MSG  1  Initial  message. 

INC 

HL 

LD 

I X , FLAG 

FRTHR1 

LD 

A, (HL) 

LD 

A,  ( IX-M6) 

OR 

A 

JR 

NZ, ICANG 

PUSH 

HL 

LD 

A,  C 

PUSH 

BC 

CP 

01 

PUSH 

AF 

JR 

Z.ICAN3  (Don’t  want  2  lots  of  dark  1  1 

LD 

HL, SPEC 

1 Poi nt  to  base 

INC 

(HL) 

(Effectively  PUSH  stack 

1 

LD 

B,  13 

B,  (HL) 

CALL 

MFETCH  (Send  dark  message. 

LZL 1 

(Oat  new  count  in  B 

JR 

ICAN3 

HL 

ICANG 

LD 

I Y,  OBJLOC 

DJNZ 

LZL  1 

(Find  new  entry 

PUSH 

BC 

1 

LD 

A, 16  (Set  to  'I  am  carrying..’ 

POP 

(Retrieve  FLAG  No. 

ADD 

SUB 

62 

LD 

C.A 

LD 

(HL) , A 

|Save  it. 

LD 

B,C 

POP 

BC 

CALL 

MFETCH  (Print  as  appropriate. 

POP 

HL 

INC 

HL 

(Skip  over  No. 

LD 

HL.UMESS 

JP 

MPRX 

POP 

BC 

t 

DEC 

C 

LB55 

DEC 

C 

CP 

7DH 

DEC 

C  1  Return  true  value. 

JR 

NZ.LB36 

1  Ending  a  conditional  *>??? 

LD 

A,  C 

LD 

A, (SPEC) 

CP 

235 

SUB 

1 

JR 

NZ, I CANY 

JR 

NC.SRXX 

LD 

C,(IX  +  14)  1  Then  load  present  location. 

XOR 

A 

ICANX 

LD 

DE , 0000 

SRXX 

LD 

(SPEC) , A 

(Effectively  POP  stack. 

I  CAN  1 

LD 

D, (IY+0) 

JP 

MPRX 

LD 

A,  (IYM) 

1 

OR 

A 

LB36 

JR 

Z, ICANZ 

1  Now  to  chock 

flags  pointad  to 

by  the  various  ’STACK’  levels. 

INC 

IY  (On  to  next  two 

1  To  do 

this  it 

is  nacassary  to 

find  offset  into  the  FLAG  table 

INC 

IY 

land  than  test 

tha  location,  for  EVERY  laval  currantly  active. 

CP 

C 

; 

JR 

NZ, ICAN1 

| Oh,  4  or  a  6809  '  ! 

1 

1 

LD 

A,  E 

PUSH 

AF 

1  Check  All  levels  for  true 

OR 

A 

LD 

A, (SPEC) 

JR 

Z , NOAND 

OR 

A 

(Test  DEPTH 

LD 

A,  ’  ’ 

JP 

Z , LOVEL 

(Miss  out  altogether  if  ZERO 

CALL 

COUT 

PUSH 

HL 

(Else  start  testing 

LD 

A,  ’!«’ 

PUSH 

BC 

CALL 

COUT 

LD 

c,  1 

(Assume  true  until  otherwise. 

LD 

A,  ’  ’ 

22 

482 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


CALL  COUT 

NOAND  PUSH  DC 

CALL  F INDUS 

POP  DC 

INC  C 

JR  ICAN1 

ICANZ  LD  A,  C 

OR  A 

JR  NZ , ICAN2 

LD  HL , MSG 

LD  B, 19 

CALL  NFCTCH 

ICAN2  LD  A,  ’ . ’ 

CALL  COUT 

CALL  CRLF 

ICAN3  POP  IY 

POP  IX 


CX  AF.AF' 

RCT 
I 

I CANY  CP 
JR 
LD 
JR 

ICANZ 1  LD 
JR 


I  Thi  a  routine  (FINDHS)  look®  thru  th#  object  table  for  object 
jin  D  regitter  and  print®  th#  correct  ®®®s«g®. 

I 

F INDUS  PUSH  IX 

LD  IX, OBJ DCS 

FIND1  LD  A,<IX+0> 

LD  B, (IX+1) 

CP  D 

JR  Z , F I ND2 

INC  IX 

INC  IX 

JR  FIND1 

FIND2  POP  IX 

CALL  HFETCH 

RCT 


I Th®  end .  Th®  database  fil®  is  link®d  h®r®. 


End  Listing 


234 

NZ, ICANZ 1 
C,  233 
ICANX 
C,  234 
ICANX 


{This  correct®  a  bit  of  bad 
|d®«ign  in  th®  first  plac®. 


I  Increment  it®®®  found. 

| If  not  z®ro  th®n  CRLF 
|®ls®  ’nothing  sp®cial’ 


KEY  'lt‘®  a  shiny  BRASS  k®y  with  th®  nam®  SHED  on  it...X* 
NATCH  ’It*®  Ju®t  an  ordinary  match.' 

*  Quit®  useful  for  lighting  lamps. X' 

LAMP  ’Look®  lik®  an  oil  lamp  to  m®..X* 

STATUE  ’Thi*  is  a  statu®  of  Aphrodite.  ’ 

'It*®  covered  in  cobwebs. X’ 

E NOTABLE 


t  WORDHATCH  CONDI T ION/ACT ION  SETS  • 


HATCH*  /•  S®ts  of  match  pairs,  i®  pairs  of  keywords,  where  «/ 

/•  either  word  may  b®  the  mask  ANY,  and  the  second  word  9/ 
/•  may  b®  NUL  (no  word)  or  INP  (replaced  at  runtime  with  9/ 
/t  user  input.)  */ 

/•  An  optional  TEST  section  may  precede  the  action  entry  t/ 
/*  following  the  rules  of  the  CONDITION/ ACT  ION  tables.  •/ 
/•  An  ACTION  entry  is  mandatory,  and  may  allow  dropping  9/ 
/•  thru  or  termination  as  desired.  9/ 

MATCH  GET , ANY 
TEST  OH, INP 
ACTION  TKE, INP, OK 

NATCH  GET, NUL 
ACTION  PRH, 39, EX 

NATCH  GET, ANY 
TEST  ONC, INP 
ACTION  PRN.44.EX 

NATCH  GET .ANY 
ACTION  PRH, 36, EX 

NATCH  INVEN, NUL 
ACTION  INV.EX 

MATCH  LOOK, AROUND 
ACTION  GRUN 

NATCH  DROP, ANY 
TE9T  OWC, INP 
ACTION  DR, INP, OK 

NATCH  DROP, ANY 
ACTION  PRH, 33, EX 

NATCH  LOOK, NUL 
ACTION  LA, EX 

NATCH  LOOK, ANY 
TE8T  OP, INP 
ACTION  D8C0B, INP, EX 


Listing  II 


/t  Released  into  public  domain  1981  P.  Scargi 1 1  9/ 


*  Beginning  of  main  database  section,  encoded  entirely  in 
a  the  ADVEN  language.  File  is  run  thru  MAKEADV.COM  then 
a  assembled  and  linked  to  the  main  program. 


•  OBJECT  NAME / LOC AT  I ON  and  OBJECT  NAME /DESCRIPT I ON  PAIRS  a 
a  also  PROPERTIES  OF  OBJECTS  and  OBJECT  DETAILED  INFO  a 


OBJ LOC  /a  Object  locations.  The  number  following  the  object  9/ 

/a  keyword  is  the  location  number  where  the  object  9/ 

/a  will  reside  at  the  beginning  of  the  game.  a/ 

STATUE  4 
KEY  8 

HATCH  3 
LAMP  232 
ULAHP  1 1 

ENDTABLE 


OBJDES  /a  Object  descriptions.  The  number  following  the  9/ 

/a  object  keyword  is  the  description  number  from  the  9/ 

/a  UNESS  table.  All  objects  MUST  have  both  LOCATION  9/ 

/a  entries  and  DESCRIPTION  entries.  «/ 

KEY  1 

HATCH  2 
LAMP  3 
ULAHP  4 
STATUE  6 

ENDTABLE 

OBPROP  /a  Legal  verbs  associated  with  objects.  9/ 

/a  Where  no  properties  shown,  objects  considered  to  have  9/ 
/a  universal  properties,  ie  get,  drop  etc  all  work.  •/ 

/a  Where  properties  are  shown,  only  those  are  valid.  9/ 

STATUE  LOOK 

ENDTABLE 


HATCH  QUIT , ANY 
ACTION  QT 

NATCH  HELP, ANY 
ACTION  PRH, 40, EX 

NATCH  WHO, ANY 
ACTION  PRH, 41, EX 

HATCH  ON, LAMP 

TEST  OC, ULAHP, OC, HATCH 

ACTION  SWP, LAMP, FLIP, 17, OK 

HATCH  ON, LAMP 
TEST  OC, ULAHP 
ACTION  PR, 03, EX 

NATCH  OFF, LAMP 

TEST  OC, LAMP 

ACTION  SWP, LAMP, FLIP, 17, OK 

NATCH  ON, LAMP 
TEST  OC , LAMP 
ACTION  PRH, 42, EX 

NATCH  OFF , LAMP 
TEST  OC , UL AMP 
ACTION  PRH, 42, EX 

HATCH  UNLOCK, ANY 

TEST  TF , 23 ,01, OC , KEY , CL , 9 

ACTION  SF, 23,00, OK 

HATCH  LOCK, ANY 

TEST  TF, 23, OO, OC, KEY, CL, 9 

ACTION  SF, 23, 01, OK 

HATCH  IN, ANY 

TEST  TF, 23,00, CL, 9 

ACTION  MV, 11 

HATCH  YES, ANY 
ACTION  PRH, 43 

HATCH  SCORE , ANY 
ACTION  SC, EX 

HATCHALL 
ACTION  PRH, 37 

ENDTABLE 


OBJDSK  /a  Where  required,  an  object  may  have  a  special 

/a  description.  This  is  optional  and  may  be  as  long  as 
/a  required,  and  may  include  conditionals  as  in  the 
/a  location  tables. 


9/  a  Standard  message®  for  system  use  mainly  a 

9/  aaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaaa 

9/ 

9/  MSG  /a  The  positions  of  these  messages  MUST  NOT  be  altered  9/ 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


23 

483 


Adven-80  (Listing  continued,  text  begins  on  page  8) 


1  ’ >That  means  nothing  to  me<9,  I'm  afra id!<7.)  ''X* 

2  ’  North’ 

3  ’  South’ 

4  ’  East ’ 

3  *  West ’ 

6  ’  Northeast’ 

7  ’  Northwest ’ 

8  ’  Southeast’ 

9  ’  Southwest’ 

10  ’  Up’ 

1 1  ’  Down ’ 

12  ’  In’ 

13  ’  Out’ 

14  ’Visible  exits  are  ’ 

13  ’ >It  ’•  dark,  I  can’t  see  anything*?  at  all>.’ 

’It  is  Over y  ) dangerous  to  move  in  the  dark.X’ 

16  ’I  am  Opresent 1 y  >carrying  ’ 

17  ’I  am  wearing  ’ 

18  ’I  can  see  ’ 

19  ’nothing  special* 

20  ’  >1  don’t  Oquite  )  follow  you.  Could  you  try  ’ 
’re-phraeeing  that....X’ 

21  ’ >1  can(Jno)(?')t  go  <9in  that  direction. > <?there. >X* 

22  ’  right’ 

23  ’  left’ 

24  ’ ><?Ehh ! !  >That  doesn't  make  sense<9,  buddy!  MMX’ 

23  ’ X9I *m  sorry,  but  )I  can  see  no  such  object  here.X’ 

26  ’ >PROGRAM  ERROR  I -INVALID  CONDITION  | | | |  X’ 

27  ’>0uitting  with  * 

28  ’  points. X’ 

29  ’  Ok . X’ 

30  ’Your *9  present!  score  is  ’ 

31  ’ >PROGRAM  ERROR  »-  CANT  FIND  OBJECT  FOR  ACTION  itii  X’ 

32  ’ > PROGRAM  ERROR  i-  INVALID  CONDITION  X’ 

33  ’ >Try  again... I’m  not  sure  which  object  you  mean.X’ 

34  ’ >1  am  not  wearing  this  item.X’ 

33  ’ >Thi s  is  not  amongst  the  items  I  am  carrying.X’ 

36  ’ >1  can’t  see  the  object  <9you  mean  !here....X’ 

37  ’  XTHuhXBEhh)  M  M  MX’ 

38  ’>SorrY»  I  can’t  (9possi bl y  > carry  anything  else.X’ 

39  ’ ><?Borry,  I’m  not  sure  from  that  what  ’ 

’you  want  me  to  getlOYou  want  whai.!  MX’ 

«0  ’I  can’t  help  you  <?at  this  time! <91 ’m  afraidJX’ 

41  ’>Don’t  ask  silly  questions<9,  please!  !'X’ 

42  ’><91  believe  I  already  did  that  MX!’ 

’<?It  is  already  MM  MMX)’ 

13  ’  >8orry,  no  chance  MX’ 

14  *  >But  this  is  something  I ’m  already  carrying  !X’ 

13  ’Looks  <9distinctly  Jordinary  to  me  ! ! ! ! X’ 


6  ’ PSorry,  that’s  quite  impossible.)’ 

’ <91 'm  sorry  but  I  can’t  do  that.)X’ 

•  You  may  expand  here  if  necessary,  but  preferably  9/ 

»  use  the  UMESS  table  for  user  messages  (max  246  9/ 

NOTABLE 

IIIIIIIIMMMtttllllltllMMMIttMtlMtllMIIMMIIIIIIlMIII 
*  User  defined  messages,  expandable  up  to  246  9 


UMESS 

1  'a  set  of  keys' 

2  ’some  matches' 

3  ’an  oil  lamp  with  a  BLUE  glow’ 

4  ’an  old  worn  out  lamp’ 

5  ’What  with... <9  my  fingernails  ????)’  /»  note  use  of  •/ 

’  <**  I’m  not  carrying  any  matches  !M)X’  /»  random  func.9/ 

6  ’an  old  dirty  statue’ 

ENDTABLE 


9  LOCATION  DESCRIPTIONS  AND  EXIT  CODES 


LOC  / 9  L.ocations  with  available  exit  table  at  start  9/ 

l  NORMAL,  2,  N,  2,  3,  S,  10 

’I  am  in  the  grounds  of  a  derelict  country  mansion’ 

’,  it  is  a  fine  day  and  I  can  hear  birds  singing  in’ 
the  trees. X* 


2  NORMAL, 12, IN, 3.3, S, 1,5, W. 9 

’1  am  at  the  front  of  the  mansion.  There  is  no  door’ 

'  and  I  can  see  a  long  hallway  inside. X’ 

3  NORMAL, 22. RI, 4, 23, LE, 5,  10, U, 6,  13, EXIT, 2 

’I  am  in  a  long  Hallway.  The  light  is  dim  here  as  there’ 
’  has  been  no  power  here  for  a  long  time.X’ 

4  N0EXIT, 13, EXIT, RTN 

’I  am  in  an  old  study.  There  are  cobwebs  all  around. X’ 

5  N0EXIT, 13, EXIT, RTN 

’I’ve  entered  some  sort  of  kitchen,  by  the  look  of  it. 
’There's  a  cooker  of  a  kind,  and  a  sink,  but  everything 
’is  broken  and  decayed. X’ 

6  NORMAL, 11, DO, 3,3,S,8,22,RI,7, 23, LE, 7, 2,N,7,6,NE,7 

’ 1  am  on  a  wierd  sort  of  landing,  with  exits  in  many  ’ 
’directions.  The  floor  doesn’t  look  too  safe  to  me''X’ 


7  NOEXIT, 13, EXIT, RTN 

*1  am  facing  a  boarded-up  door .X’ 

8  NOEXIT, 13, EXIT, RTN 

*1  am  in  a  pink  bathroom.  The  bsth  has  a  big  crack  in  it" 
and  all  the  pipes  have  been  long  di sconnec tea . X’ 

9  NORMAL, 4, EA, 2, 3, W, 10 

’I  am  standing  outside  an  old  <Alocked-up  Jwooden  ’ 

’shed.  <AThe  windows  have  been  boarded-up. )X’ 

10  NORMAL, 2, N, 1,4, EA, 9, 11, DO,  12 

*1  am  standing  in  front  of  an  old  well.  It  looks  like  ’ 

*1  could  go  down  there  if  I  wanted  to. <A  Of  course  I’d  ’ 
’need  some  kind  of  lamp  as  it's  probably  very  dark 
’down  there! . X’ 

11  NORMAL,  1 3, EX  IT, RTN 

’  I  am  inside  an  old  wooden  shed. 7.’ 

12  DARK,  4,  W,  13,3,  EA,  14,  10,  U,  10 

*  I  am  standing  in  a  low,  damp  passageway . X* 

13  DARK, 5, EA, 12,2, N, 15 

’I  am  in  a  narrow  passage,  to  the  North  is  a  dead  end.X  ’ 
Expand  up  to  246  locations  maximum  •/ 

ENDTABLE 


•  KEYS.  FIR8T  13  ARE  RE8ERVED. . . MUST  NOT  BE  ALTERED.  ’IT* -231  9 


TABKEY 


N 

’N 

NORT  ’ 

S 

’S 

SOUT’ 

EA 

’E 

EAST’ 

W 

•w 

WEST’ 

NE 

*NE 

SE 

’BE 

» 

NM 

’NW 

SW 

•sw 

U 

•u 

UP  » 

DO 

’D 

DOWN’ 

LE 

’L 

LEFT’ 

RI 

•R 

RIGH’ 

IN 

’  IN 

ENTE’ 

EXIT 

•exitleavout 

LOOK  ’LOOKPERUEXAM’ 

INVCN  • I NVt • 

QUIT  ’ QUI TEND  ST0PBYE  AB0R’ 


GET  ’GET  GRABT AKECARRP 1 CK ’ 

DROP  ’ DR0PREM0 ’ 

OPEN  ’OPEN’ 

LAMP  ’LAMP’ 

ULAMP 

WEAR  ’ WEAR ' 

LIFT  ’LIFTPUSHMOVEPULLYANk ' 

MATCH  ' HATC ’ 

SCORE  ‘ SC0R ’ 

AROUND  ’ AR0UHERE ’ 

SAY  ’SAY  YELLSHOUCALLSCRE* 

Of  f  ’OFF  UNLI’ 

ON  ’ON  L IGHSTR I BURNAL I GF IRE ’ 

HELP  ’HELPASSI’ 

BEGIN  ’ BEG 1 ST  AR ' 

CLOSE  ’ CL0SSHUT ’ 

DOOR  ’ DOOR ’ 

READ  ’READ’ 

THROW  ’ THR0HURLCMUC * 

LOCk  ’LOCK’ 

UNL0P  ’UNL0' 

JUMP  JUMP' 

FORWARD  ’  F ORW  ' 

BACKWARD  ’  BAP 

BOARD  ’NOT  I  BOARS I GN' 

WHO  ’WHO  WHEN WHAT IS  WHERHOW  WHY  ’ 

LISTEN  ’LIST  HEAR ’ 

N01E  ’NOTE’ 

STUDY  ’STUD’ 

KITCHEN  ’ K I TC ’ 

STAIRS  ’ UPSTSTAI ’ 

ROOM  ’ ROOM ' 

BATH  BATH’ 

KEY  ’KEY  KEYS' 

SHED  ' HUT  SHED  * 

FRONT  ’FRON’ 

GROUNDS  'GROU' 

WELL  ’ WELL  * 

YES  ’ YES  ' 

CARE  ’CAREQUIECLOS’ 

STATUE  ’STATFIGU' 

/ 4  IMPORTANT  -  No  more  than  246  keys  (As  many  alternatives  9/ 
/%  as  required,  up  to  one  line. 

ENDTABLE 


4  SIGN-ON  MESSAGE.  THIS  WILL  NEED  MINOR  CHANGE  FOR  EACH  ADV.  4 


24 

484 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


’  ITU 


CHP  9  ( 26 ) 

Welcome  to  ADVE-80,  a  new  type  of  ADVENTURE  game.  I  will* 


'  be  your  eyes  and  ears  in  this  game  as  we  travel 
’together  through  an  amazing  fantasy  world.  ' 

’If  you  have  any  problems  tn  getting  me  to  ’ 

’understand  you,  please  re-phrase  your  * 

’sentence.  I  cannot  usually  undertake  to  answer  ' 

'questions  but  if  you  like  you  may  ask  ' 

’me  for  help.  ’ 

’Enjoy  playing  ADVEN-80,  for  further  details 

’contact  Pete  Scargill  on  0432-373903  (Great  Britain)  after  6  p.m.  X' 
’ADVEN-80  V. 1.1  1981  P.  Scargill.  X’ 

’Hit  any  key  to  begin . .  ’ 

ENDTABLE 


FLAG 

1 

01 

2 

00 

3 

02 

4 

00 

3 

OO 

6 

00 

7 

00 

8 

00 

9 

OO 

10 

80 

11 

00 

12 

OO 

13 

00 

14 

01 

13 

OO 

16 

OO 

17 

01 

18 

00 

19 

OO 

20 

01 

21 

00 

22 

00 

23 

01 

24 

OO 

23 

OO 

26 

00 

27 

OO 

28 

00 

29 

OO 

30 

OO 

31 

00 

32 

00 

33 

00 

34 

OO 

33 

OO 

36 

OO 

37 

OO 

38 

OO 

39 

00 

40 

OO 

41 

OO 

42 

00 

43 

00 

44 

00 

43 

00 

46 

00 

47 

OO 

48 

00 

ft  If  OO  then  dark  location  9/ 
ft  No.  of  items  carried.  (AUTO)  9/ 
ft  Max  No.  of  objects  can  carry  (AUTO)  »/ 
ft  3  Count  up  every  turn  (AUTO)  9/ 


ft  3  Count  down  every  turn  (AUTO)  9/ 


/ 9  2  Count  down  if  dark  t>  lamp  on.  (AUTO)  9/ 

/ 9  Counts  up  if  dark  l>  lamp  Empty  (AUTO)  9/ 

/9  Present  Score  (MANUAL  UPDATE)  9/ 

/9  Present  Location  (After  1st  loc..  AUTO)  9/ 

/9  FF  (normal )  or  FE  (No  directions)  (AUTO)  9/ 

/ 9  Determines  if  we  can  see.  00-BLIND. (AUTO)  9/ 
/ 9  LAMP  ON/OFF.  ON-OO,  OFF -01  (MANUAL)  9/ 

/ 9  No.  of  items  WORN  (AUTO)  9/ 

/ 9  No.  of  items  HERE  (AUTO)  9/ 

/ •  Last  location  store  (AUTO)  9/ 

/ 9  2  Special  Test  Flags  (AUTO)  9/ 

/ 9  are  set  compl imentary  at  random.  9/ 

ft  26  Flags  (A-Z)  for  MANUAL  text  processi ng . 9/ 

ft  Will  require  init.  for  individual  9/ 
ft  Adventures.  9/ 

ft  Active  any  value  other  than  00.9/ 


/•  maximum  number  is  246  -  do  not  skip  any  numbers.  9/ 


ENDTABLE 


ENDGAME 


End  Listing 


Don’t  let  your  hot  utilities 
or  computing  ideas 
sit  on  the  shelf. 

DDJ  is  a  great  place 
for  bright  authors 
to  get  a  start. 
Contact  us  at: 

Dr.  Dobb’s  Journal 
P.0.  Box  E 

Menlo  Park,  CA  94025 
(415) 323-3111 


Listing  III 

10  PRINT i PRINT i PRINT i PRINT  t  PRINT 

20  PRINT  "999  ADVEN  an  ADVENTURE  database  conversion  utility  999" 

30  PRINT  " . - 

40  DEFINT  A-Z 
50  CPH— 0 
60  PRINT 

70  INPUT  "Enter  name  of  Database  File  (assumed  ext  .ADV)"|FC6 
80  IF  FC9-""  THEN  PRINT  "Invalid  name" « GOTO  70 
VO  IF  INSTR (FC6, " . " ) — 0  THEN  110 
100  FC9-LEFT9 (FC9, INSTR (FC9, -t ) 

110  FS-FC9*-".  ADV" 

120  MC6-FC9*". ZBO" 

130  TE6T-0 

140  PRINT  "Input  file  -  "  |  F9 
130  PRINT  "Output  file-  "»MC6 
160  PRINT 
1 70  OPEN  " I " , 1 , FS 
180  OPEN  "0“ , 2.MC9 

200  PRINTC2, " |  ADVENTURE  Z80  DATABASE  SYSTEM" 

210  PRINTC2, " |  Released  into  the  public  domain  1981  P.  Scargill" 

220  PRINTE2, " y  This  file  called  " | MC* 

230  PRINTC2, " |  For  ZILOG/MOSTEK  Assemblers." 

231  READ  WSiIF  W6< >"E0F"  THEN  PR I NT £2, W«i GOTO  231 
240  REM 

230  LINE  INPUT£1,QS 
260  GOSUB  1580 


(Continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


25 

485 


Adven-80  (Listing  continued,  text  begins  on  page  8) 


270  IF  Q*-""  THEN  250 

280  IF  LEFT*<Q*, 1 >-"  "  THEN  Q*-HID* <Q*, 2> I  SOTO  280 
290  IF  LEFT*<Q*, 1)-CHR*<9>  THEN  Q*-HID* <0*. 2) l GOTO  280 
300  IF  LEFT* <0*. I THEN  250 
310  REN 

320  IF  RIGHT*<Q*, 1>«”  "  THEN  Q*-LEFT* <Q*, LEN <Q*) - 1 ) i GOTO  320 

330  IF  LEFT*  <Q*t  6) —"OBJLOC"  THEN  TEST "TEST ♦ i i GOTO  450 

340  IF  LEFT*  <0*, 6) —"OBJDES"  THEN  TEST«TEST*2i GOTO  510 

350  IF  LEFT*  <Q*,  6)  — "MATCHW"  THEN  TEST-TEBT-Mi  GOTO  540 

360  IF  LEFT*  <Q*, 3) — "HSG"  THEN  TEST-TEBT+Bi GOTO  640 

370  IF  LEFT* (Q*, 5) —"UHESS"  THEN  TEST-TEST+161 GOTO  740 

380  IF  LEFT*  <Q*, 3) —"LOC"  THEN  TE8T-TEST^32i  GOTO  780 

390  IF  LEF  T  •  ( O* ,  6  >  —  "  T  ABKE  V  "  THEN  TEST  "TEST  +64 1  GOTO  870 

400  IF  LEFT*  <0*  ,5>— “TITL1  M  THEN  TEST-TEST+l  28i  GOTO  1  lOO 

410  IF  LEFT* <Q*,4> -"FLAG"  THEN  TEBT-TEST*256i GOTO  1170 

415  IF  LEF T • ( Q* ,6)«" OBJ DSK "  THEN  TEST-TEST^512i GOTO  1261 

416  IF  LEF T •  ( Q* ,  6 )  —  " OBPROP "  THEN  TEST-TESTM024i  GOTO  10*1 

420  IF  LEF T* ( O* , 8 >  * " ENDGANE "  AND  TEST-2047  THEN  PRINT" CEOFJ  ALL  CORRECT 

i CLOSE i GOTO  1620 

430  IF  LEFT* (Q*, 8) <  >“ ENDGANE"  THEN  PRINT  "BAD  L I NE " i PR I NT  Q*iCLOSE 
: GOTO  1620 

440  PRINT  "HISSING  SECTION  NET  AT  END  OF  GANE " i CLOSE I  GOTO  1620 
450  PRINT  "Proctitinq  OBJLOC  table." 

460  PRINT£2, "OBJLOC" | 

470  GOSUB  1480 

480  IF  LEFT*  <0*, 8) -"ENDTABLE"  THEN  PRINTC2, "  DEFB  OO,0O“iGOT0  250 
485  HID* (Q*, INSTR (Q*. "  ")tl)«"t" 

490  PR I NT £2, "  DEFB  " | O* 

500  GOTO  470 


510  PRINT  "Processing  OBJDES  table." 

520  PRINTC2, "OBJDES" | 

530  GOTO  470 

540  PRINT  "Processing  HATCHN  table." 

550  PRINTC2,  "HATCHW'j 
560  GOSUB  1480 

570  IF  LEFT* (Q*, 8) -"ENDTABLE"  THEN  GOTO  480 

580  IF  Q*-"HATCHALL“  THEN  PRINT£2, "  DEFB  255, 255" *  GOTO  560 

590  IF  LEFT*  <Q*,  5)0 "NATCH"  AND  LEFT*  (O*,  4)  <  >"TEST"  THEN  610 

600  PRINT£2,"  DEFB  " | NID* (O*, INSTR (Q*, "  "> ♦111 GOTO  560 

610  IF  LEFT* (Q*, 6) <  >- ACT  ION"  THEN  CLOSEiPRINT  "COND/ACT ION  FAULT" 


i PRINT  0*i GOTO  1620 

620  PRINTC2, "  DEFB  255, " |NID* <Q*t INSTR (O*, "  " > 1 ) ; " , 255" 

630  GOTO  560 

640  PRINT  -Processing  NSG  table. " 

650  PR I NT £2 , " NSG " | 

660  WE*— "NES" 

670  GOSUB  1480 

680  IF  LEFT* <0*, 8) -"ENDTABLE"  THEN  GOTO  480 
690  IF  LEFT*<0*.  1)0"'  “  THEN  710 
700  PRINT£2,  "  DEFB  "|Q*iGOTO  670 
710  PRINT£2,"  DEFB  00" 

720  PRINTC2,"  DCFB  " | NID* <0*, INSTR (Q*, "  - > ♦ 1 > 

730  GOTO  670 

740  PRINT  "Processing  UHESS  table." 

750  PRINTC2, -UHE8S-I 
760  WE*--UHE8" 

770  GOTO  670 

780  PRINT  “Processing  LOC  table." 

7*0  PRINTC2, "LOC"| 

BOO  GOSUB  1480 

810  IF  LEFT* (0*, 8) -"ENDTABLE"  THEN  GOTO  480 
820  IF  LEFT* (0*, !)<>"' "  THEN  840 
830  PRINT£2,"  DEFB  "|Q*iGOTO  800 
840  PRINTC2, "  DEFB  00" 

850  PRINT£2, "  DEFB  " | NI D* <0*, INSTR <Q*, "  “ ) *1 ) » " , 255" 

860  GOTO  800 

870  PRINT  "Processing  TABKEY  table." 

880  CNT-0 

8*0  PRINTC2, "TABKEV " 

900  GOSUB  1480 

910  IF  LEFT* (0*, 8) -"ENDTABLE"  THEN  1030 

920  IF  INSTR (Q*, "  " ) -O  THEN  CNT -CNT ♦ 1 1 PR I NT £2 , 0* j "  EOU  "|CNT 
i GOTO  900  * 

930  Q1*-LEFT*<0«, INSTR (Q*. "  ")-l) 

940  Q*-NID*(0*, INSTR (0*, "  ">♦!) 

950  IF  LEFT* (0*, 1 ) -"  -  THEN  Q*-NID* (0«, 2) i GOTO  950 
960  CNT -CNT ♦ 1 

970  PR I NT £2 , Q 1 * | "  EOU  " | CNT 
980  PRINT£2, "  DEFB  " | CNT 

990  IF  LEFT*  <0*, 1 )-"* "  AND  RIGHT* <Q«, 1 )-"’ "  THEN  1010 
lOOO  CLOSEiPRINT  "INCORRECT  KEYS  M|0*iG0T0  1620 
1010  PRINT£2, "  DEFN  " | 0* 

1020  GOTO  900 

1030  PRINT£2, "THEN  EOU  250" I PRINTC2, "  DEFB  250" 


1040  PR I NT £2, "  DEFN  ’ THENAND  ALBO* “ 

1050  PR I NT £2, "IT  EOU  251 " l PR1NTC2, "  DEFB  251" 
1060  PRINTC2."  DEFN  ’IT  THEN’" 

1070  PRINT£2, "AGAIN  EOU  252" i PR INT£2, "  DEFB  252" 
1080  PR I NT £2, "  DEFN  ’ AGAIREPE ’ " 

1090  GOTO  400 

1091  PRINT  "Processing  OBPROP  table." 

1092  PR I NT £2, "OBPROP"! 

1093  GOTO  1263 

1100  PRINT  "Processing  TITL1  table." 

1 1 10  PRINTC2, " T I TL 1 "  | 

1120  GOSUB  1400 

1130  IF  LEFT* (Q*,0) -"ENDTABLE"  THEN  GOTO  480 
1140  IF  LEF T •  ( Q* ,5)0" CHR*  (  "  THEN  1160 
1 150  Q*-NID*(Q*,6) i0*-LEFT»(0*,LEN(0*)-l) 

1160  PRINTC2, "  DEFB  "|Q*iGOTO  1120 
1170  PRINT  "Proce**ing  FLAG  table. M 
1100  PRINTC2, "FLAG  DEFB  00" 

1190  GOSUB  1400 

1200  IF  LEFT* (Q*, 8) -"ENDTABLE"  THEN  GOTO  480 


1210 

1220 

1230 

1240 

1250 

1260 

1261 

1262 

1263 

1265 

1266 

1267 

1268 

1270 

1271 
1200 
1290 
1300 
1310 
1320 
1330 
1340 
1350 
1360 
1370 
1380 
1390 
1400 
1410 
1420 

1430 

1440 

1450 


IF  VAL  <  Q* ) — O  THEN  CLOSEiPRINT  Q*i PRINT  "INVALID  FLAG" 
i GOTO  1620 

IF  LEFT* (Q*. 2) -"14"  THEN  PRINT£2, "FL14" | 

IF  LEFT* (O*. 2) -"20"  THEN  PR I NT£2, "FL20" | 

IF  LEFT* <0*, 2) -"21"  THEN  PR INT£2, "FL21 " | 

PRINTC2,"  DEFB  " | NID* (O*, INSTR (O*. -  ")♦!) 

GOTO  1190 

PRINT  "Processing  OBJDSK  table." 

PRINT£2, "OBJDSK" | 

GOSUB  1480  i IF  LEFT* <0*, 1 X "  THEN  PRINTC2,"  DEFB  00" 

IF  LEFT* <0*, 8) -"ENDTABLE"  THEN  GOTO  480 
NID* <0*, INSTR (O*, "  "),1)— "," 

PRINT£2, "  DEFB  "|Q* 

GOTO  1263 

DATA  "  GLOBAL  OBJLOC","  GLOBAL  OBJDES","  GLOBAL  NATCHW" 

DATA  "  GLOBAL  OBPROP","  GLOBAL  OBJDBK" 

DATA  "  GLOBAL  T I TL 1 " ,  "  GLOBAL  NSG","  GLOBAL  UHESS" 

DATA  “  GLOBAL  LOC","  GLOBAL  TABKEY" , "  GLOBAL  FLAG" 

DATA  "  GLOBAL  FL14","  GLOBAL  FL20","  GLOBAL  FL21" 

DATA  "RTNi  EOU  249"," ANY i  EOU  255","INPi  EOU  00- 
DATA  "NULt  EOU  OO" , "NORMAL i  EOU  255“ , “NOEX ITi  EOU  254- 
DATA  "DARKi  EOU  253" , "DARK NO i  EOU  252", "CLi  EOU  1" 

DATA  "NCL i  EOU  2“,"0Pi  EOU  3","OCi  EOU  4","0Wi  EOU  5" 

DATA  "OWCi  EOU  6","0Hi  EOU  7","0NPi  EOU  8","0NCi  EOU  *" 

DATA  "ONWi  EOU  10","NWCi  EOU  1 1 " , "ONHl  EOU  12","0Ei  EOU  13- 
DATA  "ONE i  EOU  14","8Ll  EOU  15“,"N8Li  EOU  16","RNDi  EOU  17- 
DATA  "TF:  EOU  IB" , "NTF i  EOU  19","GE«  EOU  20","LTi  EOU  21" 
DATA  "C2i  EOU  22“,"C3i  EOU  23","NC2i  EOU  24","NC3i  EOU  25" 
DATA  "INV:  EOU  l","TKEi  EOU  2","WRi  EOU  3“,"DR:  EOU  4" 

DATA  "PRi  EOU  5","PRNi  EOU  6","DLl  EOU  7","3Fi  EOU  8" 

DATA  " DSCOBi  EOU  9","SWPs  EOU  10","NVi  EOU  ll","OKi  EOU  12" 
, "QT i  EOU  13" 

DATA  "INFi  EOU  14","DEFi  EOU  15","EXi  EOU  16","SCi  EOU  17" 
DATA  "PUi  EOU  18", " CR i  EOU  l*-,"DESi  EOU  20","FLIPi  EOU  21" 
DATA  "LA i  EOU  22","SNAi  EOU  23","SNBi  EOU  24","WTi  EOU  25" 


1460  DATA  "PFi  EOU  26"."ATFi  EOU  27", "SFFi  EOU  2B","QRUNi  EOU  2*" 

1470  DATA  "EOF" 

1480  LINE  INPUT£1 , O* 

1490  GOSUB  1580 

1500  IF  LEFT* <0*, 1 ) -"  "  THEN  Q*=NID* (Q«, 2) t GOTO  1500 
1510  IF  LEFT* (0*, 1) -CHR* (9)  THEN  0*-NID* <0*, 2) I  GOTO  1500 
1520  IF  LEFT* (O*, 1 ) -"•"  THEN  1480 
1530  IF  INSTR (0*. CHR* (9) ) -O  THEN  1550 

1540  O*— LEFT • ( O* , INSTR ( 0* , CHR* ( 9 ) ) - 1 ) ♦ "  " +H I D* ( Q* , INSTR  < 0* , CHR* ( 9  > ) ♦ 1 ) 
•GOTO  1530 

1550  IF  RIGHT* <0*, 1 )-"  "  THEN  0*-LEFT* <Q«, LEN <Q*> -1 ) x GOTO  1550 
1560  IF  O*-""  THEN  1480 
1570  RETURN 

1500  IF  I N8TR  < 0* , " / 1 " > -O  THEN  RETURN 

1590  IF  INSTR <0*, "«/">-0  THEN  CLOSEiPRINT  "BAD  COHHENT" 

■PRINT  Q* i GOTO  1620 

1600  O*— LEFT* (O*. IN6TR<QS, "/•">— 1> ♦N I DS  < Q* , INSTR (O*, "»/")+2> 

1610  GOTO  1580 

1620  PRINT  "Returning  to  CP/N  operating  systee" 

1630  END 


End  Listing 


If  you  want  to  present  your  ground-breaking 
work  to  some  of  the  most  innovative  and 
influential  people  in  the  microcomputing 
industry,  DDJ  can  help.  Contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


26 

486 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


Terminal  Programs 
for  North  Star 


Although  1  have  had  my  North  Star 
Horizon  for  almost  three  years, 
only  recently  have  I  had  the  op¬ 
portunity  to  use  it  to  communicate  with 
another  system.  A  change  of  employers 
has  provided  a  Prime  computer  which 
may  be  accessed,  via  a  modem,  at  300  or 
1200  baud.  This  was  enough  motivation 
for  me  to  borrow  a  modem  and  write  a 
routine  that  would  allow  me  to  use  my 
North  Star  system  as  a  terminal  with 
which  I  could  communicate  with  the 
Prime  computer.  At  first,  the  results 
were  very  disappointing  because  charac¬ 
ters  were  being  dropped  in  almost  every 
line  received.  On  a  hunch,  I  modified  the 
North  Star’s  initialization  routine  so  it 
programmed  the  8251  USART  for  one 
stop  bit  instead  of  two,  and  the  problem 
disappeared. 

The  program  listing  titled  MODEM. - 
ASM  (Listing  I,  p.  30)  is  an  expanded 
version  of  my  original  program.  At  the 
suggestion  of  DDJ,  a  feature  was  added 
which  computes  the  address  of  the  user 
area  I/O  table  and  calls  the  various  I/O 
routines  using  the  jumps  in  this  table.  The 
user  area  address  is  computed  by  adding 
700H  to  the  CP/M  BIOS  address  fetched 
from  location  0001 H.  All  of  the  I/O  and 
status  calls  are  passed  to  the  subroutine 
JUMPS  in  MODEM. ASM.  This  base  ad¬ 
dress  for  the  user  area  is  passed  on  the 
stack  and  the  offsets  for  the  I/O  routines 
are  passed  by  the  calls  to  JUMPS  using  a 
technique  I  learned  while  working  with 
the  TI9900  and  the  RCA  1802.  What 
would  normally  be  the  return  address  on 
the  stack,  instead  points  to  a  byte  which 
is  the  offset  into  the  jump  table  for  the 
I/O  routine  being  requested.  The  address 
of  the  user  area  is  preserved  as  the  first 
entry  on  the  stack  and  the  correct  return 
address  is  PUSHed  onto  the  stack  by 
JUMPS.  The  offset  is  added  to  the  base 
address  in  HL  and  a  PCHL  is  executed  to 
get  to  the  correct  I/O  routine.  When  the 
I/O  routine  does  a  RET  it  will  return  to 
the  address  immediately  following  the 
byte  which  contained  the  offset. 

The  program  MODEM. ASM  loops  be¬ 
tween  status  checks  of  the  console  and 
the  modem  input  ports  and  services  either 


by  Richard  Blessing 


Richard  Blessing,  R.R.4,  Box  5,  Geneseo, 
IL  61254. 


28 


port  when  a  character  is  presented.  Com¬ 
munication  is  in  the  full  duplex  mode 
and  since  the  Prime  echos  everything 
back  to  the  sender,  only  the  modem  in¬ 
put  is  displayed  on  the  console.  The  con¬ 
sole  input  routine  traps  two  characters 
which  can  be  used  to  request  special  func¬ 
tions.  An  ESCAPE  entered  from  the  con¬ 
sole  will  cause  a  JMP  0000H  and  reset  the 
system,  returning  to  CP/M.  An  FF  (form 
feed),  or  control- L  will  toggle  the  printer 
on/off. 

I  used  MODEM. ASM  for  about  two 
weeks  before  I  decided  I  needed  a  meth¬ 
od  for  transferring  disk  files  between  the 
Prime  and  my  North  Star  system.  I  want¬ 
ed  to  be  able  to  use  the  editors  on  my 
home  system,  which  are  much  superior  to 
the  editor  available  on  the  Prime.  Also, 
Pascal  is  supposed  to  soon  be  available  on 
the  Prime  and  I  hope  to  develop  programs 
on  the  North  Star  for  use  on  the  Prime. 
These  reasons  led  to  the  development  of 
the  program  MODEM. PAS  (Listing  II,  p. 
30). 

MODEM. PAS  is  written  in  Pascal/ 
MT+  and  functions  like  MODEM. ASM 
with  the  additional  ability  to  trans¬ 
fer  disk  files.  The  program  relies  on  the 
interactive  nature  of  the  Prime  to  transfer 
disk  files,  in  that  it  uses  X_ON  and 
X—OFF  to  control  communications  be¬ 
tween  the  North  Star  and  the  Prime. 
Also,  the  Prime’s  DELAY  command  is 
used  to  request  extra  NULL’s  be  sent  at 
the  end  of  each  line  to  allow  the  X_OFF 
command  to  take  effect.  This  enables 
MODEM. PAS  to  write  to  the  disk  file 
without  missing  any  characters  that  might 
have  been  sent  before  the  X_OFF  was 
seen  by  the  Prime. 

To  receive  a  file  from  the  Prime, 
invoke  the  Prime’s  editor  as  though  you 
were  going  to  edit  the  file  to  be  sent. 
Then  enter  an  EOT  at  the  console  which 
informs  MODEM. PAS  a  file  is  to  be  re¬ 
ceived  and  written  to  a  disk  file. 
MODEM. PAS  will  request  a  filename  to 
use.  Once  you  enter  the  filename  every¬ 
thing  received  from  the  modem  or 
console  will  be  written  to  this  file  until 
another  EOT  is  entered  at  the  console. 
This  requires  some  editing  of  the  file  once 
it  is  received  to  remove  the  editor  com¬ 
mands  used  to  get  the  file.  However,  it 
also  allows  you  to  send  commands  to  the 
Prime  or  MODEM. PAS  program  and  to 
concatenate  files  or  abort  the  command. 
As  I  mentioned  above,  it  is  necessary  to 
request  extra  NULL’s  at  the  end  of  each 


line  by  using  the  Prime’s  DELAY  com¬ 
mand.  A  <  DELAY  20  40  >  seems  to 
work  very  well. 

Files  are  transmitted  to  the  Prime 
using  both  MODEM. PAS  and  a  small 
FORTRAN  program  called  GET_F. 
A  listing  of  GET_F  appears  in  the  top 
portion  of  the  listing  for  MODEM. PAS. 
First  start  the  execution  of  GET_F  on 
the  Prime  and  respond  to  the  request 
for  the  filename  with  the  Prime  filename 
you  want  to  write  to.  Next  enter  a  SUB, 
or  control-Z,  at  the  console  and  answer 
the  prompt  for  a  filename  with  the  name 
of  the  file  you  wish  to  send  from  the 
North  Star.  MODEM. PAS  will  display  a 

for  each  line  ACKed  by  GET_F  and 
will  display  an  for  each  line  not 

ACKed  by  GET_F.  Lines  which  consist 
of  only  a  CR  LF  will  usually  not  get 
ACKed  even  though  they  are  okay.  Both 
programs  will  display  a  message  when  the 
EOF  has  been  transmitted  and  received. 
Control  is  returned  to  the  console  so  do 
not  enter  another  SUB.  This  routine  is 
much  slower  than  the  routine  used  to  re¬ 
ceive  files  because  of  the  time  required 
to  process  each  character  echoed  by  the 
Prime.  A  40K  file  took  two  hours  to 
transmit  at  300  BAUD  but  it  was  a  lot 
faster  and  less  work  that  if  I  had  to  re¬ 
type  the  file. 

In  addition  to  using  MODEM. PAS 
in  my  work  I  have  been  using  MODEM. - 
PAS  to  communicate  with  RCPM’s  (Re¬ 
mote  CP/M  systems)  and  CBB’s  (Com¬ 
puter  Bulletin  Boards)  around  the  coun¬ 
try.  I  used  it  to  transmit  a  copy  of  the 
36K  assembly  listing  of  XMODEM  from 
an  RCPM  in  Chicago  to  my  North  Star 
system.  XMODEM  is  a  utility  written  by 
Keith  Peterson  for  transmitting  files  be¬ 
tween  remote  CP/M  systems.  I  now  use 
XMODEM  to  transfer  files  when  talking 
to  RCPM’s,  since  it  is  available  and  more 
efficient  than  the  routines  I  use  with  the 
Prime.  I  was  unaware  of  the  large  amount 
of  software  available  free  on  the  RCPM’s; 
this  alone  makes  the  entire  project  worth¬ 
while. 

I  borrowed  the  modem  used  to 
develop  the  programs  presented  in  this 
article  and  later  purchased  a  used  Omni¬ 
tec  701 B  acoustic  modem  for  $50.  The 
used  modem  cost  a  sixth  of  what  the  bor¬ 
rowed  modem  cost  and  works  just  as 
well.  Also,  the  Pascal/MT+  I  used  to  write 
MODEM. PAS  is  an  excellent  product  and 
I  recommend  it  to  anyone  considering 
purchasing  Pascal.  BBj 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


487 


Terminal  Programs  for  N*  (Text  begins  on  page  28) 


Listing  I 


i: 

2* 

3! 

t 

4: 

5: 

6! 

f 

MODEM. ASH 

t 

i 

A  SIMPLE  ROUTINE 

TO  ALL ON  THE  N9 

71 

f 

TO  ACT  AS  A  DUHP 

TERMINAL  USING  A 

8: 

O' 

i 

MODEM. 

7  a 

io: 

f 

ii : 

0100 

ORG 

0100H 

12: 

i 

n: 

i 

OFFSETS 

INTO  USER 

AREA  OF  Cfjfc  FOR 

14: 

r 

JUMPS  TO  EACH  ROUTINE. 

is: 

f 

u: 

0000  * 

CSTAT 

EQU 

0 

CONSOLE  STATUS 

17J 

» 

is: 

0003  = 

CONIN 

EOU 

3 

CONSOLE  INPUT 

1?: 

r 

20: 

0006  * 

CONOUT 

EOU 

6 

CONSOLE  OUTPUT 

21 : 

i 

22: 

0009  * 

LIST 

EQU 

9 

PRINTER 

23: 

t 

24: 

r 

25: 

i 

THE  HODEH  IS  CONNECTED  TD  N»  SECOND  SERIAL 

26: 

i 

PORT. 

YOU  HILL  HAVE  TO  SET  UP  YOUR  USER 

27: 

i 

AREA  TO 

PROVIDE  STATUS  AND  I/O  ROUTINES 

28: 

i 

IF  THEY 

DO  NOT  ALREADY  EXIST. 

29: 

i 

30 : 

i 

31 : 

oooc  = 

HODOUT 

EOU 

12 

MODEM  OUTPUT 

32: 

1 

CP/M'S  PUNCH 

33: 

34: 

000F  » 

NODIN 

EQU 

15 

MODEM  INPUT 

35: 

f 

CP/M'S  READER 

36: 

i 

37J 

0012  - 

MSTAT 

EQU 

18 

MODEM  STATUS 

38: 

i 

C^H'S  PRINTER  STATUS 

39: 

i 

40: 

0700  - 

USER 

EOU 

0700H 

OFFSET  FROM  BIOS  TO  USER  AREA 

41: 

» 

42: 

f 

43: 

00 IB  * 

ESC 

EQU 

IBM 

ESCAPE  TO  EXIT 

44: 

I 

45: 

OOOC  = 

FF 

EQU 

OCH 

CONTROL -L  TO  TOGGLE  PRINTER 

46: 

» 

ON  /  OFF 

47: 

r 

48: 

i 

SET  UP 

STACK  ANB 

TURN  OFF  PRINTER 

49: 

1 

FLAG. 

so: 

5i: 

0100  318201 

start: 

LXI 

SP» STACK 

52: 

0103  AF 

XRA 

A 

CLEAR  PRINT  FLAG 

53: 

0104  326201 

STA 

PFLAG 

SAVE  PRINT  FLAG 

54: 

55: 

0107  2A0100 

LHLD 

000 1H 

i  GET  ADDRESS  OF  BIOS 

56: 

010A  110007 

LXI 

D»USER 

i  ADD  OFFSET  INTO  USER 

57: 

010D  19 

DAD 

D 

»  AREA  FOR  I/O  ROUTINES 

58: 

010C  E5 

PUSH 

H 

J  SAVE  ON  STACK 

59: 

i 

60 : 

i 

41: 

i 

KEYBOARD  INPUT 

ROUTINE 

12! 

TRAPS  CONTROL-L  TO  TURN  PRINTER 

63! 

» 

FLAG  ON/OFF  OR 

AN  ESCAPE 

64! 

i 

TO  EXIT 

AND  RETURN  TO  CP/M 

451 

> 

44! 

OtOF  CD5101 

cino: 

CALL 

JUHPS 

1  CHECK  FOR  CHARACTER 

471 

» 

FROH  CONSOLE 

48i 

0112  00 

DB 

CSTAT 

i  OFFSET  TO  CONSOLE  STATUS 

47: 

» 

70! 

0113  87 

ORA 

A 

71* 

0114  CAJ401 

JZ 

CIM1 

1  DON'T  BAIT 

72: 

i 

ELSE 

73! 

0117  CD5101 

CALL 

JUHPS 

i  GET  CHARACTER 

74: 

9 

FROH  CONSOLE 

75! 

01 1A  03 

BB 

CONIN 

1  OFFSET  TO  CONSOLE  INPUT 

74! 

i 

77! 

OUB  FE1B 

CFI 

ESC 

i  TEST  FOR  ESCAPE 

78S 

01  ID  CA5D01 

JZ 

EXIT 

1  EXIT  TO  CP/H 

771 

80S 

0120  FEOC 

CPI 

FF 

1  TEST  FOR  CONTROL-L 

si : 

IF  NOT  A  CONTROL -P 

82! 

0122  C22F01 

JNZ 

C0UT1 

1  SEND  CHARACTER  OUT  HODEH 

83! 

i 

ELSE 

84: 

0125  3A4201 

LDA 

PFLAG 

i  TOGGLE  PRINTER  FLAG 

85: 

0128  2F 

CNA 

1  ON/OFF 

84: 

0127  324201 

STA 

PFLAG 

1  AND  SAVE 

87: 

012C  C33401 

JHP 

CIN1 

i  CHECK  FOR  INPUT  FROH  HODEH 

88! 

1 

87: 

» 

HODEN  OUTPUT 

to: 

1 

9i: 

012F 

4F 

couti: 

MOV 

C»A 

i  SEND  CHARACTER  OUT 

92: 

0130 

CD5101 

CALL 

JUMPS 

i  MODEM  PORT. 

93: 

0133 

OC 

DB 

HODOUT 

J  OFFSET  TO  MODEM  OUTPUT 

94: 

95: 

» 

MODEM 

INPUT 

96: 

i 

97  J 

0134 

CD5101 

cini: 

CALL 

JUMPS 

»  CHECK  FOR  CHARACTER 

98: 

» 

FROM  MODEM 

99: 

0137 

12 

DB 

MSTAT 

i  OFFSET  TO  MODEM  STATUS 

100: 

101 : 

0138 

B7 

ORA 

A 

102: 

0139 

CA0F01 

JZ 

CINO 

i  DON'T  WAIT  FOR  ONE  ! 

103: 

i 

104: 

013C 

CD5101 

CALL 

JUMPS 

i  GET  CHARACTER 

105: 

013F 

OF 

DB 

NODIN 

5  OFFSET  TO  MODEM  INPUT 

106: 

i 

107: 

0140 

4F 

MOV 

Ct  A 

i  SAVE  CHARACTER 

loe: 

t 

109: 

t 

CONSOLE  OUTPUT 

no: 

t 

m: 

0141 

3A6201 

couo: 

LDA 

PFLAG 

1  TEST  PRINTER  FLAG 

112: 

0144 

FEOO 

CPI 

00H 

»  TEST  FLAG  <0  =  OFF»  -1  *  0N> 

in: 

t 

iu: 

0146 

C45101 

CNZ 

JUMPS 

t  IF  PRINTER  FLAG  IS  ON 

ns: 

t 

CALL  PRINT  ROUTINE. 

no: 

0149 

09 

DB 

LIST 

i  OFFSET  TO  LIST 

117: 

t 

ns: 

9 

THEN 

no: 

i 

120: 

014A 

CDS101 

CALL 

JUMPS 

1  WRITE  TO  CONSOLE 

121 1 

014D 

06 

DB 

CONOUT 

»  OFFSET  TO  CONSOLE  OUTPUT 

122: 

i 

123: 

9 

124: 

014E 

C30F01 

JMP 

CINO 

i  LOOP 

125: 

9 

126: 

9 

127: 

i 

THIS  ROUTINE  JUHPS  INTO  THE  USER  AREA 

128: 

9 

JUMP  TABLE.  IT 

LEAVES  THE  RETURN  ADDRESS 

129: 

f 

ON  THE 

STACK  FOR 

THE  ROUTINE  WHICH  CALLED 

iso: 

9 

JUMPS. 

1 31 : 

9 

132! 

0151 

El 

jumps: 

POP 

H 

!  GET  ADDRESS  OF  OFFSET  IN 

133: 

0152 

7E 

MOV 

A»M 

i  CALLINC  ROUTINE  AND  HOVE  TO  A 

134: 

9 

135: 

0153 

23 

I  NX 

H 

!  INCREHENT  PAST  OFFSET  BYTE  TO 

136! 

0154 

EB 

XCHG 

1  CORRECT  RETURN  ADDRESS 

137: 

138: 

0155 

El 

POP 

H 

i  GET  BASE  ADDRESS  OF  USER  TABLE 

139: 

0156 

E5 

PUSH 

H 

!  SAVE  FOR  NEXT  TIHE  THRU 

no: 

» 

141 : 

0157 

D5 

PUSH 

D 

i  PUT  RETURN  ADDRESS  ON  TOP 

142: 

f 

OF  THE  STACK 

143: 

» 

144: 

0158 

1600 

MV  I 

DtOOH 

!  COHPUTE  JUHP  AODRESS  BY  ADDING 

ns: 

015A 

5F 

MOV 

E*A 

i  OFFSET  TO  BASE  ADDRESS 

146: 

015B 

19 

DAD 

D 

147: 

9 

ne: 

015C 

E9 

PCHL 

i  JUHP  INTO  USER  TABLE 

149: 

9 

150: 

9 

151 : 

015D 

OCOO 

exit: 

HVI 

C»OOH 

i  RESET  SYSTEH 

152: 

015F 

C 3 0000 

JMP 

OOOOH 

!  GOT  AN  ESCAPE  FROH  CONSOLE 

153: 

» 

154: 

9 

STORAGE  AREA 

155: 

9 

156: 

0162 

x 

PFLAG 

EOU 

% 

t  PRINTER  FLAG 

157: 

9 

158: 

0182 

X 

STACK 

EOU 

•F20H 

i  A  LITTLE  SPACE  FOR  STORAGE 

159: 

9 

160: 

0162 

END 

End  Listing 


Listing  II 

Pascal/HT+  Release  5.2  Coeerieht  (c)  I960  HT  HicroSYSTEHS  Pa*e  «  1 

Compilation  of:  BJ MODEM 


Stmt  Nest  Source  Stateaent 


2  0 

3  0 

4  0 

5  0 

6  0 

7  0 

8  0 


Modea  rroiraa 
by 

Richard  Blessing 
Nay  13*1981 

This  proiraa  is  written  in  Pascal/MTF  and 
is  being  used  on  a  North  Star  Horizon  to 


30 

488 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


9 

0 

coeeunicate  with  a  Priee  coeeuter.  In 

10 

0 

addition  to  the  operation  as  a  tereinal 

11 

0 

the  following  coeeands  are  available! 

12 

0 

FF, 

13 

0 

Control-L  -  Turns  printer  listing  0N/0FF. 

14 

0 

15 

0 

EOT* 

16 

0 

Control-D  -  Turns  disk  save  0N/0FF, 

17 

0 

18 

0 

SUB* 

19 

0 

Control-Z  -  XMIT  DISK  <TEXT>  FILE  to  Priee 

20 

0 

21 

0 

CAN* 

22 

0 

Control-X  -  Returns  to  CP/M. 

23 

0 

«) 

24 

0 

( S$PS ) 

Stet 

25 

26 

27 

28 
29 

Nest 

0 

0 

0 

0 

0 

Source 

<* 

Stateeent 

Note!  The  following  FORTRAN  prodrae  is  executed 
on  the  Priee  when  sending  files  to  it. 

30 

0 

ittstssstssssssssssssssssssssssssssssssssssssssssssssssssssssssssssssss 

31 

0 

s 

PROGRAM  GET.F  t 

32 

0 

i 

I 

33 

0 

t 

PROGRAM  TO  RECEIVE  FILES  FROM  NS  t 

34 

0 

i 

1 

35 

0 

s 

CHARACTER  FILENAMES 16*  REC0RDS132*  ACKS1  S 

36 

0 

s 

t 

37 

0 

t 

DATA  ACK/t006/  S 

38 

0 

« 

* 

39 

0 

t 

MRITEUpM  "ENTER  IMNE  OF  FILE  TO  BE  BRITTEN' '  )'  >  * 

40 

0 

s 

REAIK  1,'(A16)'  )  FILENAME  1 

41 

0 

i 

X 

42 

0 

i 

0PEN( 7*FILE=FILENAME.ERR=?OO.IOSTAT»IER7 )  t 

43 

0 

t 

t 

44 

0 

s 

WRITE<  1»(" START  XMIT"  )' >  1 

45 

0 

t 

t 

46 

0 

47 

0 

* 

t 

48 

0 

S  WHILE  NOT  EOF  DO  f 

4? 

0 

1  1 

CONTINUE  t 

50 

0 

« 

51 

0 

« 

READ<  1 » '  (  A132 )'  *END*2  )  RECORD  /%  GET  RECORD  FROM  N*  t 

52 

0 

« 

53 

0 

* 

WRITE(  7*'(A132)'  )  RECORD  /»  WRITE  TO  DISK  FILE  $ 

54 

0 

t 

55 

0 

$ 

WRITE<  1»'(A1 )'  )  ACK  /I  SEND  ACKNOWLEDGE  TO  NS  S 

56 

0 

S 

57 

0 

$ 

CO  TO  1  S 

58 

0 

X 

5? 

0 

$ 

RECEIVED  EOF  FROM  NS  f 

60 

0 

I  2 

CONTINUE  | 

61 

0 

1 

CLOSE  (7)  S 

62 

0 

t 

STOP  t 

63 

0 

t 

64 

0 

»  900 

CONTINUE  t 

65 

0 

* 

BRITE<  Ip '("ERROR  OPENING  UNIT  7  "rIB>'>  IER7  1 

66 

0 

t 

STOP  $ 

67 

0 

S 

68 

0 

1 

END  S 

6? 

70 

71 

72 

0 

0 

0 

0 

ssssssssssssssssstssssmssssssssssssstsssssssssssssssttsssssssssssssss 

t) 

<  s$ps  ) 

Stet 

Nest 

Source 

Stateeent 

73 

0 

prodrae  MODEM.PASi 

74 

0 

75 

0 

const 

76 

1 

77 

1 

cr  =  sod;  lf  *  ioa ; 

78 

1 

FF  =  soc;  EOT  *  S04i 

7? 

1 

CAN  =  $18*  X.OFF  =  $13* 

80 

1 

X.ON  *  $11*  SUB  =  $ia; 

81 

1 

ACK  =  $06i 

82 

1 

83 

1 

(S 

Port  addresses  and  easks  S) 

84 

1 

PORTO.STATUS  =  $03*  P0RT1.STATUS  =  $05*  P0RT2.STATUS  *  $06) 

85 

1 

PORTO  .OUT  =  $02i  PORT  1  .OUT  *  $04)  PORT  2  .OUT  «  $OOi 

86 

1 

PORTO. IN  =  $02)  PORT 1. IN  *  $04) 

87 

1 

IN.MASK  =  $02)  OUT.MASK  =  $01) 

88 

1 

89 

1 

END.OF.FILE  =  $03) 

90 

1 

91 

1 

NULL  =  $00 ; 

92 

1 

93 

1 

ERROR  =  255*  (S  Value  returned  bv  unsuccessful 

94 

1 

disk  procedures  and  functions  t) 

95 

1 

96 

1 

var 

97 

1 

DISKlt 

98 

1 

DISK2  !  text) 

9? 

1 

CRLF  !  strinSC 23) 

100 

101 

102 

103 

104 

105 

106 

107 

108 
10? 
no 
111 
112 


Slot 

113 

114 

115 

116 

117 

118 

119 

120 
121 
122 

123 

124 

125 

126 

127 

128 
12? 

130 

131 

132 

133 

134 

135 

136 

137 

138 
13? 

140 

141 

142 

Stet 

143 

144 

145 

146 

147 

148 
14? 

150 

151 

152 

153 

154 

155 

156 

157 

158 
15? 
160 
161 
162 

163 

164 

165 

166 

167 

168 
16? 

170 

171 


Stet 

172 

173 

174 

175 

176 

177 

178 

179 

180 
181 
182 

183 

184 

185 

186 
187 


BUFFER  J  strindC132]i 
FILENAME  :  strindCUJ) 

KEY  :  bvte) 


PRINT-FLAG* 

DISK.FLAGt 

QUIT  !  boolean* 


( S$PS ) 


Source  Statement 


procedure  OUT_CONSOLE(  KEY  !  bvte)) 
bed  in 

waii( PORTO.STATUS*  OUT. MASK.  false)) 

outCPORTO.OUT ]  !«  KEY 
end. 


procedure  MODEM. I N(  var  KEY  :  bvte)i 
beiin 

if  ( ine<  PORT  1  .STATUS)  4  IN.MASK )  <>  0  then 
KEY  !  =  inp( P0RT1.IN )  4  $7F 

else 

KEY  !  =  NULL 

endi 


procedure  M0DEM.0UT(  KEY  !  bvte)} 
bed  in 

waiU PORT  1. STATUS.  OUT.MASK,  false X 

outCPORTl.OUTl  :*  KEY) 
endi 

<S$PS) 

Source  Stateeent 


(t  This  procedure  writes  env  partial  buffers  to  the  disk  file 
and  then  closes  the  file* 

*) 

procedure  FLUSH. AND_CL0SE(  var  RESULT  1  integer  » 

var 

I  !  integer* 

WRITE .ERROR  !  boolean; 

begin 

N0DEN_0UT<  X.OFF  ))  (t  Stop  xeit  froe  Priee  t) 

BUFFER  J*  concatl  BUFFER  »CRLF>) 

for  I  !*  2  to  length  BUFFER)  do 
begin 

WRITE  .ERROR  1*  wnb<DISKl*  BUFFERE  I  ] )) 
if  WRITE. ERROR  then 
writelnl  'Error  writing  to  disk'  )) 

end! 

closet  DISKI .  RESULT)* 
if  RESULT  =  ERROR  then 
wnteln( 'Error  closing  '*  FILENAME)* 

FILENAME  I*  "  »* 

M0DEM_0UT<  X.0N )  (S  Restart  xeit  froe  Priee  t) 
endi 
( S$PS ) 


Source  Stateeent 

procedure  DISK.RESETt  var  RESULT  l  integer); 
begin 

MODEM.OUTt  X.OFF  )) 

writelnt  'Enter  naee  of  file  to  be  sent'  )) 
readlnt  FILENAME)) 
assidnt  DISK2*  FILENAME)* 
resett  DISK2 )) 

RESULT  :=  ioresult; 

M0DEM_0UT(  X.O N ) 
endi 


procedure  DISK.REWRITEl  var  RESULT  !  integer)} 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


31 

489 


Terminal  Programs  for  N*  (Listing  continued,  text  begins  on  page  28) 


H0DEH_0UT<  X.OFF  )! 

writeln(  '  Enter  filenaee'  )» 
readlni  FILENAME  )i 
assign*  DISKI.  FILENAME  )* 
rewrite  DISKI  )! 

RESULT  :=  IORESULTi 
M0DEM_0UT(  X_0N) 


Source  Statement 

procedure  DISK.REAIK  var  RESULT  J  integer  )* 


Source  Stateaent 


procedure  DISK_WRITE(  KEY  1  bute)! 

var 

I  !  integer; 

WRITE. ERROR  :  boolean! 

begin 

if  KEY  =  CR  then 
beam 

(>  The  CR  is  used  as  a  flad  and  never  sets  concat  to  BUFFER. 
Also.  the  LF  is  dropped  while  sendind  the  X.OFF  so  both  are 
added  to  the  line  received. 

<) 

M0DEH_0UT<  X.OFF  )i 

BUFFER  1=  concat(  BUFFER » CRLF )!  (t  We  add  thee  back  here  t) 


DOT  J  CHAR! 

BYTE.OUT  * 

BYTE.IN  :  bvtei 
LINE-COUNT  l  integer! 


(t  This  procedure  is  used  to  validate  each  byte  as  it  is 
ECHOed  by  the  Pnae.  t) 

procedure  GET_ECHO<  var  BYTE.IN  :  byte! 

BYTE.OUT  !  byte)* 
var 

I  •  inteaer! 


for  I  :=  2  to  lenath<  BUFFER )  do 
WRITE-ERROR  J=  unWDISKl.  BUFFERC ID* 
if  WRITE .ERROR  then 

wnteln( 'Error  writing  to  disk')* 
BUFFER  1=  "» 

HODEN_OUT<  X.ON ) 
end 
else 

BUFFER  :=  concat< BUFFER*  chr(  KEY  ) )» 

end! 


(t  Loop  and  give  the  echoed  character  a  chance  to  get  here  t) 
for  I  J*  1  to  10000  do 
begin 

H0DEH_IN<  BYTE.IN)! 
if  BYTE.IN  <>  NULL  then 

if  (BYTE.IN  =  ACK)  or  (BYTE.IN  »  BYTE.OUT)  then 
exit! 

end! 

end! 


procedure  PRINTER(KEY  5  bste )» 

beam 

wait<  P0RT2.STATUS*  OUT.HASK.  false)! 
outtP0RT2_0UT]  J*  KEY! 

out[P0RT2_STATUS]  J*  120  (I  Reset  parallel  port  I) 
end! 

(**P*> 


begin  (t  DISK.READ  t) 
LINE-COUNT  I*  0* 


Source  Statement 


repeat  (t  For  each  line  f) 

repeat  (t  For  each  character  t) 

BYTE.OUT  :=  inb(  DISK2 )! 

if  (BYTE.OUT  <>  $1A)  then  (t  Check  for  CP/M  EOF  t) 
MODEH_0UT(  BYTE.OUT)* 

CET.ECH0( BYTE.IN.  BYTE.OUT)! 
until  (BYTE.OUT  =  LF )  or  (BYTE.OUT  *  41A)! 

CET_ECH0<  BYTE.IN,  BYTE.OUT  )i 

(t  If  Pnae  ACK's  the  line  sent  print  a  else  print  a 
to  indicate  a  possible  error  in  the  line  received 
t) 

if  BYTE.IN  =  ACK  then 
DOT  J* 
else 


Source  Stateaent 


252 

3 

DOT  :=  '*'! 

253 

3 

254 

3 

LINE-COUNT  J=  LINE. COUNT  4 

255 

3 

if  (LINE-COUNT  aod  50)  *  0 

256 

3 

writelnl DOT ) 

257 

3 

else 

259 

3 

wnte(  DOT )» 

259 

3 

260 

3 

until  BYTE.OUT  =  flA! 

261 

*> 

i. 

262 

*> 

4. 

writeln('End  of  file  reached 

263 

A 

M0DEH.0UT( END.OF.FILE )» 

264 

*» 

265 

n 

close(  DISK2*  RESULT)! 

266 

n 

if  RESULT  =  ERROR  then 

267 

*» 

wnteln( 'Error  closing  '  »FI 

268 

o 

end! 

269 

1 

270 

1 

271 

1 

272 

1 

273 

1 

( *4P* ) 

313 

1 

procedure 

IN.C0NS0LE(  var  KEY  :  byte! 

314 

1 

var  QUIT  J  boolean)! 

315 

1 

316 

1 

var 

317 

2 

RESULT 

1  inteseri 

318 

2 

319 

2 

320 

2 

321 

2 

begin 

322 

2 

KEY  :* 

NULL! 

323 

2 

if  (  inp(PORTO.STATUS)  &  IN. MASK )  <>  0  then 

324 

2 

KEY  I 

=  lne(PORTO.IN)  &  I7F! 

325 

2 

326 

case  KEY  of 

327 

2 

328 

•» 

NULL 

J  !  (1  NO  INPUT  <) 

329 

3 

330 

3 

FF 

:  begin  <t  Toggle  print  flag  ON/OFF  *> 

331 

4 

PRINT-FLAG  I*  not(  PRINT-FLAG  )i 

332 

4 

KEY  !=  NULL 

333 

4 

end! 

334 

3 

335 

3 

EOT 

:  (t  Open  a  disk  file  to  receive  incoeing 

data 

336 

3 

or  Flush  and  Close  a  disk  file  after 

receiving 

337 

3 

a  file. 

t) 

338 

3 

begin 

339 

4 

KEY  t*  NULL! 

340 

4 

341 

4 

if  DISK.FLAG  then 

342 

4 

FLUSH. AND.CLQSE(  RESULT ) 

343 

4 

344 

4 

else 

345 

4 

346 

4 

begin 

347 

5 

DISK.REWRITE(  RESULT)! 

348 

5 

if  RESULT  =  ERROR  then 

349 

5 

writeln( 'Error  rewriting  '*  FILENAME)! 

350 

5 

351 

5 

end! 

352 

4 

DISK.FLAG  not( DISK.FLAG)! 

353 

4 

end! 

354 

3 

355 

3 

356 

3 

32 

490 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


357 

3 

SUB  •  <t  Send  a  disk  file  to  another  sustea  *) 

392 

2 

358 

3 

besin 

393 

2 

if  QUIT  then  (»  QUIT  set  in  I*  CONSOLE  «> 

35? 

4 

KEY  !=  NULLi 

394 

2 

exit) 

360 

4 

DISK_RESET(  RESULT )) 

395 

2 

361 

4 

if  RESULT  <>  ERROR  then 

396 

2 

if  KEY  <>  NULL  then 

362 

4 

DISK_READ< RESULT) 

397 

2 

H0DEN_0UT( KEY  )) 

363 

4 

398 

2 

364 

4 

else 

39? 

2 

M0DEH_IN<  KEY)) 

365 

4 

400 

2 

if  KEY  <>  NULL  then 

366 

4 

writeln(  'Could  not  reset  '.FILENNNE) 

401 

•> 

0UT_C0HS0LE(  KEY )i 

402 

2 

403 

*> 

if  KEY  <>  HULL  then 

Stftt 

He  st 

Source  Statement 

404 

2 

besin 

405 

3 

if  DISK.FLAG  then 

367 

4 

endi 

406 

3 

DISK.NRITEtKEY  )t 

368 

3 

407 

3 

if  PRINT. FLAG  then 

369 

3 

CAN  :  QUIT  ;=  true)  <*  Exit  to  CP/H  $) 

408 

3 

PRINTER!  KEY >i 

370 

3 

409 

3 

end) 

271 

3 

end 

410 

2 

until  1  <>  I) 

372 

n 

4. 

end) 

411 

1 

end. 

373 

1 

411 

0 

374 

1 

411 

0 

Noraal  End  of  Input  Reached 

375 

1 

(HP*) 

SUt 

Nest 

Source  Statement 

End  Listing 

376 

1 

377 

1 

( **********  MAIN  PROGRAM  **********  ) 

378 

1 

37? 

1 

be*  in 

380 

1 

381 

1 

(*  Load  <cr>i<lf>  into  CRLF  *) 

382 

1 

383 

1 

CRLF  J=  concaUCRLFr  chr(CR).  chr<LF>>« 

384 

1 

385 

1 

386 

1 

DISK.FLAG  :*  false)  PR I NT .FLAG  J*  false) 

387 

1 

QUIT  Is  false) 

388 

1 

389 

1 

repeat 

390 

2 

391 

2 

IN_C0NS0LE(  KEY»  QUIT)) 

Do  you  have  a  microcomputing  manuscript 
that  seems  too  advanced  for  most  magazines, 
but  too  exciting  for  an  academic  journal? 
DDJ  may  be  the  niche 
you  have  been  looking  for. 

Let  us  hear  from  you  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


33 

491 


Small  VM 

Nucleus  of  a  Portable  Software 
Development  Environment 


Portability  is,  or  should  be,  a  major 
concern  of  everyone  developing 
software  for  microcomputers.  The 
present  variety  of  computers  and  operat¬ 
ing  systems,  and  the  rate  of  new  product 
announcements  makes  it  highly  desirable 
to  write  software  which  can  be  ported 
easily  to  foreign  environments. 

One  approach  to  limiting  the  impact 
of  porting  software  is  to  create  a  virtual 
operating  system  (VOS);  i.e.,  a  pseudo 
operating  system  which  runs  under  and 
takes  advantage  of  the  services  provided 
by  a  real  operating  system.  This  VOS 
would  look  the  same  to  the  user  and  to 
the  programs  running  under  it  regardless 
of  the  particular,  real  operating  system 
being  used. 

Application  software  is  then  written 
in  a  high  level  language  under  the  VOS. 
Porting  any  amount  of  software  is  just  a 
matter  of  developing  another  VOS  for  the 
new  operating  system  and  recompiling. 
If  the  new  computer  uses  a  different  pro¬ 
cessor  chip,  then  the  compiler,  assembler, 
and  loader  software  must  be  revised  or 
exchanged  for  different  packages.  Having 
a  self-compiler  is  a  real  advantage. 

To  the  user,  the  programs  and  the 
virtual  operating  system  look  the  same. 
This  limits  the  amount  of  retraining  need¬ 
ed,  as  well  as  the  amount  of  revision  to 
system  documentation. 

A  VOS  may  be  viewed  on  three 
levels.  At  the  lowest  level  is  the  interface 
to  the  real  machine;  this  is  called  the  vir¬ 
tual  machine  (VM).  It  is  a  collection  of 
primitives  for  handling  program  control, 
memory  management,  and  file  manage¬ 
ment  functions.  The  VM  is  written  in  as¬ 
sembly  language  and  is  the  only  part  that 
must  be  rewritten  when  the  VOS  is  port¬ 
ed.  The  second  level  is  the  command  pro¬ 
cessor.  It  is  written  in  a  high  level  lan¬ 
guage  and  interfaces  the  user  to  the  VM. 
The  third  level  is  the  collection  of  pro¬ 
grams  needed  to  round  out  a  complete 
software  development  environment.  This 
includes  text  editors,  compilers,  loaders, 
file  manipulation  programs,  text  format¬ 
ters,  etc. 

The  VOS  is  invoked  as  an  option  so 
that  the  full  capabilities  of  the  real 
operating  system  are  always  available. 
This  approach  has  been  used  to  create 


by  J.  E.  Hendrix 


J.  E.  Hendrix,  Rt.  1,  Box  74-B-l ,  Oxford, 
MS  38655. 


UNIX -like  (UNIX  is  a  trademark  of  Bell 
Labs)  environments  on  all  sorts  of 
systems  from  micros  to  mainframes.  For 
a  full  discusssion  of  the  VOS  approach  to 
software  portability  see  “A  Virtual  Oper¬ 
ating  System”  by  Dennis  E.  Hall, 
Deborah  K.  Scherrer,  and  Joseph  S. 
Sventak  ( Communications  of  the  ACM, 
September  1980,  volume  23,  number  9). 

Overview 

Small/ VM  is  the  first  step  in  a  proj¬ 
ect  to  develop  a  portable  software  devel¬ 
opment  environment  based  on  the  VOS 
concept.  The  listing  published  with  this 
article  is  copyrighted  and  is  intended  for 
private,  non-commercial  use  only. 

Small/ VM  is  written  for  North  Star 
DOS.  It  occupies  3K  bytes  (plus  537 
bytes  for  every  open  file  on  DD  systems, 
281  for  SD)  and  may  be  loaded  with  a 
program  or  operated  co-resident  with 
DOS  at  any  convenient  address.  Small/ 
VM  provides  program  control,  memory 
management,  and  file  management  ser¬ 
vices  for  programs  written  in  Small/C  or 
assembly  language. 

Small/VM  is  written  for  Allen 
Ashley’s  PDS  macro  assembler,  and  is 
compatible  with  North  Star  DOS  5.1 
and  later  releases.  It  performs  all  I/O 
through  standard  entry  points,  making  it 
compatible  with  whatever  device  drivers 
may  be  in  use.  It  supports  the  following 
features: 

•  UNIX-like  file  management  primi¬ 
tives 

•  automatic  file  creation  and  sizing 

•  random  file  access 

•  dynamic  memory  allocation 

•  UNIX-like  command  line  argu¬ 
ment  passing 

•  UNIX-like  redirection  of  standard 
I/O 

•  control  of  program  execution 

Invoking  Small/VM 

Ordinarily,  Small/VM  resides  on  disk 


as  a  North  Star  “GO”  file.  It  is  invoked 
by  a  “GO  VM”  command  either  manually 
or  automatically  at  boot  time.  After  be¬ 
ing  invoked,  it  does  some  housekeeping 
and  returns  to  DOS.  Then  it  is  ready  to 
service  programs  which  expect  its  pre¬ 
sence  in  memory  at  a  given  address.  I 
call  this  a  resident  copy  of  Small/VM. 
It  may  also  be  kept  as  a  file  of  relocatable 
code  to  be  loaded  and  linked  with  a  pro¬ 
gram  forming  a  self-contained  unit.  1 
call  this  a  local  copy  of  Small/VM. 

Memory  Map 

The  only  constraint  on  memory  uti¬ 
lization  is  that  some  amount  of  free  mem¬ 
ory  must  follow  the  program  for  use  by 
the  machine  stack  and  for  allocation  to 
the  program.  The  location  of  the  end  of 
the  program  is  passed  to  Small/VM  at 
BOJ  time,  and  the  location  of  the  end  of 
free  memory  is  a  variable  within  Small/ 
VM.  Free  memory  is  allocated  from  the 
end  of  the  program  toward  high  memory, 
and  stack  space  starts  at  the  end  of  free 
memory  and  grows  toward  the  program. 

Calling  Small/VM  Routines 

Except  for  CCBOJ,  all  Small/VM 
routines  are  called  by  pushing  parameters 
onto  the  stack  in  the  order  they  appear  in 
a  “C”  function  call,  then  executing  a 
CALL  to  the  appropriate  routine.  Each 
routine’s  calling  sequence  is  document¬ 
ed  in  the  listing.  Some  routines  return  a 
value  in  HL;  others  return  zero  for  suc¬ 
cess.  Minus  2  is  an  error  flag  indicating 
failure. 

File  Concepts 

Files  are  referenced  by  means  of 
small  integer  values  called  file  descriptors. 
They  are  assigned  as  shown  in  Table  1 . 
The  user  of  Small/VM  views  a  file  as  sim¬ 
ply  a  string  of  bytes.  Blocking  and  de¬ 
blocking  is  handled  automatically,  so 
there  is  no  need  to  be  concerned  about 
the  disk  format.  Files  on  disk  look  the 


TABLE  I 


UNIX 

North 

default 

standard 

Star 

open 

fd 

file 

device 

mode 

comment 

0 

stdin 

0 

read 

console  (redirectable) 

1 

stdout 

0 

write 

console  (redirectable) 

2 

stderr 

0 

read/write 

console  (fixed) 

3-9 

1-7 

read/write 

2nd  serial  I/O,  etc. 

10-17 

closed 

disk  files 

34 

492 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


same  as  I/O  ports  while  reading  and  writ¬ 
ing. 

Small/VM  Entry  Points 

A  jump  table  is  located  near  the  be¬ 
ginning  of  Small/VM  to  standardize  entry 
points  in  resident  copies.  When  Small/VM 
is  loaded  with  a  program,  calls  are  made 
directly  to  the  routines.  CCEOM  at  the 
front  of  the  table  locates  the  end  of  free 
memory. 

The  following  outline  lists  the  Small/ 
VM  entry  points  alphabetically  and  sum¬ 
marizes  the  operation  of  each.  The  syn¬ 
tax  for  calling  each  routine  is  given  as  it 
would  appear  in  a  “C”  program. 


A.  CCALOC 

1.  Call 

address  =  CCALLOC(size) 
address:  pointer  to  allocated  block  of 
memory 

size:  number  of  bytes  requested 

2.  Description 

CCALLOC  reserves  a  block  of  free 
memory  of  the  size  requested.  If  in¬ 
sufficient  space  exists  between  the  last 
allocated  block  and  the  stack,  the  pro¬ 
gram  aborts  with  an  allocation  error 
indication  (A?)  on  the  console. 

B.  CCAVAIL 

1.  Call 

size  =  CCAVAIL( ) 

size:  number  of  bytes  of  free  memory 
remaining 

2.  Description 

CCAVAIL  calculates  how  many  bytes 
of  free  memroy  existed  between  the 
end  of  the  last  allocated  block  of 
memory  and  the  top  of  the  stack.  If  a 
negative  value  results  an  overlap  con¬ 
dition  exists,  and  the  program  aborts 
with  a  memory  allocation  error  indi¬ 
cation  (A?)  on  the  console. 

C.  CCBOJ 
1.  Call 

This  routine  is  called  automatically 
at  the  beginning  of  the  program.  It  is 
not  called  by  the  program  explicitly. 
On  entry,  CCBOJ  expects  the  address 
of  the  first  byte  following  the  program 
(first  byte  of  free  memory)  to  be  in 
the  DE  register  pair.  The  address  at 
which  CCBOJ  is  to  return  to  the  pro¬ 
gram  must  be  on  top  of  the  stack.  The 
following  code  brackets  every  program 
or  sub-program  compiled  by  Small/C: 


LXI 

D,  $+6 

JMP 

CC9998 

CC9997: 

JMP 

CCBOJ 

CC9998: 

DS 

6 

PUSH 

D 

LXI 

D,  $+6 

JMP 

CC9997 

ORG 

CC9998 

JMP 

END 

$+6 

Any  number  of  modules  bracketed  by 
this  code  and  loaded  together  will  call 
CCBOJ  properly  even  though  none  of 
them  knows  where  the  program  resides 
in  memory  or  which  position  it  occu¬ 
pies  in  the  sequence  of  modules  which 
make  up  the  program.  Every  module 
but  the  last  has  the  code  following 
“JMP  $+6”  which  loads  at  CC9998 
overlayed  by  the  prefix  of  the  follow¬ 
ing  module. 

2.  Description 

CCBOJ  first  decides  whether  the  pro¬ 
gram  is  being  started  or  continued.  If 
it  is  being  continued,  CCBOJ  restores 
all  registers  and  reenters  the  program 
at  the  point  of  interruption.  If  it  is  be¬ 
ing  started,  CCBOJ  sets  the  machine 
stack  to  the  nominal  end  of  memory. 
Memory  above  this  point  may  be  dedi¬ 
cated  to  drivers  or  whatever. 

Next,  CCBOJ  scans  the  command 
line  in  DOS  in  order  to  establish  I/O 
redirection  and  set  up  command  line 
parameters  to  be  passed  to  the  pro¬ 
gram.  The  standard  input  file  may  be 
redirected  from  the  default  keyboard 
assignment  by  entering  a  “<”  fol¬ 
lowed  immediately  by  a  file  name  or  a 
file  descriptor  of  an  auxiliary  I/O  port. 
The  standard  output  file  may  be  re¬ 
directed  from  the  default  console  out¬ 
put  device  assignment  by  entering  a 
“>”  followed  immediately  by  a  file 
name  or  a  file  descriptor  for  an  auxil¬ 
iary  I/O  port.  If  the  standard  output 
file  does  not  exist  it  is  automatically 
created.  If  the  standard  input  file  does 
not  exist  the  program  is  aborted  with 
a  redirection  error  indication  (R?)  on 
the  console. 

Every  string  of  non-blank  charac¬ 
ters  following  “GO”  (except  for  I/O 
redirection  specifications)  are  taken 
for  parameters  to  the  program.  Each 
one  is  terminated  with  a  null  byte.  A 
pointer  to  each  one  is  pushed  onto  the 


stack.  Finally,  a  count  of  the  number 
of  parameters  is  pushed,  followed  by  a 
pointer  to  the  first  parameter  pointer 
of  the  list.  The  first  function  of  the 
program  should  be  coded  as  follows  in 
order  to  reference  the  command  line 
parameters: 

main(argc,  argv)  int  argc,  *argv; 

Finally  CCBOJ  pushes  the  address 
of  CCEXIT  onto  the  stack  and  reen¬ 
ters  to  the  program.  The  final  RET  of 
the  program  transfers  control  to 
CCEXIT.  A  program  may  also  explicit¬ 
ly  call  CCEXIT. 

D.  CCCLOSE 

1.  Call 

status  =  CCCLOSE(fd) 
status:  zero  for  success,  else  -2 

fd:  file  descriptor  of  file  to  be 
closed 

2.  Description 

CCCLOSE  terminates  access  to  a  file 
by: 

a.  flushing  its  buffer  if  necessary. 

b.  setting  the  file’s  new  size  in  the  file 
directory,  if  the  file  is  opened  in 
write  mode,  is  the  last  file  on  the 
diskette  physically,  and  zero  was 
given  for  a  file  size  at  open  time. 

c.  freeing  memory  used  for  the  file 
control  block. 

d.  flagging  the  file  descriptor  block  to 
indicate  a  closed  status. 

E.  CCEXIT 

1.  Call 

CCEXIT(errorcode) 
errorcode:  a  value  indicating  the  na¬ 
ture  of  the  exit 

2.  Description 

CCEXIT  closes  any  open  files.  If  error- 
code  is  non-zero,  its  low  order  byte  is 
displayed  on  the  console  followed  by 
a  question  mark.  Control  is  then  re¬ 
turned  to  DOS. 

F.  CCFILE 

1.  Call 

address  =  CCFILE(fd) 
address:  address  of  the  file  control 
block  associated  with  fd 
fd:  file  descriptor  for  the  file  in 
question 

2.  Description 

CCFILE  tells  the  caller  where  to  find 
the  file  control  block  for  a  specified 
file.  The  first  16  bytes  are  an  in-core 
copy  of  the  file’s  disk  directory  entry. 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


35 

493 


G.  CCFLUSH 

1.  Call 

status  =  CCFLUSH(fd) 
status:  zero  for  success,  else  -2 
fd:  file  descriptor 

2.  Description 

CCFLUSH  allows  the  program  to  force 
buffer  flushing  if  changes  have  been 
made  to  the  file.  Nothing  happens  if 
the  buffer  contains  no  changes. 

H.  CCFREE 

I.  Call 

status  =  CCFREE(address,  size) 
status:  zero  for  success,  else  address 
address:  location  of  the  block  to  be 
freed 

size:  number  of  bytes  to  free 
2.  Description 

CCFREE  frees  the  block  of  memory 
described  by  address  and  size  only  if  it 
matches  the  end  of  allocated  memory; 
otherwise,  it  takes  no  action  and  re¬ 
turns  address. 

I.  CCHALT 

1.  Call 
CCHALTO 

2.  Description 

This  routine  allows  a  program  to  inter¬ 
rupt  itself.  It  saves  the  registers  (in¬ 
cluding  stack  pointer)  and  returns  to 
DOS.  Processing  may  be  resumed  by 
entering  a  CTL-R  (resident  copy  of 
Small/VM)  or  issuing  a  “JP”  to  the 
start  of  the  program  (local  copy). 

J.  CCMODE 

1.  Call 

mode  =  CCMODE(fd) 
mode:  0  if  closed 

1  if  read  only 

2  if  write  only 

3  if  read/write 
fd:  file  descriptor 

2.  Description 

CCMODE  indicates  the  open-mode  of 
a  file. 

K.  CCOPEN 

1.  Call 

status  =  CCOPEN(fd,  name,  mode,  size, 
type,  tdi) 

status:  zero  for  success,  else  -2 

fd:  file  descriptor  to  be  assigned  to 
the  file 

name:  address  of  null  terminated  char¬ 
acter  string  containing  the 
name  in  North  Star  format  of 
the  file  to  be  opened 


mode:  0  —  allocate  a  file  control  block 
only 

1  -  read  mode 

2  —  write  mode 

3  —  read/write  mode 

size:  size  of  new  file  in  disk  blocks 
type:  North  Star  file  type 
tdi:  North  Star  type  dependent  in¬ 
formation  (first  2  bytes) 

2.  Description 

CCOPEN  opens  disk  files,  making 
them  accessible  to  the  program.  If 
write  mode  is  specified,  non-existing 
files  are  created.  If  size  is  zero,  write 
mode  is  given,  and  the  file  is  either 
new  or  the  last  file  on  the  diskette 
physically,  then  its  size  is  set  automa¬ 
tically  at  close  time.  Type  and  tdi  go 
into  the  file  directory  entry  of  a  new 
file.  These  North  Star  dependent  para¬ 
meters  do  not  create  a  significant 
portability  problem  since  in  the  Small/ 
C  environment,  this  routine  is  usually 
called  indirectly  through  the  fopen 
routine  in  the  standard  I/O  library. 
Fopen  supplies  zeros  for  them.  Their 
presence  permits  some  programs  great¬ 
er  freedom  in  performing  file  manipu¬ 
lation  functions. 

L.  CCPOLL 

1.  Call 

CCPOLL(flag) 

flag:  0  —  disable  operator  interrupts 
1  -  enable  operator  interrupts 
and  poll  for  one 

2.  Description 

Two  types  of  interrupts  are  recognized 
by  CCPOLL.  A  CTL-C  causes  the  pro¬ 
gram  to  return  to  DOS  after  preserving 
its  registers;  it  may  be  resumed  at  a 
later  time.  Any  other  unsolicited  char¬ 
acter  from  the  keyboard  causes  the 
program  to  pause  until  a  second  CTL- 
C  character  is  entered.  One  CCPOLL(O) 
call  makes  the  program  uninterrupta- 
ble.  CCPOLL(l)  calls  should  be  placed 
in  major  loops  within  the  program  to 
permit  full  operator  control. 

M.  CCPURGE 

1.  Call 

status  =  CCPURGE(name) 
status:  zero  for  success,  else  -2 
name:  address  of  null  terminated  char¬ 
acter  string  containing  the 
name  of  the  file  in  North  Star 
format 

2.  Description 

CCPURGE  locates  the  specified  file  on 
the  specified  or  default  drive  and  re¬ 


moves  its  entry  from  the  directory. 

N.  CCREAD 

1.  Call 

count  =  CCREAD(fd,  recaddr,  recsz) 
count:  number  of  bytes  actually  read 
or  -2  on  failure 

fd:  file  descriptor  of  an  open  file 
recaddr:  address  of  first  byte  of  pro¬ 
gram’s  record  buffer 
recsz:  number  of  bytes  requested 

2.  Description 

CCREAD  fetches  the  next  string  of 
bytes  of  the  length  specified  from  the 
file  indicated.  If  fewer  than  the  re¬ 
quested  number  of  bytes  remain  in  the 
file,  then  as  many  as  remain  are  trans¬ 
ferred  to  recaddr.  The  actual  number 
of  bytes  transferred  is  returned  to  the 
caller  —  zero  at  end  of  file.  Successive 
reads  transfer  data  from  consecutive 
byte  locations  in  the  file.  CCSEEK 
may  be  used  to  alter  the  sequence  of 
reading. 

O.  CCSEEK 

1.  Call 

status  =  CCSEEK(fd,  disp,  base) 
status:  zero  for  success,  else  -2 
fd:  file  descriptor 

disp:  displacement  (32  bits  unsigned) 
base:  determines  type  of  displace¬ 
ment 

0  -  bytes  from  current  position 
1  to  65535  -  size  in  bytes  of 
records  to  displace  from 
the  beginning  of  the  file 

2.  Description 

CCSEEK  relocates  the  current  position 
within  a  file  to  a  new  byte  address.  If 
the  new  position  is  outside  the  current 
buffer,  the  target  sector  is  read  into 
memory.  If  the  current  buffer  contains 
changed  data  it  is  flushed  before  read¬ 
ing  the  new  sector.  Presently  Small/C 
does  not  support  “long”  variables,  so 
the  displacement  may  be  passed  to 
CCSEEK  as  two  16-bit  values;  e.g., 
a  zero  followed  by  a  16-bit  displace¬ 
ment.  CCSEEK  may  be  used  only  with 
files  opened  for  read  or  read/write;  i.e., 
previously  existing  files. 

P.  CCWRITE 

1.  Call 

count  =  CCWRITE(fd,  recaddr,  recsz) 
count:  number  of  bytes  actually  writ¬ 
ten 

fd:  file  descriptor 

recaddr:  address  of  the  record  to  be 
written 


36 

494 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


recsz:  number  of  bytes  to  write 
2.  Description 

CCWRITE  writes  the  number  of  bytes 
specified  by  recsz  from  recaddr  to  the 
file  indicated  by  fd.  Successive  writes 
transfer  data  to  consecutive  byte  loca¬ 
tions  in  the  file.  CCSEEK  may  be  used 
to  alter  the  sequence  of  writing,  but 
only  if  the  file  is  open  in  read/write 
mode. 

Conclusion 

Small/VM  adds  file  management, 
memory  management,  and  program  man¬ 
agement  functions  to  North  Star  DOS. 
The  ability  to  alter  standard  input  and 
output  assignments  at  execution  time  and 
to  pass  command  line  arguments  to  pro¬ 
grams  makes  it  possible  to  develop  pro¬ 
grams  in  Small/C  which  give  the  North 
Star  computer  a  definite  UNIX  flavor.  To 
date,  I  have  implemented  most  of  the 
programs  described  in  the  book  Software 
Tools  by  Kernighan  and  Plauger.  In  fact, 
this  article  was  prepared  with  the  soft¬ 
ware  tools  editor  and  text  formatter. 
Small/C  required  some  revision  to  its  ex¬ 
pression  analyzer  to  make  it  properly 
scale  values  added  to  and  subtracted  from 
pointers  and  array  names;  but  has  per¬ 
formed  flawlessly  since.  I  am  well  pleased 
with  the  performance  of  programs  writ¬ 
ten  in  Small/C  and  with  the  ease  with 
which  they  are  developed  and  maintained. 
We  owe  a  debt  of  gratitude  to  Ron  Cain 
for  placing  his  compiler  in  the  public 
domain. 

This  has  been  a  very  abbreviated  de¬ 
scription  of  Small/VM.  For  those  who 
wish  to  pursue  it  further,  complete  docu¬ 
mentation  (58  pages)  is  available  for  $10. 
The  package  is  available  in  double  density 
format,  including  documentation,  for 
$35.  Small/C  is  included  at  no  charge. 
Single  density  users  do  not  have  enough 
disk  space  to  compile  programs  as  large  as 
the  compiler  itself,  but  I  will  make  the 
package  available  to  them  for  $40  (two 
diskettes)  if  they  are  interested.  Since  I 
cannot  afford  the  time  to  properly  sup¬ 
port  the  package,  all  source  code  is  in¬ 
cluded.  Experienced  assembly  language 
programmers  should  have  no  trouble  pro¬ 
viding  their  own  support.  BPj 


DDJ’s  responsive  readership 
can  give  you  invaluable  feedback 
on  your  ideas  and  innovations. 
Find  out  how  you  can  reach  them 
by  contacting  us  at; 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415) 323-3111 


You  Read  Dr.  Dobb’s  Journal 
And  You  Don’t  Subscribe?! 

Save  $13  off  newsstand  prices  for  2  yrs. 
Save  $5  for  1  yr. 

Can  you  afford  to  miss  an  issue  with  information  vital 
to  your  interests?  As  a  subscriber  you  can  look  for¬ 
ward  to  articles  on  Small-C,  FORTH,  CP/M,  S- 100, 
Compiler  optimization,  Concurrent  Programming  and 
more,  delivered  right  to  your  door.  And  you’ll  never 
miss  the  issue  that  covers  your  project. 

DR.  DOBB’S  JOURNAL 
P.O.  Box  E 

Menlo  Park,  CA  94025 


Yes!  Sign  me  up  for  _ 2  yrs.  $47  _ 1  yr.  $25 

_  I  enclose  a  check/money  order 

_  Charge  my  Visa,  MasterCard,  American  Express 

_  Please  bill  me  later 

Name  _ 

Address  _ 


Credit  Card _  Exp.  date 

Acct  No.  _ 

Signature _ 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


37 

495 


Small  VM  (Text  begins  on  page  34) 


2  I *********************************************************** , 

3  i*  Small/VM*  version  1.0 

41*  A  virtual-machine  Interface  to  North  Star  DOS 

5  i*  for  Small/C  and  assembly  language  programs. 

6  »* 

7  l*  Copyright  198  1  J.  F.  Hendrix. 

H  i*  All  rights  reserved. 

V  I* 

10  l*  Written  for  PDS  MAKRO  assembler. 


I |  i A*********************************************************** 

12  I 

13  I 

14  , -  ENTRY  POINTS 

lb  I 

16  JMP  TRAP  IlSKIPPED  IF  LOADED  WITH  PROGRAM 

17  JMP  CCV9V8  1 1 EXECUTED  ONLY  IF  LOADED  WITH  PROGRAM 

18  CCEOMi  ENTRY  || NOMINAL  END  OF  MEMORY 

I V  DW  08000H 

20  JMP  CCBOJ 

21  JMP  CCEXIT 

22  JMP  CCPOLL 

23  JMP  CCHALT 

24  JMP  CCOPEN 

2b  JMP  CCCLOSE 

26  JMP  CCREAD 

27  JMP  CCWHITE 

28  JMP  CCSEfcK 

2V  JMP  CCMO0E 

30  JMP  CCFILE 

31  JMP  CCPURCE 

32  JMP  CCFLUSH 

33  JMP  CCALLOC 

34  JMP  CCFRFE 

35  JMP  CCAVAIL 

36  I 

37  »  DIVERT  CIN  CALLS  TO  CINTRAP 

38  i 

3V  TRAPi  LHLD  CIN*I 

40  SHLD  CINV  IlSAVE  CIN  VECTOR 

41  LX  I  H. CINTRAP 

42  SHLI)  CIN*  I 

43  JMP  DOS 

44  I 

4b  I - DOS  ENTRY  POINTS 

4o  l 

47  DOS*  EOU  2028H  IIWARM  START 

48  COUT«  EOU  2000H  .  I  I  CHAR  OUTPUT 

4V  CIN*  EOU  201  OH  IlCHAR  INPUT 

bO  CONTC*  EQU  201 6H  IlCTL-C  DETECT  ROUTINE 

51  DLixiK*  EOU  201  CH  llDIRECToRY  L(X>KUP 

52  DWRIT*  EOU  201  EH  llDIRECToRY  REWRITE 

53  DCOM*  EOU  2022H  llRD,  WRT,  OR  VERIFY 

54  CMUbE  *  EOU  203  I H  1 1 DOS  CMD  BUFFER  VECTOR 

5b  CONEG*  EOU  2034H  ItOI . 02 .03.04 ,F I . F2 ,F3, F4  —  O-OUAD.  F-FAST  STEP 

56  I 

57  l -  MISC  ASSEMBLY  CONSTANTS 

58  I 


5V 

AMAX  > 

EOU 

7 

II#  OF  AUX  I/O  PORTS 

60 

FMAX  • 

EOU 

8 

II#  OF  OPEN  FILES 

61 

bLKSZi 

EOU 

256 

I (DISK  BLOCK  SIZF 

62 

DDEN  * 

EOU 

2 

1 IDRIVE  DENSITY  —  1 -SINGLE.  2-DOUBLF 

63 

DSKSZi 

EQU 

350 

1 1  SECTORS  PER  SIDE  OF  DISKETTE 

64 

BPAD* 

EOU 

0 

1 IBUFFER  PAD  BYTE 

6b 

FCBONLYi 

EOU 

0 

IIOPEN  MODE  -  ALLOC  FCB  ONLY 

66 

RD* 

EQU 

1 

IIOPEN  MODE  -  READ 

67 

WRT* 

EOU 

2 

IIOPEN  MODE  -  WRITE 

68 

RDWRT* 

EOU 

3 

IIOPEN  MODE  -  READ/WRITE 

6V 

DCOMR* 

EQU 

1 

1 1  DCOM  READ  COMMAND 

70 

DCOM W 1 

EOU 

0 

IlDCOM  WRITE  0)MM AND 

71 

72 

1 

1 - 

FILE  DESCRIPTOR 

BLOCKS  ( FOB'S ) 

73 

74 

1 

FDBSZ* 

EOU 

4 

l ISIZE  OF  FDB  ENTRY 

7b 

FMODE  * 

EOU 

0 

1  IOFFSET  To  OPEN  MODE 

76 

FDEV  * 

EOU 

1 

1 IOFFSET  TO  N*  DEVICE 

77 

FFCb* 

EOU 

2 

1  IOFFSET  To  ADDR  OF  CORR  FCB 

78 

7V 

80 

FDBi 

FD  0 

DB 

RO 

IlSTDIN  OPEN  FOR  RD 

81 

DB 

0 

II  STD  IN  -  DEV  0  —  CONSOLE 

82 

DW 

0 

IlSTDIN  HAS  NO  FCB 

83 

84 

•  * 

FD  1 

DB 

WRT 

1 iSTDOUT  OPEN  FOR  WRT 

8b 

DB 

0 

IlSTDOUT  -  DEV  0  —  CONSOLE 

86 

DW 

0 

l  ISTDOUT  HAS  NO  FCB 

B7 

88 

1 

FD  2 

DB 

RDWRT 

1 ISTDERR  OPEN  FOR  RD/WRT 

8v 

DB 

0 

1 iSTDERR  -  DEV  0  --  CONSOLE  (ALWAYS) 

VO 

DW 

0 

1 ISTDERR  HAS  NO  FCB 

91 

1 - 

FD  3  THRU 

2  *AMAX 

92 

V3 

REPT 

DH 

AMAX 

RDWRT 

IIAUX  POHTS  OPEN  FOR  RD/WRT 

V4 

DB 

1  *# 

IlDEV  1,2,3 _ 

vb 

DW 

0 

UNO  Deb's 

VO 

97 

i - — 

REPND 

FD  3*AMAX 

THRU 

2* AM AX*FMAX 

Vb 

vv 

REPT 

DB 

FMAX 

0 

II DISK  FILES  CLOSED 

100 

DB 

0 

HUNUSED 

101 

uw 

0 

II ADDR  OF  CORR  FCB 

102 

103 

104 

l 

FDBV* 

REPND 

DW 

0 

••CURRENT  FDB  VECTOR 

10b  I 
lOo  t 

107  I - FILE  CONTROL  BLOCKS  (FCB's) 

108  I 

I OV  I - N*  FILE-DIRECTORY  ENTRY  ( FDE)  OFFSETS 

110  « 

I  I  I  NAM*  EOU  0  IlFILE  NAME 

112  DA*  EQU  8  I tDISK  ADDRESS  (SECTORS  0  -  349/699) 

113  FSZ*  EOU  10  nFILE  SIZE  IN  SECTORS 

114  ETY*  EOU  12  IlFILE  TYPE  (HIGH  BIT  SFT  IF  DOUBLE  DENSITY  FILE) 

Mb  TDI*  EQU  13  II TYPE-DEPENDENT  INFO 

116  I 


117  I - OTHER  OFFSETS 

I  18  I 

I  IV  DRV*  EOU  16  I IDRIVE 

120  NBb*  EOU  17  IINXT  BYTE  IN  BUFFER  (0.1,2 . BSZ-I  ) 

121  CBF  *  EOU  19  1 1  CUR  BUFFER  IN  FILE  (0,1,2 . 32/67) 

122  BSZ*  EQU  21  I IBUFFER  SIZE  (256  OR  512  BYTES) 

123  CHG*  EOU  23  1 10-NO  CHANGE  TO  BUFFER.  I. BUFFER  CHANGED 

124  BUF*  EOU  24  I IBUFFER 

12b  I 

126  I  FCB'S  ARE  ALLOCATED  BY  ALLOC 

127  I 

128  FCBSZ*  EOU  BUF*BLKSZ*DOENl ISIZE  OF  AN  FCB 


12V  l 

130  FCBV  *  DW  0  II  CURRENT  FCB  VECTOR 

131  I 

132  I - CALL  PARAMETERS 

133  I 


134  CPTDI *  DS  2  IIOPEN  -  TYPE  DEP.  INFO 

135  CPTYPE *  DS  2  I lOPEN  -  FILE  TYPE 

136  CPBASE*  DS  0  llSEEK  -  BASE 

137  CPSIZE*  DS  2  IIOPEN  -  FILE  SIZE  (256  BYTE  BLOCKS)!  FREE  -  MFM  SIZF 

138  CPMODE*  DS  0  IIOPEN  -  MODE 

139  CPRECSZ*  DS  0  I IREAD/WRITF  -  RECORD  SIZE 

140  CPDISP*  DS  0  llSEEK  -  DISPLACEMENT  (32  BITS) 

141  CPADDR*  DS  2  IlFREE  -  MEM  ADDR 

142  CPNAME*  DS  0  IIOPEN  -  FILE  NAME  ADDR 

143  CPREC*  DS  2  I iREAD/WR I TE  -  RECORD  ADDR 

144  CPFD*  DS  2  IlFILE  DESCRIPTOR 

145  I 


146  I - MISC  STORAGE 

147  | 

148  UPCSW*  DB  I  1 1  IGNORE  CTL-C'S  IF  ZERO 

14V  EOP *  DW  0  MEND  OF  PROGRAM 

150  FREEMEM*  UW  0  I  I  CURRENT  FREE  MEM  PTR 

151  SOb*  DW  0  IlSTART  OF  CMD  LINE  BUFFFR  IN  DOS 

152  ARGC •  DW  0  1 1 ARGUMENT  COUNT  FOR  MAIN 

153  RED*  DW  2*AMAX*FMAX  IlNEXT  REDIR  FD 

154  BOJRET *  DW  0  I  I ADDR  FOR  RET  TO  PROG 

15b  FDfaVTMP*  UW  0  IlHOLD  FDBV 

156  CINV*  DW  0  IlCIN  VECTOR  (ZERO  IF  LOADED  WITH  PROGRAM) 

157  FILNAME*  DS  B  llTEMP  FILE  NAME  STORAGE 

158  SPACE*  DB  20H 

15V  NCbF  *  DW  0 

160  NNBB  *  DW  0 

•  6 1  SAVSP*  DW  0  1 1 NON-ZERO  ON  PROGRAM  HALT  ONLY  (CTL-C) 

162  TEMP*  DW  0 

163  CMD*  DB  0 

164  DATA*  DB  0  IlHOLD  DATA  BYTE 

16b  I 

166  l 

167  I -  MACRO  DEFINITIONS 

168  I 

169  NOEXP 

170  RARU*  MACRO  HI.LO 

171  MOV  A. HI 

172  RAR 

173  MOV  HI, A 

174  MOV  A , LO 


17b  RAR 

I7e  MOV  LO,  A 

177  MACND 

178  SB CM •  MACRO  HI.LO 

179  MOV  A ,L 

180  SBB  LO 

181  MOV  L. A 

182  MOV  A.H 

183  SBB  HI 

184  MOV  H, A 

18b  MACND 

186  CADM *  MACRO  HI.LO 

187  MOV  A ,L 

188  ADC  LO 

18V  MOV  L, A 

190  MOV  A.H 

191  ADC  HI 

192  MOV  H.A 

193  MACND 

194  ADRHL*  MACRO  BLOCK, FIELD 

195  LHLD  BLOCKV 

196  LXI  B. FIELD 

197  DAD  B 

198  MACND 

19V  GE1A  *  MACRO  BLOCK. FIELD 

200  ADRHL  BLOCK, FIELD 

201  MOV  A.M 

202  MACND 

203  PUTA*  MACRO  BLOCK, FI  ELD 

204  ADRHL  BLOCK, FIELD 

205  MOV  M , A 

206  MACND 

207  GETHLi  MACRO  BLOCK, FIELD 

208  ADRHL  BLOCK. FIELD 

2 OV  CALL  GINT 

210  MACND 

211  PUlHL*  MACRO  BLOCK, FIELD 

212  XCHG 

213  ADRHL  BLOCK, FIELD 

214  XCHG 

215  CALL  PINT 

216  MACND 

217  I 

218  I 

21V  l - —  CCBOJ ()  stack  ■  return  addr,  DE  ■  free  mem  artdr 

22 0  l  set  up  return  to  EOJ 

221  l  scan  for  command  line  parameters 

222  l  establish  I/O  redirection 

223  i 


22 4  CCBOJ* 

ENTRY 

225 

LHLD 

CINV 

II LOADED  WITH  PROG? 

226 

MOV 

A.H 

227 

ORA 

L 

226 

JNZ 

BOJO 

1  INO 

229 

LHLD 

SAVSP 

1 1  YES . 

THEN  IS  PROG  HALTED? 

230 

MOV 

A.H 

23  1 

232 

ORA 

JNZ 

REENTER 

IlYES, 

THEN  CONTINUE  IT 

38 

496 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


233  BOJO*  XTHL  34V  , 

234  SHLD  BOJRET  1 1 BOJ RET- RE TURN  ADOR  FOR  PROGRAM  START  3bO  I  FILE  REDIRECTION 

23b  LHLD  CCEOM  m  i  , 


236 

SPHL 

IlSET  STACK  PTR 

237 

XCHG 

• IHL  ->  END  OF  PROGRAM 

238 

SHLD 

EOP 

23V 

SHLD 

FREEMEM 

•  UNIT  FREE  MEM  PTR 

240 

XRA 

A 

24  1 

STA 

FDB^FDEV 

II UNDIRECT  STDIN 

242 

STA 

FDB^FDBSZ^FDEV II UNDIRECT  STDOUT 

243 

LXI 

H.2+AMA X*FMAX 

244 

SHLD 

RFD 

MRESEr  1ST  RB3IR  FD 

24b  i 

246 

MV  I 

A.AMAX«3 

II  1ST  FILE  FD 

247  BOJ It 

PUSH 

PS* 

248 

CALL 

LOCFDB 

IlHL-FDB  VECTOR  (CAN'T  FAIL) 

24V 

SHLD 

FDBV 

250 

XRA 

A 

251 

PUT  A 

FDB.FMODE 

1 IMARK  FD  CLOSED 

252 

MOV 

H.A 

253 

MOV 

L.A 

254 

PUTHL 

FDB.FFCB 

UNO  FCB  ALLOCATED 

255 

POP 

PSN 

256 

I  NR 

A 

257 

CPI 

AMAX+FMAXO 

IlLAST  FILE  FD  ♦  1 

258 

JNZ 

BOJ  1 

25V  1 

260 

LXI 

H.O 

261 

SHLD 

SAVSP 

IIMAKE  CONT  CMD  ( AC >  INVALID 

262 

SHLD 

A  RGC 

IIRESET  A  RGC 

263  l 

264  |  PROCESS  CMD 

LINE  PARAMETERS 

26b  1 

266 

LXI 

H.CMDBF 

267 

CALL 

GINT 

268 

SHLD 

SOB 

ll->  DOS  CMD  LINE 

26V  ENDLPi 

I  NX 

H 

270 

MOV 

A.M 

271 

CPI 

OOH 

llENO  OF  LINE? 

272 

JNZ 

ENDLP 

UNO 

273  1 

274  SOBCK 1  * 

CALL 

GTSOB 

l iRET  IF  SOB«PTR 

275 

DCX 

H 

276 

MOV 

A.M 

277 

CPI 

2  OH 

II  SPACE? 

278 

JZ 

SOBCK  1 

II  YES 

27V  1 

280 

XRA 

A 

281 

I  NX 

H 

282 

MOV 

M ,  A 

IIZERO  FOLLOW  INC  BYTE 

283 

DCX 

H 

284  | 

285  DECR2I 

DCX 

H 

28e 

MOV 

A.M 

28  7 

CPI 

20H 

1 1  SPACE? 

288 

JNZ 

CKRIN 

28V 

I  NX 

H 

290 

PUSH 

H 

IlNEXT  ARGV  PTR 

352  RFILEi 

XCHG 

IlDE  ->  NAME 

353 

LHLD 

RFD 

UHL-NEXT  REDIR  FD 

354 

PUSH 

H 

35b 

XCHG 

UHL  ->  NAME 

356 

PUSH 

H 

357 

MV  I 

B.O 

IIBC-OPEN  MODE 

358 

PUSH 

B 

35V 

LXI 

H.O 

llHL-SIZE.  TYPE.  TUI 

360 

PUSH 

H 

361 

PUSH 

H 

362 

PUSH 

H 

363 

CALL 

C COPEN 

IIOPEN  REDIR  FILE  «  — 

364 

POP 

B 

365 

POP 

B 

366 

POP 

B 

367 

POP 

B 

368 

POP 

B 

36V 

POP 

B 

370 

MOV 

A.L 

II  SUCCESSFUL? 

371 

ANA 

A 

372 

JZ 

RFILE2 

1  1  YES 

373  1 

374 

MVI 

B.52H 

II "R"  CLUE 

375 

JMP 

ABORT 

376  1 

377  RFILE2I 

LHLD 

RFD 

378 

MOV 

A.L 

1 IA-RED I R  FD 

37V 

DCX 

H 

1 IDECR  FOR  NEXT  REDIR 

380 

SHLD 

RFD 

381 

JMP 

RFLAG 

382  1 

383  GTSOBi 

XCHG 

384 

LHLD 

SOB 

385 

XCHG 

l iDE-SOB,  HL-PTR 

386 

PUSH 

H 

387 

CALL 

UCMP 

388 

POP 

H 

38V 

RC 

IIRET  IF  SOB<PTR 

390 

POP 

B 

UWASr  RET  A  DDR 

391  1 

392 

PUSH 

H 

393 

POP 

D 

3V4 

LXI 

H.2 

395 

DAD 

D 

396 

MOV 

A.M 

3V7 

ORA 

A 

1 IZERO? 

3V8 

XCHG 

3VV 

JZ 

SKPA 

IIYES 

400 

I  NX 

H 

401 

PUSH 

H 

1 INEXT  ARGV  PTR 

402 

DCX 

H 

403 

CALL 

ARGS 

404  SKPAi 

LHLD 

A  RGC 

40b 

PUSH 

H 

II PUSH  ARGC 

406 

LXI 

H.2 

291 

DCX 

H 

292 

CALL 

ARGS 

293 

JMP 

SOBCK  1 

294  i 

2V5  CKRIN* 

CPI 

3CH 

II  "<"  ? 

296 

JZ 

RIN 

IIYES 

297 

CPI 

3  EH 

ll  ">■  ? 

298 

JZ 

ROUT 

IIYES 

29V 

CALL 

GTSOB 

IIRET  IF  SOB < PTR 

300 

JMP 

DECR2 

301  1 

302  1  PUSH 

PTR*I  & 

BUMP  ARGC 

303  1 

304  ARGS* 

XCHG 

305 

LHLD 

ARGC 

306 

I  NX 

H 

307 

SHLD 

ARGC 

308 

XCHG 

30V 

RET 

310  1 

311  1  REDIR 

STDIN 

312 

313 

1 

RIN* 

MVI 

C.RD 

314 

JMP 

RDIR 

31b 

316 

l 

1  REDIR 

STDOUT 

317 

318 

1 

Rout* 

MVI 

C.NR1 

31V  I 


320  i  REDIRECT  ROUTINE 

321  I 


322  RDIR* 

PUSH 

H 

IlSAVE  CMD  LINE  PTR 

323 

MOV 

A.C 

1 IFFTCH  RD/ART  FLAG 

324 

SUI 

1 

••CONVERT  TO  STDIN/STDOUT  FD 

325 

CALL 

LOCFDB 

IlHL-FDB  VECTOR  (CAN'T  FAIL) 

326 

SHLD 

FDBVTMP 

1 1  < - 

327  i 

328 

POP 

H 

IlFETCH  CMD  LINE  PTR 

32V 

PUSH 

H 

HAND  SAVE  IT  AGAIN 

330 

I  NX 

H 

331 

I  NX 

H 

332 

MOV 

A.M 

ll LOAD  2ND  BYTE 

333 

DCX 

H 

UHL  -»  1ST  BYTE 

334 

ANA 

A 

33b 

336  1 

JNZ 

RFILE 

IINOT  A  SINGLE  CHAR  TOKEN 

337 

MOV 

A.M 

338 

CPI 

33H 

IlLT  1ST  AUX  PORT? 

33V 

JM 

RFILE 

IIYES 

340 

CPI 

50*AMAX 

HOT  LAST  AUX  PORT? 

34  1 

JP 

RFILE 

IIYES 

342 

343  I 

SUI 

30H 

••CONVERT  TO  BINARY 

344  RFLAG* 

LHLD 

FDBVTMP 

34b 

SHLD 

FDBV 

346 

PUTA 

FDB.FDEV 

IlFLAG  REDlRECriON  < - 

347 

POP 

H 

••RESTORE  CMD  LINE  PTR 

348 

JMP 

SOBCK 1 

407 

DAD 

SP 

408 

PUSH 

H 

II PUSH  ARGV 

40V 

• 

410 

LXI 

H.EXITO 

4  1  1 

PUSH 

H 

IlSEl  UP  PROG  EXIT  TO  EXITO 

412 

LHLD 

BOJRET 

4  13 

PCHL 

•  •RETURN  TO  PROGRAM 

4  14 

i 

415 

1 

416 

417 

1  close  files, 

,  reset  controls.  Jmp  to  DOS 

418 

lerrcode*  O-normal  exit 

41V 

•  1-255 

Identifies  specific  error 

420 

1 

non-zero 

byte  Is  displayed  on  console 

421 

1 

422 

CCEXITi 

i  ENTRY 

423 

LXI 

H.2 

••ERROR  CODE? 

424 

DAD 

SP 

425 

MOV 

A.M 

426 

ANA 

A 

427 

JZ 

EXITO 

1 INO 

428 

1 

42V 

MOV 

B .  A 

430 

ABORT* 

XRA 

A 

431 

CALL 

COUT 

432 

MVI 

B.3FH 

1 1“?« 

433 

XRA 

A 

434 

CALL 

COUT 

435 

MVI 

B.ODH 

IlCR 

436 

XRA 

A 

437 

CALL 

COUT 

438 

MVI 

B.OAH 

•  ILF 

43V 

XRA 

A 

440 

CALL 

COUT 

44  1 

1 

442 

EXITO* 

LXI 

H.AMAXO 

•  1  1ST  FILE  FD 

44  3 

EXITI  • 

PUSH 

H 

444 

CALL 

CCCLOSE 

IICLOSE  IT  IF  OPEN 

445 

LXI 

H.O 

446 

PUTHL 

FDB.FFCB 

IIZERO  FCB  A DDR 

44  7 

POP 

D 

448 

PUSH 

D 

44  V 

LXI 

H.AMAX+FMAX 

♦2 ll LAST  FILE  FD 

450 

CALL 

UCMP 

IlDONE? 

451 

JZ 

DOS 

IlYEP 

452 

POP 

H 

453 

I  NX 

H 

454 

JMP 

EXITI 

455 

1 

450 

1 

457 

1  — - 

NORMAL  RETURN  TO  USER 

PROGRAM 

458 

1 

45V 

DONE* 

LXI 

H.O 

460 

RET 

46  I  I 

462  I 

463  I -  ERROR  RETURNS 

464  I 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


39 

497 


Small  VM 


(Listing  continued,  text  begins  on  page  34) 


46b  ERR2»  POP  B 

466  ERR  I'  POP  B 

467  ERR«  LX  I  H.-2 

46B  RET 

46V  I 

470  I 

471  I - BLOCK  MOVE 

472  t  HL-SOURCE  ADDR ,  DE-DEST  ADDR.  C-LENGTH 

473  l 

474  BMOVEi  MOV  A.M 

47b  [NX  H 

476  XCHG 

477  MOV  M , A 

47B  I  NX  H 

47V  XCHG 

480  DCR  C 

481  JNZ  BMOVE 

482  RET 

483  I 

404  , - GET  call  PARMS  FROM  STACK 

48b  l  DE-DEST  ADDR,  C-#  BYTES  TO  FETCH 

486  l 

48  7  GETPi  LX  I  H.4  II  TWO  CALLS  DEEP 

48B  DAD  SP 

48V  GETP I l  MOV  A.M 

4V0  STAX  D 

4V  I  DCR  C 

4V2  RZ 

4V3  I  NX  H 

4V4  [NX  D 

495  JMP  GETPI 

4V6  I 

4V7  I - FIND  FDB  &  FCB  ENTRIES 

4VB  t 


4VV 

FlNUFt 

LDA 

CPFD 

ll LOAD  FD 

500 

CALL 

LOCFDB 

1 IHL-ORJGINAL  FDH  VECTOR 

501 

LDA 

CPFD 

502 

CPI 

2 

1 1  RED I RECTA BLE? 

503 

JP 

FNDFI 

1 INO 

504 

XCHG 

IlDE-FDB  VECTOR 

505 

LXI 

H.FDEV 

506 

DAD 

D 

IlHL-FDB  DEV  VECTOR 

507 

MOV 

A.M 

1 1  LOAD  DEV 

50b 

XCHG 

IIHL-FDB  VECTOR 

50V 

ANA 

A 

1 1 REDIRECTED? 

510 

JZ 

FNDFI 

UNO 

51  1 

CALL 

LOCFDB 

UHL-RED!  R  FOB  VECTOR 

512 

FNDFI • 

SHLD 

FDBV 

•  •SAVE  FDB  VECTOR  «  — 

51  3 

LXI 

D.FFCB 

1 (OFFSET  TO  FCB  VECTOR 

514 

DAD 

D 

1 IHL-ADDR  Or  FCB  VECTOR 

515 

CALL 

GINT 

1 IHL-FCB  VECTOR 

516 

SHLD 

FCBV 

1 ISAVE  FCB  VECTOR  < - 

517 

RET 

518 

« 

5  1 V 

|  -- - 

LOCATE 

FDB  ENTRY 

(A-FD) 

520 

1 

521 

LOCFDB) 

i  CPI 

3*amax»FMAX  t (OUT  OF  RANGE? 

522 

JP 

ERR2 

1  1  YES 

581  I 


582 

IBUF2I 

GETHL 

FCB.BSZ 

583 

XCHG 

1  IDE- BUFFER  SIZE 

584 

ADRHL 

F  CB .  BUF 

UHL  ->  BUFFER 

585 

I BUF  3 • 

MV  I 

A.BPAD 

IIA-PAD  BYTE 

586 

MOV 

M.A 

58  7 

I  NX 

H 

588 

DCX 

D 

58V 

MOV 

A  .D 

5V0 

ORA 

E 

5V  1 

JNZ 

IBUF3 

592 

1 

5V3 

I ----- 

ZERO  NBH 

5V  4 

l 

595 

ZNBbi 

LXI 

H.O 

596 

PUTHL 

FCB.NBb 

1 (ZERO  N8B 

597 

STC 

ll FLAG  NEW  BUFFER  FITS 

5V  B 

RET 

59V 

1 

600 

1 - 

UPDATE  BUFFER  CONTROLS 

601 

l 

602 

UBUFi 

XRA 

A 

603 

PUTA 

FCB.CHG 

ll CLEAR  CHANGE  FLAG 

604 

GETHL 

FCB.CBF 

1  I BUMP  CBF 

605 

I  NX 

H 

606 

PUTHL 

FCB.CBF 

607 

RET 

608 

• 

60  V 

1  — — - 

SET  UP  DCOM  CALL  FOR  READ  OR  WRITE 

610 

1 

61  1 

DSKlOi 

GETHL 

FCB. DA 

612 

XCHG 

613 

GETHL 

FCB.CBF 

614 

DAD 

D 

615 

PUSH 

H 

IlSAVE  DA^CBF 

616 

ADRHL 

F  CB .  BUF 

617 

PUSH 

H 

1 ISAVE  BUFFER  ADDR 

618 

GETA 

FCB.FTY 

IIBIT  7  ->  DD 

61V 

ANI 

80H 

620 

MOV 

E.  A 

621 

GETA 

FCB. DRV 

622 

ORA 

E 

623 

MOV 

C  ,  A 

UC-DRIVE  (BIT  7  ->  DD) 

624 

LDA 

CMD 

625 

MOV 

B ,  A 

1 IB-DCOM  COMMAND 

626 

MV  I 

A.  1 

1 IA-NBR  OF  SECTORS 

627 

POP 

D 

IlDE-BUFFER  ADOR 

628 

POP 

H 

l  IHL-DA+CBF-DSK  ADOR 

62V 

CALL 

DCOM 

ll DOS  CALL  < - 

630 

JC 

ERR  2 

631 

RET 

632 

1 

633 

1 - 

COMPARE  hl  TO  DRIVE 

SIZE  IN  SECTORS 

634 

i 

SET  CY  IF 

HL<DRIVE 

SIZE 

035 

l 

636 

CDSZ« 

XCHG 

1  IDE- (HL) 

637 

GETA 

FCB.  DRV 

638 

MOV 

C.A 

UC-DRIVE 

40 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


69  7 

DAD 

SP 

813 

1 

698 

MOV 

A.M 

814 

1  CALL 

DLOOK  TO 

FIND  FILE 

69V 

STA 

UPCSN 

815 

I 

700 

ANA 

A 

816 

OPNJi 

XCHG 

701 

RZ 

31  7 

MVI 

A.20H 

702 

CALL 

CONTC 

818 

OPN4  I 

MOV 

M,  A 

703 

RNC 

UNO  CONSOLE  INPUT 

8 1 V 

I  NX 

H 

704 

JZ 

CCHALT 

IlCTL-C  FROM  0)NS()LE 

820 

DCR 

C 

705 

1 

821 

JP 

0PN4 

706 

MVI 

A ,  0 

II PAUSE  TILL  NEXT  CHR  FROM  CONSOLE 

822 

GETA 

F  C8 .DRV 

707 

CALL 

CIN 

823 

LHLD 

FCBV 

708 

CPI 

3 

1 ICTL-C? 

824 

CALL 

DLOOK 

70V 

RNZ 

UNO.  RESUME  PROGRAM 

825 

JC 

NEW 

710 

826 

1 

711 

82  7 

1  COPY 

N*  FOE  INTO  FCB 

712 

1 - 

CCHALH  ) 

828 

1 

713 

save  context 

and  return  to  DOS 

82V 

OLD* 

LXI 

D.-8 

714 

830 

DAD 

D 

715 

CCHALTi 

ENTRY 

831 

XCHG 

716 

PUSH 

PSN 

IlYES.  SAVE  CONTEXT 

832 

LHLD 

FCBV 

717 

PUSH 

B 

833 

XCHG 

716 

PUSH 

D 

834 

MVI 

C.I6 

71V 

PUSH 

H 

835 

CALL 

BMOVE 

720 

LX  I 

H.O 

836 

1 

721 

DAD 

SP 

83  7 

GETA 

FCB.FTY 

722 

SHLD 

SAVSP 

IlSAVE  SP 

838 

ANI 

8  OH 

723 

JMP 

DOS 

83V 

RLC 

724 

l 

840 

ADI 

1 

725 

REENTER 

»  LHLD 

SAVSP 

ll RESTORE  SP 

84  1 

MOV 

H.  A 

726 

SPHL 

842 

MVI 

L.O 

727 

LX  I 

H.O 

843 

PUTHL 

FCB.BSZ 

1 1 FLAG  CONT  CMD  INVALID 


734  l 

735  I 

736  i-——  CCOPEN(fd,  na me,  mode,  size,  type,  tdi) 

737  i 

/38  I  fd«  file  descriptor 

73V  I  namei  address  of  N*  file  name  (  and  drive)  terminaded  with  NULL  char 

740  l  mode*  l-rd,  2- wrt.  3-rd/wrt.  0»al locate  FCB  and  exit 

741  i  size'  file  size  in  blocks  for  open,  D-'ise  space  in  file  or  space  avail 

742  l  type*  file  type  for  new  file  (0-127) 

743  l  tdl i  type-dependent-info  for  new  file  (0-65535) 


745  CCOPENi 

ENTRY 

740 

LXI 

D.CPTDI 

IlFETCH  CALL 

PARMS 

/  4  7 

MVI 

C, 1  2 

/4H 

CALL 

GETP 

74V 

CALL 

FINDF 

IlSET  FDBV  A 

FCBV 

750 

LXI 

D.O 

751 

LDA 

CPFD 

II  I/O  PORT? 

752 

CPI 

3+AMAX 

753 

JM 

ERR 

IlYES 

754 

GETA 

FDH.FMODF 

IIOPEN? 

i » force  trailing  spaces 

IIWlLL  OVERRITE  DA  BYTE 


UA-DRV 

UHL  ->  FILENAME. SP.SP,  . 

IlLOOK  FOR  IT  < - 

UNO!  FOUND 


II BACK  UP  8  BYTES 


344  I 

84b 

846 

847 

848 
84V 

850 

851 

852  I 

853  I  YES. 

854  | 

855 

856 

857 

858 
85V 
860 

861  I 

862 


I  IDE  ->  DEST 
IlFDE  SIZE 


IIMINUS  IF  DD 
1 1  ISOLATE  DENSITY  BIT 


M I -SO,  2 -DO 

I IHL  -  0 1  00H/Q200H  (256/512) 


IlSET  BUFFER  SIZE  <  — 


I • LON  BY  I E  OF  MODE 
I  IRD? 

I  I  YES 

l l RD/NRT7 

I I  YES 

I IWRT? 

1 1  NO 


THEN  FORCE  ZERO  LENGTH  IF  LAST  FILE  ON  DISKETTE 


LX  I  H.20FFH 

SHLL)  FILNAME 

GETA  FCb.URV 

I.X  I  H. FILNAME 

CALL  DLOOK 

JNC  OLD2 

PUSH  H 

CETHL  FCb.DA 

PUSH  H 

GE1HL  FCB.FSZ 


I INEVFR.  NEVER  FILE  NAME 


I  I  < - 

I I  SHOULD  HAVE  FAILED  BUT  DIDN'T 


IlSAVE  A DDR  OF  1ST  FREE  SECTOR 
I  I  SAVE  A DDR  OF  CURRFNT  FILE 


866 

XCHG 

IlDE  -  CUR  FILE  SZ 

867 

POP 

H 

UHL  ■  CUR  FILE  A  DDR 

608 

DAD 

D 

UHL  -  NEXT  SECTOR  ADDR 

66V 

POP 

D 

IlDE  -  1ST  FREE  SECTOR  ADDR 

870 

CALL 

UCMP 

1 IDE-HL? 

UNO.  MUST  BE  IMBEDDED  FILE 
IlYES,  MUST  BE  LAST  FILF 


1 1 NON -ZERO  SIZE  ARC  MEANS  LEAVE  SAME  SIZF 
I  lELSE  ZERO  FSZ  < - 


755  ANA  A 

756  JNZ  ERR 

757  I 

758  LHLD  FCB1 

75V  MOV  A  ,H 

7oO  ORA  L 

761  JNZ  OPNI 

762  LX  I  H.F< 

763  PUSH  H 

764  CALL  CCAI 

765  POP  B 

766  SHLD  FCB1 

767  PUTHL  FOB 

768  I 

76V  OPN0  •  LDA  CPMi 

770  CPI  FCB' 

771  JZ  DONl 

772  I 

773  MV  I  A. I 

774  PUTA  FCB 

775  I 

776  I  VALIDATE  FILE  NAME 


JNZ 

ERR 

IlYES 

oe  i 

882 

LHLD 

FCBV 

IlFCB  ALREADY  ALLOCATED? 

883 

884 

MOV 

A  ,  H 

885 

ORA 

L 

880 

JNZ 

OPNO 

1 1  YES 

LXI 

H.FCBSZ 

IIGET  MFM  FOR  NEW  FCB 

PUSH 

H 

887 

CALL 

CCALLOC 

888 

POP 

B 

88V 

SHLD 

FCBV 

8V0 

PUTHL 

FDB.FFCB 

891 

892 

LDA 

CPMODE 

89  3 

CPI 

FCBONLY 

894 

JZ 

DONE 

1 l ALLOC  FCB  ONLY 

895 

890 

MVI 

A.  1 

IlSET  DEFAULT  DRIVE  NUMBER 

89  7 

PUTA 

FCB. DRV 

898 

RD,  RD/NRT,  OR  (NRT  A  IMBEDDED  FILE) 


GETHL  FCB.FSZ 
MOV  A  ,H 

ORA  L 

JZ  OPNERR 

JMP  OPNB 


IlFAIL  IF  ZERO  LENGTH  FILE 


IlFIRST  FREE  DSK  A DDR  « - 


I  ISIGN->DD 

I I  < - 


777  1 

90 1 

I  NX 

H 

II FORCE  FILF  SIZE  UP  T( 

/  78 

LHLD 

FCBV 

V02 

MOV 

A.H 

IlDIV  BY  2  TO  GET  SECT( 

779 

XCHG 

IlDE  ->  NAME  IN  FCB 

903 

RAW 

780 

LHLD 

CPNAME 

1 IHL  ->  NAMF 

904 

MOV 

H.  A 

78  1 

MVI 

C.8 

II  CHARS  TO  SEARCH 

905 

MOV 

A .  L 

782  OPNI  i 

MOV 

A.M 

IlLOAD  NXT  BYTE 

906 

RAR 

783 

I  NX 

H 

IINXT  BYTE 

907 

MOV 

L.  A 

784 

ANA 

A 

1 INULL? 

908  1 

785 

J  Z 

0PN3 

1  1  YES 

909  NEW  1 i 

PUTHL 

FCB.FSZ 

IlFILE  SIZE  (SECTORS)  - 

786 

CPI 

2  CM 

II  COMMA? 

910 

LXI 

H,DDEN*BLKSZ 

78  7 

JZ 

0PN2 

IlYES 

VI  1 

PUTHL 

FCB.BSZ 

IlSET  BUFFER  SZ  <— 

788 

CPI 

2  OH 

1 ISPACE? 

912 

LHLD 

CPTDI 

/8V 

JZ 

OPNERR 

IlYES 

913 

PUTHL 

FCB.TDI 

1 i TUI  BYTES  1 &2 

790 

XCHG 

V  1  4 

XRA 

A 

791 

MOV 

M ,  A 

1 1  STORE  IN  FCB  NAME-MAY  HARMLESSLY  OVERWRITE  DA  BYTE 

915 

PUTA 

FCB.TDI *2 

UTDI  BYTE  3 

792 

I  NX 

H 

916  1 

793 

XCHG 

917 

LDA 

CPMODE 

794 

DCR 

C 

918 

CPI 

WRT 

i IWRT? 

795 

JP 

OPN  1 

IlNOT  TRAILING  BYTE  YET 

9  1  V 

JNZ 

OPNERR 

UNO 

796 

JMP 

OPNERR 

IININTH  BYTE  MUST  BE  NULL  OR  COMMA 

920  1 

19  7  1 

921  NEW2> 

GETHL 

FCb.DA 

798  0PN2 i 

MOV 

A.M 

IlDRIVE  -  1  THRU  8? 

922 

XCHG 

79V 

CPI 

3IH 

Ill 

923 

GETHL 

FCB.FSZ 

800 

JM 

OPNERR 

1  INO 

924 

DAD 

D 

1  iHL-DAeFSZ 

801 

CPI 

39H 

1  19 

925 

LXI 

D.DSKSZ 

1 IDE-DSKSZ 

802 

JP 

OPNERR 

UNO 

926 

CALL 

UCMP 

803 

SUI 

30H 

II CONVERT  TO  BINARY 

927 

JC 

OPNERR 

IlDAeFSZ  >  DSKSZ  —  NO 

1 1 STORE  IN  FCB  OVER  DEFAULT 


1 1  NEXT  BYTE  NULL? 


92V  I  DISALLOW  IF  PREVIOUS  OPEN  WITH  FSZ-0  ON  SAME  DRIVE 
V30  I 

93 1  MV  I  B.FDBSZ 

932  MV I  C.FMAX 

V33  LX  I  H,FDB>FDBSZ*(3eAMAX) IlFIRST  F ILE-FDH 

V34  | 

935  NEN3i  MOV  A.M  l I  LOAD  OPEN-MODE 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


41 

499 


Small  VM 


(Listing  continued,  text  begins  on  page  34) 


936 

ANA 

A 

1 IOPEN? 

937 

JZ 

NEW4 

UNO  —  SKIPS  CUR  FDB  T CIO 

938 

PUSH 

H 

MSAVE  CUR  FDB  A  DDR 

93V 

LXI 

D.FFCB 

940 

DAD 

D 

IIHL  ->  FCB  ADOR 

94  1 

CALL 

GINT 

IIHL  ->  FCB 

942 

SHLD 

TEMP 

94  3 

LXI 

U.FSZ 

944 

DAD 

D 

IIHL  ->  FSZ 

945 

CALL 

GINT 

IIHL-FSZ 

946 

LXI 

D.O 

947 

CALL 

UCMP 

IlFSZ-O? 

948 

POP 

H 

1 1 RESTORE  CUR  FDB  ADOR 

94V 

JNZ 

NEH4 

1  iFSZoO 

950 

PUSH 

H 

95  1 

LHLD 

TEMP 

IIHL  ->  FCB 

952 

LXI 

D.DRV 

953 

DAD 

D 

954 

CALL 

GINT  \ 

955 

XCHG 

IlDE-DRV  (GARBAGE  IN  HIGH  BYTE) 

956 

PUSH 

8 

957 

GET  A 

FCB. DRV 

IIA-DRV  THIS  CALL 

958 

POP 

B 

959 

POP 

H 

960 

XRA 

E 

IlSAME  DRIVE/ 

961 

962 

JZ 

OPNERR 

IIYEP!  --  SAME  DRV.  FSZ-O.  OPEN 

963 

NEW4  i 

MV  I 

D.O 

964 

MOV 

E.B 

965 

DAD 

D 

II BUMP  TO  NXT  FOB 

966 

DCR 

C 

1 IANOTHER? 

967 

JNZ 

NEN3 

1 1  YES 

968 

1 

969 

1  FIND 

NULL  FDE 

970 

1 

971 

GETA 

FCB.  DRV 

972 

LXI 

H. SPACE 

973 

CALL 

DLOOK 

IIEMPTY  FDE? 

974 

JC 

OPNERR 

1  INO 

975 

1 

976 

1  COPY 

FCB  FIELDS  TO  FDE 

97/ 

« 

978 

LXI 

D.-8 

II BACKUP  8  BYTES 

979 

DAD 

D 

980 

XCHG 

IlDE  ->  FDE 

981 

ADRHL 

FCB.  NAM 

IlFDE  FIELDS  IN  FCB 

982 

MV  I 

C.I6 

IlFDE  SIZE 

983 

CALL 

BMOVE 

984 

l 

985 

i  WRITE  FDE  H) 

DISK  DIRECTORY 

980 

1 

987 

CALL 

DNRIT 

IlNEW  FDE  < - 

988 

l 

989 

OPNBi 

LXI 

H.O 

990 

PUTHL 

FCB.CBF 

IlCBF-O  < - 

9V  1 

CALL 

I BUF 

•  UNIT  NEW  BUFFER.  ZERO  NBB ,  CHI 

While  your  manuscript  may  be  too  technical 
for  some  other  micro  publications,  it  may  be 
“just  what  the  doctor  ordered”  for  our 
audience.  Let  us  take  a  look  at  it,  won’t  you? 
You  can  reach  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


992 

JNC 

OPNERR 

••WON'T  FIT 

993 

XRA 

A 

994 

PUTA 

F  CB ,  CHG 

llCHG-0  < - 

995 

LDA 

CPMODE 

990 

PUTA 

FDB.FMODE 

II SET  MODE  IN  FDB 

997 

CPI 

WRT 

l iWRT? 

998 

JNZ 

SEEK4 

UNO  —  SEEK  1ST  BYTE  ( RD  OR  RD/WRT) 

999 

JMP 

DONE 

iiEXIT 

1000  1 

1001  OPNERRi 

CALL 

FCBFRFE 

IlDEALLOCATF  FCB 

1002 

JMP 

ERR 

1003  1 

1004  i  TRY  To  DEALLOCATE  THE  CURRENT  FCB 

1005  1 

1006  FCBFREEi  LHLD 

FCBV 

1007 

PUSH 

H 

1008 

LXI 

H.FCBSZ 

1009 

PUSH 

H 

1010 

CALL 

CCFREE 

llHL-0  IF  MEM  RELEASED.  ELSE  ORIG  FCBV  VALUE 

101  1 

POP 

B 

1012 

POP 

B 

1013 

PUTHL 

FDB.FFCB 

HZERO  FCB  PTR  OR  LEAVE  UNCHANGED 

1014 

RET 

1015  1 

1016  l 

1017  l - 

CCCLOSE<  fd> 

1018  1 

1019  CCCLOSE 

•  ENTRY 

1020 

LXI 

D.CPFD 

II FETCH  CALL  PARM 

1021 

MV  1 

C.2 

1022 

CALL 

GETP 

1023 

CALL 

FINDF 

llSET  FDBV  A  FCBV  VECTORS 

1024 

LXI 

D.O 

1025 

CALL 

UCMP 

IlHL-FCHV-O?  (I/O  PORT) 

1020 

JZ 

ERR 

1  l  YES 

102  7 

GETA 

FDB.FMODE 

l IOPEN? 

1028 

ANA 

A 

1  029 

JZ 

ERR 

UNO 

1030  l 

1031 

CALL 

BFLUSH 

1 1 FLUSH  THE  BUFFER  IF  NECESSARY 

1032  l 

1033 

GETHL 

FCB.  FSZ 

llFILE  SIZE  ZERO? 

1  034 

LXI 

D.O 

1035 

CALL 

UCMP 

1036 

JNZ 

CLSE2 

I  INO 

1037  l 

1038 

GETHL 

FCB.CBF 

••HIGHEST  BUFFER  ♦  1 

1039 

PUTHL 

FCB. FSZ 

llSET  FILE  SIZE  «— 

1040 

LHLD 

FCBV 

1 1  COPY  FILE  NAMF  FROM  FCB  To  FILNAMF 

1041 

LXI 

D.F  ILNAMF 

IlSINCE  FILNAME  IS  FOLLOW FD  BY  A  SPACE 

1042 

M  V  I 

C.8 

••WHICH  DLOIK  NEEDS 

1043 

CALL 

BMOVE 

1044  | 

1045 

GETA 

FCB, DRV 

II READ  FDE  FROM  DISK 

1046 

LXI 

H.F  ILNAME 

104  7 

CALL 

DLOOK 

1  1  < - 

1  048 

JC 

ERR 

1049  1 

1050 

I  NX 

H 

105  1 

I  NX 

H 

1052 

XCHG 

IlDE  ->  FSZ  IN  DOS  FDE 

1053 

ADRHL 

FCB.  FSZ 

ilHL->FSZ  IN  FCB 

1054 

MV  I 

C.6 

1055 

CALL 

BMOVE 

ll COPY  FSZ.  FTY .  AND  TDI  INTO  DOS  FDE 

1056 

CALL 

DWRIT 

IIHRITE  UPDATED  FDE  To  DISK  < - 

105  7  l 

1058  CLSE2« 

CALL 

FCBFREE 

llTRY  TO  DEALLOCATE  FCB 

1059 

XRA 

A 

1060 

PUTA 

FDB.FMODE 

IlCLOSE  FILE  «— 

1  061 

JMP 

DONE 

1062  1 

1063  1 

1064  | - 

CCREAD(fd 

.  rec,  recsz) 

1065  1 

1 066  1  f  d i 

f 1 le  descriptor  of 

an  open  file 

1067  i  reci 

memory  address  of  i 

jser  data 

1068  lrecsz> 

number  of  bytes  to 

transfer 

1069  i 

1070  CCREADi 

ENTRY 

1071 

LXI 

D.CPRECSZ 

IIFETCH  CALL  PARMS 

1072 

MV  I 

C.6 

1073 

CALL 

GETP 

1074 

CALL 

FINDF 

llSET  FD6V  a  FCBV  VECTORS 

1075 

GETA 

FDB.FMODE 

l IOPEN  FOR  RD  OR  RD/WRT ? 

1076 

CPI 

RD 

1077 

JZ 

RDI 

1  1  YES 

1078 

CPI 

RD4RT 

1079 

JNZ 

ERR 

1  INO 

1  060  RDI  • 

LXI 

H.O 

1  IYES 

1061 

SHLD 

TEMP 

MBYTE  INDEX  -  0 

1062  1 

1063  «  LAST 

BYTE  TRANSFERRED? 

1084  i 

1085  RD2i 

XCHG 

IlDE-CUR  BYTE  INDFX 

1066 

LHLD 

CPRECSZ 

llHL-BYTES  TO  TFR 

1  087 

PUSH 

D 

1088 

CALL 

UCMP 

•  I  CUR  BYTE<HYTES  TO  TFR? 

1069 

POP 

H 

MHL-CUR  BYTE  INDEX 

1090 

JC 

RD3 

l 1 YES  —  NOT  YET  FINISHED 

1091 

re  r 

••FINISHED  —  RETURN  COUNT  OF  BYTES  TRANSFERRED 

1092  1 

1093  1  GET  NEX 1  BYTE 

1094  | 

1095  RD3i 

LDA 

FCBV 

1090 

MOV 

D,  A 

1097 

LDA 

FCBV*  1 

1098 

ORA 

D 

1099 

JNZ 

RD5 

l IF I LE  INPUT 

1  100  i 

HOI  WD3AI 

GETA 

FDB.FDEV 

II  I/O  PORT  INPUT  —  WHICH  PORT? 

1  102 

CALL 

CIN 

1 1  < - 

1  103 

MOV 

B.A 

IlSAVE  DATA 

1104 

LDA 

UPCSW 

l IHONOR  CTL-C  INTERRUPT? 

1  105 

ANA 

A 

1106 

MOV 

A ,  B 

II RESTORE  DATA 

1  107 

JZ 

RD4 

1  INO 

1108 

CPI 

3 

l  i CTL-C? 

1  109 

JNZ 

RD4 

i  INO 

1110 

GETA 

FDB.FDEV 

1  II  1 

ORA 

A 

ll FROM  CONSOLE? 

1  112 

MOV 

A  ,  B 

••RESTORE  DATA 

1  113 

JNZ 

RD4 

l  INO 

1  1  14 

CALL 

COt  ALT 

1  l  YES 

42 

500 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


RD3  A 


I  I  lb 
I  I  10  I 


1 1 1 7  1  MOVE  BYTE  FROM 

(A)  TO  USER  AREA 

1  1  IB  l 

1 1 IV  RD4i 

LHLD 

TEMP 

1120 

XCHO 

IlDE-BYTE  INDEX 

1  121 

LHLL) 

CPREC 

1  122 

DAD 

D 

IlHL-CUR  BYTE  IN  USER  AREA 

1  123  i 

1  124 

MOV 

M.A 

1 1  < - 

1  12b  1 

1  120 

LX  1 

H.  1 

1  12/ 

DAO 

D 

llBUMP  INDEX 

1  12b 

SHLD 

TEMP 

1129 

JMP 

RD2 

1  130  l 

1131  l  ANY  MORE  BYTES 

IN  BUFFER? 

1  132  l 

1133  RDbi 

GETHL 

FCB.NBb 

1  134 

XCHO 

1  13b 

GETHL 

F  C8 . BSZ 

1  130 

PUSH 

D 

1137 

CALL 

UCMP 

1  lNBb<BSZ? 

1  I3B 

POP 

D 

1 IDE-NBB 

1  1  39 

JNC 

RD6 

1  INO 

1  140  | 

1141  i  FETCH 

NEXT  BYTE  FROM  BUFFER 

1  142  1 

1 143  RDbAi 

ADRHL 

FCB.BUF 

1  1  44 

DAD 

D 

MHL->  NEXT  BYTE  IN  BUFFER 

1  14b 

MOV 

A  ,  M 

1 1  < - 

1  146 

LX  I 

H ,  1 

1  147 

DAD 

D 

1 IBUMP  NBB 

1  14b 

PUSH 

PSW 

1  1  4V 

PUTHL 

FCB.NBB 

1  ISO 

POP 

PSW 

1  ISI 

JMP 

RD4 

MGO  PUT  BYTE  IN  USER  AREA 

1  152  1 

1  1  S3  RU6i 

GETHL 

FCB.CBF 

1  154 

1  NX 

H 

1  15b 

PUSH 

H 

1 1  SAVE  NEW  CBF  FOR  SEEK 

1156 

XCHG 

1  157 

GETHL 

FCB.FSZ 

1  IbB 

CALL 

UCMP 

1 1 ( CBF* 1 ) <F  SZ  7 

1  15V 

POP 

H 

l INEW  CBF 

1  100 

JC 

RD7 

1  1  YES 

1  161 

LHLD 

TEMP 

1  INO 

1162 

RET 

1  163  l 

1 164  i  SEEK 

NEXT  SECTOR 

1  165  1 

1  166  RD7 • 

LX  I 

D,  0 

M NEW  NBB 

1  167 

CALL 

RWSEEK 

1 1  < - 

1  168 

MOV 

A.H 

1  l SEEK  OK? 

116V 

ORA 

L 

1170 

JNZ 

ERR 

1  INO 

1171 

XCHG 

1  IDE-ONBB 

1172 

JMP 

RD5A 

1  173  1 

1  1  74  l 

1  175  , - 

CCWRITE(fd,  rec,  recsz) 

1  1  76  l 

1  1  77  l  Mi 

file  descriptor  of 

an  open  file 

1 1 78  i  rec  i 

memory  address  of  user  data 

1 l 79  irecsz  • 

number  of  bytes  to 

tr ans  f er 

1  180  i 

1181  CCNRITE*  ENTRY 

1  182 

LX  I 

D.CPRECSZ 

•  •FETCH  CALL  PARMS 

1  183 

M  VI 

C.6 

1  184 

CALL 

GETP 

1  18b 

CALL 

FINDF 

l  iSET  FDB V  &  FCBV  VECTORS 

1  180 

GET  A 

FDB.FMODE 

••OPEN  FOR  RD  OR  RD/WRT? 

1  187 

CPI 

WRT 

1188 

JZ 

WRTI 

1  l  YES 

1  18V 

CPI 

RDWRT 

1190 

JNZ 

ERR 

1  INO 

1191  1 

1192  WR1  1  i 

LX  I 

H.O 

1  IYES 

1  IV3 

SHLD 

TEMP 

i IBYTE  INDEX  ■  0 

1  194  WR12I 

XCHG 

ilDE-CUR  BYTE  INDEX 

1  195 

LHLD 

CPRECSZ 

IlHL-BYTES  TO  TRANSFER 

1  196 

PUSH 

D 

1  197 

CALL 

UCMP 

1  198 

POP 

H 

1  19V 

RNC 

••FINISHED  —  RETURN  COUNT  OF  BYTES  TRANSFERFD 

1200  I 

1201  1  TRANSFER  NEXT 

BYTE 

1202  1 

1203  WRTJi 

XCHG 

IlDE-CUR  BYTE  INDEX 

1204 

LHLD 

CPREC 

1205 

DAD 

D 

IIHL  ->  CUR  BYTE  OF  USER  DATA 

1206 

MOV 

E.M 

1  lE-DATA  BYTE  < - 

1207  l 

1208 

LDA 

FCBV 

1  20  v 

MOV 

D,  A 

1210 

LDA 

FCBV* 1 

1211 

ORA 

D 

1212 

JNZ 

WRTb 

IlFILE  OUTPUT 

1213  1 

1214 

GETA 

FDB.FDEV 

••I/O  PORT  OUTPUT  --  WHICH  PORT? 

1215 

MOV 

B.E 

M DATA  BYTE 

1210 

CALL 

COUT 

1217  1 

1218  1  BUMP 

BYTE  INDEX  A  LOOP  BACK 

1  2  1  V  1 

1220  WRT4I 

LHLD 

TEMP 

1221 

I  NX 

H 

1222 

SHLD 

TEMP 

1223 

JMP 

WRT  2 

1224  • 

1225  l  WILL 

BYTE  FIT 

IN  CUR  BUFFER? 

1226  l 

1227  WRTbi 

MOV 

A ,  E 

IISAVE  DATA  BYTE  (E) 

1228 

STA 

DATA 

122V 

GETHL 

FCB.NBB 

1230 

XCHG 

l IDE-NBB 

1231 

GETHL 

F  CB . BSZ 

1 IHL-BSZ 

1232 

CALL 

UCMP 

1  |NBB<BSZ  ? 

1233 

JC 

WRT  10 

1  IYES 

1234  i 

1235  1  NO  - 

-  THEN  SEEK  OR  I  NIT 

NEXT  BUFFER 

1230  1 

123/ 

GETA 

FDB.FMODE 

1238 

CPI 

WRT 

1 l WRT  MODE? 

123V 

J  7. 

WRT  V 

1 1  YES 

1240  1 

124  1 

GETHL 

FCB.CBF 

UNO  —  MUST  BE  RD/WRT  MODE  THEN 

1242 

I  NX 

H 

•  •NEW  CBF 

1243 

LX  I 

D.O 

IINEW  NBB 

1244 

CALL 

RWSEEK 

II  < - 

1245 

MOV 

A.H 

i ID  ID  SEEK  FAIL? 

1246 

ORA 

L 

1247 

JNZ 

WRT9A 

•IYES  —  EOF 

1248 

JMP 

WRT  10 

1 INO  —  GOOD 

124V 

1 

1250 

1  FLUSH  4  PAD  THE  BUFFER.  BUMP  CBF 

1251 

1 

1252 

WRTVi  CALL 

BFLUSH 

1253 

JC 

WRT  10 

•INEXT  BUFFER  FITS 

1254 

l 

1255 

WRT VA •  LHLD 

TEMP 

UNO  ROOM  SO  RETURN  COUNT  OF  BYTES  TRANSFERRED 

1250 

RET 

125/ 

1 

1258 

1  STUFF  THIS  BYTE  IN  THE  BUFFER 

125V 

1 

1260 

WRT 1 0*  MV  I 

A.  1 

1261 

PUTA 

FCB.CHG 

••SET  CHANGE-FLAG 

1262 

GETHL 

FCB.NBB 

1263 

X  CHG 

l IDE-NBB  OFFSET  IN  BUFFER 

1264 

ADRHL 

FCB.BUF 

1265 

DAD 

D 

IIHL  ->  NEXT  BYTE  IN  THE  BUFFER 

1260 

LDA 

DATA 

126/ 

MOV 

M.A 

llSTUFF  IN  BUFFER 

1268 

1 

1209 

XCHG 

1270 

I  NX 

H 

1 IBUMP  NBB 

1271 

PUTHL 

FCB.NBB 

1272 

JMP 

WRT4 

1273 

1 

1274 

1 

1275 

, -  CCSEEKIfd 

.  dlsp.  base) 

1270 

i 

1277 

l  fdi  file  descriptor 

1278 

l  dispi  displacement  from 

base  (32  bit  value) 

1279 

1  base'  0  ■  bytes  from  current  position 

1280 

1  1.2. 3.. 

..  -  1.2.3, 

, ...  byte  units  from  BOF 

1281 

1 

1282 

CCSEEKi  ENTRY 

1283 

LXI 

D.CPBASE 

•  •FETCH  CALL  PARMS 

1284 

MV  I 

C.8 

1285 

CALL 

GETP 

1280 

CALL 

F  I NDF 

II  SET  FDBV  4  FCBV  VECTORS 

1287 

1 

1288 

LDA 

CPFU 

128V 

CPI 

3*AMAX 

ll I/O  PORT? 

1290 

JM 

ERR 

1 1  YES 

1291 

1 

1292 

GETA 

FDB.FMODE 

1 lOPEN? 

1293 

ANA 

A 

1294 

JZ 

ERR 

1  INO 

1295 

CPI 

WRT 

1 lOPEN  FOR  WRT? 

1290 

JZ 

ERR 

1 1  YES 

1297  l 

1298  I  CALCULATE  NEW  CBF  4  NBB 
I2VV  I 


1300 

LHLD 

CPBASE 

1  301 

MOV 

A.H 

1302 

ORA 

L 

1303 

JNZ 

SEEKIC 

1  304 

GETHL 

FCB.BSZ 

1 30b  PUSH  H 


Our  high-quality  editorial  and 
your  high-quality  products  are 
made  for  each  other!  Call  (415) 
323-31  11  to  reserve  your  space 
in  the  next  Dr.  Dobb ’s  Journal. 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


43 

501 


Small  VM  (Listing  continued,  text  begins  on  page  34) 


I30O 
1307 
I  308 
130V 
1310 
131  I 

1312 

1313 

1314 

1315 
I  316 

1317 

1318 
I  3 1 V 
1320 
I  32  1 

1322 

1323 

1324 
I  32b 
1326 
I  327 
1328 
I  32V 

1330 

1331 
I  332 
1333 
I  334 

I  33b 
I  336 

1337 

1338 
I  33V 
I  340 
134  1 

1342 

1343 

1344 
134b 

1346 

1347 
I  348 

1349 

1350 

1351 

1352 

1353 
I  354 
135b 
I  356 
135/ 

I  358 
I  35V 
1360 
I  361 
1362 


GETHL 

FCB.CBF 

LX  I 

D.O 

UDE.HL-CBF 

POP 

B 

1  IBC-BSZ 

CALL 

MULT32 

llDE.HL-CBF*BSZ 

PUSH 

D 

X  CHG 
GETHL 

FCB.NBB 

DAD 

D 

POP 

D 

JNC 

SEEK  1  A 

I  NX 

D 

SEEK  1 A • 

PUSH 

X  CHG 

D 

UDE.HL-<  CBF'*BSZ)  ♦NBB 

LHLD 

CPDISP 

DAD 

D 

POP 

D 

JNC 

SEEKIB 

I  NX 

D 

SEEK IBi 

PUSH 

H 

LHLD 

CPD I SPe2 

DAD 

D 

XCHG 

POP 

H 

IlDE, HL-(  ( C8F*BSZ  UNBB )  ♦CPD ISP 

JMP 

SEEK  ID 

SEEK IC« 

LHLD 

CPBASE 

PUSH 

H 

LHLD 

XCHG 

CP0ISP42 

LHLD 

CPDISP 

UDE.HL-CPDISP 

POP 

B 

llBC-CPBASE 

CALL 

MULT32 

1  IDE, ML-CPOISP*CP BASE 

SEEK IDi 

PUSH 

H 

GETHL 

FCB.BSZ 

UMUST  BE  A  POWER  OF  2  FROM  I  TO  16 

MV  I 

C.-l 

SEEK  1 E ■ 

ANA 

A 

I  NR 

C 

RARD 

H.L 

JNC 

SEEK  IF 

POP 

H 

1 IDE.HL -TARGET  BYTE  POINTER.  OL002I 

CALL 

P2DIV 

UHL- NCBF.  DE-NNBB 

1  <<<  ENTRY  POINT  FROM  READ 

<1  WRITE  >>> 

RWSEEK  * 

SHLD 

XCHG 

NCBF 

IlSAVE  NEW  CBF 

SHLD 

NNBB 

••SAVE  NEW  NBB  (REMAINDER) 

GETHL 

FCB.CBF 

CALL 

UCMP 

U NEW  CBF  -  OLD  CBF? 

JZ 

SEEK5 

1 1 YES ,  SKIP  FLUSH  A  FILL 

l  FLUSH 

OLD  BUFFER 

CALL 

BFLUSH 

II  < - 

LX  I 

D.O 

GETHL 

FCB.FSZ 

1  lFSZ-0? 

PUSH 

H 

Don’t  let  your  hot  utilities  or  computing  ideas 
sit  on  the  shelf.  DDJ  is  a  great  place  for  bright 
authors  to  get  a  start.  Contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


1  363 

CALL 

UCMP 

1  364 

POP 

H 

1365 

JNZ 

SEEK2 

1366  1 

1367 

LHLD 

NCBF 

1368 

CALL 

CDSZ 

136V 

JNC 

ERR 

1370 

JMP 

SEEK3 

137  1  i 

1372  SEEK2I 

XCHG 

1373 

LHLD 

NCBF 

1374 

XCHG 

137b 

CALL 

UCMP 

1376 

JNC 

ERR 

1377  1 

1378  1  READ 

NEW  BUFFER 

137V  i 

1380  SEEK3I 

CALL 

NBUF 

1381  1 

1382  SEFK4 i 

MV  I 

A.DCOMR 

1  383 

STA 

CMD 

1  384 

PUSH 

B 

1385 

CALL 

DSKIO 

1386 

POP 

B 

1387 

JMP 

DONF 

1  386  1 

138V  SEEKbi 

CALL 

NBUF 

1390 

JMP 

DONE 

139  1  l 

I3V2  1 

I  (NO 

IlNEW  CBF  <  DRIVE  SIZE? 
UNO  —  TOO  HAD 

IIDE-FSZ 

I  INCBF<FSZ? 

UNO  —  TOO  BAD 


1 1 HAKES  JMP  TO  ERP2  WORK  IN  DSKIO 
I  l  < - 

USET  CBF,  NBB.  AND  CHG 


1393  I - CCMODE(fd) 

•394  |  returns  open  mode  of  fd 

1395  l 


1  396 

CCMODE •  ENTRY 

1  397 

LX  I 

D.CPFD 

I3V8 

MV  I 

C.2 

1  39V 

CALL 

GETP 

1400 

CALL 

FINDF 

1  401 

GETA 

FDB , FMODE 

1402 

1403 

1404 

1405 

CALL 

RET 

1 

l 

SXT 

1406 

1 - CCFILE(fd) 

1407 

1408 

i  returns  addr  of 

CCF I LE •  FNTRY 

FCB  else  zero 

I40v 

LX  I 

D.CPFD 

1410 

MV  I 

C,2 

141  1 

CALL 

GETP 

1412 

1413 

1414 

1415 

CALL 

RET 

1 

1 

FINDF 

l  iHL-FCBV 

14  16 

14  17 
1418 

1  4  1  V 

l  deletes  named  file 

i 

CCPURGEi  ENTRY 

1420 

L  X I 

D.CPNAME 

142  1 

MVI 

C.2 

1422 

CALL 

GETP 

1423 

MV  I 

C  •  8 

IIBYTES  TO  MOVE 

1424 

LX  I 

D.FILNAME 

IIDEST  PTR 

1425 

LHLD 

CPNAME 

1 1 SOURCE  PTR 

1426 

PURGE li  MOV 

A  > 

142  7 
1428 

I  NX 
XCHG 

H 

142V 

ANA 

A 

1430 

1431 

JZ 

1 

PURGE 2 

1432 

MOV 

M.  A 

1433 

1434 

I  NX 
XCHG 

H 

1435 

dcr 

C 

1436 

JNZ 

PURGE  1 

1437 

1438 

JMP 

PURGE  3 

143V 

PURGE2  i  MV  I 

A.20H 

1  (TERMINAL  SPACE  FOR  DL<X>K 

1440 
144  1 

MOV 

1 

M ,  A 

1442 

PURGE3 1  M  V I 

A.  1 

ll DEFAULT  DRIVE 

144  3 

LX! 

H.F ILNAMt 

UHL  ->  FILE  NAME.  SP 

1  444 

CALL 

DLOOK 

1 1  < - 

1445 

JC 

ERR 

UNO  SUCH  FILE 

1446 

LX  I 

D.-8 

144  7 

DAD 

D 

1 1  BACKUP  8  BYTES 

1448 

MVI 

A  . 20H 

1  44V 

MOV 

M ,  A 

1 1  FORCE  SP  OVER  1ST  BYTE  OF 

1450 

CALL 

DWRIT 

II  < - 

1451 

1452 

1453 

JMP 

1 

1 

DONE 

1454 

• -  CCF LUSH ( f d ) 

1455 

1456 

1457 

1 

1 

CCFLUSHi  ENTRY 

flush  fd's  buffer  If  modified 

1458 

LX  I 

D.CPFD 

IlFETCH  CALL  PARM 

145V 

MVI 

C.2 

1460 

CALL 

GETP 

1461 

1462 

CALL 

1 

FINDF 

USET  FDBV  i  FCBV 

1463 

MOV 

A.H 

1464 

ORA 

L 

1465 

JZ 

DONE 

II  IGNORE  IF  NO  FCB 

1  466 

GETA 

FDB. FMODE 

1467 

ANA 

A 

1468 

JZ 

DONE 

U IGNORE  IF  CLOSED 

146V 

GETA 

FCb.CHC 

1470 

ANA 

A 

1471 

1472 

JZ 

1 

DONE 

II  IGNORE  IF  NOT  MODIFIED 

1473 

MVI 

A.DCOMW 

1474 

STA 

CMD 

14/5 

PUSH 

B 

HMAKES  ERR2  WORK 

1476 

CALL 

DSKIO 

1 1  < - 

1477 

POP 

B 

14  7b 

XRA 

A 

147V 

PUTA 

FCB.CHC 

1 (ZERO  CHG  FLAG 

1480 
1  48  1 
1482 

JMP 

1 

l 

DONE 

1483 

l - CCALLOC(slze) 

1484 

1485 

1  allocates  size 

1 

bytes  and  returns  the  addrev 

44 

502 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


I486 

CCALLOC* 

ENTRY 

1  487 

LXI 

H  ,2 

1  488 

DAD 

SP 

1  48v 

MOV 

E.M 

I4V0 

I  NX 

H 

14V  1 

MOV 

D.M 

•  I  DE-MS  I ZE 

I4V2 

LHLD 

FREEMEM 

I4V3 

PUSH 

H 

HOLD  FREE  MEM  PTR 

1  4V4 

DAD 

U 

1495 

PUSH 

H 

•  •NEW  FREE  MEM  PTR 

1  4V6 

X  CHG 

1497 

LXI 

H.O 

1498 

DAD 

SP 

1  4  VV 

CALL 

UCMP 

•  •NEW  PTR  <  SP? 

1500 

POP 

H 

•  •NEW  PTR 

1501 

POP 

D 

• IOLD  PTR 

lt>02 

JC 

ALLOCI 

•  •  YES 

1503 

l 

1504 

ACLUE « 

M  V I 

B.4  IH 

••“A"  CLUE 

1505 

JMP 

ABORT 

1500 

« 

1507 

ALLOCI i 

SHLD 

FREEMEM 

••UPDATE  PTR 

1508 

XCHG 

••RET  OLD  PTR 

150V 

RET 

1510 

l 

151  1 

1 

1512 

1513 

1 

releases  size 

bytes  at  addr 

1514 

l 

1515 

CO-REE* 

ENTRY 

1516 

LXI 

D.CPSIZE 

1517 

MV  I 

C.4 

1518 

CALL 

GETP 

1  51  V 

LHLI) 

CPA DDR 

1520 

PUSH 

H 

•  •BLOCK  TO  FREE 

1521 

XCHG 

1522 

LHLD 

CPSIZE 

••SIZE  TO  FREE 

1523 

DAD 

D 

••FREE  ONLY  IF  LAST  BLOCK  ALLOCATED 

1524 

XCHG 

1525 

LHLD 

FREEMEM 

1526 

CALL 

UCMP 

•  •MATCH? 

1527 

JZ 

FREE  1 

•  «YES 

1528 

1 

152V 

POP 

H 

••NO.  SO  RETURN  ORIGINAL  BLOCK  PTR 

1530 

RET 

1531 

1 

1532 

FREEH 

POP 

D 

1533 

PUSH 

D 

•  •  BLOCK  TO  FREE 

1534 

LHLD 

EOP 

1535 

CALL 

UCMP 

••BLOCK  PTR  <  END  OF  PROG? 

1536 

POP 

H 

1537 

JNC 

PREE2 

1 INO 

1538 

1 

153V 

MV  I 

B.46H 

M-F"  CLUE 

1540 

JMP 

ABORT 

154  1 

1 

1542 

FREE2* 

SHLD 

FRFFMEM 

••UPDATE  FREE  MEM  PTR 

1543 

LXI 

H.O 

1544 

RET 

1545 

i 

1546 

1 

1547 

1 - CCA VA I L ( ) 

1548 

I 

return  number  of  bytes  available  for  allocation 

154V 

1 

abort  If  stack  overflow  found 

1550 

1 

1551 

CCA VA I L  * 

ENTRY 

1552 

LHLD 

FREEMEM 

1553 

XCHG 

•  •DE-ADDR  OF  1ST  FREE  BYTE 

1554 

LXI 

H.O 

1  555 

DAD 

SP 

••HL-STACK  ADDR 

1  550 

XRA 

A 

•  JCY-0 

1557 

SBCM 

D.E 

1558 

JC 

ACLUE 

••STACK  OVERFLOW 

155V 

RET 

1560 

1 

1561 

1 - LOCAL  ARITHMETIC  A 

LOGICAL  ROUTINES 

1562 

1 

1563 

l PUT  THE 

ACCUM  INTO  HL  AND 

SIGN  EXTEND  THROUGH  H. 

1564 

SXT  * 

MOV 

L.  A 

1565 

RLC 

1566 

SBB 

A 

1567 

MOV 

H .  A 

1568 

RET 

156V 

•FETCH  A 

FULL  16 

-BIT  INTEGER  FROM  THE  ADDRESS  IN  HL 

1570 

•INTO  HL 

1571 

GINT  * 

MOV 

A  .M 

1572 

I  NX 

H 

1573 

MOV 

H.M 

1574 

MOV 

L .  A 

1575 

RET 

15/0 

•STORE  A 

16-BIT 

INTEGER  IN 

HI.  AT  THE  ADORESS  IN  DE 

1577 

PINT* 

MOV 

A.L 

1578 

STAX 

D 

157V 

I  NX 

D 

1580 

MOV 

A.H 

1581 

STAX 

D 

1582 

RET 

1583 

• 

1584 

•COMMON 

ROUTINE 

TO  PERFORM 

UNSIGNED  COMPARE 

1585 

•CARRY  SET  IF  DE 

<  HL 

1586 

•ZERO/NONZFRO  SET  ACCORDINGLY 

1587 

UCMP* 

MOV 

A.D 

1588 

CMP 

H 

158V 

JNZ 

UCMPI 

I5V0 

MOV 

A.E 

I5VI 

CMP 

L 

I5V2 

UCMPI * 

LXI 

H,  1 

1593 

RET 

1594 

1 

1595 

•MULTIPLY  DE.HL 

BY  BC  AND 

RETURN  IN  DE.HL 

I5V0 

•(UNSIGNED  MULTIPLY) 

15V  7 

MULT32* 

I5V8 

XCHG 

1  dVV 

SHLD 

MULTHIM 

1000 

LXI 

H.O 

1601 

SHLD 

MULTHIQ 

1602 

MULT  1  * 

MOV 

A.C 

1603 

RRC 

1604 

JNC 

MULT2 

1605 

DAD 

D 

1  o06 

PUSH 

H 

••ADD  MSB'S 

1607 

PUSH 

D 

1608 

LHLD 

MULTHIM 

1  60V 

XCHG 

1610 

LHLD 

MULTHIQ 

loll 

CADM 

D.E 

1612 

SHLD 

MULTHIO 

1613 

POP 

I) 

1614 

POP 

H 

1615  MULT2* 

XRA 

A 

1616 

MOV 

A.B 

1617 

RAR 

1618 

MOV 

B.  A 

1  61 V 

MOV 

A.C 

1620 

RAR 

162  1 

MOV 

C.  A 

1622 

ORA 

B 

1623 

JZ 

MULT3 

1624 

XRA 

A 

1625 

MOV 

A.E 

1626 

RAL 

162/ 

MOV 

E.A 

1628 

MOV 

A.D 

162V 

RAL 

1630 

MOV 

D.A 

1631 

LDA 

MULTHIM 

1632 

RAL 

1633 

STA 

MULTHIM 

1634 

LDA 

MULTHIM* i 

1635 

RAL 

1636 

STA 

MULTHIM* 

1637 

JMP 

MULTI 

1638  MULT3* 

XCHG 

163V 

LHLD 

MULTHIQ 

1640 

XCHG 

1641 

RET 

1642  MULT H I Q *  DM  0 

1643  MULTHI Mi  DM  0 

1644  | 

164b  I  DIVIDE  DE.HL  BY  2**C  GIVING  HL  (QUOTIENT)  AND  DE  (REMAINDER) 

1646  I ( UNSIGNED  DIVIDE) 

164  7 

1648  P2DIVI 

164V  MOV  B.C 

1650  P2DIVH  XRA  A 

1 65 1  ORA  B 

1652  JZ  P2UIV2 

1653  OCR  B 

1654  MOV  A.L 

1655  HAR  IlCY-LSB 

1656  RARD  D.E 

1657  RARD  H.L 

•658  JMP  P2DIVI 

165V  P2DIV2I  MOV  B.C 

1660  P2DIV3'  MOV  A , B 

1661  CPI  16 

1662  RZ 

1663  INR  B 

1664  ANA  A  I lCY-0 

1665  RARD  D.F 

1666  JMP  P2DIV3 

1667  I 

1668  I 

166V  CCVVV7I  JMP  CCBOJ 

1670  CCV998 *  DS  3  »«"JMP  $*6"  LOADS  HERE 

1671  DS  3  IINEXT  MODULE.  IF  ANY.  LOADS  STARTING  HERE 

1672  PUSH  D 

1673  LXI  D,S*6 

1674  JMP  CC9V97 

1675  IlHREE  MEM  STARTS  HERE  IF  LAST  MODULE  LOADED  WITH  PROG 

1676  ORG  CCV998 

1677  JMP  S*6 

1678  END 


Even  if  you  have  never  been  published  before, 
Dr.  Dobb’s  wants 
to  see  your  good  computing  ideas. 
Contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415) 323-3111 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


51 


Small-C  Grows  Up 


"Yon  harks  the  software  wizard, 
who  builds  mythical  castles  of  the  mind ; 
which  yet,  on  second  glance,  cause  won¬ 
drous  things  to  occur.  ” 

As  a  professional  software  wizard,  I 
spend  a  fair  bit  of  my  effort 
toward  building  my  tool  chest  to 
allow  me  to  be  more  effective  as  a  sys¬ 
tems  designer  and  programmer.  Over  the 
last  four  years  I’ve  built  quite  a  set  of 
tools,  but  I’m  always  hunting  for  a  better 
choice  than  assembler.  The  8080/Z80 
family  tends  to  be  so  low-level  that  even 
the  simplest  16-bit  operations  require  a 
number  of  instructions,  enough  so  that 
the  logic  of  straight-line  assembler  code 
tends  to  get  lost  in  the  details. 

My  interest  in  languages  goes  back 
some  ways  and  my  first  functional  at¬ 
tempt  at  a  “better  systems”  language  is 
an  extended  Pascal  Compiler,  that  I  call 
“ASP:  Advanced  Systems  Pascal.”  ASP 
went  a  good  way  toward  proving  a  rea¬ 
sonable  alternative  to  assembler,  yet  it 
was  too  awkward  and  ill-defined  to  be 
really  viable.  It  continues  to  be  used;  and 
when  extended  to  be  full  ISO  Pascal  will 
again  become  a  really  useful  tool. 

In  the  meantime,  my  explorations 
discovered  “C”  and  its  predecessor  “B” 
and  “BCPL,”  languages  with  the  orienta¬ 
tion  of  good  programming  practice  but 
hewn  in  the  hot  fires  of  real  systems  pro¬ 
gramming.  C  is  exceptionally  effective  in 
allowing  an  experienced  programmer  to 
express  the  actions  required  in  a  form 
that  lets  the  compiler  generate  highly  ef¬ 
ficient  code  without  complex  optimiza¬ 
tion.  My  favorite  examples  are:  “++X 
and  X  +  3”,  so  much  easier  than  trying  to 
optimize  “X  :=X  +  3”. 

Enough  prologue  -  onto  the  meat 
of  the  story.  I  had  been  playing  with  an 
experimental  “C”  compiler  when  Ron 
Cain’s  “Small-C”  was  printed  in  Dr. 
Dobb’s  issue  #48.  Glory  Day  —  a  much 
easier  path  presented  itself.  My  progress 
was  soon  dashed  as  I  found  the  BDS  C 
compiler  I’d  been  using  could  neither 
compile  the  whole  source  till  I’d  frag¬ 
mented  it,  nor  link  the  total  result  when 


by  Richard  Roth 


Richard  Roth,  c/o  InfoSoft  Systems,  25 
Sylvan  Road  South,  Westport,  CT  06880. 
Copyright  ©  1981  by  Richard  Roth.  All 
Rights  Reserved. 


done.  Back  to  the  drawing  board—  to 
form  the  gem  of  a  new  approach.  By 
using  the  structure  of  Small-C,  I  divided 
the  compiler  into  the  basic  elements  of 
operation: 

Pass  1  -  Lexical  analysis  and  token- 
izing 

Pass  2  —  Syntax  analysis 

Pass  3  —  Code  generation 

Pass  1  -  Preprocessor  and  Lexical 

The  preprocessor  and  a  tokenizer  be¬ 
come  the  first  pass.  First,  the  preproces¬ 
sor  is  invoked  and  macro  substitution 
takes  place.  Keywords  and  operators  are 
recognized  and  coded  as  a  single  byte. 
Numeric  and  character  constants  are 
coded  as  16-bit  words.  String  literals  and 
identifier  names  are  stored  in  the  literal 
pool  and  name  table,  respectively,  and  re¬ 
placed  with  the  resulting  table  offset. 

The  majority  of  the  functions  came 
directly  from  Small-C  with  the  appropri¬ 
ate  output  actions  added.  Later  on, 
additions  were  made:  conditional  com¬ 
pilations  using  “#ifdef”  and,  “#ifndef”, 
“#else”  and  “#endif”;  macro  deletion 
using  “#undef”,  B-tree  logic  for  the 
macro  and  name  tables;  binary  search  on 
keywords  and  other  optimizations. 

The  result  of  pass  1  is  three  tables  in 
memory:  token  list,  literal  pool,  name 
table.  The  macro  table  is  built  as  needed 
and  then  discarded  at  the  end  of  pass  1. 
The  in- memory  storage  may  seem  limit¬ 
ing,  however  all  modules  in  the  over 
25 6K  bytes  of  final  source  can  be  com¬ 
piled  in  a  48K  machine,  in  12  separate 
pieces;  and  the  speed  advantage  is  tremen¬ 
dous. 


Pass  2  —  Syntax 

The  second  step  in  processing  a  C 
program  is  syntax  analysis,  or  parsing. 
Again  the  functions  from  Small-C  were 
used  as  the  starting  point,  especially 
“newfunc”,  “declvar”,  “statement”  and 
the  expression  evaluator  sequence  of 
“heir”  modules. 

All  logic  relating  to  language  testing 
was  changed  to  reflect  the  token  codes 
being  processed,  rather  than  raw  source; 
for  example  “(match(“if”)==0)”  became 
“(toknis(KIF))”  where  “KIF”  is  a 
“#define”  of  the  value  of  the  token  for 
the  keyword  “if”. 

Similarly  all  keywords  and  operators 


were  tested  appropriately.  Symbol 
processing  uses  a  symbol  table  structure 
similar  to  Small-C,  but  now  the  name 
entry  is  only  a  pointer  to  the  name  table 
and  all  searches  need  only  compare  a  2- 
byte  address.  The  symbol  table  was  also 
extended  to  include  an  element  size  for 
structure  (“struct”)  data.  The  original 
entries  have  had  new  values  added  to 
allow  for  structure  definition,  and  ex¬ 
tended  the  storage  modes  of  static,  para¬ 
meter,  initialized  and  structure  member. 

As  the  compiler  developed,  I  extend¬ 
ed  the  features  available  to  include  most 
of  the  full  C  statement  syntax.  State¬ 
ments  “do”,  “for”,  “switch”,  and  “case” 
were  fairly  simple  to  add  once  the  gene¬ 
rated  code  was  defined  and  the  parse  syn¬ 
tax  was  understood.  Similarly  many  of 
the  missing  operators  were  added,  such  as 

“+=”,  “  +  +”  and  “ — 

Not  quite  so  simple  was  the  addition 
of  more  extensive  data  structures: 
“static”,  “extern”  and  “struct”.  The  stat¬ 
ic  and  external  data  types  fell  into  place 
by  adding  parameters  to  the  “declvar” 
function.  Adding  “struct”  required  exten¬ 
sive  changes  to  “parse”,  “newfunc”  and 
“declvar”  by  adding  a  new  “declstruc” 
function;  which  in  turn  calls  “defstruc”, 
and  “vardetail”.  Much  of  the  complexity 
is  because  structures  may  be  within  struc¬ 
tures,  and  so  the  logic  must  be  recursive. 
A  “struct”  declaration  can  be  either  a 
form  description,  giving  the  structure 
shape  a  name;  or  a  data  declaration,  ac¬ 
tually  declaring  some  variables;  or  both. 
A  structure  consists  of  a  named  shape  of 
a  specific  size,  plus  members  who  have  no 
storage  but  an  offset  from  the  start  of  the 
structure.  The  operators  “.”  and  “— >” 
had  to  be  added  and  pointer/array  arith¬ 
metic  had  to  be  expanded  to  account  for 
structure  element  size. 

Another  area  which  required  exten¬ 
sive  work  was  function  parameter  han¬ 
dling  and  local  stack  maintenance.  Small- 
C  uses  an  ingeniously  efficient  use  of  the 
8080/Z80  hardware  stack  pointer  for 
local  variables;  however  the  design  limit¬ 
ed  the  lovely  feature  that  C  allows,  a 
variable  number  of  parameters  in  a  func¬ 
tion.  Small-C  did  not  allow  this,  due  to 
the  order  of  parameters  on  the  stack  and 
the  reference  of  all  local  variables  via  the 
stack  pointer.  If  a  function  was  called 
with  two  parameters  then  the  first  might 
be  “SP-6”;  while  if  it  was  called  with 
three  parameters  then  the  first  would  be 


46 

504 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


Added  from  Original  Small -C 


Initializers 


Structures 


++, — , += , -= 


for,  do,  switch,  case,  default 

Variable  number  of  parameters 

Direct  relocatable  output 

#ifdef  /  fifndef  /  ielse  /  #endif/#undef 


extern,  static,  struct 
and  " . "  operators 

Command  line  controllable  compiler  table  sizes 
Auto  chaining  between  passes 

"1"  Boolean  not  &  Logical  not  operators 
Missing  from  small-C  plus 


goto  /  label 

"II"  /  "&&"  /  "?:" 


structured  Arithemtic  (other  then  int  and  char) 
( PTR+PTR  (vs)  PTR+INT) 


Library  functions 


Can't  initialize  structures  except  using  int  pointers 
Limitation  of  order  of  parameters  declarations 
Type  cast 


strlen,  strmv,  strnew,  streq,  strcmp 


Initializer:  cinit 


Bit  fields 


Register,  Explicit  automatic 

&=, !=,/=,*=,%=,>>=,<<=,*= 


Standard  files:  copen,  cclose. 


cgetc,  cputc,  cread,  cwrite, 
cexit,  ceof, 


getchar,  putchar,  gets,  puts 


union,  short,  unsigned 
long,  float,  double 


♦  if,  #line 


Formatted  I/O:  Printf 

Memory  allocation:  memptr,  alloc 

Chaining:  cchain 


Macro  with  Parameters 


Fortran/ASM  Linkage  without  special  ccent/ccret  use 
♦Include  "<name>"  (Master  disk  search) 


call  (ASM  module  call), 
ccdos  ( I /OS  &  CPM  call). 


21K  Source 


55K  Source 


Pass  3  -  27K  Source 


inp/outp  (direct  device  I/O), 

atoi  /  xtoi  /  itod  /  itox  ( ASCI I -DEC/HEX  conversions) 


ROOT  MODULE 


ccmark,  ccical,  ccent,  ccret,  ccdosw  (switch) 
celt,  ccgt,  ccge,  ccge,  ccle 


UNSIGNED:  ccult,  ccugt,  ccuge,  ccuge,  ccule 


Root  Code  16K 
Additional  functions  21K 


~500  Bytes 

8K  If  fully  loaded 


MISC:  cceq,  ccne,  ccmult,  ccdiv,  ccmod ,  ccand ,  ccor,  eexor, 

ccneg ,  cccom 

OPERATORS:  ccsub,  ccnot,  ccasl,  ccasr ,  ccmktf 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


47 

505 


“SP-8”.  There  is  no  way  the  compiler  can 
adjust  for  this  at  compile  time.  A  related 
problem  was  some  very  messy  code  for 
allocating  local  variables,  and  clearing 
local  variables  and  parameters. 

All  these  probelms  were  resolved  by 
introducing  a  variable  storage  mode  of 
“parameter”  which  is  a  reference  off  the 
“BC”  register  pair,  rather  than  the  stack 
pointer.  The  “BC”  register  is  maintained 
by  using  entry  (“ccent”)  and  exit 
(“ccret”)  routines,  which  also  handle 
clearing  local  variables  and  parameters 
with  a  simple  stack  load  using  the 
“SPHL”  instruction. 

Various  other  changes  were  installed 
to  complete  and  optimize  the  language 
accepted;  the  syntax  is  now  close  to  true 
C.  One  limitation  is  that  fixed  by  P.  L. 
Woods  in  February  1981  Dr.  Dobb's: 
“Required  Parameter  Order.”  This  has 
not  yet  been  fixed.  (A  note:  the  logic 
used  by  Mr.  Woods  looks  good  except  for 
its  failure  to  support  C  implied  “int” 
declaration  of  parameters  not  otherwise 
declared.) 

The  full  syntax  of  extended  variable 
declarations  has  not  been  added  so  the 
classic,  a  pointer  to  a  pointer  to  a  char 
“**CP”,  must  be  handled  using  an  as¬ 
signment  to  a  character  pointer  such  as 
“*(CP  =  *1P)”.  Static  or  global  data  ini¬ 
tializers  have  just  been  added,  allowing 
for  the  declaration  of  tables  of  functions 
or  strings. 


Pass  3  -  Code  Generation 

As  the  new  compiler  became  func¬ 
tional,  code  generation  was  removed  from 
pass  2  and  made  a  separate  pass;  pass  2 
outputs  code  operations  that  the  code 
generator  expands.  My  tool  kit  includes 
our  own  relocatable  assembler,  linker  and 
symbolic  debugger,  so  it  was  essential  to 
have  compatible  formats. 

Initially  the  output  was  assembler 
code,  but  as  I  learned  with  my  ASP  com¬ 
piler,  using  an  assembler  to  save  work  for 
the  compiler  writer  may  work  for  a  mini¬ 
computer  with  hard  disk;  but  a  micro 
with  floppies  is  just  too  limited  for  this 
technique  to  be  practical.  Then  a  revised 
pass  3  (called  4)  was  made  which  is  it¬ 
self  a  2-pass  assembler,  but  relieved  of 
the  tasks  of  symbol  processing  and  op¬ 
code  mnemonics.  Pass  4  first  scans  the 
code-ops  file  to  determine  the  addresses 


Small  C  GrOWS  Up  (Text  begins  on  page  46) 

Listing  I 

B . pnum 

btree  .c 

1  (  0) 

/*  binary  tree  search  logic  -  test  */ 

2  (  0) 

3  (  0) 

/*  based  on  Wirth's  A+DS  =  P  */ 

4  (  0) 

/*  Search  on  pg  205  */ 

5  (  0) 

/*  Delete  on  pg  211  */ 

6  (  0) 

7  (  0) 

♦define  tree  rt  size  6 

8  (  0) 

9  (  0) 

struct 

10  (  0) 

tree  root  { 

11  (  1) 

int  ‘tree  ptr;  /*  strart  of  tree  */ 

12  (  1) 

int  ‘tree  len;  /*  size  of  tree  element  */ 

13  (  1) 

int  ‘tree  alloc;/*  memory  alloc  func  for  tree  */ 

14  (  1) 

)  ; 

-  function  p  - 

15  (  0) 

16  (  0) 

struct 

17  (  0) 

tree  element 

18  (  0) 

i 

19  (  1) 

char  *tkey;  /*  key  pointer  */ 

20  (  1) 

int  ‘tleft,  /*  left  branch  */ 

21  (  1) 

‘tright;  /*  right  branch  */ 

22  (  1) 

/*  user  area  goes  after  here  */ 

23  (  1) 

int  tcount;  /*  just  count  hits  */ 

24  (  1) 

)  : 

-  function  1  - 

25  (  0) 

♦define  tree  el  size  8 

26  (  0) 

27  (  0) 

getline( line) 

28  (  0) 

char  ‘line; 

29  (  0) 

i 

30  (  1) 

line[0]  =  8yf; 

31  (  1) 

ccdos (  10 ,  line) ; 

32  (  1) 

ccdos(  2,  10);  /*  add  If  after  input  line  */ 

33  (  1) 

return  line+2; 

34  (  1) 

i 

-  function  2  - 

35  (  0) 

36  (  0) 

tallor(size)  /*  do  tree  space  allocate  */ 

37  (  0) 

int  size; 

38  (  0) 

{  return  alloc (size);  } 

-  function  3  - 

39  (  0) 

40  (  0) 

int  ‘troot, 

41  (  0) 

*el ; 

42  (  0) 

43  (  0) 

char  inline  [82], 

44  (  0) 

status ; 

45  (  0) 

46  (  0) 

47  (  0) 

main( ) 

48  (  0) 

i 

49  (  1) 

troot  *  tinit(tree  el  size,  tailor); 

50  (  1) 

pr int f( "tree  root  at:  %04x\n",  troot); 

51  (  1) 

52  (  1) 

wh  i  1  e  ( 1  ) 

53  (  1) 

i 

54  (  2) 

prt  tree (  troot  ->  tree  ptr); 

55  (  2) 

56  (  2) 

pr int f ( "Next  >  >  ") ; 

57  (  2) 

getline( inline) ; 

58  (  2) 

if(  inline[l]  ==  0)  break; 

59  (  2) 

60  (  2) 

el  *  tsearcM  inline+2,  troot,  ^status); 

61  (  2) 

printf( "Search  rtns:  ptr*  %04x,  status*  %2x\n". 

62  (  2) 

el ,  status ) ; 

63  (  2) 

switch( status ) 

64  (  2) 

( 

65  (  3) 

case  0;  ♦+  el  ->  tcount  ;  break; 

66  (  3) 

case  1:  el  ->  tcount  *  fr,  break; 

67  (  3) 

case  2:  printf("“  Out  of  room  “\n");  break; 

68  (  3) 

i 

69  (  2) 

i 

70  (  1) 

71  (  1) 

prt  tree(  troot  ->  tree  ptr); 

72  (  1) 

) 

-  function  4  - 

73  (  0) 

74  (  0) 

75  (  0) 

prt  tree(tree) 

76  (  0) 

int  ‘tree; 

77  (  0) 

i 

78  (  1) 

char  *pl,  *p2; 

79  (  1  ) 

80  (  1) 

pr int f( "Node :  %$4x  [%^4x  << — >>%^4x]\n". 

81  (  1) 

tree , 

82  (  1) 

pi  =  tree  ->  tleft, 

83  (  1) 

p2  *  tree  ->  tright  )  ; 

84  (  1) 

48 

506 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


85  (  1  ) 

86  (  1) 

87  (  1) 

88  (  1) 

89  (  1) 

90  (  1) 

91  (  1) 

92  (  1) 

93  (  1) 

94  (  1) 

95  (  1) 

96  (  1) 


97  (  0): 

98  (  0): 


if(  pi  1=  fi)  prt_tree( pi ) ;  /*  left  */ 

else  printf ("No  left  fork  at  %/4x\n" ,  tree); 

if  (tree  ->  tkey  1=  /) 

printf( "Value  at  %$4x  is  [%s]  for  %d  times\n" , 
tree , 

tree->tkey, 
tree->tcount  ); 

if(  p2  1=  $)  prt_tree ( p2 ) ;  /*  right  */ 

else  printf  ( "No  right  fork  at  %ff4x\n"  ,  tree); 

function  5  - 


Number  of  functions= 
B. 


End  Listing 


Listing  II 


pnum  btr 


1  ( 

oT 

binary  tree  search  logic 

2  ( 

0) 

3  ( 

0) 

/* 

based  on 

Mirth's  A+DS  =  P 

4  ( 

0) 

/* 

Search 

on  pg  205 

5  ( 

0) 

/* 

Delete 

on  pg  211 

6  ( 

0) 

7  ( 

0) 

♦define  tree 

_root_size  6 

8  ( 

0) 

9  ( 

0) 

struct 

10  ( 

0) 

tree 

{ 

11  ( 

1) 

int  *tree_ptr; 

12  ( 

1) 

int  ‘tree  len; 

13  ( 

1) 

int  ‘tree  alloc; 

14  < 

1) 

)  ; 

42 

43 

44 


15  (  0) 

16  (  0) 

17  (  0) 

18  (  0) 

19  (  1) 

20  (  1) 
21  (  1) 
22  (  1) 

23  (  1) 

24  (  0) 

(  0) 
(  0) 
(  0) 
(  0) 


-  function  0 
struct 


tree  element 


25 

26 

27 

28 

29  (  0): 

30  (  0): 

( 

( 


33  ( 


0) 

0) 

0) 


char  *tkey;  /*  key  pointer 

int  ‘tleft,  /*  left  branch 

‘tright;  /*  right  branch 

/*  user  area  goes  after  here 

}  ; 

-  function  1  - 

/*  EXTERNALLY  USED  FUNCTIONS 

/*  tinit(  tlen,  talloc)  -  Build  tree  root  initially 

/*  int  tlen;  -  length  of  a  tree  node 

/*  tree_el_size  +  user  needs 

/*  int  * ( *tal loc ( ) ) ;  -  ptr  to  alloc  function 
/*  for  tree  allocated  region 


34  (  0):  /*  tsearch( key ,  tree,  insert)  -  SEARCH  function 


0): 


35  ( 

36  (  0) 

37 

38 

39  (  0) 
(  0) 


(  0): 
(  0): 


40 

41  ( 


0) 

(  0) 
(  0) 
(  0) 


/*  char  ‘key;  -  ptr  to  search  string 

/*  int  ‘tree;-  ptr  to  tree  root,  setup  by  tinit 

/*  char  ‘insert;-  otr  to  a  variable  or  $ 

/*  if  insert  !=  (i.e.,  a  variable  address  (&var) 

/*  then  if  the  search  fails 

/*  then  a  new  entry  is  made  and  ‘insert  =  1 

/*  else  no  entry  is  made  and  ‘insert  =  $> 


45 

0): 

/*  if 

tree  alloc  function  returns  $  (no  more  room) 

46 

0): 

/* 

then  insert  fails  and  ‘insert  =  2; 

47 

0): 

48 

0): 

/* 

*/ 

49 

(  0) 

/* 

initialize  tree  root  with  sentinal 

entry 

50 

(  0) 

tinit 

(  tlen,  talloc) 

51 

(  0) 

int 

tlen,  ‘talloc; 

52 

(  0) 

{ 

53 

(  1) 

int  ‘tree,  *p; 

54 

(  1) 

tree  =  (‘talloc)  (tree  root  size 

55 

(  1) 

56 

(  1) 

/*  init  sentinal  entry  */ 

57 

1) 

tree  ->  tree  ptr  =  p  =  (‘talloc) 

(tlen)  ; 

58 

1) 

p  ->  tright  = 

59 

1) 

p  ->  tlef t  =  ; 

60 

1) 

61 

1) 

tree  ->  tree  len  =  tlen  ; 

62 

1) 

tree  ->  tree  alloc  =  talloc  ; 

63 

1) 

return  tree; 

64 

1) 

) 

-  function  2  - 

65  (  0): 

66  (  0):  /*  compare  strings  for  equality  or  direction  of  1= 

67  (  0): 

68  (  0):  tcomp  (  si,  s2) 

69  (  0):  char  *sl,  *s2; 


of  all  internal  labels  and  function  entry 
points,  and  then  outputs  relocatable  ob¬ 
ject  code,  with  a  symbol  table.  For  sym¬ 
bolic  debugging,  special  line  number 
labels  are  included  to  give  the  start  of 
each  line  of  the  source. 


The  Library 

The  final  and  perhaps  most  complex 
part  of  any  language  processor  is  the  run¬ 
time  library.  For  an  8080/Z80,  this  in¬ 
cludes  basic  16-bit  math  as  well  as  more 
extended  I/O  functions.  In  addition,  the 
“CCLIB”  includes  the  low-level  routines 
for  module  entry/exit  and  “switch;”  the 
initializing  routines  for  the  command  line 
parameters  and  disk  I/O;  and  such  high- 
level  functions  as  “printf”  and  “quick 
sort”.  I’ve  implemented  the  “portable 
C  library”  from  an  article  by  M.  E.  Lesk 
of  Bell  Labs. 


The  Result 

The  result  has  been  a  very  powerful 
programming  tool.  Not  only  is  C  a  stan¬ 
dard  language,  it  is  fast  becoming  the  best 
and  most  available  language  for  systems 
programming.  Make  no  mistake  about  it, 
C  is  not  for  beginners  or  applications  pro¬ 
grammers,  but  for  systems  work  it  is  fan¬ 
tastic.  I’ve  now  used  the  compiler  for 
some  commercial  work,  and  many  in- 
house  projects  and  am  very  pleased  with 
both  the  productivity  of  the  C  language 
and  the  speed  and  efficiency  of  the  Info- 
Soft  C  compiler. 

The  InfoSoft  C  compiler  is  available 
(to  Dr.  Dobb’s  readers)  in  two  forms:  A 
runable  version  for  $50.00  in  conjunction 
with  our  “SAL  structured  assembler” 
development  tool  kit  (list  price  $225.00). 
Or  source  may  be  licensed  for  an  addi¬ 
tional  $250.00  when  the  runable  version 
is  licensed.  The  C  compiler  is  strictly  “as- 
is”  condition,  although  the  “SAL”  pack¬ 
age  is  a  supported  product  and  includes 
the  relocation,  linking  macro  assembler 
with  structured  statements,  the  relocating 
overlay  linker,  and  symbolic  debugger. 
The  package  includes  both  Z80  and  8080 
version.  As  an  example,  I’ve  included  the 
binary-tree  routine  used  in  pass  1  for  the 
name  table  and  macro  table.  See  Listings 
I  &  II  .  »»j 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


51 


Why  wait  to  start  increasing  your 
sales?  Call  now  to  reserve  adver¬ 
tising  space  in  the  next  Dr. 
Dobb ’s  Journal  -(415)  323-31 1 1 . 


Small  C  Grows  Up 

(Listing  continued,  text  begins  on  page  46) 


101 

102 

103 


/*  allocate  and  assign  a  new  sting  key  for  entry  of  a  new  node 


/*  the  allocate  space  function  */ 


70 

0): 

l 

71 

1): 

int  c; 

72 

1): 

wh  i  1  e  (  * 

73 

1): 

i 

74 

1): 

75 

1): 

return  - 

76 

1): 

i 

77 

0) 

78 

(  0) 

79 

I  0) 

/*  allocate  and 

80 

:  0) 

81 

0) 

tsnew  (  key,  ta 

82 

0) 

char  *key;  / 

83 

:  o) 

int  *talloc; 

84 

0) 

i 

85 

:  i) 

int  cnt; 

86 

:  i) 

char  *pl. 

87 

:  i) 

88 

i) 

/ 

89 

i) 

pi  =  key; 

90 

i) 

wh  i  1  e  (  *  p 

91 

i) 

92 

i) 

p2  =  pi  = 

93 

i) 

if  (pi  == 

94 

i) 

r 

95 

i) 

while  (  * 

96 

i) 

97 

i  > 

return  p2 

98 

i) 

i 

, 

99 

(  0) 

/* 

100 

0) 

return  c; 


»-*) 

si  <  s2 


/*  fails  -  no  room  left  */ 


(  0) 
(  0) 
(  0) 


131 

132 

133 

134 

135 

136 

137 

138 

139 

140 

141 

142 

143 

144 

145 

146 

147 

148 

149 

150 

151 

152 


(  1) 

(  1) 

(  1) 

(  2) 

(  2) 

(  2) 

(  2) 

(  2) 

(  2) 

(  2) 

(  3) 

(  3) 

(  3) 

(  3) 

(  3) 

(  3) 

(  3) 

(  2): 

(  1) 

(  1) 

(  1) 

(  1) 


V 


/*  tree  search  function  proper 


104 

0) 

tsearch  (key 

tree,  insert) 

105 

0) 

char  *key 

/*  key  to  find  */ 

106 

0) 

int  *tree; 

/*  root  of  tree 

107 

0) 

char  •insert; 

/*  /  or  fcvar 

for  insert  status  */ 

108 

0) 

i 

109 

1) 

char  *pl,  *p2; 

no 

1) 

int  dir,  compv. 

•talloc; 

111 

1) 

112 

1) 

talloc 

■  tree  -> 

tree_alloc; 

113 

1) 

P2 

*  tree  -> 

tree  ptr; 

/*  root  of  tree  */ 

114 

1) 

Pi 

-  p2  -> 

tright ; 

/*  init  for  search 

115 

1) 

dir 

=  1; 

116 

1) 

117 

1) 

/*  search  the  tree  */ 

118 

1) 

while 

Pi  /) 

119 

1) 

! 

120 

2) 

p2  -  pl; 

121 

2) 

if  (  (compv  *  tcomp(key,  pl  ->  tkey) )  ) 

122 

2) 

{  pl  =  pl  -> 

tleft;  dir  =  -1;  ) 

123 

2) 

else 

124 

2) 

i  f  ( compv  >  f> ) 

125 

2) 

I  pl  *  pl  -> 

tright;  dir  *  1;  ) 

126 

2) 

el  se 

127 

2) 

(  dir  * 

break;  } 

128 

2) 

i 

129 

1) 

130 

1) 

/*  insert  if  rec 

uired  */ 

if  (dir) 

( 

if(  (pi 


(•talloc)  (tree  ->  tree_len))  =»  gf) 
•insert  »  2;  /*  no  room  for  new  node  •/ 

else 

if(  (pi  ->tkey  =  tsnew(keyf  talloc))  =*  /) 

•insert  *  2;  /*  no  room  for  key 


el  se 


/ 


{  /*  build  new  node 

•insert  *  1; 
pi  ->  tleft  * 

pi  ->  tright  *  flJ; 

/*  link  to  last  entry 
if(dir  <$)  p2  ->  tleft  =  pi; 

else  p2  ->  tright  =  pi; 


V 


else  *insert  =  i> :  /*  insert  requested  by  not  needed 


return  pi; 

} 

function  5  - 


/*  return  entry  found 


V 


Number  of  functions= 

B. 


50 

508 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


Letters 

(Continued  from  page  4) 

only  inside  function  definitions.  The 
specific  modifications  are 

a)  make  litabsz  smaller  (say  200  in¬ 
stead  of  2000) 

b)  delete  the  line 
dumplitsQ; 
from  main() 

c)  just  before  the  end  of  newfuncQ 
(after  locptr=startloc;),  add  the 
following: 

dumplitsO;  /*dump  the  literal 
pool  for  the  func¬ 
tion*/ 

/•now  re-initialize 
the  pool*/ 
litlab  =  getlabel( ); 
litptr=0 

1  added  the  hooks  for  doing  dynamic 
memory  allocation  and  recovery.  In 
trailerQ  I  added  one  statement  before 
ol('END’);  it  is 

if  (glbflag)  ol(“ENDDATA  EQU  $”); 
This  gives  me  a  value  for  the  end  of  pre¬ 
allocated  memory  (note:  the  test  is  to 
keep  from  generating  duplicate  constants 
when  compiling  modules  separately. 
However,  this  works  only  if  globals  are 
defined  in  one  module  and  it  is  the  last 
one  assembled).  Since  the  Small-c  stack 
grows  from  high  memory  down,  the  area 
between  the  stack  and  preallocated  mem¬ 
ory  is  available  as  a  heap.  So,  I  wrote  two 
storage  management  routines  which  mani¬ 
pulate  the  heap  like  a  second  stack  which 
grows  towards  high  memory, 
alloc  (b) 
int  b  ; 

[  /*allocate  a  block  of  memory  from 
the  heap  and 

*return  the  lowest  address  of  the 
block.  DO 

*NOT  check  for  collision  with  the 
stack 

*1 


#asm 

POP 

H 

;return  address 

POP 

D 

;block  size 

PUSH 

D 

PUSH 

H 

LHLD 

HEAPTOP 

;address  of  cur¬ 

XCHG 

DAD 

D 

rent  top  of  heap 

;HL<-new  top 

SHLD 

HEAPTOP 

of  heap 

XCHG 

;HL<-old  top 

of  heap 

RET 

HEAPTOP  DWENDDATA 
#endasm 

] 

To  allocate  a  block  of  memory  simply 
call  alloc  with  the  number  of  bytes  need¬ 
ed  and  assign  the  result  to  a  pointer.  In¬ 
dividual  bytes  (words)  can  be  indexed  off 
the  pointer.  The  complementary  routine 
to  return  the  block  (and  all  memory  a- 
bove  it)  is 
free(addr) 
int  addr; 

[  /*reset  the  top  of  heap  pointer  to 
addr*/ 

#asm 

POP  D  ;return  address 

POP  H  ;addr 

PUSH  H 

PUSH  D 

SHLD  HEAPTOP 

#endasm 

] 

I  hope  these  modifications  prove  use¬ 
ful. 

Sincerely  yours, 

Rodney  Black 
39  Elbow  Hill  Road 
Brookfield,  CT  06804 

Think  Smart 

Dear  Compupholk, 

I  am  currently  a  subscriber. 

I  won  a  TRS-80  16K  Ext.  B.  Color. 
I  would  like  software  that  will  make  it 
a  smart  terminal  and  not  the  dumb  one 
that  Radio  Shack  has  done  with  Compu¬ 
Serve  Software. 

I  would  like  to  be  able  to  dump  the 
retrieved  information  into  the  cassette 
and  printer. 

Hope  you  can  help. 

John  Reid 

40-15  61st  Street  Apt  3-H 
Woodside,  NY  11377 

Remember  the  old  saw  "I  paint  what 
I  see”?  Well,  DDJ  publishes  what  it  re¬ 
ceives.  We  would  be  delighted  to  publish 
articles  on  the  Color  Computer  and  16K 
Extended  BASIC,  if  someone  would  send 
us  some  -  including  smart  terminal  pro¬ 
grams  for  all  of  the  Radio  Shack  (or 
other)  mass- market  computers.  How 
' bout  it,  folks ?  A  program  with  simple 
user  instructions  and  notes  on  special  fea¬ 
tures?  You  send  the  software,  and  we’ll 
provide  the  telephone  numbers  of  CBBS’s 
around  the  country  which  you  can  ac¬ 
cess  .  .  . 


Unuecsttv 

MictWims 


This  publication 
is  available 
in  microform. 


University  Microfilms 
International 


Please  send  additional  information 
for _ 

Name _ 


Institution  . 

Street _ 

City _ 


State  _ 


300  North  Zeeb  Road  30-32  Mortimer  Street 
Dept.  PR.  Dept.  PR. 

Ann  Arbor.  Mi.  48106  London  WIN  7RA 
U.SA.  England 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


51 

509 


Essay  on  Hacking 

by  Gandalf 


They  were  among  the  brightest 
computer-science  students  at  Stan¬ 
ford.  They  spent  their  days  and 
nights  in  the  concrete-and-glass  comput¬ 
er  center  playing  harmless  games  and 
modi -vicious  “wheel  wars ”  on  the  termi¬ 
nals.  Then,  one  night,  a  hacker  (computer 
addict)  whose  code  name  was  Gandalf 
sat  down  and  tapped  out  a  cri  de  coeur: 
in  their  single-mindedness,  he  and  his  fel¬ 
low  hackers  were  losing  touch  with  the 
human  race.  Quickly  the  issue  was  joined. 
The  complete  printout  follows.  (For  a 
glossary  of  hacker  terminology,  turn  to 
page  5  7.) 

Stanford  University 

Low  Overhead  Time-Sharing  System 

(LOTS) 

From:  G.  Gandalf 
To:  Bulletin  Board 
Subject:  Essays  on  Hacking 

Dedicated  to  all  my  firends  at  LOTS 
who  will  live  their  lives  in  an  alien  culture 
surrounded  by  humanity,  and  to  Ernest, 
who  was  too  human  for  it. 

As  much  as  an  essay,  this  is  a  story. 
It  is  a  true  story  of  people  paying  $9,000 
a  year  to  lose  elements  of  their  humanity. 
It  is  a  story  of  both  seen  and  unseen 
games.  It  is  a  story  of  the  breaking  of 
wills  and  of  people.  It  is  a  story  of  addic¬ 
tions,  and  of  misplaced  values.  In  a  large 
part,  it  is  my  story. 

There  is  no  one  field  in  particular  in 
academia  that  has  a  monopoly  on  produc¬ 
tion  of  single-interest  people,  and  this 
practice  can  exist  almost  anywhere.  There 
is  the  policital-power  seeker,  all-consumed 
by  climbing  up  the  bureaucratic  rungs. 
There  is  the  stereotyped  premed,  ignoring 
all  but  his  MCAT  scores.  There  is  the 
compulsive  artist  or  writer,  forever  lost  in 
his  work.  Narrowness  is  widespread.  But 
there  is  one  field  that  seems  to  be  more 
consistent  in  this  practice.  This  essay, 
rooted  in  personal  and  painful  experi¬ 
ence,  is  about  the  people  in  computer 
science. 

In  the  middle  of  Stanford  University 
there  is  a  large  concrete-and-glass  building 
filled  with  computer  terminals.  When  one 
enters  this  buiding  through  the  glass 
doors,  one  steps  into  a  different  culture. 
Fifty  people  stare  at  terminal  screens. 
Fifty  faces  connected  to  50  bodies,  con¬ 
nected  to  50  sets  of  fingers  that  pound  on 

Reprinted  from  Psychology  Today  maga¬ 
zine.  Copyright  1980,  Ziff-Davis  Publish¬ 
ing  Co. 


50  keyboards  ultimately  linked  to  a  com¬ 
puter.  If  you  go  farther  inside,  you  can 
discover  the  true  addicts:  the  members 
of  the  Establishment.  These  are  the  peo¬ 
ple  who  spend  their  lives  with  computers 
and  fellow  “hackers.”  These  are  the  mem¬ 
bers  of  a  subculture  so  foreign  to  most 
outsiders  that  it  not  only  walls  itself  off 
but  is  walled  off,  in  turn,  by  those  who 
cannot  understand  it.  The  wall  is  built 
from  both  sides  at  once. 

These  people  deserve  a  description. 
In  very  few  ways  do  they  seem  average. 
First,  they  are  all  bright,  so  bright,  in 
fact,  that  they  experienced  social  prob¬ 
lems  even  before  they  became  interested 
in  computers.  Second,  they  are  self- 
contained.  Their  entire  social  existence 
usually  centers  around  one  another.  Very, 
very  few  remain  close  to  their  families. 
Very  very  few  associate  much  with  any¬ 
one  who  is  not  at  least  partially  a  mem¬ 
ber  of  the  hacking  group.  While  they  do 
sometimes  enjoy  entertainment  unrelated 
to  their  field,  it  is  almost  always  with 
fellow  hackers.  Third,  all  aspects  of  their 
existence  reinforce  one  another.  They  go 
to  school  in  order  to  learn  about  comput¬ 
ers,  they  work  at  jobs  in  programming 
and  computer  maintenance,  and  they  lead 
their  social  lives  with  hackers.  Academ¬ 
ically,  socially,  and  in  the  world  of  cash, 
computers  are  the  focus  of  their  exis¬ 
tence. 

The  hacker  will  probably  not  strong¬ 
ly  disagree  with  what  has  been  said  so  far. 
But  he  will  ask  the  question,  “So  what?” 
The  answer  is:  in  creating  a  subculture 
and  isolating  it,  we  are  destroying  the 
chance  that  computers  might  be  used 
wisely  as  an  integral  part  of  our  society. 
We  are  precluding  the  human  values  so 
necessary  for  the  wise  application  of  this 
technological  achievement.  The  most 
brilliant  young  minds  at  our  top  univer¬ 
sities  are  learning  how  to  play  with 
multimillion -dollar  toys  first,  and  how  to 
utilize  them  constructively  second. 

Even  if  we  ignore  the  costs  to  society 
as  a  whole,  we  have  to  look  at  the  costs 
to  the  people  involved.  The  computer  is  a 
modifier  of  personalities.  It  is  highly  ad¬ 
dictive.  People  who  gain  this  addiction 
for  a  period  of  several  months  tend  never 
to  give  it  up.  And  the  symptoms  are  very 
sad. 

The  first  thing  to  go  is  other  academ¬ 
ic  interests.  Basically  what  occurs  is  that 
the  hackers’  motivation  to  challenge 
themselves  in  any  field  not  directly  linked 
to  computers  gradually  disintegrates.  On 


the  level  of  grades,  straight-A  students 
tacitly  accept  C’s  in  noncomputer  courses. 
On  the  level  of  actual  learning,  the  same 
students  shut  off  outside  subjects  even 
more  completely  than  their  grades  would 
indicate.  This  is  common  in  many  areas  of 
specialization,  but  nothing  compares  with 
the  incredible  consumption  of  computer- 
science  students  for  computer-science 
courses,  and  their  nonchalant  attitude 
toward  every  other  class. 

The  second  thing  to  go  is  a  normal 
living  pattern.  Eating  and  sleeping  are 
completely  rearranged  to  fit  the  addic¬ 
tion.  The  typical  hacker  thinks  nothing  of 
eating  one  meal  a  day  and  subsisting  on 
junk  food,  or  of  sleeping  from  4  a.m.  to 
noon  almost  every  day  of  the  week.  Fam¬ 
ilies  are  soon  disregarded,  to  an  extent 
uncommon  even  when  one  considers  the 
separation  that  generally  occurs  in  col¬ 
lege.  It  is  simply  that  the  parents  of  hack¬ 
ers  are  ignorant  of  the  subculture  and 
cannot  relate. 

The  third  thing  to  go  is  a  balanced 
social  life.  The  hackers’  narrowness  and 
strange  schedule  simply  compound  the 
social  problems  they  experienced  before 
hackerdom.  Soon,  no  one  except  a  hacker 
has  the  capability  to  understand  other 
hackers.  No  one  except  a  hacker  will  go 
out  with  other  hackers.  No  one  except  a 
hacker  can  talk  to  another  hacker. 

The  fourth  and  final  thing  that  hap¬ 
pens  is  also  the  saddest.  The  personality 
of  the  hacker  shifts,  in  order  to  perma¬ 
nently  adjust  to  the  new  social  condi¬ 
tions.  Emotions  always  have  hurt  before, 
so  they  are  effectively  isolated.  Relations 
with  nonhackers  become  strained,  so  why 
force  the  effort?  It  is  so  much  easier  just 
to  accept  social  rejection  and  isolation, 
and  to  do  it  with  a  spirit  of  camaraderie 
that’s  shared  by  the  rest  of  the  subcul¬ 
ture. 

An  essay  should  make  an  attempt  to 
resolve  the  problem  it  points  out.  In  this 
case,  the  pointing  may  be  enough,  or  at 
least  enough  to  do  whatever  can  be  done. 
I  know  from  personal  expereince  what  a 
trauma  it  can  be.  I  was  one  of  the  top  10 
among  several  thousand  LOTS  users  last 
spring  for  the  amount  of  time  I  spent 
here.  I  have  watched  people  close  to  me 
undergo  the  transformation.  I  narrowly 
escaped  it. 

The  tragedy  is  that  I  am  so  involved 
in  piecing  my  personality  and  social  life 
back  together  that  I  think  I  have  learned 
very  little  about  how  to  prevent  this  from 
happening  in  the  first  place.  I  am  lucky. 


52 

510 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


I  will  go  on  to  some  sort  of  a  balanced 
life  (although  my  hacker  friends  will 
laugh  at  me,  since,  to  them,  my  involve¬ 
ment  was  never  serious  enough  to  make 
me  one  of  them).  Weak-willed  people, 
people  with  unstable  social  lives,  people 
in  formative  stages  of  their  lieves,  should 
not  become  involved  in  computer  science. 
It  should  be  left  until  they  are  truly  able 
to  make  decisions  and  be  aware  of  all  the 
consequences.  Computers  are  most  often 
used  by  people  who  start  when  they  are 
immature.  This  is  what  causes  the  single- 
minded  addiction.  This  is  what  takes 
some  of  the  brightest  and  most  capable 
minds  in  college  today  and  turns  them  to 
narrowness. 

From:  E.  Ernest 
To:  G.  Gandalf 

Subject:  Reply  to  “Essay  on  Hacking” 

As  the  human  to  whom  Gandalfs  es¬ 
say  was  in  part  dedicated,  I  feel  I  have  a 
responsibility  to  reply.  Obviously,  his  es¬ 
say  is  going  to  provoke  a  certain  amount 
of  defensiveness  from  the  hackers;  on  the 
other  hand,  he  has  made  a  number  of 
points  which  are  indeed  very  valid. 

I  became  rather  disillusioned  with 
LOTS  last  spring  because  I  found  that  the 
attitudes  of  the  people  whom  I  had  made 
my  friends  were  becoming  more  and 
more  machine-oriented  and  less  and  less 
human-oriented.  I  began  to  spend  less 
time  here,  and  see  the  people  less  often. 
It  was  partly  the  so-called  narrowness  to 
which  Gandalf  referred,  but  it  was  also 
a  simple  lack  of  genuine  human  caring 
on  the  part  of  these  people  that  I  left. 

I’m  not  concerned  about  their  social 
lives:  physics  majors,  premeds,  law  stu¬ 
dents,  the  regulars  at  Aunt  Minnie’s 
church  social  -  all  behave  in  roughly  the 
same  way.  Nor  am  I  concerned  about 
their  grades,  for  the  same  reason  that  I’m 
not  concerned  about  anybody’s  grades, 
including  my  own;  if  they  choose  to  get 
hassled  over  grades,  they’ll  do  so,  and 
they’ll  make  them  if  they  want  them.  I 
AM  concerned  about  the  narrow¬ 
mindedness  that  comes  from  losing  inter¬ 
est  in  such  outside  things  as  the  draft  or 
the  social  sciences,  or  all  the  various  and 
sundry  things  that  Stanford  has  to  offer. 
This  place  should  be  a  broadening  experi¬ 
ence;  to  fail  to  take  advantage  of  that  is  a 
waste  of  $9,000.  Furthermore,  narrow¬ 
mindedness  and  xenophobia  have  started 
more  wars  than  any  other  cause. 

More  than  anything  else,  I’m  con¬ 
cerned  about  the  hacker’s  shortage  of 


respect  for  others  and  a  lack  of  sympathy 
for  their  propblems,  because  he  considers 
the  problem  of  whether  or  not  he  wants  a 
HRROI  or  a  STI  in  a  certain  place  to  be 
more  fun  than  people  are.  (If  I  get  a  lot 
of  mail  telling  me  that  that’s  a  ridiculous 
example  and  no  one  could  possibly  mis¬ 
take  a  HRROI  for  a  STI,  it  will  only 
prove  my  point.)  By  and  large,  the  hack¬ 
ers  are  consultants,  and  as  consultants 
they  owe  it  to  the  users  to  be  patient, 
pleasant,  and,  above  all,  sympathetic.  A 
large  number  of  people  in  introductory 
computer-science  courses  are  not  cut  out 
for  computer  work:  the  thought  pro¬ 
cesses  it  requires  have  long  ago  been 
squashed  by  indoctrination  and  training. 
They  are  confused,  frustrated,  and  upset. 
We  do  the  best  we  can  for  them  by  teach¬ 
ing  them  PASCAL  and  giving  them  an 
interactive  system  with  a  forgiving  exec 
which  holds  their  hands  at  every  turn. 
But  there  is  nothing  like  human  comfort 
to  make  people  feel  better  about  it. 

Gandalfs  problem  was  in  attributing 
these  faults  to  the  computer.  The  ma¬ 
chine  itself  is  not  responsible  for  it:  the 
attitudes  of  the  others  toward  the  ma¬ 
chine  are  to  blame.  After  having  spent  a 
summer  doing  data  processing,  I  know 
that  not  all  computers  have  this  fascina¬ 
tion.  Look  at  J.Q.,  Vic,  Sean,  or  Karl. 
They  don’t  demonstrate  these  attitudes. 
They  know  that,  fascinating  as  it  may  be, 
the  computer  is  a  tool  and  not  a  toy.  The 
fault  lies  in  the  attitude  of  the  individual. 

What  is  to  be  done?  Nothing  is  to  be 
done.  The  hackers  know  who  they  are, 
running  around  and  having  “wheel  wars” 
late  at  night,  yakking  and  yakking  while 
someone  stands  and  waits  for  them  in 
front  of  the  consultant’s  terminal.  We 
may  only  hope  that  they  grow  out  of  it. 
Gandalf  is  wrong.  It  isn’t  a  permanent  al¬ 
teration  in  their  character  —  it  is,  hopeful¬ 
ly,  a  short-lived  immaturity  of  people  on 
their  way  to  becoming  programmers  and 
computer  scientists. 

From:  K.  Kanef 
To:  E.  Ernest 

Subject:  In  Reply  to  Reply  Txt 

In  your  opinion,  the  two  problems 
that  LOTS  hackers  have  developed  are  a 
loss  of  touch  with  their  humanity  and  an 
immature  attitude  about  the  purpose  of 
the  computer.  Until  recently,  1  would 
have  disagreed  with  the  first  assertion. 
I’m  no  longer  so  sure  that  it’s  not  true. 

I  have  even  stronger  feelings  about 
the  other  claim  that  you  make  about 


Dr.  Dobb ’s  readers 
have  been  aiding 
the  growth  and  development 
of  the  micro  field 
for  years. 

If  you  would  like 
to  make  a  contribution, 
contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415) 323-3111 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


53 

511 


hackers:  that  they  have  an  immature  view 
of  the  purpose  of  the  computer.  You  as¬ 
sume  that  childishness  is  a  thing  to  be 
avoided.  You  encourage  people  to  throw 
away  the  things  that  are  so  hard  to  retain 
in  growing  up:  the  sense  of  wonder  in 
new  wonderful  things,  the  ability  to 
PLAY.  When  I  compare  my  attitude  to 
that  of  Vic  and  the  others  you  mention 
as  having  a  more  mature  view  of  the  com¬ 
puting  world,  I  find  that  1  like  mine 
better.  1  don’t  want  to  be  like  them!  I  see 
the  computer  as  a  toy  as  well  as  a  tool. 
And  as  I  pointed  out  to  Gandalf  last 
week,  this  attitude  is  not  limited  to 
hackers.  There  were  many  people  in  my 
dorm  last  year  whose  only  knowledge  of 
computers  was  how  to  play  games  and 
send  mail,  and  they  enjoyed  using  the 
computer  as  much  as  I  did.  I  was  one  of 
the  few  people  in  that  group  who  was  in¬ 
terested  enough  in  the  field  of  computer 
programming  to  also  take  an  intro  course 


in  PASCAL. 

I  hope  that  I  will  always  be  as  fasci¬ 
nated  by  my  work  as  I  am  now.  Unfor¬ 
tunately,  I  know  that  this  is  not  likely  to 
happen;  all  too  often  people  become 
bored  with  their  professions.  You’re  right 
in  saying  that  the  childishness  of  LOTS 
hackers  is  short-lived  —  and  isn’t  it  a 
shame? 


From:  E.  Ernest 
To:  K.  Kanef 

Subject:  The  Computer  As  Toy 

I  am  impressed  by  your  skeptical  in¬ 
telligence,  and  I  appreciate  your  reply.  1 
am  sorry  that  you  became  aware  of  the 
diminution  of  simple  humanitarian  caring 
on  the  part  of  hackers  the  hard  way,  but 
pleased  that  you  know  of  its  existence. 

As  regards  play,  you  present  a  very 
convincing  argument,  but  I  would  like  to 
add  a  qualifier.  To  me,  as  one  matures, 
the  highest  forms  of  play  cease  to  be  con¬ 
sumptive  and  begin  to  be  productive. 
Sure,  we  all  need  to  play,  and  there  is  no¬ 
thing  wrong  with  consumptive  play  in  an 
appropriate  setting  and  appropriate  cir¬ 
cumstances.  Middle-aged  adults  enjoy 
Great  America,  and  this  to  me  seems  to 
be  a  perfectly  healthy  and  appropriate 
form  of  consumptive  play.  Nonetheless,  I 
don’t  believe  it  is  the  highest  form  of  play 
that  they  should  be  capable  of. 

Computer  games  are  tolerable  and 
serve  their  purpose;  even  they  help  to 
acquaint  new  users  with  the  computer 
and  to  show  that  it  is  not  a  thing  to  be 
frightened  of  or  confused  by.  But  pro¬ 
grams  that  type  “You  lose”  when  you 
type  “sigh”  to  the  exec  don’t  serve  any 
productive  purpose  at  all;  they  are  vague¬ 
ly  amusing  and  they  take  up  disk  space, 
and  an  entire  page  for  six  lines  of  code,  at 
that.  Likewise,  the  wheel  war  is  neither 
educational  nor  productive,  it  is  nothing 
more  than  consumptive  play,  and  it  can 
be  annoying. 


From:  M.  MRC 

To:  G.  Gandalf,  E.  Ernest 

Subject:  None  Given 

Most  of  the  behavior  you  describe  is 
more  or  less  typical  of  an  undergraduate- 
aged  person  and  less  typical  of  hackers  as 
they  get  older.  Rather  than  demeaning  it, 
we  should  simply  recognize  it  as  normal 
for  somebody  that  age.  In  a  high  school 
kid,  it  is  acutally  a  sign  of  maturity  to  be 


at  that  stage  so  quickly.  In  a  graduate 
student,  it’s  regressive. 

Don’t  be  misled  by  those  who  postu¬ 
late  the  “compulsive”  (and  hence  para¬ 
sitic)  programmer  versus  the  “profession¬ 
al”  programmer  —  I  know  of  no  program¬ 
mer  who  does  not  consider  the  computer 
as  a  toy  first.  You  really  do  have  to  en¬ 
joy  this  work  to  be  good  at  it.  I  know  of 
no  hacker  who  does  not  consider  the 
computer  as  a  toy  first.  What  changes  are 
the  ways  that  s/he  plays  with  the  toy. 
There  isn’t  all  that  much  difference,  in 
terms  of  the  pleasure  derived,  between 
writing  a  new  display  hack  or  a  clever 
access- control  program,  except  that  the 
former  is  something  derided  as  being 
“hacking”  and  the  latter  is  “responsible 
programming.” 

I  guess  my  point  is  that  it’s  all  a  part 
of  the  irresponsibility  that  college  under¬ 
graduates  normally  have,  and  it  shouldn’t 
be  begrudged  them;  it’s  the  last  chance 
they  are  ever  going  to  have  to  be  that  free. 


From:  A.  Anonymous 
To:  E.  Ernest,  K.  Kanef 
CC:  G.  Gandalf 

Subject:  The  Hacker  Chronicles 

We  are  dealing  with  an  infintely 
malleable  tool.  People  who  choose  to  de¬ 
velop  and  use  that  tool,  whether  for 
work,  play,  or  both,  have  that  choice  and 
cannot  be  denied  it.  A  person  who 
chooses  to  be  a  musician  must  devote 
hours  and  hours  to  gain  adequate  exper¬ 
tise.  But  would  you  consider  the  comput¬ 
er  hacker  any  less  creative  than  such  a 
person?  I  certainly  wouldn’t.  The  com¬ 
puter  serves  not  only  as  a  workhorse,  but 
also  as  an  easel  for  exercising  one’s  crea¬ 
tive  abilities.  Therefore,  in  my  opinion, 
the  hacker  has  not  limited  himself  at  all. 
Rather,  he  has  expanded  his  intellectual 
horizon  because  now  he  has  the  infinite 
tool. 

As  for  the  charge  that  it  disrupts 
one’s  social  life,  I  would  tend  to  agree 
with  this  to  a  point.  But  it  depends  on 
how  controlled  the  individual  is.  At  any 
time,  he  can  withdraw  to  a  more  normal 
schedule.  Why  doesn’t  he?  The  reason  is 
obvious.  The  infinite  tool  that  knows  few 
boundaries  is  accessible  to  a  much  higher 
degree,  and  thus  he  can  devote  more  time 
to  it.  Why  is  this  wrong?  I  think  it  is  defi¬ 
nitely  a  bonus,  since  the  usual  restraints 
of  9-to-5  are  eliminated  and  the  person 
is  allowed  to  expand  beyond  boundaries 


54 

512 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


to  do  what  he  wants. 

Now  we  come  to  the  human  versus 
the  machine  factor.  Gandalf  stresses  the 
necessity  of  human  interaction  and  the 
inherent  evil  of  the  machine.  Would  you 
stress  the  evil  of  the  instruments  in  an  or¬ 
chestra,  or  the  instruments  in  a  labora¬ 
tory,  or  the  typewriter  of  an  author?  All 
of  these  occupations  demand  extra¬ 
ordinary  amounts  of  time  for  excellence. 
But  I  see  no  greater  human  interaction  in 
these  fields  than  in  computers.  I  feel  that 
people  who  disparage  computers  for  a 
seemingly  decreased  human  interaction 
are  not  at  all  familiar  with  the  true  im¬ 
port  of  the  computer.  Not  only  is  it  the 
infinite  tool,  it  is  also  an  extremely  fluid 
medium  of  communication. 


From:  K.  Ruddies 
To:  G.  Gandalf 

Subject:  Hacking  and  the  Real  World 

I  don’t  want  to  turn  this  into  a  per¬ 
sonal  defense  or  anything  like  that,  but  as 
I’ve  said  before,  people  have  always 
found  me  strange.  I  have  always  worn  my 
hair  long  because  I  felt  it  was  comfortable 
for  me.  I  prefer  clothes  that  are  comfort¬ 
able  and  perhaps  a  bit  scroungy.  For  this, 
and  being  human,  and  getting  excited,  I 
have  gotten  pretty  bashed.  As  a  matter  of 
personal  history:  it  was  nice  for  me  to  get 
away  from  a  smog-hole  of  a  city,  where 
the  mayor  said  aloud  on  TV  once  that  the 
“black  problem”  existed  because  the 
“blacks  weren’t  disciplined  properly.” 
I  spent  time  in  an  ad  agency  where  peo¬ 
ple  were  not  only  truncated  and  anes¬ 
thetized,  but  positively  deformed  in  per¬ 
sonality.  They  viewed  people  as  real, 
honest- to-goodness  objects  of  $$  and/or 
pieces  of  meat.  They’d  promise  you  any¬ 
thing,  but  split  with  your  portfolio. 

Working  with  computers  has  been 
the  only  thing  tolerable  I  have  done  in 
quite  a  while.  It  does  have  its  drawbacks, 
and  you  can  get  into  just  doing  that  and 
not  trying  anything  else.  Part  of  it  de¬ 
rives,  I  think,  from  a  strange  version  of 
the  American  work  ethic.  The  thing  I 
find  sad  is  when  hacking  comes  before 
people;  and  it  does  sometimes  for  me, 
usually  where  $$$  and  all  this  financial- 
survival  crap  is  concerned.  But  it  is  sad¬ 
dest  when  someone  will  not  take  time  out 
from  hacking  to  be  with  people  at  all.  I 
mean  when  people  get  angry  because 
someone  sends  them  a  message  asking 
them  what  they  are  up  to,  and  the  other 


person  gets  all  freaked-out  and  sends 
nasty  notes  back. 

The  problem  is  that  the  social  struc¬ 
ture  of  LOTS  rewards  people  who  hack 
well  but  don’t  interface  well  with  people. 
If  you  look  at  who  gets  most  rewarded  at 
LOTS  and  for  what,  you  find  it  is  the 
people  who  do  programs  and  little  main¬ 
tenance  tasks.  Very  seldom  do  people 
who  get  along  with  others  and  relate  well 
to  them  get  highly  rewarded. 


From:  G.  Gandalf 
To:  A.  Anonymous 
Subject:  A  Reply 

You  base  much  of  your  argument  on 
comparisons  (e.g.,  with  musicians).  I  agree 
with  you  in  that  I  specifically  pointed  out 
that  many  people  besides  computer- 
science  majors  are  very  narrow.  This  is 
no  justification,  however.  As  the  son  of 
an  artist,  I  think  I  can  say  that  such  crea¬ 
tive  outlets  are  essential,  but  they  do  not 
and  should  not  make  up  the  totality  of 
one’s  existence. 

Secondly,  you  accuse  me  of  stressing 
the  evils  of  the  machine  world.  This  is  an 
interpretation  of  my  essay  that  is  purely 
yours.  I  attempted  to  make  clear  that  I 
thought  computers  could  be  highly  useful 
tools,  but  that  much  of  their  valuable 
potential  was  being  lost  due  to  the  nar¬ 
row  approach  to  them.  It  is  a  HUMAN 
failure  and  not  a  mechanical  one. 


From:  E.  Ernest 

To:  G.  Grog,  W.  Woody,  H.  Hima, 

B.  Berlin,  0.07,  K.  KDA,  Y.  Yduj, 

S.  Squash,  J.  Q.  Johnson 
Subject:  The  Hacker  Papers 
Dear  Sir  or  Madam, 

You  have  contributed  NOTHING, 
repeat  NOTHING,  to  the  Hacker  Papers. 
As  a  hacker,  it  is  your  responsibility  to 
defend  yourself  against  this  vicious  attack 
on  your  way  of  life.  Do  you  intend  to 
stand  idly  by  while  mealy-mouthed, 
bleeding-heart,  fuzzy-studies  majors  shred 
you?  Surely  not!  Voice  your  opinion! 
Stand  up  for  your  right  to  enjoy  not 
enough  sleep,  not  enough  terminals,  not 
enough  core!  What  people  do  with  con¬ 
senting  computers  in  private  is  their  busi¬ 
ness! 


From:  J.  Q.  Johnson 
To:  E.  Ernest 

Subject:  The  Hacker  Papers 

What,  pray  tell,  are  the  “Hacker 
Papers”?  A  work  by  Margaret  Hacker?  A 
lurid  tale  of  ax  murder?  A  discussion  of 
the  psychology  of  computer  nonprogram¬ 
ming?  If  the  last,  I  have  nothing  to  add, 
and  am  not  sure  I  appreciate  being  ad¬ 
dressed  as  a  hacker;  I’ll  have  you  know 
that  I  AM  a  “mealy-mouthed,  bleeding- 
heart,  fuzzy-studies  major,”  since  my  de¬ 
gree  is  in  political  science,  which  (next 
to  AI)  is  the  fuzziest  of  studies. 


Our  high-quality  editorial  and 
your  high-quality  products  are 
made  for  each  other!  Call  (415) 
323-3111  to  reserve  your  space 
in  the  next  Dr.  Dobb ’s  Journal. 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


55 

513 


My  feelings  are  aptly  summarized  in 
Joseph  Weizenbaum’s  Computer  Power 
and  Human  Reason ,  where  he  talks  about 
hackers  who  become  so  obsessed  in  tink¬ 
ering  with  their  grandiose  programs  that 
they  lose  sight  of  the  problem  to  be 
solved.  Though  I  disagree  with  his  ulti¬ 
mate  conclusion  that  the  computer  can¬ 
not  be  taught  to  reason  like  human  be¬ 
ings,  I  tend  to  agree  with  his  diagnosis  of 
the  effect  they  have  on  people’s  ability 
to  reason.  1  most  heartily  recommend  the 
book  for  your  consideration. 

Most  of  the  contributors  to  “The  Hacker  Pa¬ 
pers”  are  either  still  Stanford  undergraduates  or 
are  working  as  computer  specialists.  In  order  of 
their  messages,  they  include  Kenneth  Peter  (G. 
GANDALF),  Ernest  Adams  (E.  ERNEST), 
Robert  Kanefsky  (K.  KANEF),  Mark  Crispin 
(M.  MRC),  Steve  Kudlac  (K.  KUDDLES),  and 
John  Q.  Johnson  (J.  Q.  JOHNSON).  A. 
ANONYMOUS  stands  for  a  hacker  who  did  not 
wish  to  be  identified.  Credit  for  discovering  the 
papers  goes  to  psychologist  Philip  Zimbardo. 


HACKER  GLOSSARY 


Hacker:  A  person  who  makes  constant 
small  and  unimportant  modifications  to  a 
computer  program  for  enjoyment  rather 
than  to  improve  the  program. 

Hacker  display/ Display  hack:  An  altera¬ 
tion  in  a  computer  program,  done  sloppi¬ 
ly,  and,  often,  for  fun.  The  kind  of  pro¬ 
gram  involved  is  for  display  of  information 
on  a  terminal  screen. 

PASCAL:  A  relatively  new  computer  lan¬ 
guage  (like  BASIC  or  FORTRAN). 

Wheel  Wars:  Wheels  are  computer  users 
who  obtain  special  privileges.  Their  wars 
are  games  played  on  computers  in  which 
they  do  vicious  things  to  one  another,  like 
blocking  other  wheels’  access  to  the  ter¬ 
minals  or  trying  to  confuse  and  frustrate 
them.  (The  wars  occur  only  during  late 
night  hours  or  in  summer,  when  they 
won’t  interfere  with  the  work  of  other 
programmers.) 


AI:  Artificial  Intelligence,  the  study  of 
how  computers  can  be  programmed  to 
simulate  various  intellectual  processes  of 
human  beings,  such  as  language  use. 

Joseph  Weizenbaum:  A  well-known  AI  re¬ 
searcher  at  MIT  who  condemned  hackers 
in  his  book,  Computer  Power  and  Hu¬ 
man  Reason.  Compulsive  programming, 
Weizenbaum  wrote,  “represents  a  psycho¬ 
pathology  that  is  far  less  ambiguous  than, 
say,  the  milder  forms  of  schizophrenia  or 
paranoia.” 

HHROl,  STI:  Esoteric  machine  instruc¬ 
tions  used  mainly  by  wheels  and  computer 
repair  people. 

Exec:  The  executive  command  processor, 
the  program  that  carries  out  the  user’s 
orders. 

Core:  The  work  space  available  in  the 
computer,  its  internal  memory  capability. 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 

Each  issue  includes: 

•  valuable  software  tools 

•  algorithms  &  problem  solving  * 

•  industry  news 

•  important  product  reviews 

With  in-depth  coverage  of: 

•  telecommunications 

•  systems  programming 

•  language  development 

•  machine  independent 

programs 

and  much,  much  more! 


Dr.  Dobb's  Journal 


VM  i  * 


LU  ">  ’  •.’iLII 

1 21  e  I]  4  sl  in  BASIC 


Dr.  Dobb’s  Journal,  A  Publication  of  People’s  Computer  Company 
1263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  CA  94025 


Are  you  ready? 

DDJ,  the  world’s  foremost  microcomputer 
publication,  has  been  working  for  years  to  pre¬ 
pare  its  readers  to  be  innovators,  to  lead  the 
wave  of  breakthroughs  in  our  changing  tech¬ 
nology. 

Every  issue  of  Dr.  Dobb’s  Journal  helps 
one  to  understand  the  nuts  and  bolts  of  small 
computer  systems.  We  offer  entire  listings  of 
valuable  software:  our  pages  have  included 
compilers,  cross-assemblers,  editors,  new  lan¬ 
guages,  hardware  interfaces  and  more  —  usually 
before  anyone  else  thinks  of  them ! 

Even  more  important! 

Our  subscribers  share  insights,  correspond, 
and  contribute  to  one  another’s  work,  more 
than  any  other  group  we  know.  They  treat 
Dr.  Dobb’s  Journal  as  a  “hands-on”  publication. 

This  warm  cooperation  has  done  more  to 
refine  software  products,  and  generally  to 
advance  the  state  of  microcomputer  techno¬ 
logy,  than  perhaps  any  other  resource.  And  it  is 
available  to  you  through  our  pages! 

For  the  straight  facts . 

If  you  are  a  serious  computing  professional 
or  enthusiast,  then  you  should  take  a  very  close 
look  at  what  DDJ  offers  you.  We’ve  been  on 
the  cutting  edge  since  1976. 


Dr.  Dobb's  Journal,  Number  61,  November,  1981 
514 


57 


DR.  DOBB  S  CLINIC 


by  D.  E.  Cortesi,  Resident  Intern 


Ep,  Son  of  Ep 

In  the  August  Clinic  we  published  a 
plea  for  help  in  dealing  with  the  special 
features  of  the  Epson  MX-80  printer. 
Taylor  Caldwell  of  Burgess,  VA  couldn’t 
figure  out  how  to  embed  wide  or  empha¬ 
sized  characters  within  an  ordinary  line. 
His  request  produced  several  good  re¬ 
sponses.  One,  an  article- length  effort  by 
Gary  P.  Novosielski  will  appear  next 
month. 

Billy  Smith  (address  unknown;  we 
lost  his  envelope  in  our  highly  organized 
filing  system)  sent  a  letter  filled  with  ex¬ 
amples  of  special-font  characters  in  mid¬ 
line.  He  says  that  double-width  characters 
are  toggled  on  and  off  by  ASCII  SO  and 
SI  (control-n  and  control-t)  bytes  sur¬ 
rounding  the  would-be  wide  words.  Wide 
characters  can  apparently  be  switched  on 
and  off  at  any  time. 

The  other  special  fonts  —  compressed, 
emphasized,  and  double-strike  —  take  ef¬ 
fect  over  an  entire  line,  regardless  of 
where  in  the  line  the  special  characters 
that  evoke  them  appear.  A  line  that  con¬ 
tains  ESCape,  E,  for  example,  will  be 
printed  in  emphasized  mode  whether  the 
ESC,  E  pair  comes  at  the  beginning,  in 
the  middle,  or  at  the  end.  This  effect  can 
be  tamed,  Smith  says,  by  printing  a  line 
in  two  passes.  Print  the  normal  part  of 
the  line  and  end  it  with  a  CR  but  not  a 
LF,  thus; 

LPRINT  “NORMAL”;CHR$(l  3); 
then  overprint  the  special  part: 

LPRINT  CHR$(27);“E”; 

“  EMPHATIC” 

It  seems  to  us  that  the  spacing  could  get 
tricky  when  compressed  or  double-strike 
characters  are  used. 

Finally,  we  received  a  letter  from 
Steve  Semos,  an  employee  of  Epson 
America  in  Torrance,  CA.  He  wrote  first 
regarding  Caldwell’s  misconception  that 
“a  control  code  embedded  in  the  text 
may  be  recognized  or  not,  depending  on 
the  direction  the  print  head  is  to  go.”  Not 
so,  Semos  says,  “When  a  byte  is  received 
at  the  printer  it  is  placed  in  a  one- line 
buffer.  The  data  will  be  printed  when  one 
of  the  following  occurs:  the  buffer  be¬ 
comes  full,  a  carriage  return  is  received 
from  the  computer,  or  when  a  linefeed 
is  received.  The  data  is  printed  by  a 
microprocessor  in  the  printer ...  It  will 
format  the  data  in  the  same  manner  re¬ 
gardless  of  the  print  direction.” 

Semos  notes  that  some  BASICs  swal¬ 
low  ASCII  control  codes.  “The  ASCII 


control  codes  have  values  from  0  to  31. 
Some  computers  will  intercept  these 
codes  instead  of  sending  them  to  the 
printer.  This  can  be  avoided  by  adding 
128  to  the  desired  control  character  num¬ 
ber.  The  Escape  code  is  decimal  27 ;  plus 
128  makes  it  155.  When  sent  through 
BASIC  the  computer  will  pass  155  to  the 
printer,  and  the  printer  will  understand 
this  as  the  ASCII  code  ESC.” 

He  also  noted  that  the  expanded 
character  mode  is  switched  off  by  the  end 
of  a  line  (a  carriage  return  or  linefeed)  as 
well  as  by  the  SO  control  code,  so  that, 
for  example 

10  LPRINT  CHR$(14) 

20  LPRINT  “THIS  WOULD  BE  PRINT¬ 
ED  NORMAL” 

30  LPRINT  CHR$(14); 

40  LPRINT  “THIS  PRINTS  EXPAND¬ 
ED” 

50  LPRINT  CHR$(14);  “EXPANDED”; 
60  LPRINT  CHR$(20);“  NORMAL.” 

Kruskal's  Disassembler 
Reader  Mark  Northrup  of  Milwaukee,  WI 
presents  a  programming  problem  that 
probably  has  no  good  solution,  but  which 
raises  some  interesting  questions  of 
probability.  Mark  writes: 

When  you’re  disassembling  ob¬ 
ject  code  and  encounter  a  sym¬ 
bol  table,  the  disassembled  code 
is  garbage.  When  the  table  ends, 
my  problem  begins.  When  does 
the  code  line  up  and  become 
meaningful  again,  and  how  can 
you  tell?  Martin  Gardner  pro¬ 
vides  evidence  that  the  code  will 
line  up  with  an  83%  probability 
within  52  bytes  or  less  (see 
“Mathematical  Games,”  Scienti¬ 
fic  American,  February  1978). 
Northrup  enclosed  a  copy  of  the  refer¬ 
enced  column.  The  item,  too  long  to 
quote  here,  concerns  a  mathematical 
curiosity  dubbed  “Kruskal’s  Principle.” 
Gardner  presented  it  in  terms  of  counting 
chains  of  cards  as  they  are  dealt  from  a 
deck,  but  the  principle  clearly  would 
apply  to  the  disassembly  of  a  machine 
code  containing  instructions  of  varying 
length.  It  ought  to  be  possible  to  come  up 
with  a  statement  of  the  probability 
that  a  disassembler  would  be  back  in 
synch  within  some  number  of  bytes. 
Might  it  never  regain  synch?  As  to  “how 
can  you  tell,”  that  seems  to  be  a  question 
of  another  order  of  difficulty  entirely. 


Stop,  Heath! 

Terence  Hills  of  Don  Mills,  Ontario 
wrote  to  tell  of  a  dangerous  quirk  in  the 
Heath  H8.  The  H8  has  a  software- 
controlled  front  panel.  A  timer  interrupt 
gives  control  to  the  panel  monitor  code 
every  2ms.  If  the  monitor  detects  that  the 
CPU  was  in  the  halt  state,  it  awaits  user 
input;  otherwise  it  resumes  execution 
of  the  program.  Hills  says  that  the  way 
the  monitor  detects  a  prior  Halt  can  cause 
problems: 

The  monitor  pulls  the  interrupt¬ 
ed  program  counter  from  the 
stack,  decrements  it,  and  checks 
the  addressed  location  for  166 
octal  [an  8080  HLT  instruction, 

76  hex].  The  problem  is,  this 
byte  might  be  immediate  data, 
an  address,  or  a  variable.  Even  if 
it  is  an  opcode,  it  may  not  have 
been  the  last  one  executed. 
Nevertheless,  any  of  these  things 
will  send  the  machine  into  Moni¬ 
tor  mode. 

The  more  we  thought  about  this,  the 
worse  it  looked.  The  monitor  must  decre¬ 
ment  the  stacked  PC  to  find  a  HLT,  but 
it  could  equally  well  find  the  third  byte 
of  “CALL  7600H”  or  the  second  byte  of 
“MVI  A,1 18”,  or  a  “DB  ‘v’”  that  preced¬ 
ed  a  branch  target.  An  unplanned  return 
to  monitor  mode  could  occur  with  com¬ 
plete  unpredictability  -  disaster  for  a 
program  meant  to  run  unattended.  Maybe 
a  utility  could  be  written  to  search  an 
object  program  for  such  pseudo-halts  and 
flag  them. 

The  Root  of  the  Matter 

Once  in  a  while,  perhaps  in  a  graphics 
routine,  one  might  need  to  take  a  square 
root.  Even  if  the  problem  is  confined  to 
integers,  the  thought  of  doing  so  in  as¬ 
sembly  language  is  a  daunting  one.  One  of 
the  Clinic’s  more  frequent  respondents, 
L.  Barker  of  Chicago,  IL,  is  not  daunted. 
He  writes: 

A  number  of  ways  have  been 
presented  to  approximate  the 
hypotenuse  of  a  right  triangle. 
However,  the  more  accurate 
solutions  involved  multiplication 
and  division.  If  the  square  root 
was  approximated  because  of 
difficulty  in  programming,  then 
see  program  SQRT1  (Listing  1,  p. 

60).  Limiting  input  to  unsigned 
numbers  of  16  bits  gives  SQRT2. 

This  takes  a  maximum  time  of 


58 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 

515 


9K  T-states  and  is  less  than  15 
bytes  long.  For  people  in  a  real 
hurry  there  is  SQRT3  (both  in 
Listing  2,  p.  60).  This  runs  a 
worst  case  time  of  about  1200 
T-states  which  is  a  little  faster 
than  a  16-  by  16-bit  multiply. 
Adding  a  divide  to  the  end  of 
any  of  these  programs  doubles 
the  precision  of  the  computed 
answer.  When  the  Z800  comes 
out  next  year  with  the  Z80  in¬ 
struction  set  and  multiply  and 
divide,  this  will  all  look  like  a 
waste  of  time,  but  until  then, 
enjoy. 

Well,  the  Z800  won’t  be  replacing  all 
Z80’s  overnight,  you  know.  Still,  we’d 
all  like  to  know  more  about  that  chip; 
has  a  reader  any  hard  information? 

Thirty  Days  Hath  Septober .  .  . 

We  published  a  pair  of  calendar  rou¬ 
tines  in  the  July  Clinic  (#57,  p.  41). 
Edward  S.  Dayhoff  of  Silver  Springs, 
MD  has  written  to  correct  some  miscon¬ 
ceptions  and  our  sloppy  terminology. 
“These  programs,”  he  says,  “have  only 
limited  validity  ranges  because  of  the 
chaotic  nature  of  the  calendars  used 
throughout  history.  In  addition,  the  term 
‘Julian  Calendar  Date’  is  completely  er¬ 
roneous.”  He  continues, 

The  Julian  Calendar  is  complete¬ 
ly  unrelated  to  the  Julian  date  as 
a  short  perusal  of  an  encyclope¬ 
dia  will  show.  The  program  by 
C.  T.  McDaniel  uses  the  Julian 
date.  The  Julian  calendar  is 
the  calendar  without  century¬ 
adjusting  leap  years  which  came 
down  to  us  from  Augustus 
Caesar  and  which  was  used 
throughout  the  “civilized”  world 
until  reformed  by  Pope  Gregory 
XIII  in  1582.  The  reformed 
calendar  was  adopted  individual¬ 
ly  by  each  country  at  different 
times  and  was  known  as  the 
Gregorian  calendar.  The  pro¬ 
grams  both  produce  correct  Gre¬ 
gorian  calendar  dates,  but  be 
cautioned  that  they  will  pro¬ 
duce  them  for  years  before  the 
Gregorian  calendar  was  in  use! 
The  “universal”  calendars  found 
in  some  reference  books  may 
suffer  from  the  same  problem. 

The  Gregorian  calendar  was 
actually  decreed  by  the  Council 


of  Nicea  in  325  but  was  not 
used.  The  errors  of  the  Julian 
accumulated  and  when  Gregory 
published  the  reformed  calendar 
he  insisted  that  the  errors  be 
corrected  retroactive  to  325. 

That  amounted  to  10  days.  Thus 
the  day  after  October  4,  1582, 
was  October  15,  1582.  The 
calendar  change  was  enacted  im¬ 
mediately  in  France,  but  in  Eng¬ 
land  and  in  the  British  colonies 
in  America  the  change  took 
place  in  1752,  by  which  time  the 
error  was  1 1  days.  In  that  year 
September  2  was  followed  by 
September  14!  Another  change 
was  made  at  the  same  time.  Pre¬ 
viously  the  first  day  of  each  year 
was  taken  as  March  25,  Annun¬ 
ciation  day.  Thus  March  24, 

1757  was  followed  by  March 
25,  1752,  while  December  31, 

1751  was  followed  by  January 
1 ,  1751.  You  fellows  who  like  to 
program  calendars,  have  a  go  at 
that  one! 

Dayhoff  supplied  changes  to  McDaniel’s 
code,  resulting  in  the  routines  shown  in 
Listing  3,  p.  60.  The  second  calendar  pro¬ 
gram  in  issue  #57  (another  L.  Barker  ef¬ 
fort),  suffered  badly  at  the  hands  of  two 
typesetters.  Your  Intern’s  word  processing 
software  swallowed  all  the  “>”  and  “<” 
symbols,  and  the  regular  typesetter  lost 
parts  of  other  lines.  It’s  such  a  nice  little 
program  that  we’re  printing  it  again 
(Listing  4,  p.  61). 

Basically  Difficult 

The  USR  function  of  Microsoft 
BASIC  is  a  nasty,  but  often  necessary, 
way  to  escape  into  machine  code  to  ac¬ 
complish  something  that  can’t  be  done 
well  enough  (or  at  all)  through  the  in¬ 
terpreter.  One  thing  that  can’t  be  done 
through  the  interpreter  is  to  gain  access 
to  CP/M’s  RDR  and  PUN  logical  devices. 
Scott  Nowell,  of  Nashua,  NH  needed  to 
drive  a  programmable  industrial  control¬ 
ler  that  was  interfaced  through  the  RDR 
and  PUN  devices.  “The  problem  was  to 
write  a  program  that  would  send  a  string 
to  the  controller  and  get  another  string 
returned  by  the  controller.”  Nowell 
found  the  syntax  of  the  USR  function 
deceptive; 

It  says  in  the  manual  that  when 
a  string  is  passed  to  the  user 
subroutine  the  DE  register  pair 


points  to  three  bytes  called  a 
string  descriptor.  Byte  0  of  the 
descriptor  contains  the  length 
of  the  string  (0  to  255).  Bytes 
1  and  2  are  a  pointer  value  to 
the  starting  address  of  the  string. 
Although  it  does  not  say  that  a 
string  can  return  a  value  to  the 
program,  the  whole  intent  of 
the  USR  command  is  to  do  just 
that.  An  example  is 
I$  =  USR(A$) 

It  seems  rather  obvious  that  this 
should  assign  the  value  returned 
by  USR  to  1$.  Unfortunately  it 
is  really  equivalent  to  I$  =  A$; 
whatever  the  USR  function  re¬ 
turns  in  the  registers  is  dis¬ 
carded. 

We  first  determined  that  we 
could  modify  the  actual  string 
that  MBASIC  passed  to  us,  if 
we  didn’t  change  its  location  or 
length.  So  our  routine  put  the 
returned  string  right  back  where 
the  original  was.  This  causes  the 
statement  to  work  as  we  wanted. 

In  order  for  this  to  work  with 
any  length  of  input  string,  we 
decided  to  always  output  strings 
with  a  fixed  length.  A  second  re¬ 
quirement  was  not  to  send  junk 
on  the  end  of  the  string.  That  is 
done  with  an  end  of  string  mark. 

The  following  statements  accom¬ 
plish  it: 

5  DEF  USR=&HE61 2 
10  I$  =  SPACE$(80) 

20  INPUT  “ENTER  DATA:”;A$ 

30  LSET  1$  =  A$  +  CHR$(255) 

40  1$  =  USR(I$) 

This  does  limit  the  incoming 
string  to  be  no  longer  than  the 
outgoing  one,  but  it  accom¬ 
plishes  the  job. 

Share  the  Wealth 

This  Clinic  contains  several  exem¬ 
plary  “sponses”  —  readers’  revelations 
that  inform,  warn,  or  stimulate.  The  Clin¬ 
ic  thrives  on  such  input.  The  Micro  Logic 
Corp.  (POB  174,  Hackensack,  NJ  07602) 
sent  us  a  very  nice  plastic  6502  reference 
card.  We’ll  send  it  out  to  the  next  author 
of  a  “sponse”  who  requests  it. 

Next  month  we  will  present  Octa- 
metry,  a  new  branch,  or  twig,  of  mathe¬ 
matics,  and  such  other  gleanings  from 
your  fields  of  endeavor  as  may  turn  up 
by  then. 


Dr.  Dobb’s  Journal,  Number  61,  November,  1981 


59 


516 


Improved  MX-80  Printer  Driver 
For  CP/M  BIOS 

Gary  P.  Novosielski 


and  much,  much  more! 


— 


Systems 


$2.50 

($3.00  in  Canada) 


OURNAL 


ForUsers  of  Small 

Number  62  December  1981  Volume  6,  Issue  12 


Actors,  Property  Lists,  and  LISP 
Ronald  L.  Nicol 

Automatic  Loading  of  Assembly 
Language  Subroutines 

John  B.  Palmer 


Artificial 
Intelligence 
for  Micros? 

Powerful 
Memory  Test 
for  8080’s  . . . 

. . .  more  on 
Small-C! 


Small-C  Expression  Analyzer 

J.  E.  Hendrix 


Dr.  Dobbs  Journal 

For  Users  of  Small  Computer  Systems  / 


December,  1981  Volume  6,  Issue  12,  Number  62 

CONTENTS 


Actors,  Property  Lists,  and  LISP .  12 

by  Ronald  L.  Nicol 

Marching  the  8080  .  20 

by  James  Laurino 

Improved  MX-80  Driver  for  CP/M  BIOS . 24 

by  Gary  P.  Novosielski 

Connect  a  Parallel  Printer  to  Your  NorthStar  .  .  35 

by  Alan  Bomberger 

Small -C  Expression  Analyzer . 40 

by  J.  E.  Hendrix 

Automatic  Loading  of  Assembly 

Language  Subroutines . 44 

by  John  B.  Palmer 


Departments 

Letters .  4 

Dr.  Dobb’s  Clinic .  6 

Of  Interest .  8 


©  1981  by  People’s  Computer  Company  unless  otherwise  noted  on 
specific  articles.  All  rights  reserved. 


Dr.  Dobb’s  Journal  (USPS  307690)  is  published  twelve  times  per  year  by  People’s  Computer  Company,  Box  E,  1263  El  Camino  Real,  Menlo 
Park,  CA  94025.  Second  class  postage  paid  at  Menlo  Park,  California  9402  5  and  additional  entry  points.  Address  correction  requested.  Post¬ 
master:  send  form  3579  to  Box  E,  Menlo  Park,  California  94025. 


Editor,  Marlin  Ouverson 
Assistant  Editor,  Julie  Anton 
Contributing  Editors,  Dave  Caulkins 
and  Dave  Cortesi 


Marketing  Director,  Craig  S.  Harper 
Advertising  Sales,  Laird  Foshay 
Circulation  Assistants,  Susan  Hinton 
and  Alice  Hinton 


Art  Director,  Clifford  West 
Artist,  Barbara  Ruzgerian 
Typesetter,  Renny  Wiggins 
Proofreader,  Nancy  Heubach 


EDITORIAL 


No,  this  month’s  feature  article  is  not  about  speech 
problems  on  Broadway.  When  the  stage  was  first  set  for 
LISP  to  run  on  micros,  it  was  inevitable  that  artificial  intel¬ 
ligence  would  soon  make  an  entrance.  In  his  article,  author 
Nicol  explains  how  an  actor,  or  object-oriented,  language 
works,  and  how  a  program  written  in  it  can  “learn.” 

As  memory  capacity  grows,  so  will  AI  concerns  in 
microcomputing.  Some  applaud  this,  while  others  sit  in  the 
back  row  and  hiss.  We  hope  both  factions  will  offer  their 
critical  input  and  software  for  publication  in  this  journal. 
We  most  humbly  believe  that  AI  would  benefit  from  a  little 
exposure  to  the  good  Doctor’s  community  of  friends. 

Some  readers  have  accused  our  overseas  distributors  of 
being  artificially  intelligent  —  and  minimally  so,  at  that.  We 
have  had  problems  in  the  past,  which  have  mostly  been  re¬ 
solved.  Many  times  it  is  the  vagaries  of  international  postal 
systems  that  are  to  blame,  not  the  distributors.  And  if  they 
sell  their  entire  stock  -  well,  readers  everywhere  must  deal 
with  that,  unless  they  choose  to  subscribe. 

So,  if  you  live  outside  the  United  States  and  decide  it 
would  be  nice  to  receive  your  very  own  copy  of  DDJ  each 
month,  here  are  some  sure-fire  tips  to  help  you  place  a 
trouble-free  subscription: 


1)  Your  payment  to  “Dr.  Dobb’s  Journal”  must  accom¬ 
pany  your  order.  An  international  postal  money  order 
will  suffice;  if  you  pay  by  check,  it  must  be  drawn  on  a 
U.S.  bank  and  payable  in  U.S.  funds.  Both  must  be  for 


the  exact  amount  of  your  subscription  (see  page  46  for 
rates). 

2)  Print  your  name  and  full  address  (including  country) 
carefully. 

3)  We  highly  recommend  airmail.  Boats  are  slow  and  some¬ 
times  sink  —  or  at  least  the  mail  bags  seem  to  do  so. 

4)  If  you  wish  to  order  any  back  issues,  do  so  separately 
and  pay  for  them  separately. 

Following  the  above  advice  will  prevent  most  common 
errors  from  happening.  If  you  do  experience  any  trouble 
with  your  subscription,  allow  extra  time  for  international 
delivery.  If  that  doesn’t  work  and  you  need  to  write  us  a 
letter  (please,  let  it  be  in  the  King’s  good  English!),  describe 
your  experience  step-by-step  and  include  a  photocopy  of 
your  original  check  (both  sides  of  it)  or  money  order  re¬ 
ceipt. 

We  hope  you  will  subscribe  and  become  a  long-time 
friend  of  Dr.  Dobb’s  Journal.  Best  wishes  to  you  all.  May 
the  coming  year  find  your  bootleg  copies  of  useful  DDJ 
articles  supplanted  by  shiny  new  issues  of  your  own! 

Marlin  Ouverson 
Editor 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 
518 


3 


Forthright  .  .  . 

Dear  DDJ , 

Although  I  appreciate  the  beauty  of 
B.  Ragsdale’s  assembler  for  the  6502 
(DDJ  #59,  pp.  12-24)  in  terms  of  the 
mechanism  of  code  generation  for  the 
different  addressing  modes  —  there  is  a 
major  flaw  in  it. 

There  is  no  justification  whatsoever 
to  make  the  words  BEGIN,  UNTIL,  IF, 
THEN,  ELSE,  CODE  END-CODE  im¬ 
mediate  words  except  to  prevent  sophisti¬ 
cated  macro  definitions.  If  those  words 
weren’t  immediate,  one  could  define,  e.g., 

:  16INC,  (  ADR  -  ) 

DUP  INC,0=  IF,  ROT  1+  INC, THEN,  ; 

which,  at  execution  time,  will  generate  a 
macro  expansion  for  incrementing  a  16- 
bit  value.  It’s  usage  would  be  somewhat 
like  CODE  XXXX 

.  . .  COUNTER  16INC,  . . . 

END-CODE 

supposing  COUNTER  is  a  two-byte  field. 

Another  —  debatable  —  point  is  com¬ 
piler  security  with  the  conditional  con¬ 
structs.  I  think  that  compiler  security 
doesn’t  make  very  much  sense  in  assem¬ 
bler  coding  —  there  are  far  too  many  pit- 
falls  besides  conditionals  in  any  case.  On 
the  other  hand,  the  security  makes  writ¬ 
ing  of  unstructured  code  unnecessarily 
complicated. 

I  want  to  thank  the  editors  for  dedi¬ 
cating  an  entire  issue  to  FORTH  and  I 
hope  that  it  will  result  in  discussions  and 
suggestions  which  will  enhance  the 
quality  of  our  systems. 

Klaus  Schleisiek 
c/o  J.  Buettner 
Eppendorfer  Landstr.  16 
D-2000  Hamburg  20 
W-Germany 


ZSID  Bug  and  (Risky?)  Patch 

Dear  Mr.  Marlin  Ouverson! 

Instead  of  complaining  about  the 
quality  (in  all,  good)  and  the  taste  (it  de¬ 
pends)  I  send  you  my  renewal  for  two 
years  (I  hope  that  I  will  get  an  extra  issue 
for  prompt  renewal,  too,  even  if  it  is  to 
overseas).  And  I  send  you  a  small  article 
(perhaps  better  a  bug-note)  as  I  know 
that  the  journal  depends  on  input!  (This 
is  my  fifth  contribution  to  Dr.  Dobb’s.) 

It  is  about  a  CP/M  program  made  by 
Digital  Research11" .  I  think  it  will  be  use¬ 
ful  to  some  of  the  readers.  By  the  way, 
my  article  of  September,  1979  brought 
four  intense  contacts  since  then.  Perhaps 


you  may  again  publish  my  full  address 
with  the  statement  that  I  still  seek  con¬ 
tacts  to  European  CP/M  users. 

Best  wishes  for  you  and  the  whole 
crew. 

There  is  a  small  hidden  bug  in  ZSID 
version  1.4.  It  is  easily  demonstrated 
when  trying  the  following:  in  the  direct 
assembly  mode,  try  to  assemble  three  16- 
bit  loads  with  the  values  of  (in  hex): 

FF7F,  FF80,  FFFF. 
Afterwards,  list  the  product ! 

The  false  values  are  not  only  used  in 
the  assembler,  but  in  the  F  (ill),  M  (ove) 
and  D  (ump)  commands  as  well.  The  cure 
is  very  simple:  change  the  byte  at  02 AE 
(hex)  in  ZSID  from  “C2”  to  “C3”. 

SID  version  1.4  has  not  this  “fea¬ 
ture,”  so  I  suspect  that  the  routine  start¬ 
ing  at  02A1H  is,  at  some  place,  necessary 
in  the  Z80-specific  parts,  e.g.,  for  error¬ 
checking  in  relative  jumps?? 

I  did  not  encounter  any  problems 
with  the  changed  version  of  ZSID  (see 
Table  1),  but  I  am  sure  that  this  change  is 
not  without  danger.  .  .  .  Best  wishes  to  all 
CP/M  users! 

Holger  Petersen 
Samwerstr.21 
2300  KIEL  1 
West  Germany 

Table  1.  ZSID  Changes 

A>DIR 

A:  ZSID  COM 

A  >  ZSID 

ZSID  VERS  1.4 
HA100 

0100  LD  HL, 0FF7F 
0103  LD  HL , 0FF80 
0106  LD  HL, 0FFFF 
0109 

4L100, 108 

0100  LD  HL, FF7F 

0103  LD  HL , 0080 

0106  LD  HL, 00FF 

0109 

# I ZSID . COM 
#R 

NEXT  PC  END 
2900  0100  B9FF 
#L2A1, 2BC 

02A1  PUSH  DE 

02A2  CP  41 


02A4 

JP 

NC , 0BCF 

02A7 

CALL 

0EAA 

02AA 

LD 

B,  D 

02AB 

LD 

A,  B 

02  AC 

CP 

FF 

02AE 

JP 

NZ , 00B8 

02B1 

LD 

A,  E 

02B2 

OR 

A 

02B3 

JP 

P , 00B8 

02B6 

LD 

B ,  00 

02B8 

LD 

A,  E 

02B9 

POP 

DE 

02BA 

DEC 

B 

02BB 

INC 

B 

02BC 

02BD 

#S2AE 

RET 

02AE  C2 

C3 

02AF  B8 

. 

4L2ADDE 

,  2B0 

02AE 

JP 

00B8 

02B1 

4G0 

A > SAVE  40  ZSIDP.COM 
A> 

A>  DIR 

A:  ZSID  COM  :  ZSIDP  COM 

A>  ZSTDP 

ZSID  VERS  1.4 

4A100 

0100  LD  HL, 0FF7F 
0103  LD  HL, 0FF80 
0106  LD  HL, 0FFFF 
0109  . 


#L100, . 

108 

0100 

LD 

HL, FF7F 

0103 

LD 

HL, FF80 

0106 

LD 

HL, FFFF 

0109 

HG0 

A> 

Pet-urbed 

Dear  Mr.  Ouverson: 

I  thought  your  readers  might  be  inter¬ 
ested  in  this  before  they  contemplate 
buying  a  16K  Commodore  PET  computer. 
Commodore  has,  for  about  a  year,  [been] 

(Continued  on  page  19) 


4 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 

519 


uk.  UUBB’S  CLINIC 


by  D.  E.  Cortesi,  Resident  Intern 


Octametry 

In  this  column’s  first  appearance  we 
included  an  approximation  to  the  hypote¬ 
nuse  that  was  found  purely  by  chance, 
from  no  particular  theoretical  basis.  That 
little  item  generated  an  amazing  amount 
of  interest.  Now  we’ve  received  the  fol¬ 
lowing  dissertation  from  C.  Roger  Glassey 
of  the  University  of  California. 

“There  is  more  to  trigonometry  than 
the  hypotenuse  of  the  right  triangle.  One 
quick  approximation  to  the  hypotenuse, 
discussed  in  DDJ  #56,  takes  the  form: 

( 1 )  h(x,y)  =  A*x  +  B*y 

“The  geometry  behind  this  approxi¬ 
mation  can  be  used  to  derive  consistent 
approximations  to  the  sine,  cosine,  and 
tangent  functions.  These  may  be  useful 
in,  for  example,  computing  the  screen 
positions  of  points  of  a  rotating  object, 
or  in  other  applications  that  require  fast 
approximate  conversion  between  rec¬ 
tangular  and  polar  coordinates. 

“The  formula  used  to  compute  the 
hypotenuse  determines  how  distances 
will  be  measured.  When  Euclid’s  hypote¬ 
nuse,  SQRT(SQR(x)+SQR(y)),  is  used, 
the  locus  of  points  at  a  distance  of  1  unit 
from  the  origin  form  the  unit  circle.  But 
when  equation  (1)  is  used,  points  on  the 
octagon  shown  on  the  cover  of  the  July 
DDJ  are  1  unit  from  the  origin.  In  order 
to  simplify  the  discussion,  I  assume  that 
x  and  y  are  the  coordinates  of  a  point  in 
the  first  octant  of  the  plane,  so  that 
0  <  y  <  x.  Furthermore,  when  converting 
from  rectangular  to  polar,  it  seems  desir¬ 
able  that  the  point  1,0  (that  is,  the  unit 
vector  along  the  x-axis)  have  unit  length. 
In  other  words,  h(l,0)=l.  Therefore,  I 
will  take  A  in  equation  (1)  to  be  1. 

“In  Euclid’s  plane,  the  length  of  the 
arc  of  the  unit  circle  subtended  by  an 
angle  is  the  measure  of  that  angle.  In  the 
approximate  plane,  we  use  the  unit  oc¬ 
tagon,  shown  in  Figure  1  by  the  dashed 
lines.  The  point  (x,y)  is  on  this  unit  octa¬ 
gon  and  therefore,  by  definition,  h(x,y)= 
1.  The  length  of  the  line  from  the  point 
(1,0)  to  the  point  (x,y)  is  z,  the  measure 
of  the  angle  at  (0,0).  If  we  let  z  increase, 
then  we  see  (from  the  law  of  similar  tri¬ 
angles)  that  y  =  bz  and  l-x  =  az  where  a 
and  b  are  constants  of  proportionality. 

“Therefore  the  octagonal  sine,  cosine 
and  tangent  functions  are: 

(2)  s(z)  =  y/h(x,y)  =  b*z 

(3)  c(z)=  x/h(x,y)=  l-a*z 

(4)  t(z)=  s(z)/c(z)=  b*z/(l-a*z) 


Letting  y/x  =  r,  the  octagonal  arctangent 
function  is 

(5)  at(r)  =  r/(b+ar). 

“We  have  only  one  degree  of  free¬ 
dom  in  choosing  the  constants  a  and  b  be¬ 
cause,  since  they  are  the  proportionality 
constants  for  the  sides  of  a  right  triangle 
in  Euclid’s  plane, 

(6)  a*a  +  b*b  =  1. 

The  use  of  this  single  degree  of  freedom 
will  determine  the  error  of  these  approxi¬ 
mations. 

“The  octagonal  trig  functions  can  be 
used  to  calculate  the  hypotenuse  as  in 
ordinary  trigonometry.  Given  x  and  y, 
use  equation  (5)  to  obtain  z.  Then  use 
h(x,y)  =  y/s(z)  or  h(x,y)  =  x/c(z).  Either 
way,  the  result  is  h(x,y)=  x+y  *a/b.  There¬ 
fore,  the  constant  B  in  equation  (1)  is 
a/b,  and  we  have  a  set  of  approximations 
to  the  trigonometric  functions  that  are 
consistent  with  the  hypotenuse  approxi¬ 
mation. 

“Rather  than  confronting  the  issue 
of  a  suitable  value  for  B,  consider  what 
happens  when  z  increases  until  it  sub¬ 
tends  an  angle  of  45  degrees,  or  1/8  of 
the  octagon.  Let  k  be  this  value  of  z.  A 
half  circumference  of  the  unit  octagon 
is  then  4*k,  which  corresponds  to  Tt  in 
Euclid’s  world,  so4*k  is  the  octagonal  ap¬ 
proximation  to  7T.  Thus  if  you  use  equa¬ 
tion  (5)  to  compute  the  arctangent  in 
degrees,  remember  that  90  degrees  is  2*k, 
not  7r/2.  I  regard  this  constant  k,  the 
length  of  one  side  of  the  unit  octagon,  as 
the  fundamental  constant  in  the  approxi¬ 
mation  plane.  From  it  all  others  can  be 
derived. 

“Imagine  Figure  1  in  which  z=k,  so 
that  x  =  y.  Since  the  tangent  of  k  is  1,  we 
have  the  condition 

(7)  a*k  +  b*k  =  1 . 

A  little  algebra  applied  to  equations  (5) 
and  (6)  produces: 

(8)  b  =  (1  +  SQRT(2*k*k- l))/2*k 

(9)  a=  (1  -SQRT(2*k*k-l))/2*k 

Since  a  and  b  must  be  positive  and  real, 
k  must  be  chosen  between  SQRT(2)/2 
and  1 .  If  k  is  set  to  0.7895,  so  a= 0.3 1 88 
and  b  =  0.9478,  then  the  maximum  rela¬ 
tive  absolute  error  in  h(x,y)  is  about 
5.5%.  It  occurs  at  z=0.336,  which  is 
about  20  degrees,  and  also  at  z=k  or  45 
degrees.  The  corresponding  value  of  B  in 
(1)  is  0.3364. 

“The  definition  of  s(z)  given  in  (2) 


is  valid  for  -k  <  z  <  k.  For  z  <  0,  use  the 
fact  that  c(z)=c(-z).  Outside  this  range, 
imagine  you  are  doing  common  trigono¬ 
metry  with  tables  that  only  cover  the 
range  0  to  45  degrees.  For  example,  if 
k<z<2k,  use  s(z)=c(2k-z).  For  angles 
representing  more  than  one  complete 
rotation,  remember  that  8k  may  be  sub¬ 
tracted  from  z  without  changing  the  value 
of  any  of  the  octagonal  trig  functions. 

“Happy  approximations, 

—  C.  Roger  Glassey.” 


And  Furthermore  .  .  . 

While  browsing  through  back  issues 
of  that  excellent  journal.  Software,  Prac¬ 
tice  and  Experience,  we  found  a  related 
item.  In  a  short  article  in  volume  7,  num¬ 
ber  2  (March- April,  1977),  p.  277,  D.  G. 
Colquhoun  describes  “A  Fast  Approxi¬ 
mation  to  the  SIN  Function.” 

Colquhoun’s  method  is  well-suited 
to  machines  that  store  floating  point 
numbers  with  an  exponent  that  is  a 
power  of  two  stored  as  a  binary  integer. 
Two  functions  were  offered,  both  requir¬ 
ing  nothing  but  Boating- point  addition 
and  integer  operations  on  the  exponent 
field  of  the  number. 

The  less  accurate  approximation  is 

For  0  <  x  <  0.829347, 
sin(x)  =  y|  *  x 
For  0.829347  <x  <tt/2, 
sin(x)  =  ^  *  x  +  0.5  18342 

lo 

A  circle  plotted  using  this  approximation 
comes  out  as  an  octagon!  Colquhoun 
notes  that  fifteen-sixteenths  of  x  is  easily 
gotten  as  x-x/16,  while  five-sixteenths 
x  is  just  (x/4)+(x/16). 

A  more  accurate  approximation 
comes  from  a  four-stage  approximation: 


For  x  ^  0.426350, 
sin(x)  =  x 

For  0.426350  <  x  <  0.968634, 
sin(x)  =  |  *x  +  0.106587 
For  0.968634  <  x  <  1.413800, 
sin(x)  =  *x  +  0.469825 


6 

520 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


For  1.413800  <  x  <  rr/2, 
sin(x)  =  1 . 

A  circle  plotted  with  this  function  pro¬ 
duces  a  16-agon.  Three-fourths  and  three- 
eighths  are  again  easily  gotten  by  modify¬ 
ing  the  binary  exponent  of  a  float  num¬ 
ber. 


Touching  on  Tones 

In  issue  #58  (August  1981)  we  pub¬ 
lished  a  request  from  J.  R.  Snow  of  San 
Francisco,  CA.  He  was  looking  for  a 
cheap  way  to  decode  standard  touch-tone 
signals.  Snow’s  ultimate  objective  is  the 
ability  to  control  a  computer  remotely, 
by  calling  it  up  and  commanding  it 
through  the  touch-tone  pad. 

Two  readers  responded.  Gene  Head 
of  Corvallis,  OR,  suggests  that  Snow 
should  check  the  Radio  Amateur's  Hand¬ 
book  published  by  the  Amateur  Radio 
Relay  League  (ARRL),  and  also  that  the 
ads  in  QST,  the  magazine  of  the  ARRL. 
should  yield  some  suppliers. 

David  L.  Hoats  of  Bordentown,  NJ, 
referred  us  to  an  article,  “Build  this 


Unicorn- 1  Robot,  Part  9”  by  J.  A. 
Gupton,  published  in  Radio -Electronics 
magazine  in  April,  1981.  That  article  cites 
suppliers  of  a  decoder  kit  costing  $70. 
Hoats  writes,  “Having  built  the  decoder,  I 
can  assure  you  that  it  is  of  highest 
quality.  Construction  is  fairly  simple,  but 
calibration  can  be  tedious  without  the 
aid  of  a  frequency  counter.”  He  adds,  “I 
would  like  to  see  an  article  on  interfacing 
this  sort  of  decoder  to,  say,  a  KIM-1, 
since  (being  only  a  feeble-minded  hard¬ 
ware  hacker)  I’m  not  clever  enough  to 
work  out  the  programming  involved.” 

We  can  think  of  a  lot  of  applications 
of  Snow’s  idea.  A  very  small  machine 
(a  KIM  or  AIM  would  be  perfect)  could 
be  equipped  to  detect  when  the  phone 
was  ringing,  to  answer  it,  and  to  perform 
some  action  under  touch-tone  command. 
A  slightly  larger  machine  could,  with  the 
addition  of  a  Votrax  Type  ‘n’  Talk,  talk 
back  to  the  caller.  In  fact,  the  world’s 
smartest  phone-answering  machine  could 
be  built  in  this  way,  for  under  $1000. 

A  good,  cheap,  telephone  interface 
design  could  almost  be  machine  indepen¬ 
dent.  The  interface  points  would  be  the 
standard  Bell  wall-jack  on  one  end,  and 


a  set  of  parallel  latches  on  the  other.  An 
input  bit  for  ring-detect,  an  output  bit 
controlling  an  off-hook  relay,  four  bits 
for  the  decoded  touch-tone  digit,  and  a 
digit-valid  bit  would  be  enough.  Some 
means  of  switching  the  audio  signal  to  a 
recording  device  would  be  nice.  If  any¬ 
one  wants  to  design  that  circuit,  DDJ 
would  be  delighted  to  publish  it. 

Suppose  one  had  such  an  interface? 
Then  what  should  the  command  language 
look  like?  The  alphabet  of  the  command 
is  composed  of  the  touch-tone  digits.  We 
are  told  that  there  are  really  16  of  them 
defined,  but  the  standard  phone  has  only 
12  buttons  (a  portable,  16-key  touch- 
tone  pad  would  be  another  nice  project). 
The  specific  commands  would  depend  on 
the  application,  but  we  can  see  one  prob¬ 
lem  that  would  be  a  constant.  Namely, 
how  can  an  ASCII  literal  string  be  repre¬ 
sented,  using  a  12-digit  alphabet?  Bear  in 
mind  that  a  human  interface  is  involved 
here;  whatever  is  used  should  be  simple 
and  natural  enough  that  a  person  in  a 
phone  booth  on  a  wet  and  windy  night 
could  recall  and  use  it  without  notes. 
Stare  at  your  touch-tone  phone  for  a 
while  and  send  suggestions  to  the  Clinic. 


Figure  1 . 


Engineers 

Scientists 

Systems  Programmers 
Business  Owners 

All  these  read  Dr.  Dobb ’s  Journal. 
Reach  them  with  cost-effective  advertising. 
(415)  323-3111. 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


7 

521 


OF  INTEREST 


by  Dave  Cortesi 


An  Extraordinary  Offer 

We  are  in  receipt  of  a  letter  from  Bill 
Johnston  of  Applied  Computing,  who 
writes  as  follows: 

A  comple  of  years  ago  our  com¬ 
pany  was  involved  in  a  commercial 
project  to  install  automatic  ribbon 
re-inkers  on  microcomputer  printers. 
These  modification  kits  are  mounted 
inside  the  printers  where  they  auto¬ 
matically  re-ink  the  ribbon  whenever 
the  machine  is  in  operation.  The  re¬ 
sult  is  consistent  crisp,  dark  print, 
along  with  extension  of  ribbon  life 
by  a  factor  of  ten  times  or  more  .... 
We  have  perhaps  a  hundred  of  these 
kits  left  on  hand.  The  original  selling 
price  was  $150  per  kit,  which  includ¬ 
ed  installation.  The  remaining  kits 
are  being  made  available  to  interested 
computer  users  at  $18.25  each,  post¬ 
paid  ($1  extra  for  air  mail).  The  pur-, 
chaser  must  do  the  installation,  of i 
course.  The  re-inkers  will  work  on' 
any  printer  with  a  one-half  inch  or 
narrower  ribbon. 

No  technical  information  was  included, 
so  we  can't  comment  on  the  skill  needed 
for  the  installation.  Readers  who  feel 
competent  to  modify  their  own  printers, 
and  who  aren’t  worried  about  the  possi¬ 
ble  effect  on  their  printer’s  warranty, 
may  want  to  follow  up  on  this. 

Ail  Extraordinary  Board 

In  the  September  issue  we  dropped 
a  couple  of  items  to  make  room  fori  an 
IBM  announcement.  One  of  the  items  had 
an  accompanying  picture,  which  didn’t 
get  dropped.  Here’s  the  item  to  go  wjith 
the  photo:  “Eventide  Clockworks  have 
made  the  first  announcement  we’ve  s^en 
of  a  RAM  board  that  uses  the  new  64K- 
bit  chips.  They  have  packed  512K  by'jtes 
of  RAM  on  a  single  board  to  fit  the  HP 
9845  desktop  computer.  They  note  that 
one  board  has  more  capacity  than  bdth 
the  machine’s  tape  cartridges.  A  moment 
with  our  pocket  calculator  reveals  that 
the  board  costs  just  over  S12  per  kilo¬ 
byte,  suggesting  that  a  64K  board  for  an 
S-100  system  could  be  brought  in  at  well 
under  SI 000.” 

Publication  of  the  photo  without  tie 
text  caused  some  confusion  for  one  op¬ 
timistic  soul.  Richard  Factor,  Eventide 
VP,  writes  that  a  reader  called  to  ask! if 
the  board  could  possibly  be  used  to  ex¬ 
pand  a  KIM!  Well,  why  not,  Richard? 
There  are  lots  more  KIMs  than  there  are 
HP-9845s,  after  all.  If  the  KIM  market 


8 

522 


is  too  small,  give  some  thought  to  how 
much  you  could  put  on  a  single  S-100 
board.  Say,  256KB  with  error- correcting 
logic,  for  CP/ M  86?  Or  the  bank-switched 
storage  for  an  8 -user  MP/M  system  on 
one  card?  Either  one  ought  to  come  in 
around  $2500,  we  figure. 

A  Significant  Step 

Tandy  Corp.  has  been  making  a  num¬ 
ber  of  highly  significant  moves  this  fall. 
The  first  was  to  provide  bisync  communi¬ 
cations  support,  and  emulation  of  IBM 
and  DEC  bisync  workstation  and  terminal 
devices  (“Of  Interest,”  September).  The 
second  move  was  the  introduction  of  a 
communications  multiplexer  that  allowed 
a  TRS-80  Model  II  to  supply  local  net¬ 
work  services  to  16  satellite  VideoTex 
terminals  (“Of  Interest,”  October).  A 
third  was  the  recent  announcement  of  a 
hard  disk  for  the  Model  II. 

Now  Tandy  have  announced  that 
they  will  support  the  protocols  and  hard¬ 
ware  of  ARCNET,  a  local  network  archi¬ 
tecture  devised  by  the  Datapoint  corpora¬ 
tion.  ARCNET  seems  to  resemble  Xerox’s 
Ethernet  in  that  it  can  connect  large  num¬ 
bers  of  machines  cheaply  through  coaxial 
cables.  Unlike  Ethernet,  ARCNET  has 
been  in  commercial  use  since  1977.  A 
TRS-80  Model  II  is  linked  into  an 
ARCNET  by  the  addition  of  a  single 
interface  card  and  a  length  of  RG-62 
cable.  The  card  will  cost  “about  $400,” 
which  Tandy  claim  is  “significantly”  less 
than  an  Ethernet  interface.  Four  Model 
II’s  can  be  interconnected  through  a  $200 
junction  box;  larger  clusters  will  require 
an  active  junction  costing  “about  $2000.” 

Tandy  suggest  that  one  machine 
could  provide  hard-disk  file  services  to 
three  others,  the  others  being  used  simul¬ 
taneously  for  word  processing,  data 
entry,  or  what-have-you.  But  of  course, 
one  node  of  the  ARCNET  could  be  a 
VideoTex  server  providing  information 
retrieval  for  16  users.  Yet  another  could 
be  a  batch  workstation  connected  via  a 
bisync  line  to  an  IBM  or  DEC  mainframe: 
it  could  keep  its  input  and  output  job 
queues  on  the  hard  disk  run  by  the  file 
server.  Or  you  could  build  a  continent - 
spanning  bisync  network,  each  of  whose 
nodes  was  a  local  ARCNET  of  up  to  255 
Model  II’s.  In  fact,  we  can’t  think  of  any 
university  or  corporate  computing  need 
that  couldn’t  be  met  by  some  combina¬ 
tion  of  central  mainframe  and  such  a 
two-level  network. 

Taken  as  a  group,  these  moves  give 


Tandy  a  technological  base  from  which 
they  could  assault  markets  that  have  until 
now  been  the  province  of  IBM,  DEC,  and 
Data  General.  If  they  can  convert  that 
technical  lead  into  marketing  results,  they 
may  simply  run  away  from  the  rest  of 
the  micro  makers. 

Z89  Times  6  =  Z90 

Zenith  notified  us  that  they  are  ship¬ 
ping  double-density  double-sided  drives 
for  the  Z89.  The  present  Z89  (and  1189) 
drives  hold  100KB.  With  the  new  Z-89- 
37  double-density  disk  controller  card,  a 
standard  drive  becomes  soft-sectored  and 
so  can  hold  160KB.  The  controller  is 
priced  at  $395.  Its  real  use  is  in  driving 
the  new  Z-37,  a  box  containing  a  pair  of 
double-sided,  quad-density,  five-inch 
drives.  Each  drive  handles  80  tracks  per 
surface,  or  160  tracks  per  drive,  or  640KB 
of  data  per  drive.  The  dual  drive  unit  with 
its  1.3MB  total  capacity  is  priced  at 
$2000. 

An  upgraded  Z89,  containing  the 
new  disk  controller  and  64KB  of  RAM 
standard,  is  now  being  shipped  as  the  Z90 
model.  The  release  notes  that  the  disk 
controller  will  fit  an  H89,  but  it  doesn’t 
give  any  indication  of  what  these  desira¬ 
ble  enhancements  might  cost  under  the 
Heathkit  name.  Updates  for  both  HDOS 
and  the  CP/M  CBIOS  are  available. 

Bus  to  Bus 

D  &  W  Digital  tell  us  of  an  S-100 
board  that  sounds  interesting.  It’s  a  bus 
driver  for  the  IEEE-488  instrumentation 
bus.  The  centerpiece  of  the  S-100  card  is 
a  TMS  9914,  a  chip  that  handles  the  488 
protocol  in  any  of  the  Talker,  Listener, 
or  Bus  Controller  roles.  Other  board  cir¬ 
cuitry  maps  the  chip  to  8-bit  I/O  ports, 
and  provides  three  parallel  ports  besides. 
The  board  is  priced  at  $375.  Software 
drivers  written  in  M BASIC  are  provided. 

Lots  of  Dots 

Okidata,  hard  on  the  heels  of  Epson, 
have  come  out  with  a  dot-graphics  op¬ 
tion  for  their  Microline  82,  83,  and  84 
printers.  The  feature  consists  of  a  pair  of 
ROM  chips  which  are  “easily  installed  by 
the  user,”  and  are  supposed  to  be  avail¬ 
able  now  at  a  price  “under  $100.”  With 
the  feature  installed,  the  Microline  82  and 
83  printers  can  print  any  dot  on  the  page 
with  a  resolution  of  60  dots  horizontal 
and  66  vertical.  The  Microline  84  can  do 
72  by  72  dots  per  inch.  Software  tor 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


making  a  dot-for-dot  copy  of  the  screen 
of  an  Apple  is  included. 

Apple  Upgrades 

Here’s  another  way  to  print  the 
screen  of  an  Apple.  Orange  Micro  make  a 
smart  printer  interface  card  for  the  Apple 
(apple?  orange?).  At  heart  it  seems  to  be 
a  Centronics-type  parallel  interface,  but 
the  card  also  contains  on-card  firmware 
for  copying  the  high  resolution  graphics 
screen  to  any  of  several  dot -graphics 
printers.  The  Grappler,  as  they  call  it,  can 
print  the  screen  as  black  dots  for  white 
spots,  or  vice  versa,  or  double-sized,  or 
rotated  90  degrees.  It  is  also  said  to  sup¬ 
port  margins,  automatic  formfeeds,  and 
word-wrap.  The  only  thing  Orange  Micro 
omitted  to  tell  us  about  it  was  the  price. 

And  a  distributor  called  Computer 
Data  Services  tells  us  of  some  Apple  im¬ 
provements.  One  is  a  ROM  card  that 
supports  two  of  either  2K  ROMs,  or  4K 
ROMs,  or  2K  RAM  chips.  That  SI  25 
item  comes  with  a  utility  ROM  that  sup¬ 
ports  line  renumbering  and  several  other 
functions.  Another  is  a  32KB  RAM  card 
for  $239;  it  comes  with  software  that 
"will  automatically  relocate  DOS  into 
one  of  the  two  16K  banks  on  the  board.” 
That,  they  say,  allows  one  to  have  “Ap¬ 
plesoft  and  Integer  BASIC  and  DOS,  and 
48 K  to  program  with.”  We  don’t  speak 
Apple,  so  this  is  not  awfully  meaningful 
to  us  —  but  it  sounds  good. 

Yet  Another  XDIR 

There’s  a  diskette  of  CP/M  2  utilities 
to  be  had  for  S35  from  Elliam  Associates. 
The  featured  program  is  -  an  extended 
DIR.  This  one  displays  filenames  in  alpha¬ 
betical  sequence,  with  their  sizes.  It  takes 
advantage  of  CP/M  2  to  be  device  inde¬ 
pendent,  working  with  any  disk  type  or 
density  (about  time  we  saw  that  done). 
Other  programs  in  the  package  will  con¬ 
vert  a  PRN  file  back  to  ASM  source, 
make  a  symbol  table  for  SID  from  an 
ASM  listing,  and  so  on.  All  reminiscent  of 
programs  from  CPMUG.  but  if  they  have 
been  properly  upgraded  to  take  advantage 
of  CP/M  2  as  claimed,  they  are  worth¬ 
while. 

Speaking  of  CP/M  software,  our 
overseas  readers  might  like  to  know  about 
TCL  Software,  a  British  distributor  that 
seems  to  aim  at  being  the  kind  of  soft¬ 
ware  supermarket  in  the  UK  that  Life¬ 
boat  is  in  the  US.  Their  catalog  lists  a 
good  selection  of  CP/M  applications  and 


utilities  at  prices  comparable  to  those  in 
the  US,  and  they  carry  all  the  CP/M  Users 
Group  volumes. 

BASIC,  BASIC,  and  C 

Three  notices  of  interest  to  language 
buffs  came  our  way  this  month.  An  outfit 
called  BPS  (bits  per  second?  Bob,  Peter, 
and  Sam?)  has  built  a  listing  formatter 
for  Microsoft  BASIC.  The  SI  24  program 
has  two  functions:  it  converts  a  saved 
program  into  a  titled,  paginated  listing, 
and  it  creates  an  alphabetized  cross  refer¬ 
ence  of  program  names  to  the  lines  on 
which  they  are  used. 

Allen  Ashley  has  extended  his  COM¬ 
STAR  compiler  for  North  Star  BASIC  to 
provide  program  overlays.  “An  overlay 
differs  from  program  chaining,”  he  says. 


“in  that  a  root  program  segment  and 
selected  program  variables  can  survive  in¬ 
tact  as  a  new  program  segment  is  intro¬ 
duced.”  The  compiler  enhancement  is 
S75  to  present  users. 

And  JMI  has  recreated  a  memory- 
resident  executive  for  programs  in  C. 
That’s  run-time  support  for  everything 
except  file  I/O.  The  executive  supports 
multiple  tasks  with  intertask  communica¬ 
tion  and  formatted  I/O.  It  can  drive 
multiple  terminals.  The  executive  is 
written  “mostly”  in  C;  it  is  available  now 
for  the  DEC  LIS- 11  and  the  M68000, 
wih  8080  and  Z80  versions  in  prepara¬ 
tion.  The  price  is  S300. 

People  within  reach  of  San  Francisco 
who  want  to  know  more  about  C  and 
Unix  should  check  out  a  tutorial  and  con- 


Dr  Dobies  Journal 


Back 

Issues 

Available  for  $3.50 

IBM  PC,  it's 
still  hot  news 


CP/M-86  vs.  MSDOS:  A  Technical  Comparison 
Our  author  sets  the  two  operating  systems  for  the  IBM 
Personal  Computer  head-to-head,  to  see  which  comes  out 
the  winner! 

Word  Processors  for  the  IBM  Personal  Computer 

Reviewers  sample  some  of  the  latest  releases  in  this  ever- 
popular  application  of  computing  power. 

Video  Graphics  for  the  IBM  PC 

One  of  our  popular  writers  delves  into  the  details  (some 
not  clearly  documented  elsewhere)  of  high -resolution 
graphics.  This  advanced  material  is  carefully  introduced 
so  less  experienced  readers  won’t  be  lost. 

This  and  other  back  issues  are  available  for  $3.50 
from: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 


Dr.  Dobb’s  Journal.  Number  62,  December.  1981 


9 

523 


ference  to  be  held  by  Walter  Zintz’  Uni- 
Ops.  There  will  be  a  three-day  tutorial, 
January  11th  to  13th  1982,  followed  by 
the  group’s  “first  international  confer¬ 
ence.”  No  fees  are  mentioned  in  the  re¬ 
lease,  but  we  wouldn’t  assume  that  it  was 
free  until  we’d  checked. 

Info  for  Entrepreneurs 

Those  trying  to  make  it  as  indepen¬ 
dent  business  people  might  like  to  know 
about  some  information  sources  we  heard 
of.  Software  Wanted:  How  and  Where  to 
Sell  Your  Programs  is  the  title  of  a  report 
from  Battery  Lane  Publications.  They 
claim  to  have  gathered  information  from 
software  publishers  and  distributors  on 
the  kinds  of  programs  they  want,  the 
royalties  they  pay,  and  what  assistance 
they  offer  the  author.  The  $25  report 
covers  “over  60”  companies  and  is  sold 
with  a  money-back  guarantee. 

Hewlett-Packard,  like  T1  and  Atari, 


has  realized  the  value  of  third-party  soft¬ 
ware.  Now  HP  has  launched  a  program  to 
sell  third-party  software  for  its  line  of 
programmable  calculators.  Programs  will 
be  listed  in  a  single  catalog  with  HP- 
written  programs;  the  catalog  will  go  to 
all  HP  dealers.  Authors  who  qualify  for 
the  program  will  be  able  to  buy  HP  equip¬ 
ment  at  a  “significant”  discount.  The  re¬ 
lease  didn’t  give  a  mailing  address;  inter¬ 
ested  parties  should  call  Jack  Peters  di¬ 
rect. 

If  you  want  to  sell  to  computer  deal¬ 
ers,  and  if  you  have  an  Apple,  we  are 
about  to  make  your  day.  Learn  about 
Computer  Information  Systems,  that  have 
prepared  two  mailing  lists  on  Apple  II 
diskettes.  The  first  list  contains  “over 
800”  authorized  Apple  dealers  and  costs 
$150.  The  second  list  is  a  superset;  it  has 
the  Apple  dealers  and  some  800  more 
microcomputer  retail  outlets  “but  no 
Radio  Shack  stores.”  That  costs  $250. 


For  a  single  mailing  you  may  order  the 
lists  printed  on  gummed  labels  for  half 
the  above  prices,  but  that  would  clearly 
be  false  economy. 

If  you  are  a  consultant  or  a  buyer 
who  finds  it  hard  to  keep  up  with  the 
software  market,  you  may  get  some  re¬ 
lief  from  the  services  of  Transdata  Net¬ 
work  Telecommunications.  They  claim 
to  have,  on-line,  “The  equivalent  of 
50,000  pages  of  literature  on  hardware 
and  software.”  Their  release  confused  us 
a  bit,  but  it  seems  you  can  access  this 
data  in  one  of  two  ways.  You  can  estab¬ 
lish  a  credit  line  and  an  equipment  pro¬ 
file  with  them  and  then  ask  them  ques¬ 
tions  by  phone.  Or  you  can  rent  micro¬ 
fiche  copies  of  literature  —  the  manuals 
for  various  software  products,  for  in¬ 
stance  -  to  examine  for  yourself.  Each 
phone  query  is  $3;  ’fiche  rental  is  around 
$10. 

**J 


Contact  Points 

Allen  Ashley,  395  Sierra  Madre  Villa,  Pasa¬ 
dena,  CA  91 107;  (213)  793-5748. 

Battery  Lane  Publications,  POB  30214, 
Bethesda,  MD  20014;  (301)  770-2726. 

BPS,  82  Woods  End  Road,  I  airfield,  CT 
06430; (203) 254-1659. 

Computer  Data  Services,  POB  696,  Amherst, 
Nil  03031 ;  (603)  673-7375. 

Computer  Information  Systems,  218  llunt- 
ineton  Road,  Bridgeport,  CT  06608;  (203) 
579-0472. 

D  &  W  Digital,  1524  Redwood  Drive,  Los 
Altos,  CA  94022;  (415)  966- 1460. 


Elliam  Associates,  24000  Bessemer  Street, 
Woodland  Hills, CA  91367;(213)  3484278. 
Eventide  Clockworks,  265  West  54th  Street, 
New  York,  NY  10019;  (212)  581 -9290. 

JMI  Software  Consultants.  3  Neshaminy  In- 
terplex,  Trevosc,  PA  19047;  (215)  638- 
1112. 

Bill  Johnston,  c/o  Applied  Computing,  1 808 
Pomona  Drive.  Las  Cruces,  NM  88001. 
Okidata,  111  Gaither  Drive,  Mt.  Laurel,  NJ 
08054 ; (609)  235-2600. 

Orange  Micro,  3150  E.  La  Palma,  Suite  1, 
Anaheim,  CA  92806;  (714 )  630-3622. 


Jack  Peters,  Hewlett-Packard  Corvallis  (OR) 
Division;  (503)  757-2000,  extension  2207. 

TCL  (Transam  Components  Limited)  Soft¬ 
ware,  59/61  Theobald’s  Road,  London 
WC1 ;  01  -405-5240/21 1 3  (England). 
Transdata  Network  Telecommunications. 
1530  l  ast  Shaw,  Suite  117,  I  resno,  CA 
93714; (209) 227-0477. 

Walter  Zintz’  Uni-Ops,  POB  5182,  Walnut 
Creek,  CA  94596;  (415)  933-8564  morn¬ 
ings. 

Zenith  Data  Systems,  100  Milwaukee  Ave¬ 
nue,  Glenview,  IL  60025;  (312)  391-8181. 


D  &  W  Digital  bring  the  IEEE-488  bus  to  S-100  machines. 


10 

524 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


CP/M  BOOS 
and  BIOS  Calls 
v'  lor  C 


The  Game  of  Life 


much  more' 


Since  1976,  the  most  innovative  magazine  for  the  technically- 
sophisticated  microcomputer  user. 


YES!  Enter  my  subscription  to  Dr.  Dobb's  jour¬ 
nal  and  bill  me  later. 

name 

address 

city  state  zip 

Mail  to:  DDJ,  P.O.  Box  E., 

Menlo  Park,  CA  94025 


$25 

one  year  subscription 
12  issues 

saves  $5  off  the  newsstand  price 


Have  you  been  looking  for  a  magazine  that  will  provide  you 
with  serious  articles  on  programming?  Dr.  Dobb's  Journal  can 
give  you  the  technical  depth  you  need  to  understand  the 
latest  software  advances.  We  cover  every  microprocessor  with 
articles  on  C,  Forth,  Unix,  CP/M  and  much  more.  Our 
reputation  for  editorial  quality  is  well  known.  Subscribe  now, 
and  discover  what  industry  insiders  have  enjoyed  since  1976. 


Coming  articles  will  cover: 

•  new  language  development  •  compilers,  editors 

•  8-  and  16-bit  technology  •  assemblers/cross-assemblers 

•  operating  systems  •  clever  algorithms 


1983 


1976 


dr  dobbs  journal  of 


COMPUTER 


Calisthenics  O  ^)rthodontia 


Running  Light  without  Overb 


Dr.  Dobb’s  Journal 

For  Users  of  Small  Computer  Systems 


B  Tree  ISAM 
Concepts 


IBM  PC: 

Printing  Graphics 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Actors,  Property  Lists,  and 

Al  Language  Finds  Micros 


Complexity  is  the  superposition  of  simplicity;  it  is  the 
reduction  of  this  complexity  to  its  basis  in  simplicity 
that  is  the  goal  of  Artificial  Intelligence  (AI).  Even 
though  the  field  of  AI  is  a  tree  of  many  branches,  virtually  all 
in  the  field  speak  LISP,  a  list  processing  language.  LISP  allows 
fluent  use  of  property  lists,  a  data  structure  for  storing  infor¬ 
mation.  Actor  languages,  also  known  as  object-oriented  lan¬ 
guages,  are  eloquently  written  in  LISP. 

Actor  languages  are  languages  in  which  objects  communi¬ 
cate  by  the  sending  and  receiving  of  messages.  Each  actor  is  a 
member  of  a  class,  and  that  class  may  be  a  member  of  a  super¬ 
class,  and  so  on.  If  an  object  receives  a  message  to  which  it 
does  not  know  how  to  respond,  this  message  is  passed  on  to 
that  actor’s  class,  and  so  on,  until  an  actor  is  called  which  can 
respond. 

LISP  was  developed  in  the  early  1960’s  by  John  McCarthy 
as  a  recursive,  list -processing  language.  The  language  has  two 
types  of  objects,  atoms  and  lists.  An  atom  is  a  sequence  of 
alphanumeric  characters,  each  of  which  may  be  considered  a 
type  of  actor  in  the  language.  Lists  are  designated  by  left  and 
right  parentheses.  A  left  parenthesis  indicates  the  beginning  of 
a  list  and  a  right  parenthesis  signifies  the  termination  of  the 
list.  Lists  may  be  nested  to  any  level  of  complexity,  i.e.,  there 
may  be  lists  of  lists.  The  following  is  a  list  of  three  atoms: 

(IN  THE  BEGINNING) 
while  the  following  is  a  list  of  three  lists: 
((IN)(THE)(BEGINNING)) 

Property  lists  are  associated  with  atoms,  and  each  atom 
has  a  property  lists  which  allows  that  particular  atom  to  re¬ 
member  attributes  which  that  atom  may  have.  Properties  are 
accessible  through  the  use  of  an  indicator  which  itself  is  an 
atom.  The  properties  themselves  may  be  either  an  atom  or  a 
list  structure.  There  are  two  functions  in  LISP  which  allow  the 
manipulation  of  property  lists,  PUTPROP  and  GET. 

PUTPROP  provides  the  means  of  placing  properties  on 
atoms  under  a  specified  indicator.  PUTPROP  takes  three  argu¬ 
ments:  the  atom  receiving  the  property,  the  property  itself, 
and  the  indicator  under  which  the  property  will  be  stored.  The 
syntax  of  the  PUTPROP  function  is: 

(PUTPROP  atom  property  indicator) 

An  example  of  the  use  of  this  function  follows: 

(PUTPROP (QUOTE  APPLE) 

(QUOTE (FORBIDDEN  FRUIT)) 

(QUOTE  DESCRIPTION)) 

The  example  also  makes  use  of  another  LISP  function, 
QUOTE.  QUOTE  simply  means  that  what  follows  the  word 
QUOTE  is  to  be  taken  literally;  that  is,  APPLE  is  considered  as 
the  word  “apple”  not  as  some  function  named  APPLE.  The  re¬ 
sult  of  executing  the  above  example  is  to  put,  on  the  property 
list  of  the  atom  APPLE  under  the  indicator  DESCRIPTION, 
the  list  (FORBIDDEN  FRUIT). 

GET  provides  a  means  of  retrieving  the  property  once  it  is 
placed  on  the  atom.  GET  is  a  function  of  two  arguments,  the 
first  of  which  is  the  atom  to  be  investigated.  The  second  is  the 


by  Ronald  L.  Nicol 


Ronald  L.  Nicol,  LT.,  USN,  3102  Joyce  Drive,  Orlando,  FL 
32812. 


indicator  under  which  the  property  is  stored.  The  general  form 
of  the  function  GET  is: 

(GET  atom  indicator) 

An  example  of  the  use  of  this  function  follows: 

(GET(QUOTE  APPLEXQUOTE  DESCRIPTION)) 

Note  here  that  QUOTE  is  used  to  take  the  atoms  APPLE  and 
DESCRIPTION  literally.  The  result  of  the  example  will  be  the 
list  (FORBIDDEN  FRUIT).  If  no  property  is  saved  under  the 
requested  indicator,  GET  returns  the  atom  NIL. 

At  this  point  it  is  appropriate  to  discuss  the  form  a  pro¬ 
gram  or  function  takes  in  LISP.  By  necessity  this  discussion 
will  contain  only  a  subset  of  available  LISP  functions.  The  user 
builds  his  own  LISP  functions  by  using  the  functions  available 
in  the  basic  LISP  system  and  previously  defined  user  func¬ 
tions.  At  the  heart  of  the  user-defined  function  is  the  atom 
LAMBDA.  The  atom  LAMBDA  was  chosen  as  the  functional 
specifier  in  LISP  in  tribute  to  the  lambda  calculus  of  Alonzo 
Church.  The  general  form  of  a  user-defined  function  in  LISP 
is: 

(LAMBDA (variablesH text  of  function)) 
where  the  variables  specified  in  the  list  following  the  atom 
LAMBDA  are  variables  which  are  local  to  this  function.  The 
text  of  the  function  contains  previously  defined  user 
LAMBDA  functions  or  system  functions.  A  simple  function 
follows: 

(LAMBDA(X)(CAR  X)) 

Again  a  new  LISP  function,  CAR,  is  introduced.  CAR  returns 
the  first  element  of  the  list  which  is  its  argument.  The  above 
LAMBDA  function  will  return  the  first  element  of  the  list  it  is 
given  as  an  argument. 

Now  that  the  structure  of  a  LISP  function  has  been 
exposed,  it  is  necessary  to  have  a  way  in  which  to  assign  a 
name  to  a  particular  user-defined  function.  This  is  accom¬ 
plished  through  the  user  of  property  lists.  The  chosen  atom 
name  for  the  function  has  the  LAMBDA  expression  of  the 
function  placed  on  its  property  list  under  the  indicator  EXPR. 
The  LISP  system  knows  that  when  it  finds  a  list  under  the 
indicator  EXPR  on  an  atom  that  this  is  a  user-defined  func¬ 
tion.  For  example,  let  us  define  the  function  FIRST  which  re¬ 
turns  the  first  element  of  a  list. 

(PUTPROP (QUOTE  FIRST) 
(QUOTE(LAMBDA(X)(CAR  X))) 

(QUOTE  EXPR)) 

Now  the  function  FIRST  has  meaning.  Tracing  the  following 
entry  reveals  the  inner  workings  of  LISP: 

(FIRST(QUOTE(CHICKEN  OR  THE  EGG))) 

The  LISP  system  first  encounters  the  atom  FIRST  and  since  it 
is  not  quoted  it  is  assumed  to  be  a  function.  The  system  scans 
the  property  list  of  FIRST  and  finds  the  function,  (LAMBDA 
(X)(CAR  X)).  It  then  assigns  the  argument  to  FIRST,  which  in 
this  case  is  the  list  (CHICKEN  OR  THE  EGG),  the  local  varia¬ 
ble  X.  The  function  then  takes  the  CAR  of  the  argument  and 
returns  that  value  which,  in  this  case,  is  the  atom  CHICKEN. 

Another  important  system  function  in  LISP  isCDR.  CDR 
takes  one  argument  which  is  a  list  and  returns  a  list  which  is 
the  original  argument  with  the  first  element  removed.  At  this 
point  you  should  be  able  to  define  a  function  called  REST 
which  returns  a  list  with  its  first  element  missing.  Other  func¬ 
tions  are  defined  using  combinations  of  CAR  and  CDR.  For 
example,  CADR  is  the  CAR  of  the  CDR  of  a  list,  and  CDDR  is 
the  CDR  of  the  CDR  of  a  list. 


12 

526 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


LISP 


An  important  construct  in  LISP  is  the  function  COND. 
This  is  the  conditional  statement  in  LISP  and  is  similar  to 
BASIC’s  IF  .  .  .  THEN  .  .  .  ELSE.  The  general  form  of  COND 
is: 

(CONDfpl  el)(p2  e2)  .  .  .  (pn  en)) 
where  the  p’s  are  predicate  functions,  i.e.,  functions  which  re¬ 
turn  a  true  or  false  value  and  the  e’s  are  expressions.  When  the 
COND  function  is  executed,  the  predicates  are  tested  in  as¬ 
cending  order  and  when  a  particular  predicate  results  in  other 
than  a  false  value,  the  value  of  the  COND  is  the  corresponding 
expression.  For  instance,  if  pi  is  false  but  p2  is  not  false,  the 
value  of  the  COND  will  be  e2.  In  LISP  the  values  true  and  false 
are  represented  by  the  atoms  T  and  NIL  respectively.  By  way 
of  example: 

(COND((QUOTE  NIL)(QUOTE(FIRST  CLAUSE))) 
((QUOTE  T)(QUOTE(SECOND  CLAUSE)))) 
is  equal  to  the  list  (SECOND  CLAUSE)  because  NIL  is  the 
false  value  of  LISP  and  T,  of  course,  is  the  true  value.  In  LISP, 
certain  atoms  need  not  be  quoted,  among  these  are:  T,  NIL, 
EXPR.  LAMBDA,  and  a  few  others.  In  this  light,  the  above 
COND  may  be  written  as: 

(COND(NIL(QUOTE(FIRST  CALUSE))) 
(T(QUOTE(SECOND  CLAUSE)))) 

Some  of  the  other  LISP  functions  which  will  be  used 
throughout  this  article  are  presented  in  Table  1. 

And  All  the  World  is  a  Stage 

The  actor  language  which  will  be  developed  is  loosely 
based  on  a  subset  of  the  language  discussed  by  Kenneth  M. 
Kahn1 .  It  is  limited  but  is  easily  extensible,  and  for  the  sake  of 
clarity,  the  graphics  sections  of  the  language  will  not  be  dis¬ 
cussed. 

As  in  most  actor  languages,  the  concept  of  class  will 
become  very  important.  Only  one  actor  will  not  have  a  class 
and  that  is  the  actor  SOMETHING  which  is  at  the  top  of 
the  hierarchy.  In  this  particular  language,  each  actor  may  be  a 
member  of  one  class  and  of  course  that  class  may  be  a  member 
of  another  class,  etc . 

As  a  precursor  to  defining  the  first  actor,  it  is  necessary  to 
extend  the  LISP  GET  function.  GET  obtains  properties  only 
from  the  atom  which  it  is  given.  In  the  actor  environment,  if 
a  particular  actor  does  not  have  a  given  property,  the  class  of 
which  it  is  a  member  must  be  interrogated.  If  that  class  has  no 
property,  the  property  list  of  the  class  of  which  it  is  a  member 
must  be  checked,  and  so  on.  A  function  which  will  meet  these 
specifications  is  listed  below: 

(PUTPROP(QUOTE  GETANS) 

(QUOTE(LAMBDA(X  Y) 

(COND((GET  X  Y)(GET  X  Y)) 

((GET  X(QUOTE  CLASS))(GETANS 
(GET  X(QUOTE  CLASS))Y)) 

(T(LIST  X 

(QUOTE  HAS) 

(QUOTE  NO) 

Y))))) 

EXPR) 

This  function,  GETANS,  is  a  recursive  function,  i.e.,  it  is  a 
function  which  is  contained  in  its  own  definition.  This  is  one 
of  the  most  powerful  features  of  LISP,  and  a  most  interesting 
forte. 


The  above  PUTPROP  defines  the  function  GETANS.  It 
requires  two  arguments,  an  atom  and  an  indicator.  It  is  a 
COND  which  has  three  clauses,  each  of  which  responds  to  cer¬ 
tain  conditions.  The  first  clause  tests  to  see  if  there  is  a  proper¬ 
ty  on  the  atom  given  as  the  first  argument  under  the  indicator 
given  as  the  second  argument,  and  if  so  this  property  is  re¬ 
turned.  The  second  clause  calls  GETANS  with  the  same  indica¬ 
tor  but  with  the  class  of  which  the  first  argument  is  a  member. 
If  this  recursion  does  not  result  in  the  function  GETANS  find¬ 
ing  the  indicator  on  any  of  the  ancestors  of  the  first  argument, 
the  third  clause  will  cause  the  printing  of  a  message  which  in¬ 
forms  the  user  that  the  property  does  not  exist  in  the  blood¬ 
line  of  the  actor. 

Something  Exists 

It  is  now  time  to  define  the  first  actor  which  will  subse¬ 
quently  be  used  to  define  all  other  actors.  The  first  actor  is 
SOMETHING,  which  as  previoulsy  mentioned  is  at  the  highest 
level.  It  must  have  the  capabilities  to  create  and  destroy  actors, 
to  force  actors  to  remember  and  to  forget,  and  it  must  be  able 
to  interrogate  other  actors. 

So  that  SOMETHING  can  learn  other  traits,  it  must  first 
be  taught  to  remember.  SOMETHING  remembers  by: 

(PUTPROP(QUOTE  SOMETHING) 
(QUOTE(LAMBDA(MESSAGE) 

(PUTPROPtCAR  MESSAGE) 

(CADR(CDDR  MESSAGE)) 

(CAR(CDDR  MESSAGE))))) 

(QUOTE  REMEMBER)) 

After  the  above  is  entered,  SOMETHING  has  the  ability  to  re¬ 
member  whatever  the  user  desires.  To  make  SOMETHING  re¬ 
member,  the  input  is: 

(SOMETHING  REMEMBER  DAY  MONDAY) 

Before  SOMETHING  will  REMEMBER,  however,  it  is  ne¬ 
cessary  to  write  a  small  LISP  function  which  will  allow 
SOMETHING  to  receive  the  proper  orders.  The  function 
TRANSLATE  will  be  defined  as  given  in  Listing  1 .  Its  sole 
purpose  is  to  translate  input  supplied  by  the  user  to  informa¬ 
tion  which  the  collection  of  actors  can  use.  Note  that  once 
TRANSLATE  is  called,  it  continues  to  loop  and  await  input 
for  the  actors;  therefore  it  is  only  necessary  to  call  TRANS¬ 
LATE  once  at  the  beginning  of  the  conversation.  TRANS¬ 
LATE  uses  the  PROG  feature  of  LISP  which  is  a  mechanism 
for  iterative  programming  so  familiar  in  the  world  of  BASIC. 
The  general  format  of  a  PROG  is: 

(PROG(prog  variab)es)(sl  )(s2)(s3) .  .  .  (sn)) 
where  the  prog  variables  are  variables  which  are  local  to  this 
particular  PROG,  and  si  through  sn  are  LISP  statements  which 
will  be  executed  sequentially  unless  a  GO  statement  is 
encountered.  The  GO  statement  is  similar  to  the  GOTO  state¬ 
ment  in  BASIC  and  is  directed  to  an  atomic  label  which  is 
placed  before  a  statement. 

Thus  far  a  conversation  with  SOMETHING  would  consist 
of  entering: 

(TRANSLATE) 

(SOMETHING  REMEMBER  DAY  MONDAY) 

This  allows  SOMETHING  to  remember  that  the  property 
stored  under  the  indicator  DAY  is  MONDAY. 

Since  SOMETHING  can  now  remember,  it  is  useful  to  tell 
SOMETHING  how  to  make  new  actors.  This  is  accomplished 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


13 

527 


by  having  SOMETHING  remember  the  function  MAKE: 

(SOMETHING  REMEMBER  MAKE  (LAMBDA 
(MESSAGE) 

(PUTPROP(CAR(CDDR  MESSAGE)) 
(CAR  MESSAGE) 

(QUOTE  CLASS)))) 

The  function  MAKE  operates  by  placing  on  the  new  actor  the 
class  of  which  it  is  a  member,  under  the  indicator  CLASS. 
Therefore,  to  create  an  actor  named  OBJECT  the  following 
would  be  required: 

(SOMETHING  MAKE  OBJECT) 

This  creates  the  actor  OBJECT  which  is  a  member  of  the  class 
SOMETHING. 

Now  that  actors  can  remember  and  create  other  actors,  it 
is  desirable  to  ask  actors  what  they  know.  This  is  done  by 
teaching  SOMETHING  the  function  WHAT. 

(SOMETHING  REMEMBER  WHAT  (LAMBDA 
(MESSAGE) 

(PRINT(GETANS(CAR  MESSAGE) 

(CAR(CDDR  MESSAGE)))))) 

Actors  are  now  able  to  answer  the  question  “what”  as  illu¬ 
strated  by: 

(SOMETHING  WHAT  DAY) 
which  solicits  the  response  MONDAY.  Notice  also  that 
(OBJECT  WHAT  DAY) 

also  equals  MONDAY  because  the  function  GETANS  is  used 
in  WHAT,  and  OBJECT  is  of  the  class  SOMETHING. 

Occasionally  it  is  necessary  to  have  an  actor  forget  some 
information.  This  is  accomplished  through  the  use  of 
FORGET  which  is  created  as  follows: 

(SOMETHING  REMEMBER  FORGET  (LAMBDA 
(MESSAGE) 

(RF.MPROP(CAR  MESSAGE) 
(CAR(CDDR  MESSAGE))))) 

Now  an  actor  can  be  made  to  forget  anything  it  knows.  An 
exemplary  message  might  be: 

(SOMETHING  FORGET  DAY) 

Now  SOMETHING  will  not  know  that  the  day  is  Monday. 

Just  as  an  actor  might  need  to  forget  something,  so  also 
is  it  sometimes  necessary  to  destroy  an  actor.  Eradication  of 
an  actor  is  possible  with  the  use  of  UNMAKE  which  is  brought 
into  being  as  follows: 

(SOMETHING  REMEMBER  UNMAKE  (LAMBDA 
(MESSAGE) 

( RPLACD(CAR(CDDR  MESSAGE)) 
NIL))) 

This  has  the  effect  of  completely  removing  all  properties  from 
the  actor.  This  is  true  because  the  property  list  of  an  atom 
exists  as  its  CDR  and  replacing  the  CDR  of  the  atom  with  NIL 
removes  all  properties.  Sample  input  from  the  UNMAKE  func¬ 
tion  might  be: 

(SOMETHING  UNMAKE  OBJECT) 
which  results  in  the  actor  OBJECT  being  forgotten  by  the  sys¬ 
tem. 

The  Amoeba  and  Man 

One  method  of  simplifying  a  complex  system  is  to  sever  it 
into  smaller  components.  An  illustration  of  this  method  and  of 
the  newly  defined  actor  language  will  be  presented  in  the  field 
of  Biology.  Since  the  middle  of  the  eighteenth  century  when 
Carolus  Linnaeus,  the  Swedish  botanist,  wrote  Systema 


Naturae ,  man  has  been  attempting  to  place  all  living  things 
into  a  classification  scheme.  The  hierarchy  of  living  things  can 
be  considered  as  a  living  tree  with  each  of  the  branches  sharing 
certain  properties  of  the  limbs  from  which  it  sprouts. 

Of  course,  it  would  be  absurd  to  attempt  to  represent  all 
phyla  and  species  of  organisms  in  a  simple  program,  so  for  that 
reason  only  a  small  subset  will  be  considered.  It  is  hoped  that 
enough  information  will  be  available  to  give  a  taste  of  the 
method  and  a  flavor  for  why  this  particular  type  of  computer 
language  may  open  previously  closed  doors  in  information 
theory. 

The  technique  of  generating  the  actors  which  compose 
this  tree  of  life  is  represented  in  Listing  2.  A  survey  of  this  list¬ 
ing  will  indicate  the  conversational  flow  of  information  and  is 
not  unlike  the  teaching  of  a  child.  Once  all  descendents  of 
ORGANISM  have  been  told  what  they  need  to  know,  we  can 
interrogate  verious  organisms  and  the  uninformed  can  actually 
learn  significantly  from  the  actors  present. 

One  might  ask: 

(AMOFBA  WHAT  LOCOMOTION) 
which  will  promptly  be  answered  by: 

(MOVE  BY  MEANS  OF  PSEUDOPODS) 

The  question  then  arises,  do  just  amoeba  move  in  this  manner 
or  are  they  a  member  of  a  larger  class.  Therefore  one  might 
ask : 

(AMOFBA  WHAT  CLASS) 
which  solicits  the  response 
(SARCODINA) 

Now,  the  inquisitive  user  asks,  do  all  sarcodina  also  move  in 
the  way  that  the  amoeba  moves: 

(SARCODINA  WHAT  LOCOMOTION) 

Which  produces: 

(MOVE  BY  MEANS  OF  PSEUDOPODS  AND  A  FEW 
BY  FLAGELLA) 

So  it  is  now  clear  that  not  all  sarcodina  move  by  pseudopods. 
To  be  even  more  general,  the  class  of  the  sarcodina  can  be  de¬ 
termined 

(SARCODINA  WHAT  CLASS) 

and  the  answer  PLASMODROMA  will  be  given.  The  following 
dialogue  with  the  actors  might  ensue: 

User:  (PLASMADROMA  WHAT  LOCOMOTION) 
Computer:  (POSSESS  FLAGELLA  AT  SOME  STAGE 
OF  LIFECYCLE) 

User:  ( PLASMODROMA  WHAT  CLASS) 

Computer:  PROTOZOA 

User:  ( PROTOZOA  WHAT  CLASS) 

Computer:  ANIMAL 

User:  (ANIMAL  WHAT  CLASS) 

Computer:  ORGANISM 

User:  (ORGANISM  WHAT  CLASS) 

Computer:  SOMETHING 

Starting  with  man,  homo-sapien,  the  succeeding  conversa¬ 
tion  might  be  exemplary: 

User:  (HOMO-SAPIEN  WHAT  DIGESTIVE-SYSTEM) 
Computer:  (TUBULAR:  TWO  OPENINGS) 

User:  (HOMO-SAPIEN  WHAT  CELL-STRUCTURE) 
Computer:  (CELL  MEMBRANE) 

User:  (HOMO-SAPIEN  WHAT  EMBRYONIC -CELL- 
LAYERS) 

Computer:  THREE 


14 

528 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


ACTORS,  PROPERTY  LISTS,  and  LISP 


ALIST!  (1).  Number  of  areijnents*  none* 

(2) .  Type  of  arGuments!  not  applicable. 

(3) .  Value!  List  of  current  system  variables. 

APPLY!  (1).  Number  of  arguments!  3»  arguments  are  evaluated. 

(2) .  Type  of  arGuments ! 

(a) .  ArGument  1  must  evaluate  to  a  function. 

(b) .  ArGument  2  is  a  list  of  arGuments  for 

the  function  in  areument  1. 

(c) .  ArGument  3  is  the  ALIST  which  will  specify 

the  environment  in  which  the  application  of 
the  function  will  occur. 

(3) .  Value!  Result  of  applyiriG  the  specified  function 

to  the  specified  arGuments  in  the 
specified  environment. 

LIST!  (1).  Number  of  arGuments!  indefinite »  arGuments  are 

evaluated. 

(2) .  Type  of  arGuments!  lists  or  atoms. 

(3) .  Value!  list  of  evaluated  arGuments. 

REMPROP!  (1).  Number  of  arGuments!  2>  arGuments  are 

evaluated. 

(2) .  Type  of  arGuments!  atoms. 

(3) .  Value!  first  arGumentf  effect  is  to  remove  the 

property  which  is  the  second  aroument 
from  the  first  arGument. 

RPLACD!  (1).  Number  of  arGuments!  2?  arGuments  are  evaluated. 

(2) .  Type  of  arGuments!  first  and  second  arGument  is 

an  atom  or  a  list. 

(3) .  Value!  first  arGument  with  its  CDR  replaced  by 

the  second  arGument. 

SETQ!  (1).  Number  of  arGuments!  2i  the  first  arGument  is  not 

evaluated  but  the  second 
arGument  is  evaluated. 

(2).  Type  of  arGuments!  first  arGument  must  be  an  atom 

but  the  second  arGument  can  be  an 
atom  or  list. 

(3).  Value!  the  second  arGument?  the  effect  is  to  set 
the  atom  which  is  the  first  arGument  to 
the  second  arGument. 

Figure  I.  Additional  LISP  functions  used  by  the  actors  which  are  not  described  elsewhere  in  the  text. 


16 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 

529 


User:  (HOMO-SAPIEN  WHAT  CLASS) 

Computer:  PRIMATE 

User:  (PRIM  ATES  WHAT  CLASS) 

Computer:  MAMMALIA 

User:  (MAMMALIA  WHAT  SYMMETRY) 

Computer:  BILATERAL 
User:  (MAMMALIA  WHAT  LOCOMOTION) 
Computer:  (AT  LEAST  ONE  MOBILE  PHASE  IN 
DEVELOPMENT) 

User:  (MAMMALIA  WHAT  CLASS) 

Computer:  VERTEBRATA 

User:  (VERTEBRATA  WHAT  CLASS) 

Computer:  CHORDATA 

User:  (CHORDATA  WHAT  METABOLISM) 

Computer:  (ALL  DERIVE  FOOD  FROM  OTHER 
ORGANISMS) 

User:  (CHORDATA  WHAT  CLASS) 

Computer:  METAZOA 

Of  course,  the  above  cast  of  actors  can  be  expanded  and 
such  a  system  would  lead  to  a  much  more  complete  and 
meaningful  collection  of  facts.  Even  with  the  abbreviated  ver¬ 
sion  given,  it  is  apparent  that  interaction  with  the  various 
actors  can  lead  to  a  rewarding  learning  experience.  Through 
the  queries  directed  to  the  actors,  an  astute  student  would  be 
able  to  concentrate  on  the  similarities  and  differences  of  the 
various  organisms  and  it  would  certainly  be  possible  to  develop 
other  actors  which  could  ask  questions  which  might  generate 
parallels  not  previously  drawn  between  varied  organisms. 

Curtain  Call 

The  actor  language  discusssed  above  is  not  very  powerful 
by  virtue  of  its  simplicity.  It  can  be  expanded  upon  greatly 
by  the  use  of  a  pattern-matching  function  which  allows  the 
addition  of  the  IF  .  .  .  RECEIVE  message  and  a  syntax  which 
is  of  a  more  general  form.  Additionally,  graphic  functions  can 
be  added  so  that  actors  can  SHOW,  APPEAR,  ROTATE  and 
perform  other  motions  on  the  display  device.  An  excellent 
LISP  pattern  matcher  is  found  in  Artificial  Intelligence  by 
Patrick  Winston2 . 

Actor  languages  provide  a  new  perspective  to  Turing’s  idea 
of  the  incremental  computer  and  it  is  obvious  that  LISP  is  a 
superb  vehicle  for  this  generic  type  of  language.  The  general 
utility  of  LISP  is  not  limited  to  this  application  alone,  but  ex¬ 
tends  into  all  corners  of  the  Artificial  Intelligence  community. 
By  chipping  away  at  the  collective  bricks  of  intelligence  with 
tools  like  LISP,  we  will  soon  have  dissected  the  process  of 
thinking.  It  is  ironic  that  Artificial  Intelligence  itself  is  a  recur¬ 
sive  process,  the  mind  studying  the  mind. 

(Figure  II  and  III  on  following  page) 

References 

1  Kahn,  Kenneth  M.  An  Actor-Based  Animation  Language.  AI  Working 
Paper  #120.  Artificial  Intelligence  Laboratory.  Massachusetts  Insti¬ 
tute  ofeTechnology. 

2  Winston,  Patrick  Henry.  Artificial  Intelligence.  Addison  Wesley  Pub¬ 
lishing  Co.,  1977. 

Other  recommended  reading: 

Nicol,  Ronald  L.  Supersoft  LISP  Users  Manual.  Supersot't  Associates, 
1981. 

Siklossy,  Laurent.  Let ’s  Talk  Lisp.  Prentice-Hall  Inc.,  1976. 


You  Read 

Dr.  Dobb's  Journal 

And  You  Don’t 
Subscribe?! 


Save  $13 

off  newsstand  prices  for  2  yrs. 
Save  $5  for  1  yr. 


Can  you  afford  to  miss  an  issue  with 
information  vital  to  your  interests?  As  a 
subscriber  you  can  look  forward  to 
articles  on  Small-C,  FORTH,  CP/M,  S-100, 
Compiler  optimization,  Concurrent  Pro¬ 
gramming  and  more,  delivered  right  to 
your  door.  And  you’ll  never  miss  the 
issue  that  covers  your  project. 


DR.  DOBB’S  JOURNAL 
P.O.  Box  E 

Menlo  Park,  CA  94025 


Yes! 


Sign  me  up  for 
_  2  yrs.  $47 


1  yr.  $25 


_ I  enclose  a  check/money  order 

_ Charge  my  Visa,  MasterCard, 

American  Express 
_ Please  bill  me  later 

Name _ 

Address _ 


- Zip - 

Credit  Card  _ Exp.  date 

Account  No - 

Signature _ 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 

530 


17 


Letters  (Continued  from  page  4) 


drilling  out  the  memory  IC  expansion  lo¬ 
cations  on  the  logic  boards  to  prevent  the 
purchaser  from  expanding  their  computer 
to  32 K.  The  hardest  hit  by  this  is  schools, 
who  cannot  expand  them  themselves  to 
32  K  once  this  is  done,  I  know  of  several 
schools  who  purchased  these  units  and 
now  are  sorry  they  did.  This  I  feel  is  un¬ 
fair  to  purchasers  and  to  the  dealers  who 
sell  these  machines.  The  stores  have  to 
exchange  the  board  for  a  fully  expanded 
one  to  32K  at  a  cost  of  about  $500, 
passed  on  to  the  purchaser. 

These  type  of  schemes  by  microcom¬ 
puter  manufacturers  can  only  hurt  the 
industry  and  result  in  lost  sales,  not  only 
for  Commodore  but  for  other  manufac¬ 
turers  as  well. 

1  am  collecting  user  evaluations  of 
microcomputer  products  and  peripherals 
(printers,  terminals,  modems,  etc.).  Of 
special  interest  is  schemes  like  the  above 
for  prospective  purchasers  to  be  aware  of. 
I  expect  to  publish  my  results  if  I  get 


enough  responses. 

Sincerely, 

Harold  E.  Cohen 

c/o  HSC  Computer  Services,  Ltd. 

P.  O.  Box  43 

Brooklyn,  NY  11236 

Pascal  Peeve  .  .  . 

Dear  Marlin, 

1  have  just  finished  debugging  the 
Pascal  Prettyprinting  Program  that  is  in 
the  appendix  of  Pascal  With  Style  by 
Henry  Ledgard,  Paul  Naugn,  and  John 
Hueras.  After  fixing  all  my  typos  (no  easy 
task)  I  still  had  a  problem.  The  procedure 
SKIPSPACES  on  page  176  returned  ran¬ 
dom  numbers  for  the  number  of  spaces 
skipped.  Setting  the  variable  SPACESBE- 
FORE  equal  to  zero  on  entry  fixed  the 
problem.  Anyone  else  typing  in  the  pro¬ 
gram  might  like  to  know. 

By  the  way,  the  program  is  an  excel¬ 
lent  tool  that  illustrates  a  complex  pro¬ 
gram,  and  performs  a  useful  function.  I 


like  your  new  format,  and  think  the 
Clinic  is  a  great  idea. 

Sincerely, 

Jim  Shaw 
7021  N.  Park  Ave. 

Indianapolis,  IN  46220 

.  .  .  and  Praise 

Dear  Sir: 

I’d  like  to  let  my  fellow  DDJ  readers 
know  about  a  fine  software  product: 
Dynasoft  Pascal.  Dynasoft’s  version  of 
Pascal  is  a  tiny  Pascal  for  6800,  6809  or 
6502  computers  and  requires  only  12K  of 
memory  and  a  single  cassette  recorder. 
The  program  is  distributed  on  KC  or 
Apple  standard  cassettes  and  comes  with 
a  22- page  manual  and  a  4- page  supple¬ 
ment  for  the  particular  microprocessor 
used.  The  cost  is  only  $45  postpaid  from 
Dynasoft  Systems  Ltd.,  P.  O.  Box  51, 
Windsor  Junction,  Nova  Scotia,  Canada 
BON  2V0.  Dynasoft  can  accept  checks 
(Continued  on  page  34) 


Dr.  Dobb's  Journal 

For  Users  of  Small  Computer  Systems 


Each  issue  includes: 

•  valuable  software  tools 

•  algorithms  &  problem  solving 

•  industry  news 

•  important  product  reviews 

With  in-depth  coverage  of: 

•  telecommunications 

•  systems  programming 

•  language  development 

•  machine  independent 

programs 

and  much,  much  more! 

Yes!  Please  enter  my  subscription  for 

□  1  yr.  (12  issues)  $25  □  2  yrs.  $47  (save  $13  off  newsstand) 

□  Please  bill  me  □  I  enclose  check /money  order 

Name _ 

Address _ - 

City _ State _ Zip - 


Dr.  Dobb’s  Journal,  A  Publication  of  People’s  Computer  Company 
1263  El  Camino  Real,  P.O.  Box  E,  Menlo  Park,  CA  94025 


Are  you  ready? 

DDJ,  the  world’s  foremost  microcomputer 
publication,  has  been  working  for  years  to  pre¬ 
pare  its  readers  to  be  innovators,  to  lead  the 
wave  of  breakthroughs  in  our  changing  tech¬ 
nology. 

Every  issue  of  Dr.  Dobb ’s  Journal  helps 
one  to  understand  the  nuts  and  bolts  of  small 
computer  systems.  We  offer  entire  listings  of 
valuable  software:  our  pages  have  included 
compilers,  cross-assemblers,  editors,  new  lan¬ 
guages,  hardware  interfaces  and  more  —  usually 
before  anyone  else  thinks  of  them ! 


Even  more  important! 

Our  subscribers  share  insights,  correspond, 
and  contribute  to  one  another’s  work,  more 
than  any  other  group  we  know.  They  treat 
Dr.  Dobb 's  Journal  as  a  “hands-on”  publication. 

This  warm  cooperation  has  done  more  to 
refine  software  products,  and  generally  to 
advance  the  state  of  microcomputer  techno¬ 
logy,  than  perhaps  any  other  resource.  And  it  is 
available  to  you  through  our  pages ! 

For  the  straight  facts . 

If  you  are  a  serious  computing  professional 
or  enthusiast,  then  you  should  take  a  very  close 
look  at  what  DDJ  offers  you.  We’ve  been  on 
the  cutting  edge  since  1976. 


Dr.  Dobb’s  Journal.  Number  62,  December.  1981 
532 


19 


Marching  the  8080 

A  Simple  Memory  Chip  Tester 


This  paper  addresses  the  problem  of 
showing  that  a  microcomputer 
memory  is  functioning  properly. 
Virtually  every  microcomputer  user  is 
faced  with  this  problem  sooner  or  later, 
and  my  experience  indicates  that  few 
users  have  a  good  solution  available.  I  will 
describe  a  simple  and  powerful  basic  test 
program  which  I  adapted  from  a  memory 
chip  tester.  I  have  used  various  forms  of 
this  program  successfully  for  several  years 
on  several  systems. 

This  is  not  a  general  purpose  worst 
case  test,  such  tests  are  developed  with  a 
particular  system  in  mind.  Nevertheless, 
the  basic  test  of  correct  function  is  ade¬ 
quate  for  many  purposes,  and  an  under¬ 
standing  of  the  technique  will  provide  a 
starting  point  for  developing  more  strin¬ 
gent  tests. 

This  test  is  fast:  its  running  time  is 
only  proportional  to  the  size  of  the  mem¬ 
ory,  not  the  size  squared.  It  is  easy  to 
code,  requiring  about  20  to  30  bytes  of 
program.  Finally,  it  requires  that  the 
memory  have  the  specified  number  of 
separately  addressable,  correctly  operat¬ 
ing  bits  in  order  to  pass. 

Let  me  emphasize  the  last  claim  for 
this  test:  it  is  necessary  to  show  that  each 
bit  in  the  memory  operates  independent¬ 
ly  of  all  the  others.  Many  tests  ignored 
this  issue,  or  only  half  resolve  it  by  allow¬ 
ing  wrap  arounds  in  certain  cases. 

How  can  one  show  that  all  memory 
locations  are  separate?  In  larger  systems 
the  conventional  quick  test  is  a  store- 
address-as-data  pattern,  that  is,  at  each 
location  in  memory  write  the  address  of 
that  location,  then  go  back  again  to  each 
location  and  verify  that  it  contains  the 
correct  address.  This  test  is  effective  for 
machines  where  each  memory  word  can 
store  the  full  address  bit  pattern,  but  it 
doesn’t  work  for  4-  or  8 -bit  machines. 

The  simplest  approach  to  think  of 
in  this  latter  situation  is  probably  some¬ 
thing  like  the  following: 

•  Store  all  zeros  in  every  location  in 
memory. 

•  Go  to  the  first  location  and  change  it 
to  a  one. 

•  Now  check  all  the  other  locations  to 
see  if  they  still  have  zeros. 


by  James  Laurino 


James  Laurino,  414  S.  47th  St.,  Philadel¬ 
phia,  PA  19143. 


•  Finally,  restore  the  zero  to  the  first 
location  and  go  to  the  next  location. 

•  Apply  this  process  to  all  succeeding 
locations  until  the  whole  memory  has 
been  checked. 

This  shows  that  all  locations  can  store 
ones  and  zeros,  and  that  each  location 
functions  independently  from  all  the 
others. 

The  problem  in  using  this  test  comes 
from  its  long  running  time.  The  test  of 
each  location  requires  looking  at  all  the 
other  sites  once,  giving  a  total  test  time 
proportional  to  the  square  of  the  memory 
size.  Thus,  for  a  32K  memory  we  get  a 
test  time  proportional  to  215  squared,  or 
230,  approximately  a  billion  memory 
tests.  At  20  microseconds  a  test  (say  a 
five  instruction  inner  loop)  this  would 
take  about  20,000  seconds,  or  more  than 
five  hours. 

There  are  some  symmetries  we  can 
exploit  to  shorten  the  test.  For  instance, 
if  one  location.  A,  is  tested  and  shown  to 
be  functioning  independently  of  another, 
B,  then  when  the  time  comes  to  test  B  we 
can  omit  A  from  the  list  of  location  to 
check.  If  we  apply  this  simplification  sys¬ 
tematically,  we  eliminate  an  average  of 
half  of  the  checks. 

A  further  consequence  of  not  check¬ 
ing  A  after  it  has  passed  its  own  test  is 
that  we  no  longer  need  to  restore  the 
zero,  since  we  won’t  do  any  checks  here 
again.  This  saves  some  time  and  it  allows 
an  even  greater  simplification.  Many 
checks  can  be  performed  at  once. 

Consider  this:  since  location  A  is 
going  to  stay  one,  we  can  defer  checking 
B  for  any  change  until  the  most  conven¬ 
ient  time.  This  would  be  when  the  normal 
course  of  our  test  procedure  brought  us 
to  the  point  of  showing  that  B  was  inde¬ 
pendent  of  all  the  remaining  untested 
locations.  If  we  read  B  before  changing  it 
to  a  one,  and  if  we  find  it  still  a  zero, 
then  the  one  left  in  location  A  must  not 
have  affected  it  —  it  must  be  a  separate 
memory  cell  from  A.  In  fact,  since  all  the 
locations  tested  before  B  have  been  left 
ones,  we  have  shown  in  a  single  read  that 
B  is  different  from  them  all. 

The  next  step  in  the  test  is  to  make  B 
a  one.  If  we  now  proceed  to  the  next 
location  after  B  and  find  it  still  a  zero  we 
have  shown  that  it  in  turn  is  independent 
of  all  its  predecessors,  including  B. 

We  can  proceed  thus  through  the 
memory  checking  each  location  for  zero 
and  leaving  it  a  one  until  we  get  to  the 


end.  If  all  the  checks  are  passed  we  have 
shown  that  each  location  is  separate  from 
its  predecessors  and  from  its  successors, 
and  thus  that  they  all  function  separately. 

This  is  obviously  a  much  simpler  test. 
We  need  only  to  make  two  passes  through 
the  memory,  one  to  set  it  to  all  zeros,  and 
another  to  check  for  the  zeros  and  write 
the  locations  to  ones  as  they  are  checked. 
Thus  the  test  length  is  only  proportional 
to  the  memory  size  and  will  take  a  tolera¬ 
ble  time. 

There  are  many  variations  and  refine¬ 
ments  of  this  scheme  possible,  and  1  will 
discuss  some  of  the  ones  I  have  used  after 
I  demonstrate  the  coding  of  the  basic 
algorithm  for  the  8080. 

The  core  of  the  program  has  to  be 
two  successive  loops,  the  first  to  fill  the 
memory  with  the  starting  pattern  and  the 
second  to  check  the  pattern  and  com¬ 
plement  it.  A  high  level  description  would 
be: 

•  For  every  value  in  the  address  range: 
store  the  starting  pattern; 

•  For  every  value  in  the  address  range: 

check  that  the  starting  pattern  is 
still  there, 

complement  the  pattern. 

At  this  point,  two  other  kinds  of 
tests  need  to  be  considered.  The  first  is 
the  proof  that  each  bit  in  the  memory 
can  be  set  to  both  a  one  and  a  zero.  One 
way  to  do  this  would  be  to  read  each  lo¬ 
cation  after  it  had  been  complemented 
to  see  that  the  complement  pattern 
stored  correctly.  Another  way  would  be 
to  run  the  test  a  second  time  with  the 
complement  pattern  to  start.  The  other 
issue  is  to  show  that  all  the  bits  in  all 
memory  words  are  independent  of  each 
other.  We  can  resolve  both  issues  at  once. 
By  making  different  bits  in  the  word  as¬ 
sume  opposite  levels  we  show  they  are  in¬ 
dependent,  and  if  we  do  it  both  ways  we 
show  that  they  can  be  both  one  and  zero. 
For  an  8 -bit  machine,  a  simple  and  ade¬ 
quate  way  to  achieve  this  is  to  use  a  walk¬ 
ing  pattern,  that  is,  moving  a  single  one 
bit  through  successive  bit  positions  and 
repeating  the  test  for  each  of  the  8  pat¬ 
terns.  This  results  in  an  outer  loop  to 
generate  the  patterns. 

•  For  each  of  the  eight  patterns:  per¬ 
form  the  march  test  (as  above). 

I  have  coded  a  realization  of  this 
procedure  as  an  8080  assembly  language 


20 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 

533 


subroutine  below.  It  uses  all  registers  ex¬ 
cept  E.  For  speed  and  simplicity,  the  pro¬ 
gram  requires  that  addresses  start  and  end 
on  256  byte  boundaries,  or  in  other 
words,  that  the  low  address  byte  be  zero 
at  both  ends  of  the  range.  When  the  pro¬ 
gram  is  called,  B  must  contain  the  high 
byte  of  the  highest  address  in  the  range 
plus  one,  and  C  must  contain  the  high 
byte  of  the  lowest  address  in  the  range. 
For  example,  to  test  an  8K  memory  start¬ 
ing  at  zero,  C  would  contain  zero  and  B 
would  contain  20  hex.  D  is  used  to  hold 
the  current  test  pattern,  one  of  the  set, 
1,2,4,  etc.  up  to  80  hex. 

If  the  test  fails,  then  there  will  be  a 


line  A3  (23  )  were  stuck,  then  the  test 
would  fail  at  address  8.  Obviously,  you 
must  test  all  the  memory  at  once  if  you 
want  to  find  address  interactions. 

The  program  as  it  stands  is  designed 
to  be  small,  both  for  easy  hand  loading, 
and  to  make  the  main  points  obvious. 
Here  are  some  suggestions  about  the  ways 
that  the  program  can  be  extended. 

I  personally  usually  include  a  check 
of  each  location  once  it  has  been  comple¬ 
mented  (that  is  between  lines  14  and  15), 
because  this  is  needed  for  a  single  pattern 
test  and  because  I  once  found  a  problem 
this  way. 

When  a  longer  test  is  desired,  the  pro- 


MARCH  Subroutine 

upon  call:  B=  upper  limit,  C=  lower  limit. 


changes:  D.H.L.A,  Flags. 

upon  return:  Z  flag  set  if  test  passed. 


line 

label 

op 

arguments 

1 

START 

M  VI 

D,ONE 

2 

MVI 

L.ZERO 

3 

REPEAT 

MOV 

H,C 

4 

MOV 

A,B 

5 

FILL 

MOV 

M,D 

6 

INX 

H 

7 

CMP 

H 

8 

JNZ 

FILL 

9 

MOV 

H,C 

10 

CHECK 

MOV 

A,M 

1 1 

CMP 

D 

13 

CM  A 

14 

MOV 

M.A 

15 

INX 

H 

16 

MOV 

A.B 

17 

CMP 

H 

18 

JNZ 

CHECK 

19 

MOV 

A.D 

20 

RLC 

21 

MOV 

D,A 

22 

JNC 

REPEAT 

23 

RET 

31  bytes 


comments 

set  initial  pattern 

start  on  256  byte  boundary 

set  lowest  address 

setup  end  test  value  in  A 

store  pattern  in  current  location 

go  to  next  location 

check  for  end  of  range 

continue  till  end  reached 

set  lowest  address  again 

read  current  location 

compare  it  to  initial  pattern 

get  pattern  complement 

store  it  at  current  location 

go  to  next  location 

setup  end  test 

check  for  end  of  range 

continue  till  end  reached 

get  the  current  pattern 

generate  the  next  pattern 

save  next  pattern  in  D  again 

continue  till  bit  shifts  off  left  end 

then  done,  return  with  Z  set  by  last 

CMP  H 


non-zero  condition  upon  return,  H  and  L 
will  point  to  the  failing  location,  and  A 
will  have  the  bad  data  pattern. 

Many  failures  are  simple  to  diagnose. 
For  example,  if  one  address  line  is  stuck 
or  ignored,  then  memory  will  repeat  at 
an  interval  corresponding  to  the  binary 
weight  of  the  bad  address  line.  If  address 


gram  can  easily  be  changed  to  use  all  256 
possible  test  patterns  instead  of  only 
eight. 

When  the  check  scan  of  memory  is 
complete,  the  program  can  be  extended 
to  do  a  new  check  using  the  complement 
pattern  as  the  starting  data. 

It  should  be  clear  that  the  test 


doesn’t  depend  on  the  actual  sequence  in 
which  the  memory  locations  are  tested, 
and  another  order  may  make  a  more 
stringent,  but  slower,  test.  Similarly,  the 
data  pattern  needn’t  be  constant  but  can 
be  any  function  of  the  address. 

For  establishing  independence  be¬ 
tween  bits  in  a  very  wide  word,  it  would 
be  faster  to  divide  the  word  in  half  —  half 
the  bits  set  as  one,  and  half  as  zero  —  and 
then  divide  each  group  in  half  again,  etc. 

In  conclusion,  let  me  just  say  that 
this  technique  has  served  me  well  and  I 
hope  you  will  find  it  useful  in  solving 
your  own  memory  test  problems. 


Why  wait 
to  start 

increasing  your  sales? 
Call  now 
to  reserve 
advertising  space 
in  the  next 
Dr.  Dobb’s  Journal 
(415)  323-3111 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


534 


For  CP/M  BIOS 

An  Improved  MX-80  Printer  Driver 


The  Epson  MX-80  printer  is  certain¬ 
ly  one  of  the  better  printer  values 
on  the  market  for  the  small  system 
user.  1  feel  safe  in  saying  so  because  it’s 
also  one  of  the  hottest  selling.  But  no 
hardware  is  perfect,  and  the  MX-80  has 
a  few  peculiarities  worth  talking  about. 

No,  not  just  talking  about,  doing 
something  about,  because  by  using  a  sim¬ 
ple  software  driver,  and  by  taking  advan¬ 
tage  of  the  built-in  logic  of  the  printer, 
it  can  be  made  substantially  more  versa¬ 
tile. 

First,  a  little  background  about  the 
printer  itself.  In  a  call  for  help  in  Doctor 
Dobb’s  Clinic  (DDJ  #58),  Turner  Caldwell 
is  quoted  as  saying  “there  is  a  catch”  in 
the  printer  logic.  Mr.  Caldwell  states  that 
control  codes  embedded  in  the  text  are 
interpreted  differently  depending  on  the 
direction  the  bidirectional  print  head  is 
travelling.  Let’s  get  that  one  out  of  the 
way  first.  ’Tain’t  so. 

Oh,  they  may  be  interpreted  in  un¬ 
expected  ways,  but  it  has  absolutely  no¬ 
thing  to  do  with  the  direction  of  travel  of 
the  print  head.  The  printer  and  its  sup¬ 
port  logic  will  accept  data  bytes  from  the 
cpu  output  port,  buffering  all  characters 
until  a  carriage  return,  line  feed,  form 
feed,  or  vertical  tab  is  received,  or  until 
the  line  is  full,  which  forces  a  new  line. 
Only  then  is  the  physical  printing  per¬ 
formed.  The  direction  of  travel  of  the 
print  head  is  chosen  in  such  a  way  as  to 
minimize  the  travel  distance. 

How  does  it  work?  Very  well.  That’s 
all  we  need  to  care  about.  We  can  think 
of  each  line  as  being  printed  left -to -right, 
and  let  the  printer  logic  worry  about  the 
details.  One  point  is  important  to  the  fol¬ 
lowing  discussion,  however:  a  carriage 
return  is  merely  a  data  byte  which  in¬ 
structs  the  printer  to  print  the  buffer  con¬ 
tents,  if  any.  It  does  nor  return  the  car¬ 
riage.  For  example,  suppose  we  send  30 
spaces  to  the  printer,  a  carriage  return 
character,  another  29  spaces,  another 
carriage  return,  50  spaces,  and  so  forth, 
the  print  head  won’t  move  at  all.  We 
haven’t  sent  any  printing  characters  or 
line  feeds.  Until  there's  something  to 
print,  all  the  leading  spaces,  tabs,  and 
control  characters  just  tell  the  printer 
where  we  want  the  characters  to  go,  and 


by  Gary  P.  Novosielski 


Gary  P.  Novosielski.  21  W.  Pierrepont 
Ave.,  Rutherford,  NJ  0707U. 


what  we  want  them  to  look  like.  How  it 
gets  them  there  is  its  own  business. 

Contrast  this  with  the  actions  of  an 
early  generation  teletypewriter.  If  we  fed 
it  the  same  input,  the  print  head  would 
clatter  and  bump  across  the  line  printing 
nothing,  but  following  each  instruction  to 
the  “letter.”  The  result  is  the  same,  with 
one  important  difference.  All  that 
mechanical  motion  took  just  as  much 
time  as  if  we  were  printing  something. 
The  Epson  sat  there  silently  accepting 
characters  at  the  full  speed  of  the  parallel 
output  port  (which  is  pretty  darn  fast) 
and  just  smiled.  That’s  what  “smart  print¬ 
er”  means.  The  print  head  moves  only 
when,  and  only  as  far  as  necessary. 

Enough  background,  what’s  the  story 
on  the  control  characters?  Well,  to  be  fair 
to  Mr.  Caldwell,  the  MX-80  manual,  writ¬ 
ten  by  David  A.  Lein,  is  not  very  specific 
about  the  workings  of  these  codes.  This 
manual,  which  has  received  rave  notices 
in  all  the  product  reviews  I’ve  seen,  is 
described  as  a  “learner’s  manual,”  not  a 
“user’s  manual,”  and  unfortunately  that’s 
exactly  what  it  is.  It  is  written  in  an  ex¬ 
cessively  chatty  style,  aimed  squarely  at  a 
novice  computer  user  who  barely  knows 
his  way  through  a  simple  program  in 
Radio  Shack  Level  I  BASIC.  That’s  fine, 
but  when  you  want  a  straight  answer  to  a 
straight  question,  you  have  to  wade 
through  a  mound  of  sample  programs 
and  “gee-whiz”  commentary. 

The  plain  facts  on  control  characters, 
as  far  as  I  have  been  able  to  determine 
them  empirically  are  these: 

1 .  Double  Width  Characters 

(ON=CTRL-N;  OFF=CTRL-T) 

This  mode  causes  each  dot  of  each 
character  to  be  printed  twice,  causing  the 
character  to  occupy  two  print  columns. 
The  on  and  off  codes  can  be  embedded 
in  the  print  line  to  turn  the  mode  on  or 
off  for  specific  characters,  and  are  han¬ 
dled  properly  as  read  from  left  to  right, 
even  if  the  printer  decides  to  print  the 
line  backwards.  This  mode  is  reset  to  off 
automatically  when  a  physical  print  oper¬ 
ation  occurs;  i.e.,  when  the  carriage  re¬ 
turn  to  end  the  line  is  received.  The  pro¬ 
grammer  must  specifically  set  it  on  again 
if  multiple  lines  arc  to  be  printed  in  this 
mode.  The  implication  of  use  with  a  word 
processing  program  must  be  stressed  here. 
Since,  with  many  programs  the  user 
does  not  know  in  advance  where  in¬ 
dividual  print  lines  will  end,  the  only 
safe  method  of  printing  several  double¬ 
width  words  in  a  row  is  to  precede  each 


of  the  words  with  a  CTRL-N  character  in 
case  a  line  is  broken  between  the  words, 
which  would  set  the  mode  off  prema¬ 
turely. 

2.  Tab  characters  (CTRL-1) 

Tabs  are  handled  as  expected,  caus¬ 
ing  the  next  character  to  the  right  to 
print  at  the  next  tab  stop.  When  setting 
tabs,  the  bytes  following  the  ESC  “D”  are 
treated  as  7-bit  binary  numbers,  high 
bit  ignored.  The  sequence  is  terminated 
with  a  NUL  (00H  or  80H).  All  previous 
tab  stops  are  cleared.  The  first  column  of 
the  line  is  column  zero.  Obviously  you 
can’t  set  a  tab  stop  there.  If  no  tabset  se¬ 
quence  has  been  sent,  tab  characters  are 
ignored.  The  maximum  number  of  tabs  is 
said  to  be  11  2.  Try  though  I  might,  I  have 
been  unable  to  get  tabs  to  operate  while 
Double  Width  mode  is  turned  on.  They 
seem  to  be  ignored  totally  in  that  mode. 

The  above  codes  are  the  only  ones 
which  can  be  embedded  in  the  buffer  to 
affect  individual  portions  within  a  single 
line.  The  following  three  modes  all  work 
in  a  different  manner  from  the  above,  but 
similarly  to  each  other.  They  all  set  or 
reset  internal  flags  governing  the  printing 
of  the  buffer  as  a  whole,  and  are  not  ac¬ 
tually  embedded  in  the  buffer  at  all.  They 
can  occur  at  any  time  prior  to  physical 
printing  with  the  same  effect  regardless 
of  their  position  in  the  line.  The  most 
recently  transmitted  code  of  any  on/off 
pair  determines  the  condition  of  the  re¬ 
spective  flag.  The  flags  are  not  automa¬ 
tically  reset  at  the  end  of  a  line,  and  re¬ 
main  set  until  specifically  reset  by  the  off 
code. 

3.  Compressed  Printing 
(0N=CTRL-0;  OFF=CTRL-R) 

Causes  the  speed  of  print  head  travel 
across  the  page  to  be  reduced  by  a  factor 
of  1.65,  while  still  printing  characters  at 
the  normal  rate.  This  allows  132  charac¬ 
ters  to  fit  on  a  single  line,  which  normally 
holds  only  80  characters.  Although  I 
stated  above  that  these  commands  could 
occur  anywhere  in  the  line,  you  must  ob¬ 
viously  tell  the  printer  to  allow  for  more 
than  80  characters  before  sending  the 
81st  character.  Also,  if  Compressed  Print¬ 
ing  is  on,  and  is  then  turned  off  after 
more  than  80  characters  have  already 
been  received,  an  immediate  print  will  oc¬ 
cur  and  the  characters  past  column  80 
will  be  lost. 

4.  Emphasized  Printing 

(ON  =  ESC  “E”;  OFF=  ESC  “F”) 

When  set,  causes  all  characters  to 
have  twice  as  many  dots  in  the  horizontal 


24 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 

535 


For  Your  Personal 

REFERENCE 

COLLECTION 


Thousands  of  dollars’  worth  of 
microcomputer  information  and  listings! 


Dr.  Dobb’s  Journal  Vol.  V  -  All  the  ground-breaking  issues  from  1980  in  one  volume!  Sys¬ 
tems  software  reached  a  new  level  with  the  advent  of  CP/M,  chronicled  herein  by  Gary  Kildall  and  others 
( DDJ's  all-CP/M  issue  sold  out  within  weeks  of  publication).  Software  portability  became  a  topic  of  great¬ 
er  import,  and  DDJ  published  Ron  Cain’s  immediately  famous  Small-C  compiler  —  reprinted  here  in  full! 

Contents  include:  The  Evolution  of  CP/M,  a  CP/M-Flavored  C  Interpreter,  Ron  Cain’s  C  Compiler  for  the 
8080,  Further  with  Tiny  BASIC,  a  Syntax -Oriented  Compiler  Writing  Language,  CP/M  to  UCSD  Pascal 
File  Conversion.  Runtime  Library  for  the  Small-C  Compiler,  and,  as  always,  even  more ! 


direction  (four  times  as  many  if  Double 
Width  is  also  on  for  that  character),  but 
the  print  head  speed  is  cut  by  a  factor  of 
two,  so  the  characters  remain  their  nor¬ 
mal  (or  double)  width,  but  look  darker 
and  more  fully  formed.  The  manual  im¬ 
plies  that  the  print  wires  actually  hit  the 
paper  harder  in  this  mode,  which  is 
probably  rubbish. 

NOTE:  Compressed  and  Emphasized 
printing  cannot  both  be  in  effect  for  the 
same  line.  Apparently  the  print  head  has 
only  three  speeds:  Normal,  Normal/ 1.65, 
and  Normal/2. 

5.  Double  Strike  Mode 

(ON  =  ESC  “G”;  OFF=ESC  “H”) 

Each  line  is  first  printed  normally,  as 
determined  by  the  settings  of  the  above 
flags.  The  printer  then  does  a  micro  line¬ 
feed  (equal  to  one  dot  height)  and  the 
entire  line  is  then  overprinted,  doubling 
the  vertical  dot  count  without  appreci¬ 
ably  affecting  the  height  of  the  charac¬ 
ters.  One  would  expect  this  to  take  twice 
as  long  as  a  single-strike  line,  but  this  ac¬ 
tion  is  poorly  optimized  in  the  printer’s 
logic.  The  print  head  always  backs  up  to 
the  opposite  end  of  the  line  so  as  to  print 
the  second  pass  in  the  same  direction  as 
the  first,  thus  taking  up  to  three  times  as 
long  to  print  such  a  line. 

The  combined  effect  of  modes  4  and 
5  is  to  virtually  eliminate  any  space  be¬ 
tween  adjacent  dots  in  either  the  horizon¬ 
tal  or  vertical  direction.  This  produces 
practically  letter  quality  (if  somewhat 
boldface)  printeing,  wjth  an  associated 
speed  penalty  -  about  one  fifth  normal. 

Enough  control  codes  for  a  while. 
It’s  obvious  by  now  that  we  have  a  print¬ 
er  of  great  potential  here,  but  its  versa¬ 
tility  is  limited  by  the  all-or-nothing  ap¬ 
proach  of  modes  4  and  5.  Mode  3  (com¬ 
pressed)  would  normally  be  desirable 
only  for  entire  lines  of  pages  at  a  time, 
and  frankly  does  not  look  attractive  when 
mixed  with  non-compressed  characters 
on  the  same  line. 

But  it  would  be  nice  to  produce  an 
occasional  boldface  word  in  the  middle 
of  a  line  for  emphasis.  Double  Width 
mode,  which  can  easily  accomplish  this, 
has  a  touch  of  overkill  about  it. 

Since  it  would  be  nice,  let’s  do  it. 
Isn’t  this  the  computer  revolution  where 
all  is  possible?  One  way  out  is  the  follow¬ 
ing:  print  the  line,  but  leave  a  space 
where  the  boldface  word  belongs.  Send  a 
carriage  return,  but  leave  off  the  line  feed 
so  the  paper  doesn’t  advance.  Space  over 
to  where  the  empty  spot  is  (Hint:  reniem- 


Dr.  Dobb's  Journal  Vol.  I  -  The  material  brought  to- 
geiher  in  this  volume  chronicles  the  development  in  1976 
of  Tiny  BASIC  as  an  alternative  to  the  "finger  blistering" 
front-panel  machine-language  programming  which  was 
then  the  only  way  to  do  things.  This  is  always  pertinent 
for  bit  crunching  and  byte  saving,  language  design  theory, 
homebrew  computer  construction  and  the  technical 
history  of  personal  computing. 

Topics  include  Tiny  BASIC,  the  (very)  first  word  on 
CP/M.  Speech  Synthesis.  Floating  Point  Routines,  Timer 
Routines,  Building  an  IMSA1,  and  more. 


Dr.  Dobb's  Journal  Vol.  Ill  -  The  microcomputer  in¬ 
dustry  entered  its  adolescence  in  1978.  This  volume  brings 
together  the  issues  which  began  dealing  with  the  6502,  with 
mass-market  machines  and  languages  to  match.  The  authors 
began  speaking  more  in  terms  of  technique,  rather  than  of 
specific  implementations:  because  of  this  they  were  able 
to  continue  laying  the  groundwork  industry  would  follow. 
These  articles  relate  very  closely  to  what  is  generally 
available  today. 

Languages  covered  in  depth  were  SAM 76.  Pilot.  Pascal  and 
Lisp,  in  addition  to  RAM  Testers,  S-100  Bus  Standard 
Proposal.  Disassemblers,  Editors  and  much,  much  more. 


Dr.  Dobb's  Journal  Vol.  II  -  1977  found  DDJ  still 
on  the  forefront.  These  issues  offer  refinements  of  Tiny 
BASIC,  plus  then  state-of-the-art  utilities,  the  advent  of 
PILOT  for  microcomputers  and  a  great  deal  of  material 
centenng  around  the  Intel  8080,  including  a  complete 
operating  system.  Products  just  becoming  available  for 
reviews  were  the  H-8,  KIM-1.  MITS  BASIC.  Poly  Basic 
and  NIBL. 

Articles  about  Lawrence  Livermore  Lab's  BASIC,  Alpha- 
Micro.  Stnng  Handling,  Cyphers,  High  Speed  Interaction. 
I/O.  Tiny  Pilot  &  Turtle  Graphics,  many  utilities,  and 
even  more. 


Dr.  Dobb's  Journal  Vol.  IV  -  This  volume  heralds  a 
wider  interest  in  telecommunications,  in  algorithms,  and  in 
faster,  more  powerful  utilities  and  languages.  Innovation  is 
still  present  in  every  page,  and  more  attention  is  paid  to  the 
best  ways  to  use  processors  which  have  proven  longevity  - 
primarily  the  8080/ Z80,  6502,  and  6800  The  subject 
matter  is  invaluable  both  as  a  learning  tool  and  as  a  fre¬ 
quent  source  of  reference. 

Main  subjects  include:  Programming  Problems/Solutions, 
Pascal.  Information  Network  Proposal,  Floating  Point 
Arithmetic.  8-bit  to  16-bit  conversion,  Pseudorandom 
Sequences,  and  Interfacing  a  Micro  to  a  Mainframe  - 
more  than  ever! 


□  Please  send  me  the  following  Volumes  of  Dr  Dobb's  Journal  for  S20.75  each. 


YES!  □  ALL  5  for  ONLY  S88.  a  savings  of  over  159^! 


Please  charge  my  □  Visa 

1  enclose  □  Check/money  order 


□  MasterCard 


□  American  Express 


Card  -  _ 


-Expiration  Date_ 


Signature  . 

Name _ 

City _ 


_Zip_ 


Prices  subject  to  change. 

Mail  to:  Dr.  Dobb’s  Journal,  P.O.  Box  E,  Menlo  Park,  CA  94025 

Allow  6-9  weeks  for  delivery 


Vol.  I _ 

Vol  II  _ 
Vol.  Ill  _ 
Vol  IV_ 
Vol.  V_ 
ALL  5  _ 


.  x  S20.75  =  _ 
.  x  $20  75  =  _ 
.  x  $20.75  =  _ 
_  x  $20.75  =  _ 
_  x  $20.75  =  - 
-  x  $88  00  =  - 
Sub-total  S_ 


Postage  &  Handling  - 

Must  be  included  with  order. 

Please  add  SI. 25  per  hook  in  L  .S. 
($1.75  each  our  side  U.S.) 

TOTAL  $ _ 


Dr.  Dobb’s  Journal,  Number  62.  December,  1981 

536 


25 


ber  what  was  said  earlier  about  leading 
spaces).  Change  the  print  mode  to  em¬ 
phasized.  Send  the  boldface  word.  Send 
a  CR-LF  to  advance  to  the  next  line. 

That  seems  like  a  complex  way  out. 
The  printer  would  have  no  trouble,  just 
zip-zip  and  that’s  it.  The  problem  is  the 
programmer’s.  Quite  a  few  minutes  with 
a  printer  layout  sheet  would  be  required 
to  do  much  of  that,  and  if  we’re  using  a 
word  processing  program,  the  whole  thing 
goes  out  the  window  when  the  lines  get 
re-arranged,  justified,  and  what  have  you. 
What  we  need  is  a  way  to  send  control 
codes  in  a  conventional  left-to-right 
fashion  and  have  them  interpret  for  us 
automatically.  The  algorithm  above  is 
okay,  but  the  computer  should  do  the 
work. 

To  see  how  this  can  be  done,  let’s 
consider  first  a  related  fact  about  the 
MX-80: 

6.  Backspace  characters  (CTRL-H) 
Backspaces  are  ignored. 

Well,  that’s  unfriendly  to  say  the 
least.  It  tabs,  but  it  won’t  backspace.  Ac¬ 
tually  that’s  not  at  all  unusual  for  a  print¬ 
er  with  buffered  output  and  bidirectional 
printing  logic,  but  as  long  as  there’s  an 
underline  in  the  character  set,  a  back¬ 
space  is  no  luxury  item. 

Let’s  do  something  about  that  first. 
A  backspace  should  just  move  the  print 
head  one  space  backwards.  But  as  we’ve 
seen,  we  can’t  directly  tell  the  printer 
how  to  move  the  print  head.  We  can  only 
say  when  to  move  it,  and  that’s  only  a 
suggestion.  Therefore,  we  need  a  driver 
subroutine  (Listing  1)  which  will  inter¬ 
cept  the  backspace  character,  and  put  the 
appropriate  data  bytes  out  to  the  printer 
to  make  it  do  what  we  want  it  to.  Say  we 
are  at  column  N  and  want  to  back  up  one 
column.  We  tell  the  printer  to  print  the 
line  (the  first  part)  which  is  currently  in 
the  buffer.  We  do  this  by  sending  a  car¬ 
riage  return  but  no  line  feed.  This  will 
only  work,  by  the  way,  if  you  have  set 
the  internal  switches  to  suppress  automatic 
line  feed  insertion  after  carriage  returns. 
The  next  thing  is  to  get  back  to  column 
N-  1 ,  where  we  want  to  be.  We  send  N-  1 
spaces,  which  the  printer  takes  as  advice 
on  where  the  next  character  belongs. 

To  be  able  to  do  this,  the  subroutine 
needs  to  know  at  all  times  the  current 
position  in  the  output  line,  just  in  case 
the  next  character  turns  out  to  be  a  back¬ 
space.  So  we  have  to  count  printing  char¬ 
acters  and  spaces  as  we  send  them  out.  We 
don’t  count  control  codes  or  escape  se¬ 


quences.  We  have  to  be  careful  though. 
For  value  tests,  we  have  to  use  only  the 
seven  lower  bits  of  each  byte  for  compari¬ 
son,  since  the  printer  recognizes  control 
codes  with  or  without  the  high  bit  set; 
but  the  character  we  send  out  must  have 
all  8  bits  intact,  or  we’ll  never  be  able  to 
use  the  graphics  or  Katakana  chaaracters. 
Also,  within  escape  sequences,  e.g.,  set¬ 
ting  tab  stops,  some  of  the  data  bytes 
may  happen  to  resemble  printing  charac¬ 
ters,  but  the  counter  should  not  be  incre¬ 
mented. 

To  complicate  matters,  some  escape 
sequences  are  of  fixed  length,  while- 
others  are  of  variable  length.  The  Empha¬ 
sized  Printing  mode  for  example,  has  2 
characters.  Setting  form  length  takes 
three  —  ESC.  “C”,  n.  Where  n  is  the  num¬ 
ber  of  lines  per  page  in  7-bit  binary.  The 
same  for  ESC,  “A”,  n;  which  sets  verti¬ 
cal  line  spacing  (n  =  72/x;  where  x  is  in 
lines  per  inch).  But  vertical  tabstop  set¬ 
ting  may  have  up  to  64  n’s  in  the  se¬ 
quence  ESC,  “B”,  nl,  n2,  .  .  .,  nx,  NUL. 
In  this  case,  our  only  clue  is  the  occur¬ 
rence  of  the  NUL  at  the  end. 

It  turns  out  that  ESC  “B"  and  ESC 
“D”  (vertical  and  horizontal  tabset)  are 
the  only  variable  ones.  In  these  we’ll  just 
look  for  the  value  00  or  80H  to  signal  the 
end.  The  ESC  “A”  and  ESC  “C”  sequences 
are  three  bytes,  and  all  the  rest  (even  in¬ 
valid  ones  ignored  by  the  printer)  are  two 
bytes  long,  counting  the  ESC  itself. 

Tab  characters  must  also  be  properly 
counted.  It  would  be  feasible  to  intercept 
the  tabset  sequence,  store  the  values  in  a 
table,  and  on  receipt  of  a  tab  character, 
move  the  next  highest  table  value  into  the 
column  counter.  I  have  taken  a  simpler 
approach,  since  I  always  have  tabstops  set 
every  8  columns  for  compatibility  with 
normal  CP/M  conventions.  The  subrou¬ 
tine  has  a  one-shot  initialization  sequence 
which  sends  this  tabset  sequence  to  the 
printer  the  first  time  it  is  called,  and 
thereafter  it  assumes  that  a  tab  always 
positions  to  the  next  column  divisible  by 
8. 

The  characters  0A11  through  0D1I. 
i.e.,  line  feed,  vertical  tab,  form  feed,  and 
carriage  return  all  cause  printing  to  occur 
prior  to  any  paper  motion,  and  all  reset 
the  column  counter  to  zero  (in  the  print¬ 
er  as  well  as  in  the  subroutine).  Vertical 
tabs  are  treated  as  line  feeds  if  no  vertical 
tabstops  have  been  set.  There  is  no  need 
to  count  these  for  our  present  purposes. 
All  other  non-printing  characters  are 
merely  sent  to  the  printer  and  not  count¬ 


ed,  with  one  exception. 

The  final  character  to  be  considered 
is  one  chosen  from  those  normally  ig¬ 
nored  by  the  printer.  It  will  be  used  for 
the  purpose  of  printing  emphasized  or 
double  strike  words  within  a  line.  Since 
these  modes  normally  affect  an  entire 
line,  this  new  character  will  have  the  fol¬ 
lowing  conceptual  definition: 

“Causes  the  line  as  transmitted  so  far 
to  be  printed  according  to  the  current 
setting  of  the  mode  flags,  but  unlike  a 
carriage  return,  does  not  reset  the  column 
counter  to  zero.” 

For  the  purposes  of  transportability 
of  software  I  hereby  propose  a  STAN¬ 
DARD  character  for  this  purpose  for  use 
in  this  and  similar  MX-80  driver  software 
-  the  ASCII  “ETB”  (End  of  Text  Block) 
character  seems  the  natural  choice.  This 
is  the  CTRL-W  character,  17H  or  97H, 
which  presents  no  conflicts  with  CP/M 
line  editing  conventions. 

The  subroutine  does  not  pass  this 
character  to  the  printer,  but  simply  calls 
the  backspace  routine,  and  then  transmits 
one  space,  meeting  the  requirements  of 
the  definition. 

Usage  is  simple.  The  ETB  character 
is  embedded  in  the  text  just  prior  to  a 
mode  changing  command  which  is  intent- 
ed  to  apply  to  only  a  subsection  of  one 
line.  It  is  followed  by  the  mode  set  com¬ 
mand  itself,  and  the  characters  to  be 
printed  in  the  new  mode.  (It  is  not  re¬ 
quired  for  Double  Width  characters,  since 
they  are  already  handled  properly.)  An¬ 
other  ETB  is  embedded  just  prior  to  the 
mode  reset  command.  Use  of  this  embed¬ 
ded  character  method  should  make  use 
with  word  processing  programs  relatively 
simple.  It  also  has  the  advantage  that  it 
does  not  require  any  modification  to 
existing  MX-80  compatible  software.  If 
you  don’t  use  the  ETB  character,  the 
printer  performs  normally. 

Since  the  subroutine  is  intended  for 
use  in  the  BIOS  section  of  a  CP/M  sys¬ 
tem.  it  expects  to  find  the  character  in 
the  C  register.  The  subroutine  call  to 
PROUT  is  a  call  to  an  EPROM  resident 
routine  which  sends  the  character  in  the 
B  register  to  the  parallel  port  when  the 
ready  flag  is  true. 

If  is  is  not  practical  or  desirable  to 
use  it  in  this  way.  simply  write  a  replace¬ 
ment  for  PROUT  which  saves  the  regis¬ 
ters,  sends  the  byte  in  B  to  the  printer  via 
BDOS  call  or  whatever  method  is  used  in 
your  DOS,  restores  the  registers  and  re¬ 
turns.  Then  include  the  driver  in  the  ap- 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


27 

537 


plication  software.  I  chose  to  make  the 
installation  once  and  be  done  with  it 
rather  than  have  to  include  special  drivers 
in  every  piece  of  software,  some  of  which 
I  have  no  source  code  to;  PIP  for  in¬ 
stance. 

One  point  of  caution  is  required  if 
Double  Strike  mode  is  used  with  back¬ 
spacing  or  the  ETB  function.  Double 
Strike,  as  mentioned  earlier  does  a  1/72 
inch  line  feed  as  part  of  the  printing  func¬ 
tion.  This  causes  a  minor  misalignment  of 
the  remainder  of  the  line.  The  effect  is 
barely  noticeable  if  it  occurs  only  once  or 
twice  in  a  line,  but  can  add  up  if  incau¬ 
tiously  used.  In  backspacing,  the  follow¬ 
ing  method  is  preferred.  Backslashes  re¬ 
present  the  backspace  character. 

THE  WORDS  OP  CITWWW _ 

SHOULD  BE  UNDERLINED. 

This  causes  the  line  to  be  printed  in  only 
two  passes: 

THE  WORDS  OPCIT 


_ SHOULD  BE 

UNDERLINED. 

Consider  the  alternative  method  in 
which  the  backspace  character  immedi¬ 
ately  follows  each  character  to  be  under¬ 
lined. 

THE  WORDS  0\_P\_  C\_I\_T\_ 
SHOULD  BE  UNDERLINED. 

This  causes  six  passes: 

THE  WORDS  O 
_P 
_  C 
_I 
_T 

_  SHOULD  BE 

UNDERLINED. 

If  the  Double  Strike  mode  is  on  and  this 
second  method  is  used,  the  words  will 
seem  to  march  down  the  page  as  in  the  il¬ 
lustration,  though  not  as  exaggerated,  of 


course.  The  first  method  will  minimize 
this  effect.  If  a  text  processing  program 
is  used  which  automatically  breaks  up 
lines,  we  might  find  that  a  word  is  printed 
at  the  end  of  one  line  and  its  underlined 
characters  don’t  make  it  onto  the  same 
line.  To  avoid  this,  compromise  by  under¬ 
lining  each  word  individually: 

THE  WORDS  OP\\ _ CIT\\\ _ 

SHOULD  BE  UNDERLINED. 

This  ensures  that  a  word  and  its  underline 
form  a  contiguous  string  with  no  inter¬ 
vening  blanks.  In  this  example,  three 
passes  are  performed.  Actual  examples  of 
the  printing  are  shown  in  Figure  1. 

As  an  additional  aid  to  implementa¬ 
tion  of  applications  using  the  features  of 
the  MX-80,  here  are  a  few  points  which 
are  not  clearly  stated,  not  stated,  or  in¬ 
correctly  stated  in  the  manual. 

1.  The  form  length  is  remembered  inter¬ 
nally  in  terms  of  print  lines,  not 


Figure  I. 

I  his  is  an  example  erf  normal  SO  character  printing. 

It  is  possible  to  produce  Doub  .1  ts?  W  i.  c:i  til . i  characters  as  well. 

Coispressed  mode  allows  up  to  132  characters  per  line.. .......And  vou  can  produce  Double  Width  characters  in 

any  Mode. 

Emphasised  mode  allows  emphasis  of  an  entire  line  at  a  time. 

D  o  u  b  1  e  8 1  r  i  k  e  i  s  a  n  o  t  h  e  r  f  o  r  m  o  f  e  m  p  h  a  s  i  <•»  a  v  a  i  1  a  b  1  e . 


The  methods  may  be  combined  for  very  dark  printing. 

Wi th  addi t i onal  sof twar e „  backspacing 
and  under  1  i  n  i  ng  are  possible,,  and  it’s 

possible  to  use  several  of  the  modes  in  a  single  print  line. 


Examples  of  the  three  methods  of  underlining, 
problem  when  Double  Strike  mode  is  on: 

THE  WORDS  OP  CIT  SHOULD  BE  UNDERLINED. 


THE  WORDS  OP  CIT 
THE  WORDS  OP  CIT 

This  is  more  or 


SHOULD  BE  UNDERLINED. 
SHOULD  BE  UNDERLINED. 

1  e  s  s  s  e  v  e  r  e  d  e  p  e  n  d  i  n  g 


on 


the 


nere  is  a 


method  used .. 


smal  1 


(See  text,,) 


28 

538 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


inches.  If  the  number  of  lines  per  inch 
is  changed  in  mid- page,  a  form  feed 
will  not  properly  advance  to  the  top  of 
page,  since  the  same  number  of  lines 
now  take  up  a  different  number  of 
inches.  It  really  gets  loused  up. 

2.  You  can’t  remedy  the  situation  above 
by  changing  the  form  length.  Changing 
the  form  length  in  mid-page  also  resets 
the  counter  to  zero,  making  wherever 
we  are  the  new  top  of  form.  A  form 
feed  will  then  advance  to  the  same 
mid-page  spot  on  the  next  page.  The 
best  bet  is  to  only  change  form  length 
and  line  spacing  when  at  the  physical 
top  of  a  page,  or  else  count  all  your 
lines  in  software,  and  use  line  feeds  to 
position  the  paper. 

3.  The  control  codes  in  Appendix  B  of 
the  manual  for  line  spacings,  ESC  “0”, 
ESC  “1”,  and  ESC  “2”  are  the  ASCII 
characters  “0”,  “1”,  and  “2”,  i.e., 
30H,  3 1 H,  and  32H,  not  00H.  01H, 
and  02H  as  implied  in  the  appendix. 


Also,  ESC  “0”  and  ESC  “1”  have  no¬ 
thing  to  do  with  the  ESC  “A”  com¬ 
mand  as  is  stated. 

4.  The  CANCEL  code  does  nor  restore 
compressed  characters  to  normal 
width.  DEL  probably  doesn't  either, 
but  in  any  case  should  be  left  disabled 
via  the  configuration  switches.  The 
DEL  character  has  a  long  story  behind 
it  dating  back  to  punched  paper  tape. 
Printers  are  supposed  to  ignore  it. 
Make  sure  yours  does,  if  you  don’t 
want  a  headache  some  day  when  a 
piece  of  software  assumes  it  does. 

5.  Moving  on  to  Appendix  I,  the  form 
length  is  not  limited  to  66  lines.  I 
commonly  use  88  lines  per  page  with 
8  line-per-inch  spacing  and  it  works 
fine. 

6.  The  description  of  the  escape  codes 
states  properly  that  the  series  of  bytes 
in  tabset  sequences  are  treated  as 
seven-bit  binary  numbers.  It  then 


states  that  vertical  tabs  can  be  set  from 
line  1  to  255.  I  can’t  count  higher  than 
127  in  seven  bits. 

7.  Mr.  Lien  states  several  times  in  the 
text  that  double  width  characters  are 
turned  off  after  every  program  line. 
He  doesn’t  mean  print  line,  but  pro¬ 
gram  source  line.  He  makes  a  point  of 
that.  I  say  printers  can’t  tell  what 
program  line  you’re  in.  They  can’t 
tell  if  you’re  in  a  program.  They  can’t 
even  tell  if  its  a  computer  they’re 
hooked  up  to.  Double  Width  is  turned 
off  at  the  end  of  a  print  line.  Maybe 
there’s  a  bug  in  Radio  Shack  BASIC 
that’s  confusing  him. 

I’d  appreciate  hearing  of  any  prob¬ 
lems  with  or  enhancements  to  the  printer 
driver.  It  doesn’t  solve  every  problem,  but 
it  should  do  quite  a  bit  to  improve  the 
versatility  of  an  already  excellent  printer. 

(LISTING  ON  PAGE  30) 


Dr.  Dobb ’s  readers 

have  been  aiding  the  growth  and  development 
of  the  micro  field  for  years. 

If  you  would  like  to  make  a  contribution, 
contact  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


Dr.  Dobb’s  Journal,  Number  62.  December,  1981 


29 

539 


MX-80  Driver  (Text  begins  on  page  24) 


fl 

+ - 

— 

<1 

1 

MX-80 

PRINTER  DRIVER  ! 

m 

!  GARY 

P.  NOVOS I ELSK I 

• 

I 

n 

n 

f 

SOME 

USEFUL  EQUATES: 

00  IF 

= 

CTRL 

EQU 

'  '-1 

; CONTROL  KEY  MASK 

0000 

= 

NULL 

EQU 

CTRL  AND 

’ST 

; SOME  ASCII  DEFINITIONS 

0008 

= 

BS 

EOU 

CTRL  AND 

’  H' 

; BACKSPACE 

0009 

= 

HT 

EQU 

CTRL  AND 

’  I  ’ 

HORIZONTAL  TAB 

OOOA 

= 

LF 

EQU 

CTRL  AND 

’  J’ 

; L I NE  FEED 

000 B 

= 

VT 

EQU 

CTRL  AND 

’  K’ 

; VERT  I CAL  TAB 

OOOC 

= 

FF 

EQU 

CTRL  AND 

’L’ 

; FORM  FEED 

OOOD 

= 

CR 

EQU 

CTRL  AND 

’  M’ 

; CARRIAGE  RETURN 

OOOE 

= 

SO 

EQU 

CTRL  AND 

’  N’ 

; SHIFT  OUT 

0014 

= 

DC4 

EQU 

CTRL  AND 

’  T’ 

; DEVICE  CONTROL  4 

0017 

= 

ETB 

EQU 

CTRL  AND 

’  W’ 

: END  OF  TEXT  BLOCK 

0018 

= 

CAN 

EQU 

CTRL  AND 

’  X' 

; CANCEL 

00 1 B 

= 

ESC 

EQU 

CTRL  AND 

’  C  ’ 

; ESCAPE 

007 F 

= 

DEL 

EQU 

7FH 

; DELETE 

; INITIALIZATION 

STRING  FOR  PRINTER: 

0000 

80 

INITS 

DB 

NULL  OR  80H 

;  MAKE  SURE  NO  ESC  SEQUENCE 

: IS  IN  PROGRESS. 

000 1 

18 

DB 

CAN 

; CANCEL  ANYTHING  IN  BUFFER. 

0002 

1  B44 

DB 

ESC. ' D’ 

; START  THE  TABSET  SEQUENCE. 

0004 

08 1 0 1 82028 

DB 

8, 16.24,32,40, 

48,56,64,72,80 

OOOE 

5860687078 

DB 

88,96, 104 

,112, 

120 

00 1 3 

00 

DB 

NULL 

; END  THE  SEQUENCE. 

00 1 4 

oo 

PTRINIT 

DB 

0 

; INITIALIZATION  FLAG 

00 1 5 

oo 

F'ESCF 

DB 

o 

; ESCAPE  IN  PROGRESS  FLAG 

0016 

00 

PTRCHAR 

DB 

o 

; COLUMN  COUNTER 

0017 

00 

W I DEFLAG  DB 

o 

; DOUBLE  WIDTH  FLAG 

0000 

= 

4 

FALSE 

EQU 

o 

FFFF 

= 

TRUE 

EQU 

NOT  FALSE 

n 

; ENTRY 

TO  THE 

SUBROUTINE 

IS  MADE  HERE: 

LPTOUT : 

; ON  ENTRY 

.  CHARACTER  TO  BE  PRINTED  IS  IN 

; REGISTER 

C. 

00 1 8 

3A1400 

n 

LDA 

PTRINIT 

; SEE  IF  INITIALIZATION 

00 1 B 

B7 

ORA 

A 

; IS  REQURED. 

00 1C 

C23000 

JNZ 

INITD 

; JUMP  IF  NOT. 

00  IF 

2 1 0000 

LX  I 

H,  INITS 

; POINT  TO  THE  INIT  STRING. 

0022 

46 

INI  TP 

MOV 

B,  M 

; PUT  THE  CHAR  IN  B  REGISTER 

0023 

CDEEOO 

CALL 

PROUT 

; FOR  THE  OUTPUT  ROUTINE. 

0026 

78 

MOV 

A,  B 

; GET  BACK  THE  CHARACTER. 

0027 

OT 

X.  •_* 

INX 

H 

; POINT  TO  NEXT  CHARACTER. 

0028 

B7 

ORA 

A 

;  IF  WE  JUST  SENT  A  ZERO  (NUL) . 
; WE ’  RE  DONE, 

0029 

C22200 

JNZ 

INI  TP 

; ELSE  DO  SOME  MORE. 

002C 

3D 

DCR 

A 

; PUTS  OFFH  IN  THE  A  REG. 

00 2D 

321400 

STA 

PTRINIT 

; STORE  TRUE  IN  INIT  FLAG 
; SO  WE  DON’T  INITIALIZE  EVERY 
; TIME. 

; THE  PRINTER 

HAS  BEEN  INITIALIZED. 

0030 

41 

INI  TD 

MOV 

B ,  C 

; GET  CHARACTER  TO  BE  PRINTED 
; TO  THE  B  REGISTER. 

003 1 

79 

MOV 

A,  C 

; COPY  TO  A. 

0032 

E67F 

AN  I 

7FH 

; BUT  ONLY  LOW  SEVEN  BITS. 

0034 

4F 

MOV 

C,  A 

; SAVE  THE  STRIPPED  COPY  IN  C 
;FOR  COMPARISONS  LATER. 

0035 

3A1500 

LDA 

PESCF 

; SEE  IF  THE  ESCAPE  FLAG 

30 

540 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


0038 

0039 


003C 

003D 

003F 


0040 

0043 

0045 

0048 
004 A 
004 D 

0050 

0052 

0055 

0057 

005A 

005D 

005F 

0062 

0064 


0067 


0069 

006C 

006E 


007 1 
007 2 
0073 
0076 


0079 

00 7 A 
007D 
007E 

0081 

0082 


0085 

0088 

0089 


B7 

ORA 

A 

; I S  TRUE,  INDICATING 

C29D00 

JNZ 

PESCSP 

; WE  ARE  IN  THE  MIDDLE  OF  AN 
; ESCAPE  SEQUENCE. 

; ELSE  THIS  IS 

NOT  AN  ESCAPE 

SEQUENCE.  JUST  A  CHARACTER. 

79 

MOV 

A,  C 

; GET  STRIPPED  COPY  TO  A 

FE7F 

CPI 

DEL 

; IF  ITS  A  DEL, 

CS 

5 

RZ 

; IGNORE  IT  AND  RETURN. 

2 1 1 600 

LX  I 

H,  F'TRCHAR 

; POINT  TO  THE  CHARACTER  COUNTER 
; FOR  LATER. 

FE20 

CPI 

; CHECK  IF  THIS  IS  A  PRINTING 

D27900 

JNC 

PRTCHAR 

; CHAR .  IF  SO  PRINT  IT. 

; THIS  I 

S  A  CONTROL  CHARACTER 

CHECK  FOR  SPECIAL  CASES 

FE08 

CPI 

BS 

; BACKSPACE  CHAR? 

DAEEOO 

JC 

F'ROUT 

; ANYTHING  LESS  GOES  OUT  AS  IS. 

CAD200 

JZ 

PBS 

;  IF  EQUAL,  PROCESS  BACKSPACE. 

FE09 

CPI 

HT 

; TAB  CHARACTER? 

CA8500 

JZ 

PPTAB 

;  IF  SO,  PROCESS  IT. 

FEOE 

CPI 

SO 

; DOUBLE  WIDTH  SET  COMMAND? 

DA7100 

JC 

NEWLINE 

-.ANYTHING  LESS  MUST  BE  EITHER 
; LF ,  VT,  FF.  OR  CR.  HANDLE  IT. 

CAC500 

JZ 

SETWIDE 

;  IF  EQUAL,  SET  THE  FLAG. 

FE 1 4 

CPI 

DC4 

; DOUBLE  WIDTH  CLEAR  COMMAND? 

C AC BOO 

JZ 

CLRWIDE 

;  IF  SO,  CLEAR  THE  FLAG. 

FE  1 B 

CPI 

ESC 

; ESCAPE  CHARACTER? 

CA9500 

JZ 

F’ESCF' 

; INITIATE  ESCAPE  SEQUENCE 
; PROCESSING. 

FE  1 7 

CPI 

ETB 

; SPECIAL  CHARACTER  ETB  MEANS 
; DUMP  THE  BUFFER  BUT  DON" T 
; AFFECT  PRINT  POSITION. 

CAE AGO 

JZ 

F'ETBP 

FE  1 8 

n 

CPI 

CAN 

; CANCEL  MEANS  ERASE  THE  BUFFER. 

; AND  RESET  COUNTER. 

C2EE00 

JNZ 

PROUT 

; NONE  OF  THE  ABOVE.  JUST  SEND. 

NEWLINE 

S 

; A  CHARACTER 
; RESETS  THE 

HAS  BEEN  RECEIVED  WHICH 

COLUMN  COUNT. 

AF 

XRA 

A 

; A  CHEAP  ZERO 

~7  ~7 

MOV 

M,  A 

; TO  THE  COUNTER 

321700 

STA 

W I DEFLAG 

;  AND  THE  DOUBLE  WIDTH  FLAG 

C3EE00 

JMP 

PROUT 

;SEND  WHATEVER  IT  WAS  FROM 
; REGISTER  B. 

F’RTCHAR 

; A  NORMAL  PRINTING  CHARACTER  OR  SPACE 
; IS  GOING  OUT. 

34 

I  NR 

M 

; INCREMENT  COLUMN  COUNT 

3 A 1 700 

<1 

Lda 

W I  DEFLAG 

; IF  DOUBLE  WIDTH 

B7 

ORA 

A 

;  IS  OFF 

CAEEOO 

JZ 

PROUT 

;  PRINT  IT. 

34 

* 

I  NR 

M 

;  ELSE  INCREMENT  A  SECOND  TIME 
;  FOR  DOUBLE  WIDTH. 

C3EE00 

JMP 

PROUT 

;  AND  THEN  PRINT  IT. 

PPTAB:  ; PROCESS  A  TAB  CHARACTER 


3A1700 

LDA 

W I DEFLAG 

; IF  DOUBLE  WIDTH 

B7 

ORA 

A 

;  ISON 

C2EE00 

JNZ 

PROUT 

;  TAB  CHARACTERS  ARE  IGNORED 
;  FOR  SOME  UNKNOWN  REASON. 

( Listing  continued  on  next  page) 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


541 


MX-80  Driver 

(Listing  continued. 

ODBC  7E 

MOV 

A,  M 

008D  C60B 

ADI 

8 

008F  E6F8 

AN  I 

NOT  7 

0091  77 

MOV 

M,  A 

0092  C3EEOO 

JMP 

PROUT 

; ELSE  BET  THE  OLD  COLUMN  COUNT, 
;  ADJUST  TO  NEXT 

;  TAB  STOP 

;  AND  UPDATE  THE  COUNT. 

; SEND  HT  CHAR  TO  PRINTER. 


PESCP: 

; AN  ESCAPE 

CHARACTER  HAS  BEEN  RECEIVED 

; MAKE  A  NOTE 

THAT  A  SEQUENCE  IS  IN  PROGRESS. 

0095 

3EFF 

MV  I 

A, TRUE 

; PUT  ALL  ONES 

0097 

32 1 500 

STA 

PESCF 

;  IN  THE  ESCAPE  FLAG 

009A 

C3EE00 

» 

JMP 

PROUT 

;  SEND  ESC  TO  PRINTER. 

PESCSP: 

5 

PROCESS 

THE  NEXT  CHARACTER  OF  AN  ESCAPE  SEQUENCE. 

009D 

FEFF 

CPI 

TRUE 

; IF  THE  ESCAPE  FLAG  IS  ALL 
;  ONES,  WE  JUST  BEGAN, 

;  SO  THIS  MUST  BE  THE 

009F 

CAB800 

JZ 

SECOND 

;  SECOND  BYTE. 

;  ELSE 

THIS  IS  THE 

THIRD  BYTE  OR  MORE 

OOA2 

FE4  1 

THIRD 

CPI 

’A' 

; IF  THIS  IS  AN  ESC  A  SEQUENCE 

00A4 

CAB 1 00 

JZ 

LAST 

;  OR 

00A7 

FE43 

CPI 

’C' 

;  AN  ESC  C  SEQUENCE, 

00  A  9 

CAB 100 

JZ 

LAST 

;  THE  THIRD  BYTE  IS  THE  LAST. 

;  ELSE 

THIS  SEQUENCE  TERMINATES  WITH  A  NUL. 

OOAC 

79 

MOV 

A.C 

;SEE  IF  THIS  BYTE 

OOAD 

B7 

ORA 

A 

IS  A  NUL. 

OOAE 

C2EE00 

JNZ 

PROUT 

;  IF  NOT  WE’RE  STILL  WITHIN  THE 
; SEQUENCE. 

OOB 1 

AF 

LAST 

XRA 

A 

; LAST  ONE.  END  THE  SEQUENCE 
;  BY _ 

OOB2 

32 1 500 

NEXT 

STA 

PESCF 

;  ...UPDATING  THE  FLAG. 

OOB5 

C3EEOO 

SECOND: 

JMP 

PROUT 

; SEND  THE  BYTE  TO  THE  PRINTER 

; SECOND 

CHAR 

OF 

ESC  SEQUENCE. 

SEE  WHAT  THE  ID  CHARACTER  IS: 

OOB  8 

FE4 1 

CPI 

’  A' 

; A  THRU  D  ARE  3  OR  MORE  BYTES 

OOBA 

DAB 100 

JC 

LAST 

;  OTHERS  ARE  JUST  TWO 

OOBD 

FE45 

CPI 

’  E’ 

;  SO  WE  DON’T  SAVE  ANYTHING 

00  BF 

D2B100 

JNC 

LAST 

;  JUST  PUT  THEM  OUT. 

; FOR  THE  LONG  ONES,  WE  SAVE  THE 

00C2 

C3B200 

JMP 

NEXT 

; ID  CHARACTER  BY... 

•1 

SETWIDE 

J 

; A  CTRL-N 

HAS 

BEEN  RECEIVED. 

00C5 

32 1 700 

STA 

W I  DEFLAB 

; SET  THE  SOFTWARE  FLAG 

00C8 

C3EE00 

JMP 

PROUT 

;  AND  THE  HARDWARE  ONE. 

CLRWIDE 

2 

; A  CTRL-T 

HAS 

BEEN  RECEIVED. 

OOCB 

AF 

XRA 

A 

; CLEAR 

oocc 

321700 

STA 

W I  DEFLAG 

THE  SOFTWARE 

OOCF 

C3EE00 

JMP 

PROUT 

;  AND  HARDWARE  FLAGS. 

PBS: 

; PROCESS  A  BACKSPACE 

CHARACTER 

00  D  2 

AF 

XRA 

A 

; CLEAR  THE 

00D3 

32 1 700 

STA 

W I DEFLAB 

; DOUBLE  WIDTH  FLAG. 

00D6 

7E 

MOV 

A ,  M 

; GET  THE  COLUMN  COUNTER. 

00D7 

B7 

ORA 

A 

; IF  AT  LEFT  MARGIN,  NO  EFFECT. 

00  D  8 

C8 

RZ 

;  SO  FORGET  IT. 

;  ELSE 

00  D  9 

56 

MOV 

D.M 

; SAVE  COUNT  IN  D 

OODA 

35 

DCR 

M 

; BACKSPACE  THE  COUNT. 

OODB 

060D 

MV  I 

B,  CR 

; PRINT  THE  LINE  SO  FAR  BY  SEND- 
;  ING  A  CARRIAGE  RETURN 

OODD 

C DEE 00 

CALL 

PROUT 

;  TO  THE  PRINTER. 

; NOW  GET  READY  TO  SEND  SOME 

00  EO 

0620 

MV  I 

B,  ’  ’ 

;  SPACES. 

32 

542 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


PBS  1 : 


; SPACE  OVER  TO  WHERE  WE  BELONG. 

00E2  15  DCR  D  ;  DONE  YET? 

00E3  C8  RZ  ;  LEAVE  IF  SO 

00E4  CDEEOO  CALL  PROUT  ;  ELSE  PUT  OUT  A  SPACE. 

00E7  C3E200  JMF'  PBS1  ;  UNTIL  WE  GET  BACK  TO  WHERE 

;  WE  ONCE  BELONGED. 

n 

PETBP:  ; HANDLE  THE  ETB  CHARACTER.  DONE  SAME  AS  BS 

; EXCEPT  ONE  MORE  SPACE  IS  SENT. 

OOEA  34  I  NR  M  ;  ONE  MORE  SPACE 

OOEB  C3D200  JMP  PBS  ;  GO  TO  IT 

5 

OOEE  =  PROUT  EQU  * 

; THE  PROUT  ROUTINE  MUST  SEND  THE  CHARACTER 
; IN  THE  B  REGISTER  TO  THE  PRINTER,  AND 
; RETURN  ALL  REGISTERS  IN  THEIR  ORIGINAL 
; CONDITION,  EXCEPT  FOR  A  AND  FLAGS. 

; THE  FOLLOWING  IS  AN  EXAMPLE.  THE  LINES 
; BEGINNING  WITH  A  ”U"  CONTAIN  UNDEFINED  PORT 
; VALUES  WHICH  DEPEND  ON  THE  USER ’ S  INDIVIDUAL 
; HARDWARE. 

UOOEE  DBOO  IN  ST ATUSPORT 

UOOFO  E6QG  AN I  BUSYMASK 

OOF 2  C2EE00  JNZ  PROUT  ;  MAKE  IT  "JZ"  IF  THE  FLAG 

; BIT  IS  A  "READY" 

; RATHER  THAN  A  "BUSY”. 

OOFS  78  MOV  A, B 

UOOF6  D300  OUT  DAT AF'ORT 

OOF 8  C9  RET 


OOF  9 


END 


CTRL 

FALSE 

INITS 

NEXT 

PESCP 

PRTCHAR 

SO 


1 000000080 1 8 I B4408 1 O 1 820283038404850586089 
1 000 1 0006S707800000000003A 1 400B7C230002 1 78 
1 0002000000046CDEE007823B7C222003D32 1 400 1 6 
1 00030004 1 79E67F4F3A 1 500B7C29D0079FE7FC82F 
1 00040002 1 1 600FE20D27900FE0BDAEE00CAD200A6 
1 O 0 O 5 O O O F E O 9 C A 8 5 O OF E O E D A 7 1 00CAC500FE 1 4CA88 
1 0006000CB0GFE 1 BCA9500FE 1 7CAEAOOFE 1 8C2EEBE 
1 000700000AF7732 1 700C3EE00343A 1 700B7CAEE6C 
1 00080000034C3EE003A 1 700B7C2EE007EC608E6A 1 
1 0009000F877C3EE003EFF32 1 5OOC3EE0OFEFFCA44 
1 000A000B800FE4 1 CAB 1 00FE43CAB 1 0O79B7C2EE42 
1 OOOBOOOOOAF32 1 500C3EE00FE4 1 DAB 1 OOFE45D2BA 
1 OOOCOOOB 1 0OC3B2O032 1 70OC3EEO0AF32 1 700C355 
1 OOODOOOEEOO AF32 1 7007EB7C85635060DCDEE00E4 
1 00OEO0C0620 1 5C8CDEE00C3E20034C3D200DB0009 
09O0F 0O0E6OOC2EE0078D300C95D 
0  0 OOOOO O O 0 

End  Listing 


0008 

BS 

0018 

CAN 

OOCB 

CLRWIDE 

OOOD 

CR 

OOIF 

00 1 4 

DC4 

007F 

DEL 

00  IB 

ESC 

00 1 7 

ETB 

0000 

OOOC 

FF 

0009 

HT 

0030 

INI  TD 

0022 

INI  TP 

0000 

OOB 1 

LAST 

OOOA 

LF 

0018 

LPTOUT 

007 1 

NEWLINE 

OOB2 

0000 

NULL 

00D2 

PBS 

OOE2 

PBS  1 

0015 

PESCF 

0095 

00 9 D 

F'ESCSP 

OOEA 

PETBP 

0085 

F'F'TAB 

OOEE 

PROUT 

0079 

0016 

PTRCHAR 

0014 

PTRINIT 

00B8 

SECOND 

00C5 

SETWIDE 

OOOE 

00  A  2 

THIRD 

FFFF 

TRUE 

OOOB 

VT 

00 1  7 

W I DEFLAG 

Dr.  Dobb’s  Jourruil,  Number  62,  December,  1981 


33 

543 


Letters  (Continued  from  page  19) 


drawn  on  U.  S.  banks.  Also  available  is  an 
OEM  version  for  $85.  This  version  in¬ 
cludes  a  listing  of  the  p-code  interpreter 
and  a  license  to  distribute  the  interpreter 
and  software  in  p-code.  A  ROM  version 
is  available,  but  I  don’t  know  the  price. 

I  bought  the  SWTPC  6800  hobbyist’s 
version  of  Pascal.  The  package  actually  is 
a  complete  software  development  system 
for  microcomputers,  consisting  of  a 
supervisor,  editor,  Pascal  compiler  and  p- 
code  interpreter.  The  system  loads  up  to 
address  2160  hexadecimal,  leaving  about 
3.5K  free  in  a  12K  system.  This  is  com¬ 
fortable  for  medium-size  programs.  The 
supplied  tape  is  set  up  for  SWTPC’s 
SWTBUG  monitor  ROM,  which  I  have  on 
my  machine,  and  I  had  no  problem  in 
getting  the  tape  to  load  and  run.  Enough 
information  is  given  for  someone  with  a 
different  monitor  ROM  to  make  all  the 
patches  needed  to  get  Pascal  on  the  air; 
as  an  example  of  custom  I/O  routines, 
patches  to  use  the  JPC  Products  TC-3 
high-speed  tape  interface  and  CFM/3 
tape  file  management  system  are  included 
in  the  supplement  for  6800  computers. 

The  syntax  of  Dynasoft  Pascal  is, 
with  few  exceptions,  consistent  with  stan¬ 
dard  Pascal  within  the  subset  implement¬ 
ed  by  Dynasoft.  Variable  types  include 
INTEGER,  CHAR,  BOOLEAN,  SCALAR, 
SUBRANGE,  POINTER  and  ARRAY. 
This  Pascal  permits  long  variable  names, 
but  looks  at  only  the  first  4  letters;  there¬ 
fore,  BUFF  and  BUFFER  refer  to  the 
same  variable.  The  only  type  checking  is 
done  in  the  I/O  formatting  routines, 
which  means  that  INTEGER  values  may 
be  assigned  to  POINTERS  and  vice  versa. 
This  permits  building  linked  lists,  other¬ 
wise  impossible  because  this  version  of 
Pascal  lacks  the  RECORD  data  type.  Be¬ 
ing  able  to  assign  values  to  pointers  makes 
it  possible  to  directly  manipulate  memory 
locations  and  I/O  ports. 

Control  structures  included  in  Dyna¬ 
soft  Pascal  include  PROCEDURES  and 
FUNCTIONS,  which  may  be  declared  as 
FORWARD  or  EXTERNAL.  Facilities 
are  provided  for  passing  parameters  to 
machine-language  subroutines  via  the 
Pascal  parameter  stack.  Other  control 
structures  included  are  IF  . . .  THEN  . . . 
ELSE,  CASE  .  .  . OF . .  .  OTHERWISE, 
REPEAT  . .  UNTIL,  WHILE ...  DO  and 
FOR  .  .  .  DO.  Not  included  are  labels  and 
the  goto. 

To  me,  Dynasoft  Pascal  is  best  as  an 
inexpensive  way  to  learn  and  experiment 
with  Pascal.  The  supplied  manual,  while 


good  as  a  reference  to  Dynasoft  Pascal, 
doesn’t  qualify  as  a  teaching  tool  for 
novices.  A  look  in  the  local  B.  Dalton’s 
book  store  revealed  several  “how-to 
Pascal”  books,  any  of  which  would  be 
helpful  to  the  beginner.  An  experienced 
Pascal  user  would  find  Dynasoft  Pascal 
easy  to  use  —  just  the  thing  to  use  instead 
of  an  assembler  for  that  next  project.  A 
lot  can  be  done  in  Dynasoft  Pascal  and 
the  low  price  makes  up  for  Dynasoft’s 
limitations.  After  all.  I’d  have  to  pay  ten 
times  as  much  for  a  copy  of  the  UCSD 
system,  not  to  mention  the  far  more  ex¬ 
tensive  hardware  requirement.  Dynasoft 
Pascal  certainly  rates  a  “best  buy.” 

Very  truly  yours, 

William  R.  Hamblen 
946  Evans  Road 
Nashville,  TN  37204 


DDJ’s  responsive  readership  can  give  you 
invaluable  feedback  on  your  ideas  and  innova¬ 
tions.  Find  out  how  you  can  reach  them  by 
contacting  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


34 

544 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


Connect  a  Parallel 
Printer  to  Northstar 

More  on  the  MX-80 


I  would  like  to  share  my  recent  experi¬ 
ence  connecting  an  MX80  printer  to 
the  parallel  port  of  my  North  Star 
computer.  A  conversation  with  the  North 
Star  “hotline”  reaffirmed  my  belief  that 
the  “load”  pulse  available  on  the  spare 
pin  of  the  parallel  interface  was  too  short 
to  serve  as  an  output  strobe  for  the  MX80 
printer.  The  PO  (parallel  out)  flag  is  the 
wrong  polarity  to  serve  as  an  output 
strobe  so  I  was  left  with  either  a  software 
solution  or  a  hardware  modification. 

The  software  solution  suggested  by 
North  Star  involved  using  the  high  order 
bit  of  the  output  byte  as  the  output 
strobe.  To  output  to  the  printer,  three 
OUT  0  instructions  are  issued.  The  first 
is  with  the  high  order  bit  on,  the  second 
with  the  high  order  bi-t  off,  and  the  third 
with  it  on  again.  If  the  high  order  bit 


by  Alan  Bomberger 

Alan  Bomberger ,  3721  Starr  King  Circle, 
Palo  Alto,  C A  94306. 


from  the  parallel  interface  is  wired  to  the 
MX80  data  strobe  and  the  high  order  bit 
of  the  MX80  data  lines  is  tied  to  ground, 
the  result  is  correct  operation  of  the 
printer.  This  is,  in  fact,  the  way  North 
Star  has  written  the  parallel  output  rou¬ 
tine  in  its  DOS  system.  The  disadvantage 
is  that  no  graphics  are  possible. 

Since  I  wanted  to  use  the  graphics 
capabilities  of  the  MX80,  I  sought  a  hard¬ 
ware  solution.  My  CP/M  system  assumes 
that  the  existing  output  strobe  is  suffi¬ 
cient  to  operate  the  external  device  and  it 
uses  the  sequence  OUT  0,  “reset  parallel 
output  flag”,  expecting  the  acknowledge 
signal  to  set  the  parallel  output  flag.  The 
North  Star  “hotline”  suggested  that  I 
extend  the  pulse  on  the  spare  line  and  use 
it  for  the  printer  strobe.  There  is,  how¬ 
ever,  a  serious  problem  with  this  solution. 
If  interrupts  are  enabled  and  an  interrupt 
is  received  between  the  OUT  0  instruc¬ 
tion  and  the  “reset  parallel  output  flag”, 
the  system  may  hang  up.  The  hangup 
happens  when  the  interrupt  routine  takes 


enough  time  so  that  the  acknowledge  sig¬ 
nal  returns  from  the  printer  before  the 
“reset  parallel  output  flag”  instruction 
executes. 

There  are  two  solutions.  First,  the 
order  of  the  instructions  can  be  reversed 
so  that  the  Output  Flag  is  cleared  before 
the  OUT  0  instruction.  In  this  way,  the 
interrupt  will  only  delay  the  issue  of  the 
OUT  0.  Second,  the  PO  flag  can  be  used 
to  generate  the  output  strobe.  I  chose  the 
latter  as  it  made  no  difference  in  the 
hardware  needed  and  did  not  require  any 
changes  to  the  software. 

I  put  the  circuitry  necessary  to  gene¬ 
rate  the  output  strobe  in  a  small  utility 
box  with  some  status  indicators  and  a 
“RESET”  button.  The  reset  button  is  a 
handy  way  of  resetting  the  “TOP  OF 
FORM”  status  of  the  printer  without 
powering  it  off  and  on.  Since  power  is 
needed  for  the  circuitry,  I  cut  one  of  the 
three  ground  connections  to  the  parallel 
interface  connector  and  supplied  5  volts 
from  the  mother  board  instead. 

The  complete  circuit  diagram  is  at¬ 
tached.  It  is  very  simple  and  probably 
needs  no  explanation.  The  program  in¬ 
cluded  is  one  that  1  use  to  set  the  printer 
mode  of  operation  as  well  as  exchange 
the  “PRINT”  and  “PUNCH”  functions  of 
my  CP/M  system.  This  allows  me  to  use 
either  the  serial  or  parallel  port  for 
PRINT  functions  without  changing  any 
applications.  The  IOBYTE  would  serve 
the  same  purpose  if  it  was  implemented. 
The  program  prompts  the  console  for 
various  combinations  of  print  modes  and 
sets  the  printer  TAB  stops  to  the  CP/M 
standard. 

I  hope  this  note  will  make  it  easier 
for  others  to  connect  parallel  printers  to 
their  North  Star  computers. 

(LISTING  ON  PAGE  38) 


Data  \ 
Lines 


OUTBOARD  MX80  INTERFACE  for  NORTH  STAR 


North  Star 

10k  > 

<  .001 

r^i 

MX80 

PO 

B  R/C  l'  * 

STROBE 

r 

1/2  74123 

A 

Data 

Lines 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 


35 

545 


NorthStar  Parallel  Printer 

(Text  begins  on  page  35) 


;  print  setup  prograa 
;  swaps  the  list  and  punch  juap  addresses 

I  and  sets  up  the  ax80  printer  aodes 


.8080 

0005 

bdos  equ 

5 

0000 

boot  equ 

0 

0005 

list  equ 

5 

0009 

pstring  equ 

9 

Q00A 

rstr ing  equ 

10 

0018 

esc  equ 

27 

000D 

cr  equ 

Odh 

000A 

If  equ 

Oah 

0000* 

start: 

0000’ 

11  00FE ’ 

lxi 

d.aswap 

1  ask  about  swap 

0003’ 

0E  09 

avi 

c,pstnnq 

0005* 

CD  0005 

call 

bdos 

0008’ 

CO  01AC’ 

call 

answer 

000B  ’ 

C2  0029’ 

jnz 

askenh 

\  no  next  question 

000E  ’ 

2A  0001 

! 

1  hi  d 

boot*l 

1  get  juap  table  address 

ooi  r 

16  00 

avi 

d,0 

0013’ 

IE  00 

avi 

e,  13 

;  this  is  where  list  address  is 

0015’ 

19 

dad 

d 

0016’ 

4E 

aov 

c,a 

;  get  address 

0017' 

23 

inx 

h 

0018’ 

46 

aov 

b,a 

1  into  be 

0019’ 

23 

inx 

h 

;  skip  c3 

001  A' 

23 

inx 

h 

;  now  at  punch  address 

00 1 B ' 

7E 

aov 

;  pick  up  punch  address 

001C’ 

71 

aov 

a,c 

:  put  in  list  address 

001 D’ 

4F 

aov 

c,a 

;  and  save 

001E* 

23 

inx 

h 

001F  ’ 

7E 

aov 

*.« 

i  rest  of  punch  address 

0020’ 

70 

aov 

a,b 

0021’ 

47 

aov 

b,a 

0022’ 

2A  0001 

1  HI  d 

boot*l 

0025’ 

19 

dad 

d 

;  point  to  list  address  again 

0026’ 

71 

aov 

a,c 

;  put  in  punch  address 

0027' 

23 

inx 

h 

0028’ 

70 

aov 

a,b 

;  finish  swap 

i 

;  noa  see  what  setup 

0029’ 

» 

askenh: 

0029’ 

21  0136’ 

lxi 

h.nenhan 

;  turn  off  enhanced  aode 

002C  ’ 

CD  019C’ 

call 

prout 

002F  ’ 

11  009A’ 

lxi 

d,aenhan 

;  enhanced  aode7 

0032’ 

0E  09 

avi 

c,  pstring 

0034’ 

CD  0005 

call 

bdos 

;  proapt 

0037’ 

CO  01AC’ 

call 

answer 

i  get  answer 

003A’ 

C2  0043’ 

jnz 

askeap 

0030’ 

21  0146’ 

lxi 

h.enhan 

0040’ 

CD  019C’ 

call 

prout 

5  set  up  printer 

0043’ 

askeap: 

0043’ 

21  0139’ 

lxi 

h,neapha 

:  turn  off  eaphasized  aode 

0046’ 

CD  019C’ 

call 

prout 

0049’ 

11  0082’ 

lxi 

d.aeapha 

004C  ’ 

OE  09 

•vi 

c, pstring 

004E’ 

CD  0005 

call 

bdos 

:  proapt 

0051’ 

CD  01AC’ 

call 

answer 

0054’ 

C2  005D* 

jnz 

askeond 

0057’ 

21  0149’ 

lxi 

h.eapha 

005A’ 

CD  019C 

call 

prout 

0050' 

askeond: 

0050’ 

21  01 3C ’ 

lxi 

h,ncond 

0060’ 

CD  019C ’ 

call 

prout 

;  turn  off  condensed  aode 

0063' 

11  OOCC’ 

lxi 

d,acond 

0066’ 

OE  09 

avi 

c, pstring 

0068’ 

CD  0005 

call 

bdos 

006B’ 

CD  01  AC’ 

call 

answer 

006E' 

C2  0077’ 

jnz 

askpap 

0071’ 

21  0144’ 

lxi 

h.cond 

0074’ 

CD  019C’ 

call 

prout 

0077' 

askpap: 

0077’ 

21  0141’ 

lxi 

h, piper 

;  set  paper  warning 

007A' 

CD  019C’ 

call 

prout 

0070’ 

11  OODE’ 

lxi 

d,apaper 

1  ask 

0080’ 

OE  09 

avi 

c, pstring 

0082’ 

CD  0005 

call 

bdos 

0085’ 

CD  01  AC’ 

call 

answer 

0088’ 

C2  0091’ 

jnz 

set  tab 

0088’ 

21  013E’ 

lxi 

h,npaper 

5  reset  paper  warning 

0O8E’ 

CD  019C’ 

call 

prout 

0091’ 

settab: 

0091’ 

21  0123’ 

lxi 

h,  tabs 

0094* 

CD  019C’ 

call 

prout 

0097' 

C3  0000 

J*P 

boot 

009A’ 

OD  OA  64  6F 

1 

aenhan:  db 

cr,lf, 'double  vertical?  v/n  $• 

009E’ 

75  62  6C  65 

00A2  ’ 

20  76  65  72 

OOA6  ’ 

74  69  63  61 

OOAA’ 

6C  3F  20  79 

OOAE' 

2F  6E  20  24 

0082’ 

OD  OA  64  6F 

aeapha:  db 

cr, If, 'double  horizontal?  y/n  1' 

0086' 

75  62  6C  65 

OOBA’ 

20  68  6F  72 

008E ' 

69  7A  6F  6E 

OOC2’ 

74  61  6C  3F 

OOC4’ 

20  79  2F  6E 

OOCA’ 

20  24 

OOCC' 

OD  OA  63  6F 

acondi  db 

cr, If, 'condensed7  y/n  t' 

OODO’ 

6E  64  65  6E 

0004’ 

73  65  64  3F 

0088’ 

20  79  2 F  6E 

OODC’ 

20  24 

OODE’ 

OD  OA  73  75 

apaperi  db 

cr, If, 'suppress  paper  out  bell?  y/n  t' 

OOE2’ 

70  70  72  65 

00E6’ 

73  73  20  70 

OOEA’ 

61  70  65  72 

OOEE' 

20  6F  75  74 

00F2’ 

20  62  65  6C 

OOF6' 

6C  3F  20  79 

OOF  A' 

2F  6E  20  24 

OOFE’ 

OD  OA  73  77 

aswap:  db 

cr, If, 'swap  list 

and  punch  function?  y/n  »' 

0102’ 

61  70  20  6C 

0106’ 

69  73  74  20 

010A’ 

61  6E  64  20 

010E’ 

70  75  6E  63 

0112’ 

68  20  66  75 

0116' 

6E  63  74  69 

011A’ 

6F  6E  3F  20 

01  IE  ’ 

79  2F  6E  20 

0122' 

24 

0123’ 

18  44  08  10 

tabs:  db  esc, 

'D', 8, 16,24,32,40, 

,48,56,64,72,80,88,96,114,122,130,00, 

0127’ 

18  20  28  30 

0128’ 

38  40  48  50 

Q12F' 

58  60  72  7A 

0133’ 

82  00  24 

0136’ 

IB  48  24 

nenhan:  db 

esc, 'Hr 

0139' 

IB  46  24 

neapha:  db 

esc, 'FI' 

013C’ 

12  24 

ncondi  db 

18, 'I' 

01 3E’ 

18  38  24 

npaper:  db 

esc,'8l* 

0141’ 

IB  39  24 

paper:  db 

esc, '9$' 

0144’ 

OF  24 

cond:  db 

Ofh.'l' 

0146’ 

IB  47  24 

1 

enhan:  db 

esc, 'S', '$' 

0149’ 

IB  45  24 

eapha:  db 

esc,'E',T 

014C’ 

1 

input:  ds 

80 

019C’ 

1 

prout: 

019C  ’ 

5E 

aov 

e,B 

0190’ 

7E 

aov 

4.* 

1  get  byte 

019E’ 

OE  05 

■vi 

c, list 

\  to  list  device 

01  AO’ 

FE  24 

cpi 

T 

01A2’ 

C8 

rz 

1  done 

01A3’ 

E5 

push 

h 

01 A4  ’ 

CD  0005 

call 

bdos 

01A7’ 

El 

pop 

h 

01 A8  ’ 

23 

inx 

h 

;  next  character 

01A9’ 

C3  019C ' 

i«P 

prout 

01  AC  ’ 

answer: 

01  AC’ 

11  014C’ 

lxi 

d, input 

;  place  for  answer 

01AF’ 

3E  50 

avi 

a, 80 

;  aaxiaua  length 

01B1  ’ 

32  014C’ 

sta 

input 

;  set  up  for  ’read' 

01B4  ’ 

32  014E ' 

sta 

input+2 

1  aake  sure  answer  is  not  "y* 

01B7  ’ 

OE  OA 

avi 

c.rstring 

;  read  string  function 

01B9  ’ 

CD  0005 

call 

bdos 

0 1 BC  ’ 

3A  01 4E ' 

Ida 

inputs 

1  get  answer  or  80 

01BF  ’ 

FE  79 

cpi 

V 

Old’ 

C8 

rz 

01C2’ 

FE  59 

cpi 

•v 

01C4’ 

C9 

ret 

HACR0-80  3.4  Ol-Dec-80  PA8E  1-3 

end  start  End  Listing 


T 


38 


Dr.  Dobb’s  Journal.  Number  62.  December,  1981 


546 


Small-C  Expression  Analyzer 

Patching  the  Address  Arithmetic 


For  those  who  are  already  using 
small-c,  here  are  some  patches  to 
the  expression  analyzer.  In  its  ori¬ 
ginal  form,  small-c  doesn’t  always  proper¬ 
ly  scale  values  involved  in  address  arith¬ 
metic.  The  following  list  describes  its 
shortcomings: 

1.  Pointer  values  and  array  names  should 
receive  identical  treatment.  They  can  be 
used  interchangeably,  except  that  an 
array  name,  being  a  constant,  cannot  be 
used  as  an  lvalue.  In  particular,  values 
added  to  an  array  name  should  be  proper¬ 
ly  scaled  according  to  the  type  of  the  ar¬ 
ray,  just  as  in  the  case  of  pointer  arith¬ 
metic.  The  expression  *(intarray+3) 
should  refer  to  the  fourth  integer  in  the 
array.  Small-c  properly  scales  values  add- 


by  J.  E.  Hendrix 

J.  E.  Hendrix,  Rt.  1,  Box  74-B-l ,  Oxford, 
MS  38655. 


ed  to  and  subtracted  from  pointers,  but 
not  values  added  to  array  names.  It  is 
meaningless  to  subtract  a  value  from  an 
array  name. 

2.  There  is  no  requirement  in  “C”  that 
expressions  such  as  (pointer+integer)  be 
written  with  the  pointer  on  the  left  side 
of  the  operator.  Small-c,  however,  will 
scale  “integer”  only  if  the  expression  is 
written  in  that  form. 

3.  Standard  “C”  permits  address  expres¬ 
sions  to  have  more  than  two  terms.  That 
means  that  the  expression  analyzer 
should  keep  track  of  the  identity  (address 
or  object)  of  intermediate  results.  Dis¬ 
placing  an  address  (pointer  value  or  array 
name)  by  an  integral  value  should  yield 
a  new  address.  Subtracting  one  address 
from  another  of  the  same  type  should 
yield  the  integral  number  of  objects  by 
which  they  are  displaced.  All  other  arith¬ 
metic  operations  involving  addresses  are 
meaningless.  The  expression  (addressl- 


address2)  has  meaning  only  when  both 
addresses  refer  to  objects  in  the  same 
array.  Small-c  makes  no  attempt  to  track 
the  identity  of  intermediate  results  and, 
therefore,  does  not  always  properly  scale 
values  added  to  or  subtracted  from  inter¬ 
mediate  values. 

The  revisions  needed  to  correct  these 
problems  are  too  extensive  and  fragment¬ 
ed  to  describe  in  detail,  so  I  am  including 
a  complete  listing  of  the  revised  expres¬ 
sion  analyzer.  All  new  code  is  enclosed  in 
boxes.  I  leave  it  to  the  reader  to  work  out 
the  theory. 

My  complements  to  Ron  Cain  for 
his  work  in  producing  a  great  little  com¬ 
piler.  After  using  it  for  a  year,  I  am  still 
enthusiastic  about  it.  We  owe  Ron  a  debt 
of  gratitude  for  placing  it  in  the  public 
domain. 


While  your  manuscript  may  be  too  technical 
for  some  other  micro  publications,  it  may  be 
“just  what  the  doctor  ordered”  for  our 
audience.  Let  us  take  a  look  at  it,  won’t  you? 
You  can  reach  us  at: 

Dr.  Dobb’s  Journal 
P.O.  Box  E 

Menlo  Park,  CA  94025 
(415)323-3111 


40 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 

547 


Small-C  Expression  Analyzer  (Text  begins  on  page  40) 


1  /★ 

2  **  lvallOJ  -  symbol  table  address,  else  0  for  constant 

3  *★  lvalU)  -  type  Indirect  object  to  fetch,  else  0  for  static  object 

4  **  lvall2J  -  type  pointer  or  array,  else  0 
b  */ 

o  expressionO 

7  | _ { _ 

8 |  Int  lvall3)l  1 
9  I  f (hei r I ( lval ) )  r  va  1  u  e  ( l v a 1 ) i 
10  > 


11  heir  I  ( lval  ) 

12  int  1 val t ] i 

1 4  I  int  k , lval 21 31 <  1 
I b  K  =  he I r 2(  1  val  )  I 

lo  if  ( match ( ) ) 

1/  ( i f ( k==0 ){ need lval () i return  Oi ) 

lb  i f  ( lval [ I ] ) push( ) I 
lv  i f (hei r I < 1 val2  ) ) rvalue ( lva  12 )  i 
20  s tore( lval ) I 
2  I  return  0  i 

22  ) 

23  else  return  Kt 

24  ) 

2b  he ir2( lval ) 

26  int  lval  1  J  I _ 

27  I  (int  <  ,  1 va 12 1  JT1  1 

28  k=heir3( lval ) I 
2v  blanks ( ) t 

30  i f <ch( ) ! =' ! ' )return  ki 

31  if (k  )rvalue( lval ) I 

32  v*h  i  1  e  <  I ) 

33  (if  ( match ("!")) 

34  <push( ) I 

3b  i  f  (hei  r3  ( 1  va  12  ) )  rva  ltie  (  1  val  2 )  i 

3o  pop( ) l 

37  or ( ) i 

38  > 

3v  else  return  Oi 

40  ) 

41  ) 

4  2  he ir 3( lval  ) 

43  int  lval  (  ]  i 

44  |  ( int  k , 1 va!2t31  fl 

4b  k=he ir4 ( 1 va 1 ) I 

46  bl anks ( ) i 

4/  if  (ch<  ) !  )return  ki 

40  1 1 (k  )rva lue( lval  )  i 

4 v  whi le(  I ) 

bO  (if  (matched")) 

b I  ( push( ) i 

b2  if (heir4 ( 1 va 12 ) ) rvalue( 1 va 12 )  l 

b3  pop( ) I 

b4  xor ( ) l 

bb  ) 

bo  else  return  Oi 

b  7  > 

bd  > 


bv  he ir4( lva l  ) 

oO  int  lval  C ] i _ 

ol  |  (int  k , 1 va  12 1  3  1 ;  1 

62  K=he irb( 1 val )  l 

63  blanks ( )  I 

64  if  (ch(  > !  ='<K.'  )return  ki 
ob  if (k )rvalue( lval  )i 

66  wh i 1  e(  I  ) 

67  (if  (match( ) ) 

68  ( push( ) i 

6v  i f (heirb( 1 val? ) ) rvalue! 1 val 2  > l 

70  pop( ) i 

7  I  and(  )  i 

72  > 

73  else  return  Ol 

/  4  ) 

7b  ) 

/ 6  he irb(  lval ) 

77  int  lval  til 

7b  ( _ , 

7v  1  int  < ,  lval2t  31  i  | 

80  k=he ir6( lval ) l 

8 1  blanks ( )  i 

82  if  ( (cstreq(  l  i ne  +  1  pt r ,  )==0  )<4 

83  (streq( line+lptr," !=") ==) )) return  ki 

84  if  (k  )rvalue( lval ) t 
8b  while(l) 

86  (if  (match( "==") ) 

87  (push(  )  i 

88  if (hei r6( lva 12)) rvalue ( lva 12) i 

8v  pop( ) i 

0  0  eq  ( )  { 

91  ) 

92  else  if  ( match ("!=") ) 

93  (push(  )  i 

94  if (heir 6< lval2 )) rvalue (lva 12)  i 


pop( ) i 
ne  (  )  i 
> 

98  else  return  Ot 

99  ) 

100  ) 

101  he i r6( 1 val  ) 

102  int  1 val (  1  i 

103  < _ 

104  |  int  k,  1  va 1 2 [ 3 1 i~| 

I  Ob  x  =  he 1 r  7 ( 1 va 1 ) t 

I  Oc  blanks ( ) i 

107  if((streq(  line  4-1  ptr,"<")  *=0 )  & 

108  ( s tr eq ( 1 ine* lptr , " >" ) ==0 ) & 

I  Oy  (streq  ( 1  ine*  lptr  ,"<»•«>  »=())& 

110  ( s treq ( 1  i ne+ lptr ,">  =  ") ==0 )) return  ki 

Ml  i  f  ( s  treq  ( 1  ine+  lptr ,"»"))  return  kt 

112  i  f (s treq ( 1 ine* lptr ,"<<•)) return  ki 

M3  i  f  (k  )rva  lue  (  lval  )  t 

114  wh i 1 e (  I ) 

lib  (if  ( match ("<*") ) 

I I  6  (pus  h( ) t 


M  /  i  f  (hei  r7(  1  va  12  ) )  rval  ue(  1  va  12  )  i 

I  I  8 _ pop(  )  i _ 

1  1 9  [  i f ( 1 va 1 1  2  3  I  1 va 1 2 1 2  1 )  I 

120  ( u  1  e  (  )  i  - 1 

1 2  I  cont inue i 

1 22  ) 

123  le()i 

124  > 

12b  else  if  (match( ">=")) 

•  2o  (push( )  i 

127  if(heir7 (lva 12)) rvalue (lva 12)1 

I  2d  _ pop(  )  i _ 

>29  1  1 f ( 1 va 1  (  2 )  !  1  va  12 [ 2  J )  1 

I  30  ( uge ( ) i 

•  3  I  continue  t 

1 32  ) 

133  qe  (  )  i 

1 34  ) 

13b  else  i f (( streq ( 1 i ne* lptr ,"<"))  * 

1  3o  (streq  ( 1 ine*  lptr , " <<» )  =*0  )  ) 

13/  ( i  nh  y  t  e  (  )  i 

I  38  push( ) l 

■39  if (heir7( 1 va 12 ) )rvalue( 1 val 2  )  l 

•40  _ pop(  )  i _ 

•41  [  1  f  ( 1  va  1  (  2  1  !  1  va  12  ( 2  ) )  1 

I  4  2  ( u 1 t  (  )  I 

143  continue! 

I  44  ) 

14b  1 1 ( ) i 

146  ) 

•4/  else  if ( (streq(line*lptr, ">"  )  )a 

■48  (streq( 1 ine* lptr ,">>") ==0 ) ) 

I4y  ( inbyte( ) i 

I bO  push( )  i 

1  b  I  i f (heir7( 1 va 12 ) )rvalue( 1 val 2 ) » 

Ib2  _ oop(  )  i 

1  b3  I  if(l^al(2)  :  1  va  12  [  2  1 )  1 

I  b4  (ugt ( ) i 

I bb  continue! 

I  bo  ) 

lb/  gt()l 

I  b8  ) 

Ib9  else  return  Oi 

160  ) 

lo  I  > 

I  62  he i r 7 ( 1 va 1  ) 

163  int  lval [  ]  i 

164  ( _ 

I  6b f  int  k , 1 val 21 3  J  !  1 
I 6o  k  =  ne i rH(  lval  )  i 

I o /  blanks (  )  i 

I  Oh  i  r  ((  streq ( l ine* lptr , ">>"  )==0)& 
lov  ( streq  ( 1  ine-*-  lptr  ,"<<")  ==0 ))  return  ki 

170  i l ( k )r va lue ( l va 1 )  i 
17  1  wh  i  1  e  (  I  ) 

172  (if  ( m a t c h ( ">>")) 

I  73  (push( ) l 

174  i  f  (hei  r8 ( 1  va  12  ) )  rval ue(  1  va  12 )  i 


(Listing  continued  on  next  page) 


V*j 

vis 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 

548 


41 


SlTldll^C  Expression  Andlyzer  (Listing  continued,  text  begins  on  page  40) 


17b 

pop( ) 1 

176 

asr(  )! 

1  77 

> 

1  78 

else  if  (matchC  <<"  )  ) 

1  7V 

(push( ) I 

180 

i f  (hei  r8  ( 1  va  12  ) )  rval  ue  ( 1  va  12  )  1 

181 

pop( ) 1 

182 

as 1(  )  1 

183 

> 

184 

else  return  Ol 

18b 

i 

186 

> 

187 

he ir8( lval  ) 

188 

int  lval  [  ]  i 

18V 

_j _ 

IVO  [ 

int  k. lval 21 31 t 1 

19  1 

k=heirV( lval ) i 

192 

blanks ( )  i 

1 93 

i f ( ( ch( ) !»'♦')&( ch( ) !*'-') )ret urn  ki 

194 

if  (k  )rvalue( lval )i 

19b 

whi  1 e (  1 ) 

196 

(if  (matchC1*"  )> 

197 

(push( ) l 

1 V  8 

i  f  (hei  rV(  1  va  12  ) )  rval  ue  ( 1  va  12  )  I 

IVV  ] 

if (dbltest(lval,lval2)>  | 

200 

doub lereg( ) 1 

201 

pop( ) 1 

202 

if (dbltest(lval2,lval>>  ( 

203 

swap( ) I 

204 

doublereg( ) 1 

20b 

swap ( ) I 

206 

> 

20  1 

add( ) i 

20b 

result( lval,  lval2)  t  1 

20V 

j 

210 

else  if  (matchC-")) 

2  1  1 

(push( ) l 

212 

if(heirV(lval2))rvalue( 1 va 12 ) 1 

213 

if  (dbltestdval,  lval2))  1 

214 

doub lereg( ) 1 

21b 

pop( ) l 

216 

if  Mbl  test  (  lval2,  lval  ) )  ( 

217 

swap( ) t 

218 

doublereg( ) i 

21V 

swap ( ) l 

220 

i 

22  1 

sub( ) i 

222 

if ( ( lval (2  )==cint)4( lval21 2 

==c i  nt ) )  ( 

223 

swap! ) l 

224 

lmmed( ) lol ( " 1" ) 1 

22b 

asr()l  /**  div  by  2  *★/ 

226 

> 

227 

resul t( lval .  Ival2)i 

228  5 

22V  else  return  Ol 

230  > 

23  1  ) 

232  he irV( lval  ) 

233  int  lvalOi 

234  < _ 

23b  |  lnt  k, lval2( 31 I  I 

236  k«he i r I 0( 1 va 1 > l 

237  blanks ( ) t 

238  if ((ch( ) !*'*')4(ch( )!*'/')* 

23V  (cM  ) !  ■'  %'  ) )  return  ki 

240  if (k )rvalue( lval  )t 

24  1  whi 1 e(  I  ) 

242  <if  ( match ( ) ) 

243  (push( ) l 

244  i f (hei rV ( 1 va 12 ) ) rval ue( 1 va 12 ) i 

24b  pop( ) * 

24o  mult ( )  l 

24  7  > 

24b  else  if  ( match ("/") ) 

24v  (push( ) * 

250  if(heirl0(lval2) ) rvalue ( lval 2)  l 

2b  I  pop( ) l 

252  di v( ) i 

253  ) 

254  else  if  (match("%")> 

25b  ( push( )  I 

256  if(heirl0(lval2))rvalue(lval2)l 

257  pop( ) l 

258  mod( ) < 

25V  > 

260  else  return  Ol 

26 1  ) 

262  ) 

263  he i r I 0( 1 va 1 ) 

264  int  1  va  1  [  1  I 

26b  ( 

266  int  ki 

267  char  *ptri 

268  if (match ("♦♦") ) 

26V  <if( (k=heir I 0( lval )) ==0) 


270 

271 

272 

273 

274 

27b 

(needl va l ( ) 1 
return  Ol 
) 

if (lval! 11 )push( ) I 
rvalue ( 1 val ) l 
inc(  )  I 

276  r 

If ( lvalt21==clnt)  1 

277 

inc( )  I 

278 

s tore ( lval ) l 

27V 

return  Ol 

280 

> 

28  1 

else  if  (match(  "— "  )) 

282 

(lf((k=heirlO(lval)) 

283 

(needl va 1 ( ) 1 

284 

return  Ol 

28  b 

> 

286  i f ( 1 va 1 ( I  1  )push( > l 

287  rvalue ( 1  va  1 )  i 

288  dec (  )  l 

28V  |  i f ( 1 va 1 [ 2 1 ==c i nt )  | 

2V0  dec ( ) 1 


29  I  store( lval ) * 

292  return  Ol 

293  > 

294  else  if  (match <"-") > 

29b  (k*heirlO(lval >l 

296  if  (k)  rva  lue (  lval  ); 

29  7  neg( ) I 

298  rettjrn  Ot 

2VV  > 


300 

301 

302 

303 

304 

30  b 

306 

307 

308 
30V 
310 

31  I 

312 

313 

314 
31b 
316 
31  7 
318 
31V 

320 

321 

322 

323 

324 

325 

326 
32/ 
328 
32V 
330 
33  1 

332 

333 

334 
33b 
33o 

33  7 
338 
33V 
340 

34  I 
34  2 
34  3 
344 
34b 
34  6 
34  7 
348 


else  i f (match( ) ) 

(k=hei r I 0( 1 val ) » 

if  (k  )rvalue(  lval  )  i _ _ 

if (ptr  =  lval [01 ) 1 va 11  1 1 =ptr t  type  1  l 
else  lvalt I l=cintl 

lval[21=0i  /»»»*  flag  as  not  pointer  or  array  *★*★/ 
return  I i 
> 

else  if (match* "4") ) 

<k=hei r I 0( 1 val  )  i 
i  f ( k  ==  0) 

(error( " i l lega 1  address")! 
return  Ol 

) _ _ _ 

ptr= lval ( 01 l 

1 val [ 2 l=ptrt  type  1 1 

i f ( 1 va l [ I  ]  )  re  turn  Ol 

/*  global  4  non-array  */ 

immed(  )  I 

outs  tr (ptr  )  i 

nl  ( )  i 

1 val 1  I  l  =  ptrf  type  1 1 
return  Ol 

— 7 -  - 

else 

<k=hei r I  I ( lval  )  l 
if  (matchC ♦♦"> ) 

( i f ( k==0  ) 

(needl val (  )  I 
return  Ol 
) 

i f ( 1 va 1 [ I  1 )push( ) I 
rva lue (lval )  I 
lnc(  )  i 

1  f  ( 1  va  1  [  2  ]  ==  c  i  n~t~)  1 
inc (  )  I 

store( 1 val  )  i 

dec (  )  I  _ 

i  f  ( 1  va  1  [  2  1  ==c  1  nt  )~| 
de  c (  )  I 
return  Ol 
) 

else  if(match(" — ")) 

(if  (k«0> 

(needl va  1  (  )  I 
return  Ol 
> 

i f ( 1 va l ( I  1 )push(  )  l 
rvalue ( 1 va  1 )  l 


34v  dec (  )  l 

350  |  If  (lval(2]==clnt)  I 

351  de  c (  )  I 

352  store( lval  )  l 


42 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 

549 


HUIMIMliBBm 


outstr (ptr ) i nl ( )  i _ 

i  I  1  =  lval [2 )=ptrt type  1 <  1 

'return  Oi 

> 

tr=addg lb (sname ,functlon,clntfO)l 
val I 3)*ptr l 
vail  I  1*01 
eturn  01 

constant ( num) ) 

eturn(  1  va  1  (0 1  *1  va  1 1  1 1  *0  )  l 


error ("invalid  expression")! 
mmed( ) ! outdec (0) I nl ( ) ! 
unic  (  )  I 
eturn  Oi 


1 f ( ptr ( ident l*=poi nter )  ( 
lval [ I l=cint ! 

1  vail  2 l  =  ptrl ty pe 1 ! 

) 

if ( p tr ( ident  )*=array )  ( 
lval  (2  )=*ptr[  type  1 1 
return  Ol 

) _ 

else  return  I ! 

) 

i  f (ptr  =  f indglb (sname ) ) 
i f ( ptr [ ident 1 ! *f unct ion ) 

( lva  11 0)=ptr ! 
lval [ I  1=01 


if (ptrlident l!*array )  ( 

if (ptr( ident l*=pointer )  lval (2 l*ptr( ty pe 1 1 
return  I i 

_> _ 

immedC  )  l 


Dr.  Robert  Smithdas  is 
blind ,  nonhearing ,  and 
nonverbal .  He  is  a 
published  poet 


President’s  Committee  on 
Employment  of  the  Handicapped 
Washington,  D.C.  20210 

Produced  by  The  School  of  Visual  Arts  Public  Advertising  System 


Dr.  Dobb’s  Journal,  Number  62,  December,  1981 
550 


43 


Auto.  Loading  of  Assembly 
Language  Subroutines 


Have  you  ever  wanted  a  simple  way 
to  relocate  an  8080  assembly  code 
program  into  the  top  of  the  TPA  in 
CP/M?  Have  you  ever  written  a  BASIC 
program  that  requires  some  machine  code 
hidden  in  dumb  DATA  statements? 
There  is  a  better  way. 

Why  would  anybody  want  to  use  as¬ 
sembly  code  and  BASIC  together  to  solve 
a  problem?  Well,  there  really  are  a  few 
places  where  that  seems  to  be  the  right 
approach.  Let  me  give  an  example  based 
on  a  real  experience. 

Let’s  imagine  that  you  and  I  have 
been  using  BASIC  and  CP/M  for  some 
time  on  a  project.  Everything  goes  well 
until  we  wish  to  interface  BASIC  to  a 
new  analog-to-digital  converter.  At  first 
we  try  to  read  the  gadget  with  the  PEEK 
function  in  BASIC.  We  find  that  some 
readings  are  not  always  true.  The  BASIC 
interpreter  is  too  slow. 

So  we  write  machine  code  and  place 

by  John  B.  Palmer 


John  B.  Palmer,  P.  O.  Box  23,  Boonville, 
CA  95415. 


it  in  DATA  statements,  use  POKE  to  put 
it  into  memory,  and  use  CALL  to  transfer 
control  to  the  machine  code  which  in 
turn  does  a  RET  to  BASIC.  Later  we 
need  to  make  a  minor  change  and  have  a 
lot  of  trouble  understanding  what  those 
DATA  statements  mean.  We  conclude 
that  while  BASIC  may  be  quick  and  easy 
for  many  jobs,  BASIC  does  not  provide 
good  documentation  when  machine  code 
is  written  into  a  group  of  DATA  state¬ 
ments. 

The  better  way  is  to  use  the  utilities 
that  come  with  CP/M.  The  ED  program 
we  shall  use  to  edit  a  well-documented 
assembly  language  program.  The  ASM 
program  will  assemble  the  program  and 
may  report  errors. 

Once  the  program  has  been  correctly 
assembled,  it  will  take  two  or  three  steps 
to  get  both  BASIC  and  the  machine  code 
running  together.  First  we  use  the  DDT 
program  to  load  the  resulting  HEX  file 
into  the  upper  part  of  the  TPA.  After 
that  we  reboot  and  execute  BASIC  with  a 
command  line  that  limits  the  memory 
size  and  then  give  the  commands  to  load 
and  run  the  program  in  BASIC. 


The  only  objection  to  this  is  the 
number  of  steps  it  takes  to  finally  get 
into  our  BASIC  program.  If  we  make  a 
mistake  we  may  have  to  start  all  over 
again.  Is  it  possible  to  write  a  simple  COM 
file  that  will  do  everything?  Yes,  it  is. 

Quite  a  while  back  in  DDJ  (Vol.  3, 
No.  2)  there  was  an  article  by  Gary  Kildall 
that  explained  how  to  write  self-relocating 
code.  By  using  this  trick  we  can  bypass 
DDT  and  have  our  code  load  itself  in  the 
upper  part  of  the  TPA. 

We  shall  want  to  create  a  Submit  file 
on  the  A  drive  that  will  start  BASIC  with 
the  right  memory  size  and  load  our 
BASIC  program  right  away.  Figure  1  is 
a  partial  example  of  how  this  could  be 
done. 

Briefly,  here  are  the  steps  we  need  to 
take  in  order  to  create  our  COM  file  that 
will  do  everything  we  need  with  just  one 
simple  command.  (We  assume  that  the 
machine  code  to  interface  BASIC  to  our 
new  toy  is  less  than  256  bytes.) 

Step  1.  Write  a  memory  move  pro¬ 
gram  that  will  move  a  block  of  code  that 
starts  at  0200h  into  a  destination  in  the 
upper  TPA.  As  each  byte  is  moved, 


Our  high-quality  editorial 
and 

your  high-quality  products 
are  made  for  each  other! 

Call  (415)  323-31 1 1  to  reserve  your  space 
in  the  next  Dr.  Dobb’s  Journal. 


44 


Dr.  Dobb’s  Journal,  Number  62,  December  1981 

551 


check  to  see  if  its  contents  are  equal  to 
the  byte  in  the  same  relative  place  in  a 
comparison  block  that  starts  at  0300  hex. 
If  they  are  not  equal,  the  byte  is  the  high- 
order  byte  of  an  address;  correct  the  ad¬ 
dress  in  the  destination. 

Step  2.  Combine  the  memory  move 
with  the  program  in  Figure  1  so  that  after 
the  machine  code  is  put  in  place  a  file 
called  “$$$.SUB”  is  written  onto  the  A 
drive. 

Step  3.  Assemble  two  copies  of  the 
desired  BASIC-to-gadget  machine  code. 
Originate  one  copy  at  0200  hex.  Origi¬ 
nate  the  other  at  0300  hex  to  be  the  com¬ 
parison  block. 

Step  4.  Write  a  text  file  of  type  .SUB 
that  has  the  proper  command  line  to  in¬ 
voke  BASIC,  set  memory  size,  and  load 
and  execute  our  BASIC  program.  It 
should  be  a  single  line  something  like 
this:  BASIC  ANALOG/M&H9000.  Then 
try  to  execute  it  with  the  SUBMIT  utility 
on  the  B  drive.  We  get  a  file  “$$$.SUB” 
on  the  B  drive. 

Step  5.  Invoke  DDT.  Read  in  the 
memory  mover  HEX  file.  Read  in  the 
HEX  code  that  originates  at  0200.  Read 
in  the  HEX  code  that  originates  at  0300. 
Read  in  the  $$$.SUB  file  with  offset  so 
that  it  lands  at  0400.  Reboot.  SAVE  4 
Widget.COM. 

Now  then,  anytime  we  give  the  sim¬ 
ple  command  WIDGET  the  machine  code 
will  move  into  the  upper  TPA  and  BASIC 
will  automatically  be  invoked  with  the 
proper  command  line. 

This  may  seem  to  be  overly  compli¬ 
cated.  Perhaps  it  is.  But  the  steps  outlined 
above  need  only  be  done  once,  and  can 
themselves  be  made  into  a  Submit  file. 

Now  let’s  review  what  objectives 
have  been  met. 

1.  The  end  user  can  still  use  his  BASIC 
interactive  interpreter.  No  need  to 
teach  him  a  new  language. 

2.  We  have  avoided  the  distasteful  prac¬ 
tice  of  placing  a  machine  language  pro¬ 
gram  into  a  group  of  DATA  state¬ 
ments. 

3.  The  assembly  language  program  can  be 
edited  and  altered  with  very  little  im¬ 
pact  on  the  main  application  program 
written  in  BASIC. 

4.  No  new  software  was  purchased. 
Everything  was  done  with  the  existing 
interpreter  and  system  utilities. 

I  hope  this  may  be  of  some  help  to 
others  who  have  had  to  face  a  similar 
problem  with  their  microcomputer  opera¬ 
tions.  »*j 


Figure  I. 

*  *  *  *  *  *  *  *  *  *  a:  *  *  *  * 


MAKE  H 

iU 1 U  E .:>E L  u i  fc. 

FILE  ON  THE  'A'  DRIVE 

* 

USING  04UUH  AS  SHE  BLOCK  Ub  cuOfc  10  BE 

•  + 

WRi  1  1  Eft 

ONTO  DISK  Hi 

$$$.  SUB 

j  +  : 

h  *  *: 

•+•  •+•  *  *  M 

*  +:  *;  +  *: 

ck 

EWU 

OOH 

Lb 

EuU 

ohh 

MHKhU 1 0 : 

MV  I 

L.  26 

SE  i  L'l'lH 

LX  I 

0.,  O40OH 

LHLL 

yb 

[■IV 1 

L,.  22  .; 

MHKE  KILL 

LXi 

0..  b  LB 

LHLL 

Ob 

Ink 

H  ; 

lEbl  b OK  ObbH 

•J  <L 

ERROR 

MVi 

L,  21  ; 

WRI  IE 

LX  J. 

Lb  bit! 

LHLL 

Mb 

biv  i 

L..  1L  , 

CLOSE 

uHi 

L* .  b  LB 

LHLL 

Mb 

MVI 

l:..  y 

LAI 

L-*..  NH1 iNEi 

b 

LhLl 

Mb 

jmp 

M  ; 

REBUU 1  LKi'! 

Dr.  Dobb’s  Journal,  Number  62,  December,  1981 
552 


45 


Index 


Index 


2716  EPROM  programmer  [M-80]  189-190 
6502 

Assembler  for  the  6502  369-373 
Byte-count  routine  83 
Opcodes  analysis  [  BASIC/Pet]  96-97 
Reader  response  185 

6809 

Multi -byte  opcodes  279 

Tiny  BASIC  for  the  6809,  Santa  Barbara  202-203 
8080  (also  see  Z-80)  187 

Memory  chip  tester  533-534 
North  Star  DOSMOVER  124 
Z-80 

Cross  assembler  for  8080/Z-80  230-234 
Editor,  assembler,  disassembler  in  XL  package  36-40 
Adams,  E.  514 

Adven-80,  adventure  development  system  468-473 
Airy,  B.  6,7, 11 

Algorithm  to  convert  integer  date  [MP/M]  201 
Algorithms  (FORTH)  148-149 
Apple  II 

File  system.  Tiny  240-241 
Arrays,  cassette  I/O  routine  [BASIC]  150-152 
Artificial  intelligence  419 

"Thinking"  program,  ERGO  100 
Artificial  intelligence  language,  LISP  526-530 
Assemblers 

Assembler  for  the  6502  [FORTH]  369-373 
Cross  assembler  for  8080/Z-80  230-234 
Editor,  assembler,  disassembler  in  XL  package  36-40 
Editor/ Assembler  Plus  123 
BASIC 

Arrays,  cassette  I/O  routine  150-152 
BASIC- FORTH  427-428 
MIN  and  MAX  definition  312 
North  Star 

Debugging  concatenated  programs  64 

North  Star  DOSMOVER  124 

Small  VM  development,  portable  software  492-495 

Terminal  programs  for  North  Star  487 

Text  editor  input  routine  42-43 

Time  keeping  in  microcomputers  287-289 

PET 

Analysis  6502  opcodes  96-97 
Speed  reading  using  a  computer  95 
POKE  and  PEEK,  BASIC  version  3.2  enhancement  62 
Polynomial  evaluation  146-147 
Rubik's  cube  simulator  291-292 
Time  delay  circuit  design  197 
Tiny  BASIC  for  the  6809,  Santa  Barbara  202-203 
Bugs  419 

ZX80  Sinclair  60-61 
BASIC- FORTH  [FORTH]  427-428 
BASIC -Plus  45 


Bassett,  S.  148 

Binary  to  decimal  conversion  routine  271 
Readers'  improvements  422 
Blessing,  R.  487 
Bolton,  B.  330 
Brodgen,  W.  237 
Byte-count  routine  [6502]  83 
Byte  manipulation  and  pointers  [Fortran]  103 
C  language  (see  also:  Small-C  compiler) 

Time  functions  330-331 
Cage,  T.  124 

Calendar  routines  313,  516 
Card  shuffling  356 
Caulkins,  D.  63,95 
CBASIC-2 

DB.BAS  package  file  maintenance  80 
CLOAD  Magazine,  Inc.  122 
COMAL-80  [CP/M]  235-236 
As  an  interpreter  235 
Compal-80  102 

Compiler  writing  tool,  META4  321 

Implementing  an  M4  interpreter  329 
M4  language  325 
META4  language  322 
Compilers 

Small-C  compiler 

Error  run-time  library  routine  53 
Small-C  compiler  bug  fixes  and  enhancement  228 
Small-C  cross-compiler  implementation  66-67 
Small-C  programming  504-507 
Tincmp,  compiler  for  Pidgin  284-286 
Computer  conferencing  429-431 
Conversion 

Binary  to  decimal  conversion  routine  271 
File  conversion,  H8  text  editor  to  CP/M  239 
Submit  file  comments  200,415 
Cortesi,  D.  200,271,312,414,422,520 
CP/M 

COMAL -80  235-236 

DDT,  circumventing  200 

DUMP  utility  readability  enhancement  93 

File  conversion,  H8  text  editor  to  CP/M  239 

Keyboard  input  definition  194-196 

SCRIBE  IX,  word  processing  package  220-222 

Submit  file  comments  200 

Text  editor  WORD -MASTER  with  the  Compal-80  102 
ZDM  debugger  186 

Cross  assembler  for  8080/ Z-80  [8080/Z-80]  230-234 
XASM -86  features  232 
Z-88  project  230 

Database  design  [FORTH]  398-401 
Davis,  D.  126 

DB.BAS  package  file  maintenance  [CBASIC-2]  80 
DDT,  circumventing  [CP/M]  200 


555 


Debuggers 

DDT,  circumventing  200 
ZDM  debugger  for  CP/M  users  80-81 
Debugging  concatenated  programs  [BASIC/North  Star]  64 
Decompiler  [FORTH]  403 
Demas,  J.  36 
Dobyns,  B.  178 

DUMP  utility  readability  enhancement  [CP/M]  93 
implementation  227 
Duncan,  R.  69,140,187,403 
Editors 

Editor,  assembler,  disassembler  in  XL  package 
[8080/Z-80]  36-40 
Editor/Assembler  Plus  [TRS-80]  123 
Program  editors,  reassessment  of  237-238 
Screen  editor,  MINCE  178 
Screen-oriented  editors  383 
Text  editor  input  routine  [BASIC]  42-43 
Text  editor  WORD-MASTER  with  the  Compal-80  102 
Underline  modification  126 
ZX80  Sinclair  60-61 

Electronic  phone  book  [PCNET  project]  63,87,  133, 176 
Embedding  wide  characters  within  an  ordinary  line  515 
Faulkner,  D.  15 
Favitta,  M.  80 

Fibonacci  numbers  sequence  [FORTH]  9,  91 
File  comparator  [ Z  - 80 ]  15 

File  conversion,  H8  text  editor  to  CP/M  [conversion]  239 
File  system.  Tiny  [Apple  II]  240-241 
Floppy  disk  test  [Z-80]  140-145 
FORTH 

Algorithms  148-149 

Assembler  for  the  6502  369-373 

BASIC- FORTH  427-428 

Database  design  398-401 

Decompiler  403 

Description  411-413 

Fibonacci  numbers  9 

Fibonacci  numbers  sequence  91 

FORTH  as  language  and  environment  381  -382 

Overview  6,12 

Construction  of  program-like  commands  8 
Metamorphic  changes  by  concatenations  of  characters  10 
Primitives  7 

Reader  response  137,.185 
Use  by  novices  1 2 
Variables  stack  7 

Parameterized  command  concept  54-59 
Reader  response  186 
Philosophy  of  363-368 

Software  development  methodology  364 
Software  tools  367 
Screen-oriented  editor  383 
String  routines  51 

FORTH  as  language  and  environment  [FORTH]  381-382 

FORTH  description  411-413 

Fortran 

Byte  manipulation  and  pointers  103 
Small-C  cross-compiler  implementation  66-67 
Freed,  E.  103 
Gale,  W.  240,282,321 
Gordon,  H.  6,54 
Greenlaw,  D.  88 
H8  computer  239 
Hacking  510-514 
Hallem,  R.  149 
Harris,  D.  63,177 
Harris,  K.  363 
Hatfield,  J.  122 
Haydon,  G.  398 


Head,  G.  80,220 
Hendrix,  J.  492 
Hightower,  M.  127 
Hinds,  J,  202 
Hoffman,  R.  146 

Hypotenuse  approximation  on  integer  values  200 
Reader  input  312,359,520 
James,  J.  429 
Johnson,  J.  514 
Kalish,  M.  122 
Kanefsky,  R.  514 

Keyboard  input  definition  [CP/M]  194-196 
Theory  195 
Knippenberg,  H.  197 
Kudlac,  S.  514 
Language  register  3 
Lawrence,  J.  45 
Laxen,  H.  383 

LISP  (see  artificial  intelligence  language) 

Loeliger,  R.  381 
M-4  interpreter  329 
M-4  language  325 
M-80 

2716  EPROM  programmer  189-190 
Maggs,  P.  127 

Mailing  list  label  printer  [SLIC]  149 
Memory  chip  tester  [8080]  533-534 
Memory-mapped  video  displays  16 
Memory  test  [Z-80]  69 
Meta  4  (see  compiler  writing  tool) 

Miller,  E.  189 
Mills,  J.  230 

MIN  and  MAX  definition  [BASIC]  312 
Extended  to  other  functions  354 
MINCE,  screen  editor  178 
Monitor  MON  3  [TRS-80]  122 
MP/M 

Algorithm  to  convert  integer  date  201 
Nicol,  R,  123,526 
N-Logs  53,281 
North  Star  (see  BASIC) 

North  Star  DOS  36,270 
North  Star  DOSMOVER  [8080]  124 
Terminal  programs  for  North  Star  487 
Palmer,  J.  60,194 

PAN  protocol  revision  [PCNET  Project]  63 
Parameterized  command  concept  [FORTH]  54-59 
Access  55 

Conditional-jump  primitive  57 
Data  structures  55 
Notation  54-55 
Reader  response  [FORTH]  186 
Status-register  56 
Pascal 

Card  shuffling  356 
“Upside"  down,  nature  of  4 
Patches 

POKE  and  PEEK,  BASIC  version  3.2  enhancement  62 
PCNET  project  176 

Electric  phone  book  63,87,133,176 
PAN  protocol  revision  63 
PCNET  protocol  63,177 
Rehoushek,  J.  291 
Pelle,  M.  235 

Personal  computer  networks  (see  PCNET) 

Peter,  K.  514 

Philosophy  of  FORTH  [FORTH]  363-368 
PH  I  MON  subroutines  15 
Pidgin  321 

Tincmp,  compiler  for  Pidgin  284-286 


Pidgin,  systems  programming  languages  282-284 
Pocket  computer.  Radio  Shack  88 

POKE  and  PEEK,  BASIC  version  3.2  enhancement  [BASIC]  62 
Alternative  patch  228 
Polynomial  evaluation  [BASIC]  146-147 
Portable  software  development,  Small/VM  492-495 
Printers 

Printer  toggle  installation  in  North  Star  DOS  5.2  270 
Program  editors,  reassessment  of  [editors]  237-238 
Programmers 

2716  EPROM  programmer  189-190 
Programming  237 

Artificial  Intelligence  language,  LISP  526-530 
BASIC-  FORTH  427-428 
Pidgin,  systems  programming  language  282-284 
Small-C  programming  504-507 
Time  functions  330-331 
Programs 

Adventure  development  system,  Adven-80  468-473 
Assembler  for  the  6502  369-373 
BASIC-  FORTH  427-428 
COMAL-80  235-236 
Compiler  writing  tool,  META4  321 
Cross  assembler  for  8080/Z-80  230-234 
Debugging  concatenated  programs  64 
Decompiler  403 

DUMP  utility  readability  enhancement  93 
File  comparator  15 

File  conversion,  H8  text  editor  to  CP/M  239 
File  system.  Tiny  240-241 
Floppy  disk  test  140-145 
Keyboard  input  definition  194-196 
Mailing  list  label  printer  149 
Memory  test  [Z-80]  69 
North  Star  DOSMOVER  124 
Pidgin,  systems  programming  language  282-284 
Rubik's  cube  simulator  291-292 
Screen -oriented  editor  383 
Small-C  programming  504-507 
Speed  reading  using  a  computer  95 
Terminal  programs  for  North  Star  487 
'Thinking"  programs,  ERGO  100 
Time  delay  circuit  design  197 
Time  functions  330-331 
Time-keeping  in  microcomputers  287-289 
Tiny  BASIC  for  the  6809,  Santa  Barbara  202-203 
Turing  machine  simulation  45 
Video  drivers  16-17 
Radio  Shack  (see  TRS-80) 

Radio  Shack  pocket  computer  88 

Ragsdale,  W.  369 

Rohde,  A.  150 

Roth,  R.  504 

Routines 

Arrays,  cassette  I/O  routine  150-152 
Binary  to  decimal  conversion  routine  271 
Byte  manipulation  and  pointers  103 
Calendar  routines  313 
Database  design  398-401 
DUMP  utility  readability  enhancement  93 
Polynomial  evaluation  146-147 
Small-C  cross-compiler  implementation  66-67 
Text  editor  input  routine  42-43 
Text  editor  WORD-MASTER  with  the  Compal-80  102 
Rubik's  Cube  simulator  [BASIC]  291  -292 
Rubin,  S.  100 

Santa  Barbara  (see  Tiny  BASIC  for  the  6809) 

Scargill,  P.  468 
Scott,  J.  239 


Screen  editor,  MINCE  178 
Addendum  227 

Extended  with  Amethyst  181-182 
Screen  editors  1 78 
Screen -oriented  editor  102 
[FORTH]  383 

Scribe  IX,  wordprocessing  package  [CP/M]  220-222 
Sinclair  BASIC  61 
Skjellum,  A.  16,102,423 
SLIC 

Mailing  list  label  printer  149 
Small-C  compiler 

Bug  fixes  and  enhancements  228 

Error  run-time  library  routines  [compiler]  53 

Modification  465 

Small-C  cross-compiler  implementation  [Fortran]  66-67 
Bug  correction  67 
Bugs  228,277 
Update  104 

Small-C  programming  504-507 
Small  VM  development,  portable  software 
[BASIC/North  Star]  492-495 
Smart,  B.  270 
Smith,  G.  42,64 
Softky,  S.  100 
Software  reviews 

CLOAD  Magazine,  Inc.  122 
DB.BAS  package  file  maintenance  80 
Editor,  assembler,  disassembler  in  XL  package  36-40 
Editor/Assembler  Plus  123 
Monitor  MON  3  122 
Screen  editor,  MINCE  178 
SCRIBE  IX  word  processing  package  220-222 
Utility  package,  Disk  Keyplus  122 
ZDM  debugger  for  CP/M  users  80-81 
Sonderstrup,  S.  235 

Speech  synthesizer  interface  [TRS-80]  127-129 
Speed  reading  using  a  computer  [BASIC/Pet]  95 
Using  EDand  PIP  in  CP/M  186 
String  routines  [FORTH]  51 

Submit  file  comments  [CP/M  /  conversions]  200,415 
Testing  binary  integer  for  single  1-bit  414 
Tektronix  4010  simulator  [Z-80]  423-425 
Terminal  programs  for  North  Star  [North  Star]  487 
Text  editor 

Input  routine  [BASIC/North  Star]  42-43 
WORD-MASTER  with  the  Compal-80  [CP/M]  102 
‘Thinking"  program,  ERGO  [artificial  intelligence]  100 
Documentation  319 
Time-delay  circuit  design  [BASIC]  197 
Small  error  420 

Time  functions  [C  language]  330-331 

Time-keeping  in  microcomputers  [BASIC/North  Star]  287-289 
Timin,  M.  41 1 

Tincmp,  compiler  for  Pidgin  284-286 
Ting,  C.H.  427 

Tiny  BASIC  for  the  6809,  Santa  Barbara  [6809  ]  202-203 
TRS-80 

Editor/Assembler  Plus  123 
Monitor  MON  3  122 
Snythesizer  interface  127-129 
Utility  package.  Disk  Keyplus  122 
Turing  machine  simulation  [programs]  45 
Underline  modification  126 
Universal  language  45 

Utility  package,  Disk  Keyplus  [TRS-80]  122 
Van  Iderstine,  T.  62 
VDM-1  124 

Video  drivers  [Z-80]  16-17 


Time-dependent  coding  93 
Wexler,  S.  122 
Whitlock,  H.  96 
Woods,  P.  66,104 

Word  processing  package  (see  SCRIBE  IX) 
Yates,  D.  287 
Z-80  (see  also  8080) 

File  comparator  15 
Floppy  disk  test  140-145 


Memory  test  69 
Tektronix  4010  simulator  423 
Video  drivers  16-17 

Z-80  microprocessor,  use  and  misuse  187-188 
ZDM  debugger  tor  CP/ M  users  [Z-80]  80-81 
Inline  assembler  [CP/M]  186 
ZSID  bug  and  patch  519 
ZX80,  Sinclair  [BASIC]  60-61 
Reader  response  137,229 


The  Dr.  Dobbs  Series 

The  People’s  Computer  Company 

A  collection  of  fascinating  bits  of  information  for  the  home  computer  hobbyist.  These 
works,  from  People’s  Computer  Company,  are  not  just  “the  best  of. . .  ,”  they  include 
almost  everything  from  all  issues  of  Dr.  Dobb's  Journal.  “There’s  more  creativity,  wild 
ideas,  and  raw  enthusiasm  here  per  page  than  you  are  likely  to  find  anywhere  else  in 
the  personal  computing  press.”  Creative  Computing. 

Dr.  Dobb  s  Journal,  Volume  1 

Chronicles  the  advent  of  the  microcomputer  era  in  1976.  Always  pertinent  for  bit  crunching 
and  byte  saving,  language  design,  home-brew  computer  projects,  and  the  technical  history  of 
personal  computing. 

Topics  include:  Tiny  BASIC,  the  first  words  on  CP/M,  Speech  Synthesis,  Floating  Point 
Routines,  6502  Disassembler  for  the  Apple,  Timer  Routines,  and  much  more.  #5475,  paper, 
368  pages. 

Dr.  Dobb  s  Journal,  Volume  2 

The  small  computer  emerges  as  a  powerful  tool  for  the  modern  age  in  these  issues  from  1977. 
Topics  include:  Lawrence  Livermore  Lab’s  BASIC,  Dr.  Starkweather’s  PILOT,  Using  a 
Modem,  String  Handling  Techniques,  Ciphers,  Turtle  Graphics,  micro  utilities,  and  much 
more.  #5484,  paper,  480  pages. 

Dr.  Dobb  s  Journal,  Volume  3 

Explores  the  foundations  of  the  mass  market  computer  industry  and  advances  in 
microcomputer  programming  in  1978. 

Topics  include:  Programming  in  BASIC,  PILOT,  and  Pascal,  RAM  Memory  Testers,  Apple 
utility  programs,  S-100  Bus  Standard,  STRUBAL:  A  Structured  BASIC  Compiler,  and  much 
more.  #5490,  paper,  480  pages. 

Dr.  Dobb’s  Journal,  Volume  4 

Heralds  the  widespread  acceptance  of  the  microcomputer  in  America.  Innovative  ideas  and 
articles  guide  the  reader  through  the  age  of  discovery  in  1979. 

Topics  include:  Programming  problems  for  the  popular  micros,  Selecting  Business  Software, 
Microcomputer  Speech  and  Music,  Printers  and  Plotters,  Information  Networks,  interfacing 
techniques,  and  much  more.  #5491,  paper,  480  pages. 

Dr.  Dobb  s  Journal,  Volume  5 

Focuses  on  the  technological  promise  of  the  modern  microcomputer  and  the  creative 
challenges  facing  programmers  in  1980. 

Topics  include:  The  revolutionary  impact  of  CP/M,  C  programming  and  the  UNIX 
operating  system,  survey  of  computer  networks,  graphics,  software  portability,  introduction 
to  FORTH,  compiler  writing,  and  much  more.  #5492,  paper,  464  pages. 

Dr.  Dobb  s  Journal,  Volume  6 

The  microcomputer  enters  the  mainstream  —  these  issues  assess  the  revolutionary  impact  of 
microcomputers  on  the  individual  and  on  our  society. 

Topics  include:  Computer  Conferencing,  The  Power  of  FORTH,  8-  and  16-Bit 
Technology,  Rubik’s  Cube  Simulator,  An  Adventure  Came  Development  System,  and  much 
more.  #5493,  paper,  576  pages. 

Look  for  these  volumes  of  Dr.  Dobb's  at  your  local  computer  store  and  bookstore.  All  volumes 
are  also  available  from  Hayden  Book  Company. 


HAYDEN  BOOK  COMPANY  INC. 

Hasbrouck  Heights,  New  Jersey 


ISBN  0-8104-5493-9 


