www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/07/04/22:07:27

Date: Fri, 5 Jul 1996 05:01:59 +0300 (EET DST)
From: Samuli Takala <tax AT cc DOT hut DOT fi>
To: "[vecna]" <vecna AT Walden DOT mo DOT net>
cc: djgpp AT delorie DOT com
Subject: Re: Setpixel in AT&T inline asm....
In-Reply-To: <4rh0g5$m9r@twain.mo.net>
Message-ID: <Pine.OSF.3.93.960705044000.1288B-100000@alpha.hut.fi>
MIME-Version: 1.0

On 4 Jul 1996, [vecna] wrote:
[snip]
> char *virscr;
> 
> This is my (yes, unoptimized) setpixel routine:
> 
> setpixel(int x, int y, char c)
> {
>   asm("pushl %eax \n\t"
>       "pushl %ebx \n\t"
>       "pushl %edi \n\t"
> 
>       "movzx $_y, %eax \n\t"
>       "imul $320, %eax \n\t"
>       "movzx $_x, %ebx \n\t"
>       "add %ebx, %eax \n\t"
>       "mov $_virscr, %ebx \n\t"
>       "add %ebx, %eax \n\t"
>       "mov %eax, %edi \n\t"
>       "movb $_c, %al \n\t"
>       "stosb \n\t"
> 
>       "popl %edi \n\t"
>       "popl %ebx \n\t"
>       "popl %eax \n\t");
> }
> 
> The immediate problem being, it can't recognize movzx. I can't think of any
> other alias this was be listed as... not to mention I'm really guessing here.

movzx is simply movz in at&t. Add the operator length suffix to that.

> get into extended ASM just yet). Also, could someone confirm or correct me
> that a char is a byte, an int is 16 bits? (or is it 32?) geez, what I wouldn't

char is a byte. int is 32 bits. short int is 16 bits.

You will also face the problem that DJGPP won't recognize your references
to the local variables x, y and c. They have to be used as in the example
below. I don't know if this is 'extended ASM', but it's the only way of
doing this that I know (or, you could write the setpixel completely in
assembler and put it in a .s file).
Your routine should look something
like this:
void setpixel(int x, int y, char c)
{
   /* Note TWO %% in front of registers! */
   asm ("
        movl   %1, %%eax      /* No need for movz, since int is 32 bits */
        imul    $320, %%eax
        addl   %0, %%eax      /* No need to move X through ebx */
        addl   _virscr, %%eax /* Global symbols can be used directly */
        movl   %%eax, %%edi
        movb   %2, %%al
        stosb
        "
        :   /* outputs would go here */
        :   /* inputs are here */
         "m" (x),    /* first field is referred to as %0 */
         "m" (y),    /* %1 */
         "m" (c)     /* %2 */
        : "eax","edi","cc"  /* we mess up eax, edi and flags */
        );

You don't need to push/pop registers, just tell gcc that you are
changing their values (after the third ':').

I prefer to put asm in one big "". That way you don't have to put any
funny things between commands. Just have to be careful with comments,
they can only be placed after complete command. If you only have
a label on a line, don't put comment there or the compiler will choke
on it. I think the same goes for rep*.


Samppa

Samuli Takala      Samuli DOT Takala AT hut DOT fi       Finger tax AT hut DOT fi for more info.
See my homepage for Formula One Shadow Series: http://www.hut.fi/~tax/
		  "Kuorma-auto - Hyödyksesi tiellä"

- Raw text -


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