function RDTSC: comp; var TimeStamp : record case byte of 1: (Whole: comp); 2: (Lo, Hi: LongInt); end; begin asm db $0F; db $31; {BASM doesn't support RDTSC} {Pentium RDTSC - Read Time Stamp Counter - instruction} {$ifdef Cpu386} mov [TimeStamp.Lo],eax // the low dword mov [TimeStamp.Hi],edx // the high dword {$else} db D32 mov word ptr TimeStamp.Lo,AX {mov [TimeStamp.Lo],eax - the low dword} db D32 mov word ptr TimeStamp.Hi,DX {mov [TimeStamp.Hi],edx - the high dword} {$endif} end; Result := TimeStamp.Whole; end;
type CompStr = string[25]; {Comps have up to 18 digits, plus commas, and sign}
function CompToStr(N: comp): CompStr; var Low3 : string[3]; N1 : extended; begin if N < 0 then Result := '-' + CompToStr(-N) else begin N1 := N / 1000; Str(Round(Frac(N1) * 1000), Low3); N := Int(N1); if N > 0 then begin while Length(Low3) < 3 do Low3 := '0' + Low3; Result := CompToStr(N) + ThousandSeparator + Low3; end else Result := Low3 end; end;
procedure TForm1.Button1Click(Sender: TObject); begin //showmessage(inttostr( Ticker)); memo1.Lines.Add(CompToStr(RDTSC)); end;