This code executes a native hardware instruction on the x86 and x64 processors, CPUID
. That instruction cannot be accessed by native Pascal code, so you will need to drop into assembler. The code in your question does not work because it mixes Pascal and assembler, which is not allowed in the 64 bit compiler, and a really bad idea in the 32 bit compiler. So, the way forward is to code this as a pure assembler routine.
There are a great many examples around of how to do this. For instance, Rodrigo Ruz has this unit: https://github.com/RRUZ/vcl-styles-plugins/blob/master/Common/delphi-detours-library/CPUID.pas which contains exactly what you need.
It's not terribly difficult to roll your own. It might go like this:
{$APPTYPE CONSOLE}
uses
System.SysUtils;
type
TRegisters = record
EAX: UInt32;
EBX: UInt32;
ECX: UInt32;
EDX: UInt32;
end;
function GetCPUID(ID: Integer): TRegisters;
asm
{$IF Defined(CPUX86)}
push ebx
push edi
mov edi, edx
cpuid
mov [edi+$0], eax
mov [edi+$4], ebx
mov [edi+$8], ecx
mov [edi+$c], edx
pop edi
pop ebx
{$ELSEIF Defined(CPUX64)}
mov r8, rbx
mov r9, rcx
mov eax, edx
cpuid
mov [r9+$0], eax
mov [r9+$4], ebx
mov [r9+$8], ecx
mov [r9+$c], edx
mov rbx, r8
{$ELSE}
{$Message Fatal 'GetCPUID has not been implemented for this architecture.'}
{$IFEND}
end;
var
Registers: TRegisters;
begin
Registers := GetCPUID(1);
Writeln(IntToHex(Registers.EAX, 8) + '-' + IntToHex(Registers.EBX, 8) + '-' + IntToHex(Registers.ECX, 8) + '-' + IntToHex(Registers.EDX, 8));
Readln;
end.
You need to understand the calling conventions, how the parameters map to registers, which registers must be preserved, and so on.
With some websearch you will be able to find countless more examples. For example, there is a Stack Overflow post here (Porting Assembler x86 CPU ID code to AMD64) which is arguably a duplicate of this question.