www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1998/06/11/19:34:38

Sender: nate AT cartsys DOT com
Message-ID: <35806237.C2BEE6A0@cartsys.com>
Date: Thu, 11 Jun 1998 16:03:19 -0700
From: Nate Eldredge <nate AT cartsys DOT com>
MIME-Version: 1.0
To: Ian Chapman <ichapman AT mailcity DOT com>
CC: djgpp AT delorie DOT com, Xavi Cardona <xavicardona AT rocketmail DOT com>
Subject: Re: z80 to 386
References: <357D73EA DOT 73E0 AT rocketmail DOT com> <357FDA5C DOT A56E038A AT mailcity DOT com>

Ian Chapman wrote:
> 
> Hi Xavi,
>         I use
> 
>                 *** char asm[30] ={"movb whatever"}; ***
> 
> and it assembles  Regards Ian.

Huh??? The documentation says nothing like this, and I can't make it
work either.  I think the original poster wanted some instructions
assembled and placed in an array, and that doesn't do it.  If you really
have managed to do this, please post your exact code and GCC version.

> Xavi Cardona wrote:
> > 
> > Hi!
> > I'm working on a Z80 to 80386 machine code translator.
> > I make the following routine for putting the "movb $0x1,i" in the
> >  string variable, but it doesn't work. Gcc says "parse error before
> > asm".
> > As you see, I don't want to execute the movb instruccion. I just want to
> > store the machine code of this instruccion on an array.
> > main()
> > {int i=5;
> > char string[30]; /*more space than we really need*/
> > string=asm ("movb $0x1,%0"
> >         :"=g" (i)
> >         :"g" (i)     );
> > }
> > There is any easy :) way for doing this?
> > Thanks in advanced.

Well.... you could do something like this:

asm(".data \n\t"
    "_string: \n\t"
    "movb $0x1, %0 \n\t"
    ".text" : "=g" (i) : "0" (i)); /* note change here; read docs for
why it's needed */

But that would require that:

* It be outside all functions, or in a function that cannot be inlined.
* `i' be a global or static variable

This would also not be useful for an assembler (which is basically what
you are writing), because for any case other than a move of that exact
value to the exact location at which `i' happens to reside, the code
wouldn't work.
-- 

Nate Eldredge
nate AT cartsys DOT com


- Raw text -


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