OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

12
FORTH DIMENSIONS OCTOBBR/IOVEMbER 1978 VOLUME 1, NO. 3 7 CONTENTS HISTORICAL PBPSPBCTIVB COITPIBPTED UTBPIAL DTC VI ITC for FORTH David J. Sir.# D-CHARTS Kim Earria ?ORTH VI ASSEMBLY Richard 1. Main HIGH SPEED DISC COPY Richard B. Main SUBSCRIPTIOII OPPOPTUIIITY Page 24 Paee 24 Page 25 Page 30 Page 33 Page 34 Page 35 FORTH INTEREST GWP ***a* RO. Box 1105 .**** San Carlos, Ca. 94070

Transcript of OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

Page 1: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

FORTH DIMENSIONS OCTOBBR/IOVEMbER 1978 VOLUME 1, NO. 3

7 CONTENTS

HISTORICAL PBPSPBCTIVB

COITPIBPTED UTBPIAL

DTC VI ITC for FORTH David J . S ir .#

D-CHARTS Kim Earria

?ORTH VI ASSEMBLY Richard 1. Main

H I G H SPEED DISC COPY Richard B. Main

SUBSCRIPTIOII OPPOPTUIIITY

Page 2 4

Paee 2 4

Page 2 5

Page 30

Page 33

Page 34

Page 35

FORTH INTEREST G W P * * * a * RO. Box 1105 . * * * * San Carlos, Ca. 94070

Page 2: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

HlSrORJCAl F O R T H was o r e a t e d by H r . C h a r l e s H.

n o o r e i n a b o u t 1969 a t t h e N a t i o n a l Radio Astronomy O b s e r v a t o r y , C h a r l o t t e s v l l l e , V A . I t was c r e a t e d o u t of h i s d i s s a t i s f a o t i o n w l t h a v a i l a b l e programming t o o l s , e s p e o i a l l y f o r a u t o m a t l o n . D i s t r i b u t i o n of h l a work t o o t h e r o b s e r v a t o r i e s h a s made FORTH t h o d e - f a c t o s t a n d a r d l a n g u a g e f o r o b s e r v a t o r y a u t o m a t i o n .

M r . n o o r e and s e v e r a l a a a o c i a t e s formed F o r t h I n c . i n 1 9 7 3 f o r t h e p u r p o s e o f l l c e n a l n g and s u p p o r t of t h e FORTH O p e r a t i n g S y s t e m a n d Programming Language , and t o s u p p l y a p p l i c a t i o n p r o g r a a a i n g t o meet cus tomers’ u n i q u e r a q u i r e m e n t r .

FORTH e n j o y s a s y n e r g l s m or its f e a t u r e * . I t h a s none o f t h e e l e p h a n t i n e c h a r a c t e r i s t i c s of PL/1 o r F O R T R A N . I t has a d e n s i t y and s p e e d f a r s u r p a o r l n g BASIC, b u t r e t a i n s an i n t e r o e t i v e n a t u r e d u r i n g p rogram d e v e l o p m e n t . Sinoa i t 1s e x t e n s l b l e , s p e c i a l wordo a r e e a s i l y d e f i n e d

PERSPECTIVE t o g i v e it t h e tmrsanm8a or APL. It8 c l a r i t y and c o n a i a t a n o y r e a r l t f rom b o l a s t h e p r o 4 u o t OF a single 8 l n d . (an v m r m A?% and PASCAL).

A l t h o u f i t h o l a n g u a g e o p a o l f l o a t i o n and many l r p l e o e n t a t l o n s are i n the p u b l l a d o m a i n , many o t h e r i m p l e a e n t a t l o n a and a p p l i c a t i o n p a c k a g e s 8m a r 8 i l a b l o 8 . program p r o d u c t s of c o r m m r o l a l 8 u p p l l e r a .

The FORTH In t e re s t Group 18 omnterad l n n o r t h e r n Ca l i fo rn ia . I t waa fo rmed in ! 9 7 8 by 10081 FORTH programre rm t o aocour8ga Uam of t h e l a n g u a g o by t h e intmrohanae of ldeam t h o u g h 8emiaars and p u b l l o a t l o n a . Abou t 300 m e m b e r s a r e p r e s e n t l y a88OOl8tOd ? n t o a ~ o o s e n a t i o n a l o r g a n i z a t i o n . ( ‘Looam moans t h a t no b u d g e t o x i s t a t o s u p p o r t any f o r m 1 e f f o r t . ) A l l e f f o r t is on a v o l u n t e e r br8fa and t h e g r o u p l a a s m o a l a t o d with no vondors.

;3 W.?.R 8 /20 /78

CONTRIBUTED MATERIAL

PAGE 24

FORTH INTEREST GROUP . .*** PO. Box 1105 - - - * * San.W@s, Ca. 94070

Page 3: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

D T C V E R S U S I T C FOR F O R T H ON THE PDP-11

By D a v i d J. S i r a g L a b o r a t o r y S o f t w a r e Systems, Inc.

3636 M a n d e v i l l e Canyon Road, Loo Angeles, C A 90049

D u r i n g t h e d e s i g n o f LABFORTH, t h e F O R T H i m p l e m e n t a t i o n b y L a b o r a t o r y So f tware Systems, t h e c h o i c e had t o b e made b e t w e e n d i r e c t t h r e a d e d code ( D T C ) and i n d i r e c t t h r e a d e d code ( I T C ) . A d e t a i l e d a n a l y s i s showed DTC t o be s i g n i f i c a n t l y S u p e r i o r t o I T C i n b o t h speed and s i t e . T h i s a n a l y s i s c o n t r a d i c t s t h e f i n d i n g s o f Dewar ( A C M June 1975) w h i c h were r e f e r e n c e d i n t h e "Threaded Code" a r t i c l e i n t h e August 1978 i s s u e o f F O R T H D imens ions . Dewar compared h i s u s e o f I T c w i t h DTC a s usqd f o r PDP-11 FORTRAN. H i s a n a l y s i s does n o t a p p l y t o t h e i m p l e m e n t a t i o n o f F O R T H on t h e PDP-11.

The FORTH a n a l y s i s i n v o l v e s 3 t y p e s o f d e f i n i t i o n s - low l e v e l ( C O D E ) , h i g h t e v e l (COLON), and s t o r a g e ( v a r i a b l e , e t c ) . The l o w l e v e l d e f i n i t i o n s w i l l be e n c o u n t e r e d most f r e q u e n t l y b y f a r because o f t h e p y r a m i d a l n a t u r e o f F O R T H d e f i n i t i o n s . O n t h e o t h e r hand, s t o r a g e d e f i n i t i o n s w i l l be e n c o u n t e r e d f a r l e s s f r e q u e n t l y i n FORTH t h a n i n F O R T R A N because i n F O R T H t h e s t a c k i s used e x t e n s i v e l y w h i t e i n F O R T R A N n o s t a c k i s a v a i l a b l e . Also, when s t o r a g e l o c a t i o n s a r e used i n FORTH o p e r a t o r s a r e a v a i l a b l e w h i c h m i n i m i z e t h e number o f r e f e r e n c e s . Fo r example, i n FORTRAN

COUNT = COUNT + 1

i n v o l v e s 2 r e f e r e n c e s t o t h e v a r i a b l e COUNT, w h i l e i n FORTH

COUNT 1+!

i n v o l v e s o n l y 1 r e f e r e n c e . I t s h o u l d b e n o t e d t h a t i n LABFORTH, l+! 4s a p r i m i t i v e , but i t i s n o t i n some o t h e r v e r s i o n s o f F O R T H . A n o t h e r f a c t o r w h i c h r e d u c e s t h e r e f e r e n c e s t o s t o r a g e l o c a t i o n s i s t h a t i n FORTH l i t e r a l s a r e p l a c e d i n l i n e and h a n d l e d b y a r e f e r e n c e t o t h e LITERAL ( l o w l e v e l ) r o u t i n e .

The OTC and I T C r o u t i n e s f o r t h e 3 t y p e s o f d e f i n i t i o n s a r e shown below, t h e y a r e condensed t o show o n l y t h e r e l a t i v e PDP-11/40 ove rhead . The r e g i s t e r n o t a t i o n i n t h e r o u t i n e s i s as f o l l o w s :

Q i s t h e cue r e g i s t e r ( R 5 ) w h i c h p o i n t s t o t h e n e x t a d d r e s s . I t i s c a l l e d I C ( i n s t r u c t i o n c o u n t e r ) i n some l i t e r a t u r e .

S is t h e s t a c k p o i n t e r (R1).

R i s t h e r e t u r n s t a c k p o i n t e r ( R 6 ) .

P i s t h e p r o g r a m c o u n t e r (R7).

R O i s a t e m p o r a r y r e g i s t e r assumed t o b e a v a i l a b l e . 0 - >

PAGE 2 5

FORTH INTEREST GROUP . * * * * PO. BOX 1105 * * * * . San Carlos, Ca. 94070

Page 4: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

DTC AND I T C R O U T I N E S

NARE

L I N K 8

J S R a,a(P)+

AODRESSE S

LOW L E V E L D E F I N I T I O N ( CODE 1

= N E S T

OVE R H E A 0 2 WORDS 8.0 USEC

H 1 6 M L E V E L D E F I N I T I O N ( C O L O N )

NAME 8

L I N K CODE ADDR

ADDRESSES

ADR UNNEST:\

STORAGE DEf X N I ?IOU 4 Y A R A I 8 C f 1

, N E S T : 4'MOV Q,-(R)

MOV RO,Q MOV 2 ) + , R O JMP a(Ro)+ OVERHEAD 2 WORDS 14.0 U S f C

DfC

m L I N K

R A C H I N E OVERHEAD 1 WORD 2.3 USEC

, = N E X T

OVERHEAD 2 UORDS 5.7 USEC

NARE E

L I N K bCODE ADDR M A C H I N E CODE

M O V ( ~ ) + , R o JMP a ( R O ) +

OVERHEAD 3 WORDS 4.6 USEC

= N E X T

OVE: R H E A 0 1 WORD 4.6 USEC

Page 5: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

The d i s t i n c t i o n be tween DTC and I T C as a p p l i e d t o F O R T H i s t h a t i n D T C e x e c u t a b l e mach ine code i s e x p e c t e d a s t h e f i r s t word a f t e r t h e d e f i n i t i o n name; u h i l e , i n I T C t h e a d d r e s s o f t h e mach ine code i s expec ted . Thus t h e D T C space advan tage i n t h e e n t r y t o a l ow l e v e l d e f i n i t i o n i s o b v i o u s . The mach ine code o f t h e low l e v e l d e f i n i t i o n t e r m i n a t e s w i t h t h e " N E X T " r o u t i n e . I n DTC N E X T i s a 1 word r o u t i n e w h i l e i n I T C t h e e x t r a l e v e l o f i n d i r e c t i o n r e s u l t s i n a 2 r o u t i n e (Note : a JMP NEXT wou ld a l s o t a k e 2 words ) .

r DTC V E R S U S I T C O V E R H E A D S U M M A R Y

PLC Kc Q T C A D V A N T A G E

I Low l e v e l 1 word 3 words 2 words ( CODE 1 2.3 usec 4.6 usec 2.3 usec

I n t h e h i g h l e v e l d e f i n i t i o n t h e mach ine code o f t h e " N E S T " r o u t i n e i s s t o r e d i n l i n e f o r DTC, b u t s i n c e i t i s o n l y 1 w o r d , i t t a k e s no more room t h a n t h e p o i n t e r t o t h e " N E S T " r o u t i n e . However, t h e 1 i n s t r u c t i o n f o r DTC t a k e s c o n s i d e r a b l y l e s s t i m e t o e x e c u t e t h a n t h e 4 i n s t r u c t i o n s f o r I T C (Note : r e p l a c i n g t h e l a s t 2 i n s t r u c t i o n s w i t h JMP N E X T wou ld t a k e even more t i m e ) . The r e m a i n i n g words i n t h e h i g h l e v e l d e f i n i t i o n a r e a d d r e s s e s i n b o t h cases. The l a s t a d d r e s s p o i n t s t o t h e UNNEST r o u t i n e w h i c h a g a i n i s more complex f o r Z T C because o f t h e a d d i t i o n a l i n d i r e c t i o n .

S t o r age 2 words 1 word -1 word (VARIABLE) 5.7 usec 4.6 usec -1.1 usec

High l e v e l 2 words (COLON) 8.0 usec

2 u o r d s 0 words 14.0 usec 6.0 usec

The summary t a b l e shows t h a t DTC has t h e o v e r h e a d a d v a n t a g e i n bo th l o w l e v e l and h i g h l e v e l d e f i n i t i o n s ; w h i l e I T C has t h e a d v a n t a g e i n s t o r a g e d e f i n i t i o n s . C o n s i d e r i n g t h e h i g h o c c u r r e n c e o f l o w l e v e l d e f i n i t i o n s and t h e l o w usage o f s t o r a g e d e f i n i t i o n s , one c a n see t h a t a FORTH i m p l e m e n t a t i o n w i t h D T C has I s i g n i f i c a n t speed and space

- - > P A G E 2 7

FORTH tNTEREST GROUP . * * * * RO. BOX 1105 * * * * * San Carlos, Ca. 94070

Page 6: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

advan tage o v e r one u s i n g I T C . To make t h e a d v a n t a g e more c o n c r e t e w e i g h t s s h o u l d be a s s i g n e d t o t h e v a r i o u s d e f i n i t i o n t y p e s . I f we have a p rogram c o n t a i n i n g 500 d e f i n i t i o n s ( i n c l u d i n g t h e s t a n d a r d FORTH d e f i n i t i o n s ) , we m i g h t e x p e c t 200 low l e v e l . . 250 h i g h l e v e l , and 50 s t o r a g e d e f i n i t i o n s . U s i n g t h e s e numbers t h e s i z e a d v a n t a g e o f l o w l e v e l , h i g h l e v e l , and s t o r a g e s h o u l d be w e i g h t e d -4, - 5 , and .l r e s p e c t i v e l y . D u r i n g t h e e x e c u t i o n o f a program, ue m i g h t e x p e c t t h e f r e q u e n c y of o c c u r r e n c e o f low l e v e l , h i g h l e v e l , and s t o r a g e t o b e 60%, 20%, a n d 20X r e s p e c t i v e l y . The r e s u l t o f a p p l y i n g t h e s e w e i g h t s i s shown i n t h e f o l l o w i n g t a b l e .

1

a 1

Low l e v e l 2 x - 4 = - 8 words 2.3 x .6 = 1.38 usec

H i g h l e v e l 0 x . 5 = 0 words 6.0 x - 2 = 1.2 usec

W E I G H T E D A D V A N T A G E OF DTC O V E R I T C

S t o r a g e -1 x .1 = 0.1 words -1.1 x . Z = 0 . 2 2 usec

Weigh ted advan tage .7 words 2.4 u s t c J

S I Z E A D V A N T A G E I SPEED A D V A N T A G E

Thus u s i n g t h e w e i g h t e d advan tage f o r DTC we wou ld e x p e c t t o save - 7 w o r d s i n each o f t h e 500 d e f i n i t i o n s w h i c h i s a t o t a l o f 350 words. A l s o each t i m e a d e f i n i t i o n i s e x e c u t e d t h e ove rhead wou ld be 2.4 u s c c l e s s . T h i s may r e p r e s e n t a s a v i n g s o f 20 o r 30% o f t h e t o t a l e x e c u t i o n t i m e o f t h e f r e q u e n t l y used s h o r t d e f i n i t i o n s .

The r e m a i n i n g advan tage t h a t i s c l a i m e d f o r I T C i s one o f mach ine i ndepeodance because no mach ine code appears i n t h e code g e n e r a t e d by t h e c o m p i l e r . B u t even t h i s a d v a n t a g e i s i l l u s i o n a r y s i n c e fORTH p r o g r a m s a r e t r a n s p o r t e d i n s o u r c e form. I n f a c t o n most sys tems t h e y a r e c o m p i l e d each t i n e t h e y a r e l o a d e d v i a t h e L O A D command. Thus, a f t e r a FORTH sys tem i s h o s t e d on a g i v e n computer, t h e mach ine code t h a t i s g e n e r a t e d b y t h e c o m p i l e r i s s u i t a b l e f o r t h a t p a r t i c u l a r machine; t h i s i n c l u d e s t h e mach ine code g e n e r a t e d f o r t h e DTC r o u t i n e s . I f one d i d t r y t o i n t r o d u c e t h e c o n c e p t o f FORTH p o r t a b i l i t y a t t h e o b j e c t code l e v e l b y r e s t r i c t i n g t h e ~ r o g r a m s t o h i g h l e v e l d e f i n i t i o n s and p l a c i n g a l l mach ine code i n a r u n - t i m e Package, he wou ld s t i l l p r o b a b l y have mach ine dependenc ies i n b y t e v t r s u s word addresses , f l o a t i n g p o i n t f o rma t , and c h a r a c t e r S t r i n g r e p r e s e n t a t i o n . In any case, c u r r e n t FORTH C n p l e n t n t a t i o n s do not c l a i m t r a n s p o r t a b i l i t y a t t h e o b j e c t code l e v e l . - -*

PAGE 28

FORTH INTEREST GROUP PO. Box 1105 = * * * * San Carlos, Ca. 94070

s i c a ba Ha d i e l

i ! Pi

Page 7: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

The s i t ua t i o n c o n s i d e r e b o t h spe However, d i f f e r e n t e f f o r t a 1

y s i s o f DTC v e r s u s I T C h a e s e n t e d b y F O R T H o n t h e tse o f DTC p r o v i d e s s i g n i f and s i z t , Thus LABFOR t i s r e h o s t e d o n a n o t h e r The change w o u l d b e h u i t h a l l t h e o t h e r c h a n g e

FORTH I n t e r e s t Group 7 8 1 Old C o u n t r y Road San C a r l o s , C A 94070

s shown PDP-11

i c a n t TH was

colnput a n d 1 ed s w h i c h

t h a t when t h e s p e c i a l a s o p p o s e d t o F O R T R A N i s

a d v a n t a g e s o v e r I T C i n i m p l e m e n t e d u s i n g D T C .

e r , t h e c h o i c e may b e a s p a r t o f t h e r e h o s t i n g w o u l d b e r e q u i r e d .

;S DJS

LABORATORY SOFTWARE SYSTEMS, INC. 3634 MANOEVIUE CANYON ROAD LOS ANGELES. CALIF. 90049 121 3) 472-6995

Dear F i g g y ,

F O R T H D i m e n s i o n s i s j u s t t h e s o r t o f c o m m u n i c a t i o n s v e h i c l e w h i c h i s n e e d e d b y the FORTH c o m m u n i t y f o r b o t h u s e r s a n d v e n d o r s . My p a y m e n t f o r a s u b s c r i p t i o n i s e n c l o s e d .

A S O r . R.F, H a r p e r i n d i c a t e d i n a n e a r l i e r l e t t e r , we a t L a b o r a t o r y S o f t w a r e Sys tems h a v e d e v e l o p e d a v e r s i o n o f F O R T H o n t h e PDP-11 c a l l e d LABFORTH. As t h e name i m p l i e s , LABFORTH c o n t a i n s f e a t u r e s w h i c h make i t p a r t i c u l a r l y s u i t a b l e f o r t h e s c i e n t i f i c l a b o r a t o r y e n v i r o n m e n t . T h i s e n v i r o n m e n t i n c l u d e s h i g h s p e e d d a t a c o l l e c t i o n a n d a n a l y s i s ; t h u s p a r t i c u l a r a t t e n t i o n i s g i v e n t o m a k i n g LABFORTH f a s t . F o r t h i s r e a s o n t h e d i r e c t v e r s u s i n d i r e c t t h r e a d e d c o d e d i s c u s s i o n i n t h e T h r e a d Code a r t i c l e i n t h e A u g u s t f S e p t e m b e r 1978 i s s u e o f FORTH D i m e n s i o n s was o f p a r t i c u l a r i n t e r e s t . Our a n a l y s i s o f DTC v e r s u s I T C was a n i m p o r t a n t a s p e c t o f t h e e f f o r t t o d e s i g n LABFORTH f o r maximum speed. DTC p r o v e d t o b e f a s t e r t h a n I T C a n d a s a b o n u s r e q u i r e d l e s s space . An a r t i c l e o n t h i s a n a l y s i s i s e n c l o s e d f o r y o u r p a p e r . I t c o n t r a d i c t s D e w a r ' s a n a l y s i s o f D T C v e r s u s I T C f o r DEC's FORTRAN, bu t h i s a n a l y s i s c a n n o t r e a l l y b e a p p l i e d t o FORTH. I f DEC h a d u s e d DTC i n a more e l e g a n t manner, D T C may a l s o h a v e f a r e d b e t t e r i n t h e F O R T R A N case.

H o p e f u l l y t h e DTC a d v a n t a g e s w i l l p e r s u a d e y o u t o d e l e t e t h e r e q u i r e m e n t t h a t FORTH b e i m p l e m e n t e d w i t h I T C . The p r o g r a m m i n g t e c h n i q u e s u s e d i n i m p l e m e n t i n g FORTH o u g h t t o b e l e f t t o t h e d e s i g n e r a n d h i s r e s u l t s s h o u l d t o b e e v a l u a t e d b y b e n c h m a r k s .

I l o o k f o r w a r d t o y o u r n e x t i s s u e o f FORTH D i m e n s i o n s .

D a v s S i r a g

L a b o r a t o r ? S o f t w a r e Systems, I n c .

PACE 2 9

FORM INTEREST GROUP * * . = * RO. BOX 1105 * * a * - San Carlos, Ca. 94070

Page 8: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

An alternative style 0 D-charts will be descri purpose of flowcharting well as the shortcomi flowcharting.

D-CHARTS

u i r Harris

' f flowcharts called .bed. But first the will be discussed as ngs of traditional

A flowchart should be a tool for the design and analysis of sequential procedures which make the control flow of a procedure clear. With FORTH and other modern languages, flowcharts should be optimized for the top-down design of structured programs and should help the understanding and debugging of existing ones. An analogy may be made with a road map. This graphic representa- tion of data makes it easy to choose an opt imum route to some destination, but when driving, a sequential list of .instructions is easier to use (e.g., turn right on 3rd street, left on Ave. F , go 3 blocks, etc.). Indentat ion of source statements to show control structures is helpful and is recom- mended, but a two dimensional graphic display of those control structures can be superior. A good flowchart notation should be easy to learn, convenient to use (e.g., good legibility with free-hand drawn charts) , compact (minimizing off-page lines), adaptable to specialized notations, language, and personal style, and modifiable with minimum redrawing of unchanged sec- t ions.

Traditional flowcharting using ANSI standard symbols has been so unsuccessful at meeting these goals that "flowchart' has become a dirty word. This style is not Structured, is at a lower level than any higher level language (e.g., no loop symbol), requires the use'of symbol templates for legibility, and forces program statements to be crammed inside these symbols like captions in a cartoon.

The only mlinesm in Drcharts are u8ed to show nonsequential Control paths (e.g., conditional branches, loops). In a proper D-chart, no lines go up: a11 lines either go down OK sideways. Any need for l i n e 8 directed up can be (and should be) met with the loop symbols. This simplifies the reading of a D-chart since it always starts at the top of a page and ends at the bottom.

It is customary to underline the entry naae (or FORTH definition name) at the top of a D-chart.

2-WAY BRANCH SYMBOL

In PORTR, this structure takes the form;

condition IF true phrase ELSE false phralle THEN .

Another FORTH structure which is used for conditional compilation has more mnemonic names :

condition IFTRUE true phrase OTREFWISE false phrase ENDIF .

The D-chart symbol has parts for each of these elements:

false phrase ttUC phrase

D-charts have a simplicity and power similar I to FORTH. They are the invention of Prof. words following BNDIP (or THBN) Edsger W . Dijkstra, a champion of top-down design, structured programming, and clear, ConC1s.e notat ion. They form a context-free language. D-charts are denser than ANSI " t m e phrase" l r executed; o t h e n i r e , tho "falme flowcharts usually allowing twice as much phrase" i~ executed. The words follouing ElP)IF program to be displayed per page. There are only two symbols in the basic languager however, like FORTH, extensions may be added

The "condition" i m evelwted, If it l m trua, the

(or TXEN) are unconditionally executed.

€or convenience. If either phrase Is omitted, am with

Sequential statements are written in free form, one below the other, and without condition IF true phrase TilltN boxes.

s t is t enen t a vertical line is drawn as shown: next statement I next statement condition A 1 true phrase

- - w

PACE 30

FORTH INTEREST GROUP * . . ** PO. Box 1105 * * * * * San Carlos, Ca. 94070

Page 9: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

:0

, t ?r 30

th re t s 1.

w

!I

a

I:

>r LC

>f

h

I :

LOOP SYMBOL

T h e basic loop defining syrbol for D-charts is properly structured.

cond i t ion

1

The switch symbol: +- indicates that when the switch is encountered, the .“condition“ (on the aide line) is evaluated.

1. If the “condition. is true, then the side line path is takenr i f false, then the down line is taken (and the loop is terminated).

2. If the side line is taken, all statements down to the dot are executed. The dot is the loop end symbol and indicates that control is returned to the switch.

3. The “condition” is again evalua- ted. Its outcome might have changed during the execution of the loop atatement.

Repeat these steps starting with Step 1.

This symbol tests the loop conditlon before executing the loop body. However, other loops test the condition at the end of the loop body (e.g., DO .. LOOP and BEGIN .. END) or in the middle of the loop body. This loop symbol nay be extended for these other cases by adding a test within the loop body. Consider the FORTH loop structure

BEGIN loop body condition END . The loop body is always executed oncer and is repeated as long as condition is false. T h e D-chart symbol for t h i s structure would be:

condition F

A more general case is

BEGIN first phrase

AGAIN condition IF second phrase

which is explained better graphically than verbally: +- first phrase

condition b second phrase I

Both previous symbols may be properly nested indefinitely. The following example shows how these symbols may be combined. This is the FORTH interpreter from the P.I.C. model.

I INTERPRET BEGIN ( ’ ) I F HERE NUMBER ELSE EXECUTE THEN

7 STACK AGAIN ;

INTERPRET - until null word executed

I search dictionary far next word

found A convert word to integer

push Integer

execute word I

c, check stack

d

PAGE 31

FORTH INTEREST GROUP * * * * * RO. BOX 1105 **.*. San Carlos, Ca. 94070

Page 10: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

n-WAY BRANCH SYMBOL

A s t r u c t u r e d n-way b r a n c h symbol (Some- times c a l l e d a CASE s t a t e m e n t ) may b e d e f i n e d f o r c o n v e n i e n c e . ( I t is f u n c - t i o n a l l y e q u i v a l e n t t o n n e s t e d 2 - v a y

b r a n c h e s ) . O n e s t y l e f o r t h i s s y m b o l 1s :

I

T h e c o n d i t i o n is u o u a l l y a n i n d e x w h i c h selects o n e Of t h e cases. The r e j o i n i n g o f c o n t r o l t o a s i n g l e l i n e a f t e r t h e cases a re r e q u i r e d b y s t r u c t u r e d program- m i n g . D e p e n d i n g o n t h e c o m p l e x i t y o f t h e c a s e s , t h i s s y m b o l m a y b e d r a w n d i f f e r e n t l y .

D - c h a r t s ace e f f i c i e n t a n d u s e f u l . T h e y a re v a s t l y s u p e r i o r t o t r a d i t i o n a l f l o v c h a r t s t y l e .

f i r s t case s e c o n d case .. l a s t case ;S KIM HARRIS

P.O. Box 8045 Austin, M 78712 Wwe&er 3, 1978

Editor , mrth D i m e n s i c n s :

Thank yw for your card ard s-nt letter. I an sorry that I d i d mt g e t back to yw momr w i t h a copy of t h e s o u r c e code f o r my FQRPH system. ~ t a n k l y , I w a s su rp r i sed that p are in t e re s t ed in the system, since it is r a t h e r limited i n f a c i l i t i e s am3 m f o m w i t h no other version i n term o f names. I Stopped work on the systern just abut the time I &gan to receive ~ n u a l s fona ~X~IS arrd the 6502 IWUH form FIG. I can see llow hou I wxld add an assembler, t e x t editor, ard rardan block i/o.to t h e sys t em, but my d u t i e s a t work and a t school precluje any f u r t h e r developlent of U.T. €?3RRI for

I want to e s p e c i a l l y t h a n k you f o r informing rn o f Paul Ba r tho ld i ' s v i s i t to the Universi ty of lkxas. I w a s able to meet w i t h him and we had a very s t i m u l a t i n g d i s c u s s i o n f o r a b o u t a n hour and a ha l f . I w a s su rp r i sed to l e a r n f m n him har widely FORTH is used cormnercial ly , though u s u a l l y unde r other nanes. W e also discussed tu, extensions to the l anguage t h a t I b e l i e v e g r e a t l y enhance it: ( 1 ) syntax checkirq on cmpilatim f o r pmper ly balancpd BDXN. .EM) and IF..FJSE..lW3 cons t ruc t s , and ( 2 ) the funct ions .n -" ard "PARI" to " P W that allow explicit r e fe rence to paranetera on the stack. F i n a l l y , h e showed m e sane progr-ing e x a n p l c s f r a n the Fwrm manual he wote which wide f i r s t - hand proof o f the ease o f prograuniq r a t h e r sophis- t i c a t e d p r o b l e m i n FORTH. I t is e s p e c i a l l y im- portant because moSt FPople i n the ccmplter science d e p a r t m n t here respond to my presen ta t ion o f w i t h a resnudirq lack of i n t e r e s t . Mter all , they keep abreast of the f i e l d and i f they have not heard o f it ....

IKW.

I have been promoting FORTH among t h e local mnprter clubs Md lodc forward to the results of FIG'S m i c r o ccnputer efforts. P l e c s e keep i n tarh.

S i m e e l y yours,

Greg Walker

PAC& 32

SE/l was written by - r i d €&search c;roup, Inc. to be e x a c t l y uhat it says it is, a S Y S I M languclge. SV1 is a mall i n t e r a c t i v e incranental capiler t h a t qenerates Mirect threaded code. It is a 16 bi t ps;eudo arachine f o r use on mini a d micro carputers. New d e f i n i t i o n s can bc added to an alreafy r i d set of i n t r i n s i c instructions. It is t h i s e x t e n s i b i l i t y t h a t allows any user to create t h e most optinnnn vocebulary for h i s i r d i v i d d aeplicatim.

SW1 is a v i r t u a l s t a c k processor. Using t h e iQ)1 mnctpt f o r f o t h v a r i a b l e s a d instmctiars makes it pssible to ex te rd stepuiee p r o g r d q to include s t e p u i e debugging. SrJl does t h i s q u i t e nicely. W e RPN stack is also oclc o f the nrwt e f f e c t i v e means o f inplmmting tcp donr design, bo t t an up d i n g .

StJl oprates on a pinciple of t h r c a k d mde. All of the elements OF- SWl (procedures, var i ab le , ampaler d i r e c t i v e s , etc.) r e f e r e n a the previous e n t r y . Thus, e a c h code i n d i r e c t l y " t h r e a d s " t h e others ard is i n t u r n threaded by t h e d f o l l a r i r q it. * a m SW1 is a p;eudo machine, p o r t a b i l i t y between d i f f e r e n t pruceseors and hardware is r c a d i l y arrorplisbed. ?he low level i n t e r p r e t e r is r e a l l y the Fcnadrine. I t is slnall (only 1 1 byte6 are used) , & f a t .

On o f the mrrt poverful f ea tu res o f Syl is the fact t h a t is u s e s a l l o n - l i n e storage media as v i r t u a l memory. I n e f f e c t t h e user can write programs i n SW1 u s i n g t h e f u l l c a p a c i t y o f d i s k storage and n e v e r be concerned w i t h placement o f i n f o m t i o n on t h e disk. SW1 allows you to progran machine codc procedures i n assenbler uirq a high level language. This c a n optimize I/O OK math rwtines.

?hc abwe information w a s excerpted fran a press release of Nove&er 3, 1978. R>t f u r t h e r informa- t ion, c o n t a c t nr. Dick Jones, Dnperical Research C K O U ~ , Inc. , 28206 144th Avenue, S.E., Kent , WA 98031. P h a p (206) 631-4851.

FORTH INTEREST GROUP * * * * * PO. BOX 1105 * * * . * San Carlos, Ca. 94070

Page 11: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

Here are some f a c t s r e g a r d i n g F o r t h object size mcj exeuct ion S- ver sus w-1~ coding.

mrm, ~m., sane programers (myse l f inclded), 0-m sane p r e t t y incredible state-

writs about F o r t h code r e s u l t i n g i n less memory wid ( 1 a d execution speeds as f a s t as h-1~ w r i t t e n COQ ( ! ! ) . 'R, he lp clear the air I ' l l try to exp la in those tuo outrageous c lam.

F i r s t , F o r t h code can r u n a s f a s t , bu t not f a s t e r , u s i n g a c o n s t r u c t i o n a l s t a t e m e n t called "Code" which is f o l l o w e d by a sort of mnemonic machine code s t r i n g and a jump back to t h e F o r t h inner inteqxeter. I t isn' t reasonable to just have one b i g aodc statement . for the %hole -ran. So t h i s g e t s us i n t o a n o t h e r F o r t h c o n s t r u c t i o n a l statentent called a "colon d e f i n i t i m ' .

Colon s t a t e m e n t s cost speed b u t s a v e progrii~~~ m r y ~ y c r kssenbly. Colon s ta tements c o n s t i t u t e the 'high level" aspect o f b r t h bu t let's get badc to the point.

An exanple "code" statement i n m c t h to hendle the character input f m n a Cm to an I n t e l SeC 80/20 mrould be:

OODEKEY B D C I N E D X N P R R C I 1 W 3 C S W EC IbP A L H PNI IiPpusH JM€'

WE: F o r t h code s t a t e m e n t s allow beqin-end and i f - e l s e - t h e n c o n s t r u c t s w i t h i n t h e assembly. A l s o F o r t h r e q u i r e s sou rce - destinati-rand o lgan iza t ion o f each assenbly statement (A L Mov instead of MDV

This exac t sdme routine in k-1~ lm- guage would be:

L A ) *

;place i n next avail

;input status ;rotate r e o e i v e r ready ; i n t o carry b i t

; i n p t CRP data ;push data on ; s t ack in 16-bi t :format

By e n t e r i n g ' KEY BD DUMP o n t h e F o r t h system you'll get the object code d i sp layed as:

4W0 DB 0P BP D2 08 4% CB Ec 6P 26 ~0 a 41 m

This is e x a c t l y what t h e AeE+mbly code would pmduce if OSG'ed a t 4flj7H ard the label HptGH = a t 41H.

Ikr icwing the exarple mrth code statemnt: 'BEGIN" v.uduced no cbject but s i n p l y acted aa a label f o r "END. provided the JM: address f o r EH). *CS* s i n p l y pmvided the JMP typ for m, i n this case JNC. "cs Nop ns" d d have aDnplamtad the jurQ type md produced JC.

Ihc abve e x m p l e s vhile rmt e s p e c i a l l y e x c i t i r q o n t h e s u r f a c e are q u i t e i n t e r e s t i n g when y o u ' r e a c t u a l l y wr i t i nq these p rogram on a system installed w i t h F o r t h and o n e t h a t i s n ' t . Using s t a n d a r d disk-based Assmbler system y w ' d prcbably have to open an edit f i l e , write t h e p m q r a , close t n e edit f i l e , call t h e assembler, and load t h e oblect f i l e so you could use t h e d e b q program to execute. mybe 10-30 m i n u t e s depend ing o n t h e p r o b l e m you have a l o n g t h e way. I n F o r t h , you 'd e n t e r t h e code s t a t e m e n t on t h e command l i n e , carriage r e t u r n , ty "KEY", (a), and it 's executing. 30 secOndS maxlmm! I f you l i k e d t h e way "KEY" executed you'd save i t o f f o n t h e d i s k u s i n g t h e F o r t h E d i t o r . (Another 20 seaxds. )

The colon s t a t e m n t in b r t h was said to save man i n m r y over Assembly, and provide t h e hign l e v e l l a n g u q e a b i l i t y . An exanple code statement t h a t would read the CRT keyboard cam& messages and t hen execute the des i r ed a c t i o n could lodc l i k e :

: KL'YBQRW) 64 fl Do KEY 7F AM) Dup 0D = IF LFAVE THEN Loup MECVIF ;

Keyboard is t h e l a b e l of t h i s r o u t i n e . Every other word (Do, KEY, AND, =, LEAVE, THEN, LL)cB, and EXECVIE) r equ i r e s tm by tes of m r y . p-bit nunbers r equ i r e 3 bytes, 1 f o r the nunber am1 2 for a routine that d i f f e r e n t i a t e s nunbers Era hods and provides t h e s e numbers o n t h e s t a c k for u s e by s u c c e e d i n g operations, e.g., 64 and B for 'Do'.

"te m r y saving can be v i sua l i zed by thinking of the routine "keyba rd" as a r o u t i r e t h a t looks like:

;a pmJran ;a p r o g r m ;to stact a 64 locp :to i n p i t d a t a ;# for ANi) ;to AND i t ; to WP d a t a ; f o r (CR) test : f o r (CR) test ; i f (CR) l eave loq, ; to canplete IF ;to loop 64 times :to Do ComMnd ;to UO next one

b o k i q a t it t h i s way, each CALL twes a byte. F o u r t e e n b y t e s c o u l d b e s a v e d i f t h e CALL OPCODE could be eliminated. Ihe r e s u l t m u l d be the tw by te address' of everything to CALL. The innemst €m-th i n t e r p r e t e r u ses these address ' i n serruence and is about 12 by te s of merory code and has ;he label 'NEXT'.

Thus, f o r j u s t t h i s s i n g l e example, 14 b y t e s WLP saved, a t t h e cost o f 12 by te s f o r "NMl". But cwry colon ad code Statement used "NEXT" so the mmry savings b u i l d because "NEXT" is executed so many times. me j u s t i f i c a t i o n i n using subroutine calls i n Assenbly mde ve r sus i n l i n e ccde is based o n how many times it is called. "kE)(T" is c a n p l e t e l y j u s t i f i e d because it is called an e m m s n u n k r o f times. Forth, Inc., has stated .NEXT" would be a n

- - w

P A G E 3 3

FORTH INTEREST GROUP * * * * * PO. BOX 1105 * * * * * San Carlos, Ca. 94070

Page 12: OCTOBBR/IOVEMbER VOLUME 1, CONTENTS HISTORICAL …

excellent mic- to be inclujed in a 80 set and I 'd have to agree. Befoe a "NEXT" vould be implemented l n W S processor - l ike 8085, 6800, or the l ike , Ftxth is going to have t0 beoanc q u i t e dear to t h e i n d u s t r y . So I d o n ' t see i t happening except i n some 2900 bit-rlict iwle- m n t a t ions.

All t h i s concern abwt microToding 'NEXT h a its mot. "m" is executed between each wxd ln a colon statement bebeen each w x d of a uxd t h a t i t s e l f i s the rime of a colon statement. mem€orer "NDCT" slcvs thirqs d w n during e x a t i o n , krt k rcdeemirq since it saves space arrd all- the high level nature of h r t h .

?t, keep thirqs w i n g quickly in the execution of m r t h pmgrans, colon statements should ccntain a feu mrds defining the action of t h e defined colon s ta tement and each word should be v e r y c l o s e l y connected to a code s ta tement as p o s s i b l e ( s i n c e code statements run a t full machine speed). A l s o , each word in a colon statement should be povFrful, if the mrd is the label o f a cok statement, th ia could mean large code statanents .

large code s ta tanents can quickly ge t ou t of hand wi th more t h a n two l i n e s ( l ine i n t h e example of =my-), b e c a w of the lesser a b i l i t y t~ cQnaent e& acax as in Assetbly. So Ftxth, Inc., has stated & staterronts should be kept short am3 meet. It's r e a l l y up to the user to trqde o f f r e a h b i l i t y for

IIhe nanirq of colon and c d e etaterPnt labels CM mally improve m a d a b i l i t y i f p put gl~e t-ht i n t o the naning.

& was sa id earlier, the Forth pmqrsn statement can be executed by enter inq it on t h e connand l ine, then typing the name for execut im. Colon statements a r e included i n t h i s a b i l i t y and ext remely f a s t d i r q ad debugging is t h e result.

I r e a l l y object to paying $2,500 for any Softsate , but B r t h is mrth it. (Ihey'd probably sell mce i f it w s n ' t so expemive.) Besides the p r i c e thero EWXYM to be a feu other mpediments to Fbrth gaining a m o ~ rapld p w a r i t y growth. ( 1 ) I t &es take

g e t t i r q used to. ( 2 ) There's not m ~ y m r t h 6ystsPs and progrmmers amwd. (3 ) Pecple, i n my j w t , are tob quick to & e m it.

speed-

'lb r e a l l y ge t f a s t d i sk copies on your )05800 (RI I n t e l Corp.) m r t h systme, add t h i a progrm to your disking load:

0 1 2 3 4 5 6 7 0 9

10 1 1 12 13 1 4 15

( H I G H SPEED DISK COPY ~ ~ ~ - 7 a i o o i 16384 CONSTANT SCRATCH

2 0 0 0 CONSTANT B I A S 26 CONSTANT TRACK

4 CONSTANT READ 6 CONSTANT WRITE

26 CONSTANT ALL

DO SCRATCH I TRACK ' READ ALL 1/0 I . SCRATCH I TRACK B I A S + WRITE ALL 1/0 STATUS I F [ ERROR] LEAVE THEN

LOOP FLUSH CR [ COPY J 7 ECHO ;S DUPLICATE TAKES 80 SECONDS 10 FORnAT AND COPY ENTIRE NEW DISK.

: DUPLICATE FnT 7 7 o

lbe main reason t h i s progrim will take anly 80 seomds to make a is whole tracka are read fmn t h e master d i s k i n d r i v e g and whole t r a c k s are written to tk mpy i n dr ive 1. But, alas, p ' l l need 3328 b y t e s of cont inuous RAM to run t h i s

progran. Iha amstant nancd EX3WKH provides the f i r s t address o€ the 3328 RAn bytes needed.

cwLIu\TE lhen exewted calls t?m to €omat the disk i n d r i v e 1 . "77 &I W- P e t s up a D L O O P to mpy all 77 tracks. I/O requires m T C H (locatiar) I ( t h e t r a c k and index of t h e loop) TRACK ( t o canpute block # f o r I/O) REM (fmn, drive B) and ALL (for # of sectors). VO w i l l perform the disk operatian. -1- p r i n t s the current t rack birq mpied to e n t e r t a i n t h e aperator. Next, Sa?Am q a i n gives t he s c r a t c h area for I /O and I TRACK BIAS + provides the equivalent block nunbcr i n d r i v e 1 for vo.

WRI"T3 ALL instructs I/O to write a l l 26 sectors fmn scratch area. I/O perfora the disk operation. bTMzLs pops t h e d isk StatU8 byte fmn locat ian 20H and i f ntn-zero p r i n t s ERFOR a d leaves t h e loop. ~lse the loop repeats Md MLSH is executed f o r the hedc-f-it. Cow is printed Md BELL is echo'ed to Qzp to signal capletion.