Changing a value of a number using inline assembly in C ++

I am trying to increase a numerical value using the built-in assembly in C ++. The reason I do this is to practice my "built-in assembly" skills.

Good thing I have done so far:

void main()
{
    int x;
    cout << "Please enter a number ";
    cin >> x;
    cout << "The number you entered is: " << x << "\n";
    foo(&x);
    cout << "The new number is: " << x;
    cin >> x;
}

void foo(int *x) 
{
    __asm
    {
        inc [x]
    };
}

And the meaning has never changed.

+5
source share
3 answers

x. x - , x ( foo). , , main x. , inc [x] . , [x], inc [[x]]. , , : , . :

push eax
mov eax, [x]
inc dword ptr [eax]
pop eax
+7

, , Visual ++ int-pointer:

void foo(*x)
{
  (*x)++;
}

(*x)++;
mov         eax,dword ptr [x] 
mov         ecx,dword ptr [eax] 
add         ecx,1 
mov         edx,dword ptr [x] 
mov         dword ptr [edx],ecx 

, Aneri.

0

x86 , , . :

__asm
{
    mov eax, x
    mov ebx, [eax]
    inc ebx
    mov [eax], ebx
};
-3

All Articles