www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/05/13/18:10:01

From: moskewicz AT MEM DOT po DOT com
Date: Mon, 13 May 1996 18:07:39 -0400
Message-Id: <9605132207.AA07512@mercury>
To: djgpp AT delorie DOT com
Subject: Re: Loading Selectors

	Corrected version of my earlier code to load selectors:
asm("
    movw %3, %%fs
    movw %4, %%gs
1:
    movl %%fs:(,%0,1),%%eax
    addl  $0x4, %0
    movl %%eax,%%gs:(,%1,1)
    addl  $0x4, %1
    decl %2
    jnz  1b
    "
    : // no outputs
    :"D"(gr_offset_offset),"S"(true_gr_offset),"c"(mode.WinSize*256)
     ,"m"(gr_selector),"m"(true_gr_selector)
    :"%eax","%ecx"
    );
	Here, since gcc doesn't touch fs and gs, I don't have to restore them,
and the "m" constraint forces gcc to use a memory fetch to load fg and
gs, rather than waste a register.

	Also, I have seen several people post asm like this:
{
	asm("movl %0,%%eax": :"g"(food):"%eax","%ebx"); //move food to eax
	asm("addl %eax, %ebx");	//add eax to ebx
}
	Besides the fact that one should be keeping things in one asm, isn't
this missing the point of constraints? This is my understanding of what
it should be:
{
	asm("addl %0,%%ebx": :"a"(food):"%ebx" ); //Or "r" if we don't care if
eax is used, or "m" if we don't need food again
}



Anyone care to clarify?
----
moskewicz AT mem DOT po DOT com


- Raw text -


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