would someone please explain the Imp Ring in Core Wars?
c JMP imp-2666
launch SPL c
SPL imp+2667
imp MOV 0,2667
end launch
I think the above code is of the '88 Standard because it uses end
to signify the start of the program and there are no colons for the labels.
The program starts at the launch label. I need help visualizing how this Imp Ring "crawls" through the memory.
Let's disect this, line by line:
c JMP imp-2666
This causes the program counter to jump to the location of "imp" ...well really, 2666 locations before it. That's called an offset. Note the label "c."
launch SPL c
Here, the label "launch" is used to name the code block that follows. SPL means to "split" which means it will not only jump to location C, but it will also execute code that follows. That's the nature of split - start another process. Get it? :)
SPL imp + 2667
Again, another imp process is started, although this time it's at 2667 AHEAD of the current instruction pointer.
imp MOV 0, 2667
Remember all those instructions that use "imp" in their fields? this is it. If you don't know already, all the imp does is copy itself (the MOV instruction) to somewhere, so that it may execute itself endlessly.
end launch
Yep, you're right, it signifies the end of the code block. It's for the preprocessor, really.
Of course, in assembly, you've got to look at the whole picture: why does this instruction go here, what does it do in relation to everything else? This one's easy: it spawns an imp at every 2667 memory locations, so that they can overrun the core and its enemy. It's dumb though, unless it's part of a bigger warrior, chiefly because imps overwrite its enemy, absorbing it as a process, not killing it. It ends in a tie.
Hey, while we're on the subject, I'm looking for people to play with. I'm getting in to corewars myself. Wanna play some time? haha. Hope my explanation worked for you.