www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/03/22/01:20:38

Xref: news2.mv.net comp.os.msdos.djgpp:2038
From: brennan AT mack DOT rt66 DOT com (Brennan "Mr. Wacko" Underwood)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Is this ASM ok?
Date: 21 Mar 1996 14:29:52 -0700
Organization: None, eh?
Lines: 53
Message-ID: <4ishog$obf@mack.rt66.com>
References: <3150B8B2 DOT 8B2 AT jeffnet DOT org>
NNTP-Posting-Host: mack.rt66.com
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:
>Hi, I am pretty new to DJGPP and I have 2 questions about the below ASM 
>code. #1: The below code compiles fine under DJGPP 2.0 when I use -O2 on 
>the commandline, but if I use -O3 then GAS tells me that stosb is an 
>unrecognized instruction. #2: I heard that you are supposed to tell 
>DJGPP which registers you are messing with, how do I do this?
> 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 */
>  );

Problem: _tscreen refers to what tscreen points to, not the pointer value
of tscreen. $_tscreen is just the pointer val.
Looks like you're interpolating a color val with 8.8 fixed point. I
assume tcolstep is already in 8.8.
Here's how I would write this (notice that the register loads can be handled
by GCC):
asm(
  "loopf:\n\t"
  "movb %%dh, (%%edi)\n\t"	/* write integer portion of color - U1 */
  "addl %%ebx, %%edx\n\t"       /* Add colstep to col             - V1 */
  "incl %%edi\n\t"		/* increment edi                  - U2 */
  "decl %ecx\n\t"		/* decrement count                - V2 */
  "jnz loopf"     	        /* If ecx not zero goto loop      - U3 */
  : : "D" (tscreen), "d" (tcol1), "b" (tcolstep), "c" (tlength)/*loaded regs*/
  : "%edi", "%ebx", "%ecx", "%edx"); /* clobbered regs */

1. stosb is slower than the equivalent instructions (unless it's rep'ed), so
I broke it out. This code will write 1 pixel every 3 cycles on a Pentium.
1 pixel every 8 cycles on a 486.

2. If I hadn't done GCC register loading, I would have had to do something
like "movl $_tscreen, %%edi"

3. The \n\t's are to make the listing look OK if you do a -S (compile to
assembly).

4. You could jam a 1-cycle instruction into the code before the jnz
for free (on a Pentium, and if it didn't change the flags)


--brennan
-- 
brennan AT rt66 DOT com  |  http://www.rt66.com/~brennan/. Well, duh.

- Raw text -


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