Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Instruction Set Reference

Every instruction has two spellings: the JSON name used in the CASM IR ("op": "push_int") and the CVM1 mnemonic used in the text assembly and the binary (PUSH). The tables below give both, the operand, and the stack effect. Behaviour was checked against crush-ast v0.13.0 (dc0d0278, 2026-12-03); the examples at the end of each section are run by this guide’s checker.

Reading stack effects

a b → c means: pop b (the top), pop a, push c. The rightmost value is always the top of the stack. … is “whatever was below”.

Operands in the text assembly follow the mnemonic: PUSH 42, LOAD 3, CAP_CALL "io.print" 1. In the IR they are named fields next to op.

Two instruction sets. The IR (casm::OpCode) is wider than the VM: it has names the VM bytecode does not (break, continue, await with a handle, call_host, import_var) and the VM bytecode has mnemonics the IR lowering never emits (ROT, PICK, CAST, the MATH_* family). The last section lists exactly which IR ops reach the VM.

Stack

JSON opCVM1OperandStack effectNotes
push_intPUSHvalue (i64)→ int
push_floatPUSH_F64value (f64)→ float
push_strPUSH_STRvalue (string)→ strtext form: quoted string
push_boolPUSH_BOOLvalue (bool; 1/0 in text)→ bool
push_nullPUSH_NULL—→ null
popPOP—a →
dupDUP—a → a a
swapSWAP—a b → b a
rotROT—a b c → b a cas observed on dc0d0278; not Forth’s ROT
pickPICK nn… → … vcopy the item n below the top (PICK 2 copies the third)
rollROLL nn… → … vmove the item n below the top to the top
—NOP——text/binary only
.func main
    PUSH 1
    PUSH 2
    PUSH 3
    ROLL 2          ; stack is now 2 3 1
    CAP_CALL "io.print" 1
    CAP_CALL "io.print" 1
    CAP_CALL "io.print" 1
    HALT
1
3
2

Variables

JSON opCVM1OperandStack effectNotes
loadLOAD slotname→ vpush the variable
storeSTORE slotnamev →pop into the variable
export_var—name—IR only; lowers to NOP (the value stays on the stack)
import_var—name—IR only; not lowered

In the IR a variable is a name; in CVM1 it is a numeric slot (0–65535) local to the current call frame. Frames do not share slots: a callee cannot see its caller’s variables.

Arithmetic and comparison

All binary operators pop b then a and push a OP b.

JSON opCVM1EffectNotes
add sub mulADD SUB MULa b → a∘bADD also concatenates strings
divDIVa b → a/binteger division on two ints (7/2 = 3), float otherwise
modMODa b → a%b
negNEGa → -a
eq neEQ NEa b → bool
lt gt le geLT GT LE GEa b → bool
and orAND ORa b → booleager — both operands are already evaluated. The && / || operators of Crush compile to jumps, not to these
notNOTa → boollogical not
bit_and bit_or bit_xorBITAND BITOR BITXORa b → a∘b
bit_notBITNOTa → ~a
shl shrSHL SHRa b → a<<b / a>>b
.func main
    PUSH 10
    PUSH 3
    SUB                 ; 10 - 3
    CAP_CALL "io.print" 1
    PUSH 7
    PUSH 2
    DIV                 ; integer division
    CAP_CALL "io.print" 1
    PUSH 12
    PUSH 10
    BITAND
    CAP_CALL "io.print" 1
    PUSH 1
    PUSH 4
    SHL
    CAP_CALL "io.print" 1
    HALT
7
3
8
16

Control flow

JSON opCVM1OperandStack effectNotes
jmpJMP labeltarget—unconditional
jmp_if_notJZ labeltargetcond →jump if cond is falsy
jmp_ifJNZ labeltargetcond →jump if cond is truthy
callCALL namefunction, argcargs… → [result]see below
retRET—[v] →return to the caller
haltHALT——stop the whole program
enter_tryENTER_TRY labeltarget—push an exception handler
exit_tryEXIT_TRY——pop it again (normal exit of the try body)
throwTHROW—v →unwind to the nearest handler, which receives v on its stack
break continue———in the IR enum only; the compiler lowers loops to jmps and never emits these

Jump operands are instruction indices in the IR and byte offsets in the binary; the text assembler takes label names. A value is falsy if it is false, null, 0, 0.0, the empty string or an empty array; everything else (including the string "0") is truthy.

Calling convention. The caller pushes the arguments last first, then CALLs. The callee’s body begins with one STORE per parameter, in declaration order, which pops the first argument first. RET returns to the caller; a function that produces a value leaves it on the stack for RET. Crush functions always end with PUSH_NULL / RET if they have no explicit return.

.func main
    PUSH 5              ; counter
    STORE 0
loop:
    LOAD 0
    JZ done             ; stop when the counter reaches 0
    LOAD 0
    CAP_CALL "io.print" 1
    LOAD 0
    PUSH 1
    SUB
    STORE 0
    JMP loop
done:
    PUSH 4
    CALL double
    CAP_CALL "io.print" 1
    HALT
.func double
    STORE 0
    LOAD 0
    PUSH 2
    MUL
    RET
5
4
3
2
1
8

Exceptions. ENTER_TRY handler records where to resume; THROW pops a value, unwinds, and jumps to handler with that value on top of the stack.

.func main
    ENTER_TRY handler
    PUSH_STR "boom"
    THROW
    EXIT_TRY            ; not reached
    JMP end
handler:
    CAP_CALL "io.print" 1   ; prints the thrown value
end:
    HALT
boom

Collections and objects

JSON opCVM1OperandStack effectNotes
new_arrayNEW_ARRAY nsizev₁…vₙ → arraypops n values. IR quirk: lowering ignores size and emits NEW_ARRAY 0 — build arrays with new_array + array_push, as the compiler does
array_push / arr_pushARR_PUSH—array v → array
array_pop / arr_popARR_POP—array → array v
index / arr_getARR_GET—array i → valso indexes objects/strings
arr_setARR_SET—array i v → array
len / arr_lenARR_LEN—array → nworks on strings too
make_rangeMAKE_RANGE—start end → range1..4 yields 1, 2, 3
new_tuple new_list new_vector new_setNEW_TUPLE n etc.sizev₁…vₙ → collplus TUPLE_PUSH LIST_PUSH VECTOR_PUSH SET_PUSH
new_objNEW_OBJ—→ objempty object
new_structNEW_OBJname→ objthe struct name is dropped on lowering
set_fieldSET_FIELD "f"name or fieldobj v → obj
get_fieldGET_FIELD "f"name or fieldobj → v
.func main
    PUSH 10
    PUSH 20
    PUSH 30
    NEW_ARRAY 3
    DUP
    ARR_LEN
    CAP_CALL "io.print" 1       ; 3
    PUSH 1
    ARR_GET
    CAP_CALL "io.print" 1       ; 20
    NEW_OBJ
    PUSH 5
    SET_FIELD "x"
    GET_FIELD "x"
    CAP_CALL "io.print" 1       ; 5
    HALT
3
20
5

Strings, math, types

String operations pop their operands in the order shown and push the result.

JSON opCVM1Stack effect
str_containsSTR_CONTAINSs pattern → bool
str_splitSTR_SPLITs delim → array
str_replaceSTR_REPLACEs old new → s
str_joinSTR_JOINarray delim → s
str_starts_with str_ends_withSTR_STARTS_WITH STR_ENDS_WITHs prefix → bool
str_to_upper str_to_lower str_trimSTR_TO_UPPER STR_TO_LOWER STR_TRIMs → s
math_powMATH_POWbase exp → float
math_sqrt math_abs math_round math_floor math_ceilMATH_SQRT …x → float
type_ofTYPEOFv → str — "int", "float", "str", "bool", "null", "array", "map" (an object), "tuple", …
castCAST "t"v → v' — "int", "float", "string"
—VEC_ADD VEC_DOT MAT_MULvector/matrix helpers, CVM1 only
.func main
    PUSH_STR "aXb"
    PUSH_STR "X"
    PUSH_STR "-"
    STR_REPLACE
    CAP_CALL "io.print" 1       ; a-b
    PUSH 2
    PUSH 10
    MATH_POW
    CAP_CALL "io.print" 1       ; 1024.0
    PUSH_STR "12"
    CAST "int"
    PUSH 1
    ADD
    CAP_CALL "io.print" 1       ; 13
    HALT
a-b
1024.0
13

(The Crush-level equivalents of these live in the standard-library capabilities — str.*, math.*, conv.* — and compile to CAP_CALLs, not to these opcodes. See the standard library.)

Capabilities

JSON opCVM1OperandStack effect
cap_callCAP_CALL "name" argcname, argca₁…aₙ → [result]
call_host—capsule, ic_id, method, argcIR only, not lowered
call_interface—handle, method, argcIR only, not lowered

CAP_CALL pops argc arguments (the first argument was pushed first) and invokes the named host capability. Whether it then pushes a result depends on the capability: io.print returns nothing, str.len returns a number. The compiler knows this and drops the pop it would otherwise emit after a statement-position call. If the capability is not registered by the host the VM stops with unknown capability: NAME; if it is registered but missing from the manifest, with capability not declared in manifest: NAME. See the capability chapter.

Records and Kinds (COSM)

Structs compile to Records of a Kind (crush-ast CRUSH-zorro-43). The program carries a kind table, written in text assembly as one .cosm line of JSON (crushc --emit casm prints a readable summary above it as ; comments), and functions that need their arity for bound methods are written .func name N. For this source:

struct P { x: Int }
impl P { fn get(self) { return self.x } }
let p = P { x: 7 }
print(p.get())
print(p.x)
7
7

crushc --emit casm writes:

; kind table (COSM): 1 Kind, 0 interfaces
;   kind P (crush): fields [x], members [get]
.cosm {"kinds":[{"name":"P","home_lang":"crush","span":{"line":1,"col":1},"storage":{"sealed":{"fields":[{"name":"x","type":"Int"}]}},"semantics":"reference","resolution":"none","receiver":"explicit_ref","construct":"literal","members":[{"name":"get","span":{"line":2,"col":10},"kind":"method","fn":"P::get"}],"equality":"structural"}],"interfaces":[]}
.func main 0
    NEW_RECORD "P"
    PUSH 7
    SET_FIELD "x"
    STORE 0
    LOAD 0
    CALL_MEMBER "get" 0
    CAP_CALL "io.print" 1
    LOAD 0
    GET_FIELD "x"
    CAP_CALL "io.print" 1
    PUSH_NULL
    RET
.func P::get 1
    STORE 0
    LOAD 0
    GET_FIELD "x"
    RET
7
7

The member opcodes are GET_MEMBER, SET_MEMBER, HAS_MEMBER, DEL_MEMBER, CALL_MEMBER name argc, CONSTRUCT kind argc, GET_SLOT, SET_SLOT, IS_KIND (what a struct pattern tests), COPY (value semantics) and NEW_RECORD. GET_FIELD/SET_FIELD on a Record are member accesses. Only the CVM1 VMs run them; FastVM, the JIT and the AOT backends refuse a program that needs them (see Engines, AOT and Walkers).

Polyglot, concurrency, AI and DOM

JSON opCVM1Notes
exec_langEXEC_LANG "json"run a @python { } / @javascript { } / @bash { } block; the operand is a JSON string with lang, code, var_count and the marshalling lists. Needs the matching polyglot.<lang> capability — see Polyglot
spawn yield awaitSPAWN n YIELD AWAITreal green tasks on the CVM1 VMs, see Concurrency
ai_query … (10 names)AI_QUERY … (10 opcodes)gated through ai_native.<kind> capabilities; ai_capability_discovery, ai_adaptation_request, ai_semantic_switch are refused. See AI-Native CAST
dom_query dom_mutate dom_event_listenerDOM_QUERY …stubs: lowered to NOP; the dom_native.* gates exist only for hand-written CVM1

What lowers to CVM1

crush_lang_sdk::compile::casm_to_vm is the bridge from the JSON IR to a runnable program. It handles exactly these IR operations:

Loweredevery IR operation except the rows below: the stack, arithmetic, comparison, logic, bit (bit_*, shl, shr), math_*, type_of, cast, string, array/collection, object and COSM member ops, calls, jumps, try/throw, exec_lang, spawn/yield/await, and ten ai_* ops
Lowered with a lossnew_array (size ignored: always empty), new_struct (→ NEW_OBJ, name dropped), export_var and the dom_* ops (→ NOP)
Rejectedbreak, continue (no loop target in the instruction), import_var, call_host, call_interface, and the declined ai_capability_discovery, ai_adaptation_request, ai_semantic_switch: they fail with Unsupported CVM1 opcode: NAME at FUNCTION:INDEX

(crush-ast keeps this classification exhaustive in its crush-lang-sdk/tests/casm_lowering_completeness.rs; the spot checks below were run against dc0d0278.) A bit shift lowers and runs:

{
  "version": "1.0",
  "functions": { "main": { "body": [
    {"op": "push_int", "value": 1},
    {"op": "push_int", "value": 3},
    {"op": "shl"},
    {"op": "cap_call", "name": "io.print", "argc": 1},
    {"op": "halt"}
  ] } },
  "manifest": { "permissions": ["io.print"] }
}
8

while break is refused:

{
  "version": "1.0",
  "functions": { "main": { "body": [
    {"op": "push_int", "value": 1},
    {"op": "break"},
    {"op": "halt"}
  ] } },
  "manifest": { "permissions": ["io.print"] }
}