怎样得到CPU的序列号unit Main;<br><br>interface<br><br>uses Windows, Messages, SysUtils, Classes, Graphics, Controls,<br>Forms, Dialogs, ExtCtrls, StdCtrls, Buttons;<br><br>type<br>TDemoForm = class(TForm)<br>Label1: TLabel;<br>Label2: TLabel;<br>Label3: TLabel;<br>Label4: TLabel;<br>GetButton: TBitBtn;<br>CloseButton: TBitBtn;<br>Bevel1: TBevel;<br>Label5: TLabel;<br>FLabel: TLabel;<br>MLabel: TLabel;<br>PLabel: TLabel;<br>SLabel: TLabel;<br>PValue: TLabel;<br>FValue: TLabel;<br>MValue: TLabel;<br>SValue: TLabel;<br>procedure GetButtonClick(Sender: TObject);<br>end;<br><br>var<br>DemoForm: TDemoForm;<br><br>implementation<br><br>{$R *.DFM}<br><br>const<br>ID_BIT = $200000; // EFLAGS ID bit<br>type<br>TCPUID = array[1..4] of Longint;<br>TVendor = array [0..11] of char;<br><br>function IsCPUID_Available : Boolean; register;<br>asm<br>PUSHFD {direct access to flags no possible, only via stack}<br>POP EAX {flags to EAX}<br>MOV EDX,EAX {save current flags}<br>XOR EAX,ID_BIT {not ID bit}<br>PUSH EAX {onto stack}<br>POPFD {from stack to flags, with not ID bit}<br>PUSHFD {back to stack}<br>POP EAX {get back to EAX}<br>XOR EAX,EDX {check if ID bit affected}<br>JZ @exit {no, CPUID not availavle}<br>MOV AL,True {Result=True}<br>@exit:<br>end;<br><br>function GetCPUID : TCPUID; assembler; register;<br>asm<br>PUSH EBX {Save affected register}<br>PUSH EDI<br>MOV EDI,EAX {@Resukt}<br>MOV EAX,1<br>DW $A20F {CPUID Command}<br>STOSD {CPUID[1]}<br>MOV EAX,EBX<br>STOSD {CPUID[2]}<br>MOV EAX,ECX<br>STOSD {CPUID[3]}<br>MOV EAX,EDX<br>STOSD {CPUID[4]}<br>POP EDI {Restore registers}<br>POP EBX<br>end;<br><br>function GetCPUVendor : TVendor; assembler; register;<br>asm<br>PUSH EBX {Save affected register}<br>PUSH EDI<br>MOV EDI,EAX {@Result (TVendor)}<br>MOV EAX,0<br>DW $A20F {CPUID Command}<br>MOV EAX,EBX<br>XCHG EBX,ECX {save ECX result}<br>MOV ECX,4<br>@1:<br>STOSB<br>SHR EAX,8<br>LOOP @1<br>MOV EAX,EDX<br>MOV ECX,4<br>@2:<br>STOSB<br>SHR EAX,8<br>LOOP @2<br>MOV EAX,EBX<br>MOV ECX,4<br>@3:<br>STOSB<br>SHR EAX,8<br>LOOP @3<br>POP EDI {Restore registers}<br>POP EBX<br>end;<br><br>procedure TDemoForm.GetButtonClick(Sender: TObject);<br>var<br>CPUID : TCPUID;<br>I : Integer;<br>S : TVendor;<br>begin<br> for I := Low(CPUID) to High(CPUID) do CPUID := -1;<br> if IsCPUID_Available then begin<br> CPUID := GetCPUID;<br> Label1.Caption := 'CPUID[1] = ' + IntToHex(CPUID[1],8);<br> Label2.Caption := 'CPUID[2] = ' + IntToHex(CPUID[2],8);<br> Label3.Caption := 'CPUID[3] = ' + IntToHex(CPUID[3],8);<br> Label4.Caption := 'CPUID[4] = ' + IntToHex(CPUID[4],8);<br> PValue.Caption := IntToStr(CPUID[1] shr 12 and 3);<br> FValue.Caption := IntToStr(CPUID[1] shr 8 and $f);<br> MValue.Caption := IntToStr(CPUID[1] shr 4 and $f);<br> SValue.Caption := IntToStr(CPUID[1] and $f);<br> S := GetCPUVendor;<br> Label5.Caption := 'Vendor: ' + S; end<br> else begin<br> Label5.Caption := 'CPUID not available';<br> end;<br>end;<br><br>end.