String Expansion Processor

Overview

The String Expansion Processor is an optional NCS/e expansion module providing advanced text processing, comparison, structured-data, and encoding operations.

The base NCS/e CPU provides common string operations directly, including copying, case conversion, length, searching, concatenation, insertion, substring extraction, replacement, padding, trimming, and character conversion.

The String Expansion Processor provides operations that are more specialized or computationally expensive.

Programs using these verbs require a compatible String Expansion Processor to be installed.


String comparison

The base CPU provides BSEQ and BSNEQ for string equality and inequality comparisons.

The String Expansion Processor additionally provides lexicographical ordering and direct lexicographical branch operations.

String comparisons are case-sensitive and compare Unicode codepoints.


STR.CMP — Compare Strings

STR.CMP <dst> <lhs> <rhs>

Compares two strings lexicographically and stores the result in an integer register.

Operands

Position Name Type Range Description
1 dst Integer register Destination register.
2 lhs String value Left-hand operand.
3 rhs String value Right-hand operand.

Modified registers

Register Description
dst Comparison result.

Result

Result Meaning
-1 lhs sorts before rhs.
0 Both strings are equal.
1 lhs sorts after rhs.

Examples

STR.CMP r0 s0 s1

BLT $before r0 0
BEQ $equal r0 0
BGT $after r0 0

STR.BGT — Branch String Greater Than

STR.BGT <target> <lhs> <rhs>

Branches if the left-hand string sorts after the right-hand string.

Operands

Position Name Type Range Description
1 target Branch target Branch target.
2 lhs String value Left-hand operand.
3 rhs String value Right-hand operand.

Modified registers

Register Description
pc Updated if the branch is taken.

Examples

STR.BGT $after s0 s1
-- > Execution continues at `$after` if s0 sorts after s1

STR.BGE — Branch String Greater Than or Equal

STR.BGE <target> <lhs> <rhs>

Branches if the left-hand string sorts after or is equal to the right-hand string.

Operands

Position Name Type Range Description
1 target Branch target Branch target.
2 lhs String value Left-hand operand.
3 rhs String value Right-hand operand.

Modified registers

Register Description
pc Updated if the branch is taken.

Examples

STR.BGE $match_or_after s0 s1

STR.BLT — Branch String Less Than

STR.BLT <target> <lhs> <rhs>

Branches if the left-hand string sorts before the right-hand string.

Operands

Position Name Type Range Description
1 target Branch target Branch target.
2 lhs String value Left-hand operand.
3 rhs String value Right-hand operand.

Modified registers

Register Description
pc Updated if the branch is taken.

Examples

STR.BLT $before s0 s1

STR.BLE — Branch String Less Than or Equal

STR.BLE <target> <lhs> <rhs>

Branches if the left-hand string sorts before or is equal to the right-hand string.

Operands

Position Name Type Range Description
1 target Branch target Branch target.
2 lhs String value Left-hand operand.
3 rhs String value Right-hand operand.

Modified registers

Register Description
pc Updated if the branch is taken.

Examples

STR.BLE $match_or_before s0 s1

Numeric encoding

STR.HEX — Integer to Hexadecimal

STR.HEX <dst> <num>

Converts an integer to its hexadecimal string representation.

STR.HEX s0 255
-- > s0 = "FF"

STR.HEXD — Hexadecimal to Integer

STR.HEXD <dst> <str>

Converts a hexadecimal string to an integer.

STR.HEXD r0 "FF"
-- > r0 = 255

URL encoding

The String Expansion Processor provides URL encoding and decoding operations.

Planned operations include:

STR.URLENC
STR.URLDEC

These operations convert between ordinary strings and their percent-encoded representation.


JSON

The String Expansion Processor provides operations for working with JSON-encoded data.

Planned functionality includes:

  • Reading values from JSON documents.
  • Writing or replacing values.
  • Creating JSON arrays and objects.
  • Inspecting JSON value types.

Exact verbs and signatures are to be specified.


Regular expressions

The String Expansion Processor may provide regular-expression operations for advanced searching, matching, and replacement.

Exact verbs and signatures are to be specified.