Parameter value stored at address using x86 ASM

I'm trying to think about some of the built-in ASMs, but for some reason this doesn't behave as I expected. Why is this setting not equal to x value of 62?

#include <stdio.h>

int main()
{
    int x = 525;
    int* y = &x;

    _asm
    {
        mov eax, 62
        mov [y], eax
    }

    printf("%i", x);
    getchar();
    return 0;
}

As a result, the code outputs 525. I expected it to be 62.

+3
source share
2 answers

There is a completely excusable misunderstanding:

of course [y] will mean [0xCCCCCCCC] (if address x is 0xCCCCCCCC)

In high level theory, yes. The problem is that in a real assembly [0xCCCCCCCC]it makes no sense - the processor cannot dereference the memory address directly - it can only load the value from this address into the register, and then play it out.

, y - , , 1 y asm &y C 2. , , , , ( ) mov y, eax.

, , :

asm {
    mov eax, 62
    mov edx, y
    mov [edx], eax
}

[1] GCC. GCC extended asm - ...

[2] - "" C, , . , y [ebp-20], " ".

+2

x y. 62 (!) y - , [..]. , x, , * (* y). ( , .)

,

mov [&y], eax

( ).

0

All Articles