To ease the debugging phase, here is an emulator for the ternary programs:

https://github.com/ssloy/triador

A very simple sample program that computes R2+R3 and stores the results back in R3:

R1 NNN # N.B. the memory is not guaranteed to be initialized RR NNN # initialize R13 with -13, this chooses segment NNN for jumps R2 ONP # write -2 to R2 ┌─────────────────────────────────┐ R3 PPP # write 13 to R3 │ This program computes R2+R3, │ RR OPO # copy R3 to R1 <─┐ │ the result is stored in R3. │ SK NPO # skip if R2!=0 │ │ Here is a C++ world equavalent: │ JP PNO # R2==0, terminate│ ────┐ │ │ SK PNP # skip if R2>0 │ │ │ int R2 = -2; │ RR OON # R1-- │ │ │ int R3 = 13; │ SK PNN # skip if R2<0 │ │ │ while (R2!=0) { │ RR OOP # R1++ │ │ │ int R1 = R3; │ RR ONO # copy R1 to R3 │ │ │ if (R2>0) R1++; │ RR OPN # copy R2 to R1 │ │ │ if (R2<0) R1--; │ SK PNP # skip if R2>0 │ │ │ R3 = R1; │ RR OOP # R1++ │ │ │ R1 = R2; │ SK PNN # skip if R2<0 │ │ │ if (R2>0) R1--; │ RR OON # R1-- │ │ │ if (R2<0) R1++; │ RR ONP # copy R1 to R2 │ │ │ R2 = R1; │ JP NOO # jump here ──────┘ │ │ } │ EX PPP # halt and catch fire <─┘ └─────────────────────────────────┘

## Discussions

## Become a Hackaday.io Member

Create an account to leave a comment. Already have an account? Log In.