Using intel syntax asm with gcc

Programming, for all ages and all languages.
Post Reply
earlz

Using intel syntax asm with gcc

Post 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.
srg

Re:Using intel syntax asm with gcc

Post by srg »

IMHO AT&T syntax is better once you get your head arround it (not easy).
User avatar
Pype.Clicker
Member
Member
Posts: 5964
Joined: Wed Oct 18, 2006 2:31 am
Location: In a galaxy, far, far away
Contact:

Re:Using intel syntax asm with gcc

Post 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 ...
User avatar
Solar
Member
Member
Posts: 7615
Joined: Thu Nov 16, 2006 12:01 pm
Location: Germany
Contact:

Re:Using intel syntax asm with gcc

Post 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. ;)
Every good solution is obvious once you've found it.
Post Reply