Overview
The assembler uses a three-stage pipeline:- Lexer - Tokenizes the source code into a stream of tokens
- Parser - Builds an Abstract Syntax Tree (AST) from the tokens
- Compiler - Performs two-pass compilation to emit bytecode:
- Pass 1: Collect label addresses and constants
- Pass 2: Emit bytecode with resolved label references
Language Features
60+ Instructions
Full VM instruction set support including arithmetic, bitwise, memory, storage, and control flow
Symbolic Labels
Use labels as jump targets instead of raw addresses
Directives
.entry for entry points, .const for named constantsComments
Semicolon-style comments for code documentation
Basic Syntax
Instructions
Instructions are case-insensitive and follow a simple format:Registers
Minichain VM has 16 general-purpose registers (R0-R15):Register names are case-insensitive. Both
R0 and r0 are valid.Labels
Labels define symbolic names for code locations::) and must be on their own line. They can be referenced in LOADI instructions to load their addresses.
Directives
Directives provide metadata and constants:.entry Directive
Specifies the program entry point:
.const Directive
Defines named constants:
Comments
Comments start with semicolon (;) and continue to end of line:
Number Literals
The assembler supports both decimal and hexadecimal numbers:Instruction Encoding
Instructions are encoded compactly in bytecode:No operands (1 byte)
No operands (1 byte)
Instructions like
HALT, NOP, RET, REVERTSingle register (2 bytes)
Single register (2 bytes)
Instructions like
JUMP R0, LOG R1, CALLER R2Two registers (2 bytes)
Two registers (2 bytes)
Instructions like
MOV R0, R1, SLOAD R2, R3Three registers (3 bytes)
Three registers (3 bytes)
Instructions like
ADD R0, R1, R2, MUL R3, R4, R5Register + immediate (10 bytes)
Register + immediate (10 bytes)
Instructions like
LOADI R0, 100, ADDI R1, R2, 50Example Program
Here’s a complete program demonstrating various features:counter.asm
- Loads storage slot 0 into R0
- Reads the value from storage into R1
- Adds 1 to the value
- Stores the result back to storage
- Halts execution
Compilation
Assembly code is compiled to bytecode using the assembler:The assembler validates syntax, checks for undefined labels, and ensures registers are in the valid range (R0-R15).
Error Handling
The assembler provides clear error messages:Next Steps
Writing Contracts
Learn how to structure complete smart contracts
Instruction Reference
Complete reference of all VM instructions