Let me ask the question more specifically, with an example of assembly version.
Consider the function below.

void Test()
{
    int x, y, z;

    x = 1;
    if(x==1)
        y=2;
    else
        y=3;
OtherStuff:
    z = 4;
}
---------------
    x = 1;
012313BE  mov     dword ptr [x],1
    if(x==1)
012313C5  cmp     dword ptr [x],1
012313C9  jne     Test+34h (12313D4h)
        y=2;
012313CB  mov     dword ptr [y],2
    else
012313D2  jmp     OtherStuff (12313DBh)
        y=3;
012313D4  mov     dword ptr [y],3
OtherStuff:
    z = 4;
012313DB  mov     dword ptr [z],4


The assembly instruction corresponding to 'if(x==1)' is
012313C5  cmp     dword ptr [x],1

So, if I am able to change the instruction at this address during run-time to
012313C5  jmp     OtherStuff (12313DBh)

Then, I will be able to permanently skip the condition checking. Right?
Why is this not possible?

All the languages I have heard about allow the programmer to change only the data in memory; not the instructions. The programmer's thought process is controlled by this idea, subconsciously. Why can't we change the instructions at runtime? Is there any fundamental issue with that?
Is it possible to do it through direct assembly coding?

Thanks,
Gopan


Reply via email to