SBTCVM is a balanced ternary (a variant of ternary that uses a negative digit instead of 2) virtual machine written in python.
Recently, I and the rest of the SBTCVM developers have been hammering away at a new, 6.5Khz, modular, codebase called 'SBTCVM Gen 2'. Its still in alpha, but its definitely making progress, and can already run moderately complex math programs, and print their output to a virtual TTY.
For those of you who saw my previous post on Fibonacci in balanced ternary, you probably already know, SBTCVM's old codebase only had an assembler. Well...
SO, Whats going on here? well, this is the new, abstracted, primarily-numeric, language, built for SBTCVM gen2, thats not a week old.
SSTNPL is a language built primarily for mathematics. its driven by a seamless, named-integer-variable system. Its main goal is to abstract the complexities of the Virtual machine enough to provide a nice abstract language for learning Balanced Ternary mathematics, and doing calculations.
var = is how we create variables for use & change later. (you must call var for every variable you use, regardless of whether it needs a starting value. Also most operations (other than a val followed by a 'set' statement), only take variable names as arguments.
value can have 2 forms:
prefix the value with '10x' if you wish to use decimal. i.e.
otherwise you can use ternary in both +0- and p0n notations.
here we have two strange commands:
dumpd and dumpt
dumpd dumps the specified integer in decimal form
dumpt does the same, but in ternary form.
newline and space are just TTY macros intended for formatting.
the conditional goto. you might notice that it takes 3 arguments. 2 operators that are comma-separated, and a label to actually jump to.
there are actually 3 types: if(equals), ifmore, and ifless. (this is no coincidence, as SBTCVM's new CPU also has these 3)
add does just what you'd expect. It adds the two specified arguments. But how do we get our result?
thats the job of 'set' in this example, we 'set' num0 to the result of the previous operation.
swap, just switches the values of the two arguments.
And finally we just do 'goto loop' to return to the top of our loop at 'label loop', and then write a small exit routine to jump to in our conditional, and we have a program.
When we build this SSTNPL program into a memory image (.trom) and run it, via the stnpcom.py compiler and SBTCVM gen 2's curses VM frontend, the logged output looks like so:
SBTCVM's new codebase can be found here, and works in both python2 and python3:
SBTCVM is a virtual machine implementation of a balanced ternary (base 3) computer. Features several compiled languages for ternary software development. [alpha]
Simple Balanced Ternary Computer Virtual Machine
Need Help? See our Getting started guide
What is SBTCVM?
Ever wonder what computers other than the boring-old binary would be like? Well, look no further SBTCVM, a python-written VM, simulates the little-known base number called Balanced Ternary!
What is balanced ternary? well, it has "0" and "+1", just like binary but added into the mix is a "-1"! Yes, this means EVERY number is signed.
Intrigued? Well, as SBTCVM is Free & Open Source Software, and comes with a ready-to-use set of compilers and development tools, Getting started with balanced ternary with SBTCVM, should prove a fun challenge!
- bundled ternary software. including demos, games and utilities.
- 4 channel sound chip
- 6.5Khz, 9-trit CPU
- 39.388 KiloNonets of system RAM
- pygame frontend features color graphics.
- multiple specialized programming languages with integrated compilers. (SSTNPL, SBTCVM assembly)
- Suite of…