Redcode

Redcode is an esoteric programming language designed by A. K. Dewdney and David Jones in autumn 1983 and first described in the May 1984 issue of Scientific American. The purpose of Redcode is to provide an environment for Core War, in which programs attempt to crash their opponents. Redcode is (almost) Turing Complete in the same sense as C, where any given program must run within finite memory space but may be agnostic to the exact size.

Hello, World
This program prints out the words Hello, World!:

; Redcode Hello World, John Metcalf

write  sts.a  hello,     0 sts.b }write,    0 djn   write,     #7 hello  dat    72,        101 ; He        dat    108,       108 ; ll        dat    111,       44  ; o,        dat    32,        87  ;  W        dat    111,       114 ; or        dat    108,       100 ; ld        dat    33,        10  ; !\n

Imp
This program copies itself forward forever, turning other processes into copies of itself. Somewhat hard to kill, but always overwrites enemies with executable instructions. Note that this program relies on the fact that all Redcode addressing is relative--in fact, no position in memory is privledged in any way as the "first", since Redcode memory is circular.

; "Imp", A. K. Dewdney mov   0,         1 mov.i #8,        1 ; A-field can store arbitrary data. mov.i #1,       *0 ; Copies itself via A-field indirection.
 * Alternate versions using redcode-94 instruction modifier semantics:

Dwarf
This was the first offensive program. It scores 25% wins and 75% ties against Imp, and 37.5% wins, 37.5% losses, and 25% ties against itself. Additionally, in cores of size divisible by four (which are very common), it will never overwrite its execution footprint with a terminal DAT. By modern standards, though, it is very weak.

; "Dwarf", A. K. Dewdney mov  4,          @4 ; Move the bomb to the location pointed to by the bomb. (B-indirect.) add  #4,         3  ; Immediate add adds the immediate A-operand to the B-field of the cell pointed to by the B-operand. jmp  -2             ; Jump back two steps (to the MOV) dat  #4             ; The bomb. After enough cycles, dwarf will overwrite the bomb with itself, harmlessly. It then restarts the bombing run.

External resources

 * Annotated Draft of the Proposed 1994 Core War Standard
 * Thoughts on Corewar..., impomatic's Redcode programming blog
 * Core War (Wikipedia), including an overview of different strategy types