Close

More about the SIMPL Project

A project log for SIMPL

Serial Interpreted Minimal Programming Language for exploring microcontrollers & new cpu architectures

monsonitemonsonite 01/15/2021 at 15:060 Comments

SIMPL - is the acronym for Serial Interpreted Minimal Programming Language.

SIMPL is an extensible language allowing it to grow to suit the requirements of the application.

In this project: 

A 2 minute Introduction to SIMPL.

The following brief example shows how SIMPL allows you to flash a blinky LED on an Arduino or similar. The Arduino is loaded with the SIMPL kernel and connects via the serial terminal, allowing commands, shown in bold,  to be typed. 13 d            First we identify that we want to use the LED attached to digital pin 13 using the d command.  1 o              The o command allows us to send either a LOW or HIGH to the selected pin 12 - 1o turns the LED on,  0o turns it off

1000 m      We use the m command to initiate a millisecond delay in this case 1000 mS 

10{...........}   We  create a loop using curly braces - in this case the contents of the braces will be repeated 10 times Now we put it all together as a microscript

13 d 10 {1o 1000m 0o 1000m}   This will flash the LED 10 times ON for 1 second and OFF for 1 second

13d10{1o1000m0o1000m}         But the spaces were only for clarity - they can be omitted. We can edit the delay periods to create different on and off times: 13d10{1o200m0o100m}            200mS on and 100mS off Or we can alternatively use the microsecond delay command u to generate audio tones into a small speaker

13d1000{1o500u0o500u}    This will generate 1 second of 1kHz tone But SIMPL is extensible - if we like the 1kHz beep, we can allocate a user command to it -  for example B for Beep

We do use this using colon : and semicolon ; to define our new command

:B13d1000{1o500u0o500u};

Every time B is typed a tone will be generated.

BBBB    Generate 4 seconds of tone

Now create a higher tone and call it C

:C13d1200{1o400u0o400u}; 

CBCBCBCB  Generate an alternating siren sound. 

 We have created a sound effect using a few numerical parameters  and a few ascii characters as commands  d  o  m  u  {  } :  and  ;  Three conventions are used: Lowercase characters a-z are used for pre-programmed commands that are generally coded into the Flash ROM

Uppercase characters A-Z are generally used for User Defined commands (microscripts) or variables that are stored in RAM

Punctuation characters and other symbols are used for arithmetic and logical operations and program flow such as looping.

How SIMPL Works

A small program flashed into ROM provides the serial interface and command interpreter.

Every ascii character read in, causes the interpreter to jump to a unique block of code which executes the command action before returning to the interpreter to read in the next character.

This very simple interpreter has amazing flexibility and can be tailored to suit the requirements of a wide variety of applications such as CNC (plotters, 3D printers, routers, laser cutters), robotics, hardware control etc. 

The microscripts can be extended and concatenated to create a fully interactive, self-hosted programming environment - an alternative to assembly language, or higher level languages such as BASIC or Forth.

About SIMPL SIMPL is a minimal serial interface to a microcontroller to allow a self-hosted interactive programming environment. The microcontroller only needs a UART or bit-banged serial interface and responds to serial commands, and responds with serial output or direct control of the microcontroller's peripherals. SIMPL has been designed to use the minimum of processor resources in its implementation. If written in assembly language, only 2K bytes of Flash ROM and 512 bytes of RAM are needed for a minimum system.

It has been ported to ATmega328 via Arduino and MSP430 using Energia. Assembly language versions have been produced for various MSP430 devices using TI Code Composer tools. More recently it has been used to provide an interactive shell  for novel cpu designs that are simulated on ARM Cortex M7  devices such as the Nucleo STM32H743 evaluation board and the Teensy 4.x boards. SIMPL has a very small footprint, and can be quickly ported to new devices. Porting SIMPL to a new device in native assembly language is a great way to learn the ISA of the new device. SIMPL is toolkit with which to explore computing machines, both new and old.

SIMPL provides a learning exercise to understand the fundamentals of computer languages and virtual machines.

My involvement with SIMPL started in 2013 and it has been evolving ever since. Versions have been written for Arduino, MSP430 and ARM, both in C and assembly language.  Writing in hand assembled code will produce a solution that is 25% to 50% of the ROM space required by a program written in C and compiled with GCC. Further information about SIMPL may be found in my Github Repository SIMPL

Describing and documenting any software project from first principles is difficult at the best of times. 

This is a first attempt to document the SIMPL project, to describe its concepts, its philosophy and implementation. Languages evolve over a period of time. Some ideas win whilst others fail. A language is only a snapshot illlustrating current thinking.

Beginnings.

SIMPL was inspired by the Txtzyme nano-interpreter by Ward Cunningham.  Ward created a small interpreter, written in around 100 lines of C code for use with Arduino or Teensy.  

Txtzyme allowed direct manipulation of the microcontroller and peripherals using a compact set of just 13 commands entered via a serial interface. The commands could be accompanied with a single 16-bit number that was used as a control parameter. Txtzyme sequentially executed the commands stored in the serial input buffer until it encountered CR/LF characters. Control was then returned to the user. SIMPL extends the concept of Txtzyme in 5 main directions.

  1.    It extends the number of commands to include all printable ascii characters, giving much greater functionality.
  2.    It allowes the use of additional numerical parameters to allow arithmetic, comparison and logic operations to be performed
  3.    It allowes new command definitions to be created by concatenating existing commands and assigning them a new name
  4.    The txtEval function can be pointed to any area in memory, not just the input buffer, allowing the VM code to be executed from RAM
  5.    Simple listing and editing features have been added.

The SIMPL Virtual Machine.

The SIMPL VM implements a 16-bit machine with a 64K word addressing space. It is based on the principles of a bytecode interpreter, where printable ascii characters are used as the bytecodes. This makes the language printable and viewable on a serial terminal. Wherever possible, ascii characters are chosen that have a strong mnemonic value attached to them. For example, the arithmetic operators:

+    ADD

-     SUB

*     MUL 

/     DIV

It uses two main routines contained within a loop to implement the Read-Eval-Print Loop (REPL) interpreter.

In addition: It implements a serial interface using serial input  getchar()  and serial output  putchar() routines.

It provides an ascii to integer routine to process numerical character strings and convert them to 16-bit integers.

It uses an integer to ascii conversion routine printnum() which allows decimal integers to be sent to the serial terminal Optional  decimal to hex and hex to decimal routines allow for hex input and hex-dump output.

Discussions