Page 1 of 1

c compiler inline Intel notation assembly

Posted: Wed Mar 26, 2008 12:46 pm
by Gavin
What are my options ?
Has to comply with ANSI C and if possible be free and isn't likely to die out in the future.
Thanks alot.

Posted: Wed Mar 26, 2008 1:30 pm
by Zenith
The phrase "c compiler inline Intel notation assembly" is pretty vague :shock:, but I'm assuming you mean a C compiler with intel syntax for inline assembly.

gcc supports "-masm=intel", but i'm not sure if that also applies to the actual gnu assembler or if you have to supply your own intel-compatible one. IIRC the microsoft c compiler(s) also use intel as their standard assembly syntax.

And of course, it's always possible to just learn the more 'portable' AT&T syntax :wink:

Posted: Wed Mar 26, 2008 2:23 pm
by Gavin
C compiler with intel syntax for inline assembly is correct.
I've used nasm alot so i would like to stick to the intel notation if possible.
The microsoft c compiler is not as portable for amd cpu's is it?

At&t is for unix and linux right?

Posted: Wed Mar 26, 2008 3:14 pm
by JamesM
Hi,

The GNU compiler collection (GCC) is the de facto compiler set for any unix system. It uses GAS, the GNU assembler, which uses AT&T syntax natively but can be configured via assembler directives to use Intel syntax.

Several people here do this, and it going something like this:

Code: Select all

#define ASM(x) do {asm volatile(".syntax intel"); asm volatile(x); asm volatile(".syntax att");} while (0)
Hope this helps,

James

Posted: Wed Mar 26, 2008 3:15 pm
by Brynet-Inc
The GNU Assembler is capable of Intel syntax.

Silly example - Works on OpenBSD(With gcc -O0..):

Code: Select all

#include <stdio.h>

int main(void) {
	int local_var;
	
	asm(".intel_syntax noprefix");
	
	asm("mov dword ptr [ebp-28], 666");
	
	asm(".att_syntax");
	
	printf("%d", local_var);

	return 0;
}
This may help you: http://www.mirbsd.org/htman/i386/man7/g ... -howto.htm

It would probably be worth while just to learn AT&T syntax, it's a skill worth having. ;)

Posted: Wed Mar 26, 2008 3:56 pm
by Gavin
Thanks for the detailed replies .
I work on windows and use nasm alot i've only started to learn c.

If i use that define in my c source files thats where i use it right?Will that cause any problems i might not foresee?

Posted: Thu Mar 27, 2008 1:23 am
by JamesM
It shouldn't cause any problems - I got the preamble and epilogue slightly wrong though (the .syntax intel bit should be .intel_syntax noprefix, as per Brynet's post).

Posted: Thu Mar 27, 2008 8:20 am
by Gavin
I'll go ahead and use the gcc compiler it would be silly to use something else by the looks of it.
I haven't the fogiest what preamble and epilogue is, but the words sound lovely :wink:
But thanks . :D

Posted: Thu Mar 27, 2008 9:20 am
by lukem95
Gavin wrote:I'll go ahead and use the gcc compiler it would be silly to use something else by the looks of it.
I haven't the fogiest what preamble and epilogue is, but the words sound lovely :wink:
But thanks . :D
"but the works sound lovely" hahahah :D

if they had ratings on this forum, you my friend would get 6 out of 5!

[/OT]

Posted: Sat Mar 29, 2008 7:48 pm
by Gavin
Haha Luke :D

I installed cygwin and gcc and of course nasm i'm ready to get cracking on my mbr :)

Posted: Mon Apr 07, 2008 7:38 am
by jal
Brynet-Inc wrote:

Code: Select all

#include <stdio.h>

int main(void) {
	int local_var;
	
	asm(".intel_syntax noprefix");
	
	asm("mov dword ptr [ebp-28], 666");
	
	asm(".att_syntax");
	
	printf("%d", local_var);

	return 0;
}
For a very funny result forget the ".att_syntax". I did it once :).


JAL

Re: c compiler inline Intel notation assembly

Posted: Fri Apr 11, 2008 6:26 am
by Solar
Gavin wrote:Has to comply with ANSI C...
You most likely mean that the compiler should comply with ANSI C unless you do inline assembly. Nevertheless I'd like to point out that inline assembly never "complies with ANSI C", as ANSI C does not support that technique - it's a compiler-specific extension.

Posted: Fri Apr 11, 2008 5:39 pm
by zerosum
This is quite neat; I did not know you could do this.

AT&T syntax is ugly as hell (imho) and I don't understand how to do many simple things in it. I think I'll be using this to do inline asm in the sensible syntax, in future ;-)

Thanks people :-)