|
From: <eg...@of...> - 2001-01-07 18:12:02
|
On Sun, Jan 07, 2001 at 12:11:32PM -0500, Soren Andersen wrote:
> I have a Perl module written by a fellow who has only built it using M$
> tools. It uses _asm{ stuff .. } and the gcc preprocessor chokes on it. I
> have taken a look at the manual for gcc and I don't think gcc supports this,
> but does support certain uses of `asm'.
You do not want to do this!! You would do much better to eliminate the need
for inline assembler. The resulting code will be more portable, more
maintainable, and more legible. The example you posted looks like some kind
of icky hack; can you do without it?
If you absolutely can't do without inline assembler, continue:
GCC's inline assembly feature is pretty unique, and very different from that
found in MSC and most other compilers. I presume you were looking here:
http://gcc.gnu.org/onlinedocs/gcc_5.html#SEC100
The contents of the "_asm { ... }" directive under MSC are inline assembler
code which are copied directly to the output. If you understand what the
assembler code is doing, you should be able to replace it with equivalent
gcc asm(...) directives with the appropriate operands. For example, starting
with the code you cited:
> LPBYTE self;
> _asm {
> pop eax
> mov dword ptr self, eax
> }
The GCC equivalent would probably be something like this:
BYTE *self;
asm("pop %0" : "=r" (self));
There are several changes here. First of all, as someone else noted, the
assembler is using AT&T syntax instead of Intel syntax. ("movl" instead
of "mov dword ptr", opposite order of many operands, etc.) More importantly,
the gcc asm directive requires you to explicitly list the outputs, inputs
and clobbers of an assembler section, which allows the optimizer to do a
much better job. As a result, we were able to eliminate the use of eax as
a temporary here.
But...
WARNING -- that sample really is bizarre -- it just pops something off the
stack. They're making assumptions about the calling conventions in use.
Do you really know what's going on here? (I know I don't.) If you try to
just substitute the GCC asm() directive for the MSC asm{} directive, you
will probably not have much luck.
Dan
|