🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: ASM conversion from Delphi to C++Builder

#17
From: Malcolm Smith
Date: Sat, 21 Jul 2007 11:33
105 lines
3626 bytes
Your translations is what I had, but it always failed to compile, like this:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRegisters Registers;

asm
 {
  PUSH    EBX
  PUSH    EDI
  MOV     EDI, Registers
  XOR     EBX, EBX
  XOR     ECX, ECX
  XOR     EDX, EDX
  DB 0x0F, 0xA2
  MOV     [EDI], EAX
  MOV     [EDI+4], EBX
  MOV     [EDI+8], ECX
  MOV     [EDI+12], EDX
  POP     EDI
  POP     EBX
 }
}

When I moved the code to another function (like you did), it compiled.

What's the difference between the above and this:

void __fastcall TForm1::Button1Click(TObject *Sender)
{
TRegisters Registers;
GetCPUID( 0, Registers );
}

void __fastcall TForm1::GetCPUID(DWORD Param, TRegisters &Registers)
{
asm
 {
  PUSH    EBX
  PUSH    EDI
  MOV     EDI, Registers
  XOR     EBX, EBX
  XOR     ECX, ECX
  XOR     EDX, EDX
  DB 0x0F, 0xA2
  MOV     [EDI], EAX
  MOV     [EDI+4], EBX
  MOV     [EDI+8], ECX
  MOV     [EDI+12], EDX
  POP     EDI
  POP     EBX
 }
}

and why do I need to pass the DWORD Param (it would not compile without it).

-- 
Malcolm Smith



"Jonathan Benedicto" <invalid@nobody.com> wrote in message 
news:46a0dcbb$1@newsgroups.borland.com...
> 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: <46a1ef22@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> <46a0dcbb$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
Reply-To: "Malcolm Smith" <mjfreelancing@optusnet.com.au>
From: "Malcolm Smith" <mjfreelancing@optusnet.com.au>
Newsgroups: borland.public.cppbuilder.language.basm
References: <46a047d3$1@newsgroups.borland.com> <46a0dcbb$1@newsgroups.borland.com>
Subject: Re: ASM conversion from Delphi to C++Builder
Date: Sat, 21 Jul 2007 21:33:26 +1000
Lines: 107
Organization: MJ Freelancing
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: 58.107.74.229
Message-ID: <46a1ef22@newsgroups.borland.com>
X-Trace: newsgroups.borland.com 1185017634 58.107.74.229 (21 Jul 2007 04:33:54 -0700)
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