I'm the lead developer of SBTCVM, a FOSS balanced ternary VM project, Ask Me Anything!

Did you find this post useful? Show some love!

Can you explain the project like I'm five? :)

I suppose i could try. :)

SBTCVM has several major parts:

The VM of SBTCVM uses instruction level simulation to simulate a type of digital computer originally developed in Russia. It uses a 'balanced' base number. A balanced base number has an equal number of positive and negative digits. for example:

Here's a 2 trit(similar to a bit) number table as an example.

-- -4
-0 -3
-+ -2
0- -1
00 0
0+ 1
+- 2
+0 3
++ 4

not only does it have 9 states, 4 of them are negative. This inherit signing causes balanced ternary computing to be quite different from binary in places.

The (latest version's) CPU itself uses 18-trit words divided into a 9-trit instruction word, and a 9-trit data word, along with a 9-trit memory bus. This means it has 19,683 words of memory. It uses an additional 9-trit IO bus, providing 19,683 IO addresses.

The second part of SBTCVM is the programming tools. Currently SBTCVM has a fairly advanced low-level assembler, and a currently numeric, higher level language that provides a basic integer object abstraction system, along with the ability to use some assembly in-line if your feeling brave :)

A trom (memory image) dump utility is also provided, as a standard hex viewer obviously isn't going to help much. :)

The third part is software that runs in the VM. Now, the latest codebase isn't ready for huge interactive programs yet, but we do have some exciting plans... :)

I'm sorry, but that explanation was for 20-year-old folks. 😝

So, if I'm not mistaken, it's a virtual machine like the JVM? What is it going to be useful at? For instance, will it be deployed on specific hardware? Will it allow creation of compiled/interpreted programming languages? Etc., etc.

Edit: I did check out en.wikipedia.org/wiki/Ternary_comp... eventually, and I think this is kind of exciting. Ternary logic instead of binary? Talk about flipping the entire script!

Basically SBTCVM simulates a ternary computer. It has 19683 words of memory, (all ram) and at the moment programs are primarily loaded as memory images called troms (or ternary roms), but disk-based programs are in future plans. (we just haven't written the disk system yet. :p)

As far as what SBTCVM is actually useful for, learning and experimenting with balanced ternary is what lead to the first prototype in the first place, and remains an important part of the project.

what balanced ternary is

while regular ternary has 0, 1, & 2, balanced ternary has +1, 0, & -1


That negative digit can be quite confusing to beginners. For example:
lets count to 4 in Balanced ternary (p/+=+1 n/-=-1)

center: standard SBTCVM notation, right: alphanumeric notation which is less confusing in written math.

1 0+ 0p
2 +- pnHuh? where's zero?
3 +0 p0
4 ++ pp
Obvious in hindsight: the negative trit (trit: same idea as a bit) comes before zero.

converting to decimal

the second trit (left) is worth 31 (3)
the first is 30 (1)

so taking 2 as an example:

pn = +3-1 = 2

As as result of the negative digit, balanced ternary is never unsigned. So things like addresses start at the Max Negative Integer (or MNI for short.), and zero tends to fall in the middle of things.

github of latest version:
the blog has some guides and such as well:

What challenges are you facing in terms of development?

Here are some of the main ones:


SBTCVM has its own architecture for a reason. one of the key challenges has been translating elements from more modern computers to balanced ternary. You see, the last actual hardware example was built in the late 50s in Russia. So we don't have a massive amount of examples to build on.

Building the whole programming workflow

SBTCVM, having its own architecture, and not even being binary in the first place, can't use any common tools or compilers. So not only is the VM running on a custom math library, everything from SBTCVM assembly to SSTNPL to the romdump utility has been built from scratch.

having to design encodings and devices from scratch.

SBTCVM has involved inventing things from the start. the simplest of these creations is the 2 text encodings it has used: SBTCVM-BTT-6 and SBTCVM-BTT2 (current).

While SBTGA, sbtcvm's graphics system, is yet to be implemented in the new codebase, it can't use standard resolutions or color modes for obvious reasons.

Codebase & implementation

Along with the design challenges, actually implementing the architecture is quite a task. the latest codebase runs the CPU at 6.5Khz. that doesn't sound like much, but for python, it is.

The new codebase uses plenty of python classes in a modular architecture design that keeps the primary components separated (and has allowed us to plan multiple frontends i.e. curses, pygame, tk).

the assembler and SSTNPL's compiler are also class-based, but divide the instruction-specific parsing into class instances in a large list. This has allowed a variety of powerful features, and has somewhat simplified their upkeep.

programming the VM

Another challenge has been writing programs to make the VM more useful, and acting as examples for proper programs. The latest codebase doesn't have much outside the usual barrage of test programs, but the previous codebase did manage to run an RPN calculator.

Classic DEV Post from Apr 25

Microservices & RabbitMQ On Docker

A microservices-based architecture involves decomposing your monolith app into ...

Follow @usamaashraf to see more of their posts in your feed.
dev.to is now open source!
View Announcement Post View GitHub Repo
Thomas Leathers
Hi, i'm Thomas, cheif developer of the SBTCVM project, and all around artist and programmer. I do have more of an understanding of balanced ternary than most i would say.
Trending on dev.to
Who's looking for open source contributors? (August 13 edition)
#discuss #opensource
I am c++ coder in autonomous vehicle developing, Ask Me Anything!
What is YOUR ultimate goal that you want to achieve as a developer?
#discuss #goals #life
I am a software developer with 10+ years experience, and run my own profitable business - AMA!
What are your thoughts on multiples package managers?
I Failed as a Developer. And so did you.
#opensource #career #webdev #discuss
I'm a Swift Native Speaker, Ask Me Anything!
Style your Terminal better by mastering these settings 🀩
#terminal #productivity #tools #webdev