Skip to content

NetASM Instruction Set

Muhammad Shahbaz edited this page Jun 8, 2015 · 2 revisions

NetASM instructions are grouped into three main categories:

  • Initialization Instructions
  • Topology Instructions
  • Control Instructions

The syntax of the NetASM language is defined in the Core/Language.hs file.

Initialization Instructions

Instruction Description Usage
MKR (Reg, Val) Make Register: make a new register (r) with default value (v) MKR(“r0”, 0): make a register r0 with default value of 0
MKT (Tbl, Tbl) Make Table: Make a new dynamic table (t) and load it with content from static table (t0) MKT(t0, v0): make a new dynamic table t0 and load it with defaults values v0. t0 and v0 are defined using Dynamic and Static table types.
Tbl = Dynamic (String, (Int, [Fld]))
Tbl = Static  ([Ptrn]) 

Topology Instructions

Instruction Description Usage
HLT Halt: Indicates the end of topology code see Hub example above
OPF (Fld, Fld, Op, Val) f0 = f1 op v: apply operation (op) on field (f1) and value (v) and store it in field (f0) OPF(“outport”, “inport”, Add, 1): Add 1 to inport and store it in outport field
OPR (Reg, Reg, Op, Val) r0 = r1 op v: apply operation (op) on register (r1) and value (v) and store it in register (r0) OPF(“r0”, “r1”, Add, 1): Add 1 to r1 and store it in r0 register
LDR (Reg, Val) Load Register: load register (r) with value (v) LDR(“r0”, 10): Loads registers r0 with value 10
LBL (Lbl) Label: label (l) for jump and branch instructions LBL(“l0”): Creates a label l0
JMP (Lbl) Jump: jump control to label (l) JMP(“l0”): Skips the instructions till the label
BRR (Reg, CmpOp, Val, Lbl) if (r op v) then l else fallthrough: branch control to label (l) if the result of the comparison on register (r) and value (v) is true else fall through to the next instruction BRR(“r0”, Gt, 10, “l0”): Jump to label l0, if r0 is greater than 10
IBRTF (Tbl, Fld, Lbl) Branch control to label (l) if any pattern in table (t) is not present in the header, else, move to the next instruction and set the field (f) to matched index IBRTF(t0, “i”, “l0”): Jump to label l0 if any pattern in table t0 does not match the header, else, move to the next instruction and set the field i to matched index
LDFTF (Tbl, Fld) Load header with table at field: load header with the table (t) at index field (f) LDFTF(t0, “i”): Load header with contents of table t0 at index value in field i
LDFTR (Tbl, Reg) Load header with table at register: load header with the table (t) at index register (r) LDFTF(t0, “r0”): Load header with contents of table t0 at index value in register r0
Op = Add | Sub | And | Or | Xor 
CmpOp = Eq | Neq | Lt | Gt | Le | Ge 

Control Instructions

Instruction Description Usage
WRR (Reg, Val) Write Register: write register (r) with value (v) WRR(“r0”, 10): Write register r0 with default value of 10
WRT (Tbl, Ptrn, Val) Write table with pattern [(f,v)] at index value: write table (t) with pattern (p) at index value (v) WRT(t0, [("inport", 1)], 1): Write the pattern, inport=1, in table t0 at index value 1

Clone this wiki locally