Skip to content

Latest commit

 

History

History
219 lines (129 loc) · 3.18 KB

File metadata and controls

219 lines (129 loc) · 3.18 KB

Neo Virtual Machine Specification

Neo is a stack-based virtual machine; it has two stacks, the working stack, and the return stack, each 512 bytes in length.

Comments

Neo's comment syntax is ()

(this is a comment)

Literals

Integers

Integers are values placed directly into the resulting ROM.
Integers are specified with hexadecimal numbers, which must be 2, 4, 6, or 8 digits in length.

ff aa 0a

Strings

Strings are pieces of text started with ' and delimited by whitespace.

'catdog

'Hello 20 'there 0a

Labels

Labels are non-digit, non-opcode, and non-runic symbols used to mark parts.

The address of a label may be accessed with ;.
This becomes a LIT4 followed by the label's address.

@cat

;cat

Instructions

The structuce of instructions in ROM are as follows:

0 00 00000
| |  |
| |  +------ opcode
| +--------- operand size
+----------- return mode

Most instructions are able to modified with r, 4, 3, and 2.
r causes instructions to read and write from and to the return stack instead of the data stack.
4, 3, 2 changes the amount of bytes read from certain operands; without one of these modeifers, a single byte is read.

LIT, 'literal'

( - N)

Pushes the bytes following it onto the stack.

LIT 30

A shortcut for non-r LIT is #.

#10 #20
#4030

DEI, 'device input'

(device8 port8 - N)

DEO, 'device output'

(N device8 port8 - )

HLT, 'halt'

(N - )

BRP, 'breakpoint'

( - )

DUP, 'duplicate'

(N - N N)

SWP, 'swap'

(N N' - N' N)

ROT, 'rotate'

(N N' N" - N' N" N)

POP

(N - )

STH, 'stash'

(N - |N)

GPC, 'get program counter'

( - addr4)

MEMR, 'memory read'

(addr4 - N)

MEMW, 'memory write'

(N addr4 - )

MEMC, 'memory copy'

(N src4 dst4 - )

JMP, 'jump'

(addr4 - )

TJMP, 'jump if true'

(N addr4 - )

FJMP, 'jump if false'

(N addr4 - )

EQ, 'equal'

(N N' - byte)

NE, 'not equal'

(N N' - byte)

LT, 'less than'

(N 'N - byte)

GT, 'greater than'

(N 'N - byte)

ADD

(N 'N - N + 'N)

SUB, 'subtract'

(N 'N - N - 'N)

MUL, 'multiply'

(N 'N - N * 'N)

DIV, 'divide'

(N 'N - N / 'N)

AND

(N 'N - N & 'N)

OR

(N 'N - N | 'N)

XOR

(N 'N - N ^ 'N)

NOT

(N - ~N)

Devices

Devices are how Neo interfaces with the enviroment; each device has ports, which each act as functions for interfacing with the part of the enviroment that device manages.
There are 256 available device slots, each with 256 available ports.

The DEI and DEO instructions are used to read and write from and to device ports.
If a port that is only meant for writing is read from, it will return 0; likewise, if a port that is only meant for reading is written to, this does nothing.

0, System

1, Console

Port 0

Accepts: reading

This port acts as stdin.
Only one byte is ever read; any extras will be consumed, but otherwise ignored.

port 1

Accepts: writing

This port acts as stdout.

port 2

Accepts: writing

This port acts as stderr.