browser

Overview

overview
calendarsave
xyw 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: dot-single 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). dot-single it includes specific modes to operate on registers. dot-single it exposes more basic and simpler devices by default. dot-single it only exposes a single stack to the user (corresponding to Uxn's working stack). dot-single it has a concept of relocatable zero page (direct page), partly borrowed from 6809 assembly. dot-single 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 dot-single up to 64KiB of addressable memory. dot-single two stacks, one used internally by the system to manage subroutines, and one accessible to the user. dot-single 32 instructions, each with up to three different modes to operate on registers and on 16bit values. dot-single Two 8bit registers called x and y, and two 16bit registers accessible via the w mode. dot-single Up to a maximum of 16 memory-mapped devices, each with 16 reserved bytes (like Uxn). dot-single Event-based operation, similar to Uxn. dot-single Direct page accessible via a single byte, set by default to the device page, that can be moved to different locations in memory. dot-single A few assembly-inspired directives, which are also used to implement labels. dot-single Support for integers expressed in hexadecimal or binary notation. === Syntax Consider the following simple program that prints a random number from 1 to 6:
.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: dot-single numbers, like $31 and $0A dot-single directives, like .include dot-single instructions, like ADD and STB dot-single symbols, like terminal.output dot-single 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: dot-single system dot-single terminal dot-single clock dot-single file dot-single beeper