Subject: Re: advice on some inline assembler code
To: None <>
From: Ian Dall <>
List: port-pc532
Date: 09/28/1998 12:53:22
Jon Buller <> writes:

  >> That's because you added _res to the list of input operands for your
  >> assembler pattern. You have to add it to the list of output operands.
  >> Try the following definition:
  >> static __inline__ int
  >> tas(volatile slock_t *lock)
  >> {
  >> register _res;
  >> __asm__("sbitb 0,%0; sfs %1" : "=m"(*lock), "r"(_res));
  >> return (int) _res;
  >> }
  >> "sfs" (Scondi, save condition as boolean) should store a "1" to _res
  >> when the flag bit is set due to the "sbitb" instruction.

  > Thanks again Matthias.  You missed one thing though, "r" needs to
  > be "=r".  I had tried something similar to that before, and the
  > error made me look at the VAX code, and that made me modify it to
  > the top piece of code rather than the bottom.  Is there anyplace
  > this is documented, so a mere mortal can figure out if they need
  > colons or commas seperating things, if the things should be "r",
  > "=r", "=m", "=g", etc.?

Well, I assume you have read the gcc info documentation. If not, look
under "C Extensions" and "Extended Asm". I find it is not too bad, although
you need to follow the constraints cross reference to find out what all
the letters mean.