The simplest, and probably the first, Core War program is the Imp, published by
A. K. Dewdney in the original 1984 Scientific American article that first
introduced Core War to the public.
MOV 0, 1
Yes, that's it. Just one lousy MOV. But what does it do? MOV of course copies an
instruction. You should recall that all addresses in Core War are relative to the
current instruction, so the Imp in fact copies itself to the instruction just
MOV 0, 1 ; this was just executed
MOV 0, 1 ; this instruction will be executed next
Now, the Imp will execute the instruction it just wrote! Since it's exactly the
same as the first one, it will once again copy itself one instruction forward,
execute the copy, and continue to move forward while filling the core with MOVs.
Since the core has no actual end, the Imp, after filling the whole core, reaches
its starting position again and keeps on running happily in circles ad infinitum.
So the Imp actually creates it's own code as it executes it! In Core War,
self-modification is a rule rather than an exception. You need to be effective to
be successful, and that nearly always means changing your code on the fly. Luckily,
the abstract environment makes this a lot easier to follow than in ordinary