Variables

This subtle and remarkable code was discovered by Peter. It provides for variables in RAM, retrieving them without involving an address register. Consider this self-modifying code The words must be adjacent in this order. They occupy 3 words of RAM.

n!

Store value into variable n

n

Calling n will return its value, initially 0.

n may execute additional code, so long as the parameter is fetched in the first instruction word. For example

will add the variable instead of just fetching it.

n! may also execute additional code, so long as it preceeds the 4-word sequence @p drop !p ; aligned on a word boundary. I just used