It comes down to binary compatibility.
If the processors both support the subset of the instruction set used by the program with the same semantics, then you won't have to recompile the code.
Depends on the scope of the question. You can write code and run it through a compiler that converts it into machine-code specific to a particular architecture: x86, amd64, ARM (and its many revisions), mips, etc...