Page 1 of 1

Using intel syntax asm with gcc

Posted: Sun Feb 19, 2006 1:21 pm
by earlz
I was googling trying to figure out how to use the att syntax and then i saw http://wiki.bfh.ch/index.php/Inline_@$$ ... th_the_GCC and it
showed an exact intel syntax which is super easy to use and no more %0,%%eax crap
here is the small code snipplet that demonstrated it

Code: Select all

static int VarD = 0x27439AB;
static int VarB = 19;
static int VarA = 8;
static int VarC = -56;

int main() {
  __asm (
    ".intel_syntax noprefix\n" //this tells it to go intel
    "mov  EAX,[VarA]\n"
    "add  EAX,[VarB]\n"
    "mov  [VarC],EAX\n"
    ".att_syntax \n" //remember that the compiler still uses att syntax so this should be at the end everytime
  );

  VarC = VarA + VarB;
  return 0;
}
well i just wanted to share that cause i have seen many new coders(including me) saying "how do you change asm to normal" or "can i use nasm so i get the normal looking way"
which i thought was all no until now.

Re:Using intel syntax asm with gcc

Posted: Sun Feb 19, 2006 1:37 pm
by srg
IMHO AT&T syntax is better once you get your head arround it (not easy).

Re:Using intel syntax asm with gcc

Posted: Sun Feb 19, 2006 3:05 pm
by Pype.Clicker
yep . a well known trick. I think we have it in the FAQ aswell ... You're strongly suggested to write macros that will expand e.g. "INTEL(x)" into ".intel_syntax noprefix\n" x ".att_syntax" to avoid terrible mistakes here ...

Re:Using intel syntax asm with gcc

Posted: Mon Feb 20, 2006 1:04 am
by Solar
Beauty is in the eye of the beholder, or: One man's bane is another man's blessing.

There are people (like me) around who made their first ASM steps in a time when "source -> destination" was the "normal" way. Nice to see you found a way to use Intel syntax in inline ASM; I'll stick with AT&T. ;)