Article View: comp.lang.pascal.borland
Article #249Re: BASM - Type to binary
From: Dr John Stockton
Date: Sat, 24 Jul 1999 00:00
Date: Sat, 24 Jul 1999 00:00
54 lines
3311 bytes
3311 bytes
JRS: In article <12nBGCAEnUm3YwId@pedt.demon.co.uk> of Sat, 24 Jul 1999
06:06:12 in news:comp.lang.pascal.borland, Pedt Scragg
<newsmaster@pedt.demon.co.uk> wrote:
>Robert AH Prins <mailto:prinsra@williscorroon.com> said:
>
>>To avoid having to load pointers over and over again, the program uses a
>>GETMEM'ed array, I use BASM, and this works without a glitch, until...
>>I had to change the size of the elements from 8 to 16 and didn't realize
>>that I also needed to change a "shl cx, 3" into "shl cx, 4". I spend
>>ages trying to find out what was wrong - the equivalent code in Pascal
>>continued to work, be it rather more slowly.
>>
>>Does anyone know, short of what I've done now, adding a constant with
>>the required shift value, if there is a way to get the base-2 log of
>>sizes of datastructures in BASM. (Obviously restricted to sizes that are
>>powers of 2...)
>>
>I can only think of two easy ways to do it as you cannot use SizeOf in
>BASM :
>2. Declare two dummy global variables the same size as one data element
>immediately after each other and use BASM to get load the memory offset
>of each into variables then use SUB to get the memory size. You'll still
>need to SHL <register>, CL
If BASM allows "compile-time" access to offsets, then by declaring ONE
of the same size, then something, and subtracting the offsets, you get
the number you need to take the log2 of - though the original post
implied that you already have that number.
My pas-norm.htm#Bin says :
Counting bits in an ordinal : "J and Pred(J)" has one "1" bit fewer
than "J" does, for J<>0; so :
while J<>0 do begin
Inc(Count) ; J := J and Pred(J) end ;
Can you use that, somehow, unrolled, in BASM? Pseudo-code:
C := 0 ;
J := Size-1 (Relies on Size a power of 2; count its bits)
several of ( J := J and Pred(J) ; C := C + Ord(J<>0) ; )
would set C to log2(Size), give or take - and you can ensure that Size
is a power of two by checking that (Size and Pred(Size))=0.
I have a feeling that I've seen an assembler in which one could do that.
--
� John Stockton, Surrey, UK. jrs@merlyn.demon.co.uk Turnpike v4.00 MIME. �
Web <URL: http://www.merlyn.demon.co.uk/> TP/BP/D/&c. FAQqish topics & links.
Timo's TurboPascal <A HREF="ftp://garbo.uwasa.fi/pc/link/tsfaqp.zip">FAQ</A>.
<A HREF="http://www.merlyn.demon.co.uk/clpb-faq.txt">Mini-FAQ</A> of c.l.p.b.
Technical Details
Message-ID:
<9buBbaABWem3Ewzq@merlyn.demon.co.uk>Path:
arc1-ca.pugleaf.net!unknown!not-for-mailReferences:
<7naolk$5j$1@nnrp1.deja.com> <12nBGCAEnUm3YwId@pedt.demon.co.uk>Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII X-Google-Thread: 111659,1574494622d1a1c7 X-Google-Attributes: gid111659,public X-Google-Thread: 108ebd,1574494622d1a1c7 X-Google-Attributes: gid108ebd,public From: Dr John Stockton <jrs@merlyn.demon.co.uk> Subject: Re: BASM - Type to binary Date: 1999/07/24 Message-ID: <9buBbaABWem3Ewzq@merlyn.demon.co.uk> X-Deja-AN: 504869572 Content-Transfer-Encoding: 8bit X-NNTP-Posting-Host: merlyn.demon.co.uk:158.152.233.145 References: <7naolk$5j$1@nnrp1.deja.com> <12nBGCAEnUm3YwId@pedt.demon.co.uk> Content-Type: text/plain;charset=iso-8859-1 X-Complaints-To: abuse@demon.net X-Trace: news.demon.co.uk 932853753 nnrp-10:4890 NO-IDENT merlyn.demon.co.uk:158.152.233.145 Organization: Home, Surrey, UK MIME-Version: 1.0 Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal