www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/01/22/21:07:12

Xref: news-dnh.mv.net comp.os.msdos.djgpp:4612
From: korpela AT islay DOT ssl DOT berkeley DOT edu (Eric J. Korpela)
Newsgroups: comp.os.msdos.djgpp
Subject: Re: keyboard/int-handlers
Date: 22 Jan 1996 22:01:52 GMT
Organization: Cal Berkeley-- Space Sciences Lab
Lines: 62
Message-ID: <4e11gg$kbi@agate.berkeley.edu>
References: <960121002501_100662 DOT 3563_EHV52-1 AT compuserve DOT com>
NNTP-Posting-Host: islay.ssl.berkeley.edu
To: djgpp AT delorie DOT com
DJ-Gateway: from newsgroup comp.os.msdos.djgpp

In article <960121002501_100662 DOT 3563_EHV52-1 AT compuserve DOT com>,
Fulco Bohle  <100662 DOT 3563 AT compuserve DOT com> wrote:
>Hello DJ,
>
>Sorry to disturb you again !


>3) Can I reference C-variables in inline assembler ? (maybe a stupid question)	
>	example( )
>		{
>		short int	the_ax_register;
>		..
>		__asm__ __volatile__ (mov	ax, the_ax_register);
>		..
>		}

Since I grew up in the borland world, I've gotten used to the borland
register variable convention where one can access the variables directly
by name. (_AX,_BX......)  So I define local register variables for the
necessary registers.  Your example reduces to...

example() {
  register unsigned short _AX __asm__("%ax");
  short int the_ax_register;
  ..
  the_ax_register=_AX;
  ..
}

You can set up register values before entering your assembly
code and then use the output values directly.....

inline unsigned int fast_zero_extendw(unsigned short x) {
  register unsigned _EDX __asm__("%edx");
  register unsigned short _DX __asm__("%dx");
  _EDX=0;             /* Should assemble to xorl %edx,%edx */
  _DX=x;              /* Should assemble as movw _x, %dx */
  return _EDX;
}

The extended assembly for the above probably looks something like this:

inline unsigned int fast_zero_extendw(unsigned short x) {
  register unsigned result;
  asm("xorl %0,%0
       movw %1,%0"
            : "=r" (result) : "g" (x));
  return result;    
}

The advantage of the extended assembly version is that GCC gets to pick
out which register to use.  The advantage of the first is that the optimizer
has more to play with.

Eric

Eric
-- 
Eric Korpela                        |  An object at rest can never be
korpela AT ssl DOT berkeley DOT edu            |  stopped.
<a href="http://www.cs.indiana.edu/finger/mofo.ssl.berkeley.edu/korpela/w">
Click here for more info.</a>

- Raw text -


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