the answer is to encode your program using a higher-level machine code targeting a portable virtual machine.
that’s also how they managed to fit all the software of the Apollo guidance computer into it.
> “The AGC had a sophisticated software interpreter, developed by the MIT Instrumentation Laboratory, that implemented a virtual machine with more complex and capable pseudo-instructions than the native AGC.” (https://en.wikipedia.org/wiki/Apollo_Guidance_Computer#softw...)