1
1
t
1
V
1 1
l'
^1
1
I
t
1
r
1
^1
FDniTu ainEisinns
FORTH INTEREST GROUP
P.O. Box 11 05
San Carlos, CA 94070
IISIQE
168
170
174
175
180
182
186
187
Volume III
Number 6
Price; $2,^
195
196
Letters
Tech notes
Techniques Journal:
Execution Vectors
Henry Laxon
Charles Moore's BASIC
Compiler Revisited
Michael Perry
8080 Assembler
John Cassady
Skewed Sectors for CP/M
Roger D. Knapp
Graphic Graphics
Bob Gotsch
Cases Continued
FORTH Standard Team Meeting
1982 Rochester Conference
FDKTIi dlTIElSIClS
Published by Forth Interest Group
Volume in Mo. £ March/ April 19B2
Publisher Roy C. Martens
Editor Leo Brodie
Editorial Review Board
Bill Ragsdale
Dave Roulton
Kim Harris
John James
Dave KiJbridge
Henry Laxen
George Maverick
Bob Smith
John Bumgamer
Gary Felerbach
Bob Berkey
FORTH DIMENSIONS soEcits editorial matedat, comments
and letters. No responsibility is assumed for accuracy of material
submitted. MOST MATERIAL PUBLISHED BY THE FORTH
INTEREST GROUP IS IN THE PUBLIC DOMAIN. Information in
FORTH DIMENSIONS may be reproduced with credit giweo tO the
autlnor and the Forth Interest Group.
Subscription to FORTH DIMENSIONS is free with muimbership
in the Forth Interest Group at $15,00 per year ($27.00 foreign
air). For membership, change of address and/or to submit
material, the address is;
Forth Interest Group
P.O. Box 1105
San Carlos, CA 94070
l-fSTORICAL PERSPECTIVE
FROM THE EDITOR
Hi: I'm happy to say ttiat atartirtg witl^ this tesue, Fll be
serving as regular editor of FORTH Oimensiorts. I'd like to thank
Carl Street, the previous editor, who has been a great he^) to me
during the transition. Carl has made several Important contribu-
tions to FORTH Dimensions, such as the w^riter's kit for helping
you submit articles. Carl wfill rejoin FORTH Dimensions as our
advertising director beginning later this year.
I'd also like to thank Roy Martens, the publisher, for sug-
gesting that 1 take the editor's post, and for teaching me some of
the facts of life in magazine publication.
I hope to make this rnaqazine as useful as possible to the
greatest number of people. Sirice most of our readers are still
learning FORTH at one level or another, I Intend to encourage the
publication of tutorials (such as Henry Laxen's excellent series
which continues with this Issue), ^jplication stories (sure, FORTH
is fun, but let^ show the world what we can do with it!), examples
of well'wrltten I^RTH code (the beat way to learn style is by
reading elegant examples), and any ideas, discoveries, impressions
or feeUngs you care to express (this is your magazine, after aU9.
In short, we'll be concentrating on how to use FORTH in
solving problems.
By contrast, system implementation details are more the
responsibility of the individual vendors' documentation. In
addition, the FORTH eoinmimity hoasts tv/o ortjanizations
devoted to imprnviFiq and Rxtendinr) the language: the Standards
Team and the FORTH Modification Laboratory (FORML). Each
of these groups convenes annually, and the proceedings of these
conventions (available through FIG) are extremely valuable docu-
ments for the advanced study of FORTH.
I'm looking to each of you to help make this the kind of
magazine you want it to be, by contoibuting artieks, sxarrples,
and tetters. We dont have a staff of writers, so everything we
print comes from you. (If you want to contribute but dont know
v^at or how, drop me a line. Pti send you the information kit that
Carl put together, and answer any questions you may have J
I hope you enjoy FORTH Dimensions. And remember, I hope
to hear from all of you.
FORTH was created by Mr. Charles H. Moore in 1969 at the Leo Brodie
National Radio Astronomy Observatory, Charlottesville, VA. It
was created out of dissatisfaction with available programming
tools, especially for observatory automation.
Mr. Mnnre and several associates formed FORThl, Inc. in 1973
fo thf! purpose of ticcnsint;) find suppnrt of the FORTH Operating
System and Programming Language, and to supply application
programming to meet customers' unique requirements.
The Forth Interest Group ir. centered in Northern California,
Our membership is over 3,500 worldwide. It was formed in 197 B
by FORTH programmers to encourage use of the language by the
interchange of ideas through seminars and publications.
PUBUC NOTICE
Although the FORTH Interest Group specifies ail its publica-
tions are non-copyright (public domairi), several exceptions
exist. As a matter of record, we would like to note that the
copyright has been retained on the 6909 Assembly listing by
Taibott Microsystems end the Alpha-Micro Assembly listing by
Robert Bcri^i^y. Severn I cnnference papers have had copyright
reserved. The general statement by FIG cannot be taken an
absolute, where the author states otherwise.
NEW POUCY
The 79-Standard has been voted on and adipted to serve as a
coirimon denominator fnr trenspcrtahle FORTH code and for
future discussion of FORTH systems. Beginning with the next
issue, FORTH DlMENSSONiS will give prefererKe to articles that
adopt the 79-Stundard
Listings urfiich usa words that are not 79-StBndard are
welcome, but if possible explain such words in a brief glossary
with a note that they are not 79-Standard. For instance, if your
application addreaass the name field of a definition (v^ich is
illegal In ttve Standard), you should eiqjply a glMsary description
of NFA.
If possible, also include the definition of such a word. High
level source ia preferred, but if necessary, the definition may be
written in assembler.
We hope this policy will encourage unification, eliminate
ambiguity, end simplify explanations.
Page 167
FORTH DIMEMSIOMS mf6
LETTERS
FORTH AppKcation Library
Dear fig,
As distributors in ttie IK for TOI^TH
Inc*, with a rspicfly tjrowincj cLJi^t.nrn^r
base, we are potentially interested in any
<ipplicRtton software that is generally
use ftil.
MnsE: of (Tur customers arc in t.hr. pro-
cess conlrol/industrial/^cientific sectors
which, by their nsiturc, require fairly spe-
cialized and customised software. Never-
theless, vjti are sure there are many areas
of commonly useful software and that
such software would be useful even if only
as a starting point or guideline, in onjer to
avoid too much reinvention of the wheeU
Such software might bs offered as free
and unsupported, at media cost, or as a
chargeable product. Whichever way, it
needs to have at least some documenta-
tion, (i.e., overview and glossary) but it
fioes not have to be a professional pack-
age.
We tiHve an initial cnqiiiry from a user
who needs ;i 5-term controiler program for
servo control, and some process mathe-
matics for numerical fiiteritiq and linear
conversion. As tie -jaid to us. "surely
someone has done this before and written
it up enough to be useful?". So can you
help? If you're offering something free,
periiaps we can do a trade for something
you would like.
If people are interested in ^plication
exchanging we would be happy to act as a
■node' for mal<ing contacts. And where
someone has some software that has a
marketable value, we are interested in
helping to create and promote viable
packages. We'll not make any firmer plans
or suqqestions until we hear from youl
Nic Vine
Director
COMSQL
T re way House
Han worth Lane
Chertaey, Surrey KT16 9LA
Benchmark Battles
Dear Figj
I i^eliev'j that the primary considera-
tion of an implementation be fluency of
use, and not speed or size except when
specific problems arise. But after reading
the "Product Review" in FORTH Dimen-
sions III/l, page 11 and seeing some
benchmarks, I couldn't resist trying the
same on my own home-brew implementa-
tions 4mHz Z-30, 5-100 bus {one wait
state on alt memory ref's). These are the
results I get, plus another column correct-
ing for my slower clock (but not for the
wait state). I guess I designed for speed,
JUst want to stick up for the ol' Z-80.
If other people can brag about how com-
pact their implementations are, cant I
brag about how fast mine is?
Timin
□wean
LOOP TEST
Z.3
Z.9
-TEST
5.9
7.4
*TEST
S4.9
/TEST
74.3
88,6
Bonadio
4»61
LOOPTEST
1.7
1.1
-TEST
6.8
4.5
*TEST
17.5
11.7
/TEST
29A
19.6
Note
All times in seconds. Each test involves
32767 iterations.
No, I don't use any special hardware.
JiJst the normal Z-Stl instruction set. That
muittply threw me nff wher^ I first timad
it, but t.ne cycles add up abtjut riijht. 1
just can't figure out why everyone else is
so slow.
I don't have mass storage. That's why 1
skipped the last two benchmarks, 1 store
every thinq in UPRCMs. MlicK faster than
those clumsy mechanical devices,
Allan Bonadio
1521 Acton St.
Beilteley, CA 94702
Editor^ Note;
Here is the code for the benchmarks
published in Vokime III, No. It
: LOOPTEST
7PFF DO LOOP 5
! -TEST
7FFF DO I DUP - CROP LOOP j
: •TEST
7FFr DO I DUP • DROP LOOP ;
{ /TEST
7FFF DO 7FFF I / DROP LOOP }
To "G" or not t« "G"
Dear Fig,
I would like to comment on the "Start-
ing FORTH Editor." The "M" command is
bad for reasons of safety and philosophy.
It takes a line from the current screen,
and puts it "out there" somewhere. If it
goes to the wrong place (these things hap-
pen), good luck finding it,
A far better alternative la the inverse
command, which I call "G" for "get," G
takes the same parameters as M (block/
line-) and gets a line onto the current
screen. I believe that only the screen
being edited should change. M violates
this rule, G does not.
One further point! G inserts the new
line at the current line, not under it. This
allovra you to alter line 0, which M cannot.
The n(.'*r 'extension is 13R1NG , which
gets several liriKS. It takes (block/line/
count-1, 1 find .'i ;irid llRINCi extremely
useful. Comments are solicited.
Mike Perry
1 agree! G is more satisfying from the
user's point of view. With M, I find myself
checking bac^ and forth between the
source and destination blocks repeatedly.
The problem of copying a line onto line
zero with "M" remintte me of the same
problem one has with "U" (also in the
"Starting FORTH" editor). I'd like to point
out a simple way to "pu*" a line onto line
iero, moving the current line zero and
every thinq clsr- down:
T U This will be the new line zero
T X U
The second phrase swaps lines zero and
one.— ed.
FmTH in its Own Wfrite
Dear Fig,
The two paragraphs tielow appeared in
an article in BYTE Magazine on pg. 109 of
the August 1980 issue. When it first
appeared, I agreed with what it was saying
but did not feel the need to point it out to
others. Now, however, I think that it's
time to remind all of us about FORTH and
what it isn't. Clearly it isn't any other
language.
The most important criticism of
FORTH is that its source pro-
grams are difficult to read.
Some of this impression results
from unfamiilarlty with a lan-
guage different from others in
common uw. However, much of
it results from Its historical
development in systems work and
in read-only-memory-based
machine control, where very
tight programming that sacrifices
■:Marity for memory econcrriy can
be justified. Todav's trend is
strongly toward artequats com-
menting and design for readabil-
ity.
FORTH benefits rnost from a
new, different programming
style; techniques bUndly carried
over from other environments
can produce cumbersome results.
FORTH DIMENSIONS iII/6
Page 168
It still eludes me as to why peqple
insist on building things Into FORTH which
are Imports" otlner language struc-
tures and that in most places do not have
any logical place in FORTH. Surely they
would not be used by d guod FORTH pro-
grammer. Take as a simpla example spac-
ings. FORTH does not impose Indentation
or strict spacing requirements as do some
other constnints, st; why do pf^ople insist
on indenting? I riisagrpe that this cnnfri-
butfis to the readability of ths lanouaqe as
FORTH is one uf the most terst; con-
structs in existence. One mir|ht <iay that a
first attempt to improve ths rsadahility nf
FORTH should center around rp^moving the
eryptological do-dads that are used. For
instance, should bo renamed
"FETChr*. Likewise, " i " should be re-
named "STORE" and changed to
"PRINT".
Obviously this is absurd w)d so ts the
notion of indentation and otiw pseudo
spacing requirements that some say con-
tribute to ''good programming style,"
Good programming style is writing clear,
concise, fast code that does simple things
and ttien using that and other code to
construct more complex definitions. This
is the premise upon whioli F'ORTH wns
based, 1 iiave seen readable code that was
sloppily written, Coo big for the job Uiat it
attempted to accomplish and in a single
word was :sboniirtab!e. However, It
"looked neat and clejffi.''
VWian the FORTH 79 standard was
released I a (^lauded. We are all aware of
the small ambi^ities and possible defi-
ciencies in the standard. However, tlie
standards team must be commended nwre-
ly because they exist and they at least
ettempted to create s stanrlard of some
kind. Why then don't people write in stan-
dard code? It aqqr;jvales rne to see code
in your journal prefixed or post -aririrnriod
by a phrase similar to "all you ticcd tn do
to bring this code i() to the standard
is..." Why not write standard code in the
first place?
This letter is purposely provocative
and 1 sincerely hope that you decide to
pUbUsh it. Tl^rough it I hope to force a re-
evaluation of thre way some individirals
lool< at RDRTH. Some of us still think
that FORTH is elegant because of its
simplicity. It is unfortunate that many
refuse to see FORTH as the be»Jtitlit
language that it is, but aae it only as
another language that UieyM like to
resemble.
J.T. Currie, Jr.
Virginia Polytechnic Institute
8lacksbur^, VA 24061
Well-expressed, on both points! Regarding
the use of the 79-Standard, see our "New
Policy" at the front of this issue.-ed.
Minnesota Chester
Dear fig.
Greetings from the Frozen Wasteland!
This letter is to inform you of ttie
formation of a Minnesota chapter of the
FORTH Interest riroup. We have had two
meetings so frir, with attendances of
twelve and sixteen respectively. We plan
to be lutjetlriy oncf a rnonth. Anyone wtio
is interested should get In contact with us
first at the above address.
We hope to start some kind of news-
letter in the near future. I've heard that
it's possible to get copies of program list-
ings and other handouts which tmva
appeared at Northern Califomia meet<
ings. Could you please let us know how we
go about getting copies? I have enclosed a
SASE for you to respond.
One of our members is tunning a Con-
ference Tree (a Flag^^ for The Commui-
Tree Group) whit^ we hope to use for
interchange of ideas, programs, etc. out-
side U)B general n>eeting, end to comple-
ment the newsletter. The phone number
for thnt Tree is (612) 227-03D7. The
FORTH branch is very sparse right now,
however, since we are just getting off the
ground.
We are also contacting local co neuter
groups about jointly sponsoring FORTH
tutorials for specific machines, and pro-
viding a pid) lie-domain, tum4cey FORTH
system that will turn on their machines.
We currently have such softwrare for the
Apple D, SYM-i, are close on an O^oma-
1, close on an OSI, and are seeking out a
TRS-80 version.
Well, that's our plans for the next few
months* We would appreciate your cur-
rent mailing iist of Minnesota residents
C55xxx and '3(oxxx 2ip codes, 1 believe).
Hope to hear from you sooni
Marl< Abbott
Fred Olson
Co-founders of MNfig
Happy to hear about your new
chapter! Your mailing list Is on its way.
And yes, handouts from the NUirthem Cali-
fornia Chapter meetings are available.
Here's trow to obtain them:
John Cassady of the Northern Cali-
fornia chapter has agreed to serve as a
clearinghouse. The Secretary of any FIG
Chapter can mail, each month, handouts
from his own Chapter's meetings to Mr.
Cassady. In return, ,lnhn will send back
one set of all handouts he receives each
month, including thusii from the Northern
California meet inns. F.ven if a local
Chapter hns nn handouts, the Secretary
must sent at least a postcard to indicate
the Chapter's continued interest. The
local Ctiapter^ Secretary wiU males the
necessary copies to dhtribute to members
of that Ch^iter.
So, let's see those handouts from all
the Chapters; Write toi
John Cassady
339 15 th Street
Oal<lsnd, CA 94612
Brak>-5yatom
Dear fig,
The special FORTH issue of Dr. Dobb's
Journal made a deep impression on me and
on my son. My son is since 12 years a
system programmer end lenowa mere than
a dozen computer programming lan-
gu^es. I am a logician and engineer, code
designer and the developer of the only
existing proto-model of Interdisciplinary
Unified Science and its computer-
compatible language, the UNICODE.
Thus, I represfint n radically different
path of scientific development— disre-
garded by many because it does not
promise immediate financial returns.
My approach is centered on a new and
far more encompassing system-idea of the
temporary name "brain-system" having a
physical-hetera-cat^orical genetically
ordered sequence of models of logic. This
sequence taa a specific case for present-
day formal logic and a ec^tesponding sim-
plified variant of the system-idea: this is
the system-idea of the digital computer.
UNICODE is the first specific brain-
system programming language. It is a
content oriented language, it has powerful
semantics and register-techniques. It has
"words" which arc at the same time total
programs for the generation of the invars
and "content" the term intends to com-
municate.
I think to study UNICODE will lead to
unsuspected breakthrough in the develop-
ment of programming, e^ecially if think-
ing has been made elastic and modular by
studying FORTH.
I would like to receive the private
addresses of a few creative FORTH fans.
In the hope of your early reply, I remain...
Prof, nipl, Ing. D.L. Szekely
P.O. Box
91013 Jerusalem, Israel
December 1981
Anyone follow tliat?— ed.
Page 169
FORTH DIMENSIONS 10/6
TECHNOTES
ENCLOSE Correctian
for 6502
Andy Biggs
41, Lode Way
Haddenham
Ely, Cambs
CB6 3UL
England
On (-f)rn/i?rt.iny my 6502 fig-FORTH
(VI. 1) tn work with 256 byte flisc sun tors, I
discovered (after many system har-q-iipE'
that WFR's 'ENCLOSE' primitive is not
gu^srsnteed to work witli disc [Sector isizco
greater than or Rqutd to 256 bytes in si/e.
In his 'ENCLOSE,' Bill uses the 6502 Y
register to index ttirough the input text
stream, but this register is only 8 bits, so
if the text stream contains a blocl< of
delimiter characters, e.g^ 'space' bigger
than 256, it will loop forever, as I found to
my costi
When will this orcur? Never from the
terminal input buffer, which is only 80
characters long.
With a disc sector size of 256 or
bigger, if yoo have an entire sector of
apaces in a load screen, then the load will
hang iip on this chunl< of spaces.
or...
If your sector size is bigger than 256, then
any chunk of spaces 256 or bigger will
hang it.
I encountered this because I decided to
emulate John James' method used on the
PDP-11 version, where R/W' handles IK
every time, so as far as BLOCK, BUFFER,
and ENCLOSE are concerned, the disc
block is 1024 bytes, and compiling hung ifi
on any text gap bigger than 256 bytes!
Anyway, I ENCLOSE (ha ha) a revised
version of the ENCLOSE primitive which I
am now using, which has full 16 bit index-
ing. I'm suEf,- some assembly language
programmer could produce o neater ver-
sion, but at least I know that this one
works.
Keep up the good work.
By the way, IVn willing to act as a fig
software exchange/library in the UK,
unless there is someone already doing it?
•EfCLOSE- PHI«:TIvr FOR G=ez WITK !fi-:.!T ;*(DF>!xG
siACt: LOCATION, 7.1,!^ topns i'lcn ;n f- rvTr
L313
XXXI
L3I3
L3ze
L3Z7
XXXS
.C¥T£
C07 . -enc
L2i3
.WOI*D
LDA
JSft
ISETUP
rxA
SEC
SBC
«SB
TAX
STV
S3,X
STV
SI .X
DEY
DEC
SN*3
DEC
SI ,X
INV
BNE
XXXI
INC
SH*3
INC
»t,X
LDA
tSH+Z),Y
CHP
SH
BEO
L313
STY
Ti,X
IDA
SI .X
STA
UOA
(SH*Z> ,Y
ENE
L327
STY
y
STV
ilE>.X
1 DA
SI ,x
STA
TVA
CMP
.X
BNE
L3Z6
LDA
SI .y.
CMP
S5.>;
BriE
INC
BHC
INC
S3.X
.IMP
N^XT
VnA
STV
S2,X
IDA
SI ,X
STA
S3,X
[NY
ENE
INC
31 .X
INC
SN*3
PLA
S INITIALISE AS BEFORE
; SETTIKG HI INDEX - e
PRIME THESE VARIABLES FOR LOOP
) IHCREMEHT HI ADDRESS
t AMP HI inde:x
i GET CHARACTER HRCIM iKPUT Sli?£AH
i tS IT DE_1M1TER 7
! loop if true
; noh-delimit:r so put first
i RESULT OK T-)E STACK
GET CtPARACn LF /.G^,I^i
ERANCtH J r NOT A nUL L
TIOV UP RESJLTS FOR •KUt.f EXIT
IF FIRST Atj3 LAST INDEXES AKE EOUAL
THEH
lft':p,EMEHT THIS RESULT
SAVE CHARACTER
SAVE CURRENT IN!!EX AS OFFSET TO
FIRST DELIMITER AFTtR TEXT
INCRE^ijrd [itif.x
AND HI ADDRESS
RECOVER CHARACTEf.
CMP
BMF
STY
OMR
:31s
S.iJ,X
NEXT
•iCT UELIHITER
ELSE EXIT
FORTH DIMENSIONS lU/i
Page 170
TRANaENT DBFlfsBTIONS
Phillip Waason
Editor's Note: This article appeared in
the last issue, hue, unf or-ti.inn ti' !y, without
Ihf source rode, Hcrf in thp nrtirle as it
should have appeared. Our apologies.
These utiliites allow you to have tem-
porary definition (such as compiler
words: CASE, OF ENOOF, EM3CASE,
GOOO, etc.) in the dictionary during
compilation and then remove them after
compilation. TTie word TRANSIENT
moves the dictionary pointer to the
"transient area" vnhidi must be above the
end of the current dictionary. The tem-
porary deflnitloTO are then compiled into
*ls area. Next, the word PERMANENT
restores the dictionary to its normal
location. Now the application program is
compiled and the temporary definitions
are removed with the word DISPOSE.
DISPOSE will take a few seconds because
it goes through every link (including vo-
cabulary links) cind patches them to bypass
all words above the dictionary pointer.
NOTE; These wurds are written in
Micro Motion's FORTH-79 but some
nan-79-Standard words are used. The
non-Standard words have the fig-
FORTH definitiorw.
FIRST 1000 - CONSTAIvIT TAREA
VARIABLE TP TARETA TP P
J TRANSIENT ( ADDR >
Trsnsient »r&» address )
Transltnt pointer )
HERE TP a DP I I
(
^DDK )
DP I !
VQC-LINK
PERMANENT
HERE TP I
DISPOSE < -
TAREA TP
BECilW DUf
BEGIN e DUP TAREA U< UNTIL DUP ROT ! DUP 0=
UNTIL DROP VQC-LINK
BEGIN DUP 4 -
BEGIN DUP
SECIN PFA LFA 8 DUP TAREA U<
UNTII. DUP ROT PFA LFA I DUP 0-
UNTIL DROP t mJP O"
UNTIL DflOP [COMPILE FORTH DEFINITIONS I
TRANSIENT
t CASE • . I t
OF . . . )
ENPCiF ... S
ENDCASE . > . t
PERMANENT
t OEMOl
, . , CASE'
... OF ...
... OF t . .
ENDCASE
ENDOF
ENDOF
}
TRANSIENT
t WOUATE i tt —- y
OtEATE f IMMEDIATE
DOES) 9 STATE 6
IF [COMPILE LITERAL THEN
7 EENJATE SOME- LONG- MORD- NAME
PERMANENT
t DEM02
SOME- LONG -WORD -NAME . t
( SOME -LONG- WORD- NAME is troMFiled!
( as a 1 i t "sra 1 )
DISPOSE ( Removes the- wards EQUATE. SOME - LONG -UORD -NAME. )
( CASE. OF. ENDOf > anct ENDCASE from th» }
( dictionary! )
DEMOS 7 OK I T«Bt DEMOZ. it prints « »»v»n. )
RENEW TODAY!
Page 171
FORTH DIMENSIOf^JS m/6
NdVAlNiga
.lohn K. r,t)twals
Computer Technology Department
South Campus Cngrta C
Purdue University
W. Lafayette, IN 47907
I have juat finislied Inatslllng fig-
FORTH on my NOVA 1200, using the
listing I received from fig. Instead of
njmlng ft standalone, as the fig listing
does, I run it as a ta^ under ROOS Rev.
5,00.
So far 1 have founcf four bugs or omis-
sions in the listing. They are as follows:
Page in of thf^ listing - EMIT does not
Innrpment GLJT»
[COMPILE ] does not work properly. It
can be fixed by removing CFA, from
line 07 on page 42 of the listing.
VOCABULARY doas not work proper-
ly. This can be fixed by adding CFA
between AT and COMMA on line 53 of
page 44.
(FLUSH) can not be accessed until a
missing <51> is inserted after FLUSH
on line 13 of page
After installing fig FORTH, 1 entered
the CYBOS editor from the keyboard and
used this editcu" to boot the fig editor
listed in the installation manual. After
this experience, I am somewhat pessimis-
tic about FORTH's portability between
word and byte addressing machines. I had
to make quits a few changes before the
fig editor would run. Some examples!
BLANKS expects a word address and
word count*
COUNT expects a word address and
retutna a byte address.
Hf ii n nnd PAD both return word
acldressRS.
If any RODS NOVA users would like a
copy of my "fig-FORTH," they should feel
free to contact ma.
RENEW NOWl
RENEW TOOAYl
FDRTH Sandards Ctimer
Robert. L. Smith
DO. LOOP, and *LOOP
There have been some complaints
about the way that +LOOP is defined in
the FCIRTH.79 Standard. The first
obvious problem is that the Standard does
not define the action to be taken when the
increment n is equal to zero. Presumably
that M*aa either an ovnrsight, or a typotjra-
phieal error. The most likely correction is
to treat the n=0 case the same ys n>0.
since the arithmetic is defined to ho tv^o's
complement^ and for that arithmetic, the
sign of D may be considered to be finsi-
tive. I am aware of other possibilities, but
they seem to be fairly difficult to imple-
ment or explain.
The second point that is mentioned is
that the parameter range seems to have a
strange asymmetry. When a positive In-
crement is used, the DO-LOOP index I
may not reach the specified limit. How-
ever when a negative increment is used,
the index I may be equal to the specified
increment. Users of fig-FHRTH systems
have pointed out that the fig +LOOP is
;jyrnrni'trii: in thf :;eiise thuL for either
oegativ(^ or positive rncrc ■iifNits the limit
value is never reached. Hrv^ rrir^y consider
that the Standard version terminates when
the boundary between the limit n end n-1
is crossed, whether the increment is
positive OF negative.
Finally it has been rated that the
Standard LOOP and +LOOP depend on
signed arithmetic. Many, but not all,
FORTHs use a modular or circular arith-
metic on DO-LODPs, allowing the index !
to directly address memory. The use of 1
to address memory in a Standard LOOP
may result in a non-transportable program
unless a certain amount of care is taken.
The Standard version is easier to define
than one involving circular ai'Lthjnctic.
Note also that the Standard version allows
approximately twice the range of most
circular loops (such as In fig-FORThO.
The best suggestions for new looping
methods cm be found in a paper given by
Robert Berkey at the recant FORML
Conference. The paper is entitled "A
Generalized FORTH Looping Structure." 1
recommend that readers Interested in the
topic get a copy of this paper end imple-
riiorit his suggested words. 1 wqould like to
slightly modify his rrsult.s for the current
discussion. Berkey essentially shows a
technique fur looping in which the incre-
nifnl for (LOOP inay alternate between
positive and negative values without
necessarily terminating the loop. Modular
arithmetic is used so that either signed or
unsigned use of the index I may be
employed. The increment may be any
value. The terminating condition is when
the boundary between n and n-1 (actually
n+1 in Borkey's papc^) is crossed dynarni-
cally. The implemF>rit=it inn appears to be
even more efficient than that described by
Brodve and Sanderson ("Division, Rela-
tions, and Loops," Rochester Conference,
1981). The only apparent disadvantage of
the implementation is that the index is
computed by addition or subtraction. A
novel feature of Serkey's trrplementation
is that vuhen the word LFAVE is executed,
the loop is terminated at that point (i.e.,
LEAVE actually leaves). Berkey also
suggests that for normal positive
inrrern>?n!:inq loops that the index range
shouM include the upper limit, in a manner
more consistent witii otiter languages as
well as typical use in the fig-FORTH
INOFX. Finally, he suggests a construct
so that a loop may be skipped entirely If a
counting parameter is lero.
The work discussed above Is of poten-
tial interest to future directions in
FORTH It shows that FORTH is still
evolving, even though it cannot effect the
current Standard.
Potion Wanted
1 am looking for a softwfare engineering
position with another company that uses
FORTH. I would like to work for a firm
using FORTH to develop state-of-the-art
systems softwaref specifically, a FORTH*
based development nnd Of^prating system
environment to compete head on with
UNIX.
Brent Hoffman
13533 37th N.F..
Seattle, WA 98123
(206) 363-0642
FORTH DIMENSIONS m/6
Page 172
9900 Trace
Heinz F. Lerik
b'ini Woei rstfuil
I have hiid soriiy troulilt; qf^tJ.ifiq my
99Q0 FOKTH ru(«iiriy.
To PiiFje th*^ fin^Jii^i (if nn-drH [ wrufR a
p rot] rain to display all important, vectors
(IP, W, COOL, K, SP) diiij Lltn first 7 at;u;i<
contents. Even tlK; aUivk'n iiiriwiivtj is
visible.
i would like to cnntributi; it tu yuii, sii
you can offor it to nil 'J'J\H\ u-jnin with h
lOOM or siniil.ir hoard.
It was a nreal luck fur ir>e that I did
not need the adilresses /}7C and /57I , und
i;ould UDO it for y hrani-h tii the '*)TAflir>
prorjrHin. This program is switc^hed off hy
the code HF"X 4")^ JSil ! and switclnid nii hy
HtX 384 : ,
The program list nontains the routines
for terminal input and output, too.
I hope I i;an help somi; pc^iiple with my
pro^r^din.
* ;:UBI'-KUGf<ftr! to OUTF-UT STKINR TITRMINATfD l>Y >00
I c:all wnit xop sAORtss, i
nij I oK-rji vvnrr
SiV'iTttl 1)1 H-NIJI Nl) COnh l-Oft '
r-uii.ouimi p uniiiifti-ii, ;;tjreoi<i
■RMIT' iwiiihiiruijuy.
tM iri Hi.inKi)
■| rv AND
rn FA^t t.'Ki-fUk r iKDinii nn ri i'a j\ riaiisieoM
TO F'Fi 11-11 ni.ii I ME i-nm icii'. aijo iiii i ii;;ii
-.ievf-rj !Nsi:i^ i:ijuri tiii-i
* nrin/ i i-. ni , i nr i4tN!'' n-' ihe k u'h-iu i/* ^/*<)i uiiiidt^irui
* I jl FfMllMV. 1 LViij'T/n I
AORtI
44
44
FFOO
()A1 (\
i-Tiii;-
XI IF' 1 VF l.niD Ml'
46
00
llt'i 1 A
Fit MTDY
XIII- 1 vF, fjniD i-i:
48
FFllO
tlA TA
.[-1 ....
xiiF- VI r 1 III. WD
4fl
HE
UAIA
( Ki fv;f-
XUt- VI' X II IK )-F
4C
DA 1 A
■1 F ;'i>
JIIF- ■. VF DltlD WD
4E
CO
OA 1 A
ME Ml 1.'
XI ID '. ul 1. ml* Di:
SO
FF2i>
UA 1 A
■F 1 -.'I.
XUD 1 VI i:dfI( WD
Dli
DA 1 A
WL IKFV
XI ]r 4 V3 i: E 1 II.' 1 'i:
t M iUJ Bf-iIA III
MFMII ri
IN IF II f.-^ KEI
* CAI i Ifti Ui ^OP tt-iti. 1
AOI4>
'.'on
(flNlHV 1 1
HI.', H"
M 1 1 :|.i il..viE
U'J
HI
IFIS
ID
.'I
DI i:i IVJ 1. DDI . 1 III ]
(16
lire
.INI
D 1 MIDV
m
;i 1 1 IK
•Kl 1 . /
IF mil llM.l 1
It 12
••IW
111
(.1 11 IWD IMIl,- IlliDi
SC.
■■-no
KIMI-
I wm IF A i:ii/mjai: k.i.- in
1 1 1 MI'.I M n 1 1 ■
t CM I hIJ III XOI
*tfll, .■
Si!
Fni isf- J I
Sil 1 IIDODd'il.
vo
Bi:i
inio
r.ru)
w.
D 1 1 IIJ
94
1F1&
IVJ 1 D
IDf.N' .I'll 1 Dill . 1 Ml ' 1 V '
'/h
K.Hf:
JNI
1
fft
T.'/ ID
-.!/
D';d •
9A
IbFE
.DHL
1 J/
■>i;
',■.■1 H
1 IH:l<
♦1(1 1 ,n
ON 1 DI F 1
•}E
If Ifc
te'j:.* id
IllllWilll 1 DIJF . i DDI V'.'
«•:!
K.tt
.ihl
(1.;'!'
na
IFl 7
1 D
IDANSINI 1 FHFIIF- F E-MF' lY
A4
16FC:
.INI
II..'.'
380
K-1 Wf-
na
OAiiO
1 Dl 1 Hi
I.F.-.I F
AA
TEXt
'■ ip,...
1 L A 1
" W "
et
S3 (FlI
" mill
BC
S4 T L X T
..
L2
sa rtxi
" SI--"
Mcni D mvEt
» F( 1 1 * . r:;
FFICK BYTE
CA
.ti;n
mixjT
EXir If 2E.KU
<.'n
Cl.'07'
Kor'
fc'.'.i'
F-DENT ASCII CHAR.
CF
IIJFFC
.1 m-
tiKMrf!
Du
'300
MDXIl RIUF-
♦ FiUbPDOODAM TU tJIJll-UI (■
III. X WIIDIF
1 e:ai e y.uE '
*
lillURFC, 4
Wt.NNiV I I
F<) , 1
I.IJl INI
04
MOV
«R1 1 ,Rt 1
FirTtll WUDLF
Du
iilil'J
F< 1 1 , 4
Al rtiMMrrn
DA
/ II*
WtJFXI Ml IV
RIliRi;
noFY
a!^
ANDI
Id', - iicoi-i
MAUI OUI
Fi n"i
r
1 -'.
I' J
NIINBI: Ft '
'
t- 4
.11 )
.Ml IM
Fip
Al
tC, .■ /•JIJ
AIJ.II.Il.i 1 It! K.K
IH
f A
. ' ' '
Nl m A 1
i.O['n)
Ai),io;ii a;>i;ii
LtJ
If.
yiiD
D ,:. '.'
DDI Dill
FJ>
ijrt'
tint:
D 1 1 , I
!1I(IF I
F
i>fe:
DI
Dill INT t
H 4
1 rtl L'
.IMF.
WNF X 1
iliRII "
t £>
"^^ NO
H 1 Wf-
1; X I 1
» PDINI FilrtlEI!)
I 'UNI, It AN
• 1 F.l E) 1 (.ID 1 iF' Dill 1 1)1 lit 1 HI'i
F-51 t UP
i II
1 ni M 1
SIAIIIFi Nlll"
SF--ADE.
I A
I'l^t. ' '
>l FF'
■j AH,
Ml il.i 1 F -
f F^
AO
1 t
r.£j. >v
I-IIIV
LillF-y
n H h
f(4l N
1)1 i:i
1(1'
III 1) EF-'
t('l^
'^1)1 ]■ 1
KtlF'
H:', 4
OIllDUl /ID
1 ■ I'l
■. 'l!l
XIIF ■
'1 Al. , *.
h'ili /W
l(j^i
JiJll
IJf " *^^
MOV
1.; 1 1 . itii
1 'jA
i.4 r '
1)1 r,i
D. 1
loi:
.■|> ni
XI fF '
DI 1, 4
DC
•Ji::l • ■
)ti FF ■
M lifl , '
MliU l,:UI)l:
MO
D4
1 I *
XI If
h'Vh, 1
I 1 4
.■I.E.. 1
XUD
■i Dir.";.
M'Jli /If
1 I .^1
HI !
1 1 U
^'1)1 >A
X( IF'
D 1 " , 4
J 1 A
.'III 1 '
XUI '
'a i:':'
Nlili /!iF
1 I D
1 ] 1
.'1)1 1)(
XIII'
DU, 4
1 :•'.>
1 1 k .1 1
Mill
4 E1U 1 1'lii / r, 1 Al :i '.i
1 -
'.'i'l
1 1
F. 1 , / 1.
1 II IN 1
1 .'4
/
1
Di H 1 1
ni IV
1 '. 1 A . K ^
F-F lUII 13TAI>: SIARI !iIAX
J L'H
'I t A
1 ^^A
1 I
It'.-, ■'.■...11
1 .F-Ar;|-
F ■.'[.'
I .^D
Ji.at ■■ 1
liDOIII XUD
Ft-'. '■
M5ili HI. AND
1
'..'!) 1 ''.
HID
• It .' ,4
PD EMI F II- X
ii'.'M <.
C
tt -..If 11
DIIDDINI !iIAn- F=III1MII IC
1 r.'i
I ".1 1 '.
.11 1.'
i.ri mi
.IIIMI- IF F I.'UAI
I -IS
/.4
Df.CI
D ;
Ml » 1 :;iAi:i
1 M
f.i.'i
1)1 i;
DI
1 .1 II IM I 1
1 '.n
1 f .( V
ini
1 1 1 ni 1 1
DI l-'l Al UNI 11 /I-.DU
1 m:
4^^
in t X 1 1 1 1
t .' 1 1 fii ' 1
DI ^;i IMI UIH.-I DV Hfl^.
• mi ill;ll.lNi.(
hVNa.MH. D.-IM f-.E I Ufj/il 1 1 IN F-ltODItOM Dnt ^-^i
f Mfll WI1F*F. Ul III AW FJNIl^DfllMMtr) DAIAlilIli.
* IIUlj 4 1 INF tl
IK 11. VI. IIII
F'Etlll'l t-M.
AOIi'li
^4 A
'.(I A
4T)'i
i;i,f<
*!»
i':i KAD Dfir-i AljDFtl.iiy
i.il;
(;;.:,:,
i-ii 11.'
*i.-:-.. Lit'.
1)1 IMMY
'■■11'
1 l|:|i
,ii;rj
!ji'Ai(i :ii
.lllMf- DAI* IF" tt.HQ
1 1 11 iij
NIII-'
■.:'E
(Ell .
:•••/
Ffl
I /I I
If. 7
Ilir INNLD: INFE-F-DI II f. 1 i-l DUf-iNUMF 111 PFINl All
D(llNVFIJ''-i ( ID.W,rOE)f HflDV.ff.fiF-) AND SI ACI- .
FMfc SEA EI)!:, EU bWIEE;EII.() (IN liY FIE. X ■VS.' ■.U4
lEFF [ilAEllS D'. r,UIT|-HI » OFF P¥ HFX 4n?j 3H4
FVEIFfEa ■i./IZ
I 1 HV, FH CE; OF HEATUfi
MOV *llf-l,iU
MIIV t/Wi.JTFMP PCFINT TO BODY
U *!!'/ tKANCEl ID SlAIlJ!i
Page 17i " "■" ■ ■ " """ " ' " FnRTH nitvlENSIONS I1I/6 "
A TECHNIQUES TUTORIAL: EXECUTION VECTORS
This month, we continue our explora-
tion of FORTH programming techniques
by taking a look at a concept known as
Execution Vectors. This is realty a fancy
name for very simple concept, namely
using a variable to hold a pointer to a
routine that is to be executed later.
Henry Lax en
Lexen & HtairiB Inc.
24?01 Southland I>lve
Hay ward, C A 94545
however, control characters wilt succeed
and will be inei«mented hy 64, making
them displeyable.
There are several ottiei' FORTH words
that have proven useful to vector. Some
of Liiese include:
DIE Is used to send an error message to
the terminal and reset tlie FORTH system
into a clean star.e, EXECUTE: is a ds fin-
ing word which initializes itai^lf to IDIE,
but hopefully v/iil be changed later by the
user. Words defined with EXECUTE! can
be changed v/ith IS as follows;
It is only fair to warn you that the
dialect of TtlRTH thnt 1 am using is the
one discussed in Starling FORTH by l_eo
Brodie. It has several differences from
figFORTH, not the least of which Is the
fact that in figFORTH EXECUTE operates
on code field addresses {cfa,Hd, while In
Starting FO^TH EXECUTE operates on
parameter field addresses Cpfti^. This
may not seem like a big deal, but if you
have ever fed EXECUTE a pfa when it was
expecting a cfa, you have undoiibtedly
remembered the result. Anyway ► my
EXFCUTE uses pffi's. Its fanctinn is to
perform or EiXb!CIJTLI the v/ni'd tti^it thii^
pfa points to. An example will clear tliis
up. Sifipose we have the following:
! GREET ." HELLO, HOW ARE YOLT" j
• GREET ( LEAVE THE PFA OF
GREET ON THE STACK )
EXECUTE { AND NOW PERFORM IT >
the result is:
HELLO, HOW ARE YOU
which is the same result as Just typing
GREFT.
The above may not seem too signifi-
cant, but the implications are tremen-
dous. Consider the following examples:
VARIABLE 'EMIT
! EMU C CHAR — )
'EMIT i EXECUTE i
' (EMIT) 'EMIT ;
I assume that (EMIT) is a routine which
taises a character from the stack and
sends it tn the terminal. By defining EMIT
to use 'EMIT as an execution vector, we
now have the ability to redirect the output
of FORTH in any manner we choose. For
example, suppose we want all control
characters that are sent to the screen to
be prefixed with a caret. We could do the
following;
t C0«TR0L-EHIT t CHAR )
DUP 32 < BLAMK > < IF i Control Char? J
94 t - t (EMIT) < y»», Mil •» - >
64 t ASCIJ A » 1 ) + ( and convM-t it >
mat
lEHITl f
• CaNTaaL-EHIT 'EHIT •
Now all regular characters will fail the
test, since they will he larger than blanksj
KEY input from keyboard primitive
CREATE change header structures
LOAD useful for many utilities
R/W disk i/o primitive
For eKarDpk^, if LOAD were vectored,
then by ^ininrj it to print ;i ycrpjcn
instead of lo^tciir.rj it, you cnuld write a
print ullNtv which prints scrr=cns in load
order by LOADing a load screen and rede-
fining LOAD to print. CREATE could be
changed to add the screen number of each
definition to the dictionary header so that
it coutd later be retrieved with VIEW or
tfie equivalent. KEY may be changed to
get its characters from a file somewhere
instrsfid of the keyboard. In short, there
n.-R ii Thousand and one uses for Execution
Vectors.
Sut be careful, 1 may have opened
Pandora's box with the above sellinq joiJ.
There is a price to be paid for execution
vectors, and that is complexity, ttie arch-
enemy of reliability. Every word that you
decide to vector at least doiAiles the com-
plexity of the FORTH system you are
running, since it introchjces at least two or
more states that the system can be in.
You must now also know what the version
is of each e>;ecution vector you are
using. If vni; havo 7 different EKITs and 2
different Kr*-'?; =.(id 'i different LOADS,
you havK a total of 18 different states
that the system can be in just on these
vectors alone. So use vectors sparinglyj
otherwise you wili lose contrnl of the
complexity very very quickly.
Having decided to use execution vec-
tors, we're now faced with different
approaches towards implementlrtg them.
The one described above works, and is
used by many people, but It has one unfor-
tunate property, namely the need to name
a variable which is basically overhead.
Here is another way to accomplish the
same thing witliout having to define a
variable. Consider the following!
: DIE i ■ »
I flDiliVT ■ THIS HSULD HOVE [a*flaHSD!" I
1 EI^I^LL1]E[
CNEAIE ( I
(■] DIE ,
DOES> I »
> EXECUTE I
I IB < PF« I
EXECUTE: EMIT
• (EMIT) IS EMIT (or perhaps)
' CONTROL-EMIT IS EMIT
What EXECUTE: has done is combined
the variable name wiiJi the Execution
Vector name into one name. IS is used as
a convenience, so that the user can forget
the Internal structure of words defined by
EXECUTE:. Also it provides an extremely
readable way of redefining Ext^firtition
Vectors. Notice that as defined, I^i may
only be used during interprettition, I leave
it as an exeivisiv for the reader tn define
an IS that may be conpiled within : defini-
tions.
Another approach to redefining execu-
tion vectors is via the word ASSIGN. It
could be defined as follows:
I (ASarONI I OFA — 1
R> Z-r Eunf> • f
I ASSIGN < 1
COMPILE (ASSIGN)
C > t CFA a 1 LITERAL , | ItWEDIATE
It woulfi be used as follows!
1 UPPER- DNLV t 3
E' ] EMIT
DUP *?A C ASCII d-1 > > IF
DUP 133 I ASCII in ) t IF
J2 -
THEM
IHEH
(EHITI < AS ALUavs > I
When UPPER-ONLY is executed, EMIT
is redefined to execute the code follnwinq
the ASSIGN, which will convert all lower
case characters to upper case, and send
them to the terminal. Note that uf>l(ke IS,
ASSIGN may only be used within : defini-
tions.
That's all for now, good luck, and may
the FORTH be with you.
FORTH DIMENSIONS in/6
Page 174
CHARLES MOORE'S BASIC COMPILER REVISITED
Michael Perry
In this papw I wlU discun several
interastinq featutes of th« "BASIC
Cofipiler in FDRTF-T by Charles Moore
a981 FORML ftoceedlrqs).
Why ts a BASIC compiler interesting?
There are a number of [nasons. Foremost
of them is that BASIC is in many ways
typical of a veriety oi piipular languages,
particularly FOKTfiAN, PASCAL, and
ADA* Conspicuniis fecii'.^.jrf^.^ of tiiese lan-
guages are algebrnic notation, lack of
access to the underlying hardware, poor
input and output facilities, and non-exten-
sibility. FORTRAN and BASIC also suffer
from poor stnicturinq riup to tt^e e>; tensive
use of GOTO. These languages aU tend to
be ba^ at aolvitig equattoiw. OUier prom-
inent faatgra« of BASIC are it s use of
statement numbers as labels, low speed,
and Its use of a few complicated functions
(e^T PRINT) rather than many sirrple
ones.
Why is it slow? BASIC Intsrpieters
usually convert source code statements to
an intermediate form, where keywords
become tokens. The token interpreter is
slow because tokens must be deciphered
(translated into actions) at run time. This
BASIC to FORTH compiler produces code
w*iich runs unusually fast. This is because
it produces FORTH ohjeot cnde, i.e., se-
quences of addresses of code routines.
Vou should look at tiw example pro-
grams (blocks BO -82) before reading the
text. You wilt notice that each BASIC
program becomes a FORTH word named
RUN. It is executed by typing its name,
l.e., RUN. This is how BASIC usinlly
works? you type RUN to execute the
program. It serves to demonstrate that
from FORTIH's point of view, BASIC only
l<nows one "word," RUN. Is it not more
useful and flexible to let routines have any
name, and to be able to execute any of
them by typing its name? Yes, and that is
a key feature of FORTH.
How It Works
1 will refrain from commenting on the
intrinsic value of a BASIC con^iler; that
has already been covered well in Moored
papw. The principal features I will dis-
cuss are the hnndiinq of operator prece-
dence, variables in alqebroic equations,
and the usa nf tlie TOR TH cuiripiler. The
most imprirtanC part nf this iiASIC rn.n-
piier is its ability to convert ;5lrcb:aio
(infix) source code to reverse polish Cpost-
nx) object code.
A BASIC program Is compiled in;;idf>
the colon definition of a word named
RUN. This means that the F- Oi-i th system
is in its compile state, and any words to be
executed (hiring compilation must be
immediate. This use of the FCJRTX com-
piler was perttaps my greatest lesson from
studying this BASIC compiler. The ordi-
nary FORTH cooTpiier is far more versa-
tile than I had realized. If I had written
this compiler, it would doubtless have run
in the execution state and would have
been far more cniT\p liri^t.orl as a re[3Ult.
Let's look at an example. The BASIC
sta tement
10 LET X = A * B
will he compiled into object code equiva-
lent to the FORTH expression
X A ISi S 'ir + SV.'AP ;
where K, A, and B are variables. One of
the varisbles (X) returns an address, the
rest return values (with a fetch). The add
is compiled after the fetches of the values
to be added. The equals becomes the
" SWAP : " at Uie end. Because the source
code (in BASIC) is in algebraic notation,
and the (FORTH) object code is in reverse
polish order, some way is needed to
change the order of operations when com-
piling the BASIC program. The mecha-
nism which controls the compilation order
is based on the idea of operator prece-
dence, which means that some operators
are assigned higher priority than others.
PRECEDENCE
The idea of operator precedence is a
prominent feature of most computer lan-
guages (FORTH is a notable exceptiad).
Operations are not necessarily performed
in the order you specify. An example will
help. The equation X ^ 5 + 7 * 2 could
mean either X = (5*7>*2 or X = 5*
(7 • 2), usually ttie latter. In FORTH this
would be 7 2 * 5 + X [where the order is
explicit. In algebraic languarjcs some
method is needed to clarify the order of
evaluation of operators in expressions.
That is what precedence docs. Each oper-
ation is assigned s precedence level.
Operations with higher precedence are
performed earlier.
During compilation of the BASIC pro-
gram (the FORTH word named RUN) the
coirpilation of many words is deferred.
This allows the order of words to differ
between the source code and the object
code. TsJce '+' as en etxarnple. To dbfer
compilation of V a new word is created
which Es immediate (and so executes at
compile time). When this new word ia
r.'xecijtpd, it leaves ttie address of on
the stack, and on top it leaves the prece-
dence value of The defining word
PRFCFCnriMCr creates the new word as
follows; " 2 PRFCFOENCE + " . This
creates a new, immediate word named 'V,
wliich will leave the address of the old
word V under the value 2.
The word which decides how long to
defer compilaUon is D^ER. DEFO^l
looks at two pairs of numbers on the
stack. Each pair consists of an address
and a precedence value. If the precedence
of the top pair is larger than that of the
lower, DEFO^ docs nothing. If the top
precedence is less than or equal to ttie one
below, the address part of the lower pair
is compiled, and its precedence is dis-
carded. DEFER will continue to compile
until tlie tqiper precedence is larger than
the lower.
So how do you get started? Essen-
tially, most BASIC keywords (such as LET)
execute START wqhich leaves IvIOTHING
G on the stack, where ■NOTHING Is the
address of a do nothing routine and is its
precedence. This pair will remain on the
stack during the compilation of that
statement, because everything has higher
then zero precedence.
At the end of each line, RPt^J is execut
ed. It performs a f! I DEFER, which
forces the compilation of any deferred
words, because evety operator has a pre-
cedence of at least I, RPfsl then consumes
the and executes NOTHING. Actually,
each statement is ended by the start of
the next, [3ASIC keywords such as LFT
executi? STA.TEivlENT, which contains
RPN (to finish the previous statement) and
START (to begin the next).
BRANCHING
Three new branching primitives are
used. They are compiled by various higher
level words. JUMP is used by GOTO.
SKIP and JUMP are used by IF-THEN.
JUfyfP is compiled followed by an ^solute
address. When executed it simply loads
that nddrt^s? into the IP (virtual machine
instnicti'in r.i?iintrar). When SKIP executes,
it takes a boolean off the stack. If true it
adds ^ to tlie IP, skipping (usually) the
following JUMP.
(NEXT) is used for FDR-NLXT loops.
It is compiled followed by an albsobtte
address. When executed it takes three
parameters from the stacki final value of
the loop index, step size, and the address
of the variable containing the current
value of the loop index. It adds the step
(plus or minus) to the variable, and lot^s
until the index passes the limit.
Adding GOSUB would require another
branching primitive, CALL.
Page 175
FORTH DIMENSIONS III/6
STATEMENT NUMBERS
Each BASIC statement must be pre-
ceded by a number. This number acts as a
label, allowing branches between lines. In
(h\is compiler, the numerical value of the
labels does not affect execution order.
When a statement number Is encountered,
[t is conplled in line as a litetaL The
address of LIT is compiled fiallowsd by tiie
literal vakie 10. For example, when the
statment "10 REM" Is encountered, 10 is
compiled as a literal. The keyword REM
is immediate, and so is executed. It
begins by executing STATEMENT, which,
amongst other things, fetches the value of
the line number just nompiled (10), and
enters it into the :;^ate!iwnt number table
Ut5) along with the addrfiiis (HEKF:) of the
start of that statement. STATEMI^NT
then de-allocates the sp^^oe used by the
literal 10 (with a -ii AH.DT). l' si:aiis the
table and resolves any forward references
Co the new statement. When a forward
reference occurs, as in "GOTO 50" before
statement 30 is compiled, GOTO compiles
'JUMP 0'. The zero wilt later be replaced
by Bie address of line 50. The reference is
entered into the table with the address to
be patched instead of the actual address
of statement 50. Additional forward
references to the same point will be
ctiained f^nc^ other. To indicrite that
this is 3 fnrw;j[-d reference, the address in
the table is neqatRd. TFit^ means that
BASIC programs rnnst he oonifiiled below
BOnOH, so that ail adrircispE appear to be
positive. Here simplicity was chosen over
generality.
VARIABLES
There are two particularly Interesting
things to notice about variables. They are
immediate, and they know which side of
an equation they are on. Three types of
variables are supported! integers, arrays,
and two dimensional arrays. Variables
mast be rieclarerl (defined) before use.
The BASIC expressions: LET X = A + B
(where X, A, and B are variables) compiles
into the following FORTH equivalent!
X A @ 6 il + SWAP •
Notice that when an integer appears on
the left of an equals sign, it rmist compile
its address, and when on the right side, its
value (address, fetch). Also note that only
on» can appear on the left, while many
can be on tlie right.
The way this is implemented is sur-
prisingly simple. The variable ADDRESS
contains a flag which indicates which side
of the equals sign a variable is on. The
word LET sets ADDRESS to 1. "INTEGER
X" creates a variable named X, which is
immediate. When X Is executed it com-
piles Its address. X then examines
ADDRESS. If it is true (nonzero}, X
simply mekse it zero. If /^DRESS is
false, X compiles a @ after the address,
thereby rturning the value when the
BASIC program is run.
Notice that the equals sign plays nn
role in this process; everything is done by
keywords (e.g., LCD end variables.
Future Directiotis
Many more 'features can easily be
added to this BASIC compiler. 8ut why
bother? A much more fmitful line of
endeavor would be to make use of the
lessons learned in this compiler to write
compilers for other, more useful, lan-
guages such as C AC compiler which is
easy to modify and extend, and just as
portable as FORTH Is, could actually be
This article is an enhancement of the
idea presented by Kim Haris at the
Rochester FORTH Conference (from the
Conferenr:e Proceedings, paqe 97).
Basically, the article proposes a wordset
of primitives for defining control words
such as IF , ELSE , THEN , DO , LOOP ,
BEGIN , WHILE , REPEAT , UNTIL ,
AGAIN , CASE , etc. Kim points out that
these stTucures are either compiling a
branch to a location not yet defined (such
as IF — > THEN ) or back to a location
previously defined ( BEGIN <- UNTIL ).
There are two steps in compiling either
kind of branch: marking the first place
compiled and then later resolving the
branch. This observation leads to four of
Kim's words:
>MARK Marks the source of forward
branch and leaves a gap.
>RE50L\C Resolves forward branch and
leaves a gap.
<MARK Marks destination of bacle-
ward branch.
<RESOLVE Resolves backward branch.
I complement Kim at this point for his
excellent choice of names. Hero's where
ufii^fiil. Another area worthy of effort
might be generators for machine code, a
common thing for compilers to have.
Conclusions
It is possible to use FORTH to produce
portable compilers for other lanquages.
Doirq so provides insight Into the nature
of languages, and the desirability of vari-
ous approaches to problem solving.
Whether the compilers themselves prove
useful or not, it is worthwhile to write
them.
(screens on following pages)
compiler security comes in.
The word >RESOLVE is fiUinq a gap
left by >MARK . If >RESOLVE were to
first check to make sure a gap was there
( OOP @ 7PAIRS } it would help ensure
that the value on the stack was indeed left
by >MAm< . Likewise, If <RESOLVE macte
sure that the point where it branches back
to does not have a gap ( DUP li NOT
?PA!RS ) it would guarantee that it was
not answering a >MARK . This method
allows some cornpiler security where it Is
important not to carry pairs on the stack.
Examp le:
! >MARK HERE , ;
! >RESOLVE DUP g 7PAIRS HERE
SWAP 1 •
! <MAFIK HERE;
! <RESOLVE DUP P NOT ?PAIRS , ;
! W C, >MARK ;
! ENDIF >RESOLVE;
: ELSE C3 IF SWAP ENDF ;
! BEGIN <MARK ;
: UNTIL C,<R£SOLVE5
: AGAIN C3 UNTIL ;
: WHILE IF ;
1 REPEAT SWAP AGAIN ENDIF ;
Transportable Cmtial StiticlimB
With Compiler ^curlty
Marc Perkel
Perkei Software Systems
1636 N. Sherman
Springfield, MO 65B03
FORTH DIMENSIONS W6
Page 176
n
1 metJLA^Y ftfiiTNnETi: m^mm KFiniiieis
2 voataim im^: mmLisi imi fikih MimniMS
3
s : ism tL wmmx mim mp
i : (.1 S->t SiM> OVER MBS <l 13 SIGN t) {
7 fl VflPifELt tS 123 5LL5T
s : 5c»i : n :» tS *■ ;
? ( Pr£:edS!iC£ ' 1 tLMl 2 +L(1*D 3 ^flM
10 i I »J sonB i iniiEsiflrE
1 1 ARtTiinEIiC 3EF IN] TICKS
J2 i MSIC j 4 >im 5 HDftB i HUM 1 HJWB
1? i 1 10 tj ; ItMEftlATE
U t ; [ n] , ; 1 niECEKtiCE g
19 FOftlH DEFtNntEMS
74
t I Branching • Jiigh levEi )
I
; ! JUfip «> s >s i
3 : SEIP IF R> 1 t >R m» ;
i ! iKXli i ts \ stip \ variable iHlirsis — 1
5 ; jid step to var i
i ,R ;m!P R> 3 S^fiP i t ; i V ; !
7 0< IF EHflP THEN -
8 IK IF mm r; it elk s) « them >R ;
t I mm CWILE IKEIT) , ;
id
II
12
13
H
IS
74
6 i Stiteient mtten)
1 ; FIM ( n - a) 1 tS » IS 2* DC
2 OVER I S = IF ZCfiDP I 2* LEftVE THEK * tLWIP
3 IF n SSftP (5 5 21 *% 3 2* 1 tS '! THEN ;
5 : RESOLVE [ n) FIND SUP i SUP 0^ ASGRT' iiucli:at£d'
i etGlK ?HIP HKILE mi HERE RGT f REPEAT
7 HERE mmt me : t
S : CHAIJI I n • 1) FIND m i Qiif i mtiti
f ELS DW a lERE RDT ' THEN ;
10
11 i STATEIENT ( nJ mi > i ? * ALLBT RFN CPA EiECUTE
12 R) REMVE laxtfim START ;
13
U
15
73
[ PrccedencB !
VARIAKE tSmSi t IWIIASLE t(
; } 'ID t( t! tl i IK ABDfiT' UnHtehid )* | IHIIfllAfE
1 DEFES ( i I i I - i ■) l( t •
BESIN 2SVER SKAP DRSP OVER < m
mii£ 2mf m» cfa , repeat ;
: FffiCE^CE ! n ' ) IN « ttmm MR IN !
'SailtS , S> . ISIIESIATE mil 2) DEFES ;
: SPN ■; .V ; iSFfS :iiS5F i; J OS iSW Sv»t4K" !
i 5TSPT ! - a ni li ! C ADDRESS ' NDTHINS
iSITHHETi!; ; DIHEBIATE
; 716H0RE t! S IF 1 DEFER 2DS0P R> IROP IREN ;
7S
t VtriahSeO
: INTEO <BUIIIIS « , IMEIIAtE 1KIES> tCBXPllEl LITERAL
AliRESS ) IF « mess < EL3£ CDI«>IU i THEM ;
; -.fam) ; 3 a - s p ;
ESiP /R ' SEFEB p.- iffiKflLEl LITESIS.
SiCKESS j iF ftEiiPESE I
ELSE 'J 7 H i * ISttAP THEM i
t 1-3 ( 1 a - s; S««? 1- !» * ;
I WRaf ( ft - ; BiJli-ES ;i ALLOT HMKHIAIE
DSEE> ' l*i ami! ;
: ItH < K y « - al RST MT }R 1- OVER j t R> * 2H ;
: Itrnt < y X - ! <SU!LDS fiUP , t 2t AilST IRHEBIAIE
lOfS) ' IW lAttSAV) ;
77
i LET SiflTEKENT 1 fiiiDRtSS ! i INHEeiAH
: FIK [CDIS>[LE] LET : innEIIATE
: [i: CeKflLE 1 ifERE ;
: TC RPN DSSP ' ir, v ; llfflEBIATE
: ilEP m DROP ^ HEKE ; IBEDIAIE
t KIT STATEMENT JDRDP ' mm t I MMESS ! | IIRtEDIATE
t KM STATBEKT II i CA I I* Ult « '. ; IHOUIE
: [CffifPILEl REIi ; IHttElIME
! STIir SrATEHEKT CDHPILE ;5 ; lIDEDiATE
: END STftTEKEKT 2!IRDP tCailPILE} ; EOlllFlil] FORTK ; iHWPIATE
: (5ST3: ;eETt; nzmii JURP OIAIN , i
; S3TS SlFiTEitEST (ESTS; ; IJlfElliATE
i IF SrATEBENT LOSIC ; I)U)EBIAI£
I TISN mtl COMPILE SKIP <SDTO) ; lIUSDiATE
Itichati Pirry lie<
Page 177
FORTH DB-IENSIONS m/6
?s
: flSK ." ? " SKftf i
; PUT !8EJI1 BKSP • ;
i nmii mfiis m ;
1 t,l t n) {.! » DVEfi - Setm TVre SPACE ;
: , I n) ?]EKIfIE ' (,> 1 KFEI! ; jfflEIIIATE
i • ICWILEl Wm I IMeiflTE
imt DEFINITIONS
: , ?IGiQRE m flKPUTl 1 ADDRESS ! ; inOIME
«inKIETIC KFiKITiniS
: PRINT STATEREXT CDKPIIE CR ' <,! 1
: iNPui statehent 2!>m cdhpiu ask
i mmsi : r indediate
INEIIIilTE
flHPtITi INPUT
LOSIC CEFIIiiliSSIS
i </ t n ti - t ]
; <= I n n - I 1
i [ (I n - t 3
= SOT
2 PRECEDESSt
2 PflE:tC?SC£ '=
2 PSEEiiSENCE >-
2 F^DEHCE
Winnie tEFimnHB
: = < a I!) SNAF : s 1 PRECEDENCE '
! tt I r. H - tit
1 PRECEKIICE m
5 fRECEDBICE It
t PSECEKHCE t
3 PSECEMfCE t
2 MCEBCieE <
i SIMP i DO OVER I LDDP t
1 PRECEieCE -
2 PRECEIEJICE /
4 PRECEDENCE t,-
i t DNVEr, paoE 17, Prggrai 11 SOt
1 IKTEEER J IHTE^ t
2
3 ; RUN START
t 11} PRINT ' TNiS IS R CaiiHITER'
S 20 FOR e = 1 TD 4
i 34 !WiNT ■ NBTHINS CAN SO'
7 « FOR J = i TO 3
3 50 PRIST ■ NRBB'
9 15 fiEis ;
10 7* KEH K
11 S{l END
12
IJ RUN
it
IS
E!
< tific: imy deiii } SCR
INIESER K
! ARRAY CDHiailNATE
: RtRI START
10 FOR K = 1 ID 1
29 LET COfflSiNATC K = t 1« - K ! t> I
14 mitr CeORDINATf K * S
H) REIT K
SO END
RUN
I basic; itipst/priet 1
INTEGER e
mim t
INTESER Y
i mw START
10 INPUT II , Y
;E> lET = X I Y
K F?:Si I , Y ,
90 END
II 3
iitiimtiuitttttmmtimtttittHtiiiimnit
X
I Nichael ferrv
t Stanna;e Ave.
I SerkEley, Calif. !4T42
I <41S) 32i-S6;&
I
ttttiiiitttttimiiiiiiittiiimtiiimiiitttiMt
HUhael Pfrry 1983
FORTH DIMENSOMS m/6
Page 178
A ROUNDTABLE ON RECURSION
Recursion, as It applies to FORTH, is
the technique of definirtg a word in such a
way that it calls itSRlf. One nf the nicfist
exairifjif^s I've seen of a qoQtJ use for
recLJrsion can be found in Duuylas R»
HofGtadLur'a book Godel, Fscher, Bach .
He describes a system which nan produce
gramaticaUy correct phrases out of parts
of speech.
ril uae FORTH to describe his
example:
; FANCY-NOUN
4 CHOOSE
(select random number 0-3>
CASE
OF NOUN ENDOF
1 OF
NOUN PRONOUN
VERB FANCY-NOUN ENDOE
2 OF
NOUN PRONOUN
F/WCY-NOUN VERB ENDOF
3 OF
NOUN PREPOSITION
FANCY-NOUN BNKIF
ENDCASE;
Three of the four possible variations on
FANCY-NOUN include a call on FANCY-
NOUN itself. Case minht produce
"books." Case 1 might produce "rTian who
reads books*" But Case 1 miqht also
produce something more complicated, like
"man who reads books that explain alge-
bra," if the iner call to FANCY-NOUN
decides to get fancy.
Normally FORTH deliberately prevents
recursion so that you can call an existing
word inside the dsfinitjon of a new defini-
tion of the same name. For example:
I + SHOW-STACK + SHOW-STACK ;
This example might be s rBdefinition
of plus to leach beginners what tha stack
looks lil<e before and after uddicion. The
plus that is ■'^atler^ in the rfiiddle of the
definition is the original + , not the one
being defiriad.
FORTH prevents rrcmsinn wilii a word
called SMUDGE . This word usually tog-
gles a bit in t^e name field of the word
most recHitly defined. With this bit tog-
gled) ths name is "smudged"; that is, un-
recognizable. In the dsfinition of -i- sbove,
the colon leys down a head in the diction-
ary, and then executes SMUDGE before
compiling the rest of the definition.
When the second + [S encountered, the
compiler searches the dictionary for a
word of thai narrtf^. The new head with
the saiiir- name is bypassed only because it
has been smudged.
At the end of the definition, semi-
colon nriain executes SMUDGE . This
tor|r|Ies the bit back to its original atete,
so that liie nasne is again findable.
There are various means of circum-
venting FORTIH's protection against recur-
sion. Here are two recent contributions
from our readers:
A RecuF^on Tedmique
Christoph P. Kukuli«s
Aachen, West Qermviy
Here is my solution to the prrtilr'::- if
recursion in FORTH shown in a possible
wav to implement the ACKSuRMANN's
function (see FORTH DIMENSIONS, Vol.
ni. No. 3, p. 89}.
First test if your FORTH-system is
"crash-proof" with the following sequence:
! CRASH [ SMLOGE ] CKASH ;
SMUDGE CRASH
After having recovered tram CRASH
you Should try this;
(m n -> ACKEF^MANN (m,n)
:ACKERMANN ( m n ~ ACK)
[ SMUDGE ] SWAP DUP 0= IF, DROP 1+
ELSE SWAP DUP
0^ ir DROP 1 - 1 ACKERMANN
ELSE OVER SWAP
1 - ACKERMANN SWAP
1 - SWAP ACKERMANN
THEN
THEN J SIvlUDGE
Be aware of typing
3 4 ACXERMANN .
Another Recursion
Arthur J. Smith
Osahawa Canada UG 6P7
Regarding the recursion prtiilem, I
think that I have found a more elegant
solution. The solution involves an
immediately executed word to re-
SMUDGE the word being defined.
I define a wwd RECURS as follows:
! RECURS SMUi>GE; IMMEDIATE
then Lis*^ the wGr<i to hr.irimf thi"^ n'-curaive
Self definition as in the example:
:SUM
DUP 1- DUP IF RECURS SUM RECURS
EMDIF
I use the RECURS word in tree
searches.
Editor^ note:
The technique that is generally pre-
ferred was descrUied by Joel Petersen in
the original article. It defines MY5EI.jF as
: tvtY5rLr"
l.ArLSl" PFA CFA , i IMMEDIATE
or, for some other versions such as poly-
FORTHi
I MYSELF
LAST @ g 2+ , ; IMMEDIATE
MYSELF simply compiles the code
field of the latest header in the dictionary
(the word being defined) into the defini-
tion.
The problem with using the word
SMUDGE inside a definition is 1) it's not
readable, since smudging has nothing to do
with what the definition is aljout, and 2)
its behavior is different on different sys-
tems.
Similarly, having to «ay RECURS
ACKERMANN RECLIRS is not quite as
readable as simply MYSELF.
An even more readable solution Is this:
; ;R
[COMPILE] ; SMUDGE ; IMMEDIATE
SMUDGE [COMPILE] ; ; IMMEDIATE
Here a special version of colon and of
semi-colan named :R and R; are defined to
allow recursion without any other ho<]pla.
RENEW
RENEW TODAY!
Page 179
FORTH DIMENSIONS m/6
8080 ASSEMBLER
John J. Cassady
339 15th Street
Oakland, CA 9A612
Screen IS 30H
( FIGFORTH 8080 ASSEMBLER 1 8UUG17 JJC SOMAROJl
HEX VOCABULARY ASSEMBLER IMMEDIATE : 8» DUP + DUP + DUP + ;
ASSEMBLER CPA • jCOBE 8 + ! ( PATCH '.CODE IN NUCLEUS
CODE ?EXEC CREATE [COMPILE] ASSEMBLER !CSP ; IMMFMATf:
C; CURRENT § CONTEXT I ?EXEC ?C3P SMUDGE ; IMMFDIilTF
LABEL ?EXEC VARIABLE SLUDGE -2 ALLOT rcOMPILF] ASSEMBLER
!CSP ; IMMEDIATE ASSEMBLER DEFINITIONS
1
2
3
5
S
7
3
9
10
11
12
13
!«
15
CONSTANT H
CONSTANT D
CONSTANT M
1MI <8UILDS
5 CONSTANT L
3 CONSTANT E
6 CONSTANT SP
C, DOES> C§ C,
3MI <BIIILDS C, DOES> Ci SWAP
4MI CBUILDS C, DO£S> C9 C , C
SHI <BUILDS C, DOES> C^ C, ,
PSK2 03 C, (NEXT) 2 - , ;
7 C0N3TAMT A
CONSTANT 3
' ;S OB + g
: 2MI <BL'ILDS
8» ♦ C, ;
6 CONSTANT PSW
1 CONSTANT C
CONSTANT (NEXT)
C, DOES> C§ + C,
;s
PSH1
NEXT
C3 C,
C3 C,
(NEXT)
(NEXT)
Screen 49 31H
This 3D80 assembler has been avatl^le
in a slightly different form for approxi-
mtjt.ely one and one -ha If .years. It appears
to be bug-free.
ENDIF 's have been replaced by THEN,
and AGAIN has been removed in conform-
ance with FORTH-79. I have never had
oncssion to use AGAIN ; I doubt if I'll
miss it.
1 have rerntjved the copnpiler security.
We frequently want n on -structured control
mechanisms at the code level. Tfie
7PAIRS really gets in the way.
I have introduced three macros; NEXT
PSHI and PSH2. They emplece, rsspeo-
tively, a jump to NEXT , a jump to the
byte before NEXT and a jump to two bytes
before NEXT , Literally, PSHI means
push one level (Hlj and fall into NEXT . I
believe this is a more traditional approach
and the source code has a cleaner appear-
ancR,
The actual address of NEXT is stored
in (NEXT) . Its value is plucked froin ;S ,
This technique was suggested by Patrick
Swayne of the Heath User's Group. I say
"suggested" because Svifayne's method is a
bit different.
I have left out the conditional
CALLs. I never used them and they esn
always be " c;, " 'd in. The ccMidltional
jumps are, of course, handled automatic-
ijlly by the conditionals: !F WHILE and
UNTIL, in conjunction with the flag
testfirs: fl CS PF <: and NOT .
i h:jivv ri-jleii to retain the immediate
instructiririri r.'Vl and LVI as Opposed to an
immedi.Ttf- fl.Tt) il.
The IMI ZMl etc stands for "number
one machine instruction" etc. TiiL^ first
cut of this assembler was written when
three letter names were the craze.
I have a selfish motive in publishing
this assembler. I hope that this will flu*
out assemtolers for other processors anri
that there will be a "rush to ptiblish."
Ther;: is a good reason to do tliis besides
Vanity. If .^nmeof^e else publisht^s the
assembler for the "xyz" rrhlp that you lise,
and it becomes established, it mearis that
you will have Lo change your code to con-
form with the quirks of the "established"
version. It pays to get there first.
C FIGFORTH 8080 ASSEMBLER 2
1
00
IMI
NOP
76
IMI
HLT
2
07
IMI
RLC
OF
IMI
RRC
3
E9
IMI
PCHL
F9
IMI
SPHL
H
27
IMI
DAA
2F
IMI
CMA
5
80
2MI
ADD
S8
2MI
ADC
6
AO
2MI
ANA
A3
2MI
XRA
7
09
3MI
DAD
CI
3MI
POP
3
OA
3MI
LDAX
04
3MI
INR
9
OB
3MI
DCX
C7
3MI
R5T
10
C6
mi
AD I
CE
HMi
AC I
11
E6
4MI
AN I
EE
4MI
XRI
12
22
SMI
SHLD
2A
SHI
LHLD
13
CD
SMI
CALL
!S
15
81HAR22
JJC
80MASO4 )
F3
IMI
DI
FB
IMI
EI
17
IMI
RAL
IF
IMI
FAR
E3
IMI
XTHL
EB
IMI
XCHG
37
IMI
3TC
3E
IMI
CMC
90
2MI
SUB
93
2MI
SBB
BO
2MI
ORA
B8
2MI
CMP
C5
SMI
PUSH
02
3MI
STAX
05
3MI
DCR
03
3MI
INX
D3
UMI
OUT
IB
4MI
IN
P6
HHI
SUI
DE
4MI
SBI
F6
1|MI
ORI
FE
l(MI
CPI
32
SMI
ST A
3A
SMI
LDA
Screen 50 32H
{ FIGFORTH 8030 ASSEMBLER 3
1 09 IMI RET C3 5MI JMP
2 E2 CONSTANT PE F2 CONSTANT 0<
3 : MOV 3* '40 + + C, ; ; MVI 3*
4 : IMFN HERE SWAP ! ;
5 : ELSE C3 IF SWAP THEN ;
6 : UNTIL C, , ;
7 : REPEAT SWAP C3 C, , THEN ;
8 ;S
9
10
11
1?
13
14
15
31AUG17 JJC 80MARa4 )
C2 CONST I'JT 0= 1-2 CONST AN I C3
: NOT T 4- ;
6 + C, C, ; : LXI 8* 1+ C, , ;
: IF C, HERE , ;
: BEGIN HERE ;
; WHILE IF ;
FOR TH DIMENSIONS 111/6
Page IBO
Screen 51 33H „ , ,
t EXAMPLES USIMG FORTH 8080 ASSEMBLER 1 91AUG17 J-IC 80MAR12 )
1 FORTH DEFINITIONS HFX
2 CODE CSWftP C WORD-l— SWAPS HI ADD LOW BYTE OF WORly OH STACK )
3 H POP L A MOV H L MOV A H MOV PSH1 C;
4 CODE LCFOLD C FROM-2 QTY-1 CONVERTS LOWER CASE TO UPPER )
5 I> PDF H POP
6 BFGlff D A MOV E OEA 0= HOT
7 WHILE M A MOV 60 CPI CS MOT
8 IF 20 SUI A M MOV
9 THEM D DCX H ISX
10 REPEftT HEXT C;
11 ;S
12
13
14
15
Screen 52 34H
( EXAMPLES USING FORTH 3030 ASSEMBLER 2 31AUG17 JJC 80MAR12 )
1 CODE CMOVF C FROSl-3 TO-2 QTY-1 SAME AS IM NUCLEUS )
2 t L MOV B H MOV B POP D POP XTHL
3 BEGIN B A MOV C ORA 0= HOT
U MHILE H A kOV H INX D STAX D INX B DCX
5 REPEAT B POP NEXT Cj
6 CO&E -CHOVE C FROM-3 TO-2 QTY-1 SAME BUT OPP DIRECTION )
7 C L MOV B H MOV B POP XCHG
3 H f- iP 3 DAD XCHG XTHL B DAD
9 BEGIN B A MOV C ORA 0= NOT
10 WHILE H DCX M A MOV D DCX D STAX B DCX
11 REPEAT B POP NEXT C;
12 : MOVE ( FRO'^-j 1')-^ J'^-l SMART MOVE, DOES NOT OVERLAY )
13 >R 2DUP R> ROT ROT -
14 IF -CMOVE ELSE CHOVE THEN ;
15 ;S
Screen 53 35H
C EXAMPLES USING FORTH 8080 ASSEMBLER 3 31AUG17 JJC 80MAR12 )
1 30 CONSTANT CHMD ( COMMAND BYTK )
2 FO CONSTANT CMMDPORT C COMMANI' PORT )
3 F1 CONSTANT STATUSPORT ; STATL'S PORT )
4 LABEL DELAY C DELAY COMSTANT IN DE, DOH'T USE THE STACK )
5
BEGIN D DCX DA MOV E ORA 0=
UNTIL RET C;
( BIT
6
CODE STATUS
7
d POP CMMD A MVI CMMDPORT OUT
3
1.5 3 'J I LX: DELAY CALL
9
BEGIN
10
3TATUSP0RT IN L AHA 0= HOT
11
UNTIL NEXT C;
12
;s
Seve of EniltHtems
InPORlH
MitcheU E. Timin
Timfn Engineering Co,
The enclosed version of Eratosthenes
Sieve was written for imp IcfTient^tion
of Ti(nii) FORTf ! release "5. I was pleased
that it executed in 75*9 secondsi as com-
pared to the 85 seconds of figFORTH.
Mine was run on a 4 MHZ Z-80 machine,
as were the others in the BYTE magazine
article.
The speed improvement is primarily
due to the array handling capability of
Tlmin FORTH raJeate 3. FLAGS is
created with the defining word STRINQt
n FLAGS leaves the address of the nth
elem«nt of FLAGS. This calculation
occurs in machine code.
SCR
1
2
a
4
s
&
7
B
9
to
11
12
13
14
15
SCR
1
2
3
4
5
6
7
e
9
10
11
12
13
14
19
• 35
( The Sieve of Eratosthenes, after J. Cilbreath. BVIE t/Bl >
BITO CONSTANT SIZE SIZE STRING FLAGS ( Bialce srraj' of flsOS )
! PRIME ELACS SIZE 1 FILL ( start by isettlna the fldoa)
i create counter vhich remains on tof* of stack )
SIZE O DO (
I FLAGS (» t
IF (
I DUf *
DUP 1 t
BEGIN CLIP SIZE <
O OVER FLflCS C!
Ol/ER <
REPEftT
DROP DROP 1* ( drop
ENDIF
LOOP 3 SPACES , PRIMES
repeat follonino loop BITO times )
fetch next flac to top of stack >
If ri«o Im tru> ifwn d» the folloHlnal )
3 * ( calculate the i^lme ™iii*»r )
i stack isJ counter p prime. K )
WHILE ( repeat for K < B190 )
:! ( clear Kth flan )
( add primtf to K >
K Et pri»e* increinent counter)
i < f intshi dicrlay count)
36
tesMnu the sieve alooritha >
BELL 7 fMJT !
NEM-LINE CR OUT ! t
NEU-LIHE? OUT e 70 > IF NEM-LINE
O UARiraLE KOIMT
ENDIF
t
PRIPtE-TEST
10 DO PRIME LOOP
above is for timina test
O KOUNT ! NEK-LI Ni
SIZE O DO
I FLAGS C?
IF I DUP * 3 *
7 .R NEU-LIȣ7
I Kouir *i
ENDIF
LOOP m KOUNT ?
10
X i
BELL < first sound the bell
B£LL ( run the prime finder
belDV 19 for validation }
t clear counter, start rwn lint >
t checic each fJao )
( see if it's set }
( calculate the prist nunbw >
display It 1
count it >
I ( diwlav th» ceunti
Page 18X
FORTH DIMENSIONS m/6
SKEWED SECTORS FOR CP/M
Roger D. Knapp
In regard to Michael Burton's article in
FORTH DIMENSIONS, 111/2, page 53, "In-
creasing fig-FORTH Dlak Access Speed," I
enclose a dmple mod to the 8080 or Z80
easemti^ Utt to effect the CP/M rieewsd
sector disk I/O, the FXJRTH routines I
used to test the scheme are included. The
first cluster or screen is offset by 52 sec-
tors so that the operating system is trans-
parent and screens and 1 hold the direc-
tory, I move the inaasage screens to
SCRit 24 and 25 leaving Z-ZO for the
FORTH binary progrern run by CP/M or
CCXDS.
In orrinr to rhpck ^^ty incrfinf^e in disk
access speed I timed the following opera-
tion with a ID screen buffer;
20 270 10 MCOPY 20 270 10 MCOPY
20 270 10 MCQPY
Elspsed times were 204 and 133 seconds
for straight and skewed sectOTS respec-
tively. Note that this reflects disk acce»
speed for read /write of several sequential
sectors and in no way compensates for
inadequate planning or poor programming
in other disk I/O applications.
If ttiis seems trivial, then you havR no
need for CP/M file compatible 1/0. My
motive for thesm chaiigHs is the desire to
write the assemhler program for fiq-
FORTH via tnrjdcrii ?rasy to implement in
FORTH) to friends and colleagues. As
added value my disk I/O can be faster.
TPJHL:
SSKEW:
'lOT
TSCt-LC:
*30T
TSC/LS:
LO
POP
jp
DB
OB
OB
u3
D3
ow
POP
LO
ADD
LD
PUSH
■JP
OB
OB
DS
DW
TSC/,L3;
TSCAL?:
id;
ME XT
CTDSK ; SEMD DRIVE * TO CP /I'.
; RESTORE (IPl
[1, 1, 7, 13, i?,?5, 5, 11, 11 9
16. 21, 2. P, 14,20, 26, 6, 12, IR, 24, 4, 10, 15, 22
'S-SKE'
'l."+fOH
SET0aV-!2
^■+?.
[!E ;
HL , ■^P.TBL
E,(HL)
Ot
HE XT
R7H
'TiSCAL'
'C'+SOH
S-SKEV?
SECTOR SEOUEtSTIAL
; TRAIISLATICM TABLE ABOVE
; ADDS PF tJEU SECTOR
; SECTOR T^AHSLATED
; TJiSCALC
AFTER
DH OOCOL,KHSTY
OW AT
DM ZBRAM,TSCALS-S
DOUBLE DENSITY
OW L!T,BUP0R2
MDniFiETD
DlNSITV
LIT, 52. PLUS
DW
DIJ
OW
DW
D"---
h',-:
Dv;
Dli
DM
OW
OW
DW
LiT,nuPOsr
' SLlWD ~
L!T,MXORV-I
[■-.If;
OUP, DRIVE
AT,ECUf,L
Z;'R;.'i,TSCAL3-S
DROP
F.K''dJ,TSrAL£-S
DRIVE, STORE
SETDRV
L1T.SEP7R1
SLMrD.T^ACK
STf!RE,OfJEP
SSKEt!
SECSTPRE
SEns
c^KiP 5Z Sectors for
O P E: F?A-r i & £,Y-STEr(vi
SEQUENTIAL TO CPA* SKE!.'
SCR • ^<':-
( s-ylf' flisk 1 ivoijt J/0 )
1 Ff-s.TK OEFIHITI'^MS fiECIfiftL
1 LASIL If^S ( CP/f: SERVICE REt;'JEST 1 1 LnULi', C ^CUP. JOHL, C;
■ SET-:'"' ( S'ctcr X.rs:cy.. ■?('(:>- s )
H ^np. P PU^H, H B LD, L C Ln, 2! D LDPI, K'S CALL, E POP,
7 K PrT', B K B LD, L t LO. LLlPj , ]n<^ CALL, B POP,
'^. H POP. B PUSH, L C LD. IE LDPI. lOS C/iLL, P- POP,
t> V'EXT, C;
10
11 CPOE SET-DRIVE ( n — )
12 POP, B PUSH. L C LD, IP D LDPI, ms CALL, B POP,
j; !JEn, C;
14
15
FORTH DIMENSIONS m/6
Page IBZ
SCR f 51
n ( SECTOR SKEH FOR CP/M FORMAT CtUSTERS )
1 FORTH OEFIHITIOHS DECIMAL
2 : CTABLE ( bytesize TABLE 5
3 <BUILDS DO C, mor ?OES> + CP ;
4 ;Z Ifi 10 4 24 If; 12 6 26 21? 14 1? 2 21 15 9 3 23 17 11 5 25 I''
5 13 7 1 27 CTftBLE S-SKEH { for CP/M clusters \
fi
7 : ':5F,T1.1P ( Sf-.^.w n spctors for HXTS, 1
S f .-idrs bU r --- sec trk srirlr ... <;ecn trkn nddrn 1
9 ROT nvER I?.''' * + P.f'T ROT OVER + 1- SWAP 1- Si;AP
10 Da 1 ?& /t--OD SWAP 1+ S-SKEW S\^f.P ROT IZfi - OUP
13 -1 +LO!>P DRtVP ;
12
13 : »1RTS { Read n sectors. 1 f s t i sn tn an n — \
IC DO SET-IO SEC -READ DISK -ERROR P IF LEAVE THEfl LOOP ;
IS
SCR * fi?
Q ( M.GRE FfiPiAT DISK I/O 1
1 FORTH OEFIKITI'SIS DECUIAL
2
3 : L'LTS ( Write n s^^cfors to Z?/V. clustiir. )
i IT^ SET-m SEC-»'R!TE OISK-ERROR P IF LEAVE THE'i LC'OP ;
: '■:/'.;- CP/" ' skr-.;*fi rl[;St*;r 1/0,1
7 ( adrtrs his- f — ) >R 52 + 2!!0n /MOD SET-DRIVE
f. SEC/i-iLK '!SETUP ( S7 + sn cluster alloc CP/t1 )
? R> IF SEC/BLK t;RTS
30 ELSE SEC/PLK UUTS
11 Ef-fDlF TISK-ER"?*? ^ ?ERR'^R ;
12
J3 ( All nf screens fi; --ind '^.2 sn5-.irlr;ssl y Kdanttti from John Js-rms')
K t fie-FO:-!TH for the LSI-U. )
IS
SCR # 90
( ,BUPK TDH 7/11/81 )
1 DECIMAL
2 ; ,WFS ( display atir of all buffers )
1 CH # Afidr(hex) Upd B1qcIc# Screen -sub"
ft FIRST #HIIPF 1+ 1 DO
; CR I 2 .B 2 SPACES
6 DUP 2+ HEX 6 SWAP D. R DECIMAL 1 SPACES
7 DUP e "12?68 A^fD
8 0= 0= 12 + EMIT 2 SPACES
9 DUP S 32767 AND DUP 6 ,."J H SPACES
10 Fl/SCa /MOD 5 .B U SPACES 2 .H
11 l-^a + ?TEH«INAL IP LEAVK THEN
12 imp DBOP CR ;
13
lU.
15
.BtlFS
#
Adrtr(hex) Upd
Screen
-sub
1
3E82
720
90
2
3P06
721
90
1
3
3P8A
722
90
2
400E
723
90
3
1
400?
?2iv
90
U
^116
725
90
5
7
726
90
6
8
b21E
727
90
7
9
112A2
□tagnoatics on DUk Buffare
Timothy HUang
9529 NEGertz Circle
Portland, OR 97211
While I was in the process of explaining
the disking to some friends, I found it
would be nice to show thenn some sort of
representation which lists all the disk
huffpr status. This short program was
then written for this purpose.
The figFORTH uses tht; memory above
USER area fnr the disk buffer. This disk
buffer area is further divided into several
blocks with the length of each block equal
to B/BUF + 4 bytes. There are some Im-
plementations that set B/BUF to be 1024
bytes and some, like SOSO CP/M, that set
it to be 12a bytes. Another constant
beside B/BUF frequ!;ntly referred in disk-
ing Is the B/SCR (buffers per screen). For
B/BUF = 1024, the B/SCR = 1 and for
B/BUF- - 128, B/SCR = 8.
F^irrh neefis 2 hytes in front of it
as the hiindfT which contains the update
bit (bit lii) and block number (lower 0-14
bits). It also needs a 2-byte tail to end the
block.
The word BLOCK will put the begin-
ning address of a given block (assuming
the block number on statHc before exe-
cuting BLOCK ). With these simple words,
virtual memory can be utilii=ed, but it is
beyond the scope of this short article.
The short procjrarn will display the
status of each disk bloi^k until it is
hausted or you terminate it tjy prRssing
any l<ey. The first thing it does is print
out the title line (line 4). Line 5 sets up
the boundary for the DO ... LOOP. Line 6
prints the buffer nuirdier while line 7
prints the beginning address of each buffer
in hex. Lines 8 and 9 check the buffer
update status. If it has been t^dated, then
an " ! " will be printed in the upd
column. Lines 10 and II calculate the
block number, screen number and the -sub
number. The reason for teh -sub is
because for my system, 3/LBUF = 128,
B/SCR = R, there are S blocks to make a
whole screen. So, I thouglit it would be
handier to know which subpart of a given
screen the block 1 want.
Lines 12 and 15 check the early termi-
nation and finish the ctefinition.
4|#
Page 1S3
FORTH DIMENSIONS 111/6
FLOATING POINT ON THE TRS-80
Kalman Fcjes
Kaith Microsystems
PO Box 5457, Statirai F
Ottawa, Ontario K2C 3J1
Canada
Most FORTH systems have no provi-
sions for handling floating piont numbers,
although most popular micros have the
necessary routinps hidden in their ROM-
based BASIC interpreter. These are fast
routines written in assembler. The foilow-
ing is to demonstrate how these can be
accessed and used to impiemcnt single
preckion floatintj pint arithmetics for the
TRS-f)0 in MMSFOKTH, Version 1.8.
!>inq[n. pref^ision ffontinq point data is
stored a noirnalized bin^iry fraction,
with an assumed decimal point before the
most significant bit, I ^.'^ irmst significant
bit also do(.ibl(;s as a sign bit.
A binary exponent takes one byte in
each floating point number. It Is kept in
excess 128 form; that is, 128 is added to
the actual binary exponent needed.
The binary mantissa is 24 bits long, the
most significant bit representing the sign
bit. It is stored as 3 bytes normally with
the least sigriificant byte (LSB) stored
first and the most significant byte (IvISB)
last, followed by the exponent.
tskjmbers should be entered using the
notation specified for the TF^S-8(1 1.2
BASIC. Integers and dobuie prt^cision
numbers are converted to and stored in-
ternally as single precision nurhbsra.
The coiYiplete vocabulary and listing of
the source screens for either MMSFORTH
or rigFORTH (pacify) Is available for $7
CU.SJ from Kalth microsystems. It in-
cludes both single and dniile precision,
trigonometric and log functions, floating
point constant, variable and stack opera-
tors, conversion routines to/from integers
(FORTH type) and floating piont numbers.
GLOSSARY
F +
F-
F»
F/
Single Precision Floating Point
Add
( Fl Fi - F )
( F=F2+F1 >
( F2 Fl - F )
C F=F1-F1 )
( F2 Fl - F )
C F=F2«Fl >
C Fl Fl - F )
C F=F2/F1 >
Subtract
Multiply
Divide
BLOCK T
( FTP #1 :KIP 810816) FOHGET FTASK : PTASK ; HEX
1 ( SIMGLE PRKC. FLOATING POIMT POH TBS-80 IN HMSFORra VI. 8)
2 ; EXX D9 C, ;
3 CODE F.ft IXX OPBD GALL 28A7 CALL EXX HEXT
^ CODE Fjj* EXX BE. POP 2 RST OEiC CALL
5 OABt CALL EXX KE3CT
6 : pe DOT 2 + e SWAP 6 1* 40AP Ct ;
7 : Pt DOT ROT SWAP I 2 + I k kOAF CI ;
8 : A S lUgl F& ;
9 : P#0 HSHE OVEH 3E FILL BL WOHD P^t A S ;
:0 : F#IM " 7 " PAD DITP 1+ 63 EXPECT F#S; A S :
11 : F#l F^O SWAP (L) (L) , , (L) (L) , . ;
la : F# STATE Cai IP F#l ELSE P#0 THEN ; IMHEDIATE
13 : P. s A F.& ^^ i^oap c; :
Ik : lOPT ;
15
DBCIHAL
BLOCK 10
1
2
3
4
■)
6
7
8
9
10
11
12
\i
IS
< PLOT. PT. #2
HEX
CODE P-I&
CODE P_&
CODE F*&
CODE ?/&
: F+ S
* [7#
DECIHAL
F #
F # IN
!IF 810816) FORGET lOPT
EXX
EXX
EXX
EXX
F44
F*^cc
DE POP
DE POP
DE POP
DE POP
A 3 ;
A S :
BC POP
BC POP
BC POP
BC POP
: F-
: P/
716 CALL
713 CALL
64? CALL
CALL
P-4 A
p/a
8A2
S A
S A
lOPT ;
EXX NEXT
EXX N^T
EXX NEXT
EXX NEXT
S ;
A s :
PTEST
( SAMPLE AND TEST ROU'TNES)
P#1H CR P# 2 ?+ Fr.' ;i00.OE-2
F# 5000.1 F* F# 5.OO01B+3 P/
PAD P! PAD P« P, ;
F)
Takw a nurrtoer from the currant
buffer, converts it to single pre-
cision fjoating point nurnber and
leaves it on the stack.
( -- F )
Asks for a floating pint number
from the keyboard, and leaves it
on the stack.
C A - F )
Floating point feb^. Takes a
floating point number from
memory at address and leaves it
on the stack.
(F A - )
Floating point store. Stores the
floating point number an stack in
memory at location A.
F TEST ( - >
A sample program to demon-
strate the use of these floating
point operators. It fisks for a
floating poii^t numbf^r from the
keyboard, manipulates it using ail
the operators defined and prints
the result. (It should be the same
number that was supplied.)
Notes: A — 16 bit address
F, Fl, F2 — are single precision
floating pint numbers (two 16-bit
words each).
FORTH DIMENSIONS 111/6
Page 184
TURNING THE STACK INTO LOCAL VARIABLES
Marc Perk el
Perkel Software Systems
1636 N. Sherman
Springfield, MO fiS803
Occasionalty in wlting 8 dbftnition, I
find tJ»at I nefici to do unwieldly stack
juggUng. For ij>i;jrnple, suppose you (~oriie
into a word with the length, width, and
height of a box and want to return the
voJunne, aurfaDe acea, and length of
edges. Try it!
For this kind of siuation ! dfiveloped
my ARGUMFNT5-RfrSULTS words. The
middle block fo the triad ^ows my solu-
tion to the t)ox problem.
The phrase "3 ARGUMENTS" assigns
the names of local variables 1 through 9 to
nine stack positions, wtlh 51, S2 and SJ
returning tlie top 3 stack values that were
there before ? ARGUMENTS was exe-
cuted. S4 through S9 are zero-filled and
the stackpointer is set to just below 59.
SI thorugh 39 act as local variables
returning their contents, not their
addresses. To writt; to them you precede
them with the word " TO ". For example,
5 TO S'l writes a 5 into S4, Execution of
S4 returns a b tn the stack.
After all calculating is done, the
phrase "7 RESULTS" leaves that many
results on the stack relative to the stack
position when ARGUMENTS was exe-
cuted. All intermediate stack values are
lost, which is good because you can leave
the stack "^Irty" and it doesnt matter.
SCR
1
2
3
4
S
6
7
8
9
A
I-i
c;
D
E
F
1
2
■7
4
5
6
7
3
9
B
c
D
E
F
* B
( ***< ARGUHENTS-RESULTS yt** )
variable; CARG] variable CT03
! +flRG CREATE » nOES> Q CARG3 i SWAP - CTQ] B ?DUP
IF 0< IF +1 ELSE I END IF ELSE 9 ENPIF ET03 I
+fiRG SI
8 +ARG S5
10 +ARG S9
+ r'iRfi 32 4 iPiRC.
+ARC5 56 C +ARB S7
( *rO VARIABLES* )
6 +ARO S4
E +ARG S8
TO
rn
t: to:.!
*S'.ETE.;
*?!I::tj;
riTtlRE
+ STCIRE
AiiOLmEifJTEi R> zmai i? >r ---r 2* iipe + dup carg] i 12
2/ na inof o CTC)3 > i
RESULTS 2* TARG] P SWAP - SPP - 2/
m mop LOOP r> r> eargj i >r ;
spe SWAP
!■■ n
i ARGUMENT EXAMPLE BOX COMES IH WITH HEIGHT.. LENGTH
S WIBTH AND LEAVES VOLUME, SURFACE AREA S LENGTH OF EBGES )
( VOLM )
( SURF >
C EDGE }
3 ARGUHENTS
SI 32 S3 * * TO S4
SI S2 2 t * S2 S3 2 * * SI S3 2 * * + + TO S5
SI 4 # S2 4 * S3 4 « + + TO S3
53 TO S2
54 TO SI
3 RESULTS J
SCR
t
2
3
4
5
6
7
8
20
TASK f
DISKS
BISK!
5 ARGUMENTS
SI S2 0400 U/MOD 1+ TO SI TO S2
BEGIN S4 Q>
WHILE SI BLOCK S2 + S3
5V, ir SWAP UPDATE END IF
(1400 S2 - MIN DUP TO S6 CMOVE
36 no S3
S6 NEGATE +T0 S4
1 fTO SI
'> TO S2
REPEAT
RI^SULTS !
D1SK@! f
1 DISKB! f
Page 185
FORTH DIMENSIONS m/6
Accompanying these rrnmmfsnts are
several graphic specimens drawn on Apple
computer using FORTH and printed on a
dot-matrix printer. They rangf; from logo-
type design to experiment!; in geometry
and pattern. One can generate real-time
motion graphics on the Apple iii \irtiich
color and action partially compensate for
the low resolution of 280 by 192 pixels.
Hardcopy, whether prinout or color photo,
isn't the final product. The interactive,
sequenced and timed display ari the scrf^en
is the designed product, likely to displace
the medium of print on paper in the
future.
While these graphic samples could have
been programmed in othsr languages, I
have found the advantages of uting
FORTH are both practical and
expressive: Immediste and modular ex-
perimentation with the pecoliarities and
limitations of the Apple video display, and
orchestration of complex visual effects
with self-named procedures rather than
the tedious plots and pokes to undis-
tinguished addresses. With this ease of
wietding visual ideas, FORTH might lead
to n new era of computer graphics, even
creative expression.
It may remain individual and personal
expression, however, without graphics
standards. Transportability of grahics—
generating code may be neither possible
nor desirable considering the differences
in video di^ilay generation, alternate
character sets, shape tables, display Usts,
in tempts, available colors, etc., between
microcomputers. Each has some individ-
ual features to exploit. Most have, how-
ever, such limited memory for graptiics as
to make machine-dependent economy an
overriding aspect of programming for
graphics.
Despite the rarity of FORTH graphics
thus far, I'm convinced it is an sxoellent
vehicle for bringing out undiscovered
graphics poLential of each micro. In ad-
dition, tho visit:) itity [Jained by Mjme effnrt
to evnlvH- qrfihit: ir!eas in FORTH wrajid
help in both spreading and teaching the
language. Perhaps this issue of FORTH
DIMENSIONS will stimulate just such
activity.
Editor's Mote: The author tells me
that Osborne/McGraw-h-nil publishers have
used his patterns, generated on Apple H
using Cap'n Software FORTH, as cover
artwork for their book "Some Common
BASIC Programs";
GRAPHIC GRAPHICS
Bob Gotsch
California College of Arts and Crafts
! A \:' K >: ;< X .\ >:
V
FORTH DIMENSIONS 111/6
Page 186
CASES CONTINUED
Editor's Note! In Volume 11, Number 3,
FORTH OIMEIMSKINS published the results
of RG% CASE Statement ContsBt. Aa we
had hoped, the variety of responses has
stimulated further work on the subject.
Here are four additional CASE conetructes
submitted by our readers.
E]aicet^ CASE far 8000
John J. Cassady
Here is an 8080 (ZSO) version of the
l<eyed case statement by Charles Eaker
that was published in FORTH DIMEN-
SIONS II/J, page 37.
uselul.
I have found it very
1
2
3
4
5
6
7
8
9
10
T1
12
13
14
15
( CftSE STATEMENT BY CHARLES EAKER f[> II 3 39 JJC 81AUG09 )
; CASE 7C0MP C3P § !CSP 4 ; IMMFMATE
CODf: (OF) H POP D POP • - S + CALL L A MOV H OfiA =
IF B INX S INX NEXT EMDIF D PUSH ' BHANCH JMP C;
: OF 4 7F AIRS COMPILE COF) [If RE 0,5; IMMEDIATE
: EMfpOF 5 ?PAIRS COMPILE BRANCH HERE ,
SWAP 2 [COMPILE] THEH 4 ; IMMEDIATE
: EMPCASE 4 ?PAIRS COMPILE DROP
BEGIN SPe CSP S = 0=
WHILE 2 t COMPILE! THEM
REPEAT CSP r ; IMMEDIATE
: TEST CASE 41 OF A
42 OF B
C 41 TEST A OK
65
)
OF
ENDOF
EHDOF
ERDOE
EMDCASE
^ker% CAbE Augmented
Alfred J. Monroe
3769 Crnndvie.v Blvd.
Los Angeles, GA 30066
I was deiiqhtRd with Dr. Eaker's
CASE construction (FORTH DIMEN- S>CR
STONS, Vol. n. No. 3, p. 57) and imple- »
m anted it immediately. Recently I have 1
found it desirable to augment CASE with
three additional constructs in order to ^
treat ranges of variables. It has occurred 4
to me that other FORTH users may be
interested in the same extension, hence ^
this short note.
H
Screen 144 lists Dr. Faker's CASF
construct witi; anp. slight modification, 1^
OF has bBRn modified to use (OF). The 1'
original OF r-omfii led to trn tiytHS. The l'^'
revised OF nompiSns to six by hps. Thi-; 1
forty percent reduotimi in code is riot as
impressive as that which occurs using Dr. 1^
Eaker's CODE w/ord (OF5 construct, but
it does l^ve the advantage that it is highly SOK
portable. COF) tests for equality and e
leaves a true or false flag on the stack. 1
Note that it drops the test value if the 2
test Is true. 4
4
Screen 145 lists the extensions that 1 5
have fourtd useful, <OF, >UF, Jiiui RN(,;- t
OF. <0r doe:; a "lR^iS th<in" test. >OF docs V
a 'IgreatF'!:- th.in" test. RNr,-OF does an b
inclusive range test. <OK and >OI arn ^
trivial iiiodificalioiis of OF and for\ iy
RANGE and RNG-OF are constructed in 1 1
the seme ^irit as (OF) and OF . i ^
Screen 144 compiles to 175 bytes. it
Screen 145 compiles to Z23 bytes. lb — >
# 144
< I*!. feH<th!'S t>1i>h CONSIKUCI WllH fi SLIGHT MOLUFICRT ION >
! t^Cst VLOt*' CAC « !CiiH 4 i IMMtDimb
! <□!-.> UUtk = it- DkOP i LL^i to EHDlli ;
! tJ^ 4 'rt^hlki LUMPlLfc iCA- } COI^lLt eBKHNCH
Htkb , "T! I iMNhLjiHffc
: bNL>Uh b ^PHlki? UtilKxLh BKhNLH Htkt & . SblBP 2
tU-iMFlLbJ tNL-'lt- 4 t IMNbDlHit
: bNOCHbt 4 VHHif^-i. L ONPit-b L'HUP bECalN iPS CliP t» - \i =
MHJUfc 2 LCOMPiLfcJ bt-iDlh KbPbftf CSP \ i IMMbDlftlb
« 14b
< itfc <uf-, HNLi (^NuH:)^ extensiows >
! \<.i}V> tAJbk > IP l^KtfP 1 fcLSk th&tIP i
: <tJt- 4 .-PHlkis CLiMHlLb <<OF> OJMH-ILE CilKmCH
Hbkb b , b ; IflMbLilHTb
I C>t>^ uUbK < If ykOF 1 isLSE 9 fNUlF J
i >U1- 4 VPftlHi LUMPiLb <>£»-■> COMPILE OKRHKCH
HbWK ti , b j; IMMbDlflTE
: HrtMiuh >k uUbP DtiP P> 1+ < IF SUhP I- > IF [jpf.ip 1 bLbb 6
iii-JUil- cLU^.h L-KUP DKQP e tHLilS- i
: Kt4b-Ui- 4 \ PHiKi UJllPlLt RNHCit CUMPlLfc SBRfWCH HERE a , 5 1
imibUiBtb
Page 187
FORTH DIMENSIONS 1II/6
SCh; #146
< hS'lHMHLE Ui-b Of- MUtiMhtrfLD LftSt. )
1 4a L.C9^^tWi "tt" ^7' CaN5:VtfHNI "9" 65 COMSTflHT "H"
- , u UJHblrtHV "F" ii COKSTHHi "Ck"
i tONSTflNl CNTkL-C
4
V
a
11
12
13
14
ii.
■»
1
2
4
&
if
7
9
ll»
It
12
13
14
It.
(3 Uf^lABLL fLfIG
iVN-ckW tk SVHTIHX ERROK, REEMrtR Hta«ER
DRW OkOP £l "(}" i
C-HiatlKI t3< COMW*tt> HE«3hn " CR DROP D«OP QUIT J
VHtfOkT CW7RL-C
IF DROP CR tOftlHHD HKWSrr
bLSE DUP BOIF- J
CR QUIT
» 14/
C (itT-«=X LfeWe H rtiX # OW TtJP OF STRCK >
C H PRE bk. EFi<tk SOLiniON TO m INTEMHCtlUE TERMIWU- >
i Ui'l-HtX a i-Lfi& i e BhtilH KbV DUP Dl#» EMIT "ffleORT
li = 11- 1 FLMU I bkOP
tLSt DUP "tl" < if- sVN-tkR
KLS-t DUP "9" > IF DUP "R" < It- SVN-tkR
fc;L5it DLih' "F" > IF S'.-'N-ERK Ef«>lP
LMDiF bNi,>lF bhtLJlF fcW[>lF
hLHti « e= IF 43 ■- y > IF 7 - £Nt>IF SUftP 16 * + fiJOIF
Screen 147 illustrates a pre-Eaker
mlutlon to the design of an Interactive
terminal Input that places a hexadecimal
nufT^er on the stack, and which provides
for error detection and error recovery. It
iSi of course written in my usual sloppy,
unanrrotated, semi-readable fariitcn.
Screen 148 offers a neater solution in
terms of <0r and >OF. It is definitely
mora readable. Screen 149 offers a still
neater solution in terms of RNG-OF.
5crf?Ejn 1-^-^7 comptlL^j^ to 160 bytes,
screen 143 to 176 bytes, and screen 149 to
144 bytes. Need I say more?
SEND A CHECK TO FIG TODAYl
MAKE THIS YOUR BEGINNINGI
RENEW NOWr
PLfiG « UNTIL I
St*
1
4
b
h
7
3
Iti
11
i'l
13
14
lb
# 143
C H t«BTfcR Stft-UilOH lO TUfc TEFMlNfit. IM^UT ROUTINE J
a ^T-FCX PLHtj (
(4 ta^QlN KtV UUP Ul*' tMlT
UH^ CNtKL-C «• C-f«fORl
"t*!" OH 1 FLFiCi J
*■
"■i" 1 +
"ft" 1 -
>0F
<CjF
S'.'N-bftk
>0F ~
SVN-IERR
DROP SMJOF
t:Nt»Cf>
bNPCF
LNWDF
EHDOF
UN
ir SUftP
I IL J
16 * + LNDIF
1
2
4
b
6
&
11
12
13
14
lb
« 14?
<. H St ILL HbHYkk SCjLUHIDN '>
i CiE l-HfeX «J PLWCi !
fa Bb&lH KtV DUP DUP fcHIT
ChSfc LHTRL-C Of- C-ftbCfffT
"Ck" O 1 FLf* ! DROP
"8" "y kHG-QF 43 -
"ft" "F" kNCr-OF 55 -
SVH-tkK
(-Lrtu * ir ^.iHP 16 * •*• EHDIF
FLFICi ® UHTl IL J
EHDOF
£ND€F
fcNDO
EHDOF
RENEW TODAY!
FORTH DIMENSIONS llW
Page 183
CASE as a Defining Word
Dan Lerner
After reading the CASE contest arti-
cles and looking for a simple function, 1
am compelled to sutimlt a simpls CfiSE
statement. These words are fast to
compile and execute, compact, single,
generate minimum code, and very sim-
ple. There la no error checking since the
form is bo simple the most novice pro-
grammer can use it.
CASE is analogous to vectored GOTO
in other iangueges< Its usage with my
words Is:
NAME
FUNCTtON A
FUNCTtON B
FUNCTION C
CASE
A IS
B IS
C IS
(etc.)
OTHERS ERROR FUNCTION
Gencrul uaage would be as 8 menu
selector; for exarrple, you print a menu;
1 BRe«<FAST
2 LUNCH
3 DINNER
SELECTION -■>
The user types a number which goes n
the stack, Uien Rxecutes the CASE word
MEAL. MEAL selects BREAKFAST,
LUNCH or niNNFR, or ABORTS on
error. The source is:
CASE
1 IS
2 IS
3 IS
OTHERS
MEAL
BREAKFAST
LUNCH
DINNER
NO MEAL
106
1
2
3
4
S
6
7
3
9
10
11
12
13
14
IS
107
1 ;
2 !
3
4
5
6
7
8
9
10
11
12
12
14
15
CASE
A
IG
E IS
C IS
ETC.
OTHERS
NftME
nJNCTlGrJ-f;
FUNCTION- B
FUNCTION-D
ERRORFUNCTION
PAIR
ADIiR OF
FUNCTION- A
)
s CASE CREATE HERE 0.
DOES>
1 ROT ROT DUP 2+ SWAP S
DO 2IJUP e = IF DUP 2*- 8
EXECUTE ROT DROP ROT ROT
LEAVE ELSE 2+ 2+ THEN LOOP
ROT IF S EXECUTE ELSE BROP THEN DROP !
; AT COMPILATION BUILDS HFADLR ,L INK
POINTS TO ADDR OF * OF FAIRS
HERE SET TO ABDR OF VALUE -1 )
( AT EXECUTION, ADDR OF *0F PAIRS)
C COHPAIRS INPUT VALUE )
< WITH VALUE A, E, C, ETC, ANB )
< EXECUTES ASSOCIATED FUNCTION )
( CASE WORDS )
18 , ' , 1+ ! < HERE, PAIR* -
OTHERS ' , SWAP I f < HERE,
HERE, NEXT-PAIR^
t-OF-PAIRS )
You have previously defined BREAK-
FAST, LUNCH, DINNER and NO MEAL.
How CASE is Structured
CASE builds an array using IS and
OTHCRS to fill and complete the values in
the array. At execution, the DOES>
portion of CASE takes a value from the
staci< and looks through the array for it.
A match executes the word, no match
executes the word after OTHERS in
source.
The form of CASE Is a new class of
words, as CONSTANT , VARIABLE ,
MSG , etc. are. The code executed to test
tiiB array is minimal.
THIS IS THE END!
THE END OF VOLUME lit
THE END OP YOUR MEMBERSHIP?
DON'T LET IT HAPPENl
RENEW TODAY!
Page 189
FORTH DIMENSIONS 111/6
Generalized CASE Stntcture
in FORTH
CH Fey
bltroducUon
The CASE CONTCST held by FIG last
year ended with eome excellent
contr9>iitigns to the FORTH literature.
The judges noted however that few people
tried to devise a genera! case structure
encompassing both the positional type,
where the case a selected by an integer
denoting its po;;i(ion in Ltie Mst iif cases
(nia FOiiTRAN's computed (^G TG), and
ttit; more genera! lieyed type of structure,
where the case selector key is tested for a
match in the case words key list.
This article discusses a general ease
structure which combines ttie positinnal
and keyed tvce;;. fnf-^Tt-i it.seif, tlie
case structure is extcnsihle. I have added
a third type called range where the case
selector key is tested to be within the
range of pairs of values in the case words
key list.
For any of the three types of
structures, the user is also provided with
the option of u»ng headeriass high level
code sequences to specify the execution
behavior of the Individual cases.
A complete SOurcs: listing in *"ig-
FOI-^TH is given on screens 16> to 130
with illustrative examples ori sori^ens 180
and IBl. The source code listings may
seem lengthier than usual but it is tha
author's practice to include the Glossary
definition right with the source and to
annotate the source code with notes on
the status of the parameter stack. When
this practice Is followed, I find FORTH to
be an emminently readable language, even
months after the particular coding has
been prepared. However, this style of
coding requires a good FORTH video
editor. With a good case structure in
FORTH, that Is not difficult to develop.
Backgnund
In the Aug. '30 issue of Byte, Kim
Harris introduced a very simple positional
type of case compiier. A slightly revised
version of his compiler is
i CASE: <L1ST □oes> !X H EXECUTE ;
where
! <UST <BUILDS SMUDGE ESP ] j
1 IX ( k pfa.-.adr) SWAP 1 MAX
1 - DUP + + )
and la used in the form;
CASEi xxxx cfal cfsZ cfan ;
to define a case selector word named
xxxx.
When the new word, xxx , is executed
in tiie foctn
k xxxx C k-lfi,,.^
the k'th word in the list will be executed.
For example, define the following words,
COW , CHICK , PIG , and BARN :
; COW ." MooOOoo" ;
! CHICK Peep" ;
: PIG ," Dink" ;
CASE! BARN COW PIG CHICK ;
If we now execute the sequence 2
BARN , Dink will be typed. Similarly 1
BARN will type MooOOoo.
Although there are no error checks,
this case structure is easy to use, executes
fast and requires a minimum of dictionary
^sce for each case word, xxx. Bilobran,
etal have used CASEt extensively In
developing a FC^TH file sy^m with
named record components (1930 FDRML
proc. pp 188, Nov. 1980). I have dona
13<ewise following their example.
The interestinq part of the definition
of CASE; is the <8U1LDS part which I have
called <L1ST for obvious reasons. It
creates the dictionary entry for xxxx.
Then, after executing SMUDGE and CSP
which are part of fig-FORTH's compiler
security, it executes ] which forces
FGRTH into the compilation state so that
the user can enter the list. The list is
terminated by ; vMdn completes the
definition of xxxx .
For CASE; words, the list is a list of
cocte field addresses of previously defined
FORTH words. Since FORTH Is in the
compilation state when the list is being
entered, all the user has to do is list the
names of the case select words ( COW PIG
CHICK in the example of BARN ).
FORTH then compiles their code field
addresses, as long as they are not special
IMMEDIATE words which execute during
compilation.
Now suppose that we knew beforehand
that the code field address of PIG was say
H^R2. The same definition of BARN
could then have been achieved by
CASE; BARN COW [ 14382 , 3 CHICK }
where [ stopped the compilation state,
14382 was entered to the stack, the word ,
(comm^ , compiled it and ] resumed the
compilation state.
The point is that <LIST is a powerful
word for entering named lists and data of
all sorts to the dictionary. The method of
retrieval of ttw d^ta is determined by the
DOE5> part uf the compiler. Hence if we
sinnply chanye the definition of the DOES>
part of CASt'; , we c;in transform it Into a
general purpose case compiler.
The Multi-Rjrpose Case Compiler
The method utilized to develop a
generalized case compiler is to compile a
number for the case type as the first byte
in the parameter field of xxx . At
execution time, the number Is retrieved
and used to select the appropriate DOE5>
part for the case type of xxxx . The type
number is transparent to the user.
The definition of the new case
compiler is;
: MCASE: <BU1I_DS SMUDGE J CSP
HERE 1 C, C, ]
DOES> OUP C® DDESPART i
where DDESPART Is a case selector word
defined by CASEt .
The <BUn.DS part of MCASE; compiles
a "1" for the default case type (positionaD
and a "0" for the count of tiie number of
cases entered Into the case list. H also
leaves the parameter field address of the
nawly de firmed word on the stack so that it
can be found later during the compilation
process even though its name field is
smudged.
If the newly defined case word, say
xxxx , is to be other than the positional
type, it is immediately followed by the
ward KEYED or RANGE to define the
type of xxxx as keyed type = 5 or range
type = 5.
;KEYa3 5 OVER CI; IMMEDIATE
;RAhK]SE 5 OVER CJ; IMMEDIATE
The case list subsequently entered
must agree with the case type specified.
Two options are provided for the
execution elements of the case list. The
first or default option is the single word
execution as in CASE: . The second option
allows a hoaderless sequence of FGRTH
words to be defined as the execution
elements of each case. The two may not
be mixed.
A default case at the end of the case
list is mandatory, although it may be a
null word. The default case must be
preceded by the word DEFAULT; whose
definition is
; DEFAULT! ?CDMP EOL , HERE
OVER Ci? [DEF] ; IMMEDIATE
Where EDL is an end of list terminator
constant defined by
';S CFA CONSTANT EOL
FORTH DIMENSIONS III/6
Page 190
and GDEF 1 h a case selector word (teflned
by CASE: .
OEFAULTt firat checks to see that you
are in the compile state since you shiould
be compiling xxxy . It tiien enters the end
of list terminator, EOL , to the diction-
ary. Finally it takes the parameter field
address of xxxx left on the stack by the
<BU!LDS part of MCASr; , qcf, the type
of XXX X and executes the esse selector
word [DEF ] depending on the type of xxxx
. If the type is 1, 3 or 3, [DEF] counts
the number of cases entered and stores it
in the second byte of the psrameter field
of XXXX . If the COM type is 2, 4 or 6, then
ths execution elements are headerless
code sequences. Hence for these types,
{)3EF] initiates the process of defining
the de^lt code sequence.
Execution of Case Selector
All case se lectin' words, xxxx , defined
by MCASE: sre executed In the formt
k xxxx
where the l<ey, U , is an integer. The
interpretation of l< in selecting the case
depends on ttte case list type.
With three case list types and two
options for each type, there are actually 6
different forms of case lists available.
Let's consider first the Usts with single
word execution elements.
Single Word ExecuUon ElemenU
(1) Positional type
MCASE; Is used in the form:
MCASE: xxxx cfal cfaZ
DEFAULT; cfad ;
cfan
When xxxx is executed in the form l<
xxxx , the case cfak will be selected if
I<=1, 2,..,/i . Otherwise the default
case, cfad, will be selected and
executed.
(2) Keyed type
MCASE: xxxx KEYED
r kl , 1 cfal
[ kZ , ] cfaZ
[ l<n , ] cfan
DEFAULT! cfad ;
Wtien s(xxx is I fits r execut.p^ri in the
form k xxxx , the case cfal will he
executed if a value of k=ki is found in
the list. Otherwise, the default case,
cfad , will be executed.
165
165
1
145
2
*■ v*J
3
1 AS
i£5
6
165
7
16 J
3
165
9
io3
*0
165
11
165
12
165
13
16S, 14
165
15
166
164
1
166
2
I6i
3
166
^
144
5
166
6
166
s
146
9
164
1(1
164
1 1
16;.
164
13
166
14
166
IS
167
«
167
1
167
2
167
3
167
A
167
S
167
4
i47
7
167
S
167
16/
Id
167
1 1
167
167
J67
14
167
lis
168
1
168
2
168
3
163
4
163
5
16S
6
168
7
168
8
168
?
168
10
163
11
163
12
143 ;
13
163
lA
163
13
149
lo?
1
14?
2
16?
J6?
14?
4
16?
7
IAS
S
169
?
( SENEGAL CASE STtiUCTURE
EHF 16/23/81
< EXECUTION VftRlftBLES AND ARRATS ale Kin. Hwris. B»Le ftus '80 )
( ff 184 6l50 see M. A. HcCourti FB 11/4 Pp 109. EHF 2/11/81 )
; IX < K Ff£.,.sir) V uQ[*Pute& sdr of inde-! K = lf2,...fr. )
SWA? 1 KAX ( ...pfs Kfnsxl J
1 ~ tUP t + r ( . . .pfs+2:c,-i: )
i <LiST ( Ssnersl <IiUIlDS uoro Lo cor.struct n3»ed lists )
<KJILPS SHUCGE iCSF 3 i
' ! CFA e CONSTANT CDLOfl ( For hesderle&s co;ie definitions)
' fS CfA CONSTANT EOL ( End of list delifciter )
— >
! case: <LIST XK£S> U 8 EXECUTE i
t U£fu in i.hE forii; case: vm-Ax del cra2>>tcfBn S }
( to i^rsolt sr. e>;&ci<tiori srrsa x>!t:>[ with initial values cfsli )
( cf52? . . icf sfi H?iich are cooe fi?id addresses of previoU6lB )
( defirred words. E>;6Dytina x;.,.a in tri3 fo.-n; K XHK>i )
( Will prod'jce the e^.n^^li^ri uf cfsii i k= l,2f,,.fn )
: list: <li3T l^ils:- l>: i i
Used ir, fu'Bi! LIST! >;,-;>;;; C ri 1 i ri2 i r J » . . . . i ] i )
< Id creete s list of cutis ton t& risruKO >:.iiAy. , E^eciitiris y.ay.y, )
i in the tor-ml K >ix>s>t will lesve nK on the stacKt ]
t XEaVAR: <LIST DOES> t EXECUTE f
( Used in the fori; XEQVARE xkkx cfs i )
( to CTBBte an cxecyticm variable xxxx uith an initial value i
( cfs which if an exislins word* Executins kymx causes ) — >
( cfs lo be enecutedi The word cfa nsti be chan&ed bn usms )
( INSTALL nnnn AT xxxxx where nnnn is the niw word. )
J INSTALL ( ^..cfa) tCMPILEJ ' STATE 6 IF COMPILE CFA ELSE CFA
THEN f IHHZSIflTE
; AT ( cfa... J LC3H?IL£] ' STATE E IF COfiFILE 2t COrlFILE I
ELSE 2t ! THEN 5 IMSEiilATE
; (ATKIM) ( K cfs pf». ) fiGT 1 fiftX 2 * t ! i t Stores cfa at )
[ sdr = 2KtF'fs uTi£7c k-li2 n Ccri.FiJcd ba ATMN . I
; a;;;in i cfo...) LcafiPiLE3 ■ stail g if canfiLE (STkiN)
ELSE (ATt-.INJ THEN S IMMEDIATE
! Ujid in for*; It INSTALL cfs ATKIN xxxx >
< Hhere xxxk is sn execution srrss defined bu CASE! t cfs) — >
( is the new word to be installed as elskent K^liZifttrn )
: SUM r
— >
( tfflTE: McCourt'B iapleaentstion of the function IMSTALL ATKIti)
( does not worK inside a I definition. The above does. )
MCASE ; f A SENERALIZED EXTENSION OF CASEI
1. Three tupes of case stuctures;
a. POSITIONAL ( default )
t. KEVEt
2. Two strucl'jrt- options for esch tape!
a* £IiiS-E *jf-LL ci^ECuilD^t i <f£f&ull )
ttlEM 1-EvlL HLAI'^EvlFS^ CCI'E 3ERUIJ-tCE
C Define DQESFftRT and [Ii£F3 es Execution srraas to filieo )
( in later )
case; D3ESPAKT WJH BUS SUM HUM BUM BUM CUH i (6 Ceses )
case: CDEF3 DUN BUM fiUH DUM HUM SUM DUM ;
J KCASE: ( The senerslized esse co»Piier )
<BUILDS SMUDGE !C5P HERE ( Lesve Pfs on st5CK )
Pags 191 " ~ FORTH DIMENSIONS 1016
0) Range type
MCASE: xxxx RANGE
[ LI , Hi , ] cfal
[ L2 , H2 , ] cfa2
[ Ul , Hi , ] cfan
DEFAULT! cfad ;
For this type each of tt>e n entries to
the case list consists of a pair of
values specifying the upper and lov/er
limits of the range , Li and Hi ,
followed by the execution element,
cfai.
When xxxx b later executed in the
form k xxxx , the case cfai will be
selected If the condition
Li<=k<= Hi
is found during a search of the list. If
not, the default case, cfad , will be
executed.
Headsrleea Oode Execution Qements
Instead of specifying the eHeoution
elements as previously defined FORTH
words, the t^iements may be specified as a
sequence of FORTH words in the form:
Hs
..seq.
;H
DEFAULTi
where „..seq..» is the
executable FORTH words.
sequence of
Aqain we have the three applicable
case list types, tlie default type, position,
the keyed type and the range type.
Examples of the structure of each of these
types is
(1) Positional type
MCASE: xxxx
Hi ».seql_. }H
1-fc .„seq2,.. iH
Ht ...seqn... }H
DEFMJLTi ....seqcl..^ ;
(2) Keyed type
MCASE: xxxx KEYED
[ kl , ] H: ...seql... ;H
[ k2 , ] l-t ...seq?.,,. jH
[ kn , ] H: ...seqn«. ;H
DEFAULT; ...saqd ;
U9
10
U-i
11
U9
12
169
13
169
14
16?
:5
170
170
1
f yt-
*/ V
2
170
3
4
5
m
i
17C
7
170
8
170
9
17t
10
170 ;
LI
l7Ci
12
17t
170
14
17^^
if I.
C
171
1
VI
2
I J 1
i;i
4
171
S
171
171
7
171
3
171
?
171
10
171
11
171
12
171
13
171
14
171
15
172
V
172
1
irr;
2
172
3
J72
4
172
5
1/ i
6
172 8
172 9
172 It
172 11
172 12
172 13
172 14
172 15
173
173 1
173 2
173 3
171
173 5
173 6
173 7
17;
17^ 11
173 12
173 13
173 14
173 15
174 S
174 1
174 2
174 3
174 4
174 S
DD£S> CUP
DOESPART
1 Ci ( Sefsuli X.'trrE = 1 )
* Cr C HiiSi&ftr' of ca^ee in list, = )
1 <■ Enter cokpile state fo,- list }
i Gets tupe )
t Execute* tpPTOF-riste seercti )
t lEFflULT; ! ff£.,.) C Msn^atora word used efler- ce&elist in >
< an (1C#iSE; d5fir,ition. Coftf iles iS . }
TCONP EOL . HERE QVZf. C9 ( ...pfs 5<3r tafe )
£DEF3 r IhflEDIATE
J KEYED ( F'fB.,.pta? ( Used after HCftSEt xxkx to c6S4tBre~3j
3 OU£R CI ) IMMEDIATE
1 fiANSE i pf5 ...pfe) ( Used after HCASE; xxkx to est twpe=5 >
5 QyER C( } ihhediate
£ NT < fi ffs...ri pfs f ) ( ChecKs for valid catecoantf n t with >
( count iti case list with pf3 specified. Tr-ue if valid. )
0\,-£R OVEF; It ce ( ...n pfs tt count )
OVER 1 < >R < ...n pfs n count )
> R> (K 0= ; — >
( PSSITIONfiL TYPE WITH SIK-E «aftll EXECUTIQM OPTIONf TYPE 1 )
; PSFlfil- ( n pfsntl { Tape 1 cESe for BOESPARTr finds erid 5
i o.iCutss esse fi or oefaiiit if nil or (i>c&s&L-ourit fo- >
< HCflSE! lifct, Ffj, Siililer to I>. fcr CftSEl )
H? IP i Veiii f, ) 2 + SWhP ( ...ffEti n )
ELSE HOP Ce >R 6 + SiilAP IiROP S> ( ...PfE+o c )
THEM 1 - DUP + + ( ...pf3+K+2:n-lI )
B EXECUTE !
• PSCEF ( pf& sttrdsfxt) ( Counts t esses entered ant! stores }
( in CBseeount al f>fa*l . The address of the default cfa is)
£ at sd'def = Pfa+6t2:n-13 i
OVER 6 + - 2 / ( ...Pfa n-l )
It SUft!^' 1+ C! ; — >
1 IKSTflLL PSFIi^E ATMN D3£a?'6Hi
1 IKSTflLL PSBIF ATKifs [BEF3
< POSITIONAL TYPE WITH HIGH LEVEL HEP m LIST) TYPE 2 )
( code address if nU o: t.-lb
NT 6= IF t QSf ) ?R EROP R I t
Syftp ^R 4 + BEGIH 1+
R OVER = 0=
UHILE ( count not=ntf )
>R 2 - 2+ R>
REPEAT Ii^u- R> r.R5- ;
= essf t-irn i of ri th hi=^t )
V Qi" list, RsLurri SslBuitJ
1+ THEK ( ,,,n+f pfB )
t ,..pfat4 If Save n+f ;
( ...pfaH 1 f J
( ...Pf3f4 co'jnt )
C . . .sdrnut count )
-->
! PHFIHL ( ri pfe... ) i Find sfici execute iii co3s sea rt in tspe)
( 2 cstelisti rfa > Exezuls dsfeiilt if cut cf rense. )
2riMlJ EXECUTE ;
: h; ! ^fi>..r-fo tdri) ( Bsiins header less dsfiriitiori in an )
! MCmSE:: wj-.j. f^fs , Cor«?iies d'jitSiii iinK sdJrei&i co;>i'-iie& )
{ colo'i sri(i lefcveL sijress of link. Lo &e used iH )
BUF- It U Svb!?: It c; ( updstes cssecount )
li'jp c? ; fsji. If ; o-i^ )
IC? C" H- GvES C! THES { Upd&tes iMPe 1
HERE E3_ 1 ( TettF-orsry lin^. )
COLO.S f i IMfiEDIATE
t rK ( pfa adrltiipfs} ( Terminates header less definition >
( bSBun bu H! , ft^>j»t» linUr csupiies iS )
HERE 2+ S«AP ! EOL 1 i IHfiSSIATE ~>
1 PHDEr 1 pfs adr-def,..* ( Bsains headsriess defin of )
t default, Cos^ilea COLO'I ) m^? CSO? COLOtj i i
2 INSTALL FHFINt ATrilN tOZSfft^T
2 INSTALL PH£EF ATKiK CCirJ
FORTH DIMENSIONS m/6
Page 192
(3) Range type
MCASEs xxjof RANGE
[ U. , HI , I Hi
[ L2 , H2 , ] Ht
..seql..
„seql.
[ Ln , Hn
DEFAULTi
] Hs
,.seqn... jH
FhEi inturpretation of k in case
selecting iu Ihp, samp ns previously
discussed for the single word execution of
the same case type. The only difference
is that a FORTH soquoncc, ...seqi.,, is
executed instead of a single FORTH word,
cfai •
ExBinplas
Examples of all 6 possible
combinations of case structures are given
on Screens 180 and 181. If the screen Is
loaded and exainpies tested, typical
axecution results should be:
EXECUTE
1 BARN
2 BARN
.18 BARN
1 ZOO
5 ZOO
-6 ZOO
CDefaxilt^
RESULT TYPED
MOO
niiMK
PEEP (Default)
PEEP PEEP PEEP
PEEP PEEP MOO
OINK OINK OINK
1 FARM
77 FARM
□INK (Default)
MOO
-10 CASE MOOOIMC PEEP
(Default
77 CASE MOCtoooOOO
PEEP PEEP
GINK OINK
PEEP OINK MOO
MOO (Default)
-10 CORRAL
-1 CORRAL
309 CORRAL
310 CORRAL
COMMENTS
1. Kim Harris' case compiler, CASE:
avoids the use of OVER -- [1 DROP
ELSE... THEN for every case as iisud in
many of thu other HASH constructs.
Tiifi result is shorter r^oinpiled code in
thp application. The compiler,
MCASE: presented here is an extension
of CASE! and consequently shares this
feature.
2. The compiler, CASE: and the
Execution Array introduced by M.A.
McCourt in FD n/4 pp 109 are
functionally equivalent. Further, the
Execution Variable, XEQVAR , of
McCourt turns out to be a degenerate
case of CASE: with only one element
in tlie case list. The definitions
17 A
17A
7
8
174
?
174
10
174
11
17-;
14
15
2
4
r
V~t-
175
175
175
J
175
10
* 7 J
1 1
175
IZ
175
13
175
14
175
15
1 7o
ITii
1
1/i
2
176
3
4
17u
176
6
176
7
176
3
XI a
7
( KEVEC TYPE UITH SIK5LE UOSIi EXECUTIOfj OPTION, TYPE 3
I ^
176
176
13
176
14
176
15
177
G
177
1
177
2
177
3
177
4
in- S
1/ f
5
177
9
117
JO
177
11
177
* *t
13
1. t '
: XEQ/tf^RAY CASE: ;
; XEQVAR <UST OOES> % EXECUTE ;
^ 1 1
i;s
178
1
178
2
178
3
17S
4
178
5
17S
17S
7
m
8
178
9
178
10
175
11
178
12
178
13
: KSDEF ( pfB efSrdef...! ( Counts # esses erttered and slores )
e in cstecoiint si Ffs^-l. ftddr^ess of default cfe is )
( 6drdef''cf»l6t4:r.-13 )
OVEP. 6 ♦ - 4 / 1+ SWAP 14 CI i
: r.SFISD ( K Pfe...J ( SaarchES tyr-e 3 li&l for of he= )
4 La K . Stsrts St, (^fs+S . £.^e;ijl5t cf^ iftcr i / — ^
! Keu s." jife-Ii, if ftu n>st-:h fo'jnfi. )
li BEGIK 1 >F; U'J? G ^2. - ( , . A sdr 1 f )
IF ( not EGL) 3VER OJER g = ?
IF i QtBt'-H^d ) 2-f (
C..S; F,y 1 - >R 4 f THEfJ 1
Li'iii^ i ^j^LL't'Li;:! Gr EG—} S^A- h^'^^ir £
3d: l K=!IT )
> ,k sdr l+I J
3 INSTALL r,SFiN5 ftTKIH l)3iS?AST
3 IKSTftlL KSDEF ATKW CDEF]
< K£T£y 0?Tia:i UITH HIC.H LEVEL DEF I« LIST. TYPE 4 1
I KHFIKC ( K pfs...) C Searches Ibps 4 list for netch of hes* )
( to K t SLsrts Bt pfBfZ • E^e^iites high level seauerice) — >
i ...K Edrl f 3
( follOMirii: a^lch or usfsui:
2+ BiGIti 1 >R I.J"^ e EO. '
IF i not EG„) OVEf; Gvl^. (£ = ( ...ti ed' 1 K = 3T
IF t ftstcriidi 4 i ( ...k siS"it4 )
ELSE fi> 1 - ^"rt 2+ E TH!£h i ...h SGriii:;, >
ELSE ( EOLl 2f i ...K Bdrdsf 3
THEN R> ( ...K edrritM f 3
UNTIL ( HBtched ay E0L3 SUftP C.R3.=- EXECUTE i
4 IriSTALL KrI!" Ifii- ATLIr^ IO-j.'
s F;firjG:; ivrx with si«c
i Roi'HF < pfs 3drdsf...3 4 Edrdst- f f £f6Tii:ri-± j i-QjiFui= r. sua j
I store 3t pfs+1 ) —>
OVER 6 4 - 6 / U Sys? 1+ Ci i
! RftfiSE? ( K 3dr...f ) ( True if H>= velue at ecir ANt Ks* «siue3
( St Bdr+2 3
>R B'J? R e < SWAP R> 2+ e > OR 0= i
: RSFINS ( K Ffs...) ! Ss6:";his tape 3 iist for first o:currti>i
i Cc of K Hit^iri rSif C'f rarise vslues. Exeiulei cfs fcaiow- J
( ir.ii FEir. Ei.&cut = 5 dsfsylt cfe if not fojnd i
2i &EGIN 1 >R IU? e £QL - ( ...K sd' 1 f )
IF ( not EGL 3 OVllK 3>E?. Sft-iGET ( ...K sdri S )
IF ( in rense) 4 t ( ...K sdrlT4 3
ELSE 1 - >R 6 + THEN t 5S-r.;;t )
ELSE t EOL) 2+ { ...1^ edrd5f )
THtW R^- \ ...K 60' r.6« f }
Li^iTIL S In rensie or EG- ; Saifi- e EXt^-yiE ; — >
5 INSTALL RSFIHD ATKIN CO^SFV,.-:!
5 mSTftLL fiSeSF fiTKIN tDEFJ
« RfiMSE OPTION «ITH HI5H LEVEL D£F IK LIST. TYPE 6 )
J RHFIWJ < K p-fsi..3 ( Sesrc'ies tas^e 6 iist for first occurr-3
( ence of K uilhiiri Peir of rsiia^ values. If found? exezutefi)
( follouing hish level seauerice. el&e e>:ecutes dsf sequence/
2+ BEGIN 1 >R Bl^ i EOL - {,,.)( adrl f )
IF ( not EtH.) OVER OVER iiANSET t ...k sdM S )
IF ( in r5n^3 & 4 ( ...K sdrlM }
ELSE R> 1 - >R 4 + e THEN C ,,.K eOrniil >
ELSE ( EOL) 2+ ( ...K adrdef 3
Page 193
(?5rth dimenstons ni/6
are fiq-FORTH functional equivalents
of McCourt's definitions. Hence
Ci^ASEi can bu used as an Execution
Array as suggested by McC(«jrt. The
definitions of AT , ATKIN and
INSTALL on screens 167 and 168 can
tie used ala McCourt to ctianQe the
eleinnnis in TAfiE: list words. They
are used in fhe form
kiN'ilAL yyyy ATKIN xjotx
to chancjp the t^'t.h elprrient in ti oose
list, xxxx defined by CASF: to the code
field fjildiess of yyyy . Nnw whenever
k xxxx tii (ini:ijufii.oreil, llu-^ wiji'ti yyyy
wili ht^ executed rdLiier Liiaii ttie
original word in the k'th position of the
case list,
UsiiiLi the previous CASE: exnrnple of
RARN , if we execute
2 INSTALL. COW ATKIN BARN
the second case in BARN will be
chanqed from PIG to COW. I,ater
execution ot 2 l^ARN anywhere in the
program wit! theji type MooOOoo
instHnd of Oinl<,
Altbuiii})i liiis is nuii-3truf't.ure(i
j)r()i)tainmiinj, it is stiil h v;iiual)le
proqromminq tdtil whm usrri
properly. Tin? (ii Pisent dt? finil iuivj of
INSTALL find ATKiN can be used
within a t^olon definition.
Please note !ii;it tlie u'ju nf the
f.xecutiiMi Array in the d(?vr? Icprnent of
fi/ICASIJ: on screen lfi9 is purely
stylistic. It is not a necesRdiy feature
of the development.
3. The essentially unique feature of
KOHTH is that it is extendable by the
user. WiUi an expandinci FtlRTH
literature, it is clear to tliis author
that FtlRTH will improve with time
faster than all other lanquaqes and
that there is no upptir limit to its
iiTiproveini'Mit. It has been iess th:in ill
months since 1 first got FORTH up nnd
runninq. In ttiat short period of time,
Ihiiuks to the fit) lilei-ntuii;, tin?
f'DR ff-l syslefii 1 liavi* [■UJniinii nnw r.i,
in my opinion, vastly superior to any
otlKjr hinquaqe ! have ever seen. And
it wili qet better!
1 TR
14
It
THEN R>
f )
XkJ
UNTIL ( In rsnse or EOL
) SyAP D.1;aF' EXECUTE J
— >
171
V
1
1
& INSTALL mTim ATKIN SOESPART
179
*>
6 INSTALL PHIlEf ATK.IK ( SiM 8K tvfcs
2 &ri<i 4
}
179
3
ir9
A
179
6
179
7
17¥
8
17?
5
17 J
10
17"
17V
17 '>
13
17?
14
IZ'.'
\uj
lE^
; fiQ ," oiri;, i
1G5
3
! GQU ." MO' i
IGO
4
t CHICK PEEP ° f
IBS
IGl
hcase: ba»n cow pig chick default: ckick \
IS J
7
185
s
HCASi: 203 Hi CHICK CHICK CHICK tK
is;
k: cou omOM*
iK
is;
10
Hi CHICK CHICK Cm !K
IS)
I>EFfiU;,T; PIG PIC
PIG i
iSi
ig;
13
«:;a3e: fasa keyeb : 3) , i
FIG
14
t 77 . ]
CO-i
1 J
t 67 > J
CKICK
181
cefa'jlt;
PIG >
ISl
Ji
181
«-ase: cage keyed l 77 . l
K: cow ossOH'
J n
III
3
H! PIG PIG
tH
lEi
i 67 t i
H; CKIi^K CriiCK
;h
131
C'jjt PIG CiiiCf^ *
lol
t3
V6l
M-riSE; ftfi RANuE [ -3276S
T - 1 J 1 CKi lI,
ISi
8
£ f-
1 1 J J f It
1£1
1
i: 1
ISl
le
default; i
l^i
11
lU
12
HCAS!:t COSRAU RAH^E t -IC ,
■ J . ] ii; CfiiCr, c
iK
lEl
13
[ -1 I
ZC ! IG
f H
181
U
[ f
ii I J h ; C G 1- ■
ISl
IS
C 1 t 309 1 3 H! CKICi. PIG COJ iH ICTftJ.T; CG« i
FOR f hi DiMENSlONSTnTe'
Page 194
FORTH STANDARDS TEAM K«ET1NG
A FORTH Standards Team meeting
will be field in Bethesda^ MD, from May 11
through Mny 14. The mijRUtii.i is npen to
the riirrpnt Standards Tearn inemhRrs and
a limi^t^rl ruj Tiber of observers* The site
will be the National 4H Center, a self-
crintninprl (■(luratiorej I Tacjiity. jiisi. outside
Waohinntnn, DC The campus-like Center
has meetinq rooms, dining facilities and
dormitory accommodations.
This four-day meeting will allow
world-wide Team members to consider
proposals and corrections for the current
FORTH Standard and develop future stan-
dards policy. Participation is possible by
aubmittal and attendance. Written sub-
mittals received by April 30 will be
distributed to attendees before the
meeting. Late receipts will be distribued
at the team meeting. Those wishing to
attend must apply without delay, as space
Is severely limited.
Applicants (other than team members)
must siimit a biography by April 15 for
consideration by the credentials com-
mittee. You should include:
1. Your ^Uls and comprehension of
multipls FORTH dialects aF\d their
application.
2. VAty your views are representative
of a significant portion of the
FORTH community.
Accommodations are $41 to (47 per
day, per person, including meals. Send a
refundable $100 deposit (and bioqraphy for
observers) to the meetinci coordinator.
You will receive further details on choices
in housing and meals.
SiAimittals ore essential if Team
actions are to represent the broadening
scope of FORTH users. Specific con-
sideration will be given to an addendum
correcting FORTl-lr-79, the Team Charter,
and alliance with other standards groups.
Those not attending may receive copies of
siibmlttals by sending $30 to the meetinq
coordinator.
All siJbmittats and reservations should
be directed to the meeting coordinator;
Pam Totta
Creative Solutions
4801 Randolph Road
Rockville, MD 20852
(301) 984-0262
FORTH DIMENSIONS
VOLUME IV
BEGINS NEXT ISSUE
Beginning with the next issue, each
edition of FORTH DBvlENSIONS will hi^-
light a special theme. Our May/ June issue
will feature several articles on complex
arithmetic routines in FORTH such as
fixed-point trig, square root, and floating
point. Of course, the remainder of each
issue will contain the usual techno tes,
product revievirs, tutorials, letters, etc.
Suggestions for future themes Include;
Process Control Applications
Database System Applications
Teachin[j FOKTIH
Data Acquisition and Analysis
FORTH in the Arts
CP/M
Laboratory Worlcstations
Serial Communications
Ntetacompilation and its Alternatives
The FORTH Environment
Your input to these topics is greatly
needed!
RENEW TODAY!
Page 195
FORTH DIMENSIONS m/6
LECTURES ON APPLIED FORTH
a two day twrtlnar en Forth and Itt application
and the
1962 ROCHESTER FORTH CONFERENCE ON DATA BASES AND PROCESS CONTROL
May 17 through May 21, 1962
University of Rochester Rochester, New York
As part of the 1982 Rochester FORTH Conference on Data Bases and Process
Control there will be a two day seminar on Applied FORTH. Managers and pro-
grammers will find these lectures very useful for a^loring FORTH applications
BDd progranalng concepts . Each lecturer will also lead a Working Group at the
subsetiuent Conference. Participants should have a copy of Leo Brodie's book,
Starting PORTS , which is available from Mountain View Press, FO Box 4656, Mt.
View, CA 94040 for $16.00.
Lecturers for the two dey seaiinar arc:
Leo Brodle, author of Starting FORTH , on "Beginning FORTH".
Kin Harris, of Lazen & Harris, Inc., on "FORTH Progra Baling Style".
Hans NleuwenhuljKen, of the University of Utrecht, on "FORTH Programming
Environment".
Larry Forsley, of the Laboratory for Laser Energetics, on "Extensible
Control and Data Structure".
David Beers of Are go n Systems, Inc., on "A Large Programming Project Case
Study: Building a Relational Database in FO^tTH".
Steven Marcus of Kltt Peak National Observatory, on "Assemblers & Cross
Assemblers".
James Barwood of the Institute for Astronooy at the University of Hawaii,
on "Coiqjutatlon Tradeoffs".
Soger St^leton of St. Andrews C^servatory, Scotland, on "Hardware Control
with FORTH".
Raymond Dessey of Virginia Polytechnic Institute, on "Concurreni?, Het-
working and Instrument Control".
SBGISTRATION F<3RM
<aust be received by April 23, 1982)
Nane
Address
City, State _ZIP
Phone (Days) { )
CHOICES TO BE MADE
ippliod FORTH Seminar, May 17 & 18 $200.00
1982 Rochester FORTH Conference, May 19-21. 100.00
Itouslng for: (circle dates) May 16 17 18 19 20 21 $ 13.00/perBon dbl
16.50/person sgl
TOTAL AMOUNT ENCLOSED $
Make checks payable to: "University of Rochester /FORTH Conference"
Send check and Registration to:
Mrs, B, Rueckart, Lab for Laser Energetics, 250 E River Rd, Rochester, HY 14623
For Information call: Barbara Rueckert (716> 275-2357
FORTH DIMENSIONS Hl/6
Page 196
Mare FORTH for Nortfistar
now Available
Marx FORTH is a fust, [lownrfui
FORTH system written in Z-8CI code.
Package includes self -compiler, complete
source code, screen editor, ami "smart"
a?;s<>inlili^r. Some nf thp features include
calls to the N* directory functions allow-
ing creation, deletion and listing of
directories and ease of svriting FORTH
programs that operate on files created by
N* BASIC Some of the performance fea-
tures include very fast compile speeds,
very fast math, 31 -character variable
length names, case compiler security,
arguiitents-results, link field in front of
name, and many machine code definitions
for high speed.
The self-coimplfer allowr, you to change
anything. If you don't like how [ do it,
change itl Add anything you want. Price
is $85 on N* single density diskette.
Source listing available separately for $25.
Perks! Software Systems
16J6 N. Sherman
Springfield, MO 65B03
(417) 862-9830
FORTH Ftegiamndng Mds
FORTH Programming Aids are high
level FORTH routines which enhance the
development and debugging of FORTH
programs and complement cross compiler
and meta compiler operations with the.
following features:
- A command to duccmpile high Itjvol
FORTH words from AM into struc-
tured FORTH source code including
structure control words. This
command is useful to examine the
actual source code of a FORTH
word, or to obtAln variations of
FORTH words by decornpillng to
dN<, editing, and recompiling the
modified aource code.
- A commend to find words called by a
specified word to all nesting levels.
- Commands to patch improvements
into compiled words and to merge
infrequently called words fw in-
creased program speed.
- Complete source code and 40-page
manual are provided.
Requires a FORTH nucleus using the
fig-FORTH model; a minimum of 3K bytes
and a recommended 13K bytes of free dic-
tionary space. $150 Bir*gle CPU license;
$25 far manual alone (credit applied
toward program purchase). California
residents add 6.5% tax. Add J15 for
foreign air shipments. Available on S-inch
8s/ad dBks (FORTH screens or CP/M 2.2
NEW PRODUCTS
file of screens;, and Apple 3,2 and 3.3
di^s; inquite ^ihmit r if her formats.
Ben C^Jrry
Curry Aasociates
PC Box 11324
Palo Alto, CA 94306
New Book; MrodueUoi to FORTH
Introduction to FORTH, a 142^>aqe
textbook by Ken Knecht, presents the
most complete information available on
the MMS FORTH version of tlie FORTH
language. It is written for unyoniv wlio
wants to learn how to write computer
software using FORTH.
No previous knowledge of FORTH is
required, hut some exposure to Microsoft
Level n BASIC will be helpful. Although
the book is designed specifically for the
MMSFORTH version of FORTH for the
Radio Shack TRS-80 Models I and III, most
program examples can tie adapted to run
on oUier microcamputers that use dif-
ferent versions of FORTH.
RENEW NOWI
FORTH for Ohio ScienUflc
We've received from Technical
Products Co. a copy of their newsletter.
This issue contains product news and
update screens for FORTH-79, We
applaud their Intent of good customer
support, but note technical errors in
definition uf several standard wordy
( WORD , Rta , END-CODE , 2CaNSTANT
, D< ). This OSI-rORTH oper.Ttr^s with
Ohio Scientific OS_65D 3.3 operating
system release.
Their new address is Technical
Products Co., Box 2358, Boone, NC
28607 -ad.
RENEW TODAY!
" MCZ,a}S,UDS FORTH
FORTH Is now running on Zilog MCZ,
ZDS, and tvlultitech UDS microcomputer
systems. It has compiler, editor,
asserrtiler, text interpreter, and I/O drives
for floppy disk, Centronics printer, and
RS232 devices.
Assembly source listing is avalMile
now for $10. Source code on diskette is
$50 (specify MCZ, ZDS, or UDS). User's
manual will accompany each order.
Send checks to Thomas Y. Lo, Electri-
cal Engineering Department, Chung Yuan
Christian University, Chung Li, Taiwan,
Republic of China.
SoftwBie for OSI CIP
Shoot The Teacher - Find the teachsr and
shoot him with your water pistol.
(Teaches basic graphing) $6,95
Speedo Math - Race the computer with
your car, (Drills basic addition and
multiplication) $6.95
Kamakaze Fducation Pack - Four pro-
grams in one. Addition, X Tables,
Spelling, and Place Vaiue Drill. Answer a
question and your men go on their last
mission. $11.95.
That's Cr;i/y - A Lakroff from fnmwjs
TV Show where you risk ynur life to jump
over cars and a canyon. A spelling
program that provides hours of enter-
tainment. I $11.95 (specify grade level)
Want Ada Lifte Skills - A program that
helps slow readers understand the Want
Ads. Five levels of difficulty. $7.95
Rescue Ship - Transport injured soldiers to
the hospital. But the enemy has covered
the ocean with mines. One of them could
dfistroy you.
AddiLiori - $1 1 ."35
Sijhtraction - $11, 95
Multiplication - S11.95
(all three on tape - $28.00)
Pieasfi include $1.00 to cover postage and
handling and send to:
Henry Svec
668 Sherene Terrace
London Ontario Canada
N6H 3K1
Page 197
FORTH DIMENSOsIS 10/6
FORTH VENDORS
The following vendors have verrians of
FORTH available or are consultants, tFtQ
makes no judgrnent on any products.)
ALPHA hOCFlO
Professional MBnegQunent Services
724 Ara^tr.'iriero Rd. #lfl9
Palo Ako, CA S4306
(408) 2bZ-2Z18
5jerra Computer Co.
617 Mark
Albuquerque, NM 9TI23
APPLE
ID PC Company
P. O. Box U5»
Philadelphia, PA 19116
{215)
njS (Cap'n Software)
281 Arlington Avenue
Berl<eley, CA 94704
C415) 525-94S2
George Lyons
280 Hendsrson St.
Jersey City, ^4J 07302
(201) 451-2S05
MicroMction
12077 Wi I shire Blvd. #506
Los Angeles, CA 90025
013)821-^340
CROSS COMPLCRS
NautlLus Systems
P.O. Box IQSa
Santa Cruz, CA 95061
<WS) 475-7M1
polyFORTM
FORTH, Ific.
2309 Pacific Coast Hwy.
Hermosa Beach, CA 90254
C213) 372-8493
LYNX
3301 Ocean Park #301
Santa Mordca, CA 90405
(213) 430-2466
M & B Design
820 Sweettiay Drive
Suwiyvale, CA 94086
Mlcfflpofts
Shaw Lahs, Ltd.
P. O, Box 3471
Hayward, CA 94340
(415) 276-6050
North Star
The Software Works, Inc.
P. O. Box 4386
Mountain View, CA 94040
(406) 736-4938
PDP-11
Laboratory Software Systems, Inc.
3634 Mandevllle Canyon Rd.
Los Angeies, CA 90049
(213) 472-6995
OSl
Consumer Computers
8907 LsMssa Blvd.
LaMim, CA 92041
(714) 6$Mm
VENDORSi FDRTHDVCNSCNSwUlgotD
Software Federation
44 University Dr.
Arlinqtnn Heights, H. 60004
(312) 259-1355
Technical Products Co,
P. O. Sox 12983
Gainsville, FL 3Z604
(904) 372-8439
Tom Ziinmer
292 Falcato Or.
Milpitas, CA 95035
1802
FSS
P. a Box 8403
Austin, TX 7S712
(512) 477-2207
6eOD&6B09
Talbot Microsystems
1927 Curtis Avenue
Redondo Beach, CA 90278
(213) 376-9941
1RS-«I
The Micro Works (Color Coniputer)
P. a. Box UIO
Del M£i-,CA 92014
(7]fi) 943-2*00
Miller Microcomputer Services
61 Uttm Shore Rd.
Natldc, MA 01760
(6171 £53-6136
The Software t-~arm
P. O. BoK 2304
Restan, VA 22090
Sirius Systems
7528 Oak Ridge Hwy.
Knoxvilte, TN 37921
(615) 693-6583
6502
Eric C. Rehnkc
540 S. Ranch Vieiv Circle if61
Anaheim Hills, CA 92087
Setum Software, Ltd.
P. O. Box 39:'
Nsw Westnnlnister, BC
V3L 4Y7 CANADA
BBsarmfcPfM
Laboratory Ml c rosy stems
4147 Beethuven St.
Los Angeles, CA 90066
ai3) 390-9292
Tim in Engineering Co.
3573 Genesse Ave. #E-2
San Diego, CA 92121
(714) 455-9006
/^ipllmtlan RackagM
InnoSys
2150 Sh at tuck Avenue
Berkeley, CA 94704
(415) 843-8114
Decision Resources Corp.
28203 Ridgefem Ct,
Rarcho Palo Ver*, CA 90274
(213) 377-3533
pradkiet matrix In VoJunw IV. Sand In a IM
fflflflO
Emperlcal Res. Grp.
P. O. Box 1176
Milton, WA 98354
(206) 631-4855
Firmware, Boards and MaiMnes
Oalricon
7911 NE 37rd Dr.
Portland, OR 97211
(5Q3) 204-8277
Fraward Technology
2595 Martin Avenue
Santa Clara, CA 95O50
(408) 293-8993
Rockwell International
Microelectronics Devices
P.O. Box 36C3
Anaheim, CA 92803
(714) 632-2862
Zendfix Corp.
6i9e DougherLy Rd.
Dutjlin, CA 94566
Variety of FORTH Prodkicts
Interactive Comfjuifir Systems, Inc.
6403 Di Marra Rd.
Tampa, FL J^Cia
Mountain View Press
P. G. Box 4636
Mountain View, CA 94040
(415) 961-4103
Si^jersoft Associates
P.O. BoK 1628
Champaign, B. 61820
(217) 359-2112
Consultants
Creative Sokltions, toe.
4801 Randolph Rd.
Rockville, MD 20852
Dave Soulton
581 Oakridge Dr.
Redwood City, CA 94062
(415) 368-3257
Len Brodle
9720 Baden Avenue
Chatsworth, CA 91311
(21 J) 998-BJ02
□o FORTH
504 Lakemead Way
Redwood City, CA 94062
(415) 366-6124
Inner Access
517K Marine View
Belmont, CA 94002
(415) 591-8295
Laxen A Harris, Inc.
24301 Southland Drive, #303
Hayward, CA 94545
(415)887-2894
Microsystems, Inc.
2500 E. Foothill Blvd., #102
Pasadena, CA 91107
(213) 577-1471
year pmducta and aerylcas by April 18
FOI^TH DIMEN^MS ttlfs
Page 198
FIG CHAPTERS
How to form a FIG Chapter:
1. You decide on a time and place for the
first meeting in your area. (Allow at least
B weeks for steps 2 and 3.)
2. Send flG a meeting announcement en one
sidu of 8-1/2 K 11 paper 'nne copy iS
enough). Alto send list of ZIP numbers
that you want mailed to (use first three
digits If it works for you>.
3. FIG will print, address and mail to
members with (tie ZIP% you want from
Sen Carlos, CA.
4. When you've had your first meeting with 5
or more attendees then FIG will provide
you with names in your area. You have to
tell us wlW) you have 5 or more.
Northern California
4th Sat FIG Monthly MeRtinq, l:DU p.m., at
Southland 5l>oppirKj C tr., Huy ward,
CA. FORML Workshop at 10:0D am.
Southern California
Los Angeles
4th Sat FIG Meeting, 11:00 a.m^ Allstate
Savings, S8a0 So. Sepulveda, L.A.
Philip Wasson, (213) 649-1428.
Orange County
3rd Sat FIG Meeting. .12:00 noon, FuUerton
Savings, 18020 Brockhorst, Fountain
Valley, CA. (714) 896-2016.
San Dieqo
Thur i'lli Meetinc), IZ;00 noon. Guy
Kelly, C714) 268-3100, x 4784 for
site.
Northwest
Seattle Chuck Pliske or Dwight Vandenburg,
(206) 542-7611.
New England
Boston
1st Wed FIG Meeting, 7:00 p.m.. Mitre Corp.,
Cafeteria, Bedford, MA. Bob
Demrow, (617) 389-6400, xl9B.
Boston
3rd Wed MM^fORTH Us^rs Gro.jp, 7:C0 p.m.,
Cochittiate, MA. Dick Miller, (617)
653-6136 for site.
Southwest
Phoenix Peter Bates at (60Z) 996-6398,
Tulsa
3rd Tuea f- It^ Meeting, 7:30 p.m., The
Cornputer Store, 4343 So. Peoria,
Tulsa, DK. Roh Qles, (918} 599-
9304 or Art Gorski, (918) 743-0113.
Austin John Hastings, (512) 327-5864.
Dallas
Ft. Wortti
^th TTiur FIG Meeting, 7:00 p.m.. Software
Automation, 1005 Business
Parkway, Richardson, TX. Marvin
Elder, (214) 231-9142 or Bill Olssel
(214) 264-96B0.
MounLain West
Sate Lake City
Bill Haygood, (801) 942-BOOO
Mid Atlantic
Potomac JoRl Shprent2, (703) 437-9218.
New Jersey George Lyons (201) 451-2905.
New York Tom Jung, (212) 746-4062.
Midwest
Detroit Dean Vieau, (313) 493-5105.
Minnesota
1st Mon FIG Meeting. Mark Abbott (days),
(612) 954-0776 or Fred Olson, (fil2)
SBe-953Z. Call for meeting place
or write to: MNFIG, 1156 Lincoln
Avenue, St. Paul, MN 55105.
Foreign
Australia Lance Collins (03) 292600.
England FORTH Interest Group, c/o 38,
Worsley Road, Frimley, Camberley,
Surrey, GU16 5AU, England
Japan FORTH Interest Group, Beba-bldg.
8F, 3-23-8, NiBhi-9iimbashi,
Minato-ku, Toyko, 105 Japan.
Canada - Ouebee
Gilles Paillard, (418) 871-1960 or
643- 2561.
W. Germany Wolf Gorvf^rt, Roter Hahn 29, n-2
Hamburg 72, West Germany ,(040)
644- J985.
SIGN DP A FRIEND
START A FIG OUSTER
PUT THE OfiDER FCm OH THE BULLETIN BOARD
Page 199
FORTH DIMENSIONS 111/6
FORTH INTEREST GFIOUP MAIL ORDER
FORaGN
USA AIR
□ Membership in h ORTH INTCREST GROUP and Volgrne IV of $15 $27
FORTH DIMENSIONS (6 isKyf-sl
□ Volume ni of FORTH DIMENSiONS (6 issues) 15 18
O Volume II of FORTH DIMENSIONS (6 issues) 15 18
O Volume I of FORTH DIMENSIONS (6 issues) 15 18
□ flg-FORTH Installation Manual, cqnlainlng the language model of 15 18
fig-FORTH, a complete glc^ary, memtiry map and Installation InstrucUons
□ Assembly Langjagn Source Listing af fig-FORTH for specific CPU's
and machines. The above manual is required far installation.
Check appropriate boxes. Price per each*
□ lBa2 □ 6502 □ 6BO0 □ £809
□ 8080 □ 808ti/8M8 □ 990O □ APPLE II
□ PACE □ NOVA □ PDP-11 O ALPHA MICRO 15 18
□ "Starting FORTH" hy Brodie. BEST book on FORTH. (Psperbeck) 16 20
O "Starting FORTH" by Brodie. (Hard Cover) 20 25
O PROCEEDINGS 1980 FORML (FORTH ModifleatlOT Lrt») Conference 25 35
O PROCEEDINGS 1981 FORTH University of Rochester Conference 25 35
□ PROCEEDINGS 1981 FORML Conference, Both Volumes 40 55
□ Volume I, Language Structure 25 35
□ Volume 11, Systfims and Applications 25 35
□ FORTH-79 Standard, a publication of the FORTH Standards Team 15 18
O Kitt Peak Primer, by Stevens. An ind^th self -study primer 25 35
□ BYTE Maqaziny Reprints of FORTH articles, B/SO to 4/81 5 10
□ FIG T-shirts: □ Small □ Medium □ Large □ X-Large 10 12
□ Poster, Aug. 1980 BYTE cover, 16 x 22" 3 5
□ FORTH Programmer Reference Card, If ordered separately, send a FREE
stamped, addressed envelope.
TOTAL $
NAME ^MAIL STOP/ APT
ORGANIZATION (if company address)
ADDRESS
CITY STAT E Z I P C OUNfTR V
VISA // ^MASTERCARD #
EXPIRATION DATE (Minimum of $10.00 on charge cards)
M^e check or money order in US Funds on US tiank, payable to; FIG. All prices include
postage. No purchase orders without check. California residents add sales tax.
ORDER PHONE NUMBER: (415} 96Z-4653
FORTH NTEREST GROUP
PO BOX 1105
SAN CARLOS, CA 94070
o
o
o
3
r
CO -D H
« 3E
n <=> d
g wi III
£ m
o »
O O
3D
O