🚀 go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

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

Re: Better IntToStr? What do ya think

#8
From: Bob Gonder
Date: Tue, 19 Jun 2007 20:13
42 lines
2268 bytes
Colin B Maharaj wrote:

> I was wondering if this is faster and just as
>safe as IntToStr.

Ummm, No.
IntToStr returns a new AnsiString.
Your function relies on the user supplying a sufficiently large char
array so you don't accidentally overflow it.

It is, however, as safe as itoa.

>My little speed test says it is twice as fast
>as itoa and 3 time as fast as IntToStr,
>however itoa does hex and this does not!

Hex is even faster. Just write an itoh()

>Question is, do I need to be pushing any
>registers on the stack to save and restore
>on exit?

EAX
ECX
EDX
Those are the only "free" registers.
All others must be preserved.

>I think by wrapping it in a C function, I will
>not have to worry about enter/exit ASM code (?)

Compile it and look at the cpu view to see if the compiler added the
stackframe code.
I think if it were pure asm, no C code inside, you would want to take
care of things, but only if your code requires it.

I wonder if dividing by 100 instead of 10, and using AAM to get the 2
digit result would be any faster

So, you write to string in reverse order, then strrev()
Another way is to push the digits onto stack, then pop/store to
string.
Technical Details
Message-ID: <k9cg73tlrfbafr87n8ee6in36vutvjjcvb@4ax.com>
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder5.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail
References: <4677c279$1@newsgroups.borland.com>

Show Full Headers
Complete Article Headers
X-Google-Thread: 107b11,967a3c560bdbf1af
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: Better IntToStr? What do ya think
Date: Tue, 19 Jun 2007 13:13:41 -0700
Organization: MindSpring Enterprises, Inc.
Reply-To: notbg@notmindspring.invalid
Message-ID: <k9cg73tlrfbafr87n8ee6in36vutvjjcvb@4ax.com>
References: <4677c279$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: 67.77.145.161
X-Trace: newsgroups.borland.com 1182284021 67.77.145.161 (19 Jun 2007 13:13:41 -0700)
Lines: 44
Path: arc1-ca.pugleaf.net!g2news1.google.com!news3.google.com!feeder3.cambrium.nl!feeder5.cambrium.nl!feeder1.cambrium.nl!feed.tweaknews.nl!news2.euro.net!newsfeed.freenet.de!newsfeed00.sul.t-online.de!newsfeed01.sul.t-online.de!t-online.de!newsgroups.borland.com!not-for-mail