-
Notifications
You must be signed in to change notification settings - Fork 2
Dust Assembler
Dust is an assembler for the Pixi VM.
Assembler script is /dust/dust.py
. Usage: dust.py <input> <output>
where input is an assembly file and output is the desired compiled output.
A line can be either blank, a comment, a label, an instruction, or data.
A comment lines start with #
:
# This is a comment
A label consists of any number of upper case letters and must end with :
:
LABEL:
An instruction consists of an op code and two operands. An op code is any of the op codes supported by Pixie (lower case): mov
, add
, sub
, mul
, div
, rem
, not
, and
, or
, xor
, eq
, le
, leq
, jnz
, in
, out
.
An operand can be either a register or a number. Registers (lower case) are r0
, r1
, r2
, r3
, sb
, sp
, pc
. Numbers can be written in decimal, hexadecimal, or binary notation, eg: 42
, 0x2A
, 0b101010
. An operand can be optionally prefixed by *
to mark it as a dereference:
mov *r0 0xBEEF
jnz r1 :LABEL
Data can be any sequence of numbers. These are simply inlined in the resulting program. Data can be used to store constant values:
1 2 3 4 5
See BNF Grammar for formal language definition.
Following is an example program which counts down from 10, outputs numbers, then terminates:
# Countdown from 10
mov r0 10
REPEAT:
out r0 0
sub r0 1
jnz r0 :REPEAT
# Pixie terminates when PC is at 0xFFFF
jnz 1 0xFFFF
For a more complex example, check out the Brainfuck interpreter here.