NI-Script Tutorial

The Basics


Data Movement Commands

CommandMeaningExplanation
load <val>Load constant into zpPuts a value from data ROM into zp.
set ar1Move zp to ar1Copies zp into ar1.
set ar2Move zp to ar2Copies zp into ar2.
set raSet the current RAM address to zpSelects memory cell for RAM operations.
set ramStore zp into current RAM addressSaves zp into RAM at ra.
set zpeSet zpe register to zpCopies zp into zpe (loop counter, temp storage).
get ramLoad zp from current RAMReads RAM at ra into zp.
get zpeLoad zp from zpeCopies zpe into zp.
get inputRead user input into zpMain input channel.
get countGet the program counterReads the current instruction pointer into zp.

Arithmetic Commands

CommandMeaningExplanation
addar1 + ar2 → zpAdds ar1 and ar2, stores in zp.
subar1 - ar2 → zpSubtracts ar2 from ar1, result goes into zp.

Bitwise Logic Commands

CommandMeaningExplanation
andBitwise ANDLogical AND of ar1 and ar2 → zp.
orBitwise ORLogical OR of ar1 and ar2 → zp.
xorBitwise XORLogical XOR of ar1 and ar2 → zp.

Comparison and Control Flow

CommandMeaningExplanation
compJump if ar1 == ar2Compares ar1 and ar2; jumps to zp if equal.
ar2_gt_ar1Jump if ar2 > ar1Jump to zp if ar2 > ar1.
ar1_gt_ar2Jump if ar1 > ar2Jump to zp if ar1 > ar2.

Jump Commands

CommandMeaningExplanation
jump <addr>Jump to addressMoves execution to specified address; counts as 2 instructions.
jumpzpJump to zpJump to address stored in zp (dynamic jump).

Output Commands

CommandMeaningExplanation
outputPrint zpOutputs zp to main output.
output2Print zp to secondary outputOutputs zp to a second channel.
output3Print zp to third outputOutputs zp to a third channel.
output4Print zp to fourth outputOutputs zp to a fourth channel.

Extra Instruction Details

SR (Sector Register): selects active Program or Data ROM sector. Each sector holds 255 instructions. When a sector ends, the CPU automatically jumps to the next sector. Use set sr to select a sector and get sr to read it.

Program Counter: get count reads the current instruction pointer into zp.

Extra Inputs: get input2, get input3, get input4 read additional inputs independently into zp.

Extra Outputs: output2, output3, output4 write zp values to multiple output channels.

Jump Instructions: jump <addr> counts as 2 instructions. jumpzp jumps to the address stored in zp.


Summary Table of Commands

CommandDescriptionExternal Data Needed?
load <val>Load constant into zpYes (from data ROM)
set ar1Move zp to ar1No
set ar2Move zp to ar2No
set raSet RAM addressNo
set ramSet current RAM to zpNo
set zpeSet zpe to zpNo
get ramSet zp to RAMNo
get zpeSet zp to zpeNo
get inputSet zp to user inputNo
get input2Set zp to user input 2No
get input3Set zp to user input 3No
get input4Set zp to user input 4No
get countGet the current address (program counter)No
get srGet active ROM sectorNo
set srSet active ROM sectorNo
addAdd ar1 + ar2 → zpNo
subSubtract ar1 - ar2 → zpNo
andBitwise ANDNo
orBitwise ORNo
xorBitwise XORNo
compJump if ar1 == ar2No
ar2_gt_ar1Compare ar2 > ar1No
ar1_gt_ar2Compare ar1 > ar2No
outputOutput zpNo
output2Output2 zpNo
output3Output3 zpNo
output4Output4 zpNo
jump <addr>Jump to addressYes (address), counts as 2 instructions
jumpzpJump to value stored in zpNo

Simple NI-Script Tutorial

This example demonstrates a basic program flow:

; Step 1: Select data ROM sector
load 0
set sr

; Step 2: Load values into registers
load 10
set ar1
load 5
set ar2

; Step 3: Perform arithmetic
add

; Step 4: Output the result
output

Explanation: