ZASM is a human-facing assembly language that lowers to WAT. This document defines its register model, instruction set, directives, and primitive calling conventions. All conforming assemblers/linkers MUST follow these rules.
Registers are i32 locals in the generated WAT.
HL: primary accumulator and pointer (slice ptr)DE: secondary accumulator and length (slice len)A: byte accumulatorBC: general purposeIX: general purpose
Rules:
- Registers are function-local.
HL/DEform the standard slice(ptr,len)ABI.- There is no flags register; comparisons use
CPand$cmp.
LD r, imm|symLD r1, r2LD A, (HL)LD (HL), A
r/r1/r2 are from {HL,DE,A,BC,IX}. (HL) is the only supported memory form.
INC HL|DE|BCDEC DE|BCADD HL, #immADD HL, DESUB HL, #immSUB HL, DE
CP HL, rhsrhsisDE, immediate, or a symbol constant.- Sets
$cmp = HL - rhs(signed).
JR labelJR COND, labelwithCONDin{EQ,NE,LT,LE,GT,GE}(signed compare vs 0).
CALL symRET
DB— data bytesDW— i32 constantRESB— reserve bytes (zeroed)STR— data bytes + auto<name>_lenEQU— constant symbol from a numeric literalPUBLIC— export a symbolEXTERN— import a function symbol
All symbols starting with _ are reserved for host primitives.
- Inputs:
HL = dst_ptr,DE = cap - Returns:
HL := nread
- Inputs:
HL = ptr,DE = len
- Inputs:
HL = topic_ptr,DE = topic_len,BC = msg_ptr,IX = msg_len
- Input:
HL = size - Return:
HL := ptr(or-1on OOM)
- Input:
HL = ptr
- Unknown mnemonic/directive: hard error.
- Unknown symbol: hard error.
- Duplicate symbol: hard error.
- Emitted IR and WAT MUST be byte-for-byte deterministic for identical inputs.
- Data layout is deterministic: fixed base offset and 4-byte alignment.
- No timestamps, random IDs, or host-dependent formatting.
- ISA version is v1.0.0.
- Backward-compatible additions MAY be introduced in later minor versions.