Search code examples
assemblymipsmips32self-modifying

self modifying code in assembly


How would I write self modifying code in mips 32 assembly that makes a function call another function(without adding a function call in it) ? I have to modify the function's code at runtime so that it calls the other function.


Solution

  • In the name of all that is holy DON'T!

    1. Assembler is often embedded in ROM so it doesn't work.
    2. Any OS with security worth a damn will not let you modify code segments or execute data.
    3. There is a special hell reserved for those who do, walled by the curses of those of us who have ever had to maintain the damned stuff!

    MIPS has a register mode for jumps -

        jr $rs
    

    Move the address you want to jump to into the register and jump to it. It's the functional equivalent of pushing the address onto the stack and doing a return. If you want to call the function, put the jump into its own subroutine so that the return from the called function goes back to the caller.