![]() |
LT4335 strings.
Version of 8 July 2011. Home. |
By a string is meant a sequence of bits, not the character string directly supported in many environments. Rather, on this machine the character string is a higher-order abstraction that the programmer might choose to implement; the same goes for the character itself. Consequently, the LT4335 does not have a native character set.
The string type is the best choice when the programmer wants to manipulate raw bits, because many instructions for the integer and float types perform formatting automatically.
The bits in a register are numbered 0…255; if only a portion of them are needed, the higher-numbered bits are omitted.
In the instruction descriptions:
Interpretation of b9 | ||||
---|---|---|---|---|
if… | then… | if… | then… | |
b0…b8 = 09 | see details at instruction description | b5…b8 = 1000 | b0…b4 is the 5-bit string to use | |
b0…b8 = 108 | the string to use will be of zero size | b6…b8 = 100 | b0…b5 is the 6-bit string to use | |
b1…b8 = 107 | b0 is the 1-bit string to use | b7…b8 = 10 | b0…b6 is the 7-bit string to use | |
b2…b8 = 106 | b0…b1 is the 2-bit string to use | b8 = 1 | b0…b7 is the 8-bit string to use | |
b3…b8 = 105 | b0…b2 is the 3-bit string to use | bn…b8 = 108−n | b0…bn−1 is the n-bit string to use | |
b4…b8 = 104 | b0…b3 is the 4-bit string to use |
Interpretation of b12 | ||||
---|---|---|---|---|
if… | then… | if… | then… | |
b0…b11 = 012 | see details at instruction description | b6…b11 = 105 | b0…b5 is the 6-bit string to use | |
b0…b11 = 1011 | the string to use will be of zero size | b7…b11 = 104 | b0…b6 is the 7-bit string to use | |
b1…b11 = 1010 | b0 is the 1-bit string to use | b8…b11 = 1000 | b0…b7 is the 8-bit string to use | |
b2…b11 = 109 | b0…b1 is the 2-bit string to use | b9…b11 = 100 | b0…b8 is the 9-bit string to use | |
b3…b11 = 108 | b0…b2 is the 3-bit string to use | b10…b11 = 10 | b0…b9 is the 10-bit string to use | |
b4…b11 = 107 | b0…b3 is the 4-bit string to use | b11 = 1 | b0…b10 is the 11-bit string to use | |
b5…b11 = 106 | b0…b4 is the 5-bit string to use | bn…b11 = 1011−n | b0…bn−1 is the n-bit string to use |
Sometimes the size of a string is represented by a signed integer; an exception will be thrown in response to a requested string size greater than 255, less than 0, or null.
Many of the get, put, and get-and-put instructions involve an offset. This number, when added to the address of the next physical instruction (which equals the address of the current instruction plus 17), gives the address in genspace whence to read data, or whither to write it.
Get. (see also integer and float) The first instruction (SG_E) pushes an embedded string of as many as eleven bits; the others push strings found in genspace.
SG_E | string get, value embedded | b12_10_001 | |||
---|---|---|---|---|---|
Pulled: none
Pushed:
b12 is the string to be retrived. An exception is thrown if b12 = 012. | |||||
SG_AE | string get, absolute address, size embedded | u8_000_10_1101 | SG_AR | string get, absolute address, all operands in registers | 08_000_10_1101 |
Pulled:
• #0 signed integer: the address to read in genspace Pushed:
u8 is how many bits to read. If zero, SG_AR is performed instead. | Pulled:
• #0 signed integer: the address to read in genspace • #1 signed integer in 0…255: how many bits to read Pushed:
| ||||
SG_AE_Y | string get, absolute address, size embedded, synchronized | u8_100_10_1101 | SG_AR_Y | string get, absolute address, all operands in registers, synchronized | 08_100_10_1101 |
Same as SG_AE, plus synchronization. If u8 is zero, SG_AR_Y is performed instead. | Same as SG_AR, plus synchronization. | ||||
SG_RO | string get, relative address, offset embedded | s9_01_10_1101 | |||
Pulled:
• #0 signed integer in 0…255: how many bits to retrieve Pushed:
s9 is the offset. | |||||
SG_RS | string get, relative address, size embedded | u8_010_10_1101 | SG_RR | string get, relative address, all operands in registers | 08_010_10_1101 |
Pulled:
• #0 signed integer: offset Pushed:
u8 is how many bits to retrieve. If zero, SG_RR is performed instead. | Pulled:
• #0 signed integer: offset • #1 signed integer in 0…255: how many bits to retrieve Pushed:
| ||||
SG_RO_Y | string get, relative address, offset embedded, synchronized | s9_11_10_1101 | |||
Same as SG_RO, plus synchronization. | |||||
SG_RS_Y | string get, relative address, size embedded, synchronized | u8_110_10_1101 | SG_RR_Y | string get, relative address, all operands in registers, synchronized | 08_110_10_1101 |
Same as SG_RS, plus synchronization. If u8 is zero, SG_RR_Y is performed instead. | Same as SG_RR, plus synchronization. |
Put. (see also integer and float) These instructions pull a string from the stack and write it into genspace. The number of bits to write is equal to the size of the data, as indicated by a meta-register.
SP_A | string put, absolute address | 08_000_01_1101 | |||
---|---|---|---|---|---|
Pulled:
• #0 signed integer: the address to write in genspace • #1 string: data to write Pushed: none ##1old is how many bits to write. | |||||
SP_A_Y | string put, absolute address, synchronized | 08_100_01_1101 | |||
Same as SP_A, plus synchronization. | |||||
SP_RO | string put, relative address, offset embedded | s9_01_01_1101 | SP_RR | string put, relative address, all operands in registers | 08_010_01_1101 |
Pulled:
• #0 string, data to write Pushed: none ##1old is how many bits to write. s9 is the offset. If null, SP_RR is performed instead. | Pulled:
• #0 signed integer: offset • #1 string, data to write Pushed: none ##1old is how many bits to write. | ||||
SP_RO_Y | string put, relative address, offset embedded, synchronized | s9_11_01_1101 | SP_RR_Y | string put, relative address, all operands in registers, synchronized | 08_110_01_1101 |
Same as SP_RO, plus synchronization. If s9 is null, SP_RR_Y is performed instead. | Same as SP_RR, plus synchronization. |
Get and conditional put. (see also integer and float) The machine compares the string in genspace to the "old value" string. Then:
If the "new value" and "old value" strings are not of the same size, an exception is thrown. Otherwise, their mutual size determines how many bits of genspace to read and possibly write.
SGP_A | string get-and-put, absolute address | 08_000_11_1101 | |||
---|---|---|---|---|---|
Pulled:
• #0 signed integer, the address to examine in genspace • #1 string: the old value • #2 string: the new value Pushed:
| |||||
SGP_A_Y | string get-and-put, absolute address, synchronized | 08_100_11_1101 | |||
Same as SGP_A, plus synchronization. | |||||
SGP_RO | string get-and-put, relative address, offset embedded | s9_01_11_1101 | SGP_RR | string get-and-put, relative address, all operands in registers | 08_010_11_1101 |
Pulled:
• #0 string: the old value • #1 string: the new value Pushed:
s9 is the offset. If null, SG_PRR is performed instead. | Pulled:
• #0 signed integer: offset • #1 string: the old value • #2 string: the new value Pushed:
| ||||
SGP_RO_Y | string get-and-put, relative address, offset embedded, synchronized | s9_11_11_1101 | SGP_RR_Y | string get-and-put, relative address, all operands in registers, synchronized | 08_110_11_1101 |
Same as SGP_RO, plus synchronization. If s9 is null, SGP_RR_Y is performed instead. | Same as SGP_RR, plus synchronization. |
Versus. (see also integer and float) Two strings may be compared with each other. Lexicographic order is used, meaning that the strings are searched, starting at address 0 and moving toward higher addresses, until a difference is found. A bit value of 1 is deemed greater than a bit value of zero. If one string ends before a difference is found, the longer string is deemed greater than the shorter. The result of comparison is a string at #0, which contains 6 bits. Its contents are:
Address of bit within #0new | With SV_R, this bit equals 1 when … | Comments | |
---|---|---|---|
0 | #0old > #1old | never the same | analogous to integer and float |
1 | #0old ≤ #1old | ||
2 | #0old ≠ #1old | never the same | |
3 | #0old = #1old | ||
4 | #0old < #1old | never the same | |
5 | #0old ≥ #1old |
The result of a one-register comparison (SV_E) is the same as that of the two-register version (SV_R), except that the string embedded within the opcode is substituted for #1.
SV_E | string versus, one operand embedded | b9_1111_0101 | SV_R | string versus, both comparands in registers | 09_1111_0101 |
---|---|---|---|---|---|
Pulled:
• #0 string: comparand Pushed:
If b9 = 09, SV_R is performed instead. | Pulled:
• #0 string: comparand • #1 string: comparand Pushed:
|
Manufacture. These instructions push a string created from scratch.
SM_E0 | string manufacture, size embedded, fill with zeroes | u8_00000_0101 | SM_R0 | string manufacture, all operands in registers, fill with zeroes | 08_00000_0101 |
---|---|---|---|---|---|
Pulled: none
Pushed:
u8 is the size of #0new. If zero, SM_R0 is performed instead. | Pulled:
• #0 signed integer in 0…255: size of #0new Pushed:
| ||||
SM_E1 | string manufacture, size embedded, fill with ones | u8_10000_0101 | SM_R1 | string manufacture, all operands in registers, fill with ones | 08_10000_0101 |
Pulled: none
Pushed:
u8 is the size of #0new. If zero, SM_R1 is performed instead. | Pulled:
• #0 signed integer in 0…255: size of #0new Pushed:
| ||||
SM_Z | string manufacture, size zero | 0111_01_001 | |||
Pulled: none
Pushed:
This is a renaming of the integer instruction IG_E with a null value embedded, which will trim to zero bits. |
Resize. The following operations resize a string. If the string is made larger, zeroes or ones are added on the right. If the string is made smaller, bits toward the right are truncated. Either way, bits with lower addresses are unchanged. If a string is being made smaller, SR_E0 and SR_E1 have the same effect, as do SR_R0 and SR_R1.
SR_E0 | string resize, new size embedded, fill with zeroes | u8_01000_0101 | SR_R0 | string resize, all operands in registers, fill with zeroes | 08_01000_0101 |
---|---|---|---|---|---|
Pulled:
• #0 string: in the old size Pushed:
u8 is the size of #0new. If zero, SR_R0 is performed instead. | Pulled:
• #0 string: in the old size • #1 signed integer in 0…255: size of #0new Pushed:
| ||||
SR_E1 | string resize, new size embedded, fill with ones | u8_11000_0101 | SR_R1 | string resize, all operands in registers, fill with ones | 08_11000_0101 |
Pulled:
• #0 string: in the old size Pushed:
u8 is the size of #0new. If zero, SR_R1 is performed instead. | Pulled:
• #0 string: in the old size • #1 signed integer in 0…255: size of #0new Pushed:
|
To resize a string to zero, delete the top item of the stack, and then perform SM_Z.
Circulate. Strings may be shifted within a register. If D the distance of shift, and A the old address of a bit, then the value of A is moved to address A + D if this sum would be both less than the size of the string, and greater than −1. Otherwise the bit is discarded. Bits that do not otherwise receive a value are set to 0 or 1 according to the instruction. Any nontrivial shift loses information, and if the magnitude of D exceeds the size of the string, all information is lost.
Strings may also be rotated. Let S be the size of the string (in other words ##0old), D the distance of rotation, and A the old address of a bit. Then that bit's new address is (A + D) mod S. The effect is that, if one rotation is performed with distance D, and then another rotation with distance −D, the original string is produced; a rotation never loses information. If S = 0, an exception is thrown.
The final instruction simply reverses the sequence of bits.
SC_SE0 | string circulate shift, distance embedded, fill with zeroes | s9_1011_0101 | SC_SR0 | string circulate shift, distance in register, fill with zeroes | 081_1011_0101 |
---|---|---|---|---|---|
Pulled:
• #0 string: before shift Pushed:
The first 9 bits of the opcode are the distance of shift, a signed integer. If s9 is null, SC_SR0 is performed instead. | Pulled:
• #0 string: before shift • #1 signed integer: distance to shift (need not be in −255…+255, but a null throws an exception) Pushed:
| ||||
SC_SE1 | string circulate shift, distance embedded, fill with ones | s9_0011_0101 | SC_SR1 | string circulate shift, distance in register, fill with ones | 081_0011_0101 |
Pulled:
• #0 string: before shift Pushed:
The first 9 bits of the opcode are the distance of shift, a signed integer. If s9 is null, SC_SR1 is performed instead.. | Pulled:
• #0 string: before shift • #1 signed integer: distance to shift (need not be in −255…+255, but a null throws an exception) Pushed:
| ||||
SC_RE | string circulate rotate, distance embedded | s9_0111_0101 | SC_RR | string circulate rotate, distance in register | 081_0111_0101 |
Pulled:
• #0 string: before rotation Pushed:
The first 9 bits of the opcode are the distance of rotation, a signed integer. If s9 is null, SC_RR is performed instead. | Pulled:
• #0 string: before rotation • #1 signed integer: distance to rotate (need not be in −255…+255, but a null throws an exception) Pushed:
| ||||
SC_B | string circulate backwards | ?_11_000_10_0101 | |||
Pulled:
• #0 string: operand Pushed:
|
No instruction of the circulate family changes the size of a string.
Overwrite. These instructions replace a contiguous segment of the superstring with some substring. A part of the old value of the superstring is lost. An exception is thrown if the substring will not fit into the superstring at the location requested.
SO_L | string overwrite, location embedded | u8_100_10_0101 | |||
---|---|---|---|---|---|
Pulled:
• #0 string: superstring • #1 string: substring Pushed:
u8 is the address within the superstring to start writing the zeroes. | |||||
SO_S | string overwrite, substring embedded | b9_1001_0101 | SO_R | string overwrite, all operands in registers | 09_1001_0101 |
Pulled:
• #0 string: superstring • #1 signed integer in −255…+255: n (throws exception if out of range) Pushed:
b9 is string to be retrived, as in the table for SG_E. If b9 = 09, SO_R is performed instead. | Pulled:
• #0 string: superstring • #1 string: substring • #2 signed integer in −255…+255: n (throws exception if out of range) Pushed:
#2 is the location at which the substring begins to be written. | ||||
SO_0L | string overwrite with zeroes, location embedded | u8_001_10_0101 | |||
Pulled:
• #0 string: superstring • #1 signed integer in 0…255: how many zeroes to write Pushed:
u8 is the address within the superstring to start writing the zeroes. | |||||
SO_0Q | string overwrite with zeroes, quantity to write embedded | u8_101_10_0101 | SO_0R | string overwrite with zeroes, all operands in registers | 08_101_10_0101 |
Pulled:
• #0 string: superstring • #1 signed integer in 0…255: starting location Pushed:
u8 is how many zeroes to write. If zero, SO_0R is performed instead. | Pulled:
• #0 string: superstring • #1 signed integer in 0…255: starting location • #2 signed integer in 0…255: how many zeroes to write Pushed:
| ||||
SO_1L | string overwrite with ones, location embedded | u8_011_10_0101 | |||
Pulled:
• #0 string: superstring • #1 signed integer in 0…255: how many ones to write Pushed:
u8 is the address within the superstring to start writing the ones. | |||||
SO_1Q | string overwrite with ones, quantity to write embedded | u8_111_10_0101 | SO_1R | string overwrite with ones, all operands in registers | 08_111_10_0101 |
Pulled:
• #0 string: superstring • #1 signed integer in 0…255: starting location Pushed:
u8 is how many ones to write. If zero, SO_1R is performed instead. | Pulled:
• #0 string: superstring • #1 signed integer in 0…255: starting location • #2 signed integer in 0…255: how many ones to write Pushed:
|
Extract. A substring may be extracted from a superstring. An exception is thrown if any bit requested has an address less than zero, or not less than the size of the superstring.
SE_A | string extract, starting address embedded | u8_010_10_0101 | |||
---|---|---|---|---|---|
Pulled:
• #0 string: superstring • #1 signed integer: how many bits to extract Pushed:
u8 is the starting address. | |||||
SE_S | string extract, size embedded | u8_110_10_0101 | SE_R | string extract, all operands in registers | 08_110_10_0101 |
Pulled:
• #0 string: superstring • #1 signed integer: starting address Pushed:
u8 is how many bits to extract. If zero, SE_R is performed instead, | Pulled:
• #0 string: superstring • #1 signed integer: starting address • #2 signed integer: how many bits to extract Pushed:
|
An exception is thrown if any bit of the extract would be before the first bit of #1old, or after the first bit of #1old.
Find. The first eight instructions search a superstring to find an instance of a substring. If the substring is longer than the superstring, it cannot be found, but that is no cause to throw an exception. The final two instructions tell how many times the substring appears, but not where it is.
string find, location of ith instance of substring, starting at bit b … | |||||
SF_IR | … and proceeding to the right, i embedded | u8_11100_0101 | SF_BR | … and proceeding to the right, b embedded | u8_01100_0101 |
---|---|---|---|---|---|
Pulled:
• #0 string: superstring • #1 string: substring • #2 signed integer: b Pushed:
| Pulled:
• #0 string: superstring • #1 string: substring • #2 signed integer: i Pushed:
| ||||
SF_BR | … and proceeding to the right, substring embedded | b9_1101_0101 | SF_RR | … and proceeding to the right, all operands in registers | 09_1101_0101 |
Pulled:
• #0 string: superstring • #1 signed integer: i • #2 signed integer: b Pushed:
If b9 = 09, SF_RR is performed instead. | Pulled:
• #0 string: superstring • #1 string: substring • #2 signed integer: i • #3 signed integer: b Pushed:
| ||||
SF_IL | … and proceeding to the left, i embedded | u8_10100_0101 | SF_BL | … and proceeding to the left, b embedded | u8_00100_0101 |
Pulled:
• #0 string: superstring • #1 string: substring • #2 signed integer: b Pushed:
| Pulled:
• #0 string: superstring • #1 string: substring • #2 signed integer: i Pushed:
| ||||
SF_BL | … and proceeding to the left, substring embedded | b9_0101_0101 | SF_RL | … and proceeding to the left, all operands in registers | 09_0101_0101 |
Pulled:
• #0 string: superstring • #1 signed integer: i • #2 signed integer: b Pushed:
If b9 = 09, SF_RL is performed instead. | Pulled:
• #0 string: superstring • #1 string: substring • #2 signed integer: i • #3 signed integer: b Pushed:
|
SF_QE | string find, quantity of instances of substring, substring embedded | b9_0001_0101 | SF_QR | string find, quantity of instances of substring, substring in register | 09_0001_0101 |
---|---|---|---|---|---|
Pulled:
• #0 string: superstring Pushed:
b9 is the substring to seek, unless b9 = 09, in which case SF_QR is performed instead. If b9 = 108, then #0new = 1 + ##0old. | Pulled:
• #0 string: superstring • #1 string: substring Pushed:
If ##1old = 0, then #0new = 1 + ##0old. |
Join. Catenation is simple:
SJ | string join | ?_01_000_10_0101 |
---|---|---|
Pulled:
• #0 string: going to lower-order bits • #1 string: going to higher-order bits Pushed:
|
Boolean. The first instruction changes every bit of the string:
SB_N | string boolean not | ?_10_000_10_0101 |
---|---|---|
Pulled:
• #0 string: the operand Pushed:
|
The next instruction preforms the usual boolean operations bit-by-bit on two strings, if they are the same size. If not the same, an exception is thrown.
SB_O | string boolean, operation embedded | b4_?_00_000_10_0101 |
---|---|---|
Pulled:
• #0 string: an operand • #1 string: an operand Pushed:
|
The four operation bits within the opcode are interpreted thus:
Bit pattern | Value is 1 when … | Bit pattern | Value is 1 when … | |
---|---|---|---|---|
0000 | never | 1111 | always | |
0001 | #0 = 1 and #1 = 1 | 1110 | #0 = 0 or #1 = 0 | |
0010 | #0 = 1 and #1 = 0 | 1101 | #0 = 0 or #1 = 1 | |
0011 | #0 = 1 | 1100 | #0 = 0 | |
0100 | #0 = 0 and #1 = 1 | 1011 | #0 = 1 or #1 = 0 | |
0101 | #1 = 1 | 1010 | #1 = 0 | |
0110 | #0 ≠ #1 | 1001 | #0 = #1 | |
0111 | #0 = 1 or #1 = 1 | 1000 | #0 = 0 and #1 = 0 |