This documentation is relevant to version 1.0 of the assembler and version 1.1 of the virtual machine.
WNCW is inspired by Core War, a programming game with an assembly-like language. There are some differences between the two, however. For example, in Core War, each instruction is a unit in memory and addresses refer to a specific instruction. WNCW adopts a more traditional bytecode approach where instructions have varied lengths and addresses refer to a specific byte or word. (WNCW does keep the relative addressing and modulo arithmetic of Core War, however.)
The virtual machine consists of 65536 bytes of memory and a number of warriors. Each warrior has 256 bytes of pspace (a concept from Core War) and up to 256 processes, each with their own instruction pointer. Each warrior has an "active" process. On each step, each warrior executes one instruction in their active process and then, if the instruction pointer has not been modified, advances it to the start of the next instruction. The active process for the warriors next turn is then set to the next process. This repeats until there is only one warrior with processes alive, at which point this warrior is declared the winner.
Each instruction is put one after the other. The first byte consists of a so-called "opcode", with the top half being flags, explained later, and the bottom half specifying the operation to perform. Next is the destination field. Depending on the flags, this can be one or two bytes long. Next is the source field, if the operation has one. Again, this can be one or two bytes long depending on the flags.
The flags are as follows: 0x80 - destination reference; 0x40 - destination private; 0x20 - source reference; 0x10 - source private. If a field's private flag is set, that field is one byte and that input (or output) is the word in pspace at that absolute address. Otherwise, the field is two bytes and the input (or output) is the field. Additionally, if the field's reference flag is set, the input is added to the address of the instruction's opcode and that becomes the address of the input (or output).
The operations are as folows: (Note that all arithmetic in WNCW is modulo 65536.)
The assembly format used features one instruction on each line in the format
op destination, source or
op destination. Labels, beginning with a colon, can go either before the instruction on the same line, or on their own line. Lines starting with a hash are ignored. A line consisting of comma-separated integers (in decimal) are interpreted as bytes to put into the bytecode at that point. (This takes the place of
dat in Core War.)
A tilde before a field indicates the private flag for that field. Brackets (
]) around a field (and the tilde, if applicable) indicate the reference flag for that field. When the private flag is set, the field's value must be a constant integer from 0 to 255. Otherwise, it can be any number of constant integers or labels (without colons) added or subtracted together. If a label has
.src after it, it points to that instruction's destination or source field, respectively. Otherwise, it points to the opcode. Don't forget that all arithmetic in WNCW is modulo 65536.
The operations are as follows:
Samples can be found here.
If the virtual machine is compiled with
#define VIS, it opens a window when you run it. In this window, each 4x4 pixel area represents a byte of memory, left to right then up to down. When a warrior writes to a byte, an X is written there in the window. When a byte is read, a dot is written there in the window. The instruction a process will execute on the next step has a block written to the opcode byte in the window. When a process dies, two parallel horizontal lines are written to the last opcode byte it executed in the window.
Each warrior has its own color, as seen in the following list: (Anything past the length of this list will either have a garbage color or cause the virtual machine to crash.)
When the interrupt signal is sent to the virtual machine (ctrl + c in the console), it will enter a debug mode. In this state, the virtual machine pauses, and allows you to examine the memory. You can type in an address (in hexadecimal) and it will tell you the contents of the next sixteen bytes, as well as a dissassembly of those bytes. After each examination, the virtual machine is stepped one instruction for each warrior. To exit the debug mode, simply enter
0xffff as the address.
The latest version of the assembler is version 1.0.0 and the latest version of the virtual machine is version 1.1.0. Both of those files contain instructions on how to compile and use them. Older versions can be found in this directory. If you write any cool WNCW-related things (like an evolver or some wrapper scripts), please email me and I will include links to them in this section.
Back to programs list