This SO question covers the topic perhaps
How to write self-modifying code in x86 assembly
Dont let people slow you down with the "why are you doing this questions"...
You have to know enough about the language or operating system or both and punch through or work within the protection system. Then it is a matter of putting the binary you want to execute (assuming you have done your work to make it positition independent and/or dependent on the addressing given/found/acquired/whatever) in memory and branch to it. In C you can declare a function pointer then assign the address to that function being the address of this binary and then call the function (if you have no other way to branch to an address, I usually prefer to write a few lines of asm and link them that perform the branch to any arbitrary address I pass the asm).