Overview
overviewxyw is a specification for a minimalist virtual machine programmable via a concatenative, assembly-like language. It is implemented primarily as a stack machine, but it also provides four "registers" that can be used by most instructions by specifying dedicated modes, to reduce the need of stack juggling operations common to languages like Forth.
=== Rationale
xyw is heavily inspired by Uxn and its fork Bedrock, but aims at being even simpler and easier to learn. In particular, it differs from Uxn because:
its syntax is more minimalist: no runes or sigils except for . for directives, $ for hex numbers and % for binary numbers (all these are inspired by 6502 assembly syntax).
it includes specific modes to operate on registers.
it exposes more basic and simpler devices by default.
it only exposes a single stack to the user (corresponding to Uxn's working stack).
it has a concept of relocatable zero page (direct page), partly borrowed from 6809 assembly.
it maps devices to addressable memory.
In a nutshell, if Uxn can be used to create small multimedia programs that could be running on low-end laptops and small gaming handhelds, xyw can create programs that could hypothetically run on the equivalent of a 1980s pocket computer or early terminal.
=== Key Features
up to 64KiB of addressable memory.
two stacks, one used internally by the system to manage subroutines, and one accessible to the user.
32 instructions, each with up to three different modes to operate on registers and on 16bit values.
Two 8bit registers called x and y, and two 16bit registers accessible via the w mode.
Up to a maximum of 16 memory-mapped devices, each with 16 reserved bytes (like Uxn).
Event-based operation, similar to Uxn.
Direct page accessible via a single byte, set by default to the device page, that can be moved to different locations in memory.
A few assembly-inspired directives, which are also used to implement labels.
Support for integers expressed in hexadecimal or binary notation.
=== Syntax
Consider the following simple program that prints a random number from 1 to 6:
numbers, like $31 and $0A
directives, like .include
instructions, like ADD and STB
symbols, like terminal.output
comments, starting with a semicolon
=== Devices
xyw, like Uxn and Bedrock, has the notion of devices: specific areas of memory that let you interface with the outside world. You can read characters inputted via the keyboard and draw pixels simply by accessing the right bytes.
By default, xyw defines only the following devices, but another eleven custom ones could be implemented to further extend the virtual machine:
system
terminal
clock
file
beeper
.include "lib/macros.xyw"
; Get random number and calculate modulo 6
system.random LDB $06 MOD
; Print result+1 and new line
$31 ADD PUTC
NL
As you can see, xyw syntax is deliberately minimalist, there are essentially five types of tokens: