We are currently working on new rules for what content should and shouldn't be allowed on this website, and are looking for feedback! See Esolang:2026 topicality proposal to view and give feedback on the current draft.
Crawssembly
- This is still a work in progress. It may be changed in the future.
| Paradigm(s) | Imperative, Assembly |
|---|---|
| Designed by | Jonah Crawford |
| Appeared in | 2025 |
| Memory system | Cell-based |
| Dimensions | one-dimensional |
| Computational class | Turing complete |
| Reference implementation | Crawssembly |
| File extension(s) | .craw |
Crawssembly (commonly abbreviated casm) is an educational assembly-like programming language, instruction set and virtual machine created by Jonah Crawford in 2025. It is designed as an approachable introduction to low-level programming and computer architecture. Crawssembly can be easily identified via some unique conventions, notably using lowercase text rather than uppercase text, the latter being a common convention in assembly languages.[1]
Rather than targeting an existing processor architecture, Crawssembly defines its own fictional computer. The architecture uses 32-bit signed data, 256 registers, 21-bit machine instructions, numeric labels, random-access memory, persistent storage, and a collection of virtual I/O devices. Programs can interact with a terminal, framebuffer, keyboard, mouse and synthesised audio in addition to ordinary memory and file input/output.
Crawssembly is unusual among languages documented on the Esolang Wiki in that esotericism was not one of its original design goals. It is deliberately intended to make low-level programming easier, rather than more difficult. Its esoteric characteristics instead arise from the design of its artificial processor architecture and from features such as 21-bit instructions, 256 registers, dynamically executable machine code, unusual control flow, and high-level facilities implemented as assembly-language libraries.
The reference implementation is primarily written in Rust and consists of a compiler and virtual machine. The wider project includes the Crawssembly Standard Library (CSL), the Crawssembly Package Manager (CPM), and an embeddable Rust library.
Design philosophy
Crawssembly was designed as a bridge between high-level programming and conventional assembly language.
Real-world instruction sets such as x86 and ARM contain numerous architectural features resulting from performance requirements, backwards compatibility and the history of the hardware they target. Crawssembly instead begins with the concepts that the programmer is intended to learn and constructs an artificial machine around them.
Consequently, the programmer is exposed directly to concepts including:
- registers;
- signed binary integers;
- arithmetic and bitwise operations;
- jumps and conditional execution;
- memory addresses;
- volatile and persistent storage;
- machine-code encoding;
- the fetch-decode-execute cycle;
- memory-mapped-style device interaction;
- stacks and heaps;
- executable code represented as data.
The core virtual machine deliberately leaves out several operations that would ordinarily be expected from a practical architecture. For example, multiplication, division, exponentiation, stacks, and dynamic memory allocation are implemented in Crawssembly itself rather than being fundamental processor operations.
This gives Crawssembly two levels of abstraction: a deliberately small virtual processor, and software written for that processor which gradually constructs more sophisticated facilities.
The Crawssembly machine
A Crawssembly program executes on a register-based virtual machine.
The machine's ordinary values are signed 32-bit integers represented using two's complement.
Registers
There are 256 registers, numbered hexadecimal from r00 through rff:
r00 r01 r02 ... r09 r0a ... rfe rff
Most registers are general-purpose, but several have special meanings.
| Register | Purpose |
|---|---|
r00
|
Program input. This register exposes bytes supplied through an input file. |
r01
|
Arithmetic and comparison result register. Operations performed by cal store their result here, and most conditional instructions inspect it.
|
ree
|
Error information, including errors reported by I/O operations and standard-library routines. |
ref
|
Character output. Writing a character code to this register prints the corresponding character. |
rff
|
Binary output. The low eight bits of values written here are appended to the program's output. |
This means that the small program
sav 72 ref sav 105 ref
prints:
Hi
while
sav 72 rff sav 105 rff
writes the two bytes representing Hi to the program's binary output.
Constant registers
Fourteen registers near the end of the register space contain predefined constants.
| Register | Value | Meaning |
|---|---|---|
rf0 |
314159265 | π × 10⁸ |
rf1 |
271828182 | e × 10⁸ |
rf2 |
30102999 | log₁₀(2) × 10⁸ |
rf3 |
47712125 | log₁₀(3) × 10⁸ |
rf4 |
69897000 | log₁₀(5) × 10⁸ |
rf5 |
69314718 | ln(2) × 10⁸ |
rf6 |
109861228 | ln(3) × 10⁸ |
rf7 |
160943791 | ln(5) × 10⁸ |
rf8 |
141421356 | √2 × 10⁸ |
rf9 |
173205080 | √3 × 10⁸ |
rfa |
223606797 | √5 × 10⁸ |
rfb |
125992105 | ∛2 × 10⁸ |
rfc |
144224957 | ∛3 × 10⁸ |
rfd |
170997594 | ∛5 × 10⁸ |
rfe |
2147483647 | 2³¹ − 1 |
The mathematical constants are scaled by 10⁸ because Crawssembly's basic data type is an integer.
Basic syntax
Crawssembly source files conventionally use the .craw extension.
Instructions are line-oriented:
sav 10 r02 cal add 5 r02 io text int r01 stp
This program stores 10 in r02, adds 5 to it, prints the resulting value of 15, and terminates.
Comments begin with a semicolon:
sav 42 r02 ; the answer
Whitespace is not structurally significant, although indentation is commonly used around conditional regions.
Immediate operands are signed eight-bit integers, giving an ordinary immediate range of −128 to 127. Larger values must therefore be constructed, loaded, or obtained by other means.
Core instructions
Despite the size of the virtual machine's environment, the CPU instruction set is relatively small.
sav
sav copies a value into a register.
sav 42 r02 sav r02 r03
The first instruction places 42 into r02. The second copies the contents of r02 into r03.
cal
All primitive arithmetic and bitwise operations are performed using cal:
cal OPERATION VALUE REGISTER
The result is always placed in r01.
Eight primitive operations are available:
| Operation | Meaning |
|---|---|
not |
bitwise NOT |
and |
bitwise AND |
or |
bitwise OR |
xor |
bitwise XOR |
shl |
logical shift left |
shr |
logical shift right |
sar |
arithmetic shift right |
add |
addition |
For example,
sav 17 r02 cal add 25 r02
leaves 42 in r01.
There is deliberately no primitive multiplication or division instruction.
Derived arithmetic operations
The limited arithmetic instruction set of Crawssembly requires several common mathematical operations to be constructed from simpler instructions.
Negation
Since Crawssembly uses two's complement integers, negation can be performed by inverting every bit of a value and adding one.
cal not r02 rff cal add 1 r01
The result is the negation of r02, stored in r01.
The register rff is conventionally supplied as the unused operand of the unary NOT operation.
Subtraction
Subtraction can be implemented by negating the second operand and adding it to the first.
cal not r03 rff cal add 1 r01 cal add r02 r01
This calculates the difference between r02 and r03 without a dedicated subtraction instruction.
Bit masking
Individual bits or groups of bits within a register can be extracted or modified using the logical operations provided by cal.
| Operation | Example | Result when the initial value is 100 |
|---|---|---|
| Extract the lowest four bits | cal and 15 r02 |
4 |
| Set bit 1 | cal or 2 r02 |
102 |
| Clear bit 5 | cal and -33 r02 |
68 |
| Toggle bits 1 and 5 | cal xor 34 r02 |
70 |
Bit positions are numbered from zero, beginning with the least significant bit. The results of these operations are stored in r01 rather than modifying the operand register directly.
Parity detection
The parity of an integer can be determined by extracting its least significant bit:
cal and 1 r02
The result is zero for an even integer and one for an odd integer. This technique is used in algorithms such as the Collatz sequence.
Multiplication by powers of two
A logical left shift can be used to multiply an integer by a power of two, provided the result remains representable.
sav 3 r03 cal shl r02 r03
This multiplies the value of r02 by eight.
An arithmetic right shift can similarly be used to divide non-negative integers by powers of two, discarding any fractional component.
inp, nop and stp
inp advances the input stream to its next byte.
nop performs no operation.
stp terminates execution.
Labels and control flow
Labels in Crawssembly are numeric.
A line containing only a number defines a label:
100
The basic unconditional jump is jmp:
1 sav 65 ref jmp 1
This program prints A indefinitely.
Label identifiers and reuse
The documented range of usable label identifiers is 0 to 65534. The encoding corresponding to label 65535 is reserved for the stp instruction.
A label associates an identifier with a position in the program. The association can subsequently be removed using rmv, allowing the identifier to be reused.
10 nop rmv 10 10 sav 42 r02
The two occurrences of label 10 refer to different positions in the program.
This mechanism is particularly useful when including standard-library routines, as temporary label identifiers can be released after use.
Conditional jumps
Conditional jumps examine r01:
| Instruction | Behaviour |
|---|---|
jmg n |
Jump to n if r01 > 0
|
jmz n |
Jump to n if r01 = 0
|
jml n |
Jump to n if r01 < 0
|
Thus a conventional loop can be constructed as:
sav 10 r02 1 io text int r02 io text newline rff cal add -1 r02 sav r01 r02 jmg 1 stp
which outputs the integers from 10 down to 1.
Conditional regions
Crawssembly also contains an unusual second form of conditional execution.
ifg, ifz and ifl begin conditional regions, while rmv terminates them.
| Instruction | Execute region if |
|---|---|
ifg n |
r01 > 0
|
ifz n |
r01 = 0
|
ifl n |
r01 < 0
|
For example:
sav 10 r01 ifg 100 sav 89 ref sav 101 ref sav 115 ref rmv 100
prints Yes.
The indentation has no semantic significance. The numbered scope and corresponding rmv determine the region.
Indirect jumps
fgo provides indirect control flow.
For an ordinary non-zero operand,
fgo 42
transfers execution to label 42.
Unlike conventional symbolic assembly labels, Crawssembly's label identifiers are themselves representable as integer values. Consequently, they can be calculated at runtime and used with the indirect jump instruction fgo 0.
fgo 0
uses the value currently stored in r01 as the label identifier.
Consequently, a program can calculate its next destination at runtime. This can be used to implement constructs such as jump tables and dispatch systems.
Input and output
Hardware-like facilities are accessed through a single io instruction:
io DEVICE COMMAND REGISTER
Unlike sav and cal, I/O operations take register operands rather than immediate values.
The architecture currently defines eight device classes:
| Device | Purpose |
|---|---|
text |
terminal output and formatting |
time |
timestamps and delays |
screen |
graphical framebuffer |
keyboard |
keyboard state |
mouse |
mouse state |
speaker |
audio synthesis |
mem |
volatile random-access memory |
disk |
persistent storage |
This arrangement keeps peripheral operations outside the core arithmetic instruction set.
I/O operations can report errors through ree. Defined errors distinguish successful operations, invalid commands, invalid values and unavailable devices.
Text output
The text device can output characters, signed integers and hexadecimal values:
sav 42 r02 io text int r02 io text newline rff io text hex r02
It also supports spaces, terminal clearing, timestamps and RGB terminal colours.
For single characters, writing directly to ref is shorter:
sav 67 ref sav 114 ref sav 97 ref sav 119 ref
Graphics
Crawssembly includes a virtual graphical display implemented inside the terminal.
The programmer selects an X coordinate, Y coordinate and colour, modifies pixels in an internal framebuffer, and then explicitly presents the completed frame.
For example:
sav 5 r01 sav 255 r02 io screen x r01 io screen y r01 io screen red r02 io screen green r02 io screen blue r02 io screen pixel rff io screen present rff
draws a white pixel at (5, 5).
Screen operations include:
- setting X and Y coordinates;
- setting red, green and blue components;
- drawing a pixel;
- erasing a pixel;
- clearing the framebuffer;
- presenting the framebuffer;
- dumping a simplified representation of the screen.
Higher-level drawing operations such as lines, rectangles and circles are not CPU instructions. They are implemented in the standard library.
Keyboard and mouse
Keyboard input is obtained with:
io keyboard poll r02
Printable keys use character codes. Special keys are represented using additional values.
Keyboard modifier state is available as a bit field containing Shift, Control, Alt and Super.
Mouse input similarly provides X and Y coordinates and a bit field representing the mouse buttons.
These facilities allow interactive programs and games to be written without adding special language constructs for them.
Sound
Crawssembly provides eight virtual audio channels.
A program selects a channel and configures its frequency, volume and waveform before enabling it:
sav 0 r02 io speaker channel r02 sav 440 r02 io speaker freq r02 sav 50 r02 io speaker volume r02 io speaker on rff
Available waveforms include square, sine, triangle, sawtooth and noise.
Together with the time device, this is sufficient for programs to synthesise tones and simple music.
Memory
Registers provide only a small amount of directly addressable state, so Crawssembly also exposes random-access memory.
Memory uses an active address model. The program first selects an address:
sav 100 r02 io mem addr r02
and can then read or write the corresponding cell:
sav 42 r03 io mem write r03 io mem read r04
After these operations, r04 contains 42.
The documented address representation permits 32-bit addresses, although the reference virtual machine allocates a smaller finite amount of physical storage. Thus the architectural address space and the storage supplied by a particular implementation are distinct.
Persistent storage
The disk device follows the same active-address model as memory:
sav 100 r02 io disk addr r02 sav 42 r03 io disk write r03
Unlike ordinary memory, disk storage persists between executions.
The program can explicitly request that the backing storage be saved:
io disk save rff
This gives Crawssembly programs access to persistent mutable state without requiring a filesystem abstraction inside the virtual architecture.
File input and output
In addition to the virtual disk device, Crawssembly provides sequential file input and binary output through two dedicated registers.
Input stream
An input file can be supplied to the reference implementation using the --file argument:
craw program.craw --file input.txt
The contents of the file are exposed to the program as a sequence of bytes through register r00. The inp instruction advances the input stream to the next byte.
The following program reads and displays the first three bytes of the input file as characters:
sav r00 ref inp sav r00 ref inp sav r00 ref
This mechanism allows Crawssembly programs to process arbitrary binary files, including images, text documents and source code for other programming languages.
Output stream
Writing to register rff appends the least significant eight bits of the supplied value to an output buffer.
For example:
sav 72 rff sav 105 rff stp
produces a two-byte file containing the hexadecimal values 48 69, representing the ASCII string Hi.
By default, the output buffer is written to output.bin when execution terminates. Buffering avoids performing a host filesystem operation for every byte produced by the program. Abnormal termination may therefore result in incomplete or absent output files.
Unlike the disk device, this interface is sequential rather than randomly addressable.
Default binary files
| Filename | Purpose |
|---|---|
program.bin |
Compiled machine instructions |
output.bin |
Binary output generated through register rff
|
storage.bin |
Persistent storage associated with the disk device |
Machine code
Crawssembly source is compiled to a custom fixed-width 21-bit instruction format.
Most instructions have the form:
aa bbb cccccccc dddddddd
The fields are interpreted differently depending on the instruction class.
Broadly:
aaselects a core instruction group;bbbselects an operation or control mode;- the remaining two eight-bit fields contain registers, immediate values, device commands, or portions of a label identifier.
This gives exactly 2²¹ possible 21-bit instruction words.
Basic encodings
| Source | Encoding |
|---|---|
nop
|
00 000 00000000 00000000
|
sav rA rB
|
00 000 aaaaaaaa bbbbbbbb
|
sav imm rB
|
01 000 iiiiiiii bbbbbbbb
|
cal op rA rB
|
10 ooo aaaaaaaa bbbbbbbb
|
cal op imm rB
|
11 ooo iiiiiiii bbbbbbbb
|
run rA
|
01 010 00000000 aaaaaaaa
|
inp
|
01 100 00000000 00000000
|
stp
|
01 111 11111111 11111111
|
The arithmetic field ooo encodes the eight cal operations.
Control-flow instructions use a 16-bit field for their label identifier.
The io encoding divides one eight-bit field into a four-bit device identifier and four-bit command identifier:
01 110 dddd cccc rrrrrrrr
Thus the source syntax is closely related to the layout of the underlying virtual instruction word rather than being an unrelated textual notation.
Writing machine code directly
Crawssembly permits an encoded instruction to appear directly in source.
For example:
010000011010000000001 io text int r01
is equivalent to:
sav 100 r01 io text int r01
This makes the relationship between the assembly syntax and the fictional machine code directly observable to the programmer.
Dynamic instruction execution
One of Crawssembly's more unusual instructions is run.
run REGISTER
The low 21 bits of the register are interpreted as a Crawssembly machine instruction and immediately executed.
For example:
sav 0x82A03 r02 run r02
interprets 0x82A03 as:
sav 42 r03
and consequently stores 42 in r03.
This is not a separate interpreter invocation. The generated instruction executes in the current machine context and can alter registers, access devices, stop the program or modify control flow just as an instruction compiled normally would.
Code as data
Since machine instructions are ordinary 21-bit values, they can be stored and manipulated like other integers.
An instruction may therefore be:
- stored in a register;
- stored in memory;
- written to persistent storage;
- read from persistent storage;
- modified;
- generated algorithmically;
- executed using
run.
For example:
sav 0 r01 io disk addr r01 io disk read r02 run r02
reads an instruction from disk address zero and executes it.
This provides a basis for loaders, interpreters, dynamically generated code and self-modifying programs written entirely within Crawssembly.
Compilation and execution
The reference implementation conceptually consists of two stages: the compiler and the executioner.
The compiler converts textual Crawssembly instructions into 21-bit machine instructions. The resulting program is then executed by the virtual machine.
Execution follows a conventional fetch-decode-execute model:
┌──────── Virtual machine ────────┐
│ │
program.craw ──► compiler ──► machine code │
│ │ │
│ ▼ │
│ fetch │
│ │ │
│ ▼ │
│ decode │
│ │ │
│ ▼ │
│ execute ──────┐ │
│ ▲ │ │
│ └───────────┘ │
└─────────────────────────────────┘
The fictional CPU therefore has a machine-code representation independently of the source syntax.
Macros and source inclusion
Crawssembly has no primitive high-level function-call mechanism.
Instead, source can be included at compile time:
execute path/to/program.craw
The contents of the specified source file are inserted into the program during compilation.
Because this is source inclusion rather than a conventional function call, the included code shares the surrounding program's machine state.
Standard-library routines use:
executestd path/to/library.craw
This mechanism forms the basis of the Crawssembly Standard Library.
Crawssembly Standard Library
The Crawssembly Standard Library (CSL) implements facilities that would ordinarily be built into a larger instruction set or programming language.
Rather than hiding these facilities inside the VM, CSL implements them as Crawssembly programs.
Among its operations are:
- equality and comparison;
- multiplication;
- integer division;
- modulo;
- exponentiation;
- absolute value;
- negation;
- pseudorandom number generation;
- line drawing;
- rectangle drawing;
- circle drawing;
- stack operations;
- heap allocation.
Calling convention
Library routines conventionally receive arguments beginning at r02 and return results beginning at r02.
For example:
sav 12 r02 sav 5 r03 executestd math/multiply.craw io text int r02
outputs:
60
Each CSL routine documents its scope: the registers, labels and memory locations that it may alter.
This is important because library execution occurs inside the same virtual machine state as the calling program.
Implementing multiplication
Multiplication demonstrates the distinction between the Crawssembly CPU and software constructed on top of it.
There is no mul instruction. At the lowest level, multiplication must be reduced to operations such as addition, shifting and control flow.
A simple implementation could repeatedly add one operand:
; conceptual multiplication of r02 × r03 sav 0 r04 1 sav r04 r01 cal add r02 r04 sav r01 r04 cal add -1 r03 sav r01 r03 jmg 1
The standard library can provide a reusable and more complete implementation while the processor itself remains small.
This is a recurring design pattern in Crawssembly: capabilities are preferably constructed in Crawssembly when they do not need to exist as privileged machine operations.
Representation of data structures
Crawssembly does not provide native arrays, strings, structures or objects. Such data structures must be represented using registers, memory cells and conventions established by the programmer.
Arrays
An array can be represented by a contiguous sequence of memory cells. For example, the array [1, 2, 3] may be represented as follows:
| Address | Value |
|---|---|
0x00000000 |
1 |
0x00000001 |
2 |
0x00000002 |
3 |
The following program constructs this representation:
sav 0 r01 sav 1 r02 io mem addr r01 io mem write r02 sav 1 r01 sav 2 r02 io mem addr r01 io mem write r02 sav 2 r01 sav 3 r02 io mem addr r01 io mem write r02
An array index can be converted into a memory address by adding it to the base address of the array.
The virtual machine does not inherently distinguish between an array element, an instruction encoding, a character code or an ordinary integer. Their interpretation is determined entirely by the program.
The stack
Crawssembly does not have a hardware stack instruction.
CSL implements one using ordinary memory.
The stack is initialised using:
executestd stack/init.craw
and values can then be pushed and popped:
sav 42 r02 executestd stack/push.craw sav 17 r02 executestd stack/push.craw executestd stack/pop.craw io text int r02 executestd stack/pop.craw io text int r02
which retrieves 17 before 42.
The stack pointer is itself part of the program-visible state. Consequently, the stack is not a privileged structure supplied by the virtual processor: it is merely a convention implemented using memory and Crawssembly instructions.
The heap
Dynamic memory allocation is similarly implemented in CSL rather than by the virtual machine.
A program first initialises the allocator and can then request a block:
executestd heap/init.craw sav 100 r02 executestd heap/alloc.craw
The allocator searches its managed memory for a sufficiently large free block and returns an address.
The resulting address is an ordinary Crawssembly value and can be used with the memory device:
sav r02 r10 io mem addr r10 sav 42 r02 io mem write r02
Allocated memory can later be released:
sav r10 r02 executestd heap/free.craw
Allocation metadata is stored in the same memory available to ordinary programs.
Thus dynamic allocation, like the stack, is an emergent software convention rather than a special property of the VM.
Graphics library
The framebuffer exposes individual pixels, but higher-level geometry is provided by CSL.
Line drawing is implemented using a Bresenham-style integer algorithm. Rectangles and circles are similarly implemented in software.
This distinction allows the programmer to observe the complete chain from a high-level operation such as:
executestd graphics/line.craw
down to repeated manipulation of individual virtual pixels.
Register access and label lifetime
Register r00 is read-only, while rff is write-only. The rmv instruction removes a label binding, allowing its identifier to be reused later in the program. For example:
10 nop rmv 10 10 stp
Instruction encoding reference
The following tables specify the documented instruction encodings. In the patterns, l denotes a label identifier, r a register identifier, i an immediate value and o an arithmetic operation.
Arithmetic operation codes
| Operation | Mode | Meaning |
|---|---|---|
not |
000 |
Flip each bit |
and |
001 |
1 if both inputs are 1, else 0
|
or |
010 |
1 if any input is 1, else 0
|
xor |
011 |
1 if only 1 input is 1, else 0
|
shl |
100 |
Moves first value to the left |
shr |
101 |
Moves first value to the right |
sar |
110 |
Moves first value to the right, maintains sign |
add |
111 |
Adds two values together |
Control instruction patterns
| Instruction | Code | Pattern | Meaning |
|---|---|---|---|
jmz |
00 001 |
00 001 llllllll llllllll |
Jump to label if r01 = 0
|
jmg |
00 010 |
00 010 llllllll llllllll |
Jump to label if r01 > 0
|
ifl |
00 011 |
00 011 llllllll llllllll |
Continue if r01 < 0
|
jml |
00 100 |
00 100 llllllll llllllll |
Jump to label if r01 < 0
|
ifg |
00 101 |
00 101 llllllll llllllll |
Continue if r01 > 0
|
ifz |
00 110 |
00 110 llllllll llllllll |
Continue if r01 = 0
|
jmp |
00 111 |
00 111 llllllll llllllll |
Jump to label |
run |
01 010 |
01 010 00000000 rrrrrrrr |
Executes the 21-bit instruction stored in the register (more about this below) |
fgo |
01 011 |
01 011 llllllll llllllll |
Jump to label ID; 0 uses the ID in r01
|
rmv |
01 101 |
01 101 llllllll llllllll |
Removes/ends label scope |
io |
01 110 |
01 110 ddddcccc rrrrrrrr |
Accesses non-CPU devices |
| label definition | 01 111 |
01 111 llllllll llllllll |
Creates a label |
Device identifiers
| Instruction | Device | Usage |
|---|---|---|
io text |
0000 |
Accesses text character printing |
io time |
0001 |
Accesses time-based data |
io screen |
0010 |
Accesses screen graphics |
io keyboard |
0011 |
Accesses keyboard events |
io mouse |
0100 |
Accesses mouse events |
io speaker |
0101 |
Accesses speaker control |
io mem |
0110 |
Accesses volatile storage |
io disk |
0111 |
Accesses persistent storage |
Device command encodings
| Instruction | Device | Command | Binary | Meaning |
|---|---|---|---|---|
io text char |
0000 |
0000 |
01 110 0000 0000 rrrrrrrr |
Print inputted character code |
io text int |
0000 |
0001 |
01 110 0000 0001 rrrrrrrr |
Print input register's value |
io text newline |
0000 |
0010 |
01 110 0000 0010 rrrrrrrr |
Moves the text cursor to the next line |
io text hex |
0000 |
0011 |
01 110 0000 0011 rrrrrrrr |
Print input register's value in hexadecimal |
io text error |
0000 |
0100 |
01 110 0000 0100 rrrrrrrr |
Shows error text based on ree value
|
io text clear |
0000 |
0101 |
01 110 0000 0101 rrrrrrrr |
Clears the terminal, can be slow |
io text iso |
0000 |
0110 |
01 110 0000 0110 rrrrrrrr |
Prints the timestamp ISO |
io text space |
0000 |
0111 |
01 110 0000 0111 rrrrrrrr |
Prints a space |
io text r |
0000 |
1000 |
01 110 0000 1000 rrrrrrrr |
Sets the text red value |
io text g |
0000 |
1001 |
01 110 0000 1001 rrrrrrrr |
Sets the text green value |
io text b |
0000 |
1010 |
01 110 0000 1010 rrrrrrrr |
Sets the text blue value |
io text br |
0000 |
1011 |
01 110 0000 1011 rrrrrrrr |
Sets the background red value |
io text bg |
0000 |
1100 |
01 110 0000 1100 rrrrrrrr |
Sets the background green value |
io text bb |
0000 |
1101 |
01 110 0000 1101 rrrrrrrr |
Sets the background blue value |
io time unix |
0001 |
0000 |
01 110 0001 0000 rrrrrrrr |
Stores current UNIX timestamp in input register |
io time low |
0001 |
0001 |
01 110 0001 0001 rrrrrrrr |
Stores magnitude of the UNIX timestamp in input register |
io time sleepms |
0001 |
0010 |
01 110 0001 0010 rrrrrrrr |
Pauses execution for inputted number of milliseconds |
io time milli |
0001 |
0011 |
01 110 0001 0011 rrrrrrrr |
Stores the low time in milliseconds
|
io time sleepus |
0001 |
0100 |
01 110 0001 0100 rrrrrrrr |
Pauses execution for inputted number of microseconds |
io screen x |
0010 |
0000 |
01 110 0010 0000 rrrrrrrr |
Sets active x coordinate in the graphics buffer |
io screen y |
0010 |
0001 |
01 110 0010 0001 rrrrrrrr |
Sets active Y coordinate in the graphics buffer |
io screen pixel |
0010 |
0010 |
01 110 0010 0010 rrrrrrrr |
Updates pixel in the graphics buffer at active coordinates |
io screen clear |
0010 |
0011 |
01 110 0010 0011 rrrrrrrr |
Clears the graphics buffer |
io screen dump |
0010 |
0100 |
01 110 0010 0100 rrrrrrrr |
Shows a basic readout of the current screen |
io screen present |
0010 |
0101 |
01 110 0010 0101 rrrrrrrr |
Sends the graphics buffer to the screen |
io screen red |
0010 |
0110 |
01 110 0010 0110 rrrrrrrr |
Sets the red colour value of the active coordinates of the graphics buffer |
io screen green |
0010 |
0111 |
01 110 0010 0111 rrrrrrrr |
Sets the green colour value of the active coordinates of the graphics buffer |
io screen blue |
0010 |
1000 |
01 110 0010 1000 rrrrrrrr |
Sets the blue colour value of the active coordinates of the graphics buffer |
io screen erase |
0010 |
1001 |
01 110 0010 1001 rrrrrrrr |
Clears the pixel in the graphics buffer at the active coordinates |
io screen erasecell |
0010 |
1010 |
01 110 0010 1010 rrrrrrrr |
Clears the entire terminal cell of the active coordinates in the graphics buffer |
io keyboard poll |
0011 |
0000 |
01 110 0011 0000 rrrrrrrr |
Extracts the last key code pressed into input register |
io mouse x |
0100 |
0000 |
01 110 0100 0000 rrrrrrrr |
Extracts current mouse X coordinate into input register |
io mouse y |
0100 |
0001 |
01 110 0100 0001 rrrrrrrr |
Extracts current mouse Y coordinate into input register |
io mouse btn |
0100 |
0010 |
01 110 0100 0010 rrrrrrrr |
Extracts button bit field into input register (Middle, Right, Left) |
io speaker channel |
0101 |
0000 |
01 110 0101 0000 rrrrrrrr |
Sets the active speaker channel to the value in input register |
io speaker freq |
0101 |
0001 |
01 110 0101 0001 rrrrrrrr |
Sets active speaker frequency to value in input register |
io speaker volume |
0101 |
0010 |
01 110 0101 0010 rrrrrrrr |
Sets volume (0-100) of active speaker to value in input register |
io speaker wave |
0101 |
0011 |
01 110 0101 0011 rrrrrrrr |
Sets the active speaker's wave type to value in input register |
io speaker on |
0101 |
0100 |
01 110 0101 0100 rrrrrrrr |
Turns on the active speaker |
io speaker off |
0101 |
0101 |
01 110 0101 0101 rrrrrrrr |
Turns off the active speaker |
io speaker toggle |
0101 |
0110 |
01 110 0101 0110 rrrrrrrr |
Toggles the active speaker on/off |
io mem addr |
0110 |
0000 |
01 110 0110 0000 rrrrrrrr |
Sets the active memory address to the value in input register |
io mem read |
0110 |
0001 |
01 110 0110 0001 rrrrrrrr |
Extracts the value of the active memory address into input register |
io mem write |
0110 |
0010 |
01 110 0110 0010 rrrrrrrr |
Sets the active memory address's value to the value in the input register |
io disk addr |
0111 |
0000 |
01 110 0111 0000 rrrrrrrr |
Sets the active disk address to value in input register |
io disk read |
0111 |
0001 |
01 110 0111 0001 rrrrrrrr |
Extracts the active disk address's value into input register |
io disk write |
0111 |
0010 |
01 110 0111 0010 rrrrrrrr |
Sets the active disk address's value to value in input register |
io disk save |
0111 |
0011 |
01 110 0111 0011 rrrrrrrr |
Forces the disk file to reload and update |
Worked instruction decoding example
Consider the instruction:
sav 10 r01
Its machine-code representation is:
01 000 00001010 00000001
| Field | Binary value | Interpretation |
|---|---|---|
| Instruction group | 01 |
Immediate operand or control instruction |
| Operation | 000 |
Register assignment |
| First operand | 00001010 |
Signed immediate value 10 |
| Second operand | 00000001 |
Register identifier 1 |
During the fetch stage, the executioner retrieves the encoded instruction from the program.
During the decode stage, the instruction is separated into its constituent fields. These fields identify the operation, its operand type, the immediate value and the destination register.
During the execute stage, the value 10 is written to register r01.
The same instruction format is used for machine instructions executed dynamically through run.
Device error codes
Device operations report their status in ree.
| Code | Name | Description |
|---|---|---|
| 0 | IO_OK | Operation completed successfully |
| 1 | IO_INVALID_COMMAND | Invalid device command |
| 2 | IO_BAD_VALUE | Value outside valid range |
| 3 | IO_UNAVAILABLE | Device unavailable |
Additional device conventions
Keyboard and mouse bit fields
The io keyboard mod command returns the state of the modifier keys as a bit field.
| Bit | Mask | Modifier |
|---|---|---|
| 0 | 1 | Shift |
| 1 | 2 | Control |
| 2 | 4 | Alt |
| 3 | 8 | Super |
The io mouse btn command similarly encodes the left, right and middle mouse buttons in bits 0, 1 and 2 respectively. Mouse events require the terminal interface mode (--tui) in the documented implementation.
Framebuffer representation
Colour components range from −128 to 127, corresponding to unsigned RGB components from 0 to 255. This allows every colour component to be represented by an immediate operand. The terminal renderer uses coloured Unicode half-block characters, allowing two vertical pixels per terminal character cell. The erasecell command clears both halves of the selected terminal cell.
Audio waveforms
The speaker device supports eight channels, with frequency specified in hertz and volume on a scale from 0 to 100. The waveform is selected using io speaker wave.
| Identifier | Waveform |
|---|---|
| 0 | Square |
| 1 | Sine |
| 2 | Triangle |
| 3 | Sawtooth |
| 4 | Noise |
Audio output depends on the host system. All channels stop when execution terminates.
Time
| Command | Behaviour |
|---|---|
io time unix |
Reads the Unix timestamp in seconds. |
io time low |
Reads the low 31 bits of the Unix timestamp. |
io time milli |
Reads the documented millisecond time value. |
io time sleepms |
Suspends execution for a specified number of milliseconds. |
io time sleepus |
Suspends execution for a specified number of microseconds. |
The low-bit timestamp is non-negative but wraps periodically; it does not eliminate the year 2038 problem for absolute timestamps. Delay accuracy depends on host scheduling.
Standard library routine reference
The following table lists the routines documented in the README. Scope identifies registers and numeric labels that may be modified by a routine. Module and routine names correspond to paths used with executestd.
| Module | Function | Inputs | Outputs | Scope | Description |
|---|---|---|---|---|---|
| - | reset_regs |
r02 |
- | Variable, 60000 |
Resets registers from r01 up to the register specified in r02.
|
| compare | equal |
r02-r03 |
r02 |
r01-r02, 60000 |
Outputs 1 if r02 == r03, otherwise 0.
|
| compare | greater |
r02-r03 |
r02 |
r01-r02, 60000 |
Outputs 1 if r02 > r03, otherwise 0.
|
| compare | greater_equal |
r02-r03 |
r02 |
r01-r02, 60000 |
Outputs 1 if r02 >= r03, otherwise 0.
|
| compare | less |
r02-r03 |
r02 |
r01-r02, 60000 |
Outputs 1 if r02 < r03, otherwise 0.
|
| compare | less_equal |
r02-r03 |
r02 |
r01-r02, 60000 |
Outputs 1 if r02 <= r03, otherwise 0.
|
| compare | not_equal |
r02-r03 |
r02 |
r01-r02, 60000 |
Outputs 1 if r02 != r03, otherwise 0.
|
| math | abs |
r02 |
r02 |
r01-r02, 60000 |
Returns the absolute value of r02.
|
| math | divide |
r02-r03 |
r02-r03 |
r01-r04, 60000 |
Quotient in r02, remainder in r03.
|
| math | modulo |
r02-r03 |
r02 |
r01-r03, 60000 |
Returns only the remainder. |
| math | multiply |
r02-r03 |
r02 |
r01-r04, 60000-60003 |
Multiplies r02 by r03.
|
| math | negate |
r02 |
r02 |
r01-r02, 60000 |
Negates r02.
|
| math | power |
r02-r03 |
r02 |
r01-r05, 60000-60001 |
Raises r02 to the power of r03.
|
| math | random |
- | r02 |
r01-r03, 60000 |
Generates a pseudorandom integer using the current millisecond timestamp. |
| math | sign |
r02 |
r02 |
r01-r02, 60000 |
Returns -1, 0, or 1 depending on the sign of r02.
|
| screen | circle |
r02-r04 |
- | r01-r08, 60000-60001 |
Draws a circle at (r02, r03) with radius r04.
|
| screen | line |
r02-r05 |
- | r01-r0c, 60000-60002 |
Draws a line from (r02, r03) to (r04, r05).
|
| screen | rectangle |
r02-r05 |
- | r01-r10, 60000-60002 |
Draws a rectangle with corners (r02, r03) & (r04, r05).
|
| screen | rectangle_fill |
r02-r05 |
- | r01-r11, 60000-60003 |
Draws a filled-in rectangle with corners (r02, r03) & (r04, r05)
|
| stack | init |
- | red |
r01-r02, red |
Creates the stack pointer, used for the stack in RAM |
| stack | pop |
- | r02 |
r01-r02, red |
Removes the last entry on the stack, and stores it in r02 |
| stack | push |
r02 |
- | r01-r02, red |
Adds a new entry, with value of r02, to the top of the stack
|
| heap | init |
- | rec |
r01-r02 rec |
Creates the heap pointer, which tracks heap blocks in RAM |
| heap | alloc |
r02 |
rec ree |
r01-r07 rec-red, 60000-60002 |
Makes a new heap block in memory |
| heap | free |
r02 |
ree |
r01-r03, 60000-60003 |
Frees the current heap block in memory |
Stack and heap layout
The stack grows downwards from the upper end of memory and uses red as its stack pointer. The heap begins at address 0x10000 and uses rec for its pointer. Allocation headers record block size and state. Both structures must be initialised before using either, according to the README, so that collision checks can account for the other structure.
executestd stack/init.craw executestd heap/init.craw
See also Crawssembly/Heap Allocator.
Package management reference
CPM packages are compressed archives containing source files and metadata. Each published package has a name, version, author, description, download location and SHA-256 checksum. A package project contains a package.toml manifest.
my_package/ package.toml main.craw
Publishing requires authentication with the registry. The documented publishing workflow creates an archive, creates a GitHub release, uploads the archive and registers the package.
| Command | Description |
|---|---|
craw pkg login |
Log into the CPM registry |
craw pkg whoami |
Show the current account |
craw pkg pack |
Create a package archive locally |
craw pkg publish |
Publish the current package |
craw pkg install |
Install a package |
craw pkg update |
Update installed packages |
craw pkg remove |
Remove an installed package |
craw pkg logout ends the authenticated session. Installed packages can be included using executestd, like standard library routines.
Embedding the virtual machine
The reference implementation is available as a Rust crate through Cargo. The README provides the following example of executing a compiled program and inspecting a register:
use crawssembly::{RunOptions, Vm, VmConfig};
fn main() -> Result<(), String> {
let mut vm = Vm::without_audio(VmConfig::default());
vm.run_file("program.bin", RunOptions {
plain: true,
show_stats: false,
..RunOptions::default()
})?;
println!("rFF = {}", vm.registers()[0xFF]);
Ok(())
}
Implementation
The primary implementation is written in Rust and is available for Linux, Windows and macOS.
The command-line program craw compiles and executes Crawssembly source.
A minimal invocation is:
craw program.craw
The implementation also exposes options controlling facilities such as the virtual display, benchmarking and input files, described by invoking
craw --help
Output:
craw Usage: craw <file.craw> Assemble and run a file craw check <file.craw> Check that a file assembles craw compile <file.craw> Assemble to program.bin only craw crush <file.craw> Reduce a .craw file size craw debug <file.craw> Run with VM stats shown craw init <name> Creates a package structure craw install-nano Install nano syntax highlighting craw install-std Update the CSL to your machine craw pkg <command> Access the CPM (Crawssembly Package Manager) craw run <file.craw> Assemble and run a file Options: --audio Enable speaker/speech audio output --decode Open the instruction decoder --disk <file> Sets disk device to that file --dump Show assembled instructions --dump-decoded Show decoded instruction fields with --dump --file <file> Send file contents to r00 during execution --force Bypass any disk checks --help Show this help message --loop Loop the file input contents --o, --output <file> Set output filename --raw-disk <file> Set the raw bytes disk to file --readonly Deny all disk write calls --screen <widthxheight> Set virtual screen size, e.g. 128x128 --stats Show VM speed/tick statistics after running --tui Use alternate-screen terminal mode Examples: craw pkg login craw hello.craw craw debug hello.craw craw pkg install graphics craw compile hello.craw --dump craw imageviewer.craw --file image.bmp craw graphics.craw --screen 128x128 --tui
The virtual machine is also available as an embeddable Rust component, allowing other programs to execute Crawssembly code and inspect the resulting machine state.
Crawssembly Package Manager
The Crawssembly Package Manager (CPM) provides a registry for reusable Crawssembly software.
Packages can be installed using:
craw pkg install PACKAGE
and installed libraries can subsequently be incorporated into programs through executestd.
CPM supports operations for packaging, publishing, installing, listing, updating and removing packages. Published package metadata includes information such as package name, version, author, description and integrity information.
The existence of a package manager is somewhat unusual for a small experimental assembly language, but follows from Crawssembly's development beyond individual demonstration programs into a reusable programming environment.
Example programs and software
Programs written for Crawssembly include or have included examples demonstrating:
- bitmap loading;
- keyboard input;
- graphical drawing;
- memory inspection;
- register inspection;
- timers;
- arithmetic routines;
- a command shell;
- text editing;
- persistent storage;
- networking;
- dynamically executed code.
| Program | Function | Source Code Page |
|---|---|---|
| Befunge Executor | Executes Befunge-93 Code | Crawssembly/Befunge Interpreter |
| Mandelbrot Renderer | Renders the Mandelbrot Fractal | Crawssembly/Mandelbrot |
| Arcade Pong | Runs a basic Pong clone | Crawssembly/Pong |
| Library | Function | Source Code Page |
|---|---|---|
| Heap Allocator | Allocates a block of memory on the heap | Crawssembly/Heap Allocator |
Why 21 bits?
Crawssembly's machine instructions are neither byte-aligned nor powers of two in width.
The instruction format is instead sized around the information needed by the architecture:
2 bits core group 3 bits operation/mode 8 bits operand 8 bits operand ---------------------- 21 bits total
This allows two full register identifiers or immediate operands to coexist with an instruction class and operation identifier without expanding the conceptual instruction format merely to obtain a conventional byte-aligned size.
As a consequence, Crawssembly binaries have an unusual relationship with ordinary host-machine storage: the virtual instruction word is 21 bits even though the implementation necessarily stores or packs it using conventional host data structures.
Esoteric properties
Crawssembly was not intentionally designed as an esoteric programming language.
Its original purpose is educational, and many of its choices are intended to make assembly programming less intimidating. Nevertheless, it exhibits several properties unusual enough to place it naturally alongside experimental and esoteric languages:
- the language targets an entirely fictional CPU;
- instructions are 21 bits wide;
- the processor exposes 256 registers;
- several mathematical constants occupy predefined registers;
- immediate values are only eight bits despite registers holding 32-bit values;
- arithmetic operations share a single
calinstruction; - multiplication and division are library routines rather than processor instructions;
- conditional regions are associated with numbered labels and terminated using
rmv; fgo 0performs a computed jump usingr01;- peripherals are accessed through a unified
ioinstruction; - instructions can be represented as integer data and executed dynamically;
- a stack and heap are implemented in the language itself;
- the same system encompasses assembly syntax, machine-code encoding and the virtual architecture that executes it.
The result is closer to an imaginary computer architecture than to an intentionally difficult notation.
Relationship between casm and Crawssembly
The terms casm and Crawssembly are frequently used interchangeably.
More precisely, casm can refer to the assembly language and instruction syntax, while Crawssembly can refer to the larger system consisting of the language, virtual architecture, implementation, standard library and related tooling.
In ordinary usage this distinction is not generally important.
Computational class
Crawssembly is Turing-complete, as it is capable of implementing an interpreter for Brainfuck, which is itself Turing-complete.
The following implementation stores the Brainfuck source program in memory addresses 0x0000–0x0fff and uses 0x1000–0x1fff as the Brainfuck tape. It supports all eight Brainfuck instructions, including nested loops. Running this program using craw brainfuck.craw --file program.bf will execute the brainfuck program proper.
This a simple, unoptimised Brainfuck interpreter written in Crawssembly. Brainfuck source code is supplied to the interpreter using the Crawssembly input file.
sav 0 r01 ; init scratch register
sav 0 r02 ; init memory address
1 ; loader loop
sav r00 r01 ; ready input value
ifg 2 ; input > 0
io mem addr r02 ; access memory address
io mem write r00 ; write input
cal add 1 r02 ; increment address
sav r01 r02 ; update address
inp ; get next input value
jmp 1 ; continue loader loop
rmv 2 ; end input check
sav 0 r10 ; init bf pc (brainfuck program counter)
sav 0 r12 ; init tpv (tape pointer value)
sav 32 r01 ; 0b0..11111
sav 7 r02 ; shift amount
cal shl r01 r02 ; 0b0..111110000000 (0x01000)
sav r01 r11 ; init tp (tape pointer)
sav 0 r01 ; reset scratch register
1 ; main loop
io mem addr r10 ; access bf symbol
io mem read r04 ; get symbol into r04
io mem addr r11 ; access tp value
io mem read r12 ; get tpv
sav r04 r01 ; ready symbol code
cal add -62 r01 ; > symbol found
ifz 2 ; > branch
cal add 1 r11 ; increment tp
sav r01 r11 ; update tp
cal add 1 r10 ; next bfpc
sav r01 r10 ; update bfpc
jmp 1 ; continue loop
rmv 2 ; end > branch
sav r04 r01 ; ready symbol code
cal add -60 r01 ; < symbol found
ifz 2 ; < branch
cal add -1 r11 ; decrement tp
sav r01 r11 ; update tp
cal add 1 r10 ; next bfpc
sav r01 r10 ; update bfpc
jmp 1 ; continue loop
rmv 2 ; end < branch
sav r04 r01 ; ready symbol code
cal add -43 r01 ; + symbol found
ifz 2 ; + branch
cal add 1 r12 ; increment tpv
io mem addr r11 ; access tpv
io mem write r01 ; update tpv
cal add 1 r10 ; next bfpc
sav r01 r10 ; update bfpc
jmp 1 ; continue loop
rmv 2 ; end + branch
sav r04 r01 ; ready symbol code
cal add -45 r01 ; - symbol found
ifz 2 ; - branch
cal add -1 r12 ; decrement tpv
io mem addr r11 ; access tpv
io mem write r01 ; update tpv
cal add 1 r10 ; next bfpc
sav r01 r10 ; update bfpc
jmp 1 ; continue loop
rmv 2 ; end - branch
sav r04 r01 ; ready symbol code
cal add -46 r01 ; . symbol found
ifz 2 ; . branch
io text char r12 ; output tape char
cal add 1 r10 ; next bfpc
sav r01 r10 ; update bfpc
jmp 1 ; continue loop
rmv 2 ; end . branch
sav r04 r01 ; ready symbol code
cal add -44 r01 ; , symbol found
ifz 2 ; , branch
3 ; get key loop
io keyboard poll r01 ; get key press
ifz 4 ; no key
jmp 3 ; continue loop
rmv 4 ; end no key check
io mem addr r11 ; access tpv
io mem write r01 ; tpv = key
rmv 3 ; free label
cal add 1 r10 ; next bfpc
sav r01 r10 ; update bfpc
jmp 1 ; continue loop
rmv 2 ; end , branch
sav r04 r01 ; ready symbol code
cal add -91 r01 ; [ symbol found
ifz 2 ; [ branch
sav r12 r01 ; ready tpv
ifz 3 ; tpv = 0, start depth walk to find ]
sav 0 r05 ; init symbol offset value
sav 0 r06 ; init offsetted symbol
sav 0 r07 ; init depth value (+1 for [, -1 for ])
4 ; walk loop
cal add 1 r05 ; increment symbol offset value
sav r01 r05 ; update symbol offset value
cal add r01 r10 ; bfpc + offset
io mem addr r01 ; get offsetted bfpc
io mem read r06 ; read walked symbol
cal add -93 r06 ; test for ]
ifz 5 ; ] found
cal add -1 r07 ; decrease depth
sav r01 r07 ; update depth
ifl 6 ; depth < 0 (match found)
cal add r05 r10 ; get symbol address
cal add 1 r01 ; first symbol after matching ]
sav r01 r10 ; update bfpc
jmp 1 ; continue main loop
rmv 6 ; end match check
jmp 4 ; no match, continue walk
rmv 5 ; end ] check
cal add -91 r06 ; test for [
ifz 5 ; [ found
cal add 1 r07 ; increase depth
sav r01 r07 ; update depth
jmp 4 ; continue walk
rmv 5 ; end [ check
jmp 4 ; different symbol, continue walk
rmv 4 ; free label
rmv 3 ; end depth walk
cal add 1 r10 ; tpv != 0, continue
sav r01 r10 ; update bfpc
jmp 1 ; continue loop
rmv 2 ; end [ branch
sav r04 r01 ; ready symbol code
cal add -93 r01 ; ] symbol found
ifz 2 ; ] branch
sav r12 r01 ; ready tpv
ifg 3 ; tpv > 0, start depth walk to find [
sav 0 r05 ; init symbol offset value
sav 0 r06 ; init offsetted symbol
sav 0 r07 ; init depth value (+1 for ], -1 for [)
4 ; walk loop
cal add -1 r05 ; decrement symbol offset value
sav r01 r05 ; update symbol offset value
cal add r01 r10 ; bfpc + offset
io mem addr r01 ; get offsetted bfpc
io mem read r06 ; read walked symbol
cal add -91 r06 ; test for [
ifz 5 ; [ found
cal add -1 r07 ; decrease depth
sav r01 r07 ; update depth
ifl 6 ; depth < 0 (match found)
cal add r05 r10 ; get symbol address
cal add 1 r01 ; first symbol after matching [
sav r01 r10 ; update bfpc
jmp 1 ; continue main loop
rmv 6 ; end match check
jmp 4 ; no match, continue walk
rmv 5 ; end [ check
cal add -93 r06 ; test for ]
ifz 5 ; ] found
cal add 1 r07 ; increase depth
sav r01 r07 ; update depth
jmp 4 ; continue walk
rmv 5 ; end ] check
jmp 4 ; different symbol, continue walk
rmv 4 ; free label
rmv 3 ; end tpv > 0 check
sav r12 r01 ; ready tpv
ifl 3 ; tpv < 0, start depth walk to find [
sav 0 r05 ; init symbol offset value
sav 0 r06 ; init offsetted symbol
sav 0 r07 ; init depth value (+1 for ], -1 for [)
4 ; walk loop
cal add -1 r05 ; decrement symbol offset value
sav r01 r05 ; update symbol offset value
cal add r01 r10 ; bfpc + offset
io mem addr r01 ; get offsetted bfpc
io mem read r06 ; read walked symbol
cal add -91 r06 ; test for [
ifz 5 ; [ found
cal add -1 r07 ; decrease depth
sav r01 r07 ; update depth
ifl 6 ; depth < 0 (match found)
cal add r05 r10 ; get symbol address
cal add 1 r01 ; first symbol after matching [
sav r01 r10 ; update bfpc
jmp 1 ; continue main loop
rmv 6 ; end match check
jmp 4 ; no match, continue walk
rmv 5 ; end [ check
cal add -93 r06 ; test for ]
ifz 5 ; ] found
cal add 1 r07 ; increase depth
sav r01 r07 ; update depth
jmp 4 ; continue walk
rmv 5 ; end ] check
jmp 4 ; different symbol, continue walk
rmv 4 ; free label
rmv 3 ; end tpv < 0 check
cal add 1 r10 ; tpv = 0, continue
sav r01 r10 ; update bfpc
jmp 1 ; continue loop
rmv 2 ; end [ branch
sav r04 r01 ; EOF character ready
ifz 2 ; code = 0 => EOF
stp ; end program
rmv 2 ; end EOF check
cal add 1 r10 ; next bfpc
sav r01 r10 ; update bfpc
jmp 1 ; continue main loop
Example
Given the Brainfuck program:
++++++++++[>+++++++>++++++++++>+++>+<<<<-]>++.>+.+++++++..+++.>++.<<+++++++++++++++.>.+++.------.--------.>+.>.
the interpreter produces:
Hello World!
As with any implementation running on a physical computer, the reference Crawssembly implementation has finite memory; Turing-completeness refers to the language's computational model under the usual assumption of unbounded available memory.
It should be noticed that the interpreter's cells are Crawssembly integer cells, being 32-bit width, rather than the common 8-bit wrapping Brainfuck implementation. This doesn't affect Crawssembly's computational class in any way, but for brainfuck programs that utilise this feature, not all programs will function as expected.
Development
Crawssembly remains under development.
Its scope has expanded considerably from its original role as a small educational assembly environment. Later additions have included a standard library, graphical and audio devices, persistent storage, dynamic instruction execution, reusable packages and increasingly complex software written for the architecture.
Despite this expansion, the core design principle remains that functionality should be implemented on the fictional machine where practical rather than continually enlarging the CPU instruction set.
Versions
As of November 2026 there are 5 released versions, 3 of which are official releases.
| Version Number | Date Released | Core Changes | Reference |
|---|---|---|---|
| v1.0.0 | 2026-06-26 | Initial Release | [2] |
| v1.1.0 | 2026-07-02 | Added CSL, execute and executestd |
[3] |
| v1.2.0 | 2026-07-03 | Rust Cargo Crate | [4] |
| v1.3.0 | In Development | Basic Networking & Speech | N/A |
Crawssembly Quine
The following is a quine written in Crawssembly by User:Craw, created on 25 November 2026. The program was generated using Python and consists of 18,634 lines of Crawssembly code, totalling 262,389 bytes.
The program does not require any external libraries, user input or access to its own source file.
Implementation
The quine is divided into two main sections:
- A data section, which initialises memory with the ASCII representation of the executable section.
- An executable section, which reconstructs the instructions used to initialise memory before outputting its own instructions.
The executable section iterates over the stored characters, generating the corresponding memory initialisation instructions for each character. Once the null terminator is reached, the program returns to the beginning of memory and outputs the stored characters directly.
The program uses only four of Crawssembly's 256 registers. Register r01 acts as the arithmetic result and conditional jump register, r02 stores immediate character values, r03 acts as a memory address counter, and r04 holds characters retrieved from memory. The executable section is stored as a null-terminated sequence of ASCII values beginning at memory address 0. Each character occupies an individual 32-bit memory location, accessed using the io mem addr, io mem read and io mem write instructions.
The program uses two loops, controlled by numeric labels and conditional jumps. The first reconstructs the memory initialisation instructions by combining literal text, output using io text char, with the decimal representation of each stored character, output using io text int. The second resets the address counter and outputs the stored executable section character by character. This technique avoids the need for string manipulation, external libraries, dynamic code execution or access to the original source file. Although inefficient in terms of source size, the implementation requires only a small subset of Crawssembly's instruction set.
Verification
The output was verified against the original source file using a byte-for-byte comparison and SHA-256 hashes.
The Crawssembly executor appends ANSI terminal control sequences and a newline upon termination. After removing these control sequences, the output is identical to the original source file. The current implementation relies on the executor to supply the final newline.
Both the source and the processed output produced the following SHA-256 hash:
139e265cbeacf8018bf946e8f5a4182ab46ad1e8bc9f924c9bf1e73838a2ee02
Python Generator
from pathlib import Path
def print_string(text):
code = []
for char in text:
code.append(f"sav {ord(char)} r02")
code.append("io text char r02")
return code
body = [
"sav 0 r03",
"1",
"io mem addr r03",
"io mem read r04",
"sav r04 r01",
"jmz 2",
*print_string("sav "),
"io text int r04",
*print_string(" r02\n"),
*print_string("io mem write r02\n"),
*print_string("cal add 1 r03\n"),
*print_string("sav r01 r03\n"),
*print_string("io mem addr r03\n"),
"cal add 1 r03",
"sav r01 r03",
"jmp 1",
"2",
*print_string("sav 0 r02\n"),
*print_string("io mem write r02\n"),
"sav 0 r03",
"3",
"io mem addr r03",
"io mem read r04",
"sav r04 r01",
"jmz 4",
"io text char r04",
"cal add 1 r03",
"sav r01 r03",
"jmp 3",
"4",
"stp"
]
body = "\n".join(body)
header = [
"sav 0 r03",
"io mem addr r03"
]
body = "\n".join(
print_string("\n".join(header) + "\n")
) + "\n" + body
data = []
for char in body:
data.extend([
f"sav {ord(char)} r02",
"io mem write r02",
"cal add 1 r03",
"sav r01 r03",
"io mem addr r03"
])
data.extend([
"sav 0 r02",
"io mem write r02"
])
source = "\n".join(header + data) + "\n" + body
Path("quine.craw").write_bytes((source + "\n").encode("ascii"))
Source Code
The full source code is too large to fit on this page at the moment, you can find it here.
Crushed Image
The following is the binary bitmap image of the compiled Crawssembly Quine program, due to the program's large size this version is generally more suited to understanding the general format of the quine.

The actual image shown is a bmp file converted to a png file so that the image can be properly rendered.
Examples
The following are a group of code examples in Crawssembly, in no particular order.
Hello World
Standard Form
sav 72 r01 io text char r01 sav 101 r01 io text char r01 sav 108 r01 io text char r01 io text char r01 sav 111 r01 io text char r01 sav 32 r01 io text char r01 sav 87 r01 io text char r01 sav 111 r01 io text char r01 sav 114 r01 io text char r01 sav 108 r01 io text char r01 sav 100 r01 io text char r01 sav 33 r01 io text char r0
Short Form
sav 72 ref sav 101 ref sav 108 ref sav 108 ref sav 111 ref sav 32 ref sav 87 ref sav 111 ref sav 114 ref sav 108 ref sav 100 ref sav 33 ref
Cat Program
1
sav 0 r01
io keyboard poll r01
ifz 2
jmp 1
rmv 2
cal add 5 r01
ifz 2
stp
rmv 2
io text char r01
Truth-machine
Taken from Truth-machine#Crawssembly
1
sav 0 r02
io keyboard poll r02
sav r01 r02
ifz 2
jmp 1
rmv 2
cal add -49 r02
ifz 2
sav 1 r01
3
io text int r01
jmp 3
rmv 3
rmv 2
rmv 1
sav 0 r01
io text int r01
stp
Addition Calculator
1
sav 0 r02
io keyboard poll r02
sav r02 r01
ifz 2
jmp 1
rmv 2
cal add 5 r02
ifz 2
jmp 4
rmv 2
sav r03 r01
ifz 2
cal add -45 r02
ifz 3
sav 1 r05
rmv 3
cal add 1 r03
sav r01 r03
jmp 1
rmv 2
cal add -48 r02
ifl 2
jmp 1
rmv 2
cal add -57 r02
ifg 2
jmp 1
rmv 2
cal add 1 r03
sav r01 r03
sav 3 r01
cal shl r04 r01
cal add r04 r01
cal add r04 r01
sav r01 r04
cal add -48 r02
cal add r04 r01
jmp 1
4
rmv 1
rmv 2
rmv 3
rmv 4
5
sav 0 r02
io keyboard poll r02
sav r02 r01
ifz 2
jmp 5
rmv 2
cal add 5 r02
ifz 2
jmp 6
rmv 2
sav r03 r01
ifz 2
cal add -45 r02
ifz 3
sav 1 r07
rmv 3
cal add 1 r03
sav r01 r03
jmp 5
rmv 2
cal add -48 r02
ifl 2
jmp 5
rmv 2
cal add -57 r02
ifg 2
jmp 5
rmv 2
cal add 1 r03
sav r01 r03
sav 3 r01
cal shl r06 r01
cal add r06 r01
cal add r06 r01
sav r01 r06
cal add -48 r02
cal add r06 r01
jmp 5
6
rmv 2
rmv 3
rmv 4
rmv 5
rmv 6
sav r05 r01
ifg 2
cal not r04 rff
cal add 1 r01
sav r01 r04
rmv 2
sav r07 r01
ifg 2
cal not r06 rff
cal add 1 r01
sav r01 r06
rmv 2
cal add r04 r06
io text int r01
99 bottles of beer
Taken from 99_bottles_of_beer/Implementations#Crawssembly
sav 99 r02
1
io text int r02
io text space rff
sav 98 r01
io text char r01
sav 111 r01
io text char r01
sav 116 r01
io text char r01
io text char r01
sav 108 r01
io text char r01
sav 101 r01
io text char r01
sav 115 r01
io text char r01
io text space rff
sav 111 r01
io text char r01
sav 102 r01
io text char r01
io text space rff
sav 98 r01
io text char r01
sav 101 r01
io text char r01
io text char r01
sav 114 r01
io text char r01
io text space rff
sav 111 r01
io text char r01
sav 110 r01
io text char r01
io text space rff
sav 116 r01
io text char r01
sav 104 r01
io text char r01
sav 101 r01
io text char r01
io text space rff
sav 119 r01
io text char r01
sav 97 r01
io text char r01
sav 108 r01
io text char r01
io text char r01
sav 44 r01
io text char r01
io text newline rff
io text int r02
io text space rff
sav 98 r01
io text char r01
sav 111 r01
io text char r01
sav 116 r01
io text char r01
io text char r01
sav 108 r01
io text char r01
sav 101 r01
io text char r01
sav 115 r01
io text char r01
io text space rff
sav 111 r01
io text char r01
sav 102 r01
io text char r01
io text space rff
sav 98 r01
io text char r01
sav 101 r01
io text char r01
io text char r01
sav 114 r01
io text char r01
sav 46 r01
io text char r01
io text newline rff
sav 84 r01
io text char r01
sav 97 r01
io text char r01
sav 107 r01
io text char r01
sav 101 r01
io text char r01
io text space rff
sav 111 r01
io text char r01
sav 110 r01
io text char r01
sav 101 r01
io text char r01
io text space rff
sav 100 r01
io text char r01
sav 111 r01
io text char r01
sav 119 r01
io text char r01
sav 110 r01
io text char r01
sav 44 r01
io text char r01
io text space rff
sav 112 r01
io text char r01
sav 97 r01
io text char r01
sav 115 r01
io text char r01
io text char r01
io text space rff
sav 105 r01
io text char r01
sav 116 r01
io text char r01
io text space rff
sav 97 r01
io text char r01
sav 114 r01
io text char r01
sav 111 r01
io text char r01
sav 117 r01
io text char r01
sav 110 r01
io text char r01
sav 100 r01
io text char r01
sav 44 r01
io text char r01
io text newline rff
cal add -1 r02
sav r01 r02
io text int r01
io text space rff
sav 98 r01
io text char r01
sav 111 r01
io text char r01
sav 116 r01
io text char r01
io text char r01
sav 108 r01
io text char r01
sav 101 r01
io text char r01
sav 115 r01
io text char r01
io text space rff
sav 111 r01
io text char r01
sav 102 r01
io text char r01
io text space rff
sav 98 r01
io text char r01
sav 101 r01
io text char r01
io text char r01
sav 114 r01
io text char r01
io text space rff
sav 111 r01
io text char r01
sav 110 r01
io text char r01
io text space rff
sav 116 r01
io text char r01
sav 104 r01
io text char r01
sav 101 r01
io text char r01
io text space rff
sav 119 r01
io text char r01
sav 97 r01
io text char r01
sav 108 r01
io text char r01
io text char r01
sav 46 r01
io text char r01
io text newline rff
io text newline rff
sav r02 r01
ifz 2
stp
rmv 2
jmp 1
Fibonacci
The following program outputs the first 46 positive Fibonacci terms, terminating before the sequence exceeds the maximum representable value of a signed 32-bit Crawssembly register.
sav 1 r02
sav 1 r03
1
io text int r02
io text newline rff
cal add 1 r04
sav r01 r04
cal add -46 r01
ifz 2
stp
rmv 2
cal add r02 r03
sav r03 r02
sav r01 r03
jmp 1
Collatz Conjecture
sav 50 r02 ; input number
1
io text int r02
io text newline rff
cal add -1 r02
ifz 2
stp
rmv 2
cal and 1 r02
ifz 2
sav 1 r01
cal sar r02 r01
sav r01 r02
jmp 1
rmv 2
cal add r02 r02
cal add r02 r01
cal add 1 r01
sav r01 r02
jmp 1
Euclidean Algorithm
sav 104 r02 ; first value
sav 84 r03 ; second value
1
cal not r03 rff
cal add 1 r01
cal add r02 r01
ifz 2
io text int r02
stp
rmv 2
ifg 2
sav r01 r02
jmp 1
rmv 2
cal not r01 rff
cal add 1 r01
sav r01 r03
jmp 1
