Mail Archives: djgpp/2000/03/24/13:34:33
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 -