www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/03/22/13:29:22

Xref: news2.mv.net comp.os.msdos.djgpp:2059
From: korpela AT islay DOT ssl DOT berkeley DOT edu (Eric J. Korpela)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Is this ASM ok?
Date: 22 Mar 1996 00:25:25 GMT
Organization: Cal Berkeley-- Space Sciences Lab
Lines: 51
Message-ID: <4iss1l$a50@agate.berkeley.edu>
References: <3150B8B2 DOT 8B2 AT jeffnet DOT org>
NNTP-Posting-Host: islay.ssl.berkeley.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <3150B8B2 DOT 8B2 AT jeffnet DOT org>, Chris Dial  <cdial AT jeffnet DOT org> wrote:
> asm(
>  "cld
>  movl _tscreen,%edi      /* Put tscreen into edi */
>  movl _tcol1,%edx        /* Put tcol into edx */
>  movl _tcolstep,%ebx     /* Put tcolstep into ebx */
>  movl _tlength,%ecx      /* Put length into ecx */
>  loopf:
>  movb %dh,%al            /* Put color into eax */
>  addl %ebx,%edx           /* Add colstep to col */
>  stosb
>  decl %ecx
>  jnz loopf"              /* If ecx not zero goto loop */
>  );

I would make a couple of other changes.  First, if this code could be used
in multiple places (i.e. it is in an inline function, or you have
it in several functions) I'd use local labels.

I'd also let the compiler know which registers have been changed, so
it can preserve values that it needs to.

I also prefer to let the compiler do the variable loading rather than doing
it myself.  So my version of the above would look like this....

 
asm(
 "cld
 0:
 movb %%dh,%%al       /* Put color into eax */
 addl %2,%1           /* Add colstep to col */
 stosb
 decl %3
 jnz 0b"              /* If ecx not zero goto loop */
 : /* No outputs */
 : "D" (tscreen), "d" (tcol1), "b" (tcolstep), "c" (tlength)
 : "eax"
 );

My guess is that this will generate code very similar to your version
with the addition of a pushl %edi at the beginning and a popl %edi at
the end.  

Another option is to replace the "decl %3;jnz 0b" with a "loop 0b"
instruction.  I'm not sure about the relative execution times of
each.
-- 
Eric Korpela                        |  An object at rest can never be
korpela AT ssl DOT berkeley DOT edu            |  stopped.
<a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
Click here for more info.</a>

- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019