Content deleted Content added
TakuyaMurata (talk | contribs) computer programming -> computer science |
m spelling, punctuation |
||
Line 3:
==Assembly style self-modifying code:==
The kinds of self-modifying code that are used in assembly
# Optimisation of a state dependant loop.
Line 23:
}
Self
repeat N times {
Line 35:
}
Note that 2-state replacement of the opcode
'xor var at address with the value "opcodeOf(Inc) xor opcodeOf(dec)"'
Line 46:
In some cases self-modifying code executes slower on modern processors. This is because a modern processor will usually try to keep blocks of code in its [[cache]] memory. Each time the program rewrites a part of itself, the rewritten part must be loaded into the cache again, which results in a slight delay.
The cache invalidation issue on modern processors
This concideration is not unique to processors with code cache, since on any processor
Self-modifying code was used in the early days of computers in order to save memory space, which was limited. It was also used to implement [[subroutine]] calls and returns when the instruction set only provided simple branching or skipping instructions to vary the flow of control (this is still relevant in certain ultra-[[RISC]] architectures, at least theoretically, e.g. one such system has a sole branching instruction with three operands: subtract-and-branch-if-negative).
Line 81:
==TODO==
#an example and discussion of 'high-level' self-modifying code such as in LISP.
# examples and discussion of traditional uses of self-modifying code, such as in graphic Blitting units, specialisation of algorithms (like sort with
|