procedure TForm1.Button1Click(Sender: TObject);
var rebx,recx,redx:dword;
str1:string;
begin
asm
mov eax,0
db 0fh,0a2h // cpuid
mov rebx,ebx
mov recx,ecx
mov redx,edx
end;
str1:=chr(rebx mod $100)+chr((rebx div $100) mod $100)+chr((rebx div
$10000) mod $100)+chr((rebx div $1000000) mod $100);
str1:=str1+chr(redx mod $100)+chr((redx div $100) mod $100)+chr((redx div
$10000) mod $100)+chr((redx div $1000000) mod $100);
str1:=str1+chr(recx mod $100)+chr((recx div $100) mod $100)+chr((recx div
$10000) mod $100)+chr((recx div $1000000) mod $100);
edit1.text:=str1; {一执行此句就出错}
end;
end.
eax, ebx都是比较重要的寄存器,建议你用它们之前先将其入栈(最好将所有寄存器入
栈比较保险:pushad/popad),在用完后弹出栈。
*************
有这样一段代码得出CPU厂家:
int mycpuid[20];
tchar zzz[20];
_asm
{
mov eax,0
cpuid
mov mycpuid[0],ebx
mov mycpuid[4],edx
mov mycpuid[8],ecx
}
sprintf(zzz,"CPU厂家为:",mycpuid);
在VC中编译通过。
然而我在DELPHI中却总是无法通过!并且不认cpuid(注:CPUID为微处理器中的一条指令)
:温柔一刀 时间:00-12-27 16:34:36 ID:426417
CPUID这一句换成:
DW $A20F
--------------------------------------------------------------------------------
来自:chentf 时间:00-12-28 10:06:14 ID:426985
var
a:array of integer;
begin
asm
mov eax,0
DW $A20F
mov a[0],ebx
mov a[4],edx
mov a[8],ecx
end;
按F9执行,出现错误提示框:
project project1.exe raised exception class ezccessviolation with message 'accessviolation at address 00404B58 in module 'project1.exe',write of address 7563653f'.
然后由于水平有限,也看不懂CPU中的消息.
--------------------------------------------------------------------------------
来自:Iknow 时间:00-12-28 11:12:33 ID:427051
试试以下代码:
var
a:array[0..15] of byte;
dword save_edi, save_esi, save_esp, save_ebp, save_ebx;
begin
asm
mov save_edi, EDI
mov save_esi, ESI
mov save_esp, ESP
mov save_ebp, EBP
mov save_ebx, EBX
mov eax,0
DW $A20F
lea esi, a
mov edi, 0
// mov a[0],ebx
mov dword ptr [esi+edi], ebx
add edi, 4
// mov a[4],edx
mov dword ptr [esi+edi], edx
add edi, 4
// mov a[8],ecx
mov dword ptr [esi+edi], ecx
mov ebx, save_ebx
mov ebp, save_ebp
mov esp, save_esp
mov esi, save_esi
mov EDI, save_edi
end;
end;