delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/2000/03/24/13:34:33

From: buers AT gmx DOT de (Dieter Buerssner)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: Inline ASM
Date: 24 Mar 2000 16:22:49 GMT
Lines: 74
Message-ID: <8bg4on$4kibp$2@fu-berlin.de>
References: <38daf59d AT news DOT integrityonline DOT com> <38DAFAA7 DOT CC352387 AT mtu-net DOT ru>
NNTP-Posting-Host: pec-1-125.tnt1.s2.uunet.de (149.225.1.125)
Mime-Version: 1.0
X-Trace: fu-berlin.de 953914969 4868473 149.225.1.125 (16 [17104])
X-Posting-Agent: Hamster/1.3.13.0
User-Agent: Xnews/03.02.04
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp
Reply-To: djgpp AT delorie DOT com

Alexei A. Frounze wrote:

>Something like this:
>--------------8<------------------
>void putpixel (long x, long y, char color) {
>  if (VGAAddr)
>    *(VGAAddr+x+y2addr(y)) = color;
>  else {
>    __asm__ __volatile__ ("
>      pushw   %%es
>      movw    %3, %%ax
>      movw    %%ax, %%es
>      movl    %1, %%edi
>      shl     $6, %%edi
>      movl    %%edi, %%eax
>      shl     $2, %%eax
>      addl    %%eax, %%edi
>      addl    %0, %%edi
>      movb    %2, %%al
>      stosb
>      popw    %%es"
>      :
>      : "g" (x), "g" (y), "g" (color), "g" (VGA_sel)
>    );
>  };
>}

Alexei, have you tried this? It can't work in general, because
your inline assembly clobbers registers eax and edi, without
giving the compiler a chance to know this. I.e. when declaring

unsigned short VGA_sel;

and commenting everything besides the inline assembly,
the compiler w'ont generate code that saves edi accross the function
call...

Also, please compare your inline assembly with the code produced
by the following program, when compiling it with gcc -O -S.

#include <sys/farptr.h>

unsigned short VGA_sel;

void putpixel(long x, long y, char c)
{
  _farpokeb(VGA_sel,y*320+x,c);
}

Gcc assembler output: (Comments are mine)

_putpixel:
	pushl %ebp
	movl %esp,%ebp
	movl 12(%ebp),%eax        ; eax = y;
	movb 16(%ebp),%dl         ; dl = color
	leal (%eax,%eax,4),%eax   ; eax = 5*eax = 5*x
	sall $6,%eax              ; eax = 320*x 
	addl 8(%ebp),%eax         ; eax = 320*x + y; 
/APP
	movw _VGA_sel,%fs
	.byte 0x64                ; use fs selector for next
	movb %dl,(%eax)           ; movb %dl, fs:(%eax) does not always
                                ; work with some versions of gas
/NO_APP
	movl %ebp,%esp
	popl %ebp
	ret

This should be faster and less error prone.

Regards,
Dieter

- Raw text -


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