🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: ASM conversion from Delphi to C++Builder

#16
From: Jonathan Benedicto
Date: Fri, 20 Jul 2007 16:02
41 lines
2325 bytes
Malcolm Smith wrote:
> 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.

I'm no expert at ASM, but I'd guess that this would be the C++ translation:

struct TRegisters
{
 DWORD EAX;
 DWORD EBX;
 DWORD ECX;
 DWORD EDX;
};

void __fastcall GetCPUID( DWORD Param, TRegisters &Registers )
{
 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 0x0F, 0xA2                       /* CPUID opcode */
  MOV     [EDI], EAX       /* save EAX register */
  MOV     [EDI+4], EBX       /* save EBX register */
  MOV     [EDI+8], ECX       /* save ECX register */
  MOV     [EDI+12], EDX      /* save EDX register */
  POP     EDI                         /* restore registers */
  POP     EBX
 }
}

Worked for me at any rate.

Jon 
Technical Details
Message-ID: <46a0dcbb$1@newsgroups.borland.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!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: "Jonathan Benedicto" <invalid@nobody.com>
Newsgroups: borland.public.cppbuilder.language.basm
References: <46a047d3$1@newsgroups.borland.com>
In-Reply-To: <46a047d3$1@newsgroups.borland.com>
Subject: Re: ASM conversion from Delphi to C++Builder
Date: Fri, 20 Jul 2007 12:02:56 -0400
Lines: 42
MIME-Version: 1.0
Content-Type: text/plain;
 format=flowed;
 charset="iso-8859-1";
 reply-type=response
Content-Transfer-Encoding: 7bit
X-Priority: 3
X-MSMail-Priority: Normal
X-Newsreader: Microsoft Windows Mail 6.0.6000.16480
X-MimeOLE: Produced By Microsoft MimeOLE V6.0.6000.16480
NNTP-Posting-Host: 74.115.18.89
Message-ID: <46a0dcbb$1@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1184947387 74.115.18.89 (20 Jul 2007 09:03:07 -0700)
Path: arc1-ca.pugleaf.net!g2news1.google.com!news1.google.com!news.glorb.com!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail