Inline asm (x86): How to use offsettable addresses?
Frank Heckenbach
f.heckenbach@fh-soft.de
Sat Apr 30 10:39:00 GMT 2011
Ian Lance Taylor <iant@google.com> wrote:
> Frank Heckenbach <f.heckenbach@fh-soft.de> writes:
>
> >> If you want to add an offset, then you should either do it in the value
> >> passed to the asm,
> >
> > When possble that's easier, of course. In my case, however, I need
> > different (constant) offsets within the asm block.
>
> Pass each constant offset you need as a different operand to the asm.
For certain reasons, that would be somewhat cumbersome in my case.
> >> The 'o'
> >> constraint tells gcc that it can use a small offset in the address that
> >> it passes into the asm.
> >
> > Alright. But I thought (and still think ;-) that if gcc can add a
> > small offset, I should be able to add another one, since the sum of
> > two small offsets is still a small offset. (And it almost works,
> > except for this little syntactic issue whether or not to put a "+".)
>
> Let me put it this way, then; the 'o' constraint is designed for gcc
> internal use. It is not designed for the use to which you want to put
> it. What you are looking for is reasonable, but the 'o' constraint does
> not provide it.
OK, I see. I'd suggest then to reword the documentation, or perhaps
remove "o" constraint completely from the inline asm section to
avoid misleading users. If I hadn't seen it, I might have written my
code differently from the start when it would have been easier than
changing it now.
> > So I suppose, I'll keep my current work-around ("forcing" an offset
> > and always using "+") until it breaks. At least, it will give a
> > compile-time error when it fails, and not silently produce wrong
> > code. (At least I don't see a way how it could result it wrong code,
> > or do you?)
>
> I think it should always either work or give an assembly-time error,
> yes.
OK. If it ever breaks, I think I'll move the problematic code to an
external asm file. (In fact, the only reason I haven't done so yet
is so I don't have to worry about calling conventions and can let
gcc check the interface.)
Thanks for your help.
Regards,
Frank
--
Dipl.-Math. Frank Heckenbach <f.heckenbach@fh-soft.de>
Systemprogrammierung, EDV-Beratung
Stubenlohstr. 6, 91052 Erlangen, Deutschland
Tel.: +49-9131-21359
More information about the Gcc-help
mailing list