Thursday, July 26, 2018

Gen 2 update: 3 new additions to the assembler.

The assembler has grown a bit. Specifically, it has a header variable system, the new nsp framework, as well as the new xas framework. So... Whats all that mean?

Header Variables.


source files traditionally had no say in how they were assembled in the past, thats where header variables come in. What they do does vary, however:
assembler mode

head-mode=trom, head-mode=vars

head-mode refers to the mode of the assembler. currently there are two possible values:
  • trom: normal assembly (this mode will be chosen if head-mode is omitted.)
  • vars: don't assemble a trom, but do handle nsp if enabled. (nsp is explained later in this post.)

Rom Name

head-rname=<rom name>
: override the trom output name. (excluding extension)


SBTCVM Assembly Namespace (.nsp) files:

.nsp files allow you to use the namespace variables from one assembler source file (.tasm file) in another. here are the needed header variables to use them.

head-nspout=1: enables .nsp output for that source file. (excludes variables from other nsp files, as well as any builtin variables.

head-nspname=<nsp name>: override the nsp output name. (excluding extension)

head-nspin=<nsp name>
: Import an nsp into an assembler file's namespace. you can use this namespace variable multiple times to import multiple .nsp files.

If all this .nsp nonsense sounds complicated, rest assured that one of its main purposes is to make some things easier.

SBTCVM Assembly Script (XAS)

XAS is an assembly automation script system, that makes multi-source-file projects easy to assemble.

Its main purpose isn't so very useful yet, but once Gen 2 gets a bit further along, its going to come in very handy.

Currently it has 4 commands:

  • asm: takes name of tasm source file as argument. same as g2asm.py [source file]
  • print: print argument to standard output.
  • xas: run a xas script from within another xas script. takes script name as argument.
  • exit: exit. takes no arguments
to run a XAS script, just pass it as an argument to the assembler just like you would a .tasm file.

SBTCVM Gen 2-9 repository:
https://github.com/SBTCVM/SBTCVM-Gen2-9

Tuesday, July 3, 2018

tutorials: balanced ternary basics

If you happened across SBTCVM and/or Balanced Ternary someplace, and you are wondering what the heck a trit or tryte is, you are at the right place.

Lets start with the very basics:

balanced ternary, like regular ternary (base 3), has 3 digits.

Several notations exist for balanced ternary. the one you use often is best chosen for the circumstance. For example: +0- is supported by all versions of SBTCVM, while p0n is only supported by the newer SBTCVM Gen 2-9 VM, thats still in development. 
Here is the number '8' in a few forms of balanced ternary notation:
+0-
p0n

  • Positive: (+,p) your familiar positive digit.
  • Ground: (0) ground, or zero, is in the middle. but that's not even the most confusing bit.
  • Negative: (-,n) this is the curve ball, and why 2 in balanced ternary is '+-'

still dont get it? lets count from -4 to +4

-- (nn) -4
-0 (n0) -3
-+ (np) -2
0- (0n) -1
00 (00)  0
0+ (0p)  1
+- (pn)  2
+0 (p0)  3
++ (pp)  4

here are some key terms:
  • trit: a balanced ternary digit
  • tryte: 6 balanced ternary digits
 Special note: 1093 is based on the MPI of 7 trits.
  • KiloTryte (KT): 1093 trytes.
  • Kilotrit (Kt): 1093 trits.
 Helpful equations. (SBTCVM's libbaltcalc has functions for these)
  • MPI: Max positive integer: maximum positive value a length of trits can represent. ((3^n)-1)/2=MPI where n=length of trits
  • MNI: Max negative integer: lowest value a length of trits can represent. is the opposite of MPI. 
  • MCV: Max combinations value: number of combinations in a length of trits. 3^n=MCV where n=length of trits
why is MPI, MNI, and MCV, relevant now?

 Well. thats a good question! this brings me to another point:

Balanced ternary, like other balanced base numbers, have many subtle differences form bases like binary and decimal. for example: lets compare 8 trits & 8 bits
    8 trits | 8 bits
MPI: 3280   | 255
MCV: 6561   | 256

Aside from balanced ternary knocking binary out of the park numerically, notice how with binary, the MPI and MCV equivalents are only 1 off, while in balanced ternary its 3281 off. why is this? 

ok but why are MPI and MCV so different?

well. balanced ternary, like other balanced base numbers, is inherently signed. lets look at the combinations of 1 trit:

- (n) accounts for one MPI
0 (0) zero accounts for 1
+ (p) accounts for one MPI

this can be summed up into this formula:

n=length of trits
x=MPI(n)
y=MCV(n)

and then:
x+1+x=y

i.e.

x=MPI(3)=13
y=MCV(3)=27
x+1+x=y
13+1+13=y=27