Skip to main content

Script OpCodes

Operational Codes that can be used in .nnpscript files


OpCode Reference

This page documents all of the operational codes that are native to the PM through the firmware source code at app/ScriptInterpreter.c and in the NNP-API Script assembler at apps/Scripting/assembler.m. These opcodes are used to manipulate in variables, memory, and system state in .nnpscript scripts.

Script Control

OpCodeOp#OperandsDescription
NOP00No operation — skip
EXIT2550Terminate script
STARTSCPT901Start script at pointer
STOPSCPT911Stop script at pointer
RUNONCE921Run script pointer once
RUNIMM931Run script pointer immediate
RUNNEXT941Run script pointer next
RUNMULT951Decode operand for starting scripts
RESETGLOBALS961Reset global vars for script (0 = all)
TDEL701Time delay in milliseconds

Examples:

NOP
EXIT
STARTSCPT 21
STOPSCPT 7
TDEL 500

System / Network

OpCodeOp#OperandsDescription
NMT022NMT command — node, cmd
NMT133NMT command — node, cmd, param
NMT244NMT command — node, cmd, 2 params
GNS711Get node status (Op0 = node → status)
NODESCAN971Scan for node

Examples:

NMT0 7 0x95 % hex value 0x95 sent to power module (node:7) turns the network ON
NMT1 7 0x8D 1 % hex value 0x8D sent to power module (node:7) starts script at Script ID:1

Move

OpCodeOp#OperandsDescription
MOV11Move value from source to destination

Examples:

MOV 100 => myVariable
MOV N7:1006.0 => syncPeriod
MOV $syncPeriod => N7:1006.0|UNS32

Counter

OpCodeOp#OperandsDescription
INC150Increment result register
INCS780Saturating increment result register
DEC160Decrement result register
DECS790Saturating decrement result register

Branch

OpCodeOp#OperandsDescription
GOTO680Unconditional jump to label
BEQ622Branch if Op0 == Op1
BGT612Branch if Op0 > Op1
BGTE642Branch if Op0 >= Op1
BLT602Branch if Op0 < Op1
BLTE652Branch if Op0 <= Op1
BNE632Branch if Op0 != Op1
BNZ661Branch if Op0 != 0
BZ671Branch if Op0 == 0
BBITON692Branch if bit Op1 in Op0 is ON
BBITOFF722Branch if bit Op1 in Op0 is OFF

For branch instructions, the destination operand is a code block label name.

Examples:

GOTO => MainLoop
BEQ sensorValue threshold => DoAction
BNE count;0 => StimState
BLT temperature;$threshold => TooHot
BNZ errorFlag => HandleError
BBITON statusReg 3 => BitIsSet

Math

OpCodeOp#OperandsDescription
ABS211ABS(Op0) → result
ADD105Add Op0 + Op1 + ... Opn
ADDS755Saturating add Op0 + Op1 + ... Opn
SUB112Subtract Op0 from Op1
SUBS762Saturating subtract Op0 from Op1
MUL125Multiply Op0 × Op1 × ... Opn
MULS775Saturating multiply Op0 × Op1 × ... Opn
DIV132Integer divide Op0 ÷ Op1
MODD392Modulo division → remainder
SIGN501Returns +1, 0, or -1 based on sign of Op0
CHS340Change sign of result register
DIFF142Absolute value of (Op0 − Op1)
MAX172Maximum of Op0 and Op1
MIN182Minimum of Op0 and Op1
INTERPOL1003Interpolate X(Op0) in table Op1 (X values) against Op2 (Y values) → result (fixed-point)

Examples:

ADD counter 1 => counter
SUB maxValue currentValue => remaining
MUL frequency 10 => scaledFreq
DIV 1000 frequency => period
ABS error => absError
MAX a b => larger
MODD value 100 => remainder

Trigonometry

All trig functions work in degrees.

OpCodeOp#OperandsDescription
SIN431Sin(Op0°) → result
COS441Cos(Op0°) → result
TAN451Tan(Op0°) → result
ASIN461ArcSin(Op0) → result (degrees)
ACOS471ArcCos(Op0) → result (degrees)
ATAN481ArcTan(Op0) → result (degrees)
ATAN2492ArcTan2(y=Op0, x=Op1) → result (degrees)

Fixed-Point Arithmetic

OpCodeOp#OperandsDescription
ITQ241Integer to fixed-point
UTQ251Unsigned integer to fixed-point
QTI311Fixed-point to integer
QTU321Fixed-point to unsigned integer
QTS332Fixed-point to string; field width = Op1
ADDQ262Fixed-point addition Op0 + Op1 → result
SUBQ272Fixed-point subtraction Op0 − Op1 → result
MULQ282Fixed-point multiplication Op0 × Op1 → result
DIVQ292Fixed-point division Op0 ÷ Op1 → result
SQRTQ301Square root of Op0 → result

Bit Operations

OpCodeOp#OperandsDescription
AND372Bitwise AND
OR382Bitwise OR
XOR402Bitwise exclusive OR → result
COMP411Bitwise complement Op0 → result
SLFT202Op0 << Op1 (logical shift left)
SRGT192Op0 >> Op1 (logical shift right)
SIL352Arithmetic shift left
SIR362Arithmetic shift right
BITON222Set bit Op1 in Op0 → result
BITOFF232Clear bit Op1 in Op0 → result
BITSET732Set or clear bit Op1 based on Op0 (0 = clear, ≠0 = set) → result
BITCNT741Count number of set bits in Op0 → result
BBITON692Branch if bit Op1 in Op0 is ON
BBITOFF722Branch if bit Op1 in Op0 is OFF

Vector Operations

OpCodeOp#OperandsDescription
FIFO1041First-in first-out shift: Buf[i] = Buf[i-1], Buf[0] = new value → Buf
VECMOV1054Vector move: source array, source start index, dest start index, count → dest array
VECADD1212VectorA + VectorB (or scalar) → vector
VECSUB1222VectorA − VectorB (or scalar) → vector
VECMUL1232VectorA × VectorB element-wise (or scalar) → vector
VECDIV1242VectorA ÷ VectorB element-wise (or scalar) → vector
VECDOT1252VectorA · VectorB → dot product (scalar)
VECSUM1131Sum of all elements → scalar
VECPROD1141Product of all elements → scalar
VECMEAN1121Mean of all elements → scalar
VECMED1101Median value → scalar
VECMEDI1111Index of median value → scalar
VECMAX1061Maximum element value → scalar
VECMAXI1071Index of maximum element → scalar
VECMIN1081Minimum element value → scalar
VECMINI1091Index of minimum element → scalar
VECMAG1151Vector magnitude → scalar
VECMAG21161Vector magnitude squared → scalar

String Operations

OpCodeOp#OperandsDescription
ITS62Integer to string; Op0 = value, Op1 = field width
ITS082Integer to null-terminated string; Op1 = field width
UTS72Unsigned integer to string; Op1 = field width
UTS092Unsigned integer to null-terminated string; Op1 = field width
CATMOV55Concatenate Op0 + Op1 + ... → result
CATMOV0805Concatenate Op0 + Op1 + ... → result with null terminator
CATMOVCR815Concatenate Op0 + Op1 + ... → result with carriage return
SUBSTR423Substring: Op0 = string, Op1 = start index, Op2 = length → result

Examples:

ITS myInt 5 => myStr
SUBSTR fullString 0 4 => firstFour

Logging

OpCodeOp#OperandsDescription
FILE_CLOSE891Close log file (Op0 = file ID)