REAL 'oldies' might remember "Forth" !! - Page 1
Forum section: electronics / general

author: GlennSprigg
author_rank: Super Contributor
timestamp: December 29, 2017, 02:36:16 pm
content: After the response to my question about 'dBase', I thought I would go back a few MORE years, and either'remind' or "edumicate (haha)" the 'young-uns' about a very old 'Language' called "Forth", dating back to1968, and designed by "Charles Moore", which UNFORTUNATELY has fallen into dis-use today !!Sorry for my initial 'ramblings' here, but it was a Language much before it's time! In fact in it's day, it WASused in the Chips of specialized hand-held Engineering/Industrial 'Calculators' etc, and for automated controlof many machines, (imagine a 'washing-machine' today!!), and should have had a lot better recognition TODAY.It was considered the 'Fourth' generation for computer hardware, but the original 'computer' utilized could onlyhandle a '5-bit' filename, so "Fourth" became 'Forth'. (Please hang on.... I'm getting there !!)This 'Language', was initially defined with what they called 'Primitives'. An original 'Subset' of 'Words/commands'that were used to 'Create/Define' higher & higher level words, including such high level words along the way !To that in the end, ONE 'word' could describe the operation of an entire application ! (This is hard to grasp...).(You were effectively creating your own tailored 'language' along the way, and the original/new commandscould be 'written' out in a meaningful 'Sentence' like structure...... For Eg.... The command 'RunNow'......"Open Valve 1 Till Sensor 2 High. Close Valve 1. Start Pump 3".... etc etc...W.T.F. ? Yep!, that's how you would 'program' it, using these higher level 'words'.The ENTIRE software package would take up between 20k & 40k on a PC, and something like 20k on a Commodore-64.It's 'NUMBERING' system was definitely not for the 'Feint-Hearted' today...and utilized the "RPN" system...."RPN" stands for "Reverse-Polish-Notation", and when explained, it all makes sense !!THIS mathematical system has NO 'Parenthesis' characters in an equation, so placement it critical. Let's explain....NORMALLY, we may say something like.... 2+(3*4) where obviously 3*4=12, + 2 = 14.This is NOT the same as ... (2+3)*4 where 2+3 = 5, * 4 = 20 !!!If we WANT the 1st scenario to be valid, using RPN, we would say..... 3,4,*,2,+ (no parenthesis)If we WANT the 2nd scenario to be valid using RPN, we would say..... 2,3,+,4,* (no parenthesis)........AArgh... why would we do this !!!!!...... EVERYTHING in 'Forth' utilizes STACKS. Numbers & operands placed on'LIFO' (Last-In-First-Out) stacks. It is the basis of the whole languageWhen you understand STACK manipulationyou are 90% there....You can STILL download & play with 'FORTH' from numerous sources, including versions now for the PC that includequite good graphical control/display too.....THIS 'LANGUAGE' SHOULD NEVER HAVE DIED' xox

author: glarsson
author_rank: Frequent Contributor
timestamp: December 29, 2017, 03:08:04 pm
content: Also worth mentioning about Forth:Both an interpreter and a compiler at the same time.Integer division rounds towards minus infinity, not towards zero, i.e. -1/3 is -1, not 0.The programmer can extend the compile with new behaviour, e.g.:Imagine we need to create arrays. In Forth that would be something likeCode:5 ARRAY FOO ( create array FOO with five elements )42 1 FOO ! ( store 42 in second element of FOO )1 FOO @ ( get value from second element of FOO )How do we add ARRAY to the interpreter/compiler?Code:: ARRAY CREATE 2* ALLOT DOES> SWAP 2* + ;The colon enters compiler mode, compiling the new word ARRAY. The following words until the DOES> is executed when the word ARRAY is used. The words after DOES> is the inherited code executed when words created by using ARRAY (FOO in the example above) is executed. The semicolon ends the definition of the word ARRAY.Btw, I don't think Forth is dead. It is just hiding in embedded systems.Also, all Sun workstations with SPARC processors and Apple computers with PowerPC processors used a Forth system for booting.In the mid eighties I developed and sold a Forth cross compiler for use with Z80 processors. At the same time it could interpret and compile code both for the host system and the target system, i.e. words like ARRAY above could have different behavior in the host system and the target system (add info to symbol table on host system, reserve space on target system). Funny days.

author: chris_leyson
author_rank: Super Contributor
timestamp: December 29, 2017, 03:45:00 pm
content: I remember fig FORTH running on a 6502, painful.

author: Macbeth
author_rank: Super Contributor
timestamp: December 29, 2017, 03:52:01 pm
content: I dabbled with FORTH on a BBC Micro back in the day, but much preferred the inbuilt BBC Basic and its inline 6502 assembler.

author: glarsson
author_rank: Frequent Contributor
timestamp: December 29, 2017, 03:52:45 pm
content: Quote from: chris_leyson on December 29, 2017, 03:45:00 pmYes, the limited stack, addressing modes (and that page 0 crap) of the 6502 was not a good match to Forth.

author: GlennSprigg
author_rank: Super Contributor
timestamp: December 29, 2017, 04:00:01 pm
content: Dear 'Glasson' thank you for your informative reply !!!I was trying to keep it simple, but YES it's Compiler added a LOT to what could be done !You say that 'Forth' is not dead, (and should not be xx).......Why do we keep trying to re-invent the wheel Chris

author: Neomys Sapiens
author_rank: Super Contributor
timestamp: December 29, 2017, 05:01:00 pm
content: Yup. I darkly remember that someone made a µP specifically tailored to this language. Somewhere here a Forth manual must be buried - I know how it looked, but not where it is. That it hasn't made its way into the central index is a sign that it hasn't benn needed for a long time.But for notorious HP calculator users, it was pretty self explaining.

author: glarsson
author_rank: Frequent Contributor
timestamp: December 29, 2017, 05:18:31 pm
content: There have been many processors designed to run Forth, but the first (NC4000) was designed by Novix Inc (founded by Chuck Moore). Not only did Chuck invent Forth, but he also designed a processor to run it.https://en.wikipedia.org/wiki/Charles_H._Moorehttp://users.ece.cmu.edu/~koopman/stack_computers/sec4_4.html

author: Howardlong
author_rank: Super Contributor
timestamp: December 30, 2017, 10:47:15 am
content: Anyone else cut their Forth chops on a Jupiter Ace?https://en.m.wikipedia.org/wiki/Jupiter_AceIf you were an assembly language programmer the concepts were pretty easy, and wow, did it perform compared to the BASIC machines out there at the time.As well as learning Forth on it, I remember trying to teach Forth on it. That was not my finest hour.

author: glarsson
author_rank: Frequent Contributor
timestamp: December 30, 2017, 11:17:50 am
content: One place where the spirit of Forth certainly lives on is in PostScript and PDF.

author: rhb
author_rank: Super Contributor
timestamp: December 30, 2017, 03:20:21 pm
content: The demise of forth is greatly exaggerated. Check out Matthias Koch's Mecrisp.http://mecrisp.sourceforge.net/There are a vast number of forth implementations available on the web as well as many forth specific mailing lists. Now we get several new programming languages every year, most seem to be yet another variant of PL/I with its own "specialness". I think forth has quietly continued amidst the din of "new and improved".I loved forth on the 6502, but the implementations I had for the Vic20 and C64 were complete crap. Very buggy and almost no documentation. I only got as far as writing a decompiler before another round of graduate school intervened and I started playing with a MicroVAX II in a BA123 "world box".

author: stj
author_rank: Super Contributor
timestamp: December 30, 2017, 05:02:17 pm
content: and reading this thread, i am reminded about why i learned assembly on the 6502.under 60 commands to rule the world, less than 20 really used - and damned fast.

author: rhb
author_rank: Super Contributor
timestamp: December 30, 2017, 06:10:43 pm
content: When you compared it to an 8080 or Z80 it really was sweet. I still like the architecture. RISC before the term was coined.

author: joeqsmith
author_rank: Super Contributor
timestamp: December 30, 2017, 06:15:59 pm
content: I used MMSFORTH from Miller Micro Systems for a few projects in the mid 80s. Doing a search, it looks like they still offer it but it appears I my memory is flawed or they changed their name. It had turtle graphics you could use to plot your data and such. I think back then I may have been running this without a hard drive.http://www.millermicro.com/mmsforth.html

author: glarsson
author_rank: Frequent Contributor
timestamp: December 30, 2017, 06:20:51 pm
content: Quote from: rhb on December 30, 2017, 06:10:43 pmIf you could live with the tiny 256 byte stack (at a fixed location!) and page zero.

author: rhb
author_rank: Super Contributor
timestamp: December 30, 2017, 07:52:49 pm
content: We are talking about forth, remember? It needs two stacks which can easily be implemented in 256 bytes. Rockwell made 65xx devices with forth in ROM, the R65F11 and R65F12.

author: glarsson
author_rank: Frequent Contributor
timestamp: December 30, 2017, 08:00:24 pm
content: It was a comment on the 6502 processor in general. It had its limitations compared to the competition.

author: stj
author_rank: Super Contributor
timestamp: December 30, 2017, 09:51:25 pm
content: Quote from: glarsson on December 30, 2017, 06:20:51 pmpage-0 was an advantage, not a problem.you could use single-byte addressing to make stuff run even faster!

author: daybyter
author_rank: Frequent Contributor
timestamp: December 30, 2017, 10:42:49 pm
content: Forth is still used on the zx81 as an example? I still see new forth code there from time to time?

author: glarsson
author_rank: Frequent Contributor
timestamp: December 30, 2017, 11:55:36 pm
content: Quote from: stj on December 30, 2017, 09:51:25 pmYes, it could make it faster, but when trying to implement multitasking it was a liability that page 0 and stack could not be moved. The 6502 should have had two registers that defined where page 0 and stack were.

author: rrinker
author_rank: Super Contributor
timestamp: December 31, 2017, 12:27:35 am
content: having started with the 1802, with its 16x16 bit registers where any one could be the program counter and any one could be the stack pointer, and you could switch on the fly, and then moving to the Z80 for my second machine code programming experience, when I had to do part of my final program for the Apple II in assembly because the BASIC was too hideously slow to do motion graphics, I found the 6502 to be VERY hard, taking much more code to do the same thing I could have done on the Z80 or 1802. Tom Pittman had the same problem with Tiny BASIC. It fit in 2K on the Z80 or 808. It came in 200 bytes UNDER 2K on the 1802. But try as he might, he couldn't get it in 2K on a 6502 without cutting something out.

author: rhb
author_rank: Super Contributor
timestamp: December 31, 2017, 01:26:14 am
content: I've read the first 3 editions of "Computer Architecture: A Quantitative Approach" by Patterson and Hennessy cover to cover and the manuals for over a dozen processors. The 6502 is *still* my favorite processor. Very clean and simple.For the design requirements, the 6502 was a tour de force. Nothing else came close to that level of performance for the same price point. There's a great interview with Wozniak in which he describes his reaction to learning about the instruction set of the 6502. He knew what to do with it as soon as he heard about it.As for page 0, that would have been ideal for multitasking if that was where you saved registers. The art of programming is adapting the algorithms to the architecture. In every edition of Patterson and Hennessy the choice of algorithms for many tasks changed completely. On a VAX one did tests inside loops to avoid computation. On the MIPS R2000 and early SPARC you eliminated the test to avoid the branch delay slot penalty which was later eliminated by speculative execution.The last time I did any performance sensitive programming was on a DEC Alpha 19 years ago. For that I wrote a program to generate the FORTRAN code which used the only computed GOTO I have ever written. The main loop incremented by 2 and each time calculated j and j+1. But it got me a 10-15% speed up. I used Alphas because they were 5x the floating point speed of an x86 at the same clock rate and price.

author: chris_leyson
author_rank: Super Contributor
timestamp: December 31, 2017, 02:04:15 am
content: Hi guys, in an earlier post I said Forth on a 6502 was a pain. It wasn't a comment about the 6502 architecture but back then it was hard work no matter what processor it ran on. I had to buy an assembler listing from the Forth Inertrest Group, wait for it to arrive in the post and then type it up bit by bit and save on cassette tape. My only documentation was an assembler listing with few if any examples and then I had to get it run on a UK101, I didn't have the patience.Today in just half an hour I had flashforth up and running on a Microchip microstick, just plug in an FTDI RS232 serial converter, open up TerraTerm and job done. Well it should have been job done but RX and TX are swapped over in the PIC24H config file so it took a bit longer to find that bug.Anyway, after missing the obvious flashforth is now running on a PIC24HJ128GP502 on a microstick. Thanks Mikael Nordmanall running through a terminal program. No compiler required just an assembler, cool.

author: rhb
author_rank: Super Contributor
timestamp: December 31, 2017, 02:32:34 am
content: Look at Mecrisp. It really is just awesome, which is not something I say lightly! And it runs on a bunch of ARM and MSP430 dev boards from multiple vendors.I certainly agree about forth in the 80's. I've got the listings from Mountain Valley Press in my library and probably the FIG publication as well. I bought everything I could find at the time. Unfortunately, nothing matched the ROM cartridges for my Vic20 or C64.

author: Maxlor
author_rank: Frequent Contributor
timestamp: December 31, 2017, 02:49:02 am
content: Quote from: GlennSprigg on December 29, 2017, 02:36:16 pmSurely you meant to say UNFORTHUNATELY.Actually, some of my machines still run Forth code to this day. Part of the bootloader of FreeBSD is written in Forth. If you run FreeBSD, have a look at /boot/loader.4th or the other *.4th files there. I suspect the reason that it is so is because a Forth interpreter is easy to implement in a small amount of code, and the old BIOS bootloader only has a very small amount of RAM available.

author: rhb
author_rank: Super Contributor
timestamp: December 31, 2017, 02:59:27 am
content: The Sun boot monitor is written in forth, It allowed the devices to initialize themselves. Hence the "OK prompt. You could really do a lot if you understood the design model.

author: GlennSprigg
author_rank: Super Contributor
timestamp: January 02, 2018, 12:45:16 pm
content: To 'Maxlor'...... My mind must be slow today. It took me ages to realizewhat you meant, in re-quoting my word as "unFORTHunately"

author: NivagSwerdna
author_rank: Super Contributor
timestamp: January 02, 2018, 01:24:15 pm
content: I ported FIG FORTH to the Schools Commodore PET as my lower sixth (equiv Junior at High School in US) project.https://www.amazon.co.uk/Threaded-Interpretive-Languages-R-G-Loeliger/dp/007038360Xwas the starting point for my interestI have GForth on my Android phone.Happy New Year!

author: borjam
author_rank: Unknown
timestamp: January 02, 2018, 01:51:11 pm
content: I was member of the Forth Interest Group even.At the time it was an amazing tool for embedded systems. I remember that around 1990 I wrote a multitasking kernel that included "language extensions" to define a special kind of word, a TASK.A task would have an initialization section and a runtime section. The initialization section would be run once when the process was created in RAM (everything was stored in EPROM) and the runtime was the general code of the task.It was defined somewhat like this:TASK THIS_IS_A_TASKINIT>do this, initialize this device, blah blah;INITRUNTIME>the task code, most often a loop of some kind.;RUNTIMESo, TASK, INIT> and RUNTIME> were actually words that controlled the compiler creating the task description blocks to be stored in EPROM and arranged all the data structures. As part of the system boot one just had to invoke "START-KERNEL" (or something like that, I don't remember the name) and it went through the linked list of tasks to initialize, creating their data structures in RAM, invoking the INIT sections and, finally starting the multitasking kernel itself.And Forth still has more users than many would suspect. Although I admit that it doesn't fare well with the current level of software complexity.

author: Stray Electron
author_rank: Super Contributor
timestamp: January 07, 2018, 09:07:23 pm
content: I still have my package of Poly Forth (for the IBM PC) from Charles Moore sitting on my bookshelf. I also still have two Forth ROM packages for the HP-71. No, not for sale!

author: xygor
author_rank: Regular Contributor
timestamp: January 07, 2018, 10:44:41 pm
content: The thread's gotten this far and no one has mentioned GreenArrays ?!

author: GlennSprigg
author_rank: Super Contributor
timestamp: January 08, 2018, 12:39:03 pm
content: To 'xygor' ,... (and too many others to thank!)....I'm an old-bastard !! but I had never heard of "GreenArrays" until I just looked it up.....http://www.greenarraychips.com

author: rhb
author_rank: Super Contributor
timestamp: January 09, 2018, 08:11:40 pm
content: Sigh....I hope the GreenArrays or *really* expensive so I don't buy a couple. It looks very interesting.

author: kultakala
author_rank: Regular Contributor
timestamp: January 17, 2018, 11:14:58 am
content: I am not into programming, but can remember the time when it was common...May the Forth be with you!

author: james_s
author_rank: Super Contributor
timestamp: January 18, 2018, 06:46:51 pm
content: I remember playing with Forth on my Sun workstations, haven't fired one of those up in ages now, I should see if they still work.