C++ 如何将寄存器的值存储到指针指向的内存位置?

C++ 如何将寄存器的值存储到指针指向的内存位置?,c++,pointers,assembly,x86,C++,Pointers,Assembly,X86,我有以下代码: void * storage = malloc( 4 ); __asm { //assume the integer 1 is stored in eax mov eax, storage //I've tried *storage as well but apparently it's illegal syntax } /* other code here */ free(storage); 但是,在代码中,当我取消引用存储指针时(如*(int*)存储中的

我有以下代码:

void * storage = malloc( 4 );

__asm
{
    //assume the integer 1 is stored in eax
    mov eax, storage  //I've tried *storage as well but apparently it's illegal syntax
}
/* other code here */
free(storage);

但是,在代码中,当我取消引用存储指针时(如
*(int*)存储中的
),我没有得到1。那么,将C++的指针指向内存中的登记值的正确方法是什么?

< P>你确定你知道你真正需要什么吗?您请求将寄存器值存储到由
malloc
(“指针指向”)分配的内存中的代码,即
*(int*)存储
位置,但您接受了将值存储(或至少尝试存储)到指针本身的答案,这是完全不同的事情

要按要求将
eax
存储到“指针指向”的内存中,即存储到
*(int*)存储中,您必须执行类似操作

mov  edi, dword ptr storage
mov  dword ptr [edi], eax
(我对汇编指令使用“英特尔”从右到左的语法,即
mov
从右操作数复制到左操作数。我不知道编译器使用的是哪种语法-从右到左还是从左到右。)


还要注意的是,在
mov edi中,dword ptr存储
dword ptr
部分是完全可选的,没有任何区别。

我的错,我认为你是对的。我没有时间检查第一个答案是否有效。它提醒我像“dword”这样的东西是存在的,所以我认为它可以解决问题。