Self updating software

The Algol compiler on B6700 systems offered an interface to the operating system whereby executing code could pass a text string or a named disc file to the Algol compiler and was then able to invoke the new version of a procedure.

Using self-modifying code, it is possible to store a register's contents into the second byte of the instruction, then execute the modified instruction in order to achieve the desired effect.

Some compiled languages explicitly permit self-modifying code.

The modifications may be performed: In either case, the modifications may be performed directly to the machine code instructions themselves, by overlaying new instructions over the existing ones (for example: altering a compare and branch to an unconditional branch or alternatively a 'NOP').

In the IBM/360 and Z/Architecture instruction set, an EXECUTE (EX) instruction logically overlays the second byte of its target instruction with the low-order 8 bits of register 1.

The method was frequently used for testing 'first time' conditions, as in this suitably commented IBM/360 assembler example.

It uses instruction overlay to reduce the instruction path length by (N x 1)-1 where N is the number of records on the file (-1 being the overhead to perform the overlay).

However, the capability was rarely used in practice.

In the early days of computers, self-modifying code was often used to reduce use of limited memory, or improve performance, or both.

For example, in the Intel 8080 instruction set, one cannot input a byte from an input port that is specified in a register.

The input port is statically encoded in the instruction itself, as the second byte of a two byte instruction.

It was also sometimes used to implement subroutine calls and returns when the instruction set only provided simple branching or skipping instructions to vary the control flow.

Tags: , ,