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 7910779
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 3, 20262026-06-03T12:59:51+00:00 2026-06-03T12:59:51+00:00

I don’t understand how this is supposed to work. GCC inline assembler is a

  • 0

I don’t understand how this is supposed to work.

GCC inline assembler is a pain to get right, but very specific about marking clobbering information, so that the compiler knows what you’re doing.

Microsoft Visual C++’s inline assember is really easy to use (it always seems to Just Work), but I have no ideas what kinds of guarantees or assumptions it makes about your code.

Does VC++ try to “auto-detect” what registers are clobbered? How does it know how the registers and the stack pointer will be changed? Does it make any assumptions? If so, how do you get around those assumptions?

  • 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. Editorial Team
    Editorial Team
    2026-06-03T12:59:54+00:00Added an answer on June 3, 2026 at 12:59 pm

    As for why GCC doesn’t do it the way MSVC does, there are several reasons:

    1. GCC is a retargettable compiler, but the assembly syntax is just raw text. In order for the clobber detection to be automatic, GCC would have to parse the assembly language to understand what registers are being clobbered (including implicitly clobbered ones by instructions whose opcodes do not name a register). This would have to work across all architectures. Currently, GCC does not parse the assembly language; it just pastes it into the assembly output, after performing the % substitutions. The idea is to generate, and avoid parsing.

    2. In GCC inline assembly language, clobbering registers is the exception rather than the rule. The reason is that it is a more sophisticated language than that in MSVC. GCC’s inline assembly language allocates registers for you. So you usually don’t use something like %eax directly, but rather a code like %0 for which GCC substitutes an available register. (And to do that, the compiler doesn’t have to understand the assembly language! you express the constraints which ensure that GCC substitutes an appropriate register for %0 which fits the usage.) You only need clobber if your assembly code is overwriting hard-coded registers, not if it is overwriting the output operands allocated for you by GCC.

    Note that with GCC inline assembly, you don’t have to write the code which loads your assembly language operands from the C expressions that produce their initial values, or which stores your result operands into the C destinations. For instance you just express that there is to be an input operand of type "r" (register) which is derived from the expression foo->bar + 1. GCC allocates the register and generates the code to load it from foo->bar + 1, and then replaces occurences of %0 in your assembly template with the name of that register.

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

Sidebar

Related Questions

Don't know if this is the right place to ask this, but I will
Don't know if this is an eclipse specific problem but whenever I declare a
Don't need to do this right now but thinking about the future... What would
I don't know whether this is really possible, but I'm trying my best. If
I don't think this is particularly quirky, but in an attempt to control my
Don't know if I worded the question right, but basically what I want to
(Don't know if this is strictly on-topic, but I don't see any better Stack
Don't know how to explain it better but i'm trying to get a response
I don't know if this question is trivial or not. But after a couple
Don't overthink this - there's a very commonly used term and I ... have

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.