unit Unit1;
interface
uses
Windows, Messages, SysUtils, Variants, Classes, Graphics, Controls, Forms,
Dialogs, StdCtrls;
type
TForm1 = class(TForm)
Button1: TButton;
procedure Button1Click(Sender: TObject);
private
{ Private declarations }
public
{ Public declarations }
end;
var
Form1: TForm1;
implementation
{$R *.dfm}
function GetBrandString : string;
function CPUIDAvail : boolean; assembler;
{Thests wheter the CPUID instruction is available}
asm
pushfd // get flags into ax
pop eax // save a copy on the stack
mov edx,eax
xor eax, 0200000h // flip bit 21
push eax // load new value into flags
popfd // get them back
pushfd
pop eax
xor eax,edx
and eax, 0200000h // clear all but bit 21
shr eax, 21
end;
const
CPUID=$a20f;
var
s:array[0..48] of char;
begin
fillchar(s,sizeof(s),0);
if CPUIDAvail then begin
asm
//save regs
push ebx
push ecx
push edx
//check if necessary extended CPUID calls are
//supported, if not return null string
mov eax,080000000h
{dw} CPUID
cmp eax,080000004h
jb @@endbrandstr
//get first name part
mov eax,080000002h
{dw} CPUID
mov longword(s[0]),eax
mov longword(s[4]),ebx
mov longword(s[8]),ecx
mov longword(s[12]),edx
//get second name part
mov eax,080000003h
{dw} CPUID
mov longword(s[16]),eax
mov longword(s[20]),ebx
mov longword(s[24]),ecx
mov longword(s[28]),edx
//get third name part
mov eax,080000004h
{dw} CPUID
mov longword(s[32]),eax
mov longword(s[36]),ebx
mov longword(s[40]),ecx
mov longword(s[44]),edx
@@endbrandstr:
//restore regs
pop edx
pop ecx
pop ebx
end;
end;
result:=StrPas(s);
end;
procedure TForm1.Button1Click(Sender: TObject);
begin
ShowMessage(GetBrandString);
end;
end.
|
|