C++ CPUID(Intel x86 内联汇编)

void GetCPUID()
{
int s1, s2, s3, s4;
_asm
{
mov eax, 00h
xor edx, edx
cpuid
mov dword ptr[ebp - 4], edx
mov dword ptr[ebp - 8], eax

mov eax, 01h
xor ecx, ecx
xor edx, edx
cpuid
mov dword ptr[ebp - 12], edx
mov dword ptr[ebp - 16], eax
}
}
 
int* GetGPUID()
{
 __asm
 {
  //push        ebp
  //mov         ebp,esp
  //sub         esp,0C0h
  //push        ebx
  // push        esi
  // push        edi
  // lea         edi,[ebp-0C0h]
  // mov         ecx,30h
  // mov         eax,0CCCCCCCCh
  // rep stos    dword ptr es:[edi]
  mov eax,00h
  xor edx,edx
  cpuid
  mov dword ptr [ebp-4],edx
  mov dword ptr [ebp-8],eax
  mov eax,01h
  xor ecx,ecx
  xor edx,edx
  cpuid
  mov dword ptr [ebp-12],edx
  mov dword ptr [ebp-16],eax
  mov         eax,dword ptr [ebp-4] 
  mov         dword ptr [ebp-20],eax 
  mov         eax,dword ptr [ebp-8] 
  mov         dword ptr [ebp-24],eax 
  mov         eax,dword ptr [ebp-12] 
  mov         dword ptr [ebp-28],eax 
  mov         eax,dword ptr [ebp-16] 
  mov         dword ptr [ebp-32],eax 
  lea         eax, dword ptr[ebp-20] 
  pop         edi
  pop         esi
  pop         ebx
  mov         esp,ebp
  pop         ebp
  ret
 }
}

int add(int x, int y)
{
return x + y;
}

int call_ptr(int p, int x)
{
_asm
{
push         dword ptr[ebp+12]
call         dword ptr[ebp+8]
}
_asm
{
pop         edi  
pop         esi  
pop         ebx  
mov         esp,ebp 
pop         ebp  
ret  
}
}

void main(int argc, char* argv[])
{
int retVal = call_ptr((int)&add, 1);
}


int r;
_m* c_m = new _m();
int m_p;
_asm
{
push        2  
push        1  
mov         ecx,dword ptr [ebp-20]  
call        _m::_add
mov         dword ptr [ebp-8],eax  
}
_asm
{
mov         eax,dword ptr [ebp-20]
mov         dword ptr [ebp-32], eax
}

int i;
bool max;
_asm
{
mov         dword ptr [ebp-8],0 
cmp         dword ptr [ebp-8],1
jle         _loop_min  
jmp         _loop_max  
_loop_min:
mov         byte ptr [ebp-17],0
mov         al,byte ptr [ebp-17]
_loop_max:
mov         byte ptr [ebp-17],al  
}

int i;
_asm
{
mov         dword ptr [i],0  
_loop_beige:
cmp         dword ptr [i],64h  
jge         _loop_end
mov         eax,dword ptr [i]  
add         eax,1 
mov         dword ptr [i],eax  
jmp         _loop_beige
_loop_end:
}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值