Content deleted Content added
Significance for subroutines - PML |
No edit summary |
||
Line 1:
In [[computer programming]], '''self-modifying code''' is code that modifies itself. This is straightforward to write when using [[assembly language]] and is also supported by some high level language interpreters such as [[SNOBOL4]] or the [[Lisp programming language]]. It is more difficult to implement on compilers but compilers such as [[Clipper programming language|Clipper]] and [[Spitbol]] make a fair attempt at it. Batch programming scripts often involve self modifying code as well.
Self-modifying code is often executing slower on mordern processors. This is because most mordern processors will try to keep code from data in its [[cashe]] memories. Each time the processor notice a switch from code to data (when the program rewrites a part of itself), or from data to code (when the program jumps to the modified code) it will take a litle while for it to update its entires.
Self modifying code is not recomended to use when alternatives exist. This is because such code can be difficult to understand and maintain.
Self-modifying code was used in the early days of computers in order to save memory space in computers with very small main memory sizes. 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 single instruction with three operands: subtract-and-branch-if-negative).
|