c - Setting value stored at address using x86 ASM -


I am trying to get my head around some inline ASM but for some reason it is not behaving Why was not this value equivalent to x 62 as I expected?

  #include & lt; Stdio.h & gt; Int main () {int x = 525; Int * y = & amp; X; _asm {mov eax, 62 mov [y], eax} printf ("% i", x); Getchar (); Return 0; }  

Code results in the 525 output I expected it would be 62.

Here is a perfectly appropriate misconception:

Definitely [ Or] would mean [0xCCCCCC] (assuming X was 0xCCCCCCCC)

In high-level theory, yes trouble, in the actual assembly [0xCCCCCCCC] Not that the CPU can not directly define a memory address - it can only load a value from that address, then dereference that .

Similarly y is a variable , not registered , it is contained << code> y or y inside asm is considered equal to the address of the block & y c 2 In the code outside, as you can see in a debugger, what has happened, only ignores the brackets that do not understand the codec (instead of throwing a useful error) and mov y, eax < / Code>.

The way you expect the way you expect it to happen:

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

[1] This is clearly not GCC GCC extended ASM is a entire different ball game ...

[2] ] Some simplification - this is an "address" from the C-point view, but in the assembly context it is a memory operand, which is actually more like the usage of an address when I compiled it, Code> y In the form [ebp-20] , which is an address on the "stack of high-level view".


Comments

Popular posts from this blog

ios - How do I use CFArrayRef in Swift? -

eclipse plugin - Run java code error: Workspace is closed -

c - Error on building source code in VC 6 -