[gnu.gcc.bug] <<Not a bug?>> I don't understand gcc's `asm' statements...

pardo@JUNE.CS.WASHINGTON.EDU (07/14/89)

I'm trying to generate inline `asm' for the i386 Sequent.  Configured
using the configuration script, gcc version 1.34.  I'm getting
messages from the compiler that tell me that I'm doing something
wrong, but I certainly don't know what it is.

If somebody can help me, I'd appreciate it a lot.  Also, I've included
some comments on gcc.texinfo.  I hope that they are useful.


Here is a concatenation of the important data structures and code:

----------------------------------------------------------------------
typedef char lock_t;		/* A byte or so. */
typedef void *data_t;		/* A generic pointer. */

typedef struct buf_t {		/* Some random bits. */
    struct buf_t *next;
    union {
	data_t *last;
	u_int size;
    } u;
    pid_t pid;
    data_t data[1];		/* VARSIZE */
} buf_t;

typedef struct buf_list_t {
    buf_t *tail;		/* Just a struct pointer. */
    lock_t lock;
} buf_list_t;

buf_list_t freelist;

    void
init (buf_t *mtbuf)
{
    mtbuf->next = NULL;
    asm ( "movl %2,%ecx;xchgl %ecx,%0"
        : "=g" (freelist.tail)
        : "0" (freelist.tail)
        , "g" (mtbuf)
        );			/* <= LINE 168 */
    /* More stuff. */
}
----------------------------------------------------------------------

When I try to compile:

gcc -g -Wall -I/u1/pardo/june/resch/trace/pardo/include -I/u1/pardo/june/resch/trace/ogre/include -c buf.c
buf.c: In function init:
buf.c:168: invalid `asm': invalid expression as operand
buf.c:168: invalid `asm': invalid expression as operand


Also, I really want to use register `ecx' across both (really, 3)
instructions, so I originally had a hard register specifier in the
asm:

    asm ( "movl %2,%ecx;xchgl %ecx,%0"
        : "=g" (freelist.tail)
        : "0" (freelist.tail)
        , "g" (mtbuf)
        : "%ecx"
        );			/* <= LINE 169 */

Gives me:
buf.c:169: unknown register name `%ecx' in `asm'

I also tried the form "ecx" instead of "%ecx", but I got the same
message.

----------------------------------------------------------------------

Some comments on the `Extended Asm' section of gcc.texinfo:

* The manual says that the instruction template must be ``much like
  what appears in a machine description [...]''.  It appears that the
  operands *must* be parenthesized.  In my opionion, this should be
  documented, or there should be a cross reference to the part of the
  info document that explains this.

* The `Extended Asm' section of `gcc.texinfo' says that a user must
  duplicate operands that are both read and write, e.g.,:

	"=f" (x) : "0" (x)

  while the `Modifiers' section (under `Constraints in the machine
  description') says that it is possible to use "+" for read-write
  operands.  Given the statement in `Extended Asm', ``much like what
  appears in the machine description'', I wonder if it is possible to
  use a constraint string of "+" instead?

Thanks for your help!

	;-D on  ( Hard register, soft brain )  Pardo