Version of 3 July 2011.
Guide to the instructions:
These operations assist the programmer in doing arithmetic with extends (short for extended-precision integers), numbers of such large magnitude that they require more than 255 bits.
Each extend is represented by a sequence of 255-bit segments. Although the segments are typically stored consecutively in genspace, when only a few are needed it might be feasible to keep them all in CPU registers as calculations unfold. Besides the segments, there exists during calculation a carry, a single bit which will normally remain in the stack.
The programmer will typically write a loop for addition, negation, or subtraction, and nested loops for multiplication. Plain binary arithmetic, modulo 2**255, is performed segment by segment. The programmer will ordinarily start calculation with segments of less significance and proceed to those of more significance. Techniques vary, but a basic approach is to repeat the following cycle: (1) get a few segments of each input from genspace, (2) calculate, and (3) put the result segments back into genspace.
A result of the modularity is that numbers are not distinctly positive or negative; rather, the program can interpret them as desired. The operation called "negate" simply subtracts the number from 2**255.
Because there is no provision for nulls, the extends are distinct from the regular integers of the LT4335. In particular, extends cannot be used as addresses; only regular integers serve that purpose. Still, a non-null regular integer can be used to initialize a segment of an extend, and it will be sign-extended to 255 bits. If an input segment is less than 255 bits and matches the pattern for an regular integer null, an exception is thrown. Regardless of input sizes, each output segment is written as a 255-bit string.
There are no special get and put instructions for the segments of an extend. Rather, the string get and put instructions should be used; they do raw bit copying. For extends, the regular integer get and put instructions are incorrect because they may try to trim the number, severly if it has a bit pattern that looks like an integer null.
Unlike some CPUs, the LT4335 does not have a status register that contains a carry flag, so the programmer has to manage the carry explicitly; that is why it appears in the stack. An advantage, however, is that the programmer who opts for a sophisticated algorithm can simultaneously maintain in the stack carries from several different phases of the calculation. In any case, a carry is always a string of exactly one bit, 0 or 1.
The carry-in should be set to zero before adding the least-significant segments.
The carry-in should be set to one before negating the least-significant segment.
All bits are inverted, and then the carry-in is added.
The carry-in should be set to one before subtracting the least-significant segments.