VC2005 asm开发环境 cpuid

来源:互联网 发布:卖家加入农村淘宝 编辑:程序博客网 时间:2024/04/28 05:29

新建一个c++project,配置asm的编译规则,然后在cpp中录入如下代码:

#include "stdafx.h"
#include <intrin.h>
 

extern "C" int __stdcall FUNC(int arg1);

int sum(int a, int b)
{
 int c;
 __asm
 {
  mov EAX, a;
  mov EDX, b;
  add EAX, EDX;
  mov c, EAX;

 }
 return c+10000;
}


int _tmain(int argc, _TCHAR* argv[])
{
 int a = 0x1000000;
 int b = 100;
 int c = sum(a, b);
 int d = FUNC(a);

 printf("Result: %d, %x", c, d);

 int arr[4];
 for (int a = 0; a < 5; a++)
 {
  __cpuid(arr,a);
  printf("The code %d gives %d\n",a, arr[0]);
 }

 __cpuid(arr, 0x80000000);
 printf("The code %d gives %x\n",0x80000000, arr[0]);
 if (arr[0] >= 0x80000001)
 {
  __cpuid(arr, 0x80000001);
  printf("The code %d gives %x\n",0x80000001, arr[3]);

  if (!(arr[3] & (1 << 29)))
  {
   printf("x32");
  }
  else
  {
   printf("x64");
  }
 }
 else
 {
  printf("x32");
 }


 return 0;
}

另外新建一个asm文件:

.386
.model flat, stdcall
.data
.code

FUNC proc, arg1 : DWORD
mov EAX, arg1
mov EDX, 1
add EAX, EDX
RET
FUNC endp

end

 

 

另外我们可以使用/d1reportSingleClassLayout/d1reportAllClassLayout这个编译开关,它可以让MSVC 编译器(译注:至少是MSVC 6.0 以上的版本)生成一个.layout 文件,在该文件中包含有大量的极具价值的类的布局信息,包括基类在派生类中的位置,虚函数表,虚基类表(virtual base class table 我们下面会深入讨论),类的成员变量等信息(实际上我们这些图表都是从.layout文件中取出的)。

设置方法:在Project Properties->C++->Command Line->Additional Options里面加上/d1reportSingleClassLayoutDerived

 

 

原创粉丝点击