Emulator basics: a stack and register machine
We’ll make the following registers available for modification and use by the program(mer):
The register is used by the virtual machine for tracking the location of the last entry in the stack. After every instruction the virtual machine will increment the value in this register — except for a few special instructions like and . Without memory addresses it’s a simple function:
We need to do some hacking to support memory addresses:
This instruction will combine both registers and store the result in the first, then increment the register.
Source: notes.eatonphil.com