---------------Getting along in the 21st Century with half the baggage you carried in the last.------------ /*************************Low cost electronic solutions for a low impact lifestyle.************************/

Tuesday, October 27, 2015

SIMPL Revisited - Again, but this time it's personal

In May 2013, I learned about Ward Cunningham's Txtzyme language - a very simple serial command interpreter which allowed basic control of microcontroller function using a serial interface.

Tytzyme was about as easy as a "language" could get, it offered digital input and output, analogue input, rudimentary timing in uS and mS and simple repetitive loops. It was so simple, and offered so many opportunities for extension, that I decided to write some new functions - and called the extended language SIMPL - serial interpreted minimal programming language.

In the last 30 months I have ported SIMPL to Arduino, ARM and FPGA soft core processors. I have also used the Txtzyme interpreter to help to create assembly language for an entirely new soft core FPGA cpu.

Very often, during initial deveopments, we need a low level human interaction with a new microcontroller, and SIMPL seems to provide that coding framework to allow more complicated applications to be tested and coded.

SIMPL is coded in C - which allows good portability between micros, but recently I have been wondering whether SIMPL would be better coded in Forth, and act as a human interface layer between a Forth virtual machine and the human programmer.

Forth can be a difficult language to master - partly because it involves considerable manipulation of the data stack, and the need to keep track of the stack presents quite a challenge to the new programmer.

Standard Forth consists of a vocabulary of about 180 compound words, which can be entirely synthesised from about 30 primitives. When ported to a FPGA soft core CPU, optimised for Forth, most of those 30 primitives are actual native instructions. That makes it fast in execution, but still not the easiest of languages to grasp.

Can we use SIMPL to access a sufficient subset of the Forth vocabulary to allow real programs to be written, but without having to tie our brains in knots over keeping track of the stack?

The beauty of Forth, is that you can compile a new word and give it any name you wish. In SIMPL terms, this name would be a single alpha or punctuation character. Small alpha characters are reserved for the keywords, whilst capital letters can be used for User defined words.

This gives us a subset of 85 possible words - which has reduced the scope and complexity of the standard Forth language by a factor of 2.

Forth text entry consists solely of words and whitespace. This is intentional because it makes it more readable from a human point of view, and the spaces between words allows the compiler to know where one word ends and the next begins. The carriage return is usually used to denote the end of a line, and thus signal the compiler to start compilation of the contents of the input buffer.

SIMPL borrows from these ideas, but attempts to simplify by removing the whitespace. In fact a space character (ascii 32) may have it's own unique meaning to the SIMPL interpreter.

Numbers also present a burden to the traditional Forth interpreter - which has to search the dictionary only to find that a number is not listed, and then assume that it is a number. In SIMPL we assume that numbers are all decimal unless prefixed with a character that changes the base to hexadecimal.

As the compiler is only dealing with 85 possible input characters, the dictionary is simplified to an address lookup. For example if the interpreter encounters the character J, it looks up the address associated with the function called J, executes that code and then returns so as to interpret the next character in the buffer.

There are only 85 characters to interpret - so only 85 action routes to execute.

1 comment:

this looks a little like "synthetic" programming on the HP41 - it had compound command words that could be combined in "illegal" but valid ways sometimes executing multiple opcodes or register operations sequentially in ways the engineers hadn't explicitly defined, fun stuff!

Just started reading through your blog RE: I received 400 commercial scale (320 watt) solar panels, they are BB grade so they are far from matched sets - a $20 or $30 H bridge seems a more sensible method of micro-rectifying or voltage leveling their variable outputs into a standard voltage BEFORE transmission to a rectifier or distribution to a panel than any commercial solution... keep up the good work!

About Me

I am an electronics engineer working with embedded microcontrollers within instrumentation, telecoms and low power wireless.
Applications include energy saving, renewable energy, automation for CHP and open hardware
I'm interested in renewable energy, suburban repurposing/transition and gasification for domestic heat and power.
You can find me @monsonite on Twitter