BASIC programming on an Arduino
posted Aug 28th 2011 3:05pm by Brian Benchofffiled under: arduino hacks

[Mike] sent in a project he’s been working on – a port of a BASIC interpreter that fits on an Arduino. The code is meant to be a faithful port of Tiny BASIC for the 68000, and true to Tiny BASIC form, it fits in the very limited RAM of the Arduino.
True to Tiny BASIC’s assembler roots, [Mike]‘s C port makes extensive use of the “infinitely-abusable” goto statement. Kernighan and Ritchie said themselves, “code involving a goto can alway be written without one” but [Mike] found that using goto left a lot more room available for BASIC code. The BASIC interpreter eats up around 600 bytes in the Arduino RAM, leaving about 1.4 kB for BASIC code. Not much, but more than the lowest-end BASIC Stamp.
[Mike] says he started this project to see how ‘old bearded ones’ conjured up so many impressive programs with a few kB of RAM. Tiny BASIC was originally conceived for the Altair 8800 that shipped with 256 bytes of RAM stock, so it seemed like a perfect fit. Right now, all we know is we’ll be spending the weekend digging through our copies of Dr. Dobb’s Journal.








Nice effort, but I doubt it would be useful for anything semi-serious. The interpreter probably adds a very significant overhead mostly in CPU cycles, but also quite a lot in precious RAM and ROM space. It may leave 1.4KB of free ROM space, but “>30 T=T+A” takes 10 bytes of code space (11 if you use CR+LF), while the instructions would take half or less, depending on the context. It gets worse when you use proper variable names.
Writing or porting a basic interpreter isn’t exactly easy, so it probably was a good exercise for the author, and hobby coding doesn’t have to be productive to be fun.