This can be done in special cases. What you describe is something like dynamically loading plugins via the C dynamic linking loader: try `man dlopen` for details on that. Usually the code so called has to be compiled as "position independent", so you're almost certainly out of luck for any specific program.
You could look at userland exec code for some hints on how this might be done, but it almost certainly won't work to do what you describe.