Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 137377
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 11, 20262026-05-11T07:05:48+00:00 2026-05-11T07:05:48+00:00

The GCC toolchain uses AT&T assembler syntax by default, but support for Intel syntax

  • 0

The GCC toolchain uses AT&T assembler syntax by default, but support for Intel syntax is available via the .intel_syntax directive.

Additionally, both AT&T and Intel syntax are available in a prefix and a noprefix version, which differ in whether or not they require to prefix register names with a % sigil.

Depending on which directives are present, the format for address constants changes.

Let’s consider the following C code

*(int *)0xdeadbeef = 0x1234; 

Using objdump -d, we find that it’s compiled to the following assembler instruction

movl $0x1234,0xdeadbeef 

As there are no registers involved, this is the correct syntax for both .att_syntax prefix and .att_syntax noprefix, ie. embedded in C code, they look like this

__asm__('.att_syntax prefix'); __asm__('movl $0x1234,0xdeadbeef');  __asm__('.att_syntax noprefix'); __asm__('movl $0x1234,0xdeadbeef'); 

You can optionally surround the address constant with parentheses, ie.

__asm__('movl $0x1234,(0xdeadbeef)'); 

will work as well.

When adding a sigil to a plain address constant, the code will fail to copile

__asm__('movl $0x1234,$0xdeadbeef'); // won't compile 

When surrounding this expression with paranthesis, the compiler will emit wrong code without warning, ie

__asm__('movl $0x1234,($0xdeadbeef)'); // doesn't warn, but doesn't work! 

This will incorrectly emit the instruction

movl $0x1234,0x0 

In Intel mode, an address constant has to be prefixed with a segment register as well as the operand size and the PTR flag if ambiguity is possible. On my machine (an Intel dual core laptop with Windows XP and current MinGW and Cygwin GCC versions), the register ds is used by default.

Square brackets around the constant are optional. The address constant is also correctly recognized if the segment register is omitted, but the brackets are present. Omitting the register emits a warning on my system, though.

In prefix mode, the segment register has to be prefixed with %, but only using brackets will still work. These are the different ways to generate the correct instruction:

__asm__('.intel_syntax noprefix'); __asm__('mov DWORD PTR ds:0xdeadbeef,0x1234'); __asm__('mov DWORD PTR ds:[0xdeadbeef],0x1234'); __asm__('mov DWORD PTR [0xdeadbeef],0x1234'); // works, but warns!  __asm__('.intel_syntax prefix'); __asm__('mov DWORD PTR %ds:0xdeadbeef,0x1234'); __asm__('mov DWORD PTR %ds:[0xdeadbeef],0x1234'); __asm__('mov DWORD PTR [0xdeadbeef],0x1234'); // works, but warns! 

Omitting both segment register and brackets will fail to compile

__asm__('mov DWORD PTR 0xdeadbeef,0x1234'); // won't compile 

I’ll mark this question as community wiki, so if you have anything useful to add, feel free to do so.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. 2026-05-11T07:05:48+00:00Added an answer on May 11, 2026 at 7:05 am

    The noprefix/prefix directives only control whether registers require a % prefix(*) (at least it seems so and that’s the only difference the documentation mentions). Value literals always need a $ prefix in AT&T syntax and never in Intel syntax. So the following works:

    __asm__('.intel_syntax prefix'); __asm__('MOV [DWORD PTR 0xDEADBEEF], 0x1234'); 

    If you are really inclined to use Intel syntax inline assembly within C code compiled with GCC and assembled with GAS, do not forget to also add the following after it, so that the assembler can grok the rest of the (AT&T syntax) assembly generated by GCC:

    __asm__('.att_syntax prefix'); 

    The reasoning I see for the prefix/noprefix distinction is, that for AT&T syntax, the % prefix is not really needed for registers on Intel architecture, because registers are named. But for uniformity it can be there because some other architectures (i.e. SPARC) have numbered registered, in which case specifying a low number alone would be ambiguous as to whether a memory address or register was meant.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Ask A Question

Stats

  • Questions 122k
  • Answers 122k
  • Best Answers 0
  • User 1
  • Popular
  • Answers
  • Editorial Team

    How to approach applying for a job at a company ...

    • 7 Answers
  • Editorial Team

    How to handle personal stress caused by utterly incompetent and ...

    • 5 Answers
  • Editorial Team

    What is a programmer’s life like?

    • 5 Answers
  • Editorial Team
    Editorial Team added an answer The "in" line needs adjusting. It should read in typeof(T).GetCustomAttributes(typeof(CoolnessFactorAttribute),… May 12, 2026 at 12:42 am
  • Editorial Team
    Editorial Team added an answer Rather than two vectors (one for names, and one for… May 12, 2026 at 12:42 am
  • Editorial Team
    Editorial Team added an answer I've always been partial to YourKit. There are lots of… May 12, 2026 at 12:42 am

Related Questions

There appears to be no definitive standardized stack frame and C language calling conventions
I have no trouble building 1.35.0, as well as 1.36.0 on the timesys arm-gcc
so as per one of my previous questions, I'm brushing up on my C
In what segment (.BSS, .DATA, other) of an executable file are static variables stored

Trending Tags

analytics british company computer developers django employee employer english facebook french google interview javascript language life php programmer programs salary

Top Members

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.