๐Ÿš€ go-pugleaf

RetroBBS NetNews Server

Inspired by RockSolid Light RIP Retro Guy

Article View: comp.lang.pascal.borland
Article #245

Re: BASM - Type to binary

#245
From: Robert AH Prins
Date: Sat, 24 Jul 1999 00:00
119 lines
4253 bytes
In article <7nb22t$p4o$1@tron.sci.fi>,
  "Raimo Suonio" <raimo.suonio@qdlc.fi> wrote:
> Robert AH Prins kirjoitti viestiss๏ฟฝ <7naolk$5j$1@nnrp1.deja.com>...
> >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 don't understand perfectly your question, I figure that you haven't
> written the assembler code for yourself.

Explain? If you follow this group, you may very well be aware that I am
very much in favour of using BASM, not so much to increase speed, but
far more to reduce the size of the code, TP6/BP7 aren't exactly very
strong in that area, especially if your working with arrays and
pointers (and arrays of pointers)

> Anyhow, it seems that the instruction is part of the code that
> calculates the memory address offset out of the array index.  It
> simply multiplied the index by 8 and now by 16.

Oh wow, what an insight!

> If the element size
> had not been a power of two, the code would have been a little more
> complex.

I'm stunned! NO, it would not have been more complex, because the
compiler would have emitted a multiply. For speed reasons, less
important nowadays, I always make the size of small structures that are
to be put in arrays a power of two.

Anyway here is an excerpt of the code:

procedure print_in_ride_waits;
begin
  write_anyline(irw_topl);
  write_anyline(irw_sep);

  asm
    mov   ax, 1
  @1:
    push  ax
    mov   di, offset irwait
    shl   ax, 4 {<- size or irwait has gone from 8 to 16}
{
Had this been a "TYPE irwait", I would have had no problems and
the code would have continued to function. Of course a "type"
combined with a MUL would also have been OK, and on P2+, the time
difference may not make a lot of difference, but it would be very
nice if there is a way to translate type into log-2 type.
}

    add   di, ax

    cmp   word ptr [di], 0
    je    @2

    db    $66; mov   word ptr _line, $2012; dw    " |"

    mov   dx, ds
    mov   es, dx

    mov   si, ax
    mov   di, offset _line[4]
    shr   si, 33   { Think about this one... }
    mov   cx, type a_irw_desc / 4
    add   si, ax
    add   si, offset irw_desc
    cld
    rep   movsd    { Correct, I'm using a patched compiler! }

    db    $66; mov   word ptr _line[16], "| "; dw    "  "

    mov   di, offset irwait
    add   di, ax
    db    $66; mov   ax, [di + 2]
    db    $66; add   word ptr irwait + 2, ax
    db    $66; push  ax
    push  4

    mov   ax, [di]
    add   word ptr irwait, ax
    push  ax

    call  add_integer_2_line4
    call  time_2_line
    call  write_line
  @2:
    pop   ax
    inc   ax
    cmp   ax, _irw
    jle   @1
  end;
.
.
.

Robert
--
Robert AH Prins
prinsra@willis.com


Sent via Deja.com http://www.deja.com/
Share what you know. Learn what you don't.
Technical Details
Message-ID: <7nchk7$8rt$1@nnrp1.deja.com>
Path: arc1-ca.pugleaf.net!unknown!not-for-mail
References: <7naolk$5j$1@nnrp1.deja.com> <7nb22t$p4o$1@tron.sci.fi>

Show Full Headers
Complete Article Headers
X-Google-Language: ENGLISH,ASCII
X-Google-Thread: 108ebd,1574494622d1a1c7
X-Google-Attributes: gid108ebd,public
X-Google-Thread: 111659,1574494622d1a1c7
X-Google-Attributes: gid111659,public
From: Robert AH Prins <prinsra@williscorroon.com>
Subject: Re: BASM - Type to binary
Date: 1999/07/24
Message-ID: <7nchk7$8rt$1@nnrp1.deja.com>
X-Deja-AN: 504741674
References: <7naolk$5j$1@nnrp1.deja.com> <7nb22t$p4o$1@tron.sci.fi>
X-Http-User-Agent: Mozilla/4.05 [en] (WinNT; I)
X-Http-Proxy: 1.0 x39.deja.com:80 (Squid/1.1.22) for client 193.130.234.1
Organization: Deja.com - Share what you know. Learn what you don't.
X-Article-Creation-Date: Sat Jul 24 14:12:28 1999 GMT
X-MyDeja-Info: XMYDJUIDprino
Newsgroups: comp.lang.pascal.borland,borland.public.turbopascal