Home
6 - Forth
Contents
1. POP BX POP AX ADD BX AX PUSH BX NEXT D R M JMP nest DEC BP DEC BP MOV BP SI ADD AX 3 MOV SI AX NEXT see D R M LODSW JMP AX See D R M ADD AX 3 PUSH BX XCHG AX BX NEXT LODSW PUSH BX XCHG AX BX NEXT ES MOV BX BX NEXT ES POP BX POP BX NEXT POP AX ADD BX AX NEXT Forth Dimensions 11 March 1992 April Observations Ignoring the various anomalies the spread in perfor mance among the Forths for most benchmarks is about a factor of two about a factor of 1 5 among the test set versions This seems a small gain considering both the efforts that have gone into the various implementations and the resulting lack of internal consistency from one imple mentation to the next It was however easier to handle these inconsistencies when writing the various versions of the benchmarks than to handle the inconsistencies among different assemblers supplied with the various Forths Specifics The data for the D R M D S M I R M and I S M versions yields the following ratios Indirect Direct 1 7 1 ratio of times for Thread Indirect Direct 1 3 1 ratio of times for Nest1 or Nest2 Indirect Direct 1 3 1 ratio of times for Prims or Sieve Stack Reg Dir 1 2 1 ratio of times for Prims or Sieve Stack Reg Ind 1 1 1 ratio of times for Prims or Sieve I S M D R M 1 5 1 ratio of times for Prims or Sieve D R S D R M 1 1 1 ratio of times for Prims or Sieve
2. There will be no further discussion of the ANS Forth effort in this column in this issue because by the time you read this the Technical Committee will have met in mid February to vote There may not be that much to discuss or vote on because as late as mid January the committee had received zero that s correct zilch com ment If you had specific comments or objections and failed to submit them you have only yourself to blame The opportunity was cer tainly there I doubt if any standards effort has ever been SO open to scrutiny So are there any other hot buttons You bet Lots of them Object oriented pro gramming and embedded systems still enjoy lively ex changes but maybe one of the hottest topics on GEnie and ForthNet is minimal Forth March 1992 April kernels that also perform Witness the topic opened by fellow sysop Elliott Chapin on January 1 1992 This ex cerpt taken on January 17 only runs for 2 1 2 weeks and I already know of atleast two outstanding replies If you aren t participating in the guest conferences and in these discussions you are missing out on a lot of the fun associated with being a Forther Consider joining us soon Topic 26 Minimal Forth How small can a working Forth be Why try The minimal Forth ques tion has started up again small wordsets are more than an intellectual exercise Some processors are very small Small kernels ease porting From Ralf E St
3. drop I true WHEN COMPLETED drop false LOOP addr true Searcb in reverse order logoBackSearch logo false addr true LOGOS LOGOS CELL BACK LOOP dup I WHEN drop I true WHEN COMPLETED drop false LOOP Code figures and article continue in next issue THIRTY DAY FREE OFFER Free MMSFORTH GAMES DISK worth 39 95 with purchase of MMSFORTH System CRYPTOQUOTE HELPER OTHELLO BREAK FORTH and others March 1992 April A FORML Thanksgiving Richard Molen Huntington Beach CA On November 25 1991 just over forty dedicated Forthers flocked to Asilomar on California s Monterey peninsula to participate in the FORML conference Some went to exchange ideas some went to exchange ad dresses all went to exchange experiences and to increase the collective knowledge base of the Forth community This year there was some thing for just about everyone As we arrived at Asilomar the air was cool and clear with a strong breeze As we rushed in late to register and pick up our name badges and notebooks we were in the trees and a seascape full oflife In these surroundings it was asy to relax and concentrate on the confer ence itself As soon as we were registered the lunch bell rang and we went to the cafeteria to eat I was im pressed by the simple el egance of the cafeteria It wasn t until after
4. flag WHEN XXXX XXXX flag WHILE XXXX Y true true ea flag AGAIN XXXX always XXXX flag ved EE XXXX always Y 1 In brief if xxxx is any XXXX flag WHILE WHILE XXXX control structure tr XXXX WHEN someCode WHEN xxxx is equivalent to XXXX WHEN xxxx xxxx IF someCode LEAVE THEN e and similarly XXXX WHILE someCode WHILE xxxx is equivalent to xxxx O IF someCode LEAVE THEN A By using a WHEN pair we not only can test a condition to decide if the control structure must be left we can also place between WHEN and WHEN the code that must be executed just before leaving the control structure This way any leave test point can be equipped with its own specific pre exit code Using WHEN is thus the equivalent of writing WHEN and WHEN with no code between them To illustrate figuratively let s say that xxxx WHEN someThing WHEN xxxx may be informally written as Forth Dimensions 23 Lesern A Other pairs of words that we can use inside an indexed control structure are OF value OF s WITHIN lower upper WITHIN IN xl x2 xN N IN 7 3 These pairs make explicit reference to the index and are mainly used in the internals of a CASE structure though it may beused in any indexed control structure Look at Figure One b fo
5. t kid yourself you are not just another drop in the bucket your personal decision really does matter In return we ll provide you with the best tools money can buy The only limit with Forth is your own imagination You can t add extensibility to fossilized compilers You are at the mercy of that language s vendor You can easily add features from other languages to HS FORTH And using our automatic optimizer or learning a very little bit of assembly language makes your addition zip along as well as in the parent language Speaking of assembly language learning it in a supportive Forth environment turns the learning curve into a light speed escalator People who failed previous attempts to use assembly language conquer it in a few hours or days using HS FORTH WINTER SALE HS FORTH runs under MSDOS or PCDOS or from ROM Each level includes all features of lower ones Level upgrades 25 plus price difference between levels Source code is in ordinary ASCII text files HS FORTH supports megabyte and larger programs amp data and runs as fast as 64k limited Forths even without automatic optimization which accelerates to near assembler language speed Optimizer assembler and tools can load transiently Resize segments redefine words eliminate headers without recompiling Compile 79 and 83 Standard plus F83 programs PERSONAL LEVEL 299 NEW Fast direct to video memory text amp scaled clipped
6. Constant _ Variable not implemented NOP CALL NEST UM DROP doVAR doVar R gt March 1992 April Lists data 1 meg BBL V1 10 25 86 Green publici Written by Roedy Green to use as the tool for rewrit ing Abundance a vast data base program and applica tion Source code for BBL is in assembler A direct threaded 32 bit implementation with the top of stack in a register A mul tiple segment model which interprets from screen files Notes compiled tokens are offsets into the code seg ment 1 Not for military use eForth V1 0 7 27 90 Muench et al public eForth has been proposed as the successor to fig FORTH for porting to current micro processors is available in several implementations and is tailored toward transport ability ROMmability and use in embedded controllers Source code is usually in assembler A direct threaded 16 bit implementation with the top of stack on the stack It has separated heads in a single common segment and usu ally interprets source code from a host serial link when used in embedded controllers Notes All variables are user variables UP is in memory FOR NEXT loop instead of DO LOOP CATCH and THROW are used in error recovery 14 Forth Dimensions F83 V2 4 0 3 24 87 Laxen amp Perry public Written by Henry Laxen and Mike Perry to provide a working model of an 83 Standard Forth Released with many enhancements over fig FOR
7. Forth Forth in the context of the intellectual threads of our time Jack J Woehr Seeing Forth by Jack Woehr I would like to share a few observations on Forth and computer science That is the purpose of this monograph Itis offered in the hope that it will broaden slightly the stream of Forth literature which creek has been running a mite shallow of late Failing that perhaps it will serve the function of a cup of warm tea to make the seeker of Forth literature feel warmer anda little more filled until something more nourishing comes along 25 00 Forth Interest Group P O Box 8231 San Jose CA 95155 Second Class Postage Paid at San Jose CA
8. INC BP NEXT Literal PUSH BX MOV BX SI INC SI INC SI NEXT POP AX ADD BX AX NEXT Stacks 64K riFORTH V1 1990 Iilyes copyrighted A minimalist Forth fast and efficient Full source code and metacompiler in about 15 screens Does some optimization Interesting A subroutine threaded 16 bit implementation with the top of stack in a register Asingle segment model which interprets from screen files riFORTH Copyright Robert F Illyes 1990 My thanks to Robert Illyes for publishing the source code for riFORTH The availability of a com plete subroutine threaded Forth in only 12 screens made it possible to done the five different versions used in this study Upper Deck V2 0 1 26 91 Upper Deck Systems commercial An inexpensive power ful commercial version of Forth which uses multiple DOS segments It includes a very nice resident text edi tor A direct threaded 16 bit implementation with the top of stack in a register A mul tiple segment model which interprets from text files Notes When case sensitive all supplied words are lower case 1 The above information is presented with the gen erous permission of Peter Graves of Upper Deck Systems Forth Dimensions Forth Dimensions XCHG AX BX MOV BX CS BX NEXT 21 UR FORTH nts max siz h V1 1 3 11 90 LMI Code 64K Lists Data 64K Heads 64K Stacks 64K 2 commercial Register use UR FORTH is
9. fied the definitions of words which use them i e V and LOAD By using block buffers he eliminated the need for extra text file line buffers further simplify ing the system His system also on GEnie issimpler and more capable than a BASIS 17 system would be On the educational front Dr Tm Henptiass of the Physics Department at the Swinbume Institute of Tech nology in Hawthom Aus tralia gave an excellent tes timonial to the power of Forth in education Tim described in detail the challenges of teaching interfacing hard ware to classes of 60 students with various unrelated back grounds and the dramatic change in their ability to learn interfacing when Forth was used His paper also contains the exercises used to teach these students to solve simple instrumentation problems using both interrupts and multitasking People learning to write interrupt service routines can really benefit from Tim s paper Software for this paper is available on GEnie AI buffs and elderly people should take note of Dr Hendtlass s paper on the developmentofa distributed intelligent system which he calls Embedded Node Col lectives Each node collects information uses an expert system and sometimes a neural network to digest this information and communi cates with the outside world insome fashion These nodes have been used in several systems The system he cites is one which helps elderly people care for
10. max siz h Code Lists Data Heads Stack 64K Text 64K Register use AX W SI IP cS BX DI RP DS CS CX BP ES DX SP SP SS CS Next Nest JMP NEST LODSW NEST ADD AX 3 JMP AX XCHG AX SI STOSW NEXT 1 POP BX POP BX PUSH BX POP AX NEXT MOV BX AX NEXT Constant Variable CALL CALL Segments max size each Code Lists Data Heads Stack Blocks 64K non DOS version i tZ 1 AX BX CX DX Next LODSW XCHG AX BX JMP BX E e POP BX PUSH BX NEXT Constant SI DI BP SS IP RP SP CS DS ES SS Nest DEC BP DEC BP MOV SI BP INC BX INC BX MOV SI BX NEXT POP BX POP BX NEXT Variable Note Non DOS version of MMSFORTH was used in Excalibur s SAVVY DOS version in Lindberg System s OMNITERM 2 and Ashton Tate s RAPIDFILE High level words source code provided 1 The above information is presented with the generous permission of A Richard Dick Miller of Miller Microcomputer Services Forth Dimensions 17 all CS CS CS codetliststdatatp stack CS 1000H txt buft r stack Unnest SUB DI 2 MOV SI ES DI NEXT Literal LODSW PUSH AX NEXT POP AX POP BX ADD AX BX PUSH AX NEXT Unnest MOV SI BP INC BP INC BP NEXT POP AX POP DX ADD AX DX PUSH AX NEXT March 1992 April Segments max size each Code Lists Data Heads Stack Blocks 64K Regi
11. specifying stant times step doesn t allow room for misunderstanding Specifying start end step raises some subtle points to consider Suppose the specified end is step aligned with the given start as in 10 start 20 end 2 step Do we mean that the loop must assume the end value or must it stop at end step If we want to have the relation between end start and sizeexpressed simply by size end start we must deduce that the end value has to be excluded Otherwise the relation between end start and size must be written as size end start step Suppose on the contrary that the specified endisn t step aligned with the given start asin 10 start 21 end2 step March 1992 April i NGS FORTH A FAST FORTH OPTIMIZED FOR THE IBM PERSONAL COMPUTER AND MS DOS COMPATIBLES STANDARD FEATURES INCLUDE 079 STANDARD eDIRECT I O ACCESS eFULL ACCESS TO MS DOS FILES AND FUNCTIONS eENVIRONMENT SAVE amp LOAD eMULTI SEGMENTED FOR LARGE APPLICATIONS eEXTENDED ADDRESSING eMEMORY ALLOCATION CONFIGURABLE ON LINE eAUTO LOAD SCREEN BOOT eLINE amp SCREEN EDITORS eDECOMPILER AND DEBUGGING AIDS 8088 ASSEMBLER eGRAPHICS amp SOUND eNGS ENHANCEMENTS eDETAILED MANUAL elNEXPENSIVE UPGRADES eNGS USER NEWSLETTER A COMPLETE FORTH DEVELOPMENT SYSTEM PRICES START AT 70 NEW HP 150 amp HP 110 VERSIONS AVAILABLE m D NEXT GENERATION SYSTEMS P O BOX 2987 BANT
12. tests WORD NUMBER and FIND etc 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP 99 DROP Note Loads is strongly influenced by the search method and in many Forths by the number of words in the dictionary Results Initial testing was done on a 20 MHz 386 however if the code or list addresses were moved from non word to The benchmarks arrived at word boundaries the times were significantly improved are specif ically aimed at This effect was noticed using PC Forth and only i
13. 4 March 1992 April 36 information services International GEnie Access vol 12 6 pg 26 GEnie for Beginners vol 12 5 pg 34 interfacing Forth to operating systems ForST A 68000 Native Code Forth Part 2 vol 12 3 pg 34 interpreters special purpose Forth amp the Three Number Problem vol 12 44 pg 20 interrupts Interrupt Driven Communications vol 12 45 pg 18 Forth Interrupt Handling vol 12 5 pg 10 local variables ForST A 68000 Native Code Forth Part 3 vol 12 4 pg 26 Stack Variables vol 12 41 pg 18 macros text interpreter Interpretation Macro Techniques vol 12 1 pg 11 meetings annual Forth Day 1990 vol 12 46 pg 30 metacompiling Metacompilation Made Easy vol 12 46 pg 31 Metacompile by Defining Twice vol 12 42 pg 31 microprocessors Forth Best of GEnie vol 12 5 pg 36 music ear training Ear Training vol 12 5 pg 24 number formatting operations Upscale Number Input vol 12 2 pg 8 number input Upscale Number Input vol 12 82 pg 8 object oriented programming Best of GEnie vol 12 1 pg 28 optimizing compilers ForST A 68000 Native Code Forth Part 4 vol 12 4 5 pg 28 ForST A 68000 Native Code Forth vol 12 2 pg 20 Extensible Optimizing Compiler vol 12 42 pg 14 printing of source code pretty printers Letter vol 12 43 pg 6 promoting Forth Best of GEnie vol 12 86 pg 24 Embedded Control Path to Forth Acceptance vol 12 1 pg 35 promoting the use of Forth worldw
14. ASCII a WITHIN The ASCII 2 J an upper case letter WITHIN ASCII z a lower case letter WITHIN word means simply i ASCII ASCII ASCII ASCII 5 5 specifies that and are 5 ASCII IN an arithmetic operator IN ASCII ASCII ASCII 3 IN an opening parenthesis IN ASCII ASCII ASCII 3 IN a closing parenthesis IN BL OF SPACE char OF 0 OF NULL char OF ASCII 0 ASCII 9 WITHIN a decimal digit WITHIN HEX 80 100 WITHIN a graphical character One of those cr with code between 128 included and 256 excluded WITHIN I 100 gt I0 OR WHEN outside the character range WHEN I 20 AND WHILE a control character WHILE X 20 not 11111B unclassified CASE CASE if reached leaves the control structure Note The two words and may be defined to count the elements of a set of numbers So instead of writing ASCII ASCII ASCII 3 we can write ASCII ASCII ASCII and this is much better See the provided code for their definitions Example Two Special use of the case structure which allows for subcases Pairs used inside the outermost WITHIN if entered leave the CASE structure and execution continues after CASE Gust like external pairs DISASSEMBLE CASE 0000 4000 WITHIN I MoveInst WITHIN inst 25 March 1992 April 4000 8000 WITHIN 5000 6
15. BP RP ES X3J14 basis document It PX SS SP SS has fully ROMmableassem Next Nest Unnest bler source code and an CALL NEST interface to one of the stan LODSW CS NEST DEC BP MOV SI BP dard programmers text edi JMP AX DEC BP INC BP tors MOV BP SI INC BP A direct threaded 16 bit POP SI NEXT implementation with the NEXT top of stack in a register A Literal multiple segment model MOV BX BX POP BX LODSW which interprets fromscreen NEXT POP BX PUSH BX or text files NEXT MOV BX AX NEXT Constant Variable s JMP doCON JMP doVAR POP AX ADD BX AX See variable doVAR PUSH BX NEXT ADD AX 3 March 1992 April Part ONE The Curly Control Structure Set Kourtis Giorgio Genoa Italy AUTHOR smiling Hi I ve got a new proposal on a new complete set of control structures READER annoyed Anotber proposal Do you know that this is the 134th Forth proposal on extensions expansions additions etc to control structures AUTHOR less smilingly Yes but mine READER smiling Oh yes Sure yours is better includes as subcases all previous proposals is original has support for errors is coherent etc AUTHOR happy Exactly READER serious You know that the same thing has been claimed by 59 other articles AUTHOR aggressive Yes I know I have read every article Many are very interesting and have been important for me I copied everything that could be copied I
16. BX DEC BP DEC BP MOV BP SI MOV SI BX JMP NEXT t POP BX POP BX JMP NEXT Variable INC BX INC BX PUSH BX JMP NEXT h SI DI BP SP IP RP SP Nest JMP NEST NEST XCHG SP BP PUSH ES PUSH SI XCHG SP BP MOV DI AX MOV AX DI 3 ADD AX seg MOV ES AX SUB SI SI NEXT POP BX POP BX NEXT Variable CALL doVAR doVAR POP BX MOV AX BX PUSH BX NEXT Heads 64K uU ow Ww d MOV SI BP INC BP INC BP JMP NEXT Literal LODSW JMP APUSH POP BX POP AX ADD AX BX JMP APUSH Lists 1 meg code datat blocks CS Lists CS Unnest XCHG SI BP POP SI POP ES XCHG SI BP NEXT Literal LODSW ES JMP APUSH POP BX POP AX ADD AX BX JMP APUSH March 1992 April iz i Segments max size each Code n 64K Lists Data n 64K Heads n 64K Stack 64K 4 BX CX DX LODSW XCHG DI AX JMP DI Qo MOV BX BX NEXT Constant PUSH BX MOV BX DI 2 NEXT Segments max size each Code 64K Lists 64K Stacks 64K X BX CX DX ll ct Oo o LODSW JMP AX farli MOV BX ES BX NEXT Constant PUSH BX MOV BX value NEXT March 1992 April SI DI BP SP Tool 64K SI DI BP SP IP W RP SP Nest _ INC BP INC BP MOV BP SI LEA SI DI 2 NEXT t POP AX MOV BX AX POP BX NEXT Variable _ PUSH BX LEA BX DI 2 NEXT D
17. BX POP AX MOV BX value ADD AX 3 ADD BX AX NEXT MOV BX AX NEXT NEXT 19 March 1992 April ments m iz h Code Lists Data Heads Stack Blocks 64K Register use AX BX tos CX DX Next TP ERN XCHG SP SI MOV BX BX XCHG SP SI Constant XCHG SP SI PUSH BX MOV BX value XCHG SP SI SI DI BP SS SP RP Nest CALL XXX XCHG SP SI POP BX POP BX XCHG SP SI Variable XCHG SP SI PUSH BX MOV BX addr XCHG SP SI cs DS ES SS all cs cs cs IP IP Unnest RET Literal XCHG SP SI PUSH BX MOVE BX value XCHG SP SI XCHG SP SI POP AX ADD BX AX XCHG SP SI When these words are compiled in line these instructions may be eliminated Illyes Robert F A Tiny and Very Fast Subroutine threaded Forth Proceedings of tbe 1990 Rochester Forth Conference page 76 The Forth Institute Lists 64K Code 64K Register use AX W SI BX tos DI CX BP DX SS Next LODSW NEST JMP AX f poo MOV ES BX BX NEXT PUSH BX MOVE BX value NEXT March 1992 April doVAR Data 64K IP WwW RP SP Nest MOV DI pfa JMP NEST DEC BP DEC BP MOV BP SI MOV SI DI NEXT POP ES BX POP BX NEXT Variable MOV DI addr JMP doVAR PUSH BX MOV BX DI NEXT CS DS ES SS Heads 64K code lists data stacks 20 Unnest MOV SI BP INC BP
18. GRAND ScaLE This theme applies equally to projects requiring multiple program mers and to applications or systems consisting of large amounts of code and or of significant complexity Pa pers will be refereed To encourage entries the author of the winning article will receive 500 the second place 250 and the third place 100 Articles will be evaluated for publication even ifthey do not win a cash prize You need not have been personally involved in the subject of your entry just write about it in sufficient technical detail and address the particular challenges that were faced and describe how or whether they were overcome Chances are if you think a subject might fit the theme of this contest the judges will be anxious to include it in their evalua tions so get started soon The deadline for contest en tries is August 3 1992 Maila hard copy and a diskette Macintosh 800K or PC pre ferred to the Forth Interest Group P O Box 8231 San Jose California 95155 or mail the hard copy and upload an ASCII version to MARLIN O on GEnie s e mail service with an attached note describing the file and compression archive format if any We all look forward to receiving your contribution At the other end of the scale we have minimal Forths How small can you get and still have a language What are the fewest required words in Forth That is the on line discussion excerpted in The Bes
19. are used very often Some people have tricky ideas about how to realize BRANCH and BRANCH and they are not slow BRANCH R gt DUP CELL gt R BRANCH 0 R gt SWAP OVER Q AND CELL gt R From Mike Haas Subject Min Forth andgood performance Bernd Paysan writes In basic words LIT LITERAL This did not answer the question In fact the ques tion touches on something that is important to me as the author of JForth JForth in cludes a standalone applica tion generator called CLONE It is used thus CLONE lt wordname gt This creates an entirely standalone image that in cludes only the Forth words needed by lt wordname gt If lt wordname gt didn t call EMIT then EMIT doesn t get CLONEd into the image This leads to very small executables CLONEing NOOP creates a standalone program of about 3K this is the support necessary to ini tialize the environment if ei ther double clicked from an March 1992 April icon ortyped into the Amiga s shell When CLONE puts to gether the new image it has to perform many relocations since everything is moved around relative to the start of the program as opposed to the start of the JForth image This means that CLONE must be able to tell the dif ference between a compiled number and a compiled ad dress as might produce For this purpose I ve implemented ALITERAL The concept that a com piled numb
20. ck k kk kk class byte array super ldarray Initialize the array zm init n 1 setsize self allocate self 7m Set the element size Allocate space Return value at index location m get i val idx check self array addr self c m Set value at index location m put val i idx check self array addr self c 7m Fill the array with value val m fill array addr self elems self rot fill m Clear the array m clear 0 fill self m init init method class KKKKKKKKKKKKK V word array kkck kk k kk kk A A LAL Check bounds Start of array Add index Fetch Check bounds Start of array Add index Store Get address of elements Do it Set initialization method class word array super byte array V Initialize the array zm init n 2 setsize self allocate self m X Return value at index location Set the element size Allocate space m get i val idx check self Check bounds 2 Index gt offset array addr self Start of array Add index Fetch Forth Dimensions 41 learns a person s habits The expert system evaluates its inputs to determine what action is needed a gentle prompting a phone call for help etc Idon tthink George Orwell would have cared much for this system but it certainly can be instrumental in helping an elderl
21. floating point native code generation For Applications Forth 83 Metacompiler Unique table driven multi pass Forth compiler Compiles compact ROMable or disk based applications Excellent error handling Produces headerless code compiles from intermediate states and performs conditional compilation Cross compiles to 8080 Z 80 8088 68000 6502 8051 8096 1802 6303 6809 68HC11 34010 V25 RTX 2000 No license fee or royalty for compiled applications Laboratory Microsystems Incorporated Post Office Box 10430 Marina del Rey CA 90295 Phone Credit Card Orders to 213 306 7412 FAX 213 301 0761 35 March 1992 April 250 100 2nd prize 3rd prize See editorial in this issue Forth Dimensions Volume XII Index A subject index to Forth Dimensions contents publisbed from May 90 April 91 Prepared by Mike Elola architectures threading models for Forth Letter vol 12 1 pg 7 arithmetic operations Extended Precision Math Made Easy vol 12 4 pg 16 arrays Arrays in Forth vol 12 6 pg 13 assembly language Forth Assembler amp Free Use of Labels vol 12 44 pg 23 bulletin boards Best of GEnie vol 12 45 pg 36 calculator simulation Pencil and Paper Arithmetic vol 12 46 pg 22 chapters Forth Interest Group Talking it up in the Outfield vol 12 1 pg 32 compiling systems Forth Letter vol 12 41 pg 7 conferences FORML XII Forth in Indus
22. of Forth adepts is producing a series of articles applying Forthto hands on hardware software projects that you can do a laboratory for increasing your Forth profi ciency at the workbench Vendors and developers will have more opportunities to contribute technical and in dustry information in ways that will show what they are doing successfully and where Forth is excelling in real world application And we have scheduled tutorials about traditional tools like CREATE DOES as well as the control structures that will be introduced in ANS Forth More than ever we believe that from beginner to expert every Forth user and project manager will want to receive the vital in formation that will be ap pearing here Reader participation has always been a key element of this publication Your contributions are the lifeblood of our pages dramatically helpingto chart our direction We not only welcome your own articles and letters to the editor we need them March 1992 April FD can now announce the third in a series of con tests for Forth authors The first called for entries about Forth hardware and the winners were published in our issue XI 6 More recently the winners of our object oriented Forth contest ap peared in issue XII 5 Draw ing on feedback from Forth vendors the theme of our current contest is Forth in large scale applications This is our first call for papers about FORTH ON A
23. of stack in a register A mul tiple segment model which interprets from screen files Notes Colon word PFA s literals constants and vari able addresses are compiled in line in the code seg ment Forth Dimensions LaFORTH V4 0 9 24 87 Stuart amp Smith copyrighted Experimental version by LaFarr Stuart and Robert L Smith Has some very inter esting features including calling Forth from Forth and interpreting a word at a time instead of a line at a time Source code is in assembler A direct threaded 16 bit implementation with the top of stack on the stack A single segment model with an extra segment for interpreting text files Notes the return stack is in the ES segment and grows up MMSFORTH V2 4 5 30 85 Miller Microcomputer Sucs commercial Commercial version of Forth includes advanced full screen editor many utilities Options include database word processor general ledger expert system and advanced utilities Source code is in screen files in DOS version and in direct blocks screens in self booting ver sion which supports more efficient Forth disk formats such as 1K sector size Most source code is supplied full source code and metacom piler are available Indirect threaded 16 bit implementation top of stack on stack single segment model DOS version uses a separate Heads segment Interprets from direct blocks DOS version uses screen files nts
24. offs The benchmarks arrived at are specifically aimed at the attributes studied and do not necessarily correlate with real appli cations Threading There are two aspects of threading in Forth to be evaluated The efficiency of incrementing the Forth in struction pointer and the efficiency of nesting and unnesting Forth Dimensions The following threading benchmarks were used Empty loop Empty XX X 30 000 0 DO LOOP XX 5 0 DO X LOOP Threading Thread YY XX CODE NC NEXT END CODE 7 7 30 000 0 DO NC NC NC NC NC NC LOOP YY 5 0 DO Y LOOP X Nestingl Nestl Z2 XX DON m 2 30 000 0 DO N N N N N N LOOP ZZ 5 0 DO 2 LOOP V Nesting2 Nest2 WW XX Wl W2Wl WWR WA W3 WS W4 W6 W5 DOW 30 000 0 DO W6 LOOP WW 5 0 DO W LOOP The two nesting benchmarks should be equivalent but can be very different depending upon any optimization applied Forth Threading Width BBL direct 32 160s eForth direct 16 16 F83 indirect 16 16 F PC direct 16 16pp Fifth subroutine 32 HS FORTH indirect 16 16 KForth direct 16 16 LaFORTH direct 16 16 MMSFORTH indirect 16 16 MVP FORTH indirect 16 16 PC Forth indirect 16 16 PMFORTH direct 16 16 polyFORTH indirect 16 16 Pygmy direct 16 16 riFORTH subroutine 16 16 UniForth indirect 16 16 Upper Deck direct 16 16 UR FORTH direct 16 16 ZEN direct 16 16 is a 16 bi
25. proposals Forth hardware emulators embedded systems and the usual and unusual wide ranging fare 39 PCYerk Classes Rick Grehan Last issue s winner of the Object Oriented Forth contest returns with supplemental code Here you will find the Forth foundations of basic classes storage classes byte and word arrays strings and string arrays Use this or another object oriented Forth to explore the symbiosis of traditional Forth and classical object style programming Departments 4 Editorial Coming attractions call for conte t papers about this issue 31 New FIG Board Members Mike Elola Nicholas Solntseff Jack Woehr 32 BestofGEnie Dearth of feedback on ANS Forth how minimal can Forth get 36 Volume XII Index The complete subject index to Forth Dimensions contents pub lished from May 1990 April 1991 37 Advertisers Index reSource Listings Sources of information about FIG ANS Forth classes on line Forth connections and FIG chapters will return in the next issue Forth Dimensions 3 March 1992 April scelto New Conte St for Forth Authors With this issue many of you will be due to renew your membership in the Forth Interest Group This is a year to do so promptly and to make a gift membership or two for the office a co work er or friend here are a few things to look for in coming issues of Forth Dimensions A West coast group
26. took every good idea that has appeared I tried to unify solutions I attempted to solve all the problems I was aware of I tried to render uniform the proposed set of words I sacrificed strict historical continuity to improve teachability while avoiding conflicts among old and new syntaxes And I have used them for more than two years refining them until they were stable enough except the interactivity of control flow words March 1992 April READER very dubious Hmm okay I ll listen to you but I hope you ll have something new to tell me AUTHOR happy and enthusiastic Oh thank you I ll present six control structures that you can add at will Here are some simple rules to follow Every control structure has a name a beginning and an end The beginning is set by the word name while the end is set by the word name E g CASE LOOP CASE LOOP The beginning of a control structure may accept some value on the stack e g 5 TIMES TIMES The end ofthe control structure when reached may jump out of the control structure or can jump unconditionally or conditionally to the beginning of the control structure more precisely to the word immediately after the beginning CONTROL and CASE jump out REPEAT and FOR jump unconditionally to the beginning while TIMES and LOOP jump conditionally to the beginning or out of the control structure With the exception of CONTROL and REPEAT the other c
27. used and becomes more important as an application becomes more complex The Forths reviewed Forth Dimensions range from simple to very complex and the documentation of their structure ranges from nonexistent to well detailed Further some provide complete source code and some do not although you can usually obtain it for a fee At the most advanced level those that supply source provide it either as native Forth code with a metacompiler or as assembly code for use with a standard assembler Be warned most metacompilers are difficult to master at best and you usually require some understanding of them to follow the accompanying Forth source Finally remember Forth can never well hardly ever be too small or too fast especially for all those big and slow applications Forth Assemblers an aside How to move the contents of memory pointed to by the contents of register BX into a register AX in this case MOV AX BX opcode destination source AX BX MOV destination source opcode AX BX MOV same order trailing period BX AX MOV source destination opcode BX AX MOV BX AX LDA 3 0 MOV 3 0 LDA same order trailing comma same order different opcode same order different register names same order different opcode and there are probably more and you haven t seen how to index yet The code fragments are all given in a standard format This does not reflect the flavor of the assemble
28. 000 WITHIN I AddInst WITHIN 6000 7000 WITHIN I SubInst WITHIN I 1 AND 0 WHEN I JsrInst WHEN else I JmpInst WITHIN I 8000 1000 TO I 1 OF OF 7 OF OF CASE ResultDisplay FOR Example Type the powers of two smaller than 1 000 000 1 FOR I 1 000 000 lt WHILE I I 2x TO I Example Type the con tents of a null terminated list StartAddr FOR I WHILE I CELL I TO I FOR Example Do a loop that executes at least once like DO LOOP Only for illustra tion purposes 10 FOR someCode 5 STEP I 90 WHILE FOR 90 10 DO someCode 5 LOOP TIMES DROPS X1 X2 Xn n TIMES DROP TIMES MULTIEXECUTE token times TIMES DUP EXECUTE TIMES DROP CountBack from TIMES I TIMES March 1992 April or I STEP FOR Figure Two Compilation effects of CONTROL REPEAT FOR and CASE HOUR Pointer to Pointer to MAIN LEAVE leaving LEAVE LEAVING to end code code 6 6 6 5 CountBack types 43210 1 CountBack types 0 0 CountBack doesn t type anything 2 CountBack issues an error message Presenting JLEAVING and COMPLETED While the subset of words discussed above resolves many problems until now some are still unresolved Here I will present the problems and the solutions to them using extensions of the wordset The JLEAVINGI Clause Let s suppose there are three variables VO V1 and V2 that c
29. 16 Megabyte physical address space or gigabyte virtual for programs and data DOS amp BIOS fully and freely available 32 bit address operand range with 386 ROMULUS HS FORTH from ROM 99 Shipping system US 7 Canada 19 foreign 49 We accept MC VISA amp AmEx Free Online Glossary plus Tools amp Toys Disk with all systems Free 286FORTH also for 386 with all Professional and Production level systems March 1992 April Forth Systems Comparisons Guy M Kelly La Jolla California Code fragments and benchmarks for several of the Forths for the PC are outlined to illustrate various tradeoffs and their effect on performance The following list represents some of the Forths I have been able to study They span a wide range of imple mentation tradeoffs and provide some insight into the results of these tradeoffs Forth Model Author s Status BBL 83 Green public eForth X3J14 Muench amp Ting public F83 83 Laxen amp Perry public F PC 83 Zimmer amp Smith public Fifth Click amp Snow share HS FORTH Callahan commercial KForth experimental Kelly copyrighted LaFORTH experimental Smith amp Stuart copyrighted MMSFORTH 79 Miller et al commercial MVP FORTH 79 Haydon public PC Forth 83 Kelly public PMFORTH fig Moreton commercial polyFORTH 83 Moore et al commercial Pygmy cmFORTH Sergeant copyrighted riFORTH cmFORTH Illyes copyrighted UniForth 83 Hendon share Upper Deck 83 Graves commercial UR FORTH 83 Dunca
30. A CLARA CA 95055 408 241 5909 March 1992 April 30 Is that an error condition If not how many times do we have to repeat the loop Let s compare the choices of BASIC and Forth and deduce the relationship between start end step and times Considering a positive step in BASIC we write FOR I 10 TO 18 STEP 3 PRINT I NEXT I loop is done 3 times FOR I 10 TO 19 STEP 3 PRINT I NEXT I loop is done 4 times FOR I 10 TO 20 STEP 3 PRINT I NEXT I loop is done 4 times FOR I 10 TO 21 STEP 3 PRINT I NEXT I loop is done 4 times FOR I 10 TO 22 STEP 3 PRINT I NEXT I loop is done 5 times So the relation is times diff step 1 where diff end stant In standard Forth a DO LOOP works like 19 10 DO I 3 LOOP loop is done 3 times 20 10 DO I 3 4LOOP loop is done 4 times 21 10 DO I 3 LOOP loop is done 4 times 22 10 DO I 3 LOOP loop is done 4 times 23 10 DO I 3 LOOP loop is done 5 times So the relationis 4fmes diff 1 step 1 check itagainst the examples to convince yourself This relation gets simplified as times diff when the step is 1 We can observe that the Forth formula giving the times is more complex than the BASIC formula If we also consider negative steps things get much worse for Forth What I consider the simplest choice is to define times diff step That choice is equivalent to the Forth one for the case step 1 most common Besides that choice has some usef
31. FORTH S R 13 1 9 6 9 6 5 4 9 6 34 8 6 8 Fifth 7 1 20 9 20 9 70 4 97 2 KForth D R 3 0 5 8 25 8 25 8 21 6 36 2 21 9 LaFORTH D R 3 6 5 8 29 9 29 7 26 9 36 3 0 5 UR FORTH D R 3 0 5 8 31 9 32 0 24 3 38 2 0 5 Pygmy D R 3 2 5 9 32 0 32 0 23 5 39 7 47 Upper Deck D R 42 5 9 32 1 32 1 23 8 39 8 0 5 ZEN D R 3 6 6 8 34 1 33 8 27 4 4 6 4 4 HS FORTH I R 5 5 9 8 34 2 35 8 28 5 48 8 0 7 polyFORTH I S 48 9 9 34 5 34 5 31 5 52 9 1 0 PC Forth I S 5 6 10 0 34 5 34 5 32 7 54 8 8 4 UniForth LS 3 6 10 7 35 9 35 8 33 3 2 7 MMSFORTH 1 S 5 2 10 0 37 4 37 4 33 4 55 6 0 5 BBL D R L 4 0 5 9 41 4 41 4 33 1 49 0 4 3 eForth D S 4 3 42 2 F83 I S J 5 4 15 1 43 4 43 4 41 5 68 1 3 8 PMFORTH D S 5 5 9 6 43 5 43 5 39 8 70 15 1 F PC D S P 3 1 11 0 46 4 46 4 30 3 44 9 0 9 MVP FORTH 1 S J 14 2 19 8 53 3 53 3 50 8 8 5 Sorted by nesting time 1 Type Indirect Direct or Subroutine threading stack top in Register or on Stack 1 meg Lists 1 meg lists on Paragraphs Jump to NEXT Timing _ _ In general the results were as follows fastest to To obtain the maximum slowest advantage from Forth subroutine threading top of stack in register direct threading top of stack in register one should understand indirect threading top of stack in register the rationale for its structure indirect threading top of stack in memory and its inherent stren gth s direct threading top of stack in memory and weak
32. I ve im plemented ALITERAL My Sun Forth and Forthmacs systems which are fully relocatable and support an application stripper program that does the same thing as JForth s CLONE have the same problem and solve it in the same way My equivalent of ALITERAL is named The answer to the above question is that there is no standard way of com piling in an address vs a literal number and there should be You can do it in ANS Forth by using POSTPONE with or by using something like S FOO EVALUATE possibly with a string that is constructed at run time March 1992 April 34 Forth Dimensions Continued from page 31 job to become a program mer He has been steadily employed in Forth since that time He currently chairs the Software Collegium at Vesta Technologies where he has been employed since Febru ary 1988 Vesta manufac tures single board comput ers for embedded control with Forth in ROM Besides serving as the Vice President of FIG Jack is a Contributing Editor for Embedded Systems Programming magazine the author of Seeing Forth Offete Enterprises 1992 frequently writes Forth articles for Dr Dobb s Journal and is the author of JAX4TH the first dpANS Forth for the Amiga The Forth community is a besieged minority The Forth Interest Group has suffered a decline in recent years Old members have left the group and new members are slow to repla
33. March 1992 April 3 lt E 3 C Tm Ss SILICON COMPOSERS INC Announcing the SC FOX 1O32 Board for FAST Forth I O 6 299 00 012 ouod SQUARTSS seeeeeese eeeeeesene eeeeeeoee C9 ch orollet byte Decode Pat v seseseeecotce T KE eeoeeee 1 eeoeenese 99999069009 rers Byte e RS232 899909090000 w Timing PAL eee0e0000 6 aw ty 206 PhM FA 999090909090900999099 e 00909909900000009000000000000 91 S con Composers Inc Palo Alto The 1032 is a plug on daughter board for either The program SEND below reads 1K blocks from a SCSI the SBC32 stand alone or PCS32 PC plug in drive and transmits them out one of the 1032 board s four single board computers RS232 serial ports at 230K Baud SEND uses only 1032 5 MB sec SCSI Port facilities Disk read speed is limited by SCSI drive speed Attach up to 7 SCSI Devices 4 RS232 Serial Ports up to 230K baud 16 bit Bidirectional Parallel Port may be used as two 8 bit ports 2 programmable counter timers Prototyping area on board All bus signal brought out to pads Full Interrupt Support Two 50 pin user application connectors No jumpers totally software configurable Driver software source included Single 5 Volt low power operation Full ground and power plane 4 Layer Eurocard size 100mm x 160mm User manual and interface schematics included Low chip count 8 ICs for maximum reliability
34. NOVATION 513 748 0390 P O Box 69 Springboro OH 45066 MEET THAT DEADLINE 1 Use subroutine libraries written for other languages More efficiently Combine raw power of extensible languages with convenience of carefully implemented functions Yes it is faster than optimized C Compile 40 000 lines per minute Stay totally interactive even while compiling Program at any level of abstraction from machine code thru application specific language with equal ease and efficiency Alter routines without recompiling Use source code for 2500 functions Use data structures control structures and interface protocols from any other language Implement borrowed feature often more efficiently than in the source Use an architecture that supports small programs or full megabyte ones with a single version Forget chaotic syntax requirements Outperform good programmers stuck using conventional languages But only until they also switch HS FORTH with FOOPS The only full multiple inheritance interactive object oriented language under MSDOS Seeing is believing OOL s really are incredible at simplifying important parts of any significant program So naturally the theoreticians drive the idea into the ground trying to bend all tasks to their noble mold Add on OOL s provide a better solution but only Forth allows the add on to blend in as an integral part of the language and only HS FO
35. RTH provides true multiple inheritance amp membership Lets define classes BODY ARM and ROBOT with methods MOVE and RAISE The ROBOT class inherits INHERIT gt BODY HAS ARM RightArm HAS ARM LeftArm If Simon Alvin and Theodore are robots we could control them with Alvin s RightArm RAISE or 45 10 Simon MOVE or 5 20 FOR ALL ROBOT MOVE The painful OOL learning curve disappears when you don t have to force the world into a hierarchy Forth Dimensions WAKE UP Forth is no longer a language that tempts programmers with great expectations then frustrates them with the need to reinvent simple tools expected in any commercial language HS FORTH Meets Your Needs Don t judge Forth by public domain products or ones from vendors primarily interested in consulting they profit from not providing needed tools Public domain versions are cheap if your time is worthless Useful in learning Forth s basics they fail to show its true potential Not to mention being s l o w We don t shortchange you with promises We provide implemented functions to help you complete your application quickly And we ask you not to shortchange us by trying to save a few bucks using inadequate public domain or pirate versions We worked hard coming up with the ideas that you now see sprouting up in other Forths We won t throw in the towel but the drain on resources delays the introduction of even better tools Don
36. TH and available for 8080 Z80 8086 family and 68000 series microproces sors Includes full source code and metacompiler in DOS screen files An indirect threaded 16 bit implementation with the top of stack on the stack A single segment model which interprets from screen files Notes Central NEXT F PC V3 50 10 22 89 Zimmer amp Smith public A massive effort and implementation by Tom Zimmer and Robert L Smith with support from a variety of other persons and groups Many enhancements over F83 and a large set of con tributed add ons by other programmers Has a very complete text editor and hyper text like source code and documentation browser Very big and very complete includes full source code and metacompiler A direct segment threaded 16 bit implementa tion with the top of stack on the stack A multiple segment model which interprets from text files Notes colon definitions start on paragraph boundaries Forth Dimensions Segments max size each Code Lists Data Heads Stack Blocks 64K BX iow WoW Iz DX LODSW MOV BX AX JMP BX POP BX PUSH BX JMP NEXT Constant _ INC BX INC BX MOV AX BX JMP APUSH men max Code Data Stack Blocks 64K AX BX CX DX Next LODSW ES JMP AX POP BX PUSH BX NEXT Constant JMP doCON MOV BX AX PUSH BX 3 NEXT SI DI BP SP IP RP SP Nest INC BX INC
37. Test routines for SCSI parallel and serial ports supplied in source code form Plug together up to 6 1032 Boards in a stack For additional product and pricing information please contact us at SILICON COMPOSERS INC 208 California Avenue Palo Ako CA 94306 415 322 8763 2 Forth Dimensions Contents Features 6 Forth Systems Comparisons Guy M Kelly Award winning paper dissecting and comparing nineteen Forths including commercial shareware and public domain systems Provides detailed testing information analysis of how to compare different Forths discussion of critical non performance related factors and timing results Won the Public Service award at the 1991 FORML Conference 22 The Curly Control Structure Set Kourtis Giorgio After an in depth review of all the literature on Forth control structures and following two years of development and testing the author proposes a new set of control structures for you to try out In search of performance ease of use generalization flexibility and teachability without sacrificing too much in terms of historical continuity Think it can t be done at least not better Or just want to brush up on how control structures work Open your mind and sharpen your wits Part one of two 38 A FORML Thanksgiving Richard Molen The annual Forth Modification Laboratory FORML is a long standing Forth tradition Join those who gathered on California s Monterey peninsula to discuss new
38. These ratios indicate that changing from indirect thread ing to direct threading in the multi segment version provides about a 3096 speed up while changing from top of stack on the stack to top of stack in a register provides about a 1096 speed up Changing both provides about a 5096 speed up The segment model affects performance in the case shown above by about 5 10 because the D R S version does not permit the best possible optimization of the Forth virtual machine for speed as shown by the code fragments on the preceding page A more significant reason for segmentation is that it provides separation of the components of a Forth word and can provide more memory in which to program For example separating the headers from the rest of the words can provide more program space or can make an application smaller and much harder to disassemble Another reason for segmentation is that more and more operating systems restrict the use of data and code in the same memory hunk These systems normally restrict read write access to data structures in the code hunk making an application either use separate hunks for code and data or use the operating system to overcome such restrictions with possible performance penalties Opinions Selecting one Forth over another for a typical gain of 5096 in performance may be the wrong reason to make the choice Changing from an 8088 to a faster member of the family changingan algorithm orusing the op
39. Type Empty Thread Nest1 Nest2 Prims Sieve Loads HS FORTH I R 5 5 9 8 34 2 33 8 28 5 48 4 0 7 optimized 3 2 0 0 0 0 0 0 5 2 12 9 0 7 UR FORTH D R 3 0 5 8 51 9 32 0 24 3 38 2 0 5 optimized 0 8 12 9 23 1 23 1 6 3 7 5 0 5 Name Empty Thread Nest1 Nest2 Prims Sieve S R S 13 1 9 6 9 6 5 4 9 6 34 8 D R M 2 9 5 8 25 8 25 8 21 5 36 2 D S M 2 9 5 8 25 8 25 8 25 1 42 3 D R S 2 9 5 8 31 9 32 3 23 4 37 9 I R M 3 6 10 0 33 8 33 5 28 8 47 7 I S M 3 6 10 0 33 8 33 5 32 1 53 2 March 1992 April 10 Forth Dimensions The following lists the versions of NEXT nest EXIT literal CONSTANT VARIABLE and used in these models EXIT nest NEXT CON VAR LIT MOV SI BP INC BP INC BP NEXT DEC BP DEC BP MOV BP SI MOV SI addr NEXT LODSW JMP AX PUSH BX MOV BX NEXT see CON see CON ES MOV BX BX NEXT ES POP BX POP BX NEXT POP AX ADD BX AX NEXT Code Fragments D R M D R M see CON MOV BX PUSH BX NEXT POP BX ES PUSH BX NEXT POP BX ES POP BX NEXT POP BX POP AX ADD BX AX PUSH BX NEXT D R M LODSW XCHG AX DX JMP DX see D R M see CON LODSW PUSH BX XCHG AX BX NEXT ES MOV BX BX NEXT ES POP BX POP BX NEXT POP AX ADD BX AX NEXT D R M LODSW XCHG AX BX JMP BX see D R M lt see CON LODSW PUSH AX NEXT POP BX ES PUSH BX NEXT POP BX ES POP NEXT BX
40. ack Multiple I R M Indirect in Register Multiple I S M Indirect on Stack Multiple D R S Direct in Register Single The versions were optimized for speed at the expense of size All models used an in line NEXT and in line nest LIT etc where possible The benchmark results sorted by nesting time are given in Table Five Note that for riPORTH Nest2 is almost twice as fast as Nestl while Thread and Nest take the same time This is because riFORTH is subroutine threaded and has built in optimization Referring to the nesting benchmarks the code no op NC and the colon no ops N and W1 all compile as return instructions However W2 is compiled as ajumptoW1 W3 as a jump to W2 etc thus doing five jumps and a return inside the W loop instead of six call return pairs Also note that the Prims are executed much faster for riFORTH than the other versions because riFORTH drops adjacent XCHG BP SI pairs from code macros as it compiles them into the list field ofa colon definition while the Sieve which uses a high level DO LOOP is only slightly faster The apparent anomaly among the other versions is D R S the only one of the five that is not multi segment It nests more slowly but does Prims and Sieve faster than D S M because nest LIT and VARIABLE cannot be as highly optimized for speed Table Five Performance of test set versions of Forth Table Four Results using optimizers Forth
41. addr n thestring count m allocate init method class ok ockok cock x x x kx x x x String array X Xkkok ck k ck ck kk k kk This array is a collection of pointers to string elements class string array super word array o A A ALAA Allocate space for the array n of elements Vm max size for each string element m allocate mn dup init self X Make space for it string gt body X Need this to make string swap 0 do here gt r X Save location 2dup instantiate Make a string object r i put self X Store addr of object loop 2drop Clear stack im Fetch a string at index i Store in address addr Lots of get messages here The one in the curly brackets goes to an integer array and fetches the address of a string object The get outside the curly brackets sends a get to a string type im get i addr swap get get self Fetch im Place a string at element in index i m put addr i put get self m allocate lt lt init method class Forth Dimensions 43 mated molecular biology workstation designed to au tomate the HGP bottleneck of preparing DNA fragments for analysis At its core is a three axes robot arm capable of delivering liquids to 001 accuracy The software runs on a Macintosh and was written in polyFORTH using a simple round robin tasker Dennis Rurrer spoke last He pointed out the need for a common valida
42. arting address Thus let s define the additional modifier BACK to be used like BACK LOOP LOOP This has the effect of reversing the order of the values assumed by the index in the absence of BACK BACK StartAddr elements ElementSize LastAddr elements ElementSize DUP NEGATE gt R OVER 1 ROT SWAP R gt With the above choices and definitions we have a very flexible loop construct that accepts various input formats and greatly simplifies work with arrays Obviously depending on the problem at hand similar techniques may be used to extend the patterns accepted by the loop construct making it possible to feed the construct with a format natural to the problem at hand Moreover the basic format is very easy to implement fast to execute and ADVERTISERS INDEX Forth Interest Group 35 Harvard Softworks 5 Laboratory Microsystems 35 Miller Microcomputer Services Ne 37 Next Generation Systems ssseee 30 Silicon Composers 2 Forth Dimensions 37 precise in meaning Examples Create and initialize a table 100 CONSTANT LOGOS 29 CONSTANT SIMPLELOGO CREATE LOGOS LOGOS CELLS ALLOT LOGOSINIT LOGOS LOGOS CELL LOOP SIMPLELOGO I LOOP Search our table for a specified value and leave its address if it is found logoSearch logo false LOGOS LOGOS CELL LOOP dup I WHEN
43. ata 64K Video 64K IP CS DS RP ES SP SS Nest 1 DEC BP DEC BP MOV BP SI MOV SI pfa NEXT POP ES BX POP BX NEXT Variable PUSH BX MOV BX addr NEXT cs DS ES SS code liststdata heads misc stacks Unnest MOV SI BP DEC BP DEC BP NEXT Literal PUSH BX MOV BX SI INC SI INC SI NEXT POP AX ADD BX AX NEXT Heads 64K Msgs 1K code lists data stacks 16 Unnest MOV SI BP INC BP INC BP NEXT Literal PUSH BX MOV BX value NEXT POP AX ADD BX AX NEXT HS FORTH V4 24 8 9 91 Harvard Softworks commercial A very complete com mercial implementation of Forth for the 8086 family of microcomputers One of the few Forths in this review that provides compatibility with the DOS linker Source code and metacompilers available Multiple Forth segments in a single DOS allocation An indirect threaded 16 bit implementation with the top of stack in a register A multiple segment model which interprets from text or screen files 1 The above information is presented with the gen erous permission of Jim Callahan of Harvard Softworks KForth V0 9 9 28 91 Kelly copyrighted Currently an experimen tal model to investigate vari ous aspects of threading and segmentation Current ver sion is fast C in line direct threaded multi segment in multiple DOS segments A direct threaded 16 bit implementation with the top
44. ation of the fig FORTH 8080 assembly code Central NEXT PC Forth V1 56 9 09 87 Kelly public Written expressly for teaching purposes Includes full source code and a simple interactive metacompiler which does not require mixing meta commands in with the Forth source code Also includes a very power ful screen editor with over lay capability for use with other Forths as well as many utilities Available in both self booting and DOS versions An indirect threaded 16 bit implementation with the top of stack on the stack A single segment model which interprets from screens di rect or file or text files Forth Dimensions polyFORTH PF86S MSD FORTH Inc commercial The mother of all Forths well almost by FORTH Inc Complete source code with metacompiler EGA VGA graphics data base floating point screen editor debugger and other support Full multi user capability built in at the kernel level Source code and shadow screens in screen files Indirect threaded 16 bit implementation top of stack on stack multiple segment model Interprets from screen files A 32 bit 386 protected mode version is also available FORTH Inc Pygmy V1 3 10 4 90 Sergeant copyrighted Based on the Chuck Moore cmFORTH model The source code and the metacompiler are in screen file A direct threaded 16 bit implementation with the top of stack in a register A single segment model which interprets fro
45. ce them Atthe same time Forth professionals are confronted with the paradox of Forth usage increasing while Forth market share is declining These are ominous runes cast at the feet of Forth Yet we believe that our heterodox model of compu tation presents a more holis tic approach to the interac tion of man and machine than the path taken by or thodox computer scientists Ifour approach still has value then the practices and insti tutions which have served us are worth the effort taken to maintain them I have sought and ac cepted admission to the Board of Directors of the Forth Interest Group in order to contribute to the preserva tion of an organization which has proved so useful in the past decade an organization which hopefully shall con tinue to render effective ser vice in the coming decade The Forth Interest Group has historically fulfilled two important roles that of aid 1st prize New Contest Announcement Call for Papers Forth Dimensions is sponsoring a contest for articles about Forth on a Grand Scale Write about large scale Forth applications systems or 500 If you stay and if you bring others FIG will continue as your tutor friend and advocate ing newcomers entering upon the path to Forth pro ficiency and that of a mutual aid society for Forth pro grammers I know this from experience I leamed Forth in the course of many en t
46. ch an editor s text for a specific character We want the cur sor to move during the search and if the character is found have it point to that charac ter otherwise we want to reset the cursor to its original position not simply leaving it at the end of the text Below is a word to do that using the new word COM PLETED CharSearch char true cursor swap keep previous position TextEnd cursor of chars to end of text char char NextCharGet char char textChar Move the cursor on while furnishing the TIMES dup pointed char WHEN 2drop true WHEN COMPLETED drop initialCursorPosition Cursor false TIMES Compare with the flowchart in Figure Five LEAVING and COMPLETED can be used together The next example isa variation of the previous one Here we want to search our text for the first occurrence of or Figure Four Retum stack control structure frame small tack growth direction addresses E of stack is at left Frame generated by SIMPLE 00 long 04 long 08 word OA CS beginning oldCSF CSF points here large addresses previous RS data Frame generated by INDEXED ana TIMES long long 08 word 0A long I beginning T Reteaser INDEX extra value 0 previous RS data CSF points here Frame generated by LOOP long O4 long 08 word OA long QE long 12 long 16 res beginni
47. d processor Rick has a B S degree in physics and applied mathematics and an M S degree in mathematics computer science His work on a PC version of the Yerk implementation won first prize in FD s object oriented Forth contest The following code builds on the object oriented Forth discussed in the last issue of FD ok ck oko e e ek x e Ax x kx x BASIC CLASSES ekckokoko koe KO KR E KKKKKKKKK object KKKKKKKEK class OA 1A LA object 0 ivar dummy Return address to object s instantiaion in variable Segment You can use this to get an object s address and store it in a variable for deferred binding E G variable frank 12 word array bob 44 fill bob addr bob frank 2 get frank 8 FORTH RESPONDS 44 ok m addr dummy 2 m addr V Return address to 2m ivar addr dummy m Start of object s ivars region addr Return the length of the object s data area XV Used to get offset to ivar area m length n dummy 2 X Get pointer to instantiation Class address in token segment Gt V Length m class Forth Dimensions 39 FORML continued idea that Forth had to be 16 bits indirect threaded and interpretive he was able to make this 8 bit native code system This useful insight applies to applications as well FRANK SERGEANT has writ ten a three instruction F
48. d prop erly to obtain needed goals Along with my help I now feel that the business group has made considerable progress in setting priorities and focusing its energies In the years that I have served I have become especially aware of our limitations Understanding and con fronting those limitations is a vital leadership skill Other wise we can easily squander our limited resources both in terms of volunteer time and FIG reserves Although our progress at learning to work within our limitations has come slowly Iam proud about the decisions we have made so far Over the last year we have spent considerably less money for nearly the same services More remarkably we have not sacrificed the quality of those services Admittedly some ofthe ser vices have been cut Others besides myself have had to step up our level of volun teer work to compensate 31 New FIG Board Memb No doubt FIG has perse vered because of its deter mined leaders I d like to continue to serve FIG now more than ever since I ex pect to be able to enjoy monitoring FIG s financial stabilization if not recovery Innovative ideas from all of our business team partners have been essential to help turn things around Beyond specific measures we have taken a long soul searching period has contributed to our success This has helped in still similar attitudes in most of the business team mem bers and increases my abil ity and
49. dients The word CONTROL if reached exits the control structure REPEAT gt REPEAT Equivalent to but much more flexible than the usual BEGIN UNTIL or BEGIN WHILE REPEAT structures Any number of WHILEs or WHENs may be used inside this structure along with the pairs WHEN WHEN etc CASE KeyValue CASE Comparable to Eaker s CASE structure CASE takes a number from the stack the subject of our research and puts it into the index where it can be retrieved by I KeyValue Afterwards by means of pairs like OF OF WITHIN WITHIN IN IN and others yet to be invented and also by using WHEN WHEN or WHILE WHILE we can select and perform the desired action If the CASE word is reached the control structure is left FOR initialValue FOR General purpose looping construct unlike a FOR NEXT definite loop FOR takes a number from the stack and puts it into the index Afterwards the index may be manipulated by words like I TO I and STEP The loop termination condition must be handled explicitly using WHILE or WHEN This is an imitation of the Clanguage s FOR construct The desired model of loop pre increment pre decrement post increment post decrement fixed or variable step etc must March 1992 April 24 be handled explicitly checking and incrementing dec rementing at the beginning or end of the loop depending on the d
50. e or the value after the last one step Index step the constant difference between two successive index values times Total number of different values assumed by the index during the loop equal to the number of times the loop will be executed The possible combinations that can be used to specify the set of values the index will assume are start end step start end times stan times step end times step The combination end times step isn t worthy of discussion Start end step is the combination chosen by Forth and other languages Forth uses loops primarily to work on memory addresses so startspecifies the firstaddress we have to work on and end is the limit address In such cases it is sometimes useful to specify start size step instead where size is the size of memory we want to work on size end start Start end times can be used when we want to sample a function in an interval given by stant end with a certain resolution times This combination would probably have to be implemented with floating point numbers its usefulness with integers is dubious Start times step is used when we work on an array of elements of which we know the starting address the number of elements and the element size This combination is the simplest and most efficient to implement It will be our base for implementing all other kinds of loops We usually know the number of elements in an array and its first memory address Moreover
51. eagerness to serve Sull we cannot yet rest assured of our future and I don t know if we ever will this is not necessarily so bad I personally feel that any stability we realize by small but steady efforts is more durable than stability or growth that is perhaps attainable by occasional concerted efforts involving greater risks I also hope to moderate the efforts of others who would try to vitalize Forth with some kind of slick mar keting shtick Steve Wozniak and the Homebrew Com puter Club are now much further away from main stream culturethan they were at one time group such as FIG may need to remain in relative obscurity for the foreseeable future Never theless we should position ourselves comfortably Act ing out of desperation is not the way to inspire and keep the faith of our new and returning members Nicholas Solntseff Dr Nicholas Solntseff is of Russian emigr back ground and was born in Shanghai China well before World War II He was edu cated in English in Shanghai and completed his schooling at Sydney Technical High School in Sydney Australia Dr Solntseff attended Sydney University where he studied physics and obtained his B Sc in 1953 and Ph D in 1958 Aftera period of employment in England s nuclear engi neering industry he joined the University of London in 1963 Returning to Australia in 1967 Dr Solntseff switched to Computer Science and taught at the Univ
52. er tising sales 408 277 0668 Fax 408 286 8988 Copyright 1992 by Forth In terest Group Inc The material contained in this periodical but not the code is copyrighted by the individual authors of the articles and by Forth Interest Group Inc respectively Any reproduction or use of this periodical as it is com piled or the articles except repro ductions for non commercial pur poses without the written per mission of Forth Interest Group Inc is a violation of the Copyright Laws Any code bearing a copyright notice however can be used only with permission of the copyright holder The Forth Interest Group The Forth Interest Group is the association of programmers man agers and engineers who create practical Forth based solutions to real world needs Many research hardware and software designs that will advance the general state of the art FIG provides a climate of intellectual exchange and benefits intended to assist each of its mem bers Publications conferences seminars telecommunications and area chapter meetings are among its activities Forth Dimensions ISSN 0884 0822 is published bimonthly for 40 46 52 per year by the Forth Interest Group 1330 S Bascom Ave Suite D San Jose CA 95128 Second class postage paid at San Jose CA POSTMASTER Send ad dress changes to Forth Dimensions P O Box 8231 San Jose CA 95155 Forth Dimensions HARVARD SOFTWORKS NUMBER ONE IN FORTH IN
53. er and a compiled address as might produce ROT a b c b c a gt R SWAP R gt SWAP Inner Interpreters VAR addr P gt CONST n PERQ NEXT R gt R gt DUP IF 1 gt R ELSE CELL ENDIF gt R LIT n R gt OR DO limit index SWAP R gt SWAP gt R SWAP gt R OR LOOP R gt R gt 1 DUP R lt IF gt R DUP ELSE R gt 2DROP CELL ENDIF OR LOOP n R gt SWAP DUP R gt SWAP 0 lt OVER R lt XOR IF gt R DUP ELSE R gt 2DROP CELL ENDIF OR Comparisons via divide and conquer S n m flag 2DUP XOR 0 lt IF DROP ELSE ENDIF 0 lt i n m flag 2DUP XOR 0 lt IF NIP ELSE SWAP ENDIF 0 lt U lt n m flag 2DUP XOR 0 lt IF NIP ELSE ENDIF 0 lt U gt n m flag 2DUP XOR 0 lt IF DROP ELSE SWAP ENDIF 0 lt For the really esoteric Unsigned multiplication and division quot lt n q q 2 OR rem lt m rV m r 0 lt 1 AND SWAP 2 OR div n r n rn f OVER DUP 0 lt IF OVER 0 ELSE 1 ENDIF MOD m n 4r q SWAP 0 OVER rem lt m SWAP 2 n Vr m q F FOR gt R div SWAP R rem lt m SWAP R gt quot lt NEXT gt R div gt R NIP R gt R gt quot lt nn m quot MOD NIP MOD n m ren MOD DROP n m nm unsigned 0 SWAP F FOR DUP gt R 0 lt IF OVER ENDIF 2 R gt 2 NEXT 0 lt IF ELSE NIP ENDIF For this purpose
54. er must be able to be differentiated from a compiled address is not normally needed in Forth but for sophisticated func tionality such as CLONE it is necessary The answer to the above question is that there is no standard way of compiling Mitch Bradley Eng Sun COM Figure One Eng EXECUTE tick PR not that portable though in an address vs a literal number andthere shouldbe From Rob Chapman Subject Min Forth andgood performance I once had similar high level definitions for BRANCH R gt OR OBRANCH n 0 R CELL R AND R gt CELL gt R In this case I got faster branches but slower condi tional branches OBRANCH and 0 repre sent the classic chicken and egg syndrome In the above definition we depend on 0 as a primitive However if we wish to define 0 in Forth 0 n IF 1 ELSE 0 THEN then we need conditional branching as a primitive Other amusements dredged up from the cellar fare given in Figure One Rob From E RATHER Elizabeth Horrors From Mitch Bradley Subject Min Forth andgood performance Mike Haas writes When JForth s CLONE puts together the new image it has to perform many relocations since everything is moved around relative to the start of the program as op posed to the start of the JForth image This means that CLONE must be able to tell the difference between a compiled numb
55. ersity of New South Wales until 1970 when he moved to McMaster University Ontario Canada after a year as Visiting Pro fessor at the University of Colorado Dr Solntseff has been involved with Forth since 1981 when he implemented his first fig Forth on an Ohio Scientific microcomputer He has been the convenor of the South Ontario Chapter of the Forth Interest Group since its inception early in 1982 Dr Solntseffs research interests include the implementation of a Forth like language called Markov as well as interfacing Forth with Micro soft Windows For the last two years Dr Solntseff and his students have been working on human interface techniques in Medical Expert Systems being developed in the Department of Clinical Epidemiology McMaster University Jack Woehr Jack Woehr learned Forth in 1986 and quit his factory Continued on page 35 March 1992 April News from the Forth RoundTable Best Of Genie Gary Smith Little Rock Arkansas Discussion regarding the ANS Forth draft standard continued hot and heavy as we entered 1992 On Janu ary 16 the special invited guest in our on line confer ence was Greg Bailey of Athena Programming and Technical Subcommittee chair on the X3J14 Technical Committee Greg s topic was The Costs and Benefits of Adopting ANS Forth If you were not present at Greg s guest conference and have not yet captured the tran script I highly recommend doing so
56. ertaining Saturdays spent at Wolf and Pruneridge Roads Furthermore each phase of my successful career in Forth has involved employment found either at a meeting of the Forth Interest Group or via the GEnie Forth Interest Group RoundTable I call upon all enthusias tic exponents of the Forth approach to urge their Forth acquaintances to join or to renew their membership in the Forth Interest Group FIG will try to keep up its end of the bargain by constantly improving the quality of Forth Dimensions and by in creased attention to the needs of beginners to local chap ters and to community ac tivities for the promotion and benefit of Forth Irs time to vote with your feet if you walk away from FIG FIG will become merely a part of computer club history like the Homebrew society If you stay and if you bring others FIG will continue as your tutor friend and advocate Now it s up to you Jack Woehr JaxQwell UUCP JAX on GEnie Sysop RCFB 303 278 0364 FAX 303 422 9800 Total control with LMI FORTH For Programming Professionals an expanding family of compatible high performance compilers for microcomputers For Development Interactive Forth 83 Interpreter Compilers for MS DOS OS 2 and the 80386 16 bit and 32 bit implementations Full screen editor and assembler Uses standard operating system files 500 page manual written in plain English e Support for graphics
57. es 20 17 14 11 Along with the loop structure are furnished the four parameter modifying words END END SIZE and BACK These words allow you to specify in many different ways the order and the set of values that must be spanned by the index during the loop Examples and Test Suites The above set of control flow words has been presented by figures and somewhat by words Examples are important for two reasons e Clarify obscure or dubious points e Given the fact that only the constructing elements have been shown provide some interesting combinations of them Some probably haven t even been explored yet CONTROL Example Test whetherthe three variables A B and C contain 0 The so called ANDIF construct ABC allZero CONTROL A 0 WHILE B 0 WHILE C 0 2 WHILE A B C contain 0 CONTROL REPEAT Example One Traverse a list until a 0 list terminator is found addr REPEAT DUP WHILE REPEAT lastAddr or equivalently addr REPEAT DUP 0 WHEN REPEAT Example Two Given the address of a null terminated string leave the address of the first space or the EndAddr if no spaces are found addr REPEAT DUP C DUP WHILE BL WHEN 1 REPEAT CASE Example One Take a character code from the stack and qualify it WhatCharitIs char CASE pop char from stack and put into index The character with code I Forth Dimensions is w ASCII A WITHIN
58. es anyone know where to get it I found it in FIG s on line library on GEnie It is now available via e mail from FNEAS To get it send a message to fneas willett pgh pa us with the following body send MINI4T41 ARC path your email address RELATIVE to the INTERNET goes here Forth Dimensions You mustsupply an Internet relative e mail address with the path command Doug Preferred dwp willett pgh pa us Okay pitt sei twillet dwp From Nick Janow Subject Minimal Forth Elliot C writes The minimal Forth question has started up again small wordsets are more than an intellectual exercise Some processors are very small Small ker nels ease porting Minimal kernels might also be valuable on large processors If the kernel and a program can fitin the cache it will really scream along Nick_Janow mindlink bc ca From Andy Valencia Subject Looking for a small PD Forth for the 8086 Doug Philips writes send MINIAT41 ARC Iwas disappointed to find that there is no source available for this Forth If I m goingtoliveunderan opaque execution environment I usually will go for a richer one like F PC For a spartan environment I at least want the ability to customize at any level Just my opinion Andy Valencia From RCS Subject Haydon s levels of Forth In Glen Haydon s mag num opus All About Forth Grd edition his introduc tion page ix describes lev el
59. esired behavior If FOR is reached the loop is repeated TIMES times TIMES Similar to the 0 DO LOOP construct Takes a number from the stack there exists an error condition if the number is negative and puts it into the index a Before every iteration the value ofthe index is checked If I contains 0 the control structure is left and execution continues after TIMES Otherwise I is decremented and execution continues after TIMES beginning an iteration If and when TIMES is reached the process is repeated from point a pre incrementing model LOOP Start times step LOOP Start specifies the initial value of the index times specifies the maximum number of times the loop must be done it could end prematurely due to words like LEAVE WHEN and WHILE If times is negative there is an error condition Step and times are put on the return stack and start is put into the index also on the return stack a Before every iteration the times is checked If it is 0 the control structure is left and execution proceeds after LOOP If times is not 0 it is decremented and an iteration begins If and when LOOP is reached the step is added to the index then the process is repeated from point a Thus 10 beginning 4 times Forth Dimensions 5 step LOOP I LOOP types 10 15 20 25 while 20 beginning 4 times 3 step LOOP I LOOP typ
60. f these components using riFORTH as a base system Guy found only a 2 1 performance ratio between the fastest and slowest of these versions He concluded that other considerations of ten outweigh this perfor mance gain This certainly surprised me His tests and riFORTH are available on GEnie One of my favorite foods for thought is metacompila tion Guy dispels the myster ies of metacompilation and offers the metacompiler which he used for the benchmarking project This metacompiler also available on GEnie is capable of gen erating new Forth systems with various threading and memory segmenting schemes Guy s papers are a must for anyone who wants to experiment with Forth architectures It is easy to see why Guy Kelty won the Public Service award Thank you Guy ANDREW McKEWAN spiced up the Motorola 6805 emula tor with an optimizing Forth native code compiler This must be ambrosia for anyone working with the 6805 emulator He commented that after he tossed out the Forth Dimensions PC Yerk Classes Rick Grehan Peterborough New Hampshire Rick Grehan is a senior editor at BYTE magazine and the technical director of BYTE Lab He first encountered Forth over seven years ago when developing a music synthesizer control system built around a KIM 1 Since then he has used Forth on 68000 systems including the Macintosh the Apple II and the IBM PC He has also done extensive work on the SC32 stack base
61. h is simple with very nice de bugging tools For example a definition s object and source code are displayed side by side when editing encouraging users to see what is actually compiled Mike s paper was quite tasty If you have ever crashed your system by leaving an unbalanced return stack raise your hand lower your head or at least read on ROLAND KoruveK s paper describes and implements retur stack security using a temporary stack for compile time housekeeping While this takes a little more compile time it is well worth it for applications which allow users open access to the Forth environment In addition he added a prompt which dis plays the top three cells on the temporary stack when compiling a definition inter actively This allows a pro grammer to see what s hap pening as the definition is compiling Roland received the most in keeping with FORMI award a bottle of wine for this effort Guy Kzuy served up a very informative entree by speaking of his efforts to characterize tradeoffs in various Forth architectures Inhis paper he benchmarked and characterized 19 of the most common Forths See article in this issue Ed He also documented the se quences required to open a file and load a program the various assembler syntaxes and a brief on each of these Forths In addition he further isolated the effects of thread ing segmenting and regis ter usage by manipulating each o
62. ically equiva lent to the original Again refer to Figures Seven and Eight Another example will better clarify these concepts Suppose we have a null terminated string and must scan it for the first occur rence ofthe character or or equivalently Figure Three TIMES and LOOP compilation effects XXXX Pointer to Pointer to Pointer MAIN XXXX Completed LEAVE waving LEAVE COMPLETED LEAVING to End code code code XXXX ce to pem to px MAIN XXXX leaving LEAVE Completed LEAVE COMPLETED LEAVING toEnd code code code XXXX Pointer to Pointer MAIN XXXX leaving LEAVE LEAVING toEnd code code NM J main XXXX Pointer to Pointer MAIN XXXX Completed LEAVE COMPLETED to ee eL code code DOTT gem MAIN XXXX to End code XXXX MAN JCOMPLETED completed JLEAVING ceang de de XXXX QC man j Pee MAIN XXXX JLEAVING Dani JCOMPLETED Completed de code N man j completed XXXX MAIN p code JLEAVING Leaving XXXX CO leaving XXXX MAIN JCOMPLETED 0 code Completed XXXX code completed XXXXf MAIN 0 le XXXX main Forth Dimensions 27 March 1992 April etc 2 Exhaustion of the number of looping times speci fied Depending on the rea son why execution left the loop different behaviors can be requested Let s explain via example Suppose we must sear
63. ide Soviet Forth info vol 12 6 pg 11 reviews and surveys Best of GEnie vol 12 2 pg 36 serial line communication routines Interrupt Driven Communications vol 12 45 pg 18 sieve of primes benchmark Letter vol 12 82 pg 6 Re Letter vol 11 45 pg 6 Letter vol 12 2 pg 5 simulations From Clepsydras to Neural Nets vol 12 6 pg 6 stack effects testing Testing Toolkit vol 12 3 pg 31 standards ANSI Best of GEnie vol 12 6 pg 24 Letters vol 12 5 pg 6 Best of GEnie vol 12 3 pg 37 target compiling using a hosted target Interrupt Driven Communications vol 12 5 pg 18 Smart RAM vol 12 3 pg 28 tutorials Metacompilation Made Easy vol 12 6 pg 31 GEnie for Beginners vol 12 5 pg 34 Forth amp the Three Number Problem vol 12 4 pg 20 variables headless Anonymous Things vol 12 1 pg 8 variables stack Stack Variables vol 12 1 pg 18 vectored execution ForST A 68000 Native Code Forth Part 5 vol 12 6 pg 16 Forth Dimensions Continued from page 30 SIZE StartAddr ArraySize ElementSize Start times step dup gt R R gt END StartAddr LimitAddr ElementSize Start times step gt R OVER R R gt END StartAddr LastAddr ElementSize Start times step END swap lt swap this last word isn t really felt useful Moreover sometimes an array must be scanned in reverse order although it s easier to specify the array by its st
64. m Set value at index location m put val i idx check self Check bounds 2 Index gt offset array addr self Start of array Add index Store 7m Fill the array with value m fill val array addr self Get address elems self XV of elements 0 do 2dup i 2 Form address Store value loop 2drop Clear stack 7m init init method class KAEKKKKKEKK V String Akkkkk kkk A string object consists of a maximum byte count byte count and trailing null byte The maximum count does NOT include the preceding byte count and trailing null byte class string lt super object m allocate 1 ivar 0 ivar maxcount thestring Allocate space for the string n is of bytes to allocate n Save in max count For byte count amp null byte dup maxcount c 2 allot m b Clear the string m clear 0 thestring 7 zm put Store a string in the string object addr must point to a packed null terminated string addr See if the string will fit dup c maxcount gt if clear o amp mstacks abort String too long endif thestring 42 Forth Dimensions Copy contents of string object to destination address Note usage of Upper Deck Forth s operator m get addr thestring swap 7m Return the address of the first character of the string and the byte count m count
65. m screen files Forth Dimensions or only slightly different times Segments max size each Code Lists Heads n 64K Data Stack Blocks 64K Extended data M Register use AX SI IP CS codetlists heads BX U DI W DS datatstacks CX BP RP ES DX SP SP SS DS Next Nest 1 2 Unnest CS LODSW XCHG SP BP XCHG SP BP XCHG AX DI PUSH SI POP SI JMP DI XCHG SP BP XCHG SP BP LEA CELL SI DI NEXT NEXT g j Literal POP DI POP DI CS LODSW PUSH DI POP DI PUSH AX NEXT NEXT NEXT Constant Variable MOV CS DI DI 2 MOV CS DI DI 2 POP DX PUSH DI PUSH DI POP AX NEXT NEXT ADD AX DX Note the reported benchmarks were done on pF86 MSD which is a single segment version PUSH AX dated 1 20 87 The newer multi segment version detailed above should produce the same NEXT 1 The above information is presented with the generous permission of Elizabeth Rather of a ae PE C REI GE a aE Ea a a a a a a a a aT Segments max size each Code Lists Data Heads Stack Blocks 64K Register use AX W SI IP CS all BX tos DI DS CS CX BP RP ES CS DX SS SP SS CS Next Nest Unnest JMP NEST LODSW NEST XCHG SP BP XCHG SP BP JMP AX PUSH SI POP SI XCHG SP BP XCHG SI BP ADD AX 3 NEXT MOV SI AX NEXT Ges Literal MOV BX BX POP AX PUSH BX NEXT MOV BX AX LODSW POP BX MOV BX AX NEXT NEXT Constant in line Variable t JMP doVAR PUSH BX doVAR PUSH
66. n amp Wilton commercial ZEN X3J14 Tracy copyrighted Includes overlays to convert to fig 79 or 83 standard Some of these Forths are available in different packages including public share or commercial versions The version tested had the status indicated The non commercial versions are typically available at no charge the commercial versions are typically copyrighted The model does not imply compatibility These Forths cover a range of categories and complexi ties as Table One illustrates Theauthor presentedthis paper atthe 1991 FORML Conference Those who were unable to attend that event can order the complete proceedings from the Forth Interest Group March 1992 April Segment Models Assuming four logical segments not including the Stacks there are 15 different models The following lists these models and indicates their use by each of the Forths studied C L D H C L H D C L D H CL DH C D LH CLDH e F83 La MMS MVP PC pygmy ri Uni polyFORTH PM ZEN BBL HS FORTH UR FORTH F PC KForth Upper Deck Not found C L D H LC D H H C L D C D L H C H L D CLD H C D L H L D C H D H C L Descriptions Brief descriptions of most of the Forths tested are included at the end of this paper all assembly code is in a common format Benchmarks While studying the various threading stack and seg menting methods it seemed that a set of simple benchmarks could help in evaluating the performance trade
67. nesses 1 Expected to be third not last PMFORTH was the only example 16 bit Threading Nesting Primitives Sieve Subroutine 10 5 10 10 35 Direct 6 07 25 34 22 27 36 45 Indirect 10 34 37 28 33 48 56 I JMP NEXT 15 20 43 53 42 50 68 46 bit paragraphs F PC Din 11 46 30 45 32 bit BBL Dir 06 41 33 49 Fifth Sub 21 70 97 Forth Dimensions 9 March 1992 April Optimization Two of the Forths allowed optimization of user speci fied words The results obtained using the optimizers are shown in Table Four Comments Several aspects of these Forths make direct comparison difficult Most of them do not automatically optimize their code nor do they directly span multiple segments How ever riFORTH does automatic optimization polyFORTH has multiple C L H spaces BBL F PC and Fifth have up to one meg of list space F83 and MVP FORTH have a central NEXT MVP FORTH and PMFORTH have inefficient versions of NEXT KForth does high level parsing eForth interprets files via a serial link and LaFORTH uses a 64K text buffer Further Tests Because of the differences mentioned above a test set of five different versions of Forth were produced They were all derived from riFORTH a subroutine threaded Forth available in a minimum number of screens The versions including riFORTH were Name Model S R S Subroutine in Register Single riFORTH D R M Direct in Register Multiple D S M Direct on St
68. ng oldCSF INDEX STEP BackCounter n extra vO extra vi extra v2 previous RS data CSF points here Frame generated by RECOVERABEY 1 long 04 long 08 word OA long long 12 long 16 T beginning oldCSF INDEX a OldSP J previous RS data extra vO extra vi extra v2 CSF points here false Figure Five First CharSearch example TIMES dup NextCharGet WHEN 2drop true WHEN JCOMPLETED drop cursor false drop cursor false TIMES E See the flowchart in Figure Six CharSearch cursor keep initial cursor position textEnd cursor calculate 4 chars to end of text and character under cursor TIMES charGet TIMES dup ascii when dup ascii when LOOP Discussion and Examples l dup ascii when Standard Forth offers only one kind of definite loop with drop two variations DO LOOP and DO LOOP The DO LOOP has March 1992 April COMPLETED Cursor false Restore initial cursor position LEAVING 2drop true Drop initial cursor position 28 Forth Dimensions Figure Six Using JLEAVING with JCOMPLETED cursor textEnd cursor Q dup ascii gt LEAVING lt gt COMPLETED lt drop cursor false tried until now to be both a TIMES loop and a LOOP loop But when you try to do two things at once you do them inefficiently The drawbacks of the DO LOOP are Counter intuitive p
69. ng of the chip is anti climactic What caught my eye was the simplicity of the user interface It seemed so simple I wondered if my four year old daughter could learn to use it The emulator did what he needed no more no less Trivial deci sions which could distract him or any user from his thinking were all but elimi nated Thank you Chuck Dr Tinc gave the recipe for primordial soup by speci fying the modules needed to implement the Tieara Com puter Organism System He also supplied the code and theory for creating and kill ing simulated organisms with a challenge to add the muta tion and evolution compo nents Jerr Fox won the Pro gramming Virtual Hardware award with his simulation n F PC of the MuP20 run ning eFORTH As if running a simulation of CHuck Moont s latest chip wouldn t be enough fun Jeff also simu lated with eFORTH and DesqView parallel process ing with the F20 an enhanced MuP20 using FORTH Linda a bulletin board style parallel processor manager This must mean that Jeff is simulating virtual machines based on the simulation of a virtual processor which runs on a virtual machine i e eForth and DesqView Jeff s paper describes his efforts in detail Another tasty dish was Dr Tinc s talk about the Catalyst his contribution to the Human Genome Project the greatest reverse engineering project of all time The Catalyst is an auto March 1992 April i
70. ngs I read the word POSTPONE What is this How is it imple mented COMPILE R gt DUP CELL R 8 POSTPONE BL WORD FIND DUP 0 IF lt not found code gt THEN 0 lt IF COMPILE COMPILE THEN IMMEDIATE COMPILE is not part of ANS Forth and this definition here is exactly the wrong thing because it is rather tricky and dependent on a threaded code Forth POST PONE nice word awful name is not that what a Forth pro grammer does with the things he doesn t want to do first postpone them and then wait It postpones the compile time behavior thus it is COMPILE for non immediate words and COMP ILE for immediate What Forth words need to be coded in assembly to have a good perfor mance My estimation 30 till 50 will do Arithmetics AND OR XOR CELL UM UM MOD Stack DUP OVER SWAP ROT DROP Return Stack gt R R gt EXECUTE Memory CQ C MOVE FILL Tests 0 0 lt lt U Dictionary FIND or an appropriate ba sic of it Inner interpreter NEXT DOCOL DOES gt Control flow 33 BRANCH BRANCH LOOP LOOP If you compile words like CELLS DUP for 16 bits by expanding macros these words are enough to give good performance It is not very worthwhile to do much more This is exactly in the range of 30 to 50 words some more will not add much some less will decrease performance It may be worth it to add LIT as a code word since literals
71. nvesti the attributes studied gated for PC Forth and PC FORTH a now discontinued z product from LMI which resisted attempts to force code or and do not necessari ly list addresses to non word boundaries A 4 77 MHz 8088 correlate with did not exhibit this behavior and was used to obtain the results listed in Tables Two and Three real app lications Table Two Forth Type Empty Thread Nest1 Nest2 Prims Sieve Loads BBL D R L 4 0 5 9 41 4 41 4 33 1 49 0 4 3 eForth D S 4 3 42 2 F83 I S J 5 4 15 1 43 4 43 4 41 5 68 1 3 8 F PC D S P 3 1 11 0 46 4 46 4 30 3 44 9 0 9 Fifth S 7 1 20 9 20 9 70 4 97 2 HS FORTH I R 5 5 9 8 34 2 33 8 28 5 48 8 0 7 KForth D R 2 9 5 8 25 8 25 8 21 6 36 2 21 9 LaFORTH D R 3 6 5 8 29 9 29 7 26 9 36 3 0 5 MMSFORTH I S 5 2 10 0 37 4 37 4 33 4 55 6 0 5 MVP FORTH I SJ 142 19 8 53 3 53 3 50 8 8 5 PC Forth I S 3 6 10 0 34 5 34 5 32 7 54 8 8 4 PMFORTH D S 5 5 9 6 43 5 43 5 39 8 70 15 1 polyFORTH I S 4 8 9 9 34 5 34 5 31 5 52 9 1 0 Pygmy D R 3 2 5 9 32 0 32 0 23 5 39 7 4 7 riFORTH S R 13 1 9 6 9 6 5 4 9 6 34 8 6 8 UniForth I S 3 6 10 7 35 9 35 8 33 3 2 7 Upper Deck D R 4 2 5 9 32 1 32 1 23 8 39 8 0 5 UR FORTH D R 2 1 5 8 31 9 32 0 24 3 38 2 0 5 ZEN D R 3 6 6 8 34 1 33 8 27 4 44 6 4 4 he times in seconds all measurements on a 4 77 MHz 8088 PC March 1992 April 8 Forth Dimensions Table Three Forth Type Empty Thread Nest1 Nest2 Prims Sieve Loads ri
72. oard also held its first meeting The board is now composed of the following individuals Jobn Hall President Jack Woebr Vice President Mike Elola Secretary Dennis Ruffer Treasurer David Petty Nicholas Sointseff C H Ting The board welcomes comments from FIG mem bers Jobn Hall will return in the next issue with bis President s Letter Mike Elola I started out my involve ment in FIG as secretary of the business group that meets once a month to discuss the operation of FIG I came to my first meeting at the request of Kim Harris who consid ered me a good candidate to replace him as secretary Partly out of respect for him I agreed to become part of the business group I considered my role as that of an observer for the first couple of years Soon I overcame my initial skepti cism with the business team members and their qualifica tions By now I have gained substantial respect for the leadership skills of the out Forth Dimensions ers going president Robert Reiling as well as the current president John Hall CThe president presides over the business meetings and ends up having to referee some very delicate clashes during the long haul This experience gives me a background with FIG and its leaders so I feel confident that I can contribute My biggest concern for FIG has not really changed I have always been concerned that our collective FIG energies might not be applie
73. one of the Ax W SI IP CS few Forths in thisreviewthat BX tos DI DS listst data is compatible with the DOS CX BP RP ES linker It is well supported DX SS SP SS stacks with many extensionsanda Next Nest Unnest very good screen oriented MOV DI pfa editor Most source code is JMP NEST provided in screen files LODSW NEST XCHG SP BP MOV SI BP Complete source is available JMP AX PUSH SI INC BP A direct threaded 16 bit XCHG SP BP INC BP implementation with the top MOV SI DI of stack in a register A mul NEXT NEXT tiple DOS segment model Literal which interprets fromscreen MOV BX BX POP BX PUSH BX or text files Also available in NEXT POP BX LODSW OS 2 1 x 386 32 bit pro NEXT MOV BX AX tected mode and Windows NEXT implementations which are Constant Variable compatible atForthlanguage MOV DI value MOV DI addr level with the DOS version JMP doCON JMP doVAR PUSH BX doVAR PUSH BX POP AX Note supports binary over woy px pr MOV BX DI ADD BX AX lays NEXT NEXT NEXT 1 The above information is presented with the generous permission of Ray Duncan of Laboratory Microsystems Inc 2 Segment model for version tested varies with implementation ZEN ments max V1 5a 4 2 91 Tracy Code Lists 64K Data Heads Stack 64K copyright Register use Currently Sept 1991 AX W SI IP CS codetlists ZEN is the only Forth inthis BX tos DI DS datatheadst stacks review that is tracking the CX
74. ontain addresses of strings and we want to know if at least two among them are equal Using the set presented so far here is a solution CONTROL OORA MAIN JLEAVING leaving CONTROL 4 SIMPLE 1 Pointer to MAIN LEAVE toend code REPEAT CONTROL MAIN CONTROL 2 0 code REPEAT MAIN JLEAVING paving REPEAT SIMPLE Pointer to Pointer to MAIN AGAIN leaving LEAVE LEAVING to end code code REPEAT MAIN REPEAT 0 code 4 2 SIMPLE 1 Pointer to MAIN LEAVE to end code FOR amp CASE CASE and FOR compile similarly to CONTROL and REPEAT respectively but with SIMPLE replaced by INDEXED 26 Forth Dimensions CONTROL VO V1 S WHEN At least two equal WHEN V1 V2 WHEN At least two equal WHEN V2 VO WHEN At least two equal WHEN RN All different CONTROL This solution however is redundant and wasteful of space At the expense of computational time we could choose to check all three equalities by ORing them together at the end and using an IF ELSE THEN control structure Here I ll show a third solution that is neither redundant nor slow CONTROL VO V1 WHEN V1 V2 WHEN v2 V3 WHEN All different LEAVING At least two equal CONTROL The previous solution and its meaning may be explained in more general terms Let XXXX be the name of a control structure CONTROL TIMES etc Let s call the
75. ontrol structures dispose of an index like a DO LOOP in standard Forth That index usually named I has a different meaning among control structures In the CASE control structure forexample I contains the subject of our research As shown in Figure One a when inside a control structure we can use some control flow words that jump conditionally or unconditionally beyond the end of the control structure like LEAVE WHEN and WHILE or can jump to the word immediately after the beginning of the control structure like AGAIN and AGAIN Forth Dimensions Figure One a These control flow words can be used any number of times in any combination and also can be used in secondaries called from within the control structure allowing forexample WHILE to be defined as WHILE flag LEAVE XXXX WHEN WHILE 0 WHEN false A Depending on the imple mentation this feature may AGAIN AGAIN be available or not While not often used it is a rarely available but interesting fea ture that can provide new possibilities Looking again at Figure One a we see that apart from LEAVE WHEN WHILE AGAIN and AGAIN there are words that must be used WHEN m in pairs WHEN flag WHEN WHILE flag WHILE WHILE WHILE amp ecz Y always XXXX AGAIN XXXX 1false Y always Y LEAVE XXXX irue Y r XXXX
76. orth for embedded system devel opment on a budget I don t have room here to elaborate in detail well only three words I guess I do The only words needed to start de veloping on an embedded system are XG X and XCALL which fetch store and ex ecute a routine on the target system respectively Frank described how he imple mented these words in an MC68HC11 chip Having used a Cadillac four word variation I d have to say that Frank is right on target Anyone who has done serious development can appreciate the usefulness of version control and file com parison Wi BADEN presented his tools which he has ported many times over many sys tems over many years Wil distributed 20 pages of code forming the basis of a text file based source code con trol system His implemen tation is capable of compar ing and collating large files and keeps all versions of a file in a compact format It is a useful tool in any language I found it interesting that some of those who used blocks did not see a need for such tools Perhaps the modularity of blocks com bined with the fact that the majority of those using blocks used date stamping reduces the need for such tools Those interested in receiving a copy of this code on disk should contact Wil Guy Key called our at tention to some of the tradeoffs of interpreting March 1992 April source from text files By adding some intelligence to parsing words Guy simpli
77. osition of loop start and end end start instead of start end This has allowed the DO LOOP to work as TIMES loop when used like 0 DO LOOP If the positions had been start end we would have had to write 0 SWAP DO LOOP Slow execution when working like TIMES because in stead of decrementing and checking a flag like the TIMES construct the DO LOOP must increment and check against a limit This drawback coupled with the appearance of Forth processors has led to the use of FOR NEXT in recent times Slow execution when working like DO LOOP because the step is pushed and popped from the stack atevery iteration of the loop without any valid reason Forth traditionalists could sustain that in such a manner itis possible to use a computed loop step that varies from one iteration to the next but we can observe that real life cases Forth Dimensions have a constant loop step and moreover a much more flexibleloopis furnished by the FOR FOR construct which allows for any test at any step Cor any new computed index value and any model of loop pre increment or post decrement etc Establishing the Best Input Characteristics for Loops Definite loops are usually used for doing something a certain number of times while allowing the index to assume a predefined set of values The set of values may be specified by three out of the following four parameters Start First index value end Last index valu
78. pair of words like WHEN WHEN WHILE WHILE OF OF etc as specialized leaving points while words like WHEN andWHILEareunspecialized If such an occurrence is found we must substitute a space for it and leave on the stack SubstitutionAddr 1 true otherwise we must leave a false on the stack Here is a solution using LEAVING StringAddr FOR I C WHILE false WHILE I CQ ascii WHEN I C ascii WHEN I CQ ascii WHEN 1 STEP LEAVING bl I C I 1 true FOR Maybe the above would read more clearly if written infor mally as FOR I C WHILE false WHILE I CQ ascii ORIF I C ascii ORIF I CQ ascii ORIF 1 STEP JORWHEN bl I C I 1 true FOR The COMPLETED Clause A similar problem is encountered in definite loops A definite loop like TIMES or LOOP may end for two reasons 1 Premature end due to leavers like WHEN WHILE LEAVE leaving points Thus the code in Figure Seven is logically equivalent to that in Figure Eight In other words suppose we have a control structure with a LEAVING embed ded in it If we transform all unspecialized leaving points into the corresponding spe cialized pair inserting into the specialized pair the code contained between the original LEAVING and the end of the control structure then deleting the code from LEAVING inclusive to the end of the control structure exclusive we obtain new code that is log
79. r a definition of their workings Inside indexed control structures three words are sup plied to reference the index and its value I indexValue Leaves on the stack the value of the index March 1992 April Figure One b TO I newValue Stores into the index a new value OF if l x always Y WIN x K OF III STEP valueToAdd Adds to the index a value stepping it STEP is equivalent to I TO I WITHIN lf ower e upper lower upper WITHIN WITHIN Y always is equivalent to Description of Ill lower upper WITHIN Todd T iN Resist Bape LTO TTR WHEN WHEN t Curly Control Structures otherwise J Given the previous 0777777777777 framework now I am going to illustrate briefly the use of if leX1 or leX2 or each of these control struc IN or l X n 1 or l Xn tures and how they work Later we will see some ex amples WIE X1x2 Xnn IN L CONTROL CONTROL otherwise X OF OF is equivalent to X WHEN WHEN X1X2 Xnn IN IN is like X1X2 Xnn over roll IN WHEN WHEN always Y y IN 1111 The word CONTROL marks the beginning of the control structure The word CONTROL marks the end They may be used as label points when jumping via words like WHEN WHILE AGAIN AGAIN and word pairs like WHEN WHEN etc ANDIF structures are easily implementable with these ingre
80. r mnemonics of the various Forths studied as hinted at above but does make it easier to understand and compare the examples CACHE NAME 30 EXPECT cr BBLBENCH cr my old version did not have USING L SIEVE FIV cr C cr LA LA HI cr from DOS BT size handle READ TP couldn t find a better way must be one 400 LOAD cr non DOS see MMSBENCH 342 or 171 LOAD cr see MVPBENCH INCLUDE PCBENCH cr or 1 LOADUSING PCBENCH cr PYGBENCH cr 600 PYGBENCH 2 UNIT cr 1 LOAD cr RIFORTH RIBENCH cr from DOS 2 LOAD cr screens start from 1 UNIFORTH UNIBENCH cr from DOS CAPS ON RELOAD BENCH cr INCLUDE ZENBENCH cr cr 1 LOAD cr 1 LOAD cr LT RUN cr BT OPEN handle cr LT RUN cr 1201 LOAD cr or 1 LOAD cr L How to open a file and load a program in the various Forths Forth Case Method BBL screen file 0 CACHE NAME 8 OPEN CACHE eForth text lines via serial channel F83 screen file OPEN F83BENCH F PC text file FLOAD BENCH lt cr gt Fifth text file HS FORTH text file FLOAD HSFBENCH lt cr gt LaForth text file BT MT TEXT LABENCH Z 0 LT DROP TP XC MMSFORTH Screens MVP FORTH Screens PC Forth screen file text file INCLUDE PCBNECH cr PMFORTH screen file OPEN B PBENCH lt cr gt in PMfile 1 SFLOAD lt cr gt polyFORTH screen file CHART PCBENCH Pygmy screen file NAMEZ 2 OPEN riFORTH sc
81. ranzenbach Subject List of Forth words Hi I m searching for a list of Forth words that is required to be implemented in assem bly language to create a reasonable but very small in size Forth environment Is there anyone who has assembled a list containing those primitives and possi bly the implementation of the higher level words Happy New Year Ralf From Milan Merhar Subject Minimum Forth en vironments 32 Reply to two recent posts I have a small 6809 system in order to learn some assembly Just for fun D I want to write a small Forth environ ment What is about the minimum set of Forth words as a starter Thus using this minimum I write the other words in Forth Regards Ton t Lam I m searching for a list of Forth words that is 7e quiredtobe implemented in assembly language to create a reasonable but very small in size Forth environment Is there anyone who has assembled a list contain ing those primitives and possibly the implemen tation of the higher level words Ralf I ve sat in on a couple of informal discussions on this subject The general consen sus is that about ten words are sufficient Stack ops DUP create a stack element DROP destroy a stack ele ment SWAP move stack element gt R and R gt stack exchange Arithmetic logic LITERAL constants etc NAND sounds silly but you can synthesize anything else out of i
82. reen file UniForth screen file 1 LOAD lt cr gt Upper Deck text file UR FORTH screen file ASM USING LMIBENCH ZEN text file Forth Dimensions 13 March 1992 April n max 12 Code 64K Heads n 64K Stack Block 64K Register use AX W SI IP CS code BX tos lsw DI 0 lit DS liststdata seg off of CX tos msw BP RP ES lists data 32 bit addr DX SP SP SS stacks Next Nest bigger faster Unnest LODSW XCHG SP BP XCHG SP BP JMP AX PUSH SI POP DS PUSH DS POP SI XCHG SP BP XCHG SP BP MOV DX xxx pfa seg NEXT MOV SI xxx pfa offset MOV DS DX NEXT Qe m m H Nest slower smaller MOV ES CX MOV ES CX MOV DS xxx_pfa seg MOV CX ES BX 2 POP ES BXt 2 MOV AX xxx_pfa off MOV BX ES BX POP ES BX JMP DOCOL NEXT POP CX POP BX DOCOL XCHG SP BP NEXT PUSH SI PUSH DS XCHG SP BP MOV DS DX MOV SI AX NEXT Constant in line Variable PUSH BX PUSH BX POP DX PUSH CX PUSH CX POP AX MOV BX lsw MOV CX xxx_pfa seg ADD BX AX MOV CX msw MOV BX xxx_pfa off ADC CX DX NEXT NEXT NEXT I a8 a De SF Peay EIN ments m iz h Code Lists Data Heads Stack Blocks 64K Register use AX SI IP CS all segments BX DI DS CS CX BP RP ES CS DX SP SP SS CS Next Nest Unnest NOP CALL NEST LODSW XCHG SP BP XCHG SP BP JMP AX PUSH SI POP SI XCHG SP BP XCHG SI BP POP SI NEXT NEXT Qo Literal POP BX POP BX LODSW PUSH BX POP BX PUSH AX NEXT NEXT NEXT
83. s do not Some require significantly more memory for a given application than others The segmentation information and the code fragments presented for the Forths provide some insight as to the advantages and limitations of the various Forths Another consideration that is becoming more important at least in the PC world is the ease with which foreign libraries and facilities DLLs OLE etc can be accommo dated Most ofthe Forths reviewed have no built in capability a few do If this is an important consideration one should investigate the support for interfacing to other programs and libraries that may be available Most ofthe Forths reviewed claim to support multitasking If this is an important feature be warned that the support provided is usually minimal Further almost none of these Forths provide useful multiuser support Forth For those wishing to evaluate Forth important consider ations include ease of use induding DOS interface and available editors standardization and adherence to avail able Forth texts Another consideration that is important when consider ing a Forth is whether you are going to approach it as a black box or whether you are interested in understanding its internal structure To obtain the maximum advantage from Forth one should understand both the rational for its structure and its inherent strengths and weaknesses This requires at least some understanding of the internals of the version being
84. s of Forth Level 0 includes the 63 func tions Charles Moore has often listed as the basis of Forth They lack any form of input or output to stor age devices Level 1 fig with rudimentary Forth Dimensions storage Level 2 MVP with a richer function set Level 3 F83 Level 4 F PC Level 5 The future 32 bit everything Can someone cite where Moore defined his funda mental 63 functions Regards rcs From Ton t Lam CRC Subject Min Forth andgood performance Some time ago I asked for the minimum Forth sys tem It turned out that nine words are necessary How ever the performance is likely to be lazy I can imagine I started with EMIT and KEY though Now as I go along it ap peared to be very easy to add new words in assembly My question now is What Forth words need to be coded in assembly to have good per formance My estimation 30 to 50 will do Now I am asking How is a number officially com piled into a word Le how to distinguish a number from an execution address In other strings I read the word POSTPONE What is this How is it implemented Ton t Lam From Bernd Paysan Subject Min Forth andgood performance Ton t Lam CRC writes How is a number offi cially compiled into a word Le how to distin guish a number from an execution address In basic words LIT R DUP CELL gt R LITERAL POSTPONE LIT IMMEDIATE In other stri
85. ster use AX BX Cx DX W Next _ MOV AX ST INC SI INC SI MOV BX AX MOV DX AX INC DX JMP BX d t POP BX MOV AX BX JMP APUSH Constant Segments max size each SI DI BP SP S INC DX DEC BP DEC BP MOV BP SI MOV SI DX JMP NEXT 1 POP BX POP AX MOV BX AX JMP NEXT Variable Code Lists Data Heads Stack Blocks 64K Q Uu XX WM 1 x LODSW XCHG AX BX JMP BX 8 _ POP BX PUSH BX NEXT Constant INC BX INC BX PUSH BX NEXT March 1992 April SI DI BP SP IP RP SP Nest DEC BP DEC BP MOV BP SI INC SI INC SI MOV SI BX NEXT 1 POP BX POP BX NEXT Variable INC BX INC BX PUSH BX NEXT cs DS ES SS cs DS ES SS all CS CS all CS cs cs 18 Unnest MOV SI BP INC BP INC BP JMP NEXT Literal MOV AX SI INC SI INC SI JMP APUSH POP AX POP BX ADD AX BX JMP APUSH Unnest MOV SI BP INC BP INC BP NEXT Literal LODSW PUSH AX NEXT t POP AX POP DX ADD DX AX PUSH DX NEXT MVP FORTH V1 0405 03 5 17 85 MVP public One of the first 79 Stan dard Forths Based on the fig FORTH 8086 implemen tation model Source code in direct blocks screens An indirect threaded 16 bit implementation with the top of stack on the stack A single segment model which interprets from direct blocks screens Notes NEXT and NEST seem to be a direct transl
86. t Address space access and 6 orC and CQ if you wish P and P for I O space port access if your CPU has such a thing Dictionary extension CREATE This is a very sparse list Even the rawest bootstrap system would probably de fine a richer set of primitives than this Forexample and and would be a Jot nicer ifthey were primitives rather than colon definitions made of tens or hundreds of primitive ops Similarly words like FIND are very nice to have Amore sensible minimum set of primitives may be found in the eForth model no doubt an implementation of it is available for most any CPU you re interested in Also look at the current ANS Forth pro posal the Core wordset will give you a good idea as to what functions are needed although lots of them won t be primitives in an imple mentation such as you de scribe Discussions of the an gels on the heads of pins variety continue as to which primitivesbelong on the short list For example if you have R you could synthesize DUP Rob Chapman once pro posed a set of primitives for a Forth machine that had two kinds of arithmetic logi cal ops the first kind returns the value of the result the second kind returns the re sulting carry bits Regards Milan J Merhar From Doug Philips Subject Looking for a small PD Forth for the 8086 Ralf E Stranzenbach writes Tve heard about a small Forth named MINI4T41 Do
87. t of GEnie this month Elsewhere in this issue you will find supplemental code to the object oriented Forth PCYerk by Rick Grehan and a meaty discussion of control structures by Kourtis Giorgio that will be con cluded in the next issue Fi nally Guy Kelly shares his FORML paper with FD readers It is a significant piece of work that shows what goes into evaluating Forth systems and we thank him for allowing us to pub lish it here It demonstrates the difficulty of doing head to head product compari sons and is the first substan tial attempt we know of to do so thoroughly and objec tively Pay special heed to his warning that benchmark excellence alone does not mean that any single system will be the right one every purpose Manlin Ouverson Editor Forth Dimensions Volume XIII Number 6 March April 1992 Published by the Forth Interest Group Editor Marlin Ouverson Circulation Order Desk Anna Brereton Forth Dimensions welcomes editorial material letters to the editor and comments from its readers No responsibility is as sumed for accuracy of submissions Subscription to Forth Dimen sions is included with membership in the Forth Interest Group at 40 per year 52 overseas air student rate available For membership change of address and to submit items for publication the address is Forth Interest Group P O Box 8231 San Jose California 95155 Administrative offices and adv
88. t paragraph address n 64K segments for lists data or heads Top of Stack Location Primitives Prims QQ XX Exercise variable constant DUP SWAP OVER DROP VARIABLE LOC 10 CONSTANT TEN NULL TEN DUP LOC SWAP OVER DROP Q 30 000 0 DO NULL LOOP QQ 5 0 DO Q LOOP Other Benchmarks To satisfy the curious the standard Sieve benchmark and a simple interpreting time benchmark are included X Sieve Sieve 10 0 do DO PRIME loop 8190 CONSTANT SIZE CREATE FLAGS SIZE ALLOT DO PRIME FLAGS SIZE 1 FILL 0 SIZE 0 DO FLAGS I C IF I DUP 3 DUP I BEGIN DUP SIZE lt WHILE 0 OVER FLAGS C OVER REPEAT THEN LOOP Table One Stack Segments in reg N C m L D n H S B on stack 1 sep heads on stack 1 on stack 3 C D S mL H in reg N2n C n L D n H S in reg 5 C L D H S in reg 2 2nd for text files on stack 1 non DOS 2 C L D H on stack 1 on stack 1 on stack 2 C L D H S on stack N n C L H D S n D in reg 1 in reg 1 on stack 1 in reg 5 C L D H S in reg 4 C L D H S in reg 2 C L D H S 1 Width given as stack width token width os indicates token is an offset into the code segment pp indicates token 2 Code List Data Head and Stack m L indicates one meg of paragraph space for tokens n L D or n H indicates Forth Dimensions 7 March 1992 April Interpret time benchmark Interpret time Loads
89. themselves The neural network an in put into the expert system March 1992 April ce ec e e e e e e x e A kx e x x STORAGE CLASSES ck koc koc Kak KEKE oce oe eoe e ce ceo ck ck ok e e e x e e e e e e x x KK KEK xx ldarray 1 dimensional array KEK e ehe che cede cce ke ck ck oe ce ck KKK KEKE eG e KKK x class ldarray 2 ivar 2 ivar lt super object nelems X 4 of elements in the array eleimsize Size of each element in bytes Allocate space for the array m allocate n dup nelems elemsize allot 7 Store of elements Set aside space in vars segment Set the elements size tm setsize n elemsize im Initialize the array n is of elements in the array m is the element size m init nm setsize self Set the element size allocate self Allocate memory m X Return the of elements m elems n nelems im Return length of data area m length n length self Header information elems self elemsize Length of data portion Add it all m Do bounds checking for index m idx check i i dup 1 nelems gt Check bounds if clear o amp mstacks Clear the stacks abort Array bounds exceeded endif 7m Return the address of the array members start m array addr addr elemsize 2 7m class 40 Forth Dimensions KKKKKKKKKKKKK V xx byte array okck ck k ko
90. timizers available with several of the Forths can result in gains of from three to more than 30 March 1992 April The following considerations would seem at least as important quality and completeness of the implementation availability and appropriateness of additional modules availability and quality of support including documenta tion e transportability of source and ease of use application size supported Notice that price is not in the above list If you are going to use the Forth for a commercial application even the highest priced commercial Forth is inexpensive if it has features that are important to your application and will allow you to finish your project significantly faster than you otherwise would A particular consideration these days is the size of the application supported Most commercial applications are big and growing bigger especially those that have to run under most of the current graphical user interfaces The typical single segment Forth even with overlays is hard pressed to support the bloated programs that seem to be required Even embedded systems are getting larger although mini mizing their size is still very important Most of the Forths reviewed do not easily support large programs and among those that do there are a variety of trade offs that need to be considered Some of the Forths that seemtosupport large programs have limitations on the space available for code and or data other
91. tion suite for testing whether a Forth system is compliant His pa per discusses the labeling and documentation aspects of this effort Dennis is look ing for people willing to work with him to develop the suite In my opinion a common test suite would force inter pretation of the standard in areas where it is unclear and in a sense test the validity of the standard itself Dennis can be contacted at Forth Inc I could talk about the wine and cheese parties which were fun the im promptu talks there were some gems and the work shops which were lively that are the less formal parts of FORML but I m running out of room The presenta tions were wonderful and I look forward to reviewing many of them in detail but what I found to be at least as inspiring were the people themselves their experi ence their personalities and their insights The presenta tions will be published shortly in the conference proceed ings but this dimension of FORML will only be captured in the minds of those that attended March 1992 April NEW FROM THE FORTH INTEREST GROUP More on Forth Engines C H Ting Editor More on Forth Engines Vol 14 RTX Pocket Scope eForth for muP20 ShBoom eForth for CP M amp Z80 XMODEM for eForth Vol 15 Moore New CAD System for Chip Design A portrait of the P20 Rible QS1 Forth Processor QS2 RISCing it all P20 eForth Software Simulator Debugger 15 00 each Seeing
92. try vol 12 46 pg 20 control flow directives text interpreter support of Interactive Control Structures vol 12 42 pg 28 Letter vol 12 1 pg 7 deferring compilation compiler directives for ForST A 68000 Native Code Forth Part 5 vol 12 6 pg 16 design language driven Letter vol 12 43 pg 5 design philosophy Forth Dictionary Structures and Forth vol 12 42 pg 26 division 8086 Reliable 8086 amp 80286 Division vol 12 4 pg 5 division floored Best of GEnie vol 12 5 pg 36 Positive Divisor Floored Division vol 12 1 pg 14 dynamic memory management Best of GEnie vol 12 3 pg 37 Dynamic Memory Allocation vol 12 3 pg 17 Dynamic Virtual Memory Management vol 12 3 pg 7 Banking on the R65F11 vol 12 1 pg 23 Stack Variables vol 12 1 pg 18 education of Forth programmers Best of GEnie vol 12 46 pg 24 Best of GEnie vol 12 44 pg 30 error handling Letter vol 12 5 pg 5 Best of GEnie vol 12 43 pg 37 file operations generic ForST A 68000 Native Code Forth Part 2 vol 12 3 pg 34 floating point arithmetic Pencil and Paper Arithmetic vol 12 6 pg 22 ForST A 68000 Native Code Forth Part 3 vol 12 4 pg 26 Forth Dimensions magazine Letter vol 12 1 pg 6 Forth Interest Group President s Letter vol 12 6 pg 5 Best of GEnie vol 12 5 pg 36 Letter vol 12 2 pg 5 Forth leaders Best of GEnie vol 12 46 pg 24 history of Forth Editorial vol 12 4 pg
93. ul consequences when the stepis not aligned to the start see later examples while maintaining historical continuity when the end is aligned to the start Additional Support Words for Definite Loops Keeping the above discussion in mind let s consider the various ways we can specify an array on which we have to work StartAddress elements SizeOfElements StartAddress SizeOfArray SizeOfElements StartAddress LimitAddress SizeOfElements limit address is the first address not belonging to the array StartAddress LastElementAddress SizeOfElements So the generic pattern is StartAddress 77 SizeOfElemenits Thus let s define three modifiers SIZE END and END that operate on three numbers and convert them to the standard format start times step Continued on page 37 For subtle minded readers The kind of division used rounded toward negative infinity or toward zero doesn t bother us except for unusual cases like 10 start 9 end 2 step where if we round toward negative infinity the result of the division is negative and so correctly the looping construct issues an error message If we round toward zero the loop will execute zero times without issuing the error message Forth Dimensions In lieu of the usual President s Letter we offer tbe following statements made bythe newest members of the Forth Interest Group s Boardof Directors Theywere installed last November at the FORML conference where the new b
94. we were seated that I noticed there weren tany menus How nice it was to not worry about what to eat Could there be a GUI lesson here I mused I enjoyed my French dip sandwich as Guy GROTKE gave me bits of information to mentally munch on He He supplied the code and theory for creating and killing simulated organisms tercepted with a big hug by Wa Banen who makes it a point to greet everyone at FORML in this fashion It s a nice way to start Asilomar is a beautiful retreat sprinkled with wind swept Monterey pine and cypress trees Weathered boardwalks cut through the struggling vegetation in the dune restoration project leading to a beach of white sand and deep blue water a living picture Early morn ing finds deer foraging among March 1992 April talked about the three di mensional mouse project he has been working on and the ADSP2105 chip that costs less than 10 00 apiece Adjourning from lunch we assembled in Merrill Hall a large rustic building on top ofa small knoll Ropert REING began the conference by welcoming us and announc ing the agenda Mke Perry moderated Having enjoyed a good lunch I looked for ward to the veritable smor gasbord of knowledge about 38 to be served The first presentation came from Mike Froma His eyes lit up as he described HomeComing Forth his implementation of a mini mal Forth system on top of Apple s HyperCard environ ment HomeComing Fort
95. windowed graphics in bit blit windows mono cga ega vga all ellipsoids splines bezier curves arcs turtles lightning fast pattern drawing even with irregular boundaries powerful parsing formatting file and device I O DOS shells interrupt handlers call high level Forth from interrupts single step trace decompiler music compile 40 000 lines per minute stacks file search paths format to strings software floating point trig transcen dental 18 digit integer amp scaled integer math vars A B IS C compiles to 4 words 1 4 dimension var arrays automatic optimizer for machine code speed PROFESSIONAL LEVEL 399 hardware floating point data structures for all data types from simple thru complex 4D var arrays operations complete thru complex hyperbolics turnkey seal interactive dynamic linker for foreign subroutine libraries round robin amp interrupt driven multitaskers dynamic string manager file blocks sector mapped blocks x86 amp 7 assemblers PRODUCTION LEVEL 499 Metacompiler DOS ROM direct indirect threaded systems start at 200 bytes Forth cores from 2 kbytes C data structures amp struct compiler TurboWindow C MetaGraphics library 200 graphic window functions PostScript style line attributes amp fonts viewports ONLINE GLOSSARY 45 PROFESSIONAL and PRODUCTION LEVEL EXTENSIONS FOOPS with multiple inheritance 79 TOOLS amp TOYS DISK 79 286FORTH or 386FORTH 299
96. y person to be more self sufficient Thank you Tim not just for your presentation and soft ware but also for your re cent neural network articles in Fortb Dimensions Plenty of treats were to be had for the hardwired Forthers BraD RODRIGUEZ discussed his PISC 1 Pa thetic Instruction Set Com puter which uses 1976 TTL technology has a mere 2100 gates and implements Forth in microcode PISC 1 adds a whole new dimension to the phrase lean and mean Dr Tic showed us how we can create our own chips at the kitchen table by using the National Security Agency s public domain CMOSN macro cell library So where s the DIP Well Dr Ting showed us that too by using the library to create a 40 pin Data Comparator Chip With plenty of hand waving which he promised us in his paper JOHN RIBLE discussed his QS2 QuickSand 2 project pro posal for a graduate level VLSI design project at the University of California at Santa Cruz It is a 16 bit mi croprocessor with classical RISC features which has among other things a hard ware based threaded code interpreter CHUcK Moore demon strated his MuP20 chip emu lator software which dis played each layer of the chip in a different color Using the seven button interface he scrolled through the chip March 1992 April displaying layers both indi vidually and combined Chuck pointed out that since the chip can be emulated the circuitry is tested and the maki
Download Pdf Manuals
Related Search
Related Contents
Fisher-Price P5600 User's Manual Melissa 638-141 User's Manual Extensión Inalámbrica de Señal Remota IR 15-1950 Samsung PS-42V4S Bruksanvisning MDS 3.0 Resident Assessment Manual Chapter 3 Section A Samsung Galaxy Next User Manual Fluke 54200M01 Video Signal Generator Data Bedienungsanleitung DJ Lase Pro 1200 RGB láser manual de instrucciones Copyright © All rights reserved.