This document contains a very short description of the REDCODE
assembler and MARS emulator. If you really want to get serious
about corewars, like entering a tournament, you should join the
International Core Wars Society by sending $25.00 to
International Core Wars Society
8619 Wassall Street
Wichita, KS 62210-1934
For other information, see the January 1987 issue of "Scientific
American."
Strategy.
The object of the game is to code up a warrior (program) which
will outlast all other warriors it meets, or at least keep going
until the clock runs out. The way one destroys a warrior is to get
all of his processes to execute data values. A warrior may spawn
new processes as described below, but he is limited to a maximum
of 64 processes. There is a certain amount of luck involved in a
particular battle, as the processes are loaded in a random, non-
overlapping manner. All addressing is relative to the instructions
location, so there is no way to know in advance where your
opponent is. There are examples of some previously successful
programs included with this down load. So far, I have not seen any
examples of a self repairing program.
Operation. The two programs supplied are meant to be run either
from the desktop or from a shell. First, one uses his favorite
text editor to create an ASCII file of the source code for his
warrior with the extension .s. The assembler converts the source
code into a listing file with extension .l, and an object file
with extension .o. Assembly errors are shown in the listing file.
The corewars program is then run, and using the GEM menus, you
load two warriors and turn them loose. The default settings for
core size and battle length are the ones used in the 2nd
International Core War Competition. These values may be different
in the next tournament.
Assembler Syntax.
I tried to follow the syntax in the original core wars standard
dated May 21, 1986.
All characters are converted to uppercase when read. Blank lines are
allowed.
The syntax of a line is
label operation operand(s) comments.
These fields are discussed in more detail below.
Labels. Labels are indicated by a letter in the first character
position of a line, and are terminated by white space. Labels have
a maximum of 8 characters, and all other characters must be
alphanumeric.
Operations. The operation field consists a valid operation listed
below, and is terminated by whitespace.
Operands. The operand field may contain none, one, or two operands,
depending on the instruction. If two operands are required, they
should be separated by a comma. Each operand may be preceded by a
mode character, also given below. Addition and subtraction of
labels, constants, etc. are supported, but no parenthesis are
allowed. The operands field is terminated by either a ;,
whitespace, or the end of the line. No checking is done
on the legality of arithmetic operations as far as overflow or label
arithmetic.
Comments. Comments are indicated by a ;. All characters from the
semi-colon to the end of the line are treated as a comment. If the
first character of a line is a ;, the line will be treated as a
comment only.
Mode Characters. Note that all addressing is done relative to the
program counter. This is called direct addressing in the core wars
standard, but I'm more used to calling this relative addressing.
# Immediate Addressing. The operand is treated as a constant. Note
that if a label is used, the translated value of the label
relative to the location count is used. This probably isn't
correct, but it made the implementation easier.
$ Direct Addressing. Again, this is relative to the location
counter. Direct addressing is the default mode.
@ Indirect Addressing. This uses the contents of the location of
the referenced location as a pointer to actual location. Note that
the pointer is evaluated relative to the pointer location.
< Auto-Decrement Indirect Addressing. This is similar to Indirect
Addressing as described above, but the pointer is reduced by one
before it is used. If you do strange things using this instruction,
strange things may happen, as the microcode for this mode
is not well defined in the standard.
The Operations. Value as used below means the portion of the word
used for storing numeric values. All values are modulo memory
size, although the modulus operation is not performed until the
warrior's object code is loaded.
DAT value
This is not an operation, but an assembler directive which places
the value at the location given by the location counter. Any
process which executes a data statement will die.
MOV A,B
Move the value at the effective address A to the effective address
B.
ADD A,B
Add the value at the effective address A to the value at effective
address B, and place the result in effective address B.
SUB A,B
Subtract the value at the effective address A from the value at effective
address B, and place the result in effective address B.
JMP A
Start executing at effective address A.
JMZ A,B
If the value at effective address B is zero, then execution starts at
effective location A. Otherwise execution continues with the next
location.
JMN A,B
If the value at effective address B is not zero, then execution
starts at effective location A. Otherwise execution continues with
the next location.
DJN A,B
The value at the effective address B is decremented by one. If the
result is not zero, then execution starts at effective location A.
Otherwise execution continues with the next location.
CMP A,B
The value at effective address A is compared with the value at
effective address B. If they are equal, the next location is
skipped. If neither one of the operand's mode is immediate, then
the complete word is tested for equality.
SPL B
This instruction spawns a new process which will start executing
at effective address B. The spawning process continues at the next
location. Spawning will not occur if there are already 64
processes running for this warrior.
END
This is an assembler directive indicating the end of the REDCODE.
This assembler is unhappy if it does not find an END directive
before it finds an end-of-file.
SPACE N,M
This is an assembler directive which is ignored by this assembler.
Miscellaneous.
Instruction execution begins at the first location or at the label
START. Any key stops the battle. Dark dots represent program
counters, while light dots represent a memory access. The
instruction trace columns are instruction operation code, a mode,
a value, b mode, and b value. Core accesses are indicated by
read/write, location, operation code, a field mode, a field value,
b mode, and b value. The b value is used to hold data values.