Core War
Writing / Glenn Strong Translation / BolideCaster
The Core War game is invented by A.K. Dewdney in 1983 and is achieved by him and David Jones at Western Ontario University. An article published by Science in May 1984 made this game widely known, since then, Core War has become more complex. In the Core War game, programs written in a special assembly language (called RedCode) are executed on an analog computer. Each program object has tried to lose operational capabilities to other programs running on the simulator while trying to protect themselves from the same fate. Such an attack can be implemented by writing illegal instructions to other programs to implement the memory location to be executed.
1 simulator
Redcode's simulator is often referred to as MARS (Memory Array Redcode Simulator, memory array Redcode Simulator). Mars operates by maintaining a array of memory (or "core") of the simulated computer; except for programs for the game, the rest are empty. Each location in the array can store a RedCode directive. The program is unable to determine the location of their memory, because all addressing in RedCode is "relative to instructions", and memory is looped (see the RedCode section below to learn about addressing). The execution model is simple: in the way, each program is allowed to execute a command at a time (i.e., the program 1 executes an instruction, then the program 2, then the program 3; when all programs are executed, the program 1 is executed The second instruction, so, etc.). Typically, each program will execute its first instruction, followed by the next instruction in the memory, then then the next, etc. (but some instructions can change this order). Each program starts from a random position in memory, and the spacing between the two programs is not less than 1000 addresses. Every game has time limit, if the time has arrived all programs, the game is announced.
2 redcode
Redcode is a simple language similar to assembly language. The instructions can be used to move from one memory location to another, perform simple arithmetic operations, and change the order of the program, and so on. Each RedCode directive has three domains, although some instructions use only two of them. These three domains correspond to: (i) instruction itself and its addressing mode. (Ii) A domain and the B domain, including the address of the instructions to operate. Unwanted domains will contain zero values.
2.1 instructions
Each RedCode directive takes one or two values as a parameter. These values are usually the address, specify where the instruction looks up or place the value or placement value. The addressing method of each address can be directly addressed (there is no prefix, or a $ symbol), which means that the address itself is the target; indirect addressing (in an @ prefix), meaning that the target address is specified by the address; Or immediate addressing (in a # is prefix), the address should be treated as an integer. An unusual feature of RedCode is calculated by all instructions relative to the current instruction. So the instruction JMP 1 means "jump to the next position" (this is actually the default behavior of the simulator, so the actual meaning of this instruction is "nothing"). Similarly, Add # 1 -1 means "add integers 1 to the previous position". The same unusual is that the machine's memory is loop (i.e., all addresses are calculated as the memory size). This means that if the last actual memory location is 8000 (common size), attempt to access location 8000 1 will actually get zero. This feature allows the program to ignore special circumstances that occur when arriving at the boundary of the machine memory. (Translator Note: The instructions described below are only part of the existing RedCode instruction set.)
DAT has only the B domain. If the DAT instruction is executed, it will lead to the termination of the program. The B domain of the instruction can be used to store a digital value. This command is equivalent to the zero value in the address (the program is used to place the "zero bomb").
MOV has a domain and B domain. The MOV instruction copies all the contents of the location indicated by the A domain to the location indicated by the B domain.
Add has an A domain and the B domain. Take the contents of the A domain and add it to the content of the B domain. All arithmetic operations in RedCode are performed in memory in memory.
SUB has A domains and B domains. Take the contents of the A domain, minus the contents of the B domain. All arithmetic operations in RedCode are performed in memory in memory.
JMP has only A domain. This is a jump command that makes instructions in the A domain becomes the next instruction.
JMZ has an A domain and the B domain. This is a conditional jump instruction. If the value indicated by the B domain is zero, jump to the instruction indicated by the A domain; otherwise it will not do anything.
JMG has an A domain and the B domain. This instruction is similar to the JMZ instruction, but the condition is that the value indicated by the B domain must be greater than zero.
DJZ has an A domain and the B domain. The most complex jump instruction. It minimizes the value indicated by the B domain. If the number of the B domain indicates to zero, jump to the instruction indicated by the A domain.
CMP has a domain and the B domain. Compare the values indicated by the A domain and the B domain, if they don't wait, skip the next instruction.
3 cases
The smallest Core War Samurai (Warrior) is IMP:
MOV 0 1
This program copies the address zero (because the relative addresses used in the RedCode, the content of the address, the current location) to address 1. In other words, it copies itself to the next position. Because the next position of the current location is also the next position to be executed, the effect of the execution of the program is to populate the memory with the MOV 0 1 instruction. DWARF is a more spicy procedure:
Add # 5 3MOV # 0 @ 2jmp -2dat -1 It places "zero bomb" in memory. Table 1 shows the partial tracking results of the DWARF program being executed. It is necessary to pay attention to:
* Other programs in the machine perform one step in each step of this program. This tracking assumes that there is no directive to modify any memory visible in the table. * Use the MOV to place zero to a location medium price to place a DAT 0 instruction there. Any program attempting to perform the statement will be terminated. * @ 地址 模式 变 允 位置 位置 位置 位置 间 作. 间.. * The last JMP-2 statement is intended to place a DAT 0 statement every 5 memory locations. Because the program is less than 5 instructions, as long as the total size of memory is a multiple of 5, it will never rewrite itself. Address Step 1 Step 2 Step 3 Step 4 1000 Add # 5 3 Add # 5 3 Add # 5 3 Add # 5 31001 MOV # 0 @ 2 MOV # 0 @ 2 MOV # 0 @ 2 MOV # 0 @ 21002 JMP -2 JMP -2 JMP -2 JMP -2 1003 DAT -1 DAT 4 DAT 4 DAT 410041005 DAT 0 DAT 0
4 more information
Original Core WAR article can be found at http://www.koth.org/info/akdewdney/. On this site, there is also a Core War related documentation and links, and can be downloaded from PMARs (portable mats, portable MARS) software available for Windows and UNIX; at the same time, it also provides a fight for the Core War Samurai from the world. "Yamou".