Software which deliberately modifies the machine instructions comprising itself in
memory. This technique obviously only works when writing in
assembly language. It is of questionable value unless working in an environment where memory is so restricted that incredibly
tight code is a necessity. It is a bitch to
debug.
A simple example: say you have a program containing a variable foo which is only ever used by two instructions, one of which loads it into a register, the other of which increments it (we'll assume the architecture has an inc instruction which can be applied to a memory location):
start: load r1, foo
;
; other stuff...
;
inc foo
jmp start
Then instead of wasting
memory by having
foo stored somewhere outside the code, we can instead change things so that the
load instruction contains a literal value (which we set to
foo's initial value), and the
inc instruction references
the actual memory location of the load instruction's operand:
start: load r1, 42
;
; other stuff...
;
inc (start+1)
jmp start
Thus after execution of
inc (start+1) the
load instruction stored in memory will actually be
load r1, 43--the code has self-modified.
This, of course, is a very weak example. Much more interesting things happen when you start modifying the actual opcodes, so that completely different instructions will be executed on each pass through the loop.