Thread View: comp.lang.pascal.borland
9 messages
9 total messages
Started by Robert AH Prins
Fri, 23 Jul 1999 00:00
BASM - Type to binary
Author: Robert AH Prins
Date: Fri, 23 Jul 1999 00:00
Date: Fri, 23 Jul 1999 00:00
22 lines
1518 bytes
1518 bytes
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...) Thanks, Robert -- Robert AH Prins prinsra@willis.com Sent via Deja.com http://www.deja.com/ Share what you know. Learn what you don't.
Re: BASM - Type to binary
Author: Raimo Suonio
Date: Sat, 24 Jul 1999 00:00
Date: Sat, 24 Jul 1999 00:00
33 lines
1866 bytes
1866 bytes
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. 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. If the element size had not been a power of two, the code would have been a little more complex. -- Raimo Suonio raimo.suonio@qdlc.fi (remove spam preventing q)
Re: BASM - Type to binary
Author: Pedt Scragg
Date: Sat, 24 Jul 1999 00:00
Date: Sat, 24 Jul 1999 00:00
32 lines
2131 bytes
2131 bytes
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 : 1. In your startup program code get the SizeOf the data element into a global variable and, if being used for shifts, convert to the relevant power of two. You can just load this into CL for your shifts - as SHL <register>, CL 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 HTH -- Pedt Veni; Vidi; Visa ... I came, I saw, I did a little shopping
Re: BASM - Type to binary
Author: Robert AH Prins
Date: Sat, 24 Jul 1999 00:00
Date: Sat, 24 Jul 1999 00:00
119 lines
4253 bytes
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.
Re: BASM - Type to binary
Author: Robert AH Prins
Date: Sat, 24 Jul 1999 00:00
Date: Sat, 24 Jul 1999 00:00
119 lines
4253 bytes
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.
Re: BASM - Type to binary
Author: Dr John Stockton
Date: Sat, 24 Jul 1999 00:00
Date: Sat, 24 Jul 1999 00:00
42 lines
2569 bytes
2569 bytes
JRS: In article <7naolk$5j$1@nnrp1.deja.com> of Fri, 23 Jul 1999
22:00:23 in news:comp.lang.pascal.borland, Robert AH Prins
<prinsra@williscorroon.com> wrote:
>
>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 know enough (any) BASM - however :
You _want_ to arrange that the shift count will automatically be
correct, for the *easy* subsequent avoidance of error.
If that cannot be contrived, it *may* be possible to define the log as a
source-code constant, and arrange that assembly fails if the constant is
incorrect, thereby giving *reliable* avoidance of error, which will
suffice. I've done this in Pascal/Delphi. Perhaps you can use not a
log2 but a pow2, with some equivalent of
const A = <log2?> ;
B = 1 shl A ;
then C = 1 div (Size-B) ;
or type Ar = array [B..Size, Size..B] of byte ;
Or, maybe, some equivalent of
const X = SizeOf(SizedType) ;
A = <log2?> ;
...
if X shr A <> 1 then HALT(234) ;
so that, if wrong, the program will fail immediately on test with a
specific message.
Note : you crossposted between "publicly" and "privately" owned
newsgroups. I *think* that this reply will go only to public servers,
and be missed by TeamB.
--
� John Stockton, Surrey, UK. jrs@merlyn.demon.co.uk Turnpike v4.00 MIME. �
Web <URL: http://www.merlyn.demon.co.uk/> - w. FAQish topics, links, acronyms
Dates - miscdate.htm Year 2000 - date2000.htm Critical Dates - critdate.htm
Y2k for beginners - year2000.txt UK mini-FAQ - y2k-mfaq.txt Don't Mail News
Re: BASM - Type to binary
Author: Matthias B�chse
Date: Sat, 24 Jul 1999 00:00
Date: Sat, 24 Jul 1999 00:00
6 lines
1091 bytes
1091 bytes
> rep movsd { Correct, I'm using a patched compiler! }
Wanna have too ...
--
Contact me at: Matthias.Buechse@T-Online.de
Homepage (German only): http://home.t-online.de/home/Matthias.Buechse/
Re: BASM - Type to binary
Author: 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.
Re: BASM - Type to binary
Author: Raimo Suonio
Date: Sun, 25 Jul 1999 00:00
Date: Sun, 25 Jul 1999 00:00
48 lines
2566 bytes
2566 bytes
Robert AH Prins wrote in message <7nchk7$8rt$1@nnrp1.deja.com>... >In article <7nb22t$p4o$1@tron.sci.fi>, > "Raimo Suonio" <raimo.suonio@qdlc.fi> wrote: >> >> 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) Oh, my apologies! I don't have any profile about you. I really didn't understand the structure of your question, but it was due to me having not english as my native language. I understand it now after the answer of Pedt Scragg. Taking that into account, you wrote that it took ages to find the correction needed after you changed the element size, and that led me to the conclusion that you had got the code from someone else and did not know it thoroughly. >> 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. Hey, you don't have to be that nasty. I just tried to be helpful according to the premisses I had. -- Raimo Suonio raimo.suonio@qdlc.fi (remove spam preventing q)
Thread Navigation
This is a paginated view of messages in the thread with full content displayed inline.
Messages are displayed in chronological order, with the original post highlighted in green.
Use pagination controls to navigate through all messages in large threads.
Back to All Threads