Avoid destroying the contents of registers. Or the program will die.

If you are adding your own code in Ghidra, you will, of course, need to install a jump out from the factory programme code into your code. A common method is to override mov instructions, as they update registers with new values and these registers can be freely used in your own code (e.g. mapswitching). In this example, overwriting two movs with the ‘J My_code’ command allows us to use the d15 and a2 registers. One thing to keep in mind - we need to put the piece of original code we ‘destroyed’ at the very end of our program, so that the d15 and a2 registers regain their correct factory content. If we need more registers (in fact, we always need them), having one data register and one address register is enough to store another in RAM and rebuild their contents at the end. It is essential to remember this, reverse-engineering geeks. 😉
Nov 15 / Thomas
Created with