我在visual C++ 2010 Ultimate(Windows 7 Professional)中内联汇编时遇到了问题。我所有的内联组件不工作,当我使用字符,DWORD串等等等等......所以,我在我的控制台应用程序复制从MSDN此代码:内联程序集崩溃?
// InlineAssembler_Calling_C_Functions_in_Inline_Assembly.cpp
// processor: x86
#include <stdio.h>
char format[] = "%s %s\n";
char hello[] = "Hello";
char world[] = "world";
int main(void)
{
__asm
{
mov eax, offset world
push eax
mov eax, offset hello
push eax
mov eax, offset format
push eax
call printf
//clean up the stack so that main can exit cleanly
//use the unused register ebx to do the cleanup
pop ebx
pop ebx
pop ebx
}
}
我什么都没有,除了我的应用程序的那些行,结果:该字符串未打印并且应用程序崩溃。任何想法为什么发生这种情况
所以我不知道为什么'printf'导致访问冲突,但是您可以通过简单地推入前三个参数(不需要首先加载到'eax'),然后将12加到esp后重现问题函数调用,即不弹出'eax'。 'printf'仍然崩溃.' –
虽然这不是原因,但这个答案仍然增加了一些非常重要的东西,这肯定会避免_future_崩溃。 +1 – BlackBear