🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: borland.public.cppbuilder.language.basm
Article #21

Re: ASM conversion from Delphi to C++Builder

#21
From: Ed Mulroy [TeamB]
Date: Sun, 22 Jul 2007 12:57
83 lines
3335 bytes
Either of these should be close.  I say 'close' because I have not tested 
them.  As is the case with many if not most PCs my computer has the CPUID 
command blocked for security purposes.

.  Ed

-------------------------------------
#pragma pack(push, 1) /* struct packed on byte boundaries */
struct TRegisters
  {
  unsigned int EAX;
  unsigned int EBX;
  unsigned int ECX;
  unsigned int EDX;
  };
#pragma pack(pop)

void __fastcall GetCPUID_1(unsigned int cmd, TRegisters & regs)
  {
  _EBX = _ECX = _EDX = 0;
  _EDI = reinterpret_cast<unsigned long>(& regs);
  _EAX = cmd;
  __emit__(0x0F, 0xA2); // insert opcode for GetCpuId
  regs.EDX = _EDX;
  regs.ECX = _ECX;
  regs.EBX = _EBX;
  regs.EAX = _EAX;
  }

void __fastcall GetCPUID_2(unsigned int cmd, TRegisters & regs)
  {
  __asm {
    xor edx,edx
    mov ebx,edx
    mov ecx,edx
    mov eax,[cmd]
    mov edi,esi /* _EDI = (unsigned long) & regs; */
    db 0FH, 0A2H /* opcode for GetCpuId */
    }

  regs.EDX = _EDX;
  regs.ECX = _ECX;
  regs.EBX = _EBX;
  regs.EAX = _EAX;
  }
-------------------------------------

.  Ed

> Malcolm Smith wrote in message
> news:46a047d3$1@newsgroups.borland.com...
>
> I'm trying to convert this PAS code into a C++ unit but I am not having 
> any luck with the ASM code - it won't compile as is (although the PAS file 
> does).
>
> Can someone please help with the ASM translation.  I know I could just use 
> the .PAS file but I want to learn something along the way.
>
>
> TRegisters = record
>  EAX,
>  EBX,
>  ECX,
>  EDX: Cardinal;
> end;
>
> procedure GetCPUID(Param: Cardinal; var Registers: TRegisters);
> asm
>  PUSH    EBX                         {save affected registers}
>  PUSH    EDI
>  MOV     EDI, Registers
>  XOR     EBX, EBX                    {clear EBX register}
>  XOR     ECX, ECX                    {clear ECX register}
>  XOR     EDX, EDX                    {clear EDX register}
>  DB $0F, $A2                         {CPUID opcode}
>  MOV     TRegisters(EDI).&EAX, EAX   {save EAX register}
>  MOV     TRegisters(EDI).&EBX, EBX   {save EBX register}
>  MOV     TRegisters(EDI).&ECX, ECX   {save ECX register}
>  MOV     TRegisters(EDI).&EDX, EDX   {save EDX register}
>  POP     EDI                         {restore registers}
>  POP     EBX
> end;
Technical Details
Message-ID: <46a3542c$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!62.111.101.3.MISMATCH!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <46a047d3$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 107b11,b95ef5f9173e844a
X-Google-Attributes: gid107b11,public,usenet
X-Google-Language: ENGLISH,ASCII-7-bit
From: "Ed Mulroy [TeamB]" <dont_email_me@bitbuc.ket>
Newsgroups: borland.public.cppbuilder.language.basm
References: <46a047d3$1@newsgroups.borland.com>
Subject: Re: ASM conversion from Delphi to C++Builder
Date: Sun, 22 Jul 2007 08:57:16 -0400
Lines: 85
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Outlook Express 6.00.2900.3138
X-MimeOLE: Produced By Microsoft MimeOLE V6.00.2900.3138
X-RFC2646: Format=Flowed; Response
NNTP-Posting-Host: 69.142.254.168
Message-ID: <46a3542c$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1185109036 69.142.254.168 (22 Jul 2007 05:57:16 -0700)
X-Authenticated-User: edmulroy
Path: arc1-ca.pugleaf.net!g2news1.google.com!news4.google.com!proxad.net!feeder1-2.proxad.net!62.111.101.3.MISMATCH!news.germany.com!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail