public inbox for gcc-help@gcc.gnu.org
 help / color / mirror / Atom feed
* GNU C++ Inline Assembler
@ 2008-08-10 21:39 Robin-Vossen
  2008-08-11  6:37 ` Bob Plantz
  0 siblings, 1 reply; 10+ messages in thread
From: Robin-Vossen @ 2008-08-10 21:39 UTC (permalink / raw)
  To: gcc-help


Hello, 
is there a known way to use MSVC++ Style Inline Assembler in GCC code?
The main diffrence is that MSVC uses Intel Syntax. And GCC uses AT&T. I dont
like AT&T...
I wonder if there is a library or a function in GCC itself to compile the
following code segment: (MSVC can do this..)

int main ()
{
int INTEGER;
char CHARACTER;
INTEGER = 1;
__asm{ 
            mov eax, [INTEGER]
            inc eax, esp
            mov [INTEGER], eax
            mov [CHARACTER], ah
         }
return 0;
}

as you see I can use Pointers to variables. and use Intel Syntax.

Can this be done?
At this moment I run a Windows Version of GCC mainly.
And I hate MSVC, takes long to load and stuff. So I HOPE that I can do this
in GCC.
So I can remove MSVC soon.

Thanks,
Cheers,
Robin
-- 
View this message in context: http://www.nabble.com/GNU-C%2B%2B-Inline-Assembler-tp18912389p18912389.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-10 21:39 GNU C++ Inline Assembler Robin-Vossen
@ 2008-08-11  6:37 ` Bob Plantz
  2008-08-11 16:35   ` Robin-Vossen
  0 siblings, 1 reply; 10+ messages in thread
From: Bob Plantz @ 2008-08-11  6:37 UTC (permalink / raw)
  To: Robin-Vossen; +Cc: gcc-help

On Sun, 2008-08-10 at 04:11 -0700, Robin-Vossen wrote:

I'm not aware of any use of the inc instruction that takes two operands:

> __asm{ 
>             mov eax, [INTEGER]
>             inc eax, esp
>             mov [INTEGER], eax
>             mov [CHARACTER], ah
>          }
> return 0;
> }

so I don't completely understand your code.

Have you tried -masm=intel? I've only gone as far as seeing that it
generates intel-style asm from C/C++. I decided that it was better to
follow the "when in Rome..." rule.

The syntax issue seems arbitrary to me. I've used lots of assemblers.
They're all different.

For several years in the 1980s I had contracts with two companies that
used different chips. One assembler used source,destination and the
other destination,source. I would work with one in the morning, the
other in the afternoon. Just had to be careful.

Bob


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-11  6:37 ` Bob Plantz
@ 2008-08-11 16:35   ` Robin-Vossen
  2008-08-11 16:59     ` David Daney
  2008-08-11 21:24     ` Andrew Haley
  0 siblings, 2 replies; 10+ messages in thread
From: Robin-Vossen @ 2008-08-11 16:35 UTC (permalink / raw)
  To: gcc-help


Well, thanks:

But, I just want to use Intel-Style ASM in there. with dest, src setup.
Since I do quite a lot of Revercing and well I sometimes need to Copy
Directly from Olly/IDA into C Code.
Since that uses Intel I need the intel.
Also, Well as you saw I used Pointers to Variables in my C Code. I didnt
find a way to do that in GCC C Compiler.
I never heard of the -masm line. I am going to read up on that.

Thanks already, I hope I made my question a bit clearer now.

Cheers,
Robin


Bob Plantz wrote:
> 
> On Sun, 2008-08-10 at 04:11 -0700, Robin-Vossen wrote:
> 
> I'm not aware of any use of the inc instruction that takes two operands:
> 
>> __asm{ 
>>             mov eax, [INTEGER]
>>             inc eax, esp
>>             mov [INTEGER], eax
>>             mov [CHARACTER], ah
>>          }
>> return 0;
>> }
> 
> so I don't completely understand your code.
> 
> Have you tried -masm=intel? I've only gone as far as seeing that it
> generates intel-style asm from C/C++. I decided that it was better to
> follow the "when in Rome..." rule.
> 
> The syntax issue seems arbitrary to me. I've used lots of assemblers.
> They're all different.
> 
> For several years in the 1980s I had contracts with two companies that
> used different chips. One assembler used source,destination and the
> other destination,source. I would work with one in the morning, the
> other in the afternoon. Just had to be careful.
> 
> Bob
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/GNU-C%2B%2B-Inline-Assembler-tp18912389p18929255.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-11 16:35   ` Robin-Vossen
@ 2008-08-11 16:59     ` David Daney
  2008-08-11 21:24     ` Andrew Haley
  1 sibling, 0 replies; 10+ messages in thread
From: David Daney @ 2008-08-11 16:59 UTC (permalink / raw)
  To: Robin-Vossen; +Cc: gcc-help

Robin-Vossen wrote:

> Also, Well as you saw I used Pointers to Variables in my C Code. I didnt
> find a way to do that in GCC C Compiler.

You can do this with GCC's asm instruction, but the syntax is different.  Please see the fine documentation here:


http://gcc.gnu.org/onlinedocs/gcc-4.3.0/gcc/Extended-Asm.html

David Daney

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-11 16:35   ` Robin-Vossen
  2008-08-11 16:59     ` David Daney
@ 2008-08-11 21:24     ` Andrew Haley
  2008-08-12  1:08       ` Bob Plantz
  1 sibling, 1 reply; 10+ messages in thread
From: Andrew Haley @ 2008-08-11 21:24 UTC (permalink / raw)
  To: Robin-Vossen; +Cc: gcc-help

Robin-Vossen wrote:
> Well, thanks:
> 
> But, I just want to use Intel-Style ASM in there. with dest, src setup.
> Since I do quite a lot of Revercing and well I sometimes need to Copy
> Directly from Olly/IDA into C Code.
> Since that uses Intel I need the intel.

Sure, but it massively de-optimizes the code.  If you want the best
performance -- and if you're using asm I guess you do -- you'll
want to use GNU-style asm.

Andrew.

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-11 21:24     ` Andrew Haley
@ 2008-08-12  1:08       ` Bob Plantz
  2008-08-12  2:29         ` Brian Dessent
  0 siblings, 1 reply; 10+ messages in thread
From: Bob Plantz @ 2008-08-12  1:08 UTC (permalink / raw)
  To: Andrew Haley; +Cc: Robin-Vossen, gcc-help

On Mon, 2008-08-11 at 19:29 +0100, Andrew Haley wrote:

> Sure, but it massively de-optimizes the code.  If you want the best
> performance -- and if you're using asm I guess you do -- you'll
> want to use GNU-style asm.
> 
> Andrew.

How can that be? The thing that matters is the machine code. Both
syntaxes generate exactly the same machine code.

Bob


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-12  1:08       ` Bob Plantz
@ 2008-08-12  2:29         ` Brian Dessent
  2008-08-12  8:56           ` Bob Plantz
  2008-08-12 15:26           ` Ian Lance Taylor
  0 siblings, 2 replies; 10+ messages in thread
From: Brian Dessent @ 2008-08-12  2:29 UTC (permalink / raw)
  To: Bob Plantz; +Cc: Andrew Haley, Robin-Vossen, gcc-help

Bob Plantz wrote:

> How can that be? The thing that matters is the machine code. Both
> syntaxes generate exactly the same machine code.

Because the MSVC style of inline assembler doesn't allow for specifying
any constraints such as which registers or stack slots are clobbered. 
This means that compiler can't assume anything about the state before
and after the block, it must just throw away all dataflow information it
had before the block and assume everything was clobbered, leading to
tons of useless redundant loads/stores.  The GNU style inline asm works
within the framework of the optimizing compiler, rather than outside it
by totally going behind it's back.

Read the long thread that starts here:
<http://gcc.gnu.org/ml/gcc/2004-05/threads.html#00070>.

Brian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-12  2:29         ` Brian Dessent
@ 2008-08-12  8:56           ` Bob Plantz
  2008-08-13 17:27             ` Robin-Vossen
  2008-08-12 15:26           ` Ian Lance Taylor
  1 sibling, 1 reply; 10+ messages in thread
From: Bob Plantz @ 2008-08-12  8:56 UTC (permalink / raw)
  To: gcc-help; +Cc: Andrew Haley, Robin-Vossen

On Mon, 2008-08-11 at 18:07 -0700, Brian Dessent wrote:

> Because the MSVC style of inline assembler doesn't allow for specifying
> any constraints such as which registers or stack slots are clobbered. 
> This means that compiler can't assume anything about the state before
> and after the block, it must just throw away all dataflow information it
> had before the block and assume everything was clobbered, leading to
> tons of useless redundant loads/stores.  The GNU style inline asm works
> within the framework of the optimizing compiler, rather than outside it
> by totally going behind it's back.
> 
> Read the long thread that starts here:
> <http://gcc.gnu.org/ml/gcc/2004-05/threads.html#00070>.

Thank you for the explanation and the link. I've never been a Microsoft
programmer, and I haven't used CodeWarrior (Mac PowerPC) for  a long
time. I had forgotten about that technique of inline assembly.

Bob


^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-12  2:29         ` Brian Dessent
  2008-08-12  8:56           ` Bob Plantz
@ 2008-08-12 15:26           ` Ian Lance Taylor
  1 sibling, 0 replies; 10+ messages in thread
From: Ian Lance Taylor @ 2008-08-12 15:26 UTC (permalink / raw)
  To: gcc-help; +Cc: Bob Plantz, Andrew Haley, Robin-Vossen

Brian Dessent <brian@dessent.net> writes:

> Read the long thread that starts here:
> <http://gcc.gnu.org/ml/gcc/2004-05/threads.html#00070>.

I still think that this would be cool:

http://gcc.gnu.org/ml/gcc/2004-05/msg00391.html

(but I have no plans to work on it myself).

Ian

^ permalink raw reply	[flat|nested] 10+ messages in thread

* Re: GNU C++ Inline Assembler
  2008-08-12  8:56           ` Bob Plantz
@ 2008-08-13 17:27             ` Robin-Vossen
  0 siblings, 0 replies; 10+ messages in thread
From: Robin-Vossen @ 2008-08-13 17:27 UTC (permalink / raw)
  To: gcc-help


Thanks ALL, I think I can continue doing my work soon now.
I understand that I'd lose a lot of preformance doing it the MS way.
But, well I dont need speed =) Since I am a RCE I need it to check if I was
sure the code did that I thought it would do. ^^

But, yea this will help me.
I'll read the three links I've got from you guys and then Ill continue
asking Quesitons if something is still not clear to me.

Thanks for everything.

Cheers,
Robin


Bob Plantz wrote:
> 
> On Mon, 2008-08-11 at 18:07 -0700, Brian Dessent wrote:
> 
>> Because the MSVC style of inline assembler doesn't allow for specifying
>> any constraints such as which registers or stack slots are clobbered. 
>> This means that compiler can't assume anything about the state before
>> and after the block, it must just throw away all dataflow information it
>> had before the block and assume everything was clobbered, leading to
>> tons of useless redundant loads/stores.  The GNU style inline asm works
>> within the framework of the optimizing compiler, rather than outside it
>> by totally going behind it's back.
>> 
>> Read the long thread that starts here:
>> <http://gcc.gnu.org/ml/gcc/2004-05/threads.html#00070>.
> 
> Thank you for the explanation and the link. I've never been a Microsoft
> programmer, and I haven't used CodeWarrior (Mac PowerPC) for  a long
> time. I had forgotten about that technique of inline assembly.
> 
> Bob
> 
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/GNU-C%2B%2B-Inline-Assembler-tp18912389p18959097.html
Sent from the gcc - Help mailing list archive at Nabble.com.

^ permalink raw reply	[flat|nested] 10+ messages in thread

end of thread, other threads:[~2008-08-13  8:43 UTC | newest]

Thread overview: 10+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2008-08-10 21:39 GNU C++ Inline Assembler Robin-Vossen
2008-08-11  6:37 ` Bob Plantz
2008-08-11 16:35   ` Robin-Vossen
2008-08-11 16:59     ` David Daney
2008-08-11 21:24     ` Andrew Haley
2008-08-12  1:08       ` Bob Plantz
2008-08-12  2:29         ` Brian Dessent
2008-08-12  8:56           ` Bob Plantz
2008-08-13 17:27             ` Robin-Vossen
2008-08-12 15:26           ` Ian Lance Taylor

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).