Redcode
Redcode is the programming language used in Core War. It is executed by a virtual machine known as a Memory Array Redcode Simulator, or MARS. The design of Redcode is loosely based on actual CISC assembly languages of the early 1980s era, but contains several features not usually found in actual computer systems.
0000: ADD.AB # 4, $ 3 0001: MOV.F $ 2, @ 2 0002: JMP.B $ -2, $ 0 0003: DAT.F # 0, # 0Assembled ICWS-94 style Redcode
Both Redcode and the MARS environment are designed to provide a simple and abstract platform without the complexity of actual computers and processors. Although Redcode is meant to resemble an ordinary CISC assembly language, it differs in many ways from "real" assembly:
- Redcode has very few operations—10 in ICWS-88 and 18 in ICWS-94.
- Each assembled instruction is divided into an instruction code and two numeric fields. No numeric value is defined for the instruction code. The code may only be copied as part of an entire instruction, and may only be compared for equality.
- Besides the opcode and two numeric operands, ICWS-94 allows each Redcode instruction to have a modifier that defines the size (one field, both fields, or entire instruction) of the data that the instruction operates on. Additionally, each of the numeric fields has associated addressing mode. ICWS-88 defines four addressing modes, and ICWS-94 extends this number to 8.
- Each Redcode instruction has the same length and takes the same time to execute. The memory is addressed in units of one instruction.
- All numbers are unsigned (i.e. non-negative) integers less than the size of the memory. Therefore there is a one-to-one correspondence between numbers and memory locations. All arithmetic is done modulo the size of the memory.
- Only relative addressing is used. That is, address 0 always refers to the currently executing instruction, address 1 to the instruction after it, and so on. Addresses past the end of the memory wrap around to the beginning. This way, a program cannot (and need not) know its absolute location in the memory.
Each program can also have several active processes, each having its own instruction pointer. Each program starts with only one process, but others can be created with the SPL instruction. The processes for each program execute alternately, so that the execution speed of each process is inversely proportional to the number of active processes the program has. A process dies when it executes a DAT instruction or performs a division by zero. A program is considered dead when it has no more processes left.
Read more about this topic: Core War