Universal Register Machine
1. Gadgets
A gadget is a partial register machine graph.
- It has one entry wire, and one or more exit wires.
- The gadget operates on input and ouptut registers specified in the gadget's name.
- The gadget may use other registers, called scratch registers, for temporary storage.
- The gadget assumes scratch registers are initialized to
. - The gadget ensures scratch registers are set back to
before the gadget exits.
1.1 Zero
An example gadget is the "zero

1.2 Addition
Another gadget is the "add

1.3 Copy
Another gadget is the copy

Another gadget is "copy

1.4 Multiply
Another gadget is "muliply

1.5 Push
Another gadget is "push

Given input values
1.6 Pop
Another gadget is "pop

If
2. Universal Register Machine
The universal register machine carries out the following computations:
- Starts with
, (code of the program), (code of a list of arguments), and all other registers zeroed. - Decode
as an RM program . - Decode
as a list of register values . - Carry out the computation of
starting with , , , (and any other registers zeroed).
Mnemonics for the registers of
: result of the simulated computation (if any). : code of the program. : code of a list of arguments. : PC (program counter) - label of the current instruction._ : - label number of the next instruction(s). : - code of the current instruction body. : - value of the register to be used by the current instruction. : scratch registers. : other scratch registers.
Execution runs as follows:
- Copy the
th item of into (halt if >length of list.) - If
, halt. Otherwise, decode . is either or . - Copy the
th item of into . - Execute instruction at
, update , restore register values at . - Repeat
