www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/08/07/13:14:50

Message-Id: <199608071658.JAA08681@bluesky>
Comments: Authenticated sender is <kbaca AT bluesky>
From: "Kevin Baca" <kbaca AT bluesky DOT com>
To: dbarrett AT srvr1 DOT engin DOT umich DOT edu (David M Barrett), djgpp AT delorie DOT com
Date: Wed, 7 Aug 1996 10:01:27 +0000
MIME-Version: 1.0
Subject: Re: Accessing Variables in Inline ASM

> Ok, I'm starting to get the hang of inline ASM, but I just can't
> find a good reference on how to access variables via inline ASM. 
> I've heard that you must declare everything globally, but this can't
> be the best solution.  Does anyone know a better way, or a place
> where I could read up on the subject?  If I declare a variable
> within a function, how can I use that variable in my inline ASM
> routine?  If the function is recursive, how will that affect things?
>  Thanks!
> 
> -David :)

The following function adds 3 ints and returns the result.  You can
see how it accesses local variables.  The "rm" means the variable
could either be in a register or in memory.  Check out the info
section of gcc on inline assembly for more of this kind of stuff.

int add3(int i, int j, int k)
{
   int ret;

  __asm__("
           movl %1,%%eax
           addl %2,%%eax
           addl %3,%%eax"
           : "=a" ret
           : "rm" (i),"rm" (j),"rm" (k)
           : "eax");

   return ret;
}

-Kevin 

- Raw text -


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