在MFC中包含__asm时遇到问题 [英] having problem including __asm in MFC

查看:110
本文介绍了在MFC中包含__asm时遇到问题的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我在Windows7 64位的VS2008中创建了一个基于MFC对话框的应用程序.我放置了一些asm代码:

Hi,

I created a MFC dialog based app in VS2008 in Windows7 64bit. I placed some asm code:

void CMfcAsmTestDlg::OnBnClickedButton1()
{
  char format[] = "%s %s\n";
  char hello[] = "Hello";
  char world[] = "world";

   __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
   }
}

我得到:错误C2415:操作数类型不正确.我使用"mov"一词的每一行都会发生这种情况.

我是否需要更改任何项目设置或包括任何文件?

I get: error C2415: improper operand type. This happens on each line I used the word ''mov''.

Do I need to change any project settings or include any file?

推荐答案

这是因为寄存器eax仅接受长整型类型:
This is because register eax accepts only long int types:
void OnBnClickedButton1()
{
  char buff[256];
  char format[] = "%s %s\n";
  char hello[] = "Hello";
  char world[] = "world";
  unsigned int  f = (unsigned int)format,
                h = (unsigned int)hello,
                w = (unsigned int)world,
                b = (unsigned int)buff;

   __asm
   {
      mov  eax, w
      push eax
      mov  eax, h
      push eax
      mov  eax, f
      push eax
      mov  eax, b
      push eax
      call sprintf
      //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
      pop  ebx
   }
}


问候.


这篇关于在MFC中包含__asm时遇到问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆