delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1997/08/01/03:00:38

From: sarmis AT starnets DOT ro
Message-ID: <33E18968.602B@starnets.ro>
Date: Fri, 01 Aug 1997 09:59:52 +0300
MIME-Version: 1.0
To: djgpp AT delorie DOT com
Subject: Inline Assembler

Hello from Romania again !!!

  I have a real problem with the gcc's inline assembler.

  I'm trying to develop a GRAPHICS library (for VESA modes) and the GCC
does things I don't understand. (You'd better look below).

int video_address;
int color;

void bar(int x, int y, int w, int h)
{
  if (h == 0 || w == 0) return;
  __asm__ __volatile__(
  "
  __oneline_bar__:
    movl %0, %%ecx
    shr $2, %%ecx
    jecxz __no_long_bar__
    rep
    stosl
  __no_long_bar__:
    movl %0, %%ecx
    andl $3, %%ecx
    jecxz __no_bytes_bar__
    rep
    stosb
  __no_bytes_bar__:
    addl $640, %%edi
    subl %0, %%edi
    subl $1, %1
    jnc __oneline_bar__
  "
  :
  :"D"(video_address + 640 * y + x), "a"(color), "r"(w), "r"(h)
  :"%edi", "%ecx"
  );
}

That was what I wrote, and look what GCC created (I ran it with -S -s
-m486 -O3, but it does the same thing no metter what parametrs I give
him, and even if I replace "r"(w) with "q"(w) and "r"(h) with "q"(h))


	.file	"rect.cc"
gcc2_compiled.:
___gnu_compiled_cplusplus:
.text
	.align 4
.globl _bar__Fiiii
_bar__Fiiii:
	pushl %ebp
	movl %esp,%ebp
	subl $4,%esp
	pushl %edi
	pushl %esi
	pushl %ebx
	movl 12(%ebp),%ecx
	movl 16(%ebp),%ebx
	movl 20(%ebp),%edx
	testl %edx,%edx
	je L5
	testl %ebx,%ebx
	je L5
	leal (%ecx,%ecx,4),%ecx
	movl %ecx,%eax
	sall $7,%eax
	addl _video_address,%eax
	movl %eax,%esi
	addl 8(%ebp),%esi
	movl %esi,%edi
	movl _color,%eax
/APP
	
  __oneline_bar__:
    movl %edi, %ecx
    shr $2, %ecx
    jecxz __no_long_bar__
    rep
    stosl
  __no_long_bar__:
    movl %edi, %ecx
    andl $3, %ecx
    jecxz __no_bytes_bar__
    rep
    stosb
  __no_bytes_bar__:
    addl $640, %edi
    subl %edi, %edi                             ;   Why does the GCC
replace %0 with %edi ?
    subl $1, %eax
    jnc __oneline_bar__
  
/NO_APP
L5:
	leal -16(%ebp),%esp
	popl %ebx
	popl %esi
	popl %edi
	movl %ebp,%esp
	popl %ebp
	ret
.globl _video_address
.data
	.align 2
_video_address:
	.space 4
.globl _color
	.align 2
_color:
	.space 4


    Thanks a lot for bothering.

Eduard.

- Raw text -


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