🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: ASM conversion from Delphi to C++Builder

#23
From: Bob Gonder
Date: Sun, 22 Jul 2007 13:22
55 lines
2313 bytes
Ed Mulroy [TeamB] wrote:

>Either of these should be close.  I say 'close' because I have not tested 

Definately untested <G>

I would also be tempted to turn off stack frames for this function.

>void __fastcall GetCPUID_1(unsigned int cmd, TRegisters & regs)
>  {
>  _EBX = _ECX = _EDX = 0;

Premature clearing of passed variables.
_fastcall Order( EAX, EDX, ECX, SP[4], SP[8].... )

>  _EDI = reinterpret_cast<unsigned long>(& regs);

	_EDI = _EDX
EDI and EBX not preserved as required
(unless compiler is doing hidden magic)

>  _EAX = cmd;

	NOP, cmd is passed in eax

>  __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; */

Same issues, plus new one:
Where did esi come from?

>    db 0FH, 0A2H /* opcode for GetCpuId */
>    }
>
>  regs.EDX = _EDX;

Does the compiler "know" that you trounced edx (regs)?

>  regs.ECX = _ECX;
>  regs.EBX = _EBX;
>  regs.EAX = _EAX;
>  }
Technical Details
Message-ID: <37l6a3dnmrn3m9blstu4dqvmmjah97nbif@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
References: <46a047d3$1@newsgroups.borland.com> <46a3542c$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: Bob Gonder <notbg@notmindspring.invalid>
Newsgroups: borland.public.cppbuilder.language.basm
Subject: Re: ASM conversion from Delphi to C++Builder
Date: Sun, 22 Jul 2007 06:22:27 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <37l6a3dnmrn3m9blstu4dqvmmjah97nbif@4ax.com>
References: <46a047d3$1@newsgroups.borland.com> <46a3542c$1@newsgroups.borland.com>
X-Newsreader: Forte Agent 1.93/32.576 English (American)
MIME-Version: 1.0
Content-Type: text/plain; charset=us-ascii
Content-Transfer-Encoding: 7bit
NNTP-Posting-Host: 69.69.85.190
X-Trace: newsgroups.borland.com 1185110546 69.69.85.190 (22 Jul 2007 06:22:26 -0700)
Lines: 57
Path: arc1-ca.pugleaf.net!g2news1.google.com!news2.google.com!news1.google.com!border1.nntp.dca.giganews.com!border2.nntp.dca.giganews.com!nntp.giganews.com!newspeer1.nwr.nac.net!newsfeeds.ihug.co.nz!ihug.co.nz!newsgroups.borland.com!not-for-mail
X-Original-Bytes: 2152